Coverage Report

Created: 2025-06-24 06:45

/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
333k
{
132
333k
  RELOC *reloc_src = (RELOC *) src;
133
333k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
333k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
333k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
333k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
#ifdef SWAP_IN_RELOC_OFFSET
139
122k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
#endif
141
333k
}
pei-i386.c:coff_swap_reloc_in
Line
Count
Source
131
27.5k
{
132
27.5k
  RELOC *reloc_src = (RELOC *) src;
133
27.5k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
27.5k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
27.5k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
27.5k
  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
27.5k
}
pe-x86_64.c:coff_swap_reloc_in
Line
Count
Source
131
39.4k
{
132
39.4k
  RELOC *reloc_src = (RELOC *) src;
133
39.4k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
39.4k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
39.4k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
39.4k
  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
39.4k
}
pei-x86_64.c:coff_swap_reloc_in
Line
Count
Source
131
26.5k
{
132
26.5k
  RELOC *reloc_src = (RELOC *) src;
133
26.5k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
26.5k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
26.5k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
26.5k
  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
26.5k
}
pe-aarch64.c:coff_swap_reloc_in
Line
Count
Source
131
14.5k
{
132
14.5k
  RELOC *reloc_src = (RELOC *) src;
133
14.5k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
14.5k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
14.5k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
14.5k
  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
14.5k
}
pei-aarch64.c:coff_swap_reloc_in
Line
Count
Source
131
38.1k
{
132
38.1k
  RELOC *reloc_src = (RELOC *) src;
133
38.1k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
38.1k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
38.1k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
38.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
38.1k
}
pei-ia64.c:coff_swap_reloc_in
Line
Count
Source
131
16.0k
{
132
16.0k
  RELOC *reloc_src = (RELOC *) src;
133
16.0k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
16.0k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
16.0k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
16.0k
  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.0k
}
pei-loongarch64.c:coff_swap_reloc_in
Line
Count
Source
131
17.2k
{
132
17.2k
  RELOC *reloc_src = (RELOC *) src;
133
17.2k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
17.2k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
17.2k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
17.2k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
17.2k
#ifdef SWAP_IN_RELOC_OFFSET
139
17.2k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
17.2k
#endif
141
17.2k
}
pei-riscv64.c:coff_swap_reloc_in
Line
Count
Source
131
15.4k
{
132
15.4k
  RELOC *reloc_src = (RELOC *) src;
133
15.4k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
15.4k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
15.4k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
15.4k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
15.4k
#ifdef SWAP_IN_RELOC_OFFSET
139
15.4k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
15.4k
#endif
141
15.4k
}
pe-arm-wince.c:coff_swap_reloc_in
Line
Count
Source
131
6.76k
{
132
6.76k
  RELOC *reloc_src = (RELOC *) src;
133
6.76k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
6.76k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
6.76k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
6.76k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
6.76k
#ifdef SWAP_IN_RELOC_OFFSET
139
6.76k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
6.76k
#endif
141
6.76k
}
pe-arm.c:coff_swap_reloc_in
Line
Count
Source
131
6.76k
{
132
6.76k
  RELOC *reloc_src = (RELOC *) src;
133
6.76k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
6.76k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
6.76k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
6.76k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
6.76k
#ifdef SWAP_IN_RELOC_OFFSET
139
6.76k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
6.76k
#endif
141
6.76k
}
pe-i386.c:coff_swap_reloc_in
Line
Count
Source
131
13.6k
{
132
13.6k
  RELOC *reloc_src = (RELOC *) src;
133
13.6k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
13.6k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
13.6k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
13.6k
  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
13.6k
}
pe-mcore.c:coff_swap_reloc_in
Line
Count
Source
131
13.2k
{
132
13.2k
  RELOC *reloc_src = (RELOC *) src;
133
13.2k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
13.2k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
13.2k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
13.2k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
13.2k
#ifdef SWAP_IN_RELOC_OFFSET
139
13.2k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
13.2k
#endif
141
13.2k
}
pe-sh.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
#ifdef SWAP_IN_RELOC_OFFSET
139
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
#endif
141
13.5k
}
pei-arm-wince.c:coff_swap_reloc_in
Line
Count
Source
131
20.2k
{
132
20.2k
  RELOC *reloc_src = (RELOC *) src;
133
20.2k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
20.2k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
20.2k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
20.2k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
20.2k
#ifdef SWAP_IN_RELOC_OFFSET
139
20.2k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
20.2k
#endif
141
20.2k
}
pei-arm.c:coff_swap_reloc_in
Line
Count
Source
131
23.4k
{
132
23.4k
  RELOC *reloc_src = (RELOC *) src;
133
23.4k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
23.4k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
23.4k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
23.4k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
23.4k
#ifdef SWAP_IN_RELOC_OFFSET
139
23.4k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
23.4k
#endif
141
23.4k
}
pei-mcore.c:coff_swap_reloc_in
Line
Count
Source
131
19.0k
{
132
19.0k
  RELOC *reloc_src = (RELOC *) src;
133
19.0k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
19.0k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
19.0k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
19.0k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
19.0k
#ifdef SWAP_IN_RELOC_OFFSET
139
19.0k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
19.0k
#endif
141
19.0k
}
pei-sh.c:coff_swap_reloc_in
Line
Count
Source
131
21.7k
{
132
21.7k
  RELOC *reloc_src = (RELOC *) src;
133
21.7k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
21.7k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
21.7k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
21.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
21.7k
}
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
10.7M
#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
44.4M
{
171
44.4M
  FILHDR *filehdr_src = (FILHDR *) src;
172
44.4M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
44.4M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
44.4M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
44.4M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
44.4M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
44.4M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
44.4M
  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
44.4M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
4.08M
    {
185
4.08M
      filehdr_dst->f_nsyms = 0;
186
4.08M
      filehdr_dst->f_flags |= F_LSYMS;
187
4.08M
    }
188
189
44.4M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
44.4M
}
pei-i386.c:coff_swap_filehdr_in
Line
Count
Source
170
1.11M
{
171
1.11M
  FILHDR *filehdr_src = (FILHDR *) src;
172
1.11M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
1.11M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
1.11M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
1.11M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
1.11M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
1.11M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
1.11M
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
1.11M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
58.5k
    {
185
58.5k
      filehdr_dst->f_nsyms = 0;
186
58.5k
      filehdr_dst->f_flags |= F_LSYMS;
187
58.5k
    }
188
189
1.11M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
1.11M
}
pe-x86_64.c:coff_swap_filehdr_in
Line
Count
Source
170
3.42M
{
171
3.42M
  FILHDR *filehdr_src = (FILHDR *) src;
172
3.42M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
3.42M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
3.42M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
3.42M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
3.42M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
3.42M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
3.42M
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
3.42M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
355k
    {
185
355k
      filehdr_dst->f_nsyms = 0;
186
355k
      filehdr_dst->f_flags |= F_LSYMS;
187
355k
    }
188
189
3.42M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
3.42M
}
pei-x86_64.c:coff_swap_filehdr_in
Line
Count
Source
170
1.11M
{
171
1.11M
  FILHDR *filehdr_src = (FILHDR *) src;
172
1.11M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
1.11M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
1.11M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
1.11M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
1.11M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
1.11M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
1.11M
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
1.11M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
61.4k
    {
185
61.4k
      filehdr_dst->f_nsyms = 0;
186
61.4k
      filehdr_dst->f_flags |= F_LSYMS;
187
61.4k
    }
188
189
1.11M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
1.11M
}
pe-aarch64.c:coff_swap_filehdr_in
Line
Count
Source
170
3.36M
{
171
3.36M
  FILHDR *filehdr_src = (FILHDR *) src;
172
3.36M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
3.36M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
3.36M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
3.36M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
3.36M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
3.36M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
3.36M
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
3.36M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
354k
    {
185
354k
      filehdr_dst->f_nsyms = 0;
186
354k
      filehdr_dst->f_flags |= F_LSYMS;
187
354k
    }
188
189
3.36M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
3.36M
}
pei-aarch64.c:coff_swap_filehdr_in
Line
Count
Source
170
1.07M
{
171
1.07M
  FILHDR *filehdr_src = (FILHDR *) src;
172
1.07M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
1.07M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
1.07M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
1.07M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
1.07M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
1.07M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
1.07M
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
1.07M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
55.7k
    {
185
55.7k
      filehdr_dst->f_nsyms = 0;
186
55.7k
      filehdr_dst->f_flags |= F_LSYMS;
187
55.7k
    }
188
189
1.07M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
1.07M
}
pei-ia64.c:coff_swap_filehdr_in
Line
Count
Source
170
1.04M
{
171
1.04M
  FILHDR *filehdr_src = (FILHDR *) src;
172
1.04M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
1.04M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
1.04M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
1.04M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
1.04M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
1.04M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
1.04M
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
1.04M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
52.4k
    {
185
52.4k
      filehdr_dst->f_nsyms = 0;
186
52.4k
      filehdr_dst->f_flags |= F_LSYMS;
187
52.4k
    }
188
189
1.04M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
1.04M
}
pei-loongarch64.c:coff_swap_filehdr_in
Line
Count
Source
170
1.07M
{
171
1.07M
  FILHDR *filehdr_src = (FILHDR *) src;
172
1.07M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
1.07M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
1.07M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
1.07M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
1.07M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
1.07M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
1.07M
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
1.07M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
55.6k
    {
185
55.6k
      filehdr_dst->f_nsyms = 0;
186
55.6k
      filehdr_dst->f_flags |= F_LSYMS;
187
55.6k
    }
188
189
1.07M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
1.07M
}
pei-riscv64.c:coff_swap_filehdr_in
Line
Count
Source
170
1.07M
{
171
1.07M
  FILHDR *filehdr_src = (FILHDR *) src;
172
1.07M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
1.07M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
1.07M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
1.07M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
1.07M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
1.07M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
1.07M
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
1.07M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
55.5k
    {
185
55.5k
      filehdr_dst->f_nsyms = 0;
186
55.5k
      filehdr_dst->f_flags |= F_LSYMS;
187
55.5k
    }
188
189
1.07M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
1.07M
}
pe-arm-wince.c:coff_swap_filehdr_in
Line
Count
Source
170
6.70M
{
171
6.70M
  FILHDR *filehdr_src = (FILHDR *) src;
172
6.70M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
6.70M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
6.70M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
6.70M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
6.70M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
6.70M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
6.70M
  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
6.70M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
704k
    {
185
704k
      filehdr_dst->f_nsyms = 0;
186
704k
      filehdr_dst->f_flags |= F_LSYMS;
187
704k
    }
188
189
6.70M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
6.70M
}
pe-arm.c:coff_swap_filehdr_in
Line
Count
Source
170
6.70M
{
171
6.70M
  FILHDR *filehdr_src = (FILHDR *) src;
172
6.70M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
6.70M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
6.70M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
6.70M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
6.70M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
6.70M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
6.70M
  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
6.70M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
704k
    {
185
704k
      filehdr_dst->f_nsyms = 0;
186
704k
      filehdr_dst->f_flags |= F_LSYMS;
187
704k
    }
188
189
6.70M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
6.70M
}
pe-i386.c:coff_swap_filehdr_in
Line
Count
Source
170
3.36M
{
171
3.36M
  FILHDR *filehdr_src = (FILHDR *) src;
172
3.36M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
3.36M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
3.36M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
3.36M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
3.36M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
3.36M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
3.36M
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
3.36M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
353k
    {
185
353k
      filehdr_dst->f_nsyms = 0;
186
353k
      filehdr_dst->f_flags |= F_LSYMS;
187
353k
    }
188
189
3.36M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
3.36M
}
pe-mcore.c:coff_swap_filehdr_in
Line
Count
Source
170
6.70M
{
171
6.70M
  FILHDR *filehdr_src = (FILHDR *) src;
172
6.70M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
6.70M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
6.70M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
6.70M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
6.70M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
6.70M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
6.70M
  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
6.70M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
699k
    {
185
699k
      filehdr_dst->f_nsyms = 0;
186
699k
      filehdr_dst->f_flags |= F_LSYMS;
187
699k
    }
188
189
6.70M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
6.70M
}
pe-sh.c:coff_swap_filehdr_in
Line
Count
Source
170
3.35M
{
171
3.35M
  FILHDR *filehdr_src = (FILHDR *) src;
172
3.35M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
3.35M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
3.35M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
3.35M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
3.35M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
3.35M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
3.35M
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
3.35M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
349k
    {
185
349k
      filehdr_dst->f_nsyms = 0;
186
349k
      filehdr_dst->f_flags |= F_LSYMS;
187
349k
    }
188
189
3.35M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
3.35M
}
pei-arm-wince.c:coff_swap_filehdr_in
Line
Count
Source
170
1.06M
{
171
1.06M
  FILHDR *filehdr_src = (FILHDR *) src;
172
1.06M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
1.06M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
1.06M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
1.06M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
1.06M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
1.06M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
1.06M
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
1.06M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
55.6k
    {
185
55.6k
      filehdr_dst->f_nsyms = 0;
186
55.6k
      filehdr_dst->f_flags |= F_LSYMS;
187
55.6k
    }
188
189
1.06M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
1.06M
}
pei-arm.c:coff_swap_filehdr_in
Line
Count
Source
170
1.06M
{
171
1.06M
  FILHDR *filehdr_src = (FILHDR *) src;
172
1.06M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
1.06M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
1.06M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
1.06M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
1.06M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
1.06M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
1.06M
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
1.06M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
55.6k
    {
185
55.6k
      filehdr_dst->f_nsyms = 0;
186
55.6k
      filehdr_dst->f_flags |= F_LSYMS;
187
55.6k
    }
188
189
1.06M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
1.06M
}
pei-mcore.c:coff_swap_filehdr_in
Line
Count
Source
170
1.06M
{
171
1.06M
  FILHDR *filehdr_src = (FILHDR *) src;
172
1.06M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
1.06M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
1.06M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
1.06M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
1.06M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
1.06M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
1.06M
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
1.06M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
55.5k
    {
185
55.5k
      filehdr_dst->f_nsyms = 0;
186
55.5k
      filehdr_dst->f_flags |= F_LSYMS;
187
55.5k
    }
188
189
1.06M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
1.06M
}
pei-sh.c:coff_swap_filehdr_in
Line
Count
Source
170
1.06M
{
171
1.06M
  FILHDR *filehdr_src = (FILHDR *) src;
172
1.06M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
1.06M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
1.06M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
1.06M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
1.06M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
1.06M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
1.06M
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
1.06M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
55.6k
    {
185
55.6k
      filehdr_dst->f_nsyms = 0;
186
55.6k
      filehdr_dst->f_flags |= F_LSYMS;
187
55.6k
    }
188
189
1.06M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
1.06M
}
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
5.51M
{
207
5.51M
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
5.51M
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
5.51M
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
5.51M
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
5.51M
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
5.51M
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
5.51M
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
5.51M
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
5.51M
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
5.51M
  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
3.29M
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
3.29M
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
  scnhdr_int->s_nreloc = 0;
227
#else
228
2.22M
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
2.22M
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
#endif
231
232
5.51M
  if (scnhdr_int->s_vaddr != 0)
233
3.45M
    {
234
3.45M
      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
3.45M
    }
241
242
5.51M
#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
5.51M
  if (scnhdr_int->s_paddr > 0
248
5.51M
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
249
3.56M
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
250
3.56M
    || (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
1.17M
    scnhdr_int->s_size = scnhdr_int->s_paddr;
256
5.51M
#endif
257
5.51M
}
pei-i386.c:coff_swap_scnhdr_in
Line
Count
Source
206
452k
{
207
452k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
452k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
452k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
452k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
452k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
452k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
452k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
452k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
452k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
452k
  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
452k
#ifdef COFF_IMAGE_WITH_PE
224
452k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
452k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
452k
  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
452k
  if (scnhdr_int->s_vaddr != 0)
233
308k
    {
234
308k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
308k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
237
308k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
238
308k
      scnhdr_int->s_vaddr &= 0xffffffff;
239
308k
#endif
240
308k
    }
241
242
452k
#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
452k
  if (scnhdr_int->s_paddr > 0
248
452k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
249
337k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
250
337k
    || (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
115k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
256
452k
#endif
257
452k
}
pe-x86_64.c:coff_swap_scnhdr_in
Line
Count
Source
206
1.19M
{
207
1.19M
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
1.19M
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
1.19M
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
1.19M
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
1.19M
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
1.19M
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
1.19M
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
1.19M
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
1.19M
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
1.19M
  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
1.19M
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
1.19M
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
1.19M
#endif
231
232
1.19M
  if (scnhdr_int->s_vaddr != 0)
233
453k
    {
234
453k
      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
453k
    }
241
242
1.19M
#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
1.19M
  if (scnhdr_int->s_paddr > 0
248
1.19M
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
249
454k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
250
454k
    || (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
61.9k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
256
1.19M
#endif
257
1.19M
}
pei-x86_64.c:coff_swap_scnhdr_in
Line
Count
Source
206
433k
{
207
433k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
433k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
433k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
433k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
433k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
433k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
433k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
433k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
433k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
433k
  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
433k
#ifdef COFF_IMAGE_WITH_PE
224
433k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
433k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
433k
  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
433k
  if (scnhdr_int->s_vaddr != 0)
233
312k
    {
234
312k
      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
312k
    }
241
242
433k
#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
433k
  if (scnhdr_int->s_paddr > 0
248
433k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
249
294k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
250
294k
    || (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
132k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
256
433k
#endif
257
433k
}
pe-aarch64.c:coff_swap_scnhdr_in
Line
Count
Source
206
276k
{
207
276k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
276k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
276k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
276k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
276k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
276k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
276k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
276k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
276k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
276k
  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
276k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
276k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
276k
#endif
231
232
276k
  if (scnhdr_int->s_vaddr != 0)
233
134k
    {
234
134k
      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
134k
    }
241
242
276k
#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
276k
  if (scnhdr_int->s_paddr > 0
248
276k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
249
136k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
250
136k
    || (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
18.9k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
256
276k
#endif
257
276k
}
pei-aarch64.c:coff_swap_scnhdr_in
Line
Count
Source
206
364k
{
207
364k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
364k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
364k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
364k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
364k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
364k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
364k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
364k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
364k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
364k
  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
364k
#ifdef COFF_IMAGE_WITH_PE
224
364k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
364k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
364k
  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
364k
  if (scnhdr_int->s_vaddr != 0)
233
266k
    {
234
266k
      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
266k
    }
241
242
364k
#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
364k
  if (scnhdr_int->s_paddr > 0
248
364k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
249
266k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
250
266k
    || (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
108k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
256
364k
#endif
257
364k
}
pei-ia64.c:coff_swap_scnhdr_in
Line
Count
Source
206
310k
{
207
310k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
310k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
310k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
310k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
310k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
310k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
310k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
310k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
310k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
310k
  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
310k
#ifdef COFF_IMAGE_WITH_PE
224
310k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
310k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
310k
  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
310k
  if (scnhdr_int->s_vaddr != 0)
233
222k
    {
234
222k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
222k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
237
222k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
238
222k
      scnhdr_int->s_vaddr &= 0xffffffff;
239
222k
#endif
240
222k
    }
241
242
310k
#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
310k
  if (scnhdr_int->s_paddr > 0
248
310k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
249
237k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
250
237k
    || (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
98.0k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
256
310k
#endif
257
310k
}
pei-loongarch64.c:coff_swap_scnhdr_in
Line
Count
Source
206
307k
{
207
307k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
307k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
307k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
307k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
307k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
307k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
307k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
307k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
307k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
307k
  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
307k
#ifdef COFF_IMAGE_WITH_PE
224
307k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
307k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
307k
  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
307k
  if (scnhdr_int->s_vaddr != 0)
233
208k
    {
234
208k
      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
208k
    }
241
242
307k
#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
307k
  if (scnhdr_int->s_paddr > 0
248
307k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
249
220k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
250
220k
    || (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
98.9k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
256
307k
#endif
257
307k
}
pei-riscv64.c:coff_swap_scnhdr_in
Line
Count
Source
206
274k
{
207
274k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
274k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
274k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
274k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
274k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
274k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
274k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
274k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
274k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
274k
  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
274k
#ifdef COFF_IMAGE_WITH_PE
224
274k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
274k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
274k
  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
274k
  if (scnhdr_int->s_vaddr != 0)
233
174k
    {
234
174k
      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
174k
    }
241
242
274k
#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
274k
  if (scnhdr_int->s_paddr > 0
248
274k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
249
180k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
250
180k
    || (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
66.0k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
256
274k
#endif
257
274k
}
pe-arm-wince.c:coff_swap_scnhdr_in
Line
Count
Source
206
86.7k
{
207
86.7k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
86.7k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
86.7k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
86.7k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
86.7k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
86.7k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
86.7k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
86.7k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
86.7k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
86.7k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
#ifdef COFF_IMAGE_WITH_PE
224
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
  scnhdr_int->s_nreloc = 0;
227
#else
228
86.7k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
86.7k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
86.7k
#endif
231
232
86.7k
  if (scnhdr_int->s_vaddr != 0)
233
65.4k
    {
234
65.4k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
65.4k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
237
65.4k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
238
65.4k
      scnhdr_int->s_vaddr &= 0xffffffff;
239
65.4k
#endif
240
65.4k
    }
241
242
86.7k
#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
86.7k
  if (scnhdr_int->s_paddr > 0
248
86.7k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
249
64.7k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
250
64.7k
    || (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
15.4k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
256
86.7k
#endif
257
86.7k
}
pe-arm.c:coff_swap_scnhdr_in
Line
Count
Source
206
86.7k
{
207
86.7k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
86.7k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
86.7k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
86.7k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
86.7k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
86.7k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
86.7k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
86.7k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
86.7k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
86.7k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
#ifdef COFF_IMAGE_WITH_PE
224
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
  scnhdr_int->s_nreloc = 0;
227
#else
228
86.7k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
86.7k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
86.7k
#endif
231
232
86.7k
  if (scnhdr_int->s_vaddr != 0)
233
65.4k
    {
234
65.4k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
65.4k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
237
65.4k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
238
65.4k
      scnhdr_int->s_vaddr &= 0xffffffff;
239
65.4k
#endif
240
65.4k
    }
241
242
86.7k
#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
86.7k
  if (scnhdr_int->s_paddr > 0
248
86.7k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
249
64.7k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
250
64.7k
    || (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
15.4k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
256
86.7k
#endif
257
86.7k
}
pe-i386.c:coff_swap_scnhdr_in
Line
Count
Source
206
193k
{
207
193k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
193k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
193k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
193k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
193k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
193k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
193k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
193k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
193k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
193k
  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
193k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
193k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
193k
#endif
231
232
193k
  if (scnhdr_int->s_vaddr != 0)
233
138k
    {
234
138k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
138k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
237
138k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
238
138k
      scnhdr_int->s_vaddr &= 0xffffffff;
239
138k
#endif
240
138k
    }
241
242
193k
#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
193k
  if (scnhdr_int->s_paddr > 0
248
193k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
249
143k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
250
143k
    || (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
26.6k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
256
193k
#endif
257
193k
}
pe-mcore.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
#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
218k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
218k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
218k
#endif
231
232
218k
  if (scnhdr_int->s_vaddr != 0)
233
158k
    {
234
158k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
158k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
237
158k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
238
158k
      scnhdr_int->s_vaddr &= 0xffffffff;
239
158k
#endif
240
158k
    }
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
165k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
250
165k
    || (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
33.9k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
256
218k
#endif
257
218k
}
pe-sh.c:coff_swap_scnhdr_in
Line
Count
Source
206
164k
{
207
164k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
164k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
164k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
164k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
164k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
164k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
164k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
164k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
164k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
164k
  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
164k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
164k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
164k
#endif
231
232
164k
  if (scnhdr_int->s_vaddr != 0)
233
109k
    {
234
109k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
109k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
237
109k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
238
109k
      scnhdr_int->s_vaddr &= 0xffffffff;
239
109k
#endif
240
109k
    }
241
242
164k
#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
164k
  if (scnhdr_int->s_paddr > 0
248
164k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
249
110k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
250
110k
    || (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
23.8k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
256
164k
#endif
257
164k
}
pei-arm-wince.c:coff_swap_scnhdr_in
Line
Count
Source
206
268k
{
207
268k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
268k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
268k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
268k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
268k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
268k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
268k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
268k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
268k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
268k
  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
268k
#ifdef COFF_IMAGE_WITH_PE
224
268k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
268k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
268k
  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
268k
  if (scnhdr_int->s_vaddr != 0)
233
196k
    {
234
196k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
196k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
237
196k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
238
196k
      scnhdr_int->s_vaddr &= 0xffffffff;
239
196k
#endif
240
196k
    }
241
242
268k
#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
268k
  if (scnhdr_int->s_paddr > 0
248
268k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
249
207k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
250
207k
    || (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
84.8k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
256
268k
#endif
257
268k
}
pei-arm.c:coff_swap_scnhdr_in
Line
Count
Source
206
333k
{
207
333k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
333k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
333k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
333k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
333k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
333k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
333k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
333k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
333k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
333k
  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
333k
#ifdef COFF_IMAGE_WITH_PE
224
333k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
333k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
333k
  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
333k
  if (scnhdr_int->s_vaddr != 0)
233
246k
    {
234
246k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
246k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
237
246k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
238
246k
      scnhdr_int->s_vaddr &= 0xffffffff;
239
246k
#endif
240
246k
    }
241
242
333k
#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
333k
  if (scnhdr_int->s_paddr > 0
248
333k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
249
260k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
250
260k
    || (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
103k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
256
333k
#endif
257
333k
}
pei-mcore.c:coff_swap_scnhdr_in
Line
Count
Source
206
261k
{
207
261k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
261k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
261k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
261k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
261k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
261k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
261k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
261k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
261k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
261k
  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
261k
#ifdef COFF_IMAGE_WITH_PE
224
261k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
261k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
261k
  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
261k
  if (scnhdr_int->s_vaddr != 0)
233
190k
    {
234
190k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
190k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
237
190k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
238
190k
      scnhdr_int->s_vaddr &= 0xffffffff;
239
190k
#endif
240
190k
    }
241
242
261k
#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
261k
  if (scnhdr_int->s_paddr > 0
248
261k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
249
197k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
250
197k
    || (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
76.4k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
256
261k
#endif
257
261k
}
pei-sh.c:coff_swap_scnhdr_in
Line
Count
Source
206
285k
{
207
285k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
285k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
285k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
285k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
285k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
285k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
285k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
285k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
285k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
285k
  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
285k
#ifdef COFF_IMAGE_WITH_PE
224
285k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
285k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
285k
  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
285k
  if (scnhdr_int->s_vaddr != 0)
233
207k
    {
234
207k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
207k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
237
207k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
238
207k
      scnhdr_int->s_vaddr &= 0xffffffff;
239
207k
#endif
240
207k
    }
241
242
285k
#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
285k
  if (scnhdr_int->s_paddr > 0
248
285k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
249
222k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
250
222k
    || (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
93.4k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
256
285k
#endif
257
285k
}
258
259
static bool
260
pe_mkobject (bfd *abfd)
261
1.90M
{
262
  /* Some x86 code followed by an ascii string.  */
263
1.90M
  static const char default_dos_message[64] = {
264
1.90M
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
265
1.90M
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
266
1.90M
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
267
1.90M
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
268
1.90M
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
269
1.90M
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
270
1.90M
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
271
1.90M
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
272
273
1.90M
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
274
1.90M
  abfd->tdata.pe_obj_data = pe;
275
1.90M
  if (pe == NULL)
276
0
    return false;
277
278
1.90M
  pe->coff.pe = 1;
279
280
  /* in_reloc_p is architecture dependent.  */
281
1.90M
  pe->in_reloc_p = in_reloc_p;
282
283
1.90M
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
284
285
1.90M
  bfd_coff_long_section_names (abfd)
286
1.90M
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
287
288
1.90M
  return true;
289
1.90M
}
pei-i386.c:pe_mkobject
Line
Count
Source
261
167k
{
262
  /* Some x86 code followed by an ascii string.  */
263
167k
  static const char default_dos_message[64] = {
264
167k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
265
167k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
266
167k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
267
167k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
268
167k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
269
167k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
270
167k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
271
167k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
272
273
167k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
274
167k
  abfd->tdata.pe_obj_data = pe;
275
167k
  if (pe == NULL)
276
0
    return false;
277
278
167k
  pe->coff.pe = 1;
279
280
  /* in_reloc_p is architecture dependent.  */
281
167k
  pe->in_reloc_p = in_reloc_p;
282
283
167k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
284
285
167k
  bfd_coff_long_section_names (abfd)
286
167k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
287
288
167k
  return true;
289
167k
}
pe-x86_64.c:pe_mkobject
Line
Count
Source
261
279k
{
262
  /* Some x86 code followed by an ascii string.  */
263
279k
  static const char default_dos_message[64] = {
264
279k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
265
279k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
266
279k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
267
279k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
268
279k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
269
279k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
270
279k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
271
279k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
272
273
279k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
274
279k
  abfd->tdata.pe_obj_data = pe;
275
279k
  if (pe == NULL)
276
0
    return false;
277
278
279k
  pe->coff.pe = 1;
279
280
  /* in_reloc_p is architecture dependent.  */
281
279k
  pe->in_reloc_p = in_reloc_p;
282
283
279k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
284
285
279k
  bfd_coff_long_section_names (abfd)
286
279k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
287
288
279k
  return true;
289
279k
}
pei-x86_64.c:pe_mkobject
Line
Count
Source
261
177k
{
262
  /* Some x86 code followed by an ascii string.  */
263
177k
  static const char default_dos_message[64] = {
264
177k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
265
177k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
266
177k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
267
177k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
268
177k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
269
177k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
270
177k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
271
177k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
272
273
177k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
274
177k
  abfd->tdata.pe_obj_data = pe;
275
177k
  if (pe == NULL)
276
0
    return false;
277
278
177k
  pe->coff.pe = 1;
279
280
  /* in_reloc_p is architecture dependent.  */
281
177k
  pe->in_reloc_p = in_reloc_p;
282
283
177k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
284
285
177k
  bfd_coff_long_section_names (abfd)
286
177k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
287
288
177k
  return true;
289
177k
}
pe-aarch64.c:pe_mkobject
Line
Count
Source
261
69.3k
{
262
  /* Some x86 code followed by an ascii string.  */
263
69.3k
  static const char default_dos_message[64] = {
264
69.3k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
265
69.3k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
266
69.3k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
267
69.3k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
268
69.3k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
269
69.3k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
270
69.3k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
271
69.3k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
272
273
69.3k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
274
69.3k
  abfd->tdata.pe_obj_data = pe;
275
69.3k
  if (pe == NULL)
276
0
    return false;
277
278
69.3k
  pe->coff.pe = 1;
279
280
  /* in_reloc_p is architecture dependent.  */
281
69.3k
  pe->in_reloc_p = in_reloc_p;
282
283
69.3k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
284
285
69.3k
  bfd_coff_long_section_names (abfd)
286
69.3k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
287
288
69.3k
  return true;
289
69.3k
}
pei-aarch64.c:pe_mkobject
Line
Count
Source
261
119k
{
262
  /* Some x86 code followed by an ascii string.  */
263
119k
  static const char default_dos_message[64] = {
264
119k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
265
119k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
266
119k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
267
119k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
268
119k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
269
119k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
270
119k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
271
119k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
272
273
119k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
274
119k
  abfd->tdata.pe_obj_data = pe;
275
119k
  if (pe == NULL)
276
0
    return false;
277
278
119k
  pe->coff.pe = 1;
279
280
  /* in_reloc_p is architecture dependent.  */
281
119k
  pe->in_reloc_p = in_reloc_p;
282
283
119k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
284
285
119k
  bfd_coff_long_section_names (abfd)
286
119k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
287
288
119k
  return true;
289
119k
}
pei-ia64.c:pe_mkobject
Line
Count
Source
261
123k
{
262
  /* Some x86 code followed by an ascii string.  */
263
123k
  static const char default_dos_message[64] = {
264
123k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
265
123k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
266
123k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
267
123k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
268
123k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
269
123k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
270
123k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
271
123k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
272
273
123k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
274
123k
  abfd->tdata.pe_obj_data = pe;
275
123k
  if (pe == NULL)
276
0
    return false;
277
278
123k
  pe->coff.pe = 1;
279
280
  /* in_reloc_p is architecture dependent.  */
281
123k
  pe->in_reloc_p = in_reloc_p;
282
283
123k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
284
285
123k
  bfd_coff_long_section_names (abfd)
286
123k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
287
288
123k
  return true;
289
123k
}
pei-loongarch64.c:pe_mkobject
Line
Count
Source
261
106k
{
262
  /* Some x86 code followed by an ascii string.  */
263
106k
  static const char default_dos_message[64] = {
264
106k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
265
106k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
266
106k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
267
106k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
268
106k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
269
106k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
270
106k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
271
106k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
272
273
106k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
274
106k
  abfd->tdata.pe_obj_data = pe;
275
106k
  if (pe == NULL)
276
0
    return false;
277
278
106k
  pe->coff.pe = 1;
279
280
  /* in_reloc_p is architecture dependent.  */
281
106k
  pe->in_reloc_p = in_reloc_p;
282
283
106k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
284
285
106k
  bfd_coff_long_section_names (abfd)
286
106k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
287
288
106k
  return true;
289
106k
}
pei-riscv64.c:pe_mkobject
Line
Count
Source
261
98.9k
{
262
  /* Some x86 code followed by an ascii string.  */
263
98.9k
  static const char default_dos_message[64] = {
264
98.9k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
265
98.9k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
266
98.9k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
267
98.9k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
268
98.9k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
269
98.9k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
270
98.9k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
271
98.9k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
272
273
98.9k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
274
98.9k
  abfd->tdata.pe_obj_data = pe;
275
98.9k
  if (pe == NULL)
276
0
    return false;
277
278
98.9k
  pe->coff.pe = 1;
279
280
  /* in_reloc_p is architecture dependent.  */
281
98.9k
  pe->in_reloc_p = in_reloc_p;
282
283
98.9k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
284
285
98.9k
  bfd_coff_long_section_names (abfd)
286
98.9k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
287
288
98.9k
  return true;
289
98.9k
}
pe-arm-wince.c:pe_mkobject
Line
Count
Source
261
36.0k
{
262
  /* Some x86 code followed by an ascii string.  */
263
36.0k
  static const char default_dos_message[64] = {
264
36.0k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
265
36.0k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
266
36.0k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
267
36.0k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
268
36.0k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
269
36.0k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
270
36.0k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
271
36.0k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
272
273
36.0k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
274
36.0k
  abfd->tdata.pe_obj_data = pe;
275
36.0k
  if (pe == NULL)
276
0
    return false;
277
278
36.0k
  pe->coff.pe = 1;
279
280
  /* in_reloc_p is architecture dependent.  */
281
36.0k
  pe->in_reloc_p = in_reloc_p;
282
283
36.0k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
284
285
36.0k
  bfd_coff_long_section_names (abfd)
286
36.0k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
287
288
36.0k
  return true;
289
36.0k
}
pe-arm.c:pe_mkobject
Line
Count
Source
261
36.0k
{
262
  /* Some x86 code followed by an ascii string.  */
263
36.0k
  static const char default_dos_message[64] = {
264
36.0k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
265
36.0k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
266
36.0k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
267
36.0k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
268
36.0k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
269
36.0k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
270
36.0k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
271
36.0k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
272
273
36.0k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
274
36.0k
  abfd->tdata.pe_obj_data = pe;
275
36.0k
  if (pe == NULL)
276
0
    return false;
277
278
36.0k
  pe->coff.pe = 1;
279
280
  /* in_reloc_p is architecture dependent.  */
281
36.0k
  pe->in_reloc_p = in_reloc_p;
282
283
36.0k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
284
285
36.0k
  bfd_coff_long_section_names (abfd)
286
36.0k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
287
288
36.0k
  return true;
289
36.0k
}
pe-i386.c:pe_mkobject
Line
Count
Source
261
91.4k
{
262
  /* Some x86 code followed by an ascii string.  */
263
91.4k
  static const char default_dos_message[64] = {
264
91.4k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
265
91.4k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
266
91.4k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
267
91.4k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
268
91.4k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
269
91.4k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
270
91.4k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
271
91.4k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
272
273
91.4k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
274
91.4k
  abfd->tdata.pe_obj_data = pe;
275
91.4k
  if (pe == NULL)
276
0
    return false;
277
278
91.4k
  pe->coff.pe = 1;
279
280
  /* in_reloc_p is architecture dependent.  */
281
91.4k
  pe->in_reloc_p = in_reloc_p;
282
283
91.4k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
284
285
91.4k
  bfd_coff_long_section_names (abfd)
286
91.4k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
287
288
91.4k
  return true;
289
91.4k
}
pe-mcore.c:pe_mkobject
Line
Count
Source
261
68.6k
{
262
  /* Some x86 code followed by an ascii string.  */
263
68.6k
  static const char default_dos_message[64] = {
264
68.6k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
265
68.6k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
266
68.6k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
267
68.6k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
268
68.6k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
269
68.6k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
270
68.6k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
271
68.6k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
272
273
68.6k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
274
68.6k
  abfd->tdata.pe_obj_data = pe;
275
68.6k
  if (pe == NULL)
276
0
    return false;
277
278
68.6k
  pe->coff.pe = 1;
279
280
  /* in_reloc_p is architecture dependent.  */
281
68.6k
  pe->in_reloc_p = in_reloc_p;
282
283
68.6k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
284
285
68.6k
  bfd_coff_long_section_names (abfd)
286
68.6k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
287
288
68.6k
  return true;
289
68.6k
}
pe-sh.c:pe_mkobject
Line
Count
Source
261
62.4k
{
262
  /* Some x86 code followed by an ascii string.  */
263
62.4k
  static const char default_dos_message[64] = {
264
62.4k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
265
62.4k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
266
62.4k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
267
62.4k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
268
62.4k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
269
62.4k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
270
62.4k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
271
62.4k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
272
273
62.4k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
274
62.4k
  abfd->tdata.pe_obj_data = pe;
275
62.4k
  if (pe == NULL)
276
0
    return false;
277
278
62.4k
  pe->coff.pe = 1;
279
280
  /* in_reloc_p is architecture dependent.  */
281
62.4k
  pe->in_reloc_p = in_reloc_p;
282
283
62.4k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
284
285
62.4k
  bfd_coff_long_section_names (abfd)
286
62.4k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
287
288
62.4k
  return true;
289
62.4k
}
pei-arm-wince.c:pe_mkobject
Line
Count
Source
261
112k
{
262
  /* Some x86 code followed by an ascii string.  */
263
112k
  static const char default_dos_message[64] = {
264
112k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
265
112k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
266
112k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
267
112k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
268
112k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
269
112k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
270
112k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
271
112k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
272
273
112k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
274
112k
  abfd->tdata.pe_obj_data = pe;
275
112k
  if (pe == NULL)
276
0
    return false;
277
278
112k
  pe->coff.pe = 1;
279
280
  /* in_reloc_p is architecture dependent.  */
281
112k
  pe->in_reloc_p = in_reloc_p;
282
283
112k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
284
285
112k
  bfd_coff_long_section_names (abfd)
286
112k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
287
288
112k
  return true;
289
112k
}
pei-arm.c:pe_mkobject
Line
Count
Source
261
158k
{
262
  /* Some x86 code followed by an ascii string.  */
263
158k
  static const char default_dos_message[64] = {
264
158k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
265
158k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
266
158k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
267
158k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
268
158k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
269
158k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
270
158k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
271
158k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
272
273
158k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
274
158k
  abfd->tdata.pe_obj_data = pe;
275
158k
  if (pe == NULL)
276
0
    return false;
277
278
158k
  pe->coff.pe = 1;
279
280
  /* in_reloc_p is architecture dependent.  */
281
158k
  pe->in_reloc_p = in_reloc_p;
282
283
158k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
284
285
158k
  bfd_coff_long_section_names (abfd)
286
158k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
287
288
158k
  return true;
289
158k
}
pei-mcore.c:pe_mkobject
Line
Count
Source
261
93.2k
{
262
  /* Some x86 code followed by an ascii string.  */
263
93.2k
  static const char default_dos_message[64] = {
264
93.2k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
265
93.2k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
266
93.2k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
267
93.2k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
268
93.2k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
269
93.2k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
270
93.2k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
271
93.2k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
272
273
93.2k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
274
93.2k
  abfd->tdata.pe_obj_data = pe;
275
93.2k
  if (pe == NULL)
276
0
    return false;
277
278
93.2k
  pe->coff.pe = 1;
279
280
  /* in_reloc_p is architecture dependent.  */
281
93.2k
  pe->in_reloc_p = in_reloc_p;
282
283
93.2k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
284
285
93.2k
  bfd_coff_long_section_names (abfd)
286
93.2k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
287
288
93.2k
  return true;
289
93.2k
}
pei-sh.c:pe_mkobject
Line
Count
Source
261
105k
{
262
  /* Some x86 code followed by an ascii string.  */
263
105k
  static const char default_dos_message[64] = {
264
105k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
265
105k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
266
105k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
267
105k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
268
105k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
269
105k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
270
105k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
271
105k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
272
273
105k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
274
105k
  abfd->tdata.pe_obj_data = pe;
275
105k
  if (pe == NULL)
276
0
    return false;
277
278
105k
  pe->coff.pe = 1;
279
280
  /* in_reloc_p is architecture dependent.  */
281
105k
  pe->in_reloc_p = in_reloc_p;
282
283
105k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
284
285
105k
  bfd_coff_long_section_names (abfd)
286
105k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
287
288
105k
  return true;
289
105k
}
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.90M
{
298
1.90M
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
299
1.90M
  pe_data_type *pe;
300
301
1.90M
  if (! pe_mkobject (abfd))
302
0
    return NULL;
303
304
1.90M
  pe = pe_data (abfd);
305
1.90M
  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.90M
  pe->coff.local_n_btmask = N_BTMASK;
310
1.90M
  pe->coff.local_n_btshft = N_BTSHFT;
311
1.90M
  pe->coff.local_n_tmask = N_TMASK;
312
1.90M
  pe->coff.local_n_tshift = N_TSHIFT;
313
1.90M
  pe->coff.local_symesz = SYMESZ;
314
1.90M
  pe->coff.local_auxesz = AUXESZ;
315
1.90M
  pe->coff.local_linesz = LINESZ;
316
317
1.90M
  pe->coff.timestamp = internal_f->f_timdat;
318
319
1.90M
  obj_raw_syment_count (abfd) =
320
1.90M
    obj_conv_table_size (abfd) =
321
1.90M
      internal_f->f_nsyms;
322
323
1.90M
  pe->real_flags = internal_f->f_flags;
324
325
1.90M
  if ((internal_f->f_flags & F_DLL) != 0)
326
653k
    pe->dll = 1;
327
328
1.90M
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
329
1.31M
    abfd->flags |= HAS_DEBUG;
330
331
#ifdef COFF_IMAGE_WITH_PE
332
1.26M
  if (aouthdr)
333
683k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
334
#endif
335
336
#ifdef ARM
337
343k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
338
0
    coff_data (abfd) ->flags = 0;
339
#endif
340
341
1.90M
  memcpy (pe->dos_message, internal_f->pe.dos_message,
342
1.90M
    sizeof (pe->dos_message));
343
344
1.90M
  return (void *) pe;
345
1.90M
}
pei-i386.c:pe_mkobject_hook
Line
Count
Source
297
167k
{
298
167k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
299
167k
  pe_data_type *pe;
300
301
167k
  if (! pe_mkobject (abfd))
302
0
    return NULL;
303
304
167k
  pe = pe_data (abfd);
305
167k
  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
167k
  pe->coff.local_n_btmask = N_BTMASK;
310
167k
  pe->coff.local_n_btshft = N_BTSHFT;
311
167k
  pe->coff.local_n_tmask = N_TMASK;
312
167k
  pe->coff.local_n_tshift = N_TSHIFT;
313
167k
  pe->coff.local_symesz = SYMESZ;
314
167k
  pe->coff.local_auxesz = AUXESZ;
315
167k
  pe->coff.local_linesz = LINESZ;
316
317
167k
  pe->coff.timestamp = internal_f->f_timdat;
318
319
167k
  obj_raw_syment_count (abfd) =
320
167k
    obj_conv_table_size (abfd) =
321
167k
      internal_f->f_nsyms;
322
323
167k
  pe->real_flags = internal_f->f_flags;
324
325
167k
  if ((internal_f->f_flags & F_DLL) != 0)
326
44.3k
    pe->dll = 1;
327
328
167k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
329
137k
    abfd->flags |= HAS_DEBUG;
330
331
167k
#ifdef COFF_IMAGE_WITH_PE
332
167k
  if (aouthdr)
333
110k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
334
167k
#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
167k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
342
167k
    sizeof (pe->dos_message));
343
344
167k
  return (void *) pe;
345
167k
}
pe-x86_64.c:pe_mkobject_hook
Line
Count
Source
297
279k
{
298
279k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
299
279k
  pe_data_type *pe;
300
301
279k
  if (! pe_mkobject (abfd))
302
0
    return NULL;
303
304
279k
  pe = pe_data (abfd);
305
279k
  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
279k
  pe->coff.local_n_btmask = N_BTMASK;
310
279k
  pe->coff.local_n_btshft = N_BTSHFT;
311
279k
  pe->coff.local_n_tmask = N_TMASK;
312
279k
  pe->coff.local_n_tshift = N_TSHIFT;
313
279k
  pe->coff.local_symesz = SYMESZ;
314
279k
  pe->coff.local_auxesz = AUXESZ;
315
279k
  pe->coff.local_linesz = LINESZ;
316
317
279k
  pe->coff.timestamp = internal_f->f_timdat;
318
319
279k
  obj_raw_syment_count (abfd) =
320
279k
    obj_conv_table_size (abfd) =
321
279k
      internal_f->f_nsyms;
322
323
279k
  pe->real_flags = internal_f->f_flags;
324
325
279k
  if ((internal_f->f_flags & F_DLL) != 0)
326
73.9k
    pe->dll = 1;
327
328
279k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
329
187k
    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
279k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
342
279k
    sizeof (pe->dos_message));
343
344
279k
  return (void *) pe;
345
279k
}
pei-x86_64.c:pe_mkobject_hook
Line
Count
Source
297
177k
{
298
177k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
299
177k
  pe_data_type *pe;
300
301
177k
  if (! pe_mkobject (abfd))
302
0
    return NULL;
303
304
177k
  pe = pe_data (abfd);
305
177k
  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
177k
  pe->coff.local_n_btmask = N_BTMASK;
310
177k
  pe->coff.local_n_btshft = N_BTSHFT;
311
177k
  pe->coff.local_n_tmask = N_TMASK;
312
177k
  pe->coff.local_n_tshift = N_TSHIFT;
313
177k
  pe->coff.local_symesz = SYMESZ;
314
177k
  pe->coff.local_auxesz = AUXESZ;
315
177k
  pe->coff.local_linesz = LINESZ;
316
317
177k
  pe->coff.timestamp = internal_f->f_timdat;
318
319
177k
  obj_raw_syment_count (abfd) =
320
177k
    obj_conv_table_size (abfd) =
321
177k
      internal_f->f_nsyms;
322
323
177k
  pe->real_flags = internal_f->f_flags;
324
325
177k
  if ((internal_f->f_flags & F_DLL) != 0)
326
49.1k
    pe->dll = 1;
327
328
177k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
329
135k
    abfd->flags |= HAS_DEBUG;
330
331
177k
#ifdef COFF_IMAGE_WITH_PE
332
177k
  if (aouthdr)
333
102k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
334
177k
#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
177k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
342
177k
    sizeof (pe->dos_message));
343
344
177k
  return (void *) pe;
345
177k
}
pe-aarch64.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
17.9k
    pe->dll = 1;
327
328
69.2k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
329
51.8k
    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
}
pei-aarch64.c:pe_mkobject_hook
Line
Count
Source
297
119k
{
298
119k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
299
119k
  pe_data_type *pe;
300
301
119k
  if (! pe_mkobject (abfd))
302
0
    return NULL;
303
304
119k
  pe = pe_data (abfd);
305
119k
  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
119k
  pe->coff.local_n_btmask = N_BTMASK;
310
119k
  pe->coff.local_n_btshft = N_BTSHFT;
311
119k
  pe->coff.local_n_tmask = N_TMASK;
312
119k
  pe->coff.local_n_tshift = N_TSHIFT;
313
119k
  pe->coff.local_symesz = SYMESZ;
314
119k
  pe->coff.local_auxesz = AUXESZ;
315
119k
  pe->coff.local_linesz = LINESZ;
316
317
119k
  pe->coff.timestamp = internal_f->f_timdat;
318
319
119k
  obj_raw_syment_count (abfd) =
320
119k
    obj_conv_table_size (abfd) =
321
119k
      internal_f->f_nsyms;
322
323
119k
  pe->real_flags = internal_f->f_flags;
324
325
119k
  if ((internal_f->f_flags & F_DLL) != 0)
326
38.8k
    pe->dll = 1;
327
328
119k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
329
94.0k
    abfd->flags |= HAS_DEBUG;
330
331
119k
#ifdef COFF_IMAGE_WITH_PE
332
119k
  if (aouthdr)
333
78.0k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
334
119k
#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
119k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
342
119k
    sizeof (pe->dos_message));
343
344
119k
  return (void *) pe;
345
119k
}
pei-ia64.c:pe_mkobject_hook
Line
Count
Source
297
123k
{
298
123k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
299
123k
  pe_data_type *pe;
300
301
123k
  if (! pe_mkobject (abfd))
302
0
    return NULL;
303
304
123k
  pe = pe_data (abfd);
305
123k
  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
123k
  pe->coff.local_n_btmask = N_BTMASK;
310
123k
  pe->coff.local_n_btshft = N_BTSHFT;
311
123k
  pe->coff.local_n_tmask = N_TMASK;
312
123k
  pe->coff.local_n_tshift = N_TSHIFT;
313
123k
  pe->coff.local_symesz = SYMESZ;
314
123k
  pe->coff.local_auxesz = AUXESZ;
315
123k
  pe->coff.local_linesz = LINESZ;
316
317
123k
  pe->coff.timestamp = internal_f->f_timdat;
318
319
123k
  obj_raw_syment_count (abfd) =
320
123k
    obj_conv_table_size (abfd) =
321
123k
      internal_f->f_nsyms;
322
323
123k
  pe->real_flags = internal_f->f_flags;
324
325
123k
  if ((internal_f->f_flags & F_DLL) != 0)
326
70.5k
    pe->dll = 1;
327
328
123k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
329
62.4k
    abfd->flags |= HAS_DEBUG;
330
331
123k
#ifdef COFF_IMAGE_WITH_PE
332
123k
  if (aouthdr)
333
70.9k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
334
123k
#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
123k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
342
123k
    sizeof (pe->dos_message));
343
344
123k
  return (void *) pe;
345
123k
}
pei-loongarch64.c:pe_mkobject_hook
Line
Count
Source
297
106k
{
298
106k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
299
106k
  pe_data_type *pe;
300
301
106k
  if (! pe_mkobject (abfd))
302
0
    return NULL;
303
304
106k
  pe = pe_data (abfd);
305
106k
  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
106k
  pe->coff.local_n_btmask = N_BTMASK;
310
106k
  pe->coff.local_n_btshft = N_BTSHFT;
311
106k
  pe->coff.local_n_tmask = N_TMASK;
312
106k
  pe->coff.local_n_tshift = N_TSHIFT;
313
106k
  pe->coff.local_symesz = SYMESZ;
314
106k
  pe->coff.local_auxesz = AUXESZ;
315
106k
  pe->coff.local_linesz = LINESZ;
316
317
106k
  pe->coff.timestamp = internal_f->f_timdat;
318
319
106k
  obj_raw_syment_count (abfd) =
320
106k
    obj_conv_table_size (abfd) =
321
106k
      internal_f->f_nsyms;
322
323
106k
  pe->real_flags = internal_f->f_flags;
324
325
106k
  if ((internal_f->f_flags & F_DLL) != 0)
326
22.7k
    pe->dll = 1;
327
328
106k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
329
82.1k
    abfd->flags |= HAS_DEBUG;
330
331
106k
#ifdef COFF_IMAGE_WITH_PE
332
106k
  if (aouthdr)
333
53.0k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
334
106k
#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
106k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
342
106k
    sizeof (pe->dos_message));
343
344
106k
  return (void *) pe;
345
106k
}
pei-riscv64.c:pe_mkobject_hook
Line
Count
Source
297
98.9k
{
298
98.9k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
299
98.9k
  pe_data_type *pe;
300
301
98.9k
  if (! pe_mkobject (abfd))
302
0
    return NULL;
303
304
98.9k
  pe = pe_data (abfd);
305
98.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
98.9k
  pe->coff.local_n_btmask = N_BTMASK;
310
98.9k
  pe->coff.local_n_btshft = N_BTSHFT;
311
98.9k
  pe->coff.local_n_tmask = N_TMASK;
312
98.9k
  pe->coff.local_n_tshift = N_TSHIFT;
313
98.9k
  pe->coff.local_symesz = SYMESZ;
314
98.9k
  pe->coff.local_auxesz = AUXESZ;
315
98.9k
  pe->coff.local_linesz = LINESZ;
316
317
98.9k
  pe->coff.timestamp = internal_f->f_timdat;
318
319
98.9k
  obj_raw_syment_count (abfd) =
320
98.9k
    obj_conv_table_size (abfd) =
321
98.9k
      internal_f->f_nsyms;
322
323
98.9k
  pe->real_flags = internal_f->f_flags;
324
325
98.9k
  if ((internal_f->f_flags & F_DLL) != 0)
326
38.1k
    pe->dll = 1;
327
328
98.9k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
329
67.2k
    abfd->flags |= HAS_DEBUG;
330
331
98.9k
#ifdef COFF_IMAGE_WITH_PE
332
98.9k
  if (aouthdr)
333
64.6k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
334
98.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
98.9k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
342
98.9k
    sizeof (pe->dos_message));
343
344
98.9k
  return (void *) pe;
345
98.9k
}
pe-arm-wince.c:pe_mkobject_hook
Line
Count
Source
297
36.0k
{
298
36.0k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
299
36.0k
  pe_data_type *pe;
300
301
36.0k
  if (! pe_mkobject (abfd))
302
0
    return NULL;
303
304
36.0k
  pe = pe_data (abfd);
305
36.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
36.0k
  pe->coff.local_n_btmask = N_BTMASK;
310
36.0k
  pe->coff.local_n_btshft = N_BTSHFT;
311
36.0k
  pe->coff.local_n_tmask = N_TMASK;
312
36.0k
  pe->coff.local_n_tshift = N_TSHIFT;
313
36.0k
  pe->coff.local_symesz = SYMESZ;
314
36.0k
  pe->coff.local_auxesz = AUXESZ;
315
36.0k
  pe->coff.local_linesz = LINESZ;
316
317
36.0k
  pe->coff.timestamp = internal_f->f_timdat;
318
319
36.0k
  obj_raw_syment_count (abfd) =
320
36.0k
    obj_conv_table_size (abfd) =
321
36.0k
      internal_f->f_nsyms;
322
323
36.0k
  pe->real_flags = internal_f->f_flags;
324
325
36.0k
  if ((internal_f->f_flags & F_DLL) != 0)
326
11.3k
    pe->dll = 1;
327
328
36.0k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
329
22.4k
    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
36.0k
#ifdef ARM
337
36.0k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
338
0
    coff_data (abfd) ->flags = 0;
339
36.0k
#endif
340
341
36.0k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
342
36.0k
    sizeof (pe->dos_message));
343
344
36.0k
  return (void *) pe;
345
36.0k
}
pe-arm.c:pe_mkobject_hook
Line
Count
Source
297
36.0k
{
298
36.0k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
299
36.0k
  pe_data_type *pe;
300
301
36.0k
  if (! pe_mkobject (abfd))
302
0
    return NULL;
303
304
36.0k
  pe = pe_data (abfd);
305
36.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
36.0k
  pe->coff.local_n_btmask = N_BTMASK;
310
36.0k
  pe->coff.local_n_btshft = N_BTSHFT;
311
36.0k
  pe->coff.local_n_tmask = N_TMASK;
312
36.0k
  pe->coff.local_n_tshift = N_TSHIFT;
313
36.0k
  pe->coff.local_symesz = SYMESZ;
314
36.0k
  pe->coff.local_auxesz = AUXESZ;
315
36.0k
  pe->coff.local_linesz = LINESZ;
316
317
36.0k
  pe->coff.timestamp = internal_f->f_timdat;
318
319
36.0k
  obj_raw_syment_count (abfd) =
320
36.0k
    obj_conv_table_size (abfd) =
321
36.0k
      internal_f->f_nsyms;
322
323
36.0k
  pe->real_flags = internal_f->f_flags;
324
325
36.0k
  if ((internal_f->f_flags & F_DLL) != 0)
326
11.3k
    pe->dll = 1;
327
328
36.0k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
329
22.4k
    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
36.0k
#ifdef ARM
337
36.0k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
338
0
    coff_data (abfd) ->flags = 0;
339
36.0k
#endif
340
341
36.0k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
342
36.0k
    sizeof (pe->dos_message));
343
344
36.0k
  return (void *) pe;
345
36.0k
}
pe-i386.c:pe_mkobject_hook
Line
Count
Source
297
91.3k
{
298
91.3k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
299
91.3k
  pe_data_type *pe;
300
301
91.3k
  if (! pe_mkobject (abfd))
302
0
    return NULL;
303
304
91.3k
  pe = pe_data (abfd);
305
91.3k
  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
91.3k
  pe->coff.local_n_btmask = N_BTMASK;
310
91.3k
  pe->coff.local_n_btshft = N_BTSHFT;
311
91.3k
  pe->coff.local_n_tmask = N_TMASK;
312
91.3k
  pe->coff.local_n_tshift = N_TSHIFT;
313
91.3k
  pe->coff.local_symesz = SYMESZ;
314
91.3k
  pe->coff.local_auxesz = AUXESZ;
315
91.3k
  pe->coff.local_linesz = LINESZ;
316
317
91.3k
  pe->coff.timestamp = internal_f->f_timdat;
318
319
91.3k
  obj_raw_syment_count (abfd) =
320
91.3k
    obj_conv_table_size (abfd) =
321
91.3k
      internal_f->f_nsyms;
322
323
91.3k
  pe->real_flags = internal_f->f_flags;
324
325
91.3k
  if ((internal_f->f_flags & F_DLL) != 0)
326
40.2k
    pe->dll = 1;
327
328
91.3k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
329
69.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
91.3k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
342
91.3k
    sizeof (pe->dos_message));
343
344
91.3k
  return (void *) pe;
345
91.3k
}
pe-mcore.c:pe_mkobject_hook
Line
Count
Source
297
68.5k
{
298
68.5k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
299
68.5k
  pe_data_type *pe;
300
301
68.5k
  if (! pe_mkobject (abfd))
302
0
    return NULL;
303
304
68.5k
  pe = pe_data (abfd);
305
68.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
68.5k
  pe->coff.local_n_btmask = N_BTMASK;
310
68.5k
  pe->coff.local_n_btshft = N_BTSHFT;
311
68.5k
  pe->coff.local_n_tmask = N_TMASK;
312
68.5k
  pe->coff.local_n_tshift = N_TSHIFT;
313
68.5k
  pe->coff.local_symesz = SYMESZ;
314
68.5k
  pe->coff.local_auxesz = AUXESZ;
315
68.5k
  pe->coff.local_linesz = LINESZ;
316
317
68.5k
  pe->coff.timestamp = internal_f->f_timdat;
318
319
68.5k
  obj_raw_syment_count (abfd) =
320
68.5k
    obj_conv_table_size (abfd) =
321
68.5k
      internal_f->f_nsyms;
322
323
68.5k
  pe->real_flags = internal_f->f_flags;
324
325
68.5k
  if ((internal_f->f_flags & F_DLL) != 0)
326
19.8k
    pe->dll = 1;
327
328
68.5k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
329
52.1k
    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
68.5k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
342
68.5k
    sizeof (pe->dos_message));
343
344
68.5k
  return (void *) pe;
345
68.5k
}
pe-sh.c:pe_mkobject_hook
Line
Count
Source
297
62.3k
{
298
62.3k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
299
62.3k
  pe_data_type *pe;
300
301
62.3k
  if (! pe_mkobject (abfd))
302
0
    return NULL;
303
304
62.3k
  pe = pe_data (abfd);
305
62.3k
  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.3k
  pe->coff.local_n_btmask = N_BTMASK;
310
62.3k
  pe->coff.local_n_btshft = N_BTSHFT;
311
62.3k
  pe->coff.local_n_tmask = N_TMASK;
312
62.3k
  pe->coff.local_n_tshift = N_TSHIFT;
313
62.3k
  pe->coff.local_symesz = SYMESZ;
314
62.3k
  pe->coff.local_auxesz = AUXESZ;
315
62.3k
  pe->coff.local_linesz = LINESZ;
316
317
62.3k
  pe->coff.timestamp = internal_f->f_timdat;
318
319
62.3k
  obj_raw_syment_count (abfd) =
320
62.3k
    obj_conv_table_size (abfd) =
321
62.3k
      internal_f->f_nsyms;
322
323
62.3k
  pe->real_flags = internal_f->f_flags;
324
325
62.3k
  if ((internal_f->f_flags & F_DLL) != 0)
326
28.0k
    pe->dll = 1;
327
328
62.3k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
329
46.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
62.3k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
342
62.3k
    sizeof (pe->dos_message));
343
344
62.3k
  return (void *) pe;
345
62.3k
}
pei-arm-wince.c:pe_mkobject_hook
Line
Count
Source
297
112k
{
298
112k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
299
112k
  pe_data_type *pe;
300
301
112k
  if (! pe_mkobject (abfd))
302
0
    return NULL;
303
304
112k
  pe = pe_data (abfd);
305
112k
  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
112k
  pe->coff.local_n_btmask = N_BTMASK;
310
112k
  pe->coff.local_n_btshft = N_BTSHFT;
311
112k
  pe->coff.local_n_tmask = N_TMASK;
312
112k
  pe->coff.local_n_tshift = N_TSHIFT;
313
112k
  pe->coff.local_symesz = SYMESZ;
314
112k
  pe->coff.local_auxesz = AUXESZ;
315
112k
  pe->coff.local_linesz = LINESZ;
316
317
112k
  pe->coff.timestamp = internal_f->f_timdat;
318
319
112k
  obj_raw_syment_count (abfd) =
320
112k
    obj_conv_table_size (abfd) =
321
112k
      internal_f->f_nsyms;
322
323
112k
  pe->real_flags = internal_f->f_flags;
324
325
112k
  if ((internal_f->f_flags & F_DLL) != 0)
326
46.3k
    pe->dll = 1;
327
328
112k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
329
64.3k
    abfd->flags |= HAS_DEBUG;
330
331
112k
#ifdef COFF_IMAGE_WITH_PE
332
112k
  if (aouthdr)
333
31.3k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
334
112k
#endif
335
336
112k
#ifdef ARM
337
112k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
338
0
    coff_data (abfd) ->flags = 0;
339
112k
#endif
340
341
112k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
342
112k
    sizeof (pe->dos_message));
343
344
112k
  return (void *) pe;
345
112k
}
pei-arm.c:pe_mkobject_hook
Line
Count
Source
297
158k
{
298
158k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
299
158k
  pe_data_type *pe;
300
301
158k
  if (! pe_mkobject (abfd))
302
0
    return NULL;
303
304
158k
  pe = pe_data (abfd);
305
158k
  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
158k
  pe->coff.local_n_btmask = N_BTMASK;
310
158k
  pe->coff.local_n_btshft = N_BTSHFT;
311
158k
  pe->coff.local_n_tmask = N_TMASK;
312
158k
  pe->coff.local_n_tshift = N_TSHIFT;
313
158k
  pe->coff.local_symesz = SYMESZ;
314
158k
  pe->coff.local_auxesz = AUXESZ;
315
158k
  pe->coff.local_linesz = LINESZ;
316
317
158k
  pe->coff.timestamp = internal_f->f_timdat;
318
319
158k
  obj_raw_syment_count (abfd) =
320
158k
    obj_conv_table_size (abfd) =
321
158k
      internal_f->f_nsyms;
322
323
158k
  pe->real_flags = internal_f->f_flags;
324
325
158k
  if ((internal_f->f_flags & F_DLL) != 0)
326
59.3k
    pe->dll = 1;
327
328
158k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
329
101k
    abfd->flags |= HAS_DEBUG;
330
331
158k
#ifdef COFF_IMAGE_WITH_PE
332
158k
  if (aouthdr)
333
61.0k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
334
158k
#endif
335
336
158k
#ifdef ARM
337
158k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
338
0
    coff_data (abfd) ->flags = 0;
339
158k
#endif
340
341
158k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
342
158k
    sizeof (pe->dos_message));
343
344
158k
  return (void *) pe;
345
158k
}
pei-mcore.c:pe_mkobject_hook
Line
Count
Source
297
93.2k
{
298
93.2k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
299
93.2k
  pe_data_type *pe;
300
301
93.2k
  if (! pe_mkobject (abfd))
302
0
    return NULL;
303
304
93.2k
  pe = pe_data (abfd);
305
93.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
93.2k
  pe->coff.local_n_btmask = N_BTMASK;
310
93.2k
  pe->coff.local_n_btshft = N_BTSHFT;
311
93.2k
  pe->coff.local_n_tmask = N_TMASK;
312
93.2k
  pe->coff.local_n_tshift = N_TSHIFT;
313
93.2k
  pe->coff.local_symesz = SYMESZ;
314
93.2k
  pe->coff.local_auxesz = AUXESZ;
315
93.2k
  pe->coff.local_linesz = LINESZ;
316
317
93.2k
  pe->coff.timestamp = internal_f->f_timdat;
318
319
93.2k
  obj_raw_syment_count (abfd) =
320
93.2k
    obj_conv_table_size (abfd) =
321
93.2k
      internal_f->f_nsyms;
322
323
93.2k
  pe->real_flags = internal_f->f_flags;
324
325
93.2k
  if ((internal_f->f_flags & F_DLL) != 0)
326
33.5k
    pe->dll = 1;
327
328
93.2k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
329
58.3k
    abfd->flags |= HAS_DEBUG;
330
331
93.2k
#ifdef COFF_IMAGE_WITH_PE
332
93.2k
  if (aouthdr)
333
56.5k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
334
93.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
93.2k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
342
93.2k
    sizeof (pe->dos_message));
343
344
93.2k
  return (void *) pe;
345
93.2k
}
pei-sh.c:pe_mkobject_hook
Line
Count
Source
297
105k
{
298
105k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
299
105k
  pe_data_type *pe;
300
301
105k
  if (! pe_mkobject (abfd))
302
0
    return NULL;
303
304
105k
  pe = pe_data (abfd);
305
105k
  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
105k
  pe->coff.local_n_btmask = N_BTMASK;
310
105k
  pe->coff.local_n_btshft = N_BTSHFT;
311
105k
  pe->coff.local_n_tmask = N_TMASK;
312
105k
  pe->coff.local_n_tshift = N_TSHIFT;
313
105k
  pe->coff.local_symesz = SYMESZ;
314
105k
  pe->coff.local_auxesz = AUXESZ;
315
105k
  pe->coff.local_linesz = LINESZ;
316
317
105k
  pe->coff.timestamp = internal_f->f_timdat;
318
319
105k
  obj_raw_syment_count (abfd) =
320
105k
    obj_conv_table_size (abfd) =
321
105k
      internal_f->f_nsyms;
322
323
105k
  pe->real_flags = internal_f->f_flags;
324
325
105k
  if ((internal_f->f_flags & F_DLL) != 0)
326
47.9k
    pe->dll = 1;
327
328
105k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
329
63.5k
    abfd->flags |= HAS_DEBUG;
330
331
105k
#ifdef COFF_IMAGE_WITH_PE
332
105k
  if (aouthdr)
333
55.3k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
334
105k
#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
105k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
342
105k
    sizeof (pe->dos_message));
343
344
105k
  return (void *) pe;
345
105k
}
346
347
static bool
348
pe_print_private_bfd_data (bfd *abfd, void *vfile)
349
10.0k
{
350
10.0k
  FILE *file = (FILE *) vfile;
351
352
10.0k
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
353
0
    return false;
354
355
10.0k
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
356
9.54k
    return true;
357
358
530
  fputc ('\n', file);
359
360
530
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
361
10.0k
}
pei-i386.c:pe_print_private_bfd_data
Line
Count
Source
349
526
{
350
526
  FILE *file = (FILE *) vfile;
351
352
526
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
353
0
    return false;
354
355
526
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
356
526
    return true;
357
358
0
  fputc ('\n', file);
359
360
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
361
526
}
pe-x86_64.c:pe_print_private_bfd_data
Line
Count
Source
349
1.06k
{
350
1.06k
  FILE *file = (FILE *) vfile;
351
352
1.06k
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
353
0
    return false;
354
355
1.06k
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
356
1.06k
    return true;
357
358
0
  fputc ('\n', file);
359
360
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
361
1.06k
}
pei-x86_64.c:pe_print_private_bfd_data
Line
Count
Source
349
829
{
350
829
  FILE *file = (FILE *) vfile;
351
352
829
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
353
0
    return false;
354
355
829
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
356
829
    return true;
357
358
0
  fputc ('\n', file);
359
360
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
361
829
}
pe-aarch64.c:pe_print_private_bfd_data
Line
Count
Source
349
738
{
350
738
  FILE *file = (FILE *) vfile;
351
352
738
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
353
0
    return false;
354
355
738
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
356
738
    return true;
357
358
0
  fputc ('\n', file);
359
360
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
361
738
}
pei-aarch64.c:pe_print_private_bfd_data
Line
Count
Source
349
2.93k
{
350
2.93k
  FILE *file = (FILE *) vfile;
351
352
2.93k
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
353
0
    return false;
354
355
2.93k
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
356
2.93k
    return true;
357
358
0
  fputc ('\n', file);
359
360
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
361
2.93k
}
pei-ia64.c:pe_print_private_bfd_data
Line
Count
Source
349
613
{
350
613
  FILE *file = (FILE *) vfile;
351
352
613
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
353
0
    return false;
354
355
613
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
356
613
    return true;
357
358
0
  fputc ('\n', file);
359
360
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
361
613
}
pei-loongarch64.c:pe_print_private_bfd_data
Line
Count
Source
349
651
{
350
651
  FILE *file = (FILE *) vfile;
351
352
651
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
353
0
    return false;
354
355
651
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
356
651
    return true;
357
358
0
  fputc ('\n', file);
359
360
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
361
651
}
pei-riscv64.c:pe_print_private_bfd_data
Line
Count
Source
349
647
{
350
647
  FILE *file = (FILE *) vfile;
351
352
647
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
353
0
    return false;
354
355
647
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
356
647
    return true;
357
358
0
  fputc ('\n', file);
359
360
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
361
647
}
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
226
{
350
226
  FILE *file = (FILE *) vfile;
351
352
226
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
353
0
    return false;
354
355
226
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
356
226
    return true;
357
358
0
  fputc ('\n', file);
359
360
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
361
226
}
pe-mcore.c:pe_print_private_bfd_data
Line
Count
Source
349
407
{
350
407
  FILE *file = (FILE *) vfile;
351
352
407
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
353
0
    return false;
354
355
407
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
356
407
    return true;
357
358
0
  fputc ('\n', file);
359
360
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
361
407
}
pe-sh.c:pe_print_private_bfd_data
Line
Count
Source
349
337
{
350
337
  FILE *file = (FILE *) vfile;
351
352
337
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
353
0
    return false;
354
355
337
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
356
337
    return true;
357
358
0
  fputc ('\n', file);
359
360
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
361
337
}
pei-arm-wince.c:pe_print_private_bfd_data
Line
Count
Source
349
180
{
350
180
  FILE *file = (FILE *) vfile;
351
352
180
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
353
0
    return false;
354
355
180
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
356
0
    return true;
357
358
180
  fputc ('\n', file);
359
360
180
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
361
180
}
pei-arm.c:pe_print_private_bfd_data
Line
Count
Source
349
350
{
350
350
  FILE *file = (FILE *) vfile;
351
352
350
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
353
0
    return false;
354
355
350
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
356
0
    return true;
357
358
350
  fputc ('\n', file);
359
360
350
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
361
350
}
pei-mcore.c:pe_print_private_bfd_data
Line
Count
Source
349
226
{
350
226
  FILE *file = (FILE *) vfile;
351
352
226
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
353
0
    return false;
354
355
226
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
356
226
    return true;
357
358
0
  fputc ('\n', file);
359
360
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
361
226
}
pei-sh.c:pe_print_private_bfd_data
Line
Count
Source
349
344
{
350
344
  FILE *file = (FILE *) vfile;
351
352
344
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
353
0
    return false;
354
355
344
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
356
344
    return true;
357
358
0
  fputc ('\n', file);
359
360
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
361
344
}
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
17
{
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
17
  if (pe_data (obfd) != NULL
373
17
      && pe_data (ibfd) != NULL
374
17
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
375
11
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
376
377
17
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
378
1
    return false;
379
380
16
  if (pe_saved_coff_bfd_copy_private_bfd_data)
381
1
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
382
383
15
  return true;
384
16
}
pei-i386.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
368
5
{
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
5
  if (pe_data (obfd) != NULL
373
5
      && pe_data (ibfd) != NULL
374
5
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
375
2
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
376
377
5
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
378
1
    return false;
379
380
4
  if (pe_saved_coff_bfd_copy_private_bfd_data)
381
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
382
383
4
  return true;
384
4
}
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
3
{
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
3
  if (pe_data (obfd) != NULL
373
3
      && pe_data (ibfd) != NULL
374
3
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
375
3
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
376
377
3
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
378
0
    return false;
379
380
3
  if (pe_saved_coff_bfd_copy_private_bfd_data)
381
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
382
383
3
  return true;
384
3
}
Unexecuted instantiation: pe-aarch64.c:pe_bfd_copy_private_bfd_data
pei-aarch64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
368
2
{
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
2
  if (pe_data (obfd) != NULL
373
2
      && pe_data (ibfd) != NULL
374
2
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
375
0
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
376
377
2
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
378
0
    return false;
379
380
2
  if (pe_saved_coff_bfd_copy_private_bfd_data)
381
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
382
383
2
  return true;
384
2
}
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
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
}
Unexecuted instantiation: pei-loongarch64.c:pe_bfd_copy_private_bfd_data
pei-riscv64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
368
5
{
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
5
  if (pe_data (obfd) != NULL
373
5
      && pe_data (ibfd) != NULL
374
5
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
375
5
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
376
377
5
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
378
0
    return false;
379
380
5
  if (pe_saved_coff_bfd_copy_private_bfd_data)
381
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
382
383
5
  return true;
384
5
}
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
Unexecuted instantiation: pei-sh.c:pe_bfd_copy_private_bfd_data
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
409k
#define NUM_ILF_RELOCS    8
419
1.36M
#define NUM_ILF_SECTIONS  6
420
1.02M
#define NUM_ILF_SYMS    (2 + NUM_ILF_SECTIONS)
421
422
204k
#define SIZEOF_ILF_SYMS    (NUM_ILF_SYMS * sizeof (*vars.sym_cache))
423
204k
#define SIZEOF_ILF_SYM_TABLE   (NUM_ILF_SYMS * sizeof (*vars.sym_table))
424
204k
#define SIZEOF_ILF_NATIVE_SYMS   (NUM_ILF_SYMS * sizeof (*vars.native_syms))
425
204k
#define SIZEOF_ILF_SYM_PTR_TABLE (NUM_ILF_SYMS * sizeof (*vars.sym_ptr_table))
426
204k
#define SIZEOF_ILF_EXT_SYMS  (NUM_ILF_SYMS * sizeof (*vars.esym_table))
427
204k
#define SIZEOF_ILF_RELOCS  (NUM_ILF_RELOCS * sizeof (*vars.reltab))
428
204k
#define SIZEOF_ILF_INT_RELOCS  (NUM_ILF_RELOCS * sizeof (*vars.int_reltab))
429
204k
#define SIZEOF_ILF_STRINGS   (strlen (symbol_name) * 2 + 8 \
430
204k
          + 21 + strlen (source_dll)   \
431
204k
          + NUM_ILF_SECTIONS * 9       \
432
204k
          + STRING_SIZE_SIZE)
433
136k
#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
51.6k
#define SIZEOF_IDATA4   (2 * 4)
438
51.6k
#define SIZEOF_IDATA5   (2 * 4)
439
#else
440
152k
#define SIZEOF_IDATA4   (1 * 4)
441
152k
#define SIZEOF_IDATA5   (1 * 4)
442
#endif
443
444
182k
#define SIZEOF_IDATA6   (2 + strlen (import_name) + 1 + 1)
445
136k
#define SIZEOF_IDATA7   (strlen (source_dll) + 1 + 1)
446
136k
#define SIZEOF_ILF_SECTIONS (NUM_ILF_SECTIONS \
447
136k
         * sizeof (struct coff_section_tdata))
448
449
#define ILF_DATA_SIZE       \
450
136k
    + SIZEOF_ILF_SYMS        \
451
136k
    + SIZEOF_ILF_SYM_TABLE      \
452
136k
    + SIZEOF_ILF_NATIVE_SYMS      \
453
136k
    + SIZEOF_ILF_SYM_PTR_TABLE      \
454
136k
    + SIZEOF_ILF_EXT_SYMS      \
455
136k
    + SIZEOF_ILF_RELOCS        \
456
136k
    + SIZEOF_ILF_INT_RELOCS      \
457
136k
    + SIZEOF_ILF_STRINGS      \
458
136k
    + SIZEOF_IDATA2        \
459
136k
    + SIZEOF_IDATA4        \
460
136k
    + SIZEOF_IDATA5        \
461
136k
    + SIZEOF_IDATA6        \
462
136k
    + SIZEOF_IDATA7        \
463
136k
    + SIZEOF_ILF_SECTIONS      \
464
136k
    + 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
122k
{
475
122k
  arelent *entry;
476
122k
  struct internal_reloc *internal;
477
478
122k
  entry = vars->reltab + vars->relcount;
479
122k
  internal = vars->int_reltab + vars->relcount;
480
481
122k
  entry->address     = address;
482
122k
  entry->addend      = 0;
483
122k
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
484
122k
  entry->sym_ptr_ptr = sym;
485
486
122k
  internal->r_vaddr  = address;
487
122k
  internal->r_symndx = sym_index;
488
122k
  internal->r_type   = entry->howto ? entry->howto->type : 0;
489
490
122k
  vars->relcount ++;
491
492
122k
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
493
122k
}
pei-i386.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
474
19.3k
{
475
19.3k
  arelent *entry;
476
19.3k
  struct internal_reloc *internal;
477
478
19.3k
  entry = vars->reltab + vars->relcount;
479
19.3k
  internal = vars->int_reltab + vars->relcount;
480
481
19.3k
  entry->address     = address;
482
19.3k
  entry->addend      = 0;
483
19.3k
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
484
19.3k
  entry->sym_ptr_ptr = sym;
485
486
19.3k
  internal->r_vaddr  = address;
487
19.3k
  internal->r_symndx = sym_index;
488
19.3k
  internal->r_type   = entry->howto ? entry->howto->type : 0;
489
490
19.3k
  vars->relcount ++;
491
492
19.3k
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
493
19.3k
}
pei-x86_64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
474
17.2k
{
475
17.2k
  arelent *entry;
476
17.2k
  struct internal_reloc *internal;
477
478
17.2k
  entry = vars->reltab + vars->relcount;
479
17.2k
  internal = vars->int_reltab + vars->relcount;
480
481
17.2k
  entry->address     = address;
482
17.2k
  entry->addend      = 0;
483
17.2k
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
484
17.2k
  entry->sym_ptr_ptr = sym;
485
486
17.2k
  internal->r_vaddr  = address;
487
17.2k
  internal->r_symndx = sym_index;
488
17.2k
  internal->r_type   = entry->howto ? entry->howto->type : 0;
489
490
17.2k
  vars->relcount ++;
491
492
17.2k
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
493
17.2k
}
pei-aarch64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
474
14.6k
{
475
14.6k
  arelent *entry;
476
14.6k
  struct internal_reloc *internal;
477
478
14.6k
  entry = vars->reltab + vars->relcount;
479
14.6k
  internal = vars->int_reltab + vars->relcount;
480
481
14.6k
  entry->address     = address;
482
14.6k
  entry->addend      = 0;
483
14.6k
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
484
14.6k
  entry->sym_ptr_ptr = sym;
485
486
14.6k
  internal->r_vaddr  = address;
487
14.6k
  internal->r_symndx = sym_index;
488
14.6k
  internal->r_type   = entry->howto ? entry->howto->type : 0;
489
490
14.6k
  vars->relcount ++;
491
492
14.6k
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
493
14.6k
}
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.2k
{
475
13.2k
  arelent *entry;
476
13.2k
  struct internal_reloc *internal;
477
478
13.2k
  entry = vars->reltab + vars->relcount;
479
13.2k
  internal = vars->int_reltab + vars->relcount;
480
481
13.2k
  entry->address     = address;
482
13.2k
  entry->addend      = 0;
483
13.2k
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
484
13.2k
  entry->sym_ptr_ptr = sym;
485
486
13.2k
  internal->r_vaddr  = address;
487
13.2k
  internal->r_symndx = sym_index;
488
13.2k
  internal->r_type   = entry->howto ? entry->howto->type : 0;
489
490
13.2k
  vars->relcount ++;
491
492
13.2k
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
493
13.2k
}
pei-arm-wince.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
474
197
{
475
197
  arelent *entry;
476
197
  struct internal_reloc *internal;
477
478
197
  entry = vars->reltab + vars->relcount;
479
197
  internal = vars->int_reltab + vars->relcount;
480
481
197
  entry->address     = address;
482
197
  entry->addend      = 0;
483
197
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
484
197
  entry->sym_ptr_ptr = sym;
485
486
197
  internal->r_vaddr  = address;
487
197
  internal->r_symndx = sym_index;
488
197
  internal->r_type   = entry->howto ? entry->howto->type : 0;
489
490
197
  vars->relcount ++;
491
492
197
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
493
197
}
pei-arm.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
474
30.7k
{
475
30.7k
  arelent *entry;
476
30.7k
  struct internal_reloc *internal;
477
478
30.7k
  entry = vars->reltab + vars->relcount;
479
30.7k
  internal = vars->int_reltab + vars->relcount;
480
481
30.7k
  entry->address     = address;
482
30.7k
  entry->addend      = 0;
483
30.7k
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
484
30.7k
  entry->sym_ptr_ptr = sym;
485
486
30.7k
  internal->r_vaddr  = address;
487
30.7k
  internal->r_symndx = sym_index;
488
30.7k
  internal->r_type   = entry->howto ? entry->howto->type : 0;
489
490
30.7k
  vars->relcount ++;
491
492
30.7k
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
493
30.7k
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_symbol_reloc
pei-sh.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
474
16.6k
{
475
16.6k
  arelent *entry;
476
16.6k
  struct internal_reloc *internal;
477
478
16.6k
  entry = vars->reltab + vars->relcount;
479
16.6k
  internal = vars->int_reltab + vars->relcount;
480
481
16.6k
  entry->address     = address;
482
16.6k
  entry->addend      = 0;
483
16.6k
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
484
16.6k
  entry->sym_ptr_ptr = sym;
485
486
16.6k
  internal->r_vaddr  = address;
487
16.6k
  internal->r_symndx = sym_index;
488
16.6k
  internal->r_type   = entry->howto ? entry->howto->type : 0;
489
490
16.6k
  vars->relcount ++;
491
492
16.6k
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
493
16.6k
}
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
93.2k
{
503
93.2k
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
504
93.2k
            coff_section_data (vars->abfd, sec)->i);
505
93.2k
}
pei-i386.c:pe_ILF_make_a_reloc
Line
Count
Source
502
15.3k
{
503
15.3k
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
504
15.3k
            coff_section_data (vars->abfd, sec)->i);
505
15.3k
}
pei-x86_64.c:pe_ILF_make_a_reloc
Line
Count
Source
502
13.2k
{
503
13.2k
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
504
13.2k
            coff_section_data (vars->abfd, sec)->i);
505
13.2k
}
pei-aarch64.c:pe_ILF_make_a_reloc
Line
Count
Source
502
11.2k
{
503
11.2k
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
504
11.2k
            coff_section_data (vars->abfd, sec)->i);
505
11.2k
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_reloc
pei-loongarch64.c:pe_ILF_make_a_reloc
Line
Count
Source
502
7.83k
{
503
7.83k
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
504
7.83k
            coff_section_data (vars->abfd, sec)->i);
505
7.83k
}
pei-riscv64.c:pe_ILF_make_a_reloc
Line
Count
Source
502
10.9k
{
503
10.9k
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
504
10.9k
            coff_section_data (vars->abfd, sec)->i);
505
10.9k
}
pei-arm-wince.c:pe_ILF_make_a_reloc
Line
Count
Source
502
138
{
503
138
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
504
138
            coff_section_data (vars->abfd, sec)->i);
505
138
}
pei-arm.c:pe_ILF_make_a_reloc
Line
Count
Source
502
21.2k
{
503
21.2k
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
504
21.2k
            coff_section_data (vars->abfd, sec)->i);
505
21.2k
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_reloc
pei-sh.c:pe_ILF_make_a_reloc
Line
Count
Source
502
13.1k
{
503
13.1k
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
504
13.1k
            coff_section_data (vars->abfd, sec)->i);
505
13.1k
}
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
122k
{
513
  /* Make sure that there is somewhere to store the internal relocs.  */
514
122k
  if (coff_section_data (vars->abfd, sec) == NULL)
515
    /* We should probably return an error indication here.  */
516
0
    abort ();
517
518
122k
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
519
520
122k
  sec->relocation  = vars->reltab;
521
122k
  sec->reloc_count = vars->relcount;
522
122k
  sec->flags      |= SEC_RELOC;
523
524
122k
  vars->reltab     += vars->relcount;
525
122k
  vars->int_reltab += vars->relcount;
526
122k
  vars->relcount   = 0;
527
528
122k
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
529
122k
}
pei-i386.c:pe_ILF_save_relocs
Line
Count
Source
512
19.3k
{
513
  /* Make sure that there is somewhere to store the internal relocs.  */
514
19.3k
  if (coff_section_data (vars->abfd, sec) == NULL)
515
    /* We should probably return an error indication here.  */
516
0
    abort ();
517
518
19.3k
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
519
520
19.3k
  sec->relocation  = vars->reltab;
521
19.3k
  sec->reloc_count = vars->relcount;
522
19.3k
  sec->flags      |= SEC_RELOC;
523
524
19.3k
  vars->reltab     += vars->relcount;
525
19.3k
  vars->int_reltab += vars->relcount;
526
19.3k
  vars->relcount   = 0;
527
528
19.3k
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
529
19.3k
}
pei-x86_64.c:pe_ILF_save_relocs
Line
Count
Source
512
17.2k
{
513
  /* Make sure that there is somewhere to store the internal relocs.  */
514
17.2k
  if (coff_section_data (vars->abfd, sec) == NULL)
515
    /* We should probably return an error indication here.  */
516
0
    abort ();
517
518
17.2k
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
519
520
17.2k
  sec->relocation  = vars->reltab;
521
17.2k
  sec->reloc_count = vars->relcount;
522
17.2k
  sec->flags      |= SEC_RELOC;
523
524
17.2k
  vars->reltab     += vars->relcount;
525
17.2k
  vars->int_reltab += vars->relcount;
526
17.2k
  vars->relcount   = 0;
527
528
17.2k
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
529
17.2k
}
pei-aarch64.c:pe_ILF_save_relocs
Line
Count
Source
512
14.6k
{
513
  /* Make sure that there is somewhere to store the internal relocs.  */
514
14.6k
  if (coff_section_data (vars->abfd, sec) == NULL)
515
    /* We should probably return an error indication here.  */
516
0
    abort ();
517
518
14.6k
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
519
520
14.6k
  sec->relocation  = vars->reltab;
521
14.6k
  sec->reloc_count = vars->relcount;
522
14.6k
  sec->flags      |= SEC_RELOC;
523
524
14.6k
  vars->reltab     += vars->relcount;
525
14.6k
  vars->int_reltab += vars->relcount;
526
14.6k
  vars->relcount   = 0;
527
528
14.6k
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
529
14.6k
}
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.2k
{
513
  /* Make sure that there is somewhere to store the internal relocs.  */
514
13.2k
  if (coff_section_data (vars->abfd, sec) == NULL)
515
    /* We should probably return an error indication here.  */
516
0
    abort ();
517
518
13.2k
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
519
520
13.2k
  sec->relocation  = vars->reltab;
521
13.2k
  sec->reloc_count = vars->relcount;
522
13.2k
  sec->flags      |= SEC_RELOC;
523
524
13.2k
  vars->reltab     += vars->relcount;
525
13.2k
  vars->int_reltab += vars->relcount;
526
13.2k
  vars->relcount   = 0;
527
528
13.2k
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
529
13.2k
}
pei-arm-wince.c:pe_ILF_save_relocs
Line
Count
Source
512
197
{
513
  /* Make sure that there is somewhere to store the internal relocs.  */
514
197
  if (coff_section_data (vars->abfd, sec) == NULL)
515
    /* We should probably return an error indication here.  */
516
0
    abort ();
517
518
197
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
519
520
197
  sec->relocation  = vars->reltab;
521
197
  sec->reloc_count = vars->relcount;
522
197
  sec->flags      |= SEC_RELOC;
523
524
197
  vars->reltab     += vars->relcount;
525
197
  vars->int_reltab += vars->relcount;
526
197
  vars->relcount   = 0;
527
528
197
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
529
197
}
pei-arm.c:pe_ILF_save_relocs
Line
Count
Source
512
30.7k
{
513
  /* Make sure that there is somewhere to store the internal relocs.  */
514
30.7k
  if (coff_section_data (vars->abfd, sec) == NULL)
515
    /* We should probably return an error indication here.  */
516
0
    abort ();
517
518
30.7k
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
519
520
30.7k
  sec->relocation  = vars->reltab;
521
30.7k
  sec->reloc_count = vars->relcount;
522
30.7k
  sec->flags      |= SEC_RELOC;
523
524
30.7k
  vars->reltab     += vars->relcount;
525
30.7k
  vars->int_reltab += vars->relcount;
526
30.7k
  vars->relcount   = 0;
527
528
30.7k
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
529
30.7k
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_save_relocs
pei-sh.c:pe_ILF_save_relocs
Line
Count
Source
512
16.6k
{
513
  /* Make sure that there is somewhere to store the internal relocs.  */
514
16.6k
  if (coff_section_data (vars->abfd, sec) == NULL)
515
    /* We should probably return an error indication here.  */
516
0
    abort ();
517
518
16.6k
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
519
520
16.6k
  sec->relocation  = vars->reltab;
521
16.6k
  sec->reloc_count = vars->relcount;
522
16.6k
  sec->flags      |= SEC_RELOC;
523
524
16.6k
  vars->reltab     += vars->relcount;
525
16.6k
  vars->int_reltab += vars->relcount;
526
16.6k
  vars->relcount   = 0;
527
528
16.6k
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
529
16.6k
}
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
385k
{
540
385k
  coff_symbol_type *sym;
541
385k
  combined_entry_type *ent;
542
385k
  SYMENT *esym;
543
385k
  unsigned short sclass;
544
545
385k
  if (extra_flags & BSF_LOCAL)
546
212k
    sclass = C_STAT;
547
173k
  else
548
173k
    sclass = C_EXT;
549
550
#ifdef THUMBPEMAGIC
551
102k
  if (vars->magic == THUMBPEMAGIC)
552
33.1k
    {
553
33.1k
      if (extra_flags & BSF_FUNCTION)
554
3.43k
  sclass = C_THUMBEXTFUNC;
555
29.7k
      else if (extra_flags & BSF_LOCAL)
556
18.3k
  sclass = C_THUMBSTAT;
557
11.3k
      else
558
11.3k
  sclass = C_THUMBEXT;
559
33.1k
    }
560
#endif
561
562
385k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
563
564
385k
  sym = vars->sym_ptr;
565
385k
  ent = vars->native_ptr;
566
385k
  esym = vars->esym_ptr;
567
568
  /* Copy the symbol's name into the string table.  */
569
385k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
570
571
385k
  if (section == NULL)
572
64.8k
    section = bfd_und_section_ptr;
573
574
  /* Initialise the external symbol.  */
575
385k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
576
385k
      esym->e.e.e_offset);
577
385k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
578
385k
  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
385k
  ent->u.syment.n_sclass    = sclass;
585
385k
  ent->u.syment.n_scnum     = section->target_index;
586
385k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
587
385k
  ent->is_sym = true;
588
589
385k
  sym->symbol.the_bfd = vars->abfd;
590
385k
  sym->symbol.name    = vars->string_ptr;
591
385k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
592
385k
  sym->symbol.section = section;
593
385k
  sym->native       = ent;
594
595
385k
  *vars->table_ptr = vars->sym_index;
596
385k
  *vars->sym_ptr_ptr = sym;
597
598
  /* Adjust pointers for the next symbol.  */
599
385k
  vars->sym_index ++;
600
385k
  vars->sym_ptr ++;
601
385k
  vars->sym_ptr_ptr ++;
602
385k
  vars->table_ptr ++;
603
385k
  vars->native_ptr ++;
604
385k
  vars->esym_ptr ++;
605
385k
  vars->string_ptr += len + 1;
606
607
385k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
608
385k
}
pei-i386.c:pe_ILF_make_a_symbol
Line
Count
Source
539
61.4k
{
540
61.4k
  coff_symbol_type *sym;
541
61.4k
  combined_entry_type *ent;
542
61.4k
  SYMENT *esym;
543
61.4k
  unsigned short sclass;
544
545
61.4k
  if (extra_flags & BSF_LOCAL)
546
33.9k
    sclass = C_STAT;
547
27.4k
  else
548
27.4k
    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
61.4k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
563
564
61.4k
  sym = vars->sym_ptr;
565
61.4k
  ent = vars->native_ptr;
566
61.4k
  esym = vars->esym_ptr;
567
568
  /* Copy the symbol's name into the string table.  */
569
61.4k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
570
571
61.4k
  if (section == NULL)
572
10.7k
    section = bfd_und_section_ptr;
573
574
  /* Initialise the external symbol.  */
575
61.4k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
576
61.4k
      esym->e.e.e_offset);
577
61.4k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
578
61.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
61.4k
  ent->u.syment.n_sclass    = sclass;
585
61.4k
  ent->u.syment.n_scnum     = section->target_index;
586
61.4k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
587
61.4k
  ent->is_sym = true;
588
589
61.4k
  sym->symbol.the_bfd = vars->abfd;
590
61.4k
  sym->symbol.name    = vars->string_ptr;
591
61.4k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
592
61.4k
  sym->symbol.section = section;
593
61.4k
  sym->native       = ent;
594
595
61.4k
  *vars->table_ptr = vars->sym_index;
596
61.4k
  *vars->sym_ptr_ptr = sym;
597
598
  /* Adjust pointers for the next symbol.  */
599
61.4k
  vars->sym_index ++;
600
61.4k
  vars->sym_ptr ++;
601
61.4k
  vars->sym_ptr_ptr ++;
602
61.4k
  vars->table_ptr ++;
603
61.4k
  vars->native_ptr ++;
604
61.4k
  vars->esym_ptr ++;
605
61.4k
  vars->string_ptr += len + 1;
606
607
61.4k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
608
61.4k
}
pei-x86_64.c:pe_ILF_make_a_symbol
Line
Count
Source
539
52.8k
{
540
52.8k
  coff_symbol_type *sym;
541
52.8k
  combined_entry_type *ent;
542
52.8k
  SYMENT *esym;
543
52.8k
  unsigned short sclass;
544
545
52.8k
  if (extra_flags & BSF_LOCAL)
546
29.1k
    sclass = C_STAT;
547
23.7k
  else
548
23.7k
    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.8k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
563
564
52.8k
  sym = vars->sym_ptr;
565
52.8k
  ent = vars->native_ptr;
566
52.8k
  esym = vars->esym_ptr;
567
568
  /* Copy the symbol's name into the string table.  */
569
52.8k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
570
571
52.8k
  if (section == NULL)
572
8.94k
    section = bfd_und_section_ptr;
573
574
  /* Initialise the external symbol.  */
575
52.8k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
576
52.8k
      esym->e.e.e_offset);
577
52.8k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
578
52.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
52.8k
  ent->u.syment.n_sclass    = sclass;
585
52.8k
  ent->u.syment.n_scnum     = section->target_index;
586
52.8k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
587
52.8k
  ent->is_sym = true;
588
589
52.8k
  sym->symbol.the_bfd = vars->abfd;
590
52.8k
  sym->symbol.name    = vars->string_ptr;
591
52.8k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
592
52.8k
  sym->symbol.section = section;
593
52.8k
  sym->native       = ent;
594
595
52.8k
  *vars->table_ptr = vars->sym_index;
596
52.8k
  *vars->sym_ptr_ptr = sym;
597
598
  /* Adjust pointers for the next symbol.  */
599
52.8k
  vars->sym_index ++;
600
52.8k
  vars->sym_ptr ++;
601
52.8k
  vars->sym_ptr_ptr ++;
602
52.8k
  vars->table_ptr ++;
603
52.8k
  vars->native_ptr ++;
604
52.8k
  vars->esym_ptr ++;
605
52.8k
  vars->string_ptr += len + 1;
606
607
52.8k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
608
52.8k
}
pei-aarch64.c:pe_ILF_make_a_symbol
Line
Count
Source
539
45.1k
{
540
45.1k
  coff_symbol_type *sym;
541
45.1k
  combined_entry_type *ent;
542
45.1k
  SYMENT *esym;
543
45.1k
  unsigned short sclass;
544
545
45.1k
  if (extra_flags & BSF_LOCAL)
546
24.8k
    sclass = C_STAT;
547
20.2k
  else
548
20.2k
    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
45.1k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
563
564
45.1k
  sym = vars->sym_ptr;
565
45.1k
  ent = vars->native_ptr;
566
45.1k
  esym = vars->esym_ptr;
567
568
  /* Copy the symbol's name into the string table.  */
569
45.1k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
570
571
45.1k
  if (section == NULL)
572
7.63k
    section = bfd_und_section_ptr;
573
574
  /* Initialise the external symbol.  */
575
45.1k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
576
45.1k
      esym->e.e.e_offset);
577
45.1k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
578
45.1k
  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
45.1k
  ent->u.syment.n_sclass    = sclass;
585
45.1k
  ent->u.syment.n_scnum     = section->target_index;
586
45.1k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
587
45.1k
  ent->is_sym = true;
588
589
45.1k
  sym->symbol.the_bfd = vars->abfd;
590
45.1k
  sym->symbol.name    = vars->string_ptr;
591
45.1k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
592
45.1k
  sym->symbol.section = section;
593
45.1k
  sym->native       = ent;
594
595
45.1k
  *vars->table_ptr = vars->sym_index;
596
45.1k
  *vars->sym_ptr_ptr = sym;
597
598
  /* Adjust pointers for the next symbol.  */
599
45.1k
  vars->sym_index ++;
600
45.1k
  vars->sym_ptr ++;
601
45.1k
  vars->sym_ptr_ptr ++;
602
45.1k
  vars->table_ptr ++;
603
45.1k
  vars->native_ptr ++;
604
45.1k
  vars->esym_ptr ++;
605
45.1k
  vars->string_ptr += len + 1;
606
607
45.1k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
608
45.1k
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_symbol
pei-loongarch64.c:pe_ILF_make_a_symbol
Line
Count
Source
539
28.9k
{
540
28.9k
  coff_symbol_type *sym;
541
28.9k
  combined_entry_type *ent;
542
28.9k
  SYMENT *esym;
543
28.9k
  unsigned short sclass;
544
545
28.9k
  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.9k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
563
564
28.9k
  sym = vars->sym_ptr;
565
28.9k
  ent = vars->native_ptr;
566
28.9k
  esym = vars->esym_ptr;
567
568
  /* Copy the symbol's name into the string table.  */
569
28.9k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
570
571
28.9k
  if (section == NULL)
572
4.77k
    section = bfd_und_section_ptr;
573
574
  /* Initialise the external symbol.  */
575
28.9k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
576
28.9k
      esym->e.e.e_offset);
577
28.9k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
578
28.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
28.9k
  ent->u.syment.n_sclass    = sclass;
585
28.9k
  ent->u.syment.n_scnum     = section->target_index;
586
28.9k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
587
28.9k
  ent->is_sym = true;
588
589
28.9k
  sym->symbol.the_bfd = vars->abfd;
590
28.9k
  sym->symbol.name    = vars->string_ptr;
591
28.9k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
592
28.9k
  sym->symbol.section = section;
593
28.9k
  sym->native       = ent;
594
595
28.9k
  *vars->table_ptr = vars->sym_index;
596
28.9k
  *vars->sym_ptr_ptr = sym;
597
598
  /* Adjust pointers for the next symbol.  */
599
28.9k
  vars->sym_index ++;
600
28.9k
  vars->sym_ptr ++;
601
28.9k
  vars->sym_ptr_ptr ++;
602
28.9k
  vars->table_ptr ++;
603
28.9k
  vars->native_ptr ++;
604
28.9k
  vars->esym_ptr ++;
605
28.9k
  vars->string_ptr += len + 1;
606
607
28.9k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
608
28.9k
}
pei-riscv64.c:pe_ILF_make_a_symbol
Line
Count
Source
539
42.4k
{
540
42.4k
  coff_symbol_type *sym;
541
42.4k
  combined_entry_type *ent;
542
42.4k
  SYMENT *esym;
543
42.4k
  unsigned short sclass;
544
545
42.4k
  if (extra_flags & BSF_LOCAL)
546
22.7k
    sclass = C_STAT;
547
19.7k
  else
548
19.7k
    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.4k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
563
564
42.4k
  sym = vars->sym_ptr;
565
42.4k
  ent = vars->native_ptr;
566
42.4k
  esym = vars->esym_ptr;
567
568
  /* Copy the symbol's name into the string table.  */
569
42.4k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
570
571
42.4k
  if (section == NULL)
572
7.28k
    section = bfd_und_section_ptr;
573
574
  /* Initialise the external symbol.  */
575
42.4k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
576
42.4k
      esym->e.e.e_offset);
577
42.4k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
578
42.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
42.4k
  ent->u.syment.n_sclass    = sclass;
585
42.4k
  ent->u.syment.n_scnum     = section->target_index;
586
42.4k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
587
42.4k
  ent->is_sym = true;
588
589
42.4k
  sym->symbol.the_bfd = vars->abfd;
590
42.4k
  sym->symbol.name    = vars->string_ptr;
591
42.4k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
592
42.4k
  sym->symbol.section = section;
593
42.4k
  sym->native       = ent;
594
595
42.4k
  *vars->table_ptr = vars->sym_index;
596
42.4k
  *vars->sym_ptr_ptr = sym;
597
598
  /* Adjust pointers for the next symbol.  */
599
42.4k
  vars->sym_index ++;
600
42.4k
  vars->sym_ptr ++;
601
42.4k
  vars->sym_ptr_ptr ++;
602
42.4k
  vars->table_ptr ++;
603
42.4k
  vars->native_ptr ++;
604
42.4k
  vars->esym_ptr ++;
605
42.4k
  vars->string_ptr += len + 1;
606
607
42.4k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
608
42.4k
}
pei-arm-wince.c:pe_ILF_make_a_symbol
Line
Count
Source
539
2.06k
{
540
2.06k
  coff_symbol_type *sym;
541
2.06k
  combined_entry_type *ent;
542
2.06k
  SYMENT *esym;
543
2.06k
  unsigned short sclass;
544
545
2.06k
  if (extra_flags & BSF_LOCAL)
546
1.78k
    sclass = C_STAT;
547
288
  else
548
288
    sclass = C_EXT;
549
550
2.06k
#ifdef THUMBPEMAGIC
551
2.06k
  if (vars->magic == THUMBPEMAGIC)
552
834
    {
553
834
      if (extra_flags & BSF_FUNCTION)
554
22
  sclass = C_THUMBEXTFUNC;
555
812
      else if (extra_flags & BSF_LOCAL)
556
731
  sclass = C_THUMBSTAT;
557
81
      else
558
81
  sclass = C_THUMBEXT;
559
834
    }
560
2.06k
#endif
561
562
2.06k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
563
564
2.06k
  sym = vars->sym_ptr;
565
2.06k
  ent = vars->native_ptr;
566
2.06k
  esym = vars->esym_ptr;
567
568
  /* Copy the symbol's name into the string table.  */
569
2.06k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
570
571
2.06k
  if (section == NULL)
572
105
    section = bfd_und_section_ptr;
573
574
  /* Initialise the external symbol.  */
575
2.06k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
576
2.06k
      esym->e.e.e_offset);
577
2.06k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
578
2.06k
  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
2.06k
  ent->u.syment.n_sclass    = sclass;
585
2.06k
  ent->u.syment.n_scnum     = section->target_index;
586
2.06k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
587
2.06k
  ent->is_sym = true;
588
589
2.06k
  sym->symbol.the_bfd = vars->abfd;
590
2.06k
  sym->symbol.name    = vars->string_ptr;
591
2.06k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
592
2.06k
  sym->symbol.section = section;
593
2.06k
  sym->native       = ent;
594
595
2.06k
  *vars->table_ptr = vars->sym_index;
596
2.06k
  *vars->sym_ptr_ptr = sym;
597
598
  /* Adjust pointers for the next symbol.  */
599
2.06k
  vars->sym_index ++;
600
2.06k
  vars->sym_ptr ++;
601
2.06k
  vars->sym_ptr_ptr ++;
602
2.06k
  vars->table_ptr ++;
603
2.06k
  vars->native_ptr ++;
604
2.06k
  vars->esym_ptr ++;
605
2.06k
  vars->string_ptr += len + 1;
606
607
2.06k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
608
2.06k
}
pei-arm.c:pe_ILF_make_a_symbol
Line
Count
Source
539
99.9k
{
540
99.9k
  coff_symbol_type *sym;
541
99.9k
  combined_entry_type *ent;
542
99.9k
  SYMENT *esym;
543
99.9k
  unsigned short sclass;
544
545
99.9k
  if (extra_flags & BSF_LOCAL)
546
54.0k
    sclass = C_STAT;
547
45.8k
  else
548
45.8k
    sclass = C_EXT;
549
550
99.9k
#ifdef THUMBPEMAGIC
551
99.9k
  if (vars->magic == THUMBPEMAGIC)
552
32.3k
    {
553
32.3k
      if (extra_flags & BSF_FUNCTION)
554
3.41k
  sclass = C_THUMBEXTFUNC;
555
28.9k
      else if (extra_flags & BSF_LOCAL)
556
17.6k
  sclass = C_THUMBSTAT;
557
11.2k
      else
558
11.2k
  sclass = C_THUMBEXT;
559
32.3k
    }
560
99.9k
#endif
561
562
99.9k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
563
564
99.9k
  sym = vars->sym_ptr;
565
99.9k
  ent = vars->native_ptr;
566
99.9k
  esym = vars->esym_ptr;
567
568
  /* Copy the symbol's name into the string table.  */
569
99.9k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
570
571
99.9k
  if (section == NULL)
572
16.2k
    section = bfd_und_section_ptr;
573
574
  /* Initialise the external symbol.  */
575
99.9k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
576
99.9k
      esym->e.e.e_offset);
577
99.9k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
578
99.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
99.9k
  ent->u.syment.n_sclass    = sclass;
585
99.9k
  ent->u.syment.n_scnum     = section->target_index;
586
99.9k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
587
99.9k
  ent->is_sym = true;
588
589
99.9k
  sym->symbol.the_bfd = vars->abfd;
590
99.9k
  sym->symbol.name    = vars->string_ptr;
591
99.9k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
592
99.9k
  sym->symbol.section = section;
593
99.9k
  sym->native       = ent;
594
595
99.9k
  *vars->table_ptr = vars->sym_index;
596
99.9k
  *vars->sym_ptr_ptr = sym;
597
598
  /* Adjust pointers for the next symbol.  */
599
99.9k
  vars->sym_index ++;
600
99.9k
  vars->sym_ptr ++;
601
99.9k
  vars->sym_ptr_ptr ++;
602
99.9k
  vars->table_ptr ++;
603
99.9k
  vars->native_ptr ++;
604
99.9k
  vars->esym_ptr ++;
605
99.9k
  vars->string_ptr += len + 1;
606
607
99.9k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
608
99.9k
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_symbol
pei-sh.c:pe_ILF_make_a_symbol
Line
Count
Source
539
53.0k
{
540
53.0k
  coff_symbol_type *sym;
541
53.0k
  combined_entry_type *ent;
542
53.0k
  SYMENT *esym;
543
53.0k
  unsigned short sclass;
544
545
53.0k
  if (extra_flags & BSF_LOCAL)
546
29.0k
    sclass = C_STAT;
547
23.9k
  else
548
23.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
53.0k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
563
564
53.0k
  sym = vars->sym_ptr;
565
53.0k
  ent = vars->native_ptr;
566
53.0k
  esym = vars->esym_ptr;
567
568
  /* Copy the symbol's name into the string table.  */
569
53.0k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
570
571
53.0k
  if (section == NULL)
572
9.08k
    section = bfd_und_section_ptr;
573
574
  /* Initialise the external symbol.  */
575
53.0k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
576
53.0k
      esym->e.e.e_offset);
577
53.0k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
578
53.0k
  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
53.0k
  ent->u.syment.n_sclass    = sclass;
585
53.0k
  ent->u.syment.n_scnum     = section->target_index;
586
53.0k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
587
53.0k
  ent->is_sym = true;
588
589
53.0k
  sym->symbol.the_bfd = vars->abfd;
590
53.0k
  sym->symbol.name    = vars->string_ptr;
591
53.0k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
592
53.0k
  sym->symbol.section = section;
593
53.0k
  sym->native       = ent;
594
595
53.0k
  *vars->table_ptr = vars->sym_index;
596
53.0k
  *vars->sym_ptr_ptr = sym;
597
598
  /* Adjust pointers for the next symbol.  */
599
53.0k
  vars->sym_index ++;
600
53.0k
  vars->sym_ptr ++;
601
53.0k
  vars->sym_ptr_ptr ++;
602
53.0k
  vars->table_ptr ++;
603
53.0k
  vars->native_ptr ++;
604
53.0k
  vars->esym_ptr ++;
605
53.0k
  vars->string_ptr += len + 1;
606
607
53.0k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
608
53.0k
}
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
212k
{
618
212k
  asection_ptr sec;
619
212k
  flagword     flags;
620
212k
  intptr_t alignment;
621
622
212k
  sec = bfd_make_section_old_way (vars->abfd, name);
623
212k
  if (sec == NULL)
624
0
    return NULL;
625
626
212k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
627
628
212k
  bfd_set_section_flags (sec, flags | extra_flags);
629
630
212k
  bfd_set_section_alignment (sec, 2);
631
632
  /* Check that we will not run out of space.  */
633
212k
  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
212k
  bfd_set_section_size (sec, (bfd_size_type) size);
638
212k
  sec->contents = vars->data;
639
212k
  sec->target_index = vars->sec_index ++;
640
641
  /* Advance data pointer in the vars structure.  */
642
212k
  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
212k
  if (size & 1)
649
24.0k
    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
212k
#if GCC_VERSION >= 3000
656
212k
  alignment = __alignof__ (struct coff_section_tdata);
657
#else
658
  alignment = 8;
659
#endif
660
212k
  vars->data
661
212k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
662
663
  /* Create a coff_section_tdata structure for our use.  */
664
212k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
665
212k
  vars->data += sizeof (struct coff_section_tdata);
666
667
212k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
668
669
  /* Create a symbol to refer to this section.  */
670
212k
  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
212k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
674
675
212k
  return sec;
676
212k
}
pei-i386.c:pe_ILF_make_a_section
Line
Count
Source
617
33.9k
{
618
33.9k
  asection_ptr sec;
619
33.9k
  flagword     flags;
620
33.9k
  intptr_t alignment;
621
622
33.9k
  sec = bfd_make_section_old_way (vars->abfd, name);
623
33.9k
  if (sec == NULL)
624
0
    return NULL;
625
626
33.9k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
627
628
33.9k
  bfd_set_section_flags (sec, flags | extra_flags);
629
630
33.9k
  bfd_set_section_alignment (sec, 2);
631
632
  /* Check that we will not run out of space.  */
633
33.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
33.9k
  bfd_set_section_size (sec, (bfd_size_type) size);
638
33.9k
  sec->contents = vars->data;
639
33.9k
  sec->target_index = vars->sec_index ++;
640
641
  /* Advance data pointer in the vars structure.  */
642
33.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
33.9k
  if (size & 1)
649
2.46k
    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
33.9k
#if GCC_VERSION >= 3000
656
33.9k
  alignment = __alignof__ (struct coff_section_tdata);
657
#else
658
  alignment = 8;
659
#endif
660
33.9k
  vars->data
661
33.9k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
662
663
  /* Create a coff_section_tdata structure for our use.  */
664
33.9k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
665
33.9k
  vars->data += sizeof (struct coff_section_tdata);
666
667
33.9k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
668
669
  /* Create a symbol to refer to this section.  */
670
33.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
33.9k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
674
675
33.9k
  return sec;
676
33.9k
}
pei-x86_64.c:pe_ILF_make_a_section
Line
Count
Source
617
29.1k
{
618
29.1k
  asection_ptr sec;
619
29.1k
  flagword     flags;
620
29.1k
  intptr_t alignment;
621
622
29.1k
  sec = bfd_make_section_old_way (vars->abfd, name);
623
29.1k
  if (sec == NULL)
624
0
    return NULL;
625
626
29.1k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
627
628
29.1k
  bfd_set_section_flags (sec, flags | extra_flags);
629
630
29.1k
  bfd_set_section_alignment (sec, 2);
631
632
  /* Check that we will not run out of space.  */
633
29.1k
  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.1k
  bfd_set_section_size (sec, (bfd_size_type) size);
638
29.1k
  sec->contents = vars->data;
639
29.1k
  sec->target_index = vars->sec_index ++;
640
641
  /* Advance data pointer in the vars structure.  */
642
29.1k
  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.1k
  if (size & 1)
649
3.85k
    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.1k
#if GCC_VERSION >= 3000
656
29.1k
  alignment = __alignof__ (struct coff_section_tdata);
657
#else
658
  alignment = 8;
659
#endif
660
29.1k
  vars->data
661
29.1k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
662
663
  /* Create a coff_section_tdata structure for our use.  */
664
29.1k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
665
29.1k
  vars->data += sizeof (struct coff_section_tdata);
666
667
29.1k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
668
669
  /* Create a symbol to refer to this section.  */
670
29.1k
  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.1k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
674
675
29.1k
  return sec;
676
29.1k
}
pei-aarch64.c:pe_ILF_make_a_section
Line
Count
Source
617
24.8k
{
618
24.8k
  asection_ptr sec;
619
24.8k
  flagword     flags;
620
24.8k
  intptr_t alignment;
621
622
24.8k
  sec = bfd_make_section_old_way (vars->abfd, name);
623
24.8k
  if (sec == NULL)
624
0
    return NULL;
625
626
24.8k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
627
628
24.8k
  bfd_set_section_flags (sec, flags | extra_flags);
629
630
24.8k
  bfd_set_section_alignment (sec, 2);
631
632
  /* Check that we will not run out of space.  */
633
24.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
24.8k
  bfd_set_section_size (sec, (bfd_size_type) size);
638
24.8k
  sec->contents = vars->data;
639
24.8k
  sec->target_index = vars->sec_index ++;
640
641
  /* Advance data pointer in the vars structure.  */
642
24.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
24.8k
  if (size & 1)
649
2.48k
    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
24.8k
#if GCC_VERSION >= 3000
656
24.8k
  alignment = __alignof__ (struct coff_section_tdata);
657
#else
658
  alignment = 8;
659
#endif
660
24.8k
  vars->data
661
24.8k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
662
663
  /* Create a coff_section_tdata structure for our use.  */
664
24.8k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
665
24.8k
  vars->data += sizeof (struct coff_section_tdata);
666
667
24.8k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
668
669
  /* Create a symbol to refer to this section.  */
670
24.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
24.8k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
674
675
24.8k
  return sec;
676
24.8k
}
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.7k
{
618
22.7k
  asection_ptr sec;
619
22.7k
  flagword     flags;
620
22.7k
  intptr_t alignment;
621
622
22.7k
  sec = bfd_make_section_old_way (vars->abfd, name);
623
22.7k
  if (sec == NULL)
624
0
    return NULL;
625
626
22.7k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
627
628
22.7k
  bfd_set_section_flags (sec, flags | extra_flags);
629
630
22.7k
  bfd_set_section_alignment (sec, 2);
631
632
  /* Check that we will not run out of space.  */
633
22.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
22.7k
  bfd_set_section_size (sec, (bfd_size_type) size);
638
22.7k
  sec->contents = vars->data;
639
22.7k
  sec->target_index = vars->sec_index ++;
640
641
  /* Advance data pointer in the vars structure.  */
642
22.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
22.7k
  if (size & 1)
649
2.69k
    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.7k
#if GCC_VERSION >= 3000
656
22.7k
  alignment = __alignof__ (struct coff_section_tdata);
657
#else
658
  alignment = 8;
659
#endif
660
22.7k
  vars->data
661
22.7k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
662
663
  /* Create a coff_section_tdata structure for our use.  */
664
22.7k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
665
22.7k
  vars->data += sizeof (struct coff_section_tdata);
666
667
22.7k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
668
669
  /* Create a symbol to refer to this section.  */
670
22.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
22.7k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
674
675
22.7k
  return sec;
676
22.7k
}
pei-arm-wince.c:pe_ILF_make_a_section
Line
Count
Source
617
1.78k
{
618
1.78k
  asection_ptr sec;
619
1.78k
  flagword     flags;
620
1.78k
  intptr_t alignment;
621
622
1.78k
  sec = bfd_make_section_old_way (vars->abfd, name);
623
1.78k
  if (sec == NULL)
624
0
    return NULL;
625
626
1.78k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
627
628
1.78k
  bfd_set_section_flags (sec, flags | extra_flags);
629
630
1.78k
  bfd_set_section_alignment (sec, 2);
631
632
  /* Check that we will not run out of space.  */
633
1.78k
  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.78k
  bfd_set_section_size (sec, (bfd_size_type) size);
638
1.78k
  sec->contents = vars->data;
639
1.78k
  sec->target_index = vars->sec_index ++;
640
641
  /* Advance data pointer in the vars structure.  */
642
1.78k
  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.78k
  if (size & 1)
649
32
    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.78k
#if GCC_VERSION >= 3000
656
1.78k
  alignment = __alignof__ (struct coff_section_tdata);
657
#else
658
  alignment = 8;
659
#endif
660
1.78k
  vars->data
661
1.78k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
662
663
  /* Create a coff_section_tdata structure for our use.  */
664
1.78k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
665
1.78k
  vars->data += sizeof (struct coff_section_tdata);
666
667
1.78k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
668
669
  /* Create a symbol to refer to this section.  */
670
1.78k
  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.78k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
674
675
1.78k
  return sec;
676
1.78k
}
pei-arm.c:pe_ILF_make_a_section
Line
Count
Source
617
54.0k
{
618
54.0k
  asection_ptr sec;
619
54.0k
  flagword     flags;
620
54.0k
  intptr_t alignment;
621
622
54.0k
  sec = bfd_make_section_old_way (vars->abfd, name);
623
54.0k
  if (sec == NULL)
624
0
    return NULL;
625
626
54.0k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
627
628
54.0k
  bfd_set_section_flags (sec, flags | extra_flags);
629
630
54.0k
  bfd_set_section_alignment (sec, 2);
631
632
  /* Check that we will not run out of space.  */
633
54.0k
  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
54.0k
  bfd_set_section_size (sec, (bfd_size_type) size);
638
54.0k
  sec->contents = vars->data;
639
54.0k
  sec->target_index = vars->sec_index ++;
640
641
  /* Advance data pointer in the vars structure.  */
642
54.0k
  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
54.0k
  if (size & 1)
649
6.03k
    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
54.0k
#if GCC_VERSION >= 3000
656
54.0k
  alignment = __alignof__ (struct coff_section_tdata);
657
#else
658
  alignment = 8;
659
#endif
660
54.0k
  vars->data
661
54.0k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
662
663
  /* Create a coff_section_tdata structure for our use.  */
664
54.0k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
665
54.0k
  vars->data += sizeof (struct coff_section_tdata);
666
667
54.0k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
668
669
  /* Create a symbol to refer to this section.  */
670
54.0k
  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
54.0k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
674
675
54.0k
  return sec;
676
54.0k
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_section
pei-sh.c:pe_ILF_make_a_section
Line
Count
Source
617
29.0k
{
618
29.0k
  asection_ptr sec;
619
29.0k
  flagword     flags;
620
29.0k
  intptr_t alignment;
621
622
29.0k
  sec = bfd_make_section_old_way (vars->abfd, name);
623
29.0k
  if (sec == NULL)
624
0
    return NULL;
625
626
29.0k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
627
628
29.0k
  bfd_set_section_flags (sec, flags | extra_flags);
629
630
29.0k
  bfd_set_section_alignment (sec, 2);
631
632
  /* Check that we will not run out of space.  */
633
29.0k
  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.0k
  bfd_set_section_size (sec, (bfd_size_type) size);
638
29.0k
  sec->contents = vars->data;
639
29.0k
  sec->target_index = vars->sec_index ++;
640
641
  /* Advance data pointer in the vars structure.  */
642
29.0k
  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.0k
  if (size & 1)
649
3.81k
    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.0k
#if GCC_VERSION >= 3000
656
29.0k
  alignment = __alignof__ (struct coff_section_tdata);
657
#else
658
  alignment = 8;
659
#endif
660
29.0k
  vars->data
661
29.0k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
662
663
  /* Create a coff_section_tdata structure for our use.  */
664
29.0k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
665
29.0k
  vars->data += sizeof (struct coff_section_tdata);
666
667
29.0k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
668
669
  /* Create a symbol to refer to this section.  */
670
29.0k
  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.0k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
674
675
29.0k
  return sec;
676
29.0k
}
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
136k
#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
29.0k
#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
78.1k
{
800
78.1k
  bfd_byte *       ptr;
801
78.1k
  pe_ILF_vars      vars;
802
78.1k
  struct internal_filehdr  internal_f;
803
78.1k
  unsigned int       import_type;
804
78.1k
  unsigned int       import_name_type;
805
78.1k
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
806
78.1k
  coff_symbol_type **    imp_sym;
807
78.1k
  unsigned int       imp_index;
808
78.1k
  intptr_t alignment;
809
810
  /* Decode and verify the types field of the ILF structure.  */
811
78.1k
  import_type = types & 0x3;
812
78.1k
  import_name_type = (types & 0x1c) >> 2;
813
814
78.1k
  switch (import_type)
815
78.1k
    {
816
34.2k
    case IMPORT_CODE:
817
57.5k
    case IMPORT_DATA:
818
75.3k
    case IMPORT_CONST:
819
75.3k
      break;
820
821
2.76k
    default:
822
      /* xgettext:c-format */
823
2.76k
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
824
2.76k
        abfd, import_type);
825
2.76k
      return false;
826
78.1k
    }
827
828
75.3k
  switch (import_name_type)
829
75.3k
    {
830
21.5k
    case IMPORT_ORDINAL:
831
28.9k
    case IMPORT_NAME:
832
44.6k
    case IMPORT_NAME_NOPREFIX:
833
61.4k
    case IMPORT_NAME_UNDECORATE:
834
61.4k
      import_name = symbol_name;
835
61.4k
      break;
836
837
11.2k
    case IMPORT_NAME_EXPORTAS:
838
11.2k
      if (!import_name || !import_name[0])
839
4.50k
  {
840
4.50k
    _bfd_error_handler (_("%pB: missing import name for "
841
4.50k
        "IMPORT_NAME_EXPORTAS for %s"),
842
4.50k
            abfd, symbol_name);
843
4.50k
    return false;
844
4.50k
  }
845
6.70k
      break;
846
847
6.70k
    default:
848
      /* xgettext:c-format */
849
2.71k
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
850
2.71k
        abfd, import_name_type);
851
2.71k
      return false;
852
75.3k
    }
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
68.1k
  vars.bim
862
68.1k
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
863
68.1k
  if (vars.bim == NULL)
864
0
    return false;
865
866
68.1k
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
867
68.1k
  vars.bim->buffer = ptr;
868
68.1k
  vars.bim->size   = ILF_DATA_SIZE;
869
68.1k
  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
68.1k
  vars.sym_cache = (coff_symbol_type *) ptr;
875
68.1k
  vars.sym_ptr   = (coff_symbol_type *) ptr;
876
68.1k
  vars.sym_index = 0;
877
68.1k
  ptr += SIZEOF_ILF_SYMS;
878
879
68.1k
  vars.sym_table = (unsigned int *) ptr;
880
68.1k
  vars.table_ptr = (unsigned int *) ptr;
881
68.1k
  ptr += SIZEOF_ILF_SYM_TABLE;
882
883
68.1k
  vars.native_syms = (combined_entry_type *) ptr;
884
68.1k
  vars.native_ptr  = (combined_entry_type *) ptr;
885
68.1k
  ptr += SIZEOF_ILF_NATIVE_SYMS;
886
887
68.1k
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
888
68.1k
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
889
68.1k
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
890
891
68.1k
  vars.esym_table = (SYMENT *) ptr;
892
68.1k
  vars.esym_ptr   = (SYMENT *) ptr;
893
68.1k
  ptr += SIZEOF_ILF_EXT_SYMS;
894
895
68.1k
  vars.reltab   = (arelent *) ptr;
896
68.1k
  vars.relcount = 0;
897
68.1k
  ptr += SIZEOF_ILF_RELOCS;
898
899
68.1k
  vars.int_reltab  = (struct internal_reloc *) ptr;
900
68.1k
  ptr += SIZEOF_ILF_INT_RELOCS;
901
902
68.1k
  vars.string_table = (char *) ptr;
903
68.1k
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
904
68.1k
  ptr += SIZEOF_ILF_STRINGS;
905
68.1k
  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
68.1k
#if GCC_VERSION >= 3000
915
68.1k
  alignment = __alignof__ (struct coff_section_tdata);
916
#else
917
  alignment = 8;
918
#endif
919
68.1k
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
920
921
68.1k
  vars.data = ptr;
922
68.1k
  vars.abfd = abfd;
923
68.1k
  vars.sec_index = 0;
924
68.1k
  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
68.1k
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
934
68.1k
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
935
68.1k
  if (id4 == NULL || id5 == NULL)
936
0
    goto error_return;
937
938
  /* Fill in the contents of these sections.  */
939
68.1k
  if (import_name_type == IMPORT_ORDINAL)
940
21.5k
    {
941
21.5k
      if (ordinal == 0)
942
  /* See PR 20907 for a reproducer.  */
943
3.33k
  goto error_return;
944
945
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
946
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
947
6.99k
      ((unsigned int *) id4->contents)[0] = ordinal;
948
6.99k
      ((unsigned int *) id4->contents)[1] = 0x80000000;
949
6.99k
      ((unsigned int *) id5->contents)[0] = ordinal;
950
6.99k
      ((unsigned int *) id5->contents)[1] = 0x80000000;
951
#else
952
11.2k
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
953
11.2k
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
954
11.2k
#endif
955
11.2k
    }
956
46.6k
  else
957
46.6k
    {
958
46.6k
      char *symbol;
959
46.6k
      unsigned int len;
960
961
      /* Create .idata$6 - the Hint Name Table.  */
962
46.6k
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
963
46.6k
      if (id6 == NULL)
964
0
  goto error_return;
965
966
      /* If necessary, trim the import symbol name.  */
967
46.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
46.6k
      if (import_name_type != IMPORT_NAME
977
46.6k
    && import_name_type != IMPORT_NAME_EXPORTAS)
978
32.5k
  {
979
32.5k
    char c = symbol[0];
980
981
    /* Check that we don't remove for targets with empty
982
       USER_LABEL_PREFIX the leading underscore.  */
983
32.5k
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
984
32.5k
        || c == '@' || c == '?')
985
9.31k
      symbol++;
986
32.5k
  }
987
988
46.6k
      len = strlen (symbol);
989
46.6k
      if (import_name_type == IMPORT_NAME_UNDECORATE)
990
16.7k
  {
991
    /* Truncate at the first '@'.  */
992
16.7k
    char *at = strchr (symbol, '@');
993
994
16.7k
    if (at != NULL)
995
4.21k
      len = at - symbol;
996
16.7k
  }
997
998
46.6k
      id6->contents[0] = ordinal & 0xff;
999
46.6k
      id6->contents[1] = ordinal >> 8;
1000
1001
46.6k
      memcpy ((char *) id6->contents + 2, symbol, len);
1002
46.6k
      id6->contents[len + 2] = '\0';
1003
46.6k
    }
1004
1005
64.8k
  if (import_name_type != IMPORT_ORDINAL)
1006
46.6k
    {
1007
46.6k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1008
46.6k
      pe_ILF_save_relocs (&vars, id4);
1009
1010
46.6k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1011
46.6k
      pe_ILF_save_relocs (&vars, id5);
1012
46.6k
    }
1013
1014
  /* Create an import symbol.  */
1015
64.8k
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1016
64.8k
  imp_sym   = vars.sym_ptr_ptr - 1;
1017
64.8k
  imp_index = vars.sym_index - 1;
1018
1019
  /* Create extra sections depending upon the type of import we are
1020
     dealing with.  */
1021
64.8k
  switch (import_type)
1022
64.8k
    {
1023
0
      int i;
1024
1025
29.0k
    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
64.2k
      for (i = NUM_ENTRIES (jtab); i--;)
1030
64.2k
  {
1031
64.2k
    if (jtab[i].size == 0)
1032
29.0k
      continue;
1033
35.1k
    if (jtab[i].magic == magic)
1034
29.0k
      break;
1035
35.1k
  }
1036
      /* If we did not find a matching entry something is wrong.  */
1037
29.0k
      if (i < 0)
1038
0
  abort ();
1039
1040
      /* Create the .text section.  */
1041
29.0k
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1042
29.0k
      if (text == NULL)
1043
0
  goto error_return;
1044
1045
      /* Copy in the jump code.  */
1046
29.0k
      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
3.96k
      if (magic == AMD64MAGIC)
1064
3.96k
  {
1065
3.96k
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1066
3.96k
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1067
3.96k
              imp_index);
1068
3.96k
  }
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
29.0k
      pe_ILF_save_relocs (&vars, text);
1076
29.0k
      break;
1077
1078
20.5k
    case IMPORT_DATA:
1079
35.7k
    case IMPORT_CONST:
1080
35.7k
      break;
1081
1082
0
    default:
1083
      /* XXX code not yet written.  */
1084
0
      abort ();
1085
64.8k
    }
1086
1087
  /* Now create a symbol describing the imported value.  */
1088
64.8k
  switch (import_type)
1089
64.8k
    {
1090
29.0k
    case IMPORT_CODE:
1091
29.0k
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1092
29.0k
          BSF_NOT_AT_END | BSF_FUNCTION);
1093
1094
29.0k
      break;
1095
1096
20.5k
    case IMPORT_DATA:
1097
      /* Nothing to do here.  */
1098
20.5k
      break;
1099
1100
15.1k
    case IMPORT_CONST:
1101
15.1k
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1102
15.1k
      break;
1103
1104
0
    default:
1105
      /* XXX code not yet written.  */
1106
0
      abort ();
1107
64.8k
    }
1108
1109
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1110
64.8k
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1111
64.8k
  if (ptr)
1112
9.10k
    *ptr = 0;
1113
64.8k
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1114
64.8k
  if (ptr)
1115
9.10k
    *ptr = '.';
1116
1117
  /* Initialise the bfd.  */
1118
64.8k
  memset (&internal_f, 0, sizeof (internal_f));
1119
1120
64.8k
  internal_f.f_magic  = magic;
1121
64.8k
  internal_f.f_symptr = 0;
1122
64.8k
  internal_f.f_nsyms  = 0;
1123
64.8k
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1124
1125
64.8k
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1126
64.8k
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1127
0
    goto error_return;
1128
1129
64.8k
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1130
0
    goto error_return;
1131
1132
64.8k
  obj_pe (abfd) = true;
1133
#ifdef THUMBPEMAGIC
1134
16.3k
  if (vars.magic == THUMBPEMAGIC)
1135
    /* Stop some linker warnings about thumb code not supporting
1136
       interworking.  */
1137
5.06k
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1138
#endif
1139
1140
  /* Switch from file contents to memory contents.  */
1141
64.8k
  bfd_cache_close (abfd);
1142
1143
64.8k
  abfd->iostream = (void *) vars.bim;
1144
64.8k
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1145
64.8k
  abfd->iovec = &_bfd_memory_iovec;
1146
64.8k
  abfd->where = 0;
1147
64.8k
  abfd->origin = 0;
1148
64.8k
  abfd->size = 0;
1149
64.8k
  obj_sym_filepos (abfd) = 0;
1150
1151
  /* Point the bfd at the symbol table.  */
1152
64.8k
  obj_symbols (abfd) = vars.sym_cache;
1153
64.8k
  abfd->symcount = vars.sym_index;
1154
1155
64.8k
  obj_raw_syments (abfd) = vars.native_syms;
1156
64.8k
  obj_raw_syment_count (abfd) = vars.sym_index;
1157
64.8k
  obj_coff_keep_raw_syms (abfd) = true;
1158
1159
64.8k
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1160
64.8k
  obj_coff_keep_syms (abfd) = true;
1161
1162
64.8k
  obj_convert (abfd) = vars.sym_table;
1163
64.8k
  obj_conv_table_size (abfd) = vars.sym_index;
1164
1165
64.8k
  obj_coff_strings (abfd) = vars.string_table;
1166
64.8k
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1167
64.8k
  obj_coff_keep_strings (abfd) = true;
1168
1169
64.8k
  return true;
1170
1171
3.33k
 error_return:
1172
3.33k
  free (vars.bim->buffer);
1173
3.33k
  free (vars.bim);
1174
3.33k
  return false;
1175
64.8k
}
pei-i386.c:pe_ILF_build_a_bfd
Line
Count
Source
799
13.0k
{
800
13.0k
  bfd_byte *       ptr;
801
13.0k
  pe_ILF_vars      vars;
802
13.0k
  struct internal_filehdr  internal_f;
803
13.0k
  unsigned int       import_type;
804
13.0k
  unsigned int       import_name_type;
805
13.0k
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
806
13.0k
  coff_symbol_type **    imp_sym;
807
13.0k
  unsigned int       imp_index;
808
13.0k
  intptr_t alignment;
809
810
  /* Decode and verify the types field of the ILF structure.  */
811
13.0k
  import_type = types & 0x3;
812
13.0k
  import_name_type = (types & 0x1c) >> 2;
813
814
13.0k
  switch (import_type)
815
13.0k
    {
816
4.47k
    case IMPORT_CODE:
817
10.4k
    case IMPORT_DATA:
818
12.6k
    case IMPORT_CONST:
819
12.6k
      break;
820
821
416
    default:
822
      /* xgettext:c-format */
823
416
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
824
416
        abfd, import_type);
825
416
      return false;
826
13.0k
    }
827
828
12.6k
  switch (import_name_type)
829
12.6k
    {
830
3.49k
    case IMPORT_ORDINAL:
831
4.91k
    case IMPORT_NAME:
832
7.87k
    case IMPORT_NAME_NOPREFIX:
833
10.4k
    case IMPORT_NAME_UNDECORATE:
834
10.4k
      import_name = symbol_name;
835
10.4k
      break;
836
837
1.70k
    case IMPORT_NAME_EXPORTAS:
838
1.70k
      if (!import_name || !import_name[0])
839
1.02k
  {
840
1.02k
    _bfd_error_handler (_("%pB: missing import name for "
841
1.02k
        "IMPORT_NAME_EXPORTAS for %s"),
842
1.02k
            abfd, symbol_name);
843
1.02k
    return false;
844
1.02k
  }
845
677
      break;
846
847
677
    default:
848
      /* xgettext:c-format */
849
415
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
850
415
        abfd, import_name_type);
851
415
      return false;
852
12.6k
    }
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
11.1k
  vars.bim
862
11.1k
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
863
11.1k
  if (vars.bim == NULL)
864
0
    return false;
865
866
11.1k
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
867
11.1k
  vars.bim->buffer = ptr;
868
11.1k
  vars.bim->size   = ILF_DATA_SIZE;
869
11.1k
  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
11.1k
  vars.sym_cache = (coff_symbol_type *) ptr;
875
11.1k
  vars.sym_ptr   = (coff_symbol_type *) ptr;
876
11.1k
  vars.sym_index = 0;
877
11.1k
  ptr += SIZEOF_ILF_SYMS;
878
879
11.1k
  vars.sym_table = (unsigned int *) ptr;
880
11.1k
  vars.table_ptr = (unsigned int *) ptr;
881
11.1k
  ptr += SIZEOF_ILF_SYM_TABLE;
882
883
11.1k
  vars.native_syms = (combined_entry_type *) ptr;
884
11.1k
  vars.native_ptr  = (combined_entry_type *) ptr;
885
11.1k
  ptr += SIZEOF_ILF_NATIVE_SYMS;
886
887
11.1k
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
888
11.1k
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
889
11.1k
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
890
891
11.1k
  vars.esym_table = (SYMENT *) ptr;
892
11.1k
  vars.esym_ptr   = (SYMENT *) ptr;
893
11.1k
  ptr += SIZEOF_ILF_EXT_SYMS;
894
895
11.1k
  vars.reltab   = (arelent *) ptr;
896
11.1k
  vars.relcount = 0;
897
11.1k
  ptr += SIZEOF_ILF_RELOCS;
898
899
11.1k
  vars.int_reltab  = (struct internal_reloc *) ptr;
900
11.1k
  ptr += SIZEOF_ILF_INT_RELOCS;
901
902
11.1k
  vars.string_table = (char *) ptr;
903
11.1k
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
904
11.1k
  ptr += SIZEOF_ILF_STRINGS;
905
11.1k
  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
11.1k
#if GCC_VERSION >= 3000
915
11.1k
  alignment = __alignof__ (struct coff_section_tdata);
916
#else
917
  alignment = 8;
918
#endif
919
11.1k
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
920
921
11.1k
  vars.data = ptr;
922
11.1k
  vars.abfd = abfd;
923
11.1k
  vars.sec_index = 0;
924
11.1k
  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
11.1k
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
934
11.1k
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
935
11.1k
  if (id4 == NULL || id5 == NULL)
936
0
    goto error_return;
937
938
  /* Fill in the contents of these sections.  */
939
11.1k
  if (import_name_type == IMPORT_ORDINAL)
940
3.49k
    {
941
3.49k
      if (ordinal == 0)
942
  /* See PR 20907 for a reproducer.  */
943
418
  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
3.07k
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
953
3.07k
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
954
3.07k
#endif
955
3.07k
    }
956
7.68k
  else
957
7.68k
    {
958
7.68k
      char *symbol;
959
7.68k
      unsigned int len;
960
961
      /* Create .idata$6 - the Hint Name Table.  */
962
7.68k
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
963
7.68k
      if (id6 == NULL)
964
0
  goto error_return;
965
966
      /* If necessary, trim the import symbol name.  */
967
7.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
7.68k
      if (import_name_type != IMPORT_NAME
977
7.68k
    && import_name_type != IMPORT_NAME_EXPORTAS)
978
5.58k
  {
979
5.58k
    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.58k
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
984
5.58k
        || c == '@' || c == '?')
985
1.95k
      symbol++;
986
5.58k
  }
987
988
7.68k
      len = strlen (symbol);
989
7.68k
      if (import_name_type == IMPORT_NAME_UNDECORATE)
990
2.62k
  {
991
    /* Truncate at the first '@'.  */
992
2.62k
    char *at = strchr (symbol, '@');
993
994
2.62k
    if (at != NULL)
995
906
      len = at - symbol;
996
2.62k
  }
997
998
7.68k
      id6->contents[0] = ordinal & 0xff;
999
7.68k
      id6->contents[1] = ordinal >> 8;
1000
1001
7.68k
      memcpy ((char *) id6->contents + 2, symbol, len);
1002
7.68k
      id6->contents[len + 2] = '\0';
1003
7.68k
    }
1004
1005
10.7k
  if (import_name_type != IMPORT_ORDINAL)
1006
7.68k
    {
1007
7.68k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1008
7.68k
      pe_ILF_save_relocs (&vars, id4);
1009
1010
7.68k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1011
7.68k
      pe_ILF_save_relocs (&vars, id5);
1012
7.68k
    }
1013
1014
  /* Create an import symbol.  */
1015
10.7k
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1016
10.7k
  imp_sym   = vars.sym_ptr_ptr - 1;
1017
10.7k
  imp_index = vars.sym_index - 1;
1018
1019
  /* Create extra sections depending upon the type of import we are
1020
     dealing with.  */
1021
10.7k
  switch (import_type)
1022
10.7k
    {
1023
0
      int i;
1024
1025
3.95k
    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.90k
      for (i = NUM_ENTRIES (jtab); i--;)
1030
7.90k
  {
1031
7.90k
    if (jtab[i].size == 0)
1032
3.95k
      continue;
1033
3.95k
    if (jtab[i].magic == magic)
1034
3.95k
      break;
1035
3.95k
  }
1036
      /* If we did not find a matching entry something is wrong.  */
1037
3.95k
      if (i < 0)
1038
0
  abort ();
1039
1040
      /* Create the .text section.  */
1041
3.95k
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1042
3.95k
      if (text == NULL)
1043
0
  goto error_return;
1044
1045
      /* Copy in the jump code.  */
1046
3.95k
      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.95k
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1072
3.95k
            BFD_RELOC_32, (asymbol **) imp_sym,
1073
3.95k
            imp_index);
1074
1075
3.95k
      pe_ILF_save_relocs (&vars, text);
1076
3.95k
      break;
1077
1078
4.84k
    case IMPORT_DATA:
1079
6.80k
    case IMPORT_CONST:
1080
6.80k
      break;
1081
1082
0
    default:
1083
      /* XXX code not yet written.  */
1084
0
      abort ();
1085
10.7k
    }
1086
1087
  /* Now create a symbol describing the imported value.  */
1088
10.7k
  switch (import_type)
1089
10.7k
    {
1090
3.95k
    case IMPORT_CODE:
1091
3.95k
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1092
3.95k
          BSF_NOT_AT_END | BSF_FUNCTION);
1093
1094
3.95k
      break;
1095
1096
4.84k
    case IMPORT_DATA:
1097
      /* Nothing to do here.  */
1098
4.84k
      break;
1099
1100
1.95k
    case IMPORT_CONST:
1101
1.95k
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1102
1.95k
      break;
1103
1104
0
    default:
1105
      /* XXX code not yet written.  */
1106
0
      abort ();
1107
10.7k
    }
1108
1109
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1110
10.7k
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1111
10.7k
  if (ptr)
1112
1.44k
    *ptr = 0;
1113
10.7k
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1114
10.7k
  if (ptr)
1115
1.44k
    *ptr = '.';
1116
1117
  /* Initialise the bfd.  */
1118
10.7k
  memset (&internal_f, 0, sizeof (internal_f));
1119
1120
10.7k
  internal_f.f_magic  = magic;
1121
10.7k
  internal_f.f_symptr = 0;
1122
10.7k
  internal_f.f_nsyms  = 0;
1123
10.7k
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1124
1125
10.7k
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1126
10.7k
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1127
0
    goto error_return;
1128
1129
10.7k
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1130
0
    goto error_return;
1131
1132
10.7k
  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
10.7k
  bfd_cache_close (abfd);
1142
1143
10.7k
  abfd->iostream = (void *) vars.bim;
1144
10.7k
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1145
10.7k
  abfd->iovec = &_bfd_memory_iovec;
1146
10.7k
  abfd->where = 0;
1147
10.7k
  abfd->origin = 0;
1148
10.7k
  abfd->size = 0;
1149
10.7k
  obj_sym_filepos (abfd) = 0;
1150
1151
  /* Point the bfd at the symbol table.  */
1152
10.7k
  obj_symbols (abfd) = vars.sym_cache;
1153
10.7k
  abfd->symcount = vars.sym_index;
1154
1155
10.7k
  obj_raw_syments (abfd) = vars.native_syms;
1156
10.7k
  obj_raw_syment_count (abfd) = vars.sym_index;
1157
10.7k
  obj_coff_keep_raw_syms (abfd) = true;
1158
1159
10.7k
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1160
10.7k
  obj_coff_keep_syms (abfd) = true;
1161
1162
10.7k
  obj_convert (abfd) = vars.sym_table;
1163
10.7k
  obj_conv_table_size (abfd) = vars.sym_index;
1164
1165
10.7k
  obj_coff_strings (abfd) = vars.string_table;
1166
10.7k
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1167
10.7k
  obj_coff_keep_strings (abfd) = true;
1168
1169
10.7k
  return true;
1170
1171
418
 error_return:
1172
418
  free (vars.bim->buffer);
1173
418
  free (vars.bim);
1174
418
  return false;
1175
10.7k
}
pei-x86_64.c:pe_ILF_build_a_bfd
Line
Count
Source
799
10.5k
{
800
10.5k
  bfd_byte *       ptr;
801
10.5k
  pe_ILF_vars      vars;
802
10.5k
  struct internal_filehdr  internal_f;
803
10.5k
  unsigned int       import_type;
804
10.5k
  unsigned int       import_name_type;
805
10.5k
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
806
10.5k
  coff_symbol_type **    imp_sym;
807
10.5k
  unsigned int       imp_index;
808
10.5k
  intptr_t alignment;
809
810
  /* Decode and verify the types field of the ILF structure.  */
811
10.5k
  import_type = types & 0x3;
812
10.5k
  import_name_type = (types & 0x1c) >> 2;
813
814
10.5k
  switch (import_type)
815
10.5k
    {
816
4.69k
    case IMPORT_CODE:
817
7.93k
    case IMPORT_DATA:
818
10.1k
    case IMPORT_CONST:
819
10.1k
      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
10.5k
    }
827
828
10.1k
  switch (import_name_type)
829
10.1k
    {
830
2.63k
    case IMPORT_ORDINAL:
831
3.88k
    case IMPORT_NAME:
832
5.56k
    case IMPORT_NAME_NOPREFIX:
833
8.35k
    case IMPORT_NAME_UNDECORATE:
834
8.35k
      import_name = symbol_name;
835
8.35k
      break;
836
837
1.52k
    case IMPORT_NAME_EXPORTAS:
838
1.52k
      if (!import_name || !import_name[0])
839
620
  {
840
620
    _bfd_error_handler (_("%pB: missing import name for "
841
620
        "IMPORT_NAME_EXPORTAS for %s"),
842
620
            abfd, symbol_name);
843
620
    return false;
844
620
  }
845
907
      break;
846
847
907
    default:
848
      /* xgettext:c-format */
849
314
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
850
314
        abfd, import_name_type);
851
314
      return false;
852
10.1k
    }
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.26k
  vars.bim
862
9.26k
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
863
9.26k
  if (vars.bim == NULL)
864
0
    return false;
865
866
9.26k
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
867
9.26k
  vars.bim->buffer = ptr;
868
9.26k
  vars.bim->size   = ILF_DATA_SIZE;
869
9.26k
  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.26k
  vars.sym_cache = (coff_symbol_type *) ptr;
875
9.26k
  vars.sym_ptr   = (coff_symbol_type *) ptr;
876
9.26k
  vars.sym_index = 0;
877
9.26k
  ptr += SIZEOF_ILF_SYMS;
878
879
9.26k
  vars.sym_table = (unsigned int *) ptr;
880
9.26k
  vars.table_ptr = (unsigned int *) ptr;
881
9.26k
  ptr += SIZEOF_ILF_SYM_TABLE;
882
883
9.26k
  vars.native_syms = (combined_entry_type *) ptr;
884
9.26k
  vars.native_ptr  = (combined_entry_type *) ptr;
885
9.26k
  ptr += SIZEOF_ILF_NATIVE_SYMS;
886
887
9.26k
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
888
9.26k
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
889
9.26k
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
890
891
9.26k
  vars.esym_table = (SYMENT *) ptr;
892
9.26k
  vars.esym_ptr   = (SYMENT *) ptr;
893
9.26k
  ptr += SIZEOF_ILF_EXT_SYMS;
894
895
9.26k
  vars.reltab   = (arelent *) ptr;
896
9.26k
  vars.relcount = 0;
897
9.26k
  ptr += SIZEOF_ILF_RELOCS;
898
899
9.26k
  vars.int_reltab  = (struct internal_reloc *) ptr;
900
9.26k
  ptr += SIZEOF_ILF_INT_RELOCS;
901
902
9.26k
  vars.string_table = (char *) ptr;
903
9.26k
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
904
9.26k
  ptr += SIZEOF_ILF_STRINGS;
905
9.26k
  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.26k
#if GCC_VERSION >= 3000
915
9.26k
  alignment = __alignof__ (struct coff_section_tdata);
916
#else
917
  alignment = 8;
918
#endif
919
9.26k
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
920
921
9.26k
  vars.data = ptr;
922
9.26k
  vars.abfd = abfd;
923
9.26k
  vars.sec_index = 0;
924
9.26k
  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.26k
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
934
9.26k
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
935
9.26k
  if (id4 == NULL || id5 == NULL)
936
0
    goto error_return;
937
938
  /* Fill in the contents of these sections.  */
939
9.26k
  if (import_name_type == IMPORT_ORDINAL)
940
2.63k
    {
941
2.63k
      if (ordinal == 0)
942
  /* See PR 20907 for a reproducer.  */
943
312
  goto error_return;
944
945
2.32k
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
946
2.32k
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
947
2.32k
      ((unsigned int *) id4->contents)[0] = ordinal;
948
2.32k
      ((unsigned int *) id4->contents)[1] = 0x80000000;
949
2.32k
      ((unsigned int *) id5->contents)[0] = ordinal;
950
2.32k
      ((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
2.32k
    }
956
6.62k
  else
957
6.62k
    {
958
6.62k
      char *symbol;
959
6.62k
      unsigned int len;
960
961
      /* Create .idata$6 - the Hint Name Table.  */
962
6.62k
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
963
6.62k
      if (id6 == NULL)
964
0
  goto error_return;
965
966
      /* If necessary, trim the import symbol name.  */
967
6.62k
      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.62k
      if (import_name_type != IMPORT_NAME
977
6.62k
    && import_name_type != IMPORT_NAME_EXPORTAS)
978
4.47k
  {
979
4.47k
    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.47k
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
984
4.47k
        || c == '@' || c == '?')
985
574
      symbol++;
986
4.47k
  }
987
988
6.62k
      len = strlen (symbol);
989
6.62k
      if (import_name_type == IMPORT_NAME_UNDECORATE)
990
2.78k
  {
991
    /* Truncate at the first '@'.  */
992
2.78k
    char *at = strchr (symbol, '@');
993
994
2.78k
    if (at != NULL)
995
337
      len = at - symbol;
996
2.78k
  }
997
998
6.62k
      id6->contents[0] = ordinal & 0xff;
999
6.62k
      id6->contents[1] = ordinal >> 8;
1000
1001
6.62k
      memcpy ((char *) id6->contents + 2, symbol, len);
1002
6.62k
      id6->contents[len + 2] = '\0';
1003
6.62k
    }
1004
1005
8.94k
  if (import_name_type != IMPORT_ORDINAL)
1006
6.62k
    {
1007
6.62k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1008
6.62k
      pe_ILF_save_relocs (&vars, id4);
1009
1010
6.62k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1011
6.62k
      pe_ILF_save_relocs (&vars, id5);
1012
6.62k
    }
1013
1014
  /* Create an import symbol.  */
1015
8.94k
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1016
8.94k
  imp_sym   = vars.sym_ptr_ptr - 1;
1017
8.94k
  imp_index = vars.sym_index - 1;
1018
1019
  /* Create extra sections depending upon the type of import we are
1020
     dealing with.  */
1021
8.94k
  switch (import_type)
1022
8.94k
    {
1023
0
      int i;
1024
1025
3.96k
    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.93k
      for (i = NUM_ENTRIES (jtab); i--;)
1030
7.93k
  {
1031
7.93k
    if (jtab[i].size == 0)
1032
3.96k
      continue;
1033
3.96k
    if (jtab[i].magic == magic)
1034
3.96k
      break;
1035
3.96k
  }
1036
      /* If we did not find a matching entry something is wrong.  */
1037
3.96k
      if (i < 0)
1038
0
  abort ();
1039
1040
      /* Create the .text section.  */
1041
3.96k
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1042
3.96k
      if (text == NULL)
1043
0
  goto error_return;
1044
1045
      /* Copy in the jump code.  */
1046
3.96k
      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
3.96k
#ifdef AMD64MAGIC
1063
3.96k
      if (magic == AMD64MAGIC)
1064
3.96k
  {
1065
3.96k
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1066
3.96k
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1067
3.96k
              imp_index);
1068
3.96k
  }
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
3.96k
      pe_ILF_save_relocs (&vars, text);
1076
3.96k
      break;
1077
1078
3.13k
    case IMPORT_DATA:
1079
4.98k
    case IMPORT_CONST:
1080
4.98k
      break;
1081
1082
0
    default:
1083
      /* XXX code not yet written.  */
1084
0
      abort ();
1085
8.94k
    }
1086
1087
  /* Now create a symbol describing the imported value.  */
1088
8.94k
  switch (import_type)
1089
8.94k
    {
1090
3.96k
    case IMPORT_CODE:
1091
3.96k
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1092
3.96k
          BSF_NOT_AT_END | BSF_FUNCTION);
1093
1094
3.96k
      break;
1095
1096
3.13k
    case IMPORT_DATA:
1097
      /* Nothing to do here.  */
1098
3.13k
      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
8.94k
    }
1108
1109
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1110
8.94k
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1111
8.94k
  if (ptr)
1112
1.77k
    *ptr = 0;
1113
8.94k
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1114
8.94k
  if (ptr)
1115
1.77k
    *ptr = '.';
1116
1117
  /* Initialise the bfd.  */
1118
8.94k
  memset (&internal_f, 0, sizeof (internal_f));
1119
1120
8.94k
  internal_f.f_magic  = magic;
1121
8.94k
  internal_f.f_symptr = 0;
1122
8.94k
  internal_f.f_nsyms  = 0;
1123
8.94k
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1124
1125
8.94k
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1126
8.94k
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1127
0
    goto error_return;
1128
1129
8.94k
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1130
0
    goto error_return;
1131
1132
8.94k
  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.94k
  bfd_cache_close (abfd);
1142
1143
8.94k
  abfd->iostream = (void *) vars.bim;
1144
8.94k
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1145
8.94k
  abfd->iovec = &_bfd_memory_iovec;
1146
8.94k
  abfd->where = 0;
1147
8.94k
  abfd->origin = 0;
1148
8.94k
  abfd->size = 0;
1149
8.94k
  obj_sym_filepos (abfd) = 0;
1150
1151
  /* Point the bfd at the symbol table.  */
1152
8.94k
  obj_symbols (abfd) = vars.sym_cache;
1153
8.94k
  abfd->symcount = vars.sym_index;
1154
1155
8.94k
  obj_raw_syments (abfd) = vars.native_syms;
1156
8.94k
  obj_raw_syment_count (abfd) = vars.sym_index;
1157
8.94k
  obj_coff_keep_raw_syms (abfd) = true;
1158
1159
8.94k
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1160
8.94k
  obj_coff_keep_syms (abfd) = true;
1161
1162
8.94k
  obj_convert (abfd) = vars.sym_table;
1163
8.94k
  obj_conv_table_size (abfd) = vars.sym_index;
1164
1165
8.94k
  obj_coff_strings (abfd) = vars.string_table;
1166
8.94k
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1167
8.94k
  obj_coff_keep_strings (abfd) = true;
1168
1169
8.94k
  return true;
1170
1171
312
 error_return:
1172
312
  free (vars.bim->buffer);
1173
312
  free (vars.bim);
1174
312
  return false;
1175
8.94k
}
pei-aarch64.c:pe_ILF_build_a_bfd
Line
Count
Source
799
9.10k
{
800
9.10k
  bfd_byte *       ptr;
801
9.10k
  pe_ILF_vars      vars;
802
9.10k
  struct internal_filehdr  internal_f;
803
9.10k
  unsigned int       import_type;
804
9.10k
  unsigned int       import_name_type;
805
9.10k
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
806
9.10k
  coff_symbol_type **    imp_sym;
807
9.10k
  unsigned int       imp_index;
808
9.10k
  intptr_t alignment;
809
810
  /* Decode and verify the types field of the ILF structure.  */
811
9.10k
  import_type = types & 0x3;
812
9.10k
  import_name_type = (types & 0x1c) >> 2;
813
814
9.10k
  switch (import_type)
815
9.10k
    {
816
3.90k
    case IMPORT_CODE:
817
6.73k
    case IMPORT_DATA:
818
8.79k
    case IMPORT_CONST:
819
8.79k
      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
9.10k
    }
827
828
8.79k
  switch (import_name_type)
829
8.79k
    {
830
2.33k
    case IMPORT_ORDINAL:
831
3.41k
    case IMPORT_NAME:
832
4.42k
    case IMPORT_NAME_NOPREFIX:
833
6.84k
    case IMPORT_NAME_UNDECORATE:
834
6.84k
      import_name = symbol_name;
835
6.84k
      break;
836
837
1.63k
    case IMPORT_NAME_EXPORTAS:
838
1.63k
      if (!import_name || !import_name[0])
839
524
  {
840
524
    _bfd_error_handler (_("%pB: missing import name for "
841
524
        "IMPORT_NAME_EXPORTAS for %s"),
842
524
            abfd, symbol_name);
843
524
    return false;
844
524
  }
845
1.10k
      break;
846
847
1.10k
    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
8.79k
    }
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.95k
  vars.bim
862
7.95k
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
863
7.95k
  if (vars.bim == NULL)
864
0
    return false;
865
866
7.95k
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
867
7.95k
  vars.bim->buffer = ptr;
868
7.95k
  vars.bim->size   = ILF_DATA_SIZE;
869
7.95k
  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.95k
  vars.sym_cache = (coff_symbol_type *) ptr;
875
7.95k
  vars.sym_ptr   = (coff_symbol_type *) ptr;
876
7.95k
  vars.sym_index = 0;
877
7.95k
  ptr += SIZEOF_ILF_SYMS;
878
879
7.95k
  vars.sym_table = (unsigned int *) ptr;
880
7.95k
  vars.table_ptr = (unsigned int *) ptr;
881
7.95k
  ptr += SIZEOF_ILF_SYM_TABLE;
882
883
7.95k
  vars.native_syms = (combined_entry_type *) ptr;
884
7.95k
  vars.native_ptr  = (combined_entry_type *) ptr;
885
7.95k
  ptr += SIZEOF_ILF_NATIVE_SYMS;
886
887
7.95k
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
888
7.95k
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
889
7.95k
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
890
891
7.95k
  vars.esym_table = (SYMENT *) ptr;
892
7.95k
  vars.esym_ptr   = (SYMENT *) ptr;
893
7.95k
  ptr += SIZEOF_ILF_EXT_SYMS;
894
895
7.95k
  vars.reltab   = (arelent *) ptr;
896
7.95k
  vars.relcount = 0;
897
7.95k
  ptr += SIZEOF_ILF_RELOCS;
898
899
7.95k
  vars.int_reltab  = (struct internal_reloc *) ptr;
900
7.95k
  ptr += SIZEOF_ILF_INT_RELOCS;
901
902
7.95k
  vars.string_table = (char *) ptr;
903
7.95k
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
904
7.95k
  ptr += SIZEOF_ILF_STRINGS;
905
7.95k
  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.95k
#if GCC_VERSION >= 3000
915
7.95k
  alignment = __alignof__ (struct coff_section_tdata);
916
#else
917
  alignment = 8;
918
#endif
919
7.95k
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
920
921
7.95k
  vars.data = ptr;
922
7.95k
  vars.abfd = abfd;
923
7.95k
  vars.sec_index = 0;
924
7.95k
  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.95k
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
934
7.95k
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
935
7.95k
  if (id4 == NULL || id5 == NULL)
936
0
    goto error_return;
937
938
  /* Fill in the contents of these sections.  */
939
7.95k
  if (import_name_type == IMPORT_ORDINAL)
940
2.33k
    {
941
2.33k
      if (ordinal == 0)
942
  /* See PR 20907 for a reproducer.  */
943
317
  goto error_return;
944
945
2.02k
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
946
2.02k
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
947
2.02k
      ((unsigned int *) id4->contents)[0] = ordinal;
948
2.02k
      ((unsigned int *) id4->contents)[1] = 0x80000000;
949
2.02k
      ((unsigned int *) id5->contents)[0] = ordinal;
950
2.02k
      ((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
2.02k
    }
956
5.61k
  else
957
5.61k
    {
958
5.61k
      char *symbol;
959
5.61k
      unsigned int len;
960
961
      /* Create .idata$6 - the Hint Name Table.  */
962
5.61k
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
963
5.61k
      if (id6 == NULL)
964
0
  goto error_return;
965
966
      /* If necessary, trim the import symbol name.  */
967
5.61k
      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.61k
      if (import_name_type != IMPORT_NAME
977
5.61k
    && import_name_type != IMPORT_NAME_EXPORTAS)
978
3.43k
  {
979
3.43k
    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.43k
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
984
3.43k
        || c == '@' || c == '?')
985
475
      symbol++;
986
3.43k
  }
987
988
5.61k
      len = strlen (symbol);
989
5.61k
      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
573
      len = at - symbol;
996
2.42k
  }
997
998
5.61k
      id6->contents[0] = ordinal & 0xff;
999
5.61k
      id6->contents[1] = ordinal >> 8;
1000
1001
5.61k
      memcpy ((char *) id6->contents + 2, symbol, len);
1002
5.61k
      id6->contents[len + 2] = '\0';
1003
5.61k
    }
1004
1005
7.63k
  if (import_name_type != IMPORT_ORDINAL)
1006
5.61k
    {
1007
5.61k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1008
5.61k
      pe_ILF_save_relocs (&vars, id4);
1009
1010
5.61k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1011
5.61k
      pe_ILF_save_relocs (&vars, id5);
1012
5.61k
    }
1013
1014
  /* Create an import symbol.  */
1015
7.63k
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1016
7.63k
  imp_sym   = vars.sym_ptr_ptr - 1;
1017
7.63k
  imp_index = vars.sym_index - 1;
1018
1019
  /* Create extra sections depending upon the type of import we are
1020
     dealing with.  */
1021
7.63k
  switch (import_type)
1022
7.63k
    {
1023
0
      int i;
1024
1025
3.37k
    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
6.74k
      for (i = NUM_ENTRIES (jtab); i--;)
1030
6.74k
  {
1031
6.74k
    if (jtab[i].size == 0)
1032
3.37k
      continue;
1033
3.37k
    if (jtab[i].magic == magic)
1034
3.37k
      break;
1035
3.37k
  }
1036
      /* If we did not find a matching entry something is wrong.  */
1037
3.37k
      if (i < 0)
1038
0
  abort ();
1039
1040
      /* Create the .text section.  */
1041
3.37k
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1042
3.37k
      if (text == NULL)
1043
0
  goto error_return;
1044
1045
      /* Copy in the jump code.  */
1046
3.37k
      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.37k
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1072
3.37k
            BFD_RELOC_32, (asymbol **) imp_sym,
1073
3.37k
            imp_index);
1074
1075
3.37k
      pe_ILF_save_relocs (&vars, text);
1076
3.37k
      break;
1077
1078
2.62k
    case IMPORT_DATA:
1079
4.26k
    case IMPORT_CONST:
1080
4.26k
      break;
1081
1082
0
    default:
1083
      /* XXX code not yet written.  */
1084
0
      abort ();
1085
7.63k
    }
1086
1087
  /* Now create a symbol describing the imported value.  */
1088
7.63k
  switch (import_type)
1089
7.63k
    {
1090
3.37k
    case IMPORT_CODE:
1091
3.37k
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1092
3.37k
          BSF_NOT_AT_END | BSF_FUNCTION);
1093
1094
3.37k
      break;
1095
1096
2.62k
    case IMPORT_DATA:
1097
      /* Nothing to do here.  */
1098
2.62k
      break;
1099
1100
1.64k
    case IMPORT_CONST:
1101
1.64k
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1102
1.64k
      break;
1103
1104
0
    default:
1105
      /* XXX code not yet written.  */
1106
0
      abort ();
1107
7.63k
    }
1108
1109
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1110
7.63k
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1111
7.63k
  if (ptr)
1112
1.34k
    *ptr = 0;
1113
7.63k
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1114
7.63k
  if (ptr)
1115
1.34k
    *ptr = '.';
1116
1117
  /* Initialise the bfd.  */
1118
7.63k
  memset (&internal_f, 0, sizeof (internal_f));
1119
1120
7.63k
  internal_f.f_magic  = magic;
1121
7.63k
  internal_f.f_symptr = 0;
1122
7.63k
  internal_f.f_nsyms  = 0;
1123
7.63k
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1124
1125
7.63k
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1126
7.63k
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1127
0
    goto error_return;
1128
1129
7.63k
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1130
0
    goto error_return;
1131
1132
7.63k
  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.63k
  bfd_cache_close (abfd);
1142
1143
7.63k
  abfd->iostream = (void *) vars.bim;
1144
7.63k
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1145
7.63k
  abfd->iovec = &_bfd_memory_iovec;
1146
7.63k
  abfd->where = 0;
1147
7.63k
  abfd->origin = 0;
1148
7.63k
  abfd->size = 0;
1149
7.63k
  obj_sym_filepos (abfd) = 0;
1150
1151
  /* Point the bfd at the symbol table.  */
1152
7.63k
  obj_symbols (abfd) = vars.sym_cache;
1153
7.63k
  abfd->symcount = vars.sym_index;
1154
1155
7.63k
  obj_raw_syments (abfd) = vars.native_syms;
1156
7.63k
  obj_raw_syment_count (abfd) = vars.sym_index;
1157
7.63k
  obj_coff_keep_raw_syms (abfd) = true;
1158
1159
7.63k
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1160
7.63k
  obj_coff_keep_syms (abfd) = true;
1161
1162
7.63k
  obj_convert (abfd) = vars.sym_table;
1163
7.63k
  obj_conv_table_size (abfd) = vars.sym_index;
1164
1165
7.63k
  obj_coff_strings (abfd) = vars.string_table;
1166
7.63k
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1167
7.63k
  obj_coff_keep_strings (abfd) = true;
1168
1169
7.63k
  return true;
1170
1171
317
 error_return:
1172
317
  free (vars.bim->buffer);
1173
317
  free (vars.bim);
1174
317
  return false;
1175
7.63k
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_build_a_bfd
pei-loongarch64.c:pe_ILF_build_a_bfd
Line
Count
Source
799
5.83k
{
800
5.83k
  bfd_byte *       ptr;
801
5.83k
  pe_ILF_vars      vars;
802
5.83k
  struct internal_filehdr  internal_f;
803
5.83k
  unsigned int       import_type;
804
5.83k
  unsigned int       import_name_type;
805
5.83k
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
806
5.83k
  coff_symbol_type **    imp_sym;
807
5.83k
  unsigned int       imp_index;
808
5.83k
  intptr_t alignment;
809
810
  /* Decode and verify the types field of the ILF structure.  */
811
5.83k
  import_type = types & 0x3;
812
5.83k
  import_name_type = (types & 0x1c) >> 2;
813
814
5.83k
  switch (import_type)
815
5.83k
    {
816
2.72k
    case IMPORT_CODE:
817
4.62k
    case IMPORT_DATA:
818
5.62k
    case IMPORT_CONST:
819
5.62k
      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
5.83k
    }
827
828
5.62k
  switch (import_name_type)
829
5.62k
    {
830
1.06k
    case IMPORT_ORDINAL:
831
1.64k
    case IMPORT_NAME:
832
2.42k
    case IMPORT_NAME_NOPREFIX:
833
4.28k
    case IMPORT_NAME_UNDECORATE:
834
4.28k
      import_name = symbol_name;
835
4.28k
      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.62k
    }
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.98k
  vars.bim
862
4.98k
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
863
4.98k
  if (vars.bim == NULL)
864
0
    return false;
865
866
4.98k
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
867
4.98k
  vars.bim->buffer = ptr;
868
4.98k
  vars.bim->size   = ILF_DATA_SIZE;
869
4.98k
  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.98k
  vars.sym_cache = (coff_symbol_type *) ptr;
875
4.98k
  vars.sym_ptr   = (coff_symbol_type *) ptr;
876
4.98k
  vars.sym_index = 0;
877
4.98k
  ptr += SIZEOF_ILF_SYMS;
878
879
4.98k
  vars.sym_table = (unsigned int *) ptr;
880
4.98k
  vars.table_ptr = (unsigned int *) ptr;
881
4.98k
  ptr += SIZEOF_ILF_SYM_TABLE;
882
883
4.98k
  vars.native_syms = (combined_entry_type *) ptr;
884
4.98k
  vars.native_ptr  = (combined_entry_type *) ptr;
885
4.98k
  ptr += SIZEOF_ILF_NATIVE_SYMS;
886
887
4.98k
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
888
4.98k
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
889
4.98k
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
890
891
4.98k
  vars.esym_table = (SYMENT *) ptr;
892
4.98k
  vars.esym_ptr   = (SYMENT *) ptr;
893
4.98k
  ptr += SIZEOF_ILF_EXT_SYMS;
894
895
4.98k
  vars.reltab   = (arelent *) ptr;
896
4.98k
  vars.relcount = 0;
897
4.98k
  ptr += SIZEOF_ILF_RELOCS;
898
899
4.98k
  vars.int_reltab  = (struct internal_reloc *) ptr;
900
4.98k
  ptr += SIZEOF_ILF_INT_RELOCS;
901
902
4.98k
  vars.string_table = (char *) ptr;
903
4.98k
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
904
4.98k
  ptr += SIZEOF_ILF_STRINGS;
905
4.98k
  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.98k
#if GCC_VERSION >= 3000
915
4.98k
  alignment = __alignof__ (struct coff_section_tdata);
916
#else
917
  alignment = 8;
918
#endif
919
4.98k
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
920
921
4.98k
  vars.data = ptr;
922
4.98k
  vars.abfd = abfd;
923
4.98k
  vars.sec_index = 0;
924
4.98k
  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.98k
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
934
4.98k
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
935
4.98k
  if (id4 == NULL || id5 == NULL)
936
0
    goto error_return;
937
938
  /* Fill in the contents of these sections.  */
939
4.98k
  if (import_name_type == IMPORT_ORDINAL)
940
1.06k
    {
941
1.06k
      if (ordinal == 0)
942
  /* See PR 20907 for a reproducer.  */
943
216
  goto error_return;
944
945
853
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
946
853
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
947
853
      ((unsigned int *) id4->contents)[0] = ordinal;
948
853
      ((unsigned int *) id4->contents)[1] = 0x80000000;
949
853
      ((unsigned int *) id5->contents)[0] = ordinal;
950
853
      ((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
853
    }
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.63k
  {
979
2.63k
    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.63k
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
984
2.63k
        || c == '@' || c == '?')
985
1.04k
      symbol++;
986
2.63k
  }
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
573
      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.77k
  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.77k
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1016
4.77k
  imp_sym   = vars.sym_ptr_ptr - 1;
1017
4.77k
  imp_index = vars.sym_index - 1;
1018
1019
  /* Create extra sections depending upon the type of import we are
1020
     dealing with.  */
1021
4.77k
  switch (import_type)
1022
4.77k
    {
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.36k
    case IMPORT_CONST:
1080
2.36k
      break;
1081
1082
0
    default:
1083
      /* XXX code not yet written.  */
1084
0
      abort ();
1085
4.77k
    }
1086
1087
  /* Now create a symbol describing the imported value.  */
1088
4.77k
  switch (import_type)
1089
4.77k
    {
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
680
    case IMPORT_CONST:
1101
680
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1102
680
      break;
1103
1104
0
    default:
1105
      /* XXX code not yet written.  */
1106
0
      abort ();
1107
4.77k
    }
1108
1109
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1110
4.77k
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1111
4.77k
  if (ptr)
1112
807
    *ptr = 0;
1113
4.77k
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1114
4.77k
  if (ptr)
1115
807
    *ptr = '.';
1116
1117
  /* Initialise the bfd.  */
1118
4.77k
  memset (&internal_f, 0, sizeof (internal_f));
1119
1120
4.77k
  internal_f.f_magic  = magic;
1121
4.77k
  internal_f.f_symptr = 0;
1122
4.77k
  internal_f.f_nsyms  = 0;
1123
4.77k
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1124
1125
4.77k
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1126
4.77k
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1127
0
    goto error_return;
1128
1129
4.77k
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1130
0
    goto error_return;
1131
1132
4.77k
  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.77k
  bfd_cache_close (abfd);
1142
1143
4.77k
  abfd->iostream = (void *) vars.bim;
1144
4.77k
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1145
4.77k
  abfd->iovec = &_bfd_memory_iovec;
1146
4.77k
  abfd->where = 0;
1147
4.77k
  abfd->origin = 0;
1148
4.77k
  abfd->size = 0;
1149
4.77k
  obj_sym_filepos (abfd) = 0;
1150
1151
  /* Point the bfd at the symbol table.  */
1152
4.77k
  obj_symbols (abfd) = vars.sym_cache;
1153
4.77k
  abfd->symcount = vars.sym_index;
1154
1155
4.77k
  obj_raw_syments (abfd) = vars.native_syms;
1156
4.77k
  obj_raw_syment_count (abfd) = vars.sym_index;
1157
4.77k
  obj_coff_keep_raw_syms (abfd) = true;
1158
1159
4.77k
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1160
4.77k
  obj_coff_keep_syms (abfd) = true;
1161
1162
4.77k
  obj_convert (abfd) = vars.sym_table;
1163
4.77k
  obj_conv_table_size (abfd) = vars.sym_index;
1164
1165
4.77k
  obj_coff_strings (abfd) = vars.string_table;
1166
4.77k
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1167
4.77k
  obj_coff_keep_strings (abfd) = true;
1168
1169
4.77k
  return true;
1170
1171
216
 error_return:
1172
216
  free (vars.bim->buffer);
1173
216
  free (vars.bim);
1174
216
  return false;
1175
4.77k
}
pei-riscv64.c:pe_ILF_build_a_bfd
Line
Count
Source
799
8.44k
{
800
8.44k
  bfd_byte *       ptr;
801
8.44k
  pe_ILF_vars      vars;
802
8.44k
  struct internal_filehdr  internal_f;
803
8.44k
  unsigned int       import_type;
804
8.44k
  unsigned int       import_name_type;
805
8.44k
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
806
8.44k
  coff_symbol_type **    imp_sym;
807
8.44k
  unsigned int       imp_index;
808
8.44k
  intptr_t alignment;
809
810
  /* Decode and verify the types field of the ILF structure.  */
811
8.44k
  import_type = types & 0x3;
812
8.44k
  import_name_type = (types & 0x1c) >> 2;
813
814
8.44k
  switch (import_type)
815
8.44k
    {
816
2.69k
    case IMPORT_CODE:
817
5.05k
    case IMPORT_DATA:
818
8.13k
    case IMPORT_CONST:
819
8.13k
      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.44k
    }
827
828
8.13k
  switch (import_name_type)
829
8.13k
    {
830
2.00k
    case IMPORT_ORDINAL:
831
2.67k
    case IMPORT_NAME:
832
4.52k
    case IMPORT_NAME_NOPREFIX:
833
6.25k
    case IMPORT_NAME_UNDECORATE:
834
6.25k
      import_name = symbol_name;
835
6.25k
      break;
836
837
1.66k
    case IMPORT_NAME_EXPORTAS:
838
1.66k
      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
1.24k
      break;
846
847
1.24k
    default:
848
      /* xgettext:c-format */
849
212
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
850
212
        abfd, import_name_type);
851
212
      return false;
852
8.13k
    }
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.49k
  vars.bim
862
7.49k
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
863
7.49k
  if (vars.bim == NULL)
864
0
    return false;
865
866
7.49k
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
867
7.49k
  vars.bim->buffer = ptr;
868
7.49k
  vars.bim->size   = ILF_DATA_SIZE;
869
7.49k
  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.49k
  vars.sym_cache = (coff_symbol_type *) ptr;
875
7.49k
  vars.sym_ptr   = (coff_symbol_type *) ptr;
876
7.49k
  vars.sym_index = 0;
877
7.49k
  ptr += SIZEOF_ILF_SYMS;
878
879
7.49k
  vars.sym_table = (unsigned int *) ptr;
880
7.49k
  vars.table_ptr = (unsigned int *) ptr;
881
7.49k
  ptr += SIZEOF_ILF_SYM_TABLE;
882
883
7.49k
  vars.native_syms = (combined_entry_type *) ptr;
884
7.49k
  vars.native_ptr  = (combined_entry_type *) ptr;
885
7.49k
  ptr += SIZEOF_ILF_NATIVE_SYMS;
886
887
7.49k
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
888
7.49k
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
889
7.49k
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
890
891
7.49k
  vars.esym_table = (SYMENT *) ptr;
892
7.49k
  vars.esym_ptr   = (SYMENT *) ptr;
893
7.49k
  ptr += SIZEOF_ILF_EXT_SYMS;
894
895
7.49k
  vars.reltab   = (arelent *) ptr;
896
7.49k
  vars.relcount = 0;
897
7.49k
  ptr += SIZEOF_ILF_RELOCS;
898
899
7.49k
  vars.int_reltab  = (struct internal_reloc *) ptr;
900
7.49k
  ptr += SIZEOF_ILF_INT_RELOCS;
901
902
7.49k
  vars.string_table = (char *) ptr;
903
7.49k
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
904
7.49k
  ptr += SIZEOF_ILF_STRINGS;
905
7.49k
  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.49k
#if GCC_VERSION >= 3000
915
7.49k
  alignment = __alignof__ (struct coff_section_tdata);
916
#else
917
  alignment = 8;
918
#endif
919
7.49k
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
920
921
7.49k
  vars.data = ptr;
922
7.49k
  vars.abfd = abfd;
923
7.49k
  vars.sec_index = 0;
924
7.49k
  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.49k
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
934
7.49k
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
935
7.49k
  if (id4 == NULL || id5 == NULL)
936
0
    goto error_return;
937
938
  /* Fill in the contents of these sections.  */
939
7.49k
  if (import_name_type == IMPORT_ORDINAL)
940
2.00k
    {
941
2.00k
      if (ordinal == 0)
942
  /* See PR 20907 for a reproducer.  */
943
212
  goto error_return;
944
945
1.79k
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
946
1.79k
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
947
1.79k
      ((unsigned int *) id4->contents)[0] = ordinal;
948
1.79k
      ((unsigned int *) id4->contents)[1] = 0x80000000;
949
1.79k
      ((unsigned int *) id5->contents)[0] = ordinal;
950
1.79k
      ((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.79k
    }
956
5.49k
  else
957
5.49k
    {
958
5.49k
      char *symbol;
959
5.49k
      unsigned int len;
960
961
      /* Create .idata$6 - the Hint Name Table.  */
962
5.49k
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
963
5.49k
      if (id6 == NULL)
964
0
  goto error_return;
965
966
      /* If necessary, trim the import symbol name.  */
967
5.49k
      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.49k
      if (import_name_type != IMPORT_NAME
977
5.49k
    && import_name_type != IMPORT_NAME_EXPORTAS)
978
3.57k
  {
979
3.57k
    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.57k
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
984
3.57k
        || c == '@' || c == '?')
985
710
      symbol++;
986
3.57k
  }
987
988
5.49k
      len = strlen (symbol);
989
5.49k
      if (import_name_type == IMPORT_NAME_UNDECORATE)
990
1.73k
  {
991
    /* Truncate at the first '@'.  */
992
1.73k
    char *at = strchr (symbol, '@');
993
994
1.73k
    if (at != NULL)
995
673
      len = at - symbol;
996
1.73k
  }
997
998
5.49k
      id6->contents[0] = ordinal & 0xff;
999
5.49k
      id6->contents[1] = ordinal >> 8;
1000
1001
5.49k
      memcpy ((char *) id6->contents + 2, symbol, len);
1002
5.49k
      id6->contents[len + 2] = '\0';
1003
5.49k
    }
1004
1005
7.28k
  if (import_name_type != IMPORT_ORDINAL)
1006
5.49k
    {
1007
5.49k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1008
5.49k
      pe_ILF_save_relocs (&vars, id4);
1009
1010
5.49k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1011
5.49k
      pe_ILF_save_relocs (&vars, id5);
1012
5.49k
    }
1013
1014
  /* Create an import symbol.  */
1015
7.28k
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1016
7.28k
  imp_sym   = vars.sym_ptr_ptr - 1;
1017
7.28k
  imp_index = vars.sym_index - 1;
1018
1019
  /* Create extra sections depending upon the type of import we are
1020
     dealing with.  */
1021
7.28k
  switch (import_type)
1022
7.28k
    {
1023
0
      int i;
1024
1025
2.27k
    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.54k
      for (i = NUM_ENTRIES (jtab); i--;)
1030
4.54k
  {
1031
4.54k
    if (jtab[i].size == 0)
1032
2.27k
      continue;
1033
2.27k
    if (jtab[i].magic == magic)
1034
2.27k
      break;
1035
2.27k
  }
1036
      /* If we did not find a matching entry something is wrong.  */
1037
2.27k
      if (i < 0)
1038
0
  abort ();
1039
1040
      /* Create the .text section.  */
1041
2.27k
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1042
2.27k
      if (text == NULL)
1043
0
  goto error_return;
1044
1045
      /* Copy in the jump code.  */
1046
2.27k
      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.27k
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1072
2.27k
            BFD_RELOC_32, (asymbol **) imp_sym,
1073
2.27k
            imp_index);
1074
1075
2.27k
      pe_ILF_save_relocs (&vars, text);
1076
2.27k
      break;
1077
1078
2.15k
    case IMPORT_DATA:
1079
5.01k
    case IMPORT_CONST:
1080
5.01k
      break;
1081
1082
0
    default:
1083
      /* XXX code not yet written.  */
1084
0
      abort ();
1085
7.28k
    }
1086
1087
  /* Now create a symbol describing the imported value.  */
1088
7.28k
  switch (import_type)
1089
7.28k
    {
1090
2.27k
    case IMPORT_CODE:
1091
2.27k
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1092
2.27k
          BSF_NOT_AT_END | BSF_FUNCTION);
1093
1094
2.27k
      break;
1095
1096
2.15k
    case IMPORT_DATA:
1097
      /* Nothing to do here.  */
1098
2.15k
      break;
1099
1100
2.86k
    case IMPORT_CONST:
1101
2.86k
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1102
2.86k
      break;
1103
1104
0
    default:
1105
      /* XXX code not yet written.  */
1106
0
      abort ();
1107
7.28k
    }
1108
1109
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1110
7.28k
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1111
7.28k
  if (ptr)
1112
708
    *ptr = 0;
1113
7.28k
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1114
7.28k
  if (ptr)
1115
708
    *ptr = '.';
1116
1117
  /* Initialise the bfd.  */
1118
7.28k
  memset (&internal_f, 0, sizeof (internal_f));
1119
1120
7.28k
  internal_f.f_magic  = magic;
1121
7.28k
  internal_f.f_symptr = 0;
1122
7.28k
  internal_f.f_nsyms  = 0;
1123
7.28k
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1124
1125
7.28k
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1126
7.28k
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1127
0
    goto error_return;
1128
1129
7.28k
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1130
0
    goto error_return;
1131
1132
7.28k
  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.28k
  bfd_cache_close (abfd);
1142
1143
7.28k
  abfd->iostream = (void *) vars.bim;
1144
7.28k
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1145
7.28k
  abfd->iovec = &_bfd_memory_iovec;
1146
7.28k
  abfd->where = 0;
1147
7.28k
  abfd->origin = 0;
1148
7.28k
  abfd->size = 0;
1149
7.28k
  obj_sym_filepos (abfd) = 0;
1150
1151
  /* Point the bfd at the symbol table.  */
1152
7.28k
  obj_symbols (abfd) = vars.sym_cache;
1153
7.28k
  abfd->symcount = vars.sym_index;
1154
1155
7.28k
  obj_raw_syments (abfd) = vars.native_syms;
1156
7.28k
  obj_raw_syment_count (abfd) = vars.sym_index;
1157
7.28k
  obj_coff_keep_raw_syms (abfd) = true;
1158
1159
7.28k
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1160
7.28k
  obj_coff_keep_syms (abfd) = true;
1161
1162
7.28k
  obj_convert (abfd) = vars.sym_table;
1163
7.28k
  obj_conv_table_size (abfd) = vars.sym_index;
1164
1165
7.28k
  obj_coff_strings (abfd) = vars.string_table;
1166
7.28k
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1167
7.28k
  obj_coff_keep_strings (abfd) = true;
1168
1169
7.28k
  return true;
1170
1171
212
 error_return:
1172
212
  free (vars.bim->buffer);
1173
212
  free (vars.bim);
1174
212
  return false;
1175
7.28k
}
pei-arm-wince.c:pe_ILF_build_a_bfd
Line
Count
Source
799
2.09k
{
800
2.09k
  bfd_byte *       ptr;
801
2.09k
  pe_ILF_vars      vars;
802
2.09k
  struct internal_filehdr  internal_f;
803
2.09k
  unsigned int       import_type;
804
2.09k
  unsigned int       import_name_type;
805
2.09k
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
806
2.09k
  coff_symbol_type **    imp_sym;
807
2.09k
  unsigned int       imp_index;
808
2.09k
  intptr_t alignment;
809
810
  /* Decode and verify the types field of the ILF structure.  */
811
2.09k
  import_type = types & 0x3;
812
2.09k
  import_name_type = (types & 0x1c) >> 2;
813
814
2.09k
  switch (import_type)
815
2.09k
    {
816
1.00k
    case IMPORT_CODE:
817
1.33k
    case IMPORT_DATA:
818
1.67k
    case IMPORT_CONST:
819
1.67k
      break;
820
821
415
    default:
822
      /* xgettext:c-format */
823
415
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
824
415
        abfd, import_type);
825
415
      return false;
826
2.09k
    }
827
828
1.67k
  switch (import_name_type)
829
1.67k
    {
830
757
    case IMPORT_ORDINAL:
831
764
    case IMPORT_NAME:
832
791
    case IMPORT_NAME_NOPREFIX:
833
817
    case IMPORT_NAME_UNDECORATE:
834
817
      import_name = symbol_name;
835
817
      break;
836
837
441
    case IMPORT_NAME_EXPORTAS:
838
441
      if (!import_name || !import_name[0])
839
432
  {
840
432
    _bfd_error_handler (_("%pB: missing import name for "
841
432
        "IMPORT_NAME_EXPORTAS for %s"),
842
432
            abfd, symbol_name);
843
432
    return false;
844
432
  }
845
9
      break;
846
847
417
    default:
848
      /* xgettext:c-format */
849
417
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
850
417
        abfd, import_name_type);
851
417
      return false;
852
1.67k
    }
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
826
  vars.bim
862
826
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
863
826
  if (vars.bim == NULL)
864
0
    return false;
865
866
826
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
867
826
  vars.bim->buffer = ptr;
868
826
  vars.bim->size   = ILF_DATA_SIZE;
869
826
  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
826
  vars.sym_cache = (coff_symbol_type *) ptr;
875
826
  vars.sym_ptr   = (coff_symbol_type *) ptr;
876
826
  vars.sym_index = 0;
877
826
  ptr += SIZEOF_ILF_SYMS;
878
879
826
  vars.sym_table = (unsigned int *) ptr;
880
826
  vars.table_ptr = (unsigned int *) ptr;
881
826
  ptr += SIZEOF_ILF_SYM_TABLE;
882
883
826
  vars.native_syms = (combined_entry_type *) ptr;
884
826
  vars.native_ptr  = (combined_entry_type *) ptr;
885
826
  ptr += SIZEOF_ILF_NATIVE_SYMS;
886
887
826
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
888
826
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
889
826
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
890
891
826
  vars.esym_table = (SYMENT *) ptr;
892
826
  vars.esym_ptr   = (SYMENT *) ptr;
893
826
  ptr += SIZEOF_ILF_EXT_SYMS;
894
895
826
  vars.reltab   = (arelent *) ptr;
896
826
  vars.relcount = 0;
897
826
  ptr += SIZEOF_ILF_RELOCS;
898
899
826
  vars.int_reltab  = (struct internal_reloc *) ptr;
900
826
  ptr += SIZEOF_ILF_INT_RELOCS;
901
902
826
  vars.string_table = (char *) ptr;
903
826
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
904
826
  ptr += SIZEOF_ILF_STRINGS;
905
826
  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
826
#if GCC_VERSION >= 3000
915
826
  alignment = __alignof__ (struct coff_section_tdata);
916
#else
917
  alignment = 8;
918
#endif
919
826
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
920
921
826
  vars.data = ptr;
922
826
  vars.abfd = abfd;
923
826
  vars.sec_index = 0;
924
826
  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
826
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
934
826
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
935
826
  if (id4 == NULL || id5 == NULL)
936
0
    goto error_return;
937
938
  /* Fill in the contents of these sections.  */
939
826
  if (import_name_type == IMPORT_ORDINAL)
940
757
    {
941
757
      if (ordinal == 0)
942
  /* See PR 20907 for a reproducer.  */
943
721
  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
36
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
953
36
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
954
36
#endif
955
36
    }
956
69
  else
957
69
    {
958
69
      char *symbol;
959
69
      unsigned int len;
960
961
      /* Create .idata$6 - the Hint Name Table.  */
962
69
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
963
69
      if (id6 == NULL)
964
0
  goto error_return;
965
966
      /* If necessary, trim the import symbol name.  */
967
69
      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
69
      if (import_name_type != IMPORT_NAME
977
69
    && import_name_type != IMPORT_NAME_EXPORTAS)
978
53
  {
979
53
    char c = symbol[0];
980
981
    /* Check that we don't remove for targets with empty
982
       USER_LABEL_PREFIX the leading underscore.  */
983
53
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
984
53
        || c == '@' || c == '?')
985
13
      symbol++;
986
53
  }
987
988
69
      len = strlen (symbol);
989
69
      if (import_name_type == IMPORT_NAME_UNDECORATE)
990
26
  {
991
    /* Truncate at the first '@'.  */
992
26
    char *at = strchr (symbol, '@');
993
994
26
    if (at != NULL)
995
6
      len = at - symbol;
996
26
  }
997
998
69
      id6->contents[0] = ordinal & 0xff;
999
69
      id6->contents[1] = ordinal >> 8;
1000
1001
69
      memcpy ((char *) id6->contents + 2, symbol, len);
1002
69
      id6->contents[len + 2] = '\0';
1003
69
    }
1004
1005
105
  if (import_name_type != IMPORT_ORDINAL)
1006
69
    {
1007
69
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1008
69
      pe_ILF_save_relocs (&vars, id4);
1009
1010
69
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1011
69
      pe_ILF_save_relocs (&vars, id5);
1012
69
    }
1013
1014
  /* Create an import symbol.  */
1015
105
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1016
105
  imp_sym   = vars.sym_ptr_ptr - 1;
1017
105
  imp_index = vars.sym_index - 1;
1018
1019
  /* Create extra sections depending upon the type of import we are
1020
     dealing with.  */
1021
105
  switch (import_type)
1022
105
    {
1023
0
      int i;
1024
1025
59
    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
155
      for (i = NUM_ENTRIES (jtab); i--;)
1030
155
  {
1031
155
    if (jtab[i].size == 0)
1032
59
      continue;
1033
96
    if (jtab[i].magic == magic)
1034
59
      break;
1035
96
  }
1036
      /* If we did not find a matching entry something is wrong.  */
1037
59
      if (i < 0)
1038
0
  abort ();
1039
1040
      /* Create the .text section.  */
1041
59
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1042
59
      if (text == NULL)
1043
0
  goto error_return;
1044
1045
      /* Copy in the jump code.  */
1046
59
      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
59
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1072
59
            BFD_RELOC_32, (asymbol **) imp_sym,
1073
59
            imp_index);
1074
1075
59
      pe_ILF_save_relocs (&vars, text);
1076
59
      break;
1077
1078
27
    case IMPORT_DATA:
1079
46
    case IMPORT_CONST:
1080
46
      break;
1081
1082
0
    default:
1083
      /* XXX code not yet written.  */
1084
0
      abort ();
1085
105
    }
1086
1087
  /* Now create a symbol describing the imported value.  */
1088
105
  switch (import_type)
1089
105
    {
1090
59
    case IMPORT_CODE:
1091
59
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1092
59
          BSF_NOT_AT_END | BSF_FUNCTION);
1093
1094
59
      break;
1095
1096
27
    case IMPORT_DATA:
1097
      /* Nothing to do here.  */
1098
27
      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
105
    }
1108
1109
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1110
105
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1111
105
  if (ptr)
1112
13
    *ptr = 0;
1113
105
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1114
105
  if (ptr)
1115
13
    *ptr = '.';
1116
1117
  /* Initialise the bfd.  */
1118
105
  memset (&internal_f, 0, sizeof (internal_f));
1119
1120
105
  internal_f.f_magic  = magic;
1121
105
  internal_f.f_symptr = 0;
1122
105
  internal_f.f_nsyms  = 0;
1123
105
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1124
1125
105
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1126
105
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1127
0
    goto error_return;
1128
1129
105
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1130
0
    goto error_return;
1131
1132
105
  obj_pe (abfd) = true;
1133
105
#ifdef THUMBPEMAGIC
1134
105
  if (vars.magic == THUMBPEMAGIC)
1135
    /* Stop some linker warnings about thumb code not supporting
1136
       interworking.  */
1137
37
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1138
105
#endif
1139
1140
  /* Switch from file contents to memory contents.  */
1141
105
  bfd_cache_close (abfd);
1142
1143
105
  abfd->iostream = (void *) vars.bim;
1144
105
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1145
105
  abfd->iovec = &_bfd_memory_iovec;
1146
105
  abfd->where = 0;
1147
105
  abfd->origin = 0;
1148
105
  abfd->size = 0;
1149
105
  obj_sym_filepos (abfd) = 0;
1150
1151
  /* Point the bfd at the symbol table.  */
1152
105
  obj_symbols (abfd) = vars.sym_cache;
1153
105
  abfd->symcount = vars.sym_index;
1154
1155
105
  obj_raw_syments (abfd) = vars.native_syms;
1156
105
  obj_raw_syment_count (abfd) = vars.sym_index;
1157
105
  obj_coff_keep_raw_syms (abfd) = true;
1158
1159
105
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1160
105
  obj_coff_keep_syms (abfd) = true;
1161
1162
105
  obj_convert (abfd) = vars.sym_table;
1163
105
  obj_conv_table_size (abfd) = vars.sym_index;
1164
1165
105
  obj_coff_strings (abfd) = vars.string_table;
1166
105
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1167
105
  obj_coff_keep_strings (abfd) = true;
1168
1169
105
  return true;
1170
1171
721
 error_return:
1172
721
  free (vars.bim->buffer);
1173
721
  free (vars.bim);
1174
721
  return false;
1175
105
}
pei-arm.c:pe_ILF_build_a_bfd
Line
Count
Source
799
18.2k
{
800
18.2k
  bfd_byte *       ptr;
801
18.2k
  pe_ILF_vars      vars;
802
18.2k
  struct internal_filehdr  internal_f;
803
18.2k
  unsigned int       import_type;
804
18.2k
  unsigned int       import_name_type;
805
18.2k
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
806
18.2k
  coff_symbol_type **    imp_sym;
807
18.2k
  unsigned int       imp_index;
808
18.2k
  intptr_t alignment;
809
810
  /* Decode and verify the types field of the ILF structure.  */
811
18.2k
  import_type = types & 0x3;
812
18.2k
  import_name_type = (types & 0x1c) >> 2;
813
814
18.2k
  switch (import_type)
815
18.2k
    {
816
10.4k
    case IMPORT_CODE:
817
13.6k
    case IMPORT_DATA:
818
17.8k
    case IMPORT_CONST:
819
17.8k
      break;
820
821
415
    default:
822
      /* xgettext:c-format */
823
415
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
824
415
        abfd, import_type);
825
415
      return false;
826
18.2k
    }
827
828
17.8k
  switch (import_name_type)
829
17.8k
    {
830
6.33k
    case IMPORT_ORDINAL:
831
7.57k
    case IMPORT_NAME:
832
12.6k
    case IMPORT_NAME_NOPREFIX:
833
15.6k
    case IMPORT_NAME_UNDECORATE:
834
15.6k
      import_name = symbol_name;
835
15.6k
      break;
836
837
1.70k
    case IMPORT_NAME_EXPORTAS:
838
1.70k
      if (!import_name || !import_name[0])
839
432
  {
840
432
    _bfd_error_handler (_("%pB: missing import name for "
841
432
        "IMPORT_NAME_EXPORTAS for %s"),
842
432
            abfd, symbol_name);
843
432
    return false;
844
432
  }
845
1.27k
      break;
846
847
1.27k
    default:
848
      /* xgettext:c-format */
849
417
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
850
417
        abfd, import_name_type);
851
417
      return false;
852
17.8k
    }
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
16.9k
  vars.bim
862
16.9k
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
863
16.9k
  if (vars.bim == NULL)
864
0
    return false;
865
866
16.9k
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
867
16.9k
  vars.bim->buffer = ptr;
868
16.9k
  vars.bim->size   = ILF_DATA_SIZE;
869
16.9k
  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
16.9k
  vars.sym_cache = (coff_symbol_type *) ptr;
875
16.9k
  vars.sym_ptr   = (coff_symbol_type *) ptr;
876
16.9k
  vars.sym_index = 0;
877
16.9k
  ptr += SIZEOF_ILF_SYMS;
878
879
16.9k
  vars.sym_table = (unsigned int *) ptr;
880
16.9k
  vars.table_ptr = (unsigned int *) ptr;
881
16.9k
  ptr += SIZEOF_ILF_SYM_TABLE;
882
883
16.9k
  vars.native_syms = (combined_entry_type *) ptr;
884
16.9k
  vars.native_ptr  = (combined_entry_type *) ptr;
885
16.9k
  ptr += SIZEOF_ILF_NATIVE_SYMS;
886
887
16.9k
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
888
16.9k
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
889
16.9k
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
890
891
16.9k
  vars.esym_table = (SYMENT *) ptr;
892
16.9k
  vars.esym_ptr   = (SYMENT *) ptr;
893
16.9k
  ptr += SIZEOF_ILF_EXT_SYMS;
894
895
16.9k
  vars.reltab   = (arelent *) ptr;
896
16.9k
  vars.relcount = 0;
897
16.9k
  ptr += SIZEOF_ILF_RELOCS;
898
899
16.9k
  vars.int_reltab  = (struct internal_reloc *) ptr;
900
16.9k
  ptr += SIZEOF_ILF_INT_RELOCS;
901
902
16.9k
  vars.string_table = (char *) ptr;
903
16.9k
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
904
16.9k
  ptr += SIZEOF_ILF_STRINGS;
905
16.9k
  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
16.9k
#if GCC_VERSION >= 3000
915
16.9k
  alignment = __alignof__ (struct coff_section_tdata);
916
#else
917
  alignment = 8;
918
#endif
919
16.9k
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
920
921
16.9k
  vars.data = ptr;
922
16.9k
  vars.abfd = abfd;
923
16.9k
  vars.sec_index = 0;
924
16.9k
  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
16.9k
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
934
16.9k
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
935
16.9k
  if (id4 == NULL || id5 == NULL)
936
0
    goto error_return;
937
938
  /* Fill in the contents of these sections.  */
939
16.9k
  if (import_name_type == IMPORT_ORDINAL)
940
6.33k
    {
941
6.33k
      if (ordinal == 0)
942
  /* See PR 20907 for a reproducer.  */
943
721
  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.61k
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
953
5.61k
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
954
5.61k
#endif
955
5.61k
    }
956
10.6k
  else
957
10.6k
    {
958
10.6k
      char *symbol;
959
10.6k
      unsigned int len;
960
961
      /* Create .idata$6 - the Hint Name Table.  */
962
10.6k
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
963
10.6k
      if (id6 == NULL)
964
0
  goto error_return;
965
966
      /* If necessary, trim the import symbol name.  */
967
10.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
10.6k
      if (import_name_type != IMPORT_NAME
977
10.6k
    && import_name_type != IMPORT_NAME_EXPORTAS)
978
8.11k
  {
979
8.11k
    char c = symbol[0];
980
981
    /* Check that we don't remove for targets with empty
982
       USER_LABEL_PREFIX the leading underscore.  */
983
8.11k
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
984
8.11k
        || c == '@' || c == '?')
985
2.85k
      symbol++;
986
8.11k
  }
987
988
10.6k
      len = strlen (symbol);
989
10.6k
      if (import_name_type == IMPORT_NAME_UNDECORATE)
990
3.06k
  {
991
    /* Truncate at the first '@'.  */
992
3.06k
    char *at = strchr (symbol, '@');
993
994
3.06k
    if (at != NULL)
995
471
      len = at - symbol;
996
3.06k
  }
997
998
10.6k
      id6->contents[0] = ordinal & 0xff;
999
10.6k
      id6->contents[1] = ordinal >> 8;
1000
1001
10.6k
      memcpy ((char *) id6->contents + 2, symbol, len);
1002
10.6k
      id6->contents[len + 2] = '\0';
1003
10.6k
    }
1004
1005
16.2k
  if (import_name_type != IMPORT_ORDINAL)
1006
10.6k
    {
1007
10.6k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1008
10.6k
      pe_ILF_save_relocs (&vars, id4);
1009
1010
10.6k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1011
10.6k
      pe_ILF_save_relocs (&vars, id5);
1012
10.6k
    }
1013
1014
  /* Create an import symbol.  */
1015
16.2k
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1016
16.2k
  imp_sym   = vars.sym_ptr_ptr - 1;
1017
16.2k
  imp_index = vars.sym_index - 1;
1018
1019
  /* Create extra sections depending upon the type of import we are
1020
     dealing with.  */
1021
16.2k
  switch (import_type)
1022
16.2k
    {
1023
0
      int i;
1024
1025
9.49k
    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
25.0k
      for (i = NUM_ENTRIES (jtab); i--;)
1030
25.0k
  {
1031
25.0k
    if (jtab[i].size == 0)
1032
9.49k
      continue;
1033
15.5k
    if (jtab[i].magic == magic)
1034
9.49k
      break;
1035
15.5k
  }
1036
      /* If we did not find a matching entry something is wrong.  */
1037
9.49k
      if (i < 0)
1038
0
  abort ();
1039
1040
      /* Create the .text section.  */
1041
9.49k
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1042
9.49k
      if (text == NULL)
1043
0
  goto error_return;
1044
1045
      /* Copy in the jump code.  */
1046
9.49k
      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
9.49k
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1072
9.49k
            BFD_RELOC_32, (asymbol **) imp_sym,
1073
9.49k
            imp_index);
1074
1075
9.49k
      pe_ILF_save_relocs (&vars, text);
1076
9.49k
      break;
1077
1078
2.86k
    case IMPORT_DATA:
1079
6.75k
    case IMPORT_CONST:
1080
6.75k
      break;
1081
1082
0
    default:
1083
      /* XXX code not yet written.  */
1084
0
      abort ();
1085
16.2k
    }
1086
1087
  /* Now create a symbol describing the imported value.  */
1088
16.2k
  switch (import_type)
1089
16.2k
    {
1090
9.49k
    case IMPORT_CODE:
1091
9.49k
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1092
9.49k
          BSF_NOT_AT_END | BSF_FUNCTION);
1093
1094
9.49k
      break;
1095
1096
2.86k
    case IMPORT_DATA:
1097
      /* Nothing to do here.  */
1098
2.86k
      break;
1099
1100
3.89k
    case IMPORT_CONST:
1101
3.89k
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1102
3.89k
      break;
1103
1104
0
    default:
1105
      /* XXX code not yet written.  */
1106
0
      abort ();
1107
16.2k
    }
1108
1109
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1110
16.2k
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1111
16.2k
  if (ptr)
1112
1.80k
    *ptr = 0;
1113
16.2k
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1114
16.2k
  if (ptr)
1115
1.80k
    *ptr = '.';
1116
1117
  /* Initialise the bfd.  */
1118
16.2k
  memset (&internal_f, 0, sizeof (internal_f));
1119
1120
16.2k
  internal_f.f_magic  = magic;
1121
16.2k
  internal_f.f_symptr = 0;
1122
16.2k
  internal_f.f_nsyms  = 0;
1123
16.2k
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1124
1125
16.2k
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1126
16.2k
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1127
0
    goto error_return;
1128
1129
16.2k
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1130
0
    goto error_return;
1131
1132
16.2k
  obj_pe (abfd) = true;
1133
16.2k
#ifdef THUMBPEMAGIC
1134
16.2k
  if (vars.magic == THUMBPEMAGIC)
1135
    /* Stop some linker warnings about thumb code not supporting
1136
       interworking.  */
1137
5.02k
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1138
16.2k
#endif
1139
1140
  /* Switch from file contents to memory contents.  */
1141
16.2k
  bfd_cache_close (abfd);
1142
1143
16.2k
  abfd->iostream = (void *) vars.bim;
1144
16.2k
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1145
16.2k
  abfd->iovec = &_bfd_memory_iovec;
1146
16.2k
  abfd->where = 0;
1147
16.2k
  abfd->origin = 0;
1148
16.2k
  abfd->size = 0;
1149
16.2k
  obj_sym_filepos (abfd) = 0;
1150
1151
  /* Point the bfd at the symbol table.  */
1152
16.2k
  obj_symbols (abfd) = vars.sym_cache;
1153
16.2k
  abfd->symcount = vars.sym_index;
1154
1155
16.2k
  obj_raw_syments (abfd) = vars.native_syms;
1156
16.2k
  obj_raw_syment_count (abfd) = vars.sym_index;
1157
16.2k
  obj_coff_keep_raw_syms (abfd) = true;
1158
1159
16.2k
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1160
16.2k
  obj_coff_keep_syms (abfd) = true;
1161
1162
16.2k
  obj_convert (abfd) = vars.sym_table;
1163
16.2k
  obj_conv_table_size (abfd) = vars.sym_index;
1164
1165
16.2k
  obj_coff_strings (abfd) = vars.string_table;
1166
16.2k
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1167
16.2k
  obj_coff_keep_strings (abfd) = true;
1168
1169
16.2k
  return true;
1170
1171
721
 error_return:
1172
721
  free (vars.bim->buffer);
1173
721
  free (vars.bim);
1174
721
  return false;
1175
16.2k
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_build_a_bfd
pei-sh.c:pe_ILF_build_a_bfd
Line
Count
Source
799
10.9k
{
800
10.9k
  bfd_byte *       ptr;
801
10.9k
  pe_ILF_vars      vars;
802
10.9k
  struct internal_filehdr  internal_f;
803
10.9k
  unsigned int       import_type;
804
10.9k
  unsigned int       import_name_type;
805
10.9k
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
806
10.9k
  coff_symbol_type **    imp_sym;
807
10.9k
  unsigned int       imp_index;
808
10.9k
  intptr_t alignment;
809
810
  /* Decode and verify the types field of the ILF structure.  */
811
10.9k
  import_type = types & 0x3;
812
10.9k
  import_name_type = (types & 0x1c) >> 2;
813
814
10.9k
  switch (import_type)
815
10.9k
    {
816
4.27k
    case IMPORT_CODE:
817
7.83k
    case IMPORT_DATA:
818
10.5k
    case IMPORT_CONST:
819
10.5k
      break;
820
821
369
    default:
822
      /* xgettext:c-format */
823
369
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
824
369
        abfd, import_type);
825
369
      return false;
826
10.9k
    }
827
828
10.5k
  switch (import_name_type)
829
10.5k
    {
830
2.92k
    case IMPORT_ORDINAL:
831
4.04k
    case IMPORT_NAME:
832
6.44k
    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.40k
    case IMPORT_NAME_EXPORTAS:
838
1.40k
      if (!import_name || !import_name[0])
839
625
  {
840
625
    _bfd_error_handler (_("%pB: missing import name for "
841
625
        "IMPORT_NAME_EXPORTAS for %s"),
842
625
            abfd, symbol_name);
843
625
    return false;
844
625
  }
845
778
      break;
846
847
778
    default:
848
      /* xgettext:c-format */
849
413
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
850
413
        abfd, import_name_type);
851
413
      return false;
852
10.5k
    }
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.49k
  vars.bim
862
9.49k
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
863
9.49k
  if (vars.bim == NULL)
864
0
    return false;
865
866
9.49k
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
867
9.49k
  vars.bim->buffer = ptr;
868
9.49k
  vars.bim->size   = ILF_DATA_SIZE;
869
9.49k
  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.49k
  vars.sym_cache = (coff_symbol_type *) ptr;
875
9.49k
  vars.sym_ptr   = (coff_symbol_type *) ptr;
876
9.49k
  vars.sym_index = 0;
877
9.49k
  ptr += SIZEOF_ILF_SYMS;
878
879
9.49k
  vars.sym_table = (unsigned int *) ptr;
880
9.49k
  vars.table_ptr = (unsigned int *) ptr;
881
9.49k
  ptr += SIZEOF_ILF_SYM_TABLE;
882
883
9.49k
  vars.native_syms = (combined_entry_type *) ptr;
884
9.49k
  vars.native_ptr  = (combined_entry_type *) ptr;
885
9.49k
  ptr += SIZEOF_ILF_NATIVE_SYMS;
886
887
9.49k
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
888
9.49k
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
889
9.49k
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
890
891
9.49k
  vars.esym_table = (SYMENT *) ptr;
892
9.49k
  vars.esym_ptr   = (SYMENT *) ptr;
893
9.49k
  ptr += SIZEOF_ILF_EXT_SYMS;
894
895
9.49k
  vars.reltab   = (arelent *) ptr;
896
9.49k
  vars.relcount = 0;
897
9.49k
  ptr += SIZEOF_ILF_RELOCS;
898
899
9.49k
  vars.int_reltab  = (struct internal_reloc *) ptr;
900
9.49k
  ptr += SIZEOF_ILF_INT_RELOCS;
901
902
9.49k
  vars.string_table = (char *) ptr;
903
9.49k
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
904
9.49k
  ptr += SIZEOF_ILF_STRINGS;
905
9.49k
  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.49k
#if GCC_VERSION >= 3000
915
9.49k
  alignment = __alignof__ (struct coff_section_tdata);
916
#else
917
  alignment = 8;
918
#endif
919
9.49k
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
920
921
9.49k
  vars.data = ptr;
922
9.49k
  vars.abfd = abfd;
923
9.49k
  vars.sec_index = 0;
924
9.49k
  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.49k
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
934
9.49k
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
935
9.49k
  if (id4 == NULL || id5 == NULL)
936
0
    goto error_return;
937
938
  /* Fill in the contents of these sections.  */
939
9.49k
  if (import_name_type == IMPORT_ORDINAL)
940
2.92k
    {
941
2.92k
      if (ordinal == 0)
942
  /* See PR 20907 for a reproducer.  */
943
414
  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.50k
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
953
2.50k
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
954
2.50k
#endif
955
2.50k
    }
956
6.57k
  else
957
6.57k
    {
958
6.57k
      char *symbol;
959
6.57k
      unsigned int len;
960
961
      /* Create .idata$6 - the Hint Name Table.  */
962
6.57k
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
963
6.57k
      if (id6 == NULL)
964
0
  goto error_return;
965
966
      /* If necessary, trim the import symbol name.  */
967
6.57k
      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.57k
      if (import_name_type != IMPORT_NAME
977
6.57k
    && import_name_type != IMPORT_NAME_EXPORTAS)
978
4.67k
  {
979
4.67k
    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.67k
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
984
4.67k
        || c == '@' || c == '?')
985
1.69k
      symbol++;
986
4.67k
  }
987
988
6.57k
      len = strlen (symbol);
989
6.57k
      if (import_name_type == IMPORT_NAME_UNDECORATE)
990
2.27k
  {
991
    /* Truncate at the first '@'.  */
992
2.27k
    char *at = strchr (symbol, '@');
993
994
2.27k
    if (at != NULL)
995
678
      len = at - symbol;
996
2.27k
  }
997
998
6.57k
      id6->contents[0] = ordinal & 0xff;
999
6.57k
      id6->contents[1] = ordinal >> 8;
1000
1001
6.57k
      memcpy ((char *) id6->contents + 2, symbol, len);
1002
6.57k
      id6->contents[len + 2] = '\0';
1003
6.57k
    }
1004
1005
9.08k
  if (import_name_type != IMPORT_ORDINAL)
1006
6.57k
    {
1007
6.57k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1008
6.57k
      pe_ILF_save_relocs (&vars, id4);
1009
1010
6.57k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1011
6.57k
      pe_ILF_save_relocs (&vars, id5);
1012
6.57k
    }
1013
1014
  /* Create an import symbol.  */
1015
9.08k
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1016
9.08k
  imp_sym   = vars.sym_ptr_ptr - 1;
1017
9.08k
  imp_index = vars.sym_index - 1;
1018
1019
  /* Create extra sections depending upon the type of import we are
1020
     dealing with.  */
1021
9.08k
  switch (import_type)
1022
9.08k
    {
1023
0
      int i;
1024
1025
3.53k
    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.06k
      for (i = NUM_ENTRIES (jtab); i--;)
1030
7.06k
  {
1031
7.06k
    if (jtab[i].size == 0)
1032
3.53k
      continue;
1033
3.53k
    if (jtab[i].magic == magic)
1034
3.53k
      break;
1035
3.53k
  }
1036
      /* If we did not find a matching entry something is wrong.  */
1037
3.53k
      if (i < 0)
1038
0
  abort ();
1039
1040
      /* Create the .text section.  */
1041
3.53k
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1042
3.53k
      if (text == NULL)
1043
0
  goto error_return;
1044
1045
      /* Copy in the jump code.  */
1046
3.53k
      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.53k
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1072
3.53k
            BFD_RELOC_32, (asymbol **) imp_sym,
1073
3.53k
            imp_index);
1074
1075
3.53k
      pe_ILF_save_relocs (&vars, text);
1076
3.53k
      break;
1077
1078
3.25k
    case IMPORT_DATA:
1079
5.54k
    case IMPORT_CONST:
1080
5.54k
      break;
1081
1082
0
    default:
1083
      /* XXX code not yet written.  */
1084
0
      abort ();
1085
9.08k
    }
1086
1087
  /* Now create a symbol describing the imported value.  */
1088
9.08k
  switch (import_type)
1089
9.08k
    {
1090
3.53k
    case IMPORT_CODE:
1091
3.53k
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1092
3.53k
          BSF_NOT_AT_END | BSF_FUNCTION);
1093
1094
3.53k
      break;
1095
1096
3.25k
    case IMPORT_DATA:
1097
      /* Nothing to do here.  */
1098
3.25k
      break;
1099
1100
2.29k
    case IMPORT_CONST:
1101
2.29k
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1102
2.29k
      break;
1103
1104
0
    default:
1105
      /* XXX code not yet written.  */
1106
0
      abort ();
1107
9.08k
    }
1108
1109
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1110
9.08k
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1111
9.08k
  if (ptr)
1112
1.20k
    *ptr = 0;
1113
9.08k
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1114
9.08k
  if (ptr)
1115
1.20k
    *ptr = '.';
1116
1117
  /* Initialise the bfd.  */
1118
9.08k
  memset (&internal_f, 0, sizeof (internal_f));
1119
1120
9.08k
  internal_f.f_magic  = magic;
1121
9.08k
  internal_f.f_symptr = 0;
1122
9.08k
  internal_f.f_nsyms  = 0;
1123
9.08k
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1124
1125
9.08k
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1126
9.08k
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1127
0
    goto error_return;
1128
1129
9.08k
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1130
0
    goto error_return;
1131
1132
9.08k
  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.08k
  bfd_cache_close (abfd);
1142
1143
9.08k
  abfd->iostream = (void *) vars.bim;
1144
9.08k
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1145
9.08k
  abfd->iovec = &_bfd_memory_iovec;
1146
9.08k
  abfd->where = 0;
1147
9.08k
  abfd->origin = 0;
1148
9.08k
  abfd->size = 0;
1149
9.08k
  obj_sym_filepos (abfd) = 0;
1150
1151
  /* Point the bfd at the symbol table.  */
1152
9.08k
  obj_symbols (abfd) = vars.sym_cache;
1153
9.08k
  abfd->symcount = vars.sym_index;
1154
1155
9.08k
  obj_raw_syments (abfd) = vars.native_syms;
1156
9.08k
  obj_raw_syment_count (abfd) = vars.sym_index;
1157
9.08k
  obj_coff_keep_raw_syms (abfd) = true;
1158
1159
9.08k
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1160
9.08k
  obj_coff_keep_syms (abfd) = true;
1161
1162
9.08k
  obj_convert (abfd) = vars.sym_table;
1163
9.08k
  obj_conv_table_size (abfd) = vars.sym_index;
1164
1165
9.08k
  obj_coff_strings (abfd) = vars.string_table;
1166
9.08k
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1167
9.08k
  obj_coff_keep_strings (abfd) = true;
1168
1169
9.08k
  return true;
1170
1171
414
 error_return:
1172
414
  free (vars.bim->buffer);
1173
414
  free (vars.bim);
1174
414
  return false;
1175
9.08k
}
1176
1177
/* Cleanup function, returned from check_format hook.  */
1178
1179
static void
1180
pe_ILF_cleanup (bfd *abfd)
1181
82
{
1182
82
  coff_object_cleanup (abfd);
1183
1184
82
  struct bfd_in_memory *bim = abfd->iostream;
1185
82
  free (bim->buffer);
1186
82
  free (bim);
1187
82
  abfd->iostream = NULL;
1188
82
}
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
41
{
1182
41
  coff_object_cleanup (abfd);
1183
1184
41
  struct bfd_in_memory *bim = abfd->iostream;
1185
41
  free (bim->buffer);
1186
41
  free (bim);
1187
41
  abfd->iostream = NULL;
1188
41
}
pei-arm.c:pe_ILF_cleanup
Line
Count
Source
1181
41
{
1182
41
  coff_object_cleanup (abfd);
1183
1184
41
  struct bfd_in_memory *bim = abfd->iostream;
1185
41
  free (bim->buffer);
1186
41
  free (bim);
1187
41
  abfd->iostream = NULL;
1188
41
}
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
623k
{
1196
623k
  bfd_byte    buffer[14];
1197
623k
  bfd_byte *    ptr;
1198
623k
  char *    symbol_name;
1199
623k
  char *    source_dll;
1200
623k
  char *    import_name;
1201
623k
  unsigned int    machine;
1202
623k
  bfd_size_type   size;
1203
623k
  unsigned int    ordinal;
1204
623k
  unsigned int    types;
1205
623k
  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
623k
  if (bfd_read (buffer, 14, abfd) != 14)
1210
5.11k
    return NULL;
1211
1212
618k
  ptr = buffer;
1213
1214
618k
  machine = H_GET_16 (abfd, ptr);
1215
618k
  ptr += 2;
1216
1217
  /* Check that the machine type is recognised.  */
1218
618k
  magic = 0;
1219
1220
618k
  switch (machine)
1221
618k
    {
1222
4.12k
    case IMAGE_FILE_MACHINE_UNKNOWN:
1223
5.11k
    case IMAGE_FILE_MACHINE_ALPHA:
1224
5.13k
    case IMAGE_FILE_MACHINE_ALPHA64:
1225
7.03k
    case IMAGE_FILE_MACHINE_IA64:
1226
7.03k
      break;
1227
1228
87.0k
    case IMAGE_FILE_MACHINE_I386:
1229
#ifdef I386MAGIC
1230
15.6k
      magic = I386MAGIC;
1231
#endif
1232
87.0k
      break;
1233
1234
100k
    case IMAGE_FILE_MACHINE_AMD64:
1235
#ifdef AMD64MAGIC
1236
12.2k
      magic = AMD64MAGIC;
1237
#endif
1238
100k
      break;
1239
1240
1.88k
    case IMAGE_FILE_MACHINE_R3000:
1241
2.87k
    case IMAGE_FILE_MACHINE_R4000:
1242
4.76k
    case IMAGE_FILE_MACHINE_R10000:
1243
1244
5.72k
    case IMAGE_FILE_MACHINE_MIPS16:
1245
7.58k
    case IMAGE_FILE_MACHINE_MIPSFPU:
1246
7.62k
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1247
#ifdef MIPS_ARCH_MAGIC_WINCE
1248
      magic = MIPS_ARCH_MAGIC_WINCE;
1249
#endif
1250
7.62k
      break;
1251
1252
45.1k
    case IMAGE_FILE_MACHINE_SH3:
1253
102k
    case IMAGE_FILE_MACHINE_SH4:
1254
#ifdef SH_ARCH_MAGIC_WINCE
1255
13.3k
      magic = SH_ARCH_MAGIC_WINCE;
1256
#endif
1257
102k
      break;
1258
1259
51.5k
    case IMAGE_FILE_MACHINE_ARM:
1260
#ifdef ARMPEMAGIC
1261
17.6k
      magic = ARMPEMAGIC;
1262
#endif
1263
51.5k
      break;
1264
1265
36.6k
    case IMAGE_FILE_MACHINE_ARM64:
1266
#ifdef AARCH64MAGIC
1267
10.8k
      magic = AARCH64MAGIC;
1268
#endif
1269
36.6k
      break;
1270
1271
67.1k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1272
#ifdef LOONGARCH64MAGIC
1273
7.49k
      magic = LOONGARCH64MAGIC;
1274
#endif
1275
67.1k
      break;
1276
1277
77.9k
    case IMAGE_FILE_MACHINE_RISCV64:
1278
#ifdef RISCV64MAGIC
1279
11.1k
      magic = RISCV64MAGIC;
1280
#endif
1281
77.9k
      break;
1282
1283
25.4k
    case IMAGE_FILE_MACHINE_THUMB:
1284
#ifdef THUMBPEMAGIC
1285
      {
1286
  extern const bfd_target TARGET_LITTLE_SYM;
1287
1288
8.40k
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1289
8.40k
    magic = THUMBPEMAGIC;
1290
      }
1291
#endif
1292
25.4k
      break;
1293
1294
0
    case IMAGE_FILE_MACHINE_POWERPC:
1295
      /* We no longer support PowerPC.  */
1296
54.5k
    default:
1297
54.5k
      _bfd_error_handler
1298
  /* xgettext:c-format */
1299
54.5k
  (_("%pB: unrecognised machine type (0x%x)"
1300
54.5k
     " in Import Library Format archive"),
1301
54.5k
   abfd, machine);
1302
54.5k
      bfd_set_error (bfd_error_malformed_archive);
1303
1304
54.5k
      return NULL;
1305
0
      break;
1306
618k
    }
1307
1308
563k
  if (magic == 0)
1309
466k
    {
1310
466k
      _bfd_error_handler
1311
  /* xgettext:c-format */
1312
466k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1313
466k
     " in Import Library Format archive"),
1314
466k
   abfd, machine);
1315
466k
      bfd_set_error (bfd_error_wrong_format);
1316
1317
466k
      return NULL;
1318
466k
    }
1319
1320
  /* We do not bother to check the date.
1321
     date = H_GET_32 (abfd, ptr);  */
1322
96.7k
  ptr += 4;
1323
1324
96.7k
  size = H_GET_32 (abfd, ptr);
1325
96.7k
  ptr += 4;
1326
1327
96.7k
  if (size == 0)
1328
2.62k
    {
1329
2.62k
      _bfd_error_handler
1330
2.62k
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1331
2.62k
      bfd_set_error (bfd_error_malformed_archive);
1332
1333
2.62k
      return NULL;
1334
2.62k
    }
1335
1336
94.1k
  ordinal = H_GET_16 (abfd, ptr);
1337
94.1k
  ptr += 2;
1338
1339
94.1k
  types = H_GET_16 (abfd, ptr);
1340
  /* ptr += 2; */
1341
1342
  /* Now read in the two strings that follow.  */
1343
94.1k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1344
94.1k
  if (ptr == NULL)
1345
9.63k
    return NULL;
1346
1347
84.4k
  symbol_name = (char *) ptr;
1348
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1349
84.4k
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1350
1351
  /* Verify that the strings are null terminated.  */
1352
84.4k
  if (ptr[size - 1] != 0
1353
84.4k
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1354
6.33k
    {
1355
6.33k
      _bfd_error_handler
1356
6.33k
  (_("%pB: string not null terminated in ILF object file"), abfd);
1357
6.33k
      bfd_set_error (bfd_error_malformed_archive);
1358
6.33k
      bfd_release (abfd, ptr);
1359
6.33k
      return NULL;
1360
6.33k
    }
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
78.1k
  import_name = source_dll + strlen (source_dll) + 1;
1369
78.1k
  if ((bfd_byte *) import_name >= ptr + size)
1370
15.6k
    {
1371
      /* If this points at the end of the ptr+size block, we only had
1372
   two strings. */
1373
15.6k
      import_name = NULL;
1374
15.6k
    }
1375
1376
  /* Now construct the bfd.  */
1377
78.1k
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1378
78.1k
          source_dll, ordinal, types,
1379
78.1k
          import_name))
1380
13.3k
    {
1381
13.3k
      bfd_release (abfd, ptr);
1382
13.3k
      return NULL;
1383
13.3k
    }
1384
1385
64.8k
  return pe_ILF_cleanup;
1386
78.1k
}
pei-i386.c:pe_ILF_object_p
Line
Count
Source
1195
76.2k
{
1196
76.2k
  bfd_byte    buffer[14];
1197
76.2k
  bfd_byte *    ptr;
1198
76.2k
  char *    symbol_name;
1199
76.2k
  char *    source_dll;
1200
76.2k
  char *    import_name;
1201
76.2k
  unsigned int    machine;
1202
76.2k
  bfd_size_type   size;
1203
76.2k
  unsigned int    ordinal;
1204
76.2k
  unsigned int    types;
1205
76.2k
  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
76.2k
  if (bfd_read (buffer, 14, abfd) != 14)
1210
573
    return NULL;
1211
1212
75.6k
  ptr = buffer;
1213
1214
75.6k
  machine = H_GET_16 (abfd, ptr);
1215
75.6k
  ptr += 2;
1216
1217
  /* Check that the machine type is recognised.  */
1218
75.6k
  magic = 0;
1219
1220
75.6k
  switch (machine)
1221
75.6k
    {
1222
425
    case IMAGE_FILE_MACHINE_UNKNOWN:
1223
535
    case IMAGE_FILE_MACHINE_ALPHA:
1224
537
    case IMAGE_FILE_MACHINE_ALPHA64:
1225
749
    case IMAGE_FILE_MACHINE_IA64:
1226
749
      break;
1227
1228
15.6k
    case IMAGE_FILE_MACHINE_I386:
1229
15.6k
#ifdef I386MAGIC
1230
15.6k
      magic = I386MAGIC;
1231
15.6k
#endif
1232
15.6k
      break;
1233
1234
12.2k
    case IMAGE_FILE_MACHINE_AMD64:
1235
#ifdef AMD64MAGIC
1236
      magic = AMD64MAGIC;
1237
#endif
1238
12.2k
      break;
1239
1240
210
    case IMAGE_FILE_MACHINE_R3000:
1241
320
    case IMAGE_FILE_MACHINE_R4000:
1242
530
    case IMAGE_FILE_MACHINE_R10000:
1243
1244
638
    case IMAGE_FILE_MACHINE_MIPS16:
1245
845
    case IMAGE_FILE_MACHINE_MIPSFPU:
1246
850
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1247
#ifdef MIPS_ARCH_MAGIC_WINCE
1248
      magic = MIPS_ARCH_MAGIC_WINCE;
1249
#endif
1250
850
      break;
1251
1252
6.04k
    case IMAGE_FILE_MACHINE_SH3:
1253
13.3k
    case IMAGE_FILE_MACHINE_SH4:
1254
#ifdef SH_ARCH_MAGIC_WINCE
1255
      magic = SH_ARCH_MAGIC_WINCE;
1256
#endif
1257
13.3k
      break;
1258
1259
3.25k
    case IMAGE_FILE_MACHINE_ARM:
1260
#ifdef ARMPEMAGIC
1261
      magic = ARMPEMAGIC;
1262
#endif
1263
3.25k
      break;
1264
1265
3.23k
    case IMAGE_FILE_MACHINE_ARM64:
1266
#ifdef AARCH64MAGIC
1267
      magic = AARCH64MAGIC;
1268
#endif
1269
3.23k
      break;
1270
1271
7.46k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1272
#ifdef LOONGARCH64MAGIC
1273
      magic = LOONGARCH64MAGIC;
1274
#endif
1275
7.46k
      break;
1276
1277
11.0k
    case IMAGE_FILE_MACHINE_RISCV64:
1278
#ifdef RISCV64MAGIC
1279
      magic = RISCV64MAGIC;
1280
#endif
1281
11.0k
      break;
1282
1283
1.72k
    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.72k
      break;
1293
1294
0
    case IMAGE_FILE_MACHINE_POWERPC:
1295
      /* We no longer support PowerPC.  */
1296
6.06k
    default:
1297
6.06k
      _bfd_error_handler
1298
  /* xgettext:c-format */
1299
6.06k
  (_("%pB: unrecognised machine type (0x%x)"
1300
6.06k
     " in Import Library Format archive"),
1301
6.06k
   abfd, machine);
1302
6.06k
      bfd_set_error (bfd_error_malformed_archive);
1303
1304
6.06k
      return NULL;
1305
0
      break;
1306
75.6k
    }
1307
1308
69.5k
  if (magic == 0)
1309
53.9k
    {
1310
53.9k
      _bfd_error_handler
1311
  /* xgettext:c-format */
1312
53.9k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1313
53.9k
     " in Import Library Format archive"),
1314
53.9k
   abfd, machine);
1315
53.9k
      bfd_set_error (bfd_error_wrong_format);
1316
1317
53.9k
      return NULL;
1318
53.9k
    }
1319
1320
  /* We do not bother to check the date.
1321
     date = H_GET_32 (abfd, ptr);  */
1322
15.6k
  ptr += 4;
1323
1324
15.6k
  size = H_GET_32 (abfd, ptr);
1325
15.6k
  ptr += 4;
1326
1327
15.6k
  if (size == 0)
1328
415
    {
1329
415
      _bfd_error_handler
1330
415
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1331
415
      bfd_set_error (bfd_error_malformed_archive);
1332
1333
415
      return NULL;
1334
415
    }
1335
1336
15.2k
  ordinal = H_GET_16 (abfd, ptr);
1337
15.2k
  ptr += 2;
1338
1339
15.2k
  types = H_GET_16 (abfd, ptr);
1340
  /* ptr += 2; */
1341
1342
  /* Now read in the two strings that follow.  */
1343
15.2k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1344
15.2k
  if (ptr == NULL)
1345
1.24k
    return NULL;
1346
1347
13.9k
  symbol_name = (char *) ptr;
1348
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1349
13.9k
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1350
1351
  /* Verify that the strings are null terminated.  */
1352
13.9k
  if (ptr[size - 1] != 0
1353
13.9k
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1354
954
    {
1355
954
      _bfd_error_handler
1356
954
  (_("%pB: string not null terminated in ILF object file"), abfd);
1357
954
      bfd_set_error (bfd_error_malformed_archive);
1358
954
      bfd_release (abfd, ptr);
1359
954
      return NULL;
1360
954
    }
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
13.0k
  import_name = source_dll + strlen (source_dll) + 1;
1369
13.0k
  if ((bfd_byte *) import_name >= ptr + size)
1370
3.85k
    {
1371
      /* If this points at the end of the ptr+size block, we only had
1372
   two strings. */
1373
3.85k
      import_name = NULL;
1374
3.85k
    }
1375
1376
  /* Now construct the bfd.  */
1377
13.0k
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1378
13.0k
          source_dll, ordinal, types,
1379
13.0k
          import_name))
1380
2.27k
    {
1381
2.27k
      bfd_release (abfd, ptr);
1382
2.27k
      return NULL;
1383
2.27k
    }
1384
1385
10.7k
  return pe_ILF_cleanup;
1386
13.0k
}
pei-x86_64.c:pe_ILF_object_p
Line
Count
Source
1195
49.3k
{
1196
49.3k
  bfd_byte    buffer[14];
1197
49.3k
  bfd_byte *    ptr;
1198
49.3k
  char *    symbol_name;
1199
49.3k
  char *    source_dll;
1200
49.3k
  char *    import_name;
1201
49.3k
  unsigned int    machine;
1202
49.3k
  bfd_size_type   size;
1203
49.3k
  unsigned int    ordinal;
1204
49.3k
  unsigned int    types;
1205
49.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
49.3k
  if (bfd_read (buffer, 14, abfd) != 14)
1210
573
    return NULL;
1211
1212
48.8k
  ptr = buffer;
1213
1214
48.8k
  machine = H_GET_16 (abfd, ptr);
1215
48.8k
  ptr += 2;
1216
1217
  /* Check that the machine type is recognised.  */
1218
48.8k
  magic = 0;
1219
1220
48.8k
  switch (machine)
1221
48.8k
    {
1222
425
    case IMAGE_FILE_MACHINE_UNKNOWN:
1223
535
    case IMAGE_FILE_MACHINE_ALPHA:
1224
537
    case IMAGE_FILE_MACHINE_ALPHA64:
1225
749
    case IMAGE_FILE_MACHINE_IA64:
1226
749
      break;
1227
1228
4.95k
    case IMAGE_FILE_MACHINE_I386:
1229
#ifdef I386MAGIC
1230
      magic = I386MAGIC;
1231
#endif
1232
4.95k
      break;
1233
1234
12.2k
    case IMAGE_FILE_MACHINE_AMD64:
1235
12.2k
#ifdef AMD64MAGIC
1236
12.2k
      magic = AMD64MAGIC;
1237
12.2k
#endif
1238
12.2k
      break;
1239
1240
210
    case IMAGE_FILE_MACHINE_R3000:
1241
320
    case IMAGE_FILE_MACHINE_R4000:
1242
530
    case IMAGE_FILE_MACHINE_R10000:
1243
1244
638
    case IMAGE_FILE_MACHINE_MIPS16:
1245
845
    case IMAGE_FILE_MACHINE_MIPSFPU:
1246
850
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1247
#ifdef MIPS_ARCH_MAGIC_WINCE
1248
      magic = MIPS_ARCH_MAGIC_WINCE;
1249
#endif
1250
850
      break;
1251
1252
1.49k
    case IMAGE_FILE_MACHINE_SH3:
1253
4.39k
    case IMAGE_FILE_MACHINE_SH4:
1254
#ifdef SH_ARCH_MAGIC_WINCE
1255
      magic = SH_ARCH_MAGIC_WINCE;
1256
#endif
1257
4.39k
      break;
1258
1259
3.25k
    case IMAGE_FILE_MACHINE_ARM:
1260
#ifdef ARMPEMAGIC
1261
      magic = ARMPEMAGIC;
1262
#endif
1263
3.25k
      break;
1264
1265
3.23k
    case IMAGE_FILE_MACHINE_ARM64:
1266
#ifdef AARCH64MAGIC
1267
      magic = AARCH64MAGIC;
1268
#endif
1269
3.23k
      break;
1270
1271
7.46k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1272
#ifdef LOONGARCH64MAGIC
1273
      magic = LOONGARCH64MAGIC;
1274
#endif
1275
7.46k
      break;
1276
1277
3.88k
    case IMAGE_FILE_MACHINE_RISCV64:
1278
#ifdef RISCV64MAGIC
1279
      magic = RISCV64MAGIC;
1280
#endif
1281
3.88k
      break;
1282
1283
1.72k
    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.72k
      break;
1293
1294
0
    case IMAGE_FILE_MACHINE_POWERPC:
1295
      /* We no longer support PowerPC.  */
1296
6.06k
    default:
1297
6.06k
      _bfd_error_handler
1298
  /* xgettext:c-format */
1299
6.06k
  (_("%pB: unrecognised machine type (0x%x)"
1300
6.06k
     " in Import Library Format archive"),
1301
6.06k
   abfd, machine);
1302
6.06k
      bfd_set_error (bfd_error_malformed_archive);
1303
1304
6.06k
      return NULL;
1305
0
      break;
1306
48.8k
    }
1307
1308
42.7k
  if (magic == 0)
1309
30.5k
    {
1310
30.5k
      _bfd_error_handler
1311
  /* xgettext:c-format */
1312
30.5k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1313
30.5k
     " in Import Library Format archive"),
1314
30.5k
   abfd, machine);
1315
30.5k
      bfd_set_error (bfd_error_wrong_format);
1316
1317
30.5k
      return NULL;
1318
30.5k
    }
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
315
    {
1329
315
      _bfd_error_handler
1330
315
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1331
315
      bfd_set_error (bfd_error_malformed_archive);
1332
1333
315
      return NULL;
1334
315
    }
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
697
    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
722
    {
1355
722
      _bfd_error_handler
1356
722
  (_("%pB: string not null terminated in ILF object file"), abfd);
1357
722
      bfd_set_error (bfd_error_malformed_archive);
1358
722
      bfd_release (abfd, ptr);
1359
722
      return NULL;
1360
722
    }
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.5k
  import_name = source_dll + strlen (source_dll) + 1;
1369
10.5k
  if ((bfd_byte *) import_name >= ptr + size)
1370
1.78k
    {
1371
      /* If this points at the end of the ptr+size block, we only had
1372
   two strings. */
1373
1.78k
      import_name = NULL;
1374
1.78k
    }
1375
1376
  /* Now construct the bfd.  */
1377
10.5k
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1378
10.5k
          source_dll, ordinal, types,
1379
10.5k
          import_name))
1380
1.55k
    {
1381
1.55k
      bfd_release (abfd, ptr);
1382
1.55k
      return NULL;
1383
1.55k
    }
1384
1385
8.94k
  return pe_ILF_cleanup;
1386
10.5k
}
pei-aarch64.c:pe_ILF_object_p
Line
Count
Source
1195
99.8k
{
1196
99.8k
  bfd_byte    buffer[14];
1197
99.8k
  bfd_byte *    ptr;
1198
99.8k
  char *    symbol_name;
1199
99.8k
  char *    source_dll;
1200
99.8k
  char *    import_name;
1201
99.8k
  unsigned int    machine;
1202
99.8k
  bfd_size_type   size;
1203
99.8k
  unsigned int    ordinal;
1204
99.8k
  unsigned int    types;
1205
99.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
99.8k
  if (bfd_read (buffer, 14, abfd) != 14)
1210
573
    return NULL;
1211
1212
99.2k
  ptr = buffer;
1213
1214
99.2k
  machine = H_GET_16 (abfd, ptr);
1215
99.2k
  ptr += 2;
1216
1217
  /* Check that the machine type is recognised.  */
1218
99.2k
  magic = 0;
1219
1220
99.2k
  switch (machine)
1221
99.2k
    {
1222
425
    case IMAGE_FILE_MACHINE_UNKNOWN:
1223
535
    case IMAGE_FILE_MACHINE_ALPHA:
1224
537
    case IMAGE_FILE_MACHINE_ALPHA64:
1225
749
    case IMAGE_FILE_MACHINE_IA64:
1226
749
      break;
1227
1228
15.6k
    case IMAGE_FILE_MACHINE_I386:
1229
#ifdef I386MAGIC
1230
      magic = I386MAGIC;
1231
#endif
1232
15.6k
      break;
1233
1234
12.2k
    case IMAGE_FILE_MACHINE_AMD64:
1235
#ifdef AMD64MAGIC
1236
      magic = AMD64MAGIC;
1237
#endif
1238
12.2k
      break;
1239
1240
210
    case IMAGE_FILE_MACHINE_R3000:
1241
320
    case IMAGE_FILE_MACHINE_R4000:
1242
530
    case IMAGE_FILE_MACHINE_R10000:
1243
1244
638
    case IMAGE_FILE_MACHINE_MIPS16:
1245
845
    case IMAGE_FILE_MACHINE_MIPSFPU:
1246
850
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1247
#ifdef MIPS_ARCH_MAGIC_WINCE
1248
      magic = MIPS_ARCH_MAGIC_WINCE;
1249
#endif
1250
850
      break;
1251
1252
6.04k
    case IMAGE_FILE_MACHINE_SH3:
1253
13.3k
    case IMAGE_FILE_MACHINE_SH4:
1254
#ifdef SH_ARCH_MAGIC_WINCE
1255
      magic = SH_ARCH_MAGIC_WINCE;
1256
#endif
1257
13.3k
      break;
1258
1259
14.3k
    case IMAGE_FILE_MACHINE_ARM:
1260
#ifdef ARMPEMAGIC
1261
      magic = ARMPEMAGIC;
1262
#endif
1263
14.3k
      break;
1264
1265
10.8k
    case IMAGE_FILE_MACHINE_ARM64:
1266
10.8k
#ifdef AARCH64MAGIC
1267
10.8k
      magic = AARCH64MAGIC;
1268
10.8k
#endif
1269
10.8k
      break;
1270
1271
7.46k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1272
#ifdef LOONGARCH64MAGIC
1273
      magic = LOONGARCH64MAGIC;
1274
#endif
1275
7.46k
      break;
1276
1277
11.0k
    case IMAGE_FILE_MACHINE_RISCV64:
1278
#ifdef RISCV64MAGIC
1279
      magic = RISCV64MAGIC;
1280
#endif
1281
11.0k
      break;
1282
1283
6.69k
    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
6.69k
      break;
1293
1294
0
    case IMAGE_FILE_MACHINE_POWERPC:
1295
      /* We no longer support PowerPC.  */
1296
6.06k
    default:
1297
6.06k
      _bfd_error_handler
1298
  /* xgettext:c-format */
1299
6.06k
  (_("%pB: unrecognised machine type (0x%x)"
1300
6.06k
     " in Import Library Format archive"),
1301
6.06k
   abfd, machine);
1302
6.06k
      bfd_set_error (bfd_error_malformed_archive);
1303
1304
6.06k
      return NULL;
1305
0
      break;
1306
99.2k
    }
1307
1308
93.1k
  if (magic == 0)
1309
82.3k
    {
1310
82.3k
      _bfd_error_handler
1311
  /* xgettext:c-format */
1312
82.3k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1313
82.3k
     " in Import Library Format archive"),
1314
82.3k
   abfd, machine);
1315
82.3k
      bfd_set_error (bfd_error_wrong_format);
1316
1317
82.3k
      return NULL;
1318
82.3k
    }
1319
1320
  /* We do not bother to check the date.
1321
     date = H_GET_32 (abfd, ptr);  */
1322
10.8k
  ptr += 4;
1323
1324
10.8k
  size = H_GET_32 (abfd, ptr);
1325
10.8k
  ptr += 4;
1326
1327
10.8k
  if (size == 0)
1328
316
    {
1329
316
      _bfd_error_handler
1330
316
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1331
316
      bfd_set_error (bfd_error_malformed_archive);
1332
1333
316
      return NULL;
1334
316
    }
1335
1336
10.5k
  ordinal = H_GET_16 (abfd, ptr);
1337
10.5k
  ptr += 2;
1338
1339
10.5k
  types = H_GET_16 (abfd, ptr);
1340
  /* ptr += 2; */
1341
1342
  /* Now read in the two strings that follow.  */
1343
10.5k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1344
10.5k
  if (ptr == NULL)
1345
774
    return NULL;
1346
1347
9.72k
  symbol_name = (char *) ptr;
1348
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1349
9.72k
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1350
1351
  /* Verify that the strings are null terminated.  */
1352
9.72k
  if (ptr[size - 1] != 0
1353
9.72k
      || (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
9.10k
  import_name = source_dll + strlen (source_dll) + 1;
1369
9.10k
  if ((bfd_byte *) import_name >= ptr + size)
1370
1.92k
    {
1371
      /* If this points at the end of the ptr+size block, we only had
1372
   two strings. */
1373
1.92k
      import_name = NULL;
1374
1.92k
    }
1375
1376
  /* Now construct the bfd.  */
1377
9.10k
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1378
9.10k
          source_dll, ordinal, types,
1379
9.10k
          import_name))
1380
1.46k
    {
1381
1.46k
      bfd_release (abfd, ptr);
1382
1.46k
      return NULL;
1383
1.46k
    }
1384
1385
7.63k
  return pe_ILF_cleanup;
1386
9.10k
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_object_p
pei-loongarch64.c:pe_ILF_object_p
Line
Count
Source
1195
40.5k
{
1196
40.5k
  bfd_byte    buffer[14];
1197
40.5k
  bfd_byte *    ptr;
1198
40.5k
  char *    symbol_name;
1199
40.5k
  char *    source_dll;
1200
40.5k
  char *    import_name;
1201
40.5k
  unsigned int    machine;
1202
40.5k
  bfd_size_type   size;
1203
40.5k
  unsigned int    ordinal;
1204
40.5k
  unsigned int    types;
1205
40.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
40.5k
  if (bfd_read (buffer, 14, abfd) != 14)
1210
573
    return NULL;
1211
1212
39.9k
  ptr = buffer;
1213
1214
39.9k
  machine = H_GET_16 (abfd, ptr);
1215
39.9k
  ptr += 2;
1216
1217
  /* Check that the machine type is recognised.  */
1218
39.9k
  magic = 0;
1219
1220
39.9k
  switch (machine)
1221
39.9k
    {
1222
425
    case IMAGE_FILE_MACHINE_UNKNOWN:
1223
535
    case IMAGE_FILE_MACHINE_ALPHA:
1224
537
    case IMAGE_FILE_MACHINE_ALPHA64:
1225
749
    case IMAGE_FILE_MACHINE_IA64:
1226
749
      break;
1227
1228
4.95k
    case IMAGE_FILE_MACHINE_I386:
1229
#ifdef I386MAGIC
1230
      magic = I386MAGIC;
1231
#endif
1232
4.95k
      break;
1233
1234
3.35k
    case IMAGE_FILE_MACHINE_AMD64:
1235
#ifdef AMD64MAGIC
1236
      magic = AMD64MAGIC;
1237
#endif
1238
3.35k
      break;
1239
1240
210
    case IMAGE_FILE_MACHINE_R3000:
1241
320
    case IMAGE_FILE_MACHINE_R4000:
1242
530
    case IMAGE_FILE_MACHINE_R10000:
1243
1244
638
    case IMAGE_FILE_MACHINE_MIPS16:
1245
845
    case IMAGE_FILE_MACHINE_MIPSFPU:
1246
850
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1247
#ifdef MIPS_ARCH_MAGIC_WINCE
1248
      magic = MIPS_ARCH_MAGIC_WINCE;
1249
#endif
1250
850
      break;
1251
1252
1.49k
    case IMAGE_FILE_MACHINE_SH3:
1253
4.39k
    case IMAGE_FILE_MACHINE_SH4:
1254
#ifdef SH_ARCH_MAGIC_WINCE
1255
      magic = SH_ARCH_MAGIC_WINCE;
1256
#endif
1257
4.39k
      break;
1258
1259
3.25k
    case IMAGE_FILE_MACHINE_ARM:
1260
#ifdef ARMPEMAGIC
1261
      magic = ARMPEMAGIC;
1262
#endif
1263
3.25k
      break;
1264
1265
3.23k
    case IMAGE_FILE_MACHINE_ARM64:
1266
#ifdef AARCH64MAGIC
1267
      magic = AARCH64MAGIC;
1268
#endif
1269
3.23k
      break;
1270
1271
7.49k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1272
7.49k
#ifdef LOONGARCH64MAGIC
1273
7.49k
      magic = LOONGARCH64MAGIC;
1274
7.49k
#endif
1275
7.49k
      break;
1276
1277
3.88k
    case IMAGE_FILE_MACHINE_RISCV64:
1278
#ifdef RISCV64MAGIC
1279
      magic = RISCV64MAGIC;
1280
#endif
1281
3.88k
      break;
1282
1283
1.72k
    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.72k
      break;
1293
1294
0
    case IMAGE_FILE_MACHINE_POWERPC:
1295
      /* We no longer support PowerPC.  */
1296
6.06k
    default:
1297
6.06k
      _bfd_error_handler
1298
  /* xgettext:c-format */
1299
6.06k
  (_("%pB: unrecognised machine type (0x%x)"
1300
6.06k
     " in Import Library Format archive"),
1301
6.06k
   abfd, machine);
1302
6.06k
      bfd_set_error (bfd_error_malformed_archive);
1303
1304
6.06k
      return NULL;
1305
0
      break;
1306
39.9k
    }
1307
1308
33.9k
  if (magic == 0)
1309
26.4k
    {
1310
26.4k
      _bfd_error_handler
1311
  /* xgettext:c-format */
1312
26.4k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1313
26.4k
     " in Import Library Format archive"),
1314
26.4k
   abfd, machine);
1315
26.4k
      bfd_set_error (bfd_error_wrong_format);
1316
1317
26.4k
      return NULL;
1318
26.4k
    }
1319
1320
  /* We do not bother to check the date.
1321
     date = H_GET_32 (abfd, ptr);  */
1322
7.49k
  ptr += 4;
1323
1324
7.49k
  size = H_GET_32 (abfd, ptr);
1325
7.49k
  ptr += 4;
1326
1327
7.49k
  if (size == 0)
1328
216
    {
1329
216
      _bfd_error_handler
1330
216
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1331
216
      bfd_set_error (bfd_error_malformed_archive);
1332
1333
216
      return NULL;
1334
216
    }
1335
1336
7.28k
  ordinal = H_GET_16 (abfd, ptr);
1337
7.28k
  ptr += 2;
1338
1339
7.28k
  types = H_GET_16 (abfd, ptr);
1340
  /* ptr += 2; */
1341
1342
  /* Now read in the two strings that follow.  */
1343
7.28k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1344
7.28k
  if (ptr == NULL)
1345
1.01k
    return NULL;
1346
1347
6.26k
  symbol_name = (char *) ptr;
1348
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1349
6.26k
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1350
1351
  /* Verify that the strings are null terminated.  */
1352
6.26k
  if (ptr[size - 1] != 0
1353
6.26k
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1354
433
    {
1355
433
      _bfd_error_handler
1356
433
  (_("%pB: string not null terminated in ILF object file"), abfd);
1357
433
      bfd_set_error (bfd_error_malformed_archive);
1358
433
      bfd_release (abfd, ptr);
1359
433
      return NULL;
1360
433
    }
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.83k
  import_name = source_dll + strlen (source_dll) + 1;
1369
5.83k
  if ((bfd_byte *) import_name >= ptr + size)
1370
1.28k
    {
1371
      /* If this points at the end of the ptr+size block, we only had
1372
   two strings. */
1373
1.28k
      import_name = NULL;
1374
1.28k
    }
1375
1376
  /* Now construct the bfd.  */
1377
5.83k
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1378
5.83k
          source_dll, ordinal, types,
1379
5.83k
          import_name))
1380
1.06k
    {
1381
1.06k
      bfd_release (abfd, ptr);
1382
1.06k
      return NULL;
1383
1.06k
    }
1384
1385
4.77k
  return pe_ILF_cleanup;
1386
5.83k
}
pei-riscv64.c:pe_ILF_object_p
Line
Count
Source
1195
65.5k
{
1196
65.5k
  bfd_byte    buffer[14];
1197
65.5k
  bfd_byte *    ptr;
1198
65.5k
  char *    symbol_name;
1199
65.5k
  char *    source_dll;
1200
65.5k
  char *    import_name;
1201
65.5k
  unsigned int    machine;
1202
65.5k
  bfd_size_type   size;
1203
65.5k
  unsigned int    ordinal;
1204
65.5k
  unsigned int    types;
1205
65.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
65.5k
  if (bfd_read (buffer, 14, abfd) != 14)
1210
573
    return NULL;
1211
1212
64.9k
  ptr = buffer;
1213
1214
64.9k
  machine = H_GET_16 (abfd, ptr);
1215
64.9k
  ptr += 2;
1216
1217
  /* Check that the machine type is recognised.  */
1218
64.9k
  magic = 0;
1219
1220
64.9k
  switch (machine)
1221
64.9k
    {
1222
425
    case IMAGE_FILE_MACHINE_UNKNOWN:
1223
535
    case IMAGE_FILE_MACHINE_ALPHA:
1224
537
    case IMAGE_FILE_MACHINE_ALPHA64:
1225
749
    case IMAGE_FILE_MACHINE_IA64:
1226
749
      break;
1227
1228
4.95k
    case IMAGE_FILE_MACHINE_I386:
1229
#ifdef I386MAGIC
1230
      magic = I386MAGIC;
1231
#endif
1232
4.95k
      break;
1233
1234
12.2k
    case IMAGE_FILE_MACHINE_AMD64:
1235
#ifdef AMD64MAGIC
1236
      magic = AMD64MAGIC;
1237
#endif
1238
12.2k
      break;
1239
1240
210
    case IMAGE_FILE_MACHINE_R3000:
1241
320
    case IMAGE_FILE_MACHINE_R4000:
1242
530
    case IMAGE_FILE_MACHINE_R10000:
1243
1244
638
    case IMAGE_FILE_MACHINE_MIPS16:
1245
845
    case IMAGE_FILE_MACHINE_MIPSFPU:
1246
850
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1247
#ifdef MIPS_ARCH_MAGIC_WINCE
1248
      magic = MIPS_ARCH_MAGIC_WINCE;
1249
#endif
1250
850
      break;
1251
1252
6.04k
    case IMAGE_FILE_MACHINE_SH3:
1253
13.3k
    case IMAGE_FILE_MACHINE_SH4:
1254
#ifdef SH_ARCH_MAGIC_WINCE
1255
      magic = SH_ARCH_MAGIC_WINCE;
1256
#endif
1257
13.3k
      break;
1258
1259
3.25k
    case IMAGE_FILE_MACHINE_ARM:
1260
#ifdef ARMPEMAGIC
1261
      magic = ARMPEMAGIC;
1262
#endif
1263
3.25k
      break;
1264
1265
3.23k
    case IMAGE_FILE_MACHINE_ARM64:
1266
#ifdef AARCH64MAGIC
1267
      magic = AARCH64MAGIC;
1268
#endif
1269
3.23k
      break;
1270
1271
7.46k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1272
#ifdef LOONGARCH64MAGIC
1273
      magic = LOONGARCH64MAGIC;
1274
#endif
1275
7.46k
      break;
1276
1277
11.1k
    case IMAGE_FILE_MACHINE_RISCV64:
1278
11.1k
#ifdef RISCV64MAGIC
1279
11.1k
      magic = RISCV64MAGIC;
1280
11.1k
#endif
1281
11.1k
      break;
1282
1283
1.72k
    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.72k
      break;
1293
1294
0
    case IMAGE_FILE_MACHINE_POWERPC:
1295
      /* We no longer support PowerPC.  */
1296
6.06k
    default:
1297
6.06k
      _bfd_error_handler
1298
  /* xgettext:c-format */
1299
6.06k
  (_("%pB: unrecognised machine type (0x%x)"
1300
6.06k
     " in Import Library Format archive"),
1301
6.06k
   abfd, machine);
1302
6.06k
      bfd_set_error (bfd_error_malformed_archive);
1303
1304
6.06k
      return NULL;
1305
0
      break;
1306
64.9k
    }
1307
1308
58.9k
  if (magic == 0)
1309
47.8k
    {
1310
47.8k
      _bfd_error_handler
1311
  /* xgettext:c-format */
1312
47.8k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1313
47.8k
     " in Import Library Format archive"),
1314
47.8k
   abfd, machine);
1315
47.8k
      bfd_set_error (bfd_error_wrong_format);
1316
1317
47.8k
      return NULL;
1318
47.8k
    }
1319
1320
  /* We do not bother to check the date.
1321
     date = H_GET_32 (abfd, ptr);  */
1322
11.1k
  ptr += 4;
1323
1324
11.1k
  size = H_GET_32 (abfd, ptr);
1325
11.1k
  ptr += 4;
1326
1327
11.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
10.8k
  ordinal = H_GET_16 (abfd, ptr);
1337
10.8k
  ptr += 2;
1338
1339
10.8k
  types = H_GET_16 (abfd, ptr);
1340
  /* ptr += 2; */
1341
1342
  /* Now read in the two strings that follow.  */
1343
10.8k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1344
10.8k
  if (ptr == NULL)
1345
1.52k
    return NULL;
1346
1347
9.37k
  symbol_name = (char *) ptr;
1348
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1349
9.37k
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1350
1351
  /* Verify that the strings are null terminated.  */
1352
9.37k
  if (ptr[size - 1] != 0
1353
9.37k
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1354
933
    {
1355
933
      _bfd_error_handler
1356
933
  (_("%pB: string not null terminated in ILF object file"), abfd);
1357
933
      bfd_set_error (bfd_error_malformed_archive);
1358
933
      bfd_release (abfd, ptr);
1359
933
      return NULL;
1360
933
    }
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.44k
  import_name = source_dll + strlen (source_dll) + 1;
1369
8.44k
  if ((bfd_byte *) import_name >= ptr + size)
1370
913
    {
1371
      /* If this points at the end of the ptr+size block, we only had
1372
   two strings. */
1373
913
      import_name = NULL;
1374
913
    }
1375
1376
  /* Now construct the bfd.  */
1377
8.44k
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1378
8.44k
          source_dll, ordinal, types,
1379
8.44k
          import_name))
1380
1.15k
    {
1381
1.15k
      bfd_release (abfd, ptr);
1382
1.15k
      return NULL;
1383
1.15k
    }
1384
1385
7.28k
  return pe_ILF_cleanup;
1386
8.44k
}
pei-arm-wince.c:pe_ILF_object_p
Line
Count
Source
1195
76.0k
{
1196
76.0k
  bfd_byte    buffer[14];
1197
76.0k
  bfd_byte *    ptr;
1198
76.0k
  char *    symbol_name;
1199
76.0k
  char *    source_dll;
1200
76.0k
  char *    import_name;
1201
76.0k
  unsigned int    machine;
1202
76.0k
  bfd_size_type   size;
1203
76.0k
  unsigned int    ordinal;
1204
76.0k
  unsigned int    types;
1205
76.0k
  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
76.0k
  if (bfd_read (buffer, 14, abfd) != 14)
1210
564
    return NULL;
1211
1212
75.5k
  ptr = buffer;
1213
1214
75.5k
  machine = H_GET_16 (abfd, ptr);
1215
75.5k
  ptr += 2;
1216
1217
  /* Check that the machine type is recognised.  */
1218
75.5k
  magic = 0;
1219
1220
75.5k
  switch (machine)
1221
75.5k
    {
1222
527
    case IMAGE_FILE_MACHINE_UNKNOWN:
1223
636
    case IMAGE_FILE_MACHINE_ALPHA:
1224
638
    case IMAGE_FILE_MACHINE_ALPHA64:
1225
849
    case IMAGE_FILE_MACHINE_IA64:
1226
849
      break;
1227
1228
15.5k
    case IMAGE_FILE_MACHINE_I386:
1229
#ifdef I386MAGIC
1230
      magic = I386MAGIC;
1231
#endif
1232
15.5k
      break;
1233
1234
12.1k
    case IMAGE_FILE_MACHINE_AMD64:
1235
#ifdef AMD64MAGIC
1236
      magic = AMD64MAGIC;
1237
#endif
1238
12.1k
      break;
1239
1240
209
    case IMAGE_FILE_MACHINE_R3000:
1241
318
    case IMAGE_FILE_MACHINE_R4000:
1242
528
    case IMAGE_FILE_MACHINE_R10000:
1243
1244
635
    case IMAGE_FILE_MACHINE_MIPS16:
1245
841
    case IMAGE_FILE_MACHINE_MIPSFPU:
1246
845
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1247
#ifdef MIPS_ARCH_MAGIC_WINCE
1248
      magic = MIPS_ARCH_MAGIC_WINCE;
1249
#endif
1250
845
      break;
1251
1252
5.99k
    case IMAGE_FILE_MACHINE_SH3:
1253
13.3k
    case IMAGE_FILE_MACHINE_SH4:
1254
#ifdef SH_ARCH_MAGIC_WINCE
1255
      magic = SH_ARCH_MAGIC_WINCE;
1256
#endif
1257
13.3k
      break;
1258
1259
3.26k
    case IMAGE_FILE_MACHINE_ARM:
1260
3.26k
#ifdef ARMPEMAGIC
1261
3.26k
      magic = ARMPEMAGIC;
1262
3.26k
#endif
1263
3.26k
      break;
1264
1265
3.22k
    case IMAGE_FILE_MACHINE_ARM64:
1266
#ifdef AARCH64MAGIC
1267
      magic = AARCH64MAGIC;
1268
#endif
1269
3.22k
      break;
1270
1271
7.43k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1272
#ifdef LOONGARCH64MAGIC
1273
      magic = LOONGARCH64MAGIC;
1274
#endif
1275
7.43k
      break;
1276
1277
11.0k
    case IMAGE_FILE_MACHINE_RISCV64:
1278
#ifdef RISCV64MAGIC
1279
      magic = RISCV64MAGIC;
1280
#endif
1281
11.0k
      break;
1282
1283
1.71k
    case IMAGE_FILE_MACHINE_THUMB:
1284
1.71k
#ifdef THUMBPEMAGIC
1285
1.71k
      {
1286
1.71k
  extern const bfd_target TARGET_LITTLE_SYM;
1287
1288
1.71k
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1289
1.70k
    magic = THUMBPEMAGIC;
1290
1.71k
      }
1291
1.71k
#endif
1292
1.71k
      break;
1293
1294
0
    case IMAGE_FILE_MACHINE_POWERPC:
1295
      /* We no longer support PowerPC.  */
1296
6.08k
    default:
1297
6.08k
      _bfd_error_handler
1298
  /* xgettext:c-format */
1299
6.08k
  (_("%pB: unrecognised machine type (0x%x)"
1300
6.08k
     " in Import Library Format archive"),
1301
6.08k
   abfd, machine);
1302
6.08k
      bfd_set_error (bfd_error_malformed_archive);
1303
1304
6.08k
      return NULL;
1305
0
      break;
1306
75.5k
    }
1307
1308
69.4k
  if (magic == 0)
1309
64.4k
    {
1310
64.4k
      _bfd_error_handler
1311
  /* xgettext:c-format */
1312
64.4k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1313
64.4k
     " in Import Library Format archive"),
1314
64.4k
   abfd, machine);
1315
64.4k
      bfd_set_error (bfd_error_wrong_format);
1316
1317
64.4k
      return NULL;
1318
64.4k
    }
1319
1320
  /* We do not bother to check the date.
1321
     date = H_GET_32 (abfd, ptr);  */
1322
4.96k
  ptr += 4;
1323
1324
4.96k
  size = H_GET_32 (abfd, ptr);
1325
4.96k
  ptr += 4;
1326
1327
4.96k
  if (size == 0)
1328
418
    {
1329
418
      _bfd_error_handler
1330
418
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1331
418
      bfd_set_error (bfd_error_malformed_archive);
1332
1333
418
      return NULL;
1334
418
    }
1335
1336
4.55k
  ordinal = H_GET_16 (abfd, ptr);
1337
4.55k
  ptr += 2;
1338
1339
4.55k
  types = H_GET_16 (abfd, ptr);
1340
  /* ptr += 2; */
1341
1342
  /* Now read in the two strings that follow.  */
1343
4.55k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1344
4.55k
  if (ptr == NULL)
1345
1.53k
    return NULL;
1346
1347
3.02k
  symbol_name = (char *) ptr;
1348
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1349
3.02k
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1350
1351
  /* Verify that the strings are null terminated.  */
1352
3.02k
  if (ptr[size - 1] != 0
1353
3.02k
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1354
930
    {
1355
930
      _bfd_error_handler
1356
930
  (_("%pB: string not null terminated in ILF object file"), abfd);
1357
930
      bfd_set_error (bfd_error_malformed_archive);
1358
930
      bfd_release (abfd, ptr);
1359
930
      return NULL;
1360
930
    }
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
2.09k
  import_name = source_dll + strlen (source_dll) + 1;
1369
2.09k
  if ((bfd_byte *) import_name >= ptr + size)
1370
758
    {
1371
      /* If this points at the end of the ptr+size block, we only had
1372
   two strings. */
1373
758
      import_name = NULL;
1374
758
    }
1375
1376
  /* Now construct the bfd.  */
1377
2.09k
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1378
2.09k
          source_dll, ordinal, types,
1379
2.09k
          import_name))
1380
1.98k
    {
1381
1.98k
      bfd_release (abfd, ptr);
1382
1.98k
      return NULL;
1383
1.98k
    }
1384
1385
105
  return pe_ILF_cleanup;
1386
2.09k
}
pei-arm.c:pe_ILF_object_p
Line
Count
Source
1195
92.2k
{
1196
92.2k
  bfd_byte    buffer[14];
1197
92.2k
  bfd_byte *    ptr;
1198
92.2k
  char *    symbol_name;
1199
92.2k
  char *    source_dll;
1200
92.2k
  char *    import_name;
1201
92.2k
  unsigned int    machine;
1202
92.2k
  bfd_size_type   size;
1203
92.2k
  unsigned int    ordinal;
1204
92.2k
  unsigned int    types;
1205
92.2k
  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
92.2k
  if (bfd_read (buffer, 14, abfd) != 14)
1210
564
    return NULL;
1211
1212
91.6k
  ptr = buffer;
1213
1214
91.6k
  machine = H_GET_16 (abfd, ptr);
1215
91.6k
  ptr += 2;
1216
1217
  /* Check that the machine type is recognised.  */
1218
91.6k
  magic = 0;
1219
1220
91.6k
  switch (machine)
1221
91.6k
    {
1222
527
    case IMAGE_FILE_MACHINE_UNKNOWN:
1223
636
    case IMAGE_FILE_MACHINE_ALPHA:
1224
638
    case IMAGE_FILE_MACHINE_ALPHA64:
1225
849
    case IMAGE_FILE_MACHINE_IA64:
1226
849
      break;
1227
1228
15.5k
    case IMAGE_FILE_MACHINE_I386:
1229
#ifdef I386MAGIC
1230
      magic = I386MAGIC;
1231
#endif
1232
15.5k
      break;
1233
1234
12.1k
    case IMAGE_FILE_MACHINE_AMD64:
1235
#ifdef AMD64MAGIC
1236
      magic = AMD64MAGIC;
1237
#endif
1238
12.1k
      break;
1239
1240
209
    case IMAGE_FILE_MACHINE_R3000:
1241
318
    case IMAGE_FILE_MACHINE_R4000:
1242
528
    case IMAGE_FILE_MACHINE_R10000:
1243
1244
635
    case IMAGE_FILE_MACHINE_MIPS16:
1245
841
    case IMAGE_FILE_MACHINE_MIPSFPU:
1246
845
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1247
#ifdef MIPS_ARCH_MAGIC_WINCE
1248
      magic = MIPS_ARCH_MAGIC_WINCE;
1249
#endif
1250
845
      break;
1251
1252
5.99k
    case IMAGE_FILE_MACHINE_SH3:
1253
13.3k
    case IMAGE_FILE_MACHINE_SH4:
1254
#ifdef SH_ARCH_MAGIC_WINCE
1255
      magic = SH_ARCH_MAGIC_WINCE;
1256
#endif
1257
13.3k
      break;
1258
1259
14.4k
    case IMAGE_FILE_MACHINE_ARM:
1260
14.4k
#ifdef ARMPEMAGIC
1261
14.4k
      magic = ARMPEMAGIC;
1262
14.4k
#endif
1263
14.4k
      break;
1264
1265
3.22k
    case IMAGE_FILE_MACHINE_ARM64:
1266
#ifdef AARCH64MAGIC
1267
      magic = AARCH64MAGIC;
1268
#endif
1269
3.22k
      break;
1270
1271
7.43k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1272
#ifdef LOONGARCH64MAGIC
1273
      magic = LOONGARCH64MAGIC;
1274
#endif
1275
7.43k
      break;
1276
1277
11.0k
    case IMAGE_FILE_MACHINE_RISCV64:
1278
#ifdef RISCV64MAGIC
1279
      magic = RISCV64MAGIC;
1280
#endif
1281
11.0k
      break;
1282
1283
6.69k
    case IMAGE_FILE_MACHINE_THUMB:
1284
6.69k
#ifdef THUMBPEMAGIC
1285
6.69k
      {
1286
6.69k
  extern const bfd_target TARGET_LITTLE_SYM;
1287
1288
6.69k
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1289
6.69k
    magic = THUMBPEMAGIC;
1290
6.69k
      }
1291
6.69k
#endif
1292
6.69k
      break;
1293
1294
0
    case IMAGE_FILE_MACHINE_POWERPC:
1295
      /* We no longer support PowerPC.  */
1296
6.08k
    default:
1297
6.08k
      _bfd_error_handler
1298
  /* xgettext:c-format */
1299
6.08k
  (_("%pB: unrecognised machine type (0x%x)"
1300
6.08k
     " in Import Library Format archive"),
1301
6.08k
   abfd, machine);
1302
6.08k
      bfd_set_error (bfd_error_malformed_archive);
1303
1304
6.08k
      return NULL;
1305
0
      break;
1306
91.6k
    }
1307
1308
85.5k
  if (magic == 0)
1309
64.4k
    {
1310
64.4k
      _bfd_error_handler
1311
  /* xgettext:c-format */
1312
64.4k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1313
64.4k
     " in Import Library Format archive"),
1314
64.4k
   abfd, machine);
1315
64.4k
      bfd_set_error (bfd_error_wrong_format);
1316
1317
64.4k
      return NULL;
1318
64.4k
    }
1319
1320
  /* We do not bother to check the date.
1321
     date = H_GET_32 (abfd, ptr);  */
1322
21.1k
  ptr += 4;
1323
1324
21.1k
  size = H_GET_32 (abfd, ptr);
1325
21.1k
  ptr += 4;
1326
1327
21.1k
  if (size == 0)
1328
418
    {
1329
418
      _bfd_error_handler
1330
418
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1331
418
      bfd_set_error (bfd_error_malformed_archive);
1332
1333
418
      return NULL;
1334
418
    }
1335
1336
20.6k
  ordinal = H_GET_16 (abfd, ptr);
1337
20.6k
  ptr += 2;
1338
1339
20.6k
  types = H_GET_16 (abfd, ptr);
1340
  /* ptr += 2; */
1341
1342
  /* Now read in the two strings that follow.  */
1343
20.6k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1344
20.6k
  if (ptr == NULL)
1345
1.53k
    return NULL;
1346
1347
19.1k
  symbol_name = (char *) ptr;
1348
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1349
19.1k
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1350
1351
  /* Verify that the strings are null terminated.  */
1352
19.1k
  if (ptr[size - 1] != 0
1353
19.1k
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1354
930
    {
1355
930
      _bfd_error_handler
1356
930
  (_("%pB: string not null terminated in ILF object file"), abfd);
1357
930
      bfd_set_error (bfd_error_malformed_archive);
1358
930
      bfd_release (abfd, ptr);
1359
930
      return NULL;
1360
930
    }
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
18.2k
  import_name = source_dll + strlen (source_dll) + 1;
1369
18.2k
  if ((bfd_byte *) import_name >= ptr + size)
1370
3.12k
    {
1371
      /* If this points at the end of the ptr+size block, we only had
1372
   two strings. */
1373
3.12k
      import_name = NULL;
1374
3.12k
    }
1375
1376
  /* Now construct the bfd.  */
1377
18.2k
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1378
18.2k
          source_dll, ordinal, types,
1379
18.2k
          import_name))
1380
1.98k
    {
1381
1.98k
      bfd_release (abfd, ptr);
1382
1.98k
      return NULL;
1383
1.98k
    }
1384
1385
16.2k
  return pe_ILF_cleanup;
1386
18.2k
}
pei-mcore.c:pe_ILF_object_p
Line
Count
Source
1195
65.4k
{
1196
65.4k
  bfd_byte    buffer[14];
1197
65.4k
  bfd_byte *    ptr;
1198
65.4k
  char *    symbol_name;
1199
65.4k
  char *    source_dll;
1200
65.4k
  char *    import_name;
1201
65.4k
  unsigned int    machine;
1202
65.4k
  bfd_size_type   size;
1203
65.4k
  unsigned int    ordinal;
1204
65.4k
  unsigned int    types;
1205
65.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
65.4k
  if (bfd_read (buffer, 14, abfd) != 14)
1210
564
    return NULL;
1211
1212
64.8k
  ptr = buffer;
1213
1214
64.8k
  machine = H_GET_16 (abfd, ptr);
1215
64.8k
  ptr += 2;
1216
1217
  /* Check that the machine type is recognised.  */
1218
64.8k
  magic = 0;
1219
1220
64.8k
  switch (machine)
1221
64.8k
    {
1222
527
    case IMAGE_FILE_MACHINE_UNKNOWN:
1223
636
    case IMAGE_FILE_MACHINE_ALPHA:
1224
638
    case IMAGE_FILE_MACHINE_ALPHA64:
1225
849
    case IMAGE_FILE_MACHINE_IA64:
1226
849
      break;
1227
1228
4.91k
    case IMAGE_FILE_MACHINE_I386:
1229
#ifdef I386MAGIC
1230
      magic = I386MAGIC;
1231
#endif
1232
4.91k
      break;
1233
1234
12.1k
    case IMAGE_FILE_MACHINE_AMD64:
1235
#ifdef AMD64MAGIC
1236
      magic = AMD64MAGIC;
1237
#endif
1238
12.1k
      break;
1239
1240
209
    case IMAGE_FILE_MACHINE_R3000:
1241
318
    case IMAGE_FILE_MACHINE_R4000:
1242
528
    case IMAGE_FILE_MACHINE_R10000:
1243
1244
635
    case IMAGE_FILE_MACHINE_MIPS16:
1245
841
    case IMAGE_FILE_MACHINE_MIPSFPU:
1246
845
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1247
#ifdef MIPS_ARCH_MAGIC_WINCE
1248
      magic = MIPS_ARCH_MAGIC_WINCE;
1249
#endif
1250
845
      break;
1251
1252
5.99k
    case IMAGE_FILE_MACHINE_SH3:
1253
13.3k
    case IMAGE_FILE_MACHINE_SH4:
1254
#ifdef SH_ARCH_MAGIC_WINCE
1255
      magic = SH_ARCH_MAGIC_WINCE;
1256
#endif
1257
13.3k
      break;
1258
1259
3.26k
    case IMAGE_FILE_MACHINE_ARM:
1260
#ifdef ARMPEMAGIC
1261
      magic = ARMPEMAGIC;
1262
#endif
1263
3.26k
      break;
1264
1265
3.22k
    case IMAGE_FILE_MACHINE_ARM64:
1266
#ifdef AARCH64MAGIC
1267
      magic = AARCH64MAGIC;
1268
#endif
1269
3.22k
      break;
1270
1271
7.43k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1272
#ifdef LOONGARCH64MAGIC
1273
      magic = LOONGARCH64MAGIC;
1274
#endif
1275
7.43k
      break;
1276
1277
11.0k
    case IMAGE_FILE_MACHINE_RISCV64:
1278
#ifdef RISCV64MAGIC
1279
      magic = RISCV64MAGIC;
1280
#endif
1281
11.0k
      break;
1282
1283
1.71k
    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.71k
      break;
1293
1294
0
    case IMAGE_FILE_MACHINE_POWERPC:
1295
      /* We no longer support PowerPC.  */
1296
6.08k
    default:
1297
6.08k
      _bfd_error_handler
1298
  /* xgettext:c-format */
1299
6.08k
  (_("%pB: unrecognised machine type (0x%x)"
1300
6.08k
     " in Import Library Format archive"),
1301
6.08k
   abfd, machine);
1302
6.08k
      bfd_set_error (bfd_error_malformed_archive);
1303
1304
6.08k
      return NULL;
1305
0
      break;
1306
64.8k
    }
1307
1308
58.7k
  if (magic == 0)
1309
58.7k
    {
1310
58.7k
      _bfd_error_handler
1311
  /* xgettext:c-format */
1312
58.7k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1313
58.7k
     " in Import Library Format archive"),
1314
58.7k
   abfd, machine);
1315
58.7k
      bfd_set_error (bfd_error_wrong_format);
1316
1317
58.7k
      return NULL;
1318
58.7k
    }
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
58.0k
{
1196
58.0k
  bfd_byte    buffer[14];
1197
58.0k
  bfd_byte *    ptr;
1198
58.0k
  char *    symbol_name;
1199
58.0k
  char *    source_dll;
1200
58.0k
  char *    import_name;
1201
58.0k
  unsigned int    machine;
1202
58.0k
  bfd_size_type   size;
1203
58.0k
  unsigned int    ordinal;
1204
58.0k
  unsigned int    types;
1205
58.0k
  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
58.0k
  if (bfd_read (buffer, 14, abfd) != 14)
1210
558
    return NULL;
1211
1212
57.4k
  ptr = buffer;
1213
1214
57.4k
  machine = H_GET_16 (abfd, ptr);
1215
57.4k
  ptr += 2;
1216
1217
  /* Check that the machine type is recognised.  */
1218
57.4k
  magic = 0;
1219
1220
57.4k
  switch (machine)
1221
57.4k
    {
1222
421
    case IMAGE_FILE_MACHINE_UNKNOWN:
1223
530
    case IMAGE_FILE_MACHINE_ALPHA:
1224
532
    case IMAGE_FILE_MACHINE_ALPHA64:
1225
743
    case IMAGE_FILE_MACHINE_IA64:
1226
743
      break;
1227
1228
4.91k
    case IMAGE_FILE_MACHINE_I386:
1229
#ifdef I386MAGIC
1230
      magic = I386MAGIC;
1231
#endif
1232
4.91k
      break;
1233
1234
12.1k
    case IMAGE_FILE_MACHINE_AMD64:
1235
#ifdef AMD64MAGIC
1236
      magic = AMD64MAGIC;
1237
#endif
1238
12.1k
      break;
1239
1240
209
    case IMAGE_FILE_MACHINE_R3000:
1241
318
    case IMAGE_FILE_MACHINE_R4000:
1242
527
    case IMAGE_FILE_MACHINE_R10000:
1243
1244
634
    case IMAGE_FILE_MACHINE_MIPS16:
1245
840
    case IMAGE_FILE_MACHINE_MIPSFPU:
1246
844
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1247
#ifdef MIPS_ARCH_MAGIC_WINCE
1248
      magic = MIPS_ARCH_MAGIC_WINCE;
1249
#endif
1250
844
      break;
1251
1252
6.01k
    case IMAGE_FILE_MACHINE_SH3:
1253
13.3k
    case IMAGE_FILE_MACHINE_SH4:
1254
13.3k
#ifdef SH_ARCH_MAGIC_WINCE
1255
13.3k
      magic = SH_ARCH_MAGIC_WINCE;
1256
13.3k
#endif
1257
13.3k
      break;
1258
1259
3.22k
    case IMAGE_FILE_MACHINE_ARM:
1260
#ifdef ARMPEMAGIC
1261
      magic = ARMPEMAGIC;
1262
#endif
1263
3.22k
      break;
1264
1265
3.22k
    case IMAGE_FILE_MACHINE_ARM64:
1266
#ifdef AARCH64MAGIC
1267
      magic = AARCH64MAGIC;
1268
#endif
1269
3.22k
      break;
1270
1271
7.43k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1272
#ifdef LOONGARCH64MAGIC
1273
      magic = LOONGARCH64MAGIC;
1274
#endif
1275
7.43k
      break;
1276
1277
3.85k
    case IMAGE_FILE_MACHINE_RISCV64:
1278
#ifdef RISCV64MAGIC
1279
      magic = RISCV64MAGIC;
1280
#endif
1281
3.85k
      break;
1282
1283
1.70k
    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.70k
      break;
1293
1294
0
    case IMAGE_FILE_MACHINE_POWERPC:
1295
      /* We no longer support PowerPC.  */
1296
5.96k
    default:
1297
5.96k
      _bfd_error_handler
1298
  /* xgettext:c-format */
1299
5.96k
  (_("%pB: unrecognised machine type (0x%x)"
1300
5.96k
     " in Import Library Format archive"),
1301
5.96k
   abfd, machine);
1302
5.96k
      bfd_set_error (bfd_error_malformed_archive);
1303
1304
5.96k
      return NULL;
1305
0
      break;
1306
57.4k
    }
1307
1308
51.5k
  if (magic == 0)
1309
38.1k
    {
1310
38.1k
      _bfd_error_handler
1311
  /* xgettext:c-format */
1312
38.1k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1313
38.1k
     " in Import Library Format archive"),
1314
38.1k
   abfd, machine);
1315
38.1k
      bfd_set_error (bfd_error_wrong_format);
1316
1317
38.1k
      return NULL;
1318
38.1k
    }
1319
1320
  /* We do not bother to check the date.
1321
     date = H_GET_32 (abfd, ptr);  */
1322
13.3k
  ptr += 4;
1323
1324
13.3k
  size = H_GET_32 (abfd, ptr);
1325
13.3k
  ptr += 4;
1326
1327
13.3k
  if (size == 0)
1328
315
    {
1329
315
      _bfd_error_handler
1330
315
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1331
315
      bfd_set_error (bfd_error_malformed_archive);
1332
1333
315
      return NULL;
1334
315
    }
1335
1336
13.0k
  ordinal = H_GET_16 (abfd, ptr);
1337
13.0k
  ptr += 2;
1338
1339
13.0k
  types = H_GET_16 (abfd, ptr);
1340
  /* ptr += 2; */
1341
1342
  /* Now read in the two strings that follow.  */
1343
13.0k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1344
13.0k
  if (ptr == NULL)
1345
1.33k
    return NULL;
1346
1347
11.7k
  symbol_name = (char *) ptr;
1348
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1349
11.7k
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1350
1351
  /* Verify that the strings are null terminated.  */
1352
11.7k
  if (ptr[size - 1] != 0
1353
11.7k
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1354
807
    {
1355
807
      _bfd_error_handler
1356
807
  (_("%pB: string not null terminated in ILF object file"), abfd);
1357
807
      bfd_set_error (bfd_error_malformed_archive);
1358
807
      bfd_release (abfd, ptr);
1359
807
      return NULL;
1360
807
    }
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.9k
  import_name = source_dll + strlen (source_dll) + 1;
1369
10.9k
  if ((bfd_byte *) import_name >= ptr + size)
1370
2.05k
    {
1371
      /* If this points at the end of the ptr+size block, we only had
1372
   two strings. */
1373
2.05k
      import_name = NULL;
1374
2.05k
    }
1375
1376
  /* Now construct the bfd.  */
1377
10.9k
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1378
10.9k
          source_dll, ordinal, types,
1379
10.9k
          import_name))
1380
1.82k
    {
1381
1.82k
      bfd_release (abfd, ptr);
1382
1.82k
      return NULL;
1383
1.82k
    }
1384
1385
9.08k
  return pe_ILF_cleanup;
1386
10.9k
}
1387
1388
static void
1389
pe_bfd_read_buildid (bfd *abfd)
1390
595k
{
1391
595k
  pe_data_type *pe = pe_data (abfd);
1392
595k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1393
595k
  asection *section;
1394
595k
  bfd_byte *data = 0;
1395
595k
  bfd_size_type dataoff;
1396
595k
  unsigned int i;
1397
595k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1398
595k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1399
1400
595k
  if (size == 0)
1401
304k
    return;
1402
1403
291k
  addr += extra->ImageBase;
1404
1405
  /* Search for the section containing the DebugDirectory.  */
1406
717k
  for (section = abfd->sections; section != NULL; section = section->next)
1407
571k
    {
1408
571k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1409
145k
  break;
1410
571k
    }
1411
1412
291k
  if (section == NULL)
1413
145k
    return;
1414
1415
145k
  if (!(section->flags & SEC_HAS_CONTENTS))
1416
15.6k
    return;
1417
1418
130k
  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
130k
  if (dataoff >= section->size
1424
130k
      || size > section->size - dataoff)
1425
48.8k
    {
1426
48.8k
      _bfd_error_handler
1427
48.8k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1428
48.8k
   abfd);
1429
48.8k
      return;
1430
48.8k
    }
1431
1432
  /* Read the whole section. */
1433
81.3k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1434
31.5k
    {
1435
31.5k
      free (data);
1436
31.5k
      return;
1437
31.5k
    }
1438
1439
  /* Search for a CodeView entry in the DebugDirectory */
1440
13.2M
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1441
13.2M
    {
1442
13.2M
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1443
13.2M
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1444
13.2M
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1445
1446
13.2M
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1447
1448
13.2M
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1449
31.1k
  {
1450
31.1k
    char buffer[256 + 1];
1451
31.1k
    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
31.1k
    if (_bfd_XXi_slurp_codeview_record (abfd,
1458
31.1k
                (file_ptr) idd.PointerToRawData,
1459
31.1k
                idd.SizeOfData, cvinfo, NULL))
1460
324
      {
1461
324
        struct bfd_build_id *build_id;
1462
324
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1463
1464
324
        build_id = bfd_alloc (abfd, bidlen);
1465
324
        if (build_id)
1466
324
    {
1467
324
      build_id->size = cvinfo->SignatureLength;
1468
324
      memcpy(build_id->data, cvinfo->Signature,
1469
324
       cvinfo->SignatureLength);
1470
324
      abfd->build_id = build_id;
1471
324
    }
1472
324
      }
1473
31.1k
    break;
1474
31.1k
  }
1475
13.2M
    }
1476
1477
49.7k
  free (data);
1478
49.7k
}
pei-i386.c:pe_bfd_read_buildid
Line
Count
Source
1390
107k
{
1391
107k
  pe_data_type *pe = pe_data (abfd);
1392
107k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1393
107k
  asection *section;
1394
107k
  bfd_byte *data = 0;
1395
107k
  bfd_size_type dataoff;
1396
107k
  unsigned int i;
1397
107k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1398
107k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1399
1400
107k
  if (size == 0)
1401
68.7k
    return;
1402
1403
38.6k
  addr += extra->ImageBase;
1404
1405
  /* Search for the section containing the DebugDirectory.  */
1406
81.3k
  for (section = abfd->sections; section != NULL; section = section->next)
1407
63.3k
    {
1408
63.3k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1409
20.6k
  break;
1410
63.3k
    }
1411
1412
38.6k
  if (section == NULL)
1413
18.0k
    return;
1414
1415
20.6k
  if (!(section->flags & SEC_HAS_CONTENTS))
1416
2.20k
    return;
1417
1418
18.4k
  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.4k
  if (dataoff >= section->size
1424
18.4k
      || size > section->size - dataoff)
1425
9.14k
    {
1426
9.14k
      _bfd_error_handler
1427
9.14k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1428
9.14k
   abfd);
1429
9.14k
      return;
1430
9.14k
    }
1431
1432
  /* Read the whole section. */
1433
9.31k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1434
6.08k
    {
1435
6.08k
      free (data);
1436
6.08k
      return;
1437
6.08k
    }
1438
1439
  /* Search for a CodeView entry in the DebugDirectory */
1440
19.1k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1441
16.9k
    {
1442
16.9k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1443
16.9k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1444
16.9k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1445
1446
16.9k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1447
1448
16.9k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1449
1.01k
  {
1450
1.01k
    char buffer[256 + 1];
1451
1.01k
    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.01k
    if (_bfd_XXi_slurp_codeview_record (abfd,
1458
1.01k
                (file_ptr) idd.PointerToRawData,
1459
1.01k
                idd.SizeOfData, cvinfo, NULL))
1460
59
      {
1461
59
        struct bfd_build_id *build_id;
1462
59
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1463
1464
59
        build_id = bfd_alloc (abfd, bidlen);
1465
59
        if (build_id)
1466
59
    {
1467
59
      build_id->size = cvinfo->SignatureLength;
1468
59
      memcpy(build_id->data, cvinfo->Signature,
1469
59
       cvinfo->SignatureLength);
1470
59
      abfd->build_id = build_id;
1471
59
    }
1472
59
      }
1473
1.01k
    break;
1474
1.01k
  }
1475
16.9k
    }
1476
1477
3.23k
  free (data);
1478
3.23k
}
pei-x86_64.c:pe_bfd_read_buildid
Line
Count
Source
1390
121k
{
1391
121k
  pe_data_type *pe = pe_data (abfd);
1392
121k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1393
121k
  asection *section;
1394
121k
  bfd_byte *data = 0;
1395
121k
  bfd_size_type dataoff;
1396
121k
  unsigned int i;
1397
121k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1398
121k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1399
1400
121k
  if (size == 0)
1401
69.7k
    return;
1402
1403
51.9k
  addr += extra->ImageBase;
1404
1405
  /* Search for the section containing the DebugDirectory.  */
1406
128k
  for (section = abfd->sections; section != NULL; section = section->next)
1407
104k
    {
1408
104k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1409
28.1k
  break;
1410
104k
    }
1411
1412
51.9k
  if (section == NULL)
1413
23.7k
    return;
1414
1415
28.1k
  if (!(section->flags & SEC_HAS_CONTENTS))
1416
2.04k
    return;
1417
1418
26.1k
  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
26.1k
  if (dataoff >= section->size
1424
26.1k
      || size > section->size - dataoff)
1425
4.92k
    {
1426
4.92k
      _bfd_error_handler
1427
4.92k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1428
4.92k
   abfd);
1429
4.92k
      return;
1430
4.92k
    }
1431
1432
  /* Read the whole section. */
1433
21.1k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1434
4.89k
    {
1435
4.89k
      free (data);
1436
4.89k
      return;
1437
4.89k
    }
1438
1439
  /* Search for a CodeView entry in the DebugDirectory */
1440
12.2M
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1441
12.2M
    {
1442
12.2M
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1443
12.2M
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1444
12.2M
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1445
1446
12.2M
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1447
1448
12.2M
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1449
12.3k
  {
1450
12.3k
    char buffer[256 + 1];
1451
12.3k
    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
12.3k
    if (_bfd_XXi_slurp_codeview_record (abfd,
1458
12.3k
                (file_ptr) idd.PointerToRawData,
1459
12.3k
                idd.SizeOfData, cvinfo, NULL))
1460
227
      {
1461
227
        struct bfd_build_id *build_id;
1462
227
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1463
1464
227
        build_id = bfd_alloc (abfd, bidlen);
1465
227
        if (build_id)
1466
227
    {
1467
227
      build_id->size = cvinfo->SignatureLength;
1468
227
      memcpy(build_id->data, cvinfo->Signature,
1469
227
       cvinfo->SignatureLength);
1470
227
      abfd->build_id = build_id;
1471
227
    }
1472
227
      }
1473
12.3k
    break;
1474
12.3k
  }
1475
12.2M
    }
1476
1477
16.3k
  free (data);
1478
16.3k
}
pei-aarch64.c:pe_bfd_read_buildid
Line
Count
Source
1390
63.0k
{
1391
63.0k
  pe_data_type *pe = pe_data (abfd);
1392
63.0k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1393
63.0k
  asection *section;
1394
63.0k
  bfd_byte *data = 0;
1395
63.0k
  bfd_size_type dataoff;
1396
63.0k
  unsigned int i;
1397
63.0k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1398
63.0k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1399
1400
63.0k
  if (size == 0)
1401
23.1k
    return;
1402
1403
39.9k
  addr += extra->ImageBase;
1404
1405
  /* Search for the section containing the DebugDirectory.  */
1406
101k
  for (section = abfd->sections; section != NULL; section = section->next)
1407
79.0k
    {
1408
79.0k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1409
17.1k
  break;
1410
79.0k
    }
1411
1412
39.9k
  if (section == NULL)
1413
22.8k
    return;
1414
1415
17.1k
  if (!(section->flags & SEC_HAS_CONTENTS))
1416
1.64k
    return;
1417
1418
15.4k
  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
15.4k
  if (dataoff >= section->size
1424
15.4k
      || size > section->size - dataoff)
1425
6.92k
    {
1426
6.92k
      _bfd_error_handler
1427
6.92k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1428
6.92k
   abfd);
1429
6.92k
      return;
1430
6.92k
    }
1431
1432
  /* Read the whole section. */
1433
8.55k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1434
2.37k
    {
1435
2.37k
      free (data);
1436
2.37k
      return;
1437
2.37k
    }
1438
1439
  /* Search for a CodeView entry in the DebugDirectory */
1440
609k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1441
606k
    {
1442
606k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1443
606k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1444
606k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1445
1446
606k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1447
1448
606k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1449
3.58k
  {
1450
3.58k
    char buffer[256 + 1];
1451
3.58k
    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.58k
    if (_bfd_XXi_slurp_codeview_record (abfd,
1458
3.58k
                (file_ptr) idd.PointerToRawData,
1459
3.58k
                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.58k
    break;
1474
3.58k
  }
1475
606k
    }
1476
1477
6.17k
  free (data);
1478
6.17k
}
pei-ia64.c:pe_bfd_read_buildid
Line
Count
Source
1390
64.5k
{
1391
64.5k
  pe_data_type *pe = pe_data (abfd);
1392
64.5k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1393
64.5k
  asection *section;
1394
64.5k
  bfd_byte *data = 0;
1395
64.5k
  bfd_size_type dataoff;
1396
64.5k
  unsigned int i;
1397
64.5k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1398
64.5k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1399
1400
64.5k
  if (size == 0)
1401
26.6k
    return;
1402
1403
37.9k
  addr += extra->ImageBase;
1404
1405
  /* Search for the section containing the DebugDirectory.  */
1406
81.5k
  for (section = abfd->sections; section != NULL; section = section->next)
1407
60.2k
    {
1408
60.2k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1409
16.6k
  break;
1410
60.2k
    }
1411
1412
37.9k
  if (section == NULL)
1413
21.3k
    return;
1414
1415
16.6k
  if (!(section->flags & SEC_HAS_CONTENTS))
1416
1.66k
    return;
1417
1418
14.9k
  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
14.9k
  if (dataoff >= section->size
1424
14.9k
      || size > section->size - dataoff)
1425
7.10k
    {
1426
7.10k
      _bfd_error_handler
1427
7.10k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1428
7.10k
   abfd);
1429
7.10k
      return;
1430
7.10k
    }
1431
1432
  /* Read the whole section. */
1433
7.84k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1434
2.92k
    {
1435
2.92k
      free (data);
1436
2.92k
      return;
1437
2.92k
    }
1438
1439
  /* Search for a CodeView entry in the DebugDirectory */
1440
48.9k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1441
47.6k
    {
1442
47.6k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1443
47.6k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1444
47.6k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1445
1446
47.6k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1447
1448
47.6k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1449
3.67k
  {
1450
3.67k
    char buffer[256 + 1];
1451
3.67k
    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.67k
    if (_bfd_XXi_slurp_codeview_record (abfd,
1458
3.67k
                (file_ptr) idd.PointerToRawData,
1459
3.67k
                idd.SizeOfData, cvinfo, NULL))
1460
0
      {
1461
0
        struct bfd_build_id *build_id;
1462
0
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1463
1464
0
        build_id = bfd_alloc (abfd, bidlen);
1465
0
        if (build_id)
1466
0
    {
1467
0
      build_id->size = cvinfo->SignatureLength;
1468
0
      memcpy(build_id->data, cvinfo->Signature,
1469
0
       cvinfo->SignatureLength);
1470
0
      abfd->build_id = build_id;
1471
0
    }
1472
0
      }
1473
3.67k
    break;
1474
3.67k
  }
1475
47.6k
    }
1476
1477
4.91k
  free (data);
1478
4.91k
}
pei-loongarch64.c:pe_bfd_read_buildid
Line
Count
Source
1390
60.5k
{
1391
60.5k
  pe_data_type *pe = pe_data (abfd);
1392
60.5k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1393
60.5k
  asection *section;
1394
60.5k
  bfd_byte *data = 0;
1395
60.5k
  bfd_size_type dataoff;
1396
60.5k
  unsigned int i;
1397
60.5k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1398
60.5k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1399
1400
60.5k
  if (size == 0)
1401
35.6k
    return;
1402
1403
24.8k
  addr += extra->ImageBase;
1404
1405
  /* Search for the section containing the DebugDirectory.  */
1406
91.5k
  for (section = abfd->sections; section != NULL; section = section->next)
1407
80.8k
    {
1408
80.8k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1409
14.1k
  break;
1410
80.8k
    }
1411
1412
24.8k
  if (section == NULL)
1413
10.7k
    return;
1414
1415
14.1k
  if (!(section->flags & SEC_HAS_CONTENTS))
1416
1.97k
    return;
1417
1418
12.1k
  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.1k
  if (dataoff >= section->size
1424
12.1k
      || size > section->size - dataoff)
1425
3.69k
    {
1426
3.69k
      _bfd_error_handler
1427
3.69k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1428
3.69k
   abfd);
1429
3.69k
      return;
1430
3.69k
    }
1431
1432
  /* Read the whole section. */
1433
8.48k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1434
2.10k
    {
1435
2.10k
      free (data);
1436
2.10k
      return;
1437
2.10k
    }
1438
1439
  /* Search for a CodeView entry in the DebugDirectory */
1440
61.6k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1441
58.9k
    {
1442
58.9k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1443
58.9k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1444
58.9k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1445
1446
58.9k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1447
1448
58.9k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1449
3.72k
  {
1450
3.72k
    char buffer[256 + 1];
1451
3.72k
    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.72k
    if (_bfd_XXi_slurp_codeview_record (abfd,
1458
3.72k
                (file_ptr) idd.PointerToRawData,
1459
3.72k
                idd.SizeOfData, cvinfo, NULL))
1460
2
      {
1461
2
        struct bfd_build_id *build_id;
1462
2
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1463
1464
2
        build_id = bfd_alloc (abfd, bidlen);
1465
2
        if (build_id)
1466
2
    {
1467
2
      build_id->size = cvinfo->SignatureLength;
1468
2
      memcpy(build_id->data, cvinfo->Signature,
1469
2
       cvinfo->SignatureLength);
1470
2
      abfd->build_id = build_id;
1471
2
    }
1472
2
      }
1473
3.72k
    break;
1474
3.72k
  }
1475
58.9k
    }
1476
1477
6.38k
  free (data);
1478
6.38k
}
pei-riscv64.c:pe_bfd_read_buildid
Line
Count
Source
1390
41.9k
{
1391
41.9k
  pe_data_type *pe = pe_data (abfd);
1392
41.9k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1393
41.9k
  asection *section;
1394
41.9k
  bfd_byte *data = 0;
1395
41.9k
  bfd_size_type dataoff;
1396
41.9k
  unsigned int i;
1397
41.9k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1398
41.9k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1399
1400
41.9k
  if (size == 0)
1401
20.0k
    return;
1402
1403
21.9k
  addr += extra->ImageBase;
1404
1405
  /* Search for the section containing the DebugDirectory.  */
1406
63.9k
  for (section = abfd->sections; section != NULL; section = section->next)
1407
49.0k
    {
1408
49.0k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1409
6.98k
  break;
1410
49.0k
    }
1411
1412
21.9k
  if (section == NULL)
1413
14.9k
    return;
1414
1415
6.98k
  if (!(section->flags & SEC_HAS_CONTENTS))
1416
921
    return;
1417
1418
6.06k
  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
6.06k
  if (dataoff >= section->size
1424
6.06k
      || size > section->size - dataoff)
1425
4.29k
    {
1426
4.29k
      _bfd_error_handler
1427
4.29k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1428
4.29k
   abfd);
1429
4.29k
      return;
1430
4.29k
    }
1431
1432
  /* Read the whole section. */
1433
1.77k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1434
1.60k
    {
1435
1.60k
      free (data);
1436
1.60k
      return;
1437
1.60k
    }
1438
1439
  /* Search for a CodeView entry in the DebugDirectory */
1440
23.7k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1441
23.7k
    {
1442
23.7k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1443
23.7k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1444
23.7k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1445
1446
23.7k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1447
1448
23.7k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1449
130
  {
1450
130
    char buffer[256 + 1];
1451
130
    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
130
    if (_bfd_XXi_slurp_codeview_record (abfd,
1458
130
                (file_ptr) idd.PointerToRawData,
1459
130
                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
130
    break;
1474
130
  }
1475
23.7k
    }
1476
1477
172
  free (data);
1478
172
}
pei-arm-wince.c:pe_bfd_read_buildid
Line
Count
Source
1390
21.3k
{
1391
21.3k
  pe_data_type *pe = pe_data (abfd);
1392
21.3k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1393
21.3k
  asection *section;
1394
21.3k
  bfd_byte *data = 0;
1395
21.3k
  bfd_size_type dataoff;
1396
21.3k
  unsigned int i;
1397
21.3k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1398
21.3k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1399
1400
21.3k
  if (size == 0)
1401
3.70k
    return;
1402
1403
17.6k
  addr += extra->ImageBase;
1404
1405
  /* Search for the section containing the DebugDirectory.  */
1406
34.5k
  for (section = abfd->sections; section != NULL; section = section->next)
1407
26.2k
    {
1408
26.2k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1409
9.36k
  break;
1410
26.2k
    }
1411
1412
17.6k
  if (section == NULL)
1413
8.27k
    return;
1414
1415
9.36k
  if (!(section->flags & SEC_HAS_CONTENTS))
1416
1.50k
    return;
1417
1418
7.86k
  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.86k
  if (dataoff >= section->size
1424
7.86k
      || size > section->size - dataoff)
1425
3.16k
    {
1426
3.16k
      _bfd_error_handler
1427
3.16k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1428
3.16k
   abfd);
1429
3.16k
      return;
1430
3.16k
    }
1431
1432
  /* Read the whole section. */
1433
4.70k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1434
2.39k
    {
1435
2.39k
      free (data);
1436
2.39k
      return;
1437
2.39k
    }
1438
1439
  /* Search for a CodeView entry in the DebugDirectory */
1440
54.2k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1441
52.9k
    {
1442
52.9k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1443
52.9k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1444
52.9k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1445
1446
52.9k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1447
1448
52.9k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1449
1.01k
  {
1450
1.01k
    char buffer[256 + 1];
1451
1.01k
    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.01k
    if (_bfd_XXi_slurp_codeview_record (abfd,
1458
1.01k
                (file_ptr) idd.PointerToRawData,
1459
1.01k
                idd.SizeOfData, cvinfo, NULL))
1460
4
      {
1461
4
        struct bfd_build_id *build_id;
1462
4
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1463
1464
4
        build_id = bfd_alloc (abfd, bidlen);
1465
4
        if (build_id)
1466
4
    {
1467
4
      build_id->size = cvinfo->SignatureLength;
1468
4
      memcpy(build_id->data, cvinfo->Signature,
1469
4
       cvinfo->SignatureLength);
1470
4
      abfd->build_id = build_id;
1471
4
    }
1472
4
      }
1473
1.01k
    break;
1474
1.01k
  }
1475
52.9k
    }
1476
1477
2.30k
  free (data);
1478
2.30k
}
pei-arm.c:pe_bfd_read_buildid
Line
Count
Source
1390
32.5k
{
1391
32.5k
  pe_data_type *pe = pe_data (abfd);
1392
32.5k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1393
32.5k
  asection *section;
1394
32.5k
  bfd_byte *data = 0;
1395
32.5k
  bfd_size_type dataoff;
1396
32.5k
  unsigned int i;
1397
32.5k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1398
32.5k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1399
1400
32.5k
  if (size == 0)
1401
11.9k
    return;
1402
1403
20.5k
  addr += extra->ImageBase;
1404
1405
  /* Search for the section containing the DebugDirectory.  */
1406
43.7k
  for (section = abfd->sections; section != NULL; section = section->next)
1407
34.5k
    {
1408
34.5k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1409
11.3k
  break;
1410
34.5k
    }
1411
1412
20.5k
  if (section == NULL)
1413
9.21k
    return;
1414
1415
11.3k
  if (!(section->flags & SEC_HAS_CONTENTS))
1416
1.43k
    return;
1417
1418
9.88k
  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.88k
  if (dataoff >= section->size
1424
9.88k
      || size > section->size - dataoff)
1425
3.83k
    {
1426
3.83k
      _bfd_error_handler
1427
3.83k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1428
3.83k
   abfd);
1429
3.83k
      return;
1430
3.83k
    }
1431
1432
  /* Read the whole section. */
1433
6.05k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1434
3.33k
    {
1435
3.33k
      free (data);
1436
3.33k
      return;
1437
3.33k
    }
1438
1439
  /* Search for a CodeView entry in the DebugDirectory */
1440
48.7k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1441
47.0k
    {
1442
47.0k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1443
47.0k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1444
47.0k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1445
1446
47.0k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1447
1448
47.0k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1449
1.07k
  {
1450
1.07k
    char buffer[256 + 1];
1451
1.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
1.07k
    if (_bfd_XXi_slurp_codeview_record (abfd,
1458
1.07k
                (file_ptr) idd.PointerToRawData,
1459
1.07k
                idd.SizeOfData, cvinfo, NULL))
1460
25
      {
1461
25
        struct bfd_build_id *build_id;
1462
25
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1463
1464
25
        build_id = bfd_alloc (abfd, bidlen);
1465
25
        if (build_id)
1466
25
    {
1467
25
      build_id->size = cvinfo->SignatureLength;
1468
25
      memcpy(build_id->data, cvinfo->Signature,
1469
25
       cvinfo->SignatureLength);
1470
25
      abfd->build_id = build_id;
1471
25
    }
1472
25
      }
1473
1.07k
    break;
1474
1.07k
  }
1475
47.0k
    }
1476
1477
2.72k
  free (data);
1478
2.72k
}
pei-mcore.c:pe_bfd_read_buildid
Line
Count
Source
1390
41.8k
{
1391
41.8k
  pe_data_type *pe = pe_data (abfd);
1392
41.8k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1393
41.8k
  asection *section;
1394
41.8k
  bfd_byte *data = 0;
1395
41.8k
  bfd_size_type dataoff;
1396
41.8k
  unsigned int i;
1397
41.8k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1398
41.8k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1399
1400
41.8k
  if (size == 0)
1401
22.1k
    return;
1402
1403
19.7k
  addr += extra->ImageBase;
1404
1405
  /* Search for the section containing the DebugDirectory.  */
1406
52.6k
  for (section = abfd->sections; section != NULL; section = section->next)
1407
44.2k
    {
1408
44.2k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1409
11.2k
  break;
1410
44.2k
    }
1411
1412
19.7k
  if (section == NULL)
1413
8.43k
    return;
1414
1415
11.2k
  if (!(section->flags & SEC_HAS_CONTENTS))
1416
1.27k
    return;
1417
1418
10.0k
  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
10.0k
  if (dataoff >= section->size
1424
10.0k
      || size > section->size - dataoff)
1425
2.37k
    {
1426
2.37k
      _bfd_error_handler
1427
2.37k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1428
2.37k
   abfd);
1429
2.37k
      return;
1430
2.37k
    }
1431
1432
  /* Read the whole section. */
1433
7.64k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1434
2.97k
    {
1435
2.97k
      free (data);
1436
2.97k
      return;
1437
2.97k
    }
1438
1439
  /* Search for a CodeView entry in the DebugDirectory */
1440
69.1k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1441
67.1k
    {
1442
67.1k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1443
67.1k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1444
67.1k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1445
1446
67.1k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1447
1448
67.1k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1449
2.62k
  {
1450
2.62k
    char buffer[256 + 1];
1451
2.62k
    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.62k
    if (_bfd_XXi_slurp_codeview_record (abfd,
1458
2.62k
                (file_ptr) idd.PointerToRawData,
1459
2.62k
                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.62k
    break;
1474
2.62k
  }
1475
67.1k
    }
1476
1477
4.67k
  free (data);
1478
4.67k
}
pei-sh.c:pe_bfd_read_buildid
Line
Count
Source
1390
40.3k
{
1391
40.3k
  pe_data_type *pe = pe_data (abfd);
1392
40.3k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1393
40.3k
  asection *section;
1394
40.3k
  bfd_byte *data = 0;
1395
40.3k
  bfd_size_type dataoff;
1396
40.3k
  unsigned int i;
1397
40.3k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1398
40.3k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1399
1400
40.3k
  if (size == 0)
1401
22.5k
    return;
1402
1403
17.8k
  addr += extra->ImageBase;
1404
1405
  /* Search for the section containing the DebugDirectory.  */
1406
37.6k
  for (section = abfd->sections; section != NULL; section = section->next)
1407
29.9k
    {
1408
29.9k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1409
10.2k
  break;
1410
29.9k
    }
1411
1412
17.8k
  if (section == NULL)
1413
7.67k
    return;
1414
1415
10.2k
  if (!(section->flags & SEC_HAS_CONTENTS))
1416
998
    return;
1417
1418
9.21k
  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.21k
  if (dataoff >= section->size
1424
9.21k
      || size > section->size - dataoff)
1425
3.43k
    {
1426
3.43k
      _bfd_error_handler
1427
3.43k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1428
3.43k
   abfd);
1429
3.43k
      return;
1430
3.43k
    }
1431
1432
  /* Read the whole section. */
1433
5.78k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1434
2.86k
    {
1435
2.86k
      free (data);
1436
2.86k
      return;
1437
2.86k
    }
1438
1439
  /* Search for a CodeView entry in the DebugDirectory */
1440
20.3k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1441
19.3k
    {
1442
19.3k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1443
19.3k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1444
19.3k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1445
1446
19.3k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1447
1448
19.3k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1449
1.88k
  {
1450
1.88k
    char buffer[256 + 1];
1451
1.88k
    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.88k
    if (_bfd_XXi_slurp_codeview_record (abfd,
1458
1.88k
                (file_ptr) idd.PointerToRawData,
1459
1.88k
                idd.SizeOfData, cvinfo, NULL))
1460
4
      {
1461
4
        struct bfd_build_id *build_id;
1462
4
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1463
1464
4
        build_id = bfd_alloc (abfd, bidlen);
1465
4
        if (build_id)
1466
4
    {
1467
4
      build_id->size = cvinfo->SignatureLength;
1468
4
      memcpy(build_id->data, cvinfo->Signature,
1469
4
       cvinfo->SignatureLength);
1470
4
      abfd->build_id = build_id;
1471
4
    }
1472
4
      }
1473
1.88k
    break;
1474
1.88k
  }
1475
19.3k
    }
1476
1477
2.91k
  free (data);
1478
2.91k
}
1479
1480
static bfd_cleanup
1481
pe_bfd_object_p (bfd *abfd)
1482
42.1M
{
1483
42.1M
  bfd_byte buffer[6];
1484
42.1M
  struct external_DOS_hdr dos_hdr;
1485
42.1M
  struct external_PEI_IMAGE_hdr image_hdr;
1486
42.1M
  struct internal_filehdr internal_f;
1487
42.1M
  struct internal_aouthdr internal_a;
1488
42.1M
  bfd_size_type opt_hdr_size;
1489
42.1M
  file_ptr offset;
1490
42.1M
  bfd_cleanup result;
1491
1492
  /* Detect if this a Microsoft Import Library Format element.  */
1493
  /* First read the beginning of the header.  */
1494
42.1M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1495
42.1M
      || bfd_read (buffer, 6, abfd) != 6)
1496
95.9k
    {
1497
95.9k
      if (bfd_get_error () != bfd_error_system_call)
1498
85.5k
  bfd_set_error (bfd_error_wrong_format);
1499
95.9k
      return NULL;
1500
95.9k
    }
1501
1502
  /* Then check the magic and the version (only 0 is supported).  */
1503
42.0M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1504
42.0M
      && H_GET_16 (abfd, buffer + 4) == 0)
1505
623k
    return pe_ILF_object_p (abfd);
1506
1507
41.4M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1508
41.4M
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1509
10.0M
    {
1510
10.0M
      if (bfd_get_error () != bfd_error_system_call)
1511
10.0M
  bfd_set_error (bfd_error_wrong_format);
1512
10.0M
      return NULL;
1513
10.0M
    }
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
31.4M
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1526
20.5M
    {
1527
20.5M
      bfd_set_error (bfd_error_wrong_format);
1528
20.5M
      return NULL;
1529
20.5M
    }
1530
1531
10.9M
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1532
10.9M
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1533
10.9M
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1534
27.4k
    {
1535
27.4k
      if (bfd_get_error () != bfd_error_system_call)
1536
27.4k
  bfd_set_error (bfd_error_wrong_format);
1537
27.4k
      return NULL;
1538
27.4k
    }
1539
1540
10.8M
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1541
109k
    {
1542
109k
      bfd_set_error (bfd_error_wrong_format);
1543
109k
      return NULL;
1544
109k
    }
1545
1546
  /* Swap file header, so that we get the location for calling
1547
     real_object_p.  */
1548
10.7M
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1549
1550
10.7M
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1551
10.7M
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1552
9.44M
    {
1553
9.44M
      bfd_set_error (bfd_error_wrong_format);
1554
9.44M
      return NULL;
1555
9.44M
    }
1556
1557
1.31M
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1558
1.31M
    sizeof (internal_f.pe.dos_message));
1559
1560
  /* Read the optional header, which has variable size.  */
1561
1.31M
  opt_hdr_size = internal_f.f_opthdr;
1562
1563
1.31M
  if (opt_hdr_size != 0)
1564
802k
    {
1565
802k
      bfd_size_type amt = opt_hdr_size;
1566
802k
      bfd_byte *opthdr;
1567
1568
      /* PR 17521 file: 230-131433-0.004.  */
1569
802k
      if (amt < sizeof (PEAOUTHDR))
1570
657k
  amt = sizeof (PEAOUTHDR);
1571
1572
802k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1573
802k
      if (opthdr == NULL)
1574
27.2k
  return NULL;
1575
775k
      if (amt > opt_hdr_size)
1576
642k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1577
1578
775k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1579
1580
775k
      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
92.2k
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1587
#else
1588
92.3k
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1589
31.2k
#endif
1590
92.1k
  {
1591
92.1k
    bfd_set_error (bfd_error_wrong_format);
1592
92.1k
    return NULL;
1593
92.1k
  }
1594
92.3k
#endif
1595
1596
683k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1597
683k
    || a->SectionAlignment >= 0x80000000)
1598
376k
  {
1599
376k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1600
376k
            abfd);
1601
376k
    a->SectionAlignment &= -a->SectionAlignment;
1602
376k
    if (a->SectionAlignment >= 0x80000000)
1603
11.2k
      a->SectionAlignment = 0x40000000;
1604
376k
  }
1605
1606
683k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1607
683k
    || a->FileAlignment > a->SectionAlignment)
1608
521k
  {
1609
521k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1610
521k
            abfd);
1611
521k
    a->FileAlignment &= -a->FileAlignment;
1612
521k
    if (a->FileAlignment > a->SectionAlignment)
1613
281k
      a->FileAlignment = a->SectionAlignment;
1614
521k
  }
1615
1616
683k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1617
405k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1618
92.3k
    }
1619
1620
1.19M
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1621
1.19M
             (opt_hdr_size != 0
1622
1.19M
        ? &internal_a
1623
1.19M
        : (struct internal_aouthdr *) NULL));
1624
1625
1.19M
  if (result)
1626
595k
    {
1627
      /* Now the whole header has been processed, see if there is a build-id */
1628
595k
      pe_bfd_read_buildid(abfd);
1629
595k
    }
1630
1631
1.19M
  return result;
1632
1.31M
}
pei-i386.c:pe_bfd_object_p
Line
Count
Source
1482
3.47M
{
1483
3.47M
  bfd_byte buffer[6];
1484
3.47M
  struct external_DOS_hdr dos_hdr;
1485
3.47M
  struct external_PEI_IMAGE_hdr image_hdr;
1486
3.47M
  struct internal_filehdr internal_f;
1487
3.47M
  struct internal_aouthdr internal_a;
1488
3.47M
  bfd_size_type opt_hdr_size;
1489
3.47M
  file_ptr offset;
1490
3.47M
  bfd_cleanup result;
1491
1492
  /* Detect if this a Microsoft Import Library Format element.  */
1493
  /* First read the beginning of the header.  */
1494
3.47M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1495
3.47M
      || bfd_read (buffer, 6, abfd) != 6)
1496
8.13k
    {
1497
8.13k
      if (bfd_get_error () != bfd_error_system_call)
1498
7.25k
  bfd_set_error (bfd_error_wrong_format);
1499
8.13k
      return NULL;
1500
8.13k
    }
1501
1502
  /* Then check the magic and the version (only 0 is supported).  */
1503
3.46M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1504
3.46M
      && H_GET_16 (abfd, buffer + 4) == 0)
1505
76.2k
    return pe_ILF_object_p (abfd);
1506
1507
3.38M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1508
3.38M
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1509
817k
    {
1510
817k
      if (bfd_get_error () != bfd_error_system_call)
1511
817k
  bfd_set_error (bfd_error_wrong_format);
1512
817k
      return NULL;
1513
817k
    }
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.57M
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1526
1.44M
    {
1527
1.44M
      bfd_set_error (bfd_error_wrong_format);
1528
1.44M
      return NULL;
1529
1.44M
    }
1530
1531
1.12M
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1532
1.12M
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1533
1.12M
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1534
2.82k
    {
1535
2.82k
      if (bfd_get_error () != bfd_error_system_call)
1536
2.82k
  bfd_set_error (bfd_error_wrong_format);
1537
2.82k
      return NULL;
1538
2.82k
    }
1539
1540
1.12M
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1541
11.9k
    {
1542
11.9k
      bfd_set_error (bfd_error_wrong_format);
1543
11.9k
      return NULL;
1544
11.9k
    }
1545
1546
  /* Swap file header, so that we get the location for calling
1547
     real_object_p.  */
1548
1.11M
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1549
1550
1.11M
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1551
1.11M
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1552
953k
    {
1553
953k
      bfd_set_error (bfd_error_wrong_format);
1554
953k
      return NULL;
1555
953k
    }
1556
1557
159k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1558
159k
    sizeof (internal_f.pe.dos_message));
1559
1560
  /* Read the optional header, which has variable size.  */
1561
159k
  opt_hdr_size = internal_f.f_opthdr;
1562
1563
159k
  if (opt_hdr_size != 0)
1564
113k
    {
1565
113k
      bfd_size_type amt = opt_hdr_size;
1566
113k
      bfd_byte *opthdr;
1567
1568
      /* PR 17521 file: 230-131433-0.004.  */
1569
113k
      if (amt < sizeof (PEAOUTHDR))
1570
104k
  amt = sizeof (PEAOUTHDR);
1571
1572
113k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1573
113k
      if (opthdr == NULL)
1574
2.99k
  return NULL;
1575
110k
      if (amt > opt_hdr_size)
1576
102k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1577
1578
110k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1579
1580
110k
      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
110k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1597
110k
    || a->SectionAlignment >= 0x80000000)
1598
78.1k
  {
1599
78.1k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1600
78.1k
            abfd);
1601
78.1k
    a->SectionAlignment &= -a->SectionAlignment;
1602
78.1k
    if (a->SectionAlignment >= 0x80000000)
1603
1.70k
      a->SectionAlignment = 0x40000000;
1604
78.1k
  }
1605
1606
110k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1607
110k
    || a->FileAlignment > a->SectionAlignment)
1608
89.3k
  {
1609
89.3k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1610
89.3k
            abfd);
1611
89.3k
    a->FileAlignment &= -a->FileAlignment;
1612
89.3k
    if (a->FileAlignment > a->SectionAlignment)
1613
46.3k
      a->FileAlignment = a->SectionAlignment;
1614
89.3k
  }
1615
1616
110k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1617
44.2k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1618
110k
    }
1619
1620
156k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1621
156k
             (opt_hdr_size != 0
1622
156k
        ? &internal_a
1623
156k
        : (struct internal_aouthdr *) NULL));
1624
1625
156k
  if (result)
1626
107k
    {
1627
      /* Now the whole header has been processed, see if there is a build-id */
1628
107k
      pe_bfd_read_buildid(abfd);
1629
107k
    }
1630
1631
156k
  return result;
1632
159k
}
pei-x86_64.c:pe_bfd_object_p
Line
Count
Source
1482
3.47M
{
1483
3.47M
  bfd_byte buffer[6];
1484
3.47M
  struct external_DOS_hdr dos_hdr;
1485
3.47M
  struct external_PEI_IMAGE_hdr image_hdr;
1486
3.47M
  struct internal_filehdr internal_f;
1487
3.47M
  struct internal_aouthdr internal_a;
1488
3.47M
  bfd_size_type opt_hdr_size;
1489
3.47M
  file_ptr offset;
1490
3.47M
  bfd_cleanup result;
1491
1492
  /* Detect if this a Microsoft Import Library Format element.  */
1493
  /* First read the beginning of the header.  */
1494
3.47M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1495
3.47M
      || bfd_read (buffer, 6, abfd) != 6)
1496
8.13k
    {
1497
8.13k
      if (bfd_get_error () != bfd_error_system_call)
1498
7.25k
  bfd_set_error (bfd_error_wrong_format);
1499
8.13k
      return NULL;
1500
8.13k
    }
1501
1502
  /* Then check the magic and the version (only 0 is supported).  */
1503
3.46M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1504
3.46M
      && H_GET_16 (abfd, buffer + 4) == 0)
1505
49.3k
    return pe_ILF_object_p (abfd);
1506
1507
3.41M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1508
3.41M
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1509
826k
    {
1510
826k
      if (bfd_get_error () != bfd_error_system_call)
1511
826k
  bfd_set_error (bfd_error_wrong_format);
1512
826k
      return NULL;
1513
826k
    }
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.59M
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1526
1.46M
    {
1527
1.46M
      bfd_set_error (bfd_error_wrong_format);
1528
1.46M
      return NULL;
1529
1.46M
    }
1530
1531
1.13M
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1532
1.13M
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1533
1.13M
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1534
2.82k
    {
1535
2.82k
      if (bfd_get_error () != bfd_error_system_call)
1536
2.82k
  bfd_set_error (bfd_error_wrong_format);
1537
2.82k
      return NULL;
1538
2.82k
    }
1539
1540
1.12M
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1541
11.9k
    {
1542
11.9k
      bfd_set_error (bfd_error_wrong_format);
1543
11.9k
      return NULL;
1544
11.9k
    }
1545
1546
  /* Swap file header, so that we get the location for calling
1547
     real_object_p.  */
1548
1.11M
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1549
1550
1.11M
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1551
1.11M
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1552
944k
    {
1553
944k
      bfd_set_error (bfd_error_wrong_format);
1554
944k
      return NULL;
1555
944k
    }
1556
1557
171k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1558
171k
    sizeof (internal_f.pe.dos_message));
1559
1560
  /* Read the optional header, which has variable size.  */
1561
171k
  opt_hdr_size = internal_f.f_opthdr;
1562
1563
171k
  if (opt_hdr_size != 0)
1564
104k
    {
1565
104k
      bfd_size_type amt = opt_hdr_size;
1566
104k
      bfd_byte *opthdr;
1567
1568
      /* PR 17521 file: 230-131433-0.004.  */
1569
104k
      if (amt < sizeof (PEAOUTHDR))
1570
92.3k
  amt = sizeof (PEAOUTHDR);
1571
1572
104k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1573
104k
      if (opthdr == NULL)
1574
2.60k
  return NULL;
1575
102k
      if (amt > opt_hdr_size)
1576
90.4k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1577
1578
102k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1579
1580
102k
      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
102k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1597
102k
    || a->SectionAlignment >= 0x80000000)
1598
67.6k
  {
1599
67.6k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1600
67.6k
            abfd);
1601
67.6k
    a->SectionAlignment &= -a->SectionAlignment;
1602
67.6k
    if (a->SectionAlignment >= 0x80000000)
1603
1.66k
      a->SectionAlignment = 0x40000000;
1604
67.6k
  }
1605
1606
102k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1607
102k
    || a->FileAlignment > a->SectionAlignment)
1608
79.4k
  {
1609
79.4k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1610
79.4k
            abfd);
1611
79.4k
    a->FileAlignment &= -a->FileAlignment;
1612
79.4k
    if (a->FileAlignment > a->SectionAlignment)
1613
37.8k
      a->FileAlignment = a->SectionAlignment;
1614
79.4k
  }
1615
1616
102k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1617
60.9k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1618
102k
    }
1619
1620
168k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1621
168k
             (opt_hdr_size != 0
1622
168k
        ? &internal_a
1623
168k
        : (struct internal_aouthdr *) NULL));
1624
1625
168k
  if (result)
1626
121k
    {
1627
      /* Now the whole header has been processed, see if there is a build-id */
1628
121k
      pe_bfd_read_buildid(abfd);
1629
121k
    }
1630
1631
168k
  return result;
1632
171k
}
pei-aarch64.c:pe_bfd_object_p
Line
Count
Source
1482
3.43M
{
1483
3.43M
  bfd_byte buffer[6];
1484
3.43M
  struct external_DOS_hdr dos_hdr;
1485
3.43M
  struct external_PEI_IMAGE_hdr image_hdr;
1486
3.43M
  struct internal_filehdr internal_f;
1487
3.43M
  struct internal_aouthdr internal_a;
1488
3.43M
  bfd_size_type opt_hdr_size;
1489
3.43M
  file_ptr offset;
1490
3.43M
  bfd_cleanup result;
1491
1492
  /* Detect if this a Microsoft Import Library Format element.  */
1493
  /* First read the beginning of the header.  */
1494
3.43M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1495
3.43M
      || bfd_read (buffer, 6, abfd) != 6)
1496
8.13k
    {
1497
8.13k
      if (bfd_get_error () != bfd_error_system_call)
1498
7.25k
  bfd_set_error (bfd_error_wrong_format);
1499
8.13k
      return NULL;
1500
8.13k
    }
1501
1502
  /* Then check the magic and the version (only 0 is supported).  */
1503
3.42M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1504
3.42M
      && H_GET_16 (abfd, buffer + 4) == 0)
1505
99.8k
    return pe_ILF_object_p (abfd);
1506
1507
3.32M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1508
3.32M
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1509
810k
    {
1510
810k
      if (bfd_get_error () != bfd_error_system_call)
1511
810k
  bfd_set_error (bfd_error_wrong_format);
1512
810k
      return NULL;
1513
810k
    }
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.51M
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1526
1.42M
    {
1527
1.42M
      bfd_set_error (bfd_error_wrong_format);
1528
1.42M
      return NULL;
1529
1.42M
    }
1530
1531
1.08M
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1532
1.08M
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1533
1.08M
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1534
3.42k
    {
1535
3.42k
      if (bfd_get_error () != bfd_error_system_call)
1536
3.42k
  bfd_set_error (bfd_error_wrong_format);
1537
3.42k
      return NULL;
1538
3.42k
    }
1539
1540
1.08M
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1541
12.6k
    {
1542
12.6k
      bfd_set_error (bfd_error_wrong_format);
1543
12.6k
      return NULL;
1544
12.6k
    }
1545
1546
  /* Swap file header, so that we get the location for calling
1547
     real_object_p.  */
1548
1.07M
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1549
1550
1.07M
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1551
1.07M
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1552
957k
    {
1553
957k
      bfd_set_error (bfd_error_wrong_format);
1554
957k
      return NULL;
1555
957k
    }
1556
1557
114k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1558
114k
    sizeof (internal_f.pe.dos_message));
1559
1560
  /* Read the optional header, which has variable size.  */
1561
114k
  opt_hdr_size = internal_f.f_opthdr;
1562
1563
114k
  if (opt_hdr_size != 0)
1564
80.4k
    {
1565
80.4k
      bfd_size_type amt = opt_hdr_size;
1566
80.4k
      bfd_byte *opthdr;
1567
1568
      /* PR 17521 file: 230-131433-0.004.  */
1569
80.4k
      if (amt < sizeof (PEAOUTHDR))
1570
45.3k
  amt = sizeof (PEAOUTHDR);
1571
1572
80.4k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1573
80.4k
      if (opthdr == NULL)
1574
2.43k
  return NULL;
1575
78.0k
      if (amt > opt_hdr_size)
1576
44.5k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1577
1578
78.0k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1579
1580
78.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
78.0k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1597
78.0k
    || a->SectionAlignment >= 0x80000000)
1598
37.9k
  {
1599
37.9k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1600
37.9k
            abfd);
1601
37.9k
    a->SectionAlignment &= -a->SectionAlignment;
1602
37.9k
    if (a->SectionAlignment >= 0x80000000)
1603
823
      a->SectionAlignment = 0x40000000;
1604
37.9k
  }
1605
1606
78.0k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1607
78.0k
    || a->FileAlignment > a->SectionAlignment)
1608
62.2k
  {
1609
62.2k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1610
62.2k
            abfd);
1611
62.2k
    a->FileAlignment &= -a->FileAlignment;
1612
62.2k
    if (a->FileAlignment > a->SectionAlignment)
1613
29.4k
      a->FileAlignment = a->SectionAlignment;
1614
62.2k
  }
1615
1616
78.0k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1617
57.0k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1618
78.0k
    }
1619
1620
112k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1621
112k
             (opt_hdr_size != 0
1622
112k
        ? &internal_a
1623
112k
        : (struct internal_aouthdr *) NULL));
1624
1625
112k
  if (result)
1626
63.0k
    {
1627
      /* Now the whole header has been processed, see if there is a build-id */
1628
63.0k
      pe_bfd_read_buildid(abfd);
1629
63.0k
    }
1630
1631
112k
  return result;
1632
114k
}
pei-ia64.c:pe_bfd_object_p
Line
Count
Source
1482
1.04M
{
1483
1.04M
  bfd_byte buffer[6];
1484
1.04M
  struct external_DOS_hdr dos_hdr;
1485
1.04M
  struct external_PEI_IMAGE_hdr image_hdr;
1486
1.04M
  struct internal_filehdr internal_f;
1487
1.04M
  struct internal_aouthdr internal_a;
1488
1.04M
  bfd_size_type opt_hdr_size;
1489
1.04M
  file_ptr offset;
1490
1.04M
  bfd_cleanup result;
1491
1492
  /* Detect if this a Microsoft Import Library Format element.  */
1493
  /* First read the beginning of the header.  */
1494
1.04M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1495
1.04M
      || 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
1.04M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1504
1.04M
      && H_GET_16 (abfd, buffer + 4) == 0)
1505
0
    return pe_ILF_object_p (abfd);
1506
1507
1.04M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1508
1.04M
      || 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
1.04M
  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
1.04M
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1532
1.04M
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1533
1.04M
      || 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
1.04M
  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
1.04M
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1549
1550
1.04M
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1551
1.04M
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1552
918k
    {
1553
918k
      bfd_set_error (bfd_error_wrong_format);
1554
918k
      return NULL;
1555
918k
    }
1556
1557
126k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1558
126k
    sizeof (internal_f.pe.dos_message));
1559
1560
  /* Read the optional header, which has variable size.  */
1561
126k
  opt_hdr_size = internal_f.f_opthdr;
1562
1563
126k
  if (opt_hdr_size != 0)
1564
73.4k
    {
1565
73.4k
      bfd_size_type amt = opt_hdr_size;
1566
73.4k
      bfd_byte *opthdr;
1567
1568
      /* PR 17521 file: 230-131433-0.004.  */
1569
73.4k
      if (amt < sizeof (PEAOUTHDR))
1570
67.2k
  amt = sizeof (PEAOUTHDR);
1571
1572
73.4k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1573
73.4k
      if (opthdr == NULL)
1574
2.53k
  return NULL;
1575
70.9k
      if (amt > opt_hdr_size)
1576
65.4k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1577
1578
70.9k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1579
1580
70.9k
      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
70.9k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1597
70.9k
    || a->SectionAlignment >= 0x80000000)
1598
18.4k
  {
1599
18.4k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1600
18.4k
            abfd);
1601
18.4k
    a->SectionAlignment &= -a->SectionAlignment;
1602
18.4k
    if (a->SectionAlignment >= 0x80000000)
1603
601
      a->SectionAlignment = 0x40000000;
1604
18.4k
  }
1605
1606
70.9k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1607
70.9k
    || a->FileAlignment > a->SectionAlignment)
1608
54.1k
  {
1609
54.1k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1610
54.1k
            abfd);
1611
54.1k
    a->FileAlignment &= -a->FileAlignment;
1612
54.1k
    if (a->FileAlignment > a->SectionAlignment)
1613
21.9k
      a->FileAlignment = a->SectionAlignment;
1614
54.1k
  }
1615
1616
70.9k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1617
46.8k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1618
70.9k
    }
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
64.5k
    {
1627
      /* Now the whole header has been processed, see if there is a build-id */
1628
64.5k
      pe_bfd_read_buildid(abfd);
1629
64.5k
    }
1630
1631
123k
  return result;
1632
126k
}
pei-loongarch64.c:pe_bfd_object_p
Line
Count
Source
1482
3.43M
{
1483
3.43M
  bfd_byte buffer[6];
1484
3.43M
  struct external_DOS_hdr dos_hdr;
1485
3.43M
  struct external_PEI_IMAGE_hdr image_hdr;
1486
3.43M
  struct internal_filehdr internal_f;
1487
3.43M
  struct internal_aouthdr internal_a;
1488
3.43M
  bfd_size_type opt_hdr_size;
1489
3.43M
  file_ptr offset;
1490
3.43M
  bfd_cleanup result;
1491
1492
  /* Detect if this a Microsoft Import Library Format element.  */
1493
  /* First read the beginning of the header.  */
1494
3.43M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1495
3.43M
      || bfd_read (buffer, 6, abfd) != 6)
1496
8.13k
    {
1497
8.13k
      if (bfd_get_error () != bfd_error_system_call)
1498
7.25k
  bfd_set_error (bfd_error_wrong_format);
1499
8.13k
      return NULL;
1500
8.13k
    }
1501
1502
  /* Then check the magic and the version (only 0 is supported).  */
1503
3.42M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1504
3.42M
      && H_GET_16 (abfd, buffer + 4) == 0)
1505
40.5k
    return pe_ILF_object_p (abfd);
1506
1507
3.38M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1508
3.38M
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1509
827k
    {
1510
827k
      if (bfd_get_error () != bfd_error_system_call)
1511
827k
  bfd_set_error (bfd_error_wrong_format);
1512
827k
      return NULL;
1513
827k
    }
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.55M
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1526
1.46M
    {
1527
1.46M
      bfd_set_error (bfd_error_wrong_format);
1528
1.46M
      return NULL;
1529
1.46M
    }
1530
1531
1.08M
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1532
1.08M
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1533
1.08M
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1534
2.82k
    {
1535
2.82k
      if (bfd_get_error () != bfd_error_system_call)
1536
2.82k
  bfd_set_error (bfd_error_wrong_format);
1537
2.82k
      return NULL;
1538
2.82k
    }
1539
1540
1.08M
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1541
11.9k
    {
1542
11.9k
      bfd_set_error (bfd_error_wrong_format);
1543
11.9k
      return NULL;
1544
11.9k
    }
1545
1546
  /* Swap file header, so that we get the location for calling
1547
     real_object_p.  */
1548
1.07M
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1549
1550
1.07M
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1551
1.07M
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1552
966k
    {
1553
966k
      bfd_set_error (bfd_error_wrong_format);
1554
966k
      return NULL;
1555
966k
    }
1556
1557
104k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1558
104k
    sizeof (internal_f.pe.dos_message));
1559
1560
  /* Read the optional header, which has variable size.  */
1561
104k
  opt_hdr_size = internal_f.f_opthdr;
1562
1563
104k
  if (opt_hdr_size != 0)
1564
55.4k
    {
1565
55.4k
      bfd_size_type amt = opt_hdr_size;
1566
55.4k
      bfd_byte *opthdr;
1567
1568
      /* PR 17521 file: 230-131433-0.004.  */
1569
55.4k
      if (amt < sizeof (PEAOUTHDR))
1570
33.2k
  amt = sizeof (PEAOUTHDR);
1571
1572
55.4k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1573
55.4k
      if (opthdr == NULL)
1574
2.34k
  return NULL;
1575
53.0k
      if (amt > opt_hdr_size)
1576
32.5k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1577
1578
53.0k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1579
1580
53.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
53.0k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1597
53.0k
    || a->SectionAlignment >= 0x80000000)
1598
25.3k
  {
1599
25.3k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1600
25.3k
            abfd);
1601
25.3k
    a->SectionAlignment &= -a->SectionAlignment;
1602
25.3k
    if (a->SectionAlignment >= 0x80000000)
1603
1.14k
      a->SectionAlignment = 0x40000000;
1604
25.3k
  }
1605
1606
53.0k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1607
53.0k
    || a->FileAlignment > a->SectionAlignment)
1608
34.9k
  {
1609
34.9k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1610
34.9k
            abfd);
1611
34.9k
    a->FileAlignment &= -a->FileAlignment;
1612
34.9k
    if (a->FileAlignment > a->SectionAlignment)
1613
19.8k
      a->FileAlignment = a->SectionAlignment;
1614
34.9k
  }
1615
1616
53.0k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1617
37.8k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1618
53.0k
    }
1619
1620
101k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1621
101k
             (opt_hdr_size != 0
1622
101k
        ? &internal_a
1623
101k
        : (struct internal_aouthdr *) NULL));
1624
1625
101k
  if (result)
1626
60.5k
    {
1627
      /* Now the whole header has been processed, see if there is a build-id */
1628
60.5k
      pe_bfd_read_buildid(abfd);
1629
60.5k
    }
1630
1631
101k
  return result;
1632
104k
}
pei-riscv64.c:pe_bfd_object_p
Line
Count
Source
1482
3.43M
{
1483
3.43M
  bfd_byte buffer[6];
1484
3.43M
  struct external_DOS_hdr dos_hdr;
1485
3.43M
  struct external_PEI_IMAGE_hdr image_hdr;
1486
3.43M
  struct internal_filehdr internal_f;
1487
3.43M
  struct internal_aouthdr internal_a;
1488
3.43M
  bfd_size_type opt_hdr_size;
1489
3.43M
  file_ptr offset;
1490
3.43M
  bfd_cleanup result;
1491
1492
  /* Detect if this a Microsoft Import Library Format element.  */
1493
  /* First read the beginning of the header.  */
1494
3.43M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1495
3.43M
      || bfd_read (buffer, 6, abfd) != 6)
1496
8.13k
    {
1497
8.13k
      if (bfd_get_error () != bfd_error_system_call)
1498
7.25k
  bfd_set_error (bfd_error_wrong_format);
1499
8.13k
      return NULL;
1500
8.13k
    }
1501
1502
  /* Then check the magic and the version (only 0 is supported).  */
1503
3.42M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1504
3.42M
      && H_GET_16 (abfd, buffer + 4) == 0)
1505
65.5k
    return pe_ILF_object_p (abfd);
1506
1507
3.35M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1508
3.35M
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1509
822k
    {
1510
822k
      if (bfd_get_error () != bfd_error_system_call)
1511
822k
  bfd_set_error (bfd_error_wrong_format);
1512
822k
      return NULL;
1513
822k
    }
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.53M
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1526
1.44M
    {
1527
1.44M
      bfd_set_error (bfd_error_wrong_format);
1528
1.44M
      return NULL;
1529
1.44M
    }
1530
1531
1.08M
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1532
1.08M
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1533
1.08M
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1534
2.82k
    {
1535
2.82k
      if (bfd_get_error () != bfd_error_system_call)
1536
2.82k
  bfd_set_error (bfd_error_wrong_format);
1537
2.82k
      return NULL;
1538
2.82k
    }
1539
1540
1.08M
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1541
11.9k
    {
1542
11.9k
      bfd_set_error (bfd_error_wrong_format);
1543
11.9k
      return NULL;
1544
11.9k
    }
1545
1546
  /* Swap file header, so that we get the location for calling
1547
     real_object_p.  */
1548
1.07M
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1549
1550
1.07M
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1551
1.07M
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1552
977k
    {
1553
977k
      bfd_set_error (bfd_error_wrong_format);
1554
977k
      return NULL;
1555
977k
    }
1556
1557
93.5k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1558
93.5k
    sizeof (internal_f.pe.dos_message));
1559
1560
  /* Read the optional header, which has variable size.  */
1561
93.5k
  opt_hdr_size = internal_f.f_opthdr;
1562
1563
93.5k
  if (opt_hdr_size != 0)
1564
66.5k
    {
1565
66.5k
      bfd_size_type amt = opt_hdr_size;
1566
66.5k
      bfd_byte *opthdr;
1567
1568
      /* PR 17521 file: 230-131433-0.004.  */
1569
66.5k
      if (amt < sizeof (PEAOUTHDR))
1570
43.9k
  amt = sizeof (PEAOUTHDR);
1571
1572
66.5k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1573
66.5k
      if (opthdr == NULL)
1574
1.91k
  return NULL;
1575
64.6k
      if (amt > opt_hdr_size)
1576
42.5k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1577
1578
64.6k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1579
1580
64.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
64.6k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1597
64.6k
    || a->SectionAlignment >= 0x80000000)
1598
28.6k
  {
1599
28.6k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1600
28.6k
            abfd);
1601
28.6k
    a->SectionAlignment &= -a->SectionAlignment;
1602
28.6k
    if (a->SectionAlignment >= 0x80000000)
1603
959
      a->SectionAlignment = 0x40000000;
1604
28.6k
  }
1605
1606
64.6k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1607
64.6k
    || a->FileAlignment > a->SectionAlignment)
1608
44.1k
  {
1609
44.1k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1610
44.1k
            abfd);
1611
44.1k
    a->FileAlignment &= -a->FileAlignment;
1612
44.1k
    if (a->FileAlignment > a->SectionAlignment)
1613
26.2k
      a->FileAlignment = a->SectionAlignment;
1614
44.1k
  }
1615
1616
64.6k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1617
37.3k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1618
64.6k
    }
1619
1620
91.6k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1621
91.6k
             (opt_hdr_size != 0
1622
91.6k
        ? &internal_a
1623
91.6k
        : (struct internal_aouthdr *) NULL));
1624
1625
91.6k
  if (result)
1626
41.9k
    {
1627
      /* Now the whole header has been processed, see if there is a build-id */
1628
41.9k
      pe_bfd_read_buildid(abfd);
1629
41.9k
    }
1630
1631
91.6k
  return result;
1632
93.5k
}
pei-arm-wince.c:pe_bfd_object_p
Line
Count
Source
1482
6.82M
{
1483
6.82M
  bfd_byte buffer[6];
1484
6.82M
  struct external_DOS_hdr dos_hdr;
1485
6.82M
  struct external_PEI_IMAGE_hdr image_hdr;
1486
6.82M
  struct internal_filehdr internal_f;
1487
6.82M
  struct internal_aouthdr internal_a;
1488
6.82M
  bfd_size_type opt_hdr_size;
1489
6.82M
  file_ptr offset;
1490
6.82M
  bfd_cleanup result;
1491
1492
  /* Detect if this a Microsoft Import Library Format element.  */
1493
  /* First read the beginning of the header.  */
1494
6.82M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1495
6.82M
      || bfd_read (buffer, 6, abfd) != 6)
1496
15.8k
    {
1497
15.8k
      if (bfd_get_error () != bfd_error_system_call)
1498
14.0k
  bfd_set_error (bfd_error_wrong_format);
1499
15.8k
      return NULL;
1500
15.8k
    }
1501
1502
  /* Then check the magic and the version (only 0 is supported).  */
1503
6.81M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1504
6.81M
      && H_GET_16 (abfd, buffer + 4) == 0)
1505
76.0k
    return pe_ILF_object_p (abfd);
1506
1507
6.73M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1508
6.73M
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1509
1.69M
    {
1510
1.69M
      if (bfd_get_error () != bfd_error_system_call)
1511
1.69M
  bfd_set_error (bfd_error_wrong_format);
1512
1.69M
      return NULL;
1513
1.69M
    }
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
5.04M
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1526
3.95M
    {
1527
3.95M
      bfd_set_error (bfd_error_wrong_format);
1528
3.95M
      return NULL;
1529
3.95M
    }
1530
1531
1.08M
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1532
1.08M
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1533
1.08M
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1534
3.50k
    {
1535
3.50k
      if (bfd_get_error () != bfd_error_system_call)
1536
3.50k
  bfd_set_error (bfd_error_wrong_format);
1537
3.50k
      return NULL;
1538
3.50k
    }
1539
1540
1.08M
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1541
12.6k
    {
1542
12.6k
      bfd_set_error (bfd_error_wrong_format);
1543
12.6k
      return NULL;
1544
12.6k
    }
1545
1546
  /* Swap file header, so that we get the location for calling
1547
     real_object_p.  */
1548
1.06M
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1549
1550
1.06M
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1551
1.06M
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1552
893k
    {
1553
893k
      bfd_set_error (bfd_error_wrong_format);
1554
893k
      return NULL;
1555
893k
    }
1556
1557
176k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1558
176k
    sizeof (internal_f.pe.dos_message));
1559
1560
  /* Read the optional header, which has variable size.  */
1561
176k
  opt_hdr_size = internal_f.f_opthdr;
1562
1563
176k
  if (opt_hdr_size != 0)
1564
95.4k
    {
1565
95.4k
      bfd_size_type amt = opt_hdr_size;
1566
95.4k
      bfd_byte *opthdr;
1567
1568
      /* PR 17521 file: 230-131433-0.004.  */
1569
95.4k
      if (amt < sizeof (PEAOUTHDR))
1570
84.0k
  amt = sizeof (PEAOUTHDR);
1571
1572
95.4k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1573
95.4k
      if (opthdr == NULL)
1574
3.19k
  return NULL;
1575
92.2k
      if (amt > opt_hdr_size)
1576
81.9k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1577
1578
92.2k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1579
1580
92.2k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1581
1582
92.2k
#ifdef ARM
1583
      /* Use Subsystem to distinguish between pei-arm-little and
1584
   pei-arm-wince-little.  */
1585
92.2k
#ifdef WINCE
1586
92.2k
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1587
#else
1588
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1589
#endif
1590
60.8k
  {
1591
60.8k
    bfd_set_error (bfd_error_wrong_format);
1592
60.8k
    return NULL;
1593
60.8k
  }
1594
31.3k
#endif
1595
1596
31.3k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1597
31.3k
    || a->SectionAlignment >= 0x80000000)
1598
19.9k
  {
1599
19.9k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1600
19.9k
            abfd);
1601
19.9k
    a->SectionAlignment &= -a->SectionAlignment;
1602
19.9k
    if (a->SectionAlignment >= 0x80000000)
1603
1.37k
      a->SectionAlignment = 0x40000000;
1604
19.9k
  }
1605
1606
31.3k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1607
31.3k
    || a->FileAlignment > a->SectionAlignment)
1608
26.5k
  {
1609
26.5k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1610
26.5k
            abfd);
1611
26.5k
    a->FileAlignment &= -a->FileAlignment;
1612
26.5k
    if (a->FileAlignment > a->SectionAlignment)
1613
16.5k
      a->FileAlignment = a->SectionAlignment;
1614
26.5k
  }
1615
1616
31.3k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1617
28.4k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1618
31.3k
    }
1619
1620
112k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1621
112k
             (opt_hdr_size != 0
1622
112k
        ? &internal_a
1623
112k
        : (struct internal_aouthdr *) NULL));
1624
1625
112k
  if (result)
1626
21.3k
    {
1627
      /* Now the whole header has been processed, see if there is a build-id */
1628
21.3k
      pe_bfd_read_buildid(abfd);
1629
21.3k
    }
1630
1631
112k
  return result;
1632
176k
}
pei-arm.c:pe_bfd_object_p
Line
Count
Source
1482
6.82M
{
1483
6.82M
  bfd_byte buffer[6];
1484
6.82M
  struct external_DOS_hdr dos_hdr;
1485
6.82M
  struct external_PEI_IMAGE_hdr image_hdr;
1486
6.82M
  struct internal_filehdr internal_f;
1487
6.82M
  struct internal_aouthdr internal_a;
1488
6.82M
  bfd_size_type opt_hdr_size;
1489
6.82M
  file_ptr offset;
1490
6.82M
  bfd_cleanup result;
1491
1492
  /* Detect if this a Microsoft Import Library Format element.  */
1493
  /* First read the beginning of the header.  */
1494
6.82M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1495
6.82M
      || bfd_read (buffer, 6, abfd) != 6)
1496
15.8k
    {
1497
15.8k
      if (bfd_get_error () != bfd_error_system_call)
1498
14.0k
  bfd_set_error (bfd_error_wrong_format);
1499
15.8k
      return NULL;
1500
15.8k
    }
1501
1502
  /* Then check the magic and the version (only 0 is supported).  */
1503
6.81M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1504
6.81M
      && H_GET_16 (abfd, buffer + 4) == 0)
1505
92.2k
    return pe_ILF_object_p (abfd);
1506
1507
6.71M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1508
6.71M
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1509
1.69M
    {
1510
1.69M
      if (bfd_get_error () != bfd_error_system_call)
1511
1.69M
  bfd_set_error (bfd_error_wrong_format);
1512
1.69M
      return NULL;
1513
1.69M
    }
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
5.02M
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1526
3.93M
    {
1527
3.93M
      bfd_set_error (bfd_error_wrong_format);
1528
3.93M
      return NULL;
1529
3.93M
    }
1530
1531
1.08M
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1532
1.08M
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1533
1.08M
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1534
3.50k
    {
1535
3.50k
      if (bfd_get_error () != bfd_error_system_call)
1536
3.50k
  bfd_set_error (bfd_error_wrong_format);
1537
3.50k
      return NULL;
1538
3.50k
    }
1539
1540
1.08M
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1541
12.6k
    {
1542
12.6k
      bfd_set_error (bfd_error_wrong_format);
1543
12.6k
      return NULL;
1544
12.6k
    }
1545
1546
  /* Swap file header, so that we get the location for calling
1547
     real_object_p.  */
1548
1.06M
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1549
1550
1.06M
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1551
1.06M
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1552
893k
    {
1553
893k
      bfd_set_error (bfd_error_wrong_format);
1554
893k
      return NULL;
1555
893k
    }
1556
1557
176k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1558
176k
    sizeof (internal_f.pe.dos_message));
1559
1560
  /* Read the optional header, which has variable size.  */
1561
176k
  opt_hdr_size = internal_f.f_opthdr;
1562
1563
176k
  if (opt_hdr_size != 0)
1564
95.5k
    {
1565
95.5k
      bfd_size_type amt = opt_hdr_size;
1566
95.5k
      bfd_byte *opthdr;
1567
1568
      /* PR 17521 file: 230-131433-0.004.  */
1569
95.5k
      if (amt < sizeof (PEAOUTHDR))
1570
84.1k
  amt = sizeof (PEAOUTHDR);
1571
1572
95.5k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1573
95.5k
      if (opthdr == NULL)
1574
3.19k
  return NULL;
1575
92.3k
      if (amt > opt_hdr_size)
1576
82.0k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1577
1578
92.3k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1579
1580
92.3k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1581
1582
92.3k
#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
92.3k
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1589
31.2k
#endif
1590
31.2k
  {
1591
31.2k
    bfd_set_error (bfd_error_wrong_format);
1592
31.2k
    return NULL;
1593
31.2k
  }
1594
61.0k
#endif
1595
1596
61.0k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1597
61.0k
    || a->SectionAlignment >= 0x80000000)
1598
33.8k
  {
1599
33.8k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1600
33.8k
            abfd);
1601
33.8k
    a->SectionAlignment &= -a->SectionAlignment;
1602
33.8k
    if (a->SectionAlignment >= 0x80000000)
1603
831
      a->SectionAlignment = 0x40000000;
1604
33.8k
  }
1605
1606
61.0k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1607
61.0k
    || a->FileAlignment > a->SectionAlignment)
1608
44.1k
  {
1609
44.1k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1610
44.1k
            abfd);
1611
44.1k
    a->FileAlignment &= -a->FileAlignment;
1612
44.1k
    if (a->FileAlignment > a->SectionAlignment)
1613
26.4k
      a->FileAlignment = a->SectionAlignment;
1614
44.1k
  }
1615
1616
61.0k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1617
31.1k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1618
61.0k
    }
1619
1620
142k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1621
142k
             (opt_hdr_size != 0
1622
142k
        ? &internal_a
1623
142k
        : (struct internal_aouthdr *) NULL));
1624
1625
142k
  if (result)
1626
32.5k
    {
1627
      /* Now the whole header has been processed, see if there is a build-id */
1628
32.5k
      pe_bfd_read_buildid(abfd);
1629
32.5k
    }
1630
1631
142k
  return result;
1632
176k
}
pei-mcore.c:pe_bfd_object_p
Line
Count
Source
1482
6.82M
{
1483
6.82M
  bfd_byte buffer[6];
1484
6.82M
  struct external_DOS_hdr dos_hdr;
1485
6.82M
  struct external_PEI_IMAGE_hdr image_hdr;
1486
6.82M
  struct internal_filehdr internal_f;
1487
6.82M
  struct internal_aouthdr internal_a;
1488
6.82M
  bfd_size_type opt_hdr_size;
1489
6.82M
  file_ptr offset;
1490
6.82M
  bfd_cleanup result;
1491
1492
  /* Detect if this a Microsoft Import Library Format element.  */
1493
  /* First read the beginning of the header.  */
1494
6.82M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1495
6.82M
      || bfd_read (buffer, 6, abfd) != 6)
1496
15.8k
    {
1497
15.8k
      if (bfd_get_error () != bfd_error_system_call)
1498
14.0k
  bfd_set_error (bfd_error_wrong_format);
1499
15.8k
      return NULL;
1500
15.8k
    }
1501
1502
  /* Then check the magic and the version (only 0 is supported).  */
1503
6.81M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1504
6.81M
      && H_GET_16 (abfd, buffer + 4) == 0)
1505
65.4k
    return pe_ILF_object_p (abfd);
1506
1507
6.74M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1508
6.74M
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1509
1.69M
    {
1510
1.69M
      if (bfd_get_error () != bfd_error_system_call)
1511
1.69M
  bfd_set_error (bfd_error_wrong_format);
1512
1.69M
      return NULL;
1513
1.69M
    }
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
5.05M
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1526
3.96M
    {
1527
3.96M
      bfd_set_error (bfd_error_wrong_format);
1528
3.96M
      return NULL;
1529
3.96M
    }
1530
1531
1.08M
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1532
1.08M
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1533
1.08M
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1534
2.92k
    {
1535
2.92k
      if (bfd_get_error () != bfd_error_system_call)
1536
2.92k
  bfd_set_error (bfd_error_wrong_format);
1537
2.92k
      return NULL;
1538
2.92k
    }
1539
1540
1.08M
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1541
11.9k
    {
1542
11.9k
      bfd_set_error (bfd_error_wrong_format);
1543
11.9k
      return NULL;
1544
11.9k
    }
1545
1546
  /* Swap file header, so that we get the location for calling
1547
     real_object_p.  */
1548
1.06M
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1549
1550
1.06M
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1551
1.06M
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1552
973k
    {
1553
973k
      bfd_set_error (bfd_error_wrong_format);
1554
973k
      return NULL;
1555
973k
    }
1556
1557
95.5k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1558
95.5k
    sizeof (internal_f.pe.dos_message));
1559
1560
  /* Read the optional header, which has variable size.  */
1561
95.5k
  opt_hdr_size = internal_f.f_opthdr;
1562
1563
95.5k
  if (opt_hdr_size != 0)
1564
58.8k
    {
1565
58.8k
      bfd_size_type amt = opt_hdr_size;
1566
58.8k
      bfd_byte *opthdr;
1567
1568
      /* PR 17521 file: 230-131433-0.004.  */
1569
58.8k
      if (amt < sizeof (PEAOUTHDR))
1570
50.0k
  amt = sizeof (PEAOUTHDR);
1571
1572
58.8k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1573
58.8k
      if (opthdr == NULL)
1574
2.29k
  return NULL;
1575
56.5k
      if (amt > opt_hdr_size)
1576
48.7k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1577
1578
56.5k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1579
1580
56.5k
      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
56.5k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1597
56.5k
    || a->SectionAlignment >= 0x80000000)
1598
35.6k
  {
1599
35.6k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1600
35.6k
            abfd);
1601
35.6k
    a->SectionAlignment &= -a->SectionAlignment;
1602
35.6k
    if (a->SectionAlignment >= 0x80000000)
1603
1.18k
      a->SectionAlignment = 0x40000000;
1604
35.6k
  }
1605
1606
56.5k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1607
56.5k
    || a->FileAlignment > a->SectionAlignment)
1608
44.9k
  {
1609
44.9k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1610
44.9k
            abfd);
1611
44.9k
    a->FileAlignment &= -a->FileAlignment;
1612
44.9k
    if (a->FileAlignment > a->SectionAlignment)
1613
28.1k
      a->FileAlignment = a->SectionAlignment;
1614
44.9k
  }
1615
1616
56.5k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1617
28.9k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1618
56.5k
    }
1619
1620
93.2k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1621
93.2k
             (opt_hdr_size != 0
1622
93.2k
        ? &internal_a
1623
93.2k
        : (struct internal_aouthdr *) NULL));
1624
1625
93.2k
  if (result)
1626
41.8k
    {
1627
      /* Now the whole header has been processed, see if there is a build-id */
1628
41.8k
      pe_bfd_read_buildid(abfd);
1629
41.8k
    }
1630
1631
93.2k
  return result;
1632
95.5k
}
pei-sh.c:pe_bfd_object_p
Line
Count
Source
1482
3.41M
{
1483
3.41M
  bfd_byte buffer[6];
1484
3.41M
  struct external_DOS_hdr dos_hdr;
1485
3.41M
  struct external_PEI_IMAGE_hdr image_hdr;
1486
3.41M
  struct internal_filehdr internal_f;
1487
3.41M
  struct internal_aouthdr internal_a;
1488
3.41M
  bfd_size_type opt_hdr_size;
1489
3.41M
  file_ptr offset;
1490
3.41M
  bfd_cleanup result;
1491
1492
  /* Detect if this a Microsoft Import Library Format element.  */
1493
  /* First read the beginning of the header.  */
1494
3.41M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1495
3.41M
      || bfd_read (buffer, 6, abfd) != 6)
1496
7.90k
    {
1497
7.90k
      if (bfd_get_error () != bfd_error_system_call)
1498
7.03k
  bfd_set_error (bfd_error_wrong_format);
1499
7.90k
      return NULL;
1500
7.90k
    }
1501
1502
  /* Then check the magic and the version (only 0 is supported).  */
1503
3.40M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1504
3.40M
      && H_GET_16 (abfd, buffer + 4) == 0)
1505
58.0k
    return pe_ILF_object_p (abfd);
1506
1507
3.34M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1508
3.34M
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1509
818k
    {
1510
818k
      if (bfd_get_error () != bfd_error_system_call)
1511
818k
  bfd_set_error (bfd_error_wrong_format);
1512
818k
      return NULL;
1513
818k
    }
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.52M
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1526
1.44M
    {
1527
1.44M
      bfd_set_error (bfd_error_wrong_format);
1528
1.44M
      return NULL;
1529
1.44M
    }
1530
1531
1.08M
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1532
1.08M
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1533
1.08M
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1534
2.81k
    {
1535
2.81k
      if (bfd_get_error () != bfd_error_system_call)
1536
2.81k
  bfd_set_error (bfd_error_wrong_format);
1537
2.81k
      return NULL;
1538
2.81k
    }
1539
1540
1.08M
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1541
11.9k
    {
1542
11.9k
      bfd_set_error (bfd_error_wrong_format);
1543
11.9k
      return NULL;
1544
11.9k
    }
1545
1546
  /* Swap file header, so that we get the location for calling
1547
     real_object_p.  */
1548
1.06M
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1549
1550
1.06M
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1551
1.06M
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1552
969k
    {
1553
969k
      bfd_set_error (bfd_error_wrong_format);
1554
969k
      return NULL;
1555
969k
    }
1556
1557
99.7k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1558
99.7k
    sizeof (internal_f.pe.dos_message));
1559
1560
  /* Read the optional header, which has variable size.  */
1561
99.7k
  opt_hdr_size = internal_f.f_opthdr;
1562
1563
99.7k
  if (opt_hdr_size != 0)
1564
59.0k
    {
1565
59.0k
      bfd_size_type amt = opt_hdr_size;
1566
59.0k
      bfd_byte *opthdr;
1567
1568
      /* PR 17521 file: 230-131433-0.004.  */
1569
59.0k
      if (amt < sizeof (PEAOUTHDR))
1570
52.4k
  amt = sizeof (PEAOUTHDR);
1571
1572
59.0k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1573
59.0k
      if (opthdr == NULL)
1574
3.73k
  return NULL;
1575
55.3k
      if (amt > opt_hdr_size)
1576
51.0k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1577
1578
55.3k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1579
1580
55.3k
      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
55.3k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1597
55.3k
    || a->SectionAlignment >= 0x80000000)
1598
30.7k
  {
1599
30.7k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1600
30.7k
            abfd);
1601
30.7k
    a->SectionAlignment &= -a->SectionAlignment;
1602
30.7k
    if (a->SectionAlignment >= 0x80000000)
1603
966
      a->SectionAlignment = 0x40000000;
1604
30.7k
  }
1605
1606
55.3k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1607
55.3k
    || a->FileAlignment > a->SectionAlignment)
1608
41.1k
  {
1609
41.1k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1610
41.1k
            abfd);
1611
41.1k
    a->FileAlignment &= -a->FileAlignment;
1612
41.1k
    if (a->FileAlignment > a->SectionAlignment)
1613
28.4k
      a->FileAlignment = a->SectionAlignment;
1614
41.1k
  }
1615
1616
55.3k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1617
32.9k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1618
55.3k
    }
1619
1620
96.0k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1621
96.0k
             (opt_hdr_size != 0
1622
96.0k
        ? &internal_a
1623
96.0k
        : (struct internal_aouthdr *) NULL));
1624
1625
96.0k
  if (result)
1626
40.3k
    {
1627
      /* Now the whole header has been processed, see if there is a build-id */
1628
40.3k
      pe_bfd_read_buildid(abfd);
1629
40.3k
    }
1630
1631
96.0k
  return result;
1632
99.7k
}
1633
1634
1.04M
#define coff_object_p pe_bfd_object_p
1635
#endif /* COFF_IMAGE_WITH_PE */