Coverage Report

Created: 2025-07-08 11:15

/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-2025 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
228k
{
132
228k
  RELOC *reloc_src = (RELOC *) src;
133
228k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
228k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
228k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
228k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
#ifdef SWAP_IN_RELOC_OFFSET
139
88.6k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
#endif
141
228k
}
pei-i386.c:coff_swap_reloc_in
Line
Count
Source
131
18.2k
{
132
18.2k
  RELOC *reloc_src = (RELOC *) src;
133
18.2k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
18.2k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
18.2k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
18.2k
  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
18.2k
}
pe-x86_64.c:coff_swap_reloc_in
Line
Count
Source
131
23.8k
{
132
23.8k
  RELOC *reloc_src = (RELOC *) src;
133
23.8k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
23.8k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
23.8k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
23.8k
  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
23.8k
}
pei-x86_64.c:coff_swap_reloc_in
Line
Count
Source
131
19.2k
{
132
19.2k
  RELOC *reloc_src = (RELOC *) src;
133
19.2k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
19.2k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
19.2k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
19.2k
  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
19.2k
}
pe-aarch64.c:coff_swap_reloc_in
Line
Count
Source
131
9.90k
{
132
9.90k
  RELOC *reloc_src = (RELOC *) src;
133
9.90k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
9.90k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
9.90k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
9.90k
  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
9.90k
}
pei-aarch64.c:coff_swap_reloc_in
Line
Count
Source
131
21.9k
{
132
21.9k
  RELOC *reloc_src = (RELOC *) src;
133
21.9k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
21.9k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
21.9k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
21.9k
  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
21.9k
}
pei-ia64.c:coff_swap_reloc_in
Line
Count
Source
131
12.7k
{
132
12.7k
  RELOC *reloc_src = (RELOC *) src;
133
12.7k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
12.7k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
12.7k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
12.7k
  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
12.7k
}
pei-loongarch64.c:coff_swap_reloc_in
Line
Count
Source
131
13.0k
{
132
13.0k
  RELOC *reloc_src = (RELOC *) src;
133
13.0k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
13.0k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
13.0k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
13.0k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
13.0k
#ifdef SWAP_IN_RELOC_OFFSET
139
13.0k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
13.0k
#endif
141
13.0k
}
pei-riscv64.c:coff_swap_reloc_in
Line
Count
Source
131
12.4k
{
132
12.4k
  RELOC *reloc_src = (RELOC *) src;
133
12.4k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
12.4k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
12.4k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
12.4k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
12.4k
#ifdef SWAP_IN_RELOC_OFFSET
139
12.4k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
12.4k
#endif
141
12.4k
}
pe-arm-wince.c:coff_swap_reloc_in
Line
Count
Source
131
4.63k
{
132
4.63k
  RELOC *reloc_src = (RELOC *) src;
133
4.63k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
4.63k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
4.63k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
4.63k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
4.63k
#ifdef SWAP_IN_RELOC_OFFSET
139
4.63k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
4.63k
#endif
141
4.63k
}
pe-arm.c:coff_swap_reloc_in
Line
Count
Source
131
4.63k
{
132
4.63k
  RELOC *reloc_src = (RELOC *) src;
133
4.63k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
4.63k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
4.63k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
4.63k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
4.63k
#ifdef SWAP_IN_RELOC_OFFSET
139
4.63k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
4.63k
#endif
141
4.63k
}
pe-i386.c:coff_swap_reloc_in
Line
Count
Source
131
9.01k
{
132
9.01k
  RELOC *reloc_src = (RELOC *) src;
133
9.01k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
9.01k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
9.01k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
9.01k
  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
9.01k
}
pe-mcore.c:coff_swap_reloc_in
Line
Count
Source
131
9.93k
{
132
9.93k
  RELOC *reloc_src = (RELOC *) src;
133
9.93k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
9.93k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
9.93k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
9.93k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
9.93k
#ifdef SWAP_IN_RELOC_OFFSET
139
9.93k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
9.93k
#endif
141
9.93k
}
pe-sh.c:coff_swap_reloc_in
Line
Count
Source
131
8.70k
{
132
8.70k
  RELOC *reloc_src = (RELOC *) src;
133
8.70k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
8.70k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
8.70k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
8.70k
  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
8.70k
}
pei-arm-wince.c:coff_swap_reloc_in
Line
Count
Source
131
13.5k
{
132
13.5k
  RELOC *reloc_src = (RELOC *) src;
133
13.5k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
13.5k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
13.5k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
13.5k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
13.5k
#ifdef SWAP_IN_RELOC_OFFSET
139
13.5k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
13.5k
#endif
141
13.5k
}
pei-arm.c:coff_swap_reloc_in
Line
Count
Source
131
17.1k
{
132
17.1k
  RELOC *reloc_src = (RELOC *) src;
133
17.1k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
17.1k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
17.1k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
17.1k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
17.1k
#ifdef SWAP_IN_RELOC_OFFSET
139
17.1k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
17.1k
#endif
141
17.1k
}
pei-mcore.c:coff_swap_reloc_in
Line
Count
Source
131
13.3k
{
132
13.3k
  RELOC *reloc_src = (RELOC *) src;
133
13.3k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
13.3k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
13.3k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
13.3k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
13.3k
#ifdef SWAP_IN_RELOC_OFFSET
139
13.3k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
13.3k
#endif
141
13.3k
}
pei-sh.c:coff_swap_reloc_in
Line
Count
Source
131
16.1k
{
132
16.1k
  RELOC *reloc_src = (RELOC *) src;
133
16.1k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
16.1k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
16.1k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
16.1k
  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
16.1k
}
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: pei-riscv64.c:coff_swap_reloc_out
Unexecuted instantiation: pe-arm-wince.c:coff_swap_reloc_out
Unexecuted instantiation: pe-arm.c:coff_swap_reloc_out
Unexecuted instantiation: pe-i386.c:coff_swap_reloc_out
Unexecuted instantiation: pe-mcore.c:coff_swap_reloc_out
Unexecuted instantiation: pe-sh.c:coff_swap_reloc_out
Unexecuted instantiation: pei-arm-wince.c:coff_swap_reloc_out
Unexecuted instantiation: pei-arm.c:coff_swap_reloc_out
Unexecuted instantiation: pei-mcore.c:coff_swap_reloc_out
Unexecuted instantiation: pei-sh.c:coff_swap_reloc_out
161
#endif /* not NO_COFF_RELOCS */
162
163
#ifdef COFF_IMAGE_WITH_PE
164
#undef FILHDR
165
8.73M
#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
36.0M
{
171
36.0M
  FILHDR *filehdr_src = (FILHDR *) src;
172
36.0M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
36.0M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
36.0M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
36.0M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
36.0M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
36.0M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
36.0M
  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
36.0M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
3.13M
    {
185
3.13M
      filehdr_dst->f_nsyms = 0;
186
3.13M
      filehdr_dst->f_flags |= F_LSYMS;
187
3.13M
    }
188
189
36.0M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
36.0M
}
pei-i386.c:coff_swap_filehdr_in
Line
Count
Source
170
901k
{
171
901k
  FILHDR *filehdr_src = (FILHDR *) src;
172
901k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
901k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
901k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
901k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
901k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
901k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
901k
  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
901k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
48.9k
    {
185
48.9k
      filehdr_dst->f_nsyms = 0;
186
48.9k
      filehdr_dst->f_flags |= F_LSYMS;
187
48.9k
    }
188
189
901k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
901k
}
pe-x86_64.c:coff_swap_filehdr_in
Line
Count
Source
170
2.78M
{
171
2.78M
  FILHDR *filehdr_src = (FILHDR *) src;
172
2.78M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
2.78M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
2.78M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
2.78M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
2.78M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
2.78M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
2.78M
  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.78M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
268k
    {
185
268k
      filehdr_dst->f_nsyms = 0;
186
268k
      filehdr_dst->f_flags |= F_LSYMS;
187
268k
    }
188
189
2.78M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
2.78M
}
pei-x86_64.c:coff_swap_filehdr_in
Line
Count
Source
170
899k
{
171
899k
  FILHDR *filehdr_src = (FILHDR *) src;
172
899k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
899k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
899k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
899k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
899k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
899k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
899k
  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
899k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
51.0k
    {
185
51.0k
      filehdr_dst->f_nsyms = 0;
186
51.0k
      filehdr_dst->f_flags |= F_LSYMS;
187
51.0k
    }
188
189
899k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
899k
}
pe-aarch64.c:coff_swap_filehdr_in
Line
Count
Source
170
2.73M
{
171
2.73M
  FILHDR *filehdr_src = (FILHDR *) src;
172
2.73M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
2.73M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
2.73M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
2.73M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
2.73M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
2.73M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
2.73M
  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.73M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
268k
    {
185
268k
      filehdr_dst->f_nsyms = 0;
186
268k
      filehdr_dst->f_flags |= F_LSYMS;
187
268k
    }
188
189
2.73M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
2.73M
}
pei-aarch64.c:coff_swap_filehdr_in
Line
Count
Source
170
869k
{
171
869k
  FILHDR *filehdr_src = (FILHDR *) src;
172
869k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
869k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
869k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
869k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
869k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
869k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
869k
  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
869k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
46.4k
    {
185
46.4k
      filehdr_dst->f_nsyms = 0;
186
46.4k
      filehdr_dst->f_flags |= F_LSYMS;
187
46.4k
    }
188
189
869k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
869k
}
pei-ia64.c:coff_swap_filehdr_in
Line
Count
Source
170
852k
{
171
852k
  FILHDR *filehdr_src = (FILHDR *) src;
172
852k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
852k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
852k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
852k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
852k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
852k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
852k
  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
852k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
44.5k
    {
185
44.5k
      filehdr_dst->f_nsyms = 0;
186
44.5k
      filehdr_dst->f_flags |= F_LSYMS;
187
44.5k
    }
188
189
852k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
852k
}
pei-loongarch64.c:coff_swap_filehdr_in
Line
Count
Source
170
868k
{
171
868k
  FILHDR *filehdr_src = (FILHDR *) src;
172
868k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
868k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
868k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
868k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
868k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
868k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
868k
  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
868k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
46.4k
    {
185
46.4k
      filehdr_dst->f_nsyms = 0;
186
46.4k
      filehdr_dst->f_flags |= F_LSYMS;
187
46.4k
    }
188
189
868k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
868k
}
pei-riscv64.c:coff_swap_filehdr_in
Line
Count
Source
170
868k
{
171
868k
  FILHDR *filehdr_src = (FILHDR *) src;
172
868k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
868k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
868k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
868k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
868k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
868k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
868k
  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
868k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
46.3k
    {
185
46.3k
      filehdr_dst->f_nsyms = 0;
186
46.3k
      filehdr_dst->f_flags |= F_LSYMS;
187
46.3k
    }
188
189
868k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
868k
}
pe-arm-wince.c:coff_swap_filehdr_in
Line
Count
Source
170
5.45M
{
171
5.45M
  FILHDR *filehdr_src = (FILHDR *) src;
172
5.45M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
5.45M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
5.45M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
5.45M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
5.45M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
5.45M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
5.45M
  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
5.45M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
533k
    {
185
533k
      filehdr_dst->f_nsyms = 0;
186
533k
      filehdr_dst->f_flags |= F_LSYMS;
187
533k
    }
188
189
5.45M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
5.45M
}
pe-arm.c:coff_swap_filehdr_in
Line
Count
Source
170
5.45M
{
171
5.45M
  FILHDR *filehdr_src = (FILHDR *) src;
172
5.45M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
5.45M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
5.45M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
5.45M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
5.45M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
5.45M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
5.45M
  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
5.45M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
533k
    {
185
533k
      filehdr_dst->f_nsyms = 0;
186
533k
      filehdr_dst->f_flags |= F_LSYMS;
187
533k
    }
188
189
5.45M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
5.45M
}
pe-i386.c:coff_swap_filehdr_in
Line
Count
Source
170
2.73M
{
171
2.73M
  FILHDR *filehdr_src = (FILHDR *) src;
172
2.73M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
2.73M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
2.73M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
2.73M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
2.73M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
2.73M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
2.73M
  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.73M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
266k
    {
185
266k
      filehdr_dst->f_nsyms = 0;
186
266k
      filehdr_dst->f_flags |= F_LSYMS;
187
266k
    }
188
189
2.73M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
2.73M
}
pe-mcore.c:coff_swap_filehdr_in
Line
Count
Source
170
5.45M
{
171
5.45M
  FILHDR *filehdr_src = (FILHDR *) src;
172
5.45M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
5.45M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
5.45M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
5.45M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
5.45M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
5.45M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
5.45M
  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
5.45M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
528k
    {
185
528k
      filehdr_dst->f_nsyms = 0;
186
528k
      filehdr_dst->f_flags |= F_LSYMS;
187
528k
    }
188
189
5.45M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
5.45M
}
pe-sh.c:coff_swap_filehdr_in
Line
Count
Source
170
2.72M
{
171
2.72M
  FILHDR *filehdr_src = (FILHDR *) src;
172
2.72M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
2.72M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
2.72M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
2.72M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
2.72M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
2.72M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
2.72M
  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.72M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
264k
    {
185
264k
      filehdr_dst->f_nsyms = 0;
186
264k
      filehdr_dst->f_flags |= F_LSYMS;
187
264k
    }
188
189
2.72M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
2.72M
}
pei-arm-wince.c:coff_swap_filehdr_in
Line
Count
Source
170
867k
{
171
867k
  FILHDR *filehdr_src = (FILHDR *) src;
172
867k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
867k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
867k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
867k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
867k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
867k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
867k
  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
867k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
46.4k
    {
185
46.4k
      filehdr_dst->f_nsyms = 0;
186
46.4k
      filehdr_dst->f_flags |= F_LSYMS;
187
46.4k
    }
188
189
867k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
867k
}
pei-arm.c:coff_swap_filehdr_in
Line
Count
Source
170
867k
{
171
867k
  FILHDR *filehdr_src = (FILHDR *) src;
172
867k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
867k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
867k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
867k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
867k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
867k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
867k
  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
867k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
46.4k
    {
185
46.4k
      filehdr_dst->f_nsyms = 0;
186
46.4k
      filehdr_dst->f_flags |= F_LSYMS;
187
46.4k
    }
188
189
867k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
867k
}
pei-mcore.c:coff_swap_filehdr_in
Line
Count
Source
170
867k
{
171
867k
  FILHDR *filehdr_src = (FILHDR *) src;
172
867k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
867k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
867k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
867k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
867k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
867k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
867k
  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
867k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
46.3k
    {
185
46.3k
      filehdr_dst->f_nsyms = 0;
186
46.3k
      filehdr_dst->f_flags |= F_LSYMS;
187
46.3k
    }
188
189
867k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
867k
}
pei-sh.c:coff_swap_filehdr_in
Line
Count
Source
170
867k
{
171
867k
  FILHDR *filehdr_src = (FILHDR *) src;
172
867k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
867k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
867k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
867k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
867k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
867k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
867k
  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
867k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
46.4k
    {
185
46.4k
      filehdr_dst->f_nsyms = 0;
186
46.4k
      filehdr_dst->f_flags |= F_LSYMS;
187
46.4k
    }
188
189
867k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
867k
}
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
3.78M
{
207
3.78M
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
3.78M
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
3.78M
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
3.78M
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
3.78M
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
3.78M
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
3.78M
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
3.78M
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
3.78M
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
3.78M
  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
2.41M
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
2.41M
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
  scnhdr_int->s_nreloc = 0;
227
#else
228
1.37M
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
1.37M
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
#endif
231
232
3.78M
  if (scnhdr_int->s_vaddr != 0)
233
2.56M
    {
234
2.56M
      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) \
237
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
238
      scnhdr_int->s_vaddr &= 0xffffffff;
239
#endif
240
2.56M
    }
241
242
3.78M
#ifndef COFF_NO_HACK_SCNHDR_SIZE
243
  /* If this section holds uninitialized data and is from an object file
244
     or from an executable image that has not initialized the field,
245
     or if the image is an executable file and the physical size is padded,
246
     use the virtual size (stored in s_paddr) instead.  */
247
3.78M
  if (scnhdr_int->s_paddr > 0
248
3.78M
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
249
2.62M
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
250
2.62M
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
251
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
252
     coff_set_alignment_hook stores s_paddr in virt_size, which
253
     only works if it correctly holds the virtual size of the
254
     section.  */
255
906k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
256
3.78M
#endif
257
3.78M
}
pei-i386.c:coff_swap_scnhdr_in
Line
Count
Source
206
301k
{
207
301k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
301k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
301k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
301k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
301k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
301k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
301k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
301k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
301k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
301k
  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
301k
#ifdef COFF_IMAGE_WITH_PE
224
301k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
301k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
301k
  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
301k
  if (scnhdr_int->s_vaddr != 0)
233
212k
    {
234
212k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
212k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
237
212k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
238
212k
      scnhdr_int->s_vaddr &= 0xffffffff;
239
212k
#endif
240
212k
    }
241
242
301k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
243
  /* If this section holds uninitialized data and is from an object file
244
     or from an executable image that has not initialized the field,
245
     or if the image is an executable file and the physical size is padded,
246
     use the virtual size (stored in s_paddr) instead.  */
247
301k
  if (scnhdr_int->s_paddr > 0
248
301k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
249
234k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
250
234k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
251
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
252
     coff_set_alignment_hook stores s_paddr in virt_size, which
253
     only works if it correctly holds the virtual size of the
254
     section.  */
255
83.5k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
256
301k
#endif
257
301k
}
pe-x86_64.c:coff_swap_scnhdr_in
Line
Count
Source
206
643k
{
207
643k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
643k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
643k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
643k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
643k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
643k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
643k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
643k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
643k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
643k
  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
643k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
643k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
643k
#endif
231
232
643k
  if (scnhdr_int->s_vaddr != 0)
233
319k
    {
234
319k
      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) \
237
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
238
      scnhdr_int->s_vaddr &= 0xffffffff;
239
#endif
240
319k
    }
241
242
643k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
243
  /* If this section holds uninitialized data and is from an object file
244
     or from an executable image that has not initialized the field,
245
     or if the image is an executable file and the physical size is padded,
246
     use the virtual size (stored in s_paddr) instead.  */
247
643k
  if (scnhdr_int->s_paddr > 0
248
643k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
249
316k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
250
316k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
251
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
252
     coff_set_alignment_hook stores s_paddr in virt_size, which
253
     only works if it correctly holds the virtual size of the
254
     section.  */
255
49.8k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
256
643k
#endif
257
643k
}
pei-x86_64.c:coff_swap_scnhdr_in
Line
Count
Source
206
286k
{
207
286k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
286k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
286k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
286k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
286k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
286k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
286k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
286k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
286k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
286k
  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
286k
#ifdef COFF_IMAGE_WITH_PE
224
286k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
286k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
286k
  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
286k
  if (scnhdr_int->s_vaddr != 0)
233
218k
    {
234
218k
      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) \
237
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
238
      scnhdr_int->s_vaddr &= 0xffffffff;
239
#endif
240
218k
    }
241
242
286k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
243
  /* If this section holds uninitialized data and is from an object file
244
     or from an executable image that has not initialized the field,
245
     or if the image is an executable file and the physical size is padded,
246
     use the virtual size (stored in s_paddr) instead.  */
247
286k
  if (scnhdr_int->s_paddr > 0
248
286k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
249
212k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
250
212k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
251
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
252
     coff_set_alignment_hook stores s_paddr in virt_size, which
253
     only works if it correctly holds the virtual size of the
254
     section.  */
255
99.8k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
256
286k
#endif
257
286k
}
pe-aarch64.c:coff_swap_scnhdr_in
Line
Count
Source
206
197k
{
207
197k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
197k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
197k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
197k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
197k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
197k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
197k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
197k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
197k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
197k
  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
197k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
197k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
197k
#endif
231
232
197k
  if (scnhdr_int->s_vaddr != 0)
233
105k
    {
234
105k
      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) \
237
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
238
      scnhdr_int->s_vaddr &= 0xffffffff;
239
#endif
240
105k
    }
241
242
197k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
243
  /* If this section holds uninitialized data and is from an object file
244
     or from an executable image that has not initialized the field,
245
     or if the image is an executable file and the physical size is padded,
246
     use the virtual size (stored in s_paddr) instead.  */
247
197k
  if (scnhdr_int->s_paddr > 0
248
197k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
249
106k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
250
106k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
251
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
252
     coff_set_alignment_hook stores s_paddr in virt_size, which
253
     only works if it correctly holds the virtual size of the
254
     section.  */
255
17.1k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
256
197k
#endif
257
197k
}
pei-aarch64.c:coff_swap_scnhdr_in
Line
Count
Source
206
258k
{
207
258k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
258k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
258k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
258k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
258k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
258k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
258k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
258k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
258k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
258k
  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
258k
#ifdef COFF_IMAGE_WITH_PE
224
258k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
258k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
258k
  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
258k
  if (scnhdr_int->s_vaddr != 0)
233
187k
    {
234
187k
      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) \
237
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
238
      scnhdr_int->s_vaddr &= 0xffffffff;
239
#endif
240
187k
    }
241
242
258k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
243
  /* If this section holds uninitialized data and is from an object file
244
     or from an executable image that has not initialized the field,
245
     or if the image is an executable file and the physical size is padded,
246
     use the virtual size (stored in s_paddr) instead.  */
247
258k
  if (scnhdr_int->s_paddr > 0
248
258k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
249
183k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
250
183k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
251
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
252
     coff_set_alignment_hook stores s_paddr in virt_size, which
253
     only works if it correctly holds the virtual size of the
254
     section.  */
255
75.9k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
256
258k
#endif
257
258k
}
pei-ia64.c:coff_swap_scnhdr_in
Line
Count
Source
206
230k
{
207
230k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
230k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
230k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
230k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
230k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
230k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
230k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
230k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
230k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
230k
  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
230k
#ifdef COFF_IMAGE_WITH_PE
224
230k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
230k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
230k
  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
230k
  if (scnhdr_int->s_vaddr != 0)
233
167k
    {
234
167k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
167k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
237
167k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
238
167k
      scnhdr_int->s_vaddr &= 0xffffffff;
239
167k
#endif
240
167k
    }
241
242
230k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
243
  /* If this section holds uninitialized data and is from an object file
244
     or from an executable image that has not initialized the field,
245
     or if the image is an executable file and the physical size is padded,
246
     use the virtual size (stored in s_paddr) instead.  */
247
230k
  if (scnhdr_int->s_paddr > 0
248
230k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
249
177k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
250
177k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
251
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
252
     coff_set_alignment_hook stores s_paddr in virt_size, which
253
     only works if it correctly holds the virtual size of the
254
     section.  */
255
77.4k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
256
230k
#endif
257
230k
}
pei-loongarch64.c:coff_swap_scnhdr_in
Line
Count
Source
206
229k
{
207
229k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
229k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
229k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
229k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
229k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
229k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
229k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
229k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
229k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
229k
  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
229k
#ifdef COFF_IMAGE_WITH_PE
224
229k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
229k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
229k
  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
229k
  if (scnhdr_int->s_vaddr != 0)
233
161k
    {
234
161k
      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) \
237
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
238
      scnhdr_int->s_vaddr &= 0xffffffff;
239
#endif
240
161k
    }
241
242
229k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
243
  /* If this section holds uninitialized data and is from an object file
244
     or from an executable image that has not initialized the field,
245
     or if the image is an executable file and the physical size is padded,
246
     use the virtual size (stored in s_paddr) instead.  */
247
229k
  if (scnhdr_int->s_paddr > 0
248
229k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
249
173k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
250
173k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
251
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
252
     coff_set_alignment_hook stores s_paddr in virt_size, which
253
     only works if it correctly holds the virtual size of the
254
     section.  */
255
78.2k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
256
229k
#endif
257
229k
}
pei-riscv64.c:coff_swap_scnhdr_in
Line
Count
Source
206
210k
{
207
210k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
210k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
210k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
210k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
210k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
210k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
210k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
210k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
210k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
210k
  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
210k
#ifdef COFF_IMAGE_WITH_PE
224
210k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
210k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
210k
  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
210k
  if (scnhdr_int->s_vaddr != 0)
233
125k
    {
234
125k
      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) \
237
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
238
      scnhdr_int->s_vaddr &= 0xffffffff;
239
#endif
240
125k
    }
241
242
210k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
243
  /* If this section holds uninitialized data and is from an object file
244
     or from an executable image that has not initialized the field,
245
     or if the image is an executable file and the physical size is padded,
246
     use the virtual size (stored in s_paddr) instead.  */
247
210k
  if (scnhdr_int->s_paddr > 0
248
210k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
249
130k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
250
130k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
251
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
252
     coff_set_alignment_hook stores s_paddr in virt_size, which
253
     only works if it correctly holds the virtual size of the
254
     section.  */
255
51.1k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
256
210k
#endif
257
210k
}
pe-arm-wince.c:coff_swap_scnhdr_in
Line
Count
Source
206
57.4k
{
207
57.4k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
57.4k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
57.4k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
57.4k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
57.4k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
57.4k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
57.4k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
57.4k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
57.4k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
57.4k
  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
57.4k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
57.4k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
57.4k
#endif
231
232
57.4k
  if (scnhdr_int->s_vaddr != 0)
233
45.6k
    {
234
45.6k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
45.6k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
237
45.6k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
238
45.6k
      scnhdr_int->s_vaddr &= 0xffffffff;
239
45.6k
#endif
240
45.6k
    }
241
242
57.4k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
243
  /* If this section holds uninitialized data and is from an object file
244
     or from an executable image that has not initialized the field,
245
     or if the image is an executable file and the physical size is padded,
246
     use the virtual size (stored in s_paddr) instead.  */
247
57.4k
  if (scnhdr_int->s_paddr > 0
248
57.4k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
249
44.3k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
250
44.3k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
251
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
252
     coff_set_alignment_hook stores s_paddr in virt_size, which
253
     only works if it correctly holds the virtual size of the
254
     section.  */
255
11.9k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
256
57.4k
#endif
257
57.4k
}
pe-arm.c:coff_swap_scnhdr_in
Line
Count
Source
206
57.4k
{
207
57.4k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
57.4k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
57.4k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
57.4k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
57.4k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
57.4k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
57.4k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
57.4k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
57.4k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
57.4k
  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
57.4k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
57.4k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
57.4k
#endif
231
232
57.4k
  if (scnhdr_int->s_vaddr != 0)
233
45.6k
    {
234
45.6k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
45.6k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
237
45.6k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
238
45.6k
      scnhdr_int->s_vaddr &= 0xffffffff;
239
45.6k
#endif
240
45.6k
    }
241
242
57.4k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
243
  /* If this section holds uninitialized data and is from an object file
244
     or from an executable image that has not initialized the field,
245
     or if the image is an executable file and the physical size is padded,
246
     use the virtual size (stored in s_paddr) instead.  */
247
57.4k
  if (scnhdr_int->s_paddr > 0
248
57.4k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
249
44.3k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
250
44.3k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
251
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
252
     coff_set_alignment_hook stores s_paddr in virt_size, which
253
     only works if it correctly holds the virtual size of the
254
     section.  */
255
11.9k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
256
57.4k
#endif
257
57.4k
}
pe-i386.c:coff_swap_scnhdr_in
Line
Count
Source
206
130k
{
207
130k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
130k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
130k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
130k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
130k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
130k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
130k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
130k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
130k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
130k
  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
130k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
130k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
130k
#endif
231
232
130k
  if (scnhdr_int->s_vaddr != 0)
233
95.0k
    {
234
95.0k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
95.0k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
237
95.0k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
238
95.0k
      scnhdr_int->s_vaddr &= 0xffffffff;
239
95.0k
#endif
240
95.0k
    }
241
242
130k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
243
  /* If this section holds uninitialized data and is from an object file
244
     or from an executable image that has not initialized the field,
245
     or if the image is an executable file and the physical size is padded,
246
     use the virtual size (stored in s_paddr) instead.  */
247
130k
  if (scnhdr_int->s_paddr > 0
248
130k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
249
99.1k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
250
99.1k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
251
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
252
     coff_set_alignment_hook stores s_paddr in virt_size, which
253
     only works if it correctly holds the virtual size of the
254
     section.  */
255
17.4k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
256
130k
#endif
257
130k
}
pe-mcore.c:coff_swap_scnhdr_in
Line
Count
Source
206
168k
{
207
168k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
168k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
168k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
168k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
168k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
168k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
168k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
168k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
168k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
168k
  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
168k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
168k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
168k
#endif
231
232
168k
  if (scnhdr_int->s_vaddr != 0)
233
126k
    {
234
126k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
126k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
237
126k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
238
126k
      scnhdr_int->s_vaddr &= 0xffffffff;
239
126k
#endif
240
126k
    }
241
242
168k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
243
  /* If this section holds uninitialized data and is from an object file
244
     or from an executable image that has not initialized the field,
245
     or if the image is an executable file and the physical size is padded,
246
     use the virtual size (stored in s_paddr) instead.  */
247
168k
  if (scnhdr_int->s_paddr > 0
248
168k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
249
128k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
250
128k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
251
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
252
     coff_set_alignment_hook stores s_paddr in virt_size, which
253
     only works if it correctly holds the virtual size of the
254
     section.  */
255
27.5k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
256
168k
#endif
257
168k
}
pe-sh.c:coff_swap_scnhdr_in
Line
Count
Source
206
119k
{
207
119k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
119k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
119k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
119k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
119k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
119k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
119k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
119k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
119k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
119k
  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
119k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
119k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
119k
#endif
231
232
119k
  if (scnhdr_int->s_vaddr != 0)
233
79.6k
    {
234
79.6k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
79.6k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
237
79.6k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
238
79.6k
      scnhdr_int->s_vaddr &= 0xffffffff;
239
79.6k
#endif
240
79.6k
    }
241
242
119k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
243
  /* If this section holds uninitialized data and is from an object file
244
     or from an executable image that has not initialized the field,
245
     or if the image is an executable file and the physical size is padded,
246
     use the virtual size (stored in s_paddr) instead.  */
247
119k
  if (scnhdr_int->s_paddr > 0
248
119k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
249
77.6k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
250
77.6k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
251
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
252
     coff_set_alignment_hook stores s_paddr in virt_size, which
253
     only works if it correctly holds the virtual size of the
254
     section.  */
255
16.5k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
256
119k
#endif
257
119k
}
pei-arm-wince.c:coff_swap_scnhdr_in
Line
Count
Source
206
207k
{
207
207k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
207k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
207k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
207k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
207k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
207k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
207k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
207k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
207k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
207k
  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
207k
#ifdef COFF_IMAGE_WITH_PE
224
207k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
207k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
207k
  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
207k
  if (scnhdr_int->s_vaddr != 0)
233
157k
    {
234
157k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
157k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
237
157k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
238
157k
      scnhdr_int->s_vaddr &= 0xffffffff;
239
157k
#endif
240
157k
    }
241
242
207k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
243
  /* If this section holds uninitialized data and is from an object file
244
     or from an executable image that has not initialized the field,
245
     or if the image is an executable file and the physical size is padded,
246
     use the virtual size (stored in s_paddr) instead.  */
247
207k
  if (scnhdr_int->s_paddr > 0
248
207k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
249
163k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
250
163k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
251
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
252
     coff_set_alignment_hook stores s_paddr in virt_size, which
253
     only works if it correctly holds the virtual size of the
254
     section.  */
255
67.6k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
256
207k
#endif
257
207k
}
pei-arm.c:coff_swap_scnhdr_in
Line
Count
Source
206
267k
{
207
267k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
267k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
267k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
267k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
267k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
267k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
267k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
267k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
267k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
267k
  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
267k
#ifdef COFF_IMAGE_WITH_PE
224
267k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
267k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
267k
  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
267k
  if (scnhdr_int->s_vaddr != 0)
233
202k
    {
234
202k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
202k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
237
202k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
238
202k
      scnhdr_int->s_vaddr &= 0xffffffff;
239
202k
#endif
240
202k
    }
241
242
267k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
243
  /* If this section holds uninitialized data and is from an object file
244
     or from an executable image that has not initialized the field,
245
     or if the image is an executable file and the physical size is padded,
246
     use the virtual size (stored in s_paddr) instead.  */
247
267k
  if (scnhdr_int->s_paddr > 0
248
267k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
249
210k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
250
210k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
251
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
252
     coff_set_alignment_hook stores s_paddr in virt_size, which
253
     only works if it correctly holds the virtual size of the
254
     section.  */
255
86.1k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
256
267k
#endif
257
267k
}
pei-mcore.c:coff_swap_scnhdr_in
Line
Count
Source
206
199k
{
207
199k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
199k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
199k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
199k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
199k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
199k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
199k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
199k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
199k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
199k
  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
199k
#ifdef COFF_IMAGE_WITH_PE
224
199k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
199k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
199k
  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
199k
  if (scnhdr_int->s_vaddr != 0)
233
149k
    {
234
149k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
149k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
237
149k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
238
149k
      scnhdr_int->s_vaddr &= 0xffffffff;
239
149k
#endif
240
149k
    }
241
242
199k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
243
  /* If this section holds uninitialized data and is from an object file
244
     or from an executable image that has not initialized the field,
245
     or if the image is an executable file and the physical size is padded,
246
     use the virtual size (stored in s_paddr) instead.  */
247
199k
  if (scnhdr_int->s_paddr > 0
248
199k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
249
153k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
250
153k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
251
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
252
     coff_set_alignment_hook stores s_paddr in virt_size, which
253
     only works if it correctly holds the virtual size of the
254
     section.  */
255
58.6k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
256
199k
#endif
257
199k
}
pei-sh.c:coff_swap_scnhdr_in
Line
Count
Source
206
218k
{
207
218k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
218k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
218k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
218k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
218k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
218k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
218k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
218k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
218k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
218k
  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
218k
#ifdef COFF_IMAGE_WITH_PE
224
218k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
218k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
218k
  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
218k
  if (scnhdr_int->s_vaddr != 0)
233
165k
    {
234
165k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
165k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
237
165k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
238
165k
      scnhdr_int->s_vaddr &= 0xffffffff;
239
165k
#endif
240
165k
    }
241
242
218k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
243
  /* If this section holds uninitialized data and is from an object file
244
     or from an executable image that has not initialized the field,
245
     or if the image is an executable file and the physical size is padded,
246
     use the virtual size (stored in s_paddr) instead.  */
247
218k
  if (scnhdr_int->s_paddr > 0
248
218k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
249
173k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
250
173k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
251
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
252
     coff_set_alignment_hook stores s_paddr in virt_size, which
253
     only works if it correctly holds the virtual size of the
254
     section.  */
255
75.8k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
256
218k
#endif
257
218k
}
258
259
static bool
260
pe_mkobject (bfd *abfd)
261
1.53M
{
262
  /* Some x86 code followed by an ascii string.  */
263
1.53M
  static const char default_dos_message[64] = {
264
1.53M
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
265
1.53M
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
266
1.53M
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
267
1.53M
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
268
1.53M
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
269
1.53M
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
270
1.53M
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
271
1.53M
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
272
273
1.53M
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
274
1.53M
  abfd->tdata.pe_obj_data = pe;
275
1.53M
  if (pe == NULL)
276
0
    return false;
277
278
1.53M
  pe->coff.pe = 1;
279
280
  /* in_reloc_p is architecture dependent.  */
281
1.53M
  pe->in_reloc_p = in_reloc_p;
282
283
1.53M
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
284
285
1.53M
  bfd_coff_long_section_names (abfd)
286
1.53M
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
287
288
1.53M
  return true;
289
1.53M
}
pei-i386.c:pe_mkobject
Line
Count
Source
261
138k
{
262
  /* Some x86 code followed by an ascii string.  */
263
138k
  static const char default_dos_message[64] = {
264
138k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
265
138k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
266
138k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
267
138k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
268
138k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
269
138k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
270
138k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
271
138k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
272
273
138k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
274
138k
  abfd->tdata.pe_obj_data = pe;
275
138k
  if (pe == NULL)
276
0
    return false;
277
278
138k
  pe->coff.pe = 1;
279
280
  /* in_reloc_p is architecture dependent.  */
281
138k
  pe->in_reloc_p = in_reloc_p;
282
283
138k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
284
285
138k
  bfd_coff_long_section_names (abfd)
286
138k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
287
288
138k
  return true;
289
138k
}
pe-x86_64.c:pe_mkobject
Line
Count
Source
261
213k
{
262
  /* Some x86 code followed by an ascii string.  */
263
213k
  static const char default_dos_message[64] = {
264
213k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
265
213k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
266
213k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
267
213k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
268
213k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
269
213k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
270
213k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
271
213k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
272
273
213k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
274
213k
  abfd->tdata.pe_obj_data = pe;
275
213k
  if (pe == NULL)
276
0
    return false;
277
278
213k
  pe->coff.pe = 1;
279
280
  /* in_reloc_p is architecture dependent.  */
281
213k
  pe->in_reloc_p = in_reloc_p;
282
283
213k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
284
285
213k
  bfd_coff_long_section_names (abfd)
286
213k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
287
288
213k
  return true;
289
213k
}
pei-x86_64.c:pe_mkobject
Line
Count
Source
261
130k
{
262
  /* Some x86 code followed by an ascii string.  */
263
130k
  static const char default_dos_message[64] = {
264
130k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
265
130k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
266
130k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
267
130k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
268
130k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
269
130k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
270
130k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
271
130k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
272
273
130k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
274
130k
  abfd->tdata.pe_obj_data = pe;
275
130k
  if (pe == NULL)
276
0
    return false;
277
278
130k
  pe->coff.pe = 1;
279
280
  /* in_reloc_p is architecture dependent.  */
281
130k
  pe->in_reloc_p = in_reloc_p;
282
283
130k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
284
285
130k
  bfd_coff_long_section_names (abfd)
286
130k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
287
288
130k
  return true;
289
130k
}
pe-aarch64.c:pe_mkobject
Line
Count
Source
261
60.7k
{
262
  /* Some x86 code followed by an ascii string.  */
263
60.7k
  static const char default_dos_message[64] = {
264
60.7k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
265
60.7k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
266
60.7k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
267
60.7k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
268
60.7k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
269
60.7k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
270
60.7k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
271
60.7k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
272
273
60.7k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
274
60.7k
  abfd->tdata.pe_obj_data = pe;
275
60.7k
  if (pe == NULL)
276
0
    return false;
277
278
60.7k
  pe->coff.pe = 1;
279
280
  /* in_reloc_p is architecture dependent.  */
281
60.7k
  pe->in_reloc_p = in_reloc_p;
282
283
60.7k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
284
285
60.7k
  bfd_coff_long_section_names (abfd)
286
60.7k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
287
288
60.7k
  return true;
289
60.7k
}
pei-aarch64.c:pe_mkobject
Line
Count
Source
261
95.2k
{
262
  /* Some x86 code followed by an ascii string.  */
263
95.2k
  static const char default_dos_message[64] = {
264
95.2k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
265
95.2k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
266
95.2k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
267
95.2k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
268
95.2k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
269
95.2k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
270
95.2k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
271
95.2k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
272
273
95.2k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
274
95.2k
  abfd->tdata.pe_obj_data = pe;
275
95.2k
  if (pe == NULL)
276
0
    return false;
277
278
95.2k
  pe->coff.pe = 1;
279
280
  /* in_reloc_p is architecture dependent.  */
281
95.2k
  pe->in_reloc_p = in_reloc_p;
282
283
95.2k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
284
285
95.2k
  bfd_coff_long_section_names (abfd)
286
95.2k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
287
288
95.2k
  return true;
289
95.2k
}
pei-ia64.c:pe_mkobject
Line
Count
Source
261
103k
{
262
  /* Some x86 code followed by an ascii string.  */
263
103k
  static const char default_dos_message[64] = {
264
103k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
265
103k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
266
103k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
267
103k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
268
103k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
269
103k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
270
103k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
271
103k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
272
273
103k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
274
103k
  abfd->tdata.pe_obj_data = pe;
275
103k
  if (pe == NULL)
276
0
    return false;
277
278
103k
  pe->coff.pe = 1;
279
280
  /* in_reloc_p is architecture dependent.  */
281
103k
  pe->in_reloc_p = in_reloc_p;
282
283
103k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
284
285
103k
  bfd_coff_long_section_names (abfd)
286
103k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
287
288
103k
  return true;
289
103k
}
pei-loongarch64.c:pe_mkobject
Line
Count
Source
261
87.8k
{
262
  /* Some x86 code followed by an ascii string.  */
263
87.8k
  static const char default_dos_message[64] = {
264
87.8k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
265
87.8k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
266
87.8k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
267
87.8k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
268
87.8k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
269
87.8k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
270
87.8k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
271
87.8k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
272
273
87.8k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
274
87.8k
  abfd->tdata.pe_obj_data = pe;
275
87.8k
  if (pe == NULL)
276
0
    return false;
277
278
87.8k
  pe->coff.pe = 1;
279
280
  /* in_reloc_p is architecture dependent.  */
281
87.8k
  pe->in_reloc_p = in_reloc_p;
282
283
87.8k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
284
285
87.8k
  bfd_coff_long_section_names (abfd)
286
87.8k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
287
288
87.8k
  return true;
289
87.8k
}
pei-riscv64.c:pe_mkobject
Line
Count
Source
261
84.0k
{
262
  /* Some x86 code followed by an ascii string.  */
263
84.0k
  static const char default_dos_message[64] = {
264
84.0k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
265
84.0k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
266
84.0k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
267
84.0k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
268
84.0k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
269
84.0k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
270
84.0k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
271
84.0k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
272
273
84.0k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
274
84.0k
  abfd->tdata.pe_obj_data = pe;
275
84.0k
  if (pe == NULL)
276
0
    return false;
277
278
84.0k
  pe->coff.pe = 1;
279
280
  /* in_reloc_p is architecture dependent.  */
281
84.0k
  pe->in_reloc_p = in_reloc_p;
282
283
84.0k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
284
285
84.0k
  bfd_coff_long_section_names (abfd)
286
84.0k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
287
288
84.0k
  return true;
289
84.0k
}
pe-arm-wince.c:pe_mkobject
Line
Count
Source
261
27.5k
{
262
  /* Some x86 code followed by an ascii string.  */
263
27.5k
  static const char default_dos_message[64] = {
264
27.5k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
265
27.5k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
266
27.5k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
267
27.5k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
268
27.5k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
269
27.5k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
270
27.5k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
271
27.5k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
272
273
27.5k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
274
27.5k
  abfd->tdata.pe_obj_data = pe;
275
27.5k
  if (pe == NULL)
276
0
    return false;
277
278
27.5k
  pe->coff.pe = 1;
279
280
  /* in_reloc_p is architecture dependent.  */
281
27.5k
  pe->in_reloc_p = in_reloc_p;
282
283
27.5k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
284
285
27.5k
  bfd_coff_long_section_names (abfd)
286
27.5k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
287
288
27.5k
  return true;
289
27.5k
}
pe-arm.c:pe_mkobject
Line
Count
Source
261
27.5k
{
262
  /* Some x86 code followed by an ascii string.  */
263
27.5k
  static const char default_dos_message[64] = {
264
27.5k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
265
27.5k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
266
27.5k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
267
27.5k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
268
27.5k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
269
27.5k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
270
27.5k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
271
27.5k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
272
273
27.5k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
274
27.5k
  abfd->tdata.pe_obj_data = pe;
275
27.5k
  if (pe == NULL)
276
0
    return false;
277
278
27.5k
  pe->coff.pe = 1;
279
280
  /* in_reloc_p is architecture dependent.  */
281
27.5k
  pe->in_reloc_p = in_reloc_p;
282
283
27.5k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
284
285
27.5k
  bfd_coff_long_section_names (abfd)
286
27.5k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
287
288
27.5k
  return true;
289
27.5k
}
pe-i386.c:pe_mkobject
Line
Count
Source
261
69.2k
{
262
  /* Some x86 code followed by an ascii string.  */
263
69.2k
  static const char default_dos_message[64] = {
264
69.2k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
265
69.2k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
266
69.2k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
267
69.2k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
268
69.2k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
269
69.2k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
270
69.2k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
271
69.2k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
272
273
69.2k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
274
69.2k
  abfd->tdata.pe_obj_data = pe;
275
69.2k
  if (pe == NULL)
276
0
    return false;
277
278
69.2k
  pe->coff.pe = 1;
279
280
  /* in_reloc_p is architecture dependent.  */
281
69.2k
  pe->in_reloc_p = in_reloc_p;
282
283
69.2k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
284
285
69.2k
  bfd_coff_long_section_names (abfd)
286
69.2k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
287
288
69.2k
  return true;
289
69.2k
}
pe-mcore.c:pe_mkobject
Line
Count
Source
261
62.8k
{
262
  /* Some x86 code followed by an ascii string.  */
263
62.8k
  static const char default_dos_message[64] = {
264
62.8k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
265
62.8k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
266
62.8k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
267
62.8k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
268
62.8k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
269
62.8k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
270
62.8k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
271
62.8k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
272
273
62.8k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
274
62.8k
  abfd->tdata.pe_obj_data = pe;
275
62.8k
  if (pe == NULL)
276
0
    return false;
277
278
62.8k
  pe->coff.pe = 1;
279
280
  /* in_reloc_p is architecture dependent.  */
281
62.8k
  pe->in_reloc_p = in_reloc_p;
282
283
62.8k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
284
285
62.8k
  bfd_coff_long_section_names (abfd)
286
62.8k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
287
288
62.8k
  return true;
289
62.8k
}
pe-sh.c:pe_mkobject
Line
Count
Source
261
49.7k
{
262
  /* Some x86 code followed by an ascii string.  */
263
49.7k
  static const char default_dos_message[64] = {
264
49.7k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
265
49.7k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
266
49.7k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
267
49.7k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
268
49.7k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
269
49.7k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
270
49.7k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
271
49.7k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
272
273
49.7k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
274
49.7k
  abfd->tdata.pe_obj_data = pe;
275
49.7k
  if (pe == NULL)
276
0
    return false;
277
278
49.7k
  pe->coff.pe = 1;
279
280
  /* in_reloc_p is architecture dependent.  */
281
49.7k
  pe->in_reloc_p = in_reloc_p;
282
283
49.7k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
284
285
49.7k
  bfd_coff_long_section_names (abfd)
286
49.7k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
287
288
49.7k
  return true;
289
49.7k
}
pei-arm-wince.c:pe_mkobject
Line
Count
Source
261
90.1k
{
262
  /* Some x86 code followed by an ascii string.  */
263
90.1k
  static const char default_dos_message[64] = {
264
90.1k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
265
90.1k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
266
90.1k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
267
90.1k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
268
90.1k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
269
90.1k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
270
90.1k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
271
90.1k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
272
273
90.1k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
274
90.1k
  abfd->tdata.pe_obj_data = pe;
275
90.1k
  if (pe == NULL)
276
0
    return false;
277
278
90.1k
  pe->coff.pe = 1;
279
280
  /* in_reloc_p is architecture dependent.  */
281
90.1k
  pe->in_reloc_p = in_reloc_p;
282
283
90.1k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
284
285
90.1k
  bfd_coff_long_section_names (abfd)
286
90.1k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
287
288
90.1k
  return true;
289
90.1k
}
pei-arm.c:pe_mkobject
Line
Count
Source
261
129k
{
262
  /* Some x86 code followed by an ascii string.  */
263
129k
  static const char default_dos_message[64] = {
264
129k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
265
129k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
266
129k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
267
129k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
268
129k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
269
129k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
270
129k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
271
129k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
272
273
129k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
274
129k
  abfd->tdata.pe_obj_data = pe;
275
129k
  if (pe == NULL)
276
0
    return false;
277
278
129k
  pe->coff.pe = 1;
279
280
  /* in_reloc_p is architecture dependent.  */
281
129k
  pe->in_reloc_p = in_reloc_p;
282
283
129k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
284
285
129k
  bfd_coff_long_section_names (abfd)
286
129k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
287
288
129k
  return true;
289
129k
}
pei-mcore.c:pe_mkobject
Line
Count
Source
261
76.9k
{
262
  /* Some x86 code followed by an ascii string.  */
263
76.9k
  static const char default_dos_message[64] = {
264
76.9k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
265
76.9k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
266
76.9k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
267
76.9k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
268
76.9k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
269
76.9k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
270
76.9k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
271
76.9k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
272
273
76.9k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
274
76.9k
  abfd->tdata.pe_obj_data = pe;
275
76.9k
  if (pe == NULL)
276
0
    return false;
277
278
76.9k
  pe->coff.pe = 1;
279
280
  /* in_reloc_p is architecture dependent.  */
281
76.9k
  pe->in_reloc_p = in_reloc_p;
282
283
76.9k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
284
285
76.9k
  bfd_coff_long_section_names (abfd)
286
76.9k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
287
288
76.9k
  return true;
289
76.9k
}
pei-sh.c:pe_mkobject
Line
Count
Source
261
86.3k
{
262
  /* Some x86 code followed by an ascii string.  */
263
86.3k
  static const char default_dos_message[64] = {
264
86.3k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
265
86.3k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
266
86.3k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
267
86.3k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
268
86.3k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
269
86.3k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
270
86.3k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
271
86.3k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
272
273
86.3k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
274
86.3k
  abfd->tdata.pe_obj_data = pe;
275
86.3k
  if (pe == NULL)
276
0
    return false;
277
278
86.3k
  pe->coff.pe = 1;
279
280
  /* in_reloc_p is architecture dependent.  */
281
86.3k
  pe->in_reloc_p = in_reloc_p;
282
283
86.3k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
284
285
86.3k
  bfd_coff_long_section_names (abfd)
286
86.3k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
287
288
86.3k
  return true;
289
86.3k
}
290
291
/* Create the COFF backend specific information.  */
292
293
static void *
294
pe_mkobject_hook (bfd *abfd,
295
      void *filehdr,
296
      void *aouthdr ATTRIBUTE_UNUSED)
297
1.53M
{
298
1.53M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
299
1.53M
  pe_data_type *pe;
300
301
1.53M
  if (! pe_mkobject (abfd))
302
0
    return NULL;
303
304
1.53M
  pe = pe_data (abfd);
305
1.53M
  pe->coff.sym_filepos = internal_f->f_symptr;
306
  /* These members communicate important constants about the symbol
307
     table to GDB's symbol-reading code.  These `constants'
308
     unfortunately vary among coff implementations...  */
309
1.53M
  pe->coff.local_n_btmask = N_BTMASK;
310
1.53M
  pe->coff.local_n_btshft = N_BTSHFT;
311
1.53M
  pe->coff.local_n_tmask = N_TMASK;
312
1.53M
  pe->coff.local_n_tshift = N_TSHIFT;
313
1.53M
  pe->coff.local_symesz = SYMESZ;
314
1.53M
  pe->coff.local_auxesz = AUXESZ;
315
1.53M
  pe->coff.local_linesz = LINESZ;
316
317
1.53M
  pe->coff.timestamp = internal_f->f_timdat;
318
319
1.53M
  obj_raw_syment_count (abfd) =
320
1.53M
    obj_conv_table_size (abfd) =
321
1.53M
      internal_f->f_nsyms;
322
323
1.53M
  pe->real_flags = internal_f->f_flags;
324
325
1.53M
  if ((internal_f->f_flags & F_DLL) != 0)
326
541k
    pe->dll = 1;
327
328
1.53M
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
329
1.04M
    abfd->flags |= HAS_DEBUG;
330
331
#ifdef COFF_IMAGE_WITH_PE
332
1.02M
  if (aouthdr)
333
546k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
334
#endif
335
336
#ifdef ARM
337
274k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
338
0
    coff_data (abfd) ->flags = 0;
339
#endif
340
341
1.53M
  memcpy (pe->dos_message, internal_f->pe.dos_message,
342
1.53M
    sizeof (pe->dos_message));
343
344
1.53M
  return (void *) pe;
345
1.53M
}
pei-i386.c:pe_mkobject_hook
Line
Count
Source
297
138k
{
298
138k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
299
138k
  pe_data_type *pe;
300
301
138k
  if (! pe_mkobject (abfd))
302
0
    return NULL;
303
304
138k
  pe = pe_data (abfd);
305
138k
  pe->coff.sym_filepos = internal_f->f_symptr;
306
  /* These members communicate important constants about the symbol
307
     table to GDB's symbol-reading code.  These `constants'
308
     unfortunately vary among coff implementations...  */
309
138k
  pe->coff.local_n_btmask = N_BTMASK;
310
138k
  pe->coff.local_n_btshft = N_BTSHFT;
311
138k
  pe->coff.local_n_tmask = N_TMASK;
312
138k
  pe->coff.local_n_tshift = N_TSHIFT;
313
138k
  pe->coff.local_symesz = SYMESZ;
314
138k
  pe->coff.local_auxesz = AUXESZ;
315
138k
  pe->coff.local_linesz = LINESZ;
316
317
138k
  pe->coff.timestamp = internal_f->f_timdat;
318
319
138k
  obj_raw_syment_count (abfd) =
320
138k
    obj_conv_table_size (abfd) =
321
138k
      internal_f->f_nsyms;
322
323
138k
  pe->real_flags = internal_f->f_flags;
324
325
138k
  if ((internal_f->f_flags & F_DLL) != 0)
326
41.0k
    pe->dll = 1;
327
328
138k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
329
116k
    abfd->flags |= HAS_DEBUG;
330
331
138k
#ifdef COFF_IMAGE_WITH_PE
332
138k
  if (aouthdr)
333
91.6k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
334
138k
#endif
335
336
#ifdef ARM
337
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
338
    coff_data (abfd) ->flags = 0;
339
#endif
340
341
138k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
342
138k
    sizeof (pe->dos_message));
343
344
138k
  return (void *) pe;
345
138k
}
pe-x86_64.c:pe_mkobject_hook
Line
Count
Source
297
213k
{
298
213k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
299
213k
  pe_data_type *pe;
300
301
213k
  if (! pe_mkobject (abfd))
302
0
    return NULL;
303
304
213k
  pe = pe_data (abfd);
305
213k
  pe->coff.sym_filepos = internal_f->f_symptr;
306
  /* These members communicate important constants about the symbol
307
     table to GDB's symbol-reading code.  These `constants'
308
     unfortunately vary among coff implementations...  */
309
213k
  pe->coff.local_n_btmask = N_BTMASK;
310
213k
  pe->coff.local_n_btshft = N_BTSHFT;
311
213k
  pe->coff.local_n_tmask = N_TMASK;
312
213k
  pe->coff.local_n_tshift = N_TSHIFT;
313
213k
  pe->coff.local_symesz = SYMESZ;
314
213k
  pe->coff.local_auxesz = AUXESZ;
315
213k
  pe->coff.local_linesz = LINESZ;
316
317
213k
  pe->coff.timestamp = internal_f->f_timdat;
318
319
213k
  obj_raw_syment_count (abfd) =
320
213k
    obj_conv_table_size (abfd) =
321
213k
      internal_f->f_nsyms;
322
323
213k
  pe->real_flags = internal_f->f_flags;
324
325
213k
  if ((internal_f->f_flags & F_DLL) != 0)
326
63.0k
    pe->dll = 1;
327
328
213k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
329
134k
    abfd->flags |= HAS_DEBUG;
330
331
#ifdef COFF_IMAGE_WITH_PE
332
  if (aouthdr)
333
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
334
#endif
335
336
#ifdef ARM
337
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
338
    coff_data (abfd) ->flags = 0;
339
#endif
340
341
213k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
342
213k
    sizeof (pe->dos_message));
343
344
213k
  return (void *) pe;
345
213k
}
pei-x86_64.c:pe_mkobject_hook
Line
Count
Source
297
130k
{
298
130k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
299
130k
  pe_data_type *pe;
300
301
130k
  if (! pe_mkobject (abfd))
302
0
    return NULL;
303
304
130k
  pe = pe_data (abfd);
305
130k
  pe->coff.sym_filepos = internal_f->f_symptr;
306
  /* These members communicate important constants about the symbol
307
     table to GDB's symbol-reading code.  These `constants'
308
     unfortunately vary among coff implementations...  */
309
130k
  pe->coff.local_n_btmask = N_BTMASK;
310
130k
  pe->coff.local_n_btshft = N_BTSHFT;
311
130k
  pe->coff.local_n_tmask = N_TMASK;
312
130k
  pe->coff.local_n_tshift = N_TSHIFT;
313
130k
  pe->coff.local_symesz = SYMESZ;
314
130k
  pe->coff.local_auxesz = AUXESZ;
315
130k
  pe->coff.local_linesz = LINESZ;
316
317
130k
  pe->coff.timestamp = internal_f->f_timdat;
318
319
130k
  obj_raw_syment_count (abfd) =
320
130k
    obj_conv_table_size (abfd) =
321
130k
      internal_f->f_nsyms;
322
323
130k
  pe->real_flags = internal_f->f_flags;
324
325
130k
  if ((internal_f->f_flags & F_DLL) != 0)
326
36.4k
    pe->dll = 1;
327
328
130k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
329
92.7k
    abfd->flags |= HAS_DEBUG;
330
331
130k
#ifdef COFF_IMAGE_WITH_PE
332
130k
  if (aouthdr)
333
75.6k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
334
130k
#endif
335
336
#ifdef ARM
337
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
338
    coff_data (abfd) ->flags = 0;
339
#endif
340
341
130k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
342
130k
    sizeof (pe->dos_message));
343
344
130k
  return (void *) pe;
345
130k
}
pe-aarch64.c:pe_mkobject_hook
Line
Count
Source
297
60.7k
{
298
60.7k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
299
60.7k
  pe_data_type *pe;
300
301
60.7k
  if (! pe_mkobject (abfd))
302
0
    return NULL;
303
304
60.7k
  pe = pe_data (abfd);
305
60.7k
  pe->coff.sym_filepos = internal_f->f_symptr;
306
  /* These members communicate important constants about the symbol
307
     table to GDB's symbol-reading code.  These `constants'
308
     unfortunately vary among coff implementations...  */
309
60.7k
  pe->coff.local_n_btmask = N_BTMASK;
310
60.7k
  pe->coff.local_n_btshft = N_BTSHFT;
311
60.7k
  pe->coff.local_n_tmask = N_TMASK;
312
60.7k
  pe->coff.local_n_tshift = N_TSHIFT;
313
60.7k
  pe->coff.local_symesz = SYMESZ;
314
60.7k
  pe->coff.local_auxesz = AUXESZ;
315
60.7k
  pe->coff.local_linesz = LINESZ;
316
317
60.7k
  pe->coff.timestamp = internal_f->f_timdat;
318
319
60.7k
  obj_raw_syment_count (abfd) =
320
60.7k
    obj_conv_table_size (abfd) =
321
60.7k
      internal_f->f_nsyms;
322
323
60.7k
  pe->real_flags = internal_f->f_flags;
324
325
60.7k
  if ((internal_f->f_flags & F_DLL) != 0)
326
15.6k
    pe->dll = 1;
327
328
60.7k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
329
44.6k
    abfd->flags |= HAS_DEBUG;
330
331
#ifdef COFF_IMAGE_WITH_PE
332
  if (aouthdr)
333
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
334
#endif
335
336
#ifdef ARM
337
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
338
    coff_data (abfd) ->flags = 0;
339
#endif
340
341
60.7k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
342
60.7k
    sizeof (pe->dos_message));
343
344
60.7k
  return (void *) pe;
345
60.7k
}
pei-aarch64.c:pe_mkobject_hook
Line
Count
Source
297
95.1k
{
298
95.1k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
299
95.1k
  pe_data_type *pe;
300
301
95.1k
  if (! pe_mkobject (abfd))
302
0
    return NULL;
303
304
95.1k
  pe = pe_data (abfd);
305
95.1k
  pe->coff.sym_filepos = internal_f->f_symptr;
306
  /* These members communicate important constants about the symbol
307
     table to GDB's symbol-reading code.  These `constants'
308
     unfortunately vary among coff implementations...  */
309
95.1k
  pe->coff.local_n_btmask = N_BTMASK;
310
95.1k
  pe->coff.local_n_btshft = N_BTSHFT;
311
95.1k
  pe->coff.local_n_tmask = N_TMASK;
312
95.1k
  pe->coff.local_n_tshift = N_TSHIFT;
313
95.1k
  pe->coff.local_symesz = SYMESZ;
314
95.1k
  pe->coff.local_auxesz = AUXESZ;
315
95.1k
  pe->coff.local_linesz = LINESZ;
316
317
95.1k
  pe->coff.timestamp = internal_f->f_timdat;
318
319
95.1k
  obj_raw_syment_count (abfd) =
320
95.1k
    obj_conv_table_size (abfd) =
321
95.1k
      internal_f->f_nsyms;
322
323
95.1k
  pe->real_flags = internal_f->f_flags;
324
325
95.1k
  if ((internal_f->f_flags & F_DLL) != 0)
326
32.1k
    pe->dll = 1;
327
328
95.1k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
329
72.2k
    abfd->flags |= HAS_DEBUG;
330
331
95.1k
#ifdef COFF_IMAGE_WITH_PE
332
95.1k
  if (aouthdr)
333
60.6k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
334
95.1k
#endif
335
336
#ifdef ARM
337
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
338
    coff_data (abfd) ->flags = 0;
339
#endif
340
341
95.1k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
342
95.1k
    sizeof (pe->dos_message));
343
344
95.1k
  return (void *) pe;
345
95.1k
}
pei-ia64.c:pe_mkobject_hook
Line
Count
Source
297
103k
{
298
103k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
299
103k
  pe_data_type *pe;
300
301
103k
  if (! pe_mkobject (abfd))
302
0
    return NULL;
303
304
103k
  pe = pe_data (abfd);
305
103k
  pe->coff.sym_filepos = internal_f->f_symptr;
306
  /* These members communicate important constants about the symbol
307
     table to GDB's symbol-reading code.  These `constants'
308
     unfortunately vary among coff implementations...  */
309
103k
  pe->coff.local_n_btmask = N_BTMASK;
310
103k
  pe->coff.local_n_btshft = N_BTSHFT;
311
103k
  pe->coff.local_n_tmask = N_TMASK;
312
103k
  pe->coff.local_n_tshift = N_TSHIFT;
313
103k
  pe->coff.local_symesz = SYMESZ;
314
103k
  pe->coff.local_auxesz = AUXESZ;
315
103k
  pe->coff.local_linesz = LINESZ;
316
317
103k
  pe->coff.timestamp = internal_f->f_timdat;
318
319
103k
  obj_raw_syment_count (abfd) =
320
103k
    obj_conv_table_size (abfd) =
321
103k
      internal_f->f_nsyms;
322
323
103k
  pe->real_flags = internal_f->f_flags;
324
325
103k
  if ((internal_f->f_flags & F_DLL) != 0)
326
59.3k
    pe->dll = 1;
327
328
103k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
329
52.0k
    abfd->flags |= HAS_DEBUG;
330
331
103k
#ifdef COFF_IMAGE_WITH_PE
332
103k
  if (aouthdr)
333
60.1k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
334
103k
#endif
335
336
#ifdef ARM
337
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
338
    coff_data (abfd) ->flags = 0;
339
#endif
340
341
103k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
342
103k
    sizeof (pe->dos_message));
343
344
103k
  return (void *) pe;
345
103k
}
pei-loongarch64.c:pe_mkobject_hook
Line
Count
Source
297
87.8k
{
298
87.8k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
299
87.8k
  pe_data_type *pe;
300
301
87.8k
  if (! pe_mkobject (abfd))
302
0
    return NULL;
303
304
87.8k
  pe = pe_data (abfd);
305
87.8k
  pe->coff.sym_filepos = internal_f->f_symptr;
306
  /* These members communicate important constants about the symbol
307
     table to GDB's symbol-reading code.  These `constants'
308
     unfortunately vary among coff implementations...  */
309
87.8k
  pe->coff.local_n_btmask = N_BTMASK;
310
87.8k
  pe->coff.local_n_btshft = N_BTSHFT;
311
87.8k
  pe->coff.local_n_tmask = N_TMASK;
312
87.8k
  pe->coff.local_n_tshift = N_TSHIFT;
313
87.8k
  pe->coff.local_symesz = SYMESZ;
314
87.8k
  pe->coff.local_auxesz = AUXESZ;
315
87.8k
  pe->coff.local_linesz = LINESZ;
316
317
87.8k
  pe->coff.timestamp = internal_f->f_timdat;
318
319
87.8k
  obj_raw_syment_count (abfd) =
320
87.8k
    obj_conv_table_size (abfd) =
321
87.8k
      internal_f->f_nsyms;
322
323
87.8k
  pe->real_flags = internal_f->f_flags;
324
325
87.8k
  if ((internal_f->f_flags & F_DLL) != 0)
326
18.4k
    pe->dll = 1;
327
328
87.8k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
329
68.1k
    abfd->flags |= HAS_DEBUG;
330
331
87.8k
#ifdef COFF_IMAGE_WITH_PE
332
87.8k
  if (aouthdr)
333
41.0k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
334
87.8k
#endif
335
336
#ifdef ARM
337
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
338
    coff_data (abfd) ->flags = 0;
339
#endif
340
341
87.8k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
342
87.8k
    sizeof (pe->dos_message));
343
344
87.8k
  return (void *) pe;
345
87.8k
}
pei-riscv64.c:pe_mkobject_hook
Line
Count
Source
297
84.0k
{
298
84.0k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
299
84.0k
  pe_data_type *pe;
300
301
84.0k
  if (! pe_mkobject (abfd))
302
0
    return NULL;
303
304
84.0k
  pe = pe_data (abfd);
305
84.0k
  pe->coff.sym_filepos = internal_f->f_symptr;
306
  /* These members communicate important constants about the symbol
307
     table to GDB's symbol-reading code.  These `constants'
308
     unfortunately vary among coff implementations...  */
309
84.0k
  pe->coff.local_n_btmask = N_BTMASK;
310
84.0k
  pe->coff.local_n_btshft = N_BTSHFT;
311
84.0k
  pe->coff.local_n_tmask = N_TMASK;
312
84.0k
  pe->coff.local_n_tshift = N_TSHIFT;
313
84.0k
  pe->coff.local_symesz = SYMESZ;
314
84.0k
  pe->coff.local_auxesz = AUXESZ;
315
84.0k
  pe->coff.local_linesz = LINESZ;
316
317
84.0k
  pe->coff.timestamp = internal_f->f_timdat;
318
319
84.0k
  obj_raw_syment_count (abfd) =
320
84.0k
    obj_conv_table_size (abfd) =
321
84.0k
      internal_f->f_nsyms;
322
323
84.0k
  pe->real_flags = internal_f->f_flags;
324
325
84.0k
  if ((internal_f->f_flags & F_DLL) != 0)
326
32.5k
    pe->dll = 1;
327
328
84.0k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
329
56.9k
    abfd->flags |= HAS_DEBUG;
330
331
84.0k
#ifdef COFF_IMAGE_WITH_PE
332
84.0k
  if (aouthdr)
333
53.4k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
334
84.0k
#endif
335
336
#ifdef ARM
337
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
338
    coff_data (abfd) ->flags = 0;
339
#endif
340
341
84.0k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
342
84.0k
    sizeof (pe->dos_message));
343
344
84.0k
  return (void *) pe;
345
84.0k
}
pe-arm-wince.c:pe_mkobject_hook
Line
Count
Source
297
27.5k
{
298
27.5k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
299
27.5k
  pe_data_type *pe;
300
301
27.5k
  if (! pe_mkobject (abfd))
302
0
    return NULL;
303
304
27.5k
  pe = pe_data (abfd);
305
27.5k
  pe->coff.sym_filepos = internal_f->f_symptr;
306
  /* These members communicate important constants about the symbol
307
     table to GDB's symbol-reading code.  These `constants'
308
     unfortunately vary among coff implementations...  */
309
27.5k
  pe->coff.local_n_btmask = N_BTMASK;
310
27.5k
  pe->coff.local_n_btshft = N_BTSHFT;
311
27.5k
  pe->coff.local_n_tmask = N_TMASK;
312
27.5k
  pe->coff.local_n_tshift = N_TSHIFT;
313
27.5k
  pe->coff.local_symesz = SYMESZ;
314
27.5k
  pe->coff.local_auxesz = AUXESZ;
315
27.5k
  pe->coff.local_linesz = LINESZ;
316
317
27.5k
  pe->coff.timestamp = internal_f->f_timdat;
318
319
27.5k
  obj_raw_syment_count (abfd) =
320
27.5k
    obj_conv_table_size (abfd) =
321
27.5k
      internal_f->f_nsyms;
322
323
27.5k
  pe->real_flags = internal_f->f_flags;
324
325
27.5k
  if ((internal_f->f_flags & F_DLL) != 0)
326
8.02k
    pe->dll = 1;
327
328
27.5k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
329
18.5k
    abfd->flags |= HAS_DEBUG;
330
331
#ifdef COFF_IMAGE_WITH_PE
332
  if (aouthdr)
333
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
334
#endif
335
336
27.5k
#ifdef ARM
337
27.5k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
338
0
    coff_data (abfd) ->flags = 0;
339
27.5k
#endif
340
341
27.5k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
342
27.5k
    sizeof (pe->dos_message));
343
344
27.5k
  return (void *) pe;
345
27.5k
}
pe-arm.c:pe_mkobject_hook
Line
Count
Source
297
27.5k
{
298
27.5k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
299
27.5k
  pe_data_type *pe;
300
301
27.5k
  if (! pe_mkobject (abfd))
302
0
    return NULL;
303
304
27.5k
  pe = pe_data (abfd);
305
27.5k
  pe->coff.sym_filepos = internal_f->f_symptr;
306
  /* These members communicate important constants about the symbol
307
     table to GDB's symbol-reading code.  These `constants'
308
     unfortunately vary among coff implementations...  */
309
27.5k
  pe->coff.local_n_btmask = N_BTMASK;
310
27.5k
  pe->coff.local_n_btshft = N_BTSHFT;
311
27.5k
  pe->coff.local_n_tmask = N_TMASK;
312
27.5k
  pe->coff.local_n_tshift = N_TSHIFT;
313
27.5k
  pe->coff.local_symesz = SYMESZ;
314
27.5k
  pe->coff.local_auxesz = AUXESZ;
315
27.5k
  pe->coff.local_linesz = LINESZ;
316
317
27.5k
  pe->coff.timestamp = internal_f->f_timdat;
318
319
27.5k
  obj_raw_syment_count (abfd) =
320
27.5k
    obj_conv_table_size (abfd) =
321
27.5k
      internal_f->f_nsyms;
322
323
27.5k
  pe->real_flags = internal_f->f_flags;
324
325
27.5k
  if ((internal_f->f_flags & F_DLL) != 0)
326
8.02k
    pe->dll = 1;
327
328
27.5k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
329
18.5k
    abfd->flags |= HAS_DEBUG;
330
331
#ifdef COFF_IMAGE_WITH_PE
332
  if (aouthdr)
333
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
334
#endif
335
336
27.5k
#ifdef ARM
337
27.5k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
338
0
    coff_data (abfd) ->flags = 0;
339
27.5k
#endif
340
341
27.5k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
342
27.5k
    sizeof (pe->dos_message));
343
344
27.5k
  return (void *) pe;
345
27.5k
}
pe-i386.c:pe_mkobject_hook
Line
Count
Source
297
69.2k
{
298
69.2k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
299
69.2k
  pe_data_type *pe;
300
301
69.2k
  if (! pe_mkobject (abfd))
302
0
    return NULL;
303
304
69.2k
  pe = pe_data (abfd);
305
69.2k
  pe->coff.sym_filepos = internal_f->f_symptr;
306
  /* These members communicate important constants about the symbol
307
     table to GDB's symbol-reading code.  These `constants'
308
     unfortunately vary among coff implementations...  */
309
69.2k
  pe->coff.local_n_btmask = N_BTMASK;
310
69.2k
  pe->coff.local_n_btshft = N_BTSHFT;
311
69.2k
  pe->coff.local_n_tmask = N_TMASK;
312
69.2k
  pe->coff.local_n_tshift = N_TSHIFT;
313
69.2k
  pe->coff.local_symesz = SYMESZ;
314
69.2k
  pe->coff.local_auxesz = AUXESZ;
315
69.2k
  pe->coff.local_linesz = LINESZ;
316
317
69.2k
  pe->coff.timestamp = internal_f->f_timdat;
318
319
69.2k
  obj_raw_syment_count (abfd) =
320
69.2k
    obj_conv_table_size (abfd) =
321
69.2k
      internal_f->f_nsyms;
322
323
69.2k
  pe->real_flags = internal_f->f_flags;
324
325
69.2k
  if ((internal_f->f_flags & F_DLL) != 0)
326
31.3k
    pe->dll = 1;
327
328
69.2k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
329
54.0k
    abfd->flags |= HAS_DEBUG;
330
331
#ifdef COFF_IMAGE_WITH_PE
332
  if (aouthdr)
333
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
334
#endif
335
336
#ifdef ARM
337
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
338
    coff_data (abfd) ->flags = 0;
339
#endif
340
341
69.2k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
342
69.2k
    sizeof (pe->dos_message));
343
344
69.2k
  return (void *) pe;
345
69.2k
}
pe-mcore.c:pe_mkobject_hook
Line
Count
Source
297
62.7k
{
298
62.7k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
299
62.7k
  pe_data_type *pe;
300
301
62.7k
  if (! pe_mkobject (abfd))
302
0
    return NULL;
303
304
62.7k
  pe = pe_data (abfd);
305
62.7k
  pe->coff.sym_filepos = internal_f->f_symptr;
306
  /* These members communicate important constants about the symbol
307
     table to GDB's symbol-reading code.  These `constants'
308
     unfortunately vary among coff implementations...  */
309
62.7k
  pe->coff.local_n_btmask = N_BTMASK;
310
62.7k
  pe->coff.local_n_btshft = N_BTSHFT;
311
62.7k
  pe->coff.local_n_tmask = N_TMASK;
312
62.7k
  pe->coff.local_n_tshift = N_TSHIFT;
313
62.7k
  pe->coff.local_symesz = SYMESZ;
314
62.7k
  pe->coff.local_auxesz = AUXESZ;
315
62.7k
  pe->coff.local_linesz = LINESZ;
316
317
62.7k
  pe->coff.timestamp = internal_f->f_timdat;
318
319
62.7k
  obj_raw_syment_count (abfd) =
320
62.7k
    obj_conv_table_size (abfd) =
321
62.7k
      internal_f->f_nsyms;
322
323
62.7k
  pe->real_flags = internal_f->f_flags;
324
325
62.7k
  if ((internal_f->f_flags & F_DLL) != 0)
326
17.7k
    pe->dll = 1;
327
328
62.7k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
329
46.9k
    abfd->flags |= HAS_DEBUG;
330
331
#ifdef COFF_IMAGE_WITH_PE
332
  if (aouthdr)
333
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
334
#endif
335
336
#ifdef ARM
337
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
338
    coff_data (abfd) ->flags = 0;
339
#endif
340
341
62.7k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
342
62.7k
    sizeof (pe->dos_message));
343
344
62.7k
  return (void *) pe;
345
62.7k
}
pe-sh.c:pe_mkobject_hook
Line
Count
Source
297
49.6k
{
298
49.6k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
299
49.6k
  pe_data_type *pe;
300
301
49.6k
  if (! pe_mkobject (abfd))
302
0
    return NULL;
303
304
49.6k
  pe = pe_data (abfd);
305
49.6k
  pe->coff.sym_filepos = internal_f->f_symptr;
306
  /* These members communicate important constants about the symbol
307
     table to GDB's symbol-reading code.  These `constants'
308
     unfortunately vary among coff implementations...  */
309
49.6k
  pe->coff.local_n_btmask = N_BTMASK;
310
49.6k
  pe->coff.local_n_btshft = N_BTSHFT;
311
49.6k
  pe->coff.local_n_tmask = N_TMASK;
312
49.6k
  pe->coff.local_n_tshift = N_TSHIFT;
313
49.6k
  pe->coff.local_symesz = SYMESZ;
314
49.6k
  pe->coff.local_auxesz = AUXESZ;
315
49.6k
  pe->coff.local_linesz = LINESZ;
316
317
49.6k
  pe->coff.timestamp = internal_f->f_timdat;
318
319
49.6k
  obj_raw_syment_count (abfd) =
320
49.6k
    obj_conv_table_size (abfd) =
321
49.6k
      internal_f->f_nsyms;
322
323
49.6k
  pe->real_flags = internal_f->f_flags;
324
325
49.6k
  if ((internal_f->f_flags & F_DLL) != 0)
326
21.9k
    pe->dll = 1;
327
328
49.6k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
329
36.7k
    abfd->flags |= HAS_DEBUG;
330
331
#ifdef COFF_IMAGE_WITH_PE
332
  if (aouthdr)
333
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
334
#endif
335
336
#ifdef ARM
337
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
338
    coff_data (abfd) ->flags = 0;
339
#endif
340
341
49.6k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
342
49.6k
    sizeof (pe->dos_message));
343
344
49.6k
  return (void *) pe;
345
49.6k
}
pei-arm-wince.c:pe_mkobject_hook
Line
Count
Source
297
90.0k
{
298
90.0k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
299
90.0k
  pe_data_type *pe;
300
301
90.0k
  if (! pe_mkobject (abfd))
302
0
    return NULL;
303
304
90.0k
  pe = pe_data (abfd);
305
90.0k
  pe->coff.sym_filepos = internal_f->f_symptr;
306
  /* These members communicate important constants about the symbol
307
     table to GDB's symbol-reading code.  These `constants'
308
     unfortunately vary among coff implementations...  */
309
90.0k
  pe->coff.local_n_btmask = N_BTMASK;
310
90.0k
  pe->coff.local_n_btshft = N_BTSHFT;
311
90.0k
  pe->coff.local_n_tmask = N_TMASK;
312
90.0k
  pe->coff.local_n_tshift = N_TSHIFT;
313
90.0k
  pe->coff.local_symesz = SYMESZ;
314
90.0k
  pe->coff.local_auxesz = AUXESZ;
315
90.0k
  pe->coff.local_linesz = LINESZ;
316
317
90.0k
  pe->coff.timestamp = internal_f->f_timdat;
318
319
90.0k
  obj_raw_syment_count (abfd) =
320
90.0k
    obj_conv_table_size (abfd) =
321
90.0k
      internal_f->f_nsyms;
322
323
90.0k
  pe->real_flags = internal_f->f_flags;
324
325
90.0k
  if ((internal_f->f_flags & F_DLL) != 0)
326
38.0k
    pe->dll = 1;
327
328
90.0k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
329
53.0k
    abfd->flags |= HAS_DEBUG;
330
331
90.0k
#ifdef COFF_IMAGE_WITH_PE
332
90.0k
  if (aouthdr)
333
23.9k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
334
90.0k
#endif
335
336
90.0k
#ifdef ARM
337
90.0k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
338
0
    coff_data (abfd) ->flags = 0;
339
90.0k
#endif
340
341
90.0k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
342
90.0k
    sizeof (pe->dos_message));
343
344
90.0k
  return (void *) pe;
345
90.0k
}
pei-arm.c:pe_mkobject_hook
Line
Count
Source
297
129k
{
298
129k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
299
129k
  pe_data_type *pe;
300
301
129k
  if (! pe_mkobject (abfd))
302
0
    return NULL;
303
304
129k
  pe = pe_data (abfd);
305
129k
  pe->coff.sym_filepos = internal_f->f_symptr;
306
  /* These members communicate important constants about the symbol
307
     table to GDB's symbol-reading code.  These `constants'
308
     unfortunately vary among coff implementations...  */
309
129k
  pe->coff.local_n_btmask = N_BTMASK;
310
129k
  pe->coff.local_n_btshft = N_BTSHFT;
311
129k
  pe->coff.local_n_tmask = N_TMASK;
312
129k
  pe->coff.local_n_tshift = N_TSHIFT;
313
129k
  pe->coff.local_symesz = SYMESZ;
314
129k
  pe->coff.local_auxesz = AUXESZ;
315
129k
  pe->coff.local_linesz = LINESZ;
316
317
129k
  pe->coff.timestamp = internal_f->f_timdat;
318
319
129k
  obj_raw_syment_count (abfd) =
320
129k
    obj_conv_table_size (abfd) =
321
129k
      internal_f->f_nsyms;
322
323
129k
  pe->real_flags = internal_f->f_flags;
324
325
129k
  if ((internal_f->f_flags & F_DLL) != 0)
326
48.6k
    pe->dll = 1;
327
328
129k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
329
83.2k
    abfd->flags |= HAS_DEBUG;
330
331
129k
#ifdef COFF_IMAGE_WITH_PE
332
129k
  if (aouthdr)
333
50.0k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
334
129k
#endif
335
336
129k
#ifdef ARM
337
129k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
338
0
    coff_data (abfd) ->flags = 0;
339
129k
#endif
340
341
129k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
342
129k
    sizeof (pe->dos_message));
343
344
129k
  return (void *) pe;
345
129k
}
pei-mcore.c:pe_mkobject_hook
Line
Count
Source
297
76.9k
{
298
76.9k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
299
76.9k
  pe_data_type *pe;
300
301
76.9k
  if (! pe_mkobject (abfd))
302
0
    return NULL;
303
304
76.9k
  pe = pe_data (abfd);
305
76.9k
  pe->coff.sym_filepos = internal_f->f_symptr;
306
  /* These members communicate important constants about the symbol
307
     table to GDB's symbol-reading code.  These `constants'
308
     unfortunately vary among coff implementations...  */
309
76.9k
  pe->coff.local_n_btmask = N_BTMASK;
310
76.9k
  pe->coff.local_n_btshft = N_BTSHFT;
311
76.9k
  pe->coff.local_n_tmask = N_TMASK;
312
76.9k
  pe->coff.local_n_tshift = N_TSHIFT;
313
76.9k
  pe->coff.local_symesz = SYMESZ;
314
76.9k
  pe->coff.local_auxesz = AUXESZ;
315
76.9k
  pe->coff.local_linesz = LINESZ;
316
317
76.9k
  pe->coff.timestamp = internal_f->f_timdat;
318
319
76.9k
  obj_raw_syment_count (abfd) =
320
76.9k
    obj_conv_table_size (abfd) =
321
76.9k
      internal_f->f_nsyms;
322
323
76.9k
  pe->real_flags = internal_f->f_flags;
324
325
76.9k
  if ((internal_f->f_flags & F_DLL) != 0)
326
29.9k
    pe->dll = 1;
327
328
76.9k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
329
45.9k
    abfd->flags |= HAS_DEBUG;
330
331
76.9k
#ifdef COFF_IMAGE_WITH_PE
332
76.9k
  if (aouthdr)
333
45.6k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
334
76.9k
#endif
335
336
#ifdef ARM
337
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
338
    coff_data (abfd) ->flags = 0;
339
#endif
340
341
76.9k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
342
76.9k
    sizeof (pe->dos_message));
343
344
76.9k
  return (void *) pe;
345
76.9k
}
pei-sh.c:pe_mkobject_hook
Line
Count
Source
297
86.2k
{
298
86.2k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
299
86.2k
  pe_data_type *pe;
300
301
86.2k
  if (! pe_mkobject (abfd))
302
0
    return NULL;
303
304
86.2k
  pe = pe_data (abfd);
305
86.2k
  pe->coff.sym_filepos = internal_f->f_symptr;
306
  /* These members communicate important constants about the symbol
307
     table to GDB's symbol-reading code.  These `constants'
308
     unfortunately vary among coff implementations...  */
309
86.2k
  pe->coff.local_n_btmask = N_BTMASK;
310
86.2k
  pe->coff.local_n_btshft = N_BTSHFT;
311
86.2k
  pe->coff.local_n_tmask = N_TMASK;
312
86.2k
  pe->coff.local_n_tshift = N_TSHIFT;
313
86.2k
  pe->coff.local_symesz = SYMESZ;
314
86.2k
  pe->coff.local_auxesz = AUXESZ;
315
86.2k
  pe->coff.local_linesz = LINESZ;
316
317
86.2k
  pe->coff.timestamp = internal_f->f_timdat;
318
319
86.2k
  obj_raw_syment_count (abfd) =
320
86.2k
    obj_conv_table_size (abfd) =
321
86.2k
      internal_f->f_nsyms;
322
323
86.2k
  pe->real_flags = internal_f->f_flags;
324
325
86.2k
  if ((internal_f->f_flags & F_DLL) != 0)
326
39.4k
    pe->dll = 1;
327
328
86.2k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
329
51.7k
    abfd->flags |= HAS_DEBUG;
330
331
86.2k
#ifdef COFF_IMAGE_WITH_PE
332
86.2k
  if (aouthdr)
333
44.7k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
334
86.2k
#endif
335
336
#ifdef ARM
337
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
338
    coff_data (abfd) ->flags = 0;
339
#endif
340
341
86.2k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
342
86.2k
    sizeof (pe->dos_message));
343
344
86.2k
  return (void *) pe;
345
86.2k
}
346
347
static bool
348
pe_print_private_bfd_data (bfd *abfd, void *vfile)
349
6.52k
{
350
6.52k
  FILE *file = (FILE *) vfile;
351
352
6.52k
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
353
0
    return false;
354
355
6.52k
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
356
6.05k
    return true;
357
358
466
  fputc ('\n', file);
359
360
466
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
361
6.52k
}
pei-i386.c:pe_print_private_bfd_data
Line
Count
Source
349
499
{
350
499
  FILE *file = (FILE *) vfile;
351
352
499
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
353
0
    return false;
354
355
499
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
356
499
    return true;
357
358
0
  fputc ('\n', file);
359
360
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
361
499
}
pe-x86_64.c:pe_print_private_bfd_data
Line
Count
Source
349
686
{
350
686
  FILE *file = (FILE *) vfile;
351
352
686
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
353
0
    return false;
354
355
686
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
356
686
    return true;
357
358
0
  fputc ('\n', file);
359
360
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
361
686
}
pei-x86_64.c:pe_print_private_bfd_data
Line
Count
Source
349
742
{
350
742
  FILE *file = (FILE *) vfile;
351
352
742
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
353
0
    return false;
354
355
742
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
356
742
    return true;
357
358
0
  fputc ('\n', file);
359
360
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
361
742
}
pe-aarch64.c:pe_print_private_bfd_data
Line
Count
Source
349
562
{
350
562
  FILE *file = (FILE *) vfile;
351
352
562
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
353
0
    return false;
354
355
562
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
356
562
    return true;
357
358
0
  fputc ('\n', file);
359
360
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
361
562
}
pei-aarch64.c:pe_print_private_bfd_data
Line
Count
Source
349
1.53k
{
350
1.53k
  FILE *file = (FILE *) vfile;
351
352
1.53k
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
353
0
    return false;
354
355
1.53k
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
356
1.53k
    return true;
357
358
0
  fputc ('\n', file);
359
360
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
361
1.53k
}
pei-ia64.c:pe_print_private_bfd_data
Line
Count
Source
349
368
{
350
368
  FILE *file = (FILE *) vfile;
351
352
368
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
353
0
    return false;
354
355
368
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
356
368
    return true;
357
358
0
  fputc ('\n', file);
359
360
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
361
368
}
pei-loongarch64.c:pe_print_private_bfd_data
Line
Count
Source
349
357
{
350
357
  FILE *file = (FILE *) vfile;
351
352
357
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
353
0
    return false;
354
355
357
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
356
357
    return true;
357
358
0
  fputc ('\n', file);
359
360
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
361
357
}
pei-riscv64.c:pe_print_private_bfd_data
Line
Count
Source
349
359
{
350
359
  FILE *file = (FILE *) vfile;
351
352
359
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
353
0
    return false;
354
355
359
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
356
359
    return true;
357
358
0
  fputc ('\n', file);
359
360
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
361
359
}
Unexecuted instantiation: pe-arm-wince.c:pe_print_private_bfd_data
Unexecuted instantiation: pe-arm.c:pe_print_private_bfd_data
pe-i386.c:pe_print_private_bfd_data
Line
Count
Source
349
138
{
350
138
  FILE *file = (FILE *) vfile;
351
352
138
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
353
0
    return false;
354
355
138
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
356
138
    return true;
357
358
0
  fputc ('\n', file);
359
360
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
361
138
}
pe-mcore.c:pe_print_private_bfd_data
Line
Count
Source
349
260
{
350
260
  FILE *file = (FILE *) vfile;
351
352
260
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
353
0
    return false;
354
355
260
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
356
260
    return true;
357
358
0
  fputc ('\n', file);
359
360
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
361
260
}
pe-sh.c:pe_print_private_bfd_data
Line
Count
Source
349
224
{
350
224
  FILE *file = (FILE *) vfile;
351
352
224
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
353
0
    return false;
354
355
224
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
356
224
    return true;
357
358
0
  fputc ('\n', file);
359
360
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
361
224
}
pei-arm-wince.c:pe_print_private_bfd_data
Line
Count
Source
349
104
{
350
104
  FILE *file = (FILE *) vfile;
351
352
104
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
353
0
    return false;
354
355
104
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
356
0
    return true;
357
358
104
  fputc ('\n', file);
359
360
104
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
361
104
}
pei-arm.c:pe_print_private_bfd_data
Line
Count
Source
349
362
{
350
362
  FILE *file = (FILE *) vfile;
351
352
362
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
353
0
    return false;
354
355
362
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
356
0
    return true;
357
358
362
  fputc ('\n', file);
359
360
362
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
361
362
}
pei-mcore.c:pe_print_private_bfd_data
Line
Count
Source
349
129
{
350
129
  FILE *file = (FILE *) vfile;
351
352
129
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
353
0
    return false;
354
355
129
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
356
129
    return true;
357
358
0
  fputc ('\n', file);
359
360
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
361
129
}
pei-sh.c:pe_print_private_bfd_data
Line
Count
Source
349
192
{
350
192
  FILE *file = (FILE *) vfile;
351
352
192
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
353
0
    return false;
354
355
192
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
356
192
    return true;
357
358
0
  fputc ('\n', file);
359
360
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
361
192
}
362
363
/* Copy any private info we understand from the input bfd
364
   to the output bfd.  */
365
366
static bool
367
pe_bfd_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
368
30
{
369
  /* PR binutils/716: Copy the large address aware flag.
370
     XXX: Should we be copying other flags or other fields in the pe_data()
371
     structure ?  */
372
30
  if (pe_data (obfd) != NULL
373
30
      && pe_data (ibfd) != NULL
374
30
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
375
23
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
376
377
30
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
378
1
    return false;
379
380
29
  if (pe_saved_coff_bfd_copy_private_bfd_data)
381
1
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
382
383
28
  return true;
384
29
}
pei-i386.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
368
12
{
369
  /* PR binutils/716: Copy the large address aware flag.
370
     XXX: Should we be copying other flags or other fields in the pe_data()
371
     structure ?  */
372
12
  if (pe_data (obfd) != NULL
373
12
      && pe_data (ibfd) != NULL
374
12
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
375
8
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
376
377
12
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
378
1
    return false;
379
380
11
  if (pe_saved_coff_bfd_copy_private_bfd_data)
381
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
382
383
11
  return true;
384
11
}
Unexecuted instantiation: pe-x86_64.c:pe_bfd_copy_private_bfd_data
pei-x86_64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
368
8
{
369
  /* PR binutils/716: Copy the large address aware flag.
370
     XXX: Should we be copying other flags or other fields in the pe_data()
371
     structure ?  */
372
8
  if (pe_data (obfd) != NULL
373
8
      && pe_data (ibfd) != NULL
374
8
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
375
8
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
376
377
8
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
378
0
    return false;
379
380
8
  if (pe_saved_coff_bfd_copy_private_bfd_data)
381
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
382
383
8
  return true;
384
8
}
Unexecuted instantiation: pe-aarch64.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pei-aarch64.c:pe_bfd_copy_private_bfd_data
pei-ia64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
368
1
{
369
  /* PR binutils/716: Copy the large address aware flag.
370
     XXX: Should we be copying other flags or other fields in the pe_data()
371
     structure ?  */
372
1
  if (pe_data (obfd) != NULL
373
1
      && pe_data (ibfd) != NULL
374
1
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
375
0
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
376
377
1
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
378
0
    return false;
379
380
1
  if (pe_saved_coff_bfd_copy_private_bfd_data)
381
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
382
383
1
  return true;
384
1
}
pei-loongarch64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
368
1
{
369
  /* PR binutils/716: Copy the large address aware flag.
370
     XXX: Should we be copying other flags or other fields in the pe_data()
371
     structure ?  */
372
1
  if (pe_data (obfd) != NULL
373
1
      && pe_data (ibfd) != NULL
374
1
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
375
1
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
376
377
1
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
378
0
    return false;
379
380
1
  if (pe_saved_coff_bfd_copy_private_bfd_data)
381
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
382
383
1
  return true;
384
1
}
pei-riscv64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
368
6
{
369
  /* PR binutils/716: Copy the large address aware flag.
370
     XXX: Should we be copying other flags or other fields in the pe_data()
371
     structure ?  */
372
6
  if (pe_data (obfd) != NULL
373
6
      && pe_data (ibfd) != NULL
374
6
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
375
5
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
376
377
6
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
378
0
    return false;
379
380
6
  if (pe_saved_coff_bfd_copy_private_bfd_data)
381
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
382
383
6
  return true;
384
6
}
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
pei-arm-wince.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
368
1
{
369
  /* PR binutils/716: Copy the large address aware flag.
370
     XXX: Should we be copying other flags or other fields in the pe_data()
371
     structure ?  */
372
1
  if (pe_data (obfd) != NULL
373
1
      && pe_data (ibfd) != NULL
374
1
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
375
0
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
376
377
1
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
378
0
    return false;
379
380
1
  if (pe_saved_coff_bfd_copy_private_bfd_data)
381
1
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
382
383
0
  return true;
384
1
}
Unexecuted instantiation: pei-arm.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pei-mcore.c:pe_bfd_copy_private_bfd_data
pei-sh.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
368
1
{
369
  /* PR binutils/716: Copy the large address aware flag.
370
     XXX: Should we be copying other flags or other fields in the pe_data()
371
     structure ?  */
372
1
  if (pe_data (obfd) != NULL
373
1
      && pe_data (ibfd) != NULL
374
1
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
375
1
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
376
377
1
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
378
0
    return false;
379
380
1
  if (pe_saved_coff_bfd_copy_private_bfd_data)
381
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
382
383
1
  return true;
384
1
}
385
386
#define coff_bfd_copy_private_section_data \
387
  _bfd_XX_bfd_copy_private_section_data
388
389
#define coff_get_symbol_info _bfd_XX_get_symbol_info
390
391
#ifdef COFF_IMAGE_WITH_PE
392

393
/* Code to handle Microsoft's Import Library Format.
394
   Also known as LINK6 format.
395
   Documentation about this format can be found at:
396
397
   https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#import-library-format  */
398
399
/* The following constants specify the sizes of the various data
400
   structures that we have to create in order to build a bfd describing
401
   an ILF object file.  The final "+ 1" in the definitions of SIZEOF_IDATA6
402
   and SIZEOF_IDATA7 below is to allow for the possibility that we might
403
   need a padding byte in order to ensure 16 bit alignment for the section's
404
   contents.
405
406
   The value for SIZEOF_ILF_STRINGS is computed as follows:
407
408
      There will be NUM_ILF_SECTIONS section symbols.  Allow 9 characters
409
      per symbol for their names (longest section name is .idata$x).
410
411
      There will be two symbols for the imported value, one the symbol name
412
      and one with _imp__ prefixed.  Allowing for the terminating nul's this
413
      is strlen (symbol_name) * 2 + 8 + 21 + strlen (source_dll).
414
415
      The strings in the string table must start STRING__SIZE_SIZE bytes into
416
      the table in order to for the string lookup code in coffgen/coffcode to
417
      work.  */
418
352k
#define NUM_ILF_RELOCS    8
419
1.17M
#define NUM_ILF_SECTIONS  6
420
882k
#define NUM_ILF_SYMS    (2 + NUM_ILF_SECTIONS)
421
422
176k
#define SIZEOF_ILF_SYMS    (NUM_ILF_SYMS * sizeof (*vars.sym_cache))
423
176k
#define SIZEOF_ILF_SYM_TABLE   (NUM_ILF_SYMS * sizeof (*vars.sym_table))
424
176k
#define SIZEOF_ILF_NATIVE_SYMS   (NUM_ILF_SYMS * sizeof (*vars.native_syms))
425
176k
#define SIZEOF_ILF_SYM_PTR_TABLE (NUM_ILF_SYMS * sizeof (*vars.sym_ptr_table))
426
176k
#define SIZEOF_ILF_EXT_SYMS  (NUM_ILF_SYMS * sizeof (*vars.esym_table))
427
176k
#define SIZEOF_ILF_RELOCS  (NUM_ILF_RELOCS * sizeof (*vars.reltab))
428
176k
#define SIZEOF_ILF_INT_RELOCS  (NUM_ILF_RELOCS * sizeof (*vars.int_reltab))
429
176k
#define SIZEOF_ILF_STRINGS   (strlen (symbol_name) * 2 + 8 \
430
176k
          + 21 + strlen (source_dll)   \
431
176k
          + NUM_ILF_SECTIONS * 9       \
432
176k
          + STRING_SIZE_SIZE)
433
117k
#define SIZEOF_IDATA2   (5 * 4)
434
435
/* For PEx64 idata4 & 5 have thumb size of 8 bytes.  */
436
#if defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64)
437
40.5k
#define SIZEOF_IDATA4   (2 * 4)
438
40.5k
#define SIZEOF_IDATA5   (2 * 4)
439
#else
440
135k
#define SIZEOF_IDATA4   (1 * 4)
441
135k
#define SIZEOF_IDATA5   (1 * 4)
442
#endif
443
444
158k
#define SIZEOF_IDATA6   (2 + strlen (import_name) + 1 + 1)
445
117k
#define SIZEOF_IDATA7   (strlen (source_dll) + 1 + 1)
446
117k
#define SIZEOF_ILF_SECTIONS (NUM_ILF_SECTIONS \
447
117k
         * sizeof (struct coff_section_tdata))
448
449
#define ILF_DATA_SIZE       \
450
117k
    + SIZEOF_ILF_SYMS        \
451
117k
    + SIZEOF_ILF_SYM_TABLE      \
452
117k
    + SIZEOF_ILF_NATIVE_SYMS      \
453
117k
    + SIZEOF_ILF_SYM_PTR_TABLE      \
454
117k
    + SIZEOF_ILF_EXT_SYMS      \
455
117k
    + SIZEOF_ILF_RELOCS        \
456
117k
    + SIZEOF_ILF_INT_RELOCS      \
457
117k
    + SIZEOF_ILF_STRINGS      \
458
117k
    + SIZEOF_IDATA2        \
459
117k
    + SIZEOF_IDATA4        \
460
117k
    + SIZEOF_IDATA5        \
461
117k
    + SIZEOF_IDATA6        \
462
117k
    + SIZEOF_IDATA7        \
463
117k
    + SIZEOF_ILF_SECTIONS      \
464
117k
    + MAX_TEXT_SECTION_SIZE
465
466
/* Create an empty relocation against the given symbol.  */
467
468
static void
469
pe_ILF_make_a_symbol_reloc (pe_ILF_vars *   vars,
470
          bfd_vma     address,
471
          bfd_reloc_code_real_type  reloc,
472
          struct bfd_symbol **  sym,
473
          unsigned int    sym_index)
474
104k
{
475
104k
  arelent *entry;
476
104k
  struct internal_reloc *internal;
477
478
104k
  entry = vars->reltab + vars->relcount;
479
104k
  internal = vars->int_reltab + vars->relcount;
480
481
104k
  entry->address     = address;
482
104k
  entry->addend      = 0;
483
104k
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
484
104k
  entry->sym_ptr_ptr = sym;
485
486
104k
  internal->r_vaddr  = address;
487
104k
  internal->r_symndx = sym_index;
488
104k
  internal->r_type   = entry->howto ? entry->howto->type : 0;
489
490
104k
  vars->relcount ++;
491
492
104k
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
493
104k
}
pei-i386.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
474
17.8k
{
475
17.8k
  arelent *entry;
476
17.8k
  struct internal_reloc *internal;
477
478
17.8k
  entry = vars->reltab + vars->relcount;
479
17.8k
  internal = vars->int_reltab + vars->relcount;
480
481
17.8k
  entry->address     = address;
482
17.8k
  entry->addend      = 0;
483
17.8k
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
484
17.8k
  entry->sym_ptr_ptr = sym;
485
486
17.8k
  internal->r_vaddr  = address;
487
17.8k
  internal->r_symndx = sym_index;
488
17.8k
  internal->r_type   = entry->howto ? entry->howto->type : 0;
489
490
17.8k
  vars->relcount ++;
491
492
17.8k
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
493
17.8k
}
pei-x86_64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
474
12.3k
{
475
12.3k
  arelent *entry;
476
12.3k
  struct internal_reloc *internal;
477
478
12.3k
  entry = vars->reltab + vars->relcount;
479
12.3k
  internal = vars->int_reltab + vars->relcount;
480
481
12.3k
  entry->address     = address;
482
12.3k
  entry->addend      = 0;
483
12.3k
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
484
12.3k
  entry->sym_ptr_ptr = sym;
485
486
12.3k
  internal->r_vaddr  = address;
487
12.3k
  internal->r_symndx = sym_index;
488
12.3k
  internal->r_type   = entry->howto ? entry->howto->type : 0;
489
490
12.3k
  vars->relcount ++;
491
492
12.3k
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
493
12.3k
}
pei-aarch64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
474
12.3k
{
475
12.3k
  arelent *entry;
476
12.3k
  struct internal_reloc *internal;
477
478
12.3k
  entry = vars->reltab + vars->relcount;
479
12.3k
  internal = vars->int_reltab + vars->relcount;
480
481
12.3k
  entry->address     = address;
482
12.3k
  entry->addend      = 0;
483
12.3k
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
484
12.3k
  entry->sym_ptr_ptr = sym;
485
486
12.3k
  internal->r_vaddr  = address;
487
12.3k
  internal->r_symndx = sym_index;
488
12.3k
  internal->r_type   = entry->howto ? entry->howto->type : 0;
489
490
12.3k
  vars->relcount ++;
491
492
12.3k
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
493
12.3k
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_symbol_reloc
pei-loongarch64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
474
10.2k
{
475
10.2k
  arelent *entry;
476
10.2k
  struct internal_reloc *internal;
477
478
10.2k
  entry = vars->reltab + vars->relcount;
479
10.2k
  internal = vars->int_reltab + vars->relcount;
480
481
10.2k
  entry->address     = address;
482
10.2k
  entry->addend      = 0;
483
10.2k
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
484
10.2k
  entry->sym_ptr_ptr = sym;
485
486
10.2k
  internal->r_vaddr  = address;
487
10.2k
  internal->r_symndx = sym_index;
488
10.2k
  internal->r_type   = entry->howto ? entry->howto->type : 0;
489
490
10.2k
  vars->relcount ++;
491
492
10.2k
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
493
10.2k
}
pei-riscv64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
474
13.5k
{
475
13.5k
  arelent *entry;
476
13.5k
  struct internal_reloc *internal;
477
478
13.5k
  entry = vars->reltab + vars->relcount;
479
13.5k
  internal = vars->int_reltab + vars->relcount;
480
481
13.5k
  entry->address     = address;
482
13.5k
  entry->addend      = 0;
483
13.5k
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
484
13.5k
  entry->sym_ptr_ptr = sym;
485
486
13.5k
  internal->r_vaddr  = address;
487
13.5k
  internal->r_symndx = sym_index;
488
13.5k
  internal->r_type   = entry->howto ? entry->howto->type : 0;
489
490
13.5k
  vars->relcount ++;
491
492
13.5k
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
493
13.5k
}
pei-arm-wince.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
474
141
{
475
141
  arelent *entry;
476
141
  struct internal_reloc *internal;
477
478
141
  entry = vars->reltab + vars->relcount;
479
141
  internal = vars->int_reltab + vars->relcount;
480
481
141
  entry->address     = address;
482
141
  entry->addend      = 0;
483
141
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
484
141
  entry->sym_ptr_ptr = sym;
485
486
141
  internal->r_vaddr  = address;
487
141
  internal->r_symndx = sym_index;
488
141
  internal->r_type   = entry->howto ? entry->howto->type : 0;
489
490
141
  vars->relcount ++;
491
492
141
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
493
141
}
pei-arm.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
474
23.2k
{
475
23.2k
  arelent *entry;
476
23.2k
  struct internal_reloc *internal;
477
478
23.2k
  entry = vars->reltab + vars->relcount;
479
23.2k
  internal = vars->int_reltab + vars->relcount;
480
481
23.2k
  entry->address     = address;
482
23.2k
  entry->addend      = 0;
483
23.2k
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
484
23.2k
  entry->sym_ptr_ptr = sym;
485
486
23.2k
  internal->r_vaddr  = address;
487
23.2k
  internal->r_symndx = sym_index;
488
23.2k
  internal->r_type   = entry->howto ? entry->howto->type : 0;
489
490
23.2k
  vars->relcount ++;
491
492
23.2k
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
493
23.2k
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_symbol_reloc
pei-sh.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
474
15.2k
{
475
15.2k
  arelent *entry;
476
15.2k
  struct internal_reloc *internal;
477
478
15.2k
  entry = vars->reltab + vars->relcount;
479
15.2k
  internal = vars->int_reltab + vars->relcount;
480
481
15.2k
  entry->address     = address;
482
15.2k
  entry->addend      = 0;
483
15.2k
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
484
15.2k
  entry->sym_ptr_ptr = sym;
485
486
15.2k
  internal->r_vaddr  = address;
487
15.2k
  internal->r_symndx = sym_index;
488
15.2k
  internal->r_type   = entry->howto ? entry->howto->type : 0;
489
490
15.2k
  vars->relcount ++;
491
492
15.2k
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
493
15.2k
}
494
495
/* Create an empty relocation against the given section.  */
496
497
static void
498
pe_ILF_make_a_reloc (pe_ILF_vars *         vars,
499
         bfd_vma           address,
500
         bfd_reloc_code_real_type  reloc,
501
         asection_ptr        sec)
502
81.3k
{
503
81.3k
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
504
81.3k
            coff_section_data (vars->abfd, sec)->i);
505
81.3k
}
pei-i386.c:pe_ILF_make_a_reloc
Line
Count
Source
502
14.0k
{
503
14.0k
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
504
14.0k
            coff_section_data (vars->abfd, sec)->i);
505
14.0k
}
pei-x86_64.c:pe_ILF_make_a_reloc
Line
Count
Source
502
9.62k
{
503
9.62k
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
504
9.62k
            coff_section_data (vars->abfd, sec)->i);
505
9.62k
}
pei-aarch64.c:pe_ILF_make_a_reloc
Line
Count
Source
502
9.55k
{
503
9.55k
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
504
9.55k
            coff_section_data (vars->abfd, sec)->i);
505
9.55k
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_reloc
pei-loongarch64.c:pe_ILF_make_a_reloc
Line
Count
Source
502
7.82k
{
503
7.82k
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
504
7.82k
            coff_section_data (vars->abfd, sec)->i);
505
7.82k
}
pei-riscv64.c:pe_ILF_make_a_reloc
Line
Count
Source
502
11.3k
{
503
11.3k
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
504
11.3k
            coff_section_data (vars->abfd, sec)->i);
505
11.3k
}
pei-arm-wince.c:pe_ILF_make_a_reloc
Line
Count
Source
502
100
{
503
100
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
504
100
            coff_section_data (vars->abfd, sec)->i);
505
100
}
pei-arm.c:pe_ILF_make_a_reloc
Line
Count
Source
502
16.4k
{
503
16.4k
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
504
16.4k
            coff_section_data (vars->abfd, sec)->i);
505
16.4k
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_reloc
pei-sh.c:pe_ILF_make_a_reloc
Line
Count
Source
502
12.4k
{
503
12.4k
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
504
12.4k
            coff_section_data (vars->abfd, sec)->i);
505
12.4k
}
506
507
/* Move the queued relocs into the given section.  */
508
509
static void
510
pe_ILF_save_relocs (pe_ILF_vars *vars,
511
        asection_ptr sec)
512
104k
{
513
  /* Make sure that there is somewhere to store the internal relocs.  */
514
104k
  if (coff_section_data (vars->abfd, sec) == NULL)
515
    /* We should probably return an error indication here.  */
516
0
    abort ();
517
518
104k
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
519
520
104k
  sec->relocation  = vars->reltab;
521
104k
  sec->reloc_count = vars->relcount;
522
104k
  sec->flags      |= SEC_RELOC;
523
524
104k
  vars->reltab     += vars->relcount;
525
104k
  vars->int_reltab += vars->relcount;
526
104k
  vars->relcount   = 0;
527
528
104k
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
529
104k
}
pei-i386.c:pe_ILF_save_relocs
Line
Count
Source
512
17.8k
{
513
  /* Make sure that there is somewhere to store the internal relocs.  */
514
17.8k
  if (coff_section_data (vars->abfd, sec) == NULL)
515
    /* We should probably return an error indication here.  */
516
0
    abort ();
517
518
17.8k
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
519
520
17.8k
  sec->relocation  = vars->reltab;
521
17.8k
  sec->reloc_count = vars->relcount;
522
17.8k
  sec->flags      |= SEC_RELOC;
523
524
17.8k
  vars->reltab     += vars->relcount;
525
17.8k
  vars->int_reltab += vars->relcount;
526
17.8k
  vars->relcount   = 0;
527
528
17.8k
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
529
17.8k
}
pei-x86_64.c:pe_ILF_save_relocs
Line
Count
Source
512
12.3k
{
513
  /* Make sure that there is somewhere to store the internal relocs.  */
514
12.3k
  if (coff_section_data (vars->abfd, sec) == NULL)
515
    /* We should probably return an error indication here.  */
516
0
    abort ();
517
518
12.3k
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
519
520
12.3k
  sec->relocation  = vars->reltab;
521
12.3k
  sec->reloc_count = vars->relcount;
522
12.3k
  sec->flags      |= SEC_RELOC;
523
524
12.3k
  vars->reltab     += vars->relcount;
525
12.3k
  vars->int_reltab += vars->relcount;
526
12.3k
  vars->relcount   = 0;
527
528
12.3k
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
529
12.3k
}
pei-aarch64.c:pe_ILF_save_relocs
Line
Count
Source
512
12.3k
{
513
  /* Make sure that there is somewhere to store the internal relocs.  */
514
12.3k
  if (coff_section_data (vars->abfd, sec) == NULL)
515
    /* We should probably return an error indication here.  */
516
0
    abort ();
517
518
12.3k
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
519
520
12.3k
  sec->relocation  = vars->reltab;
521
12.3k
  sec->reloc_count = vars->relcount;
522
12.3k
  sec->flags      |= SEC_RELOC;
523
524
12.3k
  vars->reltab     += vars->relcount;
525
12.3k
  vars->int_reltab += vars->relcount;
526
12.3k
  vars->relcount   = 0;
527
528
12.3k
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
529
12.3k
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_save_relocs
pei-loongarch64.c:pe_ILF_save_relocs
Line
Count
Source
512
10.2k
{
513
  /* Make sure that there is somewhere to store the internal relocs.  */
514
10.2k
  if (coff_section_data (vars->abfd, sec) == NULL)
515
    /* We should probably return an error indication here.  */
516
0
    abort ();
517
518
10.2k
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
519
520
10.2k
  sec->relocation  = vars->reltab;
521
10.2k
  sec->reloc_count = vars->relcount;
522
10.2k
  sec->flags      |= SEC_RELOC;
523
524
10.2k
  vars->reltab     += vars->relcount;
525
10.2k
  vars->int_reltab += vars->relcount;
526
10.2k
  vars->relcount   = 0;
527
528
10.2k
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
529
10.2k
}
pei-riscv64.c:pe_ILF_save_relocs
Line
Count
Source
512
13.5k
{
513
  /* Make sure that there is somewhere to store the internal relocs.  */
514
13.5k
  if (coff_section_data (vars->abfd, sec) == NULL)
515
    /* We should probably return an error indication here.  */
516
0
    abort ();
517
518
13.5k
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
519
520
13.5k
  sec->relocation  = vars->reltab;
521
13.5k
  sec->reloc_count = vars->relcount;
522
13.5k
  sec->flags      |= SEC_RELOC;
523
524
13.5k
  vars->reltab     += vars->relcount;
525
13.5k
  vars->int_reltab += vars->relcount;
526
13.5k
  vars->relcount   = 0;
527
528
13.5k
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
529
13.5k
}
pei-arm-wince.c:pe_ILF_save_relocs
Line
Count
Source
512
141
{
513
  /* Make sure that there is somewhere to store the internal relocs.  */
514
141
  if (coff_section_data (vars->abfd, sec) == NULL)
515
    /* We should probably return an error indication here.  */
516
0
    abort ();
517
518
141
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
519
520
141
  sec->relocation  = vars->reltab;
521
141
  sec->reloc_count = vars->relcount;
522
141
  sec->flags      |= SEC_RELOC;
523
524
141
  vars->reltab     += vars->relcount;
525
141
  vars->int_reltab += vars->relcount;
526
141
  vars->relcount   = 0;
527
528
141
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
529
141
}
pei-arm.c:pe_ILF_save_relocs
Line
Count
Source
512
23.2k
{
513
  /* Make sure that there is somewhere to store the internal relocs.  */
514
23.2k
  if (coff_section_data (vars->abfd, sec) == NULL)
515
    /* We should probably return an error indication here.  */
516
0
    abort ();
517
518
23.2k
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
519
520
23.2k
  sec->relocation  = vars->reltab;
521
23.2k
  sec->reloc_count = vars->relcount;
522
23.2k
  sec->flags      |= SEC_RELOC;
523
524
23.2k
  vars->reltab     += vars->relcount;
525
23.2k
  vars->int_reltab += vars->relcount;
526
23.2k
  vars->relcount   = 0;
527
528
23.2k
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
529
23.2k
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_save_relocs
pei-sh.c:pe_ILF_save_relocs
Line
Count
Source
512
15.2k
{
513
  /* Make sure that there is somewhere to store the internal relocs.  */
514
15.2k
  if (coff_section_data (vars->abfd, sec) == NULL)
515
    /* We should probably return an error indication here.  */
516
0
    abort ();
517
518
15.2k
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
519
520
15.2k
  sec->relocation  = vars->reltab;
521
15.2k
  sec->reloc_count = vars->relcount;
522
15.2k
  sec->flags      |= SEC_RELOC;
523
524
15.2k
  vars->reltab     += vars->relcount;
525
15.2k
  vars->int_reltab += vars->relcount;
526
15.2k
  vars->relcount   = 0;
527
528
15.2k
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
529
15.2k
}
530
531
/* Create a global symbol and add it to the relevant tables.  */
532
533
static void
534
pe_ILF_make_a_symbol (pe_ILF_vars *  vars,
535
          const char *   prefix,
536
          const char *   symbol_name,
537
          asection_ptr   section,
538
          flagword       extra_flags)
539
331k
{
540
331k
  coff_symbol_type *sym;
541
331k
  combined_entry_type *ent;
542
331k
  SYMENT *esym;
543
331k
  unsigned short sclass;
544
545
331k
  if (extra_flags & BSF_LOCAL)
546
181k
    sclass = C_STAT;
547
149k
  else
548
149k
    sclass = C_EXT;
549
550
#ifdef THUMBPEMAGIC
551
81.6k
  if (vars->magic == THUMBPEMAGIC)
552
23.2k
    {
553
23.2k
      if (extra_flags & BSF_FUNCTION)
554
2.06k
  sclass = C_THUMBEXTFUNC;
555
21.1k
      else if (extra_flags & BSF_LOCAL)
556
12.7k
  sclass = C_THUMBSTAT;
557
8.40k
      else
558
8.40k
  sclass = C_THUMBEXT;
559
23.2k
    }
560
#endif
561
562
331k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
563
564
331k
  sym = vars->sym_ptr;
565
331k
  ent = vars->native_ptr;
566
331k
  esym = vars->esym_ptr;
567
568
  /* Copy the symbol's name into the string table.  */
569
331k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
570
571
331k
  if (section == NULL)
572
55.8k
    section = bfd_und_section_ptr;
573
574
  /* Initialise the external symbol.  */
575
331k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
576
331k
      esym->e.e.e_offset);
577
331k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
578
331k
  esym->e_sclass[0] = sclass;
579
580
  /* The following initialisations are unnecessary - the memory is
581
     zero initialised.  They are just kept here as reminders.  */
582
583
  /* Initialise the internal symbol structure.  */
584
331k
  ent->u.syment.n_sclass    = sclass;
585
331k
  ent->u.syment.n_scnum     = section->target_index;
586
331k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
587
331k
  ent->is_sym = true;
588
589
331k
  sym->symbol.the_bfd = vars->abfd;
590
331k
  sym->symbol.name    = vars->string_ptr;
591
331k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
592
331k
  sym->symbol.section = section;
593
331k
  sym->native       = ent;
594
595
331k
  *vars->table_ptr = vars->sym_index;
596
331k
  *vars->sym_ptr_ptr = sym;
597
598
  /* Adjust pointers for the next symbol.  */
599
331k
  vars->sym_index ++;
600
331k
  vars->sym_ptr ++;
601
331k
  vars->sym_ptr_ptr ++;
602
331k
  vars->table_ptr ++;
603
331k
  vars->native_ptr ++;
604
331k
  vars->esym_ptr ++;
605
331k
  vars->string_ptr += len + 1;
606
607
331k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
608
331k
}
pei-i386.c:pe_ILF_make_a_symbol
Line
Count
Source
539
52.7k
{
540
52.7k
  coff_symbol_type *sym;
541
52.7k
  combined_entry_type *ent;
542
52.7k
  SYMENT *esym;
543
52.7k
  unsigned short sclass;
544
545
52.7k
  if (extra_flags & BSF_LOCAL)
546
29.6k
    sclass = C_STAT;
547
23.1k
  else
548
23.1k
    sclass = C_EXT;
549
550
#ifdef THUMBPEMAGIC
551
  if (vars->magic == THUMBPEMAGIC)
552
    {
553
      if (extra_flags & BSF_FUNCTION)
554
  sclass = C_THUMBEXTFUNC;
555
      else if (extra_flags & BSF_LOCAL)
556
  sclass = C_THUMBSTAT;
557
      else
558
  sclass = C_THUMBEXT;
559
    }
560
#endif
561
562
52.7k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
563
564
52.7k
  sym = vars->sym_ptr;
565
52.7k
  ent = vars->native_ptr;
566
52.7k
  esym = vars->esym_ptr;
567
568
  /* Copy the symbol's name into the string table.  */
569
52.7k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
570
571
52.7k
  if (section == NULL)
572
9.07k
    section = bfd_und_section_ptr;
573
574
  /* Initialise the external symbol.  */
575
52.7k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
576
52.7k
      esym->e.e.e_offset);
577
52.7k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
578
52.7k
  esym->e_sclass[0] = sclass;
579
580
  /* The following initialisations are unnecessary - the memory is
581
     zero initialised.  They are just kept here as reminders.  */
582
583
  /* Initialise the internal symbol structure.  */
584
52.7k
  ent->u.syment.n_sclass    = sclass;
585
52.7k
  ent->u.syment.n_scnum     = section->target_index;
586
52.7k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
587
52.7k
  ent->is_sym = true;
588
589
52.7k
  sym->symbol.the_bfd = vars->abfd;
590
52.7k
  sym->symbol.name    = vars->string_ptr;
591
52.7k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
592
52.7k
  sym->symbol.section = section;
593
52.7k
  sym->native       = ent;
594
595
52.7k
  *vars->table_ptr = vars->sym_index;
596
52.7k
  *vars->sym_ptr_ptr = sym;
597
598
  /* Adjust pointers for the next symbol.  */
599
52.7k
  vars->sym_index ++;
600
52.7k
  vars->sym_ptr ++;
601
52.7k
  vars->sym_ptr_ptr ++;
602
52.7k
  vars->table_ptr ++;
603
52.7k
  vars->native_ptr ++;
604
52.7k
  vars->esym_ptr ++;
605
52.7k
  vars->string_ptr += len + 1;
606
607
52.7k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
608
52.7k
}
pei-x86_64.c:pe_ILF_make_a_symbol
Line
Count
Source
539
39.9k
{
540
39.9k
  coff_symbol_type *sym;
541
39.9k
  combined_entry_type *ent;
542
39.9k
  SYMENT *esym;
543
39.9k
  unsigned short sclass;
544
545
39.9k
  if (extra_flags & BSF_LOCAL)
546
21.7k
    sclass = C_STAT;
547
18.1k
  else
548
18.1k
    sclass = C_EXT;
549
550
#ifdef THUMBPEMAGIC
551
  if (vars->magic == THUMBPEMAGIC)
552
    {
553
      if (extra_flags & BSF_FUNCTION)
554
  sclass = C_THUMBEXTFUNC;
555
      else if (extra_flags & BSF_LOCAL)
556
  sclass = C_THUMBSTAT;
557
      else
558
  sclass = C_THUMBEXT;
559
    }
560
#endif
561
562
39.9k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
563
564
39.9k
  sym = vars->sym_ptr;
565
39.9k
  ent = vars->native_ptr;
566
39.9k
  esym = vars->esym_ptr;
567
568
  /* Copy the symbol's name into the string table.  */
569
39.9k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
570
571
39.9k
  if (section == NULL)
572
6.80k
    section = bfd_und_section_ptr;
573
574
  /* Initialise the external symbol.  */
575
39.9k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
576
39.9k
      esym->e.e.e_offset);
577
39.9k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
578
39.9k
  esym->e_sclass[0] = sclass;
579
580
  /* The following initialisations are unnecessary - the memory is
581
     zero initialised.  They are just kept here as reminders.  */
582
583
  /* Initialise the internal symbol structure.  */
584
39.9k
  ent->u.syment.n_sclass    = sclass;
585
39.9k
  ent->u.syment.n_scnum     = section->target_index;
586
39.9k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
587
39.9k
  ent->is_sym = true;
588
589
39.9k
  sym->symbol.the_bfd = vars->abfd;
590
39.9k
  sym->symbol.name    = vars->string_ptr;
591
39.9k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
592
39.9k
  sym->symbol.section = section;
593
39.9k
  sym->native       = ent;
594
595
39.9k
  *vars->table_ptr = vars->sym_index;
596
39.9k
  *vars->sym_ptr_ptr = sym;
597
598
  /* Adjust pointers for the next symbol.  */
599
39.9k
  vars->sym_index ++;
600
39.9k
  vars->sym_ptr ++;
601
39.9k
  vars->sym_ptr_ptr ++;
602
39.9k
  vars->table_ptr ++;
603
39.9k
  vars->native_ptr ++;
604
39.9k
  vars->esym_ptr ++;
605
39.9k
  vars->string_ptr += len + 1;
606
607
39.9k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
608
39.9k
}
pei-aarch64.c:pe_ILF_make_a_symbol
Line
Count
Source
539
36.4k
{
540
36.4k
  coff_symbol_type *sym;
541
36.4k
  combined_entry_type *ent;
542
36.4k
  SYMENT *esym;
543
36.4k
  unsigned short sclass;
544
545
36.4k
  if (extra_flags & BSF_LOCAL)
546
20.3k
    sclass = C_STAT;
547
16.1k
  else
548
16.1k
    sclass = C_EXT;
549
550
#ifdef THUMBPEMAGIC
551
  if (vars->magic == THUMBPEMAGIC)
552
    {
553
      if (extra_flags & BSF_FUNCTION)
554
  sclass = C_THUMBEXTFUNC;
555
      else if (extra_flags & BSF_LOCAL)
556
  sclass = C_THUMBSTAT;
557
      else
558
  sclass = C_THUMBEXT;
559
    }
560
#endif
561
562
36.4k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
563
564
36.4k
  sym = vars->sym_ptr;
565
36.4k
  ent = vars->native_ptr;
566
36.4k
  esym = vars->esym_ptr;
567
568
  /* Copy the symbol's name into the string table.  */
569
36.4k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
570
571
36.4k
  if (section == NULL)
572
6.09k
    section = bfd_und_section_ptr;
573
574
  /* Initialise the external symbol.  */
575
36.4k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
576
36.4k
      esym->e.e.e_offset);
577
36.4k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
578
36.4k
  esym->e_sclass[0] = sclass;
579
580
  /* The following initialisations are unnecessary - the memory is
581
     zero initialised.  They are just kept here as reminders.  */
582
583
  /* Initialise the internal symbol structure.  */
584
36.4k
  ent->u.syment.n_sclass    = sclass;
585
36.4k
  ent->u.syment.n_scnum     = section->target_index;
586
36.4k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
587
36.4k
  ent->is_sym = true;
588
589
36.4k
  sym->symbol.the_bfd = vars->abfd;
590
36.4k
  sym->symbol.name    = vars->string_ptr;
591
36.4k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
592
36.4k
  sym->symbol.section = section;
593
36.4k
  sym->native       = ent;
594
595
36.4k
  *vars->table_ptr = vars->sym_index;
596
36.4k
  *vars->sym_ptr_ptr = sym;
597
598
  /* Adjust pointers for the next symbol.  */
599
36.4k
  vars->sym_index ++;
600
36.4k
  vars->sym_ptr ++;
601
36.4k
  vars->sym_ptr_ptr ++;
602
36.4k
  vars->table_ptr ++;
603
36.4k
  vars->native_ptr ++;
604
36.4k
  vars->esym_ptr ++;
605
36.4k
  vars->string_ptr += len + 1;
606
607
36.4k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
608
36.4k
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_symbol
pei-loongarch64.c:pe_ILF_make_a_symbol
Line
Count
Source
539
28.8k
{
540
28.8k
  coff_symbol_type *sym;
541
28.8k
  combined_entry_type *ent;
542
28.8k
  SYMENT *esym;
543
28.8k
  unsigned short sclass;
544
545
28.8k
  if (extra_flags & BSF_LOCAL)
546
16.2k
    sclass = C_STAT;
547
12.6k
  else
548
12.6k
    sclass = C_EXT;
549
550
#ifdef THUMBPEMAGIC
551
  if (vars->magic == THUMBPEMAGIC)
552
    {
553
      if (extra_flags & BSF_FUNCTION)
554
  sclass = C_THUMBEXTFUNC;
555
      else if (extra_flags & BSF_LOCAL)
556
  sclass = C_THUMBSTAT;
557
      else
558
  sclass = C_THUMBEXT;
559
    }
560
#endif
561
562
28.8k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
563
564
28.8k
  sym = vars->sym_ptr;
565
28.8k
  ent = vars->native_ptr;
566
28.8k
  esym = vars->esym_ptr;
567
568
  /* Copy the symbol's name into the string table.  */
569
28.8k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
570
571
28.8k
  if (section == NULL)
572
4.76k
    section = bfd_und_section_ptr;
573
574
  /* Initialise the external symbol.  */
575
28.8k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
576
28.8k
      esym->e.e.e_offset);
577
28.8k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
578
28.8k
  esym->e_sclass[0] = sclass;
579
580
  /* The following initialisations are unnecessary - the memory is
581
     zero initialised.  They are just kept here as reminders.  */
582
583
  /* Initialise the internal symbol structure.  */
584
28.8k
  ent->u.syment.n_sclass    = sclass;
585
28.8k
  ent->u.syment.n_scnum     = section->target_index;
586
28.8k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
587
28.8k
  ent->is_sym = true;
588
589
28.8k
  sym->symbol.the_bfd = vars->abfd;
590
28.8k
  sym->symbol.name    = vars->string_ptr;
591
28.8k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
592
28.8k
  sym->symbol.section = section;
593
28.8k
  sym->native       = ent;
594
595
28.8k
  *vars->table_ptr = vars->sym_index;
596
28.8k
  *vars->sym_ptr_ptr = sym;
597
598
  /* Adjust pointers for the next symbol.  */
599
28.8k
  vars->sym_index ++;
600
28.8k
  vars->sym_ptr ++;
601
28.8k
  vars->sym_ptr_ptr ++;
602
28.8k
  vars->table_ptr ++;
603
28.8k
  vars->native_ptr ++;
604
28.8k
  vars->esym_ptr ++;
605
28.8k
  vars->string_ptr += len + 1;
606
607
28.8k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
608
28.8k
}
pei-riscv64.c:pe_ILF_make_a_symbol
Line
Count
Source
539
42.8k
{
540
42.8k
  coff_symbol_type *sym;
541
42.8k
  combined_entry_type *ent;
542
42.8k
  SYMENT *esym;
543
42.8k
  unsigned short sclass;
544
545
42.8k
  if (extra_flags & BSF_LOCAL)
546
22.9k
    sclass = C_STAT;
547
19.9k
  else
548
19.9k
    sclass = C_EXT;
549
550
#ifdef THUMBPEMAGIC
551
  if (vars->magic == THUMBPEMAGIC)
552
    {
553
      if (extra_flags & BSF_FUNCTION)
554
  sclass = C_THUMBEXTFUNC;
555
      else if (extra_flags & BSF_LOCAL)
556
  sclass = C_THUMBSTAT;
557
      else
558
  sclass = C_THUMBEXT;
559
    }
560
#endif
561
562
42.8k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
563
564
42.8k
  sym = vars->sym_ptr;
565
42.8k
  ent = vars->native_ptr;
566
42.8k
  esym = vars->esym_ptr;
567
568
  /* Copy the symbol's name into the string table.  */
569
42.8k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
570
571
42.8k
  if (section == NULL)
572
7.34k
    section = bfd_und_section_ptr;
573
574
  /* Initialise the external symbol.  */
575
42.8k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
576
42.8k
      esym->e.e.e_offset);
577
42.8k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
578
42.8k
  esym->e_sclass[0] = sclass;
579
580
  /* The following initialisations are unnecessary - the memory is
581
     zero initialised.  They are just kept here as reminders.  */
582
583
  /* Initialise the internal symbol structure.  */
584
42.8k
  ent->u.syment.n_sclass    = sclass;
585
42.8k
  ent->u.syment.n_scnum     = section->target_index;
586
42.8k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
587
42.8k
  ent->is_sym = true;
588
589
42.8k
  sym->symbol.the_bfd = vars->abfd;
590
42.8k
  sym->symbol.name    = vars->string_ptr;
591
42.8k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
592
42.8k
  sym->symbol.section = section;
593
42.8k
  sym->native       = ent;
594
595
42.8k
  *vars->table_ptr = vars->sym_index;
596
42.8k
  *vars->sym_ptr_ptr = sym;
597
598
  /* Adjust pointers for the next symbol.  */
599
42.8k
  vars->sym_index ++;
600
42.8k
  vars->sym_ptr ++;
601
42.8k
  vars->sym_ptr_ptr ++;
602
42.8k
  vars->table_ptr ++;
603
42.8k
  vars->native_ptr ++;
604
42.8k
  vars->esym_ptr ++;
605
42.8k
  vars->string_ptr += len + 1;
606
607
42.8k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
608
42.8k
}
pei-arm-wince.c:pe_ILF_make_a_symbol
Line
Count
Source
539
1.72k
{
540
1.72k
  coff_symbol_type *sym;
541
1.72k
  combined_entry_type *ent;
542
1.72k
  SYMENT *esym;
543
1.72k
  unsigned short sclass;
544
545
1.72k
  if (extra_flags & BSF_LOCAL)
546
1.49k
    sclass = C_STAT;
547
228
  else
548
228
    sclass = C_EXT;
549
550
1.72k
#ifdef THUMBPEMAGIC
551
1.72k
  if (vars->magic == THUMBPEMAGIC)
552
776
    {
553
776
      if (extra_flags & BSF_FUNCTION)
554
16
  sclass = C_THUMBEXTFUNC;
555
760
      else if (extra_flags & BSF_LOCAL)
556
697
  sclass = C_THUMBSTAT;
557
63
      else
558
63
  sclass = C_THUMBEXT;
559
776
    }
560
1.72k
#endif
561
562
1.72k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
563
564
1.72k
  sym = vars->sym_ptr;
565
1.72k
  ent = vars->native_ptr;
566
1.72k
  esym = vars->esym_ptr;
567
568
  /* Copy the symbol's name into the string table.  */
569
1.72k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
570
571
1.72k
  if (section == NULL)
572
84
    section = bfd_und_section_ptr;
573
574
  /* Initialise the external symbol.  */
575
1.72k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
576
1.72k
      esym->e.e.e_offset);
577
1.72k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
578
1.72k
  esym->e_sclass[0] = sclass;
579
580
  /* The following initialisations are unnecessary - the memory is
581
     zero initialised.  They are just kept here as reminders.  */
582
583
  /* Initialise the internal symbol structure.  */
584
1.72k
  ent->u.syment.n_sclass    = sclass;
585
1.72k
  ent->u.syment.n_scnum     = section->target_index;
586
1.72k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
587
1.72k
  ent->is_sym = true;
588
589
1.72k
  sym->symbol.the_bfd = vars->abfd;
590
1.72k
  sym->symbol.name    = vars->string_ptr;
591
1.72k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
592
1.72k
  sym->symbol.section = section;
593
1.72k
  sym->native       = ent;
594
595
1.72k
  *vars->table_ptr = vars->sym_index;
596
1.72k
  *vars->sym_ptr_ptr = sym;
597
598
  /* Adjust pointers for the next symbol.  */
599
1.72k
  vars->sym_index ++;
600
1.72k
  vars->sym_ptr ++;
601
1.72k
  vars->sym_ptr_ptr ++;
602
1.72k
  vars->table_ptr ++;
603
1.72k
  vars->native_ptr ++;
604
1.72k
  vars->esym_ptr ++;
605
1.72k
  vars->string_ptr += len + 1;
606
607
1.72k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
608
1.72k
}
pei-arm.c:pe_ILF_make_a_symbol
Line
Count
Source
539
79.8k
{
540
79.8k
  coff_symbol_type *sym;
541
79.8k
  combined_entry_type *ent;
542
79.8k
  SYMENT *esym;
543
79.8k
  unsigned short sclass;
544
545
79.8k
  if (extra_flags & BSF_LOCAL)
546
42.8k
    sclass = C_STAT;
547
37.0k
  else
548
37.0k
    sclass = C_EXT;
549
550
79.8k
#ifdef THUMBPEMAGIC
551
79.8k
  if (vars->magic == THUMBPEMAGIC)
552
22.4k
    {
553
22.4k
      if (extra_flags & BSF_FUNCTION)
554
2.04k
  sclass = C_THUMBEXTFUNC;
555
20.3k
      else if (extra_flags & BSF_LOCAL)
556
12.0k
  sclass = C_THUMBSTAT;
557
8.34k
      else
558
8.34k
  sclass = C_THUMBEXT;
559
22.4k
    }
560
79.8k
#endif
561
562
79.8k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
563
564
79.8k
  sym = vars->sym_ptr;
565
79.8k
  ent = vars->native_ptr;
566
79.8k
  esym = vars->esym_ptr;
567
568
  /* Copy the symbol's name into the string table.  */
569
79.8k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
570
571
79.8k
  if (section == NULL)
572
13.2k
    section = bfd_und_section_ptr;
573
574
  /* Initialise the external symbol.  */
575
79.8k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
576
79.8k
      esym->e.e.e_offset);
577
79.8k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
578
79.8k
  esym->e_sclass[0] = sclass;
579
580
  /* The following initialisations are unnecessary - the memory is
581
     zero initialised.  They are just kept here as reminders.  */
582
583
  /* Initialise the internal symbol structure.  */
584
79.8k
  ent->u.syment.n_sclass    = sclass;
585
79.8k
  ent->u.syment.n_scnum     = section->target_index;
586
79.8k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
587
79.8k
  ent->is_sym = true;
588
589
79.8k
  sym->symbol.the_bfd = vars->abfd;
590
79.8k
  sym->symbol.name    = vars->string_ptr;
591
79.8k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
592
79.8k
  sym->symbol.section = section;
593
79.8k
  sym->native       = ent;
594
595
79.8k
  *vars->table_ptr = vars->sym_index;
596
79.8k
  *vars->sym_ptr_ptr = sym;
597
598
  /* Adjust pointers for the next symbol.  */
599
79.8k
  vars->sym_index ++;
600
79.8k
  vars->sym_ptr ++;
601
79.8k
  vars->sym_ptr_ptr ++;
602
79.8k
  vars->table_ptr ++;
603
79.8k
  vars->native_ptr ++;
604
79.8k
  vars->esym_ptr ++;
605
79.8k
  vars->string_ptr += len + 1;
606
607
79.8k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
608
79.8k
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_symbol
pei-sh.c:pe_ILF_make_a_symbol
Line
Count
Source
539
48.6k
{
540
48.6k
  coff_symbol_type *sym;
541
48.6k
  combined_entry_type *ent;
542
48.6k
  SYMENT *esym;
543
48.6k
  unsigned short sclass;
544
545
48.6k
  if (extra_flags & BSF_LOCAL)
546
26.6k
    sclass = C_STAT;
547
21.9k
  else
548
21.9k
    sclass = C_EXT;
549
550
#ifdef THUMBPEMAGIC
551
  if (vars->magic == THUMBPEMAGIC)
552
    {
553
      if (extra_flags & BSF_FUNCTION)
554
  sclass = C_THUMBEXTFUNC;
555
      else if (extra_flags & BSF_LOCAL)
556
  sclass = C_THUMBSTAT;
557
      else
558
  sclass = C_THUMBEXT;
559
    }
560
#endif
561
562
48.6k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
563
564
48.6k
  sym = vars->sym_ptr;
565
48.6k
  ent = vars->native_ptr;
566
48.6k
  esym = vars->esym_ptr;
567
568
  /* Copy the symbol's name into the string table.  */
569
48.6k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
570
571
48.6k
  if (section == NULL)
572
8.37k
    section = bfd_und_section_ptr;
573
574
  /* Initialise the external symbol.  */
575
48.6k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
576
48.6k
      esym->e.e.e_offset);
577
48.6k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
578
48.6k
  esym->e_sclass[0] = sclass;
579
580
  /* The following initialisations are unnecessary - the memory is
581
     zero initialised.  They are just kept here as reminders.  */
582
583
  /* Initialise the internal symbol structure.  */
584
48.6k
  ent->u.syment.n_sclass    = sclass;
585
48.6k
  ent->u.syment.n_scnum     = section->target_index;
586
48.6k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
587
48.6k
  ent->is_sym = true;
588
589
48.6k
  sym->symbol.the_bfd = vars->abfd;
590
48.6k
  sym->symbol.name    = vars->string_ptr;
591
48.6k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
592
48.6k
  sym->symbol.section = section;
593
48.6k
  sym->native       = ent;
594
595
48.6k
  *vars->table_ptr = vars->sym_index;
596
48.6k
  *vars->sym_ptr_ptr = sym;
597
598
  /* Adjust pointers for the next symbol.  */
599
48.6k
  vars->sym_index ++;
600
48.6k
  vars->sym_ptr ++;
601
48.6k
  vars->sym_ptr_ptr ++;
602
48.6k
  vars->table_ptr ++;
603
48.6k
  vars->native_ptr ++;
604
48.6k
  vars->esym_ptr ++;
605
48.6k
  vars->string_ptr += len + 1;
606
607
48.6k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
608
48.6k
}
609
610
/* Create a section.  */
611
612
static asection_ptr
613
pe_ILF_make_a_section (pe_ILF_vars * vars,
614
           const char *  name,
615
           unsigned int  size,
616
           flagword      extra_flags)
617
181k
{
618
181k
  asection_ptr sec;
619
181k
  flagword     flags;
620
181k
  intptr_t alignment;
621
622
181k
  sec = bfd_make_section_old_way (vars->abfd, name);
623
181k
  if (sec == NULL)
624
0
    return NULL;
625
626
181k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
627
628
181k
  bfd_set_section_flags (sec, flags | extra_flags);
629
630
181k
  bfd_set_section_alignment (sec, 2);
631
632
  /* Check that we will not run out of space.  */
633
181k
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
634
635
  /* Set the section size and contents.  The actual
636
     contents are filled in by our parent.  */
637
181k
  bfd_set_section_size (sec, (bfd_size_type) size);
638
181k
  sec->contents = vars->data;
639
181k
  sec->target_index = vars->sec_index ++;
640
641
  /* Advance data pointer in the vars structure.  */
642
181k
  vars->data += size;
643
644
  /* Skip the padding byte if it was not needed.
645
     The logic here is that if the string length is odd,
646
     then the entire string length, including the null byte,
647
     is even and so the extra, padding byte, is not needed.  */
648
181k
  if (size & 1)
649
20.5k
    vars->data --;
650
651
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
652
     preserve host alignment requirements.  The BFD_ASSERTs in this
653
     functions will warn us if we run out of room, but we should
654
     already have enough padding built in to ILF_DATA_SIZE.  */
655
181k
#if GCC_VERSION >= 3000
656
181k
  alignment = __alignof__ (struct coff_section_tdata);
657
#else
658
  alignment = 8;
659
#endif
660
181k
  vars->data
661
181k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
662
663
  /* Create a coff_section_tdata structure for our use.  */
664
181k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
665
181k
  vars->data += sizeof (struct coff_section_tdata);
666
667
181k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
668
669
  /* Create a symbol to refer to this section.  */
670
181k
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
671
672
  /* Cache the index to the symbol in the coff_section_data structure.  */
673
181k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
674
675
181k
  return sec;
676
181k
}
pei-i386.c:pe_ILF_make_a_section
Line
Count
Source
617
29.6k
{
618
29.6k
  asection_ptr sec;
619
29.6k
  flagword     flags;
620
29.6k
  intptr_t alignment;
621
622
29.6k
  sec = bfd_make_section_old_way (vars->abfd, name);
623
29.6k
  if (sec == NULL)
624
0
    return NULL;
625
626
29.6k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
627
628
29.6k
  bfd_set_section_flags (sec, flags | extra_flags);
629
630
29.6k
  bfd_set_section_alignment (sec, 2);
631
632
  /* Check that we will not run out of space.  */
633
29.6k
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
634
635
  /* Set the section size and contents.  The actual
636
     contents are filled in by our parent.  */
637
29.6k
  bfd_set_section_size (sec, (bfd_size_type) size);
638
29.6k
  sec->contents = vars->data;
639
29.6k
  sec->target_index = vars->sec_index ++;
640
641
  /* Advance data pointer in the vars structure.  */
642
29.6k
  vars->data += size;
643
644
  /* Skip the padding byte if it was not needed.
645
     The logic here is that if the string length is odd,
646
     then the entire string length, including the null byte,
647
     is even and so the extra, padding byte, is not needed.  */
648
29.6k
  if (size & 1)
649
2.13k
    vars->data --;
650
651
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
652
     preserve host alignment requirements.  The BFD_ASSERTs in this
653
     functions will warn us if we run out of room, but we should
654
     already have enough padding built in to ILF_DATA_SIZE.  */
655
29.6k
#if GCC_VERSION >= 3000
656
29.6k
  alignment = __alignof__ (struct coff_section_tdata);
657
#else
658
  alignment = 8;
659
#endif
660
29.6k
  vars->data
661
29.6k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
662
663
  /* Create a coff_section_tdata structure for our use.  */
664
29.6k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
665
29.6k
  vars->data += sizeof (struct coff_section_tdata);
666
667
29.6k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
668
669
  /* Create a symbol to refer to this section.  */
670
29.6k
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
671
672
  /* Cache the index to the symbol in the coff_section_data structure.  */
673
29.6k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
674
675
29.6k
  return sec;
676
29.6k
}
pei-x86_64.c:pe_ILF_make_a_section
Line
Count
Source
617
21.7k
{
618
21.7k
  asection_ptr sec;
619
21.7k
  flagword     flags;
620
21.7k
  intptr_t alignment;
621
622
21.7k
  sec = bfd_make_section_old_way (vars->abfd, name);
623
21.7k
  if (sec == NULL)
624
0
    return NULL;
625
626
21.7k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
627
628
21.7k
  bfd_set_section_flags (sec, flags | extra_flags);
629
630
21.7k
  bfd_set_section_alignment (sec, 2);
631
632
  /* Check that we will not run out of space.  */
633
21.7k
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
634
635
  /* Set the section size and contents.  The actual
636
     contents are filled in by our parent.  */
637
21.7k
  bfd_set_section_size (sec, (bfd_size_type) size);
638
21.7k
  sec->contents = vars->data;
639
21.7k
  sec->target_index = vars->sec_index ++;
640
641
  /* Advance data pointer in the vars structure.  */
642
21.7k
  vars->data += size;
643
644
  /* Skip the padding byte if it was not needed.
645
     The logic here is that if the string length is odd,
646
     then the entire string length, including the null byte,
647
     is even and so the extra, padding byte, is not needed.  */
648
21.7k
  if (size & 1)
649
2.95k
    vars->data --;
650
651
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
652
     preserve host alignment requirements.  The BFD_ASSERTs in this
653
     functions will warn us if we run out of room, but we should
654
     already have enough padding built in to ILF_DATA_SIZE.  */
655
21.7k
#if GCC_VERSION >= 3000
656
21.7k
  alignment = __alignof__ (struct coff_section_tdata);
657
#else
658
  alignment = 8;
659
#endif
660
21.7k
  vars->data
661
21.7k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
662
663
  /* Create a coff_section_tdata structure for our use.  */
664
21.7k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
665
21.7k
  vars->data += sizeof (struct coff_section_tdata);
666
667
21.7k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
668
669
  /* Create a symbol to refer to this section.  */
670
21.7k
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
671
672
  /* Cache the index to the symbol in the coff_section_data structure.  */
673
21.7k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
674
675
21.7k
  return sec;
676
21.7k
}
pei-aarch64.c:pe_ILF_make_a_section
Line
Count
Source
617
20.3k
{
618
20.3k
  asection_ptr sec;
619
20.3k
  flagword     flags;
620
20.3k
  intptr_t alignment;
621
622
20.3k
  sec = bfd_make_section_old_way (vars->abfd, name);
623
20.3k
  if (sec == NULL)
624
0
    return NULL;
625
626
20.3k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
627
628
20.3k
  bfd_set_section_flags (sec, flags | extra_flags);
629
630
20.3k
  bfd_set_section_alignment (sec, 2);
631
632
  /* Check that we will not run out of space.  */
633
20.3k
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
634
635
  /* Set the section size and contents.  The actual
636
     contents are filled in by our parent.  */
637
20.3k
  bfd_set_section_size (sec, (bfd_size_type) size);
638
20.3k
  sec->contents = vars->data;
639
20.3k
  sec->target_index = vars->sec_index ++;
640
641
  /* Advance data pointer in the vars structure.  */
642
20.3k
  vars->data += size;
643
644
  /* Skip the padding byte if it was not needed.
645
     The logic here is that if the string length is odd,
646
     then the entire string length, including the null byte,
647
     is even and so the extra, padding byte, is not needed.  */
648
20.3k
  if (size & 1)
649
2.25k
    vars->data --;
650
651
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
652
     preserve host alignment requirements.  The BFD_ASSERTs in this
653
     functions will warn us if we run out of room, but we should
654
     already have enough padding built in to ILF_DATA_SIZE.  */
655
20.3k
#if GCC_VERSION >= 3000
656
20.3k
  alignment = __alignof__ (struct coff_section_tdata);
657
#else
658
  alignment = 8;
659
#endif
660
20.3k
  vars->data
661
20.3k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
662
663
  /* Create a coff_section_tdata structure for our use.  */
664
20.3k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
665
20.3k
  vars->data += sizeof (struct coff_section_tdata);
666
667
20.3k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
668
669
  /* Create a symbol to refer to this section.  */
670
20.3k
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
671
672
  /* Cache the index to the symbol in the coff_section_data structure.  */
673
20.3k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
674
675
20.3k
  return sec;
676
20.3k
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_section
pei-loongarch64.c:pe_ILF_make_a_section
Line
Count
Source
617
16.2k
{
618
16.2k
  asection_ptr sec;
619
16.2k
  flagword     flags;
620
16.2k
  intptr_t alignment;
621
622
16.2k
  sec = bfd_make_section_old_way (vars->abfd, name);
623
16.2k
  if (sec == NULL)
624
0
    return NULL;
625
626
16.2k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
627
628
16.2k
  bfd_set_section_flags (sec, flags | extra_flags);
629
630
16.2k
  bfd_set_section_alignment (sec, 2);
631
632
  /* Check that we will not run out of space.  */
633
16.2k
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
634
635
  /* Set the section size and contents.  The actual
636
     contents are filled in by our parent.  */
637
16.2k
  bfd_set_section_size (sec, (bfd_size_type) size);
638
16.2k
  sec->contents = vars->data;
639
16.2k
  sec->target_index = vars->sec_index ++;
640
641
  /* Advance data pointer in the vars structure.  */
642
16.2k
  vars->data += size;
643
644
  /* Skip the padding byte if it was not needed.
645
     The logic here is that if the string length is odd,
646
     then the entire string length, including the null byte,
647
     is even and so the extra, padding byte, is not needed.  */
648
16.2k
  if (size & 1)
649
2.66k
    vars->data --;
650
651
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
652
     preserve host alignment requirements.  The BFD_ASSERTs in this
653
     functions will warn us if we run out of room, but we should
654
     already have enough padding built in to ILF_DATA_SIZE.  */
655
16.2k
#if GCC_VERSION >= 3000
656
16.2k
  alignment = __alignof__ (struct coff_section_tdata);
657
#else
658
  alignment = 8;
659
#endif
660
16.2k
  vars->data
661
16.2k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
662
663
  /* Create a coff_section_tdata structure for our use.  */
664
16.2k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
665
16.2k
  vars->data += sizeof (struct coff_section_tdata);
666
667
16.2k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
668
669
  /* Create a symbol to refer to this section.  */
670
16.2k
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
671
672
  /* Cache the index to the symbol in the coff_section_data structure.  */
673
16.2k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
674
675
16.2k
  return sec;
676
16.2k
}
pei-riscv64.c:pe_ILF_make_a_section
Line
Count
Source
617
22.9k
{
618
22.9k
  asection_ptr sec;
619
22.9k
  flagword     flags;
620
22.9k
  intptr_t alignment;
621
622
22.9k
  sec = bfd_make_section_old_way (vars->abfd, name);
623
22.9k
  if (sec == NULL)
624
0
    return NULL;
625
626
22.9k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
627
628
22.9k
  bfd_set_section_flags (sec, flags | extra_flags);
629
630
22.9k
  bfd_set_section_alignment (sec, 2);
631
632
  /* Check that we will not run out of space.  */
633
22.9k
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
634
635
  /* Set the section size and contents.  The actual
636
     contents are filled in by our parent.  */
637
22.9k
  bfd_set_section_size (sec, (bfd_size_type) size);
638
22.9k
  sec->contents = vars->data;
639
22.9k
  sec->target_index = vars->sec_index ++;
640
641
  /* Advance data pointer in the vars structure.  */
642
22.9k
  vars->data += size;
643
644
  /* Skip the padding byte if it was not needed.
645
     The logic here is that if the string length is odd,
646
     then the entire string length, including the null byte,
647
     is even and so the extra, padding byte, is not needed.  */
648
22.9k
  if (size & 1)
649
2.79k
    vars->data --;
650
651
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
652
     preserve host alignment requirements.  The BFD_ASSERTs in this
653
     functions will warn us if we run out of room, but we should
654
     already have enough padding built in to ILF_DATA_SIZE.  */
655
22.9k
#if GCC_VERSION >= 3000
656
22.9k
  alignment = __alignof__ (struct coff_section_tdata);
657
#else
658
  alignment = 8;
659
#endif
660
22.9k
  vars->data
661
22.9k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
662
663
  /* Create a coff_section_tdata structure for our use.  */
664
22.9k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
665
22.9k
  vars->data += sizeof (struct coff_section_tdata);
666
667
22.9k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
668
669
  /* Create a symbol to refer to this section.  */
670
22.9k
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
671
672
  /* Cache the index to the symbol in the coff_section_data structure.  */
673
22.9k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
674
675
22.9k
  return sec;
676
22.9k
}
pei-arm-wince.c:pe_ILF_make_a_section
Line
Count
Source
617
1.49k
{
618
1.49k
  asection_ptr sec;
619
1.49k
  flagword     flags;
620
1.49k
  intptr_t alignment;
621
622
1.49k
  sec = bfd_make_section_old_way (vars->abfd, name);
623
1.49k
  if (sec == NULL)
624
0
    return NULL;
625
626
1.49k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
627
628
1.49k
  bfd_set_section_flags (sec, flags | extra_flags);
629
630
1.49k
  bfd_set_section_alignment (sec, 2);
631
632
  /* Check that we will not run out of space.  */
633
1.49k
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
634
635
  /* Set the section size and contents.  The actual
636
     contents are filled in by our parent.  */
637
1.49k
  bfd_set_section_size (sec, (bfd_size_type) size);
638
1.49k
  sec->contents = vars->data;
639
1.49k
  sec->target_index = vars->sec_index ++;
640
641
  /* Advance data pointer in the vars structure.  */
642
1.49k
  vars->data += size;
643
644
  /* Skip the padding byte if it was not needed.
645
     The logic here is that if the string length is odd,
646
     then the entire string length, including the null byte,
647
     is even and so the extra, padding byte, is not needed.  */
648
1.49k
  if (size & 1)
649
23
    vars->data --;
650
651
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
652
     preserve host alignment requirements.  The BFD_ASSERTs in this
653
     functions will warn us if we run out of room, but we should
654
     already have enough padding built in to ILF_DATA_SIZE.  */
655
1.49k
#if GCC_VERSION >= 3000
656
1.49k
  alignment = __alignof__ (struct coff_section_tdata);
657
#else
658
  alignment = 8;
659
#endif
660
1.49k
  vars->data
661
1.49k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
662
663
  /* Create a coff_section_tdata structure for our use.  */
664
1.49k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
665
1.49k
  vars->data += sizeof (struct coff_section_tdata);
666
667
1.49k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
668
669
  /* Create a symbol to refer to this section.  */
670
1.49k
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
671
672
  /* Cache the index to the symbol in the coff_section_data structure.  */
673
1.49k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
674
675
1.49k
  return sec;
676
1.49k
}
pei-arm.c:pe_ILF_make_a_section
Line
Count
Source
617
42.8k
{
618
42.8k
  asection_ptr sec;
619
42.8k
  flagword     flags;
620
42.8k
  intptr_t alignment;
621
622
42.8k
  sec = bfd_make_section_old_way (vars->abfd, name);
623
42.8k
  if (sec == NULL)
624
0
    return NULL;
625
626
42.8k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
627
628
42.8k
  bfd_set_section_flags (sec, flags | extra_flags);
629
630
42.8k
  bfd_set_section_alignment (sec, 2);
631
632
  /* Check that we will not run out of space.  */
633
42.8k
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
634
635
  /* Set the section size and contents.  The actual
636
     contents are filled in by our parent.  */
637
42.8k
  bfd_set_section_size (sec, (bfd_size_type) size);
638
42.8k
  sec->contents = vars->data;
639
42.8k
  sec->target_index = vars->sec_index ++;
640
641
  /* Advance data pointer in the vars structure.  */
642
42.8k
  vars->data += size;
643
644
  /* Skip the padding byte if it was not needed.
645
     The logic here is that if the string length is odd,
646
     then the entire string length, including the null byte,
647
     is even and so the extra, padding byte, is not needed.  */
648
42.8k
  if (size & 1)
649
4.16k
    vars->data --;
650
651
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
652
     preserve host alignment requirements.  The BFD_ASSERTs in this
653
     functions will warn us if we run out of room, but we should
654
     already have enough padding built in to ILF_DATA_SIZE.  */
655
42.8k
#if GCC_VERSION >= 3000
656
42.8k
  alignment = __alignof__ (struct coff_section_tdata);
657
#else
658
  alignment = 8;
659
#endif
660
42.8k
  vars->data
661
42.8k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
662
663
  /* Create a coff_section_tdata structure for our use.  */
664
42.8k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
665
42.8k
  vars->data += sizeof (struct coff_section_tdata);
666
667
42.8k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
668
669
  /* Create a symbol to refer to this section.  */
670
42.8k
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
671
672
  /* Cache the index to the symbol in the coff_section_data structure.  */
673
42.8k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
674
675
42.8k
  return sec;
676
42.8k
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_section
pei-sh.c:pe_ILF_make_a_section
Line
Count
Source
617
26.6k
{
618
26.6k
  asection_ptr sec;
619
26.6k
  flagword     flags;
620
26.6k
  intptr_t alignment;
621
622
26.6k
  sec = bfd_make_section_old_way (vars->abfd, name);
623
26.6k
  if (sec == NULL)
624
0
    return NULL;
625
626
26.6k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
627
628
26.6k
  bfd_set_section_flags (sec, flags | extra_flags);
629
630
26.6k
  bfd_set_section_alignment (sec, 2);
631
632
  /* Check that we will not run out of space.  */
633
26.6k
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
634
635
  /* Set the section size and contents.  The actual
636
     contents are filled in by our parent.  */
637
26.6k
  bfd_set_section_size (sec, (bfd_size_type) size);
638
26.6k
  sec->contents = vars->data;
639
26.6k
  sec->target_index = vars->sec_index ++;
640
641
  /* Advance data pointer in the vars structure.  */
642
26.6k
  vars->data += size;
643
644
  /* Skip the padding byte if it was not needed.
645
     The logic here is that if the string length is odd,
646
     then the entire string length, including the null byte,
647
     is even and so the extra, padding byte, is not needed.  */
648
26.6k
  if (size & 1)
649
3.56k
    vars->data --;
650
651
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
652
     preserve host alignment requirements.  The BFD_ASSERTs in this
653
     functions will warn us if we run out of room, but we should
654
     already have enough padding built in to ILF_DATA_SIZE.  */
655
26.6k
#if GCC_VERSION >= 3000
656
26.6k
  alignment = __alignof__ (struct coff_section_tdata);
657
#else
658
  alignment = 8;
659
#endif
660
26.6k
  vars->data
661
26.6k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
662
663
  /* Create a coff_section_tdata structure for our use.  */
664
26.6k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
665
26.6k
  vars->data += sizeof (struct coff_section_tdata);
666
667
26.6k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
668
669
  /* Create a symbol to refer to this section.  */
670
26.6k
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
671
672
  /* Cache the index to the symbol in the coff_section_data structure.  */
673
26.6k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
674
675
26.6k
  return sec;
676
26.6k
}
677
678
/* This structure contains the code that goes into the .text section
679
   in order to perform a jump into the DLL lookup table.  The entries
680
   in the table are index by the magic number used to represent the
681
   machine type in the PE file.  The contents of the data[] arrays in
682
   these entries are stolen from the jtab[] arrays in ld/pe-dll.c.
683
   The SIZE field says how many bytes in the DATA array are actually
684
   used.  The OFFSET field says where in the data array the address
685
   of the .idata$5 section should be placed.  */
686
117k
#define MAX_TEXT_SECTION_SIZE 32
687
688
typedef struct
689
{
690
  unsigned short magic;
691
  unsigned char  data[MAX_TEXT_SECTION_SIZE];
692
  unsigned int   size;
693
  unsigned int   offset;
694
}
695
jump_table;
696
697
static const jump_table jtab[] =
698
{
699
#ifdef I386MAGIC
700
  { I386MAGIC,
701
    { 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, 0x90, 0x90 },
702
    8, 2
703
  },
704
#endif
705
706
#ifdef AMD64MAGIC
707
  { AMD64MAGIC,
708
    { 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, 0x90, 0x90 },
709
    8, 2
710
  },
711
#endif
712
713
#ifdef  MC68MAGIC
714
  { MC68MAGIC,
715
    { /* XXX fill me in */ },
716
    0, 0
717
  },
718
#endif
719
720
#ifdef  MIPS_ARCH_MAGIC_WINCE
721
  { MIPS_ARCH_MAGIC_WINCE,
722
    { 0x00, 0x00, 0x08, 0x3c, 0x00, 0x00, 0x08, 0x8d,
723
      0x08, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00 },
724
    16, 0
725
  },
726
#endif
727
728
#ifdef  SH_ARCH_MAGIC_WINCE
729
  { SH_ARCH_MAGIC_WINCE,
730
    { 0x01, 0xd0, 0x02, 0x60, 0x2b, 0x40,
731
      0x09, 0x00, 0x00, 0x00, 0x00, 0x00 },
732
    12, 8
733
  },
734
#endif
735
736
#ifdef AARCH64MAGIC
737
/* We don't currently support jumping to DLLs, so if
738
   someone does try emit a runtime trap.  Through UDF #0.  */
739
  { AARCH64MAGIC,
740
    { 0x00, 0x00, 0x00, 0x00 },
741
    4, 0
742
  },
743
744
#endif
745
746
#ifdef  ARMPEMAGIC
747
  { ARMPEMAGIC,
748
    { 0x00, 0xc0, 0x9f, 0xe5, 0x00, 0xf0,
749
      0x9c, 0xe5, 0x00, 0x00, 0x00, 0x00},
750
    12, 8
751
  },
752
#endif
753
754
#ifdef  THUMBPEMAGIC
755
  { THUMBPEMAGIC,
756
    { 0x40, 0xb4, 0x02, 0x4e, 0x36, 0x68, 0xb4, 0x46,
757
      0x40, 0xbc, 0x60, 0x47, 0x00, 0x00, 0x00, 0x00 },
758
    16, 12
759
  },
760
#endif
761
762
#ifdef LOONGARCH64MAGIC
763
/* We don't currently support jumping to DLLs, so if
764
   someone does try emit a runtime trap.  Through BREAK 0.  */
765
  { LOONGARCH64MAGIC,
766
    { 0x00, 0x00, 0x2a, 0x00 },
767
    4, 0
768
  },
769
770
#endif
771
772
#ifdef RISCV64MAGIC
773
  /* We don't currently support jumping to DLLs, so if
774
     someone does try emit a runtime trap.  Through EBREAK.  */
775
  { RISCV64MAGIC,
776
    { 0x73, 0x00, 0x10, 0x00 },
777
    4, 0
778
  },
779
780
#endif
781
782
  { 0, { 0 }, 0, 0 }
783
};
784
785
#ifndef NUM_ENTRIES
786
23.6k
#define NUM_ENTRIES(a) (sizeof (a) / sizeof (a)[0])
787
#endif
788
789
/* Build a full BFD from the information supplied in a ILF object.  */
790
791
static bool
792
pe_ILF_build_a_bfd (bfd *     abfd,
793
        unsigned int    magic,
794
        char *      symbol_name,
795
        char *      source_dll,
796
        unsigned int    ordinal,
797
        unsigned int    types,
798
        char *      import_name)
799
67.3k
{
800
67.3k
  bfd_byte *       ptr;
801
67.3k
  pe_ILF_vars      vars;
802
67.3k
  struct internal_filehdr  internal_f;
803
67.3k
  unsigned int       import_type;
804
67.3k
  unsigned int       import_name_type;
805
67.3k
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
806
67.3k
  coff_symbol_type **    imp_sym;
807
67.3k
  unsigned int       imp_index;
808
67.3k
  intptr_t alignment;
809
810
  /* Decode and verify the types field of the ILF structure.  */
811
67.3k
  import_type = types & 0x3;
812
67.3k
  import_name_type = (types & 0x1c) >> 2;
813
814
67.3k
  switch (import_type)
815
67.3k
    {
816
28.1k
    case IMPORT_CODE:
817
48.5k
    case IMPORT_DATA:
818
64.9k
    case IMPORT_CONST:
819
64.9k
      break;
820
821
2.42k
    default:
822
      /* xgettext:c-format */
823
2.42k
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
824
2.42k
        abfd, import_type);
825
2.42k
      return false;
826
67.3k
    }
827
828
64.9k
  switch (import_name_type)
829
64.9k
    {
830
18.1k
    case IMPORT_ORDINAL:
831
23.8k
    case IMPORT_NAME:
832
37.6k
    case IMPORT_NAME_NOPREFIX:
833
52.9k
    case IMPORT_NAME_UNDECORATE:
834
52.9k
      import_name = symbol_name;
835
52.9k
      break;
836
837
9.57k
    case IMPORT_NAME_EXPORTAS:
838
9.57k
      if (!import_name || !import_name[0])
839
3.68k
  {
840
3.68k
    _bfd_error_handler (_("%pB: missing import name for "
841
3.68k
        "IMPORT_NAME_EXPORTAS for %s"),
842
3.68k
            abfd, symbol_name);
843
3.68k
    return false;
844
3.68k
  }
845
5.89k
      break;
846
847
5.89k
    default:
848
      /* xgettext:c-format */
849
2.40k
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
850
2.40k
        abfd, import_name_type);
851
2.40k
      return false;
852
64.9k
    }
853
854
  /* Initialise local variables.
855
856
     Note these are kept in a structure rather than being
857
     declared as statics since bfd frowns on global variables.
858
859
     We are going to construct the contents of the BFD in memory,
860
     so allocate all the space that we will need right now.  */
861
58.8k
  vars.bim
862
58.8k
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
863
58.8k
  if (vars.bim == NULL)
864
0
    return false;
865
866
58.8k
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
867
58.8k
  vars.bim->buffer = ptr;
868
58.8k
  vars.bim->size   = ILF_DATA_SIZE;
869
58.8k
  if (ptr == NULL)
870
0
    goto error_return;
871
872
  /* Initialise the pointers to regions of the memory and the
873
     other contents of the pe_ILF_vars structure as well.  */
874
58.8k
  vars.sym_cache = (coff_symbol_type *) ptr;
875
58.8k
  vars.sym_ptr   = (coff_symbol_type *) ptr;
876
58.8k
  vars.sym_index = 0;
877
58.8k
  ptr += SIZEOF_ILF_SYMS;
878
879
58.8k
  vars.sym_table = (unsigned int *) ptr;
880
58.8k
  vars.table_ptr = (unsigned int *) ptr;
881
58.8k
  ptr += SIZEOF_ILF_SYM_TABLE;
882
883
58.8k
  vars.native_syms = (combined_entry_type *) ptr;
884
58.8k
  vars.native_ptr  = (combined_entry_type *) ptr;
885
58.8k
  ptr += SIZEOF_ILF_NATIVE_SYMS;
886
887
58.8k
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
888
58.8k
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
889
58.8k
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
890
891
58.8k
  vars.esym_table = (SYMENT *) ptr;
892
58.8k
  vars.esym_ptr   = (SYMENT *) ptr;
893
58.8k
  ptr += SIZEOF_ILF_EXT_SYMS;
894
895
58.8k
  vars.reltab   = (arelent *) ptr;
896
58.8k
  vars.relcount = 0;
897
58.8k
  ptr += SIZEOF_ILF_RELOCS;
898
899
58.8k
  vars.int_reltab  = (struct internal_reloc *) ptr;
900
58.8k
  ptr += SIZEOF_ILF_INT_RELOCS;
901
902
58.8k
  vars.string_table = (char *) ptr;
903
58.8k
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
904
58.8k
  ptr += SIZEOF_ILF_STRINGS;
905
58.8k
  vars.end_string_ptr = (char *) ptr;
906
907
  /* The remaining space in bim->buffer is used
908
     by the pe_ILF_make_a_section() function.  */
909
910
  /* PR 18758: Make sure that the data area is sufficiently aligned for
911
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
912
     the test of GCC_VERSION.  For other compilers we assume 8 byte
913
     alignment.  */
914
58.8k
#if GCC_VERSION >= 3000
915
58.8k
  alignment = __alignof__ (struct coff_section_tdata);
916
#else
917
  alignment = 8;
918
#endif
919
58.8k
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
920
921
58.8k
  vars.data = ptr;
922
58.8k
  vars.abfd = abfd;
923
58.8k
  vars.sec_index = 0;
924
58.8k
  vars.magic = magic;
925
926
  /* Create the initial .idata$<n> sections:
927
     [.idata$2:  Import Directory Table -- not needed]
928
     .idata$4:  Import Lookup Table
929
     .idata$5:  Import Address Table
930
931
     Note we do not create a .idata$3 section as this is
932
     created for us by the linker script.  */
933
58.8k
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
934
58.8k
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
935
58.8k
  if (id4 == NULL || id5 == NULL)
936
0
    goto error_return;
937
938
  /* Fill in the contents of these sections.  */
939
58.8k
  if (import_name_type == IMPORT_ORDINAL)
940
18.1k
    {
941
18.1k
      if (ordinal == 0)
942
  /* See PR 20907 for a reproducer.  */
943
3.00k
  goto error_return;
944
945
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
946
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
947
5.81k
      ((unsigned int *) id4->contents)[0] = ordinal;
948
5.81k
      ((unsigned int *) id4->contents)[1] = 0x80000000;
949
5.81k
      ((unsigned int *) id5->contents)[0] = ordinal;
950
5.81k
      ((unsigned int *) id5->contents)[1] = 0x80000000;
951
#else
952
9.30k
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
953
9.30k
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
954
9.30k
#endif
955
9.30k
    }
956
40.6k
  else
957
40.6k
    {
958
40.6k
      char *symbol;
959
40.6k
      unsigned int len;
960
961
      /* Create .idata$6 - the Hint Name Table.  */
962
40.6k
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
963
40.6k
      if (id6 == NULL)
964
0
  goto error_return;
965
966
      /* If necessary, trim the import symbol name.  */
967
40.6k
      symbol = import_name;
968
969
      /* As used by MS compiler, '_', '@', and '?' are alternative
970
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
971
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
972
   of these is used for a symbol.  We strip this leading char for
973
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
974
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
975
976
40.6k
      if (import_name_type != IMPORT_NAME
977
40.6k
    && import_name_type != IMPORT_NAME_EXPORTAS)
978
29.0k
  {
979
29.0k
    char c = symbol[0];
980
981
    /* Check that we don't remove for targets with empty
982
       USER_LABEL_PREFIX the leading underscore.  */
983
29.0k
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
984
29.0k
        || c == '@' || c == '?')
985
8.58k
      symbol++;
986
29.0k
  }
987
988
40.6k
      len = strlen (symbol);
989
40.6k
      if (import_name_type == IMPORT_NAME_UNDECORATE)
990
15.3k
  {
991
    /* Truncate at the first '@'.  */
992
15.3k
    char *at = strchr (symbol, '@');
993
994
15.3k
    if (at != NULL)
995
3.96k
      len = at - symbol;
996
15.3k
  }
997
998
40.6k
      id6->contents[0] = ordinal & 0xff;
999
40.6k
      id6->contents[1] = ordinal >> 8;
1000
1001
40.6k
      memcpy ((char *) id6->contents + 2, symbol, len);
1002
40.6k
      id6->contents[len + 2] = '\0';
1003
40.6k
    }
1004
1005
55.8k
  if (import_name_type != IMPORT_ORDINAL)
1006
40.6k
    {
1007
40.6k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1008
40.6k
      pe_ILF_save_relocs (&vars, id4);
1009
1010
40.6k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1011
40.6k
      pe_ILF_save_relocs (&vars, id5);
1012
40.6k
    }
1013
1014
  /* Create an import symbol.  */
1015
55.8k
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1016
55.8k
  imp_sym   = vars.sym_ptr_ptr - 1;
1017
55.8k
  imp_index = vars.sym_index - 1;
1018
1019
  /* Create extra sections depending upon the type of import we are
1020
     dealing with.  */
1021
55.8k
  switch (import_type)
1022
55.8k
    {
1023
0
      int i;
1024
1025
23.6k
    case IMPORT_CODE:
1026
      /* CODE functions are special, in that they get a trampoline that
1027
   jumps to the main import symbol.  Create a .text section to hold it.
1028
   First we need to look up its contents in the jump table.  */
1029
52.0k
      for (i = NUM_ENTRIES (jtab); i--;)
1030
52.0k
  {
1031
52.0k
    if (jtab[i].size == 0)
1032
23.6k
      continue;
1033
28.4k
    if (jtab[i].magic == magic)
1034
23.6k
      break;
1035
28.4k
  }
1036
      /* If we did not find a matching entry something is wrong.  */
1037
23.6k
      if (i < 0)
1038
0
  abort ();
1039
1040
      /* Create the .text section.  */
1041
23.6k
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1042
23.6k
      if (text == NULL)
1043
0
  goto error_return;
1044
1045
      /* Copy in the jump code.  */
1046
23.6k
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1047
1048
      /* Create a reloc for the data in the text section.  */
1049
#ifdef MIPS_ARCH_MAGIC_WINCE
1050
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1051
  {
1052
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1053
              (struct bfd_symbol **) imp_sym,
1054
              imp_index);
1055
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1056
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1057
              (struct bfd_symbol **) imp_sym,
1058
              imp_index);
1059
  }
1060
      else
1061
#endif
1062
#ifdef AMD64MAGIC
1063
2.72k
      if (magic == AMD64MAGIC)
1064
2.72k
  {
1065
2.72k
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1066
2.72k
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1067
2.72k
              imp_index);
1068
2.72k
  }
1069
0
      else
1070
0
#endif
1071
0
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1072
0
            BFD_RELOC_32, (asymbol **) imp_sym,
1073
0
            imp_index);
1074
1075
23.6k
      pe_ILF_save_relocs (&vars, text);
1076
23.6k
      break;
1077
1078
18.2k
    case IMPORT_DATA:
1079
32.2k
    case IMPORT_CONST:
1080
32.2k
      break;
1081
1082
0
    default:
1083
      /* XXX code not yet written.  */
1084
0
      abort ();
1085
55.8k
    }
1086
1087
  /* Now create a symbol describing the imported value.  */
1088
55.8k
  switch (import_type)
1089
55.8k
    {
1090
23.6k
    case IMPORT_CODE:
1091
23.6k
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1092
23.6k
          BSF_NOT_AT_END | BSF_FUNCTION);
1093
1094
23.6k
      break;
1095
1096
18.2k
    case IMPORT_DATA:
1097
      /* Nothing to do here.  */
1098
18.2k
      break;
1099
1100
13.9k
    case IMPORT_CONST:
1101
13.9k
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1102
13.9k
      break;
1103
1104
0
    default:
1105
      /* XXX code not yet written.  */
1106
0
      abort ();
1107
55.8k
    }
1108
1109
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1110
55.8k
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1111
55.8k
  if (ptr)
1112
7.99k
    *ptr = 0;
1113
55.8k
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1114
55.8k
  if (ptr)
1115
7.99k
    *ptr = '.';
1116
1117
  /* Initialise the bfd.  */
1118
55.8k
  memset (&internal_f, 0, sizeof (internal_f));
1119
1120
55.8k
  internal_f.f_magic  = magic;
1121
55.8k
  internal_f.f_symptr = 0;
1122
55.8k
  internal_f.f_nsyms  = 0;
1123
55.8k
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1124
1125
55.8k
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1126
55.8k
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1127
0
    goto error_return;
1128
1129
55.8k
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1130
0
    goto error_return;
1131
1132
55.8k
  obj_pe (abfd) = true;
1133
#ifdef THUMBPEMAGIC
1134
13.3k
  if (vars.magic == THUMBPEMAGIC)
1135
    /* Stop some linker warnings about thumb code not supporting
1136
       interworking.  */
1137
3.58k
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1138
#endif
1139
1140
  /* Switch from file contents to memory contents.  */
1141
55.8k
  bfd_cache_close (abfd);
1142
1143
55.8k
  abfd->iostream = (void *) vars.bim;
1144
55.8k
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1145
55.8k
  abfd->iovec = &_bfd_memory_iovec;
1146
55.8k
  abfd->where = 0;
1147
55.8k
  abfd->origin = 0;
1148
55.8k
  abfd->size = 0;
1149
55.8k
  obj_sym_filepos (abfd) = 0;
1150
1151
  /* Point the bfd at the symbol table.  */
1152
55.8k
  obj_symbols (abfd) = vars.sym_cache;
1153
55.8k
  abfd->symcount = vars.sym_index;
1154
1155
55.8k
  obj_raw_syments (abfd) = vars.native_syms;
1156
55.8k
  obj_raw_syment_count (abfd) = vars.sym_index;
1157
55.8k
  obj_coff_keep_raw_syms (abfd) = true;
1158
1159
55.8k
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1160
55.8k
  obj_coff_keep_syms (abfd) = true;
1161
1162
55.8k
  obj_convert (abfd) = vars.sym_table;
1163
55.8k
  obj_conv_table_size (abfd) = vars.sym_index;
1164
1165
55.8k
  obj_coff_strings (abfd) = vars.string_table;
1166
55.8k
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1167
55.8k
  obj_coff_keep_strings (abfd) = true;
1168
1169
55.8k
  return true;
1170
1171
3.00k
 error_return:
1172
3.00k
  free (vars.bim->buffer);
1173
3.00k
  free (vars.bim);
1174
3.00k
  return false;
1175
55.8k
}
pei-i386.c:pe_ILF_build_a_bfd
Line
Count
Source
799
10.6k
{
800
10.6k
  bfd_byte *       ptr;
801
10.6k
  pe_ILF_vars      vars;
802
10.6k
  struct internal_filehdr  internal_f;
803
10.6k
  unsigned int       import_type;
804
10.6k
  unsigned int       import_name_type;
805
10.6k
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
806
10.6k
  coff_symbol_type **    imp_sym;
807
10.6k
  unsigned int       imp_index;
808
10.6k
  intptr_t alignment;
809
810
  /* Decode and verify the types field of the ILF structure.  */
811
10.6k
  import_type = types & 0x3;
812
10.6k
  import_name_type = (types & 0x1c) >> 2;
813
814
10.6k
  switch (import_type)
815
10.6k
    {
816
4.23k
    case IMPORT_CODE:
817
8.95k
    case IMPORT_DATA:
818
10.2k
    case IMPORT_CONST:
819
10.2k
      break;
820
821
412
    default:
822
      /* xgettext:c-format */
823
412
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
824
412
        abfd, import_type);
825
412
      return false;
826
10.6k
    }
827
828
10.2k
  switch (import_name_type)
829
10.2k
    {
830
2.34k
    case IMPORT_ORDINAL:
831
3.53k
    case IMPORT_NAME:
832
6.29k
    case IMPORT_NAME_NOPREFIX:
833
8.71k
    case IMPORT_NAME_UNDECORATE:
834
8.71k
      import_name = symbol_name;
835
8.71k
      break;
836
837
1.20k
    case IMPORT_NAME_EXPORTAS:
838
1.20k
      if (!import_name || !import_name[0])
839
526
  {
840
526
    _bfd_error_handler (_("%pB: missing import name for "
841
526
        "IMPORT_NAME_EXPORTAS for %s"),
842
526
            abfd, symbol_name);
843
526
    return false;
844
526
  }
845
677
      break;
846
847
677
    default:
848
      /* xgettext:c-format */
849
312
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
850
312
        abfd, import_name_type);
851
312
      return false;
852
10.2k
    }
853
854
  /* Initialise local variables.
855
856
     Note these are kept in a structure rather than being
857
     declared as statics since bfd frowns on global variables.
858
859
     We are going to construct the contents of the BFD in memory,
860
     so allocate all the space that we will need right now.  */
861
9.39k
  vars.bim
862
9.39k
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
863
9.39k
  if (vars.bim == NULL)
864
0
    return false;
865
866
9.39k
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
867
9.39k
  vars.bim->buffer = ptr;
868
9.39k
  vars.bim->size   = ILF_DATA_SIZE;
869
9.39k
  if (ptr == NULL)
870
0
    goto error_return;
871
872
  /* Initialise the pointers to regions of the memory and the
873
     other contents of the pe_ILF_vars structure as well.  */
874
9.39k
  vars.sym_cache = (coff_symbol_type *) ptr;
875
9.39k
  vars.sym_ptr   = (coff_symbol_type *) ptr;
876
9.39k
  vars.sym_index = 0;
877
9.39k
  ptr += SIZEOF_ILF_SYMS;
878
879
9.39k
  vars.sym_table = (unsigned int *) ptr;
880
9.39k
  vars.table_ptr = (unsigned int *) ptr;
881
9.39k
  ptr += SIZEOF_ILF_SYM_TABLE;
882
883
9.39k
  vars.native_syms = (combined_entry_type *) ptr;
884
9.39k
  vars.native_ptr  = (combined_entry_type *) ptr;
885
9.39k
  ptr += SIZEOF_ILF_NATIVE_SYMS;
886
887
9.39k
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
888
9.39k
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
889
9.39k
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
890
891
9.39k
  vars.esym_table = (SYMENT *) ptr;
892
9.39k
  vars.esym_ptr   = (SYMENT *) ptr;
893
9.39k
  ptr += SIZEOF_ILF_EXT_SYMS;
894
895
9.39k
  vars.reltab   = (arelent *) ptr;
896
9.39k
  vars.relcount = 0;
897
9.39k
  ptr += SIZEOF_ILF_RELOCS;
898
899
9.39k
  vars.int_reltab  = (struct internal_reloc *) ptr;
900
9.39k
  ptr += SIZEOF_ILF_INT_RELOCS;
901
902
9.39k
  vars.string_table = (char *) ptr;
903
9.39k
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
904
9.39k
  ptr += SIZEOF_ILF_STRINGS;
905
9.39k
  vars.end_string_ptr = (char *) ptr;
906
907
  /* The remaining space in bim->buffer is used
908
     by the pe_ILF_make_a_section() function.  */
909
910
  /* PR 18758: Make sure that the data area is sufficiently aligned for
911
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
912
     the test of GCC_VERSION.  For other compilers we assume 8 byte
913
     alignment.  */
914
9.39k
#if GCC_VERSION >= 3000
915
9.39k
  alignment = __alignof__ (struct coff_section_tdata);
916
#else
917
  alignment = 8;
918
#endif
919
9.39k
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
920
921
9.39k
  vars.data = ptr;
922
9.39k
  vars.abfd = abfd;
923
9.39k
  vars.sec_index = 0;
924
9.39k
  vars.magic = magic;
925
926
  /* Create the initial .idata$<n> sections:
927
     [.idata$2:  Import Directory Table -- not needed]
928
     .idata$4:  Import Lookup Table
929
     .idata$5:  Import Address Table
930
931
     Note we do not create a .idata$3 section as this is
932
     created for us by the linker script.  */
933
9.39k
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
934
9.39k
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
935
9.39k
  if (id4 == NULL || id5 == NULL)
936
0
    goto error_return;
937
938
  /* Fill in the contents of these sections.  */
939
9.39k
  if (import_name_type == IMPORT_ORDINAL)
940
2.34k
    {
941
2.34k
      if (ordinal == 0)
942
  /* See PR 20907 for a reproducer.  */
943
315
  goto error_return;
944
945
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
946
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
947
      ((unsigned int *) id4->contents)[0] = ordinal;
948
      ((unsigned int *) id4->contents)[1] = 0x80000000;
949
      ((unsigned int *) id5->contents)[0] = ordinal;
950
      ((unsigned int *) id5->contents)[1] = 0x80000000;
951
#else
952
2.03k
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
953
2.03k
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
954
2.03k
#endif
955
2.03k
    }
956
7.04k
  else
957
7.04k
    {
958
7.04k
      char *symbol;
959
7.04k
      unsigned int len;
960
961
      /* Create .idata$6 - the Hint Name Table.  */
962
7.04k
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
963
7.04k
      if (id6 == NULL)
964
0
  goto error_return;
965
966
      /* If necessary, trim the import symbol name.  */
967
7.04k
      symbol = import_name;
968
969
      /* As used by MS compiler, '_', '@', and '?' are alternative
970
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
971
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
972
   of these is used for a symbol.  We strip this leading char for
973
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
974
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
975
976
7.04k
      if (import_name_type != IMPORT_NAME
977
7.04k
    && import_name_type != IMPORT_NAME_EXPORTAS)
978
5.18k
  {
979
5.18k
    char c = symbol[0];
980
981
    /* Check that we don't remove for targets with empty
982
       USER_LABEL_PREFIX the leading underscore.  */
983
5.18k
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
984
5.18k
        || c == '@' || c == '?')
985
1.94k
      symbol++;
986
5.18k
  }
987
988
7.04k
      len = strlen (symbol);
989
7.04k
      if (import_name_type == IMPORT_NAME_UNDECORATE)
990
2.42k
  {
991
    /* Truncate at the first '@'.  */
992
2.42k
    char *at = strchr (symbol, '@');
993
994
2.42k
    if (at != NULL)
995
905
      len = at - symbol;
996
2.42k
  }
997
998
7.04k
      id6->contents[0] = ordinal & 0xff;
999
7.04k
      id6->contents[1] = ordinal >> 8;
1000
1001
7.04k
      memcpy ((char *) id6->contents + 2, symbol, len);
1002
7.04k
      id6->contents[len + 2] = '\0';
1003
7.04k
    }
1004
1005
9.07k
  if (import_name_type != IMPORT_ORDINAL)
1006
7.04k
    {
1007
7.04k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1008
7.04k
      pe_ILF_save_relocs (&vars, id4);
1009
1010
7.04k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1011
7.04k
      pe_ILF_save_relocs (&vars, id5);
1012
7.04k
    }
1013
1014
  /* Create an import symbol.  */
1015
9.07k
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1016
9.07k
  imp_sym   = vars.sym_ptr_ptr - 1;
1017
9.07k
  imp_index = vars.sym_index - 1;
1018
1019
  /* Create extra sections depending upon the type of import we are
1020
     dealing with.  */
1021
9.07k
  switch (import_type)
1022
9.07k
    {
1023
0
      int i;
1024
1025
3.80k
    case IMPORT_CODE:
1026
      /* CODE functions are special, in that they get a trampoline that
1027
   jumps to the main import symbol.  Create a .text section to hold it.
1028
   First we need to look up its contents in the jump table.  */
1029
7.61k
      for (i = NUM_ENTRIES (jtab); i--;)
1030
7.61k
  {
1031
7.61k
    if (jtab[i].size == 0)
1032
3.80k
      continue;
1033
3.80k
    if (jtab[i].magic == magic)
1034
3.80k
      break;
1035
3.80k
  }
1036
      /* If we did not find a matching entry something is wrong.  */
1037
3.80k
      if (i < 0)
1038
0
  abort ();
1039
1040
      /* Create the .text section.  */
1041
3.80k
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1042
3.80k
      if (text == NULL)
1043
0
  goto error_return;
1044
1045
      /* Copy in the jump code.  */
1046
3.80k
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1047
1048
      /* Create a reloc for the data in the text section.  */
1049
#ifdef MIPS_ARCH_MAGIC_WINCE
1050
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1051
  {
1052
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1053
              (struct bfd_symbol **) imp_sym,
1054
              imp_index);
1055
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1056
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1057
              (struct bfd_symbol **) imp_sym,
1058
              imp_index);
1059
  }
1060
      else
1061
#endif
1062
#ifdef AMD64MAGIC
1063
      if (magic == AMD64MAGIC)
1064
  {
1065
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1066
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1067
              imp_index);
1068
  }
1069
      else
1070
#endif
1071
3.80k
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1072
3.80k
            BFD_RELOC_32, (asymbol **) imp_sym,
1073
3.80k
            imp_index);
1074
1075
3.80k
      pe_ILF_save_relocs (&vars, text);
1076
3.80k
      break;
1077
1078
4.11k
    case IMPORT_DATA:
1079
5.26k
    case IMPORT_CONST:
1080
5.26k
      break;
1081
1082
0
    default:
1083
      /* XXX code not yet written.  */
1084
0
      abort ();
1085
9.07k
    }
1086
1087
  /* Now create a symbol describing the imported value.  */
1088
9.07k
  switch (import_type)
1089
9.07k
    {
1090
3.80k
    case IMPORT_CODE:
1091
3.80k
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1092
3.80k
          BSF_NOT_AT_END | BSF_FUNCTION);
1093
1094
3.80k
      break;
1095
1096
4.11k
    case IMPORT_DATA:
1097
      /* Nothing to do here.  */
1098
4.11k
      break;
1099
1100
1.15k
    case IMPORT_CONST:
1101
1.15k
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1102
1.15k
      break;
1103
1104
0
    default:
1105
      /* XXX code not yet written.  */
1106
0
      abort ();
1107
9.07k
    }
1108
1109
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1110
9.07k
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1111
9.07k
  if (ptr)
1112
1.44k
    *ptr = 0;
1113
9.07k
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1114
9.07k
  if (ptr)
1115
1.44k
    *ptr = '.';
1116
1117
  /* Initialise the bfd.  */
1118
9.07k
  memset (&internal_f, 0, sizeof (internal_f));
1119
1120
9.07k
  internal_f.f_magic  = magic;
1121
9.07k
  internal_f.f_symptr = 0;
1122
9.07k
  internal_f.f_nsyms  = 0;
1123
9.07k
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1124
1125
9.07k
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1126
9.07k
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1127
0
    goto error_return;
1128
1129
9.07k
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1130
0
    goto error_return;
1131
1132
9.07k
  obj_pe (abfd) = true;
1133
#ifdef THUMBPEMAGIC
1134
  if (vars.magic == THUMBPEMAGIC)
1135
    /* Stop some linker warnings about thumb code not supporting
1136
       interworking.  */
1137
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1138
#endif
1139
1140
  /* Switch from file contents to memory contents.  */
1141
9.07k
  bfd_cache_close (abfd);
1142
1143
9.07k
  abfd->iostream = (void *) vars.bim;
1144
9.07k
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1145
9.07k
  abfd->iovec = &_bfd_memory_iovec;
1146
9.07k
  abfd->where = 0;
1147
9.07k
  abfd->origin = 0;
1148
9.07k
  abfd->size = 0;
1149
9.07k
  obj_sym_filepos (abfd) = 0;
1150
1151
  /* Point the bfd at the symbol table.  */
1152
9.07k
  obj_symbols (abfd) = vars.sym_cache;
1153
9.07k
  abfd->symcount = vars.sym_index;
1154
1155
9.07k
  obj_raw_syments (abfd) = vars.native_syms;
1156
9.07k
  obj_raw_syment_count (abfd) = vars.sym_index;
1157
9.07k
  obj_coff_keep_raw_syms (abfd) = true;
1158
1159
9.07k
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1160
9.07k
  obj_coff_keep_syms (abfd) = true;
1161
1162
9.07k
  obj_convert (abfd) = vars.sym_table;
1163
9.07k
  obj_conv_table_size (abfd) = vars.sym_index;
1164
1165
9.07k
  obj_coff_strings (abfd) = vars.string_table;
1166
9.07k
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1167
9.07k
  obj_coff_keep_strings (abfd) = true;
1168
1169
9.07k
  return true;
1170
1171
315
 error_return:
1172
315
  free (vars.bim->buffer);
1173
315
  free (vars.bim);
1174
315
  return false;
1175
9.07k
}
pei-x86_64.c:pe_ILF_build_a_bfd
Line
Count
Source
799
8.35k
{
800
8.35k
  bfd_byte *       ptr;
801
8.35k
  pe_ILF_vars      vars;
802
8.35k
  struct internal_filehdr  internal_f;
803
8.35k
  unsigned int       import_type;
804
8.35k
  unsigned int       import_name_type;
805
8.35k
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
806
8.35k
  coff_symbol_type **    imp_sym;
807
8.35k
  unsigned int       imp_index;
808
8.35k
  intptr_t alignment;
809
810
  /* Decode and verify the types field of the ILF structure.  */
811
8.35k
  import_type = types & 0x3;
812
8.35k
  import_name_type = (types & 0x1c) >> 2;
813
814
8.35k
  switch (import_type)
815
8.35k
    {
816
3.45k
    case IMPORT_CODE:
817
5.78k
    case IMPORT_DATA:
818
8.04k
    case IMPORT_CONST:
819
8.04k
      break;
820
821
310
    default:
822
      /* xgettext:c-format */
823
310
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
824
310
        abfd, import_type);
825
310
      return false;
826
8.35k
    }
827
828
8.04k
  switch (import_name_type)
829
8.04k
    {
830
2.30k
    case IMPORT_ORDINAL:
831
2.97k
    case IMPORT_NAME:
832
4.42k
    case IMPORT_NAME_NOPREFIX:
833
6.54k
    case IMPORT_NAME_UNDECORATE:
834
6.54k
      import_name = symbol_name;
835
6.54k
      break;
836
837
1.19k
    case IMPORT_NAME_EXPORTAS:
838
1.19k
      if (!import_name || !import_name[0])
839
621
  {
840
621
    _bfd_error_handler (_("%pB: missing import name for "
841
621
        "IMPORT_NAME_EXPORTAS for %s"),
842
621
            abfd, symbol_name);
843
621
    return false;
844
621
  }
845
571
      break;
846
847
571
    default:
848
      /* xgettext:c-format */
849
310
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
850
310
        abfd, import_name_type);
851
310
      return false;
852
8.04k
    }
853
854
  /* Initialise local variables.
855
856
     Note these are kept in a structure rather than being
857
     declared as statics since bfd frowns on global variables.
858
859
     We are going to construct the contents of the BFD in memory,
860
     so allocate all the space that we will need right now.  */
861
7.11k
  vars.bim
862
7.11k
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
863
7.11k
  if (vars.bim == NULL)
864
0
    return false;
865
866
7.11k
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
867
7.11k
  vars.bim->buffer = ptr;
868
7.11k
  vars.bim->size   = ILF_DATA_SIZE;
869
7.11k
  if (ptr == NULL)
870
0
    goto error_return;
871
872
  /* Initialise the pointers to regions of the memory and the
873
     other contents of the pe_ILF_vars structure as well.  */
874
7.11k
  vars.sym_cache = (coff_symbol_type *) ptr;
875
7.11k
  vars.sym_ptr   = (coff_symbol_type *) ptr;
876
7.11k
  vars.sym_index = 0;
877
7.11k
  ptr += SIZEOF_ILF_SYMS;
878
879
7.11k
  vars.sym_table = (unsigned int *) ptr;
880
7.11k
  vars.table_ptr = (unsigned int *) ptr;
881
7.11k
  ptr += SIZEOF_ILF_SYM_TABLE;
882
883
7.11k
  vars.native_syms = (combined_entry_type *) ptr;
884
7.11k
  vars.native_ptr  = (combined_entry_type *) ptr;
885
7.11k
  ptr += SIZEOF_ILF_NATIVE_SYMS;
886
887
7.11k
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
888
7.11k
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
889
7.11k
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
890
891
7.11k
  vars.esym_table = (SYMENT *) ptr;
892
7.11k
  vars.esym_ptr   = (SYMENT *) ptr;
893
7.11k
  ptr += SIZEOF_ILF_EXT_SYMS;
894
895
7.11k
  vars.reltab   = (arelent *) ptr;
896
7.11k
  vars.relcount = 0;
897
7.11k
  ptr += SIZEOF_ILF_RELOCS;
898
899
7.11k
  vars.int_reltab  = (struct internal_reloc *) ptr;
900
7.11k
  ptr += SIZEOF_ILF_INT_RELOCS;
901
902
7.11k
  vars.string_table = (char *) ptr;
903
7.11k
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
904
7.11k
  ptr += SIZEOF_ILF_STRINGS;
905
7.11k
  vars.end_string_ptr = (char *) ptr;
906
907
  /* The remaining space in bim->buffer is used
908
     by the pe_ILF_make_a_section() function.  */
909
910
  /* PR 18758: Make sure that the data area is sufficiently aligned for
911
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
912
     the test of GCC_VERSION.  For other compilers we assume 8 byte
913
     alignment.  */
914
7.11k
#if GCC_VERSION >= 3000
915
7.11k
  alignment = __alignof__ (struct coff_section_tdata);
916
#else
917
  alignment = 8;
918
#endif
919
7.11k
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
920
921
7.11k
  vars.data = ptr;
922
7.11k
  vars.abfd = abfd;
923
7.11k
  vars.sec_index = 0;
924
7.11k
  vars.magic = magic;
925
926
  /* Create the initial .idata$<n> sections:
927
     [.idata$2:  Import Directory Table -- not needed]
928
     .idata$4:  Import Lookup Table
929
     .idata$5:  Import Address Table
930
931
     Note we do not create a .idata$3 section as this is
932
     created for us by the linker script.  */
933
7.11k
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
934
7.11k
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
935
7.11k
  if (id4 == NULL || id5 == NULL)
936
0
    goto error_return;
937
938
  /* Fill in the contents of these sections.  */
939
7.11k
  if (import_name_type == IMPORT_ORDINAL)
940
2.30k
    {
941
2.30k
      if (ordinal == 0)
942
  /* See PR 20907 for a reproducer.  */
943
310
  goto error_return;
944
945
1.99k
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
946
1.99k
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
947
1.99k
      ((unsigned int *) id4->contents)[0] = ordinal;
948
1.99k
      ((unsigned int *) id4->contents)[1] = 0x80000000;
949
1.99k
      ((unsigned int *) id5->contents)[0] = ordinal;
950
1.99k
      ((unsigned int *) id5->contents)[1] = 0x80000000;
951
#else
952
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
953
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
954
#endif
955
1.99k
    }
956
4.81k
  else
957
4.81k
    {
958
4.81k
      char *symbol;
959
4.81k
      unsigned int len;
960
961
      /* Create .idata$6 - the Hint Name Table.  */
962
4.81k
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
963
4.81k
      if (id6 == NULL)
964
0
  goto error_return;
965
966
      /* If necessary, trim the import symbol name.  */
967
4.81k
      symbol = import_name;
968
969
      /* As used by MS compiler, '_', '@', and '?' are alternative
970
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
971
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
972
   of these is used for a symbol.  We strip this leading char for
973
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
974
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
975
976
4.81k
      if (import_name_type != IMPORT_NAME
977
4.81k
    && import_name_type != IMPORT_NAME_EXPORTAS)
978
3.56k
  {
979
3.56k
    char c = symbol[0];
980
981
    /* Check that we don't remove for targets with empty
982
       USER_LABEL_PREFIX the leading underscore.  */
983
3.56k
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
984
3.56k
        || c == '@' || c == '?')
985
574
      symbol++;
986
3.56k
  }
987
988
4.81k
      len = strlen (symbol);
989
4.81k
      if (import_name_type == IMPORT_NAME_UNDECORATE)
990
2.11k
  {
991
    /* Truncate at the first '@'.  */
992
2.11k
    char *at = strchr (symbol, '@');
993
994
2.11k
    if (at != NULL)
995
335
      len = at - symbol;
996
2.11k
  }
997
998
4.81k
      id6->contents[0] = ordinal & 0xff;
999
4.81k
      id6->contents[1] = ordinal >> 8;
1000
1001
4.81k
      memcpy ((char *) id6->contents + 2, symbol, len);
1002
4.81k
      id6->contents[len + 2] = '\0';
1003
4.81k
    }
1004
1005
6.80k
  if (import_name_type != IMPORT_ORDINAL)
1006
4.81k
    {
1007
4.81k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1008
4.81k
      pe_ILF_save_relocs (&vars, id4);
1009
1010
4.81k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1011
4.81k
      pe_ILF_save_relocs (&vars, id5);
1012
4.81k
    }
1013
1014
  /* Create an import symbol.  */
1015
6.80k
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1016
6.80k
  imp_sym   = vars.sym_ptr_ptr - 1;
1017
6.80k
  imp_index = vars.sym_index - 1;
1018
1019
  /* Create extra sections depending upon the type of import we are
1020
     dealing with.  */
1021
6.80k
  switch (import_type)
1022
6.80k
    {
1023
0
      int i;
1024
1025
2.72k
    case IMPORT_CODE:
1026
      /* CODE functions are special, in that they get a trampoline that
1027
   jumps to the main import symbol.  Create a .text section to hold it.
1028
   First we need to look up its contents in the jump table.  */
1029
5.44k
      for (i = NUM_ENTRIES (jtab); i--;)
1030
5.44k
  {
1031
5.44k
    if (jtab[i].size == 0)
1032
2.72k
      continue;
1033
2.72k
    if (jtab[i].magic == magic)
1034
2.72k
      break;
1035
2.72k
  }
1036
      /* If we did not find a matching entry something is wrong.  */
1037
2.72k
      if (i < 0)
1038
0
  abort ();
1039
1040
      /* Create the .text section.  */
1041
2.72k
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1042
2.72k
      if (text == NULL)
1043
0
  goto error_return;
1044
1045
      /* Copy in the jump code.  */
1046
2.72k
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1047
1048
      /* Create a reloc for the data in the text section.  */
1049
#ifdef MIPS_ARCH_MAGIC_WINCE
1050
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1051
  {
1052
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1053
              (struct bfd_symbol **) imp_sym,
1054
              imp_index);
1055
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1056
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1057
              (struct bfd_symbol **) imp_sym,
1058
              imp_index);
1059
  }
1060
      else
1061
#endif
1062
2.72k
#ifdef AMD64MAGIC
1063
2.72k
      if (magic == AMD64MAGIC)
1064
2.72k
  {
1065
2.72k
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1066
2.72k
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1067
2.72k
              imp_index);
1068
2.72k
  }
1069
0
      else
1070
0
#endif
1071
0
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1072
0
            BFD_RELOC_32, (asymbol **) imp_sym,
1073
0
            imp_index);
1074
1075
2.72k
      pe_ILF_save_relocs (&vars, text);
1076
2.72k
      break;
1077
1078
2.22k
    case IMPORT_DATA:
1079
4.07k
    case IMPORT_CONST:
1080
4.07k
      break;
1081
1082
0
    default:
1083
      /* XXX code not yet written.  */
1084
0
      abort ();
1085
6.80k
    }
1086
1087
  /* Now create a symbol describing the imported value.  */
1088
6.80k
  switch (import_type)
1089
6.80k
    {
1090
2.72k
    case IMPORT_CODE:
1091
2.72k
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1092
2.72k
          BSF_NOT_AT_END | BSF_FUNCTION);
1093
1094
2.72k
      break;
1095
1096
2.22k
    case IMPORT_DATA:
1097
      /* Nothing to do here.  */
1098
2.22k
      break;
1099
1100
1.84k
    case IMPORT_CONST:
1101
1.84k
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1102
1.84k
      break;
1103
1104
0
    default:
1105
      /* XXX code not yet written.  */
1106
0
      abort ();
1107
6.80k
    }
1108
1109
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1110
6.80k
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1111
6.80k
  if (ptr)
1112
1.44k
    *ptr = 0;
1113
6.80k
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1114
6.80k
  if (ptr)
1115
1.44k
    *ptr = '.';
1116
1117
  /* Initialise the bfd.  */
1118
6.80k
  memset (&internal_f, 0, sizeof (internal_f));
1119
1120
6.80k
  internal_f.f_magic  = magic;
1121
6.80k
  internal_f.f_symptr = 0;
1122
6.80k
  internal_f.f_nsyms  = 0;
1123
6.80k
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1124
1125
6.80k
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1126
6.80k
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1127
0
    goto error_return;
1128
1129
6.80k
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1130
0
    goto error_return;
1131
1132
6.80k
  obj_pe (abfd) = true;
1133
#ifdef THUMBPEMAGIC
1134
  if (vars.magic == THUMBPEMAGIC)
1135
    /* Stop some linker warnings about thumb code not supporting
1136
       interworking.  */
1137
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1138
#endif
1139
1140
  /* Switch from file contents to memory contents.  */
1141
6.80k
  bfd_cache_close (abfd);
1142
1143
6.80k
  abfd->iostream = (void *) vars.bim;
1144
6.80k
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1145
6.80k
  abfd->iovec = &_bfd_memory_iovec;
1146
6.80k
  abfd->where = 0;
1147
6.80k
  abfd->origin = 0;
1148
6.80k
  abfd->size = 0;
1149
6.80k
  obj_sym_filepos (abfd) = 0;
1150
1151
  /* Point the bfd at the symbol table.  */
1152
6.80k
  obj_symbols (abfd) = vars.sym_cache;
1153
6.80k
  abfd->symcount = vars.sym_index;
1154
1155
6.80k
  obj_raw_syments (abfd) = vars.native_syms;
1156
6.80k
  obj_raw_syment_count (abfd) = vars.sym_index;
1157
6.80k
  obj_coff_keep_raw_syms (abfd) = true;
1158
1159
6.80k
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1160
6.80k
  obj_coff_keep_syms (abfd) = true;
1161
1162
6.80k
  obj_convert (abfd) = vars.sym_table;
1163
6.80k
  obj_conv_table_size (abfd) = vars.sym_index;
1164
1165
6.80k
  obj_coff_strings (abfd) = vars.string_table;
1166
6.80k
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1167
6.80k
  obj_coff_keep_strings (abfd) = true;
1168
1169
6.80k
  return true;
1170
1171
310
 error_return:
1172
310
  free (vars.bim->buffer);
1173
310
  free (vars.bim);
1174
310
  return false;
1175
6.80k
}
pei-aarch64.c:pe_ILF_build_a_bfd
Line
Count
Source
799
7.35k
{
800
7.35k
  bfd_byte *       ptr;
801
7.35k
  pe_ILF_vars      vars;
802
7.35k
  struct internal_filehdr  internal_f;
803
7.35k
  unsigned int       import_type;
804
7.35k
  unsigned int       import_name_type;
805
7.35k
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
806
7.35k
  coff_symbol_type **    imp_sym;
807
7.35k
  unsigned int       imp_index;
808
7.35k
  intptr_t alignment;
809
810
  /* Decode and verify the types field of the ILF structure.  */
811
7.35k
  import_type = types & 0x3;
812
7.35k
  import_name_type = (types & 0x1c) >> 2;
813
814
7.35k
  switch (import_type)
815
7.35k
    {
816
3.19k
    case IMPORT_CODE:
817
5.45k
    case IMPORT_DATA:
818
7.04k
    case IMPORT_CONST:
819
7.04k
      break;
820
821
312
    default:
822
      /* xgettext:c-format */
823
312
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
824
312
        abfd, import_type);
825
312
      return false;
826
7.35k
    }
827
828
7.04k
  switch (import_name_type)
829
7.04k
    {
830
1.63k
    case IMPORT_ORDINAL:
831
2.57k
    case IMPORT_NAME:
832
3.35k
    case IMPORT_NAME_NOPREFIX:
833
5.53k
    case IMPORT_NAME_UNDECORATE:
834
5.53k
      import_name = symbol_name;
835
5.53k
      break;
836
837
1.29k
    case IMPORT_NAME_EXPORTAS:
838
1.29k
      if (!import_name || !import_name[0])
839
422
  {
840
422
    _bfd_error_handler (_("%pB: missing import name for "
841
422
        "IMPORT_NAME_EXPORTAS for %s"),
842
422
            abfd, symbol_name);
843
422
    return false;
844
422
  }
845
873
      break;
846
847
873
    default:
848
      /* xgettext:c-format */
849
209
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
850
209
        abfd, import_name_type);
851
209
      return false;
852
7.04k
    }
853
854
  /* Initialise local variables.
855
856
     Note these are kept in a structure rather than being
857
     declared as statics since bfd frowns on global variables.
858
859
     We are going to construct the contents of the BFD in memory,
860
     so allocate all the space that we will need right now.  */
861
6.41k
  vars.bim
862
6.41k
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
863
6.41k
  if (vars.bim == NULL)
864
0
    return false;
865
866
6.41k
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
867
6.41k
  vars.bim->buffer = ptr;
868
6.41k
  vars.bim->size   = ILF_DATA_SIZE;
869
6.41k
  if (ptr == NULL)
870
0
    goto error_return;
871
872
  /* Initialise the pointers to regions of the memory and the
873
     other contents of the pe_ILF_vars structure as well.  */
874
6.41k
  vars.sym_cache = (coff_symbol_type *) ptr;
875
6.41k
  vars.sym_ptr   = (coff_symbol_type *) ptr;
876
6.41k
  vars.sym_index = 0;
877
6.41k
  ptr += SIZEOF_ILF_SYMS;
878
879
6.41k
  vars.sym_table = (unsigned int *) ptr;
880
6.41k
  vars.table_ptr = (unsigned int *) ptr;
881
6.41k
  ptr += SIZEOF_ILF_SYM_TABLE;
882
883
6.41k
  vars.native_syms = (combined_entry_type *) ptr;
884
6.41k
  vars.native_ptr  = (combined_entry_type *) ptr;
885
6.41k
  ptr += SIZEOF_ILF_NATIVE_SYMS;
886
887
6.41k
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
888
6.41k
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
889
6.41k
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
890
891
6.41k
  vars.esym_table = (SYMENT *) ptr;
892
6.41k
  vars.esym_ptr   = (SYMENT *) ptr;
893
6.41k
  ptr += SIZEOF_ILF_EXT_SYMS;
894
895
6.41k
  vars.reltab   = (arelent *) ptr;
896
6.41k
  vars.relcount = 0;
897
6.41k
  ptr += SIZEOF_ILF_RELOCS;
898
899
6.41k
  vars.int_reltab  = (struct internal_reloc *) ptr;
900
6.41k
  ptr += SIZEOF_ILF_INT_RELOCS;
901
902
6.41k
  vars.string_table = (char *) ptr;
903
6.41k
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
904
6.41k
  ptr += SIZEOF_ILF_STRINGS;
905
6.41k
  vars.end_string_ptr = (char *) ptr;
906
907
  /* The remaining space in bim->buffer is used
908
     by the pe_ILF_make_a_section() function.  */
909
910
  /* PR 18758: Make sure that the data area is sufficiently aligned for
911
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
912
     the test of GCC_VERSION.  For other compilers we assume 8 byte
913
     alignment.  */
914
6.41k
#if GCC_VERSION >= 3000
915
6.41k
  alignment = __alignof__ (struct coff_section_tdata);
916
#else
917
  alignment = 8;
918
#endif
919
6.41k
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
920
921
6.41k
  vars.data = ptr;
922
6.41k
  vars.abfd = abfd;
923
6.41k
  vars.sec_index = 0;
924
6.41k
  vars.magic = magic;
925
926
  /* Create the initial .idata$<n> sections:
927
     [.idata$2:  Import Directory Table -- not needed]
928
     .idata$4:  Import Lookup Table
929
     .idata$5:  Import Address Table
930
931
     Note we do not create a .idata$3 section as this is
932
     created for us by the linker script.  */
933
6.41k
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
934
6.41k
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
935
6.41k
  if (id4 == NULL || id5 == NULL)
936
0
    goto error_return;
937
938
  /* Fill in the contents of these sections.  */
939
6.41k
  if (import_name_type == IMPORT_ORDINAL)
940
1.63k
    {
941
1.63k
      if (ordinal == 0)
942
  /* See PR 20907 for a reproducer.  */
943
315
  goto error_return;
944
945
1.31k
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
946
1.31k
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
947
1.31k
      ((unsigned int *) id4->contents)[0] = ordinal;
948
1.31k
      ((unsigned int *) id4->contents)[1] = 0x80000000;
949
1.31k
      ((unsigned int *) id5->contents)[0] = ordinal;
950
1.31k
      ((unsigned int *) id5->contents)[1] = 0x80000000;
951
#else
952
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
953
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
954
#endif
955
1.31k
    }
956
4.77k
  else
957
4.77k
    {
958
4.77k
      char *symbol;
959
4.77k
      unsigned int len;
960
961
      /* Create .idata$6 - the Hint Name Table.  */
962
4.77k
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
963
4.77k
      if (id6 == NULL)
964
0
  goto error_return;
965
966
      /* If necessary, trim the import symbol name.  */
967
4.77k
      symbol = import_name;
968
969
      /* As used by MS compiler, '_', '@', and '?' are alternative
970
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
971
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
972
   of these is used for a symbol.  We strip this leading char for
973
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
974
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
975
976
4.77k
      if (import_name_type != IMPORT_NAME
977
4.77k
    && import_name_type != IMPORT_NAME_EXPORTAS)
978
2.96k
  {
979
2.96k
    char c = symbol[0];
980
981
    /* Check that we don't remove for targets with empty
982
       USER_LABEL_PREFIX the leading underscore.  */
983
2.96k
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
984
2.96k
        || c == '@' || c == '?')
985
473
      symbol++;
986
2.96k
  }
987
988
4.77k
      len = strlen (symbol);
989
4.77k
      if (import_name_type == IMPORT_NAME_UNDECORATE)
990
2.18k
  {
991
    /* Truncate at the first '@'.  */
992
2.18k
    char *at = strchr (symbol, '@');
993
994
2.18k
    if (at != NULL)
995
337
      len = at - symbol;
996
2.18k
  }
997
998
4.77k
      id6->contents[0] = ordinal & 0xff;
999
4.77k
      id6->contents[1] = ordinal >> 8;
1000
1001
4.77k
      memcpy ((char *) id6->contents + 2, symbol, len);
1002
4.77k
      id6->contents[len + 2] = '\0';
1003
4.77k
    }
1004
1005
6.09k
  if (import_name_type != IMPORT_ORDINAL)
1006
4.77k
    {
1007
4.77k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1008
4.77k
      pe_ILF_save_relocs (&vars, id4);
1009
1010
4.77k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1011
4.77k
      pe_ILF_save_relocs (&vars, id5);
1012
4.77k
    }
1013
1014
  /* Create an import symbol.  */
1015
6.09k
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1016
6.09k
  imp_sym   = vars.sym_ptr_ptr - 1;
1017
6.09k
  imp_index = vars.sym_index - 1;
1018
1019
  /* Create extra sections depending upon the type of import we are
1020
     dealing with.  */
1021
6.09k
  switch (import_type)
1022
6.09k
    {
1023
0
      int i;
1024
1025
2.76k
    case IMPORT_CODE:
1026
      /* CODE functions are special, in that they get a trampoline that
1027
   jumps to the main import symbol.  Create a .text section to hold it.
1028
   First we need to look up its contents in the jump table.  */
1029
5.53k
      for (i = NUM_ENTRIES (jtab); i--;)
1030
5.53k
  {
1031
5.53k
    if (jtab[i].size == 0)
1032
2.76k
      continue;
1033
2.76k
    if (jtab[i].magic == magic)
1034
2.76k
      break;
1035
2.76k
  }
1036
      /* If we did not find a matching entry something is wrong.  */
1037
2.76k
      if (i < 0)
1038
0
  abort ();
1039
1040
      /* Create the .text section.  */
1041
2.76k
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1042
2.76k
      if (text == NULL)
1043
0
  goto error_return;
1044
1045
      /* Copy in the jump code.  */
1046
2.76k
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1047
1048
      /* Create a reloc for the data in the text section.  */
1049
#ifdef MIPS_ARCH_MAGIC_WINCE
1050
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1051
  {
1052
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1053
              (struct bfd_symbol **) imp_sym,
1054
              imp_index);
1055
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1056
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1057
              (struct bfd_symbol **) imp_sym,
1058
              imp_index);
1059
  }
1060
      else
1061
#endif
1062
#ifdef AMD64MAGIC
1063
      if (magic == AMD64MAGIC)
1064
  {
1065
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1066
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1067
              imp_index);
1068
  }
1069
      else
1070
#endif
1071
2.76k
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1072
2.76k
            BFD_RELOC_32, (asymbol **) imp_sym,
1073
2.76k
            imp_index);
1074
1075
2.76k
      pe_ILF_save_relocs (&vars, text);
1076
2.76k
      break;
1077
1078
2.15k
    case IMPORT_DATA:
1079
3.33k
    case IMPORT_CONST:
1080
3.33k
      break;
1081
1082
0
    default:
1083
      /* XXX code not yet written.  */
1084
0
      abort ();
1085
6.09k
    }
1086
1087
  /* Now create a symbol describing the imported value.  */
1088
6.09k
  switch (import_type)
1089
6.09k
    {
1090
2.76k
    case IMPORT_CODE:
1091
2.76k
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1092
2.76k
          BSF_NOT_AT_END | BSF_FUNCTION);
1093
1094
2.76k
      break;
1095
1096
2.15k
    case IMPORT_DATA:
1097
      /* Nothing to do here.  */
1098
2.15k
      break;
1099
1100
1.17k
    case IMPORT_CONST:
1101
1.17k
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1102
1.17k
      break;
1103
1104
0
    default:
1105
      /* XXX code not yet written.  */
1106
0
      abort ();
1107
6.09k
    }
1108
1109
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1110
6.09k
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1111
6.09k
  if (ptr)
1112
909
    *ptr = 0;
1113
6.09k
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1114
6.09k
  if (ptr)
1115
909
    *ptr = '.';
1116
1117
  /* Initialise the bfd.  */
1118
6.09k
  memset (&internal_f, 0, sizeof (internal_f));
1119
1120
6.09k
  internal_f.f_magic  = magic;
1121
6.09k
  internal_f.f_symptr = 0;
1122
6.09k
  internal_f.f_nsyms  = 0;
1123
6.09k
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1124
1125
6.09k
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1126
6.09k
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1127
0
    goto error_return;
1128
1129
6.09k
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1130
0
    goto error_return;
1131
1132
6.09k
  obj_pe (abfd) = true;
1133
#ifdef THUMBPEMAGIC
1134
  if (vars.magic == THUMBPEMAGIC)
1135
    /* Stop some linker warnings about thumb code not supporting
1136
       interworking.  */
1137
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1138
#endif
1139
1140
  /* Switch from file contents to memory contents.  */
1141
6.09k
  bfd_cache_close (abfd);
1142
1143
6.09k
  abfd->iostream = (void *) vars.bim;
1144
6.09k
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1145
6.09k
  abfd->iovec = &_bfd_memory_iovec;
1146
6.09k
  abfd->where = 0;
1147
6.09k
  abfd->origin = 0;
1148
6.09k
  abfd->size = 0;
1149
6.09k
  obj_sym_filepos (abfd) = 0;
1150
1151
  /* Point the bfd at the symbol table.  */
1152
6.09k
  obj_symbols (abfd) = vars.sym_cache;
1153
6.09k
  abfd->symcount = vars.sym_index;
1154
1155
6.09k
  obj_raw_syments (abfd) = vars.native_syms;
1156
6.09k
  obj_raw_syment_count (abfd) = vars.sym_index;
1157
6.09k
  obj_coff_keep_raw_syms (abfd) = true;
1158
1159
6.09k
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1160
6.09k
  obj_coff_keep_syms (abfd) = true;
1161
1162
6.09k
  obj_convert (abfd) = vars.sym_table;
1163
6.09k
  obj_conv_table_size (abfd) = vars.sym_index;
1164
1165
6.09k
  obj_coff_strings (abfd) = vars.string_table;
1166
6.09k
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1167
6.09k
  obj_coff_keep_strings (abfd) = true;
1168
1169
6.09k
  return true;
1170
1171
315
 error_return:
1172
315
  free (vars.bim->buffer);
1173
315
  free (vars.bim);
1174
315
  return false;
1175
6.09k
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_build_a_bfd
pei-loongarch64.c:pe_ILF_build_a_bfd
Line
Count
Source
799
5.81k
{
800
5.81k
  bfd_byte *       ptr;
801
5.81k
  pe_ILF_vars      vars;
802
5.81k
  struct internal_filehdr  internal_f;
803
5.81k
  unsigned int       import_type;
804
5.81k
  unsigned int       import_name_type;
805
5.81k
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
806
5.81k
  coff_symbol_type **    imp_sym;
807
5.81k
  unsigned int       imp_index;
808
5.81k
  intptr_t alignment;
809
810
  /* Decode and verify the types field of the ILF structure.  */
811
5.81k
  import_type = types & 0x3;
812
5.81k
  import_name_type = (types & 0x1c) >> 2;
813
814
5.81k
  switch (import_type)
815
5.81k
    {
816
2.72k
    case IMPORT_CODE:
817
4.62k
    case IMPORT_DATA:
818
5.60k
    case IMPORT_CONST:
819
5.60k
      break;
820
821
210
    default:
822
      /* xgettext:c-format */
823
210
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
824
210
        abfd, import_type);
825
210
      return false;
826
5.81k
    }
827
828
5.60k
  switch (import_name_type)
829
5.60k
    {
830
1.06k
    case IMPORT_ORDINAL:
831
1.63k
    case IMPORT_NAME:
832
2.41k
    case IMPORT_NAME_NOPREFIX:
833
4.26k
    case IMPORT_NAME_UNDECORATE:
834
4.26k
      import_name = symbol_name;
835
4.26k
      break;
836
837
1.12k
    case IMPORT_NAME_EXPORTAS:
838
1.12k
      if (!import_name || !import_name[0])
839
420
  {
840
420
    _bfd_error_handler (_("%pB: missing import name for "
841
420
        "IMPORT_NAME_EXPORTAS for %s"),
842
420
            abfd, symbol_name);
843
420
    return false;
844
420
  }
845
707
      break;
846
847
707
    default:
848
      /* xgettext:c-format */
849
216
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
850
216
        abfd, import_name_type);
851
216
      return false;
852
5.60k
    }
853
854
  /* Initialise local variables.
855
856
     Note these are kept in a structure rather than being
857
     declared as statics since bfd frowns on global variables.
858
859
     We are going to construct the contents of the BFD in memory,
860
     so allocate all the space that we will need right now.  */
861
4.97k
  vars.bim
862
4.97k
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
863
4.97k
  if (vars.bim == NULL)
864
0
    return false;
865
866
4.97k
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
867
4.97k
  vars.bim->buffer = ptr;
868
4.97k
  vars.bim->size   = ILF_DATA_SIZE;
869
4.97k
  if (ptr == NULL)
870
0
    goto error_return;
871
872
  /* Initialise the pointers to regions of the memory and the
873
     other contents of the pe_ILF_vars structure as well.  */
874
4.97k
  vars.sym_cache = (coff_symbol_type *) ptr;
875
4.97k
  vars.sym_ptr   = (coff_symbol_type *) ptr;
876
4.97k
  vars.sym_index = 0;
877
4.97k
  ptr += SIZEOF_ILF_SYMS;
878
879
4.97k
  vars.sym_table = (unsigned int *) ptr;
880
4.97k
  vars.table_ptr = (unsigned int *) ptr;
881
4.97k
  ptr += SIZEOF_ILF_SYM_TABLE;
882
883
4.97k
  vars.native_syms = (combined_entry_type *) ptr;
884
4.97k
  vars.native_ptr  = (combined_entry_type *) ptr;
885
4.97k
  ptr += SIZEOF_ILF_NATIVE_SYMS;
886
887
4.97k
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
888
4.97k
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
889
4.97k
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
890
891
4.97k
  vars.esym_table = (SYMENT *) ptr;
892
4.97k
  vars.esym_ptr   = (SYMENT *) ptr;
893
4.97k
  ptr += SIZEOF_ILF_EXT_SYMS;
894
895
4.97k
  vars.reltab   = (arelent *) ptr;
896
4.97k
  vars.relcount = 0;
897
4.97k
  ptr += SIZEOF_ILF_RELOCS;
898
899
4.97k
  vars.int_reltab  = (struct internal_reloc *) ptr;
900
4.97k
  ptr += SIZEOF_ILF_INT_RELOCS;
901
902
4.97k
  vars.string_table = (char *) ptr;
903
4.97k
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
904
4.97k
  ptr += SIZEOF_ILF_STRINGS;
905
4.97k
  vars.end_string_ptr = (char *) ptr;
906
907
  /* The remaining space in bim->buffer is used
908
     by the pe_ILF_make_a_section() function.  */
909
910
  /* PR 18758: Make sure that the data area is sufficiently aligned for
911
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
912
     the test of GCC_VERSION.  For other compilers we assume 8 byte
913
     alignment.  */
914
4.97k
#if GCC_VERSION >= 3000
915
4.97k
  alignment = __alignof__ (struct coff_section_tdata);
916
#else
917
  alignment = 8;
918
#endif
919
4.97k
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
920
921
4.97k
  vars.data = ptr;
922
4.97k
  vars.abfd = abfd;
923
4.97k
  vars.sec_index = 0;
924
4.97k
  vars.magic = magic;
925
926
  /* Create the initial .idata$<n> sections:
927
     [.idata$2:  Import Directory Table -- not needed]
928
     .idata$4:  Import Lookup Table
929
     .idata$5:  Import Address Table
930
931
     Note we do not create a .idata$3 section as this is
932
     created for us by the linker script.  */
933
4.97k
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
934
4.97k
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
935
4.97k
  if (id4 == NULL || id5 == NULL)
936
0
    goto error_return;
937
938
  /* Fill in the contents of these sections.  */
939
4.97k
  if (import_name_type == IMPORT_ORDINAL)
940
1.06k
    {
941
1.06k
      if (ordinal == 0)
942
  /* See PR 20907 for a reproducer.  */
943
210
  goto error_return;
944
945
851
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
946
851
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
947
851
      ((unsigned int *) id4->contents)[0] = ordinal;
948
851
      ((unsigned int *) id4->contents)[1] = 0x80000000;
949
851
      ((unsigned int *) id5->contents)[0] = ordinal;
950
851
      ((unsigned int *) id5->contents)[1] = 0x80000000;
951
#else
952
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
953
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
954
#endif
955
851
    }
956
3.91k
  else
957
3.91k
    {
958
3.91k
      char *symbol;
959
3.91k
      unsigned int len;
960
961
      /* Create .idata$6 - the Hint Name Table.  */
962
3.91k
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
963
3.91k
      if (id6 == NULL)
964
0
  goto error_return;
965
966
      /* If necessary, trim the import symbol name.  */
967
3.91k
      symbol = import_name;
968
969
      /* As used by MS compiler, '_', '@', and '?' are alternative
970
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
971
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
972
   of these is used for a symbol.  We strip this leading char for
973
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
974
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
975
976
3.91k
      if (import_name_type != IMPORT_NAME
977
3.91k
    && import_name_type != IMPORT_NAME_EXPORTAS)
978
2.62k
  {
979
2.62k
    char c = symbol[0];
980
981
    /* Check that we don't remove for targets with empty
982
       USER_LABEL_PREFIX the leading underscore.  */
983
2.62k
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
984
2.62k
        || c == '@' || c == '?')
985
1.04k
      symbol++;
986
2.62k
  }
987
988
3.91k
      len = strlen (symbol);
989
3.91k
      if (import_name_type == IMPORT_NAME_UNDECORATE)
990
1.85k
  {
991
    /* Truncate at the first '@'.  */
992
1.85k
    char *at = strchr (symbol, '@');
993
994
1.85k
    if (at != NULL)
995
570
      len = at - symbol;
996
1.85k
  }
997
998
3.91k
      id6->contents[0] = ordinal & 0xff;
999
3.91k
      id6->contents[1] = ordinal >> 8;
1000
1001
3.91k
      memcpy ((char *) id6->contents + 2, symbol, len);
1002
3.91k
      id6->contents[len + 2] = '\0';
1003
3.91k
    }
1004
1005
4.76k
  if (import_name_type != IMPORT_ORDINAL)
1006
3.91k
    {
1007
3.91k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1008
3.91k
      pe_ILF_save_relocs (&vars, id4);
1009
1010
3.91k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1011
3.91k
      pe_ILF_save_relocs (&vars, id5);
1012
3.91k
    }
1013
1014
  /* Create an import symbol.  */
1015
4.76k
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1016
4.76k
  imp_sym   = vars.sym_ptr_ptr - 1;
1017
4.76k
  imp_index = vars.sym_index - 1;
1018
1019
  /* Create extra sections depending upon the type of import we are
1020
     dealing with.  */
1021
4.76k
  switch (import_type)
1022
4.76k
    {
1023
0
      int i;
1024
1025
2.40k
    case IMPORT_CODE:
1026
      /* CODE functions are special, in that they get a trampoline that
1027
   jumps to the main import symbol.  Create a .text section to hold it.
1028
   First we need to look up its contents in the jump table.  */
1029
4.80k
      for (i = NUM_ENTRIES (jtab); i--;)
1030
4.80k
  {
1031
4.80k
    if (jtab[i].size == 0)
1032
2.40k
      continue;
1033
2.40k
    if (jtab[i].magic == magic)
1034
2.40k
      break;
1035
2.40k
  }
1036
      /* If we did not find a matching entry something is wrong.  */
1037
2.40k
      if (i < 0)
1038
0
  abort ();
1039
1040
      /* Create the .text section.  */
1041
2.40k
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1042
2.40k
      if (text == NULL)
1043
0
  goto error_return;
1044
1045
      /* Copy in the jump code.  */
1046
2.40k
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1047
1048
      /* Create a reloc for the data in the text section.  */
1049
#ifdef MIPS_ARCH_MAGIC_WINCE
1050
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1051
  {
1052
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1053
              (struct bfd_symbol **) imp_sym,
1054
              imp_index);
1055
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1056
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1057
              (struct bfd_symbol **) imp_sym,
1058
              imp_index);
1059
  }
1060
      else
1061
#endif
1062
#ifdef AMD64MAGIC
1063
      if (magic == AMD64MAGIC)
1064
  {
1065
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1066
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1067
              imp_index);
1068
  }
1069
      else
1070
#endif
1071
2.40k
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1072
2.40k
            BFD_RELOC_32, (asymbol **) imp_sym,
1073
2.40k
            imp_index);
1074
1075
2.40k
      pe_ILF_save_relocs (&vars, text);
1076
2.40k
      break;
1077
1078
1.68k
    case IMPORT_DATA:
1079
2.35k
    case IMPORT_CONST:
1080
2.35k
      break;
1081
1082
0
    default:
1083
      /* XXX code not yet written.  */
1084
0
      abort ();
1085
4.76k
    }
1086
1087
  /* Now create a symbol describing the imported value.  */
1088
4.76k
  switch (import_type)
1089
4.76k
    {
1090
2.40k
    case IMPORT_CODE:
1091
2.40k
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1092
2.40k
          BSF_NOT_AT_END | BSF_FUNCTION);
1093
1094
2.40k
      break;
1095
1096
1.68k
    case IMPORT_DATA:
1097
      /* Nothing to do here.  */
1098
1.68k
      break;
1099
1100
676
    case IMPORT_CONST:
1101
676
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1102
676
      break;
1103
1104
0
    default:
1105
      /* XXX code not yet written.  */
1106
0
      abort ();
1107
4.76k
    }
1108
1109
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1110
4.76k
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1111
4.76k
  if (ptr)
1112
806
    *ptr = 0;
1113
4.76k
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1114
4.76k
  if (ptr)
1115
806
    *ptr = '.';
1116
1117
  /* Initialise the bfd.  */
1118
4.76k
  memset (&internal_f, 0, sizeof (internal_f));
1119
1120
4.76k
  internal_f.f_magic  = magic;
1121
4.76k
  internal_f.f_symptr = 0;
1122
4.76k
  internal_f.f_nsyms  = 0;
1123
4.76k
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1124
1125
4.76k
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1126
4.76k
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1127
0
    goto error_return;
1128
1129
4.76k
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1130
0
    goto error_return;
1131
1132
4.76k
  obj_pe (abfd) = true;
1133
#ifdef THUMBPEMAGIC
1134
  if (vars.magic == THUMBPEMAGIC)
1135
    /* Stop some linker warnings about thumb code not supporting
1136
       interworking.  */
1137
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1138
#endif
1139
1140
  /* Switch from file contents to memory contents.  */
1141
4.76k
  bfd_cache_close (abfd);
1142
1143
4.76k
  abfd->iostream = (void *) vars.bim;
1144
4.76k
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1145
4.76k
  abfd->iovec = &_bfd_memory_iovec;
1146
4.76k
  abfd->where = 0;
1147
4.76k
  abfd->origin = 0;
1148
4.76k
  abfd->size = 0;
1149
4.76k
  obj_sym_filepos (abfd) = 0;
1150
1151
  /* Point the bfd at the symbol table.  */
1152
4.76k
  obj_symbols (abfd) = vars.sym_cache;
1153
4.76k
  abfd->symcount = vars.sym_index;
1154
1155
4.76k
  obj_raw_syments (abfd) = vars.native_syms;
1156
4.76k
  obj_raw_syment_count (abfd) = vars.sym_index;
1157
4.76k
  obj_coff_keep_raw_syms (abfd) = true;
1158
1159
4.76k
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1160
4.76k
  obj_coff_keep_syms (abfd) = true;
1161
1162
4.76k
  obj_convert (abfd) = vars.sym_table;
1163
4.76k
  obj_conv_table_size (abfd) = vars.sym_index;
1164
1165
4.76k
  obj_coff_strings (abfd) = vars.string_table;
1166
4.76k
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1167
4.76k
  obj_coff_keep_strings (abfd) = true;
1168
1169
4.76k
  return true;
1170
1171
210
 error_return:
1172
210
  free (vars.bim->buffer);
1173
210
  free (vars.bim);
1174
210
  return false;
1175
4.76k
}
pei-riscv64.c:pe_ILF_build_a_bfd
Line
Count
Source
799
8.29k
{
800
8.29k
  bfd_byte *       ptr;
801
8.29k
  pe_ILF_vars      vars;
802
8.29k
  struct internal_filehdr  internal_f;
803
8.29k
  unsigned int       import_type;
804
8.29k
  unsigned int       import_name_type;
805
8.29k
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
806
8.29k
  coff_symbol_type **    imp_sym;
807
8.29k
  unsigned int       imp_index;
808
8.29k
  intptr_t alignment;
809
810
  /* Decode and verify the types field of the ILF structure.  */
811
8.29k
  import_type = types & 0x3;
812
8.29k
  import_name_type = (types & 0x1c) >> 2;
813
814
8.29k
  switch (import_type)
815
8.29k
    {
816
2.48k
    case IMPORT_CODE:
817
4.80k
    case IMPORT_DATA:
818
8.08k
    case IMPORT_CONST:
819
8.08k
      break;
820
821
212
    default:
822
      /* xgettext:c-format */
823
212
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
824
212
        abfd, import_type);
825
212
      return false;
826
8.29k
    }
827
828
8.08k
  switch (import_name_type)
829
8.08k
    {
830
1.86k
    case IMPORT_ORDINAL:
831
2.53k
    case IMPORT_NAME:
832
4.58k
    case IMPORT_NAME_NOPREFIX:
833
6.30k
    case IMPORT_NAME_UNDECORATE:
834
6.30k
      import_name = symbol_name;
835
6.30k
      break;
836
837
1.56k
    case IMPORT_NAME_EXPORTAS:
838
1.56k
      if (!import_name || !import_name[0])
839
319
  {
840
319
    _bfd_error_handler (_("%pB: missing import name for "
841
319
        "IMPORT_NAME_EXPORTAS for %s"),
842
319
            abfd, symbol_name);
843
319
    return false;
844
319
  }
845
1.24k
      break;
846
847
1.24k
    default:
848
      /* xgettext:c-format */
849
210
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
850
210
        abfd, import_name_type);
851
210
      return false;
852
8.08k
    }
853
854
  /* Initialise local variables.
855
856
     Note these are kept in a structure rather than being
857
     declared as statics since bfd frowns on global variables.
858
859
     We are going to construct the contents of the BFD in memory,
860
     so allocate all the space that we will need right now.  */
861
7.55k
  vars.bim
862
7.55k
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
863
7.55k
  if (vars.bim == NULL)
864
0
    return false;
865
866
7.55k
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
867
7.55k
  vars.bim->buffer = ptr;
868
7.55k
  vars.bim->size   = ILF_DATA_SIZE;
869
7.55k
  if (ptr == NULL)
870
0
    goto error_return;
871
872
  /* Initialise the pointers to regions of the memory and the
873
     other contents of the pe_ILF_vars structure as well.  */
874
7.55k
  vars.sym_cache = (coff_symbol_type *) ptr;
875
7.55k
  vars.sym_ptr   = (coff_symbol_type *) ptr;
876
7.55k
  vars.sym_index = 0;
877
7.55k
  ptr += SIZEOF_ILF_SYMS;
878
879
7.55k
  vars.sym_table = (unsigned int *) ptr;
880
7.55k
  vars.table_ptr = (unsigned int *) ptr;
881
7.55k
  ptr += SIZEOF_ILF_SYM_TABLE;
882
883
7.55k
  vars.native_syms = (combined_entry_type *) ptr;
884
7.55k
  vars.native_ptr  = (combined_entry_type *) ptr;
885
7.55k
  ptr += SIZEOF_ILF_NATIVE_SYMS;
886
887
7.55k
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
888
7.55k
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
889
7.55k
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
890
891
7.55k
  vars.esym_table = (SYMENT *) ptr;
892
7.55k
  vars.esym_ptr   = (SYMENT *) ptr;
893
7.55k
  ptr += SIZEOF_ILF_EXT_SYMS;
894
895
7.55k
  vars.reltab   = (arelent *) ptr;
896
7.55k
  vars.relcount = 0;
897
7.55k
  ptr += SIZEOF_ILF_RELOCS;
898
899
7.55k
  vars.int_reltab  = (struct internal_reloc *) ptr;
900
7.55k
  ptr += SIZEOF_ILF_INT_RELOCS;
901
902
7.55k
  vars.string_table = (char *) ptr;
903
7.55k
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
904
7.55k
  ptr += SIZEOF_ILF_STRINGS;
905
7.55k
  vars.end_string_ptr = (char *) ptr;
906
907
  /* The remaining space in bim->buffer is used
908
     by the pe_ILF_make_a_section() function.  */
909
910
  /* PR 18758: Make sure that the data area is sufficiently aligned for
911
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
912
     the test of GCC_VERSION.  For other compilers we assume 8 byte
913
     alignment.  */
914
7.55k
#if GCC_VERSION >= 3000
915
7.55k
  alignment = __alignof__ (struct coff_section_tdata);
916
#else
917
  alignment = 8;
918
#endif
919
7.55k
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
920
921
7.55k
  vars.data = ptr;
922
7.55k
  vars.abfd = abfd;
923
7.55k
  vars.sec_index = 0;
924
7.55k
  vars.magic = magic;
925
926
  /* Create the initial .idata$<n> sections:
927
     [.idata$2:  Import Directory Table -- not needed]
928
     .idata$4:  Import Lookup Table
929
     .idata$5:  Import Address Table
930
931
     Note we do not create a .idata$3 section as this is
932
     created for us by the linker script.  */
933
7.55k
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
934
7.55k
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
935
7.55k
  if (id4 == NULL || id5 == NULL)
936
0
    goto error_return;
937
938
  /* Fill in the contents of these sections.  */
939
7.55k
  if (import_name_type == IMPORT_ORDINAL)
940
1.86k
    {
941
1.86k
      if (ordinal == 0)
942
  /* See PR 20907 for a reproducer.  */
943
209
  goto error_return;
944
945
1.65k
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
946
1.65k
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
947
1.65k
      ((unsigned int *) id4->contents)[0] = ordinal;
948
1.65k
      ((unsigned int *) id4->contents)[1] = 0x80000000;
949
1.65k
      ((unsigned int *) id5->contents)[0] = ordinal;
950
1.65k
      ((unsigned int *) id5->contents)[1] = 0x80000000;
951
#else
952
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
953
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
954
#endif
955
1.65k
    }
956
5.68k
  else
957
5.68k
    {
958
5.68k
      char *symbol;
959
5.68k
      unsigned int len;
960
961
      /* Create .idata$6 - the Hint Name Table.  */
962
5.68k
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
963
5.68k
      if (id6 == NULL)
964
0
  goto error_return;
965
966
      /* If necessary, trim the import symbol name.  */
967
5.68k
      symbol = import_name;
968
969
      /* As used by MS compiler, '_', '@', and '?' are alternative
970
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
971
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
972
   of these is used for a symbol.  We strip this leading char for
973
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
974
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
975
976
5.68k
      if (import_name_type != IMPORT_NAME
977
5.68k
    && import_name_type != IMPORT_NAME_EXPORTAS)
978
3.77k
  {
979
3.77k
    char c = symbol[0];
980
981
    /* Check that we don't remove for targets with empty
982
       USER_LABEL_PREFIX the leading underscore.  */
983
3.77k
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
984
3.77k
        || c == '@' || c == '?')
985
709
      symbol++;
986
3.77k
  }
987
988
5.68k
      len = strlen (symbol);
989
5.68k
      if (import_name_type == IMPORT_NAME_UNDECORATE)
990
1.72k
  {
991
    /* Truncate at the first '@'.  */
992
1.72k
    char *at = strchr (symbol, '@');
993
994
1.72k
    if (at != NULL)
995
671
      len = at - symbol;
996
1.72k
  }
997
998
5.68k
      id6->contents[0] = ordinal & 0xff;
999
5.68k
      id6->contents[1] = ordinal >> 8;
1000
1001
5.68k
      memcpy ((char *) id6->contents + 2, symbol, len);
1002
5.68k
      id6->contents[len + 2] = '\0';
1003
5.68k
    }
1004
1005
7.34k
  if (import_name_type != IMPORT_ORDINAL)
1006
5.68k
    {
1007
5.68k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1008
5.68k
      pe_ILF_save_relocs (&vars, id4);
1009
1010
5.68k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1011
5.68k
      pe_ILF_save_relocs (&vars, id5);
1012
5.68k
    }
1013
1014
  /* Create an import symbol.  */
1015
7.34k
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1016
7.34k
  imp_sym   = vars.sym_ptr_ptr - 1;
1017
7.34k
  imp_index = vars.sym_index - 1;
1018
1019
  /* Create extra sections depending upon the type of import we are
1020
     dealing with.  */
1021
7.34k
  switch (import_type)
1022
7.34k
    {
1023
0
      int i;
1024
1025
2.16k
    case IMPORT_CODE:
1026
      /* CODE functions are special, in that they get a trampoline that
1027
   jumps to the main import symbol.  Create a .text section to hold it.
1028
   First we need to look up its contents in the jump table.  */
1029
4.32k
      for (i = NUM_ENTRIES (jtab); i--;)
1030
4.32k
  {
1031
4.32k
    if (jtab[i].size == 0)
1032
2.16k
      continue;
1033
2.16k
    if (jtab[i].magic == magic)
1034
2.16k
      break;
1035
2.16k
  }
1036
      /* If we did not find a matching entry something is wrong.  */
1037
2.16k
      if (i < 0)
1038
0
  abort ();
1039
1040
      /* Create the .text section.  */
1041
2.16k
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1042
2.16k
      if (text == NULL)
1043
0
  goto error_return;
1044
1045
      /* Copy in the jump code.  */
1046
2.16k
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1047
1048
      /* Create a reloc for the data in the text section.  */
1049
#ifdef MIPS_ARCH_MAGIC_WINCE
1050
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1051
  {
1052
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1053
              (struct bfd_symbol **) imp_sym,
1054
              imp_index);
1055
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1056
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1057
              (struct bfd_symbol **) imp_sym,
1058
              imp_index);
1059
  }
1060
      else
1061
#endif
1062
#ifdef AMD64MAGIC
1063
      if (magic == AMD64MAGIC)
1064
  {
1065
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1066
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1067
              imp_index);
1068
  }
1069
      else
1070
#endif
1071
2.16k
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1072
2.16k
            BFD_RELOC_32, (asymbol **) imp_sym,
1073
2.16k
            imp_index);
1074
1075
2.16k
      pe_ILF_save_relocs (&vars, text);
1076
2.16k
      break;
1077
1078
2.11k
    case IMPORT_DATA:
1079
5.17k
    case IMPORT_CONST:
1080
5.17k
      break;
1081
1082
0
    default:
1083
      /* XXX code not yet written.  */
1084
0
      abort ();
1085
7.34k
    }
1086
1087
  /* Now create a symbol describing the imported value.  */
1088
7.34k
  switch (import_type)
1089
7.34k
    {
1090
2.16k
    case IMPORT_CODE:
1091
2.16k
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1092
2.16k
          BSF_NOT_AT_END | BSF_FUNCTION);
1093
1094
2.16k
      break;
1095
1096
2.11k
    case IMPORT_DATA:
1097
      /* Nothing to do here.  */
1098
2.11k
      break;
1099
1100
3.06k
    case IMPORT_CONST:
1101
3.06k
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1102
3.06k
      break;
1103
1104
0
    default:
1105
      /* XXX code not yet written.  */
1106
0
      abort ();
1107
7.34k
    }
1108
1109
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1110
7.34k
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1111
7.34k
  if (ptr)
1112
708
    *ptr = 0;
1113
7.34k
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1114
7.34k
  if (ptr)
1115
708
    *ptr = '.';
1116
1117
  /* Initialise the bfd.  */
1118
7.34k
  memset (&internal_f, 0, sizeof (internal_f));
1119
1120
7.34k
  internal_f.f_magic  = magic;
1121
7.34k
  internal_f.f_symptr = 0;
1122
7.34k
  internal_f.f_nsyms  = 0;
1123
7.34k
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1124
1125
7.34k
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1126
7.34k
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1127
0
    goto error_return;
1128
1129
7.34k
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1130
0
    goto error_return;
1131
1132
7.34k
  obj_pe (abfd) = true;
1133
#ifdef THUMBPEMAGIC
1134
  if (vars.magic == THUMBPEMAGIC)
1135
    /* Stop some linker warnings about thumb code not supporting
1136
       interworking.  */
1137
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1138
#endif
1139
1140
  /* Switch from file contents to memory contents.  */
1141
7.34k
  bfd_cache_close (abfd);
1142
1143
7.34k
  abfd->iostream = (void *) vars.bim;
1144
7.34k
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1145
7.34k
  abfd->iovec = &_bfd_memory_iovec;
1146
7.34k
  abfd->where = 0;
1147
7.34k
  abfd->origin = 0;
1148
7.34k
  abfd->size = 0;
1149
7.34k
  obj_sym_filepos (abfd) = 0;
1150
1151
  /* Point the bfd at the symbol table.  */
1152
7.34k
  obj_symbols (abfd) = vars.sym_cache;
1153
7.34k
  abfd->symcount = vars.sym_index;
1154
1155
7.34k
  obj_raw_syments (abfd) = vars.native_syms;
1156
7.34k
  obj_raw_syment_count (abfd) = vars.sym_index;
1157
7.34k
  obj_coff_keep_raw_syms (abfd) = true;
1158
1159
7.34k
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1160
7.34k
  obj_coff_keep_syms (abfd) = true;
1161
1162
7.34k
  obj_convert (abfd) = vars.sym_table;
1163
7.34k
  obj_conv_table_size (abfd) = vars.sym_index;
1164
1165
7.34k
  obj_coff_strings (abfd) = vars.string_table;
1166
7.34k
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1167
7.34k
  obj_coff_keep_strings (abfd) = true;
1168
1169
7.34k
  return true;
1170
1171
209
 error_return:
1172
209
  free (vars.bim->buffer);
1173
209
  free (vars.bim);
1174
209
  return false;
1175
7.34k
}
pei-arm-wince.c:pe_ILF_build_a_bfd
Line
Count
Source
799
1.86k
{
800
1.86k
  bfd_byte *       ptr;
801
1.86k
  pe_ILF_vars      vars;
802
1.86k
  struct internal_filehdr  internal_f;
803
1.86k
  unsigned int       import_type;
804
1.86k
  unsigned int       import_name_type;
805
1.86k
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
806
1.86k
  coff_symbol_type **    imp_sym;
807
1.86k
  unsigned int       imp_index;
808
1.86k
  intptr_t alignment;
809
810
  /* Decode and verify the types field of the ILF structure.  */
811
1.86k
  import_type = types & 0x3;
812
1.86k
  import_name_type = (types & 0x1c) >> 2;
813
814
1.86k
  switch (import_type)
815
1.86k
    {
816
878
    case IMPORT_CODE:
817
1.21k
    case IMPORT_DATA:
818
1.54k
    case IMPORT_CONST:
819
1.54k
      break;
820
821
313
    default:
822
      /* xgettext:c-format */
823
313
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
824
313
        abfd, import_type);
825
313
      return false;
826
1.86k
    }
827
828
1.54k
  switch (import_name_type)
829
1.54k
    {
830
651
    case IMPORT_ORDINAL:
831
655
    case IMPORT_NAME:
832
674
    case IMPORT_NAME_NOPREFIX:
833
695
    case IMPORT_NAME_UNDECORATE:
834
695
      import_name = symbol_name;
835
695
      break;
836
837
434
    case IMPORT_NAME_EXPORTAS:
838
434
      if (!import_name || !import_name[0])
839
428
  {
840
428
    _bfd_error_handler (_("%pB: missing import name for "
841
428
        "IMPORT_NAME_EXPORTAS for %s"),
842
428
            abfd, symbol_name);
843
428
    return false;
844
428
  }
845
6
      break;
846
847
418
    default:
848
      /* xgettext:c-format */
849
418
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
850
418
        abfd, import_name_type);
851
418
      return false;
852
1.54k
    }
853
854
  /* Initialise local variables.
855
856
     Note these are kept in a structure rather than being
857
     declared as statics since bfd frowns on global variables.
858
859
     We are going to construct the contents of the BFD in memory,
860
     so allocate all the space that we will need right now.  */
861
701
  vars.bim
862
701
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
863
701
  if (vars.bim == NULL)
864
0
    return false;
865
866
701
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
867
701
  vars.bim->buffer = ptr;
868
701
  vars.bim->size   = ILF_DATA_SIZE;
869
701
  if (ptr == NULL)
870
0
    goto error_return;
871
872
  /* Initialise the pointers to regions of the memory and the
873
     other contents of the pe_ILF_vars structure as well.  */
874
701
  vars.sym_cache = (coff_symbol_type *) ptr;
875
701
  vars.sym_ptr   = (coff_symbol_type *) ptr;
876
701
  vars.sym_index = 0;
877
701
  ptr += SIZEOF_ILF_SYMS;
878
879
701
  vars.sym_table = (unsigned int *) ptr;
880
701
  vars.table_ptr = (unsigned int *) ptr;
881
701
  ptr += SIZEOF_ILF_SYM_TABLE;
882
883
701
  vars.native_syms = (combined_entry_type *) ptr;
884
701
  vars.native_ptr  = (combined_entry_type *) ptr;
885
701
  ptr += SIZEOF_ILF_NATIVE_SYMS;
886
887
701
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
888
701
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
889
701
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
890
891
701
  vars.esym_table = (SYMENT *) ptr;
892
701
  vars.esym_ptr   = (SYMENT *) ptr;
893
701
  ptr += SIZEOF_ILF_EXT_SYMS;
894
895
701
  vars.reltab   = (arelent *) ptr;
896
701
  vars.relcount = 0;
897
701
  ptr += SIZEOF_ILF_RELOCS;
898
899
701
  vars.int_reltab  = (struct internal_reloc *) ptr;
900
701
  ptr += SIZEOF_ILF_INT_RELOCS;
901
902
701
  vars.string_table = (char *) ptr;
903
701
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
904
701
  ptr += SIZEOF_ILF_STRINGS;
905
701
  vars.end_string_ptr = (char *) ptr;
906
907
  /* The remaining space in bim->buffer is used
908
     by the pe_ILF_make_a_section() function.  */
909
910
  /* PR 18758: Make sure that the data area is sufficiently aligned for
911
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
912
     the test of GCC_VERSION.  For other compilers we assume 8 byte
913
     alignment.  */
914
701
#if GCC_VERSION >= 3000
915
701
  alignment = __alignof__ (struct coff_section_tdata);
916
#else
917
  alignment = 8;
918
#endif
919
701
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
920
921
701
  vars.data = ptr;
922
701
  vars.abfd = abfd;
923
701
  vars.sec_index = 0;
924
701
  vars.magic = magic;
925
926
  /* Create the initial .idata$<n> sections:
927
     [.idata$2:  Import Directory Table -- not needed]
928
     .idata$4:  Import Lookup Table
929
     .idata$5:  Import Address Table
930
931
     Note we do not create a .idata$3 section as this is
932
     created for us by the linker script.  */
933
701
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
934
701
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
935
701
  if (id4 == NULL || id5 == NULL)
936
0
    goto error_return;
937
938
  /* Fill in the contents of these sections.  */
939
701
  if (import_name_type == IMPORT_ORDINAL)
940
651
    {
941
651
      if (ordinal == 0)
942
  /* See PR 20907 for a reproducer.  */
943
617
  goto error_return;
944
945
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
946
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
947
      ((unsigned int *) id4->contents)[0] = ordinal;
948
      ((unsigned int *) id4->contents)[1] = 0x80000000;
949
      ((unsigned int *) id5->contents)[0] = ordinal;
950
      ((unsigned int *) id5->contents)[1] = 0x80000000;
951
#else
952
34
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
953
34
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
954
34
#endif
955
34
    }
956
50
  else
957
50
    {
958
50
      char *symbol;
959
50
      unsigned int len;
960
961
      /* Create .idata$6 - the Hint Name Table.  */
962
50
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
963
50
      if (id6 == NULL)
964
0
  goto error_return;
965
966
      /* If necessary, trim the import symbol name.  */
967
50
      symbol = import_name;
968
969
      /* As used by MS compiler, '_', '@', and '?' are alternative
970
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
971
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
972
   of these is used for a symbol.  We strip this leading char for
973
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
974
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
975
976
50
      if (import_name_type != IMPORT_NAME
977
50
    && import_name_type != IMPORT_NAME_EXPORTAS)
978
40
  {
979
40
    char c = symbol[0];
980
981
    /* Check that we don't remove for targets with empty
982
       USER_LABEL_PREFIX the leading underscore.  */
983
40
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
984
40
        || c == '@' || c == '?')
985
8
      symbol++;
986
40
  }
987
988
50
      len = strlen (symbol);
989
50
      if (import_name_type == IMPORT_NAME_UNDECORATE)
990
21
  {
991
    /* Truncate at the first '@'.  */
992
21
    char *at = strchr (symbol, '@');
993
994
21
    if (at != NULL)
995
5
      len = at - symbol;
996
21
  }
997
998
50
      id6->contents[0] = ordinal & 0xff;
999
50
      id6->contents[1] = ordinal >> 8;
1000
1001
50
      memcpy ((char *) id6->contents + 2, symbol, len);
1002
50
      id6->contents[len + 2] = '\0';
1003
50
    }
1004
1005
84
  if (import_name_type != IMPORT_ORDINAL)
1006
50
    {
1007
50
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1008
50
      pe_ILF_save_relocs (&vars, id4);
1009
1010
50
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1011
50
      pe_ILF_save_relocs (&vars, id5);
1012
50
    }
1013
1014
  /* Create an import symbol.  */
1015
84
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1016
84
  imp_sym   = vars.sym_ptr_ptr - 1;
1017
84
  imp_index = vars.sym_index - 1;
1018
1019
  /* Create extra sections depending upon the type of import we are
1020
     dealing with.  */
1021
84
  switch (import_type)
1022
84
    {
1023
0
      int i;
1024
1025
41
    case IMPORT_CODE:
1026
      /* CODE functions are special, in that they get a trampoline that
1027
   jumps to the main import symbol.  Create a .text section to hold it.
1028
   First we need to look up its contents in the jump table.  */
1029
107
      for (i = NUM_ENTRIES (jtab); i--;)
1030
107
  {
1031
107
    if (jtab[i].size == 0)
1032
41
      continue;
1033
66
    if (jtab[i].magic == magic)
1034
41
      break;
1035
66
  }
1036
      /* If we did not find a matching entry something is wrong.  */
1037
41
      if (i < 0)
1038
0
  abort ();
1039
1040
      /* Create the .text section.  */
1041
41
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1042
41
      if (text == NULL)
1043
0
  goto error_return;
1044
1045
      /* Copy in the jump code.  */
1046
41
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1047
1048
      /* Create a reloc for the data in the text section.  */
1049
#ifdef MIPS_ARCH_MAGIC_WINCE
1050
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1051
  {
1052
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1053
              (struct bfd_symbol **) imp_sym,
1054
              imp_index);
1055
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1056
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1057
              (struct bfd_symbol **) imp_sym,
1058
              imp_index);
1059
  }
1060
      else
1061
#endif
1062
#ifdef AMD64MAGIC
1063
      if (magic == AMD64MAGIC)
1064
  {
1065
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1066
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1067
              imp_index);
1068
  }
1069
      else
1070
#endif
1071
41
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1072
41
            BFD_RELOC_32, (asymbol **) imp_sym,
1073
41
            imp_index);
1074
1075
41
      pe_ILF_save_relocs (&vars, text);
1076
41
      break;
1077
1078
24
    case IMPORT_DATA:
1079
43
    case IMPORT_CONST:
1080
43
      break;
1081
1082
0
    default:
1083
      /* XXX code not yet written.  */
1084
0
      abort ();
1085
84
    }
1086
1087
  /* Now create a symbol describing the imported value.  */
1088
84
  switch (import_type)
1089
84
    {
1090
41
    case IMPORT_CODE:
1091
41
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1092
41
          BSF_NOT_AT_END | BSF_FUNCTION);
1093
1094
41
      break;
1095
1096
24
    case IMPORT_DATA:
1097
      /* Nothing to do here.  */
1098
24
      break;
1099
1100
19
    case IMPORT_CONST:
1101
19
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1102
19
      break;
1103
1104
0
    default:
1105
      /* XXX code not yet written.  */
1106
0
      abort ();
1107
84
    }
1108
1109
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1110
84
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1111
84
  if (ptr)
1112
10
    *ptr = 0;
1113
84
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1114
84
  if (ptr)
1115
10
    *ptr = '.';
1116
1117
  /* Initialise the bfd.  */
1118
84
  memset (&internal_f, 0, sizeof (internal_f));
1119
1120
84
  internal_f.f_magic  = magic;
1121
84
  internal_f.f_symptr = 0;
1122
84
  internal_f.f_nsyms  = 0;
1123
84
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1124
1125
84
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1126
84
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1127
0
    goto error_return;
1128
1129
84
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1130
0
    goto error_return;
1131
1132
84
  obj_pe (abfd) = true;
1133
84
#ifdef THUMBPEMAGIC
1134
84
  if (vars.magic == THUMBPEMAGIC)
1135
    /* Stop some linker warnings about thumb code not supporting
1136
       interworking.  */
1137
28
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1138
84
#endif
1139
1140
  /* Switch from file contents to memory contents.  */
1141
84
  bfd_cache_close (abfd);
1142
1143
84
  abfd->iostream = (void *) vars.bim;
1144
84
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1145
84
  abfd->iovec = &_bfd_memory_iovec;
1146
84
  abfd->where = 0;
1147
84
  abfd->origin = 0;
1148
84
  abfd->size = 0;
1149
84
  obj_sym_filepos (abfd) = 0;
1150
1151
  /* Point the bfd at the symbol table.  */
1152
84
  obj_symbols (abfd) = vars.sym_cache;
1153
84
  abfd->symcount = vars.sym_index;
1154
1155
84
  obj_raw_syments (abfd) = vars.native_syms;
1156
84
  obj_raw_syment_count (abfd) = vars.sym_index;
1157
84
  obj_coff_keep_raw_syms (abfd) = true;
1158
1159
84
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1160
84
  obj_coff_keep_syms (abfd) = true;
1161
1162
84
  obj_convert (abfd) = vars.sym_table;
1163
84
  obj_conv_table_size (abfd) = vars.sym_index;
1164
1165
84
  obj_coff_strings (abfd) = vars.string_table;
1166
84
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1167
84
  obj_coff_keep_strings (abfd) = true;
1168
1169
84
  return true;
1170
1171
617
 error_return:
1172
617
  free (vars.bim->buffer);
1173
617
  free (vars.bim);
1174
617
  return false;
1175
84
}
pei-arm.c:pe_ILF_build_a_bfd
Line
Count
Source
799
15.0k
{
800
15.0k
  bfd_byte *       ptr;
801
15.0k
  pe_ILF_vars      vars;
802
15.0k
  struct internal_filehdr  internal_f;
803
15.0k
  unsigned int       import_type;
804
15.0k
  unsigned int       import_name_type;
805
15.0k
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
806
15.0k
  coff_symbol_type **    imp_sym;
807
15.0k
  unsigned int       imp_index;
808
15.0k
  intptr_t alignment;
809
810
  /* Decode and verify the types field of the ILF structure.  */
811
15.0k
  import_type = types & 0x3;
812
15.0k
  import_name_type = (types & 0x1c) >> 2;
813
814
15.0k
  switch (import_type)
815
15.0k
    {
816
7.69k
    case IMPORT_CODE:
817
10.7k
    case IMPORT_DATA:
818
14.7k
    case IMPORT_CONST:
819
14.7k
      break;
820
821
313
    default:
822
      /* xgettext:c-format */
823
313
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
824
313
        abfd, import_type);
825
313
      return false;
826
15.0k
    }
827
828
14.7k
  switch (import_name_type)
829
14.7k
    {
830
5.69k
    case IMPORT_ORDINAL:
831
6.36k
    case IMPORT_NAME:
832
10.0k
    case IMPORT_NAME_NOPREFIX:
833
12.8k
    case IMPORT_NAME_UNDECORATE:
834
12.8k
      import_name = symbol_name;
835
12.8k
      break;
836
837
1.47k
    case IMPORT_NAME_EXPORTAS:
838
1.47k
      if (!import_name || !import_name[0])
839
428
  {
840
428
    _bfd_error_handler (_("%pB: missing import name for "
841
428
        "IMPORT_NAME_EXPORTAS for %s"),
842
428
            abfd, symbol_name);
843
428
    return false;
844
428
  }
845
1.04k
      break;
846
847
1.04k
    default:
848
      /* xgettext:c-format */
849
418
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
850
418
        abfd, import_name_type);
851
418
      return false;
852
14.7k
    }
853
854
  /* Initialise local variables.
855
856
     Note these are kept in a structure rather than being
857
     declared as statics since bfd frowns on global variables.
858
859
     We are going to construct the contents of the BFD in memory,
860
     so allocate all the space that we will need right now.  */
861
13.8k
  vars.bim
862
13.8k
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
863
13.8k
  if (vars.bim == NULL)
864
0
    return false;
865
866
13.8k
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
867
13.8k
  vars.bim->buffer = ptr;
868
13.8k
  vars.bim->size   = ILF_DATA_SIZE;
869
13.8k
  if (ptr == NULL)
870
0
    goto error_return;
871
872
  /* Initialise the pointers to regions of the memory and the
873
     other contents of the pe_ILF_vars structure as well.  */
874
13.8k
  vars.sym_cache = (coff_symbol_type *) ptr;
875
13.8k
  vars.sym_ptr   = (coff_symbol_type *) ptr;
876
13.8k
  vars.sym_index = 0;
877
13.8k
  ptr += SIZEOF_ILF_SYMS;
878
879
13.8k
  vars.sym_table = (unsigned int *) ptr;
880
13.8k
  vars.table_ptr = (unsigned int *) ptr;
881
13.8k
  ptr += SIZEOF_ILF_SYM_TABLE;
882
883
13.8k
  vars.native_syms = (combined_entry_type *) ptr;
884
13.8k
  vars.native_ptr  = (combined_entry_type *) ptr;
885
13.8k
  ptr += SIZEOF_ILF_NATIVE_SYMS;
886
887
13.8k
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
888
13.8k
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
889
13.8k
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
890
891
13.8k
  vars.esym_table = (SYMENT *) ptr;
892
13.8k
  vars.esym_ptr   = (SYMENT *) ptr;
893
13.8k
  ptr += SIZEOF_ILF_EXT_SYMS;
894
895
13.8k
  vars.reltab   = (arelent *) ptr;
896
13.8k
  vars.relcount = 0;
897
13.8k
  ptr += SIZEOF_ILF_RELOCS;
898
899
13.8k
  vars.int_reltab  = (struct internal_reloc *) ptr;
900
13.8k
  ptr += SIZEOF_ILF_INT_RELOCS;
901
902
13.8k
  vars.string_table = (char *) ptr;
903
13.8k
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
904
13.8k
  ptr += SIZEOF_ILF_STRINGS;
905
13.8k
  vars.end_string_ptr = (char *) ptr;
906
907
  /* The remaining space in bim->buffer is used
908
     by the pe_ILF_make_a_section() function.  */
909
910
  /* PR 18758: Make sure that the data area is sufficiently aligned for
911
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
912
     the test of GCC_VERSION.  For other compilers we assume 8 byte
913
     alignment.  */
914
13.8k
#if GCC_VERSION >= 3000
915
13.8k
  alignment = __alignof__ (struct coff_section_tdata);
916
#else
917
  alignment = 8;
918
#endif
919
13.8k
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
920
921
13.8k
  vars.data = ptr;
922
13.8k
  vars.abfd = abfd;
923
13.8k
  vars.sec_index = 0;
924
13.8k
  vars.magic = magic;
925
926
  /* Create the initial .idata$<n> sections:
927
     [.idata$2:  Import Directory Table -- not needed]
928
     .idata$4:  Import Lookup Table
929
     .idata$5:  Import Address Table
930
931
     Note we do not create a .idata$3 section as this is
932
     created for us by the linker script.  */
933
13.8k
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
934
13.8k
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
935
13.8k
  if (id4 == NULL || id5 == NULL)
936
0
    goto error_return;
937
938
  /* Fill in the contents of these sections.  */
939
13.8k
  if (import_name_type == IMPORT_ORDINAL)
940
5.69k
    {
941
5.69k
      if (ordinal == 0)
942
  /* See PR 20907 for a reproducer.  */
943
617
  goto error_return;
944
945
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
946
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
947
      ((unsigned int *) id4->contents)[0] = ordinal;
948
      ((unsigned int *) id4->contents)[1] = 0x80000000;
949
      ((unsigned int *) id5->contents)[0] = ordinal;
950
      ((unsigned int *) id5->contents)[1] = 0x80000000;
951
#else
952
5.07k
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
953
5.07k
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
954
5.07k
#endif
955
5.07k
    }
956
8.20k
  else
957
8.20k
    {
958
8.20k
      char *symbol;
959
8.20k
      unsigned int len;
960
961
      /* Create .idata$6 - the Hint Name Table.  */
962
8.20k
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
963
8.20k
      if (id6 == NULL)
964
0
  goto error_return;
965
966
      /* If necessary, trim the import symbol name.  */
967
8.20k
      symbol = import_name;
968
969
      /* As used by MS compiler, '_', '@', and '?' are alternative
970
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
971
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
972
   of these is used for a symbol.  We strip this leading char for
973
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
974
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
975
976
8.20k
      if (import_name_type != IMPORT_NAME
977
8.20k
    && import_name_type != IMPORT_NAME_EXPORTAS)
978
6.48k
  {
979
6.48k
    char c = symbol[0];
980
981
    /* Check that we don't remove for targets with empty
982
       USER_LABEL_PREFIX the leading underscore.  */
983
6.48k
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
984
6.48k
        || c == '@' || c == '?')
985
2.14k
      symbol++;
986
6.48k
  }
987
988
8.20k
      len = strlen (symbol);
989
8.20k
      if (import_name_type == IMPORT_NAME_UNDECORATE)
990
2.82k
  {
991
    /* Truncate at the first '@'.  */
992
2.82k
    char *at = strchr (symbol, '@');
993
994
2.82k
    if (at != NULL)
995
470
      len = at - symbol;
996
2.82k
  }
997
998
8.20k
      id6->contents[0] = ordinal & 0xff;
999
8.20k
      id6->contents[1] = ordinal >> 8;
1000
1001
8.20k
      memcpy ((char *) id6->contents + 2, symbol, len);
1002
8.20k
      id6->contents[len + 2] = '\0';
1003
8.20k
    }
1004
1005
13.2k
  if (import_name_type != IMPORT_ORDINAL)
1006
8.20k
    {
1007
8.20k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1008
8.20k
      pe_ILF_save_relocs (&vars, id4);
1009
1010
8.20k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1011
8.20k
      pe_ILF_save_relocs (&vars, id5);
1012
8.20k
    }
1013
1014
  /* Create an import symbol.  */
1015
13.2k
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1016
13.2k
  imp_sym   = vars.sym_ptr_ptr - 1;
1017
13.2k
  imp_index = vars.sym_index - 1;
1018
1019
  /* Create extra sections depending upon the type of import we are
1020
     dealing with.  */
1021
13.2k
  switch (import_type)
1022
13.2k
    {
1023
0
      int i;
1024
1025
6.85k
    case IMPORT_CODE:
1026
      /* CODE functions are special, in that they get a trampoline that
1027
   jumps to the main import symbol.  Create a .text section to hold it.
1028
   First we need to look up its contents in the jump table.  */
1029
18.5k
      for (i = NUM_ENTRIES (jtab); i--;)
1030
18.5k
  {
1031
18.5k
    if (jtab[i].size == 0)
1032
6.85k
      continue;
1033
11.6k
    if (jtab[i].magic == magic)
1034
6.85k
      break;
1035
11.6k
  }
1036
      /* If we did not find a matching entry something is wrong.  */
1037
6.85k
      if (i < 0)
1038
0
  abort ();
1039
1040
      /* Create the .text section.  */
1041
6.85k
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1042
6.85k
      if (text == NULL)
1043
0
  goto error_return;
1044
1045
      /* Copy in the jump code.  */
1046
6.85k
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1047
1048
      /* Create a reloc for the data in the text section.  */
1049
#ifdef MIPS_ARCH_MAGIC_WINCE
1050
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1051
  {
1052
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1053
              (struct bfd_symbol **) imp_sym,
1054
              imp_index);
1055
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1056
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1057
              (struct bfd_symbol **) imp_sym,
1058
              imp_index);
1059
  }
1060
      else
1061
#endif
1062
#ifdef AMD64MAGIC
1063
      if (magic == AMD64MAGIC)
1064
  {
1065
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1066
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1067
              imp_index);
1068
  }
1069
      else
1070
#endif
1071
6.85k
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1072
6.85k
            BFD_RELOC_32, (asymbol **) imp_sym,
1073
6.85k
            imp_index);
1074
1075
6.85k
      pe_ILF_save_relocs (&vars, text);
1076
6.85k
      break;
1077
1078
2.75k
    case IMPORT_DATA:
1079
6.41k
    case IMPORT_CONST:
1080
6.41k
      break;
1081
1082
0
    default:
1083
      /* XXX code not yet written.  */
1084
0
      abort ();
1085
13.2k
    }
1086
1087
  /* Now create a symbol describing the imported value.  */
1088
13.2k
  switch (import_type)
1089
13.2k
    {
1090
6.85k
    case IMPORT_CODE:
1091
6.85k
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1092
6.85k
          BSF_NOT_AT_END | BSF_FUNCTION);
1093
1094
6.85k
      break;
1095
1096
2.75k
    case IMPORT_DATA:
1097
      /* Nothing to do here.  */
1098
2.75k
      break;
1099
1100
3.65k
    case IMPORT_CONST:
1101
3.65k
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1102
3.65k
      break;
1103
1104
0
    default:
1105
      /* XXX code not yet written.  */
1106
0
      abort ();
1107
13.2k
    }
1108
1109
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1110
13.2k
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1111
13.2k
  if (ptr)
1112
1.56k
    *ptr = 0;
1113
13.2k
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1114
13.2k
  if (ptr)
1115
1.56k
    *ptr = '.';
1116
1117
  /* Initialise the bfd.  */
1118
13.2k
  memset (&internal_f, 0, sizeof (internal_f));
1119
1120
13.2k
  internal_f.f_magic  = magic;
1121
13.2k
  internal_f.f_symptr = 0;
1122
13.2k
  internal_f.f_nsyms  = 0;
1123
13.2k
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1124
1125
13.2k
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1126
13.2k
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1127
0
    goto error_return;
1128
1129
13.2k
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1130
0
    goto error_return;
1131
1132
13.2k
  obj_pe (abfd) = true;
1133
13.2k
#ifdef THUMBPEMAGIC
1134
13.2k
  if (vars.magic == THUMBPEMAGIC)
1135
    /* Stop some linker warnings about thumb code not supporting
1136
       interworking.  */
1137
3.55k
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1138
13.2k
#endif
1139
1140
  /* Switch from file contents to memory contents.  */
1141
13.2k
  bfd_cache_close (abfd);
1142
1143
13.2k
  abfd->iostream = (void *) vars.bim;
1144
13.2k
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1145
13.2k
  abfd->iovec = &_bfd_memory_iovec;
1146
13.2k
  abfd->where = 0;
1147
13.2k
  abfd->origin = 0;
1148
13.2k
  abfd->size = 0;
1149
13.2k
  obj_sym_filepos (abfd) = 0;
1150
1151
  /* Point the bfd at the symbol table.  */
1152
13.2k
  obj_symbols (abfd) = vars.sym_cache;
1153
13.2k
  abfd->symcount = vars.sym_index;
1154
1155
13.2k
  obj_raw_syments (abfd) = vars.native_syms;
1156
13.2k
  obj_raw_syment_count (abfd) = vars.sym_index;
1157
13.2k
  obj_coff_keep_raw_syms (abfd) = true;
1158
1159
13.2k
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1160
13.2k
  obj_coff_keep_syms (abfd) = true;
1161
1162
13.2k
  obj_convert (abfd) = vars.sym_table;
1163
13.2k
  obj_conv_table_size (abfd) = vars.sym_index;
1164
1165
13.2k
  obj_coff_strings (abfd) = vars.string_table;
1166
13.2k
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1167
13.2k
  obj_coff_keep_strings (abfd) = true;
1168
1169
13.2k
  return true;
1170
1171
617
 error_return:
1172
617
  free (vars.bim->buffer);
1173
617
  free (vars.bim);
1174
617
  return false;
1175
13.2k
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_build_a_bfd
pei-sh.c:pe_ILF_build_a_bfd
Line
Count
Source
799
9.95k
{
800
9.95k
  bfd_byte *       ptr;
801
9.95k
  pe_ILF_vars      vars;
802
9.95k
  struct internal_filehdr  internal_f;
803
9.95k
  unsigned int       import_type;
804
9.95k
  unsigned int       import_name_type;
805
9.95k
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
806
9.95k
  coff_symbol_type **    imp_sym;
807
9.95k
  unsigned int       imp_index;
808
9.95k
  intptr_t alignment;
809
810
  /* Decode and verify the types field of the ILF structure.  */
811
9.95k
  import_type = types & 0x3;
812
9.95k
  import_name_type = (types & 0x1c) >> 2;
813
814
9.95k
  switch (import_type)
815
9.95k
    {
816
3.47k
    case IMPORT_CODE:
817
6.92k
    case IMPORT_DATA:
818
9.61k
    case IMPORT_CONST:
819
9.61k
      break;
820
821
338
    default:
822
      /* xgettext:c-format */
823
338
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
824
338
        abfd, import_type);
825
338
      return false;
826
9.95k
    }
827
828
9.61k
  switch (import_name_type)
829
9.61k
    {
830
2.57k
    case IMPORT_ORDINAL:
831
3.59k
    case IMPORT_NAME:
832
5.84k
    case IMPORT_NAME_NOPREFIX:
833
8.00k
    case IMPORT_NAME_UNDECORATE:
834
8.00k
      import_name = symbol_name;
835
8.00k
      break;
836
837
1.29k
    case IMPORT_NAME_EXPORTAS:
838
1.29k
      if (!import_name || !import_name[0])
839
517
  {
840
517
    _bfd_error_handler (_("%pB: missing import name for "
841
517
        "IMPORT_NAME_EXPORTAS for %s"),
842
517
            abfd, symbol_name);
843
517
    return false;
844
517
  }
845
778
      break;
846
847
778
    default:
848
      /* xgettext:c-format */
849
315
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
850
315
        abfd, import_name_type);
851
315
      return false;
852
9.61k
    }
853
854
  /* Initialise local variables.
855
856
     Note these are kept in a structure rather than being
857
     declared as statics since bfd frowns on global variables.
858
859
     We are going to construct the contents of the BFD in memory,
860
     so allocate all the space that we will need right now.  */
861
8.78k
  vars.bim
862
8.78k
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
863
8.78k
  if (vars.bim == NULL)
864
0
    return false;
865
866
8.78k
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
867
8.78k
  vars.bim->buffer = ptr;
868
8.78k
  vars.bim->size   = ILF_DATA_SIZE;
869
8.78k
  if (ptr == NULL)
870
0
    goto error_return;
871
872
  /* Initialise the pointers to regions of the memory and the
873
     other contents of the pe_ILF_vars structure as well.  */
874
8.78k
  vars.sym_cache = (coff_symbol_type *) ptr;
875
8.78k
  vars.sym_ptr   = (coff_symbol_type *) ptr;
876
8.78k
  vars.sym_index = 0;
877
8.78k
  ptr += SIZEOF_ILF_SYMS;
878
879
8.78k
  vars.sym_table = (unsigned int *) ptr;
880
8.78k
  vars.table_ptr = (unsigned int *) ptr;
881
8.78k
  ptr += SIZEOF_ILF_SYM_TABLE;
882
883
8.78k
  vars.native_syms = (combined_entry_type *) ptr;
884
8.78k
  vars.native_ptr  = (combined_entry_type *) ptr;
885
8.78k
  ptr += SIZEOF_ILF_NATIVE_SYMS;
886
887
8.78k
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
888
8.78k
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
889
8.78k
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
890
891
8.78k
  vars.esym_table = (SYMENT *) ptr;
892
8.78k
  vars.esym_ptr   = (SYMENT *) ptr;
893
8.78k
  ptr += SIZEOF_ILF_EXT_SYMS;
894
895
8.78k
  vars.reltab   = (arelent *) ptr;
896
8.78k
  vars.relcount = 0;
897
8.78k
  ptr += SIZEOF_ILF_RELOCS;
898
899
8.78k
  vars.int_reltab  = (struct internal_reloc *) ptr;
900
8.78k
  ptr += SIZEOF_ILF_INT_RELOCS;
901
902
8.78k
  vars.string_table = (char *) ptr;
903
8.78k
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
904
8.78k
  ptr += SIZEOF_ILF_STRINGS;
905
8.78k
  vars.end_string_ptr = (char *) ptr;
906
907
  /* The remaining space in bim->buffer is used
908
     by the pe_ILF_make_a_section() function.  */
909
910
  /* PR 18758: Make sure that the data area is sufficiently aligned for
911
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
912
     the test of GCC_VERSION.  For other compilers we assume 8 byte
913
     alignment.  */
914
8.78k
#if GCC_VERSION >= 3000
915
8.78k
  alignment = __alignof__ (struct coff_section_tdata);
916
#else
917
  alignment = 8;
918
#endif
919
8.78k
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
920
921
8.78k
  vars.data = ptr;
922
8.78k
  vars.abfd = abfd;
923
8.78k
  vars.sec_index = 0;
924
8.78k
  vars.magic = magic;
925
926
  /* Create the initial .idata$<n> sections:
927
     [.idata$2:  Import Directory Table -- not needed]
928
     .idata$4:  Import Lookup Table
929
     .idata$5:  Import Address Table
930
931
     Note we do not create a .idata$3 section as this is
932
     created for us by the linker script.  */
933
8.78k
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
934
8.78k
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
935
8.78k
  if (id4 == NULL || id5 == NULL)
936
0
    goto error_return;
937
938
  /* Fill in the contents of these sections.  */
939
8.78k
  if (import_name_type == IMPORT_ORDINAL)
940
2.57k
    {
941
2.57k
      if (ordinal == 0)
942
  /* See PR 20907 for a reproducer.  */
943
409
  goto error_return;
944
945
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
946
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
947
      ((unsigned int *) id4->contents)[0] = ordinal;
948
      ((unsigned int *) id4->contents)[1] = 0x80000000;
949
      ((unsigned int *) id5->contents)[0] = ordinal;
950
      ((unsigned int *) id5->contents)[1] = 0x80000000;
951
#else
952
2.16k
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
953
2.16k
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
954
2.16k
#endif
955
2.16k
    }
956
6.20k
  else
957
6.20k
    {
958
6.20k
      char *symbol;
959
6.20k
      unsigned int len;
960
961
      /* Create .idata$6 - the Hint Name Table.  */
962
6.20k
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
963
6.20k
      if (id6 == NULL)
964
0
  goto error_return;
965
966
      /* If necessary, trim the import symbol name.  */
967
6.20k
      symbol = import_name;
968
969
      /* As used by MS compiler, '_', '@', and '?' are alternative
970
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
971
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
972
   of these is used for a symbol.  We strip this leading char for
973
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
974
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
975
976
6.20k
      if (import_name_type != IMPORT_NAME
977
6.20k
    && import_name_type != IMPORT_NAME_EXPORTAS)
978
4.41k
  {
979
4.41k
    char c = symbol[0];
980
981
    /* Check that we don't remove for targets with empty
982
       USER_LABEL_PREFIX the leading underscore.  */
983
4.41k
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
984
4.41k
        || c == '@' || c == '?')
985
1.68k
      symbol++;
986
4.41k
  }
987
988
6.20k
      len = strlen (symbol);
989
6.20k
      if (import_name_type == IMPORT_NAME_UNDECORATE)
990
2.16k
  {
991
    /* Truncate at the first '@'.  */
992
2.16k
    char *at = strchr (symbol, '@');
993
994
2.16k
    if (at != NULL)
995
675
      len = at - symbol;
996
2.16k
  }
997
998
6.20k
      id6->contents[0] = ordinal & 0xff;
999
6.20k
      id6->contents[1] = ordinal >> 8;
1000
1001
6.20k
      memcpy ((char *) id6->contents + 2, symbol, len);
1002
6.20k
      id6->contents[len + 2] = '\0';
1003
6.20k
    }
1004
1005
8.37k
  if (import_name_type != IMPORT_ORDINAL)
1006
6.20k
    {
1007
6.20k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1008
6.20k
      pe_ILF_save_relocs (&vars, id4);
1009
1010
6.20k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1011
6.20k
      pe_ILF_save_relocs (&vars, id5);
1012
6.20k
    }
1013
1014
  /* Create an import symbol.  */
1015
8.37k
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1016
8.37k
  imp_sym   = vars.sym_ptr_ptr - 1;
1017
8.37k
  imp_index = vars.sym_index - 1;
1018
1019
  /* Create extra sections depending upon the type of import we are
1020
     dealing with.  */
1021
8.37k
  switch (import_type)
1022
8.37k
    {
1023
0
      int i;
1024
1025
2.84k
    case IMPORT_CODE:
1026
      /* CODE functions are special, in that they get a trampoline that
1027
   jumps to the main import symbol.  Create a .text section to hold it.
1028
   First we need to look up its contents in the jump table.  */
1029
5.68k
      for (i = NUM_ENTRIES (jtab); i--;)
1030
5.68k
  {
1031
5.68k
    if (jtab[i].size == 0)
1032
2.84k
      continue;
1033
2.84k
    if (jtab[i].magic == magic)
1034
2.84k
      break;
1035
2.84k
  }
1036
      /* If we did not find a matching entry something is wrong.  */
1037
2.84k
      if (i < 0)
1038
0
  abort ();
1039
1040
      /* Create the .text section.  */
1041
2.84k
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1042
2.84k
      if (text == NULL)
1043
0
  goto error_return;
1044
1045
      /* Copy in the jump code.  */
1046
2.84k
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1047
1048
      /* Create a reloc for the data in the text section.  */
1049
#ifdef MIPS_ARCH_MAGIC_WINCE
1050
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1051
  {
1052
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1053
              (struct bfd_symbol **) imp_sym,
1054
              imp_index);
1055
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1056
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1057
              (struct bfd_symbol **) imp_sym,
1058
              imp_index);
1059
  }
1060
      else
1061
#endif
1062
#ifdef AMD64MAGIC
1063
      if (magic == AMD64MAGIC)
1064
  {
1065
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1066
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1067
              imp_index);
1068
  }
1069
      else
1070
#endif
1071
2.84k
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1072
2.84k
            BFD_RELOC_32, (asymbol **) imp_sym,
1073
2.84k
            imp_index);
1074
1075
2.84k
      pe_ILF_save_relocs (&vars, text);
1076
2.84k
      break;
1077
1078
3.14k
    case IMPORT_DATA:
1079
5.53k
    case IMPORT_CONST:
1080
5.53k
      break;
1081
1082
0
    default:
1083
      /* XXX code not yet written.  */
1084
0
      abort ();
1085
8.37k
    }
1086
1087
  /* Now create a symbol describing the imported value.  */
1088
8.37k
  switch (import_type)
1089
8.37k
    {
1090
2.84k
    case IMPORT_CODE:
1091
2.84k
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1092
2.84k
          BSF_NOT_AT_END | BSF_FUNCTION);
1093
1094
2.84k
      break;
1095
1096
3.14k
    case IMPORT_DATA:
1097
      /* Nothing to do here.  */
1098
3.14k
      break;
1099
1100
2.38k
    case IMPORT_CONST:
1101
2.38k
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1102
2.38k
      break;
1103
1104
0
    default:
1105
      /* XXX code not yet written.  */
1106
0
      abort ();
1107
8.37k
    }
1108
1109
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1110
8.37k
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1111
8.37k
  if (ptr)
1112
1.11k
    *ptr = 0;
1113
8.37k
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1114
8.37k
  if (ptr)
1115
1.11k
    *ptr = '.';
1116
1117
  /* Initialise the bfd.  */
1118
8.37k
  memset (&internal_f, 0, sizeof (internal_f));
1119
1120
8.37k
  internal_f.f_magic  = magic;
1121
8.37k
  internal_f.f_symptr = 0;
1122
8.37k
  internal_f.f_nsyms  = 0;
1123
8.37k
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1124
1125
8.37k
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1126
8.37k
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1127
0
    goto error_return;
1128
1129
8.37k
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1130
0
    goto error_return;
1131
1132
8.37k
  obj_pe (abfd) = true;
1133
#ifdef THUMBPEMAGIC
1134
  if (vars.magic == THUMBPEMAGIC)
1135
    /* Stop some linker warnings about thumb code not supporting
1136
       interworking.  */
1137
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1138
#endif
1139
1140
  /* Switch from file contents to memory contents.  */
1141
8.37k
  bfd_cache_close (abfd);
1142
1143
8.37k
  abfd->iostream = (void *) vars.bim;
1144
8.37k
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1145
8.37k
  abfd->iovec = &_bfd_memory_iovec;
1146
8.37k
  abfd->where = 0;
1147
8.37k
  abfd->origin = 0;
1148
8.37k
  abfd->size = 0;
1149
8.37k
  obj_sym_filepos (abfd) = 0;
1150
1151
  /* Point the bfd at the symbol table.  */
1152
8.37k
  obj_symbols (abfd) = vars.sym_cache;
1153
8.37k
  abfd->symcount = vars.sym_index;
1154
1155
8.37k
  obj_raw_syments (abfd) = vars.native_syms;
1156
8.37k
  obj_raw_syment_count (abfd) = vars.sym_index;
1157
8.37k
  obj_coff_keep_raw_syms (abfd) = true;
1158
1159
8.37k
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1160
8.37k
  obj_coff_keep_syms (abfd) = true;
1161
1162
8.37k
  obj_convert (abfd) = vars.sym_table;
1163
8.37k
  obj_conv_table_size (abfd) = vars.sym_index;
1164
1165
8.37k
  obj_coff_strings (abfd) = vars.string_table;
1166
8.37k
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1167
8.37k
  obj_coff_keep_strings (abfd) = true;
1168
1169
8.37k
  return true;
1170
1171
409
 error_return:
1172
409
  free (vars.bim->buffer);
1173
409
  free (vars.bim);
1174
409
  return false;
1175
8.37k
}
1176
1177
/* Cleanup function, returned from check_format hook.  */
1178
1179
static void
1180
pe_ILF_cleanup (bfd *abfd)
1181
62
{
1182
62
  coff_object_cleanup (abfd);
1183
1184
62
  struct bfd_in_memory *bim = abfd->iostream;
1185
62
  free (bim->buffer);
1186
62
  free (bim);
1187
62
  abfd->iostream = NULL;
1188
62
}
Unexecuted instantiation: pei-i386.c:pe_ILF_cleanup
Unexecuted instantiation: pei-x86_64.c:pe_ILF_cleanup
Unexecuted instantiation: pei-aarch64.c:pe_ILF_cleanup
Unexecuted instantiation: pei-ia64.c:pe_ILF_cleanup
Unexecuted instantiation: pei-loongarch64.c:pe_ILF_cleanup
Unexecuted instantiation: pei-riscv64.c:pe_ILF_cleanup
pei-arm-wince.c:pe_ILF_cleanup
Line
Count
Source
1181
31
{
1182
31
  coff_object_cleanup (abfd);
1183
1184
31
  struct bfd_in_memory *bim = abfd->iostream;
1185
31
  free (bim->buffer);
1186
31
  free (bim);
1187
31
  abfd->iostream = NULL;
1188
31
}
pei-arm.c:pe_ILF_cleanup
Line
Count
Source
1181
31
{
1182
31
  coff_object_cleanup (abfd);
1183
1184
31
  struct bfd_in_memory *bim = abfd->iostream;
1185
31
  free (bim->buffer);
1186
31
  free (bim);
1187
31
  abfd->iostream = NULL;
1188
31
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_cleanup
Unexecuted instantiation: pei-sh.c:pe_ILF_cleanup
1189
1190
/* We have detected an Import Library Format archive element.
1191
   Decode the element and return the appropriate target.  */
1192
1193
static bfd_cleanup
1194
pe_ILF_object_p (bfd *abfd)
1195
539k
{
1196
539k
  bfd_byte    buffer[14];
1197
539k
  bfd_byte *    ptr;
1198
539k
  char *    symbol_name;
1199
539k
  char *    source_dll;
1200
539k
  char *    import_name;
1201
539k
  unsigned int    machine;
1202
539k
  bfd_size_type   size;
1203
539k
  unsigned int    ordinal;
1204
539k
  unsigned int    types;
1205
539k
  unsigned int    magic;
1206
1207
  /* Upon entry the first six bytes of the ILF header have
1208
     already been read.  Now read the rest of the header.  */
1209
539k
  if (bfd_read (buffer, 14, abfd) != 14)
1210
3.23k
    return NULL;
1211
1212
536k
  ptr = buffer;
1213
1214
536k
  machine = H_GET_16 (abfd, ptr);
1215
536k
  ptr += 2;
1216
1217
  /* Check that the machine type is recognised.  */
1218
536k
  magic = 0;
1219
1220
536k
  switch (machine)
1221
536k
    {
1222
4.11k
    case IMAGE_FILE_MACHINE_UNKNOWN:
1223
5.09k
    case IMAGE_FILE_MACHINE_ALPHA:
1224
5.09k
    case IMAGE_FILE_MACHINE_ALPHA64:
1225
6.97k
    case IMAGE_FILE_MACHINE_IA64:
1226
6.97k
      break;
1227
1228
64.9k
    case IMAGE_FILE_MACHINE_I386:
1229
#ifdef I386MAGIC
1230
12.2k
      magic = I386MAGIC;
1231
#endif
1232
64.9k
      break;
1233
1234
82.5k
    case IMAGE_FILE_MACHINE_AMD64:
1235
#ifdef AMD64MAGIC
1236
9.95k
      magic = AMD64MAGIC;
1237
#endif
1238
82.5k
      break;
1239
1240
1.87k
    case IMAGE_FILE_MACHINE_R3000:
1241
1.95k
    case IMAGE_FILE_MACHINE_R4000:
1242
2.94k
    case IMAGE_FILE_MACHINE_R10000:
1243
1244
3.91k
    case IMAGE_FILE_MACHINE_MIPS16:
1245
5.75k
    case IMAGE_FILE_MACHINE_MIPSFPU:
1246
5.77k
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1247
#ifdef MIPS_ARCH_MAGIC_WINCE
1248
      magic = MIPS_ARCH_MAGIC_WINCE;
1249
#endif
1250
5.77k
      break;
1251
1252
33.9k
    case IMAGE_FILE_MACHINE_SH3:
1253
92.4k
    case IMAGE_FILE_MACHINE_SH4:
1254
#ifdef SH_ARCH_MAGIC_WINCE
1255
12.1k
      magic = SH_ARCH_MAGIC_WINCE;
1256
#endif
1257
92.4k
      break;
1258
1259
46.4k
    case IMAGE_FILE_MACHINE_ARM:
1260
#ifdef ARMPEMAGIC
1261
15.7k
      magic = ARMPEMAGIC;
1262
#endif
1263
46.4k
      break;
1264
1265
31.9k
    case IMAGE_FILE_MACHINE_ARM64:
1266
#ifdef AARCH64MAGIC
1267
8.93k
      magic = AARCH64MAGIC;
1268
#endif
1269
31.9k
      break;
1270
1271
66.6k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1272
#ifdef LOONGARCH64MAGIC
1273
7.43k
      magic = LOONGARCH64MAGIC;
1274
#endif
1275
66.6k
      break;
1276
1277
68.8k
    case IMAGE_FILE_MACHINE_RISCV64:
1278
#ifdef RISCV64MAGIC
1279
10.1k
      magic = RISCV64MAGIC;
1280
#endif
1281
68.8k
      break;
1282
1283
18.5k
    case IMAGE_FILE_MACHINE_THUMB:
1284
#ifdef THUMBPEMAGIC
1285
      {
1286
  extern const bfd_target TARGET_LITTLE_SYM;
1287
1288
6.07k
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1289
6.07k
    magic = THUMBPEMAGIC;
1290
      }
1291
#endif
1292
18.5k
      break;
1293
1294
0
    case IMAGE_FILE_MACHINE_POWERPC:
1295
      /* We no longer support PowerPC.  */
1296
51.2k
    default:
1297
51.2k
      _bfd_error_handler
1298
  /* xgettext:c-format */
1299
51.2k
  (_("%pB: unrecognised machine type (0x%x)"
1300
51.2k
     " in Import Library Format archive"),
1301
51.2k
   abfd, machine);
1302
51.2k
      bfd_set_error (bfd_error_malformed_archive);
1303
1304
51.2k
      return NULL;
1305
0
      break;
1306
536k
    }
1307
1308
485k
  if (magic == 0)
1309
402k
    {
1310
402k
      _bfd_error_handler
1311
  /* xgettext:c-format */
1312
402k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1313
402k
     " in Import Library Format archive"),
1314
402k
   abfd, machine);
1315
402k
      bfd_set_error (bfd_error_wrong_format);
1316
1317
402k
      return NULL;
1318
402k
    }
1319
1320
  /* We do not bother to check the date.
1321
     date = H_GET_32 (abfd, ptr);  */
1322
82.5k
  ptr += 4;
1323
1324
82.5k
  size = H_GET_32 (abfd, ptr);
1325
82.5k
  ptr += 4;
1326
1327
82.5k
  if (size == 0)
1328
2.20k
    {
1329
2.20k
      _bfd_error_handler
1330
2.20k
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1331
2.20k
      bfd_set_error (bfd_error_malformed_archive);
1332
1333
2.20k
      return NULL;
1334
2.20k
    }
1335
1336
80.3k
  ordinal = H_GET_16 (abfd, ptr);
1337
80.3k
  ptr += 2;
1338
1339
80.3k
  types = H_GET_16 (abfd, ptr);
1340
  /* ptr += 2; */
1341
1342
  /* Now read in the two strings that follow.  */
1343
80.3k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1344
80.3k
  if (ptr == NULL)
1345
8.02k
    return NULL;
1346
1347
72.3k
  symbol_name = (char *) ptr;
1348
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1349
72.3k
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1350
1351
  /* Verify that the strings are null terminated.  */
1352
72.3k
  if (ptr[size - 1] != 0
1353
72.3k
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1354
5.03k
    {
1355
5.03k
      _bfd_error_handler
1356
5.03k
  (_("%pB: string not null terminated in ILF object file"), abfd);
1357
5.03k
      bfd_set_error (bfd_error_malformed_archive);
1358
5.03k
      bfd_release (abfd, ptr);
1359
5.03k
      return NULL;
1360
5.03k
    }
1361
1362
  /* An ILF file may contain a third string, after source_dll; this is
1363
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1364
     block of data is null terminated, ptr[size-1]==0, but we don't
1365
     know how many individual null terminated strings we have in there.
1366
1367
     First find the end of source_dll.  */
1368
67.3k
  import_name = source_dll + strlen (source_dll) + 1;
1369
67.3k
  if ((bfd_byte *) import_name >= ptr + size)
1370
13.3k
    {
1371
      /* If this points at the end of the ptr+size block, we only had
1372
   two strings. */
1373
13.3k
      import_name = NULL;
1374
13.3k
    }
1375
1376
  /* Now construct the bfd.  */
1377
67.3k
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1378
67.3k
          source_dll, ordinal, types,
1379
67.3k
          import_name))
1380
11.5k
    {
1381
11.5k
      bfd_release (abfd, ptr);
1382
11.5k
      return NULL;
1383
11.5k
    }
1384
1385
55.8k
  return pe_ILF_cleanup;
1386
67.3k
}
pei-i386.c:pe_ILF_object_p
Line
Count
Source
1195
66.4k
{
1196
66.4k
  bfd_byte    buffer[14];
1197
66.4k
  bfd_byte *    ptr;
1198
66.4k
  char *    symbol_name;
1199
66.4k
  char *    source_dll;
1200
66.4k
  char *    import_name;
1201
66.4k
  unsigned int    machine;
1202
66.4k
  bfd_size_type   size;
1203
66.4k
  unsigned int    ordinal;
1204
66.4k
  unsigned int    types;
1205
66.4k
  unsigned int    magic;
1206
1207
  /* Upon entry the first six bytes of the ILF header have
1208
     already been read.  Now read the rest of the header.  */
1209
66.4k
  if (bfd_read (buffer, 14, abfd) != 14)
1210
363
    return NULL;
1211
1212
66.0k
  ptr = buffer;
1213
1214
66.0k
  machine = H_GET_16 (abfd, ptr);
1215
66.0k
  ptr += 2;
1216
1217
  /* Check that the machine type is recognised.  */
1218
66.0k
  magic = 0;
1219
1220
66.0k
  switch (machine)
1221
66.0k
    {
1222
423
    case IMAGE_FILE_MACHINE_UNKNOWN:
1223
532
    case IMAGE_FILE_MACHINE_ALPHA:
1224
532
    case IMAGE_FILE_MACHINE_ALPHA64:
1225
742
    case IMAGE_FILE_MACHINE_IA64:
1226
742
      break;
1227
1228
12.2k
    case IMAGE_FILE_MACHINE_I386:
1229
12.2k
#ifdef I386MAGIC
1230
12.2k
      magic = I386MAGIC;
1231
12.2k
#endif
1232
12.2k
      break;
1233
1234
9.92k
    case IMAGE_FILE_MACHINE_AMD64:
1235
#ifdef AMD64MAGIC
1236
      magic = AMD64MAGIC;
1237
#endif
1238
9.92k
      break;
1239
1240
209
    case IMAGE_FILE_MACHINE_R3000:
1241
218
    case IMAGE_FILE_MACHINE_R4000:
1242
328
    case IMAGE_FILE_MACHINE_R10000:
1243
1244
436
    case IMAGE_FILE_MACHINE_MIPS16:
1245
641
    case IMAGE_FILE_MACHINE_MIPSFPU:
1246
644
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1247
#ifdef MIPS_ARCH_MAGIC_WINCE
1248
      magic = MIPS_ARCH_MAGIC_WINCE;
1249
#endif
1250
644
      break;
1251
1252
4.60k
    case IMAGE_FILE_MACHINE_SH3:
1253
12.1k
    case IMAGE_FILE_MACHINE_SH4:
1254
#ifdef SH_ARCH_MAGIC_WINCE
1255
      magic = SH_ARCH_MAGIC_WINCE;
1256
#endif
1257
12.1k
      break;
1258
1259
3.02k
    case IMAGE_FILE_MACHINE_ARM:
1260
#ifdef ARMPEMAGIC
1261
      magic = ARMPEMAGIC;
1262
#endif
1263
3.02k
      break;
1264
1265
2.88k
    case IMAGE_FILE_MACHINE_ARM64:
1266
#ifdef AARCH64MAGIC
1267
      magic = AARCH64MAGIC;
1268
#endif
1269
2.88k
      break;
1270
1271
7.40k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1272
#ifdef LOONGARCH64MAGIC
1273
      magic = LOONGARCH64MAGIC;
1274
#endif
1275
7.40k
      break;
1276
1277
10.0k
    case IMAGE_FILE_MACHINE_RISCV64:
1278
#ifdef RISCV64MAGIC
1279
      magic = RISCV64MAGIC;
1280
#endif
1281
10.0k
      break;
1282
1283
1.28k
    case IMAGE_FILE_MACHINE_THUMB:
1284
#ifdef THUMBPEMAGIC
1285
      {
1286
  extern const bfd_target TARGET_LITTLE_SYM;
1287
1288
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1289
    magic = THUMBPEMAGIC;
1290
      }
1291
#endif
1292
1.28k
      break;
1293
1294
0
    case IMAGE_FILE_MACHINE_POWERPC:
1295
      /* We no longer support PowerPC.  */
1296
5.68k
    default:
1297
5.68k
      _bfd_error_handler
1298
  /* xgettext:c-format */
1299
5.68k
  (_("%pB: unrecognised machine type (0x%x)"
1300
5.68k
     " in Import Library Format archive"),
1301
5.68k
   abfd, machine);
1302
5.68k
      bfd_set_error (bfd_error_malformed_archive);
1303
1304
5.68k
      return NULL;
1305
0
      break;
1306
66.0k
    }
1307
1308
60.3k
  if (magic == 0)
1309
48.1k
    {
1310
48.1k
      _bfd_error_handler
1311
  /* xgettext:c-format */
1312
48.1k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1313
48.1k
     " in Import Library Format archive"),
1314
48.1k
   abfd, machine);
1315
48.1k
      bfd_set_error (bfd_error_wrong_format);
1316
1317
48.1k
      return NULL;
1318
48.1k
    }
1319
1320
  /* We do not bother to check the date.
1321
     date = H_GET_32 (abfd, ptr);  */
1322
12.2k
  ptr += 4;
1323
1324
12.2k
  size = H_GET_32 (abfd, ptr);
1325
12.2k
  ptr += 4;
1326
1327
12.2k
  if (size == 0)
1328
213
    {
1329
213
      _bfd_error_handler
1330
213
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1331
213
      bfd_set_error (bfd_error_malformed_archive);
1332
1333
213
      return NULL;
1334
213
    }
1335
1336
12.0k
  ordinal = H_GET_16 (abfd, ptr);
1337
12.0k
  ptr += 2;
1338
1339
12.0k
  types = H_GET_16 (abfd, ptr);
1340
  /* ptr += 2; */
1341
1342
  /* Now read in the two strings that follow.  */
1343
12.0k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1344
12.0k
  if (ptr == NULL)
1345
771
    return NULL;
1346
1347
11.2k
  symbol_name = (char *) ptr;
1348
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1349
11.2k
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1350
1351
  /* Verify that the strings are null terminated.  */
1352
11.2k
  if (ptr[size - 1] != 0
1353
11.2k
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1354
633
    {
1355
633
      _bfd_error_handler
1356
633
  (_("%pB: string not null terminated in ILF object file"), abfd);
1357
633
      bfd_set_error (bfd_error_malformed_archive);
1358
633
      bfd_release (abfd, ptr);
1359
633
      return NULL;
1360
633
    }
1361
1362
  /* An ILF file may contain a third string, after source_dll; this is
1363
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1364
     block of data is null terminated, ptr[size-1]==0, but we don't
1365
     know how many individual null terminated strings we have in there.
1366
1367
     First find the end of source_dll.  */
1368
10.6k
  import_name = source_dll + strlen (source_dll) + 1;
1369
10.6k
  if ((bfd_byte *) import_name >= ptr + size)
1370
2.82k
    {
1371
      /* If this points at the end of the ptr+size block, we only had
1372
   two strings. */
1373
2.82k
      import_name = NULL;
1374
2.82k
    }
1375
1376
  /* Now construct the bfd.  */
1377
10.6k
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1378
10.6k
          source_dll, ordinal, types,
1379
10.6k
          import_name))
1380
1.56k
    {
1381
1.56k
      bfd_release (abfd, ptr);
1382
1.56k
      return NULL;
1383
1.56k
    }
1384
1385
9.07k
  return pe_ILF_cleanup;
1386
10.6k
}
pei-x86_64.c:pe_ILF_object_p
Line
Count
Source
1195
41.8k
{
1196
41.8k
  bfd_byte    buffer[14];
1197
41.8k
  bfd_byte *    ptr;
1198
41.8k
  char *    symbol_name;
1199
41.8k
  char *    source_dll;
1200
41.8k
  char *    import_name;
1201
41.8k
  unsigned int    machine;
1202
41.8k
  bfd_size_type   size;
1203
41.8k
  unsigned int    ordinal;
1204
41.8k
  unsigned int    types;
1205
41.8k
  unsigned int    magic;
1206
1207
  /* Upon entry the first six bytes of the ILF header have
1208
     already been read.  Now read the rest of the header.  */
1209
41.8k
  if (bfd_read (buffer, 14, abfd) != 14)
1210
363
    return NULL;
1211
1212
41.5k
  ptr = buffer;
1213
1214
41.5k
  machine = H_GET_16 (abfd, ptr);
1215
41.5k
  ptr += 2;
1216
1217
  /* Check that the machine type is recognised.  */
1218
41.5k
  magic = 0;
1219
1220
41.5k
  switch (machine)
1221
41.5k
    {
1222
423
    case IMAGE_FILE_MACHINE_UNKNOWN:
1223
532
    case IMAGE_FILE_MACHINE_ALPHA:
1224
532
    case IMAGE_FILE_MACHINE_ALPHA64:
1225
742
    case IMAGE_FILE_MACHINE_IA64:
1226
742
      break;
1227
1228
3.23k
    case IMAGE_FILE_MACHINE_I386:
1229
#ifdef I386MAGIC
1230
      magic = I386MAGIC;
1231
#endif
1232
3.23k
      break;
1233
1234
9.95k
    case IMAGE_FILE_MACHINE_AMD64:
1235
9.95k
#ifdef AMD64MAGIC
1236
9.95k
      magic = AMD64MAGIC;
1237
9.95k
#endif
1238
9.95k
      break;
1239
1240
209
    case IMAGE_FILE_MACHINE_R3000:
1241
218
    case IMAGE_FILE_MACHINE_R4000:
1242
328
    case IMAGE_FILE_MACHINE_R10000:
1243
1244
436
    case IMAGE_FILE_MACHINE_MIPS16:
1245
641
    case IMAGE_FILE_MACHINE_MIPSFPU:
1246
644
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1247
#ifdef MIPS_ARCH_MAGIC_WINCE
1248
      magic = MIPS_ARCH_MAGIC_WINCE;
1249
#endif
1250
644
      break;
1251
1252
937
    case IMAGE_FILE_MACHINE_SH3:
1253
3.82k
    case IMAGE_FILE_MACHINE_SH4:
1254
#ifdef SH_ARCH_MAGIC_WINCE
1255
      magic = SH_ARCH_MAGIC_WINCE;
1256
#endif
1257
3.82k
      break;
1258
1259
3.02k
    case IMAGE_FILE_MACHINE_ARM:
1260
#ifdef ARMPEMAGIC
1261
      magic = ARMPEMAGIC;
1262
#endif
1263
3.02k
      break;
1264
1265
2.88k
    case IMAGE_FILE_MACHINE_ARM64:
1266
#ifdef AARCH64MAGIC
1267
      magic = AARCH64MAGIC;
1268
#endif
1269
2.88k
      break;
1270
1271
7.40k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1272
#ifdef LOONGARCH64MAGIC
1273
      magic = LOONGARCH64MAGIC;
1274
#endif
1275
7.40k
      break;
1276
1277
2.82k
    case IMAGE_FILE_MACHINE_RISCV64:
1278
#ifdef RISCV64MAGIC
1279
      magic = RISCV64MAGIC;
1280
#endif
1281
2.82k
      break;
1282
1283
1.28k
    case IMAGE_FILE_MACHINE_THUMB:
1284
#ifdef THUMBPEMAGIC
1285
      {
1286
  extern const bfd_target TARGET_LITTLE_SYM;
1287
1288
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1289
    magic = THUMBPEMAGIC;
1290
      }
1291
#endif
1292
1.28k
      break;
1293
1294
0
    case IMAGE_FILE_MACHINE_POWERPC:
1295
      /* We no longer support PowerPC.  */
1296
5.68k
    default:
1297
5.68k
      _bfd_error_handler
1298
  /* xgettext:c-format */
1299
5.68k
  (_("%pB: unrecognised machine type (0x%x)"
1300
5.68k
     " in Import Library Format archive"),
1301
5.68k
   abfd, machine);
1302
5.68k
      bfd_set_error (bfd_error_malformed_archive);
1303
1304
5.68k
      return NULL;
1305
0
      break;
1306
41.5k
    }
1307
1308
35.8k
  if (magic == 0)
1309
25.8k
    {
1310
25.8k
      _bfd_error_handler
1311
  /* xgettext:c-format */
1312
25.8k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1313
25.8k
     " in Import Library Format archive"),
1314
25.8k
   abfd, machine);
1315
25.8k
      bfd_set_error (bfd_error_wrong_format);
1316
1317
25.8k
      return NULL;
1318
25.8k
    }
1319
1320
  /* We do not bother to check the date.
1321
     date = H_GET_32 (abfd, ptr);  */
1322
9.95k
  ptr += 4;
1323
1324
9.95k
  size = H_GET_32 (abfd, ptr);
1325
9.95k
  ptr += 4;
1326
1327
9.95k
  if (size == 0)
1328
312
    {
1329
312
      _bfd_error_handler
1330
312
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1331
312
      bfd_set_error (bfd_error_malformed_archive);
1332
1333
312
      return NULL;
1334
312
    }
1335
1336
9.63k
  ordinal = H_GET_16 (abfd, ptr);
1337
9.63k
  ptr += 2;
1338
1339
9.63k
  types = H_GET_16 (abfd, ptr);
1340
  /* ptr += 2; */
1341
1342
  /* Now read in the two strings that follow.  */
1343
9.63k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1344
9.63k
  if (ptr == NULL)
1345
764
    return NULL;
1346
1347
8.87k
  symbol_name = (char *) ptr;
1348
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1349
8.87k
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1350
1351
  /* Verify that the strings are null terminated.  */
1352
8.87k
  if (ptr[size - 1] != 0
1353
8.87k
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1354
523
    {
1355
523
      _bfd_error_handler
1356
523
  (_("%pB: string not null terminated in ILF object file"), abfd);
1357
523
      bfd_set_error (bfd_error_malformed_archive);
1358
523
      bfd_release (abfd, ptr);
1359
523
      return NULL;
1360
523
    }
1361
1362
  /* An ILF file may contain a third string, after source_dll; this is
1363
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1364
     block of data is null terminated, ptr[size-1]==0, but we don't
1365
     know how many individual null terminated strings we have in there.
1366
1367
     First find the end of source_dll.  */
1368
8.35k
  import_name = source_dll + strlen (source_dll) + 1;
1369
8.35k
  if ((bfd_byte *) import_name >= ptr + size)
1370
1.54k
    {
1371
      /* If this points at the end of the ptr+size block, we only had
1372
   two strings. */
1373
1.54k
      import_name = NULL;
1374
1.54k
    }
1375
1376
  /* Now construct the bfd.  */
1377
8.35k
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1378
8.35k
          source_dll, ordinal, types,
1379
8.35k
          import_name))
1380
1.55k
    {
1381
1.55k
      bfd_release (abfd, ptr);
1382
1.55k
      return NULL;
1383
1.55k
    }
1384
1385
6.80k
  return pe_ILF_cleanup;
1386
8.35k
}
pei-aarch64.c:pe_ILF_object_p
Line
Count
Source
1195
85.5k
{
1196
85.5k
  bfd_byte    buffer[14];
1197
85.5k
  bfd_byte *    ptr;
1198
85.5k
  char *    symbol_name;
1199
85.5k
  char *    source_dll;
1200
85.5k
  char *    import_name;
1201
85.5k
  unsigned int    machine;
1202
85.5k
  bfd_size_type   size;
1203
85.5k
  unsigned int    ordinal;
1204
85.5k
  unsigned int    types;
1205
85.5k
  unsigned int    magic;
1206
1207
  /* Upon entry the first six bytes of the ILF header have
1208
     already been read.  Now read the rest of the header.  */
1209
85.5k
  if (bfd_read (buffer, 14, abfd) != 14)
1210
363
    return NULL;
1211
1212
85.2k
  ptr = buffer;
1213
1214
85.2k
  machine = H_GET_16 (abfd, ptr);
1215
85.2k
  ptr += 2;
1216
1217
  /* Check that the machine type is recognised.  */
1218
85.2k
  magic = 0;
1219
1220
85.2k
  switch (machine)
1221
85.2k
    {
1222
423
    case IMAGE_FILE_MACHINE_UNKNOWN:
1223
532
    case IMAGE_FILE_MACHINE_ALPHA:
1224
532
    case IMAGE_FILE_MACHINE_ALPHA64:
1225
742
    case IMAGE_FILE_MACHINE_IA64:
1226
742
      break;
1227
1228
12.2k
    case IMAGE_FILE_MACHINE_I386:
1229
#ifdef I386MAGIC
1230
      magic = I386MAGIC;
1231
#endif
1232
12.2k
      break;
1233
1234
9.92k
    case IMAGE_FILE_MACHINE_AMD64:
1235
#ifdef AMD64MAGIC
1236
      magic = AMD64MAGIC;
1237
#endif
1238
9.92k
      break;
1239
1240
209
    case IMAGE_FILE_MACHINE_R3000:
1241
218
    case IMAGE_FILE_MACHINE_R4000:
1242
328
    case IMAGE_FILE_MACHINE_R10000:
1243
1244
436
    case IMAGE_FILE_MACHINE_MIPS16:
1245
641
    case IMAGE_FILE_MACHINE_MIPSFPU:
1246
644
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1247
#ifdef MIPS_ARCH_MAGIC_WINCE
1248
      magic = MIPS_ARCH_MAGIC_WINCE;
1249
#endif
1250
644
      break;
1251
1252
4.60k
    case IMAGE_FILE_MACHINE_SH3:
1253
12.1k
    case IMAGE_FILE_MACHINE_SH4:
1254
#ifdef SH_ARCH_MAGIC_WINCE
1255
      magic = SH_ARCH_MAGIC_WINCE;
1256
#endif
1257
12.1k
      break;
1258
1259
12.6k
    case IMAGE_FILE_MACHINE_ARM:
1260
#ifdef ARMPEMAGIC
1261
      magic = ARMPEMAGIC;
1262
#endif
1263
12.6k
      break;
1264
1265
8.93k
    case IMAGE_FILE_MACHINE_ARM64:
1266
8.93k
#ifdef AARCH64MAGIC
1267
8.93k
      magic = AARCH64MAGIC;
1268
8.93k
#endif
1269
8.93k
      break;
1270
1271
7.40k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1272
#ifdef LOONGARCH64MAGIC
1273
      magic = LOONGARCH64MAGIC;
1274
#endif
1275
7.40k
      break;
1276
1277
10.0k
    case IMAGE_FILE_MACHINE_RISCV64:
1278
#ifdef RISCV64MAGIC
1279
      magic = RISCV64MAGIC;
1280
#endif
1281
10.0k
      break;
1282
1283
4.79k
    case IMAGE_FILE_MACHINE_THUMB:
1284
#ifdef THUMBPEMAGIC
1285
      {
1286
  extern const bfd_target TARGET_LITTLE_SYM;
1287
1288
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1289
    magic = THUMBPEMAGIC;
1290
      }
1291
#endif
1292
4.79k
      break;
1293
1294
0
    case IMAGE_FILE_MACHINE_POWERPC:
1295
      /* We no longer support PowerPC.  */
1296
5.68k
    default:
1297
5.68k
      _bfd_error_handler
1298
  /* xgettext:c-format */
1299
5.68k
  (_("%pB: unrecognised machine type (0x%x)"
1300
5.68k
     " in Import Library Format archive"),
1301
5.68k
   abfd, machine);
1302
5.68k
      bfd_set_error (bfd_error_malformed_archive);
1303
1304
5.68k
      return NULL;
1305
0
      break;
1306
85.2k
    }
1307
1308
79.5k
  if (magic == 0)
1309
70.5k
    {
1310
70.5k
      _bfd_error_handler
1311
  /* xgettext:c-format */
1312
70.5k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1313
70.5k
     " in Import Library Format archive"),
1314
70.5k
   abfd, machine);
1315
70.5k
      bfd_set_error (bfd_error_wrong_format);
1316
1317
70.5k
      return NULL;
1318
70.5k
    }
1319
1320
  /* We do not bother to check the date.
1321
     date = H_GET_32 (abfd, ptr);  */
1322
8.93k
  ptr += 4;
1323
1324
8.93k
  size = H_GET_32 (abfd, ptr);
1325
8.93k
  ptr += 4;
1326
1327
8.93k
  if (size == 0)
1328
215
    {
1329
215
      _bfd_error_handler
1330
215
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1331
215
      bfd_set_error (bfd_error_malformed_archive);
1332
1333
215
      return NULL;
1334
215
    }
1335
1336
8.71k
  ordinal = H_GET_16 (abfd, ptr);
1337
8.71k
  ptr += 2;
1338
1339
8.71k
  types = H_GET_16 (abfd, ptr);
1340
  /* ptr += 2; */
1341
1342
  /* Now read in the two strings that follow.  */
1343
8.71k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1344
8.71k
  if (ptr == NULL)
1345
740
    return NULL;
1346
1347
7.97k
  symbol_name = (char *) ptr;
1348
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1349
7.97k
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1350
1351
  /* Verify that the strings are null terminated.  */
1352
7.97k
  if (ptr[size - 1] != 0
1353
7.97k
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1354
624
    {
1355
624
      _bfd_error_handler
1356
624
  (_("%pB: string not null terminated in ILF object file"), abfd);
1357
624
      bfd_set_error (bfd_error_malformed_archive);
1358
624
      bfd_release (abfd, ptr);
1359
624
      return NULL;
1360
624
    }
1361
1362
  /* An ILF file may contain a third string, after source_dll; this is
1363
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1364
     block of data is null terminated, ptr[size-1]==0, but we don't
1365
     know how many individual null terminated strings we have in there.
1366
1367
     First find the end of source_dll.  */
1368
7.35k
  import_name = source_dll + strlen (source_dll) + 1;
1369
7.35k
  if ((bfd_byte *) import_name >= ptr + size)
1370
1.77k
    {
1371
      /* If this points at the end of the ptr+size block, we only had
1372
   two strings. */
1373
1.77k
      import_name = NULL;
1374
1.77k
    }
1375
1376
  /* Now construct the bfd.  */
1377
7.35k
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1378
7.35k
          source_dll, ordinal, types,
1379
7.35k
          import_name))
1380
1.25k
    {
1381
1.25k
      bfd_release (abfd, ptr);
1382
1.25k
      return NULL;
1383
1.25k
    }
1384
1385
6.09k
  return pe_ILF_cleanup;
1386
7.35k
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_object_p
pei-loongarch64.c:pe_ILF_object_p
Line
Count
Source
1195
35.1k
{
1196
35.1k
  bfd_byte    buffer[14];
1197
35.1k
  bfd_byte *    ptr;
1198
35.1k
  char *    symbol_name;
1199
35.1k
  char *    source_dll;
1200
35.1k
  char *    import_name;
1201
35.1k
  unsigned int    machine;
1202
35.1k
  bfd_size_type   size;
1203
35.1k
  unsigned int    ordinal;
1204
35.1k
  unsigned int    types;
1205
35.1k
  unsigned int    magic;
1206
1207
  /* Upon entry the first six bytes of the ILF header have
1208
     already been read.  Now read the rest of the header.  */
1209
35.1k
  if (bfd_read (buffer, 14, abfd) != 14)
1210
363
    return NULL;
1211
1212
34.7k
  ptr = buffer;
1213
1214
34.7k
  machine = H_GET_16 (abfd, ptr);
1215
34.7k
  ptr += 2;
1216
1217
  /* Check that the machine type is recognised.  */
1218
34.7k
  magic = 0;
1219
1220
34.7k
  switch (machine)
1221
34.7k
    {
1222
423
    case IMAGE_FILE_MACHINE_UNKNOWN:
1223
532
    case IMAGE_FILE_MACHINE_ALPHA:
1224
532
    case IMAGE_FILE_MACHINE_ALPHA64:
1225
742
    case IMAGE_FILE_MACHINE_IA64:
1226
742
      break;
1227
1228
3.23k
    case IMAGE_FILE_MACHINE_I386:
1229
#ifdef I386MAGIC
1230
      magic = I386MAGIC;
1231
#endif
1232
3.23k
      break;
1233
1234
3.19k
    case IMAGE_FILE_MACHINE_AMD64:
1235
#ifdef AMD64MAGIC
1236
      magic = AMD64MAGIC;
1237
#endif
1238
3.19k
      break;
1239
1240
209
    case IMAGE_FILE_MACHINE_R3000:
1241
218
    case IMAGE_FILE_MACHINE_R4000:
1242
328
    case IMAGE_FILE_MACHINE_R10000:
1243
1244
436
    case IMAGE_FILE_MACHINE_MIPS16:
1245
641
    case IMAGE_FILE_MACHINE_MIPSFPU:
1246
644
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1247
#ifdef MIPS_ARCH_MAGIC_WINCE
1248
      magic = MIPS_ARCH_MAGIC_WINCE;
1249
#endif
1250
644
      break;
1251
1252
937
    case IMAGE_FILE_MACHINE_SH3:
1253
3.82k
    case IMAGE_FILE_MACHINE_SH4:
1254
#ifdef SH_ARCH_MAGIC_WINCE
1255
      magic = SH_ARCH_MAGIC_WINCE;
1256
#endif
1257
3.82k
      break;
1258
1259
3.02k
    case IMAGE_FILE_MACHINE_ARM:
1260
#ifdef ARMPEMAGIC
1261
      magic = ARMPEMAGIC;
1262
#endif
1263
3.02k
      break;
1264
1265
2.88k
    case IMAGE_FILE_MACHINE_ARM64:
1266
#ifdef AARCH64MAGIC
1267
      magic = AARCH64MAGIC;
1268
#endif
1269
2.88k
      break;
1270
1271
7.43k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1272
7.43k
#ifdef LOONGARCH64MAGIC
1273
7.43k
      magic = LOONGARCH64MAGIC;
1274
7.43k
#endif
1275
7.43k
      break;
1276
1277
2.82k
    case IMAGE_FILE_MACHINE_RISCV64:
1278
#ifdef RISCV64MAGIC
1279
      magic = RISCV64MAGIC;
1280
#endif
1281
2.82k
      break;
1282
1283
1.28k
    case IMAGE_FILE_MACHINE_THUMB:
1284
#ifdef THUMBPEMAGIC
1285
      {
1286
  extern const bfd_target TARGET_LITTLE_SYM;
1287
1288
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1289
    magic = THUMBPEMAGIC;
1290
      }
1291
#endif
1292
1.28k
      break;
1293
1294
0
    case IMAGE_FILE_MACHINE_POWERPC:
1295
      /* We no longer support PowerPC.  */
1296
5.68k
    default:
1297
5.68k
      _bfd_error_handler
1298
  /* xgettext:c-format */
1299
5.68k
  (_("%pB: unrecognised machine type (0x%x)"
1300
5.68k
     " in Import Library Format archive"),
1301
5.68k
   abfd, machine);
1302
5.68k
      bfd_set_error (bfd_error_malformed_archive);
1303
1304
5.68k
      return NULL;
1305
0
      break;
1306
34.7k
    }
1307
1308
29.1k
  if (magic == 0)
1309
21.6k
    {
1310
21.6k
      _bfd_error_handler
1311
  /* xgettext:c-format */
1312
21.6k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1313
21.6k
     " in Import Library Format archive"),
1314
21.6k
   abfd, machine);
1315
21.6k
      bfd_set_error (bfd_error_wrong_format);
1316
1317
21.6k
      return NULL;
1318
21.6k
    }
1319
1320
  /* We do not bother to check the date.
1321
     date = H_GET_32 (abfd, ptr);  */
1322
7.43k
  ptr += 4;
1323
1324
7.43k
  size = H_GET_32 (abfd, ptr);
1325
7.43k
  ptr += 4;
1326
1327
7.43k
  if (size == 0)
1328
214
    {
1329
214
      _bfd_error_handler
1330
214
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1331
214
      bfd_set_error (bfd_error_malformed_archive);
1332
1333
214
      return NULL;
1334
214
    }
1335
1336
7.22k
  ordinal = H_GET_16 (abfd, ptr);
1337
7.22k
  ptr += 2;
1338
1339
7.22k
  types = H_GET_16 (abfd, ptr);
1340
  /* ptr += 2; */
1341
1342
  /* Now read in the two strings that follow.  */
1343
7.22k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1344
7.22k
  if (ptr == NULL)
1345
977
    return NULL;
1346
1347
6.24k
  symbol_name = (char *) ptr;
1348
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1349
6.24k
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1350
1351
  /* Verify that the strings are null terminated.  */
1352
6.24k
  if (ptr[size - 1] != 0
1353
6.24k
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1354
430
    {
1355
430
      _bfd_error_handler
1356
430
  (_("%pB: string not null terminated in ILF object file"), abfd);
1357
430
      bfd_set_error (bfd_error_malformed_archive);
1358
430
      bfd_release (abfd, ptr);
1359
430
      return NULL;
1360
430
    }
1361
1362
  /* An ILF file may contain a third string, after source_dll; this is
1363
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1364
     block of data is null terminated, ptr[size-1]==0, but we don't
1365
     know how many individual null terminated strings we have in there.
1366
1367
     First find the end of source_dll.  */
1368
5.81k
  import_name = source_dll + strlen (source_dll) + 1;
1369
5.81k
  if ((bfd_byte *) import_name >= ptr + size)
1370
1.27k
    {
1371
      /* If this points at the end of the ptr+size block, we only had
1372
   two strings. */
1373
1.27k
      import_name = NULL;
1374
1.27k
    }
1375
1376
  /* Now construct the bfd.  */
1377
5.81k
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1378
5.81k
          source_dll, ordinal, types,
1379
5.81k
          import_name))
1380
1.05k
    {
1381
1.05k
      bfd_release (abfd, ptr);
1382
1.05k
      return NULL;
1383
1.05k
    }
1384
1385
4.76k
  return pe_ILF_cleanup;
1386
5.81k
}
pei-riscv64.c:pe_ILF_object_p
Line
Count
Source
1195
57.4k
{
1196
57.4k
  bfd_byte    buffer[14];
1197
57.4k
  bfd_byte *    ptr;
1198
57.4k
  char *    symbol_name;
1199
57.4k
  char *    source_dll;
1200
57.4k
  char *    import_name;
1201
57.4k
  unsigned int    machine;
1202
57.4k
  bfd_size_type   size;
1203
57.4k
  unsigned int    ordinal;
1204
57.4k
  unsigned int    types;
1205
57.4k
  unsigned int    magic;
1206
1207
  /* Upon entry the first six bytes of the ILF header have
1208
     already been read.  Now read the rest of the header.  */
1209
57.4k
  if (bfd_read (buffer, 14, abfd) != 14)
1210
363
    return NULL;
1211
1212
57.0k
  ptr = buffer;
1213
1214
57.0k
  machine = H_GET_16 (abfd, ptr);
1215
57.0k
  ptr += 2;
1216
1217
  /* Check that the machine type is recognised.  */
1218
57.0k
  magic = 0;
1219
1220
57.0k
  switch (machine)
1221
57.0k
    {
1222
423
    case IMAGE_FILE_MACHINE_UNKNOWN:
1223
532
    case IMAGE_FILE_MACHINE_ALPHA:
1224
532
    case IMAGE_FILE_MACHINE_ALPHA64:
1225
742
    case IMAGE_FILE_MACHINE_IA64:
1226
742
      break;
1227
1228
3.23k
    case IMAGE_FILE_MACHINE_I386:
1229
#ifdef I386MAGIC
1230
      magic = I386MAGIC;
1231
#endif
1232
3.23k
      break;
1233
1234
9.92k
    case IMAGE_FILE_MACHINE_AMD64:
1235
#ifdef AMD64MAGIC
1236
      magic = AMD64MAGIC;
1237
#endif
1238
9.92k
      break;
1239
1240
209
    case IMAGE_FILE_MACHINE_R3000:
1241
218
    case IMAGE_FILE_MACHINE_R4000:
1242
328
    case IMAGE_FILE_MACHINE_R10000:
1243
1244
436
    case IMAGE_FILE_MACHINE_MIPS16:
1245
641
    case IMAGE_FILE_MACHINE_MIPSFPU:
1246
644
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1247
#ifdef MIPS_ARCH_MAGIC_WINCE
1248
      magic = MIPS_ARCH_MAGIC_WINCE;
1249
#endif
1250
644
      break;
1251
1252
4.60k
    case IMAGE_FILE_MACHINE_SH3:
1253
12.1k
    case IMAGE_FILE_MACHINE_SH4:
1254
#ifdef SH_ARCH_MAGIC_WINCE
1255
      magic = SH_ARCH_MAGIC_WINCE;
1256
#endif
1257
12.1k
      break;
1258
1259
3.02k
    case IMAGE_FILE_MACHINE_ARM:
1260
#ifdef ARMPEMAGIC
1261
      magic = ARMPEMAGIC;
1262
#endif
1263
3.02k
      break;
1264
1265
2.88k
    case IMAGE_FILE_MACHINE_ARM64:
1266
#ifdef AARCH64MAGIC
1267
      magic = AARCH64MAGIC;
1268
#endif
1269
2.88k
      break;
1270
1271
7.40k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1272
#ifdef LOONGARCH64MAGIC
1273
      magic = LOONGARCH64MAGIC;
1274
#endif
1275
7.40k
      break;
1276
1277
10.1k
    case IMAGE_FILE_MACHINE_RISCV64:
1278
10.1k
#ifdef RISCV64MAGIC
1279
10.1k
      magic = RISCV64MAGIC;
1280
10.1k
#endif
1281
10.1k
      break;
1282
1283
1.28k
    case IMAGE_FILE_MACHINE_THUMB:
1284
#ifdef THUMBPEMAGIC
1285
      {
1286
  extern const bfd_target TARGET_LITTLE_SYM;
1287
1288
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1289
    magic = THUMBPEMAGIC;
1290
      }
1291
#endif
1292
1.28k
      break;
1293
1294
0
    case IMAGE_FILE_MACHINE_POWERPC:
1295
      /* We no longer support PowerPC.  */
1296
5.68k
    default:
1297
5.68k
      _bfd_error_handler
1298
  /* xgettext:c-format */
1299
5.68k
  (_("%pB: unrecognised machine type (0x%x)"
1300
5.68k
     " in Import Library Format archive"),
1301
5.68k
   abfd, machine);
1302
5.68k
      bfd_set_error (bfd_error_malformed_archive);
1303
1304
5.68k
      return NULL;
1305
0
      break;
1306
57.0k
    }
1307
1308
51.3k
  if (magic == 0)
1309
41.2k
    {
1310
41.2k
      _bfd_error_handler
1311
  /* xgettext:c-format */
1312
41.2k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1313
41.2k
     " in Import Library Format archive"),
1314
41.2k
   abfd, machine);
1315
41.2k
      bfd_set_error (bfd_error_wrong_format);
1316
1317
41.2k
      return NULL;
1318
41.2k
    }
1319
1320
  /* We do not bother to check the date.
1321
     date = H_GET_32 (abfd, ptr);  */
1322
10.1k
  ptr += 4;
1323
1324
10.1k
  size = H_GET_32 (abfd, ptr);
1325
10.1k
  ptr += 4;
1326
1327
10.1k
  if (size == 0)
1328
210
    {
1329
210
      _bfd_error_handler
1330
210
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1331
210
      bfd_set_error (bfd_error_malformed_archive);
1332
1333
210
      return NULL;
1334
210
    }
1335
1336
9.90k
  ordinal = H_GET_16 (abfd, ptr);
1337
9.90k
  ptr += 2;
1338
1339
9.90k
  types = H_GET_16 (abfd, ptr);
1340
  /* ptr += 2; */
1341
1342
  /* Now read in the two strings that follow.  */
1343
9.90k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1344
9.90k
  if (ptr == NULL)
1345
1.09k
    return NULL;
1346
1347
8.81k
  symbol_name = (char *) ptr;
1348
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1349
8.81k
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1350
1351
  /* Verify that the strings are null terminated.  */
1352
8.81k
  if (ptr[size - 1] != 0
1353
8.81k
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1354
522
    {
1355
522
      _bfd_error_handler
1356
522
  (_("%pB: string not null terminated in ILF object file"), abfd);
1357
522
      bfd_set_error (bfd_error_malformed_archive);
1358
522
      bfd_release (abfd, ptr);
1359
522
      return NULL;
1360
522
    }
1361
1362
  /* An ILF file may contain a third string, after source_dll; this is
1363
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1364
     block of data is null terminated, ptr[size-1]==0, but we don't
1365
     know how many individual null terminated strings we have in there.
1366
1367
     First find the end of source_dll.  */
1368
8.29k
  import_name = source_dll + strlen (source_dll) + 1;
1369
8.29k
  if ((bfd_byte *) import_name >= ptr + size)
1370
901
    {
1371
      /* If this points at the end of the ptr+size block, we only had
1372
   two strings. */
1373
901
      import_name = NULL;
1374
901
    }
1375
1376
  /* Now construct the bfd.  */
1377
8.29k
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1378
8.29k
          source_dll, ordinal, types,
1379
8.29k
          import_name))
1380
950
    {
1381
950
      bfd_release (abfd, ptr);
1382
950
      return NULL;
1383
950
    }
1384
1385
7.34k
  return pe_ILF_cleanup;
1386
8.29k
}
pei-arm-wince.c:pe_ILF_object_p
Line
Count
Source
1195
66.3k
{
1196
66.3k
  bfd_byte    buffer[14];
1197
66.3k
  bfd_byte *    ptr;
1198
66.3k
  char *    symbol_name;
1199
66.3k
  char *    source_dll;
1200
66.3k
  char *    import_name;
1201
66.3k
  unsigned int    machine;
1202
66.3k
  bfd_size_type   size;
1203
66.3k
  unsigned int    ordinal;
1204
66.3k
  unsigned int    types;
1205
66.3k
  unsigned int    magic;
1206
1207
  /* Upon entry the first six bytes of the ILF header have
1208
     already been read.  Now read the rest of the header.  */
1209
66.3k
  if (bfd_read (buffer, 14, abfd) != 14)
1210
356
    return NULL;
1211
1212
66.0k
  ptr = buffer;
1213
1214
66.0k
  machine = H_GET_16 (abfd, ptr);
1215
66.0k
  ptr += 2;
1216
1217
  /* Check that the machine type is recognised.  */
1218
66.0k
  magic = 0;
1219
1220
66.0k
  switch (machine)
1221
66.0k
    {
1222
526
    case IMAGE_FILE_MACHINE_UNKNOWN:
1223
634
    case IMAGE_FILE_MACHINE_ALPHA:
1224
635
    case IMAGE_FILE_MACHINE_ALPHA64:
1225
844
    case IMAGE_FILE_MACHINE_IA64:
1226
844
      break;
1227
1228
12.1k
    case IMAGE_FILE_MACHINE_I386:
1229
#ifdef I386MAGIC
1230
      magic = I386MAGIC;
1231
#endif
1232
12.1k
      break;
1233
1234
9.91k
    case IMAGE_FILE_MACHINE_AMD64:
1235
#ifdef AMD64MAGIC
1236
      magic = AMD64MAGIC;
1237
#endif
1238
9.91k
      break;
1239
1240
208
    case IMAGE_FILE_MACHINE_R3000:
1241
216
    case IMAGE_FILE_MACHINE_R4000:
1242
326
    case IMAGE_FILE_MACHINE_R10000:
1243
1244
433
    case IMAGE_FILE_MACHINE_MIPS16:
1245
637
    case IMAGE_FILE_MACHINE_MIPSFPU:
1246
639
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1247
#ifdef MIPS_ARCH_MAGIC_WINCE
1248
      magic = MIPS_ARCH_MAGIC_WINCE;
1249
#endif
1250
639
      break;
1251
1252
4.56k
    case IMAGE_FILE_MACHINE_SH3:
1253
12.0k
    case IMAGE_FILE_MACHINE_SH4:
1254
#ifdef SH_ARCH_MAGIC_WINCE
1255
      magic = SH_ARCH_MAGIC_WINCE;
1256
#endif
1257
12.0k
      break;
1258
1259
3.02k
    case IMAGE_FILE_MACHINE_ARM:
1260
3.02k
#ifdef ARMPEMAGIC
1261
3.02k
      magic = ARMPEMAGIC;
1262
3.02k
#endif
1263
3.02k
      break;
1264
1265
2.87k
    case IMAGE_FILE_MACHINE_ARM64:
1266
#ifdef AARCH64MAGIC
1267
      magic = AARCH64MAGIC;
1268
#endif
1269
2.87k
      break;
1270
1271
7.38k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1272
#ifdef LOONGARCH64MAGIC
1273
      magic = LOONGARCH64MAGIC;
1274
#endif
1275
7.38k
      break;
1276
1277
10.0k
    case IMAGE_FILE_MACHINE_RISCV64:
1278
#ifdef RISCV64MAGIC
1279
      magic = RISCV64MAGIC;
1280
#endif
1281
10.0k
      break;
1282
1283
1.27k
    case IMAGE_FILE_MACHINE_THUMB:
1284
1.27k
#ifdef THUMBPEMAGIC
1285
1.27k
      {
1286
1.27k
  extern const bfd_target TARGET_LITTLE_SYM;
1287
1288
1.27k
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1289
1.27k
    magic = THUMBPEMAGIC;
1290
1.27k
      }
1291
1.27k
#endif
1292
1.27k
      break;
1293
1294
0
    case IMAGE_FILE_MACHINE_POWERPC:
1295
      /* We no longer support PowerPC.  */
1296
5.72k
    default:
1297
5.72k
      _bfd_error_handler
1298
  /* xgettext:c-format */
1299
5.72k
  (_("%pB: unrecognised machine type (0x%x)"
1300
5.72k
     " in Import Library Format archive"),
1301
5.72k
   abfd, machine);
1302
5.72k
      bfd_set_error (bfd_error_malformed_archive);
1303
1304
5.72k
      return NULL;
1305
0
      break;
1306
66.0k
    }
1307
1308
60.2k
  if (magic == 0)
1309
55.9k
    {
1310
55.9k
      _bfd_error_handler
1311
  /* xgettext:c-format */
1312
55.9k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1313
55.9k
     " in Import Library Format archive"),
1314
55.9k
   abfd, machine);
1315
55.9k
      bfd_set_error (bfd_error_wrong_format);
1316
1317
55.9k
      return NULL;
1318
55.9k
    }
1319
1320
  /* We do not bother to check the date.
1321
     date = H_GET_32 (abfd, ptr);  */
1322
4.29k
  ptr += 4;
1323
1324
4.29k
  size = H_GET_32 (abfd, ptr);
1325
4.29k
  ptr += 4;
1326
1327
4.29k
  if (size == 0)
1328
416
    {
1329
416
      _bfd_error_handler
1330
416
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1331
416
      bfd_set_error (bfd_error_malformed_archive);
1332
1333
416
      return NULL;
1334
416
    }
1335
1336
3.88k
  ordinal = H_GET_16 (abfd, ptr);
1337
3.88k
  ptr += 2;
1338
1339
3.88k
  types = H_GET_16 (abfd, ptr);
1340
  /* ptr += 2; */
1341
1342
  /* Now read in the two strings that follow.  */
1343
3.88k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1344
3.88k
  if (ptr == NULL)
1345
1.20k
    return NULL;
1346
1347
2.68k
  symbol_name = (char *) ptr;
1348
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1349
2.68k
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1350
1351
  /* Verify that the strings are null terminated.  */
1352
2.68k
  if (ptr[size - 1] != 0
1353
2.68k
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1354
820
    {
1355
820
      _bfd_error_handler
1356
820
  (_("%pB: string not null terminated in ILF object file"), abfd);
1357
820
      bfd_set_error (bfd_error_malformed_archive);
1358
820
      bfd_release (abfd, ptr);
1359
820
      return NULL;
1360
820
    }
1361
1362
  /* An ILF file may contain a third string, after source_dll; this is
1363
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1364
     block of data is null terminated, ptr[size-1]==0, but we don't
1365
     know how many individual null terminated strings we have in there.
1366
1367
     First find the end of source_dll.  */
1368
1.86k
  import_name = source_dll + strlen (source_dll) + 1;
1369
1.86k
  if ((bfd_byte *) import_name >= ptr + size)
1370
546
    {
1371
      /* If this points at the end of the ptr+size block, we only had
1372
   two strings. */
1373
546
      import_name = NULL;
1374
546
    }
1375
1376
  /* Now construct the bfd.  */
1377
1.86k
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1378
1.86k
          source_dll, ordinal, types,
1379
1.86k
          import_name))
1380
1.77k
    {
1381
1.77k
      bfd_release (abfd, ptr);
1382
1.77k
      return NULL;
1383
1.77k
    }
1384
1385
84
  return pe_ILF_cleanup;
1386
1.86k
}
pei-arm.c:pe_ILF_object_p
Line
Count
Source
1195
79.5k
{
1196
79.5k
  bfd_byte    buffer[14];
1197
79.5k
  bfd_byte *    ptr;
1198
79.5k
  char *    symbol_name;
1199
79.5k
  char *    source_dll;
1200
79.5k
  char *    import_name;
1201
79.5k
  unsigned int    machine;
1202
79.5k
  bfd_size_type   size;
1203
79.5k
  unsigned int    ordinal;
1204
79.5k
  unsigned int    types;
1205
79.5k
  unsigned int    magic;
1206
1207
  /* Upon entry the first six bytes of the ILF header have
1208
     already been read.  Now read the rest of the header.  */
1209
79.5k
  if (bfd_read (buffer, 14, abfd) != 14)
1210
356
    return NULL;
1211
1212
79.2k
  ptr = buffer;
1213
1214
79.2k
  machine = H_GET_16 (abfd, ptr);
1215
79.2k
  ptr += 2;
1216
1217
  /* Check that the machine type is recognised.  */
1218
79.2k
  magic = 0;
1219
1220
79.2k
  switch (machine)
1221
79.2k
    {
1222
526
    case IMAGE_FILE_MACHINE_UNKNOWN:
1223
634
    case IMAGE_FILE_MACHINE_ALPHA:
1224
635
    case IMAGE_FILE_MACHINE_ALPHA64:
1225
844
    case IMAGE_FILE_MACHINE_IA64:
1226
844
      break;
1227
1228
12.1k
    case IMAGE_FILE_MACHINE_I386:
1229
#ifdef I386MAGIC
1230
      magic = I386MAGIC;
1231
#endif
1232
12.1k
      break;
1233
1234
9.91k
    case IMAGE_FILE_MACHINE_AMD64:
1235
#ifdef AMD64MAGIC
1236
      magic = AMD64MAGIC;
1237
#endif
1238
9.91k
      break;
1239
1240
208
    case IMAGE_FILE_MACHINE_R3000:
1241
216
    case IMAGE_FILE_MACHINE_R4000:
1242
326
    case IMAGE_FILE_MACHINE_R10000:
1243
1244
433
    case IMAGE_FILE_MACHINE_MIPS16:
1245
637
    case IMAGE_FILE_MACHINE_MIPSFPU:
1246
639
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1247
#ifdef MIPS_ARCH_MAGIC_WINCE
1248
      magic = MIPS_ARCH_MAGIC_WINCE;
1249
#endif
1250
639
      break;
1251
1252
4.56k
    case IMAGE_FILE_MACHINE_SH3:
1253
12.0k
    case IMAGE_FILE_MACHINE_SH4:
1254
#ifdef SH_ARCH_MAGIC_WINCE
1255
      magic = SH_ARCH_MAGIC_WINCE;
1256
#endif
1257
12.0k
      break;
1258
1259
12.6k
    case IMAGE_FILE_MACHINE_ARM:
1260
12.6k
#ifdef ARMPEMAGIC
1261
12.6k
      magic = ARMPEMAGIC;
1262
12.6k
#endif
1263
12.6k
      break;
1264
1265
2.87k
    case IMAGE_FILE_MACHINE_ARM64:
1266
#ifdef AARCH64MAGIC
1267
      magic = AARCH64MAGIC;
1268
#endif
1269
2.87k
      break;
1270
1271
7.38k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1272
#ifdef LOONGARCH64MAGIC
1273
      magic = LOONGARCH64MAGIC;
1274
#endif
1275
7.38k
      break;
1276
1277
10.0k
    case IMAGE_FILE_MACHINE_RISCV64:
1278
#ifdef RISCV64MAGIC
1279
      magic = RISCV64MAGIC;
1280
#endif
1281
10.0k
      break;
1282
1283
4.80k
    case IMAGE_FILE_MACHINE_THUMB:
1284
4.80k
#ifdef THUMBPEMAGIC
1285
4.80k
      {
1286
4.80k
  extern const bfd_target TARGET_LITTLE_SYM;
1287
1288
4.80k
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1289
4.80k
    magic = THUMBPEMAGIC;
1290
4.80k
      }
1291
4.80k
#endif
1292
4.80k
      break;
1293
1294
0
    case IMAGE_FILE_MACHINE_POWERPC:
1295
      /* We no longer support PowerPC.  */
1296
5.72k
    default:
1297
5.72k
      _bfd_error_handler
1298
  /* xgettext:c-format */
1299
5.72k
  (_("%pB: unrecognised machine type (0x%x)"
1300
5.72k
     " in Import Library Format archive"),
1301
5.72k
   abfd, machine);
1302
5.72k
      bfd_set_error (bfd_error_malformed_archive);
1303
1304
5.72k
      return NULL;
1305
0
      break;
1306
79.2k
    }
1307
1308
73.4k
  if (magic == 0)
1309
55.9k
    {
1310
55.9k
      _bfd_error_handler
1311
  /* xgettext:c-format */
1312
55.9k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1313
55.9k
     " in Import Library Format archive"),
1314
55.9k
   abfd, machine);
1315
55.9k
      bfd_set_error (bfd_error_wrong_format);
1316
1317
55.9k
      return NULL;
1318
55.9k
    }
1319
1320
  /* We do not bother to check the date.
1321
     date = H_GET_32 (abfd, ptr);  */
1322
17.4k
  ptr += 4;
1323
1324
17.4k
  size = H_GET_32 (abfd, ptr);
1325
17.4k
  ptr += 4;
1326
1327
17.4k
  if (size == 0)
1328
416
    {
1329
416
      _bfd_error_handler
1330
416
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1331
416
      bfd_set_error (bfd_error_malformed_archive);
1332
1333
416
      return NULL;
1334
416
    }
1335
1336
17.0k
  ordinal = H_GET_16 (abfd, ptr);
1337
17.0k
  ptr += 2;
1338
1339
17.0k
  types = H_GET_16 (abfd, ptr);
1340
  /* ptr += 2; */
1341
1342
  /* Now read in the two strings that follow.  */
1343
17.0k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1344
17.0k
  if (ptr == NULL)
1345
1.20k
    return NULL;
1346
1347
15.8k
  symbol_name = (char *) ptr;
1348
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1349
15.8k
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1350
1351
  /* Verify that the strings are null terminated.  */
1352
15.8k
  if (ptr[size - 1] != 0
1353
15.8k
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1354
820
    {
1355
820
      _bfd_error_handler
1356
820
  (_("%pB: string not null terminated in ILF object file"), abfd);
1357
820
      bfd_set_error (bfd_error_malformed_archive);
1358
820
      bfd_release (abfd, ptr);
1359
820
      return NULL;
1360
820
    }
1361
1362
  /* An ILF file may contain a third string, after source_dll; this is
1363
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1364
     block of data is null terminated, ptr[size-1]==0, but we don't
1365
     know how many individual null terminated strings we have in there.
1366
1367
     First find the end of source_dll.  */
1368
15.0k
  import_name = source_dll + strlen (source_dll) + 1;
1369
15.0k
  if ((bfd_byte *) import_name >= ptr + size)
1370
2.47k
    {
1371
      /* If this points at the end of the ptr+size block, we only had
1372
   two strings. */
1373
2.47k
      import_name = NULL;
1374
2.47k
    }
1375
1376
  /* Now construct the bfd.  */
1377
15.0k
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1378
15.0k
          source_dll, ordinal, types,
1379
15.0k
          import_name))
1380
1.77k
    {
1381
1.77k
      bfd_release (abfd, ptr);
1382
1.77k
      return NULL;
1383
1.77k
    }
1384
1385
13.2k
  return pe_ILF_cleanup;
1386
15.0k
}
pei-mcore.c:pe_ILF_object_p
Line
Count
Source
1195
57.3k
{
1196
57.3k
  bfd_byte    buffer[14];
1197
57.3k
  bfd_byte *    ptr;
1198
57.3k
  char *    symbol_name;
1199
57.3k
  char *    source_dll;
1200
57.3k
  char *    import_name;
1201
57.3k
  unsigned int    machine;
1202
57.3k
  bfd_size_type   size;
1203
57.3k
  unsigned int    ordinal;
1204
57.3k
  unsigned int    types;
1205
57.3k
  unsigned int    magic;
1206
1207
  /* Upon entry the first six bytes of the ILF header have
1208
     already been read.  Now read the rest of the header.  */
1209
57.3k
  if (bfd_read (buffer, 14, abfd) != 14)
1210
356
    return NULL;
1211
1212
57.0k
  ptr = buffer;
1213
1214
57.0k
  machine = H_GET_16 (abfd, ptr);
1215
57.0k
  ptr += 2;
1216
1217
  /* Check that the machine type is recognised.  */
1218
57.0k
  magic = 0;
1219
1220
57.0k
  switch (machine)
1221
57.0k
    {
1222
526
    case IMAGE_FILE_MACHINE_UNKNOWN:
1223
634
    case IMAGE_FILE_MACHINE_ALPHA:
1224
635
    case IMAGE_FILE_MACHINE_ALPHA64:
1225
844
    case IMAGE_FILE_MACHINE_IA64:
1226
844
      break;
1227
1228
3.20k
    case IMAGE_FILE_MACHINE_I386:
1229
#ifdef I386MAGIC
1230
      magic = I386MAGIC;
1231
#endif
1232
3.20k
      break;
1233
1234
9.91k
    case IMAGE_FILE_MACHINE_AMD64:
1235
#ifdef AMD64MAGIC
1236
      magic = AMD64MAGIC;
1237
#endif
1238
9.91k
      break;
1239
1240
208
    case IMAGE_FILE_MACHINE_R3000:
1241
216
    case IMAGE_FILE_MACHINE_R4000:
1242
326
    case IMAGE_FILE_MACHINE_R10000:
1243
1244
433
    case IMAGE_FILE_MACHINE_MIPS16:
1245
637
    case IMAGE_FILE_MACHINE_MIPSFPU:
1246
639
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1247
#ifdef MIPS_ARCH_MAGIC_WINCE
1248
      magic = MIPS_ARCH_MAGIC_WINCE;
1249
#endif
1250
639
      break;
1251
1252
4.56k
    case IMAGE_FILE_MACHINE_SH3:
1253
12.0k
    case IMAGE_FILE_MACHINE_SH4:
1254
#ifdef SH_ARCH_MAGIC_WINCE
1255
      magic = SH_ARCH_MAGIC_WINCE;
1256
#endif
1257
12.0k
      break;
1258
1259
3.02k
    case IMAGE_FILE_MACHINE_ARM:
1260
#ifdef ARMPEMAGIC
1261
      magic = ARMPEMAGIC;
1262
#endif
1263
3.02k
      break;
1264
1265
2.87k
    case IMAGE_FILE_MACHINE_ARM64:
1266
#ifdef AARCH64MAGIC
1267
      magic = AARCH64MAGIC;
1268
#endif
1269
2.87k
      break;
1270
1271
7.38k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1272
#ifdef LOONGARCH64MAGIC
1273
      magic = LOONGARCH64MAGIC;
1274
#endif
1275
7.38k
      break;
1276
1277
10.0k
    case IMAGE_FILE_MACHINE_RISCV64:
1278
#ifdef RISCV64MAGIC
1279
      magic = RISCV64MAGIC;
1280
#endif
1281
10.0k
      break;
1282
1283
1.27k
    case IMAGE_FILE_MACHINE_THUMB:
1284
#ifdef THUMBPEMAGIC
1285
      {
1286
  extern const bfd_target TARGET_LITTLE_SYM;
1287
1288
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1289
    magic = THUMBPEMAGIC;
1290
      }
1291
#endif
1292
1.27k
      break;
1293
1294
0
    case IMAGE_FILE_MACHINE_POWERPC:
1295
      /* We no longer support PowerPC.  */
1296
5.72k
    default:
1297
5.72k
      _bfd_error_handler
1298
  /* xgettext:c-format */
1299
5.72k
  (_("%pB: unrecognised machine type (0x%x)"
1300
5.72k
     " in Import Library Format archive"),
1301
5.72k
   abfd, machine);
1302
5.72k
      bfd_set_error (bfd_error_malformed_archive);
1303
1304
5.72k
      return NULL;
1305
0
      break;
1306
57.0k
    }
1307
1308
51.2k
  if (magic == 0)
1309
51.2k
    {
1310
51.2k
      _bfd_error_handler
1311
  /* xgettext:c-format */
1312
51.2k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1313
51.2k
     " in Import Library Format archive"),
1314
51.2k
   abfd, machine);
1315
51.2k
      bfd_set_error (bfd_error_wrong_format);
1316
1317
51.2k
      return NULL;
1318
51.2k
    }
1319
1320
  /* We do not bother to check the date.
1321
     date = H_GET_32 (abfd, ptr);  */
1322
0
  ptr += 4;
1323
1324
0
  size = H_GET_32 (abfd, ptr);
1325
0
  ptr += 4;
1326
1327
0
  if (size == 0)
1328
0
    {
1329
0
      _bfd_error_handler
1330
0
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1331
0
      bfd_set_error (bfd_error_malformed_archive);
1332
1333
0
      return NULL;
1334
0
    }
1335
1336
0
  ordinal = H_GET_16 (abfd, ptr);
1337
0
  ptr += 2;
1338
1339
0
  types = H_GET_16 (abfd, ptr);
1340
  /* ptr += 2; */
1341
1342
  /* Now read in the two strings that follow.  */
1343
0
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1344
0
  if (ptr == NULL)
1345
0
    return NULL;
1346
1347
0
  symbol_name = (char *) ptr;
1348
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1349
0
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1350
1351
  /* Verify that the strings are null terminated.  */
1352
0
  if (ptr[size - 1] != 0
1353
0
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1354
0
    {
1355
0
      _bfd_error_handler
1356
0
  (_("%pB: string not null terminated in ILF object file"), abfd);
1357
0
      bfd_set_error (bfd_error_malformed_archive);
1358
0
      bfd_release (abfd, ptr);
1359
0
      return NULL;
1360
0
    }
1361
1362
  /* An ILF file may contain a third string, after source_dll; this is
1363
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1364
     block of data is null terminated, ptr[size-1]==0, but we don't
1365
     know how many individual null terminated strings we have in there.
1366
1367
     First find the end of source_dll.  */
1368
0
  import_name = source_dll + strlen (source_dll) + 1;
1369
0
  if ((bfd_byte *) import_name >= ptr + size)
1370
0
    {
1371
      /* If this points at the end of the ptr+size block, we only had
1372
   two strings. */
1373
0
      import_name = NULL;
1374
0
    }
1375
1376
  /* Now construct the bfd.  */
1377
0
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1378
0
          source_dll, ordinal, types,
1379
0
          import_name))
1380
0
    {
1381
0
      bfd_release (abfd, ptr);
1382
0
      return NULL;
1383
0
    }
1384
1385
0
  return pe_ILF_cleanup;
1386
0
}
pei-sh.c:pe_ILF_object_p
Line
Count
Source
1195
49.9k
{
1196
49.9k
  bfd_byte    buffer[14];
1197
49.9k
  bfd_byte *    ptr;
1198
49.9k
  char *    symbol_name;
1199
49.9k
  char *    source_dll;
1200
49.9k
  char *    import_name;
1201
49.9k
  unsigned int    machine;
1202
49.9k
  bfd_size_type   size;
1203
49.9k
  unsigned int    ordinal;
1204
49.9k
  unsigned int    types;
1205
49.9k
  unsigned int    magic;
1206
1207
  /* Upon entry the first six bytes of the ILF header have
1208
     already been read.  Now read the rest of the header.  */
1209
49.9k
  if (bfd_read (buffer, 14, abfd) != 14)
1210
348
    return NULL;
1211
1212
49.5k
  ptr = buffer;
1213
1214
49.5k
  machine = H_GET_16 (abfd, ptr);
1215
49.5k
  ptr += 2;
1216
1217
  /* Check that the machine type is recognised.  */
1218
49.5k
  magic = 0;
1219
1220
49.5k
  switch (machine)
1221
49.5k
    {
1222
420
    case IMAGE_FILE_MACHINE_UNKNOWN:
1223
528
    case IMAGE_FILE_MACHINE_ALPHA:
1224
528
    case IMAGE_FILE_MACHINE_ALPHA64:
1225
737
    case IMAGE_FILE_MACHINE_IA64:
1226
737
      break;
1227
1228
3.20k
    case IMAGE_FILE_MACHINE_I386:
1229
#ifdef I386MAGIC
1230
      magic = I386MAGIC;
1231
#endif
1232
3.20k
      break;
1233
1234
9.91k
    case IMAGE_FILE_MACHINE_AMD64:
1235
#ifdef AMD64MAGIC
1236
      magic = AMD64MAGIC;
1237
#endif
1238
9.91k
      break;
1239
1240
208
    case IMAGE_FILE_MACHINE_R3000:
1241
216
    case IMAGE_FILE_MACHINE_R4000:
1242
325
    case IMAGE_FILE_MACHINE_R10000:
1243
1244
432
    case IMAGE_FILE_MACHINE_MIPS16:
1245
636
    case IMAGE_FILE_MACHINE_MIPSFPU:
1246
638
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1247
#ifdef MIPS_ARCH_MAGIC_WINCE
1248
      magic = MIPS_ARCH_MAGIC_WINCE;
1249
#endif
1250
638
      break;
1251
1252
4.58k
    case IMAGE_FILE_MACHINE_SH3:
1253
12.1k
    case IMAGE_FILE_MACHINE_SH4:
1254
12.1k
#ifdef SH_ARCH_MAGIC_WINCE
1255
12.1k
      magic = SH_ARCH_MAGIC_WINCE;
1256
12.1k
#endif
1257
12.1k
      break;
1258
1259
2.99k
    case IMAGE_FILE_MACHINE_ARM:
1260
#ifdef ARMPEMAGIC
1261
      magic = ARMPEMAGIC;
1262
#endif
1263
2.99k
      break;
1264
1265
2.87k
    case IMAGE_FILE_MACHINE_ARM64:
1266
#ifdef AARCH64MAGIC
1267
      magic = AARCH64MAGIC;
1268
#endif
1269
2.87k
      break;
1270
1271
7.38k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1272
#ifdef LOONGARCH64MAGIC
1273
      magic = LOONGARCH64MAGIC;
1274
#endif
1275
7.38k
      break;
1276
1277
2.80k
    case IMAGE_FILE_MACHINE_RISCV64:
1278
#ifdef RISCV64MAGIC
1279
      magic = RISCV64MAGIC;
1280
#endif
1281
2.80k
      break;
1282
1283
1.27k
    case IMAGE_FILE_MACHINE_THUMB:
1284
#ifdef THUMBPEMAGIC
1285
      {
1286
  extern const bfd_target TARGET_LITTLE_SYM;
1287
1288
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1289
    magic = THUMBPEMAGIC;
1290
      }
1291
#endif
1292
1.27k
      break;
1293
1294
0
    case IMAGE_FILE_MACHINE_POWERPC:
1295
      /* We no longer support PowerPC.  */
1296
5.61k
    default:
1297
5.61k
      _bfd_error_handler
1298
  /* xgettext:c-format */
1299
5.61k
  (_("%pB: unrecognised machine type (0x%x)"
1300
5.61k
     " in Import Library Format archive"),
1301
5.61k
   abfd, machine);
1302
5.61k
      bfd_set_error (bfd_error_malformed_archive);
1303
1304
5.61k
      return NULL;
1305
0
      break;
1306
49.5k
    }
1307
1308
43.9k
  if (magic == 0)
1309
31.8k
    {
1310
31.8k
      _bfd_error_handler
1311
  /* xgettext:c-format */
1312
31.8k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1313
31.8k
     " in Import Library Format archive"),
1314
31.8k
   abfd, machine);
1315
31.8k
      bfd_set_error (bfd_error_wrong_format);
1316
1317
31.8k
      return NULL;
1318
31.8k
    }
1319
1320
  /* We do not bother to check the date.
1321
     date = H_GET_32 (abfd, ptr);  */
1322
12.1k
  ptr += 4;
1323
1324
12.1k
  size = H_GET_32 (abfd, ptr);
1325
12.1k
  ptr += 4;
1326
1327
12.1k
  if (size == 0)
1328
213
    {
1329
213
      _bfd_error_handler
1330
213
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1331
213
      bfd_set_error (bfd_error_malformed_archive);
1332
1333
213
      return NULL;
1334
213
    }
1335
1336
11.9k
  ordinal = H_GET_16 (abfd, ptr);
1337
11.9k
  ptr += 2;
1338
1339
11.9k
  types = H_GET_16 (abfd, ptr);
1340
  /* ptr += 2; */
1341
1342
  /* Now read in the two strings that follow.  */
1343
11.9k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1344
11.9k
  if (ptr == NULL)
1345
1.28k
    return NULL;
1346
1347
10.6k
  symbol_name = (char *) ptr;
1348
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1349
10.6k
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1350
1351
  /* Verify that the strings are null terminated.  */
1352
10.6k
  if (ptr[size - 1] != 0
1353
10.6k
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1354
666
    {
1355
666
      _bfd_error_handler
1356
666
  (_("%pB: string not null terminated in ILF object file"), abfd);
1357
666
      bfd_set_error (bfd_error_malformed_archive);
1358
666
      bfd_release (abfd, ptr);
1359
666
      return NULL;
1360
666
    }
1361
1362
  /* An ILF file may contain a third string, after source_dll; this is
1363
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1364
     block of data is null terminated, ptr[size-1]==0, but we don't
1365
     know how many individual null terminated strings we have in there.
1366
1367
     First find the end of source_dll.  */
1368
9.95k
  import_name = source_dll + strlen (source_dll) + 1;
1369
9.95k
  if ((bfd_byte *) import_name >= ptr + size)
1370
2.04k
    {
1371
      /* If this points at the end of the ptr+size block, we only had
1372
   two strings. */
1373
2.04k
      import_name = NULL;
1374
2.04k
    }
1375
1376
  /* Now construct the bfd.  */
1377
9.95k
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1378
9.95k
          source_dll, ordinal, types,
1379
9.95k
          import_name))
1380
1.57k
    {
1381
1.57k
      bfd_release (abfd, ptr);
1382
1.57k
      return NULL;
1383
1.57k
    }
1384
1385
8.37k
  return pe_ILF_cleanup;
1386
9.95k
}
1387
1388
static void
1389
pe_bfd_read_buildid (bfd *abfd)
1390
481k
{
1391
481k
  pe_data_type *pe = pe_data (abfd);
1392
481k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1393
481k
  asection *section;
1394
481k
  bfd_byte *data = 0;
1395
481k
  bfd_size_type dataoff;
1396
481k
  unsigned int i;
1397
481k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1398
481k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1399
1400
481k
  if (size == 0)
1401
242k
    return;
1402
1403
238k
  addr += extra->ImageBase;
1404
1405
  /* Search for the section containing the DebugDirectory.  */
1406
545k
  for (section = abfd->sections; section != NULL; section = section->next)
1407
425k
    {
1408
425k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1409
118k
  break;
1410
425k
    }
1411
1412
238k
  if (section == NULL)
1413
120k
    return;
1414
1415
118k
  if (!(section->flags & SEC_HAS_CONTENTS))
1416
12.2k
    return;
1417
1418
106k
  dataoff = addr - section->vma;
1419
1420
  /* PR 20605 and 22373: Make sure that the data is really there.
1421
     Note - since we are dealing with unsigned quantities we have
1422
     to be careful to check for potential overflows.  */
1423
106k
  if (dataoff >= section->size
1424
106k
      || size > section->size - dataoff)
1425
42.9k
    {
1426
42.9k
      _bfd_error_handler
1427
42.9k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1428
42.9k
   abfd);
1429
42.9k
      return;
1430
42.9k
    }
1431
1432
  /* Read the whole section. */
1433
63.6k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1434
23.8k
    {
1435
23.8k
      free (data);
1436
23.8k
      return;
1437
23.8k
    }
1438
1439
  /* Search for a CodeView entry in the DebugDirectory */
1440
7.75M
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1441
7.73M
    {
1442
7.73M
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1443
7.73M
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1444
7.73M
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1445
1446
7.73M
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1447
1448
7.73M
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1449
22.7k
  {
1450
22.7k
    char buffer[256 + 1];
1451
22.7k
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1452
1453
    /*
1454
      The debug entry doesn't have to have to be in a section, in which
1455
      case AddressOfRawData is 0, so always use PointerToRawData.
1456
    */
1457
22.7k
    if (_bfd_XXi_slurp_codeview_record (abfd,
1458
22.7k
                (file_ptr) idd.PointerToRawData,
1459
22.7k
                idd.SizeOfData, cvinfo, NULL))
1460
216
      {
1461
216
        struct bfd_build_id *build_id;
1462
216
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1463
1464
216
        build_id = bfd_alloc (abfd, bidlen);
1465
216
        if (build_id)
1466
216
    {
1467
216
      build_id->size = cvinfo->SignatureLength;
1468
216
      memcpy(build_id->data, cvinfo->Signature,
1469
216
       cvinfo->SignatureLength);
1470
216
      abfd->build_id = build_id;
1471
216
    }
1472
216
      }
1473
22.7k
    break;
1474
22.7k
  }
1475
7.73M
    }
1476
1477
39.7k
  free (data);
1478
39.7k
}
pei-i386.c:pe_bfd_read_buildid
Line
Count
Source
1390
91.6k
{
1391
91.6k
  pe_data_type *pe = pe_data (abfd);
1392
91.6k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1393
91.6k
  asection *section;
1394
91.6k
  bfd_byte *data = 0;
1395
91.6k
  bfd_size_type dataoff;
1396
91.6k
  unsigned int i;
1397
91.6k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1398
91.6k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1399
1400
91.6k
  if (size == 0)
1401
56.1k
    return;
1402
1403
35.4k
  addr += extra->ImageBase;
1404
1405
  /* Search for the section containing the DebugDirectory.  */
1406
63.3k
  for (section = abfd->sections; section != NULL; section = section->next)
1407
48.0k
    {
1408
48.0k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1409
20.1k
  break;
1410
48.0k
    }
1411
1412
35.4k
  if (section == NULL)
1413
15.3k
    return;
1414
1415
20.1k
  if (!(section->flags & SEC_HAS_CONTENTS))
1416
1.48k
    return;
1417
1418
18.6k
  dataoff = addr - section->vma;
1419
1420
  /* PR 20605 and 22373: Make sure that the data is really there.
1421
     Note - since we are dealing with unsigned quantities we have
1422
     to be careful to check for potential overflows.  */
1423
18.6k
  if (dataoff >= section->size
1424
18.6k
      || size > section->size - dataoff)
1425
11.0k
    {
1426
11.0k
      _bfd_error_handler
1427
11.0k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1428
11.0k
   abfd);
1429
11.0k
      return;
1430
11.0k
    }
1431
1432
  /* Read the whole section. */
1433
7.68k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1434
4.46k
    {
1435
4.46k
      free (data);
1436
4.46k
      return;
1437
4.46k
    }
1438
1439
  /* Search for a CodeView entry in the DebugDirectory */
1440
14.1k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1441
11.9k
    {
1442
11.9k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1443
11.9k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1444
11.9k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1445
1446
11.9k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1447
1448
11.9k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1449
927
  {
1450
927
    char buffer[256 + 1];
1451
927
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1452
1453
    /*
1454
      The debug entry doesn't have to have to be in a section, in which
1455
      case AddressOfRawData is 0, so always use PointerToRawData.
1456
    */
1457
927
    if (_bfd_XXi_slurp_codeview_record (abfd,
1458
927
                (file_ptr) idd.PointerToRawData,
1459
927
                idd.SizeOfData, cvinfo, NULL))
1460
48
      {
1461
48
        struct bfd_build_id *build_id;
1462
48
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1463
1464
48
        build_id = bfd_alloc (abfd, bidlen);
1465
48
        if (build_id)
1466
48
    {
1467
48
      build_id->size = cvinfo->SignatureLength;
1468
48
      memcpy(build_id->data, cvinfo->Signature,
1469
48
       cvinfo->SignatureLength);
1470
48
      abfd->build_id = build_id;
1471
48
    }
1472
48
      }
1473
927
    break;
1474
927
  }
1475
11.9k
    }
1476
1477
3.21k
  free (data);
1478
3.21k
}
pei-x86_64.c:pe_bfd_read_buildid
Line
Count
Source
1390
86.0k
{
1391
86.0k
  pe_data_type *pe = pe_data (abfd);
1392
86.0k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1393
86.0k
  asection *section;
1394
86.0k
  bfd_byte *data = 0;
1395
86.0k
  bfd_size_type dataoff;
1396
86.0k
  unsigned int i;
1397
86.0k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1398
86.0k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1399
1400
86.0k
  if (size == 0)
1401
50.2k
    return;
1402
1403
35.8k
  addr += extra->ImageBase;
1404
1405
  /* Search for the section containing the DebugDirectory.  */
1406
83.0k
  for (section = abfd->sections; section != NULL; section = section->next)
1407
65.9k
    {
1408
65.9k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1409
18.7k
  break;
1410
65.9k
    }
1411
1412
35.8k
  if (section == NULL)
1413
17.0k
    return;
1414
1415
18.7k
  if (!(section->flags & SEC_HAS_CONTENTS))
1416
1.40k
    return;
1417
1418
17.3k
  dataoff = addr - section->vma;
1419
1420
  /* PR 20605 and 22373: Make sure that the data is really there.
1421
     Note - since we are dealing with unsigned quantities we have
1422
     to be careful to check for potential overflows.  */
1423
17.3k
  if (dataoff >= section->size
1424
17.3k
      || size > section->size - dataoff)
1425
4.01k
    {
1426
4.01k
      _bfd_error_handler
1427
4.01k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1428
4.01k
   abfd);
1429
4.01k
      return;
1430
4.01k
    }
1431
1432
  /* Read the whole section. */
1433
13.3k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1434
3.06k
    {
1435
3.06k
      free (data);
1436
3.06k
      return;
1437
3.06k
    }
1438
1439
  /* Search for a CodeView entry in the DebugDirectory */
1440
6.96M
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1441
6.96M
    {
1442
6.96M
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1443
6.96M
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1444
6.96M
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1445
1446
6.96M
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1447
1448
6.96M
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1449
7.31k
  {
1450
7.31k
    char buffer[256 + 1];
1451
7.31k
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1452
1453
    /*
1454
      The debug entry doesn't have to have to be in a section, in which
1455
      case AddressOfRawData is 0, so always use PointerToRawData.
1456
    */
1457
7.31k
    if (_bfd_XXi_slurp_codeview_record (abfd,
1458
7.31k
                (file_ptr) idd.PointerToRawData,
1459
7.31k
                idd.SizeOfData, cvinfo, NULL))
1460
103
      {
1461
103
        struct bfd_build_id *build_id;
1462
103
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1463
1464
103
        build_id = bfd_alloc (abfd, bidlen);
1465
103
        if (build_id)
1466
103
    {
1467
103
      build_id->size = cvinfo->SignatureLength;
1468
103
      memcpy(build_id->data, cvinfo->Signature,
1469
103
       cvinfo->SignatureLength);
1470
103
      abfd->build_id = build_id;
1471
103
    }
1472
103
      }
1473
7.31k
    break;
1474
7.31k
  }
1475
6.96M
    }
1476
1477
10.2k
  free (data);
1478
10.2k
}
pei-aarch64.c:pe_bfd_read_buildid
Line
Count
Source
1390
52.3k
{
1391
52.3k
  pe_data_type *pe = pe_data (abfd);
1392
52.3k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1393
52.3k
  asection *section;
1394
52.3k
  bfd_byte *data = 0;
1395
52.3k
  bfd_size_type dataoff;
1396
52.3k
  unsigned int i;
1397
52.3k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1398
52.3k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1399
1400
52.3k
  if (size == 0)
1401
18.7k
    return;
1402
1403
33.5k
  addr += extra->ImageBase;
1404
1405
  /* Search for the section containing the DebugDirectory.  */
1406
79.0k
  for (section = abfd->sections; section != NULL; section = section->next)
1407
59.6k
    {
1408
59.6k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1409
14.1k
  break;
1410
59.6k
    }
1411
1412
33.5k
  if (section == NULL)
1413
19.3k
    return;
1414
1415
14.1k
  if (!(section->flags & SEC_HAS_CONTENTS))
1416
1.40k
    return;
1417
1418
12.7k
  dataoff = addr - section->vma;
1419
1420
  /* PR 20605 and 22373: Make sure that the data is really there.
1421
     Note - since we are dealing with unsigned quantities we have
1422
     to be careful to check for potential overflows.  */
1423
12.7k
  if (dataoff >= section->size
1424
12.7k
      || size > section->size - dataoff)
1425
5.33k
    {
1426
5.33k
      _bfd_error_handler
1427
5.33k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1428
5.33k
   abfd);
1429
5.33k
      return;
1430
5.33k
    }
1431
1432
  /* Read the whole section. */
1433
7.41k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1434
1.78k
    {
1435
1.78k
      free (data);
1436
1.78k
      return;
1437
1.78k
    }
1438
1439
  /* Search for a CodeView entry in the DebugDirectory */
1440
547k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1441
545k
    {
1442
545k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1443
545k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1444
545k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1445
1446
545k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1447
1448
545k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1449
3.56k
  {
1450
3.56k
    char buffer[256 + 1];
1451
3.56k
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1452
1453
    /*
1454
      The debug entry doesn't have to have to be in a section, in which
1455
      case AddressOfRawData is 0, so always use PointerToRawData.
1456
    */
1457
3.56k
    if (_bfd_XXi_slurp_codeview_record (abfd,
1458
3.56k
                (file_ptr) idd.PointerToRawData,
1459
3.56k
                idd.SizeOfData, cvinfo, NULL))
1460
1
      {
1461
1
        struct bfd_build_id *build_id;
1462
1
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1463
1464
1
        build_id = bfd_alloc (abfd, bidlen);
1465
1
        if (build_id)
1466
1
    {
1467
1
      build_id->size = cvinfo->SignatureLength;
1468
1
      memcpy(build_id->data, cvinfo->Signature,
1469
1
       cvinfo->SignatureLength);
1470
1
      abfd->build_id = build_id;
1471
1
    }
1472
1
      }
1473
3.56k
    break;
1474
3.56k
  }
1475
545k
    }
1476
1477
5.63k
  free (data);
1478
5.63k
}
pei-ia64.c:pe_bfd_read_buildid
Line
Count
Source
1390
52.3k
{
1391
52.3k
  pe_data_type *pe = pe_data (abfd);
1392
52.3k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1393
52.3k
  asection *section;
1394
52.3k
  bfd_byte *data = 0;
1395
52.3k
  bfd_size_type dataoff;
1396
52.3k
  unsigned int i;
1397
52.3k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1398
52.3k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1399
1400
52.3k
  if (size == 0)
1401
22.1k
    return;
1402
1403
30.2k
  addr += extra->ImageBase;
1404
1405
  /* Search for the section containing the DebugDirectory.  */
1406
58.2k
  for (section = abfd->sections; section != NULL; section = section->next)
1407
41.2k
    {
1408
41.2k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1409
13.2k
  break;
1410
41.2k
    }
1411
1412
30.2k
  if (section == NULL)
1413
16.9k
    return;
1414
1415
13.2k
  if (!(section->flags & SEC_HAS_CONTENTS))
1416
1.53k
    return;
1417
1418
11.7k
  dataoff = addr - section->vma;
1419
1420
  /* PR 20605 and 22373: Make sure that the data is really there.
1421
     Note - since we are dealing with unsigned quantities we have
1422
     to be careful to check for potential overflows.  */
1423
11.7k
  if (dataoff >= section->size
1424
11.7k
      || size > section->size - dataoff)
1425
5.25k
    {
1426
5.25k
      _bfd_error_handler
1427
5.25k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1428
5.25k
   abfd);
1429
5.25k
      return;
1430
5.25k
    }
1431
1432
  /* Read the whole section. */
1433
6.49k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1434
2.36k
    {
1435
2.36k
      free (data);
1436
2.36k
      return;
1437
2.36k
    }
1438
1439
  /* Search for a CodeView entry in the DebugDirectory */
1440
19.0k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1441
17.8k
    {
1442
17.8k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1443
17.8k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1444
17.8k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1445
1446
17.8k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1447
1448
17.8k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1449
2.90k
  {
1450
2.90k
    char buffer[256 + 1];
1451
2.90k
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1452
1453
    /*
1454
      The debug entry doesn't have to have to be in a section, in which
1455
      case AddressOfRawData is 0, so always use PointerToRawData.
1456
    */
1457
2.90k
    if (_bfd_XXi_slurp_codeview_record (abfd,
1458
2.90k
                (file_ptr) idd.PointerToRawData,
1459
2.90k
                idd.SizeOfData, cvinfo, NULL))
1460
1
      {
1461
1
        struct bfd_build_id *build_id;
1462
1
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1463
1464
1
        build_id = bfd_alloc (abfd, bidlen);
1465
1
        if (build_id)
1466
1
    {
1467
1
      build_id->size = cvinfo->SignatureLength;
1468
1
      memcpy(build_id->data, cvinfo->Signature,
1469
1
       cvinfo->SignatureLength);
1470
1
      abfd->build_id = build_id;
1471
1
    }
1472
1
      }
1473
2.90k
    break;
1474
2.90k
  }
1475
17.8k
    }
1476
1477
4.13k
  free (data);
1478
4.13k
}
pei-loongarch64.c:pe_bfd_read_buildid
Line
Count
Source
1390
49.7k
{
1391
49.7k
  pe_data_type *pe = pe_data (abfd);
1392
49.7k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1393
49.7k
  asection *section;
1394
49.7k
  bfd_byte *data = 0;
1395
49.7k
  bfd_size_type dataoff;
1396
49.7k
  unsigned int i;
1397
49.7k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1398
49.7k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1399
1400
49.7k
  if (size == 0)
1401
29.0k
    return;
1402
1403
20.6k
  addr += extra->ImageBase;
1404
1405
  /* Search for the section containing the DebugDirectory.  */
1406
71.2k
  for (section = abfd->sections; section != NULL; section = section->next)
1407
61.3k
    {
1408
61.3k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1409
10.8k
  break;
1410
61.3k
    }
1411
1412
20.6k
  if (section == NULL)
1413
9.88k
    return;
1414
1415
10.8k
  if (!(section->flags & SEC_HAS_CONTENTS))
1416
1.39k
    return;
1417
1418
9.41k
  dataoff = addr - section->vma;
1419
1420
  /* PR 20605 and 22373: Make sure that the data is really there.
1421
     Note - since we are dealing with unsigned quantities we have
1422
     to be careful to check for potential overflows.  */
1423
9.41k
  if (dataoff >= section->size
1424
9.41k
      || size > section->size - dataoff)
1425
2.64k
    {
1426
2.64k
      _bfd_error_handler
1427
2.64k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1428
2.64k
   abfd);
1429
2.64k
      return;
1430
2.64k
    }
1431
1432
  /* Read the whole section. */
1433
6.77k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1434
1.31k
    {
1435
1.31k
      free (data);
1436
1.31k
      return;
1437
1.31k
    }
1438
1439
  /* Search for a CodeView entry in the DebugDirectory */
1440
42.1k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1441
39.7k
    {
1442
39.7k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1443
39.7k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1444
39.7k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1445
1446
39.7k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1447
1448
39.7k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1449
3.07k
  {
1450
3.07k
    char buffer[256 + 1];
1451
3.07k
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1452
1453
    /*
1454
      The debug entry doesn't have to have to be in a section, in which
1455
      case AddressOfRawData is 0, so always use PointerToRawData.
1456
    */
1457
3.07k
    if (_bfd_XXi_slurp_codeview_record (abfd,
1458
3.07k
                (file_ptr) idd.PointerToRawData,
1459
3.07k
                idd.SizeOfData, cvinfo, NULL))
1460
1
      {
1461
1
        struct bfd_build_id *build_id;
1462
1
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1463
1464
1
        build_id = bfd_alloc (abfd, bidlen);
1465
1
        if (build_id)
1466
1
    {
1467
1
      build_id->size = cvinfo->SignatureLength;
1468
1
      memcpy(build_id->data, cvinfo->Signature,
1469
1
       cvinfo->SignatureLength);
1470
1
      abfd->build_id = build_id;
1471
1
    }
1472
1
      }
1473
3.07k
    break;
1474
3.07k
  }
1475
39.7k
    }
1476
1477
5.46k
  free (data);
1478
5.46k
}
pei-riscv64.c:pe_bfd_read_buildid
Line
Count
Source
1390
35.4k
{
1391
35.4k
  pe_data_type *pe = pe_data (abfd);
1392
35.4k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1393
35.4k
  asection *section;
1394
35.4k
  bfd_byte *data = 0;
1395
35.4k
  bfd_size_type dataoff;
1396
35.4k
  unsigned int i;
1397
35.4k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1398
35.4k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1399
1400
35.4k
  if (size == 0)
1401
17.7k
    return;
1402
1403
17.6k
  addr += extra->ImageBase;
1404
1405
  /* Search for the section containing the DebugDirectory.  */
1406
47.9k
  for (section = abfd->sections; section != NULL; section = section->next)
1407
35.5k
    {
1408
35.5k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1409
5.31k
  break;
1410
35.5k
    }
1411
1412
17.6k
  if (section == NULL)
1413
12.3k
    return;
1414
1415
5.31k
  if (!(section->flags & SEC_HAS_CONTENTS))
1416
813
    return;
1417
1418
4.50k
  dataoff = addr - section->vma;
1419
1420
  /* PR 20605 and 22373: Make sure that the data is really there.
1421
     Note - since we are dealing with unsigned quantities we have
1422
     to be careful to check for potential overflows.  */
1423
4.50k
  if (dataoff >= section->size
1424
4.50k
      || size > section->size - dataoff)
1425
3.24k
    {
1426
3.24k
      _bfd_error_handler
1427
3.24k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1428
3.24k
   abfd);
1429
3.24k
      return;
1430
3.24k
    }
1431
1432
  /* Read the whole section. */
1433
1.25k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1434
1.17k
    {
1435
1.17k
      free (data);
1436
1.17k
      return;
1437
1.17k
    }
1438
1439
  /* Search for a CodeView entry in the DebugDirectory */
1440
7.91k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1441
7.89k
    {
1442
7.89k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1443
7.89k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1444
7.89k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1445
1446
7.89k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1447
1448
7.89k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1449
62
  {
1450
62
    char buffer[256 + 1];
1451
62
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1452
1453
    /*
1454
      The debug entry doesn't have to have to be in a section, in which
1455
      case AddressOfRawData is 0, so always use PointerToRawData.
1456
    */
1457
62
    if (_bfd_XXi_slurp_codeview_record (abfd,
1458
62
                (file_ptr) idd.PointerToRawData,
1459
62
                idd.SizeOfData, cvinfo, NULL))
1460
1
      {
1461
1
        struct bfd_build_id *build_id;
1462
1
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1463
1464
1
        build_id = bfd_alloc (abfd, bidlen);
1465
1
        if (build_id)
1466
1
    {
1467
1
      build_id->size = cvinfo->SignatureLength;
1468
1
      memcpy(build_id->data, cvinfo->Signature,
1469
1
       cvinfo->SignatureLength);
1470
1
      abfd->build_id = build_id;
1471
1
    }
1472
1
      }
1473
62
    break;
1474
62
  }
1475
7.89k
    }
1476
1477
81
  free (data);
1478
81
}
pei-arm-wince.c:pe_bfd_read_buildid
Line
Count
Source
1390
17.0k
{
1391
17.0k
  pe_data_type *pe = pe_data (abfd);
1392
17.0k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1393
17.0k
  asection *section;
1394
17.0k
  bfd_byte *data = 0;
1395
17.0k
  bfd_size_type dataoff;
1396
17.0k
  unsigned int i;
1397
17.0k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1398
17.0k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1399
1400
17.0k
  if (size == 0)
1401
2.66k
    return;
1402
1403
14.3k
  addr += extra->ImageBase;
1404
1405
  /* Search for the section containing the DebugDirectory.  */
1406
29.0k
  for (section = abfd->sections; section != NULL; section = section->next)
1407
23.5k
    {
1408
23.5k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1409
8.86k
  break;
1410
23.5k
    }
1411
1412
14.3k
  if (section == NULL)
1413
5.52k
    return;
1414
1415
8.86k
  if (!(section->flags & SEC_HAS_CONTENTS))
1416
1.39k
    return;
1417
1418
7.46k
  dataoff = addr - section->vma;
1419
1420
  /* PR 20605 and 22373: Make sure that the data is really there.
1421
     Note - since we are dealing with unsigned quantities we have
1422
     to be careful to check for potential overflows.  */
1423
7.46k
  if (dataoff >= section->size
1424
7.46k
      || size > section->size - dataoff)
1425
2.69k
    {
1426
2.69k
      _bfd_error_handler
1427
2.69k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1428
2.69k
   abfd);
1429
2.69k
      return;
1430
2.69k
    }
1431
1432
  /* Read the whole section. */
1433
4.77k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1434
2.49k
    {
1435
2.49k
      free (data);
1436
2.49k
      return;
1437
2.49k
    }
1438
1439
  /* Search for a CodeView entry in the DebugDirectory */
1440
52.2k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1441
50.9k
    {
1442
50.9k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1443
50.9k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1444
50.9k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1445
1446
50.9k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1447
1448
50.9k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1449
1.00k
  {
1450
1.00k
    char buffer[256 + 1];
1451
1.00k
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1452
1453
    /*
1454
      The debug entry doesn't have to have to be in a section, in which
1455
      case AddressOfRawData is 0, so always use PointerToRawData.
1456
    */
1457
1.00k
    if (_bfd_XXi_slurp_codeview_record (abfd,
1458
1.00k
                (file_ptr) idd.PointerToRawData,
1459
1.00k
                idd.SizeOfData, cvinfo, NULL))
1460
3
      {
1461
3
        struct bfd_build_id *build_id;
1462
3
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1463
1464
3
        build_id = bfd_alloc (abfd, bidlen);
1465
3
        if (build_id)
1466
3
    {
1467
3
      build_id->size = cvinfo->SignatureLength;
1468
3
      memcpy(build_id->data, cvinfo->Signature,
1469
3
       cvinfo->SignatureLength);
1470
3
      abfd->build_id = build_id;
1471
3
    }
1472
3
      }
1473
1.00k
    break;
1474
1.00k
  }
1475
50.9k
    }
1476
1477
2.28k
  free (data);
1478
2.28k
}
pei-arm.c:pe_bfd_read_buildid
Line
Count
Source
1390
29.0k
{
1391
29.0k
  pe_data_type *pe = pe_data (abfd);
1392
29.0k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1393
29.0k
  asection *section;
1394
29.0k
  bfd_byte *data = 0;
1395
29.0k
  bfd_size_type dataoff;
1396
29.0k
  unsigned int i;
1397
29.0k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1398
29.0k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1399
1400
29.0k
  if (size == 0)
1401
10.0k
    return;
1402
1403
19.0k
  addr += extra->ImageBase;
1404
1405
  /* Search for the section containing the DebugDirectory.  */
1406
39.9k
  for (section = abfd->sections; section != NULL; section = section->next)
1407
31.4k
    {
1408
31.4k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1409
10.5k
  break;
1410
31.4k
    }
1411
1412
19.0k
  if (section == NULL)
1413
8.46k
    return;
1414
1415
10.5k
  if (!(section->flags & SEC_HAS_CONTENTS))
1416
1.33k
    return;
1417
1418
9.22k
  dataoff = addr - section->vma;
1419
1420
  /* PR 20605 and 22373: Make sure that the data is really there.
1421
     Note - since we are dealing with unsigned quantities we have
1422
     to be careful to check for potential overflows.  */
1423
9.22k
  if (dataoff >= section->size
1424
9.22k
      || size > section->size - dataoff)
1425
3.75k
    {
1426
3.75k
      _bfd_error_handler
1427
3.75k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1428
3.75k
   abfd);
1429
3.75k
      return;
1430
3.75k
    }
1431
1432
  /* Read the whole section. */
1433
5.46k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1434
2.57k
    {
1435
2.57k
      free (data);
1436
2.57k
      return;
1437
2.57k
    }
1438
1439
  /* Search for a CodeView entry in the DebugDirectory */
1440
41.0k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1441
39.2k
    {
1442
39.2k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1443
39.2k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1444
39.2k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1445
1446
39.2k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1447
1448
39.2k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1449
1.10k
  {
1450
1.10k
    char buffer[256 + 1];
1451
1.10k
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1452
1453
    /*
1454
      The debug entry doesn't have to have to be in a section, in which
1455
      case AddressOfRawData is 0, so always use PointerToRawData.
1456
    */
1457
1.10k
    if (_bfd_XXi_slurp_codeview_record (abfd,
1458
1.10k
                (file_ptr) idd.PointerToRawData,
1459
1.10k
                idd.SizeOfData, cvinfo, NULL))
1460
54
      {
1461
54
        struct bfd_build_id *build_id;
1462
54
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1463
1464
54
        build_id = bfd_alloc (abfd, bidlen);
1465
54
        if (build_id)
1466
54
    {
1467
54
      build_id->size = cvinfo->SignatureLength;
1468
54
      memcpy(build_id->data, cvinfo->Signature,
1469
54
       cvinfo->SignatureLength);
1470
54
      abfd->build_id = build_id;
1471
54
    }
1472
54
      }
1473
1.10k
    break;
1474
1.10k
  }
1475
39.2k
    }
1476
1477
2.88k
  free (data);
1478
2.88k
}
pei-mcore.c:pe_bfd_read_buildid
Line
Count
Source
1390
35.0k
{
1391
35.0k
  pe_data_type *pe = pe_data (abfd);
1392
35.0k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1393
35.0k
  asection *section;
1394
35.0k
  bfd_byte *data = 0;
1395
35.0k
  bfd_size_type dataoff;
1396
35.0k
  unsigned int i;
1397
35.0k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1398
35.0k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1399
1400
35.0k
  if (size == 0)
1401
18.4k
    return;
1402
1403
16.6k
  addr += extra->ImageBase;
1404
1405
  /* Search for the section containing the DebugDirectory.  */
1406
40.9k
  for (section = abfd->sections; section != NULL; section = section->next)
1407
32.9k
    {
1408
32.9k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1409
8.55k
  break;
1410
32.9k
    }
1411
1412
16.6k
  if (section == NULL)
1413
8.05k
    return;
1414
1415
8.55k
  if (!(section->flags & SEC_HAS_CONTENTS))
1416
696
    return;
1417
1418
7.85k
  dataoff = addr - section->vma;
1419
1420
  /* PR 20605 and 22373: Make sure that the data is really there.
1421
     Note - since we are dealing with unsigned quantities we have
1422
     to be careful to check for potential overflows.  */
1423
7.85k
  if (dataoff >= section->size
1424
7.85k
      || size > section->size - dataoff)
1425
2.52k
    {
1426
2.52k
      _bfd_error_handler
1427
2.52k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1428
2.52k
   abfd);
1429
2.52k
      return;
1430
2.52k
    }
1431
1432
  /* Read the whole section. */
1433
5.33k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1434
2.59k
    {
1435
2.59k
      free (data);
1436
2.59k
      return;
1437
2.59k
    }
1438
1439
  /* Search for a CodeView entry in the DebugDirectory */
1440
42.5k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1441
40.7k
    {
1442
40.7k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1443
40.7k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1444
40.7k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1445
1446
40.7k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1447
1448
40.7k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1449
900
  {
1450
900
    char buffer[256 + 1];
1451
900
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1452
1453
    /*
1454
      The debug entry doesn't have to have to be in a section, in which
1455
      case AddressOfRawData is 0, so always use PointerToRawData.
1456
    */
1457
900
    if (_bfd_XXi_slurp_codeview_record (abfd,
1458
900
                (file_ptr) idd.PointerToRawData,
1459
900
                idd.SizeOfData, cvinfo, NULL))
1460
1
      {
1461
1
        struct bfd_build_id *build_id;
1462
1
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1463
1464
1
        build_id = bfd_alloc (abfd, bidlen);
1465
1
        if (build_id)
1466
1
    {
1467
1
      build_id->size = cvinfo->SignatureLength;
1468
1
      memcpy(build_id->data, cvinfo->Signature,
1469
1
       cvinfo->SignatureLength);
1470
1
      abfd->build_id = build_id;
1471
1
    }
1472
1
      }
1473
900
    break;
1474
900
  }
1475
40.7k
    }
1476
1477
2.74k
  free (data);
1478
2.74k
}
pei-sh.c:pe_bfd_read_buildid
Line
Count
Source
1390
32.8k
{
1391
32.8k
  pe_data_type *pe = pe_data (abfd);
1392
32.8k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1393
32.8k
  asection *section;
1394
32.8k
  bfd_byte *data = 0;
1395
32.8k
  bfd_size_type dataoff;
1396
32.8k
  unsigned int i;
1397
32.8k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1398
32.8k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1399
1400
32.8k
  if (size == 0)
1401
17.4k
    return;
1402
1403
15.4k
  addr += extra->ImageBase;
1404
1405
  /* Search for the section containing the DebugDirectory.  */
1406
32.9k
  for (section = abfd->sections; section != NULL; section = section->next)
1407
25.8k
    {
1408
25.8k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1409
8.37k
  break;
1410
25.8k
    }
1411
1412
15.4k
  if (section == NULL)
1413
7.10k
    return;
1414
1415
8.37k
  if (!(section->flags & SEC_HAS_CONTENTS))
1416
752
    return;
1417
1418
7.62k
  dataoff = addr - section->vma;
1419
1420
  /* PR 20605 and 22373: Make sure that the data is really there.
1421
     Note - since we are dealing with unsigned quantities we have
1422
     to be careful to check for potential overflows.  */
1423
7.62k
  if (dataoff >= section->size
1424
7.62k
      || size > section->size - dataoff)
1425
2.51k
    {
1426
2.51k
      _bfd_error_handler
1427
2.51k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1428
2.51k
   abfd);
1429
2.51k
      return;
1430
2.51k
    }
1431
1432
  /* Read the whole section. */
1433
5.10k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1434
2.05k
    {
1435
2.05k
      free (data);
1436
2.05k
      return;
1437
2.05k
    }
1438
1439
  /* Search for a CodeView entry in the DebugDirectory */
1440
22.8k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1441
21.7k
    {
1442
21.7k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1443
21.7k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1444
21.7k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1445
1446
21.7k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1447
1448
21.7k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1449
1.93k
  {
1450
1.93k
    char buffer[256 + 1];
1451
1.93k
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1452
1453
    /*
1454
      The debug entry doesn't have to have to be in a section, in which
1455
      case AddressOfRawData is 0, so always use PointerToRawData.
1456
    */
1457
1.93k
    if (_bfd_XXi_slurp_codeview_record (abfd,
1458
1.93k
                (file_ptr) idd.PointerToRawData,
1459
1.93k
                idd.SizeOfData, cvinfo, NULL))
1460
3
      {
1461
3
        struct bfd_build_id *build_id;
1462
3
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1463
1464
3
        build_id = bfd_alloc (abfd, bidlen);
1465
3
        if (build_id)
1466
3
    {
1467
3
      build_id->size = cvinfo->SignatureLength;
1468
3
      memcpy(build_id->data, cvinfo->Signature,
1469
3
       cvinfo->SignatureLength);
1470
3
      abfd->build_id = build_id;
1471
3
    }
1472
3
      }
1473
1.93k
    break;
1474
1.93k
  }
1475
21.7k
    }
1476
1477
3.04k
  free (data);
1478
3.04k
}
1479
1480
static bfd_cleanup
1481
pe_bfd_object_p (bfd *abfd)
1482
34.3M
{
1483
34.3M
  bfd_byte buffer[6];
1484
34.3M
  struct external_DOS_hdr dos_hdr;
1485
34.3M
  struct external_PEI_IMAGE_hdr image_hdr;
1486
34.3M
  struct internal_filehdr internal_f;
1487
34.3M
  struct internal_aouthdr internal_a;
1488
34.3M
  bfd_size_type opt_hdr_size;
1489
34.3M
  file_ptr offset;
1490
34.3M
  bfd_cleanup result;
1491
1492
  /* Detect if this a Microsoft Import Library Format element.  */
1493
  /* First read the beginning of the header.  */
1494
34.3M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1495
34.3M
      || bfd_read (buffer, 6, abfd) != 6)
1496
75.8k
    {
1497
75.8k
      if (bfd_get_error () != bfd_error_system_call)
1498
65.9k
  bfd_set_error (bfd_error_wrong_format);
1499
75.8k
      return NULL;
1500
75.8k
    }
1501
1502
  /* Then check the magic and the version (only 0 is supported).  */
1503
34.2M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1504
34.2M
      && H_GET_16 (abfd, buffer + 4) == 0)
1505
539k
    return pe_ILF_object_p (abfd);
1506
1507
33.7M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1508
33.7M
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1509
9.13M
    {
1510
9.13M
      if (bfd_get_error () != bfd_error_system_call)
1511
9.13M
  bfd_set_error (bfd_error_wrong_format);
1512
9.13M
      return NULL;
1513
9.13M
    }
1514
1515
  /* There are really two magic numbers involved; the magic number
1516
     that says this is a NT executable (PEI) and the magic number that
1517
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1518
     the e_magic field.  The latter is stored in the f_magic field.
1519
     If the NT magic number isn't valid, the architecture magic number
1520
     could be mimicked by some other field (specifically, the number
1521
     of relocs in section 3).  Since this routine can only be called
1522
     correctly for a PEI file, check the e_magic number here, and, if
1523
     it doesn't match, clobber the f_magic number so that we don't get
1524
     a false match.  */
1525
24.6M
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1526
15.7M
    {
1527
15.7M
      bfd_set_error (bfd_error_wrong_format);
1528
15.7M
      return NULL;
1529
15.7M
    }
1530
1531
8.85M
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1532
8.85M
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1533
8.85M
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1534
19.4k
    {
1535
19.4k
      if (bfd_get_error () != bfd_error_system_call)
1536
19.4k
  bfd_set_error (bfd_error_wrong_format);
1537
19.4k
      return NULL;
1538
19.4k
    }
1539
1540
8.83M
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1541
103k
    {
1542
103k
      bfd_set_error (bfd_error_wrong_format);
1543
103k
      return NULL;
1544
103k
    }
1545
1546
  /* Swap file header, so that we get the location for calling
1547
     real_object_p.  */
1548
8.73M
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1549
1550
8.73M
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1551
8.73M
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1552
7.67M
    {
1553
7.67M
      bfd_set_error (bfd_error_wrong_format);
1554
7.67M
      return NULL;
1555
7.67M
    }
1556
1557
1.06M
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1558
1.06M
    sizeof (internal_f.pe.dos_message));
1559
1560
  /* Read the optional header, which has variable size.  */
1561
1.06M
  opt_hdr_size = internal_f.f_opthdr;
1562
1563
1.06M
  if (opt_hdr_size != 0)
1564
641k
    {
1565
641k
      bfd_size_type amt = opt_hdr_size;
1566
641k
      bfd_byte *opthdr;
1567
1568
      /* PR 17521 file: 230-131433-0.004.  */
1569
641k
      if (amt < sizeof (PEAOUTHDR))
1570
524k
  amt = sizeof (PEAOUTHDR);
1571
1572
641k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1573
641k
      if (opthdr == NULL)
1574
21.3k
  return NULL;
1575
620k
      if (amt > opt_hdr_size)
1576
512k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1577
1578
620k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1579
1580
620k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1581
1582
#ifdef ARM
1583
      /* Use Subsystem to distinguish between pei-arm-little and
1584
   pei-arm-wince-little.  */
1585
#ifdef WINCE
1586
73.8k
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1587
#else
1588
73.8k
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1589
23.8k
#endif
1590
73.7k
  {
1591
73.7k
    bfd_set_error (bfd_error_wrong_format);
1592
73.7k
    return NULL;
1593
73.7k
  }
1594
73.9k
#endif
1595
1596
546k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1597
546k
    || a->SectionAlignment >= 0x80000000)
1598
295k
  {
1599
295k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1600
295k
            abfd);
1601
295k
    a->SectionAlignment &= -a->SectionAlignment;
1602
295k
    if (a->SectionAlignment >= 0x80000000)
1603
8.82k
      a->SectionAlignment = 0x40000000;
1604
295k
  }
1605
1606
546k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1607
546k
    || a->FileAlignment > a->SectionAlignment)
1608
415k
  {
1609
415k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1610
415k
            abfd);
1611
415k
    a->FileAlignment &= -a->FileAlignment;
1612
415k
    if (a->FileAlignment > a->SectionAlignment)
1613
225k
      a->FileAlignment = a->SectionAlignment;
1614
415k
  }
1615
1616
546k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1617
319k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1618
73.9k
    }
1619
1620
966k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1621
966k
             (opt_hdr_size != 0
1622
966k
        ? &internal_a
1623
966k
        : (struct internal_aouthdr *) NULL));
1624
1625
966k
  if (result)
1626
481k
    {
1627
      /* Now the whole header has been processed, see if there is a build-id */
1628
481k
      pe_bfd_read_buildid(abfd);
1629
481k
    }
1630
1631
966k
  return result;
1632
1.06M
}
pei-i386.c:pe_bfd_object_p
Line
Count
Source
1482
2.82M
{
1483
2.82M
  bfd_byte buffer[6];
1484
2.82M
  struct external_DOS_hdr dos_hdr;
1485
2.82M
  struct external_PEI_IMAGE_hdr image_hdr;
1486
2.82M
  struct internal_filehdr internal_f;
1487
2.82M
  struct internal_aouthdr internal_a;
1488
2.82M
  bfd_size_type opt_hdr_size;
1489
2.82M
  file_ptr offset;
1490
2.82M
  bfd_cleanup result;
1491
1492
  /* Detect if this a Microsoft Import Library Format element.  */
1493
  /* First read the beginning of the header.  */
1494
2.82M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1495
2.82M
      || bfd_read (buffer, 6, abfd) != 6)
1496
6.44k
    {
1497
6.44k
      if (bfd_get_error () != bfd_error_system_call)
1498
5.61k
  bfd_set_error (bfd_error_wrong_format);
1499
6.44k
      return NULL;
1500
6.44k
    }
1501
1502
  /* Then check the magic and the version (only 0 is supported).  */
1503
2.81M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1504
2.81M
      && H_GET_16 (abfd, buffer + 4) == 0)
1505
66.4k
    return pe_ILF_object_p (abfd);
1506
1507
2.75M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1508
2.75M
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1509
746k
    {
1510
746k
      if (bfd_get_error () != bfd_error_system_call)
1511
746k
  bfd_set_error (bfd_error_wrong_format);
1512
746k
      return NULL;
1513
746k
    }
1514
1515
  /* There are really two magic numbers involved; the magic number
1516
     that says this is a NT executable (PEI) and the magic number that
1517
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1518
     the e_magic field.  The latter is stored in the f_magic field.
1519
     If the NT magic number isn't valid, the architecture magic number
1520
     could be mimicked by some other field (specifically, the number
1521
     of relocs in section 3).  Since this routine can only be called
1522
     correctly for a PEI file, check the e_magic number here, and, if
1523
     it doesn't match, clobber the f_magic number so that we don't get
1524
     a false match.  */
1525
2.00M
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1526
1.09M
    {
1527
1.09M
      bfd_set_error (bfd_error_wrong_format);
1528
1.09M
      return NULL;
1529
1.09M
    }
1530
1531
914k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1532
914k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1533
914k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1534
2.06k
    {
1535
2.06k
      if (bfd_get_error () != bfd_error_system_call)
1536
2.06k
  bfd_set_error (bfd_error_wrong_format);
1537
2.06k
      return NULL;
1538
2.06k
    }
1539
1540
912k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1541
11.3k
    {
1542
11.3k
      bfd_set_error (bfd_error_wrong_format);
1543
11.3k
      return NULL;
1544
11.3k
    }
1545
1546
  /* Swap file header, so that we get the location for calling
1547
     real_object_p.  */
1548
901k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1549
1550
901k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1551
901k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1552
769k
    {
1553
769k
      bfd_set_error (bfd_error_wrong_format);
1554
769k
      return NULL;
1555
769k
    }
1556
1557
131k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1558
131k
    sizeof (internal_f.pe.dos_message));
1559
1560
  /* Read the optional header, which has variable size.  */
1561
131k
  opt_hdr_size = internal_f.f_opthdr;
1562
1563
131k
  if (opt_hdr_size != 0)
1564
93.8k
    {
1565
93.8k
      bfd_size_type amt = opt_hdr_size;
1566
93.8k
      bfd_byte *opthdr;
1567
1568
      /* PR 17521 file: 230-131433-0.004.  */
1569
93.8k
      if (amt < sizeof (PEAOUTHDR))
1570
82.9k
  amt = sizeof (PEAOUTHDR);
1571
1572
93.8k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1573
93.8k
      if (opthdr == NULL)
1574
2.16k
  return NULL;
1575
91.6k
      if (amt > opt_hdr_size)
1576
81.7k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1577
1578
91.6k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1579
1580
91.6k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1581
1582
#ifdef ARM
1583
      /* Use Subsystem to distinguish between pei-arm-little and
1584
   pei-arm-wince-little.  */
1585
#ifdef WINCE
1586
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1587
#else
1588
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1589
#endif
1590
  {
1591
    bfd_set_error (bfd_error_wrong_format);
1592
    return NULL;
1593
  }
1594
#endif
1595
1596
91.6k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1597
91.6k
    || a->SectionAlignment >= 0x80000000)
1598
70.6k
  {
1599
70.6k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1600
70.6k
            abfd);
1601
70.6k
    a->SectionAlignment &= -a->SectionAlignment;
1602
70.6k
    if (a->SectionAlignment >= 0x80000000)
1603
1.55k
      a->SectionAlignment = 0x40000000;
1604
70.6k
  }
1605
1606
91.6k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1607
91.6k
    || a->FileAlignment > a->SectionAlignment)
1608
76.1k
  {
1609
76.1k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1610
76.1k
            abfd);
1611
76.1k
    a->FileAlignment &= -a->FileAlignment;
1612
76.1k
    if (a->FileAlignment > a->SectionAlignment)
1613
38.2k
      a->FileAlignment = a->SectionAlignment;
1614
76.1k
  }
1615
1616
91.6k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1617
36.8k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1618
91.6k
    }
1619
1620
129k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1621
129k
             (opt_hdr_size != 0
1622
129k
        ? &internal_a
1623
129k
        : (struct internal_aouthdr *) NULL));
1624
1625
129k
  if (result)
1626
91.6k
    {
1627
      /* Now the whole header has been processed, see if there is a build-id */
1628
91.6k
      pe_bfd_read_buildid(abfd);
1629
91.6k
    }
1630
1631
129k
  return result;
1632
131k
}
pei-x86_64.c:pe_bfd_object_p
Line
Count
Source
1482
2.82M
{
1483
2.82M
  bfd_byte buffer[6];
1484
2.82M
  struct external_DOS_hdr dos_hdr;
1485
2.82M
  struct external_PEI_IMAGE_hdr image_hdr;
1486
2.82M
  struct internal_filehdr internal_f;
1487
2.82M
  struct internal_aouthdr internal_a;
1488
2.82M
  bfd_size_type opt_hdr_size;
1489
2.82M
  file_ptr offset;
1490
2.82M
  bfd_cleanup result;
1491
1492
  /* Detect if this a Microsoft Import Library Format element.  */
1493
  /* First read the beginning of the header.  */
1494
2.82M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1495
2.82M
      || bfd_read (buffer, 6, abfd) != 6)
1496
6.44k
    {
1497
6.44k
      if (bfd_get_error () != bfd_error_system_call)
1498
5.61k
  bfd_set_error (bfd_error_wrong_format);
1499
6.44k
      return NULL;
1500
6.44k
    }
1501
1502
  /* Then check the magic and the version (only 0 is supported).  */
1503
2.81M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1504
2.81M
      && H_GET_16 (abfd, buffer + 4) == 0)
1505
41.8k
    return pe_ILF_object_p (abfd);
1506
1507
2.77M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1508
2.77M
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1509
753k
    {
1510
753k
      if (bfd_get_error () != bfd_error_system_call)
1511
753k
  bfd_set_error (bfd_error_wrong_format);
1512
753k
      return NULL;
1513
753k
    }
1514
1515
  /* There are really two magic numbers involved; the magic number
1516
     that says this is a NT executable (PEI) and the magic number that
1517
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1518
     the e_magic field.  The latter is stored in the f_magic field.
1519
     If the NT magic number isn't valid, the architecture magic number
1520
     could be mimicked by some other field (specifically, the number
1521
     of relocs in section 3).  Since this routine can only be called
1522
     correctly for a PEI file, check the e_magic number here, and, if
1523
     it doesn't match, clobber the f_magic number so that we don't get
1524
     a false match.  */
1525
2.02M
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1526
1.10M
    {
1527
1.10M
      bfd_set_error (bfd_error_wrong_format);
1528
1.10M
      return NULL;
1529
1.10M
    }
1530
1531
913k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1532
913k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1533
913k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1534
2.06k
    {
1535
2.06k
      if (bfd_get_error () != bfd_error_system_call)
1536
2.06k
  bfd_set_error (bfd_error_wrong_format);
1537
2.06k
      return NULL;
1538
2.06k
    }
1539
1540
911k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1541
11.3k
    {
1542
11.3k
      bfd_set_error (bfd_error_wrong_format);
1543
11.3k
      return NULL;
1544
11.3k
    }
1545
1546
  /* Swap file header, so that we get the location for calling
1547
     real_object_p.  */
1548
899k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1549
1550
899k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1551
899k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1552
774k
    {
1553
774k
      bfd_set_error (bfd_error_wrong_format);
1554
774k
      return NULL;
1555
774k
    }
1556
1557
125k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1558
125k
    sizeof (internal_f.pe.dos_message));
1559
1560
  /* Read the optional header, which has variable size.  */
1561
125k
  opt_hdr_size = internal_f.f_opthdr;
1562
1563
125k
  if (opt_hdr_size != 0)
1564
77.6k
    {
1565
77.6k
      bfd_size_type amt = opt_hdr_size;
1566
77.6k
      bfd_byte *opthdr;
1567
1568
      /* PR 17521 file: 230-131433-0.004.  */
1569
77.6k
      if (amt < sizeof (PEAOUTHDR))
1570
69.1k
  amt = sizeof (PEAOUTHDR);
1571
1572
77.6k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1573
77.6k
      if (opthdr == NULL)
1574
2.09k
  return NULL;
1575
75.6k
      if (amt > opt_hdr_size)
1576
67.6k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1577
1578
75.6k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1579
1580
75.6k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1581
1582
#ifdef ARM
1583
      /* Use Subsystem to distinguish between pei-arm-little and
1584
   pei-arm-wince-little.  */
1585
#ifdef WINCE
1586
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1587
#else
1588
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1589
#endif
1590
  {
1591
    bfd_set_error (bfd_error_wrong_format);
1592
    return NULL;
1593
  }
1594
#endif
1595
1596
75.6k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1597
75.6k
    || a->SectionAlignment >= 0x80000000)
1598
47.7k
  {
1599
47.7k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1600
47.7k
            abfd);
1601
47.7k
    a->SectionAlignment &= -a->SectionAlignment;
1602
47.7k
    if (a->SectionAlignment >= 0x80000000)
1603
1.27k
      a->SectionAlignment = 0x40000000;
1604
47.7k
  }
1605
1606
75.6k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1607
75.6k
    || a->FileAlignment > a->SectionAlignment)
1608
56.6k
  {
1609
56.6k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1610
56.6k
            abfd);
1611
56.6k
    a->FileAlignment &= -a->FileAlignment;
1612
56.6k
    if (a->FileAlignment > a->SectionAlignment)
1613
26.4k
      a->FileAlignment = a->SectionAlignment;
1614
56.6k
  }
1615
1616
75.6k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1617
42.7k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1618
75.6k
    }
1619
1620
123k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1621
123k
             (opt_hdr_size != 0
1622
123k
        ? &internal_a
1623
123k
        : (struct internal_aouthdr *) NULL));
1624
1625
123k
  if (result)
1626
86.0k
    {
1627
      /* Now the whole header has been processed, see if there is a build-id */
1628
86.0k
      pe_bfd_read_buildid(abfd);
1629
86.0k
    }
1630
1631
123k
  return result;
1632
125k
}
pei-aarch64.c:pe_bfd_object_p
Line
Count
Source
1482
2.79M
{
1483
2.79M
  bfd_byte buffer[6];
1484
2.79M
  struct external_DOS_hdr dos_hdr;
1485
2.79M
  struct external_PEI_IMAGE_hdr image_hdr;
1486
2.79M
  struct internal_filehdr internal_f;
1487
2.79M
  struct internal_aouthdr internal_a;
1488
2.79M
  bfd_size_type opt_hdr_size;
1489
2.79M
  file_ptr offset;
1490
2.79M
  bfd_cleanup result;
1491
1492
  /* Detect if this a Microsoft Import Library Format element.  */
1493
  /* First read the beginning of the header.  */
1494
2.79M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1495
2.79M
      || bfd_read (buffer, 6, abfd) != 6)
1496
6.44k
    {
1497
6.44k
      if (bfd_get_error () != bfd_error_system_call)
1498
5.61k
  bfd_set_error (bfd_error_wrong_format);
1499
6.44k
      return NULL;
1500
6.44k
    }
1501
1502
  /* Then check the magic and the version (only 0 is supported).  */
1503
2.78M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1504
2.78M
      && H_GET_16 (abfd, buffer + 4) == 0)
1505
85.5k
    return pe_ILF_object_p (abfd);
1506
1507
2.70M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1508
2.70M
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1509
739k
    {
1510
739k
      if (bfd_get_error () != bfd_error_system_call)
1511
739k
  bfd_set_error (bfd_error_wrong_format);
1512
739k
      return NULL;
1513
739k
    }
1514
1515
  /* There are really two magic numbers involved; the magic number
1516
     that says this is a NT executable (PEI) and the magic number that
1517
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1518
     the e_magic field.  The latter is stored in the f_magic field.
1519
     If the NT magic number isn't valid, the architecture magic number
1520
     could be mimicked by some other field (specifically, the number
1521
     of relocs in section 3).  Since this routine can only be called
1522
     correctly for a PEI file, check the e_magic number here, and, if
1523
     it doesn't match, clobber the f_magic number so that we don't get
1524
     a false match.  */
1525
1.96M
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1526
1.07M
    {
1527
1.07M
      bfd_set_error (bfd_error_wrong_format);
1528
1.07M
      return NULL;
1529
1.07M
    }
1530
1531
883k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1532
883k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1533
883k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1534
2.36k
    {
1535
2.36k
      if (bfd_get_error () != bfd_error_system_call)
1536
2.36k
  bfd_set_error (bfd_error_wrong_format);
1537
2.36k
      return NULL;
1538
2.36k
    }
1539
1540
880k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1541
11.7k
    {
1542
11.7k
      bfd_set_error (bfd_error_wrong_format);
1543
11.7k
      return NULL;
1544
11.7k
    }
1545
1546
  /* Swap file header, so that we get the location for calling
1547
     real_object_p.  */
1548
869k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1549
1550
869k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1551
869k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1552
778k
    {
1553
778k
      bfd_set_error (bfd_error_wrong_format);
1554
778k
      return NULL;
1555
778k
    }
1556
1557
90.9k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1558
90.9k
    sizeof (internal_f.pe.dos_message));
1559
1560
  /* Read the optional header, which has variable size.  */
1561
90.9k
  opt_hdr_size = internal_f.f_opthdr;
1562
1563
90.9k
  if (opt_hdr_size != 0)
1564
62.5k
    {
1565
62.5k
      bfd_size_type amt = opt_hdr_size;
1566
62.5k
      bfd_byte *opthdr;
1567
1568
      /* PR 17521 file: 230-131433-0.004.  */
1569
62.5k
      if (amt < sizeof (PEAOUTHDR))
1570
33.9k
  amt = sizeof (PEAOUTHDR);
1571
1572
62.5k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1573
62.5k
      if (opthdr == NULL)
1574
1.95k
  return NULL;
1575
60.6k
      if (amt > opt_hdr_size)
1576
33.2k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1577
1578
60.6k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1579
1580
60.6k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1581
1582
#ifdef ARM
1583
      /* Use Subsystem to distinguish between pei-arm-little and
1584
   pei-arm-wince-little.  */
1585
#ifdef WINCE
1586
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1587
#else
1588
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1589
#endif
1590
  {
1591
    bfd_set_error (bfd_error_wrong_format);
1592
    return NULL;
1593
  }
1594
#endif
1595
1596
60.6k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1597
60.6k
    || a->SectionAlignment >= 0x80000000)
1598
29.5k
  {
1599
29.5k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1600
29.5k
            abfd);
1601
29.5k
    a->SectionAlignment &= -a->SectionAlignment;
1602
29.5k
    if (a->SectionAlignment >= 0x80000000)
1603
685
      a->SectionAlignment = 0x40000000;
1604
29.5k
  }
1605
1606
60.6k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1607
60.6k
    || a->FileAlignment > a->SectionAlignment)
1608
47.8k
  {
1609
47.8k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1610
47.8k
            abfd);
1611
47.8k
    a->FileAlignment &= -a->FileAlignment;
1612
47.8k
    if (a->FileAlignment > a->SectionAlignment)
1613
22.9k
      a->FileAlignment = a->SectionAlignment;
1614
47.8k
  }
1615
1616
60.6k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1617
46.1k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1618
60.6k
    }
1619
1620
89.0k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1621
89.0k
             (opt_hdr_size != 0
1622
89.0k
        ? &internal_a
1623
89.0k
        : (struct internal_aouthdr *) NULL));
1624
1625
89.0k
  if (result)
1626
52.3k
    {
1627
      /* Now the whole header has been processed, see if there is a build-id */
1628
52.3k
      pe_bfd_read_buildid(abfd);
1629
52.3k
    }
1630
1631
89.0k
  return result;
1632
90.9k
}
pei-ia64.c:pe_bfd_object_p
Line
Count
Source
1482
852k
{
1483
852k
  bfd_byte buffer[6];
1484
852k
  struct external_DOS_hdr dos_hdr;
1485
852k
  struct external_PEI_IMAGE_hdr image_hdr;
1486
852k
  struct internal_filehdr internal_f;
1487
852k
  struct internal_aouthdr internal_a;
1488
852k
  bfd_size_type opt_hdr_size;
1489
852k
  file_ptr offset;
1490
852k
  bfd_cleanup result;
1491
1492
  /* Detect if this a Microsoft Import Library Format element.  */
1493
  /* First read the beginning of the header.  */
1494
852k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1495
852k
      || bfd_read (buffer, 6, abfd) != 6)
1496
0
    {
1497
0
      if (bfd_get_error () != bfd_error_system_call)
1498
0
  bfd_set_error (bfd_error_wrong_format);
1499
0
      return NULL;
1500
0
    }
1501
1502
  /* Then check the magic and the version (only 0 is supported).  */
1503
852k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1504
852k
      && H_GET_16 (abfd, buffer + 4) == 0)
1505
0
    return pe_ILF_object_p (abfd);
1506
1507
852k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1508
852k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1509
0
    {
1510
0
      if (bfd_get_error () != bfd_error_system_call)
1511
0
  bfd_set_error (bfd_error_wrong_format);
1512
0
      return NULL;
1513
0
    }
1514
1515
  /* There are really two magic numbers involved; the magic number
1516
     that says this is a NT executable (PEI) and the magic number that
1517
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1518
     the e_magic field.  The latter is stored in the f_magic field.
1519
     If the NT magic number isn't valid, the architecture magic number
1520
     could be mimicked by some other field (specifically, the number
1521
     of relocs in section 3).  Since this routine can only be called
1522
     correctly for a PEI file, check the e_magic number here, and, if
1523
     it doesn't match, clobber the f_magic number so that we don't get
1524
     a false match.  */
1525
852k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1526
0
    {
1527
0
      bfd_set_error (bfd_error_wrong_format);
1528
0
      return NULL;
1529
0
    }
1530
1531
852k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1532
852k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1533
852k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1534
0
    {
1535
0
      if (bfd_get_error () != bfd_error_system_call)
1536
0
  bfd_set_error (bfd_error_wrong_format);
1537
0
      return NULL;
1538
0
    }
1539
1540
852k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1541
0
    {
1542
0
      bfd_set_error (bfd_error_wrong_format);
1543
0
      return NULL;
1544
0
    }
1545
1546
  /* Swap file header, so that we get the location for calling
1547
     real_object_p.  */
1548
852k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1549
1550
852k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1551
852k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1552
747k
    {
1553
747k
      bfd_set_error (bfd_error_wrong_format);
1554
747k
      return NULL;
1555
747k
    }
1556
1557
105k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1558
105k
    sizeof (internal_f.pe.dos_message));
1559
1560
  /* Read the optional header, which has variable size.  */
1561
105k
  opt_hdr_size = internal_f.f_opthdr;
1562
1563
105k
  if (opt_hdr_size != 0)
1564
62.0k
    {
1565
62.0k
      bfd_size_type amt = opt_hdr_size;
1566
62.0k
      bfd_byte *opthdr;
1567
1568
      /* PR 17521 file: 230-131433-0.004.  */
1569
62.0k
      if (amt < sizeof (PEAOUTHDR))
1570
56.8k
  amt = sizeof (PEAOUTHDR);
1571
1572
62.0k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1573
62.0k
      if (opthdr == NULL)
1574
1.95k
  return NULL;
1575
60.1k
      if (amt > opt_hdr_size)
1576
55.2k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1577
1578
60.1k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1579
1580
60.1k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1581
1582
#ifdef ARM
1583
      /* Use Subsystem to distinguish between pei-arm-little and
1584
   pei-arm-wince-little.  */
1585
#ifdef WINCE
1586
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1587
#else
1588
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1589
#endif
1590
  {
1591
    bfd_set_error (bfd_error_wrong_format);
1592
    return NULL;
1593
  }
1594
#endif
1595
1596
60.1k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1597
60.1k
    || a->SectionAlignment >= 0x80000000)
1598
15.1k
  {
1599
15.1k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1600
15.1k
            abfd);
1601
15.1k
    a->SectionAlignment &= -a->SectionAlignment;
1602
15.1k
    if (a->SectionAlignment >= 0x80000000)
1603
600
      a->SectionAlignment = 0x40000000;
1604
15.1k
  }
1605
1606
60.1k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1607
60.1k
    || a->FileAlignment > a->SectionAlignment)
1608
46.2k
  {
1609
46.2k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1610
46.2k
            abfd);
1611
46.2k
    a->FileAlignment &= -a->FileAlignment;
1612
46.2k
    if (a->FileAlignment > a->SectionAlignment)
1613
19.5k
      a->FileAlignment = a->SectionAlignment;
1614
46.2k
  }
1615
1616
60.1k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1617
37.1k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1618
60.1k
    }
1619
1620
103k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1621
103k
             (opt_hdr_size != 0
1622
103k
        ? &internal_a
1623
103k
        : (struct internal_aouthdr *) NULL));
1624
1625
103k
  if (result)
1626
52.3k
    {
1627
      /* Now the whole header has been processed, see if there is a build-id */
1628
52.3k
      pe_bfd_read_buildid(abfd);
1629
52.3k
    }
1630
1631
103k
  return result;
1632
105k
}
pei-loongarch64.c:pe_bfd_object_p
Line
Count
Source
1482
2.79M
{
1483
2.79M
  bfd_byte buffer[6];
1484
2.79M
  struct external_DOS_hdr dos_hdr;
1485
2.79M
  struct external_PEI_IMAGE_hdr image_hdr;
1486
2.79M
  struct internal_filehdr internal_f;
1487
2.79M
  struct internal_aouthdr internal_a;
1488
2.79M
  bfd_size_type opt_hdr_size;
1489
2.79M
  file_ptr offset;
1490
2.79M
  bfd_cleanup result;
1491
1492
  /* Detect if this a Microsoft Import Library Format element.  */
1493
  /* First read the beginning of the header.  */
1494
2.79M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1495
2.79M
      || bfd_read (buffer, 6, abfd) != 6)
1496
6.44k
    {
1497
6.44k
      if (bfd_get_error () != bfd_error_system_call)
1498
5.61k
  bfd_set_error (bfd_error_wrong_format);
1499
6.44k
      return NULL;
1500
6.44k
    }
1501
1502
  /* Then check the magic and the version (only 0 is supported).  */
1503
2.78M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1504
2.78M
      && H_GET_16 (abfd, buffer + 4) == 0)
1505
35.1k
    return pe_ILF_object_p (abfd);
1506
1507
2.75M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1508
2.75M
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1509
754k
    {
1510
754k
      if (bfd_get_error () != bfd_error_system_call)
1511
754k
  bfd_set_error (bfd_error_wrong_format);
1512
754k
      return NULL;
1513
754k
    }
1514
1515
  /* There are really two magic numbers involved; the magic number
1516
     that says this is a NT executable (PEI) and the magic number that
1517
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1518
     the e_magic field.  The latter is stored in the f_magic field.
1519
     If the NT magic number isn't valid, the architecture magic number
1520
     could be mimicked by some other field (specifically, the number
1521
     of relocs in section 3).  Since this routine can only be called
1522
     correctly for a PEI file, check the e_magic number here, and, if
1523
     it doesn't match, clobber the f_magic number so that we don't get
1524
     a false match.  */
1525
1.99M
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1526
1.11M
    {
1527
1.11M
      bfd_set_error (bfd_error_wrong_format);
1528
1.11M
      return NULL;
1529
1.11M
    }
1530
1531
882k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1532
882k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1533
882k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1534
2.06k
    {
1535
2.06k
      if (bfd_get_error () != bfd_error_system_call)
1536
2.06k
  bfd_set_error (bfd_error_wrong_format);
1537
2.06k
      return NULL;
1538
2.06k
    }
1539
1540
880k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1541
11.3k
    {
1542
11.3k
      bfd_set_error (bfd_error_wrong_format);
1543
11.3k
      return NULL;
1544
11.3k
    }
1545
1546
  /* Swap file header, so that we get the location for calling
1547
     real_object_p.  */
1548
868k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1549
1550
868k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1551
868k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1552
783k
    {
1553
783k
      bfd_set_error (bfd_error_wrong_format);
1554
783k
      return NULL;
1555
783k
    }
1556
1557
84.9k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1558
84.9k
    sizeof (internal_f.pe.dos_message));
1559
1560
  /* Read the optional header, which has variable size.  */
1561
84.9k
  opt_hdr_size = internal_f.f_opthdr;
1562
1563
84.9k
  if (opt_hdr_size != 0)
1564
42.8k
    {
1565
42.8k
      bfd_size_type amt = opt_hdr_size;
1566
42.8k
      bfd_byte *opthdr;
1567
1568
      /* PR 17521 file: 230-131433-0.004.  */
1569
42.8k
      if (amt < sizeof (PEAOUTHDR))
1570
26.7k
  amt = sizeof (PEAOUTHDR);
1571
1572
42.8k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1573
42.8k
      if (opthdr == NULL)
1574
1.86k
  return NULL;
1575
41.0k
      if (amt > opt_hdr_size)
1576
26.2k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1577
1578
41.0k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1579
1580
41.0k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1581
1582
#ifdef ARM
1583
      /* Use Subsystem to distinguish between pei-arm-little and
1584
   pei-arm-wince-little.  */
1585
#ifdef WINCE
1586
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1587
#else
1588
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1589
#endif
1590
  {
1591
    bfd_set_error (bfd_error_wrong_format);
1592
    return NULL;
1593
  }
1594
#endif
1595
1596
41.0k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1597
41.0k
    || a->SectionAlignment >= 0x80000000)
1598
18.1k
  {
1599
18.1k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1600
18.1k
            abfd);
1601
18.1k
    a->SectionAlignment &= -a->SectionAlignment;
1602
18.1k
    if (a->SectionAlignment >= 0x80000000)
1603
899
      a->SectionAlignment = 0x40000000;
1604
18.1k
  }
1605
1606
41.0k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1607
41.0k
    || a->FileAlignment > a->SectionAlignment)
1608
25.2k
  {
1609
25.2k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1610
25.2k
            abfd);
1611
25.2k
    a->FileAlignment &= -a->FileAlignment;
1612
25.2k
    if (a->FileAlignment > a->SectionAlignment)
1613
15.1k
      a->FileAlignment = a->SectionAlignment;
1614
25.2k
  }
1615
1616
41.0k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1617
29.7k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1618
41.0k
    }
1619
1620
83.0k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1621
83.0k
             (opt_hdr_size != 0
1622
83.0k
        ? &internal_a
1623
83.0k
        : (struct internal_aouthdr *) NULL));
1624
1625
83.0k
  if (result)
1626
49.7k
    {
1627
      /* Now the whole header has been processed, see if there is a build-id */
1628
49.7k
      pe_bfd_read_buildid(abfd);
1629
49.7k
    }
1630
1631
83.0k
  return result;
1632
84.9k
}
pei-riscv64.c:pe_bfd_object_p
Line
Count
Source
1482
2.79M
{
1483
2.79M
  bfd_byte buffer[6];
1484
2.79M
  struct external_DOS_hdr dos_hdr;
1485
2.79M
  struct external_PEI_IMAGE_hdr image_hdr;
1486
2.79M
  struct internal_filehdr internal_f;
1487
2.79M
  struct internal_aouthdr internal_a;
1488
2.79M
  bfd_size_type opt_hdr_size;
1489
2.79M
  file_ptr offset;
1490
2.79M
  bfd_cleanup result;
1491
1492
  /* Detect if this a Microsoft Import Library Format element.  */
1493
  /* First read the beginning of the header.  */
1494
2.79M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1495
2.79M
      || bfd_read (buffer, 6, abfd) != 6)
1496
6.44k
    {
1497
6.44k
      if (bfd_get_error () != bfd_error_system_call)
1498
5.61k
  bfd_set_error (bfd_error_wrong_format);
1499
6.44k
      return NULL;
1500
6.44k
    }
1501
1502
  /* Then check the magic and the version (only 0 is supported).  */
1503
2.78M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1504
2.78M
      && H_GET_16 (abfd, buffer + 4) == 0)
1505
57.4k
    return pe_ILF_object_p (abfd);
1506
1507
2.72M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1508
2.72M
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1509
749k
    {
1510
749k
      if (bfd_get_error () != bfd_error_system_call)
1511
749k
  bfd_set_error (bfd_error_wrong_format);
1512
749k
      return NULL;
1513
749k
    }
1514
1515
  /* There are really two magic numbers involved; the magic number
1516
     that says this is a NT executable (PEI) and the magic number that
1517
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1518
     the e_magic field.  The latter is stored in the f_magic field.
1519
     If the NT magic number isn't valid, the architecture magic number
1520
     could be mimicked by some other field (specifically, the number
1521
     of relocs in section 3).  Since this routine can only be called
1522
     correctly for a PEI file, check the e_magic number here, and, if
1523
     it doesn't match, clobber the f_magic number so that we don't get
1524
     a false match.  */
1525
1.97M
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1526
1.09M
    {
1527
1.09M
      bfd_set_error (bfd_error_wrong_format);
1528
1.09M
      return NULL;
1529
1.09M
    }
1530
1531
881k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1532
881k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1533
881k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1534
2.06k
    {
1535
2.06k
      if (bfd_get_error () != bfd_error_system_call)
1536
2.06k
  bfd_set_error (bfd_error_wrong_format);
1537
2.06k
      return NULL;
1538
2.06k
    }
1539
1540
879k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1541
11.3k
    {
1542
11.3k
      bfd_set_error (bfd_error_wrong_format);
1543
11.3k
      return NULL;
1544
11.3k
    }
1545
1546
  /* Swap file header, so that we get the location for calling
1547
     real_object_p.  */
1548
868k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1549
1550
868k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1551
868k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1552
790k
    {
1553
790k
      bfd_set_error (bfd_error_wrong_format);
1554
790k
      return NULL;
1555
790k
    }
1556
1557
78.3k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1558
78.3k
    sizeof (internal_f.pe.dos_message));
1559
1560
  /* Read the optional header, which has variable size.  */
1561
78.3k
  opt_hdr_size = internal_f.f_opthdr;
1562
1563
78.3k
  if (opt_hdr_size != 0)
1564
55.1k
    {
1565
55.1k
      bfd_size_type amt = opt_hdr_size;
1566
55.1k
      bfd_byte *opthdr;
1567
1568
      /* PR 17521 file: 230-131433-0.004.  */
1569
55.1k
      if (amt < sizeof (PEAOUTHDR))
1570
35.5k
  amt = sizeof (PEAOUTHDR);
1571
1572
55.1k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1573
55.1k
      if (opthdr == NULL)
1574
1.71k
  return NULL;
1575
53.4k
      if (amt > opt_hdr_size)
1576
34.2k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1577
1578
53.4k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1579
1580
53.4k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1581
1582
#ifdef ARM
1583
      /* Use Subsystem to distinguish between pei-arm-little and
1584
   pei-arm-wince-little.  */
1585
#ifdef WINCE
1586
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1587
#else
1588
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1589
#endif
1590
  {
1591
    bfd_set_error (bfd_error_wrong_format);
1592
    return NULL;
1593
  }
1594
#endif
1595
1596
53.4k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1597
53.4k
    || a->SectionAlignment >= 0x80000000)
1598
22.1k
  {
1599
22.1k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1600
22.1k
            abfd);
1601
22.1k
    a->SectionAlignment &= -a->SectionAlignment;
1602
22.1k
    if (a->SectionAlignment >= 0x80000000)
1603
584
      a->SectionAlignment = 0x40000000;
1604
22.1k
  }
1605
1606
53.4k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1607
53.4k
    || a->FileAlignment > a->SectionAlignment)
1608
35.1k
  {
1609
35.1k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1610
35.1k
            abfd);
1611
35.1k
    a->FileAlignment &= -a->FileAlignment;
1612
35.1k
    if (a->FileAlignment > a->SectionAlignment)
1613
20.6k
      a->FileAlignment = a->SectionAlignment;
1614
35.1k
  }
1615
1616
53.4k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1617
29.7k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1618
53.4k
    }
1619
1620
76.6k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1621
76.6k
             (opt_hdr_size != 0
1622
76.6k
        ? &internal_a
1623
76.6k
        : (struct internal_aouthdr *) NULL));
1624
1625
76.6k
  if (result)
1626
35.4k
    {
1627
      /* Now the whole header has been processed, see if there is a build-id */
1628
35.4k
      pe_bfd_read_buildid(abfd);
1629
35.4k
    }
1630
1631
76.6k
  return result;
1632
78.3k
}
pei-arm-wince.c:pe_bfd_object_p
Line
Count
Source
1482
5.56M
{
1483
5.56M
  bfd_byte buffer[6];
1484
5.56M
  struct external_DOS_hdr dos_hdr;
1485
5.56M
  struct external_PEI_IMAGE_hdr image_hdr;
1486
5.56M
  struct internal_filehdr internal_f;
1487
5.56M
  struct internal_aouthdr internal_a;
1488
5.56M
  bfd_size_type opt_hdr_size;
1489
5.56M
  file_ptr offset;
1490
5.56M
  bfd_cleanup result;
1491
1492
  /* Detect if this a Microsoft Import Library Format element.  */
1493
  /* First read the beginning of the header.  */
1494
5.56M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1495
5.56M
      || bfd_read (buffer, 6, abfd) != 6)
1496
12.4k
    {
1497
12.4k
      if (bfd_get_error () != bfd_error_system_call)
1498
10.8k
  bfd_set_error (bfd_error_wrong_format);
1499
12.4k
      return NULL;
1500
12.4k
    }
1501
1502
  /* Then check the magic and the version (only 0 is supported).  */
1503
5.55M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1504
5.55M
      && H_GET_16 (abfd, buffer + 4) == 0)
1505
66.3k
    return pe_ILF_object_p (abfd);
1506
1507
5.48M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1508
5.48M
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1509
1.54M
    {
1510
1.54M
      if (bfd_get_error () != bfd_error_system_call)
1511
1.54M
  bfd_set_error (bfd_error_wrong_format);
1512
1.54M
      return NULL;
1513
1.54M
    }
1514
1515
  /* There are really two magic numbers involved; the magic number
1516
     that says this is a NT executable (PEI) and the magic number that
1517
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1518
     the e_magic field.  The latter is stored in the f_magic field.
1519
     If the NT magic number isn't valid, the architecture magic number
1520
     could be mimicked by some other field (specifically, the number
1521
     of relocs in section 3).  Since this routine can only be called
1522
     correctly for a PEI file, check the e_magic number here, and, if
1523
     it doesn't match, clobber the f_magic number so that we don't get
1524
     a false match.  */
1525
3.93M
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1526
3.05M
    {
1527
3.05M
      bfd_set_error (bfd_error_wrong_format);
1528
3.05M
      return NULL;
1529
3.05M
    }
1530
1531
882k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1532
882k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1533
882k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1534
2.35k
    {
1535
2.35k
      if (bfd_get_error () != bfd_error_system_call)
1536
2.35k
  bfd_set_error (bfd_error_wrong_format);
1537
2.35k
      return NULL;
1538
2.35k
    }
1539
1540
879k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1541
11.8k
    {
1542
11.8k
      bfd_set_error (bfd_error_wrong_format);
1543
11.8k
      return NULL;
1544
11.8k
    }
1545
1546
  /* Swap file header, so that we get the location for calling
1547
     real_object_p.  */
1548
867k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1549
1550
867k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1551
867k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1552
725k
    {
1553
725k
      bfd_set_error (bfd_error_wrong_format);
1554
725k
      return NULL;
1555
725k
    }
1556
1557
142k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1558
142k
    sizeof (internal_f.pe.dos_message));
1559
1560
  /* Read the optional header, which has variable size.  */
1561
142k
  opt_hdr_size = internal_f.f_opthdr;
1562
1563
142k
  if (opt_hdr_size != 0)
1564
76.1k
    {
1565
76.1k
      bfd_size_type amt = opt_hdr_size;
1566
76.1k
      bfd_byte *opthdr;
1567
1568
      /* PR 17521 file: 230-131433-0.004.  */
1569
76.1k
      if (amt < sizeof (PEAOUTHDR))
1570
67.5k
  amt = sizeof (PEAOUTHDR);
1571
1572
76.1k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1573
76.1k
      if (opthdr == NULL)
1574
2.39k
  return NULL;
1575
73.8k
      if (amt > opt_hdr_size)
1576
65.8k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1577
1578
73.8k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1579
1580
73.8k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1581
1582
73.8k
#ifdef ARM
1583
      /* Use Subsystem to distinguish between pei-arm-little and
1584
   pei-arm-wince-little.  */
1585
73.8k
#ifdef WINCE
1586
73.8k
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1587
#else
1588
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1589
#endif
1590
49.8k
  {
1591
49.8k
    bfd_set_error (bfd_error_wrong_format);
1592
49.8k
    return NULL;
1593
49.8k
  }
1594
23.9k
#endif
1595
1596
23.9k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1597
23.9k
    || a->SectionAlignment >= 0x80000000)
1598
14.0k
  {
1599
14.0k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1600
14.0k
            abfd);
1601
14.0k
    a->SectionAlignment &= -a->SectionAlignment;
1602
14.0k
    if (a->SectionAlignment >= 0x80000000)
1603
855
      a->SectionAlignment = 0x40000000;
1604
14.0k
  }
1605
1606
23.9k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1607
23.9k
    || a->FileAlignment > a->SectionAlignment)
1608
20.4k
  {
1609
20.4k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1610
20.4k
            abfd);
1611
20.4k
    a->FileAlignment &= -a->FileAlignment;
1612
20.4k
    if (a->FileAlignment > a->SectionAlignment)
1613
12.6k
      a->FileAlignment = a->SectionAlignment;
1614
20.4k
  }
1615
1616
23.9k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1617
20.9k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1618
23.9k
    }
1619
1620
90.0k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1621
90.0k
             (opt_hdr_size != 0
1622
90.0k
        ? &internal_a
1623
90.0k
        : (struct internal_aouthdr *) NULL));
1624
1625
90.0k
  if (result)
1626
17.0k
    {
1627
      /* Now the whole header has been processed, see if there is a build-id */
1628
17.0k
      pe_bfd_read_buildid(abfd);
1629
17.0k
    }
1630
1631
90.0k
  return result;
1632
142k
}
pei-arm.c:pe_bfd_object_p
Line
Count
Source
1482
5.56M
{
1483
5.56M
  bfd_byte buffer[6];
1484
5.56M
  struct external_DOS_hdr dos_hdr;
1485
5.56M
  struct external_PEI_IMAGE_hdr image_hdr;
1486
5.56M
  struct internal_filehdr internal_f;
1487
5.56M
  struct internal_aouthdr internal_a;
1488
5.56M
  bfd_size_type opt_hdr_size;
1489
5.56M
  file_ptr offset;
1490
5.56M
  bfd_cleanup result;
1491
1492
  /* Detect if this a Microsoft Import Library Format element.  */
1493
  /* First read the beginning of the header.  */
1494
5.56M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1495
5.56M
      || bfd_read (buffer, 6, abfd) != 6)
1496
12.4k
    {
1497
12.4k
      if (bfd_get_error () != bfd_error_system_call)
1498
10.8k
  bfd_set_error (bfd_error_wrong_format);
1499
12.4k
      return NULL;
1500
12.4k
    }
1501
1502
  /* Then check the magic and the version (only 0 is supported).  */
1503
5.55M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1504
5.55M
      && H_GET_16 (abfd, buffer + 4) == 0)
1505
79.5k
    return pe_ILF_object_p (abfd);
1506
1507
5.47M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1508
5.47M
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1509
1.54M
    {
1510
1.54M
      if (bfd_get_error () != bfd_error_system_call)
1511
1.54M
  bfd_set_error (bfd_error_wrong_format);
1512
1.54M
      return NULL;
1513
1.54M
    }
1514
1515
  /* There are really two magic numbers involved; the magic number
1516
     that says this is a NT executable (PEI) and the magic number that
1517
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1518
     the e_magic field.  The latter is stored in the f_magic field.
1519
     If the NT magic number isn't valid, the architecture magic number
1520
     could be mimicked by some other field (specifically, the number
1521
     of relocs in section 3).  Since this routine can only be called
1522
     correctly for a PEI file, check the e_magic number here, and, if
1523
     it doesn't match, clobber the f_magic number so that we don't get
1524
     a false match.  */
1525
3.92M
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1526
3.04M
    {
1527
3.04M
      bfd_set_error (bfd_error_wrong_format);
1528
3.04M
      return NULL;
1529
3.04M
    }
1530
1531
882k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1532
882k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1533
882k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1534
2.35k
    {
1535
2.35k
      if (bfd_get_error () != bfd_error_system_call)
1536
2.35k
  bfd_set_error (bfd_error_wrong_format);
1537
2.35k
      return NULL;
1538
2.35k
    }
1539
1540
879k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1541
11.8k
    {
1542
11.8k
      bfd_set_error (bfd_error_wrong_format);
1543
11.8k
      return NULL;
1544
11.8k
    }
1545
1546
  /* Swap file header, so that we get the location for calling
1547
     real_object_p.  */
1548
867k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1549
1550
867k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1551
867k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1552
725k
    {
1553
725k
      bfd_set_error (bfd_error_wrong_format);
1554
725k
      return NULL;
1555
725k
    }
1556
1557
142k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1558
142k
    sizeof (internal_f.pe.dos_message));
1559
1560
  /* Read the optional header, which has variable size.  */
1561
142k
  opt_hdr_size = internal_f.f_opthdr;
1562
1563
142k
  if (opt_hdr_size != 0)
1564
76.2k
    {
1565
76.2k
      bfd_size_type amt = opt_hdr_size;
1566
76.2k
      bfd_byte *opthdr;
1567
1568
      /* PR 17521 file: 230-131433-0.004.  */
1569
76.2k
      if (amt < sizeof (PEAOUTHDR))
1570
67.5k
  amt = sizeof (PEAOUTHDR);
1571
1572
76.2k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1573
76.2k
      if (opthdr == NULL)
1574
2.39k
  return NULL;
1575
73.8k
      if (amt > opt_hdr_size)
1576
65.8k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1577
1578
73.8k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1579
1580
73.8k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1581
1582
73.8k
#ifdef ARM
1583
      /* Use Subsystem to distinguish between pei-arm-little and
1584
   pei-arm-wince-little.  */
1585
#ifdef WINCE
1586
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1587
#else
1588
73.8k
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1589
23.8k
#endif
1590
23.8k
  {
1591
23.8k
    bfd_set_error (bfd_error_wrong_format);
1592
23.8k
    return NULL;
1593
23.8k
  }
1594
50.0k
#endif
1595
1596
50.0k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1597
50.0k
    || a->SectionAlignment >= 0x80000000)
1598
27.1k
  {
1599
27.1k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1600
27.1k
            abfd);
1601
27.1k
    a->SectionAlignment &= -a->SectionAlignment;
1602
27.1k
    if (a->SectionAlignment >= 0x80000000)
1603
480
      a->SectionAlignment = 0x40000000;
1604
27.1k
  }
1605
1606
50.0k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1607
50.0k
    || a->FileAlignment > a->SectionAlignment)
1608
36.7k
  {
1609
36.7k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1610
36.7k
            abfd);
1611
36.7k
    a->FileAlignment &= -a->FileAlignment;
1612
36.7k
    if (a->FileAlignment > a->SectionAlignment)
1613
23.1k
      a->FileAlignment = a->SectionAlignment;
1614
36.7k
  }
1615
1616
50.0k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1617
26.3k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1618
50.0k
    }
1619
1620
116k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1621
116k
             (opt_hdr_size != 0
1622
116k
        ? &internal_a
1623
116k
        : (struct internal_aouthdr *) NULL));
1624
1625
116k
  if (result)
1626
29.0k
    {
1627
      /* Now the whole header has been processed, see if there is a build-id */
1628
29.0k
      pe_bfd_read_buildid(abfd);
1629
29.0k
    }
1630
1631
116k
  return result;
1632
142k
}
pei-mcore.c:pe_bfd_object_p
Line
Count
Source
1482
5.56M
{
1483
5.56M
  bfd_byte buffer[6];
1484
5.56M
  struct external_DOS_hdr dos_hdr;
1485
5.56M
  struct external_PEI_IMAGE_hdr image_hdr;
1486
5.56M
  struct internal_filehdr internal_f;
1487
5.56M
  struct internal_aouthdr internal_a;
1488
5.56M
  bfd_size_type opt_hdr_size;
1489
5.56M
  file_ptr offset;
1490
5.56M
  bfd_cleanup result;
1491
1492
  /* Detect if this a Microsoft Import Library Format element.  */
1493
  /* First read the beginning of the header.  */
1494
5.56M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1495
5.56M
      || bfd_read (buffer, 6, abfd) != 6)
1496
12.4k
    {
1497
12.4k
      if (bfd_get_error () != bfd_error_system_call)
1498
10.8k
  bfd_set_error (bfd_error_wrong_format);
1499
12.4k
      return NULL;
1500
12.4k
    }
1501
1502
  /* Then check the magic and the version (only 0 is supported).  */
1503
5.55M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1504
5.55M
      && H_GET_16 (abfd, buffer + 4) == 0)
1505
57.3k
    return pe_ILF_object_p (abfd);
1506
1507
5.49M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1508
5.49M
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1509
1.54M
    {
1510
1.54M
      if (bfd_get_error () != bfd_error_system_call)
1511
1.54M
  bfd_set_error (bfd_error_wrong_format);
1512
1.54M
      return NULL;
1513
1.54M
    }
1514
1515
  /* There are really two magic numbers involved; the magic number
1516
     that says this is a NT executable (PEI) and the magic number that
1517
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1518
     the e_magic field.  The latter is stored in the f_magic field.
1519
     If the NT magic number isn't valid, the architecture magic number
1520
     could be mimicked by some other field (specifically, the number
1521
     of relocs in section 3).  Since this routine can only be called
1522
     correctly for a PEI file, check the e_magic number here, and, if
1523
     it doesn't match, clobber the f_magic number so that we don't get
1524
     a false match.  */
1525
3.94M
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1526
3.06M
    {
1527
3.06M
      bfd_set_error (bfd_error_wrong_format);
1528
3.06M
      return NULL;
1529
3.06M
    }
1530
1531
881k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1532
881k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1533
881k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1534
2.06k
    {
1535
2.06k
      if (bfd_get_error () != bfd_error_system_call)
1536
2.06k
  bfd_set_error (bfd_error_wrong_format);
1537
2.06k
      return NULL;
1538
2.06k
    }
1539
1540
879k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1541
11.4k
    {
1542
11.4k
      bfd_set_error (bfd_error_wrong_format);
1543
11.4k
      return NULL;
1544
11.4k
    }
1545
1546
  /* Swap file header, so that we get the location for calling
1547
     real_object_p.  */
1548
867k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1549
1550
867k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1551
867k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1552
788k
    {
1553
788k
      bfd_set_error (bfd_error_wrong_format);
1554
788k
      return NULL;
1555
788k
    }
1556
1557
78.9k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1558
78.9k
    sizeof (internal_f.pe.dos_message));
1559
1560
  /* Read the optional header, which has variable size.  */
1561
78.9k
  opt_hdr_size = internal_f.f_opthdr;
1562
1563
78.9k
  if (opt_hdr_size != 0)
1564
47.6k
    {
1565
47.6k
      bfd_size_type amt = opt_hdr_size;
1566
47.6k
      bfd_byte *opthdr;
1567
1568
      /* PR 17521 file: 230-131433-0.004.  */
1569
47.6k
      if (amt < sizeof (PEAOUTHDR))
1570
41.8k
  amt = sizeof (PEAOUTHDR);
1571
1572
47.6k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1573
47.6k
      if (opthdr == NULL)
1574
2.05k
  return NULL;
1575
45.6k
      if (amt > opt_hdr_size)
1576
40.6k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1577
1578
45.6k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1579
1580
45.6k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1581
1582
#ifdef ARM
1583
      /* Use Subsystem to distinguish between pei-arm-little and
1584
   pei-arm-wince-little.  */
1585
#ifdef WINCE
1586
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1587
#else
1588
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1589
#endif
1590
  {
1591
    bfd_set_error (bfd_error_wrong_format);
1592
    return NULL;
1593
  }
1594
#endif
1595
1596
45.6k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1597
45.6k
    || a->SectionAlignment >= 0x80000000)
1598
27.8k
  {
1599
27.8k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1600
27.8k
            abfd);
1601
27.8k
    a->SectionAlignment &= -a->SectionAlignment;
1602
27.8k
    if (a->SectionAlignment >= 0x80000000)
1603
1.16k
      a->SectionAlignment = 0x40000000;
1604
27.8k
  }
1605
1606
45.6k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1607
45.6k
    || a->FileAlignment > a->SectionAlignment)
1608
37.3k
  {
1609
37.3k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1610
37.3k
            abfd);
1611
37.3k
    a->FileAlignment &= -a->FileAlignment;
1612
37.3k
    if (a->FileAlignment > a->SectionAlignment)
1613
24.6k
      a->FileAlignment = a->SectionAlignment;
1614
37.3k
  }
1615
1616
45.6k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1617
23.4k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1618
45.6k
    }
1619
1620
76.9k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1621
76.9k
             (opt_hdr_size != 0
1622
76.9k
        ? &internal_a
1623
76.9k
        : (struct internal_aouthdr *) NULL));
1624
1625
76.9k
  if (result)
1626
35.0k
    {
1627
      /* Now the whole header has been processed, see if there is a build-id */
1628
35.0k
      pe_bfd_read_buildid(abfd);
1629
35.0k
    }
1630
1631
76.9k
  return result;
1632
78.9k
}
pei-sh.c:pe_bfd_object_p
Line
Count
Source
1482
2.78M
{
1483
2.78M
  bfd_byte buffer[6];
1484
2.78M
  struct external_DOS_hdr dos_hdr;
1485
2.78M
  struct external_PEI_IMAGE_hdr image_hdr;
1486
2.78M
  struct internal_filehdr internal_f;
1487
2.78M
  struct internal_aouthdr internal_a;
1488
2.78M
  bfd_size_type opt_hdr_size;
1489
2.78M
  file_ptr offset;
1490
2.78M
  bfd_cleanup result;
1491
1492
  /* Detect if this a Microsoft Import Library Format element.  */
1493
  /* First read the beginning of the header.  */
1494
2.78M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1495
2.78M
      || bfd_read (buffer, 6, abfd) != 6)
1496
6.23k
    {
1497
6.23k
      if (bfd_get_error () != bfd_error_system_call)
1498
5.41k
  bfd_set_error (bfd_error_wrong_format);
1499
6.23k
      return NULL;
1500
6.23k
    }
1501
1502
  /* Then check the magic and the version (only 0 is supported).  */
1503
2.77M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1504
2.77M
      && H_GET_16 (abfd, buffer + 4) == 0)
1505
49.9k
    return pe_ILF_object_p (abfd);
1506
1507
2.72M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1508
2.72M
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1509
747k
    {
1510
747k
      if (bfd_get_error () != bfd_error_system_call)
1511
747k
  bfd_set_error (bfd_error_wrong_format);
1512
747k
      return NULL;
1513
747k
    }
1514
1515
  /* There are really two magic numbers involved; the magic number
1516
     that says this is a NT executable (PEI) and the magic number that
1517
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1518
     the e_magic field.  The latter is stored in the f_magic field.
1519
     If the NT magic number isn't valid, the architecture magic number
1520
     could be mimicked by some other field (specifically, the number
1521
     of relocs in section 3).  Since this routine can only be called
1522
     correctly for a PEI file, check the e_magic number here, and, if
1523
     it doesn't match, clobber the f_magic number so that we don't get
1524
     a false match.  */
1525
1.97M
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1526
1.09M
    {
1527
1.09M
      bfd_set_error (bfd_error_wrong_format);
1528
1.09M
      return NULL;
1529
1.09M
    }
1530
1531
881k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1532
881k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1533
881k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1534
2.05k
    {
1535
2.05k
      if (bfd_get_error () != bfd_error_system_call)
1536
2.05k
  bfd_set_error (bfd_error_wrong_format);
1537
2.05k
      return NULL;
1538
2.05k
    }
1539
1540
879k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1541
11.3k
    {
1542
11.3k
      bfd_set_error (bfd_error_wrong_format);
1543
11.3k
      return NULL;
1544
11.3k
    }
1545
1546
  /* Swap file header, so that we get the location for calling
1547
     real_object_p.  */
1548
867k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1549
1550
867k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1551
867k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1552
787k
    {
1553
787k
      bfd_set_error (bfd_error_wrong_format);
1554
787k
      return NULL;
1555
787k
    }
1556
1557
80.6k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1558
80.6k
    sizeof (internal_f.pe.dos_message));
1559
1560
  /* Read the optional header, which has variable size.  */
1561
80.6k
  opt_hdr_size = internal_f.f_opthdr;
1562
1563
80.6k
  if (opt_hdr_size != 0)
1564
47.4k
    {
1565
47.4k
      bfd_size_type amt = opt_hdr_size;
1566
47.4k
      bfd_byte *opthdr;
1567
1568
      /* PR 17521 file: 230-131433-0.004.  */
1569
47.4k
      if (amt < sizeof (PEAOUTHDR))
1570
42.7k
  amt = sizeof (PEAOUTHDR);
1571
1572
47.4k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1573
47.4k
      if (opthdr == NULL)
1574
2.77k
  return NULL;
1575
44.7k
      if (amt > opt_hdr_size)
1576
41.6k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1577
1578
44.7k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1579
1580
44.7k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1581
1582
#ifdef ARM
1583
      /* Use Subsystem to distinguish between pei-arm-little and
1584
   pei-arm-wince-little.  */
1585
#ifdef WINCE
1586
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1587
#else
1588
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1589
#endif
1590
  {
1591
    bfd_set_error (bfd_error_wrong_format);
1592
    return NULL;
1593
  }
1594
#endif
1595
1596
44.7k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1597
44.7k
    || a->SectionAlignment >= 0x80000000)
1598
23.1k
  {
1599
23.1k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1600
23.1k
            abfd);
1601
23.1k
    a->SectionAlignment &= -a->SectionAlignment;
1602
23.1k
    if (a->SectionAlignment >= 0x80000000)
1603
722
      a->SectionAlignment = 0x40000000;
1604
23.1k
  }
1605
1606
44.7k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1607
44.7k
    || a->FileAlignment > a->SectionAlignment)
1608
33.3k
  {
1609
33.3k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1610
33.3k
            abfd);
1611
33.3k
    a->FileAlignment &= -a->FileAlignment;
1612
33.3k
    if (a->FileAlignment > a->SectionAlignment)
1613
22.4k
      a->FileAlignment = a->SectionAlignment;
1614
33.3k
  }
1615
1616
44.7k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1617
26.0k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1618
44.7k
    }
1619
1620
77.9k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1621
77.9k
             (opt_hdr_size != 0
1622
77.9k
        ? &internal_a
1623
77.9k
        : (struct internal_aouthdr *) NULL));
1624
1625
77.9k
  if (result)
1626
32.8k
    {
1627
      /* Now the whole header has been processed, see if there is a build-id */
1628
32.8k
      pe_bfd_read_buildid(abfd);
1629
32.8k
    }
1630
1631
77.9k
  return result;
1632
80.6k
}
1633
1634
852k
#define coff_object_p pe_bfd_object_p
1635
#endif /* COFF_IMAGE_WITH_PE */