Coverage Report

Created: 2023-06-29 07:13

/src/binutils-gdb/bfd/peicode.h
Line
Count
Source (jump to first uncovered line)
1
/* Support for the generic parts of PE/PEI, for BFD.
2
   Copyright (C) 1995-2023 Free Software Foundation, Inc.
3
   Written by Cygnus Solutions.
4
5
   This file is part of BFD, the Binary File Descriptor library.
6
7
   This program is free software; you can redistribute it and/or modify
8
   it under the terms of the GNU General Public License as published by
9
   the Free Software Foundation; either version 3 of the License, or
10
   (at your option) any later version.
11
12
   This program is distributed in the hope that it will be useful,
13
   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
   GNU General Public License for more details.
16
17
   You should have received a copy of the GNU General Public License
18
   along with this program; if not, write to the Free Software
19
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20
   MA 02110-1301, USA.  */
21
22
23
/* Most of this hacked by  Steve Chamberlain,
24
      sac@cygnus.com
25
26
   PE/PEI rearrangement (and code added): Donn Terry
27
               Softway Systems, Inc.  */
28
29
/* Hey look, some documentation [and in a place you expect to find it]!
30
31
   The main reference for the pei format is "Microsoft Portable Executable
32
   and Common Object File Format Specification 4.1".  Get it if you need to
33
   do some serious hacking on this code.
34
35
   Another reference:
36
   "Peering Inside the PE: A Tour of the Win32 Portable Executable
37
   File Format", MSJ 1994, Volume 9.
38
39
   The *sole* difference between the pe format and the pei format is that the
40
   latter has an MSDOS 2.0 .exe header on the front that prints the message
41
   "This app must be run under Windows." (or some such).
42
   (FIXME: Whether that statement is *really* true or not is unknown.
43
   Are there more subtle differences between pe and pei formats?
44
   For now assume there aren't.  If you find one, then for God sakes
45
   document it here!)
46
47
   The Microsoft docs use the word "image" instead of "executable" because
48
   the former can also refer to a DLL (shared library).  Confusion can arise
49
   because the `i' in `pei' also refers to "image".  The `pe' format can
50
   also create images (i.e. executables), it's just that to run on a win32
51
   system you need to use the pei format.
52
53
   FIXME: Please add more docs here so the next poor fool that has to hack
54
   on this code has a chance of getting something accomplished without
55
   wasting too much time.  */
56
57
#include "libpei.h"
58
59
static bool (*pe_saved_coff_bfd_print_private_bfd_data) (bfd *, void *) =
60
#ifndef coff_bfd_print_private_bfd_data
61
     NULL;
62
#else
63
     coff_bfd_print_private_bfd_data;
64
#undef coff_bfd_print_private_bfd_data
65
#endif
66
67
static bool pe_print_private_bfd_data (bfd *, void *);
68
#define coff_bfd_print_private_bfd_data pe_print_private_bfd_data
69
70
static bool (*pe_saved_coff_bfd_copy_private_bfd_data) (bfd *, bfd *) =
71
#ifndef coff_bfd_copy_private_bfd_data
72
     NULL;
73
#else
74
     coff_bfd_copy_private_bfd_data;
75
#undef coff_bfd_copy_private_bfd_data
76
#endif
77
78
static bool pe_bfd_copy_private_bfd_data (bfd *, bfd *);
79
#define coff_bfd_copy_private_bfd_data pe_bfd_copy_private_bfd_data
80
81
#define coff_mkobject    pe_mkobject
82
#define coff_mkobject_hook pe_mkobject_hook
83
84
#ifdef COFF_IMAGE_WITH_PE
85
/* This structure contains static variables used by the ILF code.  */
86
typedef asection * asection_ptr;
87
88
typedef struct
89
{
90
  bfd *     abfd;
91
  bfd_byte *    data;
92
  struct bfd_in_memory * bim;
93
  unsigned short  magic;
94
95
  arelent *   reltab;
96
  unsigned int    relcount;
97
98
  coff_symbol_type *  sym_cache;
99
  coff_symbol_type *  sym_ptr;
100
  unsigned int    sym_index;
101
102
  unsigned int *  sym_table;
103
  unsigned int *  table_ptr;
104
105
  combined_entry_type * native_syms;
106
  combined_entry_type * native_ptr;
107
108
  coff_symbol_type ** sym_ptr_table;
109
  coff_symbol_type ** sym_ptr_ptr;
110
111
  unsigned int    sec_index;
112
113
  char *    string_table;
114
  char *    string_ptr;
115
  char *    end_string_ptr;
116
117
  SYMENT *    esym_table;
118
  SYMENT *    esym_ptr;
119
120
  struct internal_reloc * int_reltab;
121
}
122
pe_ILF_vars;
123
#endif /* COFF_IMAGE_WITH_PE */
124
125
bfd_cleanup coff_real_object_p
126
  (bfd *, unsigned, struct internal_filehdr *, struct internal_aouthdr *);
127

128
#ifndef NO_COFF_RELOCS
129
static void
130
coff_swap_reloc_in (bfd * abfd, void * src, void * dst)
131
387k
{
132
387k
  RELOC *reloc_src = (RELOC *) src;
133
387k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
387k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
387k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
387k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
#ifdef SWAP_IN_RELOC_OFFSET
139
90.6k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
#endif
141
387k
}
pei-i386.c:coff_swap_reloc_in
Line
Count
Source
131
12.9k
{
132
12.9k
  RELOC *reloc_src = (RELOC *) src;
133
12.9k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
12.9k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
12.9k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
12.9k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
#ifdef SWAP_IN_RELOC_OFFSET
139
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
#endif
141
12.9k
}
pe-x86_64.c:coff_swap_reloc_in
Line
Count
Source
131
16.3k
{
132
16.3k
  RELOC *reloc_src = (RELOC *) src;
133
16.3k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
16.3k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
16.3k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
16.3k
  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.3k
}
pei-x86_64.c:coff_swap_reloc_in
Line
Count
Source
131
9.53k
{
132
9.53k
  RELOC *reloc_src = (RELOC *) src;
133
9.53k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
9.53k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
9.53k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
9.53k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
#ifdef SWAP_IN_RELOC_OFFSET
139
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
#endif
141
9.53k
}
pei-aarch64.c:coff_swap_reloc_in
Line
Count
Source
131
9.71k
{
132
9.71k
  RELOC *reloc_src = (RELOC *) src;
133
9.71k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
9.71k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
9.71k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
9.71k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
#ifdef SWAP_IN_RELOC_OFFSET
139
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
#endif
141
9.71k
}
pe-aarch64.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
#ifdef SWAP_IN_RELOC_OFFSET
139
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
#endif
141
17.2k
}
pei-ia64.c:coff_swap_reloc_in
Line
Count
Source
131
17.1k
{
132
17.1k
  RELOC *reloc_src = (RELOC *) src;
133
17.1k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
17.1k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
17.1k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
17.1k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
#ifdef SWAP_IN_RELOC_OFFSET
139
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
#endif
141
17.1k
}
pei-loongarch64.c:coff_swap_reloc_in
Line
Count
Source
131
8.19k
{
132
8.19k
  RELOC *reloc_src = (RELOC *) src;
133
8.19k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
8.19k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
8.19k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
8.19k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
8.19k
#ifdef SWAP_IN_RELOC_OFFSET
139
8.19k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
8.19k
#endif
141
8.19k
}
pe-arm-wince.c:coff_swap_reloc_in
Line
Count
Source
131
3.26k
{
132
3.26k
  RELOC *reloc_src = (RELOC *) src;
133
3.26k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
3.26k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
3.26k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
3.26k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
3.26k
#ifdef SWAP_IN_RELOC_OFFSET
139
3.26k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
3.26k
#endif
141
3.26k
}
pe-arm.c:coff_swap_reloc_in
Line
Count
Source
131
3.26k
{
132
3.26k
  RELOC *reloc_src = (RELOC *) src;
133
3.26k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
3.26k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
3.26k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
3.26k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
3.26k
#ifdef SWAP_IN_RELOC_OFFSET
139
3.26k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
3.26k
#endif
141
3.26k
}
pe-i386.c:coff_swap_reloc_in
Line
Count
Source
131
186k
{
132
186k
  RELOC *reloc_src = (RELOC *) src;
133
186k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
186k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
186k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
186k
  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
186k
}
pe-mcore.c:coff_swap_reloc_in
Line
Count
Source
131
24.9k
{
132
24.9k
  RELOC *reloc_src = (RELOC *) src;
133
24.9k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
24.9k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
24.9k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
24.9k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
24.9k
#ifdef SWAP_IN_RELOC_OFFSET
139
24.9k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
24.9k
#endif
141
24.9k
}
pe-sh.c:coff_swap_reloc_in
Line
Count
Source
131
12.9k
{
132
12.9k
  RELOC *reloc_src = (RELOC *) src;
133
12.9k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
12.9k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
12.9k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
12.9k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
#ifdef SWAP_IN_RELOC_OFFSET
139
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
#endif
141
12.9k
}
pei-arm-wince.c:coff_swap_reloc_in
Line
Count
Source
131
18.3k
{
132
18.3k
  RELOC *reloc_src = (RELOC *) src;
133
18.3k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
18.3k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
18.3k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
18.3k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
18.3k
#ifdef SWAP_IN_RELOC_OFFSET
139
18.3k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
18.3k
#endif
141
18.3k
}
pei-arm.c:coff_swap_reloc_in
Line
Count
Source
131
17.1k
{
132
17.1k
  RELOC *reloc_src = (RELOC *) src;
133
17.1k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
17.1k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
17.1k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
17.1k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
17.1k
#ifdef SWAP_IN_RELOC_OFFSET
139
17.1k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
17.1k
#endif
141
17.1k
}
pei-mcore.c:coff_swap_reloc_in
Line
Count
Source
131
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
}
pei-sh.c:coff_swap_reloc_in
Line
Count
Source
131
13.7k
{
132
13.7k
  RELOC *reloc_src = (RELOC *) src;
133
13.7k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
13.7k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
13.7k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
13.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
13.7k
}
142
143
static unsigned int
144
coff_swap_reloc_out (bfd * abfd, void * src, void * dst)
145
110
{
146
110
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
147
110
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
148
149
110
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
150
110
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
151
110
  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
110
  return RELSZ;
160
110
}
Unexecuted instantiation: pei-i386.c:coff_swap_reloc_out
Unexecuted instantiation: pe-x86_64.c:coff_swap_reloc_out
Unexecuted instantiation: pei-x86_64.c:coff_swap_reloc_out
Unexecuted instantiation: pei-aarch64.c:coff_swap_reloc_out
pe-aarch64.c:coff_swap_reloc_out
Line
Count
Source
145
110
{
146
110
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
147
110
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
148
149
110
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
150
110
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
151
110
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
152
153
#ifdef SWAP_OUT_RELOC_OFFSET
154
  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
110
  return RELSZ;
160
110
}
Unexecuted instantiation: pei-ia64.c:coff_swap_reloc_out
Unexecuted instantiation: pei-loongarch64.c:coff_swap_reloc_out
Unexecuted instantiation: pe-arm-wince.c:coff_swap_reloc_out
Unexecuted instantiation: pe-arm.c:coff_swap_reloc_out
Unexecuted instantiation: pe-i386.c:coff_swap_reloc_out
Unexecuted instantiation: pe-mcore.c:coff_swap_reloc_out
Unexecuted instantiation: pe-sh.c:coff_swap_reloc_out
Unexecuted instantiation: pei-arm-wince.c:coff_swap_reloc_out
Unexecuted instantiation: pei-arm.c:coff_swap_reloc_out
Unexecuted instantiation: pei-mcore.c:coff_swap_reloc_out
Unexecuted instantiation: pei-sh.c:coff_swap_reloc_out
161
#endif /* not NO_COFF_RELOCS */
162
163
#ifdef COFF_IMAGE_WITH_PE
164
#undef FILHDR
165
5.25M
#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
23.0M
{
171
23.0M
  FILHDR *filehdr_src = (FILHDR *) src;
172
23.0M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
23.0M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
23.0M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
23.0M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
23.0M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
23.0M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
23.0M
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
23.0M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
2.54M
    {
185
2.54M
      filehdr_dst->f_nsyms = 0;
186
2.54M
      filehdr_dst->f_flags |= F_LSYMS;
187
2.54M
    }
188
189
23.0M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
23.0M
}
pei-i386.c:coff_swap_filehdr_in
Line
Count
Source
170
595k
{
171
595k
  FILHDR *filehdr_src = (FILHDR *) src;
172
595k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
595k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
595k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
595k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
595k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
595k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
595k
  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
595k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
65.1k
    {
185
65.1k
      filehdr_dst->f_nsyms = 0;
186
65.1k
      filehdr_dst->f_flags |= F_LSYMS;
187
65.1k
    }
188
189
595k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
595k
}
pe-x86_64.c:coff_swap_filehdr_in
Line
Count
Source
170
1.80M
{
171
1.80M
  FILHDR *filehdr_src = (FILHDR *) src;
172
1.80M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
1.80M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
1.80M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
1.80M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
1.80M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
1.80M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
1.80M
  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.80M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
199k
    {
185
199k
      filehdr_dst->f_nsyms = 0;
186
199k
      filehdr_dst->f_flags |= F_LSYMS;
187
199k
    }
188
189
1.80M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
1.80M
}
pei-x86_64.c:coff_swap_filehdr_in
Line
Count
Source
170
602k
{
171
602k
  FILHDR *filehdr_src = (FILHDR *) src;
172
602k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
602k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
602k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
602k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
602k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
602k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
602k
  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
602k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
64.4k
    {
185
64.4k
      filehdr_dst->f_nsyms = 0;
186
64.4k
      filehdr_dst->f_flags |= F_LSYMS;
187
64.4k
    }
188
189
602k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
602k
}
pei-aarch64.c:coff_swap_filehdr_in
Line
Count
Source
170
582k
{
171
582k
  FILHDR *filehdr_src = (FILHDR *) src;
172
582k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
582k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
582k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
582k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
582k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
582k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
582k
  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
582k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
64.0k
    {
185
64.0k
      filehdr_dst->f_nsyms = 0;
186
64.0k
      filehdr_dst->f_flags |= F_LSYMS;
187
64.0k
    }
188
189
582k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
582k
}
pe-aarch64.c:coff_swap_filehdr_in
Line
Count
Source
170
1.78M
{
171
1.78M
  FILHDR *filehdr_src = (FILHDR *) src;
172
1.78M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
1.78M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
1.78M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
1.78M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
1.78M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
1.78M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
1.78M
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
1.78M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
199k
    {
185
199k
      filehdr_dst->f_nsyms = 0;
186
199k
      filehdr_dst->f_flags |= F_LSYMS;
187
199k
    }
188
189
1.78M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
1.78M
}
pei-ia64.c:coff_swap_filehdr_in
Line
Count
Source
170
565k
{
171
565k
  FILHDR *filehdr_src = (FILHDR *) src;
172
565k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
565k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
565k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
565k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
565k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
565k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
565k
  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
565k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
60.9k
    {
185
60.9k
      filehdr_dst->f_nsyms = 0;
186
60.9k
      filehdr_dst->f_flags |= F_LSYMS;
187
60.9k
    }
188
189
565k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
565k
}
pei-loongarch64.c:coff_swap_filehdr_in
Line
Count
Source
170
582k
{
171
582k
  FILHDR *filehdr_src = (FILHDR *) src;
172
582k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
582k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
582k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
582k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
582k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
582k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
582k
  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
582k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
64.0k
    {
185
64.0k
      filehdr_dst->f_nsyms = 0;
186
64.0k
      filehdr_dst->f_flags |= F_LSYMS;
187
64.0k
    }
188
189
582k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
582k
}
pe-arm-wince.c:coff_swap_filehdr_in
Line
Count
Source
170
3.54M
{
171
3.54M
  FILHDR *filehdr_src = (FILHDR *) src;
172
3.54M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
3.54M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
3.54M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
3.54M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
3.54M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
3.54M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
3.54M
  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.54M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
391k
    {
185
391k
      filehdr_dst->f_nsyms = 0;
186
391k
      filehdr_dst->f_flags |= F_LSYMS;
187
391k
    }
188
189
3.54M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
3.54M
}
pe-arm.c:coff_swap_filehdr_in
Line
Count
Source
170
3.54M
{
171
3.54M
  FILHDR *filehdr_src = (FILHDR *) src;
172
3.54M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
3.54M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
3.54M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
3.54M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
3.54M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
3.54M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
3.54M
  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.54M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
391k
    {
185
391k
      filehdr_dst->f_nsyms = 0;
186
391k
      filehdr_dst->f_flags |= F_LSYMS;
187
391k
    }
188
189
3.54M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
3.54M
}
pe-i386.c:coff_swap_filehdr_in
Line
Count
Source
170
1.78M
{
171
1.78M
  FILHDR *filehdr_src = (FILHDR *) src;
172
1.78M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
1.78M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
1.78M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
1.78M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
1.78M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
1.78M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
1.78M
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
1.78M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
198k
    {
185
198k
      filehdr_dst->f_nsyms = 0;
186
198k
      filehdr_dst->f_flags |= F_LSYMS;
187
198k
    }
188
189
1.78M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
1.78M
}
pe-mcore.c:coff_swap_filehdr_in
Line
Count
Source
170
3.54M
{
171
3.54M
  FILHDR *filehdr_src = (FILHDR *) src;
172
3.54M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
3.54M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
3.54M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
3.54M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
3.54M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
3.54M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
3.54M
  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.54M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
391k
    {
185
391k
      filehdr_dst->f_nsyms = 0;
186
391k
      filehdr_dst->f_flags |= F_LSYMS;
187
391k
    }
188
189
3.54M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
3.54M
}
pe-sh.c:coff_swap_filehdr_in
Line
Count
Source
170
1.77M
{
171
1.77M
  FILHDR *filehdr_src = (FILHDR *) src;
172
1.77M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
1.77M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
1.77M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
1.77M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
1.77M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
1.77M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
1.77M
  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.77M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
195k
    {
185
195k
      filehdr_dst->f_nsyms = 0;
186
195k
      filehdr_dst->f_flags |= F_LSYMS;
187
195k
    }
188
189
1.77M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
1.77M
}
pei-arm-wince.c:coff_swap_filehdr_in
Line
Count
Source
170
582k
{
171
582k
  FILHDR *filehdr_src = (FILHDR *) src;
172
582k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
582k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
582k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
582k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
582k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
582k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
582k
  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
582k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
63.9k
    {
185
63.9k
      filehdr_dst->f_nsyms = 0;
186
63.9k
      filehdr_dst->f_flags |= F_LSYMS;
187
63.9k
    }
188
189
582k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
582k
}
pei-arm.c:coff_swap_filehdr_in
Line
Count
Source
170
582k
{
171
582k
  FILHDR *filehdr_src = (FILHDR *) src;
172
582k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
582k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
582k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
582k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
582k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
582k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
582k
  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
582k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
63.9k
    {
185
63.9k
      filehdr_dst->f_nsyms = 0;
186
63.9k
      filehdr_dst->f_flags |= F_LSYMS;
187
63.9k
    }
188
189
582k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
582k
}
pei-mcore.c:coff_swap_filehdr_in
Line
Count
Source
170
582k
{
171
582k
  FILHDR *filehdr_src = (FILHDR *) src;
172
582k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
582k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
582k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
582k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
582k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
582k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
582k
  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
582k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
63.9k
    {
185
63.9k
      filehdr_dst->f_nsyms = 0;
186
63.9k
      filehdr_dst->f_flags |= F_LSYMS;
187
63.9k
    }
188
189
582k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
582k
}
pei-sh.c:coff_swap_filehdr_in
Line
Count
Source
170
581k
{
171
581k
  FILHDR *filehdr_src = (FILHDR *) src;
172
581k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
581k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
581k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
581k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
581k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
581k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
581k
  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
581k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
63.9k
    {
185
63.9k
      filehdr_dst->f_nsyms = 0;
186
63.9k
      filehdr_dst->f_flags |= F_LSYMS;
187
63.9k
    }
188
189
581k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
581k
}
191
192
#ifdef COFF_IMAGE_WITH_PE
193
# define coff_swap_filehdr_out _bfd_XXi_only_swap_filehdr_out
194
#elif defined COFF_WITH_peAArch64
195
# define coff_swap_filehdr_out _bfd_XX_only_swap_filehdr_out
196
#elif defined COFF_WITH_pex64
197
# define coff_swap_filehdr_out _bfd_pex64_only_swap_filehdr_out
198
#elif defined COFF_WITH_pep
199
# define coff_swap_filehdr_out _bfd_pep_only_swap_filehdr_out
200
#else
201
# define coff_swap_filehdr_out _bfd_pe_only_swap_filehdr_out
202
#endif
203
204
static void
205
coff_swap_scnhdr_in (bfd * abfd, void * ext, void * in)
206
3.68M
{
207
3.68M
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
3.68M
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
3.68M
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
3.68M
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
3.68M
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
3.68M
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
3.68M
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
3.68M
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
3.68M
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
3.68M
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
#ifdef COFF_IMAGE_WITH_PE
224
2.26M
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
2.26M
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
  scnhdr_int->s_nreloc = 0;
227
#else
228
1.42M
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
1.42M
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
#endif
231
232
3.68M
  if (scnhdr_int->s_vaddr != 0)
233
1.79M
    {
234
1.79M
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
      scnhdr_int->s_vaddr &= 0xffffffff;
238
#endif
239
1.79M
    }
240
241
3.68M
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
3.68M
  if (scnhdr_int->s_paddr > 0
247
3.68M
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
1.83M
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
1.83M
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
606k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
3.68M
#endif
256
3.68M
}
pei-i386.c:coff_swap_scnhdr_in
Line
Count
Source
206
208k
{
207
208k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
208k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
208k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
208k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
208k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
208k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
208k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
208k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
208k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
208k
  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
208k
#ifdef COFF_IMAGE_WITH_PE
224
208k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
208k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
208k
  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
208k
  if (scnhdr_int->s_vaddr != 0)
233
133k
    {
234
133k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
133k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
133k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
133k
#endif
239
133k
    }
240
241
208k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
208k
  if (scnhdr_int->s_paddr > 0
247
208k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
159k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
159k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
64.9k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
208k
#endif
256
208k
}
pe-x86_64.c:coff_swap_scnhdr_in
Line
Count
Source
206
318k
{
207
318k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
318k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
318k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
318k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
318k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
318k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
318k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
318k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
318k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
318k
  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
318k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
318k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
318k
#endif
231
232
318k
  if (scnhdr_int->s_vaddr != 0)
233
195k
    {
234
195k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
      scnhdr_int->s_vaddr &= 0xffffffff;
238
#endif
239
195k
    }
240
241
318k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
318k
  if (scnhdr_int->s_paddr > 0
247
318k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
189k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
189k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
27.0k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
318k
#endif
256
318k
}
pei-x86_64.c:coff_swap_scnhdr_in
Line
Count
Source
206
239k
{
207
239k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
239k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
239k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
239k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
239k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
239k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
239k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
239k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
239k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
239k
  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
239k
#ifdef COFF_IMAGE_WITH_PE
224
239k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
239k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
239k
  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
239k
  if (scnhdr_int->s_vaddr != 0)
233
160k
    {
234
160k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
      scnhdr_int->s_vaddr &= 0xffffffff;
238
#endif
239
160k
    }
240
241
239k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
239k
  if (scnhdr_int->s_paddr > 0
247
239k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
150k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
150k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
68.4k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
239k
#endif
256
239k
}
pei-aarch64.c:coff_swap_scnhdr_in
Line
Count
Source
206
153k
{
207
153k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
153k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
153k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
153k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
153k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
153k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
153k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
153k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
153k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
153k
  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
153k
#ifdef COFF_IMAGE_WITH_PE
224
153k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
153k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
153k
  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
153k
  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
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
      scnhdr_int->s_vaddr &= 0xffffffff;
238
#endif
239
109k
    }
240
241
153k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
153k
  if (scnhdr_int->s_paddr > 0
247
153k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
108k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
108k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
39.1k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
153k
#endif
256
153k
}
pe-aarch64.c:coff_swap_scnhdr_in
Line
Count
Source
206
166k
{
207
166k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
166k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
166k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
166k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
166k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
166k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
166k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
166k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
166k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
166k
  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
166k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
166k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
166k
#endif
231
232
166k
  if (scnhdr_int->s_vaddr != 0)
233
92.3k
    {
234
92.3k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
      scnhdr_int->s_vaddr &= 0xffffffff;
238
#endif
239
92.3k
    }
240
241
166k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
166k
  if (scnhdr_int->s_paddr > 0
247
166k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
97.1k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
97.1k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
43.5k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
166k
#endif
256
166k
}
pei-ia64.c:coff_swap_scnhdr_in
Line
Count
Source
206
246k
{
207
246k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
246k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
246k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
246k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
246k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
246k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
246k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
246k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
246k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
246k
  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
246k
#ifdef COFF_IMAGE_WITH_PE
224
246k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
246k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
246k
  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
246k
  if (scnhdr_int->s_vaddr != 0)
233
150k
    {
234
150k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
150k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
150k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
150k
#endif
239
150k
    }
240
241
246k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
246k
  if (scnhdr_int->s_paddr > 0
247
246k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
153k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
153k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
57.0k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
246k
#endif
256
246k
}
pei-loongarch64.c:coff_swap_scnhdr_in
Line
Count
Source
206
186k
{
207
186k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
186k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
186k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
186k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
186k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
186k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
186k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
186k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
186k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
186k
  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
186k
#ifdef COFF_IMAGE_WITH_PE
224
186k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
186k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
186k
  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
186k
  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
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
      scnhdr_int->s_vaddr &= 0xffffffff;
238
#endif
239
109k
    }
240
241
186k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
186k
  if (scnhdr_int->s_paddr > 0
247
186k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
112k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
112k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
36.2k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
186k
#endif
256
186k
}
pe-arm-wince.c:coff_swap_scnhdr_in
Line
Count
Source
206
42.3k
{
207
42.3k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
42.3k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
42.3k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
42.3k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
42.3k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
42.3k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
42.3k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
42.3k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
42.3k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
42.3k
  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
42.3k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
42.3k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
42.3k
#endif
231
232
42.3k
  if (scnhdr_int->s_vaddr != 0)
233
33.7k
    {
234
33.7k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
33.7k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
33.7k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
33.7k
#endif
239
33.7k
    }
240
241
42.3k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
42.3k
  if (scnhdr_int->s_paddr > 0
247
42.3k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
32.8k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
32.8k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
8.75k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
42.3k
#endif
256
42.3k
}
pe-arm.c:coff_swap_scnhdr_in
Line
Count
Source
206
42.3k
{
207
42.3k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
42.3k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
42.3k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
42.3k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
42.3k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
42.3k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
42.3k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
42.3k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
42.3k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
42.3k
  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
42.3k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
42.3k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
42.3k
#endif
231
232
42.3k
  if (scnhdr_int->s_vaddr != 0)
233
33.7k
    {
234
33.7k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
33.7k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
33.7k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
33.7k
#endif
239
33.7k
    }
240
241
42.3k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
42.3k
  if (scnhdr_int->s_paddr > 0
247
42.3k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
32.8k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
32.8k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
8.75k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
42.3k
#endif
256
42.3k
}
pe-i386.c:coff_swap_scnhdr_in
Line
Count
Source
206
145k
{
207
145k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
145k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
145k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
145k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
145k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
145k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
145k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
145k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
145k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
145k
  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
145k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
145k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
145k
#endif
231
232
145k
  if (scnhdr_int->s_vaddr != 0)
233
104k
    {
234
104k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
104k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
104k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
104k
#endif
239
104k
    }
240
241
145k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
145k
  if (scnhdr_int->s_paddr > 0
247
145k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
108k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
108k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
26.3k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
145k
#endif
256
145k
}
pe-mcore.c:coff_swap_scnhdr_in
Line
Count
Source
206
605k
{
207
605k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
605k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
605k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
605k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
605k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
605k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
605k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
605k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
605k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
605k
  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
605k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
605k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
605k
#endif
231
232
605k
  if (scnhdr_int->s_vaddr != 0)
233
101k
    {
234
101k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
101k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
101k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
101k
#endif
239
101k
    }
240
241
605k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
605k
  if (scnhdr_int->s_paddr > 0
247
605k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
101k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
101k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
19.7k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
605k
#endif
256
605k
}
pe-sh.c:coff_swap_scnhdr_in
Line
Count
Source
206
103k
{
207
103k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
103k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
103k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
103k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
103k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
103k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
103k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
103k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
103k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
103k
  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
103k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
103k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
103k
#endif
231
232
103k
  if (scnhdr_int->s_vaddr != 0)
233
68.6k
    {
234
68.6k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
68.6k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
68.6k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
68.6k
#endif
239
68.6k
    }
240
241
103k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
103k
  if (scnhdr_int->s_paddr > 0
247
103k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
69.9k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
69.9k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
12.3k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
103k
#endif
256
103k
}
pei-arm-wince.c:coff_swap_scnhdr_in
Line
Count
Source
206
158k
{
207
158k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
158k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
158k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
158k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
158k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
158k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
158k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
158k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
158k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
158k
  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
158k
#ifdef COFF_IMAGE_WITH_PE
224
158k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
158k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
158k
  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
158k
  if (scnhdr_int->s_vaddr != 0)
233
104k
    {
234
104k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
104k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
104k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
104k
#endif
239
104k
    }
240
241
158k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
158k
  if (scnhdr_int->s_paddr > 0
247
158k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
109k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
109k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
43.9k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
158k
#endif
256
158k
}
pei-arm.c:coff_swap_scnhdr_in
Line
Count
Source
206
637k
{
207
637k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
637k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
637k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
637k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
637k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
637k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
637k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
637k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
637k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
637k
  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
637k
#ifdef COFF_IMAGE_WITH_PE
224
637k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
637k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
637k
  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
637k
  if (scnhdr_int->s_vaddr != 0)
233
149k
    {
234
149k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
149k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
149k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
149k
#endif
239
149k
    }
240
241
637k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
637k
  if (scnhdr_int->s_paddr > 0
247
637k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
148k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
148k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
55.7k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
637k
#endif
256
637k
}
pei-mcore.c:coff_swap_scnhdr_in
Line
Count
Source
206
242k
{
207
242k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
242k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
242k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
242k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
242k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
242k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
242k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
242k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
242k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
242k
  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
242k
#ifdef COFF_IMAGE_WITH_PE
224
242k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
242k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
242k
  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
242k
  if (scnhdr_int->s_vaddr != 0)
233
145k
    {
234
145k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
145k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
145k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
145k
#endif
239
145k
    }
240
241
242k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
242k
  if (scnhdr_int->s_paddr > 0
247
242k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
153k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
153k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
52.4k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
242k
#endif
256
242k
}
pei-sh.c:coff_swap_scnhdr_in
Line
Count
Source
206
192k
{
207
192k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
192k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
192k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
192k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
192k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
192k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
192k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
192k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
192k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
192k
  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
192k
#ifdef COFF_IMAGE_WITH_PE
224
192k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
192k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
192k
  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
192k
  if (scnhdr_int->s_vaddr != 0)
233
99.8k
    {
234
99.8k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
99.8k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
99.8k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
99.8k
#endif
239
99.8k
    }
240
241
192k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
192k
  if (scnhdr_int->s_paddr > 0
247
192k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
104k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
104k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
42.2k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
192k
#endif
256
192k
}
257
258
static bool
259
pe_mkobject (bfd * abfd)
260
925k
{
261
925k
  pe_data_type *pe;
262
925k
  size_t amt = sizeof (pe_data_type);
263
264
925k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
925k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
925k
  pe = pe_data (abfd);
270
271
925k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
925k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
925k
  pe->dos_message[0]  = 0x0eba1f0e;
278
925k
  pe->dos_message[1]  = 0xcd09b400;
279
925k
  pe->dos_message[2]  = 0x4c01b821;
280
925k
  pe->dos_message[3]  = 0x685421cd;
281
925k
  pe->dos_message[4]  = 0x70207369;
282
925k
  pe->dos_message[5]  = 0x72676f72;
283
925k
  pe->dos_message[6]  = 0x63206d61;
284
925k
  pe->dos_message[7]  = 0x6f6e6e61;
285
925k
  pe->dos_message[8]  = 0x65622074;
286
925k
  pe->dos_message[9]  = 0x6e757220;
287
925k
  pe->dos_message[10] = 0x206e6920;
288
925k
  pe->dos_message[11] = 0x20534f44;
289
925k
  pe->dos_message[12] = 0x65646f6d;
290
925k
  pe->dos_message[13] = 0x0a0d0d2e;
291
925k
  pe->dos_message[14] = 0x24;
292
925k
  pe->dos_message[15] = 0x0;
293
294
925k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
925k
  bfd_coff_long_section_names (abfd)
297
925k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
925k
  return true;
300
925k
}
pei-i386.c:pe_mkobject
Line
Count
Source
260
73.2k
{
261
73.2k
  pe_data_type *pe;
262
73.2k
  size_t amt = sizeof (pe_data_type);
263
264
73.2k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
73.2k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
73.2k
  pe = pe_data (abfd);
270
271
73.2k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
73.2k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
73.2k
  pe->dos_message[0]  = 0x0eba1f0e;
278
73.2k
  pe->dos_message[1]  = 0xcd09b400;
279
73.2k
  pe->dos_message[2]  = 0x4c01b821;
280
73.2k
  pe->dos_message[3]  = 0x685421cd;
281
73.2k
  pe->dos_message[4]  = 0x70207369;
282
73.2k
  pe->dos_message[5]  = 0x72676f72;
283
73.2k
  pe->dos_message[6]  = 0x63206d61;
284
73.2k
  pe->dos_message[7]  = 0x6f6e6e61;
285
73.2k
  pe->dos_message[8]  = 0x65622074;
286
73.2k
  pe->dos_message[9]  = 0x6e757220;
287
73.2k
  pe->dos_message[10] = 0x206e6920;
288
73.2k
  pe->dos_message[11] = 0x20534f44;
289
73.2k
  pe->dos_message[12] = 0x65646f6d;
290
73.2k
  pe->dos_message[13] = 0x0a0d0d2e;
291
73.2k
  pe->dos_message[14] = 0x24;
292
73.2k
  pe->dos_message[15] = 0x0;
293
294
73.2k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
73.2k
  bfd_coff_long_section_names (abfd)
297
73.2k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
73.2k
  return true;
300
73.2k
}
pe-x86_64.c:pe_mkobject
Line
Count
Source
260
99.8k
{
261
99.8k
  pe_data_type *pe;
262
99.8k
  size_t amt = sizeof (pe_data_type);
263
264
99.8k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
99.8k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
99.8k
  pe = pe_data (abfd);
270
271
99.8k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
99.8k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
99.8k
  pe->dos_message[0]  = 0x0eba1f0e;
278
99.8k
  pe->dos_message[1]  = 0xcd09b400;
279
99.8k
  pe->dos_message[2]  = 0x4c01b821;
280
99.8k
  pe->dos_message[3]  = 0x685421cd;
281
99.8k
  pe->dos_message[4]  = 0x70207369;
282
99.8k
  pe->dos_message[5]  = 0x72676f72;
283
99.8k
  pe->dos_message[6]  = 0x63206d61;
284
99.8k
  pe->dos_message[7]  = 0x6f6e6e61;
285
99.8k
  pe->dos_message[8]  = 0x65622074;
286
99.8k
  pe->dos_message[9]  = 0x6e757220;
287
99.8k
  pe->dos_message[10] = 0x206e6920;
288
99.8k
  pe->dos_message[11] = 0x20534f44;
289
99.8k
  pe->dos_message[12] = 0x65646f6d;
290
99.8k
  pe->dos_message[13] = 0x0a0d0d2e;
291
99.8k
  pe->dos_message[14] = 0x24;
292
99.8k
  pe->dos_message[15] = 0x0;
293
294
99.8k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
99.8k
  bfd_coff_long_section_names (abfd)
297
99.8k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
99.8k
  return true;
300
99.8k
}
pei-x86_64.c:pe_mkobject
Line
Count
Source
260
88.5k
{
261
88.5k
  pe_data_type *pe;
262
88.5k
  size_t amt = sizeof (pe_data_type);
263
264
88.5k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
88.5k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
88.5k
  pe = pe_data (abfd);
270
271
88.5k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
88.5k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
88.5k
  pe->dos_message[0]  = 0x0eba1f0e;
278
88.5k
  pe->dos_message[1]  = 0xcd09b400;
279
88.5k
  pe->dos_message[2]  = 0x4c01b821;
280
88.5k
  pe->dos_message[3]  = 0x685421cd;
281
88.5k
  pe->dos_message[4]  = 0x70207369;
282
88.5k
  pe->dos_message[5]  = 0x72676f72;
283
88.5k
  pe->dos_message[6]  = 0x63206d61;
284
88.5k
  pe->dos_message[7]  = 0x6f6e6e61;
285
88.5k
  pe->dos_message[8]  = 0x65622074;
286
88.5k
  pe->dos_message[9]  = 0x6e757220;
287
88.5k
  pe->dos_message[10] = 0x206e6920;
288
88.5k
  pe->dos_message[11] = 0x20534f44;
289
88.5k
  pe->dos_message[12] = 0x65646f6d;
290
88.5k
  pe->dos_message[13] = 0x0a0d0d2e;
291
88.5k
  pe->dos_message[14] = 0x24;
292
88.5k
  pe->dos_message[15] = 0x0;
293
294
88.5k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
88.5k
  bfd_coff_long_section_names (abfd)
297
88.5k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
88.5k
  return true;
300
88.5k
}
pei-aarch64.c:pe_mkobject
Line
Count
Source
260
62.3k
{
261
62.3k
  pe_data_type *pe;
262
62.3k
  size_t amt = sizeof (pe_data_type);
263
264
62.3k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
62.3k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
62.3k
  pe = pe_data (abfd);
270
271
62.3k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
62.3k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
62.3k
  pe->dos_message[0]  = 0x0eba1f0e;
278
62.3k
  pe->dos_message[1]  = 0xcd09b400;
279
62.3k
  pe->dos_message[2]  = 0x4c01b821;
280
62.3k
  pe->dos_message[3]  = 0x685421cd;
281
62.3k
  pe->dos_message[4]  = 0x70207369;
282
62.3k
  pe->dos_message[5]  = 0x72676f72;
283
62.3k
  pe->dos_message[6]  = 0x63206d61;
284
62.3k
  pe->dos_message[7]  = 0x6f6e6e61;
285
62.3k
  pe->dos_message[8]  = 0x65622074;
286
62.3k
  pe->dos_message[9]  = 0x6e757220;
287
62.3k
  pe->dos_message[10] = 0x206e6920;
288
62.3k
  pe->dos_message[11] = 0x20534f44;
289
62.3k
  pe->dos_message[12] = 0x65646f6d;
290
62.3k
  pe->dos_message[13] = 0x0a0d0d2e;
291
62.3k
  pe->dos_message[14] = 0x24;
292
62.3k
  pe->dos_message[15] = 0x0;
293
294
62.3k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
62.3k
  bfd_coff_long_section_names (abfd)
297
62.3k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
62.3k
  return true;
300
62.3k
}
pe-aarch64.c:pe_mkobject
Line
Count
Source
260
27.8k
{
261
27.8k
  pe_data_type *pe;
262
27.8k
  size_t amt = sizeof (pe_data_type);
263
264
27.8k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
27.8k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
27.8k
  pe = pe_data (abfd);
270
271
27.8k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
27.8k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
27.8k
  pe->dos_message[0]  = 0x0eba1f0e;
278
27.8k
  pe->dos_message[1]  = 0xcd09b400;
279
27.8k
  pe->dos_message[2]  = 0x4c01b821;
280
27.8k
  pe->dos_message[3]  = 0x685421cd;
281
27.8k
  pe->dos_message[4]  = 0x70207369;
282
27.8k
  pe->dos_message[5]  = 0x72676f72;
283
27.8k
  pe->dos_message[6]  = 0x63206d61;
284
27.8k
  pe->dos_message[7]  = 0x6f6e6e61;
285
27.8k
  pe->dos_message[8]  = 0x65622074;
286
27.8k
  pe->dos_message[9]  = 0x6e757220;
287
27.8k
  pe->dos_message[10] = 0x206e6920;
288
27.8k
  pe->dos_message[11] = 0x20534f44;
289
27.8k
  pe->dos_message[12] = 0x65646f6d;
290
27.8k
  pe->dos_message[13] = 0x0a0d0d2e;
291
27.8k
  pe->dos_message[14] = 0x24;
292
27.8k
  pe->dos_message[15] = 0x0;
293
294
27.8k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
27.8k
  bfd_coff_long_section_names (abfd)
297
27.8k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
27.8k
  return true;
300
27.8k
}
pei-ia64.c:pe_mkobject
Line
Count
Source
260
83.0k
{
261
83.0k
  pe_data_type *pe;
262
83.0k
  size_t amt = sizeof (pe_data_type);
263
264
83.0k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
83.0k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
83.0k
  pe = pe_data (abfd);
270
271
83.0k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
83.0k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
83.0k
  pe->dos_message[0]  = 0x0eba1f0e;
278
83.0k
  pe->dos_message[1]  = 0xcd09b400;
279
83.0k
  pe->dos_message[2]  = 0x4c01b821;
280
83.0k
  pe->dos_message[3]  = 0x685421cd;
281
83.0k
  pe->dos_message[4]  = 0x70207369;
282
83.0k
  pe->dos_message[5]  = 0x72676f72;
283
83.0k
  pe->dos_message[6]  = 0x63206d61;
284
83.0k
  pe->dos_message[7]  = 0x6f6e6e61;
285
83.0k
  pe->dos_message[8]  = 0x65622074;
286
83.0k
  pe->dos_message[9]  = 0x6e757220;
287
83.0k
  pe->dos_message[10] = 0x206e6920;
288
83.0k
  pe->dos_message[11] = 0x20534f44;
289
83.0k
  pe->dos_message[12] = 0x65646f6d;
290
83.0k
  pe->dos_message[13] = 0x0a0d0d2e;
291
83.0k
  pe->dos_message[14] = 0x24;
292
83.0k
  pe->dos_message[15] = 0x0;
293
294
83.0k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
83.0k
  bfd_coff_long_section_names (abfd)
297
83.0k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
83.0k
  return true;
300
83.0k
}
pei-loongarch64.c:pe_mkobject
Line
Count
Source
260
57.4k
{
261
57.4k
  pe_data_type *pe;
262
57.4k
  size_t amt = sizeof (pe_data_type);
263
264
57.4k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
57.4k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
57.4k
  pe = pe_data (abfd);
270
271
57.4k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
57.4k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
57.4k
  pe->dos_message[0]  = 0x0eba1f0e;
278
57.4k
  pe->dos_message[1]  = 0xcd09b400;
279
57.4k
  pe->dos_message[2]  = 0x4c01b821;
280
57.4k
  pe->dos_message[3]  = 0x685421cd;
281
57.4k
  pe->dos_message[4]  = 0x70207369;
282
57.4k
  pe->dos_message[5]  = 0x72676f72;
283
57.4k
  pe->dos_message[6]  = 0x63206d61;
284
57.4k
  pe->dos_message[7]  = 0x6f6e6e61;
285
57.4k
  pe->dos_message[8]  = 0x65622074;
286
57.4k
  pe->dos_message[9]  = 0x6e757220;
287
57.4k
  pe->dos_message[10] = 0x206e6920;
288
57.4k
  pe->dos_message[11] = 0x20534f44;
289
57.4k
  pe->dos_message[12] = 0x65646f6d;
290
57.4k
  pe->dos_message[13] = 0x0a0d0d2e;
291
57.4k
  pe->dos_message[14] = 0x24;
292
57.4k
  pe->dos_message[15] = 0x0;
293
294
57.4k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
57.4k
  bfd_coff_long_section_names (abfd)
297
57.4k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
57.4k
  return true;
300
57.4k
}
pe-arm-wince.c:pe_mkobject
Line
Count
Source
260
14.4k
{
261
14.4k
  pe_data_type *pe;
262
14.4k
  size_t amt = sizeof (pe_data_type);
263
264
14.4k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
14.4k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
14.4k
  pe = pe_data (abfd);
270
271
14.4k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
14.4k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
14.4k
  pe->dos_message[0]  = 0x0eba1f0e;
278
14.4k
  pe->dos_message[1]  = 0xcd09b400;
279
14.4k
  pe->dos_message[2]  = 0x4c01b821;
280
14.4k
  pe->dos_message[3]  = 0x685421cd;
281
14.4k
  pe->dos_message[4]  = 0x70207369;
282
14.4k
  pe->dos_message[5]  = 0x72676f72;
283
14.4k
  pe->dos_message[6]  = 0x63206d61;
284
14.4k
  pe->dos_message[7]  = 0x6f6e6e61;
285
14.4k
  pe->dos_message[8]  = 0x65622074;
286
14.4k
  pe->dos_message[9]  = 0x6e757220;
287
14.4k
  pe->dos_message[10] = 0x206e6920;
288
14.4k
  pe->dos_message[11] = 0x20534f44;
289
14.4k
  pe->dos_message[12] = 0x65646f6d;
290
14.4k
  pe->dos_message[13] = 0x0a0d0d2e;
291
14.4k
  pe->dos_message[14] = 0x24;
292
14.4k
  pe->dos_message[15] = 0x0;
293
294
14.4k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
14.4k
  bfd_coff_long_section_names (abfd)
297
14.4k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
14.4k
  return true;
300
14.4k
}
pe-arm.c:pe_mkobject
Line
Count
Source
260
14.4k
{
261
14.4k
  pe_data_type *pe;
262
14.4k
  size_t amt = sizeof (pe_data_type);
263
264
14.4k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
14.4k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
14.4k
  pe = pe_data (abfd);
270
271
14.4k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
14.4k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
14.4k
  pe->dos_message[0]  = 0x0eba1f0e;
278
14.4k
  pe->dos_message[1]  = 0xcd09b400;
279
14.4k
  pe->dos_message[2]  = 0x4c01b821;
280
14.4k
  pe->dos_message[3]  = 0x685421cd;
281
14.4k
  pe->dos_message[4]  = 0x70207369;
282
14.4k
  pe->dos_message[5]  = 0x72676f72;
283
14.4k
  pe->dos_message[6]  = 0x63206d61;
284
14.4k
  pe->dos_message[7]  = 0x6f6e6e61;
285
14.4k
  pe->dos_message[8]  = 0x65622074;
286
14.4k
  pe->dos_message[9]  = 0x6e757220;
287
14.4k
  pe->dos_message[10] = 0x206e6920;
288
14.4k
  pe->dos_message[11] = 0x20534f44;
289
14.4k
  pe->dos_message[12] = 0x65646f6d;
290
14.4k
  pe->dos_message[13] = 0x0a0d0d2e;
291
14.4k
  pe->dos_message[14] = 0x24;
292
14.4k
  pe->dos_message[15] = 0x0;
293
294
14.4k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
14.4k
  bfd_coff_long_section_names (abfd)
297
14.4k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
14.4k
  return true;
300
14.4k
}
pe-i386.c:pe_mkobject
Line
Count
Source
260
53.8k
{
261
53.8k
  pe_data_type *pe;
262
53.8k
  size_t amt = sizeof (pe_data_type);
263
264
53.8k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
53.8k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
53.8k
  pe = pe_data (abfd);
270
271
53.8k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
53.8k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
53.8k
  pe->dos_message[0]  = 0x0eba1f0e;
278
53.8k
  pe->dos_message[1]  = 0xcd09b400;
279
53.8k
  pe->dos_message[2]  = 0x4c01b821;
280
53.8k
  pe->dos_message[3]  = 0x685421cd;
281
53.8k
  pe->dos_message[4]  = 0x70207369;
282
53.8k
  pe->dos_message[5]  = 0x72676f72;
283
53.8k
  pe->dos_message[6]  = 0x63206d61;
284
53.8k
  pe->dos_message[7]  = 0x6f6e6e61;
285
53.8k
  pe->dos_message[8]  = 0x65622074;
286
53.8k
  pe->dos_message[9]  = 0x6e757220;
287
53.8k
  pe->dos_message[10] = 0x206e6920;
288
53.8k
  pe->dos_message[11] = 0x20534f44;
289
53.8k
  pe->dos_message[12] = 0x65646f6d;
290
53.8k
  pe->dos_message[13] = 0x0a0d0d2e;
291
53.8k
  pe->dos_message[14] = 0x24;
292
53.8k
  pe->dos_message[15] = 0x0;
293
294
53.8k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
53.8k
  bfd_coff_long_section_names (abfd)
297
53.8k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
53.8k
  return true;
300
53.8k
}
pe-mcore.c:pe_mkobject
Line
Count
Source
260
34.2k
{
261
34.2k
  pe_data_type *pe;
262
34.2k
  size_t amt = sizeof (pe_data_type);
263
264
34.2k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
34.2k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
34.2k
  pe = pe_data (abfd);
270
271
34.2k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
34.2k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
34.2k
  pe->dos_message[0]  = 0x0eba1f0e;
278
34.2k
  pe->dos_message[1]  = 0xcd09b400;
279
34.2k
  pe->dos_message[2]  = 0x4c01b821;
280
34.2k
  pe->dos_message[3]  = 0x685421cd;
281
34.2k
  pe->dos_message[4]  = 0x70207369;
282
34.2k
  pe->dos_message[5]  = 0x72676f72;
283
34.2k
  pe->dos_message[6]  = 0x63206d61;
284
34.2k
  pe->dos_message[7]  = 0x6f6e6e61;
285
34.2k
  pe->dos_message[8]  = 0x65622074;
286
34.2k
  pe->dos_message[9]  = 0x6e757220;
287
34.2k
  pe->dos_message[10] = 0x206e6920;
288
34.2k
  pe->dos_message[11] = 0x20534f44;
289
34.2k
  pe->dos_message[12] = 0x65646f6d;
290
34.2k
  pe->dos_message[13] = 0x0a0d0d2e;
291
34.2k
  pe->dos_message[14] = 0x24;
292
34.2k
  pe->dos_message[15] = 0x0;
293
294
34.2k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
34.2k
  bfd_coff_long_section_names (abfd)
297
34.2k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
34.2k
  return true;
300
34.2k
}
pe-sh.c:pe_mkobject
Line
Count
Source
260
38.2k
{
261
38.2k
  pe_data_type *pe;
262
38.2k
  size_t amt = sizeof (pe_data_type);
263
264
38.2k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
38.2k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
38.2k
  pe = pe_data (abfd);
270
271
38.2k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
38.2k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
38.2k
  pe->dos_message[0]  = 0x0eba1f0e;
278
38.2k
  pe->dos_message[1]  = 0xcd09b400;
279
38.2k
  pe->dos_message[2]  = 0x4c01b821;
280
38.2k
  pe->dos_message[3]  = 0x685421cd;
281
38.2k
  pe->dos_message[4]  = 0x70207369;
282
38.2k
  pe->dos_message[5]  = 0x72676f72;
283
38.2k
  pe->dos_message[6]  = 0x63206d61;
284
38.2k
  pe->dos_message[7]  = 0x6f6e6e61;
285
38.2k
  pe->dos_message[8]  = 0x65622074;
286
38.2k
  pe->dos_message[9]  = 0x6e757220;
287
38.2k
  pe->dos_message[10] = 0x206e6920;
288
38.2k
  pe->dos_message[11] = 0x20534f44;
289
38.2k
  pe->dos_message[12] = 0x65646f6d;
290
38.2k
  pe->dos_message[13] = 0x0a0d0d2e;
291
38.2k
  pe->dos_message[14] = 0x24;
292
38.2k
  pe->dos_message[15] = 0x0;
293
294
38.2k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
38.2k
  bfd_coff_long_section_names (abfd)
297
38.2k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
38.2k
  return true;
300
38.2k
}
pei-arm-wince.c:pe_mkobject
Line
Count
Source
260
60.5k
{
261
60.5k
  pe_data_type *pe;
262
60.5k
  size_t amt = sizeof (pe_data_type);
263
264
60.5k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
60.5k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
60.5k
  pe = pe_data (abfd);
270
271
60.5k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
60.5k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
60.5k
  pe->dos_message[0]  = 0x0eba1f0e;
278
60.5k
  pe->dos_message[1]  = 0xcd09b400;
279
60.5k
  pe->dos_message[2]  = 0x4c01b821;
280
60.5k
  pe->dos_message[3]  = 0x685421cd;
281
60.5k
  pe->dos_message[4]  = 0x70207369;
282
60.5k
  pe->dos_message[5]  = 0x72676f72;
283
60.5k
  pe->dos_message[6]  = 0x63206d61;
284
60.5k
  pe->dos_message[7]  = 0x6f6e6e61;
285
60.5k
  pe->dos_message[8]  = 0x65622074;
286
60.5k
  pe->dos_message[9]  = 0x6e757220;
287
60.5k
  pe->dos_message[10] = 0x206e6920;
288
60.5k
  pe->dos_message[11] = 0x20534f44;
289
60.5k
  pe->dos_message[12] = 0x65646f6d;
290
60.5k
  pe->dos_message[13] = 0x0a0d0d2e;
291
60.5k
  pe->dos_message[14] = 0x24;
292
60.5k
  pe->dos_message[15] = 0x0;
293
294
60.5k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
60.5k
  bfd_coff_long_section_names (abfd)
297
60.5k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
60.5k
  return true;
300
60.5k
}
pei-arm.c:pe_mkobject
Line
Count
Source
260
84.9k
{
261
84.9k
  pe_data_type *pe;
262
84.9k
  size_t amt = sizeof (pe_data_type);
263
264
84.9k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
84.9k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
84.9k
  pe = pe_data (abfd);
270
271
84.9k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
84.9k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
84.9k
  pe->dos_message[0]  = 0x0eba1f0e;
278
84.9k
  pe->dos_message[1]  = 0xcd09b400;
279
84.9k
  pe->dos_message[2]  = 0x4c01b821;
280
84.9k
  pe->dos_message[3]  = 0x685421cd;
281
84.9k
  pe->dos_message[4]  = 0x70207369;
282
84.9k
  pe->dos_message[5]  = 0x72676f72;
283
84.9k
  pe->dos_message[6]  = 0x63206d61;
284
84.9k
  pe->dos_message[7]  = 0x6f6e6e61;
285
84.9k
  pe->dos_message[8]  = 0x65622074;
286
84.9k
  pe->dos_message[9]  = 0x6e757220;
287
84.9k
  pe->dos_message[10] = 0x206e6920;
288
84.9k
  pe->dos_message[11] = 0x20534f44;
289
84.9k
  pe->dos_message[12] = 0x65646f6d;
290
84.9k
  pe->dos_message[13] = 0x0a0d0d2e;
291
84.9k
  pe->dos_message[14] = 0x24;
292
84.9k
  pe->dos_message[15] = 0x0;
293
294
84.9k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
84.9k
  bfd_coff_long_section_names (abfd)
297
84.9k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
84.9k
  return true;
300
84.9k
}
pei-mcore.c:pe_mkobject
Line
Count
Source
260
74.9k
{
261
74.9k
  pe_data_type *pe;
262
74.9k
  size_t amt = sizeof (pe_data_type);
263
264
74.9k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
74.9k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
74.9k
  pe = pe_data (abfd);
270
271
74.9k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
74.9k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
74.9k
  pe->dos_message[0]  = 0x0eba1f0e;
278
74.9k
  pe->dos_message[1]  = 0xcd09b400;
279
74.9k
  pe->dos_message[2]  = 0x4c01b821;
280
74.9k
  pe->dos_message[3]  = 0x685421cd;
281
74.9k
  pe->dos_message[4]  = 0x70207369;
282
74.9k
  pe->dos_message[5]  = 0x72676f72;
283
74.9k
  pe->dos_message[6]  = 0x63206d61;
284
74.9k
  pe->dos_message[7]  = 0x6f6e6e61;
285
74.9k
  pe->dos_message[8]  = 0x65622074;
286
74.9k
  pe->dos_message[9]  = 0x6e757220;
287
74.9k
  pe->dos_message[10] = 0x206e6920;
288
74.9k
  pe->dos_message[11] = 0x20534f44;
289
74.9k
  pe->dos_message[12] = 0x65646f6d;
290
74.9k
  pe->dos_message[13] = 0x0a0d0d2e;
291
74.9k
  pe->dos_message[14] = 0x24;
292
74.9k
  pe->dos_message[15] = 0x0;
293
294
74.9k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
74.9k
  bfd_coff_long_section_names (abfd)
297
74.9k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
74.9k
  return true;
300
74.9k
}
pei-sh.c:pe_mkobject
Line
Count
Source
260
56.8k
{
261
56.8k
  pe_data_type *pe;
262
56.8k
  size_t amt = sizeof (pe_data_type);
263
264
56.8k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
56.8k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
56.8k
  pe = pe_data (abfd);
270
271
56.8k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
56.8k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
56.8k
  pe->dos_message[0]  = 0x0eba1f0e;
278
56.8k
  pe->dos_message[1]  = 0xcd09b400;
279
56.8k
  pe->dos_message[2]  = 0x4c01b821;
280
56.8k
  pe->dos_message[3]  = 0x685421cd;
281
56.8k
  pe->dos_message[4]  = 0x70207369;
282
56.8k
  pe->dos_message[5]  = 0x72676f72;
283
56.8k
  pe->dos_message[6]  = 0x63206d61;
284
56.8k
  pe->dos_message[7]  = 0x6f6e6e61;
285
56.8k
  pe->dos_message[8]  = 0x65622074;
286
56.8k
  pe->dos_message[9]  = 0x6e757220;
287
56.8k
  pe->dos_message[10] = 0x206e6920;
288
56.8k
  pe->dos_message[11] = 0x20534f44;
289
56.8k
  pe->dos_message[12] = 0x65646f6d;
290
56.8k
  pe->dos_message[13] = 0x0a0d0d2e;
291
56.8k
  pe->dos_message[14] = 0x24;
292
56.8k
  pe->dos_message[15] = 0x0;
293
294
56.8k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
56.8k
  bfd_coff_long_section_names (abfd)
297
56.8k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
56.8k
  return true;
300
56.8k
}
301
302
/* Create the COFF backend specific information.  */
303
304
static void *
305
pe_mkobject_hook (bfd * abfd,
306
      void * filehdr,
307
      void * aouthdr ATTRIBUTE_UNUSED)
308
924k
{
309
924k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
924k
  pe_data_type *pe;
311
312
924k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
924k
  pe = pe_data (abfd);
316
924k
  pe->coff.sym_filepos = internal_f->f_symptr;
317
  /* These members communicate important constants about the symbol
318
     table to GDB's symbol-reading code.  These `constants'
319
     unfortunately vary among coff implementations...  */
320
924k
  pe->coff.local_n_btmask = N_BTMASK;
321
924k
  pe->coff.local_n_btshft = N_BTSHFT;
322
924k
  pe->coff.local_n_tmask = N_TMASK;
323
924k
  pe->coff.local_n_tshift = N_TSHIFT;
324
924k
  pe->coff.local_symesz = SYMESZ;
325
924k
  pe->coff.local_auxesz = AUXESZ;
326
924k
  pe->coff.local_linesz = LINESZ;
327
328
924k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
924k
  obj_raw_syment_count (abfd) =
331
924k
    obj_conv_table_size (abfd) =
332
924k
      internal_f->f_nsyms;
333
334
924k
  pe->real_flags = internal_f->f_flags;
335
336
924k
  if ((internal_f->f_flags & F_DLL) != 0)
337
287k
    pe->dll = 1;
338
339
924k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
663k
    abfd->flags |= HAS_DEBUG;
341
342
#ifdef COFF_IMAGE_WITH_PE
343
641k
  if (aouthdr)
344
417k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
#endif
346
347
#ifdef ARM
348
174k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
349
0
    coff_data (abfd) ->flags = 0;
350
#endif
351
352
924k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
924k
    sizeof (pe->dos_message));
354
355
924k
  return (void *) pe;
356
924k
}
pei-i386.c:pe_mkobject_hook
Line
Count
Source
308
73.1k
{
309
73.1k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
73.1k
  pe_data_type *pe;
311
312
73.1k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
73.1k
  pe = pe_data (abfd);
316
73.1k
  pe->coff.sym_filepos = internal_f->f_symptr;
317
  /* These members communicate important constants about the symbol
318
     table to GDB's symbol-reading code.  These `constants'
319
     unfortunately vary among coff implementations...  */
320
73.1k
  pe->coff.local_n_btmask = N_BTMASK;
321
73.1k
  pe->coff.local_n_btshft = N_BTSHFT;
322
73.1k
  pe->coff.local_n_tmask = N_TMASK;
323
73.1k
  pe->coff.local_n_tshift = N_TSHIFT;
324
73.1k
  pe->coff.local_symesz = SYMESZ;
325
73.1k
  pe->coff.local_auxesz = AUXESZ;
326
73.1k
  pe->coff.local_linesz = LINESZ;
327
328
73.1k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
73.1k
  obj_raw_syment_count (abfd) =
331
73.1k
    obj_conv_table_size (abfd) =
332
73.1k
      internal_f->f_nsyms;
333
334
73.1k
  pe->real_flags = internal_f->f_flags;
335
336
73.1k
  if ((internal_f->f_flags & F_DLL) != 0)
337
19.9k
    pe->dll = 1;
338
339
73.1k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
57.5k
    abfd->flags |= HAS_DEBUG;
341
342
73.1k
#ifdef COFF_IMAGE_WITH_PE
343
73.1k
  if (aouthdr)
344
48.3k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
73.1k
#endif
346
347
#ifdef ARM
348
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
349
    coff_data (abfd) ->flags = 0;
350
#endif
351
352
73.1k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
73.1k
    sizeof (pe->dos_message));
354
355
73.1k
  return (void *) pe;
356
73.1k
}
pe-x86_64.c:pe_mkobject_hook
Line
Count
Source
308
99.7k
{
309
99.7k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
99.7k
  pe_data_type *pe;
311
312
99.7k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
99.7k
  pe = pe_data (abfd);
316
99.7k
  pe->coff.sym_filepos = internal_f->f_symptr;
317
  /* These members communicate important constants about the symbol
318
     table to GDB's symbol-reading code.  These `constants'
319
     unfortunately vary among coff implementations...  */
320
99.7k
  pe->coff.local_n_btmask = N_BTMASK;
321
99.7k
  pe->coff.local_n_btshft = N_BTSHFT;
322
99.7k
  pe->coff.local_n_tmask = N_TMASK;
323
99.7k
  pe->coff.local_n_tshift = N_TSHIFT;
324
99.7k
  pe->coff.local_symesz = SYMESZ;
325
99.7k
  pe->coff.local_auxesz = AUXESZ;
326
99.7k
  pe->coff.local_linesz = LINESZ;
327
328
99.7k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
99.7k
  obj_raw_syment_count (abfd) =
331
99.7k
    obj_conv_table_size (abfd) =
332
99.7k
      internal_f->f_nsyms;
333
334
99.7k
  pe->real_flags = internal_f->f_flags;
335
336
99.7k
  if ((internal_f->f_flags & F_DLL) != 0)
337
28.0k
    pe->dll = 1;
338
339
99.7k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
75.0k
    abfd->flags |= HAS_DEBUG;
341
342
#ifdef COFF_IMAGE_WITH_PE
343
  if (aouthdr)
344
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
#endif
346
347
#ifdef ARM
348
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
349
    coff_data (abfd) ->flags = 0;
350
#endif
351
352
99.7k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
99.7k
    sizeof (pe->dos_message));
354
355
99.7k
  return (void *) pe;
356
99.7k
}
pei-x86_64.c:pe_mkobject_hook
Line
Count
Source
308
88.4k
{
309
88.4k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
88.4k
  pe_data_type *pe;
311
312
88.4k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
88.4k
  pe = pe_data (abfd);
316
88.4k
  pe->coff.sym_filepos = internal_f->f_symptr;
317
  /* These members communicate important constants about the symbol
318
     table to GDB's symbol-reading code.  These `constants'
319
     unfortunately vary among coff implementations...  */
320
88.4k
  pe->coff.local_n_btmask = N_BTMASK;
321
88.4k
  pe->coff.local_n_btshft = N_BTSHFT;
322
88.4k
  pe->coff.local_n_tmask = N_TMASK;
323
88.4k
  pe->coff.local_n_tshift = N_TSHIFT;
324
88.4k
  pe->coff.local_symesz = SYMESZ;
325
88.4k
  pe->coff.local_auxesz = AUXESZ;
326
88.4k
  pe->coff.local_linesz = LINESZ;
327
328
88.4k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
88.4k
  obj_raw_syment_count (abfd) =
331
88.4k
    obj_conv_table_size (abfd) =
332
88.4k
      internal_f->f_nsyms;
333
334
88.4k
  pe->real_flags = internal_f->f_flags;
335
336
88.4k
  if ((internal_f->f_flags & F_DLL) != 0)
337
42.0k
    pe->dll = 1;
338
339
88.4k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
57.2k
    abfd->flags |= HAS_DEBUG;
341
342
88.4k
#ifdef COFF_IMAGE_WITH_PE
343
88.4k
  if (aouthdr)
344
52.5k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
88.4k
#endif
346
347
#ifdef ARM
348
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
349
    coff_data (abfd) ->flags = 0;
350
#endif
351
352
88.4k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
88.4k
    sizeof (pe->dos_message));
354
355
88.4k
  return (void *) pe;
356
88.4k
}
pei-aarch64.c:pe_mkobject_hook
Line
Count
Source
308
62.3k
{
309
62.3k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
62.3k
  pe_data_type *pe;
311
312
62.3k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
62.3k
  pe = pe_data (abfd);
316
62.3k
  pe->coff.sym_filepos = internal_f->f_symptr;
317
  /* These members communicate important constants about the symbol
318
     table to GDB's symbol-reading code.  These `constants'
319
     unfortunately vary among coff implementations...  */
320
62.3k
  pe->coff.local_n_btmask = N_BTMASK;
321
62.3k
  pe->coff.local_n_btshft = N_BTSHFT;
322
62.3k
  pe->coff.local_n_tmask = N_TMASK;
323
62.3k
  pe->coff.local_n_tshift = N_TSHIFT;
324
62.3k
  pe->coff.local_symesz = SYMESZ;
325
62.3k
  pe->coff.local_auxesz = AUXESZ;
326
62.3k
  pe->coff.local_linesz = LINESZ;
327
328
62.3k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
62.3k
  obj_raw_syment_count (abfd) =
331
62.3k
    obj_conv_table_size (abfd) =
332
62.3k
      internal_f->f_nsyms;
333
334
62.3k
  pe->real_flags = internal_f->f_flags;
335
336
62.3k
  if ((internal_f->f_flags & F_DLL) != 0)
337
23.1k
    pe->dll = 1;
338
339
62.3k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
38.3k
    abfd->flags |= HAS_DEBUG;
341
342
62.3k
#ifdef COFF_IMAGE_WITH_PE
343
62.3k
  if (aouthdr)
344
50.3k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
62.3k
#endif
346
347
#ifdef ARM
348
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
349
    coff_data (abfd) ->flags = 0;
350
#endif
351
352
62.3k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
62.3k
    sizeof (pe->dos_message));
354
355
62.3k
  return (void *) pe;
356
62.3k
}
pe-aarch64.c:pe_mkobject_hook
Line
Count
Source
308
27.8k
{
309
27.8k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
27.8k
  pe_data_type *pe;
311
312
27.8k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
27.8k
  pe = pe_data (abfd);
316
27.8k
  pe->coff.sym_filepos = internal_f->f_symptr;
317
  /* These members communicate important constants about the symbol
318
     table to GDB's symbol-reading code.  These `constants'
319
     unfortunately vary among coff implementations...  */
320
27.8k
  pe->coff.local_n_btmask = N_BTMASK;
321
27.8k
  pe->coff.local_n_btshft = N_BTSHFT;
322
27.8k
  pe->coff.local_n_tmask = N_TMASK;
323
27.8k
  pe->coff.local_n_tshift = N_TSHIFT;
324
27.8k
  pe->coff.local_symesz = SYMESZ;
325
27.8k
  pe->coff.local_auxesz = AUXESZ;
326
27.8k
  pe->coff.local_linesz = LINESZ;
327
328
27.8k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
27.8k
  obj_raw_syment_count (abfd) =
331
27.8k
    obj_conv_table_size (abfd) =
332
27.8k
      internal_f->f_nsyms;
333
334
27.8k
  pe->real_flags = internal_f->f_flags;
335
336
27.8k
  if ((internal_f->f_flags & F_DLL) != 0)
337
7.68k
    pe->dll = 1;
338
339
27.8k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
21.5k
    abfd->flags |= HAS_DEBUG;
341
342
#ifdef COFF_IMAGE_WITH_PE
343
  if (aouthdr)
344
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
#endif
346
347
#ifdef ARM
348
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
349
    coff_data (abfd) ->flags = 0;
350
#endif
351
352
27.8k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
27.8k
    sizeof (pe->dos_message));
354
355
27.8k
  return (void *) pe;
356
27.8k
}
pei-ia64.c:pe_mkobject_hook
Line
Count
Source
308
82.9k
{
309
82.9k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
82.9k
  pe_data_type *pe;
311
312
82.9k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
82.9k
  pe = pe_data (abfd);
316
82.9k
  pe->coff.sym_filepos = internal_f->f_symptr;
317
  /* These members communicate important constants about the symbol
318
     table to GDB's symbol-reading code.  These `constants'
319
     unfortunately vary among coff implementations...  */
320
82.9k
  pe->coff.local_n_btmask = N_BTMASK;
321
82.9k
  pe->coff.local_n_btshft = N_BTSHFT;
322
82.9k
  pe->coff.local_n_tmask = N_TMASK;
323
82.9k
  pe->coff.local_n_tshift = N_TSHIFT;
324
82.9k
  pe->coff.local_symesz = SYMESZ;
325
82.9k
  pe->coff.local_auxesz = AUXESZ;
326
82.9k
  pe->coff.local_linesz = LINESZ;
327
328
82.9k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
82.9k
  obj_raw_syment_count (abfd) =
331
82.9k
    obj_conv_table_size (abfd) =
332
82.9k
      internal_f->f_nsyms;
333
334
82.9k
  pe->real_flags = internal_f->f_flags;
335
336
82.9k
  if ((internal_f->f_flags & F_DLL) != 0)
337
30.5k
    pe->dll = 1;
338
339
82.9k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
52.5k
    abfd->flags |= HAS_DEBUG;
341
342
82.9k
#ifdef COFF_IMAGE_WITH_PE
343
82.9k
  if (aouthdr)
344
59.2k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
82.9k
#endif
346
347
#ifdef ARM
348
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
349
    coff_data (abfd) ->flags = 0;
350
#endif
351
352
82.9k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
82.9k
    sizeof (pe->dos_message));
354
355
82.9k
  return (void *) pe;
356
82.9k
}
pei-loongarch64.c:pe_mkobject_hook
Line
Count
Source
308
57.3k
{
309
57.3k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
57.3k
  pe_data_type *pe;
311
312
57.3k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
57.3k
  pe = pe_data (abfd);
316
57.3k
  pe->coff.sym_filepos = internal_f->f_symptr;
317
  /* These members communicate important constants about the symbol
318
     table to GDB's symbol-reading code.  These `constants'
319
     unfortunately vary among coff implementations...  */
320
57.3k
  pe->coff.local_n_btmask = N_BTMASK;
321
57.3k
  pe->coff.local_n_btshft = N_BTSHFT;
322
57.3k
  pe->coff.local_n_tmask = N_TMASK;
323
57.3k
  pe->coff.local_n_tshift = N_TSHIFT;
324
57.3k
  pe->coff.local_symesz = SYMESZ;
325
57.3k
  pe->coff.local_auxesz = AUXESZ;
326
57.3k
  pe->coff.local_linesz = LINESZ;
327
328
57.3k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
57.3k
  obj_raw_syment_count (abfd) =
331
57.3k
    obj_conv_table_size (abfd) =
332
57.3k
      internal_f->f_nsyms;
333
334
57.3k
  pe->real_flags = internal_f->f_flags;
335
336
57.3k
  if ((internal_f->f_flags & F_DLL) != 0)
337
14.3k
    pe->dll = 1;
338
339
57.3k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
43.7k
    abfd->flags |= HAS_DEBUG;
341
342
57.3k
#ifdef COFF_IMAGE_WITH_PE
343
57.3k
  if (aouthdr)
344
40.5k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
57.3k
#endif
346
347
#ifdef ARM
348
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
349
    coff_data (abfd) ->flags = 0;
350
#endif
351
352
57.3k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
57.3k
    sizeof (pe->dos_message));
354
355
57.3k
  return (void *) pe;
356
57.3k
}
pe-arm-wince.c:pe_mkobject_hook
Line
Count
Source
308
14.4k
{
309
14.4k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
14.4k
  pe_data_type *pe;
311
312
14.4k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
14.4k
  pe = pe_data (abfd);
316
14.4k
  pe->coff.sym_filepos = internal_f->f_symptr;
317
  /* These members communicate important constants about the symbol
318
     table to GDB's symbol-reading code.  These `constants'
319
     unfortunately vary among coff implementations...  */
320
14.4k
  pe->coff.local_n_btmask = N_BTMASK;
321
14.4k
  pe->coff.local_n_btshft = N_BTSHFT;
322
14.4k
  pe->coff.local_n_tmask = N_TMASK;
323
14.4k
  pe->coff.local_n_tshift = N_TSHIFT;
324
14.4k
  pe->coff.local_symesz = SYMESZ;
325
14.4k
  pe->coff.local_auxesz = AUXESZ;
326
14.4k
  pe->coff.local_linesz = LINESZ;
327
328
14.4k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
14.4k
  obj_raw_syment_count (abfd) =
331
14.4k
    obj_conv_table_size (abfd) =
332
14.4k
      internal_f->f_nsyms;
333
334
14.4k
  pe->real_flags = internal_f->f_flags;
335
336
14.4k
  if ((internal_f->f_flags & F_DLL) != 0)
337
5.16k
    pe->dll = 1;
338
339
14.4k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
12.6k
    abfd->flags |= HAS_DEBUG;
341
342
#ifdef COFF_IMAGE_WITH_PE
343
  if (aouthdr)
344
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
#endif
346
347
14.4k
#ifdef ARM
348
14.4k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
349
0
    coff_data (abfd) ->flags = 0;
350
14.4k
#endif
351
352
14.4k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
14.4k
    sizeof (pe->dos_message));
354
355
14.4k
  return (void *) pe;
356
14.4k
}
pe-arm.c:pe_mkobject_hook
Line
Count
Source
308
14.4k
{
309
14.4k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
14.4k
  pe_data_type *pe;
311
312
14.4k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
14.4k
  pe = pe_data (abfd);
316
14.4k
  pe->coff.sym_filepos = internal_f->f_symptr;
317
  /* These members communicate important constants about the symbol
318
     table to GDB's symbol-reading code.  These `constants'
319
     unfortunately vary among coff implementations...  */
320
14.4k
  pe->coff.local_n_btmask = N_BTMASK;
321
14.4k
  pe->coff.local_n_btshft = N_BTSHFT;
322
14.4k
  pe->coff.local_n_tmask = N_TMASK;
323
14.4k
  pe->coff.local_n_tshift = N_TSHIFT;
324
14.4k
  pe->coff.local_symesz = SYMESZ;
325
14.4k
  pe->coff.local_auxesz = AUXESZ;
326
14.4k
  pe->coff.local_linesz = LINESZ;
327
328
14.4k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
14.4k
  obj_raw_syment_count (abfd) =
331
14.4k
    obj_conv_table_size (abfd) =
332
14.4k
      internal_f->f_nsyms;
333
334
14.4k
  pe->real_flags = internal_f->f_flags;
335
336
14.4k
  if ((internal_f->f_flags & F_DLL) != 0)
337
5.16k
    pe->dll = 1;
338
339
14.4k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
12.6k
    abfd->flags |= HAS_DEBUG;
341
342
#ifdef COFF_IMAGE_WITH_PE
343
  if (aouthdr)
344
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
#endif
346
347
14.4k
#ifdef ARM
348
14.4k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
349
0
    coff_data (abfd) ->flags = 0;
350
14.4k
#endif
351
352
14.4k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
14.4k
    sizeof (pe->dos_message));
354
355
14.4k
  return (void *) pe;
356
14.4k
}
pe-i386.c:pe_mkobject_hook
Line
Count
Source
308
53.8k
{
309
53.8k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
53.8k
  pe_data_type *pe;
311
312
53.8k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
53.8k
  pe = pe_data (abfd);
316
53.8k
  pe->coff.sym_filepos = internal_f->f_symptr;
317
  /* These members communicate important constants about the symbol
318
     table to GDB's symbol-reading code.  These `constants'
319
     unfortunately vary among coff implementations...  */
320
53.8k
  pe->coff.local_n_btmask = N_BTMASK;
321
53.8k
  pe->coff.local_n_btshft = N_BTSHFT;
322
53.8k
  pe->coff.local_n_tmask = N_TMASK;
323
53.8k
  pe->coff.local_n_tshift = N_TSHIFT;
324
53.8k
  pe->coff.local_symesz = SYMESZ;
325
53.8k
  pe->coff.local_auxesz = AUXESZ;
326
53.8k
  pe->coff.local_linesz = LINESZ;
327
328
53.8k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
53.8k
  obj_raw_syment_count (abfd) =
331
53.8k
    obj_conv_table_size (abfd) =
332
53.8k
      internal_f->f_nsyms;
333
334
53.8k
  pe->real_flags = internal_f->f_flags;
335
336
53.8k
  if ((internal_f->f_flags & F_DLL) != 0)
337
12.3k
    pe->dll = 1;
338
339
53.8k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
41.7k
    abfd->flags |= HAS_DEBUG;
341
342
#ifdef COFF_IMAGE_WITH_PE
343
  if (aouthdr)
344
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
#endif
346
347
#ifdef ARM
348
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
349
    coff_data (abfd) ->flags = 0;
350
#endif
351
352
53.8k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
53.8k
    sizeof (pe->dos_message));
354
355
53.8k
  return (void *) pe;
356
53.8k
}
pe-mcore.c:pe_mkobject_hook
Line
Count
Source
308
34.2k
{
309
34.2k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
34.2k
  pe_data_type *pe;
311
312
34.2k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
34.2k
  pe = pe_data (abfd);
316
34.2k
  pe->coff.sym_filepos = internal_f->f_symptr;
317
  /* These members communicate important constants about the symbol
318
     table to GDB's symbol-reading code.  These `constants'
319
     unfortunately vary among coff implementations...  */
320
34.2k
  pe->coff.local_n_btmask = N_BTMASK;
321
34.2k
  pe->coff.local_n_btshft = N_BTSHFT;
322
34.2k
  pe->coff.local_n_tmask = N_TMASK;
323
34.2k
  pe->coff.local_n_tshift = N_TSHIFT;
324
34.2k
  pe->coff.local_symesz = SYMESZ;
325
34.2k
  pe->coff.local_auxesz = AUXESZ;
326
34.2k
  pe->coff.local_linesz = LINESZ;
327
328
34.2k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
34.2k
  obj_raw_syment_count (abfd) =
331
34.2k
    obj_conv_table_size (abfd) =
332
34.2k
      internal_f->f_nsyms;
333
334
34.2k
  pe->real_flags = internal_f->f_flags;
335
336
34.2k
  if ((internal_f->f_flags & F_DLL) != 0)
337
8.70k
    pe->dll = 1;
338
339
34.2k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
27.6k
    abfd->flags |= HAS_DEBUG;
341
342
#ifdef COFF_IMAGE_WITH_PE
343
  if (aouthdr)
344
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
#endif
346
347
#ifdef ARM
348
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
349
    coff_data (abfd) ->flags = 0;
350
#endif
351
352
34.2k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
34.2k
    sizeof (pe->dos_message));
354
355
34.2k
  return (void *) pe;
356
34.2k
}
pe-sh.c:pe_mkobject_hook
Line
Count
Source
308
38.2k
{
309
38.2k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
38.2k
  pe_data_type *pe;
311
312
38.2k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
38.2k
  pe = pe_data (abfd);
316
38.2k
  pe->coff.sym_filepos = internal_f->f_symptr;
317
  /* These members communicate important constants about the symbol
318
     table to GDB's symbol-reading code.  These `constants'
319
     unfortunately vary among coff implementations...  */
320
38.2k
  pe->coff.local_n_btmask = N_BTMASK;
321
38.2k
  pe->coff.local_n_btshft = N_BTSHFT;
322
38.2k
  pe->coff.local_n_tmask = N_TMASK;
323
38.2k
  pe->coff.local_n_tshift = N_TSHIFT;
324
38.2k
  pe->coff.local_symesz = SYMESZ;
325
38.2k
  pe->coff.local_auxesz = AUXESZ;
326
38.2k
  pe->coff.local_linesz = LINESZ;
327
328
38.2k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
38.2k
  obj_raw_syment_count (abfd) =
331
38.2k
    obj_conv_table_size (abfd) =
332
38.2k
      internal_f->f_nsyms;
333
334
38.2k
  pe->real_flags = internal_f->f_flags;
335
336
38.2k
  if ((internal_f->f_flags & F_DLL) != 0)
337
13.4k
    pe->dll = 1;
338
339
38.2k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
29.1k
    abfd->flags |= HAS_DEBUG;
341
342
#ifdef COFF_IMAGE_WITH_PE
343
  if (aouthdr)
344
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
#endif
346
347
#ifdef ARM
348
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
349
    coff_data (abfd) ->flags = 0;
350
#endif
351
352
38.2k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
38.2k
    sizeof (pe->dos_message));
354
355
38.2k
  return (void *) pe;
356
38.2k
}
pei-arm-wince.c:pe_mkobject_hook
Line
Count
Source
308
60.5k
{
309
60.5k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
60.5k
  pe_data_type *pe;
311
312
60.5k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
60.5k
  pe = pe_data (abfd);
316
60.5k
  pe->coff.sym_filepos = internal_f->f_symptr;
317
  /* These members communicate important constants about the symbol
318
     table to GDB's symbol-reading code.  These `constants'
319
     unfortunately vary among coff implementations...  */
320
60.5k
  pe->coff.local_n_btmask = N_BTMASK;
321
60.5k
  pe->coff.local_n_btshft = N_BTSHFT;
322
60.5k
  pe->coff.local_n_tmask = N_TMASK;
323
60.5k
  pe->coff.local_n_tshift = N_TSHIFT;
324
60.5k
  pe->coff.local_symesz = SYMESZ;
325
60.5k
  pe->coff.local_auxesz = AUXESZ;
326
60.5k
  pe->coff.local_linesz = LINESZ;
327
328
60.5k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
60.5k
  obj_raw_syment_count (abfd) =
331
60.5k
    obj_conv_table_size (abfd) =
332
60.5k
      internal_f->f_nsyms;
333
334
60.5k
  pe->real_flags = internal_f->f_flags;
335
336
60.5k
  if ((internal_f->f_flags & F_DLL) != 0)
337
15.6k
    pe->dll = 1;
338
339
60.5k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
40.6k
    abfd->flags |= HAS_DEBUG;
341
342
60.5k
#ifdef COFF_IMAGE_WITH_PE
343
60.5k
  if (aouthdr)
344
28.0k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
60.5k
#endif
346
347
60.5k
#ifdef ARM
348
60.5k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
349
0
    coff_data (abfd) ->flags = 0;
350
60.5k
#endif
351
352
60.5k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
60.5k
    sizeof (pe->dos_message));
354
355
60.5k
  return (void *) pe;
356
60.5k
}
pei-arm.c:pe_mkobject_hook
Line
Count
Source
308
84.9k
{
309
84.9k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
84.9k
  pe_data_type *pe;
311
312
84.9k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
84.9k
  pe = pe_data (abfd);
316
84.9k
  pe->coff.sym_filepos = internal_f->f_symptr;
317
  /* These members communicate important constants about the symbol
318
     table to GDB's symbol-reading code.  These `constants'
319
     unfortunately vary among coff implementations...  */
320
84.9k
  pe->coff.local_n_btmask = N_BTMASK;
321
84.9k
  pe->coff.local_n_btshft = N_BTSHFT;
322
84.9k
  pe->coff.local_n_tmask = N_TMASK;
323
84.9k
  pe->coff.local_n_tshift = N_TSHIFT;
324
84.9k
  pe->coff.local_symesz = SYMESZ;
325
84.9k
  pe->coff.local_auxesz = AUXESZ;
326
84.9k
  pe->coff.local_linesz = LINESZ;
327
328
84.9k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
84.9k
  obj_raw_syment_count (abfd) =
331
84.9k
    obj_conv_table_size (abfd) =
332
84.9k
      internal_f->f_nsyms;
333
334
84.9k
  pe->real_flags = internal_f->f_flags;
335
336
84.9k
  if ((internal_f->f_flags & F_DLL) != 0)
337
26.7k
    pe->dll = 1;
338
339
84.9k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
56.3k
    abfd->flags |= HAS_DEBUG;
341
342
84.9k
#ifdef COFF_IMAGE_WITH_PE
343
84.9k
  if (aouthdr)
344
47.2k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
84.9k
#endif
346
347
84.9k
#ifdef ARM
348
84.9k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
349
0
    coff_data (abfd) ->flags = 0;
350
84.9k
#endif
351
352
84.9k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
84.9k
    sizeof (pe->dos_message));
354
355
84.9k
  return (void *) pe;
356
84.9k
}
pei-mcore.c:pe_mkobject_hook
Line
Count
Source
308
74.9k
{
309
74.9k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
74.9k
  pe_data_type *pe;
311
312
74.9k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
74.9k
  pe = pe_data (abfd);
316
74.9k
  pe->coff.sym_filepos = internal_f->f_symptr;
317
  /* These members communicate important constants about the symbol
318
     table to GDB's symbol-reading code.  These `constants'
319
     unfortunately vary among coff implementations...  */
320
74.9k
  pe->coff.local_n_btmask = N_BTMASK;
321
74.9k
  pe->coff.local_n_btshft = N_BTSHFT;
322
74.9k
  pe->coff.local_n_tmask = N_TMASK;
323
74.9k
  pe->coff.local_n_tshift = N_TSHIFT;
324
74.9k
  pe->coff.local_symesz = SYMESZ;
325
74.9k
  pe->coff.local_auxesz = AUXESZ;
326
74.9k
  pe->coff.local_linesz = LINESZ;
327
328
74.9k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
74.9k
  obj_raw_syment_count (abfd) =
331
74.9k
    obj_conv_table_size (abfd) =
332
74.9k
      internal_f->f_nsyms;
333
334
74.9k
  pe->real_flags = internal_f->f_flags;
335
336
74.9k
  if ((internal_f->f_flags & F_DLL) != 0)
337
21.4k
    pe->dll = 1;
338
339
74.9k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
52.3k
    abfd->flags |= HAS_DEBUG;
341
342
74.9k
#ifdef COFF_IMAGE_WITH_PE
343
74.9k
  if (aouthdr)
344
55.0k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
74.9k
#endif
346
347
#ifdef ARM
348
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
349
    coff_data (abfd) ->flags = 0;
350
#endif
351
352
74.9k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
74.9k
    sizeof (pe->dos_message));
354
355
74.9k
  return (void *) pe;
356
74.9k
}
pei-sh.c:pe_mkobject_hook
Line
Count
Source
308
56.7k
{
309
56.7k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
56.7k
  pe_data_type *pe;
311
312
56.7k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
56.7k
  pe = pe_data (abfd);
316
56.7k
  pe->coff.sym_filepos = internal_f->f_symptr;
317
  /* These members communicate important constants about the symbol
318
     table to GDB's symbol-reading code.  These `constants'
319
     unfortunately vary among coff implementations...  */
320
56.7k
  pe->coff.local_n_btmask = N_BTMASK;
321
56.7k
  pe->coff.local_n_btshft = N_BTSHFT;
322
56.7k
  pe->coff.local_n_tmask = N_TMASK;
323
56.7k
  pe->coff.local_n_tshift = N_TSHIFT;
324
56.7k
  pe->coff.local_symesz = SYMESZ;
325
56.7k
  pe->coff.local_auxesz = AUXESZ;
326
56.7k
  pe->coff.local_linesz = LINESZ;
327
328
56.7k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
56.7k
  obj_raw_syment_count (abfd) =
331
56.7k
    obj_conv_table_size (abfd) =
332
56.7k
      internal_f->f_nsyms;
333
334
56.7k
  pe->real_flags = internal_f->f_flags;
335
336
56.7k
  if ((internal_f->f_flags & F_DLL) != 0)
337
13.5k
    pe->dll = 1;
338
339
56.7k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
44.0k
    abfd->flags |= HAS_DEBUG;
341
342
56.7k
#ifdef COFF_IMAGE_WITH_PE
343
56.7k
  if (aouthdr)
344
35.7k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
56.7k
#endif
346
347
#ifdef ARM
348
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
349
    coff_data (abfd) ->flags = 0;
350
#endif
351
352
56.7k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
56.7k
    sizeof (pe->dos_message));
354
355
56.7k
  return (void *) pe;
356
56.7k
}
357
358
static bool
359
pe_print_private_bfd_data (bfd *abfd, void * vfile)
360
8.46k
{
361
8.46k
  FILE *file = (FILE *) vfile;
362
363
8.46k
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
364
0
    return false;
365
366
8.46k
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
367
8.15k
    return true;
368
369
316
  fputc ('\n', file);
370
371
316
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
372
8.46k
}
pei-i386.c:pe_print_private_bfd_data
Line
Count
Source
360
414
{
361
414
  FILE *file = (FILE *) vfile;
362
363
414
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
364
0
    return false;
365
366
414
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
367
414
    return true;
368
369
0
  fputc ('\n', file);
370
371
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
372
414
}
pe-x86_64.c:pe_print_private_bfd_data
Line
Count
Source
360
907
{
361
907
  FILE *file = (FILE *) vfile;
362
363
907
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
364
0
    return false;
365
366
907
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
367
907
    return true;
368
369
0
  fputc ('\n', file);
370
371
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
372
907
}
pei-x86_64.c:pe_print_private_bfd_data
Line
Count
Source
360
566
{
361
566
  FILE *file = (FILE *) vfile;
362
363
566
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
364
0
    return false;
365
366
566
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
367
566
    return true;
368
369
0
  fputc ('\n', file);
370
371
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
372
566
}
pei-aarch64.c:pe_print_private_bfd_data
Line
Count
Source
360
2.24k
{
361
2.24k
  FILE *file = (FILE *) vfile;
362
363
2.24k
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
364
0
    return false;
365
366
2.24k
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
367
2.24k
    return true;
368
369
0
  fputc ('\n', file);
370
371
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
372
2.24k
}
pe-aarch64.c:pe_print_private_bfd_data
Line
Count
Source
360
1.28k
{
361
1.28k
  FILE *file = (FILE *) vfile;
362
363
1.28k
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
364
0
    return false;
365
366
1.28k
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
367
1.28k
    return true;
368
369
0
  fputc ('\n', file);
370
371
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
372
1.28k
}
pei-ia64.c:pe_print_private_bfd_data
Line
Count
Source
360
617
{
361
617
  FILE *file = (FILE *) vfile;
362
363
617
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
364
0
    return false;
365
366
617
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
367
617
    return true;
368
369
0
  fputc ('\n', file);
370
371
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
372
617
}
pei-loongarch64.c:pe_print_private_bfd_data
Line
Count
Source
360
637
{
361
637
  FILE *file = (FILE *) vfile;
362
363
637
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
364
0
    return false;
365
366
637
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
367
637
    return true;
368
369
0
  fputc ('\n', file);
370
371
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
372
637
}
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
360
190
{
361
190
  FILE *file = (FILE *) vfile;
362
363
190
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
364
0
    return false;
365
366
190
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
367
190
    return true;
368
369
0
  fputc ('\n', file);
370
371
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
372
190
}
pe-mcore.c:pe_print_private_bfd_data
Line
Count
Source
360
433
{
361
433
  FILE *file = (FILE *) vfile;
362
363
433
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
364
0
    return false;
365
366
433
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
367
433
    return true;
368
369
0
  fputc ('\n', file);
370
371
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
372
433
}
pe-sh.c:pe_print_private_bfd_data
Line
Count
Source
360
274
{
361
274
  FILE *file = (FILE *) vfile;
362
363
274
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
364
0
    return false;
365
366
274
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
367
274
    return true;
368
369
0
  fputc ('\n', file);
370
371
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
372
274
}
pei-arm-wince.c:pe_print_private_bfd_data
Line
Count
Source
360
96
{
361
96
  FILE *file = (FILE *) vfile;
362
363
96
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
364
0
    return false;
365
366
96
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
367
0
    return true;
368
369
96
  fputc ('\n', file);
370
371
96
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
372
96
}
pei-arm.c:pe_print_private_bfd_data
Line
Count
Source
360
220
{
361
220
  FILE *file = (FILE *) vfile;
362
363
220
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
364
0
    return false;
365
366
220
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
367
0
    return true;
368
369
220
  fputc ('\n', file);
370
371
220
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
372
220
}
pei-mcore.c:pe_print_private_bfd_data
Line
Count
Source
360
224
{
361
224
  FILE *file = (FILE *) vfile;
362
363
224
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
364
0
    return false;
365
366
224
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
367
224
    return true;
368
369
0
  fputc ('\n', file);
370
371
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
372
224
}
pei-sh.c:pe_print_private_bfd_data
Line
Count
Source
360
358
{
361
358
  FILE *file = (FILE *) vfile;
362
363
358
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
364
0
    return false;
365
366
358
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
367
358
    return true;
368
369
0
  fputc ('\n', file);
370
371
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
372
358
}
373
374
/* Copy any private info we understand from the input bfd
375
   to the output bfd.  */
376
377
static bool
378
pe_bfd_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
379
46
{
380
  /* PR binutils/716: Copy the large address aware flag.
381
     XXX: Should we be copying other flags or other fields in the pe_data()
382
     structure ?  */
383
46
  if (pe_data (obfd) != NULL
384
46
      && pe_data (ibfd) != NULL
385
46
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
386
24
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
387
388
46
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
389
0
    return false;
390
391
46
  if (pe_saved_coff_bfd_copy_private_bfd_data)
392
1
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
393
394
45
  return true;
395
46
}
pei-i386.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
379
4
{
380
  /* PR binutils/716: Copy the large address aware flag.
381
     XXX: Should we be copying other flags or other fields in the pe_data()
382
     structure ?  */
383
4
  if (pe_data (obfd) != NULL
384
4
      && pe_data (ibfd) != NULL
385
4
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
386
2
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
387
388
4
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
389
0
    return false;
390
391
4
  if (pe_saved_coff_bfd_copy_private_bfd_data)
392
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
393
394
4
  return true;
395
4
}
pe-x86_64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
379
1
{
380
  /* PR binutils/716: Copy the large address aware flag.
381
     XXX: Should we be copying other flags or other fields in the pe_data()
382
     structure ?  */
383
1
  if (pe_data (obfd) != NULL
384
1
      && pe_data (ibfd) != NULL
385
1
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
386
0
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
387
388
1
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
389
0
    return false;
390
391
1
  if (pe_saved_coff_bfd_copy_private_bfd_data)
392
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
393
394
1
  return true;
395
1
}
pei-x86_64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
379
17
{
380
  /* PR binutils/716: Copy the large address aware flag.
381
     XXX: Should we be copying other flags or other fields in the pe_data()
382
     structure ?  */
383
17
  if (pe_data (obfd) != NULL
384
17
      && pe_data (ibfd) != NULL
385
17
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
386
16
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
387
388
17
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
389
0
    return false;
390
391
17
  if (pe_saved_coff_bfd_copy_private_bfd_data)
392
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
393
394
17
  return true;
395
17
}
pei-aarch64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
379
2
{
380
  /* PR binutils/716: Copy the large address aware flag.
381
     XXX: Should we be copying other flags or other fields in the pe_data()
382
     structure ?  */
383
2
  if (pe_data (obfd) != NULL
384
2
      && pe_data (ibfd) != NULL
385
2
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
386
0
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
387
388
2
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
389
0
    return false;
390
391
2
  if (pe_saved_coff_bfd_copy_private_bfd_data)
392
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
393
394
2
  return true;
395
2
}
pe-aarch64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
379
1
{
380
  /* PR binutils/716: Copy the large address aware flag.
381
     XXX: Should we be copying other flags or other fields in the pe_data()
382
     structure ?  */
383
1
  if (pe_data (obfd) != NULL
384
1
      && pe_data (ibfd) != NULL
385
1
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
386
1
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
387
388
1
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
389
0
    return false;
390
391
1
  if (pe_saved_coff_bfd_copy_private_bfd_data)
392
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
393
394
1
  return true;
395
1
}
pei-ia64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
379
5
{
380
  /* PR binutils/716: Copy the large address aware flag.
381
     XXX: Should we be copying other flags or other fields in the pe_data()
382
     structure ?  */
383
5
  if (pe_data (obfd) != NULL
384
5
      && pe_data (ibfd) != NULL
385
5
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
386
5
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
387
388
5
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
389
0
    return false;
390
391
5
  if (pe_saved_coff_bfd_copy_private_bfd_data)
392
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
393
394
5
  return true;
395
5
}
pei-loongarch64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
379
11
{
380
  /* PR binutils/716: Copy the large address aware flag.
381
     XXX: Should we be copying other flags or other fields in the pe_data()
382
     structure ?  */
383
11
  if (pe_data (obfd) != NULL
384
11
      && pe_data (ibfd) != NULL
385
11
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
386
0
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
387
388
11
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
389
0
    return false;
390
391
11
  if (pe_saved_coff_bfd_copy_private_bfd_data)
392
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
393
394
11
  return true;
395
11
}
Unexecuted instantiation: pe-arm-wince.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pe-arm.c:pe_bfd_copy_private_bfd_data
pe-i386.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
379
3
{
380
  /* PR binutils/716: Copy the large address aware flag.
381
     XXX: Should we be copying other flags or other fields in the pe_data()
382
     structure ?  */
383
3
  if (pe_data (obfd) != NULL
384
3
      && pe_data (ibfd) != NULL
385
3
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
386
0
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
387
388
3
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
389
0
    return false;
390
391
3
  if (pe_saved_coff_bfd_copy_private_bfd_data)
392
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
393
394
3
  return true;
395
3
}
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
379
1
{
380
  /* PR binutils/716: Copy the large address aware flag.
381
     XXX: Should we be copying other flags or other fields in the pe_data()
382
     structure ?  */
383
1
  if (pe_data (obfd) != NULL
384
1
      && pe_data (ibfd) != NULL
385
1
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
386
0
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
387
388
1
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
389
0
    return false;
390
391
1
  if (pe_saved_coff_bfd_copy_private_bfd_data)
392
1
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
393
394
0
  return true;
395
1
}
Unexecuted instantiation: pei-arm.c:pe_bfd_copy_private_bfd_data
pei-mcore.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
379
1
{
380
  /* PR binutils/716: Copy the large address aware flag.
381
     XXX: Should we be copying other flags or other fields in the pe_data()
382
     structure ?  */
383
1
  if (pe_data (obfd) != NULL
384
1
      && pe_data (ibfd) != NULL
385
1
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
386
0
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
387
388
1
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
389
0
    return false;
390
391
1
  if (pe_saved_coff_bfd_copy_private_bfd_data)
392
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
393
394
1
  return true;
395
1
}
Unexecuted instantiation: pei-sh.c:pe_bfd_copy_private_bfd_data
396
397
#define coff_bfd_copy_private_section_data \
398
  _bfd_XX_bfd_copy_private_section_data
399
400
#define coff_get_symbol_info _bfd_XX_get_symbol_info
401
402
#ifdef COFF_IMAGE_WITH_PE
403

404
/* Code to handle Microsoft's Import Library Format.
405
   Also known as LINK6 format.
406
   Documentation about this format can be found at:
407
408
   https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#import-library-format  */
409
410
/* The following constants specify the sizes of the various data
411
   structures that we have to create in order to build a bfd describing
412
   an ILF object file.  The final "+ 1" in the definitions of SIZEOF_IDATA6
413
   and SIZEOF_IDATA7 below is to allow for the possibility that we might
414
   need a padding byte in order to ensure 16 bit alignment for the section's
415
   contents.
416
417
   The value for SIZEOF_ILF_STRINGS is computed as follows:
418
419
      There will be NUM_ILF_SECTIONS section symbols.  Allow 9 characters
420
      per symbol for their names (longest section name is .idata$x).
421
422
      There will be two symbols for the imported value, one the symbol name
423
      and one with _imp__ prefixed.  Allowing for the terminating nul's this
424
      is strlen (symbol_name) * 2 + 8 + 21 + strlen (source_dll).
425
426
      The strings in the string table must start STRING__SIZE_SIZE bytes into
427
      the table in order to for the string lookup code in coffgen/coffcode to
428
      work.  */
429
143k
#define NUM_ILF_RELOCS    8
430
477k
#define NUM_ILF_SECTIONS  6
431
358k
#define NUM_ILF_SYMS    (2 + NUM_ILF_SECTIONS)
432
433
71.6k
#define SIZEOF_ILF_SYMS    (NUM_ILF_SYMS * sizeof (* vars.sym_cache))
434
71.6k
#define SIZEOF_ILF_SYM_TABLE   (NUM_ILF_SYMS * sizeof (* vars.sym_table))
435
71.6k
#define SIZEOF_ILF_NATIVE_SYMS   (NUM_ILF_SYMS * sizeof (* vars.native_syms))
436
71.6k
#define SIZEOF_ILF_SYM_PTR_TABLE (NUM_ILF_SYMS * sizeof (* vars.sym_ptr_table))
437
71.6k
#define SIZEOF_ILF_EXT_SYMS  (NUM_ILF_SYMS * sizeof (* vars.esym_table))
438
71.6k
#define SIZEOF_ILF_RELOCS  (NUM_ILF_RELOCS * sizeof (* vars.reltab))
439
71.6k
#define SIZEOF_ILF_INT_RELOCS  (NUM_ILF_RELOCS * sizeof (* vars.int_reltab))
440
71.6k
#define SIZEOF_ILF_STRINGS   (strlen (symbol_name) * 2 + 8 \
441
71.6k
          + 21 + strlen (source_dll) \
442
71.6k
          + NUM_ILF_SECTIONS * 9 \
443
71.6k
          + STRING_SIZE_SIZE)
444
47.7k
#define SIZEOF_IDATA2   (5 * 4)
445
446
/* For PEx64 idata4 & 5 have thumb size of 8 bytes.  */
447
#if defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64)
448
20.3k
#define SIZEOF_IDATA4   (2 * 4)
449
20.3k
#define SIZEOF_IDATA5   (2 * 4)
450
#else
451
51.2k
#define SIZEOF_IDATA4   (1 * 4)
452
51.2k
#define SIZEOF_IDATA5   (1 * 4)
453
#endif
454
455
61.9k
#define SIZEOF_IDATA6   (2 + strlen (symbol_name) + 1 + 1)
456
47.7k
#define SIZEOF_IDATA7   (strlen (source_dll) + 1 + 1)
457
47.7k
#define SIZEOF_ILF_SECTIONS (NUM_ILF_SECTIONS * sizeof (struct coff_section_tdata))
458
459
#define ILF_DATA_SIZE       \
460
47.7k
    + SIZEOF_ILF_SYMS        \
461
47.7k
    + SIZEOF_ILF_SYM_TABLE      \
462
47.7k
    + SIZEOF_ILF_NATIVE_SYMS      \
463
47.7k
    + SIZEOF_ILF_SYM_PTR_TABLE      \
464
47.7k
    + SIZEOF_ILF_EXT_SYMS      \
465
47.7k
    + SIZEOF_ILF_RELOCS        \
466
47.7k
    + SIZEOF_ILF_INT_RELOCS      \
467
47.7k
    + SIZEOF_ILF_STRINGS      \
468
47.7k
    + SIZEOF_IDATA2        \
469
47.7k
    + SIZEOF_IDATA4        \
470
47.7k
    + SIZEOF_IDATA5        \
471
47.7k
    + SIZEOF_IDATA6        \
472
47.7k
    + SIZEOF_IDATA7        \
473
47.7k
    + SIZEOF_ILF_SECTIONS      \
474
47.7k
    + MAX_TEXT_SECTION_SIZE
475
476
/* Create an empty relocation against the given symbol.  */
477
478
static void
479
pe_ILF_make_a_symbol_reloc (pe_ILF_vars *   vars,
480
          bfd_vma     address,
481
          bfd_reloc_code_real_type  reloc,
482
          struct bfd_symbol **  sym,
483
          unsigned int    sym_index)
484
41.4k
{
485
41.4k
  arelent * entry;
486
41.4k
  struct internal_reloc * internal;
487
488
41.4k
  entry = vars->reltab + vars->relcount;
489
41.4k
  internal = vars->int_reltab + vars->relcount;
490
491
41.4k
  entry->address     = address;
492
41.4k
  entry->addend      = 0;
493
41.4k
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
494
41.4k
  entry->sym_ptr_ptr = sym;
495
496
41.4k
  internal->r_vaddr  = address;
497
41.4k
  internal->r_symndx = sym_index;
498
41.4k
  internal->r_type   = entry->howto ? entry->howto->type : 0;
499
500
41.4k
  vars->relcount ++;
501
502
41.4k
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
503
41.4k
}
pei-i386.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
484
6.83k
{
485
6.83k
  arelent * entry;
486
6.83k
  struct internal_reloc * internal;
487
488
6.83k
  entry = vars->reltab + vars->relcount;
489
6.83k
  internal = vars->int_reltab + vars->relcount;
490
491
6.83k
  entry->address     = address;
492
6.83k
  entry->addend      = 0;
493
6.83k
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
494
6.83k
  entry->sym_ptr_ptr = sym;
495
496
6.83k
  internal->r_vaddr  = address;
497
6.83k
  internal->r_symndx = sym_index;
498
6.83k
  internal->r_type   = entry->howto ? entry->howto->type : 0;
499
500
6.83k
  vars->relcount ++;
501
502
6.83k
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
503
6.83k
}
pei-x86_64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
484
7.54k
{
485
7.54k
  arelent * entry;
486
7.54k
  struct internal_reloc * internal;
487
488
7.54k
  entry = vars->reltab + vars->relcount;
489
7.54k
  internal = vars->int_reltab + vars->relcount;
490
491
7.54k
  entry->address     = address;
492
7.54k
  entry->addend      = 0;
493
7.54k
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
494
7.54k
  entry->sym_ptr_ptr = sym;
495
496
7.54k
  internal->r_vaddr  = address;
497
7.54k
  internal->r_symndx = sym_index;
498
7.54k
  internal->r_type   = entry->howto ? entry->howto->type : 0;
499
500
7.54k
  vars->relcount ++;
501
502
7.54k
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
503
7.54k
}
pei-aarch64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
484
3.54k
{
485
3.54k
  arelent * entry;
486
3.54k
  struct internal_reloc * internal;
487
488
3.54k
  entry = vars->reltab + vars->relcount;
489
3.54k
  internal = vars->int_reltab + vars->relcount;
490
491
3.54k
  entry->address     = address;
492
3.54k
  entry->addend      = 0;
493
3.54k
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
494
3.54k
  entry->sym_ptr_ptr = sym;
495
496
3.54k
  internal->r_vaddr  = address;
497
3.54k
  internal->r_symndx = sym_index;
498
3.54k
  internal->r_type   = entry->howto ? entry->howto->type : 0;
499
500
3.54k
  vars->relcount ++;
501
502
3.54k
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
503
3.54k
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_symbol_reloc
pei-loongarch64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
484
6.77k
{
485
6.77k
  arelent * entry;
486
6.77k
  struct internal_reloc * internal;
487
488
6.77k
  entry = vars->reltab + vars->relcount;
489
6.77k
  internal = vars->int_reltab + vars->relcount;
490
491
6.77k
  entry->address     = address;
492
6.77k
  entry->addend      = 0;
493
6.77k
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
494
6.77k
  entry->sym_ptr_ptr = sym;
495
496
6.77k
  internal->r_vaddr  = address;
497
6.77k
  internal->r_symndx = sym_index;
498
6.77k
  internal->r_type   = entry->howto ? entry->howto->type : 0;
499
500
6.77k
  vars->relcount ++;
501
502
6.77k
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
503
6.77k
}
pei-arm-wince.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
484
204
{
485
204
  arelent * entry;
486
204
  struct internal_reloc * internal;
487
488
204
  entry = vars->reltab + vars->relcount;
489
204
  internal = vars->int_reltab + vars->relcount;
490
491
204
  entry->address     = address;
492
204
  entry->addend      = 0;
493
204
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
494
204
  entry->sym_ptr_ptr = sym;
495
496
204
  internal->r_vaddr  = address;
497
204
  internal->r_symndx = sym_index;
498
204
  internal->r_type   = entry->howto ? entry->howto->type : 0;
499
500
204
  vars->relcount ++;
501
502
204
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
503
204
}
pei-arm.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
484
10.6k
{
485
10.6k
  arelent * entry;
486
10.6k
  struct internal_reloc * internal;
487
488
10.6k
  entry = vars->reltab + vars->relcount;
489
10.6k
  internal = vars->int_reltab + vars->relcount;
490
491
10.6k
  entry->address     = address;
492
10.6k
  entry->addend      = 0;
493
10.6k
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
494
10.6k
  entry->sym_ptr_ptr = sym;
495
496
10.6k
  internal->r_vaddr  = address;
497
10.6k
  internal->r_symndx = sym_index;
498
10.6k
  internal->r_type   = entry->howto ? entry->howto->type : 0;
499
500
10.6k
  vars->relcount ++;
501
502
10.6k
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
503
10.6k
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_symbol_reloc
pei-sh.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
484
5.90k
{
485
5.90k
  arelent * entry;
486
5.90k
  struct internal_reloc * internal;
487
488
5.90k
  entry = vars->reltab + vars->relcount;
489
5.90k
  internal = vars->int_reltab + vars->relcount;
490
491
5.90k
  entry->address     = address;
492
5.90k
  entry->addend      = 0;
493
5.90k
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
494
5.90k
  entry->sym_ptr_ptr = sym;
495
496
5.90k
  internal->r_vaddr  = address;
497
5.90k
  internal->r_symndx = sym_index;
498
5.90k
  internal->r_type   = entry->howto ? entry->howto->type : 0;
499
500
5.90k
  vars->relcount ++;
501
502
5.90k
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
503
5.90k
}
504
505
/* Create an empty relocation against the given section.  */
506
507
static void
508
pe_ILF_make_a_reloc (pe_ILF_vars *         vars,
509
         bfd_vma           address,
510
         bfd_reloc_code_real_type  reloc,
511
         asection_ptr        sec)
512
28.4k
{
513
28.4k
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, sec->symbol_ptr_ptr,
514
28.4k
            coff_section_data (vars->abfd, sec)->i);
515
28.4k
}
pei-i386.c:pe_ILF_make_a_reloc
Line
Count
Source
512
4.42k
{
513
4.42k
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, sec->symbol_ptr_ptr,
514
4.42k
            coff_section_data (vars->abfd, sec)->i);
515
4.42k
}
pei-x86_64.c:pe_ILF_make_a_reloc
Line
Count
Source
512
5.01k
{
513
5.01k
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, sec->symbol_ptr_ptr,
514
5.01k
            coff_section_data (vars->abfd, sec)->i);
515
5.01k
}
pei-aarch64.c:pe_ILF_make_a_reloc
Line
Count
Source
512
2.47k
{
513
2.47k
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, sec->symbol_ptr_ptr,
514
2.47k
            coff_section_data (vars->abfd, sec)->i);
515
2.47k
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_reloc
pei-loongarch64.c:pe_ILF_make_a_reloc
Line
Count
Source
512
4.80k
{
513
4.80k
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, sec->symbol_ptr_ptr,
514
4.80k
            coff_section_data (vars->abfd, sec)->i);
515
4.80k
}
pei-arm-wince.c:pe_ILF_make_a_reloc
Line
Count
Source
512
140
{
513
140
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, sec->symbol_ptr_ptr,
514
140
            coff_section_data (vars->abfd, sec)->i);
515
140
}
pei-arm.c:pe_ILF_make_a_reloc
Line
Count
Source
512
7.74k
{
513
7.74k
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, sec->symbol_ptr_ptr,
514
7.74k
            coff_section_data (vars->abfd, sec)->i);
515
7.74k
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_reloc
pei-sh.c:pe_ILF_make_a_reloc
Line
Count
Source
512
3.88k
{
513
3.88k
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, sec->symbol_ptr_ptr,
514
3.88k
            coff_section_data (vars->abfd, sec)->i);
515
3.88k
}
516
517
/* Move the queued relocs into the given section.  */
518
519
static void
520
pe_ILF_save_relocs (pe_ILF_vars * vars,
521
        asection_ptr  sec)
522
41.4k
{
523
  /* Make sure that there is somewhere to store the internal relocs.  */
524
41.4k
  if (coff_section_data (vars->abfd, sec) == NULL)
525
    /* We should probably return an error indication here.  */
526
0
    abort ();
527
528
41.4k
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
529
530
41.4k
  sec->relocation  = vars->reltab;
531
41.4k
  sec->reloc_count = vars->relcount;
532
41.4k
  sec->flags      |= SEC_RELOC;
533
534
41.4k
  vars->reltab     += vars->relcount;
535
41.4k
  vars->int_reltab += vars->relcount;
536
41.4k
  vars->relcount   = 0;
537
538
41.4k
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
539
41.4k
}
pei-i386.c:pe_ILF_save_relocs
Line
Count
Source
522
6.83k
{
523
  /* Make sure that there is somewhere to store the internal relocs.  */
524
6.83k
  if (coff_section_data (vars->abfd, sec) == NULL)
525
    /* We should probably return an error indication here.  */
526
0
    abort ();
527
528
6.83k
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
529
530
6.83k
  sec->relocation  = vars->reltab;
531
6.83k
  sec->reloc_count = vars->relcount;
532
6.83k
  sec->flags      |= SEC_RELOC;
533
534
6.83k
  vars->reltab     += vars->relcount;
535
6.83k
  vars->int_reltab += vars->relcount;
536
6.83k
  vars->relcount   = 0;
537
538
6.83k
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
539
6.83k
}
pei-x86_64.c:pe_ILF_save_relocs
Line
Count
Source
522
7.54k
{
523
  /* Make sure that there is somewhere to store the internal relocs.  */
524
7.54k
  if (coff_section_data (vars->abfd, sec) == NULL)
525
    /* We should probably return an error indication here.  */
526
0
    abort ();
527
528
7.54k
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
529
530
7.54k
  sec->relocation  = vars->reltab;
531
7.54k
  sec->reloc_count = vars->relcount;
532
7.54k
  sec->flags      |= SEC_RELOC;
533
534
7.54k
  vars->reltab     += vars->relcount;
535
7.54k
  vars->int_reltab += vars->relcount;
536
7.54k
  vars->relcount   = 0;
537
538
7.54k
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
539
7.54k
}
pei-aarch64.c:pe_ILF_save_relocs
Line
Count
Source
522
3.54k
{
523
  /* Make sure that there is somewhere to store the internal relocs.  */
524
3.54k
  if (coff_section_data (vars->abfd, sec) == NULL)
525
    /* We should probably return an error indication here.  */
526
0
    abort ();
527
528
3.54k
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
529
530
3.54k
  sec->relocation  = vars->reltab;
531
3.54k
  sec->reloc_count = vars->relcount;
532
3.54k
  sec->flags      |= SEC_RELOC;
533
534
3.54k
  vars->reltab     += vars->relcount;
535
3.54k
  vars->int_reltab += vars->relcount;
536
3.54k
  vars->relcount   = 0;
537
538
3.54k
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
539
3.54k
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_save_relocs
pei-loongarch64.c:pe_ILF_save_relocs
Line
Count
Source
522
6.77k
{
523
  /* Make sure that there is somewhere to store the internal relocs.  */
524
6.77k
  if (coff_section_data (vars->abfd, sec) == NULL)
525
    /* We should probably return an error indication here.  */
526
0
    abort ();
527
528
6.77k
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
529
530
6.77k
  sec->relocation  = vars->reltab;
531
6.77k
  sec->reloc_count = vars->relcount;
532
6.77k
  sec->flags      |= SEC_RELOC;
533
534
6.77k
  vars->reltab     += vars->relcount;
535
6.77k
  vars->int_reltab += vars->relcount;
536
6.77k
  vars->relcount   = 0;
537
538
6.77k
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
539
6.77k
}
pei-arm-wince.c:pe_ILF_save_relocs
Line
Count
Source
522
204
{
523
  /* Make sure that there is somewhere to store the internal relocs.  */
524
204
  if (coff_section_data (vars->abfd, sec) == NULL)
525
    /* We should probably return an error indication here.  */
526
0
    abort ();
527
528
204
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
529
530
204
  sec->relocation  = vars->reltab;
531
204
  sec->reloc_count = vars->relcount;
532
204
  sec->flags      |= SEC_RELOC;
533
534
204
  vars->reltab     += vars->relcount;
535
204
  vars->int_reltab += vars->relcount;
536
204
  vars->relcount   = 0;
537
538
204
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
539
204
}
pei-arm.c:pe_ILF_save_relocs
Line
Count
Source
522
10.6k
{
523
  /* Make sure that there is somewhere to store the internal relocs.  */
524
10.6k
  if (coff_section_data (vars->abfd, sec) == NULL)
525
    /* We should probably return an error indication here.  */
526
0
    abort ();
527
528
10.6k
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
529
530
10.6k
  sec->relocation  = vars->reltab;
531
10.6k
  sec->reloc_count = vars->relcount;
532
10.6k
  sec->flags      |= SEC_RELOC;
533
534
10.6k
  vars->reltab     += vars->relcount;
535
10.6k
  vars->int_reltab += vars->relcount;
536
10.6k
  vars->relcount   = 0;
537
538
10.6k
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
539
10.6k
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_save_relocs
pei-sh.c:pe_ILF_save_relocs
Line
Count
Source
522
5.90k
{
523
  /* Make sure that there is somewhere to store the internal relocs.  */
524
5.90k
  if (coff_section_data (vars->abfd, sec) == NULL)
525
    /* We should probably return an error indication here.  */
526
0
    abort ();
527
528
5.90k
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
529
530
5.90k
  sec->relocation  = vars->reltab;
531
5.90k
  sec->reloc_count = vars->relcount;
532
5.90k
  sec->flags      |= SEC_RELOC;
533
534
5.90k
  vars->reltab     += vars->relcount;
535
5.90k
  vars->int_reltab += vars->relcount;
536
5.90k
  vars->relcount   = 0;
537
538
5.90k
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
539
5.90k
}
540
541
/* Create a global symbol and add it to the relevant tables.  */
542
543
static void
544
pe_ILF_make_a_symbol (pe_ILF_vars *  vars,
545
          const char *   prefix,
546
          const char *   symbol_name,
547
          asection_ptr   section,
548
          flagword       extra_flags)
549
132k
{
550
132k
  coff_symbol_type * sym;
551
132k
  combined_entry_type * ent;
552
132k
  SYMENT * esym;
553
132k
  unsigned short sclass;
554
555
132k
  if (extra_flags & BSF_LOCAL)
556
75.0k
    sclass = C_STAT;
557
57.4k
  else
558
57.4k
    sclass = C_EXT;
559
560
#ifdef THUMBPEMAGIC
561
32.7k
  if (vars->magic == THUMBPEMAGIC)
562
7.46k
    {
563
7.46k
      if (extra_flags & BSF_FUNCTION)
564
285
  sclass = C_THUMBEXTFUNC;
565
7.18k
      else if (extra_flags & BSF_LOCAL)
566
4.59k
  sclass = C_THUMBSTAT;
567
2.59k
      else
568
2.59k
  sclass = C_THUMBEXT;
569
7.46k
    }
570
#endif
571
572
132k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
573
574
132k
  sym = vars->sym_ptr;
575
132k
  ent = vars->native_ptr;
576
132k
  esym = vars->esym_ptr;
577
578
  /* Copy the symbol's name into the string table.  */
579
132k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
580
581
132k
  if (section == NULL)
582
22.2k
    section = bfd_und_section_ptr;
583
584
  /* Initialise the external symbol.  */
585
132k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
586
132k
      esym->e.e.e_offset);
587
132k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
588
132k
  esym->e_sclass[0] = sclass;
589
590
  /* The following initialisations are unnecessary - the memory is
591
     zero initialised.  They are just kept here as reminders.  */
592
593
  /* Initialise the internal symbol structure.  */
594
132k
  ent->u.syment.n_sclass    = sclass;
595
132k
  ent->u.syment.n_scnum     = section->target_index;
596
132k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
597
132k
  ent->is_sym = true;
598
599
132k
  sym->symbol.the_bfd = vars->abfd;
600
132k
  sym->symbol.name    = vars->string_ptr;
601
132k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
602
132k
  sym->symbol.section = section;
603
132k
  sym->native       = ent;
604
605
132k
  * vars->table_ptr = vars->sym_index;
606
132k
  * vars->sym_ptr_ptr = sym;
607
608
  /* Adjust pointers for the next symbol.  */
609
132k
  vars->sym_index ++;
610
132k
  vars->sym_ptr ++;
611
132k
  vars->sym_ptr_ptr ++;
612
132k
  vars->table_ptr ++;
613
132k
  vars->native_ptr ++;
614
132k
  vars->esym_ptr ++;
615
132k
  vars->string_ptr += len + 1;
616
617
132k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
618
132k
}
pei-i386.c:pe_ILF_make_a_symbol
Line
Count
Source
549
23.0k
{
550
23.0k
  coff_symbol_type * sym;
551
23.0k
  combined_entry_type * ent;
552
23.0k
  SYMENT * esym;
553
23.0k
  unsigned short sclass;
554
555
23.0k
  if (extra_flags & BSF_LOCAL)
556
13.0k
    sclass = C_STAT;
557
10.0k
  else
558
10.0k
    sclass = C_EXT;
559
560
#ifdef THUMBPEMAGIC
561
  if (vars->magic == THUMBPEMAGIC)
562
    {
563
      if (extra_flags & BSF_FUNCTION)
564
  sclass = C_THUMBEXTFUNC;
565
      else if (extra_flags & BSF_LOCAL)
566
  sclass = C_THUMBSTAT;
567
      else
568
  sclass = C_THUMBEXT;
569
    }
570
#endif
571
572
23.0k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
573
574
23.0k
  sym = vars->sym_ptr;
575
23.0k
  ent = vars->native_ptr;
576
23.0k
  esym = vars->esym_ptr;
577
578
  /* Copy the symbol's name into the string table.  */
579
23.0k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
580
581
23.0k
  if (section == NULL)
582
3.80k
    section = bfd_und_section_ptr;
583
584
  /* Initialise the external symbol.  */
585
23.0k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
586
23.0k
      esym->e.e.e_offset);
587
23.0k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
588
23.0k
  esym->e_sclass[0] = sclass;
589
590
  /* The following initialisations are unnecessary - the memory is
591
     zero initialised.  They are just kept here as reminders.  */
592
593
  /* Initialise the internal symbol structure.  */
594
23.0k
  ent->u.syment.n_sclass    = sclass;
595
23.0k
  ent->u.syment.n_scnum     = section->target_index;
596
23.0k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
597
23.0k
  ent->is_sym = true;
598
599
23.0k
  sym->symbol.the_bfd = vars->abfd;
600
23.0k
  sym->symbol.name    = vars->string_ptr;
601
23.0k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
602
23.0k
  sym->symbol.section = section;
603
23.0k
  sym->native       = ent;
604
605
23.0k
  * vars->table_ptr = vars->sym_index;
606
23.0k
  * vars->sym_ptr_ptr = sym;
607
608
  /* Adjust pointers for the next symbol.  */
609
23.0k
  vars->sym_index ++;
610
23.0k
  vars->sym_ptr ++;
611
23.0k
  vars->sym_ptr_ptr ++;
612
23.0k
  vars->table_ptr ++;
613
23.0k
  vars->native_ptr ++;
614
23.0k
  vars->esym_ptr ++;
615
23.0k
  vars->string_ptr += len + 1;
616
617
23.0k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
618
23.0k
}
pei-x86_64.c:pe_ILF_make_a_symbol
Line
Count
Source
549
25.0k
{
550
25.0k
  coff_symbol_type * sym;
551
25.0k
  combined_entry_type * ent;
552
25.0k
  SYMENT * esym;
553
25.0k
  unsigned short sclass;
554
555
25.0k
  if (extra_flags & BSF_LOCAL)
556
14.1k
    sclass = C_STAT;
557
10.8k
  else
558
10.8k
    sclass = C_EXT;
559
560
#ifdef THUMBPEMAGIC
561
  if (vars->magic == THUMBPEMAGIC)
562
    {
563
      if (extra_flags & BSF_FUNCTION)
564
  sclass = C_THUMBEXTFUNC;
565
      else if (extra_flags & BSF_LOCAL)
566
  sclass = C_THUMBSTAT;
567
      else
568
  sclass = C_THUMBEXT;
569
    }
570
#endif
571
572
25.0k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
573
574
25.0k
  sym = vars->sym_ptr;
575
25.0k
  ent = vars->native_ptr;
576
25.0k
  esym = vars->esym_ptr;
577
578
  /* Copy the symbol's name into the string table.  */
579
25.0k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
580
581
25.0k
  if (section == NULL)
582
4.15k
    section = bfd_und_section_ptr;
583
584
  /* Initialise the external symbol.  */
585
25.0k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
586
25.0k
      esym->e.e.e_offset);
587
25.0k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
588
25.0k
  esym->e_sclass[0] = sclass;
589
590
  /* The following initialisations are unnecessary - the memory is
591
     zero initialised.  They are just kept here as reminders.  */
592
593
  /* Initialise the internal symbol structure.  */
594
25.0k
  ent->u.syment.n_sclass    = sclass;
595
25.0k
  ent->u.syment.n_scnum     = section->target_index;
596
25.0k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
597
25.0k
  ent->is_sym = true;
598
599
25.0k
  sym->symbol.the_bfd = vars->abfd;
600
25.0k
  sym->symbol.name    = vars->string_ptr;
601
25.0k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
602
25.0k
  sym->symbol.section = section;
603
25.0k
  sym->native       = ent;
604
605
25.0k
  * vars->table_ptr = vars->sym_index;
606
25.0k
  * vars->sym_ptr_ptr = sym;
607
608
  /* Adjust pointers for the next symbol.  */
609
25.0k
  vars->sym_index ++;
610
25.0k
  vars->sym_ptr ++;
611
25.0k
  vars->sym_ptr_ptr ++;
612
25.0k
  vars->table_ptr ++;
613
25.0k
  vars->native_ptr ++;
614
25.0k
  vars->esym_ptr ++;
615
25.0k
  vars->string_ptr += len + 1;
616
617
25.0k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
618
25.0k
}
pei-aarch64.c:pe_ILF_make_a_symbol
Line
Count
Source
549
12.1k
{
550
12.1k
  coff_symbol_type * sym;
551
12.1k
  combined_entry_type * ent;
552
12.1k
  SYMENT * esym;
553
12.1k
  unsigned short sclass;
554
555
12.1k
  if (extra_flags & BSF_LOCAL)
556
6.72k
    sclass = C_STAT;
557
5.45k
  else
558
5.45k
    sclass = C_EXT;
559
560
#ifdef THUMBPEMAGIC
561
  if (vars->magic == THUMBPEMAGIC)
562
    {
563
      if (extra_flags & BSF_FUNCTION)
564
  sclass = C_THUMBEXTFUNC;
565
      else if (extra_flags & BSF_LOCAL)
566
  sclass = C_THUMBSTAT;
567
      else
568
  sclass = C_THUMBEXT;
569
    }
570
#endif
571
572
12.1k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
573
574
12.1k
  sym = vars->sym_ptr;
575
12.1k
  ent = vars->native_ptr;
576
12.1k
  esym = vars->esym_ptr;
577
578
  /* Copy the symbol's name into the string table.  */
579
12.1k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
580
581
12.1k
  if (section == NULL)
582
2.19k
    section = bfd_und_section_ptr;
583
584
  /* Initialise the external symbol.  */
585
12.1k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
586
12.1k
      esym->e.e.e_offset);
587
12.1k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
588
12.1k
  esym->e_sclass[0] = sclass;
589
590
  /* The following initialisations are unnecessary - the memory is
591
     zero initialised.  They are just kept here as reminders.  */
592
593
  /* Initialise the internal symbol structure.  */
594
12.1k
  ent->u.syment.n_sclass    = sclass;
595
12.1k
  ent->u.syment.n_scnum     = section->target_index;
596
12.1k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
597
12.1k
  ent->is_sym = true;
598
599
12.1k
  sym->symbol.the_bfd = vars->abfd;
600
12.1k
  sym->symbol.name    = vars->string_ptr;
601
12.1k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
602
12.1k
  sym->symbol.section = section;
603
12.1k
  sym->native       = ent;
604
605
12.1k
  * vars->table_ptr = vars->sym_index;
606
12.1k
  * vars->sym_ptr_ptr = sym;
607
608
  /* Adjust pointers for the next symbol.  */
609
12.1k
  vars->sym_index ++;
610
12.1k
  vars->sym_ptr ++;
611
12.1k
  vars->sym_ptr_ptr ++;
612
12.1k
  vars->table_ptr ++;
613
12.1k
  vars->native_ptr ++;
614
12.1k
  vars->esym_ptr ++;
615
12.1k
  vars->string_ptr += len + 1;
616
617
12.1k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
618
12.1k
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_symbol
pei-loongarch64.c:pe_ILF_make_a_symbol
Line
Count
Source
549
21.1k
{
550
21.1k
  coff_symbol_type * sym;
551
21.1k
  combined_entry_type * ent;
552
21.1k
  SYMENT * esym;
553
21.1k
  unsigned short sclass;
554
555
21.1k
  if (extra_flags & BSF_LOCAL)
556
11.7k
    sclass = C_STAT;
557
9.33k
  else
558
9.33k
    sclass = C_EXT;
559
560
#ifdef THUMBPEMAGIC
561
  if (vars->magic == THUMBPEMAGIC)
562
    {
563
      if (extra_flags & BSF_FUNCTION)
564
  sclass = C_THUMBEXTFUNC;
565
      else if (extra_flags & BSF_LOCAL)
566
  sclass = C_THUMBSTAT;
567
      else
568
  sclass = C_THUMBEXT;
569
    }
570
#endif
571
572
21.1k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
573
574
21.1k
  sym = vars->sym_ptr;
575
21.1k
  ent = vars->native_ptr;
576
21.1k
  esym = vars->esym_ptr;
577
578
  /* Copy the symbol's name into the string table.  */
579
21.1k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
580
581
21.1k
  if (section == NULL)
582
3.68k
    section = bfd_und_section_ptr;
583
584
  /* Initialise the external symbol.  */
585
21.1k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
586
21.1k
      esym->e.e.e_offset);
587
21.1k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
588
21.1k
  esym->e_sclass[0] = sclass;
589
590
  /* The following initialisations are unnecessary - the memory is
591
     zero initialised.  They are just kept here as reminders.  */
592
593
  /* Initialise the internal symbol structure.  */
594
21.1k
  ent->u.syment.n_sclass    = sclass;
595
21.1k
  ent->u.syment.n_scnum     = section->target_index;
596
21.1k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
597
21.1k
  ent->is_sym = true;
598
599
21.1k
  sym->symbol.the_bfd = vars->abfd;
600
21.1k
  sym->symbol.name    = vars->string_ptr;
601
21.1k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
602
21.1k
  sym->symbol.section = section;
603
21.1k
  sym->native       = ent;
604
605
21.1k
  * vars->table_ptr = vars->sym_index;
606
21.1k
  * vars->sym_ptr_ptr = sym;
607
608
  /* Adjust pointers for the next symbol.  */
609
21.1k
  vars->sym_index ++;
610
21.1k
  vars->sym_ptr ++;
611
21.1k
  vars->sym_ptr_ptr ++;
612
21.1k
  vars->table_ptr ++;
613
21.1k
  vars->native_ptr ++;
614
21.1k
  vars->esym_ptr ++;
615
21.1k
  vars->string_ptr += len + 1;
616
617
21.1k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
618
21.1k
}
pei-arm-wince.c:pe_ILF_make_a_symbol
Line
Count
Source
549
1.25k
{
550
1.25k
  coff_symbol_type * sym;
551
1.25k
  combined_entry_type * ent;
552
1.25k
  SYMENT * esym;
553
1.25k
  unsigned short sclass;
554
555
1.25k
  if (extra_flags & BSF_LOCAL)
556
986
    sclass = C_STAT;
557
270
  else
558
270
    sclass = C_EXT;
559
560
1.25k
#ifdef THUMBPEMAGIC
561
1.25k
  if (vars->magic == THUMBPEMAGIC)
562
496
    {
563
496
      if (extra_flags & BSF_FUNCTION)
564
24
  sclass = C_THUMBEXTFUNC;
565
472
      else if (extra_flags & BSF_LOCAL)
566
378
  sclass = C_THUMBSTAT;
567
94
      else
568
94
  sclass = C_THUMBEXT;
569
496
    }
570
1.25k
#endif
571
572
1.25k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
573
574
1.25k
  sym = vars->sym_ptr;
575
1.25k
  ent = vars->native_ptr;
576
1.25k
  esym = vars->esym_ptr;
577
578
  /* Copy the symbol's name into the string table.  */
579
1.25k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
580
581
1.25k
  if (section == NULL)
582
103
    section = bfd_und_section_ptr;
583
584
  /* Initialise the external symbol.  */
585
1.25k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
586
1.25k
      esym->e.e.e_offset);
587
1.25k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
588
1.25k
  esym->e_sclass[0] = sclass;
589
590
  /* The following initialisations are unnecessary - the memory is
591
     zero initialised.  They are just kept here as reminders.  */
592
593
  /* Initialise the internal symbol structure.  */
594
1.25k
  ent->u.syment.n_sclass    = sclass;
595
1.25k
  ent->u.syment.n_scnum     = section->target_index;
596
1.25k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
597
1.25k
  ent->is_sym = true;
598
599
1.25k
  sym->symbol.the_bfd = vars->abfd;
600
1.25k
  sym->symbol.name    = vars->string_ptr;
601
1.25k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
602
1.25k
  sym->symbol.section = section;
603
1.25k
  sym->native       = ent;
604
605
1.25k
  * vars->table_ptr = vars->sym_index;
606
1.25k
  * vars->sym_ptr_ptr = sym;
607
608
  /* Adjust pointers for the next symbol.  */
609
1.25k
  vars->sym_index ++;
610
1.25k
  vars->sym_ptr ++;
611
1.25k
  vars->sym_ptr_ptr ++;
612
1.25k
  vars->table_ptr ++;
613
1.25k
  vars->native_ptr ++;
614
1.25k
  vars->esym_ptr ++;
615
1.25k
  vars->string_ptr += len + 1;
616
617
1.25k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
618
1.25k
}
pei-arm.c:pe_ILF_make_a_symbol
Line
Count
Source
549
31.4k
{
550
31.4k
  coff_symbol_type * sym;
551
31.4k
  combined_entry_type * ent;
552
31.4k
  SYMENT * esym;
553
31.4k
  unsigned short sclass;
554
555
31.4k
  if (extra_flags & BSF_LOCAL)
556
18.0k
    sclass = C_STAT;
557
13.4k
  else
558
13.4k
    sclass = C_EXT;
559
560
31.4k
#ifdef THUMBPEMAGIC
561
31.4k
  if (vars->magic == THUMBPEMAGIC)
562
6.97k
    {
563
6.97k
      if (extra_flags & BSF_FUNCTION)
564
261
  sclass = C_THUMBEXTFUNC;
565
6.70k
      else if (extra_flags & BSF_LOCAL)
566
4.21k
  sclass = C_THUMBSTAT;
567
2.49k
      else
568
2.49k
  sclass = C_THUMBEXT;
569
6.97k
    }
570
31.4k
#endif
571
572
31.4k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
573
574
31.4k
  sym = vars->sym_ptr;
575
31.4k
  ent = vars->native_ptr;
576
31.4k
  esym = vars->esym_ptr;
577
578
  /* Copy the symbol's name into the string table.  */
579
31.4k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
580
581
31.4k
  if (section == NULL)
582
5.27k
    section = bfd_und_section_ptr;
583
584
  /* Initialise the external symbol.  */
585
31.4k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
586
31.4k
      esym->e.e.e_offset);
587
31.4k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
588
31.4k
  esym->e_sclass[0] = sclass;
589
590
  /* The following initialisations are unnecessary - the memory is
591
     zero initialised.  They are just kept here as reminders.  */
592
593
  /* Initialise the internal symbol structure.  */
594
31.4k
  ent->u.syment.n_sclass    = sclass;
595
31.4k
  ent->u.syment.n_scnum     = section->target_index;
596
31.4k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
597
31.4k
  ent->is_sym = true;
598
599
31.4k
  sym->symbol.the_bfd = vars->abfd;
600
31.4k
  sym->symbol.name    = vars->string_ptr;
601
31.4k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
602
31.4k
  sym->symbol.section = section;
603
31.4k
  sym->native       = ent;
604
605
31.4k
  * vars->table_ptr = vars->sym_index;
606
31.4k
  * vars->sym_ptr_ptr = sym;
607
608
  /* Adjust pointers for the next symbol.  */
609
31.4k
  vars->sym_index ++;
610
31.4k
  vars->sym_ptr ++;
611
31.4k
  vars->sym_ptr_ptr ++;
612
31.4k
  vars->table_ptr ++;
613
31.4k
  vars->native_ptr ++;
614
31.4k
  vars->esym_ptr ++;
615
31.4k
  vars->string_ptr += len + 1;
616
617
31.4k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
618
31.4k
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_symbol
pei-sh.c:pe_ILF_make_a_symbol
Line
Count
Source
549
18.3k
{
550
18.3k
  coff_symbol_type * sym;
551
18.3k
  combined_entry_type * ent;
552
18.3k
  SYMENT * esym;
553
18.3k
  unsigned short sclass;
554
555
18.3k
  if (extra_flags & BSF_LOCAL)
556
10.2k
    sclass = C_STAT;
557
8.07k
  else
558
8.07k
    sclass = C_EXT;
559
560
#ifdef THUMBPEMAGIC
561
  if (vars->magic == THUMBPEMAGIC)
562
    {
563
      if (extra_flags & BSF_FUNCTION)
564
  sclass = C_THUMBEXTFUNC;
565
      else if (extra_flags & BSF_LOCAL)
566
  sclass = C_THUMBSTAT;
567
      else
568
  sclass = C_THUMBEXT;
569
    }
570
#endif
571
572
18.3k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
573
574
18.3k
  sym = vars->sym_ptr;
575
18.3k
  ent = vars->native_ptr;
576
18.3k
  esym = vars->esym_ptr;
577
578
  /* Copy the symbol's name into the string table.  */
579
18.3k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
580
581
18.3k
  if (section == NULL)
582
3.02k
    section = bfd_und_section_ptr;
583
584
  /* Initialise the external symbol.  */
585
18.3k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
586
18.3k
      esym->e.e.e_offset);
587
18.3k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
588
18.3k
  esym->e_sclass[0] = sclass;
589
590
  /* The following initialisations are unnecessary - the memory is
591
     zero initialised.  They are just kept here as reminders.  */
592
593
  /* Initialise the internal symbol structure.  */
594
18.3k
  ent->u.syment.n_sclass    = sclass;
595
18.3k
  ent->u.syment.n_scnum     = section->target_index;
596
18.3k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
597
18.3k
  ent->is_sym = true;
598
599
18.3k
  sym->symbol.the_bfd = vars->abfd;
600
18.3k
  sym->symbol.name    = vars->string_ptr;
601
18.3k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
602
18.3k
  sym->symbol.section = section;
603
18.3k
  sym->native       = ent;
604
605
18.3k
  * vars->table_ptr = vars->sym_index;
606
18.3k
  * vars->sym_ptr_ptr = sym;
607
608
  /* Adjust pointers for the next symbol.  */
609
18.3k
  vars->sym_index ++;
610
18.3k
  vars->sym_ptr ++;
611
18.3k
  vars->sym_ptr_ptr ++;
612
18.3k
  vars->table_ptr ++;
613
18.3k
  vars->native_ptr ++;
614
18.3k
  vars->esym_ptr ++;
615
18.3k
  vars->string_ptr += len + 1;
616
617
18.3k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
618
18.3k
}
619
620
/* Create a section.  */
621
622
static asection_ptr
623
pe_ILF_make_a_section (pe_ILF_vars * vars,
624
           const char *  name,
625
           unsigned int  size,
626
           flagword      extra_flags)
627
75.0k
{
628
75.0k
  asection_ptr sec;
629
75.0k
  flagword     flags;
630
75.0k
  intptr_t alignment;
631
632
75.0k
  sec = bfd_make_section_old_way (vars->abfd, name);
633
75.0k
  if (sec == NULL)
634
0
    return NULL;
635
636
75.0k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
637
638
75.0k
  bfd_set_section_flags (sec, flags | extra_flags);
639
640
75.0k
  bfd_set_section_alignment (sec, 2);
641
642
  /* Check that we will not run out of space.  */
643
75.0k
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
644
645
  /* Set the section size and contents.  The actual
646
     contents are filled in by our parent.  */
647
75.0k
  bfd_set_section_size (sec, (bfd_size_type) size);
648
75.0k
  sec->contents = vars->data;
649
75.0k
  sec->target_index = vars->sec_index ++;
650
651
  /* Advance data pointer in the vars structure.  */
652
75.0k
  vars->data += size;
653
654
  /* Skip the padding byte if it was not needed.
655
     The logic here is that if the string length is odd,
656
     then the entire string length, including the null byte,
657
     is even and so the extra, padding byte, is not needed.  */
658
75.0k
  if (size & 1)
659
7.85k
    vars->data --;
660
661
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
662
     preserve host alignment requirements.  The BFD_ASSERTs in this
663
     functions will warn us if we run out of room, but we should
664
     already have enough padding built in to ILF_DATA_SIZE.  */
665
75.0k
#if GCC_VERSION >= 3000
666
75.0k
  alignment = __alignof__ (struct coff_section_tdata);
667
#else
668
  alignment = 8;
669
#endif
670
75.0k
  vars->data
671
75.0k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
672
673
  /* Create a coff_section_tdata structure for our use.  */
674
75.0k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
675
75.0k
  vars->data += sizeof (struct coff_section_tdata);
676
677
75.0k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
678
679
  /* Create a symbol to refer to this section.  */
680
75.0k
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
681
682
  /* Cache the index to the symbol in the coff_section_data structure.  */
683
75.0k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
684
685
75.0k
  return sec;
686
75.0k
}
pei-i386.c:pe_ILF_make_a_section
Line
Count
Source
627
13.0k
{
628
13.0k
  asection_ptr sec;
629
13.0k
  flagword     flags;
630
13.0k
  intptr_t alignment;
631
632
13.0k
  sec = bfd_make_section_old_way (vars->abfd, name);
633
13.0k
  if (sec == NULL)
634
0
    return NULL;
635
636
13.0k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
637
638
13.0k
  bfd_set_section_flags (sec, flags | extra_flags);
639
640
13.0k
  bfd_set_section_alignment (sec, 2);
641
642
  /* Check that we will not run out of space.  */
643
13.0k
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
644
645
  /* Set the section size and contents.  The actual
646
     contents are filled in by our parent.  */
647
13.0k
  bfd_set_section_size (sec, (bfd_size_type) size);
648
13.0k
  sec->contents = vars->data;
649
13.0k
  sec->target_index = vars->sec_index ++;
650
651
  /* Advance data pointer in the vars structure.  */
652
13.0k
  vars->data += size;
653
654
  /* Skip the padding byte if it was not needed.
655
     The logic here is that if the string length is odd,
656
     then the entire string length, including the null byte,
657
     is even and so the extra, padding byte, is not needed.  */
658
13.0k
  if (size & 1)
659
1.72k
    vars->data --;
660
661
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
662
     preserve host alignment requirements.  The BFD_ASSERTs in this
663
     functions will warn us if we run out of room, but we should
664
     already have enough padding built in to ILF_DATA_SIZE.  */
665
13.0k
#if GCC_VERSION >= 3000
666
13.0k
  alignment = __alignof__ (struct coff_section_tdata);
667
#else
668
  alignment = 8;
669
#endif
670
13.0k
  vars->data
671
13.0k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
672
673
  /* Create a coff_section_tdata structure for our use.  */
674
13.0k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
675
13.0k
  vars->data += sizeof (struct coff_section_tdata);
676
677
13.0k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
678
679
  /* Create a symbol to refer to this section.  */
680
13.0k
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
681
682
  /* Cache the index to the symbol in the coff_section_data structure.  */
683
13.0k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
684
685
13.0k
  return sec;
686
13.0k
}
pei-x86_64.c:pe_ILF_make_a_section
Line
Count
Source
627
14.1k
{
628
14.1k
  asection_ptr sec;
629
14.1k
  flagword     flags;
630
14.1k
  intptr_t alignment;
631
632
14.1k
  sec = bfd_make_section_old_way (vars->abfd, name);
633
14.1k
  if (sec == NULL)
634
0
    return NULL;
635
636
14.1k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
637
638
14.1k
  bfd_set_section_flags (sec, flags | extra_flags);
639
640
14.1k
  bfd_set_section_alignment (sec, 2);
641
642
  /* Check that we will not run out of space.  */
643
14.1k
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
644
645
  /* Set the section size and contents.  The actual
646
     contents are filled in by our parent.  */
647
14.1k
  bfd_set_section_size (sec, (bfd_size_type) size);
648
14.1k
  sec->contents = vars->data;
649
14.1k
  sec->target_index = vars->sec_index ++;
650
651
  /* Advance data pointer in the vars structure.  */
652
14.1k
  vars->data += size;
653
654
  /* Skip the padding byte if it was not needed.
655
     The logic here is that if the string length is odd,
656
     then the entire string length, including the null byte,
657
     is even and so the extra, padding byte, is not needed.  */
658
14.1k
  if (size & 1)
659
892
    vars->data --;
660
661
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
662
     preserve host alignment requirements.  The BFD_ASSERTs in this
663
     functions will warn us if we run out of room, but we should
664
     already have enough padding built in to ILF_DATA_SIZE.  */
665
14.1k
#if GCC_VERSION >= 3000
666
14.1k
  alignment = __alignof__ (struct coff_section_tdata);
667
#else
668
  alignment = 8;
669
#endif
670
14.1k
  vars->data
671
14.1k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
672
673
  /* Create a coff_section_tdata structure for our use.  */
674
14.1k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
675
14.1k
  vars->data += sizeof (struct coff_section_tdata);
676
677
14.1k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
678
679
  /* Create a symbol to refer to this section.  */
680
14.1k
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
681
682
  /* Cache the index to the symbol in the coff_section_data structure.  */
683
14.1k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
684
685
14.1k
  return sec;
686
14.1k
}
pei-aarch64.c:pe_ILF_make_a_section
Line
Count
Source
627
6.72k
{
628
6.72k
  asection_ptr sec;
629
6.72k
  flagword     flags;
630
6.72k
  intptr_t alignment;
631
632
6.72k
  sec = bfd_make_section_old_way (vars->abfd, name);
633
6.72k
  if (sec == NULL)
634
0
    return NULL;
635
636
6.72k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
637
638
6.72k
  bfd_set_section_flags (sec, flags | extra_flags);
639
640
6.72k
  bfd_set_section_alignment (sec, 2);
641
642
  /* Check that we will not run out of space.  */
643
6.72k
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
644
645
  /* Set the section size and contents.  The actual
646
     contents are filled in by our parent.  */
647
6.72k
  bfd_set_section_size (sec, (bfd_size_type) size);
648
6.72k
  sec->contents = vars->data;
649
6.72k
  sec->target_index = vars->sec_index ++;
650
651
  /* Advance data pointer in the vars structure.  */
652
6.72k
  vars->data += size;
653
654
  /* Skip the padding byte if it was not needed.
655
     The logic here is that if the string length is odd,
656
     then the entire string length, including the null byte,
657
     is even and so the extra, padding byte, is not needed.  */
658
6.72k
  if (size & 1)
659
850
    vars->data --;
660
661
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
662
     preserve host alignment requirements.  The BFD_ASSERTs in this
663
     functions will warn us if we run out of room, but we should
664
     already have enough padding built in to ILF_DATA_SIZE.  */
665
6.72k
#if GCC_VERSION >= 3000
666
6.72k
  alignment = __alignof__ (struct coff_section_tdata);
667
#else
668
  alignment = 8;
669
#endif
670
6.72k
  vars->data
671
6.72k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
672
673
  /* Create a coff_section_tdata structure for our use.  */
674
6.72k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
675
6.72k
  vars->data += sizeof (struct coff_section_tdata);
676
677
6.72k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
678
679
  /* Create a symbol to refer to this section.  */
680
6.72k
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
681
682
  /* Cache the index to the symbol in the coff_section_data structure.  */
683
6.72k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
684
685
6.72k
  return sec;
686
6.72k
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_section
pei-loongarch64.c:pe_ILF_make_a_section
Line
Count
Source
627
11.7k
{
628
11.7k
  asection_ptr sec;
629
11.7k
  flagword     flags;
630
11.7k
  intptr_t alignment;
631
632
11.7k
  sec = bfd_make_section_old_way (vars->abfd, name);
633
11.7k
  if (sec == NULL)
634
0
    return NULL;
635
636
11.7k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
637
638
11.7k
  bfd_set_section_flags (sec, flags | extra_flags);
639
640
11.7k
  bfd_set_section_alignment (sec, 2);
641
642
  /* Check that we will not run out of space.  */
643
11.7k
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
644
645
  /* Set the section size and contents.  The actual
646
     contents are filled in by our parent.  */
647
11.7k
  bfd_set_section_size (sec, (bfd_size_type) size);
648
11.7k
  sec->contents = vars->data;
649
11.7k
  sec->target_index = vars->sec_index ++;
650
651
  /* Advance data pointer in the vars structure.  */
652
11.7k
  vars->data += size;
653
654
  /* Skip the padding byte if it was not needed.
655
     The logic here is that if the string length is odd,
656
     then the entire string length, including the null byte,
657
     is even and so the extra, padding byte, is not needed.  */
658
11.7k
  if (size & 1)
659
1.15k
    vars->data --;
660
661
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
662
     preserve host alignment requirements.  The BFD_ASSERTs in this
663
     functions will warn us if we run out of room, but we should
664
     already have enough padding built in to ILF_DATA_SIZE.  */
665
11.7k
#if GCC_VERSION >= 3000
666
11.7k
  alignment = __alignof__ (struct coff_section_tdata);
667
#else
668
  alignment = 8;
669
#endif
670
11.7k
  vars->data
671
11.7k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
672
673
  /* Create a coff_section_tdata structure for our use.  */
674
11.7k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
675
11.7k
  vars->data += sizeof (struct coff_section_tdata);
676
677
11.7k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
678
679
  /* Create a symbol to refer to this section.  */
680
11.7k
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
681
682
  /* Cache the index to the symbol in the coff_section_data structure.  */
683
11.7k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
684
685
11.7k
  return sec;
686
11.7k
}
pei-arm-wince.c:pe_ILF_make_a_section
Line
Count
Source
627
986
{
628
986
  asection_ptr sec;
629
986
  flagword     flags;
630
986
  intptr_t alignment;
631
632
986
  sec = bfd_make_section_old_way (vars->abfd, name);
633
986
  if (sec == NULL)
634
0
    return NULL;
635
636
986
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
637
638
986
  bfd_set_section_flags (sec, flags | extra_flags);
639
640
986
  bfd_set_section_alignment (sec, 2);
641
642
  /* Check that we will not run out of space.  */
643
986
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
644
645
  /* Set the section size and contents.  The actual
646
     contents are filled in by our parent.  */
647
986
  bfd_set_section_size (sec, (bfd_size_type) size);
648
986
  sec->contents = vars->data;
649
986
  sec->target_index = vars->sec_index ++;
650
651
  /* Advance data pointer in the vars structure.  */
652
986
  vars->data += size;
653
654
  /* Skip the padding byte if it was not needed.
655
     The logic here is that if the string length is odd,
656
     then the entire string length, including the null byte,
657
     is even and so the extra, padding byte, is not needed.  */
658
986
  if (size & 1)
659
39
    vars->data --;
660
661
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
662
     preserve host alignment requirements.  The BFD_ASSERTs in this
663
     functions will warn us if we run out of room, but we should
664
     already have enough padding built in to ILF_DATA_SIZE.  */
665
986
#if GCC_VERSION >= 3000
666
986
  alignment = __alignof__ (struct coff_section_tdata);
667
#else
668
  alignment = 8;
669
#endif
670
986
  vars->data
671
986
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
672
673
  /* Create a coff_section_tdata structure for our use.  */
674
986
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
675
986
  vars->data += sizeof (struct coff_section_tdata);
676
677
986
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
678
679
  /* Create a symbol to refer to this section.  */
680
986
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
681
682
  /* Cache the index to the symbol in the coff_section_data structure.  */
683
986
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
684
685
986
  return sec;
686
986
}
pei-arm.c:pe_ILF_make_a_section
Line
Count
Source
627
18.0k
{
628
18.0k
  asection_ptr sec;
629
18.0k
  flagword     flags;
630
18.0k
  intptr_t alignment;
631
632
18.0k
  sec = bfd_make_section_old_way (vars->abfd, name);
633
18.0k
  if (sec == NULL)
634
0
    return NULL;
635
636
18.0k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
637
638
18.0k
  bfd_set_section_flags (sec, flags | extra_flags);
639
640
18.0k
  bfd_set_section_alignment (sec, 2);
641
642
  /* Check that we will not run out of space.  */
643
18.0k
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
644
645
  /* Set the section size and contents.  The actual
646
     contents are filled in by our parent.  */
647
18.0k
  bfd_set_section_size (sec, (bfd_size_type) size);
648
18.0k
  sec->contents = vars->data;
649
18.0k
  sec->target_index = vars->sec_index ++;
650
651
  /* Advance data pointer in the vars structure.  */
652
18.0k
  vars->data += size;
653
654
  /* Skip the padding byte if it was not needed.
655
     The logic here is that if the string length is odd,
656
     then the entire string length, including the null byte,
657
     is even and so the extra, padding byte, is not needed.  */
658
18.0k
  if (size & 1)
659
2.46k
    vars->data --;
660
661
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
662
     preserve host alignment requirements.  The BFD_ASSERTs in this
663
     functions will warn us if we run out of room, but we should
664
     already have enough padding built in to ILF_DATA_SIZE.  */
665
18.0k
#if GCC_VERSION >= 3000
666
18.0k
  alignment = __alignof__ (struct coff_section_tdata);
667
#else
668
  alignment = 8;
669
#endif
670
18.0k
  vars->data
671
18.0k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
672
673
  /* Create a coff_section_tdata structure for our use.  */
674
18.0k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
675
18.0k
  vars->data += sizeof (struct coff_section_tdata);
676
677
18.0k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
678
679
  /* Create a symbol to refer to this section.  */
680
18.0k
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
681
682
  /* Cache the index to the symbol in the coff_section_data structure.  */
683
18.0k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
684
685
18.0k
  return sec;
686
18.0k
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_section
pei-sh.c:pe_ILF_make_a_section
Line
Count
Source
627
10.2k
{
628
10.2k
  asection_ptr sec;
629
10.2k
  flagword     flags;
630
10.2k
  intptr_t alignment;
631
632
10.2k
  sec = bfd_make_section_old_way (vars->abfd, name);
633
10.2k
  if (sec == NULL)
634
0
    return NULL;
635
636
10.2k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
637
638
10.2k
  bfd_set_section_flags (sec, flags | extra_flags);
639
640
10.2k
  bfd_set_section_alignment (sec, 2);
641
642
  /* Check that we will not run out of space.  */
643
10.2k
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
644
645
  /* Set the section size and contents.  The actual
646
     contents are filled in by our parent.  */
647
10.2k
  bfd_set_section_size (sec, (bfd_size_type) size);
648
10.2k
  sec->contents = vars->data;
649
10.2k
  sec->target_index = vars->sec_index ++;
650
651
  /* Advance data pointer in the vars structure.  */
652
10.2k
  vars->data += size;
653
654
  /* Skip the padding byte if it was not needed.
655
     The logic here is that if the string length is odd,
656
     then the entire string length, including the null byte,
657
     is even and so the extra, padding byte, is not needed.  */
658
10.2k
  if (size & 1)
659
728
    vars->data --;
660
661
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
662
     preserve host alignment requirements.  The BFD_ASSERTs in this
663
     functions will warn us if we run out of room, but we should
664
     already have enough padding built in to ILF_DATA_SIZE.  */
665
10.2k
#if GCC_VERSION >= 3000
666
10.2k
  alignment = __alignof__ (struct coff_section_tdata);
667
#else
668
  alignment = 8;
669
#endif
670
10.2k
  vars->data
671
10.2k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
672
673
  /* Create a coff_section_tdata structure for our use.  */
674
10.2k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
675
10.2k
  vars->data += sizeof (struct coff_section_tdata);
676
677
10.2k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
678
679
  /* Create a symbol to refer to this section.  */
680
10.2k
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
681
682
  /* Cache the index to the symbol in the coff_section_data structure.  */
683
10.2k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
684
685
10.2k
  return sec;
686
10.2k
}
687
688
/* This structure contains the code that goes into the .text section
689
   in order to perform a jump into the DLL lookup table.  The entries
690
   in the table are index by the magic number used to represent the
691
   machine type in the PE file.  The contents of the data[] arrays in
692
   these entries are stolen from the jtab[] arrays in ld/pe-dll.c.
693
   The SIZE field says how many bytes in the DATA array are actually
694
   used.  The OFFSET field says where in the data array the address
695
   of the .idata$5 section should be placed.  */
696
47.7k
#define MAX_TEXT_SECTION_SIZE 32
697
698
typedef struct
699
{
700
  unsigned short magic;
701
  unsigned char  data[MAX_TEXT_SECTION_SIZE];
702
  unsigned int   size;
703
  unsigned int   offset;
704
}
705
jump_table;
706
707
static const jump_table jtab[] =
708
{
709
#ifdef I386MAGIC
710
  { I386MAGIC,
711
    { 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, 0x90, 0x90 },
712
    8, 2
713
  },
714
#endif
715
716
#ifdef AMD64MAGIC
717
  { AMD64MAGIC,
718
    { 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, 0x90, 0x90 },
719
    8, 2
720
  },
721
#endif
722
723
#ifdef  MC68MAGIC
724
  { MC68MAGIC,
725
    { /* XXX fill me in */ },
726
    0, 0
727
  },
728
#endif
729
730
#ifdef  MIPS_ARCH_MAGIC_WINCE
731
  { MIPS_ARCH_MAGIC_WINCE,
732
    { 0x00, 0x00, 0x08, 0x3c, 0x00, 0x00, 0x08, 0x8d,
733
      0x08, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00 },
734
    16, 0
735
  },
736
#endif
737
738
#ifdef  SH_ARCH_MAGIC_WINCE
739
  { SH_ARCH_MAGIC_WINCE,
740
    { 0x01, 0xd0, 0x02, 0x60, 0x2b, 0x40,
741
      0x09, 0x00, 0x00, 0x00, 0x00, 0x00 },
742
    12, 8
743
  },
744
#endif
745
746
#ifdef AARCH64MAGIC
747
/* We don't currently support jumping to DLLs, so if
748
   someone does try emit a runtime trap.  Through UDF #0.  */
749
  { AARCH64MAGIC,
750
    { 0x00, 0x00, 0x00, 0x00 },
751
    4, 0
752
  },
753
754
#endif
755
756
#ifdef  ARMPEMAGIC
757
  { ARMPEMAGIC,
758
    { 0x00, 0xc0, 0x9f, 0xe5, 0x00, 0xf0,
759
      0x9c, 0xe5, 0x00, 0x00, 0x00, 0x00},
760
    12, 8
761
  },
762
#endif
763
764
#ifdef  THUMBPEMAGIC
765
  { THUMBPEMAGIC,
766
    { 0x40, 0xb4, 0x02, 0x4e, 0x36, 0x68, 0xb4, 0x46,
767
      0x40, 0xbc, 0x60, 0x47, 0x00, 0x00, 0x00, 0x00 },
768
    16, 12
769
  },
770
#endif
771
772
#ifdef LOONGARCH64MAGIC
773
/* We don't currently support jumping to DLLs, so if
774
   someone does try emit a runtime trap.  Through BREAK 0.  */
775
  { LOONGARCH64MAGIC,
776
    { 0x00, 0x00, 0x2a, 0x00 },
777
    4, 0
778
  },
779
780
#endif
781
782
  { 0, { 0 }, 0, 0 }
783
};
784
785
#ifndef NUM_ENTRIES
786
13.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
28.7k
{
799
28.7k
  bfd_byte *       ptr;
800
28.7k
  pe_ILF_vars      vars;
801
28.7k
  struct internal_filehdr  internal_f;
802
28.7k
  unsigned int       import_type;
803
28.7k
  unsigned int       import_name_type;
804
28.7k
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
805
28.7k
  coff_symbol_type **    imp_sym;
806
28.7k
  unsigned int       imp_index;
807
28.7k
  intptr_t alignment;
808
809
  /* Decode and verify the types field of the ILF structure.  */
810
28.7k
  import_type = types & 0x3;
811
28.7k
  import_name_type = (types & 0x1c) >> 2;
812
813
28.7k
  switch (import_type)
814
28.7k
    {
815
15.3k
    case IMPORT_CODE:
816
25.5k
    case IMPORT_DATA:
817
25.5k
      break;
818
819
2.03k
    case IMPORT_CONST:
820
      /* XXX code yet to be written.  */
821
      /* xgettext:c-format */
822
2.03k
      _bfd_error_handler (_("%pB: unhandled import type; %x"),
823
2.03k
        abfd, import_type);
824
2.03k
      return false;
825
826
1.20k
    default:
827
      /* xgettext:c-format */
828
1.20k
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
1.20k
        abfd, import_type);
830
1.20k
      return false;
831
28.7k
    }
832
833
25.5k
  switch (import_name_type)
834
25.5k
    {
835
9.64k
    case IMPORT_ORDINAL:
836
13.1k
    case IMPORT_NAME:
837
16.7k
    case IMPORT_NAME_NOPREFIX:
838
23.8k
    case IMPORT_NAME_UNDECORATE:
839
23.8k
      break;
840
841
1.62k
    default:
842
      /* xgettext:c-format */
843
1.62k
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
844
1.62k
        abfd, import_name_type);
845
1.62k
      return false;
846
25.5k
    }
847
848
  /* Initialise local variables.
849
850
     Note these are kept in a structure rather than being
851
     declared as statics since bfd frowns on global variables.
852
853
     We are going to construct the contents of the BFD in memory,
854
     so allocate all the space that we will need right now.  */
855
23.8k
  vars.bim
856
23.8k
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
857
23.8k
  if (vars.bim == NULL)
858
0
    return false;
859
860
23.8k
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
861
23.8k
  vars.bim->buffer = ptr;
862
23.8k
  vars.bim->size   = ILF_DATA_SIZE;
863
23.8k
  if (ptr == NULL)
864
0
    goto error_return;
865
866
  /* Initialise the pointers to regions of the memory and the
867
     other contents of the pe_ILF_vars structure as well.  */
868
23.8k
  vars.sym_cache = (coff_symbol_type *) ptr;
869
23.8k
  vars.sym_ptr   = (coff_symbol_type *) ptr;
870
23.8k
  vars.sym_index = 0;
871
23.8k
  ptr += SIZEOF_ILF_SYMS;
872
873
23.8k
  vars.sym_table = (unsigned int *) ptr;
874
23.8k
  vars.table_ptr = (unsigned int *) ptr;
875
23.8k
  ptr += SIZEOF_ILF_SYM_TABLE;
876
877
23.8k
  vars.native_syms = (combined_entry_type *) ptr;
878
23.8k
  vars.native_ptr  = (combined_entry_type *) ptr;
879
23.8k
  ptr += SIZEOF_ILF_NATIVE_SYMS;
880
881
23.8k
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
882
23.8k
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
883
23.8k
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
884
885
23.8k
  vars.esym_table = (SYMENT *) ptr;
886
23.8k
  vars.esym_ptr   = (SYMENT *) ptr;
887
23.8k
  ptr += SIZEOF_ILF_EXT_SYMS;
888
889
23.8k
  vars.reltab   = (arelent *) ptr;
890
23.8k
  vars.relcount = 0;
891
23.8k
  ptr += SIZEOF_ILF_RELOCS;
892
893
23.8k
  vars.int_reltab  = (struct internal_reloc *) ptr;
894
23.8k
  ptr += SIZEOF_ILF_INT_RELOCS;
895
896
23.8k
  vars.string_table = (char *) ptr;
897
23.8k
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
898
23.8k
  ptr += SIZEOF_ILF_STRINGS;
899
23.8k
  vars.end_string_ptr = (char *) ptr;
900
901
  /* The remaining space in bim->buffer is used
902
     by the pe_ILF_make_a_section() function.  */
903
904
  /* PR 18758: Make sure that the data area is sufficiently aligned for
905
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
906
     the test of GCC_VERSION.  For other compilers we assume 8 byte
907
     alignment.  */
908
23.8k
#if GCC_VERSION >= 3000
909
23.8k
  alignment = __alignof__ (struct coff_section_tdata);
910
#else
911
  alignment = 8;
912
#endif
913
23.8k
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
914
915
23.8k
  vars.data = ptr;
916
23.8k
  vars.abfd = abfd;
917
23.8k
  vars.sec_index = 0;
918
23.8k
  vars.magic = magic;
919
920
  /* Create the initial .idata$<n> sections:
921
     [.idata$2:  Import Directory Table -- not needed]
922
     .idata$4:  Import Lookup Table
923
     .idata$5:  Import Address Table
924
925
     Note we do not create a .idata$3 section as this is
926
     created for us by the linker script.  */
927
23.8k
  id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
928
23.8k
  id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
929
23.8k
  if (id4 == NULL || id5 == NULL)
930
0
    goto error_return;
931
932
  /* Fill in the contents of these sections.  */
933
23.8k
  if (import_name_type == IMPORT_ORDINAL)
934
9.64k
    {
935
9.64k
      if (ordinal == 0)
936
  /* See PR 20907 for a reproducer.  */
937
1.64k
  goto error_return;
938
939
#if defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) || defined(COFF_WITH_peLoongArch64)
940
3.88k
      ((unsigned int *) id4->contents)[0] = ordinal;
941
3.88k
      ((unsigned int *) id4->contents)[1] = 0x80000000;
942
3.88k
      ((unsigned int *) id5->contents)[0] = ordinal;
943
3.88k
      ((unsigned int *) id5->contents)[1] = 0x80000000;
944
#else
945
4.11k
      * (unsigned int *) id4->contents = ordinal | 0x80000000;
946
4.11k
      * (unsigned int *) id5->contents = ordinal | 0x80000000;
947
4.11k
#endif
948
4.11k
    }
949
14.2k
  else
950
14.2k
    {
951
14.2k
      char * symbol;
952
14.2k
      unsigned int len;
953
954
      /* Create .idata$6 - the Hint Name Table.  */
955
14.2k
      id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
956
14.2k
      if (id6 == NULL)
957
0
  goto error_return;
958
959
      /* If necessary, trim the import symbol name.  */
960
14.2k
      symbol = symbol_name;
961
962
      /* As used by MS compiler, '_', '@', and '?' are alternative
963
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
964
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
965
   of these is used for a symbol.  We strip this leading char for
966
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
967
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
968
969
14.2k
      if (import_name_type != IMPORT_NAME)
970
10.7k
  {
971
10.7k
    char c = symbol[0];
972
973
    /* Check that we don't remove for targets with empty
974
       USER_LABEL_PREFIX the leading underscore.  */
975
10.7k
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
976
10.7k
        || c == '@' || c == '?')
977
2.29k
      symbol++;
978
10.7k
  }
979
980
14.2k
      len = strlen (symbol);
981
14.2k
      if (import_name_type == IMPORT_NAME_UNDECORATE)
982
7.11k
  {
983
    /* Truncate at the first '@'.  */
984
7.11k
    char *at = strchr (symbol, '@');
985
986
7.11k
    if (at != NULL)
987
1.53k
      len = at - symbol;
988
7.11k
  }
989
990
14.2k
      id6->contents[0] = ordinal & 0xff;
991
14.2k
      id6->contents[1] = ordinal >> 8;
992
993
14.2k
      memcpy ((char *) id6->contents + 2, symbol, len);
994
14.2k
      id6->contents[len + 2] = '\0';
995
14.2k
    }
996
997
22.2k
  if (import_name_type != IMPORT_ORDINAL)
998
14.2k
    {
999
14.2k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1000
14.2k
      pe_ILF_save_relocs (&vars, id4);
1001
1002
14.2k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1003
14.2k
      pe_ILF_save_relocs (&vars, id5);
1004
14.2k
    }
1005
1006
  /* Create an import symbol.  */
1007
22.2k
  pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
1008
22.2k
  imp_sym   = vars.sym_ptr_ptr - 1;
1009
22.2k
  imp_index = vars.sym_index - 1;
1010
1011
  /* Create extra sections depending upon the type of import we are dealing with.  */
1012
22.2k
  switch (import_type)
1013
22.2k
    {
1014
0
      int i;
1015
1016
13.0k
    case IMPORT_CODE:
1017
      /* CODE functions are special, in that they get a trampoline that
1018
   jumps to the main import symbol.  Create a .text section to hold it.
1019
   First we need to look up its contents in the jump table.  */
1020
28.7k
      for (i = NUM_ENTRIES (jtab); i--;)
1021
28.7k
  {
1022
28.7k
    if (jtab[i].size == 0)
1023
13.0k
      continue;
1024
15.7k
    if (jtab[i].magic == magic)
1025
13.0k
      break;
1026
15.7k
  }
1027
      /* If we did not find a matching entry something is wrong.  */
1028
13.0k
      if (i < 0)
1029
0
  abort ();
1030
1031
      /* Create the .text section.  */
1032
13.0k
      text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
1033
13.0k
      if (text == NULL)
1034
0
  goto error_return;
1035
1036
      /* Copy in the jump code.  */
1037
13.0k
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1038
1039
      /* Create a reloc for the data in the text section.  */
1040
#ifdef MIPS_ARCH_MAGIC_WINCE
1041
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1042
  {
1043
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1044
              (struct bfd_symbol **) imp_sym,
1045
              imp_index);
1046
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1047
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1048
              (struct bfd_symbol **) imp_sym,
1049
              imp_index);
1050
  }
1051
      else
1052
#endif
1053
#ifdef AMD64MAGIC
1054
2.53k
      if (magic == AMD64MAGIC)
1055
2.53k
  {
1056
2.53k
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1057
2.53k
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1058
2.53k
              imp_index);
1059
2.53k
  }
1060
0
      else
1061
0
#endif
1062
0
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1063
0
            BFD_RELOC_32, (asymbol **) imp_sym,
1064
0
            imp_index);
1065
1066
13.0k
      pe_ILF_save_relocs (& vars, text);
1067
13.0k
      break;
1068
1069
9.21k
    case IMPORT_DATA:
1070
9.21k
      break;
1071
1072
0
    default:
1073
      /* XXX code not yet written.  */
1074
0
      abort ();
1075
22.2k
    }
1076
1077
  /* Now create a symbol describing the imported value.  */
1078
22.2k
  switch (import_type)
1079
22.2k
    {
1080
13.0k
    case IMPORT_CODE:
1081
13.0k
      pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1082
13.0k
          BSF_NOT_AT_END | BSF_FUNCTION);
1083
1084
13.0k
      break;
1085
1086
9.21k
    case IMPORT_DATA:
1087
      /* Nothing to do here.  */
1088
9.21k
      break;
1089
1090
0
    default:
1091
      /* XXX code not yet written.  */
1092
0
      abort ();
1093
22.2k
    }
1094
1095
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1096
22.2k
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1097
22.2k
  if (ptr)
1098
4.35k
    * ptr = 0;
1099
22.2k
  pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1100
22.2k
  if (ptr)
1101
4.35k
    * ptr = '.';
1102
1103
  /* Initialise the bfd.  */
1104
22.2k
  memset (& internal_f, 0, sizeof (internal_f));
1105
1106
22.2k
  internal_f.f_magic  = magic;
1107
22.2k
  internal_f.f_symptr = 0;
1108
22.2k
  internal_f.f_nsyms  = 0;
1109
22.2k
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1110
1111
22.2k
  if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
1112
22.2k
      || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1113
0
    goto error_return;
1114
1115
22.2k
  if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL)
1116
0
    goto error_return;
1117
1118
22.2k
  obj_pe (abfd) = true;
1119
#ifdef THUMBPEMAGIC
1120
5.38k
  if (vars.magic == THUMBPEMAGIC)
1121
    /* Stop some linker warnings about thumb code not supporting interworking.  */
1122
1.29k
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1123
#endif
1124
1125
  /* Switch from file contents to memory contents.  */
1126
22.2k
  bfd_cache_close (abfd);
1127
1128
22.2k
  abfd->iostream = (void *) vars.bim;
1129
22.2k
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1130
22.2k
  abfd->iovec = &_bfd_memory_iovec;
1131
22.2k
  abfd->where = 0;
1132
22.2k
  abfd->origin = 0;
1133
22.2k
  abfd->size = 0;
1134
22.2k
  obj_sym_filepos (abfd) = 0;
1135
1136
  /* Point the bfd at the symbol table.  */
1137
22.2k
  obj_symbols (abfd) = vars.sym_cache;
1138
22.2k
  abfd->symcount = vars.sym_index;
1139
1140
22.2k
  obj_raw_syments (abfd) = vars.native_syms;
1141
22.2k
  obj_raw_syment_count (abfd) = vars.sym_index;
1142
1143
22.2k
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1144
22.2k
  obj_coff_keep_syms (abfd) = true;
1145
1146
22.2k
  obj_convert (abfd) = vars.sym_table;
1147
22.2k
  obj_conv_table_size (abfd) = vars.sym_index;
1148
1149
22.2k
  obj_coff_strings (abfd) = vars.string_table;
1150
22.2k
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1151
22.2k
  obj_coff_keep_strings (abfd) = true;
1152
1153
22.2k
  return true;
1154
1155
1.64k
 error_return:
1156
1.64k
  free (vars.bim->buffer);
1157
1.64k
  free (vars.bim);
1158
1.64k
  return false;
1159
22.2k
}
pei-i386.c:pe_ILF_build_a_bfd
Line
Count
Source
798
4.66k
{
799
4.66k
  bfd_byte *       ptr;
800
4.66k
  pe_ILF_vars      vars;
801
4.66k
  struct internal_filehdr  internal_f;
802
4.66k
  unsigned int       import_type;
803
4.66k
  unsigned int       import_name_type;
804
4.66k
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
805
4.66k
  coff_symbol_type **    imp_sym;
806
4.66k
  unsigned int       imp_index;
807
4.66k
  intptr_t alignment;
808
809
  /* Decode and verify the types field of the ILF structure.  */
810
4.66k
  import_type = types & 0x3;
811
4.66k
  import_name_type = (types & 0x1c) >> 2;
812
813
4.66k
  switch (import_type)
814
4.66k
    {
815
2.94k
    case IMPORT_CODE:
816
4.43k
    case IMPORT_DATA:
817
4.43k
      break;
818
819
14
    case IMPORT_CONST:
820
      /* XXX code yet to be written.  */
821
      /* xgettext:c-format */
822
14
      _bfd_error_handler (_("%pB: unhandled import type; %x"),
823
14
        abfd, import_type);
824
14
      return false;
825
826
216
    default:
827
      /* xgettext:c-format */
828
216
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
216
        abfd, import_type);
830
216
      return false;
831
4.66k
    }
832
833
4.43k
  switch (import_name_type)
834
4.43k
    {
835
2.01k
    case IMPORT_ORDINAL:
836
2.25k
    case IMPORT_NAME:
837
2.82k
    case IMPORT_NAME_NOPREFIX:
838
4.22k
    case IMPORT_NAME_UNDECORATE:
839
4.22k
      break;
840
841
216
    default:
842
      /* xgettext:c-format */
843
216
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
844
216
        abfd, import_name_type);
845
216
      return false;
846
4.43k
    }
847
848
  /* Initialise local variables.
849
850
     Note these are kept in a structure rather than being
851
     declared as statics since bfd frowns on global variables.
852
853
     We are going to construct the contents of the BFD in memory,
854
     so allocate all the space that we will need right now.  */
855
4.22k
  vars.bim
856
4.22k
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
857
4.22k
  if (vars.bim == NULL)
858
0
    return false;
859
860
4.22k
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
861
4.22k
  vars.bim->buffer = ptr;
862
4.22k
  vars.bim->size   = ILF_DATA_SIZE;
863
4.22k
  if (ptr == NULL)
864
0
    goto error_return;
865
866
  /* Initialise the pointers to regions of the memory and the
867
     other contents of the pe_ILF_vars structure as well.  */
868
4.22k
  vars.sym_cache = (coff_symbol_type *) ptr;
869
4.22k
  vars.sym_ptr   = (coff_symbol_type *) ptr;
870
4.22k
  vars.sym_index = 0;
871
4.22k
  ptr += SIZEOF_ILF_SYMS;
872
873
4.22k
  vars.sym_table = (unsigned int *) ptr;
874
4.22k
  vars.table_ptr = (unsigned int *) ptr;
875
4.22k
  ptr += SIZEOF_ILF_SYM_TABLE;
876
877
4.22k
  vars.native_syms = (combined_entry_type *) ptr;
878
4.22k
  vars.native_ptr  = (combined_entry_type *) ptr;
879
4.22k
  ptr += SIZEOF_ILF_NATIVE_SYMS;
880
881
4.22k
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
882
4.22k
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
883
4.22k
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
884
885
4.22k
  vars.esym_table = (SYMENT *) ptr;
886
4.22k
  vars.esym_ptr   = (SYMENT *) ptr;
887
4.22k
  ptr += SIZEOF_ILF_EXT_SYMS;
888
889
4.22k
  vars.reltab   = (arelent *) ptr;
890
4.22k
  vars.relcount = 0;
891
4.22k
  ptr += SIZEOF_ILF_RELOCS;
892
893
4.22k
  vars.int_reltab  = (struct internal_reloc *) ptr;
894
4.22k
  ptr += SIZEOF_ILF_INT_RELOCS;
895
896
4.22k
  vars.string_table = (char *) ptr;
897
4.22k
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
898
4.22k
  ptr += SIZEOF_ILF_STRINGS;
899
4.22k
  vars.end_string_ptr = (char *) ptr;
900
901
  /* The remaining space in bim->buffer is used
902
     by the pe_ILF_make_a_section() function.  */
903
904
  /* PR 18758: Make sure that the data area is sufficiently aligned for
905
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
906
     the test of GCC_VERSION.  For other compilers we assume 8 byte
907
     alignment.  */
908
4.22k
#if GCC_VERSION >= 3000
909
4.22k
  alignment = __alignof__ (struct coff_section_tdata);
910
#else
911
  alignment = 8;
912
#endif
913
4.22k
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
914
915
4.22k
  vars.data = ptr;
916
4.22k
  vars.abfd = abfd;
917
4.22k
  vars.sec_index = 0;
918
4.22k
  vars.magic = magic;
919
920
  /* Create the initial .idata$<n> sections:
921
     [.idata$2:  Import Directory Table -- not needed]
922
     .idata$4:  Import Lookup Table
923
     .idata$5:  Import Address Table
924
925
     Note we do not create a .idata$3 section as this is
926
     created for us by the linker script.  */
927
4.22k
  id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
928
4.22k
  id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
929
4.22k
  if (id4 == NULL || id5 == NULL)
930
0
    goto error_return;
931
932
  /* Fill in the contents of these sections.  */
933
4.22k
  if (import_name_type == IMPORT_ORDINAL)
934
2.01k
    {
935
2.01k
      if (ordinal == 0)
936
  /* See PR 20907 for a reproducer.  */
937
419
  goto error_return;
938
939
#if defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) || defined(COFF_WITH_peLoongArch64)
940
      ((unsigned int *) id4->contents)[0] = ordinal;
941
      ((unsigned int *) id4->contents)[1] = 0x80000000;
942
      ((unsigned int *) id5->contents)[0] = ordinal;
943
      ((unsigned int *) id5->contents)[1] = 0x80000000;
944
#else
945
1.59k
      * (unsigned int *) id4->contents = ordinal | 0x80000000;
946
1.59k
      * (unsigned int *) id5->contents = ordinal | 0x80000000;
947
1.59k
#endif
948
1.59k
    }
949
2.21k
  else
950
2.21k
    {
951
2.21k
      char * symbol;
952
2.21k
      unsigned int len;
953
954
      /* Create .idata$6 - the Hint Name Table.  */
955
2.21k
      id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
956
2.21k
      if (id6 == NULL)
957
0
  goto error_return;
958
959
      /* If necessary, trim the import symbol name.  */
960
2.21k
      symbol = symbol_name;
961
962
      /* As used by MS compiler, '_', '@', and '?' are alternative
963
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
964
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
965
   of these is used for a symbol.  We strip this leading char for
966
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
967
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
968
969
2.21k
      if (import_name_type != IMPORT_NAME)
970
1.96k
  {
971
1.96k
    char c = symbol[0];
972
973
    /* Check that we don't remove for targets with empty
974
       USER_LABEL_PREFIX the leading underscore.  */
975
1.96k
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
976
1.96k
        || c == '@' || c == '?')
977
243
      symbol++;
978
1.96k
  }
979
980
2.21k
      len = strlen (symbol);
981
2.21k
      if (import_name_type == IMPORT_NAME_UNDECORATE)
982
1.39k
  {
983
    /* Truncate at the first '@'.  */
984
1.39k
    char *at = strchr (symbol, '@');
985
986
1.39k
    if (at != NULL)
987
469
      len = at - symbol;
988
1.39k
  }
989
990
2.21k
      id6->contents[0] = ordinal & 0xff;
991
2.21k
      id6->contents[1] = ordinal >> 8;
992
993
2.21k
      memcpy ((char *) id6->contents + 2, symbol, len);
994
2.21k
      id6->contents[len + 2] = '\0';
995
2.21k
    }
996
997
3.80k
  if (import_name_type != IMPORT_ORDINAL)
998
2.21k
    {
999
2.21k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1000
2.21k
      pe_ILF_save_relocs (&vars, id4);
1001
1002
2.21k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1003
2.21k
      pe_ILF_save_relocs (&vars, id5);
1004
2.21k
    }
1005
1006
  /* Create an import symbol.  */
1007
3.80k
  pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
1008
3.80k
  imp_sym   = vars.sym_ptr_ptr - 1;
1009
3.80k
  imp_index = vars.sym_index - 1;
1010
1011
  /* Create extra sections depending upon the type of import we are dealing with.  */
1012
3.80k
  switch (import_type)
1013
3.80k
    {
1014
0
      int i;
1015
1016
2.41k
    case IMPORT_CODE:
1017
      /* CODE functions are special, in that they get a trampoline that
1018
   jumps to the main import symbol.  Create a .text section to hold it.
1019
   First we need to look up its contents in the jump table.  */
1020
4.83k
      for (i = NUM_ENTRIES (jtab); i--;)
1021
4.83k
  {
1022
4.83k
    if (jtab[i].size == 0)
1023
2.41k
      continue;
1024
2.41k
    if (jtab[i].magic == magic)
1025
2.41k
      break;
1026
2.41k
  }
1027
      /* If we did not find a matching entry something is wrong.  */
1028
2.41k
      if (i < 0)
1029
0
  abort ();
1030
1031
      /* Create the .text section.  */
1032
2.41k
      text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
1033
2.41k
      if (text == NULL)
1034
0
  goto error_return;
1035
1036
      /* Copy in the jump code.  */
1037
2.41k
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1038
1039
      /* Create a reloc for the data in the text section.  */
1040
#ifdef MIPS_ARCH_MAGIC_WINCE
1041
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1042
  {
1043
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1044
              (struct bfd_symbol **) imp_sym,
1045
              imp_index);
1046
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1047
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1048
              (struct bfd_symbol **) imp_sym,
1049
              imp_index);
1050
  }
1051
      else
1052
#endif
1053
#ifdef AMD64MAGIC
1054
      if (magic == AMD64MAGIC)
1055
  {
1056
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1057
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1058
              imp_index);
1059
  }
1060
      else
1061
#endif
1062
2.41k
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1063
2.41k
            BFD_RELOC_32, (asymbol **) imp_sym,
1064
2.41k
            imp_index);
1065
1066
2.41k
      pe_ILF_save_relocs (& vars, text);
1067
2.41k
      break;
1068
1069
1.38k
    case IMPORT_DATA:
1070
1.38k
      break;
1071
1072
0
    default:
1073
      /* XXX code not yet written.  */
1074
0
      abort ();
1075
3.80k
    }
1076
1077
  /* Now create a symbol describing the imported value.  */
1078
3.80k
  switch (import_type)
1079
3.80k
    {
1080
2.41k
    case IMPORT_CODE:
1081
2.41k
      pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1082
2.41k
          BSF_NOT_AT_END | BSF_FUNCTION);
1083
1084
2.41k
      break;
1085
1086
1.38k
    case IMPORT_DATA:
1087
      /* Nothing to do here.  */
1088
1.38k
      break;
1089
1090
0
    default:
1091
      /* XXX code not yet written.  */
1092
0
      abort ();
1093
3.80k
    }
1094
1095
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1096
3.80k
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1097
3.80k
  if (ptr)
1098
8
    * ptr = 0;
1099
3.80k
  pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1100
3.80k
  if (ptr)
1101
8
    * ptr = '.';
1102
1103
  /* Initialise the bfd.  */
1104
3.80k
  memset (& internal_f, 0, sizeof (internal_f));
1105
1106
3.80k
  internal_f.f_magic  = magic;
1107
3.80k
  internal_f.f_symptr = 0;
1108
3.80k
  internal_f.f_nsyms  = 0;
1109
3.80k
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1110
1111
3.80k
  if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
1112
3.80k
      || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1113
0
    goto error_return;
1114
1115
3.80k
  if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL)
1116
0
    goto error_return;
1117
1118
3.80k
  obj_pe (abfd) = true;
1119
#ifdef THUMBPEMAGIC
1120
  if (vars.magic == THUMBPEMAGIC)
1121
    /* Stop some linker warnings about thumb code not supporting interworking.  */
1122
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1123
#endif
1124
1125
  /* Switch from file contents to memory contents.  */
1126
3.80k
  bfd_cache_close (abfd);
1127
1128
3.80k
  abfd->iostream = (void *) vars.bim;
1129
3.80k
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1130
3.80k
  abfd->iovec = &_bfd_memory_iovec;
1131
3.80k
  abfd->where = 0;
1132
3.80k
  abfd->origin = 0;
1133
3.80k
  abfd->size = 0;
1134
3.80k
  obj_sym_filepos (abfd) = 0;
1135
1136
  /* Point the bfd at the symbol table.  */
1137
3.80k
  obj_symbols (abfd) = vars.sym_cache;
1138
3.80k
  abfd->symcount = vars.sym_index;
1139
1140
3.80k
  obj_raw_syments (abfd) = vars.native_syms;
1141
3.80k
  obj_raw_syment_count (abfd) = vars.sym_index;
1142
1143
3.80k
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1144
3.80k
  obj_coff_keep_syms (abfd) = true;
1145
1146
3.80k
  obj_convert (abfd) = vars.sym_table;
1147
3.80k
  obj_conv_table_size (abfd) = vars.sym_index;
1148
1149
3.80k
  obj_coff_strings (abfd) = vars.string_table;
1150
3.80k
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1151
3.80k
  obj_coff_keep_strings (abfd) = true;
1152
1153
3.80k
  return true;
1154
1155
419
 error_return:
1156
419
  free (vars.bim->buffer);
1157
419
  free (vars.bim);
1158
419
  return false;
1159
3.80k
}
pei-x86_64.c:pe_ILF_build_a_bfd
Line
Count
Source
798
5.22k
{
799
5.22k
  bfd_byte *       ptr;
800
5.22k
  pe_ILF_vars      vars;
801
5.22k
  struct internal_filehdr  internal_f;
802
5.22k
  unsigned int       import_type;
803
5.22k
  unsigned int       import_name_type;
804
5.22k
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
805
5.22k
  coff_symbol_type **    imp_sym;
806
5.22k
  unsigned int       imp_index;
807
5.22k
  intptr_t alignment;
808
809
  /* Decode and verify the types field of the ILF structure.  */
810
5.22k
  import_type = types & 0x3;
811
5.22k
  import_name_type = (types & 0x1c) >> 2;
812
813
5.22k
  switch (import_type)
814
5.22k
    {
815
3.16k
    case IMPORT_CODE:
816
4.89k
    case IMPORT_DATA:
817
4.89k
      break;
818
819
218
    case IMPORT_CONST:
820
      /* XXX code yet to be written.  */
821
      /* xgettext:c-format */
822
218
      _bfd_error_handler (_("%pB: unhandled import type; %x"),
823
218
        abfd, import_type);
824
218
      return false;
825
826
114
    default:
827
      /* xgettext:c-format */
828
114
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
114
        abfd, import_type);
830
114
      return false;
831
5.22k
    }
832
833
4.89k
  switch (import_name_type)
834
4.89k
    {
835
2.07k
    case IMPORT_ORDINAL:
836
2.51k
    case IMPORT_NAME:
837
3.62k
    case IMPORT_NAME_NOPREFIX:
838
4.57k
    case IMPORT_NAME_UNDECORATE:
839
4.57k
      break;
840
841
318
    default:
842
      /* xgettext:c-format */
843
318
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
844
318
        abfd, import_name_type);
845
318
      return false;
846
4.89k
    }
847
848
  /* Initialise local variables.
849
850
     Note these are kept in a structure rather than being
851
     declared as statics since bfd frowns on global variables.
852
853
     We are going to construct the contents of the BFD in memory,
854
     so allocate all the space that we will need right now.  */
855
4.57k
  vars.bim
856
4.57k
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
857
4.57k
  if (vars.bim == NULL)
858
0
    return false;
859
860
4.57k
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
861
4.57k
  vars.bim->buffer = ptr;
862
4.57k
  vars.bim->size   = ILF_DATA_SIZE;
863
4.57k
  if (ptr == NULL)
864
0
    goto error_return;
865
866
  /* Initialise the pointers to regions of the memory and the
867
     other contents of the pe_ILF_vars structure as well.  */
868
4.57k
  vars.sym_cache = (coff_symbol_type *) ptr;
869
4.57k
  vars.sym_ptr   = (coff_symbol_type *) ptr;
870
4.57k
  vars.sym_index = 0;
871
4.57k
  ptr += SIZEOF_ILF_SYMS;
872
873
4.57k
  vars.sym_table = (unsigned int *) ptr;
874
4.57k
  vars.table_ptr = (unsigned int *) ptr;
875
4.57k
  ptr += SIZEOF_ILF_SYM_TABLE;
876
877
4.57k
  vars.native_syms = (combined_entry_type *) ptr;
878
4.57k
  vars.native_ptr  = (combined_entry_type *) ptr;
879
4.57k
  ptr += SIZEOF_ILF_NATIVE_SYMS;
880
881
4.57k
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
882
4.57k
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
883
4.57k
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
884
885
4.57k
  vars.esym_table = (SYMENT *) ptr;
886
4.57k
  vars.esym_ptr   = (SYMENT *) ptr;
887
4.57k
  ptr += SIZEOF_ILF_EXT_SYMS;
888
889
4.57k
  vars.reltab   = (arelent *) ptr;
890
4.57k
  vars.relcount = 0;
891
4.57k
  ptr += SIZEOF_ILF_RELOCS;
892
893
4.57k
  vars.int_reltab  = (struct internal_reloc *) ptr;
894
4.57k
  ptr += SIZEOF_ILF_INT_RELOCS;
895
896
4.57k
  vars.string_table = (char *) ptr;
897
4.57k
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
898
4.57k
  ptr += SIZEOF_ILF_STRINGS;
899
4.57k
  vars.end_string_ptr = (char *) ptr;
900
901
  /* The remaining space in bim->buffer is used
902
     by the pe_ILF_make_a_section() function.  */
903
904
  /* PR 18758: Make sure that the data area is sufficiently aligned for
905
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
906
     the test of GCC_VERSION.  For other compilers we assume 8 byte
907
     alignment.  */
908
4.57k
#if GCC_VERSION >= 3000
909
4.57k
  alignment = __alignof__ (struct coff_section_tdata);
910
#else
911
  alignment = 8;
912
#endif
913
4.57k
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
914
915
4.57k
  vars.data = ptr;
916
4.57k
  vars.abfd = abfd;
917
4.57k
  vars.sec_index = 0;
918
4.57k
  vars.magic = magic;
919
920
  /* Create the initial .idata$<n> sections:
921
     [.idata$2:  Import Directory Table -- not needed]
922
     .idata$4:  Import Lookup Table
923
     .idata$5:  Import Address Table
924
925
     Note we do not create a .idata$3 section as this is
926
     created for us by the linker script.  */
927
4.57k
  id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
928
4.57k
  id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
929
4.57k
  if (id4 == NULL || id5 == NULL)
930
0
    goto error_return;
931
932
  /* Fill in the contents of these sections.  */
933
4.57k
  if (import_name_type == IMPORT_ORDINAL)
934
2.07k
    {
935
2.07k
      if (ordinal == 0)
936
  /* See PR 20907 for a reproducer.  */
937
423
  goto error_return;
938
939
1.64k
#if defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) || defined(COFF_WITH_peLoongArch64)
940
1.64k
      ((unsigned int *) id4->contents)[0] = ordinal;
941
1.64k
      ((unsigned int *) id4->contents)[1] = 0x80000000;
942
1.64k
      ((unsigned int *) id5->contents)[0] = ordinal;
943
1.64k
      ((unsigned int *) id5->contents)[1] = 0x80000000;
944
#else
945
      * (unsigned int *) id4->contents = ordinal | 0x80000000;
946
      * (unsigned int *) id5->contents = ordinal | 0x80000000;
947
#endif
948
1.64k
    }
949
2.50k
  else
950
2.50k
    {
951
2.50k
      char * symbol;
952
2.50k
      unsigned int len;
953
954
      /* Create .idata$6 - the Hint Name Table.  */
955
2.50k
      id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
956
2.50k
      if (id6 == NULL)
957
0
  goto error_return;
958
959
      /* If necessary, trim the import symbol name.  */
960
2.50k
      symbol = symbol_name;
961
962
      /* As used by MS compiler, '_', '@', and '?' are alternative
963
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
964
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
965
   of these is used for a symbol.  We strip this leading char for
966
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
967
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
968
969
2.50k
      if (import_name_type != IMPORT_NAME)
970
2.06k
  {
971
2.06k
    char c = symbol[0];
972
973
    /* Check that we don't remove for targets with empty
974
       USER_LABEL_PREFIX the leading underscore.  */
975
2.06k
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
976
2.06k
        || c == '@' || c == '?')
977
675
      symbol++;
978
2.06k
  }
979
980
2.50k
      len = strlen (symbol);
981
2.50k
      if (import_name_type == IMPORT_NAME_UNDECORATE)
982
951
  {
983
    /* Truncate at the first '@'.  */
984
951
    char *at = strchr (symbol, '@');
985
986
951
    if (at != NULL)
987
235
      len = at - symbol;
988
951
  }
989
990
2.50k
      id6->contents[0] = ordinal & 0xff;
991
2.50k
      id6->contents[1] = ordinal >> 8;
992
993
2.50k
      memcpy ((char *) id6->contents + 2, symbol, len);
994
2.50k
      id6->contents[len + 2] = '\0';
995
2.50k
    }
996
997
4.15k
  if (import_name_type != IMPORT_ORDINAL)
998
2.50k
    {
999
2.50k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1000
2.50k
      pe_ILF_save_relocs (&vars, id4);
1001
1002
2.50k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1003
2.50k
      pe_ILF_save_relocs (&vars, id5);
1004
2.50k
    }
1005
1006
  /* Create an import symbol.  */
1007
4.15k
  pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
1008
4.15k
  imp_sym   = vars.sym_ptr_ptr - 1;
1009
4.15k
  imp_index = vars.sym_index - 1;
1010
1011
  /* Create extra sections depending upon the type of import we are dealing with.  */
1012
4.15k
  switch (import_type)
1013
4.15k
    {
1014
0
      int i;
1015
1016
2.53k
    case IMPORT_CODE:
1017
      /* CODE functions are special, in that they get a trampoline that
1018
   jumps to the main import symbol.  Create a .text section to hold it.
1019
   First we need to look up its contents in the jump table.  */
1020
5.06k
      for (i = NUM_ENTRIES (jtab); i--;)
1021
5.06k
  {
1022
5.06k
    if (jtab[i].size == 0)
1023
2.53k
      continue;
1024
2.53k
    if (jtab[i].magic == magic)
1025
2.53k
      break;
1026
2.53k
  }
1027
      /* If we did not find a matching entry something is wrong.  */
1028
2.53k
      if (i < 0)
1029
0
  abort ();
1030
1031
      /* Create the .text section.  */
1032
2.53k
      text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
1033
2.53k
      if (text == NULL)
1034
0
  goto error_return;
1035
1036
      /* Copy in the jump code.  */
1037
2.53k
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1038
1039
      /* Create a reloc for the data in the text section.  */
1040
#ifdef MIPS_ARCH_MAGIC_WINCE
1041
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1042
  {
1043
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1044
              (struct bfd_symbol **) imp_sym,
1045
              imp_index);
1046
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1047
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1048
              (struct bfd_symbol **) imp_sym,
1049
              imp_index);
1050
  }
1051
      else
1052
#endif
1053
2.53k
#ifdef AMD64MAGIC
1054
2.53k
      if (magic == AMD64MAGIC)
1055
2.53k
  {
1056
2.53k
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1057
2.53k
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1058
2.53k
              imp_index);
1059
2.53k
  }
1060
0
      else
1061
0
#endif
1062
0
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1063
0
            BFD_RELOC_32, (asymbol **) imp_sym,
1064
0
            imp_index);
1065
1066
2.53k
      pe_ILF_save_relocs (& vars, text);
1067
2.53k
      break;
1068
1069
1.62k
    case IMPORT_DATA:
1070
1.62k
      break;
1071
1072
0
    default:
1073
      /* XXX code not yet written.  */
1074
0
      abort ();
1075
4.15k
    }
1076
1077
  /* Now create a symbol describing the imported value.  */
1078
4.15k
  switch (import_type)
1079
4.15k
    {
1080
2.53k
    case IMPORT_CODE:
1081
2.53k
      pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1082
2.53k
          BSF_NOT_AT_END | BSF_FUNCTION);
1083
1084
2.53k
      break;
1085
1086
1.62k
    case IMPORT_DATA:
1087
      /* Nothing to do here.  */
1088
1.62k
      break;
1089
1090
0
    default:
1091
      /* XXX code not yet written.  */
1092
0
      abort ();
1093
4.15k
    }
1094
1095
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1096
4.15k
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1097
4.15k
  if (ptr)
1098
1.24k
    * ptr = 0;
1099
4.15k
  pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1100
4.15k
  if (ptr)
1101
1.24k
    * ptr = '.';
1102
1103
  /* Initialise the bfd.  */
1104
4.15k
  memset (& internal_f, 0, sizeof (internal_f));
1105
1106
4.15k
  internal_f.f_magic  = magic;
1107
4.15k
  internal_f.f_symptr = 0;
1108
4.15k
  internal_f.f_nsyms  = 0;
1109
4.15k
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1110
1111
4.15k
  if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
1112
4.15k
      || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1113
0
    goto error_return;
1114
1115
4.15k
  if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL)
1116
0
    goto error_return;
1117
1118
4.15k
  obj_pe (abfd) = true;
1119
#ifdef THUMBPEMAGIC
1120
  if (vars.magic == THUMBPEMAGIC)
1121
    /* Stop some linker warnings about thumb code not supporting interworking.  */
1122
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1123
#endif
1124
1125
  /* Switch from file contents to memory contents.  */
1126
4.15k
  bfd_cache_close (abfd);
1127
1128
4.15k
  abfd->iostream = (void *) vars.bim;
1129
4.15k
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1130
4.15k
  abfd->iovec = &_bfd_memory_iovec;
1131
4.15k
  abfd->where = 0;
1132
4.15k
  abfd->origin = 0;
1133
4.15k
  abfd->size = 0;
1134
4.15k
  obj_sym_filepos (abfd) = 0;
1135
1136
  /* Point the bfd at the symbol table.  */
1137
4.15k
  obj_symbols (abfd) = vars.sym_cache;
1138
4.15k
  abfd->symcount = vars.sym_index;
1139
1140
4.15k
  obj_raw_syments (abfd) = vars.native_syms;
1141
4.15k
  obj_raw_syment_count (abfd) = vars.sym_index;
1142
1143
4.15k
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1144
4.15k
  obj_coff_keep_syms (abfd) = true;
1145
1146
4.15k
  obj_convert (abfd) = vars.sym_table;
1147
4.15k
  obj_conv_table_size (abfd) = vars.sym_index;
1148
1149
4.15k
  obj_coff_strings (abfd) = vars.string_table;
1150
4.15k
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1151
4.15k
  obj_coff_keep_strings (abfd) = true;
1152
1153
4.15k
  return true;
1154
1155
423
 error_return:
1156
423
  free (vars.bim->buffer);
1157
423
  free (vars.bim);
1158
423
  return false;
1159
4.15k
}
pei-aarch64.c:pe_ILF_build_a_bfd
Line
Count
Source
798
2.55k
{
799
2.55k
  bfd_byte *       ptr;
800
2.55k
  pe_ILF_vars      vars;
801
2.55k
  struct internal_filehdr  internal_f;
802
2.55k
  unsigned int       import_type;
803
2.55k
  unsigned int       import_name_type;
804
2.55k
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
805
2.55k
  coff_symbol_type **    imp_sym;
806
2.55k
  unsigned int       imp_index;
807
2.55k
  intptr_t alignment;
808
809
  /* Decode and verify the types field of the ILF structure.  */
810
2.55k
  import_type = types & 0x3;
811
2.55k
  import_name_type = (types & 0x1c) >> 2;
812
813
2.55k
  switch (import_type)
814
2.55k
    {
815
1.09k
    case IMPORT_CODE:
816
2.32k
    case IMPORT_DATA:
817
2.32k
      break;
818
819
116
    case IMPORT_CONST:
820
      /* XXX code yet to be written.  */
821
      /* xgettext:c-format */
822
116
      _bfd_error_handler (_("%pB: unhandled import type; %x"),
823
116
        abfd, import_type);
824
116
      return false;
825
826
115
    default:
827
      /* xgettext:c-format */
828
115
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
115
        abfd, import_type);
830
115
      return false;
831
2.55k
    }
832
833
2.32k
  switch (import_name_type)
834
2.32k
    {
835
971
    case IMPORT_ORDINAL:
836
1.54k
    case IMPORT_NAME:
837
1.55k
    case IMPORT_NAME_NOPREFIX:
838
2.20k
    case IMPORT_NAME_UNDECORATE:
839
2.20k
      break;
840
841
115
    default:
842
      /* xgettext:c-format */
843
115
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
844
115
        abfd, import_name_type);
845
115
      return false;
846
2.32k
    }
847
848
  /* Initialise local variables.
849
850
     Note these are kept in a structure rather than being
851
     declared as statics since bfd frowns on global variables.
852
853
     We are going to construct the contents of the BFD in memory,
854
     so allocate all the space that we will need right now.  */
855
2.20k
  vars.bim
856
2.20k
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
857
2.20k
  if (vars.bim == NULL)
858
0
    return false;
859
860
2.20k
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
861
2.20k
  vars.bim->buffer = ptr;
862
2.20k
  vars.bim->size   = ILF_DATA_SIZE;
863
2.20k
  if (ptr == NULL)
864
0
    goto error_return;
865
866
  /* Initialise the pointers to regions of the memory and the
867
     other contents of the pe_ILF_vars structure as well.  */
868
2.20k
  vars.sym_cache = (coff_symbol_type *) ptr;
869
2.20k
  vars.sym_ptr   = (coff_symbol_type *) ptr;
870
2.20k
  vars.sym_index = 0;
871
2.20k
  ptr += SIZEOF_ILF_SYMS;
872
873
2.20k
  vars.sym_table = (unsigned int *) ptr;
874
2.20k
  vars.table_ptr = (unsigned int *) ptr;
875
2.20k
  ptr += SIZEOF_ILF_SYM_TABLE;
876
877
2.20k
  vars.native_syms = (combined_entry_type *) ptr;
878
2.20k
  vars.native_ptr  = (combined_entry_type *) ptr;
879
2.20k
  ptr += SIZEOF_ILF_NATIVE_SYMS;
880
881
2.20k
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
882
2.20k
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
883
2.20k
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
884
885
2.20k
  vars.esym_table = (SYMENT *) ptr;
886
2.20k
  vars.esym_ptr   = (SYMENT *) ptr;
887
2.20k
  ptr += SIZEOF_ILF_EXT_SYMS;
888
889
2.20k
  vars.reltab   = (arelent *) ptr;
890
2.20k
  vars.relcount = 0;
891
2.20k
  ptr += SIZEOF_ILF_RELOCS;
892
893
2.20k
  vars.int_reltab  = (struct internal_reloc *) ptr;
894
2.20k
  ptr += SIZEOF_ILF_INT_RELOCS;
895
896
2.20k
  vars.string_table = (char *) ptr;
897
2.20k
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
898
2.20k
  ptr += SIZEOF_ILF_STRINGS;
899
2.20k
  vars.end_string_ptr = (char *) ptr;
900
901
  /* The remaining space in bim->buffer is used
902
     by the pe_ILF_make_a_section() function.  */
903
904
  /* PR 18758: Make sure that the data area is sufficiently aligned for
905
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
906
     the test of GCC_VERSION.  For other compilers we assume 8 byte
907
     alignment.  */
908
2.20k
#if GCC_VERSION >= 3000
909
2.20k
  alignment = __alignof__ (struct coff_section_tdata);
910
#else
911
  alignment = 8;
912
#endif
913
2.20k
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
914
915
2.20k
  vars.data = ptr;
916
2.20k
  vars.abfd = abfd;
917
2.20k
  vars.sec_index = 0;
918
2.20k
  vars.magic = magic;
919
920
  /* Create the initial .idata$<n> sections:
921
     [.idata$2:  Import Directory Table -- not needed]
922
     .idata$4:  Import Lookup Table
923
     .idata$5:  Import Address Table
924
925
     Note we do not create a .idata$3 section as this is
926
     created for us by the linker script.  */
927
2.20k
  id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
928
2.20k
  id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
929
2.20k
  if (id4 == NULL || id5 == NULL)
930
0
    goto error_return;
931
932
  /* Fill in the contents of these sections.  */
933
2.20k
  if (import_name_type == IMPORT_ORDINAL)
934
971
    {
935
971
      if (ordinal == 0)
936
  /* See PR 20907 for a reproducer.  */
937
16
  goto error_return;
938
939
955
#if defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) || defined(COFF_WITH_peLoongArch64)
940
955
      ((unsigned int *) id4->contents)[0] = ordinal;
941
955
      ((unsigned int *) id4->contents)[1] = 0x80000000;
942
955
      ((unsigned int *) id5->contents)[0] = ordinal;
943
955
      ((unsigned int *) id5->contents)[1] = 0x80000000;
944
#else
945
      * (unsigned int *) id4->contents = ordinal | 0x80000000;
946
      * (unsigned int *) id5->contents = ordinal | 0x80000000;
947
#endif
948
955
    }
949
1.23k
  else
950
1.23k
    {
951
1.23k
      char * symbol;
952
1.23k
      unsigned int len;
953
954
      /* Create .idata$6 - the Hint Name Table.  */
955
1.23k
      id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
956
1.23k
      if (id6 == NULL)
957
0
  goto error_return;
958
959
      /* If necessary, trim the import symbol name.  */
960
1.23k
      symbol = symbol_name;
961
962
      /* As used by MS compiler, '_', '@', and '?' are alternative
963
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
964
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
965
   of these is used for a symbol.  We strip this leading char for
966
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
967
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
968
969
1.23k
      if (import_name_type != IMPORT_NAME)
970
660
  {
971
660
    char c = symbol[0];
972
973
    /* Check that we don't remove for targets with empty
974
       USER_LABEL_PREFIX the leading underscore.  */
975
660
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
976
660
        || c == '@' || c == '?')
977
241
      symbol++;
978
660
  }
979
980
1.23k
      len = strlen (symbol);
981
1.23k
      if (import_name_type == IMPORT_NAME_UNDECORATE)
982
651
  {
983
    /* Truncate at the first '@'.  */
984
651
    char *at = strchr (symbol, '@');
985
986
651
    if (at != NULL)
987
2
      len = at - symbol;
988
651
  }
989
990
1.23k
      id6->contents[0] = ordinal & 0xff;
991
1.23k
      id6->contents[1] = ordinal >> 8;
992
993
1.23k
      memcpy ((char *) id6->contents + 2, symbol, len);
994
1.23k
      id6->contents[len + 2] = '\0';
995
1.23k
    }
996
997
2.19k
  if (import_name_type != IMPORT_ORDINAL)
998
1.23k
    {
999
1.23k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1000
1.23k
      pe_ILF_save_relocs (&vars, id4);
1001
1002
1.23k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1003
1.23k
      pe_ILF_save_relocs (&vars, id5);
1004
1.23k
    }
1005
1006
  /* Create an import symbol.  */
1007
2.19k
  pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
1008
2.19k
  imp_sym   = vars.sym_ptr_ptr - 1;
1009
2.19k
  imp_index = vars.sym_index - 1;
1010
1011
  /* Create extra sections depending upon the type of import we are dealing with.  */
1012
2.19k
  switch (import_type)
1013
2.19k
    {
1014
0
      int i;
1015
1016
1.07k
    case IMPORT_CODE:
1017
      /* CODE functions are special, in that they get a trampoline that
1018
   jumps to the main import symbol.  Create a .text section to hold it.
1019
   First we need to look up its contents in the jump table.  */
1020
2.15k
      for (i = NUM_ENTRIES (jtab); i--;)
1021
2.15k
  {
1022
2.15k
    if (jtab[i].size == 0)
1023
1.07k
      continue;
1024
1.07k
    if (jtab[i].magic == magic)
1025
1.07k
      break;
1026
1.07k
  }
1027
      /* If we did not find a matching entry something is wrong.  */
1028
1.07k
      if (i < 0)
1029
0
  abort ();
1030
1031
      /* Create the .text section.  */
1032
1.07k
      text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
1033
1.07k
      if (text == NULL)
1034
0
  goto error_return;
1035
1036
      /* Copy in the jump code.  */
1037
1.07k
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1038
1039
      /* Create a reloc for the data in the text section.  */
1040
#ifdef MIPS_ARCH_MAGIC_WINCE
1041
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1042
  {
1043
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1044
              (struct bfd_symbol **) imp_sym,
1045
              imp_index);
1046
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1047
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1048
              (struct bfd_symbol **) imp_sym,
1049
              imp_index);
1050
  }
1051
      else
1052
#endif
1053
#ifdef AMD64MAGIC
1054
      if (magic == AMD64MAGIC)
1055
  {
1056
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1057
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1058
              imp_index);
1059
  }
1060
      else
1061
#endif
1062
1.07k
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1063
1.07k
            BFD_RELOC_32, (asymbol **) imp_sym,
1064
1.07k
            imp_index);
1065
1066
1.07k
      pe_ILF_save_relocs (& vars, text);
1067
1.07k
      break;
1068
1069
1.11k
    case IMPORT_DATA:
1070
1.11k
      break;
1071
1072
0
    default:
1073
      /* XXX code not yet written.  */
1074
0
      abort ();
1075
2.19k
    }
1076
1077
  /* Now create a symbol describing the imported value.  */
1078
2.19k
  switch (import_type)
1079
2.19k
    {
1080
1.07k
    case IMPORT_CODE:
1081
1.07k
      pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1082
1.07k
          BSF_NOT_AT_END | BSF_FUNCTION);
1083
1084
1.07k
      break;
1085
1086
1.11k
    case IMPORT_DATA:
1087
      /* Nothing to do here.  */
1088
1.11k
      break;
1089
1090
0
    default:
1091
      /* XXX code not yet written.  */
1092
0
      abort ();
1093
2.19k
    }
1094
1095
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1096
2.19k
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1097
2.19k
  if (ptr)
1098
705
    * ptr = 0;
1099
2.19k
  pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1100
2.19k
  if (ptr)
1101
705
    * ptr = '.';
1102
1103
  /* Initialise the bfd.  */
1104
2.19k
  memset (& internal_f, 0, sizeof (internal_f));
1105
1106
2.19k
  internal_f.f_magic  = magic;
1107
2.19k
  internal_f.f_symptr = 0;
1108
2.19k
  internal_f.f_nsyms  = 0;
1109
2.19k
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1110
1111
2.19k
  if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
1112
2.19k
      || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1113
0
    goto error_return;
1114
1115
2.19k
  if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL)
1116
0
    goto error_return;
1117
1118
2.19k
  obj_pe (abfd) = true;
1119
#ifdef THUMBPEMAGIC
1120
  if (vars.magic == THUMBPEMAGIC)
1121
    /* Stop some linker warnings about thumb code not supporting interworking.  */
1122
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1123
#endif
1124
1125
  /* Switch from file contents to memory contents.  */
1126
2.19k
  bfd_cache_close (abfd);
1127
1128
2.19k
  abfd->iostream = (void *) vars.bim;
1129
2.19k
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1130
2.19k
  abfd->iovec = &_bfd_memory_iovec;
1131
2.19k
  abfd->where = 0;
1132
2.19k
  abfd->origin = 0;
1133
2.19k
  abfd->size = 0;
1134
2.19k
  obj_sym_filepos (abfd) = 0;
1135
1136
  /* Point the bfd at the symbol table.  */
1137
2.19k
  obj_symbols (abfd) = vars.sym_cache;
1138
2.19k
  abfd->symcount = vars.sym_index;
1139
1140
2.19k
  obj_raw_syments (abfd) = vars.native_syms;
1141
2.19k
  obj_raw_syment_count (abfd) = vars.sym_index;
1142
1143
2.19k
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1144
2.19k
  obj_coff_keep_syms (abfd) = true;
1145
1146
2.19k
  obj_convert (abfd) = vars.sym_table;
1147
2.19k
  obj_conv_table_size (abfd) = vars.sym_index;
1148
1149
2.19k
  obj_coff_strings (abfd) = vars.string_table;
1150
2.19k
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1151
2.19k
  obj_coff_keep_strings (abfd) = true;
1152
1153
2.19k
  return true;
1154
1155
16
 error_return:
1156
16
  free (vars.bim->buffer);
1157
16
  free (vars.bim);
1158
16
  return false;
1159
2.19k
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_build_a_bfd
pei-loongarch64.c:pe_ILF_build_a_bfd
Line
Count
Source
798
4.65k
{
799
4.65k
  bfd_byte *       ptr;
800
4.65k
  pe_ILF_vars      vars;
801
4.65k
  struct internal_filehdr  internal_f;
802
4.65k
  unsigned int       import_type;
803
4.65k
  unsigned int       import_name_type;
804
4.65k
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
805
4.65k
  coff_symbol_type **    imp_sym;
806
4.65k
  unsigned int       imp_index;
807
4.65k
  intptr_t alignment;
808
809
  /* Decode and verify the types field of the ILF structure.  */
810
4.65k
  import_type = types & 0x3;
811
4.65k
  import_name_type = (types & 0x1c) >> 2;
812
813
4.65k
  switch (import_type)
814
4.65k
    {
815
2.08k
    case IMPORT_CODE:
816
4.02k
    case IMPORT_DATA:
817
4.02k
      break;
818
819
318
    case IMPORT_CONST:
820
      /* XXX code yet to be written.  */
821
      /* xgettext:c-format */
822
318
      _bfd_error_handler (_("%pB: unhandled import type; %x"),
823
318
        abfd, import_type);
824
318
      return false;
825
826
318
    default:
827
      /* xgettext:c-format */
828
318
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
318
        abfd, import_type);
830
318
      return false;
831
4.65k
    }
832
833
4.02k
  switch (import_name_type)
834
4.02k
    {
835
1.29k
    case IMPORT_ORDINAL:
836
1.77k
    case IMPORT_NAME:
837
1.78k
    case IMPORT_NAME_NOPREFIX:
838
3.70k
    case IMPORT_NAME_UNDECORATE:
839
3.70k
      break;
840
841
319
    default:
842
      /* xgettext:c-format */
843
319
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
844
319
        abfd, import_name_type);
845
319
      return false;
846
4.02k
    }
847
848
  /* Initialise local variables.
849
850
     Note these are kept in a structure rather than being
851
     declared as statics since bfd frowns on global variables.
852
853
     We are going to construct the contents of the BFD in memory,
854
     so allocate all the space that we will need right now.  */
855
3.70k
  vars.bim
856
3.70k
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
857
3.70k
  if (vars.bim == NULL)
858
0
    return false;
859
860
3.70k
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
861
3.70k
  vars.bim->buffer = ptr;
862
3.70k
  vars.bim->size   = ILF_DATA_SIZE;
863
3.70k
  if (ptr == NULL)
864
0
    goto error_return;
865
866
  /* Initialise the pointers to regions of the memory and the
867
     other contents of the pe_ILF_vars structure as well.  */
868
3.70k
  vars.sym_cache = (coff_symbol_type *) ptr;
869
3.70k
  vars.sym_ptr   = (coff_symbol_type *) ptr;
870
3.70k
  vars.sym_index = 0;
871
3.70k
  ptr += SIZEOF_ILF_SYMS;
872
873
3.70k
  vars.sym_table = (unsigned int *) ptr;
874
3.70k
  vars.table_ptr = (unsigned int *) ptr;
875
3.70k
  ptr += SIZEOF_ILF_SYM_TABLE;
876
877
3.70k
  vars.native_syms = (combined_entry_type *) ptr;
878
3.70k
  vars.native_ptr  = (combined_entry_type *) ptr;
879
3.70k
  ptr += SIZEOF_ILF_NATIVE_SYMS;
880
881
3.70k
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
882
3.70k
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
883
3.70k
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
884
885
3.70k
  vars.esym_table = (SYMENT *) ptr;
886
3.70k
  vars.esym_ptr   = (SYMENT *) ptr;
887
3.70k
  ptr += SIZEOF_ILF_EXT_SYMS;
888
889
3.70k
  vars.reltab   = (arelent *) ptr;
890
3.70k
  vars.relcount = 0;
891
3.70k
  ptr += SIZEOF_ILF_RELOCS;
892
893
3.70k
  vars.int_reltab  = (struct internal_reloc *) ptr;
894
3.70k
  ptr += SIZEOF_ILF_INT_RELOCS;
895
896
3.70k
  vars.string_table = (char *) ptr;
897
3.70k
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
898
3.70k
  ptr += SIZEOF_ILF_STRINGS;
899
3.70k
  vars.end_string_ptr = (char *) ptr;
900
901
  /* The remaining space in bim->buffer is used
902
     by the pe_ILF_make_a_section() function.  */
903
904
  /* PR 18758: Make sure that the data area is sufficiently aligned for
905
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
906
     the test of GCC_VERSION.  For other compilers we assume 8 byte
907
     alignment.  */
908
3.70k
#if GCC_VERSION >= 3000
909
3.70k
  alignment = __alignof__ (struct coff_section_tdata);
910
#else
911
  alignment = 8;
912
#endif
913
3.70k
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
914
915
3.70k
  vars.data = ptr;
916
3.70k
  vars.abfd = abfd;
917
3.70k
  vars.sec_index = 0;
918
3.70k
  vars.magic = magic;
919
920
  /* Create the initial .idata$<n> sections:
921
     [.idata$2:  Import Directory Table -- not needed]
922
     .idata$4:  Import Lookup Table
923
     .idata$5:  Import Address Table
924
925
     Note we do not create a .idata$3 section as this is
926
     created for us by the linker script.  */
927
3.70k
  id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
928
3.70k
  id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
929
3.70k
  if (id4 == NULL || id5 == NULL)
930
0
    goto error_return;
931
932
  /* Fill in the contents of these sections.  */
933
3.70k
  if (import_name_type == IMPORT_ORDINAL)
934
1.29k
    {
935
1.29k
      if (ordinal == 0)
936
  /* See PR 20907 for a reproducer.  */
937
15
  goto error_return;
938
939
1.28k
#if defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) || defined(COFF_WITH_peLoongArch64)
940
1.28k
      ((unsigned int *) id4->contents)[0] = ordinal;
941
1.28k
      ((unsigned int *) id4->contents)[1] = 0x80000000;
942
1.28k
      ((unsigned int *) id5->contents)[0] = ordinal;
943
1.28k
      ((unsigned int *) id5->contents)[1] = 0x80000000;
944
#else
945
      * (unsigned int *) id4->contents = ordinal | 0x80000000;
946
      * (unsigned int *) id5->contents = ordinal | 0x80000000;
947
#endif
948
1.28k
    }
949
2.40k
  else
950
2.40k
    {
951
2.40k
      char * symbol;
952
2.40k
      unsigned int len;
953
954
      /* Create .idata$6 - the Hint Name Table.  */
955
2.40k
      id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
956
2.40k
      if (id6 == NULL)
957
0
  goto error_return;
958
959
      /* If necessary, trim the import symbol name.  */
960
2.40k
      symbol = symbol_name;
961
962
      /* As used by MS compiler, '_', '@', and '?' are alternative
963
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
964
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
965
   of these is used for a symbol.  We strip this leading char for
966
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
967
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
968
969
2.40k
      if (import_name_type != IMPORT_NAME)
970
1.92k
  {
971
1.92k
    char c = symbol[0];
972
973
    /* Check that we don't remove for targets with empty
974
       USER_LABEL_PREFIX the leading underscore.  */
975
1.92k
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
976
1.92k
        || c == '@' || c == '?')
977
405
      symbol++;
978
1.92k
  }
979
980
2.40k
      len = strlen (symbol);
981
2.40k
      if (import_name_type == IMPORT_NAME_UNDECORATE)
982
1.92k
  {
983
    /* Truncate at the first '@'.  */
984
1.92k
    char *at = strchr (symbol, '@');
985
986
1.92k
    if (at != NULL)
987
571
      len = at - symbol;
988
1.92k
  }
989
990
2.40k
      id6->contents[0] = ordinal & 0xff;
991
2.40k
      id6->contents[1] = ordinal >> 8;
992
993
2.40k
      memcpy ((char *) id6->contents + 2, symbol, len);
994
2.40k
      id6->contents[len + 2] = '\0';
995
2.40k
    }
996
997
3.68k
  if (import_name_type != IMPORT_ORDINAL)
998
2.40k
    {
999
2.40k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1000
2.40k
      pe_ILF_save_relocs (&vars, id4);
1001
1002
2.40k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1003
2.40k
      pe_ILF_save_relocs (&vars, id5);
1004
2.40k
    }
1005
1006
  /* Create an import symbol.  */
1007
3.68k
  pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
1008
3.68k
  imp_sym   = vars.sym_ptr_ptr - 1;
1009
3.68k
  imp_index = vars.sym_index - 1;
1010
1011
  /* Create extra sections depending upon the type of import we are dealing with.  */
1012
3.68k
  switch (import_type)
1013
3.68k
    {
1014
0
      int i;
1015
1016
1.96k
    case IMPORT_CODE:
1017
      /* CODE functions are special, in that they get a trampoline that
1018
   jumps to the main import symbol.  Create a .text section to hold it.
1019
   First we need to look up its contents in the jump table.  */
1020
3.93k
      for (i = NUM_ENTRIES (jtab); i--;)
1021
3.93k
  {
1022
3.93k
    if (jtab[i].size == 0)
1023
1.96k
      continue;
1024
1.96k
    if (jtab[i].magic == magic)
1025
1.96k
      break;
1026
1.96k
  }
1027
      /* If we did not find a matching entry something is wrong.  */
1028
1.96k
      if (i < 0)
1029
0
  abort ();
1030
1031
      /* Create the .text section.  */
1032
1.96k
      text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
1033
1.96k
      if (text == NULL)
1034
0
  goto error_return;
1035
1036
      /* Copy in the jump code.  */
1037
1.96k
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1038
1039
      /* Create a reloc for the data in the text section.  */
1040
#ifdef MIPS_ARCH_MAGIC_WINCE
1041
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1042
  {
1043
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1044
              (struct bfd_symbol **) imp_sym,
1045
              imp_index);
1046
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1047
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1048
              (struct bfd_symbol **) imp_sym,
1049
              imp_index);
1050
  }
1051
      else
1052
#endif
1053
#ifdef AMD64MAGIC
1054
      if (magic == AMD64MAGIC)
1055
  {
1056
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1057
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1058
              imp_index);
1059
  }
1060
      else
1061
#endif
1062
1.96k
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1063
1.96k
            BFD_RELOC_32, (asymbol **) imp_sym,
1064
1.96k
            imp_index);
1065
1066
1.96k
      pe_ILF_save_relocs (& vars, text);
1067
1.96k
      break;
1068
1069
1.71k
    case IMPORT_DATA:
1070
1.71k
      break;
1071
1072
0
    default:
1073
      /* XXX code not yet written.  */
1074
0
      abort ();
1075
3.68k
    }
1076
1077
  /* Now create a symbol describing the imported value.  */
1078
3.68k
  switch (import_type)
1079
3.68k
    {
1080
1.96k
    case IMPORT_CODE:
1081
1.96k
      pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1082
1.96k
          BSF_NOT_AT_END | BSF_FUNCTION);
1083
1084
1.96k
      break;
1085
1086
1.71k
    case IMPORT_DATA:
1087
      /* Nothing to do here.  */
1088
1.71k
      break;
1089
1090
0
    default:
1091
      /* XXX code not yet written.  */
1092
0
      abort ();
1093
3.68k
    }
1094
1095
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1096
3.68k
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1097
3.68k
  if (ptr)
1098
737
    * ptr = 0;
1099
3.68k
  pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1100
3.68k
  if (ptr)
1101
737
    * ptr = '.';
1102
1103
  /* Initialise the bfd.  */
1104
3.68k
  memset (& internal_f, 0, sizeof (internal_f));
1105
1106
3.68k
  internal_f.f_magic  = magic;
1107
3.68k
  internal_f.f_symptr = 0;
1108
3.68k
  internal_f.f_nsyms  = 0;
1109
3.68k
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1110
1111
3.68k
  if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
1112
3.68k
      || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1113
0
    goto error_return;
1114
1115
3.68k
  if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL)
1116
0
    goto error_return;
1117
1118
3.68k
  obj_pe (abfd) = true;
1119
#ifdef THUMBPEMAGIC
1120
  if (vars.magic == THUMBPEMAGIC)
1121
    /* Stop some linker warnings about thumb code not supporting interworking.  */
1122
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1123
#endif
1124
1125
  /* Switch from file contents to memory contents.  */
1126
3.68k
  bfd_cache_close (abfd);
1127
1128
3.68k
  abfd->iostream = (void *) vars.bim;
1129
3.68k
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1130
3.68k
  abfd->iovec = &_bfd_memory_iovec;
1131
3.68k
  abfd->where = 0;
1132
3.68k
  abfd->origin = 0;
1133
3.68k
  abfd->size = 0;
1134
3.68k
  obj_sym_filepos (abfd) = 0;
1135
1136
  /* Point the bfd at the symbol table.  */
1137
3.68k
  obj_symbols (abfd) = vars.sym_cache;
1138
3.68k
  abfd->symcount = vars.sym_index;
1139
1140
3.68k
  obj_raw_syments (abfd) = vars.native_syms;
1141
3.68k
  obj_raw_syment_count (abfd) = vars.sym_index;
1142
1143
3.68k
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1144
3.68k
  obj_coff_keep_syms (abfd) = true;
1145
1146
3.68k
  obj_convert (abfd) = vars.sym_table;
1147
3.68k
  obj_conv_table_size (abfd) = vars.sym_index;
1148
1149
3.68k
  obj_coff_strings (abfd) = vars.string_table;
1150
3.68k
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1151
3.68k
  obj_coff_keep_strings (abfd) = true;
1152
1153
3.68k
  return true;
1154
1155
15
 error_return:
1156
15
  free (vars.bim->buffer);
1157
15
  free (vars.bim);
1158
15
  return false;
1159
3.68k
}
pei-arm-wince.c:pe_ILF_build_a_bfd
Line
Count
Source
798
1.48k
{
799
1.48k
  bfd_byte *       ptr;
800
1.48k
  pe_ILF_vars      vars;
801
1.48k
  struct internal_filehdr  internal_f;
802
1.48k
  unsigned int       import_type;
803
1.48k
  unsigned int       import_name_type;
804
1.48k
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
805
1.48k
  coff_symbol_type **    imp_sym;
806
1.48k
  unsigned int       imp_index;
807
1.48k
  intptr_t alignment;
808
809
  /* Decode and verify the types field of the ILF structure.  */
810
1.48k
  import_type = types & 0x3;
811
1.48k
  import_name_type = (types & 0x1c) >> 2;
812
813
1.48k
  switch (import_type)
814
1.48k
    {
815
394
    case IMPORT_CODE:
816
645
    case IMPORT_DATA:
817
645
      break;
818
819
626
    case IMPORT_CONST:
820
      /* XXX code yet to be written.  */
821
      /* xgettext:c-format */
822
626
      _bfd_error_handler (_("%pB: unhandled import type; %x"),
823
626
        abfd, import_type);
824
626
      return false;
825
826
213
    default:
827
      /* xgettext:c-format */
828
213
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
213
        abfd, import_type);
830
213
      return false;
831
1.48k
    }
832
833
645
  switch (import_name_type)
834
645
    {
835
356
    case IMPORT_ORDINAL:
836
368
    case IMPORT_NAME:
837
392
    case IMPORT_NAME_NOPREFIX:
838
426
    case IMPORT_NAME_UNDECORATE:
839
426
      break;
840
841
219
    default:
842
      /* xgettext:c-format */
843
219
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
844
219
        abfd, import_name_type);
845
219
      return false;
846
645
    }
847
848
  /* Initialise local variables.
849
850
     Note these are kept in a structure rather than being
851
     declared as statics since bfd frowns on global variables.
852
853
     We are going to construct the contents of the BFD in memory,
854
     so allocate all the space that we will need right now.  */
855
426
  vars.bim
856
426
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
857
426
  if (vars.bim == NULL)
858
0
    return false;
859
860
426
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
861
426
  vars.bim->buffer = ptr;
862
426
  vars.bim->size   = ILF_DATA_SIZE;
863
426
  if (ptr == NULL)
864
0
    goto error_return;
865
866
  /* Initialise the pointers to regions of the memory and the
867
     other contents of the pe_ILF_vars structure as well.  */
868
426
  vars.sym_cache = (coff_symbol_type *) ptr;
869
426
  vars.sym_ptr   = (coff_symbol_type *) ptr;
870
426
  vars.sym_index = 0;
871
426
  ptr += SIZEOF_ILF_SYMS;
872
873
426
  vars.sym_table = (unsigned int *) ptr;
874
426
  vars.table_ptr = (unsigned int *) ptr;
875
426
  ptr += SIZEOF_ILF_SYM_TABLE;
876
877
426
  vars.native_syms = (combined_entry_type *) ptr;
878
426
  vars.native_ptr  = (combined_entry_type *) ptr;
879
426
  ptr += SIZEOF_ILF_NATIVE_SYMS;
880
881
426
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
882
426
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
883
426
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
884
885
426
  vars.esym_table = (SYMENT *) ptr;
886
426
  vars.esym_ptr   = (SYMENT *) ptr;
887
426
  ptr += SIZEOF_ILF_EXT_SYMS;
888
889
426
  vars.reltab   = (arelent *) ptr;
890
426
  vars.relcount = 0;
891
426
  ptr += SIZEOF_ILF_RELOCS;
892
893
426
  vars.int_reltab  = (struct internal_reloc *) ptr;
894
426
  ptr += SIZEOF_ILF_INT_RELOCS;
895
896
426
  vars.string_table = (char *) ptr;
897
426
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
898
426
  ptr += SIZEOF_ILF_STRINGS;
899
426
  vars.end_string_ptr = (char *) ptr;
900
901
  /* The remaining space in bim->buffer is used
902
     by the pe_ILF_make_a_section() function.  */
903
904
  /* PR 18758: Make sure that the data area is sufficiently aligned for
905
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
906
     the test of GCC_VERSION.  For other compilers we assume 8 byte
907
     alignment.  */
908
426
#if GCC_VERSION >= 3000
909
426
  alignment = __alignof__ (struct coff_section_tdata);
910
#else
911
  alignment = 8;
912
#endif
913
426
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
914
915
426
  vars.data = ptr;
916
426
  vars.abfd = abfd;
917
426
  vars.sec_index = 0;
918
426
  vars.magic = magic;
919
920
  /* Create the initial .idata$<n> sections:
921
     [.idata$2:  Import Directory Table -- not needed]
922
     .idata$4:  Import Lookup Table
923
     .idata$5:  Import Address Table
924
925
     Note we do not create a .idata$3 section as this is
926
     created for us by the linker script.  */
927
426
  id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
928
426
  id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
929
426
  if (id4 == NULL || id5 == NULL)
930
0
    goto error_return;
931
932
  /* Fill in the contents of these sections.  */
933
426
  if (import_name_type == IMPORT_ORDINAL)
934
356
    {
935
356
      if (ordinal == 0)
936
  /* See PR 20907 for a reproducer.  */
937
323
  goto error_return;
938
939
#if defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) || defined(COFF_WITH_peLoongArch64)
940
      ((unsigned int *) id4->contents)[0] = ordinal;
941
      ((unsigned int *) id4->contents)[1] = 0x80000000;
942
      ((unsigned int *) id5->contents)[0] = ordinal;
943
      ((unsigned int *) id5->contents)[1] = 0x80000000;
944
#else
945
33
      * (unsigned int *) id4->contents = ordinal | 0x80000000;
946
33
      * (unsigned int *) id5->contents = ordinal | 0x80000000;
947
33
#endif
948
33
    }
949
70
  else
950
70
    {
951
70
      char * symbol;
952
70
      unsigned int len;
953
954
      /* Create .idata$6 - the Hint Name Table.  */
955
70
      id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
956
70
      if (id6 == NULL)
957
0
  goto error_return;
958
959
      /* If necessary, trim the import symbol name.  */
960
70
      symbol = symbol_name;
961
962
      /* As used by MS compiler, '_', '@', and '?' are alternative
963
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
964
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
965
   of these is used for a symbol.  We strip this leading char for
966
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
967
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
968
969
70
      if (import_name_type != IMPORT_NAME)
970
58
  {
971
58
    char c = symbol[0];
972
973
    /* Check that we don't remove for targets with empty
974
       USER_LABEL_PREFIX the leading underscore.  */
975
58
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
976
58
        || c == '@' || c == '?')
977
8
      symbol++;
978
58
  }
979
980
70
      len = strlen (symbol);
981
70
      if (import_name_type == IMPORT_NAME_UNDECORATE)
982
34
  {
983
    /* Truncate at the first '@'.  */
984
34
    char *at = strchr (symbol, '@');
985
986
34
    if (at != NULL)
987
10
      len = at - symbol;
988
34
  }
989
990
70
      id6->contents[0] = ordinal & 0xff;
991
70
      id6->contents[1] = ordinal >> 8;
992
993
70
      memcpy ((char *) id6->contents + 2, symbol, len);
994
70
      id6->contents[len + 2] = '\0';
995
70
    }
996
997
103
  if (import_name_type != IMPORT_ORDINAL)
998
70
    {
999
70
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1000
70
      pe_ILF_save_relocs (&vars, id4);
1001
1002
70
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1003
70
      pe_ILF_save_relocs (&vars, id5);
1004
70
    }
1005
1006
  /* Create an import symbol.  */
1007
103
  pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
1008
103
  imp_sym   = vars.sym_ptr_ptr - 1;
1009
103
  imp_index = vars.sym_index - 1;
1010
1011
  /* Create extra sections depending upon the type of import we are dealing with.  */
1012
103
  switch (import_type)
1013
103
    {
1014
0
      int i;
1015
1016
64
    case IMPORT_CODE:
1017
      /* CODE functions are special, in that they get a trampoline that
1018
   jumps to the main import symbol.  Create a .text section to hold it.
1019
   First we need to look up its contents in the jump table.  */
1020
168
      for (i = NUM_ENTRIES (jtab); i--;)
1021
168
  {
1022
168
    if (jtab[i].size == 0)
1023
64
      continue;
1024
104
    if (jtab[i].magic == magic)
1025
64
      break;
1026
104
  }
1027
      /* If we did not find a matching entry something is wrong.  */
1028
64
      if (i < 0)
1029
0
  abort ();
1030
1031
      /* Create the .text section.  */
1032
64
      text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
1033
64
      if (text == NULL)
1034
0
  goto error_return;
1035
1036
      /* Copy in the jump code.  */
1037
64
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1038
1039
      /* Create a reloc for the data in the text section.  */
1040
#ifdef MIPS_ARCH_MAGIC_WINCE
1041
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1042
  {
1043
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1044
              (struct bfd_symbol **) imp_sym,
1045
              imp_index);
1046
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1047
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1048
              (struct bfd_symbol **) imp_sym,
1049
              imp_index);
1050
  }
1051
      else
1052
#endif
1053
#ifdef AMD64MAGIC
1054
      if (magic == AMD64MAGIC)
1055
  {
1056
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1057
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1058
              imp_index);
1059
  }
1060
      else
1061
#endif
1062
64
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1063
64
            BFD_RELOC_32, (asymbol **) imp_sym,
1064
64
            imp_index);
1065
1066
64
      pe_ILF_save_relocs (& vars, text);
1067
64
      break;
1068
1069
39
    case IMPORT_DATA:
1070
39
      break;
1071
1072
0
    default:
1073
      /* XXX code not yet written.  */
1074
0
      abort ();
1075
103
    }
1076
1077
  /* Now create a symbol describing the imported value.  */
1078
103
  switch (import_type)
1079
103
    {
1080
64
    case IMPORT_CODE:
1081
64
      pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1082
64
          BSF_NOT_AT_END | BSF_FUNCTION);
1083
1084
64
      break;
1085
1086
39
    case IMPORT_DATA:
1087
      /* Nothing to do here.  */
1088
39
      break;
1089
1090
0
    default:
1091
      /* XXX code not yet written.  */
1092
0
      abort ();
1093
103
    }
1094
1095
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1096
103
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1097
103
  if (ptr)
1098
12
    * ptr = 0;
1099
103
  pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1100
103
  if (ptr)
1101
12
    * ptr = '.';
1102
1103
  /* Initialise the bfd.  */
1104
103
  memset (& internal_f, 0, sizeof (internal_f));
1105
1106
103
  internal_f.f_magic  = magic;
1107
103
  internal_f.f_symptr = 0;
1108
103
  internal_f.f_nsyms  = 0;
1109
103
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1110
1111
103
  if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
1112
103
      || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1113
0
    goto error_return;
1114
1115
103
  if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL)
1116
0
    goto error_return;
1117
1118
103
  obj_pe (abfd) = true;
1119
103
#ifdef THUMBPEMAGIC
1120
103
  if (vars.magic == THUMBPEMAGIC)
1121
    /* Stop some linker warnings about thumb code not supporting interworking.  */
1122
47
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1123
103
#endif
1124
1125
  /* Switch from file contents to memory contents.  */
1126
103
  bfd_cache_close (abfd);
1127
1128
103
  abfd->iostream = (void *) vars.bim;
1129
103
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1130
103
  abfd->iovec = &_bfd_memory_iovec;
1131
103
  abfd->where = 0;
1132
103
  abfd->origin = 0;
1133
103
  abfd->size = 0;
1134
103
  obj_sym_filepos (abfd) = 0;
1135
1136
  /* Point the bfd at the symbol table.  */
1137
103
  obj_symbols (abfd) = vars.sym_cache;
1138
103
  abfd->symcount = vars.sym_index;
1139
1140
103
  obj_raw_syments (abfd) = vars.native_syms;
1141
103
  obj_raw_syment_count (abfd) = vars.sym_index;
1142
1143
103
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1144
103
  obj_coff_keep_syms (abfd) = true;
1145
1146
103
  obj_convert (abfd) = vars.sym_table;
1147
103
  obj_conv_table_size (abfd) = vars.sym_index;
1148
1149
103
  obj_coff_strings (abfd) = vars.string_table;
1150
103
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1151
103
  obj_coff_keep_strings (abfd) = true;
1152
1153
103
  return true;
1154
1155
323
 error_return:
1156
323
  free (vars.bim->buffer);
1157
323
  free (vars.bim);
1158
323
  return false;
1159
103
}
pei-arm.c:pe_ILF_build_a_bfd
Line
Count
Source
798
6.65k
{
799
6.65k
  bfd_byte *       ptr;
800
6.65k
  pe_ILF_vars      vars;
801
6.65k
  struct internal_filehdr  internal_f;
802
6.65k
  unsigned int       import_type;
803
6.65k
  unsigned int       import_name_type;
804
6.65k
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
805
6.65k
  coff_symbol_type **    imp_sym;
806
6.65k
  unsigned int       imp_index;
807
6.65k
  intptr_t alignment;
808
809
  /* Decode and verify the types field of the ILF structure.  */
810
6.65k
  import_type = types & 0x3;
811
6.65k
  import_name_type = (types & 0x1c) >> 2;
812
813
6.65k
  switch (import_type)
814
6.65k
    {
815
3.26k
    case IMPORT_CODE:
816
5.82k
    case IMPORT_DATA:
817
5.82k
      break;
818
819
626
    case IMPORT_CONST:
820
      /* XXX code yet to be written.  */
821
      /* xgettext:c-format */
822
626
      _bfd_error_handler (_("%pB: unhandled import type; %x"),
823
626
        abfd, import_type);
824
626
      return false;
825
826
213
    default:
827
      /* xgettext:c-format */
828
213
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
213
        abfd, import_type);
830
213
      return false;
831
6.65k
    }
832
833
5.82k
  switch (import_name_type)
834
5.82k
    {
835
1.73k
    case IMPORT_ORDINAL:
836
2.77k
    case IMPORT_NAME:
837
4.16k
    case IMPORT_NAME_NOPREFIX:
838
5.60k
    case IMPORT_NAME_UNDECORATE:
839
5.60k
      break;
840
841
219
    default:
842
      /* xgettext:c-format */
843
219
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
844
219
        abfd, import_name_type);
845
219
      return false;
846
5.82k
    }
847
848
  /* Initialise local variables.
849
850
     Note these are kept in a structure rather than being
851
     declared as statics since bfd frowns on global variables.
852
853
     We are going to construct the contents of the BFD in memory,
854
     so allocate all the space that we will need right now.  */
855
5.60k
  vars.bim
856
5.60k
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
857
5.60k
  if (vars.bim == NULL)
858
0
    return false;
859
860
5.60k
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
861
5.60k
  vars.bim->buffer = ptr;
862
5.60k
  vars.bim->size   = ILF_DATA_SIZE;
863
5.60k
  if (ptr == NULL)
864
0
    goto error_return;
865
866
  /* Initialise the pointers to regions of the memory and the
867
     other contents of the pe_ILF_vars structure as well.  */
868
5.60k
  vars.sym_cache = (coff_symbol_type *) ptr;
869
5.60k
  vars.sym_ptr   = (coff_symbol_type *) ptr;
870
5.60k
  vars.sym_index = 0;
871
5.60k
  ptr += SIZEOF_ILF_SYMS;
872
873
5.60k
  vars.sym_table = (unsigned int *) ptr;
874
5.60k
  vars.table_ptr = (unsigned int *) ptr;
875
5.60k
  ptr += SIZEOF_ILF_SYM_TABLE;
876
877
5.60k
  vars.native_syms = (combined_entry_type *) ptr;
878
5.60k
  vars.native_ptr  = (combined_entry_type *) ptr;
879
5.60k
  ptr += SIZEOF_ILF_NATIVE_SYMS;
880
881
5.60k
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
882
5.60k
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
883
5.60k
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
884
885
5.60k
  vars.esym_table = (SYMENT *) ptr;
886
5.60k
  vars.esym_ptr   = (SYMENT *) ptr;
887
5.60k
  ptr += SIZEOF_ILF_EXT_SYMS;
888
889
5.60k
  vars.reltab   = (arelent *) ptr;
890
5.60k
  vars.relcount = 0;
891
5.60k
  ptr += SIZEOF_ILF_RELOCS;
892
893
5.60k
  vars.int_reltab  = (struct internal_reloc *) ptr;
894
5.60k
  ptr += SIZEOF_ILF_INT_RELOCS;
895
896
5.60k
  vars.string_table = (char *) ptr;
897
5.60k
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
898
5.60k
  ptr += SIZEOF_ILF_STRINGS;
899
5.60k
  vars.end_string_ptr = (char *) ptr;
900
901
  /* The remaining space in bim->buffer is used
902
     by the pe_ILF_make_a_section() function.  */
903
904
  /* PR 18758: Make sure that the data area is sufficiently aligned for
905
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
906
     the test of GCC_VERSION.  For other compilers we assume 8 byte
907
     alignment.  */
908
5.60k
#if GCC_VERSION >= 3000
909
5.60k
  alignment = __alignof__ (struct coff_section_tdata);
910
#else
911
  alignment = 8;
912
#endif
913
5.60k
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
914
915
5.60k
  vars.data = ptr;
916
5.60k
  vars.abfd = abfd;
917
5.60k
  vars.sec_index = 0;
918
5.60k
  vars.magic = magic;
919
920
  /* Create the initial .idata$<n> sections:
921
     [.idata$2:  Import Directory Table -- not needed]
922
     .idata$4:  Import Lookup Table
923
     .idata$5:  Import Address Table
924
925
     Note we do not create a .idata$3 section as this is
926
     created for us by the linker script.  */
927
5.60k
  id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
928
5.60k
  id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
929
5.60k
  if (id4 == NULL || id5 == NULL)
930
0
    goto error_return;
931
932
  /* Fill in the contents of these sections.  */
933
5.60k
  if (import_name_type == IMPORT_ORDINAL)
934
1.73k
    {
935
1.73k
      if (ordinal == 0)
936
  /* See PR 20907 for a reproducer.  */
937
323
  goto error_return;
938
939
#if defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) || defined(COFF_WITH_peLoongArch64)
940
      ((unsigned int *) id4->contents)[0] = ordinal;
941
      ((unsigned int *) id4->contents)[1] = 0x80000000;
942
      ((unsigned int *) id5->contents)[0] = ordinal;
943
      ((unsigned int *) id5->contents)[1] = 0x80000000;
944
#else
945
1.40k
      * (unsigned int *) id4->contents = ordinal | 0x80000000;
946
1.40k
      * (unsigned int *) id5->contents = ordinal | 0x80000000;
947
1.40k
#endif
948
1.40k
    }
949
3.87k
  else
950
3.87k
    {
951
3.87k
      char * symbol;
952
3.87k
      unsigned int len;
953
954
      /* Create .idata$6 - the Hint Name Table.  */
955
3.87k
      id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
956
3.87k
      if (id6 == NULL)
957
0
  goto error_return;
958
959
      /* If necessary, trim the import symbol name.  */
960
3.87k
      symbol = symbol_name;
961
962
      /* As used by MS compiler, '_', '@', and '?' are alternative
963
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
964
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
965
   of these is used for a symbol.  We strip this leading char for
966
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
967
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
968
969
3.87k
      if (import_name_type != IMPORT_NAME)
970
2.82k
  {
971
2.82k
    char c = symbol[0];
972
973
    /* Check that we don't remove for targets with empty
974
       USER_LABEL_PREFIX the leading underscore.  */
975
2.82k
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
976
2.82k
        || c == '@' || c == '?')
977
710
      symbol++;
978
2.82k
  }
979
980
3.87k
      len = strlen (symbol);
981
3.87k
      if (import_name_type == IMPORT_NAME_UNDECORATE)
982
1.43k
  {
983
    /* Truncate at the first '@'.  */
984
1.43k
    char *at = strchr (symbol, '@');
985
986
1.43k
    if (at != NULL)
987
10
      len = at - symbol;
988
1.43k
  }
989
990
3.87k
      id6->contents[0] = ordinal & 0xff;
991
3.87k
      id6->contents[1] = ordinal >> 8;
992
993
3.87k
      memcpy ((char *) id6->contents + 2, symbol, len);
994
3.87k
      id6->contents[len + 2] = '\0';
995
3.87k
    }
996
997
5.27k
  if (import_name_type != IMPORT_ORDINAL)
998
3.87k
    {
999
3.87k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1000
3.87k
      pe_ILF_save_relocs (&vars, id4);
1001
1002
3.87k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1003
3.87k
      pe_ILF_save_relocs (&vars, id5);
1004
3.87k
    }
1005
1006
  /* Create an import symbol.  */
1007
5.27k
  pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
1008
5.27k
  imp_sym   = vars.sym_ptr_ptr - 1;
1009
5.27k
  imp_index = vars.sym_index - 1;
1010
1011
  /* Create extra sections depending upon the type of import we are dealing with.  */
1012
5.27k
  switch (import_type)
1013
5.27k
    {
1014
0
      int i;
1015
1016
2.93k
    case IMPORT_CODE:
1017
      /* CODE functions are special, in that they get a trampoline that
1018
   jumps to the main import symbol.  Create a .text section to hold it.
1019
   First we need to look up its contents in the jump table.  */
1020
8.54k
      for (i = NUM_ENTRIES (jtab); i--;)
1021
8.54k
  {
1022
8.54k
    if (jtab[i].size == 0)
1023
2.93k
      continue;
1024
5.60k
    if (jtab[i].magic == magic)
1025
2.93k
      break;
1026
5.60k
  }
1027
      /* If we did not find a matching entry something is wrong.  */
1028
2.93k
      if (i < 0)
1029
0
  abort ();
1030
1031
      /* Create the .text section.  */
1032
2.93k
      text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
1033
2.93k
      if (text == NULL)
1034
0
  goto error_return;
1035
1036
      /* Copy in the jump code.  */
1037
2.93k
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1038
1039
      /* Create a reloc for the data in the text section.  */
1040
#ifdef MIPS_ARCH_MAGIC_WINCE
1041
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1042
  {
1043
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1044
              (struct bfd_symbol **) imp_sym,
1045
              imp_index);
1046
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1047
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1048
              (struct bfd_symbol **) imp_sym,
1049
              imp_index);
1050
  }
1051
      else
1052
#endif
1053
#ifdef AMD64MAGIC
1054
      if (magic == AMD64MAGIC)
1055
  {
1056
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1057
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1058
              imp_index);
1059
  }
1060
      else
1061
#endif
1062
2.93k
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1063
2.93k
            BFD_RELOC_32, (asymbol **) imp_sym,
1064
2.93k
            imp_index);
1065
1066
2.93k
      pe_ILF_save_relocs (& vars, text);
1067
2.93k
      break;
1068
1069
2.34k
    case IMPORT_DATA:
1070
2.34k
      break;
1071
1072
0
    default:
1073
      /* XXX code not yet written.  */
1074
0
      abort ();
1075
5.27k
    }
1076
1077
  /* Now create a symbol describing the imported value.  */
1078
5.27k
  switch (import_type)
1079
5.27k
    {
1080
2.93k
    case IMPORT_CODE:
1081
2.93k
      pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1082
2.93k
          BSF_NOT_AT_END | BSF_FUNCTION);
1083
1084
2.93k
      break;
1085
1086
2.34k
    case IMPORT_DATA:
1087
      /* Nothing to do here.  */
1088
2.34k
      break;
1089
1090
0
    default:
1091
      /* XXX code not yet written.  */
1092
0
      abort ();
1093
5.27k
    }
1094
1095
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1096
5.27k
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1097
5.27k
  if (ptr)
1098
1.40k
    * ptr = 0;
1099
5.27k
  pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1100
5.27k
  if (ptr)
1101
1.40k
    * ptr = '.';
1102
1103
  /* Initialise the bfd.  */
1104
5.27k
  memset (& internal_f, 0, sizeof (internal_f));
1105
1106
5.27k
  internal_f.f_magic  = magic;
1107
5.27k
  internal_f.f_symptr = 0;
1108
5.27k
  internal_f.f_nsyms  = 0;
1109
5.27k
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1110
1111
5.27k
  if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
1112
5.27k
      || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1113
0
    goto error_return;
1114
1115
5.27k
  if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL)
1116
0
    goto error_return;
1117
1118
5.27k
  obj_pe (abfd) = true;
1119
5.27k
#ifdef THUMBPEMAGIC
1120
5.27k
  if (vars.magic == THUMBPEMAGIC)
1121
    /* Stop some linker warnings about thumb code not supporting interworking.  */
1122
1.24k
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1123
5.27k
#endif
1124
1125
  /* Switch from file contents to memory contents.  */
1126
5.27k
  bfd_cache_close (abfd);
1127
1128
5.27k
  abfd->iostream = (void *) vars.bim;
1129
5.27k
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1130
5.27k
  abfd->iovec = &_bfd_memory_iovec;
1131
5.27k
  abfd->where = 0;
1132
5.27k
  abfd->origin = 0;
1133
5.27k
  abfd->size = 0;
1134
5.27k
  obj_sym_filepos (abfd) = 0;
1135
1136
  /* Point the bfd at the symbol table.  */
1137
5.27k
  obj_symbols (abfd) = vars.sym_cache;
1138
5.27k
  abfd->symcount = vars.sym_index;
1139
1140
5.27k
  obj_raw_syments (abfd) = vars.native_syms;
1141
5.27k
  obj_raw_syment_count (abfd) = vars.sym_index;
1142
1143
5.27k
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1144
5.27k
  obj_coff_keep_syms (abfd) = true;
1145
1146
5.27k
  obj_convert (abfd) = vars.sym_table;
1147
5.27k
  obj_conv_table_size (abfd) = vars.sym_index;
1148
1149
5.27k
  obj_coff_strings (abfd) = vars.string_table;
1150
5.27k
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1151
5.27k
  obj_coff_keep_strings (abfd) = true;
1152
1153
5.27k
  return true;
1154
1155
323
 error_return:
1156
323
  free (vars.bim->buffer);
1157
323
  free (vars.bim);
1158
323
  return false;
1159
5.27k
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_build_a_bfd
pei-sh.c:pe_ILF_build_a_bfd
Line
Count
Source
798
3.49k
{
799
3.49k
  bfd_byte *       ptr;
800
3.49k
  pe_ILF_vars      vars;
801
3.49k
  struct internal_filehdr  internal_f;
802
3.49k
  unsigned int       import_type;
803
3.49k
  unsigned int       import_name_type;
804
3.49k
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
805
3.49k
  coff_symbol_type **    imp_sym;
806
3.49k
  unsigned int       imp_index;
807
3.49k
  intptr_t alignment;
808
809
  /* Decode and verify the types field of the ILF structure.  */
810
3.49k
  import_type = types & 0x3;
811
3.49k
  import_name_type = (types & 0x1c) >> 2;
812
813
3.49k
  switch (import_type)
814
3.49k
    {
815
2.36k
    case IMPORT_CODE:
816
3.36k
    case IMPORT_DATA:
817
3.36k
      break;
818
819
117
    case IMPORT_CONST:
820
      /* XXX code yet to be written.  */
821
      /* xgettext:c-format */
822
117
      _bfd_error_handler (_("%pB: unhandled import type; %x"),
823
117
        abfd, import_type);
824
117
      return false;
825
826
15
    default:
827
      /* xgettext:c-format */
828
15
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
15
        abfd, import_type);
830
15
      return false;
831
3.49k
    }
832
833
3.36k
  switch (import_name_type)
834
3.36k
    {
835
1.20k
    case IMPORT_ORDINAL:
836
1.91k
    case IMPORT_NAME:
837
2.41k
    case IMPORT_NAME_NOPREFIX:
838
3.14k
    case IMPORT_NAME_UNDECORATE:
839
3.14k
      break;
840
841
218
    default:
842
      /* xgettext:c-format */
843
218
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
844
218
        abfd, import_name_type);
845
218
      return false;
846
3.36k
    }
847
848
  /* Initialise local variables.
849
850
     Note these are kept in a structure rather than being
851
     declared as statics since bfd frowns on global variables.
852
853
     We are going to construct the contents of the BFD in memory,
854
     so allocate all the space that we will need right now.  */
855
3.14k
  vars.bim
856
3.14k
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
857
3.14k
  if (vars.bim == NULL)
858
0
    return false;
859
860
3.14k
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
861
3.14k
  vars.bim->buffer = ptr;
862
3.14k
  vars.bim->size   = ILF_DATA_SIZE;
863
3.14k
  if (ptr == NULL)
864
0
    goto error_return;
865
866
  /* Initialise the pointers to regions of the memory and the
867
     other contents of the pe_ILF_vars structure as well.  */
868
3.14k
  vars.sym_cache = (coff_symbol_type *) ptr;
869
3.14k
  vars.sym_ptr   = (coff_symbol_type *) ptr;
870
3.14k
  vars.sym_index = 0;
871
3.14k
  ptr += SIZEOF_ILF_SYMS;
872
873
3.14k
  vars.sym_table = (unsigned int *) ptr;
874
3.14k
  vars.table_ptr = (unsigned int *) ptr;
875
3.14k
  ptr += SIZEOF_ILF_SYM_TABLE;
876
877
3.14k
  vars.native_syms = (combined_entry_type *) ptr;
878
3.14k
  vars.native_ptr  = (combined_entry_type *) ptr;
879
3.14k
  ptr += SIZEOF_ILF_NATIVE_SYMS;
880
881
3.14k
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
882
3.14k
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
883
3.14k
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
884
885
3.14k
  vars.esym_table = (SYMENT *) ptr;
886
3.14k
  vars.esym_ptr   = (SYMENT *) ptr;
887
3.14k
  ptr += SIZEOF_ILF_EXT_SYMS;
888
889
3.14k
  vars.reltab   = (arelent *) ptr;
890
3.14k
  vars.relcount = 0;
891
3.14k
  ptr += SIZEOF_ILF_RELOCS;
892
893
3.14k
  vars.int_reltab  = (struct internal_reloc *) ptr;
894
3.14k
  ptr += SIZEOF_ILF_INT_RELOCS;
895
896
3.14k
  vars.string_table = (char *) ptr;
897
3.14k
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
898
3.14k
  ptr += SIZEOF_ILF_STRINGS;
899
3.14k
  vars.end_string_ptr = (char *) ptr;
900
901
  /* The remaining space in bim->buffer is used
902
     by the pe_ILF_make_a_section() function.  */
903
904
  /* PR 18758: Make sure that the data area is sufficiently aligned for
905
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
906
     the test of GCC_VERSION.  For other compilers we assume 8 byte
907
     alignment.  */
908
3.14k
#if GCC_VERSION >= 3000
909
3.14k
  alignment = __alignof__ (struct coff_section_tdata);
910
#else
911
  alignment = 8;
912
#endif
913
3.14k
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
914
915
3.14k
  vars.data = ptr;
916
3.14k
  vars.abfd = abfd;
917
3.14k
  vars.sec_index = 0;
918
3.14k
  vars.magic = magic;
919
920
  /* Create the initial .idata$<n> sections:
921
     [.idata$2:  Import Directory Table -- not needed]
922
     .idata$4:  Import Lookup Table
923
     .idata$5:  Import Address Table
924
925
     Note we do not create a .idata$3 section as this is
926
     created for us by the linker script.  */
927
3.14k
  id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
928
3.14k
  id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
929
3.14k
  if (id4 == NULL || id5 == NULL)
930
0
    goto error_return;
931
932
  /* Fill in the contents of these sections.  */
933
3.14k
  if (import_name_type == IMPORT_ORDINAL)
934
1.20k
    {
935
1.20k
      if (ordinal == 0)
936
  /* See PR 20907 for a reproducer.  */
937
122
  goto error_return;
938
939
#if defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) || defined(COFF_WITH_peLoongArch64)
940
      ((unsigned int *) id4->contents)[0] = ordinal;
941
      ((unsigned int *) id4->contents)[1] = 0x80000000;
942
      ((unsigned int *) id5->contents)[0] = ordinal;
943
      ((unsigned int *) id5->contents)[1] = 0x80000000;
944
#else
945
1.08k
      * (unsigned int *) id4->contents = ordinal | 0x80000000;
946
1.08k
      * (unsigned int *) id5->contents = ordinal | 0x80000000;
947
1.08k
#endif
948
1.08k
    }
949
1.94k
  else
950
1.94k
    {
951
1.94k
      char * symbol;
952
1.94k
      unsigned int len;
953
954
      /* Create .idata$6 - the Hint Name Table.  */
955
1.94k
      id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
956
1.94k
      if (id6 == NULL)
957
0
  goto error_return;
958
959
      /* If necessary, trim the import symbol name.  */
960
1.94k
      symbol = symbol_name;
961
962
      /* As used by MS compiler, '_', '@', and '?' are alternative
963
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
964
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
965
   of these is used for a symbol.  We strip this leading char for
966
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
967
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
968
969
1.94k
      if (import_name_type != IMPORT_NAME)
970
1.22k
  {
971
1.22k
    char c = symbol[0];
972
973
    /* Check that we don't remove for targets with empty
974
       USER_LABEL_PREFIX the leading underscore.  */
975
1.22k
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
976
1.22k
        || c == '@' || c == '?')
977
11
      symbol++;
978
1.22k
  }
979
980
1.94k
      len = strlen (symbol);
981
1.94k
      if (import_name_type == IMPORT_NAME_UNDECORATE)
982
733
  {
983
    /* Truncate at the first '@'.  */
984
733
    char *at = strchr (symbol, '@');
985
986
733
    if (at != NULL)
987
237
      len = at - symbol;
988
733
  }
989
990
1.94k
      id6->contents[0] = ordinal & 0xff;
991
1.94k
      id6->contents[1] = ordinal >> 8;
992
993
1.94k
      memcpy ((char *) id6->contents + 2, symbol, len);
994
1.94k
      id6->contents[len + 2] = '\0';
995
1.94k
    }
996
997
3.02k
  if (import_name_type != IMPORT_ORDINAL)
998
1.94k
    {
999
1.94k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1000
1.94k
      pe_ILF_save_relocs (&vars, id4);
1001
1002
1.94k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1003
1.94k
      pe_ILF_save_relocs (&vars, id5);
1004
1.94k
    }
1005
1006
  /* Create an import symbol.  */
1007
3.02k
  pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
1008
3.02k
  imp_sym   = vars.sym_ptr_ptr - 1;
1009
3.02k
  imp_index = vars.sym_index - 1;
1010
1011
  /* Create extra sections depending upon the type of import we are dealing with.  */
1012
3.02k
  switch (import_type)
1013
3.02k
    {
1014
0
      int i;
1015
1016
2.02k
    case IMPORT_CODE:
1017
      /* CODE functions are special, in that they get a trampoline that
1018
   jumps to the main import symbol.  Create a .text section to hold it.
1019
   First we need to look up its contents in the jump table.  */
1020
4.05k
      for (i = NUM_ENTRIES (jtab); i--;)
1021
4.05k
  {
1022
4.05k
    if (jtab[i].size == 0)
1023
2.02k
      continue;
1024
2.02k
    if (jtab[i].magic == magic)
1025
2.02k
      break;
1026
2.02k
  }
1027
      /* If we did not find a matching entry something is wrong.  */
1028
2.02k
      if (i < 0)
1029
0
  abort ();
1030
1031
      /* Create the .text section.  */
1032
2.02k
      text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
1033
2.02k
      if (text == NULL)
1034
0
  goto error_return;
1035
1036
      /* Copy in the jump code.  */
1037
2.02k
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1038
1039
      /* Create a reloc for the data in the text section.  */
1040
#ifdef MIPS_ARCH_MAGIC_WINCE
1041
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1042
  {
1043
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1044
              (struct bfd_symbol **) imp_sym,
1045
              imp_index);
1046
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1047
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1048
              (struct bfd_symbol **) imp_sym,
1049
              imp_index);
1050
  }
1051
      else
1052
#endif
1053
#ifdef AMD64MAGIC
1054
      if (magic == AMD64MAGIC)
1055
  {
1056
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1057
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1058
              imp_index);
1059
  }
1060
      else
1061
#endif
1062
2.02k
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1063
2.02k
            BFD_RELOC_32, (asymbol **) imp_sym,
1064
2.02k
            imp_index);
1065
1066
2.02k
      pe_ILF_save_relocs (& vars, text);
1067
2.02k
      break;
1068
1069
993
    case IMPORT_DATA:
1070
993
      break;
1071
1072
0
    default:
1073
      /* XXX code not yet written.  */
1074
0
      abort ();
1075
3.02k
    }
1076
1077
  /* Now create a symbol describing the imported value.  */
1078
3.02k
  switch (import_type)
1079
3.02k
    {
1080
2.02k
    case IMPORT_CODE:
1081
2.02k
      pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1082
2.02k
          BSF_NOT_AT_END | BSF_FUNCTION);
1083
1084
2.02k
      break;
1085
1086
993
    case IMPORT_DATA:
1087
      /* Nothing to do here.  */
1088
993
      break;
1089
1090
0
    default:
1091
      /* XXX code not yet written.  */
1092
0
      abort ();
1093
3.02k
    }
1094
1095
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1096
3.02k
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1097
3.02k
  if (ptr)
1098
246
    * ptr = 0;
1099
3.02k
  pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1100
3.02k
  if (ptr)
1101
246
    * ptr = '.';
1102
1103
  /* Initialise the bfd.  */
1104
3.02k
  memset (& internal_f, 0, sizeof (internal_f));
1105
1106
3.02k
  internal_f.f_magic  = magic;
1107
3.02k
  internal_f.f_symptr = 0;
1108
3.02k
  internal_f.f_nsyms  = 0;
1109
3.02k
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1110
1111
3.02k
  if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
1112
3.02k
      || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1113
0
    goto error_return;
1114
1115
3.02k
  if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL)
1116
0
    goto error_return;
1117
1118
3.02k
  obj_pe (abfd) = true;
1119
#ifdef THUMBPEMAGIC
1120
  if (vars.magic == THUMBPEMAGIC)
1121
    /* Stop some linker warnings about thumb code not supporting interworking.  */
1122
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1123
#endif
1124
1125
  /* Switch from file contents to memory contents.  */
1126
3.02k
  bfd_cache_close (abfd);
1127
1128
3.02k
  abfd->iostream = (void *) vars.bim;
1129
3.02k
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1130
3.02k
  abfd->iovec = &_bfd_memory_iovec;
1131
3.02k
  abfd->where = 0;
1132
3.02k
  abfd->origin = 0;
1133
3.02k
  abfd->size = 0;
1134
3.02k
  obj_sym_filepos (abfd) = 0;
1135
1136
  /* Point the bfd at the symbol table.  */
1137
3.02k
  obj_symbols (abfd) = vars.sym_cache;
1138
3.02k
  abfd->symcount = vars.sym_index;
1139
1140
3.02k
  obj_raw_syments (abfd) = vars.native_syms;
1141
3.02k
  obj_raw_syment_count (abfd) = vars.sym_index;
1142
1143
3.02k
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1144
3.02k
  obj_coff_keep_syms (abfd) = true;
1145
1146
3.02k
  obj_convert (abfd) = vars.sym_table;
1147
3.02k
  obj_conv_table_size (abfd) = vars.sym_index;
1148
1149
3.02k
  obj_coff_strings (abfd) = vars.string_table;
1150
3.02k
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1151
3.02k
  obj_coff_keep_strings (abfd) = true;
1152
1153
3.02k
  return true;
1154
1155
122
 error_return:
1156
122
  free (vars.bim->buffer);
1157
122
  free (vars.bim);
1158
122
  return false;
1159
3.02k
}
1160
1161
/* Cleanup function, returned from check_format hook.  */
1162
1163
static void
1164
pe_ILF_cleanup (bfd *abfd)
1165
166
{
1166
166
  struct bfd_in_memory *bim = abfd->iostream;
1167
166
  free (bim->buffer);
1168
166
  free (bim);
1169
166
  abfd->iostream = NULL;
1170
166
}
Unexecuted instantiation: pei-i386.c:pe_ILF_cleanup
Unexecuted instantiation: pei-x86_64.c:pe_ILF_cleanup
Unexecuted instantiation: pei-aarch64.c:pe_ILF_cleanup
Unexecuted instantiation: pei-ia64.c:pe_ILF_cleanup
Unexecuted instantiation: pei-loongarch64.c:pe_ILF_cleanup
pei-arm-wince.c:pe_ILF_cleanup
Line
Count
Source
1165
83
{
1166
83
  struct bfd_in_memory *bim = abfd->iostream;
1167
83
  free (bim->buffer);
1168
83
  free (bim);
1169
83
  abfd->iostream = NULL;
1170
83
}
pei-arm.c:pe_ILF_cleanup
Line
Count
Source
1165
83
{
1166
83
  struct bfd_in_memory *bim = abfd->iostream;
1167
83
  free (bim->buffer);
1168
83
  free (bim);
1169
83
  abfd->iostream = NULL;
1170
83
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_cleanup
Unexecuted instantiation: pei-sh.c:pe_ILF_cleanup
1171
1172
/* We have detected an Import Library Format archive element.
1173
   Decode the element and return the appropriate target.  */
1174
1175
static bfd_cleanup
1176
pe_ILF_object_p (bfd * abfd)
1177
248k
{
1178
248k
  bfd_byte    buffer[14];
1179
248k
  bfd_byte *    ptr;
1180
248k
  char *    symbol_name;
1181
248k
  char *    source_dll;
1182
248k
  unsigned int    machine;
1183
248k
  bfd_size_type   size;
1184
248k
  unsigned int    ordinal;
1185
248k
  unsigned int    types;
1186
248k
  unsigned int    magic;
1187
1188
  /* Upon entry the first six bytes of the ILF header have
1189
     already been read.  Now read the rest of the header.  */
1190
248k
  if (bfd_bread (buffer, (bfd_size_type) 14, abfd) != 14)
1191
3.67k
    return NULL;
1192
1193
245k
  ptr = buffer;
1194
1195
245k
  machine = H_GET_16 (abfd, ptr);
1196
245k
  ptr += 2;
1197
1198
  /* Check that the machine type is recognised.  */
1199
245k
  magic = 0;
1200
1201
245k
  switch (machine)
1202
245k
    {
1203
2.77k
    case IMAGE_FILE_MACHINE_UNKNOWN:
1204
2.81k
    case IMAGE_FILE_MACHINE_ALPHA:
1205
2.84k
    case IMAGE_FILE_MACHINE_ALPHA64:
1206
2.95k
    case IMAGE_FILE_MACHINE_IA64:
1207
2.95k
      break;
1208
1209
34.4k
    case IMAGE_FILE_MACHINE_I386:
1210
#ifdef I386MAGIC
1211
6.19k
      magic = I386MAGIC;
1212
#endif
1213
34.4k
      break;
1214
1215
49.8k
    case IMAGE_FILE_MACHINE_AMD64:
1216
#ifdef AMD64MAGIC
1217
6.76k
      magic = AMD64MAGIC;
1218
#endif
1219
49.8k
      break;
1220
1221
64
    case IMAGE_FILE_MACHINE_R3000:
1222
103
    case IMAGE_FILE_MACHINE_R4000:
1223
947
    case IMAGE_FILE_MACHINE_R10000:
1224
1225
972
    case IMAGE_FILE_MACHINE_MIPS16:
1226
999
    case IMAGE_FILE_MACHINE_MIPSFPU:
1227
1.02k
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1228
#ifdef MIPS_ARCH_MAGIC_WINCE
1229
      magic = MIPS_ARCH_MAGIC_WINCE;
1230
#endif
1231
1.02k
      break;
1232
1233
12.9k
    case IMAGE_FILE_MACHINE_SH3:
1234
31.3k
    case IMAGE_FILE_MACHINE_SH4:
1235
#ifdef SH_ARCH_MAGIC_WINCE
1236
4.64k
      magic = SH_ARCH_MAGIC_WINCE;
1237
#endif
1238
31.3k
      break;
1239
1240
35.0k
    case IMAGE_FILE_MACHINE_ARM:
1241
#ifdef ARMPEMAGIC
1242
10.8k
      magic = ARMPEMAGIC;
1243
#endif
1244
35.0k
      break;
1245
1246
12.0k
    case IMAGE_FILE_MACHINE_ARM64:
1247
#ifdef AARCH64MAGIC
1248
3.37k
      magic = AARCH64MAGIC;
1249
#endif
1250
12.0k
      break;
1251
1252
48.4k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1253
#ifdef LOONGARCH64MAGIC
1254
6.09k
      magic = LOONGARCH64MAGIC;
1255
#endif
1256
48.4k
      break;
1257
1258
7.90k
    case IMAGE_FILE_MACHINE_THUMB:
1259
#ifdef THUMBPEMAGIC
1260
      {
1261
  extern const bfd_target TARGET_LITTLE_SYM;
1262
1263
2.56k
  if (abfd->xvec == & TARGET_LITTLE_SYM)
1264
2.55k
    magic = THUMBPEMAGIC;
1265
      }
1266
#endif
1267
7.90k
      break;
1268
1269
0
    case IMAGE_FILE_MACHINE_POWERPC:
1270
      /* We no longer support PowerPC.  */
1271
22.2k
    default:
1272
22.2k
      _bfd_error_handler
1273
  /* xgettext:c-format */
1274
22.2k
  (_("%pB: unrecognised machine type (0x%x)"
1275
22.2k
     " in Import Library Format archive"),
1276
22.2k
   abfd, machine);
1277
22.2k
      bfd_set_error (bfd_error_malformed_archive);
1278
1279
22.2k
      return NULL;
1280
0
      break;
1281
245k
    }
1282
1283
223k
  if (magic == 0)
1284
182k
    {
1285
182k
      _bfd_error_handler
1286
  /* xgettext:c-format */
1287
182k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1288
182k
     " in Import Library Format archive"),
1289
182k
   abfd, machine);
1290
182k
      bfd_set_error (bfd_error_wrong_format);
1291
1292
182k
      return NULL;
1293
182k
    }
1294
1295
  /* We do not bother to check the date.
1296
     date = H_GET_32 (abfd, ptr);  */
1297
40.4k
  ptr += 4;
1298
1299
40.4k
  size = H_GET_32 (abfd, ptr);
1300
40.4k
  ptr += 4;
1301
1302
40.4k
  if (size == 0)
1303
1.82k
    {
1304
1.82k
      _bfd_error_handler
1305
1.82k
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1306
1.82k
      bfd_set_error (bfd_error_malformed_archive);
1307
1308
1.82k
      return NULL;
1309
1.82k
    }
1310
1311
38.6k
  ordinal = H_GET_16 (abfd, ptr);
1312
38.6k
  ptr += 2;
1313
1314
38.6k
  types = H_GET_16 (abfd, ptr);
1315
  /* ptr += 2; */
1316
1317
  /* Now read in the two strings that follow.  */
1318
38.6k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1319
38.6k
  if (ptr == NULL)
1320
6.49k
    return NULL;
1321
1322
32.1k
  symbol_name = (char *) ptr;
1323
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1324
32.1k
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1325
1326
  /* Verify that the strings are null terminated.  */
1327
32.1k
  if (ptr[size - 1] != 0
1328
32.1k
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1329
3.38k
    {
1330
3.38k
      _bfd_error_handler
1331
3.38k
  (_("%pB: string not null terminated in ILF object file"), abfd);
1332
3.38k
      bfd_set_error (bfd_error_malformed_archive);
1333
3.38k
      bfd_release (abfd, ptr);
1334
3.38k
      return NULL;
1335
3.38k
    }
1336
1337
  /* Now construct the bfd.  */
1338
28.7k
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1339
28.7k
          source_dll, ordinal, types))
1340
6.50k
    {
1341
6.50k
      bfd_release (abfd, ptr);
1342
6.50k
      return NULL;
1343
6.50k
    }
1344
1345
22.2k
  return pe_ILF_cleanup;
1346
28.7k
}
pei-i386.c:pe_ILF_object_p
Line
Count
Source
1177
32.7k
{
1178
32.7k
  bfd_byte    buffer[14];
1179
32.7k
  bfd_byte *    ptr;
1180
32.7k
  char *    symbol_name;
1181
32.7k
  char *    source_dll;
1182
32.7k
  unsigned int    machine;
1183
32.7k
  bfd_size_type   size;
1184
32.7k
  unsigned int    ordinal;
1185
32.7k
  unsigned int    types;
1186
32.7k
  unsigned int    magic;
1187
1188
  /* Upon entry the first six bytes of the ILF header have
1189
     already been read.  Now read the rest of the header.  */
1190
32.7k
  if (bfd_bread (buffer, (bfd_size_type) 14, abfd) != 14)
1191
458
    return NULL;
1192
1193
32.2k
  ptr = buffer;
1194
1195
32.2k
  machine = H_GET_16 (abfd, ptr);
1196
32.2k
  ptr += 2;
1197
1198
  /* Check that the machine type is recognised.  */
1199
32.2k
  magic = 0;
1200
1201
32.2k
  switch (machine)
1202
32.2k
    {
1203
346
    case IMAGE_FILE_MACHINE_UNKNOWN:
1204
351
    case IMAGE_FILE_MACHINE_ALPHA:
1205
356
    case IMAGE_FILE_MACHINE_ALPHA64:
1206
370
    case IMAGE_FILE_MACHINE_IA64:
1207
370
      break;
1208
1209
6.19k
    case IMAGE_FILE_MACHINE_I386:
1210
6.19k
#ifdef I386MAGIC
1211
6.19k
      magic = I386MAGIC;
1212
6.19k
#endif
1213
6.19k
      break;
1214
1215
6.75k
    case IMAGE_FILE_MACHINE_AMD64:
1216
#ifdef AMD64MAGIC
1217
      magic = AMD64MAGIC;
1218
#endif
1219
6.75k
      break;
1220
1221
9
    case IMAGE_FILE_MACHINE_R3000:
1222
14
    case IMAGE_FILE_MACHINE_R4000:
1223
120
    case IMAGE_FILE_MACHINE_R10000:
1224
1225
122
    case IMAGE_FILE_MACHINE_MIPS16:
1226
125
    case IMAGE_FILE_MACHINE_MIPSFPU:
1227
128
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1228
#ifdef MIPS_ARCH_MAGIC_WINCE
1229
      magic = MIPS_ARCH_MAGIC_WINCE;
1230
#endif
1231
128
      break;
1232
1233
2.04k
    case IMAGE_FILE_MACHINE_SH3:
1234
4.65k
    case IMAGE_FILE_MACHINE_SH4:
1235
#ifdef SH_ARCH_MAGIC_WINCE
1236
      magic = SH_ARCH_MAGIC_WINCE;
1237
#endif
1238
4.65k
      break;
1239
1240
3.36k
    case IMAGE_FILE_MACHINE_ARM:
1241
#ifdef ARMPEMAGIC
1242
      magic = ARMPEMAGIC;
1243
#endif
1244
3.36k
      break;
1245
1246
1.24k
    case IMAGE_FILE_MACHINE_ARM64:
1247
#ifdef AARCH64MAGIC
1248
      magic = AARCH64MAGIC;
1249
#endif
1250
1.24k
      break;
1251
1252
6.06k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1253
#ifdef LOONGARCH64MAGIC
1254
      magic = LOONGARCH64MAGIC;
1255
#endif
1256
6.06k
      break;
1257
1258
697
    case IMAGE_FILE_MACHINE_THUMB:
1259
#ifdef THUMBPEMAGIC
1260
      {
1261
  extern const bfd_target TARGET_LITTLE_SYM;
1262
1263
  if (abfd->xvec == & TARGET_LITTLE_SYM)
1264
    magic = THUMBPEMAGIC;
1265
      }
1266
#endif
1267
697
      break;
1268
1269
0
    case IMAGE_FILE_MACHINE_POWERPC:
1270
      /* We no longer support PowerPC.  */
1271
2.78k
    default:
1272
2.78k
      _bfd_error_handler
1273
  /* xgettext:c-format */
1274
2.78k
  (_("%pB: unrecognised machine type (0x%x)"
1275
2.78k
     " in Import Library Format archive"),
1276
2.78k
   abfd, machine);
1277
2.78k
      bfd_set_error (bfd_error_malformed_archive);
1278
1279
2.78k
      return NULL;
1280
0
      break;
1281
32.2k
    }
1282
1283
29.4k
  if (magic == 0)
1284
23.2k
    {
1285
23.2k
      _bfd_error_handler
1286
  /* xgettext:c-format */
1287
23.2k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1288
23.2k
     " in Import Library Format archive"),
1289
23.2k
   abfd, machine);
1290
23.2k
      bfd_set_error (bfd_error_wrong_format);
1291
1292
23.2k
      return NULL;
1293
23.2k
    }
1294
1295
  /* We do not bother to check the date.
1296
     date = H_GET_32 (abfd, ptr);  */
1297
6.19k
  ptr += 4;
1298
1299
6.19k
  size = H_GET_32 (abfd, ptr);
1300
6.19k
  ptr += 4;
1301
1302
6.19k
  if (size == 0)
1303
216
    {
1304
216
      _bfd_error_handler
1305
216
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1306
216
      bfd_set_error (bfd_error_malformed_archive);
1307
1308
216
      return NULL;
1309
216
    }
1310
1311
5.97k
  ordinal = H_GET_16 (abfd, ptr);
1312
5.97k
  ptr += 2;
1313
1314
5.97k
  types = H_GET_16 (abfd, ptr);
1315
  /* ptr += 2; */
1316
1317
  /* Now read in the two strings that follow.  */
1318
5.97k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1319
5.97k
  if (ptr == NULL)
1320
774
    return NULL;
1321
1322
5.20k
  symbol_name = (char *) ptr;
1323
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1324
5.20k
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1325
1326
  /* Verify that the strings are null terminated.  */
1327
5.20k
  if (ptr[size - 1] != 0
1328
5.20k
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1329
535
    {
1330
535
      _bfd_error_handler
1331
535
  (_("%pB: string not null terminated in ILF object file"), abfd);
1332
535
      bfd_set_error (bfd_error_malformed_archive);
1333
535
      bfd_release (abfd, ptr);
1334
535
      return NULL;
1335
535
    }
1336
1337
  /* Now construct the bfd.  */
1338
4.66k
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1339
4.66k
          source_dll, ordinal, types))
1340
865
    {
1341
865
      bfd_release (abfd, ptr);
1342
865
      return NULL;
1343
865
    }
1344
1345
3.80k
  return pe_ILF_cleanup;
1346
4.66k
}
pei-x86_64.c:pe_ILF_object_p
Line
Count
Source
1177
26.0k
{
1178
26.0k
  bfd_byte    buffer[14];
1179
26.0k
  bfd_byte *    ptr;
1180
26.0k
  char *    symbol_name;
1181
26.0k
  char *    source_dll;
1182
26.0k
  unsigned int    machine;
1183
26.0k
  bfd_size_type   size;
1184
26.0k
  unsigned int    ordinal;
1185
26.0k
  unsigned int    types;
1186
26.0k
  unsigned int    magic;
1187
1188
  /* Upon entry the first six bytes of the ILF header have
1189
     already been read.  Now read the rest of the header.  */
1190
26.0k
  if (bfd_bread (buffer, (bfd_size_type) 14, abfd) != 14)
1191
458
    return NULL;
1192
1193
25.5k
  ptr = buffer;
1194
1195
25.5k
  machine = H_GET_16 (abfd, ptr);
1196
25.5k
  ptr += 2;
1197
1198
  /* Check that the machine type is recognised.  */
1199
25.5k
  magic = 0;
1200
1201
25.5k
  switch (machine)
1202
25.5k
    {
1203
346
    case IMAGE_FILE_MACHINE_UNKNOWN:
1204
351
    case IMAGE_FILE_MACHINE_ALPHA:
1205
356
    case IMAGE_FILE_MACHINE_ALPHA64:
1206
370
    case IMAGE_FILE_MACHINE_IA64:
1207
370
      break;
1208
1209
2.45k
    case IMAGE_FILE_MACHINE_I386:
1210
#ifdef I386MAGIC
1211
      magic = I386MAGIC;
1212
#endif
1213
2.45k
      break;
1214
1215
6.76k
    case IMAGE_FILE_MACHINE_AMD64:
1216
6.76k
#ifdef AMD64MAGIC
1217
6.76k
      magic = AMD64MAGIC;
1218
6.76k
#endif
1219
6.76k
      break;
1220
1221
9
    case IMAGE_FILE_MACHINE_R3000:
1222
14
    case IMAGE_FILE_MACHINE_R4000:
1223
120
    case IMAGE_FILE_MACHINE_R10000:
1224
1225
122
    case IMAGE_FILE_MACHINE_MIPS16:
1226
125
    case IMAGE_FILE_MACHINE_MIPSFPU:
1227
128
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1228
#ifdef MIPS_ARCH_MAGIC_WINCE
1229
      magic = MIPS_ARCH_MAGIC_WINCE;
1230
#endif
1231
128
      break;
1232
1233
375
    case IMAGE_FILE_MACHINE_SH3:
1234
1.72k
    case IMAGE_FILE_MACHINE_SH4:
1235
#ifdef SH_ARCH_MAGIC_WINCE
1236
      magic = SH_ARCH_MAGIC_WINCE;
1237
#endif
1238
1.72k
      break;
1239
1240
3.36k
    case IMAGE_FILE_MACHINE_ARM:
1241
#ifdef ARMPEMAGIC
1242
      magic = ARMPEMAGIC;
1243
#endif
1244
3.36k
      break;
1245
1246
1.24k
    case IMAGE_FILE_MACHINE_ARM64:
1247
#ifdef AARCH64MAGIC
1248
      magic = AARCH64MAGIC;
1249
#endif
1250
1.24k
      break;
1251
1252
6.06k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1253
#ifdef LOONGARCH64MAGIC
1254
      magic = LOONGARCH64MAGIC;
1255
#endif
1256
6.06k
      break;
1257
1258
697
    case IMAGE_FILE_MACHINE_THUMB:
1259
#ifdef THUMBPEMAGIC
1260
      {
1261
  extern const bfd_target TARGET_LITTLE_SYM;
1262
1263
  if (abfd->xvec == & TARGET_LITTLE_SYM)
1264
    magic = THUMBPEMAGIC;
1265
      }
1266
#endif
1267
697
      break;
1268
1269
0
    case IMAGE_FILE_MACHINE_POWERPC:
1270
      /* We no longer support PowerPC.  */
1271
2.78k
    default:
1272
2.78k
      _bfd_error_handler
1273
  /* xgettext:c-format */
1274
2.78k
  (_("%pB: unrecognised machine type (0x%x)"
1275
2.78k
     " in Import Library Format archive"),
1276
2.78k
   abfd, machine);
1277
2.78k
      bfd_set_error (bfd_error_malformed_archive);
1278
1279
2.78k
      return NULL;
1280
0
      break;
1281
25.5k
    }
1282
1283
22.8k
  if (magic == 0)
1284
16.0k
    {
1285
16.0k
      _bfd_error_handler
1286
  /* xgettext:c-format */
1287
16.0k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1288
16.0k
     " in Import Library Format archive"),
1289
16.0k
   abfd, machine);
1290
16.0k
      bfd_set_error (bfd_error_wrong_format);
1291
1292
16.0k
      return NULL;
1293
16.0k
    }
1294
1295
  /* We do not bother to check the date.
1296
     date = H_GET_32 (abfd, ptr);  */
1297
6.76k
  ptr += 4;
1298
1299
6.76k
  size = H_GET_32 (abfd, ptr);
1300
6.76k
  ptr += 4;
1301
1302
6.76k
  if (size == 0)
1303
318
    {
1304
318
      _bfd_error_handler
1305
318
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1306
318
      bfd_set_error (bfd_error_malformed_archive);
1307
1308
318
      return NULL;
1309
318
    }
1310
1311
6.44k
  ordinal = H_GET_16 (abfd, ptr);
1312
6.44k
  ptr += 2;
1313
1314
6.44k
  types = H_GET_16 (abfd, ptr);
1315
  /* ptr += 2; */
1316
1317
  /* Now read in the two strings that follow.  */
1318
6.44k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1319
6.44k
  if (ptr == NULL)
1320
682
    return NULL;
1321
1322
5.76k
  symbol_name = (char *) ptr;
1323
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1324
5.76k
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1325
1326
  /* Verify that the strings are null terminated.  */
1327
5.76k
  if (ptr[size - 1] != 0
1328
5.76k
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1329
537
    {
1330
537
      _bfd_error_handler
1331
537
  (_("%pB: string not null terminated in ILF object file"), abfd);
1332
537
      bfd_set_error (bfd_error_malformed_archive);
1333
537
      bfd_release (abfd, ptr);
1334
537
      return NULL;
1335
537
    }
1336
1337
  /* Now construct the bfd.  */
1338
5.22k
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1339
5.22k
          source_dll, ordinal, types))
1340
1.07k
    {
1341
1.07k
      bfd_release (abfd, ptr);
1342
1.07k
      return NULL;
1343
1.07k
    }
1344
1345
4.15k
  return pe_ILF_cleanup;
1346
5.22k
}
pei-aarch64.c:pe_ILF_object_p
Line
Count
Source
1177
39.9k
{
1178
39.9k
  bfd_byte    buffer[14];
1179
39.9k
  bfd_byte *    ptr;
1180
39.9k
  char *    symbol_name;
1181
39.9k
  char *    source_dll;
1182
39.9k
  unsigned int    machine;
1183
39.9k
  bfd_size_type   size;
1184
39.9k
  unsigned int    ordinal;
1185
39.9k
  unsigned int    types;
1186
39.9k
  unsigned int    magic;
1187
1188
  /* Upon entry the first six bytes of the ILF header have
1189
     already been read.  Now read the rest of the header.  */
1190
39.9k
  if (bfd_bread (buffer, (bfd_size_type) 14, abfd) != 14)
1191
458
    return NULL;
1192
1193
39.5k
  ptr = buffer;
1194
1195
39.5k
  machine = H_GET_16 (abfd, ptr);
1196
39.5k
  ptr += 2;
1197
1198
  /* Check that the machine type is recognised.  */
1199
39.5k
  magic = 0;
1200
1201
39.5k
  switch (machine)
1202
39.5k
    {
1203
346
    case IMAGE_FILE_MACHINE_UNKNOWN:
1204
351
    case IMAGE_FILE_MACHINE_ALPHA:
1205
356
    case IMAGE_FILE_MACHINE_ALPHA64:
1206
370
    case IMAGE_FILE_MACHINE_IA64:
1207
370
      break;
1208
1209
6.17k
    case IMAGE_FILE_MACHINE_I386:
1210
#ifdef I386MAGIC
1211
      magic = I386MAGIC;
1212
#endif
1213
6.17k
      break;
1214
1215
6.75k
    case IMAGE_FILE_MACHINE_AMD64:
1216
#ifdef AMD64MAGIC
1217
      magic = AMD64MAGIC;
1218
#endif
1219
6.75k
      break;
1220
1221
9
    case IMAGE_FILE_MACHINE_R3000:
1222
14
    case IMAGE_FILE_MACHINE_R4000:
1223
120
    case IMAGE_FILE_MACHINE_R10000:
1224
1225
122
    case IMAGE_FILE_MACHINE_MIPS16:
1226
125
    case IMAGE_FILE_MACHINE_MIPSFPU:
1227
128
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1228
#ifdef MIPS_ARCH_MAGIC_WINCE
1229
      magic = MIPS_ARCH_MAGIC_WINCE;
1230
#endif
1231
128
      break;
1232
1233
2.04k
    case IMAGE_FILE_MACHINE_SH3:
1234
4.65k
    case IMAGE_FILE_MACHINE_SH4:
1235
#ifdef SH_ARCH_MAGIC_WINCE
1236
      magic = SH_ARCH_MAGIC_WINCE;
1237
#endif
1238
4.65k
      break;
1239
1240
7.32k
    case IMAGE_FILE_MACHINE_ARM:
1241
#ifdef ARMPEMAGIC
1242
      magic = ARMPEMAGIC;
1243
#endif
1244
7.32k
      break;
1245
1246
3.37k
    case IMAGE_FILE_MACHINE_ARM64:
1247
3.37k
#ifdef AARCH64MAGIC
1248
3.37k
      magic = AARCH64MAGIC;
1249
3.37k
#endif
1250
3.37k
      break;
1251
1252
6.06k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1253
#ifdef LOONGARCH64MAGIC
1254
      magic = LOONGARCH64MAGIC;
1255
#endif
1256
6.06k
      break;
1257
1258
1.89k
    case IMAGE_FILE_MACHINE_THUMB:
1259
#ifdef THUMBPEMAGIC
1260
      {
1261
  extern const bfd_target TARGET_LITTLE_SYM;
1262
1263
  if (abfd->xvec == & TARGET_LITTLE_SYM)
1264
    magic = THUMBPEMAGIC;
1265
      }
1266
#endif
1267
1.89k
      break;
1268
1269
0
    case IMAGE_FILE_MACHINE_POWERPC:
1270
      /* We no longer support PowerPC.  */
1271
2.78k
    default:
1272
2.78k
      _bfd_error_handler
1273
  /* xgettext:c-format */
1274
2.78k
  (_("%pB: unrecognised machine type (0x%x)"
1275
2.78k
     " in Import Library Format archive"),
1276
2.78k
   abfd, machine);
1277
2.78k
      bfd_set_error (bfd_error_malformed_archive);
1278
1279
2.78k
      return NULL;
1280
0
      break;
1281
39.5k
    }
1282
1283
36.7k
  if (magic == 0)
1284
33.3k
    {
1285
33.3k
      _bfd_error_handler
1286
  /* xgettext:c-format */
1287
33.3k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1288
33.3k
     " in Import Library Format archive"),
1289
33.3k
   abfd, machine);
1290
33.3k
      bfd_set_error (bfd_error_wrong_format);
1291
1292
33.3k
      return NULL;
1293
33.3k
    }
1294
1295
  /* We do not bother to check the date.
1296
     date = H_GET_32 (abfd, ptr);  */
1297
3.37k
  ptr += 4;
1298
1299
3.37k
  size = H_GET_32 (abfd, ptr);
1300
3.37k
  ptr += 4;
1301
1302
3.37k
  if (size == 0)
1303
115
    {
1304
115
      _bfd_error_handler
1305
115
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1306
115
      bfd_set_error (bfd_error_malformed_archive);
1307
1308
115
      return NULL;
1309
115
    }
1310
1311
3.26k
  ordinal = H_GET_16 (abfd, ptr);
1312
3.26k
  ptr += 2;
1313
1314
3.26k
  types = H_GET_16 (abfd, ptr);
1315
  /* ptr += 2; */
1316
1317
  /* Now read in the two strings that follow.  */
1318
3.26k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1319
3.26k
  if (ptr == NULL)
1320
571
    return NULL;
1321
1322
2.69k
  symbol_name = (char *) ptr;
1323
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1324
2.69k
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1325
1326
  /* Verify that the strings are null terminated.  */
1327
2.69k
  if (ptr[size - 1] != 0
1328
2.69k
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1329
138
    {
1330
138
      _bfd_error_handler
1331
138
  (_("%pB: string not null terminated in ILF object file"), abfd);
1332
138
      bfd_set_error (bfd_error_malformed_archive);
1333
138
      bfd_release (abfd, ptr);
1334
138
      return NULL;
1335
138
    }
1336
1337
  /* Now construct the bfd.  */
1338
2.55k
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1339
2.55k
          source_dll, ordinal, types))
1340
362
    {
1341
362
      bfd_release (abfd, ptr);
1342
362
      return NULL;
1343
362
    }
1344
1345
2.19k
  return pe_ILF_cleanup;
1346
2.55k
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_object_p
pei-loongarch64.c:pe_ILF_object_p
Line
Count
Source
1177
21.9k
{
1178
21.9k
  bfd_byte    buffer[14];
1179
21.9k
  bfd_byte *    ptr;
1180
21.9k
  char *    symbol_name;
1181
21.9k
  char *    source_dll;
1182
21.9k
  unsigned int    machine;
1183
21.9k
  bfd_size_type   size;
1184
21.9k
  unsigned int    ordinal;
1185
21.9k
  unsigned int    types;
1186
21.9k
  unsigned int    magic;
1187
1188
  /* Upon entry the first six bytes of the ILF header have
1189
     already been read.  Now read the rest of the header.  */
1190
21.9k
  if (bfd_bread (buffer, (bfd_size_type) 14, abfd) != 14)
1191
458
    return NULL;
1192
1193
21.5k
  ptr = buffer;
1194
1195
21.5k
  machine = H_GET_16 (abfd, ptr);
1196
21.5k
  ptr += 2;
1197
1198
  /* Check that the machine type is recognised.  */
1199
21.5k
  magic = 0;
1200
1201
21.5k
  switch (machine)
1202
21.5k
    {
1203
346
    case IMAGE_FILE_MACHINE_UNKNOWN:
1204
351
    case IMAGE_FILE_MACHINE_ALPHA:
1205
356
    case IMAGE_FILE_MACHINE_ALPHA64:
1206
370
    case IMAGE_FILE_MACHINE_IA64:
1207
370
      break;
1208
1209
2.45k
    case IMAGE_FILE_MACHINE_I386:
1210
#ifdef I386MAGIC
1211
      magic = I386MAGIC;
1212
#endif
1213
2.45k
      break;
1214
1215
2.67k
    case IMAGE_FILE_MACHINE_AMD64:
1216
#ifdef AMD64MAGIC
1217
      magic = AMD64MAGIC;
1218
#endif
1219
2.67k
      break;
1220
1221
9
    case IMAGE_FILE_MACHINE_R3000:
1222
14
    case IMAGE_FILE_MACHINE_R4000:
1223
120
    case IMAGE_FILE_MACHINE_R10000:
1224
1225
122
    case IMAGE_FILE_MACHINE_MIPS16:
1226
125
    case IMAGE_FILE_MACHINE_MIPSFPU:
1227
128
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1228
#ifdef MIPS_ARCH_MAGIC_WINCE
1229
      magic = MIPS_ARCH_MAGIC_WINCE;
1230
#endif
1231
128
      break;
1232
1233
375
    case IMAGE_FILE_MACHINE_SH3:
1234
1.72k
    case IMAGE_FILE_MACHINE_SH4:
1235
#ifdef SH_ARCH_MAGIC_WINCE
1236
      magic = SH_ARCH_MAGIC_WINCE;
1237
#endif
1238
1.72k
      break;
1239
1240
3.36k
    case IMAGE_FILE_MACHINE_ARM:
1241
#ifdef ARMPEMAGIC
1242
      magic = ARMPEMAGIC;
1243
#endif
1244
3.36k
      break;
1245
1246
1.24k
    case IMAGE_FILE_MACHINE_ARM64:
1247
#ifdef AARCH64MAGIC
1248
      magic = AARCH64MAGIC;
1249
#endif
1250
1.24k
      break;
1251
1252
6.09k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1253
6.09k
#ifdef LOONGARCH64MAGIC
1254
6.09k
      magic = LOONGARCH64MAGIC;
1255
6.09k
#endif
1256
6.09k
      break;
1257
1258
697
    case IMAGE_FILE_MACHINE_THUMB:
1259
#ifdef THUMBPEMAGIC
1260
      {
1261
  extern const bfd_target TARGET_LITTLE_SYM;
1262
1263
  if (abfd->xvec == & TARGET_LITTLE_SYM)
1264
    magic = THUMBPEMAGIC;
1265
      }
1266
#endif
1267
697
      break;
1268
1269
0
    case IMAGE_FILE_MACHINE_POWERPC:
1270
      /* We no longer support PowerPC.  */
1271
2.78k
    default:
1272
2.78k
      _bfd_error_handler
1273
  /* xgettext:c-format */
1274
2.78k
  (_("%pB: unrecognised machine type (0x%x)"
1275
2.78k
     " in Import Library Format archive"),
1276
2.78k
   abfd, machine);
1277
2.78k
      bfd_set_error (bfd_error_malformed_archive);
1278
1279
2.78k
      return NULL;
1280
0
      break;
1281
21.5k
    }
1282
1283
18.7k
  if (magic == 0)
1284
12.6k
    {
1285
12.6k
      _bfd_error_handler
1286
  /* xgettext:c-format */
1287
12.6k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1288
12.6k
     " in Import Library Format archive"),
1289
12.6k
   abfd, machine);
1290
12.6k
      bfd_set_error (bfd_error_wrong_format);
1291
1292
12.6k
      return NULL;
1293
12.6k
    }
1294
1295
  /* We do not bother to check the date.
1296
     date = H_GET_32 (abfd, ptr);  */
1297
6.09k
  ptr += 4;
1298
1299
6.09k
  size = H_GET_32 (abfd, ptr);
1300
6.09k
  ptr += 4;
1301
1302
6.09k
  if (size == 0)
1303
215
    {
1304
215
      _bfd_error_handler
1305
215
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1306
215
      bfd_set_error (bfd_error_malformed_archive);
1307
1308
215
      return NULL;
1309
215
    }
1310
1311
5.87k
  ordinal = H_GET_16 (abfd, ptr);
1312
5.87k
  ptr += 2;
1313
1314
5.87k
  types = H_GET_16 (abfd, ptr);
1315
  /* ptr += 2; */
1316
1317
  /* Now read in the two strings that follow.  */
1318
5.87k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1319
5.87k
  if (ptr == NULL)
1320
792
    return NULL;
1321
1322
5.08k
  symbol_name = (char *) ptr;
1323
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1324
5.08k
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1325
1326
  /* Verify that the strings are null terminated.  */
1327
5.08k
  if (ptr[size - 1] != 0
1328
5.08k
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1329
431
    {
1330
431
      _bfd_error_handler
1331
431
  (_("%pB: string not null terminated in ILF object file"), abfd);
1332
431
      bfd_set_error (bfd_error_malformed_archive);
1333
431
      bfd_release (abfd, ptr);
1334
431
      return NULL;
1335
431
    }
1336
1337
  /* Now construct the bfd.  */
1338
4.65k
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1339
4.65k
          source_dll, ordinal, types))
1340
970
    {
1341
970
      bfd_release (abfd, ptr);
1342
970
      return NULL;
1343
970
    }
1344
1345
3.68k
  return pe_ILF_cleanup;
1346
4.65k
}
pei-arm-wince.c:pe_ILF_object_p
Line
Count
Source
1177
32.6k
{
1178
32.6k
  bfd_byte    buffer[14];
1179
32.6k
  bfd_byte *    ptr;
1180
32.6k
  char *    symbol_name;
1181
32.6k
  char *    source_dll;
1182
32.6k
  unsigned int    machine;
1183
32.6k
  bfd_size_type   size;
1184
32.6k
  unsigned int    ordinal;
1185
32.6k
  unsigned int    types;
1186
32.6k
  unsigned int    magic;
1187
1188
  /* Upon entry the first six bytes of the ILF header have
1189
     already been read.  Now read the rest of the header.  */
1190
32.6k
  if (bfd_bread (buffer, (bfd_size_type) 14, abfd) != 14)
1191
462
    return NULL;
1192
1193
32.2k
  ptr = buffer;
1194
1195
32.2k
  machine = H_GET_16 (abfd, ptr);
1196
32.2k
  ptr += 2;
1197
1198
  /* Check that the machine type is recognised.  */
1199
32.2k
  magic = 0;
1200
1201
32.2k
  switch (machine)
1202
32.2k
    {
1203
350
    case IMAGE_FILE_MACHINE_UNKNOWN:
1204
354
    case IMAGE_FILE_MACHINE_ALPHA:
1205
358
    case IMAGE_FILE_MACHINE_ALPHA64:
1206
372
    case IMAGE_FILE_MACHINE_IA64:
1207
372
      break;
1208
1209
6.16k
    case IMAGE_FILE_MACHINE_I386:
1210
#ifdef I386MAGIC
1211
      magic = I386MAGIC;
1212
#endif
1213
6.16k
      break;
1214
1215
6.73k
    case IMAGE_FILE_MACHINE_AMD64:
1216
#ifdef AMD64MAGIC
1217
      magic = AMD64MAGIC;
1218
#endif
1219
6.73k
      break;
1220
1221
7
    case IMAGE_FILE_MACHINE_R3000:
1222
12
    case IMAGE_FILE_MACHINE_R4000:
1223
117
    case IMAGE_FILE_MACHINE_R10000:
1224
1225
122
    case IMAGE_FILE_MACHINE_MIPS16:
1226
126
    case IMAGE_FILE_MACHINE_MIPSFPU:
1227
129
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1228
#ifdef MIPS_ARCH_MAGIC_WINCE
1229
      magic = MIPS_ARCH_MAGIC_WINCE;
1230
#endif
1231
129
      break;
1232
1233
2.03k
    case IMAGE_FILE_MACHINE_SH3:
1234
4.63k
    case IMAGE_FILE_MACHINE_SH4:
1235
#ifdef SH_ARCH_MAGIC_WINCE
1236
      magic = SH_ARCH_MAGIC_WINCE;
1237
#endif
1238
4.63k
      break;
1239
1240
3.42k
    case IMAGE_FILE_MACHINE_ARM:
1241
3.42k
#ifdef ARMPEMAGIC
1242
3.42k
      magic = ARMPEMAGIC;
1243
3.42k
#endif
1244
3.42k
      break;
1245
1246
1.23k
    case IMAGE_FILE_MACHINE_ARM64:
1247
#ifdef AARCH64MAGIC
1248
      magic = AARCH64MAGIC;
1249
#endif
1250
1.23k
      break;
1251
1252
6.05k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1253
#ifdef LOONGARCH64MAGIC
1254
      magic = LOONGARCH64MAGIC;
1255
#endif
1256
6.05k
      break;
1257
1258
682
    case IMAGE_FILE_MACHINE_THUMB:
1259
682
#ifdef THUMBPEMAGIC
1260
682
      {
1261
682
  extern const bfd_target TARGET_LITTLE_SYM;
1262
1263
682
  if (abfd->xvec == & TARGET_LITTLE_SYM)
1264
676
    magic = THUMBPEMAGIC;
1265
682
      }
1266
682
#endif
1267
682
      break;
1268
1269
0
    case IMAGE_FILE_MACHINE_POWERPC:
1270
      /* We no longer support PowerPC.  */
1271
2.78k
    default:
1272
2.78k
      _bfd_error_handler
1273
  /* xgettext:c-format */
1274
2.78k
  (_("%pB: unrecognised machine type (0x%x)"
1275
2.78k
     " in Import Library Format archive"),
1276
2.78k
   abfd, machine);
1277
2.78k
      bfd_set_error (bfd_error_malformed_archive);
1278
1279
2.78k
      return NULL;
1280
0
      break;
1281
32.2k
    }
1282
1283
29.4k
  if (magic == 0)
1284
25.3k
    {
1285
25.3k
      _bfd_error_handler
1286
  /* xgettext:c-format */
1287
25.3k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1288
25.3k
     " in Import Library Format archive"),
1289
25.3k
   abfd, machine);
1290
25.3k
      bfd_set_error (bfd_error_wrong_format);
1291
1292
25.3k
      return NULL;
1293
25.3k
    }
1294
1295
  /* We do not bother to check the date.
1296
     date = H_GET_32 (abfd, ptr);  */
1297
4.09k
  ptr += 4;
1298
1299
4.09k
  size = H_GET_32 (abfd, ptr);
1300
4.09k
  ptr += 4;
1301
1302
4.09k
  if (size == 0)
1303
321
    {
1304
321
      _bfd_error_handler
1305
321
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1306
321
      bfd_set_error (bfd_error_malformed_archive);
1307
1308
321
      return NULL;
1309
321
    }
1310
1311
3.77k
  ordinal = H_GET_16 (abfd, ptr);
1312
3.77k
  ptr += 2;
1313
1314
3.77k
  types = H_GET_16 (abfd, ptr);
1315
  /* ptr += 2; */
1316
1317
  /* Now read in the two strings that follow.  */
1318
3.77k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1319
3.77k
  if (ptr == NULL)
1320
1.54k
    return NULL;
1321
1322
2.23k
  symbol_name = (char *) ptr;
1323
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1324
2.23k
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1325
1326
  /* Verify that the strings are null terminated.  */
1327
2.23k
  if (ptr[size - 1] != 0
1328
2.23k
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1329
748
    {
1330
748
      _bfd_error_handler
1331
748
  (_("%pB: string not null terminated in ILF object file"), abfd);
1332
748
      bfd_set_error (bfd_error_malformed_archive);
1333
748
      bfd_release (abfd, ptr);
1334
748
      return NULL;
1335
748
    }
1336
1337
  /* Now construct the bfd.  */
1338
1.48k
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1339
1.48k
          source_dll, ordinal, types))
1340
1.38k
    {
1341
1.38k
      bfd_release (abfd, ptr);
1342
1.38k
      return NULL;
1343
1.38k
    }
1344
1345
103
  return pe_ILF_cleanup;
1346
1.48k
}
pei-arm.c:pe_ILF_object_p
Line
Count
Source
1177
37.8k
{
1178
37.8k
  bfd_byte    buffer[14];
1179
37.8k
  bfd_byte *    ptr;
1180
37.8k
  char *    symbol_name;
1181
37.8k
  char *    source_dll;
1182
37.8k
  unsigned int    machine;
1183
37.8k
  bfd_size_type   size;
1184
37.8k
  unsigned int    ordinal;
1185
37.8k
  unsigned int    types;
1186
37.8k
  unsigned int    magic;
1187
1188
  /* Upon entry the first six bytes of the ILF header have
1189
     already been read.  Now read the rest of the header.  */
1190
37.8k
  if (bfd_bread (buffer, (bfd_size_type) 14, abfd) != 14)
1191
462
    return NULL;
1192
1193
37.3k
  ptr = buffer;
1194
1195
37.3k
  machine = H_GET_16 (abfd, ptr);
1196
37.3k
  ptr += 2;
1197
1198
  /* Check that the machine type is recognised.  */
1199
37.3k
  magic = 0;
1200
1201
37.3k
  switch (machine)
1202
37.3k
    {
1203
350
    case IMAGE_FILE_MACHINE_UNKNOWN:
1204
354
    case IMAGE_FILE_MACHINE_ALPHA:
1205
358
    case IMAGE_FILE_MACHINE_ALPHA64:
1206
372
    case IMAGE_FILE_MACHINE_IA64:
1207
372
      break;
1208
1209
6.16k
    case IMAGE_FILE_MACHINE_I386:
1210
#ifdef I386MAGIC
1211
      magic = I386MAGIC;
1212
#endif
1213
6.16k
      break;
1214
1215
6.73k
    case IMAGE_FILE_MACHINE_AMD64:
1216
#ifdef AMD64MAGIC
1217
      magic = AMD64MAGIC;
1218
#endif
1219
6.73k
      break;
1220
1221
7
    case IMAGE_FILE_MACHINE_R3000:
1222
12
    case IMAGE_FILE_MACHINE_R4000:
1223
117
    case IMAGE_FILE_MACHINE_R10000:
1224
1225
122
    case IMAGE_FILE_MACHINE_MIPS16:
1226
126
    case IMAGE_FILE_MACHINE_MIPSFPU:
1227
129
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1228
#ifdef MIPS_ARCH_MAGIC_WINCE
1229
      magic = MIPS_ARCH_MAGIC_WINCE;
1230
#endif
1231
129
      break;
1232
1233
2.03k
    case IMAGE_FILE_MACHINE_SH3:
1234
4.63k
    case IMAGE_FILE_MACHINE_SH4:
1235
#ifdef SH_ARCH_MAGIC_WINCE
1236
      magic = SH_ARCH_MAGIC_WINCE;
1237
#endif
1238
4.63k
      break;
1239
1240
7.39k
    case IMAGE_FILE_MACHINE_ARM:
1241
7.39k
#ifdef ARMPEMAGIC
1242
7.39k
      magic = ARMPEMAGIC;
1243
7.39k
#endif
1244
7.39k
      break;
1245
1246
1.23k
    case IMAGE_FILE_MACHINE_ARM64:
1247
#ifdef AARCH64MAGIC
1248
      magic = AARCH64MAGIC;
1249
#endif
1250
1.23k
      break;
1251
1252
6.05k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1253
#ifdef LOONGARCH64MAGIC
1254
      magic = LOONGARCH64MAGIC;
1255
#endif
1256
6.05k
      break;
1257
1258
1.88k
    case IMAGE_FILE_MACHINE_THUMB:
1259
1.88k
#ifdef THUMBPEMAGIC
1260
1.88k
      {
1261
1.88k
  extern const bfd_target TARGET_LITTLE_SYM;
1262
1263
1.88k
  if (abfd->xvec == & TARGET_LITTLE_SYM)
1264
1.87k
    magic = THUMBPEMAGIC;
1265
1.88k
      }
1266
1.88k
#endif
1267
1.88k
      break;
1268
1269
0
    case IMAGE_FILE_MACHINE_POWERPC:
1270
      /* We no longer support PowerPC.  */
1271
2.78k
    default:
1272
2.78k
      _bfd_error_handler
1273
  /* xgettext:c-format */
1274
2.78k
  (_("%pB: unrecognised machine type (0x%x)"
1275
2.78k
     " in Import Library Format archive"),
1276
2.78k
   abfd, machine);
1277
2.78k
      bfd_set_error (bfd_error_malformed_archive);
1278
1279
2.78k
      return NULL;
1280
0
      break;
1281
37.3k
    }
1282
1283
34.5k
  if (magic == 0)
1284
25.3k
    {
1285
25.3k
      _bfd_error_handler
1286
  /* xgettext:c-format */
1287
25.3k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1288
25.3k
     " in Import Library Format archive"),
1289
25.3k
   abfd, machine);
1290
25.3k
      bfd_set_error (bfd_error_wrong_format);
1291
1292
25.3k
      return NULL;
1293
25.3k
    }
1294
1295
  /* We do not bother to check the date.
1296
     date = H_GET_32 (abfd, ptr);  */
1297
9.27k
  ptr += 4;
1298
1299
9.27k
  size = H_GET_32 (abfd, ptr);
1300
9.27k
  ptr += 4;
1301
1302
9.27k
  if (size == 0)
1303
321
    {
1304
321
      _bfd_error_handler
1305
321
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1306
321
      bfd_set_error (bfd_error_malformed_archive);
1307
1308
321
      return NULL;
1309
321
    }
1310
1311
8.95k
  ordinal = H_GET_16 (abfd, ptr);
1312
8.95k
  ptr += 2;
1313
1314
8.95k
  types = H_GET_16 (abfd, ptr);
1315
  /* ptr += 2; */
1316
1317
  /* Now read in the two strings that follow.  */
1318
8.95k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1319
8.95k
  if (ptr == NULL)
1320
1.54k
    return NULL;
1321
1322
7.40k
  symbol_name = (char *) ptr;
1323
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1324
7.40k
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1325
1326
  /* Verify that the strings are null terminated.  */
1327
7.40k
  if (ptr[size - 1] != 0
1328
7.40k
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1329
748
    {
1330
748
      _bfd_error_handler
1331
748
  (_("%pB: string not null terminated in ILF object file"), abfd);
1332
748
      bfd_set_error (bfd_error_malformed_archive);
1333
748
      bfd_release (abfd, ptr);
1334
748
      return NULL;
1335
748
    }
1336
1337
  /* Now construct the bfd.  */
1338
6.65k
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1339
6.65k
          source_dll, ordinal, types))
1340
1.38k
    {
1341
1.38k
      bfd_release (abfd, ptr);
1342
1.38k
      return NULL;
1343
1.38k
    }
1344
1345
5.27k
  return pe_ILF_cleanup;
1346
6.65k
}
pei-mcore.c:pe_ILF_object_p
Line
Count
Source
1177
28.9k
{
1178
28.9k
  bfd_byte    buffer[14];
1179
28.9k
  bfd_byte *    ptr;
1180
28.9k
  char *    symbol_name;
1181
28.9k
  char *    source_dll;
1182
28.9k
  unsigned int    machine;
1183
28.9k
  bfd_size_type   size;
1184
28.9k
  unsigned int    ordinal;
1185
28.9k
  unsigned int    types;
1186
28.9k
  unsigned int    magic;
1187
1188
  /* Upon entry the first six bytes of the ILF header have
1189
     already been read.  Now read the rest of the header.  */
1190
28.9k
  if (bfd_bread (buffer, (bfd_size_type) 14, abfd) != 14)
1191
462
    return NULL;
1192
1193
28.4k
  ptr = buffer;
1194
1195
28.4k
  machine = H_GET_16 (abfd, ptr);
1196
28.4k
  ptr += 2;
1197
1198
  /* Check that the machine type is recognised.  */
1199
28.4k
  magic = 0;
1200
1201
28.4k
  switch (machine)
1202
28.4k
    {
1203
350
    case IMAGE_FILE_MACHINE_UNKNOWN:
1204
354
    case IMAGE_FILE_MACHINE_ALPHA:
1205
358
    case IMAGE_FILE_MACHINE_ALPHA64:
1206
372
    case IMAGE_FILE_MACHINE_IA64:
1207
372
      break;
1208
1209
2.43k
    case IMAGE_FILE_MACHINE_I386:
1210
#ifdef I386MAGIC
1211
      magic = I386MAGIC;
1212
#endif
1213
2.43k
      break;
1214
1215
6.73k
    case IMAGE_FILE_MACHINE_AMD64:
1216
#ifdef AMD64MAGIC
1217
      magic = AMD64MAGIC;
1218
#endif
1219
6.73k
      break;
1220
1221
7
    case IMAGE_FILE_MACHINE_R3000:
1222
12
    case IMAGE_FILE_MACHINE_R4000:
1223
117
    case IMAGE_FILE_MACHINE_R10000:
1224
1225
122
    case IMAGE_FILE_MACHINE_MIPS16:
1226
126
    case IMAGE_FILE_MACHINE_MIPSFPU:
1227
129
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1228
#ifdef MIPS_ARCH_MAGIC_WINCE
1229
      magic = MIPS_ARCH_MAGIC_WINCE;
1230
#endif
1231
129
      break;
1232
1233
2.03k
    case IMAGE_FILE_MACHINE_SH3:
1234
4.63k
    case IMAGE_FILE_MACHINE_SH4:
1235
#ifdef SH_ARCH_MAGIC_WINCE
1236
      magic = SH_ARCH_MAGIC_WINCE;
1237
#endif
1238
4.63k
      break;
1239
1240
3.42k
    case IMAGE_FILE_MACHINE_ARM:
1241
#ifdef ARMPEMAGIC
1242
      magic = ARMPEMAGIC;
1243
#endif
1244
3.42k
      break;
1245
1246
1.23k
    case IMAGE_FILE_MACHINE_ARM64:
1247
#ifdef AARCH64MAGIC
1248
      magic = AARCH64MAGIC;
1249
#endif
1250
1.23k
      break;
1251
1252
6.05k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1253
#ifdef LOONGARCH64MAGIC
1254
      magic = LOONGARCH64MAGIC;
1255
#endif
1256
6.05k
      break;
1257
1258
682
    case IMAGE_FILE_MACHINE_THUMB:
1259
#ifdef THUMBPEMAGIC
1260
      {
1261
  extern const bfd_target TARGET_LITTLE_SYM;
1262
1263
  if (abfd->xvec == & TARGET_LITTLE_SYM)
1264
    magic = THUMBPEMAGIC;
1265
      }
1266
#endif
1267
682
      break;
1268
1269
0
    case IMAGE_FILE_MACHINE_POWERPC:
1270
      /* We no longer support PowerPC.  */
1271
2.78k
    default:
1272
2.78k
      _bfd_error_handler
1273
  /* xgettext:c-format */
1274
2.78k
  (_("%pB: unrecognised machine type (0x%x)"
1275
2.78k
     " in Import Library Format archive"),
1276
2.78k
   abfd, machine);
1277
2.78k
      bfd_set_error (bfd_error_malformed_archive);
1278
1279
2.78k
      return NULL;
1280
0
      break;
1281
28.4k
    }
1282
1283
25.6k
  if (magic == 0)
1284
25.6k
    {
1285
25.6k
      _bfd_error_handler
1286
  /* xgettext:c-format */
1287
25.6k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1288
25.6k
     " in Import Library Format archive"),
1289
25.6k
   abfd, machine);
1290
25.6k
      bfd_set_error (bfd_error_wrong_format);
1291
1292
25.6k
      return NULL;
1293
25.6k
    }
1294
1295
  /* We do not bother to check the date.
1296
     date = H_GET_32 (abfd, ptr);  */
1297
0
  ptr += 4;
1298
1299
0
  size = H_GET_32 (abfd, ptr);
1300
0
  ptr += 4;
1301
1302
0
  if (size == 0)
1303
0
    {
1304
0
      _bfd_error_handler
1305
0
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1306
0
      bfd_set_error (bfd_error_malformed_archive);
1307
1308
0
      return NULL;
1309
0
    }
1310
1311
0
  ordinal = H_GET_16 (abfd, ptr);
1312
0
  ptr += 2;
1313
1314
0
  types = H_GET_16 (abfd, ptr);
1315
  /* ptr += 2; */
1316
1317
  /* Now read in the two strings that follow.  */
1318
0
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1319
0
  if (ptr == NULL)
1320
0
    return NULL;
1321
1322
0
  symbol_name = (char *) ptr;
1323
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1324
0
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1325
1326
  /* Verify that the strings are null terminated.  */
1327
0
  if (ptr[size - 1] != 0
1328
0
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1329
0
    {
1330
0
      _bfd_error_handler
1331
0
  (_("%pB: string not null terminated in ILF object file"), abfd);
1332
0
      bfd_set_error (bfd_error_malformed_archive);
1333
0
      bfd_release (abfd, ptr);
1334
0
      return NULL;
1335
0
    }
1336
1337
  /* Now construct the bfd.  */
1338
0
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1339
0
          source_dll, ordinal, types))
1340
0
    {
1341
0
      bfd_release (abfd, ptr);
1342
0
      return NULL;
1343
0
    }
1344
1345
0
  return pe_ILF_cleanup;
1346
0
}
pei-sh.c:pe_ILF_object_p
Line
Count
Source
1177
28.7k
{
1178
28.7k
  bfd_byte    buffer[14];
1179
28.7k
  bfd_byte *    ptr;
1180
28.7k
  char *    symbol_name;
1181
28.7k
  char *    source_dll;
1182
28.7k
  unsigned int    machine;
1183
28.7k
  bfd_size_type   size;
1184
28.7k
  unsigned int    ordinal;
1185
28.7k
  unsigned int    types;
1186
28.7k
  unsigned int    magic;
1187
1188
  /* Upon entry the first six bytes of the ILF header have
1189
     already been read.  Now read the rest of the header.  */
1190
28.7k
  if (bfd_bread (buffer, (bfd_size_type) 14, abfd) != 14)
1191
454
    return NULL;
1192
1193
28.3k
  ptr = buffer;
1194
1195
28.3k
  machine = H_GET_16 (abfd, ptr);
1196
28.3k
  ptr += 2;
1197
1198
  /* Check that the machine type is recognised.  */
1199
28.3k
  magic = 0;
1200
1201
28.3k
  switch (machine)
1202
28.3k
    {
1203
343
    case IMAGE_FILE_MACHINE_UNKNOWN:
1204
347
    case IMAGE_FILE_MACHINE_ALPHA:
1205
351
    case IMAGE_FILE_MACHINE_ALPHA64:
1206
363
    case IMAGE_FILE_MACHINE_IA64:
1207
363
      break;
1208
1209
2.43k
    case IMAGE_FILE_MACHINE_I386:
1210
#ifdef I386MAGIC
1211
      magic = I386MAGIC;
1212
#endif
1213
2.43k
      break;
1214
1215
6.73k
    case IMAGE_FILE_MACHINE_AMD64:
1216
#ifdef AMD64MAGIC
1217
      magic = AMD64MAGIC;
1218
#endif
1219
6.73k
      break;
1220
1221
7
    case IMAGE_FILE_MACHINE_R3000:
1222
11
    case IMAGE_FILE_MACHINE_R4000:
1223
116
    case IMAGE_FILE_MACHINE_R10000:
1224
1225
118
    case IMAGE_FILE_MACHINE_MIPS16:
1226
121
    case IMAGE_FILE_MACHINE_MIPSFPU:
1227
124
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1228
#ifdef MIPS_ARCH_MAGIC_WINCE
1229
      magic = MIPS_ARCH_MAGIC_WINCE;
1230
#endif
1231
124
      break;
1232
1233
2.04k
    case IMAGE_FILE_MACHINE_SH3:
1234
4.64k
    case IMAGE_FILE_MACHINE_SH4:
1235
4.64k
#ifdef SH_ARCH_MAGIC_WINCE
1236
4.64k
      magic = SH_ARCH_MAGIC_WINCE;
1237
4.64k
#endif
1238
4.64k
      break;
1239
1240
3.35k
    case IMAGE_FILE_MACHINE_ARM:
1241
#ifdef ARMPEMAGIC
1242
      magic = ARMPEMAGIC;
1243
#endif
1244
3.35k
      break;
1245
1246
1.23k
    case IMAGE_FILE_MACHINE_ARM64:
1247
#ifdef AARCH64MAGIC
1248
      magic = AARCH64MAGIC;
1249
#endif
1250
1.23k
      break;
1251
1252
6.05k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1253
#ifdef LOONGARCH64MAGIC
1254
      magic = LOONGARCH64MAGIC;
1255
#endif
1256
6.05k
      break;
1257
1258
676
    case IMAGE_FILE_MACHINE_THUMB:
1259
#ifdef THUMBPEMAGIC
1260
      {
1261
  extern const bfd_target TARGET_LITTLE_SYM;
1262
1263
  if (abfd->xvec == & TARGET_LITTLE_SYM)
1264
    magic = THUMBPEMAGIC;
1265
      }
1266
#endif
1267
676
      break;
1268
1269
0
    case IMAGE_FILE_MACHINE_POWERPC:
1270
      /* We no longer support PowerPC.  */
1271
2.72k
    default:
1272
2.72k
      _bfd_error_handler
1273
  /* xgettext:c-format */
1274
2.72k
  (_("%pB: unrecognised machine type (0x%x)"
1275
2.72k
     " in Import Library Format archive"),
1276
2.72k
   abfd, machine);
1277
2.72k
      bfd_set_error (bfd_error_malformed_archive);
1278
1279
2.72k
      return NULL;
1280
0
      break;
1281
28.3k
    }
1282
1283
25.6k
  if (magic == 0)
1284
20.9k
    {
1285
20.9k
      _bfd_error_handler
1286
  /* xgettext:c-format */
1287
20.9k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1288
20.9k
     " in Import Library Format archive"),
1289
20.9k
   abfd, machine);
1290
20.9k
      bfd_set_error (bfd_error_wrong_format);
1291
1292
20.9k
      return NULL;
1293
20.9k
    }
1294
1295
  /* We do not bother to check the date.
1296
     date = H_GET_32 (abfd, ptr);  */
1297
4.64k
  ptr += 4;
1298
1299
4.64k
  size = H_GET_32 (abfd, ptr);
1300
4.64k
  ptr += 4;
1301
1302
4.64k
  if (size == 0)
1303
319
    {
1304
319
      _bfd_error_handler
1305
319
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1306
319
      bfd_set_error (bfd_error_malformed_archive);
1307
1308
319
      return NULL;
1309
319
    }
1310
1311
4.32k
  ordinal = H_GET_16 (abfd, ptr);
1312
4.32k
  ptr += 2;
1313
1314
4.32k
  types = H_GET_16 (abfd, ptr);
1315
  /* ptr += 2; */
1316
1317
  /* Now read in the two strings that follow.  */
1318
4.32k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1319
4.32k
  if (ptr == NULL)
1320
584
    return NULL;
1321
1322
3.74k
  symbol_name = (char *) ptr;
1323
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1324
3.74k
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1325
1326
  /* Verify that the strings are null terminated.  */
1327
3.74k
  if (ptr[size - 1] != 0
1328
3.74k
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1329
247
    {
1330
247
      _bfd_error_handler
1331
247
  (_("%pB: string not null terminated in ILF object file"), abfd);
1332
247
      bfd_set_error (bfd_error_malformed_archive);
1333
247
      bfd_release (abfd, ptr);
1334
247
      return NULL;
1335
247
    }
1336
1337
  /* Now construct the bfd.  */
1338
3.49k
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1339
3.49k
          source_dll, ordinal, types))
1340
472
    {
1341
472
      bfd_release (abfd, ptr);
1342
472
      return NULL;
1343
472
    }
1344
1345
3.02k
  return pe_ILF_cleanup;
1346
3.49k
}
1347
1348
static void
1349
pe_bfd_read_buildid (bfd *abfd)
1350
314k
{
1351
314k
  pe_data_type *pe = pe_data (abfd);
1352
314k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1353
314k
  asection *section;
1354
314k
  bfd_byte *data = 0;
1355
314k
  bfd_size_type dataoff;
1356
314k
  unsigned int i;
1357
314k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1358
314k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1359
1360
314k
  if (size == 0)
1361
105k
    return;
1362
1363
208k
  addr += extra->ImageBase;
1364
1365
  /* Search for the section containing the DebugDirectory.  */
1366
933k
  for (section = abfd->sections; section != NULL; section = section->next)
1367
825k
    {
1368
825k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1369
100k
  break;
1370
825k
    }
1371
1372
208k
  if (section == NULL)
1373
108k
    return;
1374
1375
100k
  if (!(section->flags & SEC_HAS_CONTENTS))
1376
11.4k
    return;
1377
1378
89.0k
  dataoff = addr - section->vma;
1379
1380
  /* PR 20605 and 22373: Make sure that the data is really there.
1381
     Note - since we are dealing with unsigned quantities we have
1382
     to be careful to check for potential overflows.  */
1383
89.0k
  if (dataoff >= section->size
1384
89.0k
      || size > section->size - dataoff)
1385
36.0k
    {
1386
36.0k
      _bfd_error_handler
1387
36.0k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1388
36.0k
   abfd);
1389
36.0k
      return;
1390
36.0k
    }
1391
1392
  /* Read the whole section. */
1393
53.0k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1394
27.2k
    {
1395
27.2k
      free (data);
1396
27.2k
      return;
1397
27.2k
    }
1398
1399
  /* Search for a CodeView entry in the DebugDirectory */
1400
7.76M
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1401
7.74M
    {
1402
7.74M
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1403
7.74M
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1404
7.74M
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1405
1406
7.74M
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1407
1408
7.74M
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1409
13.6k
  {
1410
13.6k
    char buffer[256 + 1];
1411
13.6k
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1412
1413
    /*
1414
      The debug entry doesn't have to have to be in a section, in which
1415
      case AddressOfRawData is 0, so always use PointerToRawData.
1416
    */
1417
13.6k
    if (_bfd_XXi_slurp_codeview_record (abfd,
1418
13.6k
                (file_ptr) idd.PointerToRawData,
1419
13.6k
                idd.SizeOfData, cvinfo, NULL))
1420
66
      {
1421
66
        struct bfd_build_id* build_id = bfd_alloc (abfd,
1422
66
       sizeof (struct bfd_build_id) + cvinfo->SignatureLength);
1423
66
        if (build_id)
1424
66
    {
1425
66
      build_id->size = cvinfo->SignatureLength;
1426
66
      memcpy(build_id->data,  cvinfo->Signature,
1427
66
       cvinfo->SignatureLength);
1428
66
      abfd->build_id = build_id;
1429
66
    }
1430
66
      }
1431
13.6k
    break;
1432
13.6k
  }
1433
7.74M
    }
1434
1435
25.7k
  free (data);
1436
25.7k
}
pei-i386.c:pe_bfd_read_buildid
Line
Count
Source
1350
39.6k
{
1351
39.6k
  pe_data_type *pe = pe_data (abfd);
1352
39.6k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1353
39.6k
  asection *section;
1354
39.6k
  bfd_byte *data = 0;
1355
39.6k
  bfd_size_type dataoff;
1356
39.6k
  unsigned int i;
1357
39.6k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1358
39.6k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1359
1360
39.6k
  if (size == 0)
1361
21.3k
    return;
1362
1363
18.2k
  addr += extra->ImageBase;
1364
1365
  /* Search for the section containing the DebugDirectory.  */
1366
38.7k
  for (section = abfd->sections; section != NULL; section = section->next)
1367
29.5k
    {
1368
29.5k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1369
9.13k
  break;
1370
29.5k
    }
1371
1372
18.2k
  if (section == NULL)
1373
9.12k
    return;
1374
1375
9.13k
  if (!(section->flags & SEC_HAS_CONTENTS))
1376
790
    return;
1377
1378
8.34k
  dataoff = addr - section->vma;
1379
1380
  /* PR 20605 and 22373: Make sure that the data is really there.
1381
     Note - since we are dealing with unsigned quantities we have
1382
     to be careful to check for potential overflows.  */
1383
8.34k
  if (dataoff >= section->size
1384
8.34k
      || size > section->size - dataoff)
1385
4.78k
    {
1386
4.78k
      _bfd_error_handler
1387
4.78k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1388
4.78k
   abfd);
1389
4.78k
      return;
1390
4.78k
    }
1391
1392
  /* Read the whole section. */
1393
3.56k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1394
2.45k
    {
1395
2.45k
      free (data);
1396
2.45k
      return;
1397
2.45k
    }
1398
1399
  /* Search for a CodeView entry in the DebugDirectory */
1400
3.58k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1401
3.02k
    {
1402
3.02k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1403
3.02k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1404
3.02k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1405
1406
3.02k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1407
1408
3.02k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1409
549
  {
1410
549
    char buffer[256 + 1];
1411
549
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1412
1413
    /*
1414
      The debug entry doesn't have to have to be in a section, in which
1415
      case AddressOfRawData is 0, so always use PointerToRawData.
1416
    */
1417
549
    if (_bfd_XXi_slurp_codeview_record (abfd,
1418
549
                (file_ptr) idd.PointerToRawData,
1419
549
                idd.SizeOfData, cvinfo, NULL))
1420
20
      {
1421
20
        struct bfd_build_id* build_id = bfd_alloc (abfd,
1422
20
       sizeof (struct bfd_build_id) + cvinfo->SignatureLength);
1423
20
        if (build_id)
1424
20
    {
1425
20
      build_id->size = cvinfo->SignatureLength;
1426
20
      memcpy(build_id->data,  cvinfo->Signature,
1427
20
       cvinfo->SignatureLength);
1428
20
      abfd->build_id = build_id;
1429
20
    }
1430
20
      }
1431
549
    break;
1432
549
  }
1433
3.02k
    }
1434
1435
1.11k
  free (data);
1436
1.11k
}
pei-x86_64.c:pe_bfd_read_buildid
Line
Count
Source
1350
56.0k
{
1351
56.0k
  pe_data_type *pe = pe_data (abfd);
1352
56.0k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1353
56.0k
  asection *section;
1354
56.0k
  bfd_byte *data = 0;
1355
56.0k
  bfd_size_type dataoff;
1356
56.0k
  unsigned int i;
1357
56.0k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1358
56.0k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1359
1360
56.0k
  if (size == 0)
1361
24.1k
    return;
1362
1363
31.8k
  addr += extra->ImageBase;
1364
1365
  /* Search for the section containing the DebugDirectory.  */
1366
91.2k
  for (section = abfd->sections; section != NULL; section = section->next)
1367
77.9k
    {
1368
77.9k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1369
18.4k
  break;
1370
77.9k
    }
1371
1372
31.8k
  if (section == NULL)
1373
13.3k
    return;
1374
1375
18.4k
  if (!(section->flags & SEC_HAS_CONTENTS))
1376
1.85k
    return;
1377
1378
16.6k
  dataoff = addr - section->vma;
1379
1380
  /* PR 20605 and 22373: Make sure that the data is really there.
1381
     Note - since we are dealing with unsigned quantities we have
1382
     to be careful to check for potential overflows.  */
1383
16.6k
  if (dataoff >= section->size
1384
16.6k
      || size > section->size - dataoff)
1385
3.87k
    {
1386
3.87k
      _bfd_error_handler
1387
3.87k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1388
3.87k
   abfd);
1389
3.87k
      return;
1390
3.87k
    }
1391
1392
  /* Read the whole section. */
1393
12.7k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1394
4.24k
    {
1395
4.24k
      free (data);
1396
4.24k
      return;
1397
4.24k
    }
1398
1399
  /* Search for a CodeView entry in the DebugDirectory */
1400
7.34M
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1401
7.33M
    {
1402
7.33M
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1403
7.33M
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1404
7.33M
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1405
1406
7.33M
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1407
1408
7.33M
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1409
6.26k
  {
1410
6.26k
    char buffer[256 + 1];
1411
6.26k
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1412
1413
    /*
1414
      The debug entry doesn't have to have to be in a section, in which
1415
      case AddressOfRawData is 0, so always use PointerToRawData.
1416
    */
1417
6.26k
    if (_bfd_XXi_slurp_codeview_record (abfd,
1418
6.26k
                (file_ptr) idd.PointerToRawData,
1419
6.26k
                idd.SizeOfData, cvinfo, NULL))
1420
35
      {
1421
35
        struct bfd_build_id* build_id = bfd_alloc (abfd,
1422
35
       sizeof (struct bfd_build_id) + cvinfo->SignatureLength);
1423
35
        if (build_id)
1424
35
    {
1425
35
      build_id->size = cvinfo->SignatureLength;
1426
35
      memcpy(build_id->data,  cvinfo->Signature,
1427
35
       cvinfo->SignatureLength);
1428
35
      abfd->build_id = build_id;
1429
35
    }
1430
35
      }
1431
6.26k
    break;
1432
6.26k
  }
1433
7.33M
    }
1434
1435
8.51k
  free (data);
1436
8.51k
}
pei-aarch64.c:pe_bfd_read_buildid
Line
Count
Source
1350
32.2k
{
1351
32.2k
  pe_data_type *pe = pe_data (abfd);
1352
32.2k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1353
32.2k
  asection *section;
1354
32.2k
  bfd_byte *data = 0;
1355
32.2k
  bfd_size_type dataoff;
1356
32.2k
  unsigned int i;
1357
32.2k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1358
32.2k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1359
1360
32.2k
  if (size == 0)
1361
8.04k
    return;
1362
1363
24.1k
  addr += extra->ImageBase;
1364
1365
  /* Search for the section containing the DebugDirectory.  */
1366
57.6k
  for (section = abfd->sections; section != NULL; section = section->next)
1367
43.3k
    {
1368
43.3k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1369
9.80k
  break;
1370
43.3k
    }
1371
1372
24.1k
  if (section == NULL)
1373
14.3k
    return;
1374
1375
9.80k
  if (!(section->flags & SEC_HAS_CONTENTS))
1376
1.32k
    return;
1377
1378
8.47k
  dataoff = addr - section->vma;
1379
1380
  /* PR 20605 and 22373: Make sure that the data is really there.
1381
     Note - since we are dealing with unsigned quantities we have
1382
     to be careful to check for potential overflows.  */
1383
8.47k
  if (dataoff >= section->size
1384
8.47k
      || size > section->size - dataoff)
1385
4.73k
    {
1386
4.73k
      _bfd_error_handler
1387
4.73k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1388
4.73k
   abfd);
1389
4.73k
      return;
1390
4.73k
    }
1391
1392
  /* Read the whole section. */
1393
3.74k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1394
2.50k
    {
1395
2.50k
      free (data);
1396
2.50k
      return;
1397
2.50k
    }
1398
1399
  /* Search for a CodeView entry in the DebugDirectory */
1400
159k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1401
158k
    {
1402
158k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1403
158k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1404
158k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1405
1406
158k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1407
1408
158k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1409
239
  {
1410
239
    char buffer[256 + 1];
1411
239
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1412
1413
    /*
1414
      The debug entry doesn't have to have to be in a section, in which
1415
      case AddressOfRawData is 0, so always use PointerToRawData.
1416
    */
1417
239
    if (_bfd_XXi_slurp_codeview_record (abfd,
1418
239
                (file_ptr) idd.PointerToRawData,
1419
239
                idd.SizeOfData, cvinfo, NULL))
1420
1
      {
1421
1
        struct bfd_build_id* build_id = bfd_alloc (abfd,
1422
1
       sizeof (struct bfd_build_id) + cvinfo->SignatureLength);
1423
1
        if (build_id)
1424
1
    {
1425
1
      build_id->size = cvinfo->SignatureLength;
1426
1
      memcpy(build_id->data,  cvinfo->Signature,
1427
1
       cvinfo->SignatureLength);
1428
1
      abfd->build_id = build_id;
1429
1
    }
1430
1
      }
1431
239
    break;
1432
239
  }
1433
158k
    }
1434
1435
1.23k
  free (data);
1436
1.23k
}
pei-ia64.c:pe_bfd_read_buildid
Line
Count
Source
1350
36.5k
{
1351
36.5k
  pe_data_type *pe = pe_data (abfd);
1352
36.5k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1353
36.5k
  asection *section;
1354
36.5k
  bfd_byte *data = 0;
1355
36.5k
  bfd_size_type dataoff;
1356
36.5k
  unsigned int i;
1357
36.5k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1358
36.5k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1359
1360
36.5k
  if (size == 0)
1361
13.0k
    return;
1362
1363
23.4k
  addr += extra->ImageBase;
1364
1365
  /* Search for the section containing the DebugDirectory.  */
1366
74.1k
  for (section = abfd->sections; section != NULL; section = section->next)
1367
58.9k
    {
1368
58.9k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1369
8.25k
  break;
1370
58.9k
    }
1371
1372
23.4k
  if (section == NULL)
1373
15.1k
    return;
1374
1375
8.25k
  if (!(section->flags & SEC_HAS_CONTENTS))
1376
937
    return;
1377
1378
7.31k
  dataoff = addr - section->vma;
1379
1380
  /* PR 20605 and 22373: Make sure that the data is really there.
1381
     Note - since we are dealing with unsigned quantities we have
1382
     to be careful to check for potential overflows.  */
1383
7.31k
  if (dataoff >= section->size
1384
7.31k
      || size > section->size - dataoff)
1385
3.43k
    {
1386
3.43k
      _bfd_error_handler
1387
3.43k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1388
3.43k
   abfd);
1389
3.43k
      return;
1390
3.43k
    }
1391
1392
  /* Read the whole section. */
1393
3.88k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1394
2.02k
    {
1395
2.02k
      free (data);
1396
2.02k
      return;
1397
2.02k
    }
1398
1399
  /* Search for a CodeView entry in the DebugDirectory */
1400
27.7k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1401
27.1k
    {
1402
27.1k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1403
27.1k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1404
27.1k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1405
1406
27.1k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1407
1408
27.1k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1409
1.32k
  {
1410
1.32k
    char buffer[256 + 1];
1411
1.32k
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1412
1413
    /*
1414
      The debug entry doesn't have to have to be in a section, in which
1415
      case AddressOfRawData is 0, so always use PointerToRawData.
1416
    */
1417
1.32k
    if (_bfd_XXi_slurp_codeview_record (abfd,
1418
1.32k
                (file_ptr) idd.PointerToRawData,
1419
1.32k
                idd.SizeOfData, cvinfo, NULL))
1420
0
      {
1421
0
        struct bfd_build_id* build_id = bfd_alloc (abfd,
1422
0
       sizeof (struct bfd_build_id) + cvinfo->SignatureLength);
1423
0
        if (build_id)
1424
0
    {
1425
0
      build_id->size = cvinfo->SignatureLength;
1426
0
      memcpy(build_id->data,  cvinfo->Signature,
1427
0
       cvinfo->SignatureLength);
1428
0
      abfd->build_id = build_id;
1429
0
    }
1430
0
      }
1431
1.32k
    break;
1432
1.32k
  }
1433
27.1k
    }
1434
1435
1.85k
  free (data);
1436
1.85k
}
pei-loongarch64.c:pe_bfd_read_buildid
Line
Count
Source
1350
33.4k
{
1351
33.4k
  pe_data_type *pe = pe_data (abfd);
1352
33.4k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1353
33.4k
  asection *section;
1354
33.4k
  bfd_byte *data = 0;
1355
33.4k
  bfd_size_type dataoff;
1356
33.4k
  unsigned int i;
1357
33.4k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1358
33.4k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1359
1360
33.4k
  if (size == 0)
1361
9.78k
    return;
1362
1363
23.7k
  addr += extra->ImageBase;
1364
1365
  /* Search for the section containing the DebugDirectory.  */
1366
95.8k
  for (section = abfd->sections; section != NULL; section = section->next)
1367
80.1k
    {
1368
80.1k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1369
8.05k
  break;
1370
80.1k
    }
1371
1372
23.7k
  if (section == NULL)
1373
15.6k
    return;
1374
1375
8.05k
  if (!(section->flags & SEC_HAS_CONTENTS))
1376
601
    return;
1377
1378
7.45k
  dataoff = addr - section->vma;
1379
1380
  /* PR 20605 and 22373: Make sure that the data is really there.
1381
     Note - since we are dealing with unsigned quantities we have
1382
     to be careful to check for potential overflows.  */
1383
7.45k
  if (dataoff >= section->size
1384
7.45k
      || size > section->size - dataoff)
1385
2.24k
    {
1386
2.24k
      _bfd_error_handler
1387
2.24k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1388
2.24k
   abfd);
1389
2.24k
      return;
1390
2.24k
    }
1391
1392
  /* Read the whole section. */
1393
5.20k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1394
1.68k
    {
1395
1.68k
      free (data);
1396
1.68k
      return;
1397
1.68k
    }
1398
1399
  /* Search for a CodeView entry in the DebugDirectory */
1400
36.4k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1401
33.7k
    {
1402
33.7k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1403
33.7k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1404
33.7k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1405
1406
33.7k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1407
1408
33.7k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1409
812
  {
1410
812
    char buffer[256 + 1];
1411
812
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1412
1413
    /*
1414
      The debug entry doesn't have to have to be in a section, in which
1415
      case AddressOfRawData is 0, so always use PointerToRawData.
1416
    */
1417
812
    if (_bfd_XXi_slurp_codeview_record (abfd,
1418
812
                (file_ptr) idd.PointerToRawData,
1419
812
                idd.SizeOfData, cvinfo, NULL))
1420
1
      {
1421
1
        struct bfd_build_id* build_id = bfd_alloc (abfd,
1422
1
       sizeof (struct bfd_build_id) + cvinfo->SignatureLength);
1423
1
        if (build_id)
1424
1
    {
1425
1
      build_id->size = cvinfo->SignatureLength;
1426
1
      memcpy(build_id->data,  cvinfo->Signature,
1427
1
       cvinfo->SignatureLength);
1428
1
      abfd->build_id = build_id;
1429
1
    }
1430
1
      }
1431
812
    break;
1432
812
  }
1433
33.7k
    }
1434
1435
3.51k
  free (data);
1436
3.51k
}
pei-arm-wince.c:pe_bfd_read_buildid
Line
Count
Source
1350
18.2k
{
1351
18.2k
  pe_data_type *pe = pe_data (abfd);
1352
18.2k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1353
18.2k
  asection *section;
1354
18.2k
  bfd_byte *data = 0;
1355
18.2k
  bfd_size_type dataoff;
1356
18.2k
  unsigned int i;
1357
18.2k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1358
18.2k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1359
1360
18.2k
  if (size == 0)
1361
2.11k
    return;
1362
1363
16.1k
  addr += extra->ImageBase;
1364
1365
  /* Search for the section containing the DebugDirectory.  */
1366
42.2k
  for (section = abfd->sections; section != NULL; section = section->next)
1367
35.6k
    {
1368
35.6k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1369
9.49k
  break;
1370
35.6k
    }
1371
1372
16.1k
  if (section == NULL)
1373
6.64k
    return;
1374
1375
9.49k
  if (!(section->flags & SEC_HAS_CONTENTS))
1376
1.11k
    return;
1377
1378
8.37k
  dataoff = addr - section->vma;
1379
1380
  /* PR 20605 and 22373: Make sure that the data is really there.
1381
     Note - since we are dealing with unsigned quantities we have
1382
     to be careful to check for potential overflows.  */
1383
8.37k
  if (dataoff >= section->size
1384
8.37k
      || size > section->size - dataoff)
1385
3.27k
    {
1386
3.27k
      _bfd_error_handler
1387
3.27k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1388
3.27k
   abfd);
1389
3.27k
      return;
1390
3.27k
    }
1391
1392
  /* Read the whole section. */
1393
5.10k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1394
1.40k
    {
1395
1.40k
      free (data);
1396
1.40k
      return;
1397
1.40k
    }
1398
1399
  /* Search for a CodeView entry in the DebugDirectory */
1400
54.4k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1401
52.2k
    {
1402
52.2k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1403
52.2k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1404
52.2k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1405
1406
52.2k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1407
1408
52.2k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1409
1.50k
  {
1410
1.50k
    char buffer[256 + 1];
1411
1.50k
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1412
1413
    /*
1414
      The debug entry doesn't have to have to be in a section, in which
1415
      case AddressOfRawData is 0, so always use PointerToRawData.
1416
    */
1417
1.50k
    if (_bfd_XXi_slurp_codeview_record (abfd,
1418
1.50k
                (file_ptr) idd.PointerToRawData,
1419
1.50k
                idd.SizeOfData, cvinfo, NULL))
1420
1
      {
1421
1
        struct bfd_build_id* build_id = bfd_alloc (abfd,
1422
1
       sizeof (struct bfd_build_id) + cvinfo->SignatureLength);
1423
1
        if (build_id)
1424
1
    {
1425
1
      build_id->size = cvinfo->SignatureLength;
1426
1
      memcpy(build_id->data,  cvinfo->Signature,
1427
1
       cvinfo->SignatureLength);
1428
1
      abfd->build_id = build_id;
1429
1
    }
1430
1
      }
1431
1.50k
    break;
1432
1.50k
  }
1433
52.2k
    }
1434
1435
3.69k
  free (data);
1436
3.69k
}
pei-arm.c:pe_bfd_read_buildid
Line
Count
Source
1350
28.1k
{
1351
28.1k
  pe_data_type *pe = pe_data (abfd);
1352
28.1k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1353
28.1k
  asection *section;
1354
28.1k
  bfd_byte *data = 0;
1355
28.1k
  bfd_size_type dataoff;
1356
28.1k
  unsigned int i;
1357
28.1k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1358
28.1k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1359
1360
28.1k
  if (size == 0)
1361
5.13k
    return;
1362
1363
22.9k
  addr += extra->ImageBase;
1364
1365
  /* Search for the section containing the DebugDirectory.  */
1366
390k
  for (section = abfd->sections; section != NULL; section = section->next)
1367
380k
    {
1368
380k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1369
12.7k
  break;
1370
380k
    }
1371
1372
22.9k
  if (section == NULL)
1373
10.2k
    return;
1374
1375
12.7k
  if (!(section->flags & SEC_HAS_CONTENTS))
1376
1.92k
    return;
1377
1378
10.7k
  dataoff = addr - section->vma;
1379
1380
  /* PR 20605 and 22373: Make sure that the data is really there.
1381
     Note - since we are dealing with unsigned quantities we have
1382
     to be careful to check for potential overflows.  */
1383
10.7k
  if (dataoff >= section->size
1384
10.7k
      || size > section->size - dataoff)
1385
4.65k
    {
1386
4.65k
      _bfd_error_handler
1387
4.65k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1388
4.65k
   abfd);
1389
4.65k
      return;
1390
4.65k
    }
1391
1392
  /* Read the whole section. */
1393
6.13k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1394
4.56k
    {
1395
4.56k
      free (data);
1396
4.56k
      return;
1397
4.56k
    }
1398
1399
  /* Search for a CodeView entry in the DebugDirectory */
1400
43.1k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1401
42.6k
    {
1402
42.6k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1403
42.6k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1404
42.6k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1405
1406
42.6k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1407
1408
42.6k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1409
1.05k
  {
1410
1.05k
    char buffer[256 + 1];
1411
1.05k
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1412
1413
    /*
1414
      The debug entry doesn't have to have to be in a section, in which
1415
      case AddressOfRawData is 0, so always use PointerToRawData.
1416
    */
1417
1.05k
    if (_bfd_XXi_slurp_codeview_record (abfd,
1418
1.05k
                (file_ptr) idd.PointerToRawData,
1419
1.05k
                idd.SizeOfData, cvinfo, NULL))
1420
7
      {
1421
7
        struct bfd_build_id* build_id = bfd_alloc (abfd,
1422
7
       sizeof (struct bfd_build_id) + cvinfo->SignatureLength);
1423
7
        if (build_id)
1424
7
    {
1425
7
      build_id->size = cvinfo->SignatureLength;
1426
7
      memcpy(build_id->data,  cvinfo->Signature,
1427
7
       cvinfo->SignatureLength);
1428
7
      abfd->build_id = build_id;
1429
7
    }
1430
7
      }
1431
1.05k
    break;
1432
1.05k
  }
1433
42.6k
    }
1434
1435
1.57k
  free (data);
1436
1.57k
}
pei-mcore.c:pe_bfd_read_buildid
Line
Count
Source
1350
42.5k
{
1351
42.5k
  pe_data_type *pe = pe_data (abfd);
1352
42.5k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1353
42.5k
  asection *section;
1354
42.5k
  bfd_byte *data = 0;
1355
42.5k
  bfd_size_type dataoff;
1356
42.5k
  unsigned int i;
1357
42.5k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1358
42.5k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1359
1360
42.5k
  if (size == 0)
1361
10.6k
    return;
1362
1363
31.9k
  addr += extra->ImageBase;
1364
1365
  /* Search for the section containing the DebugDirectory.  */
1366
93.4k
  for (section = abfd->sections; section != NULL; section = section->next)
1367
78.4k
    {
1368
78.4k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1369
16.9k
  break;
1370
78.4k
    }
1371
1372
31.9k
  if (section == NULL)
1373
14.9k
    return;
1374
1375
16.9k
  if (!(section->flags & SEC_HAS_CONTENTS))
1376
1.98k
    return;
1377
1378
14.9k
  dataoff = addr - section->vma;
1379
1380
  /* PR 20605 and 22373: Make sure that the data is really there.
1381
     Note - since we are dealing with unsigned quantities we have
1382
     to be careful to check for potential overflows.  */
1383
14.9k
  if (dataoff >= section->size
1384
14.9k
      || size > section->size - dataoff)
1385
5.24k
    {
1386
5.24k
      _bfd_error_handler
1387
5.24k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1388
5.24k
   abfd);
1389
5.24k
      return;
1390
5.24k
    }
1391
1392
  /* Read the whole section. */
1393
9.72k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1394
6.68k
    {
1395
6.68k
      free (data);
1396
6.68k
      return;
1397
6.68k
    }
1398
1399
  /* Search for a CodeView entry in the DebugDirectory */
1400
88.3k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1401
87.0k
    {
1402
87.0k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1403
87.0k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1404
87.0k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1405
1406
87.0k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1407
1408
87.0k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1409
1.71k
  {
1410
1.71k
    char buffer[256 + 1];
1411
1.71k
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1412
1413
    /*
1414
      The debug entry doesn't have to have to be in a section, in which
1415
      case AddressOfRawData is 0, so always use PointerToRawData.
1416
    */
1417
1.71k
    if (_bfd_XXi_slurp_codeview_record (abfd,
1418
1.71k
                (file_ptr) idd.PointerToRawData,
1419
1.71k
                idd.SizeOfData, cvinfo, NULL))
1420
0
      {
1421
0
        struct bfd_build_id* build_id = bfd_alloc (abfd,
1422
0
       sizeof (struct bfd_build_id) + cvinfo->SignatureLength);
1423
0
        if (build_id)
1424
0
    {
1425
0
      build_id->size = cvinfo->SignatureLength;
1426
0
      memcpy(build_id->data,  cvinfo->Signature,
1427
0
       cvinfo->SignatureLength);
1428
0
      abfd->build_id = build_id;
1429
0
    }
1430
0
      }
1431
1.71k
    break;
1432
1.71k
  }
1433
87.0k
    }
1434
1435
3.04k
  free (data);
1436
3.04k
}
pei-sh.c:pe_bfd_read_buildid
Line
Count
Source
1350
27.6k
{
1351
27.6k
  pe_data_type *pe = pe_data (abfd);
1352
27.6k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1353
27.6k
  asection *section;
1354
27.6k
  bfd_byte *data = 0;
1355
27.6k
  bfd_size_type dataoff;
1356
27.6k
  unsigned int i;
1357
27.6k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1358
27.6k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1359
1360
27.6k
  if (size == 0)
1361
11.5k
    return;
1362
1363
16.1k
  addr += extra->ImageBase;
1364
1365
  /* Search for the section containing the DebugDirectory.  */
1366
49.6k
  for (section = abfd->sections; section != NULL; section = section->next)
1367
41.0k
    {
1368
41.0k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1369
7.59k
  break;
1370
41.0k
    }
1371
1372
16.1k
  if (section == NULL)
1373
8.54k
    return;
1374
1375
7.59k
  if (!(section->flags & SEC_HAS_CONTENTS))
1376
892
    return;
1377
1378
6.70k
  dataoff = addr - section->vma;
1379
1380
  /* PR 20605 and 22373: Make sure that the data is really there.
1381
     Note - since we are dealing with unsigned quantities we have
1382
     to be careful to check for potential overflows.  */
1383
6.70k
  if (dataoff >= section->size
1384
6.70k
      || size > section->size - dataoff)
1385
3.76k
    {
1386
3.76k
      _bfd_error_handler
1387
3.76k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1388
3.76k
   abfd);
1389
3.76k
      return;
1390
3.76k
    }
1391
1392
  /* Read the whole section. */
1393
2.93k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1394
1.70k
    {
1395
1.70k
      free (data);
1396
1.70k
      return;
1397
1.70k
    }
1398
1399
  /* Search for a CodeView entry in the DebugDirectory */
1400
6.69k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1401
5.64k
    {
1402
5.64k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1403
5.64k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1404
5.64k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1405
1406
5.64k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1407
1408
5.64k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1409
184
  {
1410
184
    char buffer[256 + 1];
1411
184
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1412
1413
    /*
1414
      The debug entry doesn't have to have to be in a section, in which
1415
      case AddressOfRawData is 0, so always use PointerToRawData.
1416
    */
1417
184
    if (_bfd_XXi_slurp_codeview_record (abfd,
1418
184
                (file_ptr) idd.PointerToRawData,
1419
184
                idd.SizeOfData, cvinfo, NULL))
1420
1
      {
1421
1
        struct bfd_build_id* build_id = bfd_alloc (abfd,
1422
1
       sizeof (struct bfd_build_id) + cvinfo->SignatureLength);
1423
1
        if (build_id)
1424
1
    {
1425
1
      build_id->size = cvinfo->SignatureLength;
1426
1
      memcpy(build_id->data,  cvinfo->Signature,
1427
1
       cvinfo->SignatureLength);
1428
1
      abfd->build_id = build_id;
1429
1
    }
1430
1
      }
1431
184
    break;
1432
184
  }
1433
5.64k
    }
1434
1435
1.23k
  free (data);
1436
1.23k
}
1437
1438
static bfd_cleanup
1439
pe_bfd_object_p (bfd * abfd)
1440
20.4M
{
1441
20.4M
  bfd_byte buffer[6];
1442
20.4M
  struct external_DOS_hdr dos_hdr;
1443
20.4M
  struct external_PEI_IMAGE_hdr image_hdr;
1444
20.4M
  struct internal_filehdr internal_f;
1445
20.4M
  struct internal_aouthdr internal_a;
1446
20.4M
  bfd_size_type opt_hdr_size;
1447
20.4M
  file_ptr offset;
1448
20.4M
  bfd_cleanup result;
1449
1450
  /* Detect if this a Microsoft Import Library Format element.  */
1451
  /* First read the beginning of the header.  */
1452
20.4M
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1453
20.4M
      || bfd_bread (buffer, (bfd_size_type) 6, abfd) != 6)
1454
66.5k
    {
1455
66.5k
      if (bfd_get_error () != bfd_error_system_call)
1456
57.1k
  bfd_set_error (bfd_error_wrong_format);
1457
66.5k
      return NULL;
1458
66.5k
    }
1459
1460
  /* Then check the magic and the version (only 0 is supported).  */
1461
20.4M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1462
20.4M
      && H_GET_16 (abfd, buffer + 4) == 0)
1463
248k
    return pe_ILF_object_p (abfd);
1464
1465
20.1M
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1466
20.1M
      || bfd_bread (&dos_hdr, (bfd_size_type) sizeof (dos_hdr), abfd)
1467
20.1M
   != sizeof (dos_hdr))
1468
3.71M
    {
1469
3.71M
      if (bfd_get_error () != bfd_error_system_call)
1470
3.71M
  bfd_set_error (bfd_error_wrong_format);
1471
3.71M
      return NULL;
1472
3.71M
    }
1473
1474
  /* There are really two magic numbers involved; the magic number
1475
     that says this is a NT executable (PEI) and the magic number that
1476
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1477
     the e_magic field.  The latter is stored in the f_magic field.
1478
     If the NT magic number isn't valid, the architecture magic number
1479
     could be mimicked by some other field (specifically, the number
1480
     of relocs in section 3).  Since this routine can only be called
1481
     correctly for a PEI file, check the e_magic number here, and, if
1482
     it doesn't match, clobber the f_magic number so that we don't get
1483
     a false match.  */
1484
16.4M
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1485
11.0M
    {
1486
11.0M
      bfd_set_error (bfd_error_wrong_format);
1487
11.0M
      return NULL;
1488
11.0M
    }
1489
1490
5.40M
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1491
5.40M
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1492
5.40M
      || (bfd_bread (&image_hdr, (bfd_size_type) sizeof (image_hdr), abfd)
1493
5.40M
    != sizeof (image_hdr)))
1494
51.1k
    {
1495
51.1k
      if (bfd_get_error () != bfd_error_system_call)
1496
51.1k
  bfd_set_error (bfd_error_wrong_format);
1497
51.1k
      return NULL;
1498
51.1k
    }
1499
1500
5.35M
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1501
97.3k
    {
1502
97.3k
      bfd_set_error (bfd_error_wrong_format);
1503
97.3k
      return NULL;
1504
97.3k
    }
1505
1506
  /* Swap file header, so that we get the location for calling
1507
     real_object_p.  */
1508
5.25M
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1509
1510
5.25M
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1511
5.25M
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1512
4.54M
    {
1513
4.54M
      bfd_set_error (bfd_error_wrong_format);
1514
4.54M
      return NULL;
1515
4.54M
    }
1516
1517
712k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1518
712k
    sizeof (internal_f.pe.dos_message));
1519
1520
  /* Read the optional header, which has variable size.  */
1521
712k
  opt_hdr_size = internal_f.f_opthdr;
1522
1523
712k
  if (opt_hdr_size != 0)
1524
510k
    {
1525
510k
      bfd_size_type amt = opt_hdr_size;
1526
510k
      bfd_byte * opthdr;
1527
1528
      /* PR 17521 file: 230-131433-0.004.  */
1529
510k
      if (amt < sizeof (PEAOUTHDR))
1530
337k
  amt = sizeof (PEAOUTHDR);
1531
1532
510k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1533
510k
      if (opthdr == NULL)
1534
18.6k
  return NULL;
1535
492k
      if (amt > opt_hdr_size)
1536
330k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1537
1538
492k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1539
1540
492k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1541
1542
#ifdef ARM
1543
      /* Use Subsystem to distinguish between pei-arm-little and
1544
   pei-arm-wince-little.  */
1545
#ifdef WINCE
1546
75.2k
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1547
#else
1548
75.2k
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1549
27.9k
#endif
1550
75.0k
  {
1551
75.0k
    bfd_set_error (bfd_error_wrong_format);
1552
75.0k
    return NULL;
1553
75.0k
  }
1554
75.3k
#endif
1555
1556
417k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1557
417k
    || a->SectionAlignment >= 0x80000000)
1558
244k
  {
1559
244k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1560
244k
        abfd);
1561
244k
    a->SectionAlignment &= -a->SectionAlignment;
1562
244k
    if (a->SectionAlignment >= 0x80000000)
1563
5.79k
      a->SectionAlignment = 0x40000000;
1564
244k
  }
1565
1566
417k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1567
417k
    || a->FileAlignment > a->SectionAlignment)
1568
314k
  {
1569
314k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1570
314k
            abfd);
1571
314k
    a->FileAlignment &= -a->FileAlignment;
1572
314k
    if (a->FileAlignment > a->SectionAlignment)
1573
167k
      a->FileAlignment = a->SectionAlignment;
1574
314k
  }
1575
1576
417k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1577
299k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1578
75.3k
    }
1579
1580
619k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1581
619k
             (opt_hdr_size != 0
1582
619k
        ? &internal_a
1583
619k
        : (struct internal_aouthdr *) NULL));
1584
1585
619k
  if (result)
1586
314k
    {
1587
      /* Now the whole header has been processed, see if there is a build-id */
1588
314k
      pe_bfd_read_buildid(abfd);
1589
314k
    }
1590
1591
619k
  return result;
1592
712k
}
pei-i386.c:pe_bfd_object_p
Line
Count
Source
1440
1.82M
{
1441
1.82M
  bfd_byte buffer[6];
1442
1.82M
  struct external_DOS_hdr dos_hdr;
1443
1.82M
  struct external_PEI_IMAGE_hdr image_hdr;
1444
1.82M
  struct internal_filehdr internal_f;
1445
1.82M
  struct internal_aouthdr internal_a;
1446
1.82M
  bfd_size_type opt_hdr_size;
1447
1.82M
  file_ptr offset;
1448
1.82M
  bfd_cleanup result;
1449
1450
  /* Detect if this a Microsoft Import Library Format element.  */
1451
  /* First read the beginning of the header.  */
1452
1.82M
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1453
1.82M
      || bfd_bread (buffer, (bfd_size_type) 6, abfd) != 6)
1454
6.19k
    {
1455
6.19k
      if (bfd_get_error () != bfd_error_system_call)
1456
5.34k
  bfd_set_error (bfd_error_wrong_format);
1457
6.19k
      return NULL;
1458
6.19k
    }
1459
1460
  /* Then check the magic and the version (only 0 is supported).  */
1461
1.82M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1462
1.82M
      && H_GET_16 (abfd, buffer + 4) == 0)
1463
32.7k
    return pe_ILF_object_p (abfd);
1464
1465
1.79M
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1466
1.79M
      || bfd_bread (&dos_hdr, (bfd_size_type) sizeof (dos_hdr), abfd)
1467
1.79M
   != sizeof (dos_hdr))
1468
333k
    {
1469
333k
      if (bfd_get_error () != bfd_error_system_call)
1470
333k
  bfd_set_error (bfd_error_wrong_format);
1471
333k
      return NULL;
1472
333k
    }
1473
1474
  /* There are really two magic numbers involved; the magic number
1475
     that says this is a NT executable (PEI) and the magic number that
1476
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1477
     the e_magic field.  The latter is stored in the f_magic field.
1478
     If the NT magic number isn't valid, the architecture magic number
1479
     could be mimicked by some other field (specifically, the number
1480
     of relocs in section 3).  Since this routine can only be called
1481
     correctly for a PEI file, check the e_magic number here, and, if
1482
     it doesn't match, clobber the f_magic number so that we don't get
1483
     a false match.  */
1484
1.45M
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1485
843k
    {
1486
843k
      bfd_set_error (bfd_error_wrong_format);
1487
843k
      return NULL;
1488
843k
    }
1489
1490
613k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1491
613k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1492
613k
      || (bfd_bread (&image_hdr, (bfd_size_type) sizeof (image_hdr), abfd)
1493
613k
    != sizeof (image_hdr)))
1494
6.21k
    {
1495
6.21k
      if (bfd_get_error () != bfd_error_system_call)
1496
6.21k
  bfd_set_error (bfd_error_wrong_format);
1497
6.21k
      return NULL;
1498
6.21k
    }
1499
1500
607k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1501
11.9k
    {
1502
11.9k
      bfd_set_error (bfd_error_wrong_format);
1503
11.9k
      return NULL;
1504
11.9k
    }
1505
1506
  /* Swap file header, so that we get the location for calling
1507
     real_object_p.  */
1508
595k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1509
1510
595k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1511
595k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1512
524k
    {
1513
524k
      bfd_set_error (bfd_error_wrong_format);
1514
524k
      return NULL;
1515
524k
    }
1516
1517
70.9k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1518
70.9k
    sizeof (internal_f.pe.dos_message));
1519
1520
  /* Read the optional header, which has variable size.  */
1521
70.9k
  opt_hdr_size = internal_f.f_opthdr;
1522
1523
70.9k
  if (opt_hdr_size != 0)
1524
49.9k
    {
1525
49.9k
      bfd_size_type amt = opt_hdr_size;
1526
49.9k
      bfd_byte * opthdr;
1527
1528
      /* PR 17521 file: 230-131433-0.004.  */
1529
49.9k
      if (amt < sizeof (PEAOUTHDR))
1530
40.7k
  amt = sizeof (PEAOUTHDR);
1531
1532
49.9k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1533
49.9k
      if (opthdr == NULL)
1534
1.54k
  return NULL;
1535
48.3k
      if (amt > opt_hdr_size)
1536
39.6k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1537
1538
48.3k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1539
1540
48.3k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1541
1542
#ifdef ARM
1543
      /* Use Subsystem to distinguish between pei-arm-little and
1544
   pei-arm-wince-little.  */
1545
#ifdef WINCE
1546
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1547
#else
1548
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1549
#endif
1550
  {
1551
    bfd_set_error (bfd_error_wrong_format);
1552
    return NULL;
1553
  }
1554
#endif
1555
1556
48.3k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1557
48.3k
    || a->SectionAlignment >= 0x80000000)
1558
33.2k
  {
1559
33.2k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1560
33.2k
        abfd);
1561
33.2k
    a->SectionAlignment &= -a->SectionAlignment;
1562
33.2k
    if (a->SectionAlignment >= 0x80000000)
1563
1.15k
      a->SectionAlignment = 0x40000000;
1564
33.2k
  }
1565
1566
48.3k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1567
48.3k
    || a->FileAlignment > a->SectionAlignment)
1568
32.9k
  {
1569
32.9k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1570
32.9k
            abfd);
1571
32.9k
    a->FileAlignment &= -a->FileAlignment;
1572
32.9k
    if (a->FileAlignment > a->SectionAlignment)
1573
16.1k
      a->FileAlignment = a->SectionAlignment;
1574
32.9k
  }
1575
1576
48.3k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1577
23.1k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1578
48.3k
    }
1579
1580
69.3k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1581
69.3k
             (opt_hdr_size != 0
1582
69.3k
        ? &internal_a
1583
69.3k
        : (struct internal_aouthdr *) NULL));
1584
1585
69.3k
  if (result)
1586
39.6k
    {
1587
      /* Now the whole header has been processed, see if there is a build-id */
1588
39.6k
      pe_bfd_read_buildid(abfd);
1589
39.6k
    }
1590
1591
69.3k
  return result;
1592
70.9k
}
pei-x86_64.c:pe_bfd_object_p
Line
Count
Source
1440
1.83M
{
1441
1.83M
  bfd_byte buffer[6];
1442
1.83M
  struct external_DOS_hdr dos_hdr;
1443
1.83M
  struct external_PEI_IMAGE_hdr image_hdr;
1444
1.83M
  struct internal_filehdr internal_f;
1445
1.83M
  struct internal_aouthdr internal_a;
1446
1.83M
  bfd_size_type opt_hdr_size;
1447
1.83M
  file_ptr offset;
1448
1.83M
  bfd_cleanup result;
1449
1450
  /* Detect if this a Microsoft Import Library Format element.  */
1451
  /* First read the beginning of the header.  */
1452
1.83M
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1453
1.83M
      || bfd_bread (buffer, (bfd_size_type) 6, abfd) != 6)
1454
6.19k
    {
1455
6.19k
      if (bfd_get_error () != bfd_error_system_call)
1456
5.34k
  bfd_set_error (bfd_error_wrong_format);
1457
6.19k
      return NULL;
1458
6.19k
    }
1459
1460
  /* Then check the magic and the version (only 0 is supported).  */
1461
1.83M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1462
1.83M
      && H_GET_16 (abfd, buffer + 4) == 0)
1463
26.0k
    return pe_ILF_object_p (abfd);
1464
1465
1.80M
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1466
1.80M
      || bfd_bread (&dos_hdr, (bfd_size_type) sizeof (dos_hdr), abfd)
1467
1.80M
   != sizeof (dos_hdr))
1468
334k
    {
1469
334k
      if (bfd_get_error () != bfd_error_system_call)
1470
334k
  bfd_set_error (bfd_error_wrong_format);
1471
334k
      return NULL;
1472
334k
    }
1473
1474
  /* There are really two magic numbers involved; the magic number
1475
     that says this is a NT executable (PEI) and the magic number that
1476
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1477
     the e_magic field.  The latter is stored in the f_magic field.
1478
     If the NT magic number isn't valid, the architecture magic number
1479
     could be mimicked by some other field (specifically, the number
1480
     of relocs in section 3).  Since this routine can only be called
1481
     correctly for a PEI file, check the e_magic number here, and, if
1482
     it doesn't match, clobber the f_magic number so that we don't get
1483
     a false match.  */
1484
1.46M
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1485
849k
    {
1486
849k
      bfd_set_error (bfd_error_wrong_format);
1487
849k
      return NULL;
1488
849k
    }
1489
1490
620k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1491
620k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1492
620k
      || (bfd_bread (&image_hdr, (bfd_size_type) sizeof (image_hdr), abfd)
1493
620k
    != sizeof (image_hdr)))
1494
6.21k
    {
1495
6.21k
      if (bfd_get_error () != bfd_error_system_call)
1496
6.21k
  bfd_set_error (bfd_error_wrong_format);
1497
6.21k
      return NULL;
1498
6.21k
    }
1499
1500
614k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1501
11.9k
    {
1502
11.9k
      bfd_set_error (bfd_error_wrong_format);
1503
11.9k
      return NULL;
1504
11.9k
    }
1505
1506
  /* Swap file header, so that we get the location for calling
1507
     real_object_p.  */
1508
602k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1509
1510
602k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1511
602k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1512
516k
    {
1513
516k
      bfd_set_error (bfd_error_wrong_format);
1514
516k
      return NULL;
1515
516k
    }
1516
1517
86.1k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1518
86.1k
    sizeof (internal_f.pe.dos_message));
1519
1520
  /* Read the optional header, which has variable size.  */
1521
86.1k
  opt_hdr_size = internal_f.f_opthdr;
1522
1523
86.1k
  if (opt_hdr_size != 0)
1524
54.3k
    {
1525
54.3k
      bfd_size_type amt = opt_hdr_size;
1526
54.3k
      bfd_byte * opthdr;
1527
1528
      /* PR 17521 file: 230-131433-0.004.  */
1529
54.3k
      if (amt < sizeof (PEAOUTHDR))
1530
48.6k
  amt = sizeof (PEAOUTHDR);
1531
1532
54.3k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1533
54.3k
      if (opthdr == NULL)
1534
1.84k
  return NULL;
1535
52.5k
      if (amt > opt_hdr_size)
1536
47.3k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1537
1538
52.5k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1539
1540
52.5k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1541
1542
#ifdef ARM
1543
      /* Use Subsystem to distinguish between pei-arm-little and
1544
   pei-arm-wince-little.  */
1545
#ifdef WINCE
1546
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1547
#else
1548
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1549
#endif
1550
  {
1551
    bfd_set_error (bfd_error_wrong_format);
1552
    return NULL;
1553
  }
1554
#endif
1555
1556
52.5k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1557
52.5k
    || a->SectionAlignment >= 0x80000000)
1558
33.6k
  {
1559
33.6k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1560
33.6k
        abfd);
1561
33.6k
    a->SectionAlignment &= -a->SectionAlignment;
1562
33.6k
    if (a->SectionAlignment >= 0x80000000)
1563
412
      a->SectionAlignment = 0x40000000;
1564
33.6k
  }
1565
1566
52.5k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1567
52.5k
    || a->FileAlignment > a->SectionAlignment)
1568
43.7k
  {
1569
43.7k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1570
43.7k
            abfd);
1571
43.7k
    a->FileAlignment &= -a->FileAlignment;
1572
43.7k
    if (a->FileAlignment > a->SectionAlignment)
1573
25.8k
      a->FileAlignment = a->SectionAlignment;
1574
43.7k
  }
1575
1576
52.5k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1577
38.5k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1578
52.5k
    }
1579
1580
84.3k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1581
84.3k
             (opt_hdr_size != 0
1582
84.3k
        ? &internal_a
1583
84.3k
        : (struct internal_aouthdr *) NULL));
1584
1585
84.3k
  if (result)
1586
56.0k
    {
1587
      /* Now the whole header has been processed, see if there is a build-id */
1588
56.0k
      pe_bfd_read_buildid(abfd);
1589
56.0k
    }
1590
1591
84.3k
  return result;
1592
86.1k
}
pei-aarch64.c:pe_bfd_object_p
Line
Count
Source
1440
1.81M
{
1441
1.81M
  bfd_byte buffer[6];
1442
1.81M
  struct external_DOS_hdr dos_hdr;
1443
1.81M
  struct external_PEI_IMAGE_hdr image_hdr;
1444
1.81M
  struct internal_filehdr internal_f;
1445
1.81M
  struct internal_aouthdr internal_a;
1446
1.81M
  bfd_size_type opt_hdr_size;
1447
1.81M
  file_ptr offset;
1448
1.81M
  bfd_cleanup result;
1449
1450
  /* Detect if this a Microsoft Import Library Format element.  */
1451
  /* First read the beginning of the header.  */
1452
1.81M
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1453
1.81M
      || bfd_bread (buffer, (bfd_size_type) 6, abfd) != 6)
1454
6.19k
    {
1455
6.19k
      if (bfd_get_error () != bfd_error_system_call)
1456
5.34k
  bfd_set_error (bfd_error_wrong_format);
1457
6.19k
      return NULL;
1458
6.19k
    }
1459
1460
  /* Then check the magic and the version (only 0 is supported).  */
1461
1.81M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1462
1.81M
      && H_GET_16 (abfd, buffer + 4) == 0)
1463
39.9k
    return pe_ILF_object_p (abfd);
1464
1465
1.77M
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1466
1.77M
      || bfd_bread (&dos_hdr, (bfd_size_type) sizeof (dos_hdr), abfd)
1467
1.77M
   != sizeof (dos_hdr))
1468
333k
    {
1469
333k
      if (bfd_get_error () != bfd_error_system_call)
1470
333k
  bfd_set_error (bfd_error_wrong_format);
1471
333k
      return NULL;
1472
333k
    }
1473
1474
  /* There are really two magic numbers involved; the magic number
1475
     that says this is a NT executable (PEI) and the magic number that
1476
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1477
     the e_magic field.  The latter is stored in the f_magic field.
1478
     If the NT magic number isn't valid, the architecture magic number
1479
     could be mimicked by some other field (specifically, the number
1480
     of relocs in section 3).  Since this routine can only be called
1481
     correctly for a PEI file, check the e_magic number here, and, if
1482
     it doesn't match, clobber the f_magic number so that we don't get
1483
     a false match.  */
1484
1.43M
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1485
835k
    {
1486
835k
      bfd_set_error (bfd_error_wrong_format);
1487
835k
      return NULL;
1488
835k
    }
1489
1490
601k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1491
601k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1492
601k
      || (bfd_bread (&image_hdr, (bfd_size_type) sizeof (image_hdr), abfd)
1493
601k
    != sizeof (image_hdr)))
1494
6.68k
    {
1495
6.68k
      if (bfd_get_error () != bfd_error_system_call)
1496
6.68k
  bfd_set_error (bfd_error_wrong_format);
1497
6.68k
      return NULL;
1498
6.68k
    }
1499
1500
595k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1501
12.6k
    {
1502
12.6k
      bfd_set_error (bfd_error_wrong_format);
1503
12.6k
      return NULL;
1504
12.6k
    }
1505
1506
  /* Swap file header, so that we get the location for calling
1507
     real_object_p.  */
1508
582k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1509
1510
582k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1511
582k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1512
521k
    {
1513
521k
      bfd_set_error (bfd_error_wrong_format);
1514
521k
      return NULL;
1515
521k
    }
1516
1517
61.4k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1518
61.4k
    sizeof (internal_f.pe.dos_message));
1519
1520
  /* Read the optional header, which has variable size.  */
1521
61.4k
  opt_hdr_size = internal_f.f_opthdr;
1522
1523
61.4k
  if (opt_hdr_size != 0)
1524
51.6k
    {
1525
51.6k
      bfd_size_type amt = opt_hdr_size;
1526
51.6k
      bfd_byte * opthdr;
1527
1528
      /* PR 17521 file: 230-131433-0.004.  */
1529
51.6k
      if (amt < sizeof (PEAOUTHDR))
1530
22.6k
  amt = sizeof (PEAOUTHDR);
1531
1532
51.6k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1533
51.6k
      if (opthdr == NULL)
1534
1.31k
  return NULL;
1535
50.3k
      if (amt > opt_hdr_size)
1536
22.1k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1537
1538
50.3k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1539
1540
50.3k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1541
1542
#ifdef ARM
1543
      /* Use Subsystem to distinguish between pei-arm-little and
1544
   pei-arm-wince-little.  */
1545
#ifdef WINCE
1546
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1547
#else
1548
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1549
#endif
1550
  {
1551
    bfd_set_error (bfd_error_wrong_format);
1552
    return NULL;
1553
  }
1554
#endif
1555
1556
50.3k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1557
50.3k
    || a->SectionAlignment >= 0x80000000)
1558
28.3k
  {
1559
28.3k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1560
28.3k
        abfd);
1561
28.3k
    a->SectionAlignment &= -a->SectionAlignment;
1562
28.3k
    if (a->SectionAlignment >= 0x80000000)
1563
1.29k
      a->SectionAlignment = 0x40000000;
1564
28.3k
  }
1565
1566
50.3k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1567
50.3k
    || a->FileAlignment > a->SectionAlignment)
1568
37.5k
  {
1569
37.5k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1570
37.5k
            abfd);
1571
37.5k
    a->FileAlignment &= -a->FileAlignment;
1572
37.5k
    if (a->FileAlignment > a->SectionAlignment)
1573
19.5k
      a->FileAlignment = a->SectionAlignment;
1574
37.5k
  }
1575
1576
50.3k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1577
38.8k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1578
50.3k
    }
1579
1580
60.1k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1581
60.1k
             (opt_hdr_size != 0
1582
60.1k
        ? &internal_a
1583
60.1k
        : (struct internal_aouthdr *) NULL));
1584
1585
60.1k
  if (result)
1586
32.2k
    {
1587
      /* Now the whole header has been processed, see if there is a build-id */
1588
32.2k
      pe_bfd_read_buildid(abfd);
1589
32.2k
    }
1590
1591
60.1k
  return result;
1592
61.4k
}
pei-ia64.c:pe_bfd_object_p
Line
Count
Source
1440
565k
{
1441
565k
  bfd_byte buffer[6];
1442
565k
  struct external_DOS_hdr dos_hdr;
1443
565k
  struct external_PEI_IMAGE_hdr image_hdr;
1444
565k
  struct internal_filehdr internal_f;
1445
565k
  struct internal_aouthdr internal_a;
1446
565k
  bfd_size_type opt_hdr_size;
1447
565k
  file_ptr offset;
1448
565k
  bfd_cleanup result;
1449
1450
  /* Detect if this a Microsoft Import Library Format element.  */
1451
  /* First read the beginning of the header.  */
1452
565k
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1453
565k
      || bfd_bread (buffer, (bfd_size_type) 6, abfd) != 6)
1454
0
    {
1455
0
      if (bfd_get_error () != bfd_error_system_call)
1456
0
  bfd_set_error (bfd_error_wrong_format);
1457
0
      return NULL;
1458
0
    }
1459
1460
  /* Then check the magic and the version (only 0 is supported).  */
1461
565k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1462
565k
      && H_GET_16 (abfd, buffer + 4) == 0)
1463
0
    return pe_ILF_object_p (abfd);
1464
1465
565k
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1466
565k
      || bfd_bread (&dos_hdr, (bfd_size_type) sizeof (dos_hdr), abfd)
1467
565k
   != sizeof (dos_hdr))
1468
0
    {
1469
0
      if (bfd_get_error () != bfd_error_system_call)
1470
0
  bfd_set_error (bfd_error_wrong_format);
1471
0
      return NULL;
1472
0
    }
1473
1474
  /* There are really two magic numbers involved; the magic number
1475
     that says this is a NT executable (PEI) and the magic number that
1476
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1477
     the e_magic field.  The latter is stored in the f_magic field.
1478
     If the NT magic number isn't valid, the architecture magic number
1479
     could be mimicked by some other field (specifically, the number
1480
     of relocs in section 3).  Since this routine can only be called
1481
     correctly for a PEI file, check the e_magic number here, and, if
1482
     it doesn't match, clobber the f_magic number so that we don't get
1483
     a false match.  */
1484
565k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1485
0
    {
1486
0
      bfd_set_error (bfd_error_wrong_format);
1487
0
      return NULL;
1488
0
    }
1489
1490
565k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1491
565k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1492
565k
      || (bfd_bread (&image_hdr, (bfd_size_type) sizeof (image_hdr), abfd)
1493
565k
    != sizeof (image_hdr)))
1494
0
    {
1495
0
      if (bfd_get_error () != bfd_error_system_call)
1496
0
  bfd_set_error (bfd_error_wrong_format);
1497
0
      return NULL;
1498
0
    }
1499
1500
565k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1501
0
    {
1502
0
      bfd_set_error (bfd_error_wrong_format);
1503
0
      return NULL;
1504
0
    }
1505
1506
  /* Swap file header, so that we get the location for calling
1507
     real_object_p.  */
1508
565k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1509
1510
565k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1511
565k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1512
480k
    {
1513
480k
      bfd_set_error (bfd_error_wrong_format);
1514
480k
      return NULL;
1515
480k
    }
1516
1517
85.4k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1518
85.4k
    sizeof (internal_f.pe.dos_message));
1519
1520
  /* Read the optional header, which has variable size.  */
1521
85.4k
  opt_hdr_size = internal_f.f_opthdr;
1522
1523
85.4k
  if (opt_hdr_size != 0)
1524
61.7k
    {
1525
61.7k
      bfd_size_type amt = opt_hdr_size;
1526
61.7k
      bfd_byte * opthdr;
1527
1528
      /* PR 17521 file: 230-131433-0.004.  */
1529
61.7k
      if (amt < sizeof (PEAOUTHDR))
1530
45.4k
  amt = sizeof (PEAOUTHDR);
1531
1532
61.7k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1533
61.7k
      if (opthdr == NULL)
1534
2.59k
  return NULL;
1535
59.2k
      if (amt > opt_hdr_size)
1536
43.6k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1537
1538
59.2k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1539
1540
59.2k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1541
1542
#ifdef ARM
1543
      /* Use Subsystem to distinguish between pei-arm-little and
1544
   pei-arm-wince-little.  */
1545
#ifdef WINCE
1546
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1547
#else
1548
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1549
#endif
1550
  {
1551
    bfd_set_error (bfd_error_wrong_format);
1552
    return NULL;
1553
  }
1554
#endif
1555
1556
59.2k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1557
59.2k
    || a->SectionAlignment >= 0x80000000)
1558
34.6k
  {
1559
34.6k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1560
34.6k
        abfd);
1561
34.6k
    a->SectionAlignment &= -a->SectionAlignment;
1562
34.6k
    if (a->SectionAlignment >= 0x80000000)
1563
578
      a->SectionAlignment = 0x40000000;
1564
34.6k
  }
1565
1566
59.2k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1567
59.2k
    || a->FileAlignment > a->SectionAlignment)
1568
44.3k
  {
1569
44.3k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1570
44.3k
            abfd);
1571
44.3k
    a->FileAlignment &= -a->FileAlignment;
1572
44.3k
    if (a->FileAlignment > a->SectionAlignment)
1573
18.7k
      a->FileAlignment = a->SectionAlignment;
1574
44.3k
  }
1575
1576
59.2k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1577
45.2k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1578
59.2k
    }
1579
1580
82.9k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1581
82.9k
             (opt_hdr_size != 0
1582
82.9k
        ? &internal_a
1583
82.9k
        : (struct internal_aouthdr *) NULL));
1584
1585
82.9k
  if (result)
1586
36.5k
    {
1587
      /* Now the whole header has been processed, see if there is a build-id */
1588
36.5k
      pe_bfd_read_buildid(abfd);
1589
36.5k
    }
1590
1591
82.9k
  return result;
1592
85.4k
}
pei-loongarch64.c:pe_bfd_object_p
Line
Count
Source
1440
1.81M
{
1441
1.81M
  bfd_byte buffer[6];
1442
1.81M
  struct external_DOS_hdr dos_hdr;
1443
1.81M
  struct external_PEI_IMAGE_hdr image_hdr;
1444
1.81M
  struct internal_filehdr internal_f;
1445
1.81M
  struct internal_aouthdr internal_a;
1446
1.81M
  bfd_size_type opt_hdr_size;
1447
1.81M
  file_ptr offset;
1448
1.81M
  bfd_cleanup result;
1449
1450
  /* Detect if this a Microsoft Import Library Format element.  */
1451
  /* First read the beginning of the header.  */
1452
1.81M
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1453
1.81M
      || bfd_bread (buffer, (bfd_size_type) 6, abfd) != 6)
1454
6.19k
    {
1455
6.19k
      if (bfd_get_error () != bfd_error_system_call)
1456
5.34k
  bfd_set_error (bfd_error_wrong_format);
1457
6.19k
      return NULL;
1458
6.19k
    }
1459
1460
  /* Then check the magic and the version (only 0 is supported).  */
1461
1.81M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1462
1.81M
      && H_GET_16 (abfd, buffer + 4) == 0)
1463
21.9k
    return pe_ILF_object_p (abfd);
1464
1465
1.78M
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1466
1.78M
      || bfd_bread (&dos_hdr, (bfd_size_type) sizeof (dos_hdr), abfd)
1467
1.78M
   != sizeof (dos_hdr))
1468
336k
    {
1469
336k
      if (bfd_get_error () != bfd_error_system_call)
1470
336k
  bfd_set_error (bfd_error_wrong_format);
1471
336k
      return NULL;
1472
336k
    }
1473
1474
  /* There are really two magic numbers involved; the magic number
1475
     that says this is a NT executable (PEI) and the magic number that
1476
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1477
     the e_magic field.  The latter is stored in the f_magic field.
1478
     If the NT magic number isn't valid, the architecture magic number
1479
     could be mimicked by some other field (specifically, the number
1480
     of relocs in section 3).  Since this routine can only be called
1481
     correctly for a PEI file, check the e_magic number here, and, if
1482
     it doesn't match, clobber the f_magic number so that we don't get
1483
     a false match.  */
1484
1.45M
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1485
851k
    {
1486
851k
      bfd_set_error (bfd_error_wrong_format);
1487
851k
      return NULL;
1488
851k
    }
1489
1490
600k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1491
600k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1492
600k
      || (bfd_bread (&image_hdr, (bfd_size_type) sizeof (image_hdr), abfd)
1493
600k
    != sizeof (image_hdr)))
1494
6.21k
    {
1495
6.21k
      if (bfd_get_error () != bfd_error_system_call)
1496
6.21k
  bfd_set_error (bfd_error_wrong_format);
1497
6.21k
      return NULL;
1498
6.21k
    }
1499
1500
594k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1501
11.9k
    {
1502
11.9k
      bfd_set_error (bfd_error_wrong_format);
1503
11.9k
      return NULL;
1504
11.9k
    }
1505
1506
  /* Swap file header, so that we get the location for calling
1507
     real_object_p.  */
1508
582k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1509
1510
582k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1511
582k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1512
526k
    {
1513
526k
      bfd_set_error (bfd_error_wrong_format);
1514
526k
      return NULL;
1515
526k
    }
1516
1517
55.3k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1518
55.3k
    sizeof (internal_f.pe.dos_message));
1519
1520
  /* Read the optional header, which has variable size.  */
1521
55.3k
  opt_hdr_size = internal_f.f_opthdr;
1522
1523
55.3k
  if (opt_hdr_size != 0)
1524
42.2k
    {
1525
42.2k
      bfd_size_type amt = opt_hdr_size;
1526
42.2k
      bfd_byte * opthdr;
1527
1528
      /* PR 17521 file: 230-131433-0.004.  */
1529
42.2k
      if (amt < sizeof (PEAOUTHDR))
1530
28.0k
  amt = sizeof (PEAOUTHDR);
1531
1532
42.2k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1533
42.2k
      if (opthdr == NULL)
1534
1.67k
  return NULL;
1535
40.5k
      if (amt > opt_hdr_size)
1536
27.4k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1537
1538
40.5k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1539
1540
40.5k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1541
1542
#ifdef ARM
1543
      /* Use Subsystem to distinguish between pei-arm-little and
1544
   pei-arm-wince-little.  */
1545
#ifdef WINCE
1546
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1547
#else
1548
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1549
#endif
1550
  {
1551
    bfd_set_error (bfd_error_wrong_format);
1552
    return NULL;
1553
  }
1554
#endif
1555
1556
40.5k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1557
40.5k
    || a->SectionAlignment >= 0x80000000)
1558
18.8k
  {
1559
18.8k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1560
18.8k
        abfd);
1561
18.8k
    a->SectionAlignment &= -a->SectionAlignment;
1562
18.8k
    if (a->SectionAlignment >= 0x80000000)
1563
967
      a->SectionAlignment = 0x40000000;
1564
18.8k
  }
1565
1566
40.5k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1567
40.5k
    || a->FileAlignment > a->SectionAlignment)
1568
35.1k
  {
1569
35.1k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1570
35.1k
            abfd);
1571
35.1k
    a->FileAlignment &= -a->FileAlignment;
1572
35.1k
    if (a->FileAlignment > a->SectionAlignment)
1573
21.2k
      a->FileAlignment = a->SectionAlignment;
1574
35.1k
  }
1575
1576
40.5k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1577
30.4k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1578
40.5k
    }
1579
1580
53.6k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1581
53.6k
             (opt_hdr_size != 0
1582
53.6k
        ? &internal_a
1583
53.6k
        : (struct internal_aouthdr *) NULL));
1584
1585
53.6k
  if (result)
1586
33.4k
    {
1587
      /* Now the whole header has been processed, see if there is a build-id */
1588
33.4k
      pe_bfd_read_buildid(abfd);
1589
33.4k
    }
1590
1591
53.6k
  return result;
1592
55.3k
}
pei-arm-wince.c:pe_bfd_object_p
Line
Count
Source
1440
3.60M
{
1441
3.60M
  bfd_byte buffer[6];
1442
3.60M
  struct external_DOS_hdr dos_hdr;
1443
3.60M
  struct external_PEI_IMAGE_hdr image_hdr;
1444
3.60M
  struct internal_filehdr internal_f;
1445
3.60M
  struct internal_aouthdr internal_a;
1446
3.60M
  bfd_size_type opt_hdr_size;
1447
3.60M
  file_ptr offset;
1448
3.60M
  bfd_cleanup result;
1449
1450
  /* Detect if this a Microsoft Import Library Format element.  */
1451
  /* First read the beginning of the header.  */
1452
3.60M
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1453
3.60M
      || bfd_bread (buffer, (bfd_size_type) 6, abfd) != 6)
1454
11.9k
    {
1455
11.9k
      if (bfd_get_error () != bfd_error_system_call)
1456
10.2k
  bfd_set_error (bfd_error_wrong_format);
1457
11.9k
      return NULL;
1458
11.9k
    }
1459
1460
  /* Then check the magic and the version (only 0 is supported).  */
1461
3.58M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1462
3.58M
      && H_GET_16 (abfd, buffer + 4) == 0)
1463
32.6k
    return pe_ILF_object_p (abfd);
1464
1465
3.55M
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1466
3.55M
      || bfd_bread (&dos_hdr, (bfd_size_type) sizeof (dos_hdr), abfd)
1467
3.55M
   != sizeof (dos_hdr))
1468
682k
    {
1469
682k
      if (bfd_get_error () != bfd_error_system_call)
1470
681k
  bfd_set_error (bfd_error_wrong_format);
1471
682k
      return NULL;
1472
682k
    }
1473
1474
  /* There are really two magic numbers involved; the magic number
1475
     that says this is a NT executable (PEI) and the magic number that
1476
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1477
     the e_magic field.  The latter is stored in the f_magic field.
1478
     If the NT magic number isn't valid, the architecture magic number
1479
     could be mimicked by some other field (specifically, the number
1480
     of relocs in section 3).  Since this routine can only be called
1481
     correctly for a PEI file, check the e_magic number here, and, if
1482
     it doesn't match, clobber the f_magic number so that we don't get
1483
     a false match.  */
1484
2.87M
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1485
2.27M
    {
1486
2.27M
      bfd_set_error (bfd_error_wrong_format);
1487
2.27M
      return NULL;
1488
2.27M
    }
1489
1490
601k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1491
601k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1492
601k
      || (bfd_bread (&image_hdr, (bfd_size_type) sizeof (image_hdr), abfd)
1493
601k
    != sizeof (image_hdr)))
1494
6.67k
    {
1495
6.67k
      if (bfd_get_error () != bfd_error_system_call)
1496
6.67k
  bfd_set_error (bfd_error_wrong_format);
1497
6.67k
      return NULL;
1498
6.67k
    }
1499
1500
595k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1501
12.5k
    {
1502
12.5k
      bfd_set_error (bfd_error_wrong_format);
1503
12.5k
      return NULL;
1504
12.5k
    }
1505
1506
  /* Swap file header, so that we get the location for calling
1507
     real_object_p.  */
1508
582k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1509
1510
582k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1511
582k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1512
472k
    {
1513
472k
      bfd_set_error (bfd_error_wrong_format);
1514
472k
      return NULL;
1515
472k
    }
1516
1517
109k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1518
109k
    sizeof (internal_f.pe.dos_message));
1519
1520
  /* Read the optional header, which has variable size.  */
1521
109k
  opt_hdr_size = internal_f.f_opthdr;
1522
1523
109k
  if (opt_hdr_size != 0)
1524
77.5k
    {
1525
77.5k
      bfd_size_type amt = opt_hdr_size;
1526
77.5k
      bfd_byte * opthdr;
1527
1528
      /* PR 17521 file: 230-131433-0.004.  */
1529
77.5k
      if (amt < sizeof (PEAOUTHDR))
1530
44.3k
  amt = sizeof (PEAOUTHDR);
1531
1532
77.5k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1533
77.5k
      if (opthdr == NULL)
1534
2.36k
  return NULL;
1535
75.2k
      if (amt > opt_hdr_size)
1536
43.9k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1537
1538
75.2k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1539
1540
75.2k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1541
1542
75.2k
#ifdef ARM
1543
      /* Use Subsystem to distinguish between pei-arm-little and
1544
   pei-arm-wince-little.  */
1545
75.2k
#ifdef WINCE
1546
75.2k
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1547
#else
1548
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1549
#endif
1550
47.1k
  {
1551
47.1k
    bfd_set_error (bfd_error_wrong_format);
1552
47.1k
    return NULL;
1553
47.1k
  }
1554
28.0k
#endif
1555
1556
28.0k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1557
28.0k
    || a->SectionAlignment >= 0x80000000)
1558
18.2k
  {
1559
18.2k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1560
18.2k
        abfd);
1561
18.2k
    a->SectionAlignment &= -a->SectionAlignment;
1562
18.2k
    if (a->SectionAlignment >= 0x80000000)
1563
349
      a->SectionAlignment = 0x40000000;
1564
18.2k
  }
1565
1566
28.0k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1567
28.0k
    || a->FileAlignment > a->SectionAlignment)
1568
18.3k
  {
1569
18.3k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1570
18.3k
            abfd);
1571
18.3k
    a->FileAlignment &= -a->FileAlignment;
1572
18.3k
    if (a->FileAlignment > a->SectionAlignment)
1573
11.3k
      a->FileAlignment = a->SectionAlignment;
1574
18.3k
  }
1575
1576
28.0k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1577
22.0k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1578
28.0k
    }
1579
1580
60.4k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1581
60.4k
             (opt_hdr_size != 0
1582
60.4k
        ? &internal_a
1583
60.4k
        : (struct internal_aouthdr *) NULL));
1584
1585
60.4k
  if (result)
1586
18.2k
    {
1587
      /* Now the whole header has been processed, see if there is a build-id */
1588
18.2k
      pe_bfd_read_buildid(abfd);
1589
18.2k
    }
1590
1591
60.4k
  return result;
1592
109k
}
pei-arm.c:pe_bfd_object_p
Line
Count
Source
1440
3.60M
{
1441
3.60M
  bfd_byte buffer[6];
1442
3.60M
  struct external_DOS_hdr dos_hdr;
1443
3.60M
  struct external_PEI_IMAGE_hdr image_hdr;
1444
3.60M
  struct internal_filehdr internal_f;
1445
3.60M
  struct internal_aouthdr internal_a;
1446
3.60M
  bfd_size_type opt_hdr_size;
1447
3.60M
  file_ptr offset;
1448
3.60M
  bfd_cleanup result;
1449
1450
  /* Detect if this a Microsoft Import Library Format element.  */
1451
  /* First read the beginning of the header.  */
1452
3.60M
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1453
3.60M
      || bfd_bread (buffer, (bfd_size_type) 6, abfd) != 6)
1454
11.9k
    {
1455
11.9k
      if (bfd_get_error () != bfd_error_system_call)
1456
10.2k
  bfd_set_error (bfd_error_wrong_format);
1457
11.9k
      return NULL;
1458
11.9k
    }
1459
1460
  /* Then check the magic and the version (only 0 is supported).  */
1461
3.58M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1462
3.58M
      && H_GET_16 (abfd, buffer + 4) == 0)
1463
37.8k
    return pe_ILF_object_p (abfd);
1464
1465
3.55M
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1466
3.55M
      || bfd_bread (&dos_hdr, (bfd_size_type) sizeof (dos_hdr), abfd)
1467
3.55M
   != sizeof (dos_hdr))
1468
686k
    {
1469
686k
      if (bfd_get_error () != bfd_error_system_call)
1470
686k
  bfd_set_error (bfd_error_wrong_format);
1471
686k
      return NULL;
1472
686k
    }
1473
1474
  /* There are really two magic numbers involved; the magic number
1475
     that says this is a NT executable (PEI) and the magic number that
1476
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1477
     the e_magic field.  The latter is stored in the f_magic field.
1478
     If the NT magic number isn't valid, the architecture magic number
1479
     could be mimicked by some other field (specifically, the number
1480
     of relocs in section 3).  Since this routine can only be called
1481
     correctly for a PEI file, check the e_magic number here, and, if
1482
     it doesn't match, clobber the f_magic number so that we don't get
1483
     a false match.  */
1484
2.86M
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1485
2.26M
    {
1486
2.26M
      bfd_set_error (bfd_error_wrong_format);
1487
2.26M
      return NULL;
1488
2.26M
    }
1489
1490
601k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1491
601k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1492
601k
      || (bfd_bread (&image_hdr, (bfd_size_type) sizeof (image_hdr), abfd)
1493
601k
    != sizeof (image_hdr)))
1494
6.67k
    {
1495
6.67k
      if (bfd_get_error () != bfd_error_system_call)
1496
6.67k
  bfd_set_error (bfd_error_wrong_format);
1497
6.67k
      return NULL;
1498
6.67k
    }
1499
1500
595k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1501
12.5k
    {
1502
12.5k
      bfd_set_error (bfd_error_wrong_format);
1503
12.5k
      return NULL;
1504
12.5k
    }
1505
1506
  /* Swap file header, so that we get the location for calling
1507
     real_object_p.  */
1508
582k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1509
1510
582k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1511
582k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1512
472k
    {
1513
472k
      bfd_set_error (bfd_error_wrong_format);
1514
472k
      return NULL;
1515
472k
    }
1516
1517
109k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1518
109k
    sizeof (internal_f.pe.dos_message));
1519
1520
  /* Read the optional header, which has variable size.  */
1521
109k
  opt_hdr_size = internal_f.f_opthdr;
1522
1523
109k
  if (opt_hdr_size != 0)
1524
77.6k
    {
1525
77.6k
      bfd_size_type amt = opt_hdr_size;
1526
77.6k
      bfd_byte * opthdr;
1527
1528
      /* PR 17521 file: 230-131433-0.004.  */
1529
77.6k
      if (amt < sizeof (PEAOUTHDR))
1530
44.3k
  amt = sizeof (PEAOUTHDR);
1531
1532
77.6k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1533
77.6k
      if (opthdr == NULL)
1534
2.36k
  return NULL;
1535
75.2k
      if (amt > opt_hdr_size)
1536
43.9k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1537
1538
75.2k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1539
1540
75.2k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1541
1542
75.2k
#ifdef ARM
1543
      /* Use Subsystem to distinguish between pei-arm-little and
1544
   pei-arm-wince-little.  */
1545
#ifdef WINCE
1546
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1547
#else
1548
75.2k
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1549
27.9k
#endif
1550
27.9k
  {
1551
27.9k
    bfd_set_error (bfd_error_wrong_format);
1552
27.9k
    return NULL;
1553
27.9k
  }
1554
47.2k
#endif
1555
1556
47.2k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1557
47.2k
    || a->SectionAlignment >= 0x80000000)
1558
31.3k
  {
1559
31.3k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1560
31.3k
        abfd);
1561
31.3k
    a->SectionAlignment &= -a->SectionAlignment;
1562
31.3k
    if (a->SectionAlignment >= 0x80000000)
1563
548
      a->SectionAlignment = 0x40000000;
1564
31.3k
  }
1565
1566
47.2k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1567
47.2k
    || a->FileAlignment > a->SectionAlignment)
1568
32.5k
  {
1569
32.5k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1570
32.5k
            abfd);
1571
32.5k
    a->FileAlignment &= -a->FileAlignment;
1572
32.5k
    if (a->FileAlignment > a->SectionAlignment)
1573
18.5k
      a->FileAlignment = a->SectionAlignment;
1574
32.5k
  }
1575
1576
47.2k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1577
32.3k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1578
47.2k
    }
1579
1580
79.6k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1581
79.6k
             (opt_hdr_size != 0
1582
79.6k
        ? &internal_a
1583
79.6k
        : (struct internal_aouthdr *) NULL));
1584
1585
79.6k
  if (result)
1586
28.1k
    {
1587
      /* Now the whole header has been processed, see if there is a build-id */
1588
28.1k
      pe_bfd_read_buildid(abfd);
1589
28.1k
    }
1590
1591
79.6k
  return result;
1592
109k
}
pei-mcore.c:pe_bfd_object_p
Line
Count
Source
1440
3.60M
{
1441
3.60M
  bfd_byte buffer[6];
1442
3.60M
  struct external_DOS_hdr dos_hdr;
1443
3.60M
  struct external_PEI_IMAGE_hdr image_hdr;
1444
3.60M
  struct internal_filehdr internal_f;
1445
3.60M
  struct internal_aouthdr internal_a;
1446
3.60M
  bfd_size_type opt_hdr_size;
1447
3.60M
  file_ptr offset;
1448
3.60M
  bfd_cleanup result;
1449
1450
  /* Detect if this a Microsoft Import Library Format element.  */
1451
  /* First read the beginning of the header.  */
1452
3.60M
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1453
3.60M
      || bfd_bread (buffer, (bfd_size_type) 6, abfd) != 6)
1454
11.9k
    {
1455
11.9k
      if (bfd_get_error () != bfd_error_system_call)
1456
10.2k
  bfd_set_error (bfd_error_wrong_format);
1457
11.9k
      return NULL;
1458
11.9k
    }
1459
1460
  /* Then check the magic and the version (only 0 is supported).  */
1461
3.58M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1462
3.58M
      && H_GET_16 (abfd, buffer + 4) == 0)
1463
28.9k
    return pe_ILF_object_p (abfd);
1464
1465
3.56M
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1466
3.56M
      || bfd_bread (&dos_hdr, (bfd_size_type) sizeof (dos_hdr), abfd)
1467
3.56M
   != sizeof (dos_hdr))
1468
681k
    {
1469
681k
      if (bfd_get_error () != bfd_error_system_call)
1470
681k
  bfd_set_error (bfd_error_wrong_format);
1471
681k
      return NULL;
1472
681k
    }
1473
1474
  /* There are really two magic numbers involved; the magic number
1475
     that says this is a NT executable (PEI) and the magic number that
1476
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1477
     the e_magic field.  The latter is stored in the f_magic field.
1478
     If the NT magic number isn't valid, the architecture magic number
1479
     could be mimicked by some other field (specifically, the number
1480
     of relocs in section 3).  Since this routine can only be called
1481
     correctly for a PEI file, check the e_magic number here, and, if
1482
     it doesn't match, clobber the f_magic number so that we don't get
1483
     a false match.  */
1484
2.87M
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1485
2.27M
    {
1486
2.27M
      bfd_set_error (bfd_error_wrong_format);
1487
2.27M
      return NULL;
1488
2.27M
    }
1489
1490
600k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1491
600k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1492
600k
      || (bfd_bread (&image_hdr, (bfd_size_type) sizeof (image_hdr), abfd)
1493
600k
    != sizeof (image_hdr)))
1494
6.21k
    {
1495
6.21k
      if (bfd_get_error () != bfd_error_system_call)
1496
6.21k
  bfd_set_error (bfd_error_wrong_format);
1497
6.21k
      return NULL;
1498
6.21k
    }
1499
1500
594k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1501
11.9k
    {
1502
11.9k
      bfd_set_error (bfd_error_wrong_format);
1503
11.9k
      return NULL;
1504
11.9k
    }
1505
1506
  /* Swap file header, so that we get the location for calling
1507
     real_object_p.  */
1508
582k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1509
1510
582k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1511
582k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1512
505k
    {
1513
505k
      bfd_set_error (bfd_error_wrong_format);
1514
505k
      return NULL;
1515
505k
    }
1516
1517
77.3k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1518
77.3k
    sizeof (internal_f.pe.dos_message));
1519
1520
  /* Read the optional header, which has variable size.  */
1521
77.3k
  opt_hdr_size = internal_f.f_opthdr;
1522
1523
77.3k
  if (opt_hdr_size != 0)
1524
57.4k
    {
1525
57.4k
      bfd_size_type amt = opt_hdr_size;
1526
57.4k
      bfd_byte * opthdr;
1527
1528
      /* PR 17521 file: 230-131433-0.004.  */
1529
57.4k
      if (amt < sizeof (PEAOUTHDR))
1530
37.8k
  amt = sizeof (PEAOUTHDR);
1531
1532
57.4k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1533
57.4k
      if (opthdr == NULL)
1534
2.39k
  return NULL;
1535
55.0k
      if (amt > opt_hdr_size)
1536
36.6k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1537
1538
55.0k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1539
1540
55.0k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1541
1542
#ifdef ARM
1543
      /* Use Subsystem to distinguish between pei-arm-little and
1544
   pei-arm-wince-little.  */
1545
#ifdef WINCE
1546
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1547
#else
1548
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1549
#endif
1550
  {
1551
    bfd_set_error (bfd_error_wrong_format);
1552
    return NULL;
1553
  }
1554
#endif
1555
1556
55.0k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1557
55.0k
    || a->SectionAlignment >= 0x80000000)
1558
27.8k
  {
1559
27.8k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1560
27.8k
        abfd);
1561
27.8k
    a->SectionAlignment &= -a->SectionAlignment;
1562
27.8k
    if (a->SectionAlignment >= 0x80000000)
1563
250
      a->SectionAlignment = 0x40000000;
1564
27.8k
  }
1565
1566
55.0k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1567
55.0k
    || a->FileAlignment > a->SectionAlignment)
1568
41.7k
  {
1569
41.7k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1570
41.7k
            abfd);
1571
41.7k
    a->FileAlignment &= -a->FileAlignment;
1572
41.7k
    if (a->FileAlignment > a->SectionAlignment)
1573
18.4k
      a->FileAlignment = a->SectionAlignment;
1574
41.7k
  }
1575
1576
55.0k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1577
44.5k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1578
55.0k
    }
1579
1580
74.9k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1581
74.9k
             (opt_hdr_size != 0
1582
74.9k
        ? &internal_a
1583
74.9k
        : (struct internal_aouthdr *) NULL));
1584
1585
74.9k
  if (result)
1586
42.5k
    {
1587
      /* Now the whole header has been processed, see if there is a build-id */
1588
42.5k
      pe_bfd_read_buildid(abfd);
1589
42.5k
    }
1590
1591
74.9k
  return result;
1592
77.3k
}
pei-sh.c:pe_bfd_object_p
Line
Count
Source
1440
1.80M
{
1441
1.80M
  bfd_byte buffer[6];
1442
1.80M
  struct external_DOS_hdr dos_hdr;
1443
1.80M
  struct external_PEI_IMAGE_hdr image_hdr;
1444
1.80M
  struct internal_filehdr internal_f;
1445
1.80M
  struct internal_aouthdr internal_a;
1446
1.80M
  bfd_size_type opt_hdr_size;
1447
1.80M
  file_ptr offset;
1448
1.80M
  bfd_cleanup result;
1449
1450
  /* Detect if this a Microsoft Import Library Format element.  */
1451
  /* First read the beginning of the header.  */
1452
1.80M
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1453
1.80M
      || bfd_bread (buffer, (bfd_size_type) 6, abfd) != 6)
1454
5.96k
    {
1455
5.96k
      if (bfd_get_error () != bfd_error_system_call)
1456
5.11k
  bfd_set_error (bfd_error_wrong_format);
1457
5.96k
      return NULL;
1458
5.96k
    }
1459
1460
  /* Then check the magic and the version (only 0 is supported).  */
1461
1.79M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1462
1.79M
      && H_GET_16 (abfd, buffer + 4) == 0)
1463
28.7k
    return pe_ILF_object_p (abfd);
1464
1465
1.76M
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1466
1.76M
      || bfd_bread (&dos_hdr, (bfd_size_type) sizeof (dos_hdr), abfd)
1467
1.76M
   != sizeof (dos_hdr))
1468
329k
    {
1469
329k
      if (bfd_get_error () != bfd_error_system_call)
1470
329k
  bfd_set_error (bfd_error_wrong_format);
1471
329k
      return NULL;
1472
329k
    }
1473
1474
  /* There are really two magic numbers involved; the magic number
1475
     that says this is a NT executable (PEI) and the magic number that
1476
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1477
     the e_magic field.  The latter is stored in the f_magic field.
1478
     If the NT magic number isn't valid, the architecture magic number
1479
     could be mimicked by some other field (specifically, the number
1480
     of relocs in section 3).  Since this routine can only be called
1481
     correctly for a PEI file, check the e_magic number here, and, if
1482
     it doesn't match, clobber the f_magic number so that we don't get
1483
     a false match.  */
1484
1.43M
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1485
836k
    {
1486
836k
      bfd_set_error (bfd_error_wrong_format);
1487
836k
      return NULL;
1488
836k
    }
1489
1490
599k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1491
599k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1492
599k
      || (bfd_bread (&image_hdr, (bfd_size_type) sizeof (image_hdr), abfd)
1493
599k
    != sizeof (image_hdr)))
1494
6.21k
    {
1495
6.21k
      if (bfd_get_error () != bfd_error_system_call)
1496
6.21k
  bfd_set_error (bfd_error_wrong_format);
1497
6.21k
      return NULL;
1498
6.21k
    }
1499
1500
593k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1501
11.8k
    {
1502
11.8k
      bfd_set_error (bfd_error_wrong_format);
1503
11.8k
      return NULL;
1504
11.8k
    }
1505
1506
  /* Swap file header, so that we get the location for calling
1507
     real_object_p.  */
1508
581k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1509
1510
581k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1511
581k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1512
524k
    {
1513
524k
      bfd_set_error (bfd_error_wrong_format);
1514
524k
      return NULL;
1515
524k
    }
1516
1517
56.3k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1518
56.3k
    sizeof (internal_f.pe.dos_message));
1519
1520
  /* Read the optional header, which has variable size.  */
1521
56.3k
  opt_hdr_size = internal_f.f_opthdr;
1522
1523
56.3k
  if (opt_hdr_size != 0)
1524
38.3k
    {
1525
38.3k
      bfd_size_type amt = opt_hdr_size;
1526
38.3k
      bfd_byte * opthdr;
1527
1528
      /* PR 17521 file: 230-131433-0.004.  */
1529
38.3k
      if (amt < sizeof (PEAOUTHDR))
1530
25.7k
  amt = sizeof (PEAOUTHDR);
1531
1532
38.3k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1533
38.3k
      if (opthdr == NULL)
1534
2.61k
  return NULL;
1535
35.7k
      if (amt > opt_hdr_size)
1536
25.4k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1537
1538
35.7k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1539
1540
35.7k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1541
1542
#ifdef ARM
1543
      /* Use Subsystem to distinguish between pei-arm-little and
1544
   pei-arm-wince-little.  */
1545
#ifdef WINCE
1546
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1547
#else
1548
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1549
#endif
1550
  {
1551
    bfd_set_error (bfd_error_wrong_format);
1552
    return NULL;
1553
  }
1554
#endif
1555
1556
35.7k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1557
35.7k
    || a->SectionAlignment >= 0x80000000)
1558
18.2k
  {
1559
18.2k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1560
18.2k
        abfd);
1561
18.2k
    a->SectionAlignment &= -a->SectionAlignment;
1562
18.2k
    if (a->SectionAlignment >= 0x80000000)
1563
238
      a->SectionAlignment = 0x40000000;
1564
18.2k
  }
1565
1566
35.7k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1567
35.7k
    || a->FileAlignment > a->SectionAlignment)
1568
27.9k
  {
1569
27.9k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1570
27.9k
            abfd);
1571
27.9k
    a->FileAlignment &= -a->FileAlignment;
1572
27.9k
    if (a->FileAlignment > a->SectionAlignment)
1573
17.2k
      a->FileAlignment = a->SectionAlignment;
1574
27.9k
  }
1575
1576
35.7k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1577
24.5k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1578
35.7k
    }
1579
1580
53.7k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1581
53.7k
             (opt_hdr_size != 0
1582
53.7k
        ? &internal_a
1583
53.7k
        : (struct internal_aouthdr *) NULL));
1584
1585
53.7k
  if (result)
1586
27.6k
    {
1587
      /* Now the whole header has been processed, see if there is a build-id */
1588
27.6k
      pe_bfd_read_buildid(abfd);
1589
27.6k
    }
1590
1591
53.7k
  return result;
1592
56.3k
}
1593
1594
565k
#define coff_object_p pe_bfd_object_p
1595
#endif /* COFF_IMAGE_WITH_PE */