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
34.0k
{
132
34.0k
  RELOC *reloc_src = (RELOC *) src;
133
34.0k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
34.0k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
34.0k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
34.0k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
#ifdef SWAP_IN_RELOC_OFFSET
139
14.4k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
#endif
141
34.0k
}
pei-i386.c:coff_swap_reloc_in
Line
Count
Source
131
1.40k
{
132
1.40k
  RELOC *reloc_src = (RELOC *) src;
133
1.40k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
1.40k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
1.40k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
1.40k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
#ifdef SWAP_IN_RELOC_OFFSET
139
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
#endif
141
1.40k
}
pe-x86_64.c:coff_swap_reloc_in
Line
Count
Source
131
2.69k
{
132
2.69k
  RELOC *reloc_src = (RELOC *) src;
133
2.69k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
2.69k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
2.69k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
2.69k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
#ifdef SWAP_IN_RELOC_OFFSET
139
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
#endif
141
2.69k
}
pei-x86_64.c:coff_swap_reloc_in
Line
Count
Source
131
2.33k
{
132
2.33k
  RELOC *reloc_src = (RELOC *) src;
133
2.33k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
2.33k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
2.33k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
2.33k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
#ifdef SWAP_IN_RELOC_OFFSET
139
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
#endif
141
2.33k
}
pei-aarch64.c:coff_swap_reloc_in
Line
Count
Source
131
2.89k
{
132
2.89k
  RELOC *reloc_src = (RELOC *) src;
133
2.89k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
2.89k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
2.89k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
2.89k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
#ifdef SWAP_IN_RELOC_OFFSET
139
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
#endif
141
2.89k
}
pe-aarch64.c:coff_swap_reloc_in
Line
Count
Source
131
795
{
132
795
  RELOC *reloc_src = (RELOC *) src;
133
795
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
795
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
795
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
795
  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
795
}
pei-ia64.c:coff_swap_reloc_in
Line
Count
Source
131
1.58k
{
132
1.58k
  RELOC *reloc_src = (RELOC *) src;
133
1.58k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
1.58k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
1.58k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
1.58k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
#ifdef SWAP_IN_RELOC_OFFSET
139
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
#endif
141
1.58k
}
pei-loongarch64.c:coff_swap_reloc_in
Line
Count
Source
131
2.32k
{
132
2.32k
  RELOC *reloc_src = (RELOC *) src;
133
2.32k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
2.32k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
2.32k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
2.32k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
2.32k
#ifdef SWAP_IN_RELOC_OFFSET
139
2.32k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
2.32k
#endif
141
2.32k
}
pe-arm-wince.c:coff_swap_reloc_in
Line
Count
Source
131
930
{
132
930
  RELOC *reloc_src = (RELOC *) src;
133
930
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
930
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
930
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
930
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
930
#ifdef SWAP_IN_RELOC_OFFSET
139
930
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
930
#endif
141
930
}
pe-arm.c:coff_swap_reloc_in
Line
Count
Source
131
930
{
132
930
  RELOC *reloc_src = (RELOC *) src;
133
930
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
930
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
930
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
930
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
930
#ifdef SWAP_IN_RELOC_OFFSET
139
930
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
930
#endif
141
930
}
pe-i386.c:coff_swap_reloc_in
Line
Count
Source
131
2.12k
{
132
2.12k
  RELOC *reloc_src = (RELOC *) src;
133
2.12k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
2.12k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
2.12k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
2.12k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
#ifdef SWAP_IN_RELOC_OFFSET
139
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
#endif
141
2.12k
}
pe-mcore.c:coff_swap_reloc_in
Line
Count
Source
131
3.02k
{
132
3.02k
  RELOC *reloc_src = (RELOC *) src;
133
3.02k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
3.02k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
3.02k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
3.02k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
3.02k
#ifdef SWAP_IN_RELOC_OFFSET
139
3.02k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
3.02k
#endif
141
3.02k
}
pe-sh.c:coff_swap_reloc_in
Line
Count
Source
131
1.00k
{
132
1.00k
  RELOC *reloc_src = (RELOC *) src;
133
1.00k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
1.00k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
1.00k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
1.00k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
#ifdef SWAP_IN_RELOC_OFFSET
139
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
#endif
141
1.00k
}
pei-arm-wince.c:coff_swap_reloc_in
Line
Count
Source
131
2.42k
{
132
2.42k
  RELOC *reloc_src = (RELOC *) src;
133
2.42k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
2.42k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
2.42k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
2.42k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
2.42k
#ifdef SWAP_IN_RELOC_OFFSET
139
2.42k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
2.42k
#endif
141
2.42k
}
pei-arm.c:coff_swap_reloc_in
Line
Count
Source
131
2.76k
{
132
2.76k
  RELOC *reloc_src = (RELOC *) src;
133
2.76k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
2.76k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
2.76k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
2.76k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
2.76k
#ifdef SWAP_IN_RELOC_OFFSET
139
2.76k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
2.76k
#endif
141
2.76k
}
pei-mcore.c:coff_swap_reloc_in
Line
Count
Source
131
2.02k
{
132
2.02k
  RELOC *reloc_src = (RELOC *) src;
133
2.02k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
2.02k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
2.02k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
2.02k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
2.02k
#ifdef SWAP_IN_RELOC_OFFSET
139
2.02k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
2.02k
#endif
141
2.02k
}
pei-sh.c:coff_swap_reloc_in
Line
Count
Source
131
4.82k
{
132
4.82k
  RELOC *reloc_src = (RELOC *) src;
133
4.82k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
4.82k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
4.82k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
4.82k
  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
4.82k
}
142
143
static unsigned int
144
coff_swap_reloc_out (bfd * abfd, void * src, void * dst)
145
0
{
146
0
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
147
0
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
148
149
0
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
150
0
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
151
0
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
152
153
#ifdef SWAP_OUT_RELOC_OFFSET
154
0
  SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
155
#endif
156
#ifdef SWAP_OUT_RELOC_EXTRA
157
  SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
158
#endif
159
0
  return RELSZ;
160
0
}
Unexecuted instantiation: pei-i386.c:coff_swap_reloc_out
Unexecuted instantiation: pe-x86_64.c:coff_swap_reloc_out
Unexecuted instantiation: pei-x86_64.c:coff_swap_reloc_out
Unexecuted instantiation: pei-aarch64.c:coff_swap_reloc_out
Unexecuted instantiation: pe-aarch64.c:coff_swap_reloc_out
Unexecuted instantiation: pei-ia64.c:coff_swap_reloc_out
Unexecuted instantiation: pei-loongarch64.c:coff_swap_reloc_out
Unexecuted instantiation: pe-arm-wince.c:coff_swap_reloc_out
Unexecuted instantiation: pe-arm.c:coff_swap_reloc_out
Unexecuted instantiation: pe-i386.c:coff_swap_reloc_out
Unexecuted instantiation: pe-mcore.c:coff_swap_reloc_out
Unexecuted instantiation: pe-sh.c:coff_swap_reloc_out
Unexecuted instantiation: pei-arm-wince.c:coff_swap_reloc_out
Unexecuted instantiation: pei-arm.c:coff_swap_reloc_out
Unexecuted instantiation: pei-mcore.c:coff_swap_reloc_out
Unexecuted instantiation: pei-sh.c:coff_swap_reloc_out
161
#endif /* not NO_COFF_RELOCS */
162
163
#ifdef COFF_IMAGE_WITH_PE
164
#undef FILHDR
165
1.57M
#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
7.43M
{
171
7.43M
  FILHDR *filehdr_src = (FILHDR *) src;
172
7.43M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
7.43M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
7.43M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
7.43M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
7.43M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
7.43M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
7.43M
  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
7.43M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
625k
    {
185
625k
      filehdr_dst->f_nsyms = 0;
186
625k
      filehdr_dst->f_flags |= F_LSYMS;
187
625k
    }
188
189
7.43M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
7.43M
}
pei-i386.c:coff_swap_filehdr_in
Line
Count
Source
170
177k
{
171
177k
  FILHDR *filehdr_src = (FILHDR *) src;
172
177k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
177k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
177k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
177k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
177k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
177k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
177k
  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
177k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
20.8k
    {
185
20.8k
      filehdr_dst->f_nsyms = 0;
186
20.8k
      filehdr_dst->f_flags |= F_LSYMS;
187
20.8k
    }
188
189
177k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
177k
}
pe-x86_64.c:coff_swap_filehdr_in
Line
Count
Source
170
589k
{
171
589k
  FILHDR *filehdr_src = (FILHDR *) src;
172
589k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
589k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
589k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
589k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
589k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
589k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
589k
  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
589k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
44.6k
    {
185
44.6k
      filehdr_dst->f_nsyms = 0;
186
44.6k
      filehdr_dst->f_flags |= F_LSYMS;
187
44.6k
    }
188
189
589k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
589k
}
pei-x86_64.c:coff_swap_filehdr_in
Line
Count
Source
170
183k
{
171
183k
  FILHDR *filehdr_src = (FILHDR *) src;
172
183k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
183k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
183k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
183k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
183k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
183k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
183k
  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
183k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
20.4k
    {
185
20.4k
      filehdr_dst->f_nsyms = 0;
186
20.4k
      filehdr_dst->f_flags |= F_LSYMS;
187
20.4k
    }
188
189
183k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
183k
}
pei-aarch64.c:coff_swap_filehdr_in
Line
Count
Source
170
173k
{
171
173k
  FILHDR *filehdr_src = (FILHDR *) src;
172
173k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
173k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
173k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
173k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
173k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
173k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
173k
  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
173k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
20.1k
    {
185
20.1k
      filehdr_dst->f_nsyms = 0;
186
20.1k
      filehdr_dst->f_flags |= F_LSYMS;
187
20.1k
    }
188
189
173k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
173k
}
pe-aarch64.c:coff_swap_filehdr_in
Line
Count
Source
170
585k
{
171
585k
  FILHDR *filehdr_src = (FILHDR *) src;
172
585k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
585k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
585k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
585k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
585k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
585k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
585k
  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
585k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
44.3k
    {
185
44.3k
      filehdr_dst->f_nsyms = 0;
186
44.3k
      filehdr_dst->f_flags |= F_LSYMS;
187
44.3k
    }
188
189
585k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
585k
}
pei-ia64.c:coff_swap_filehdr_in
Line
Count
Source
170
173k
{
171
173k
  FILHDR *filehdr_src = (FILHDR *) src;
172
173k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
173k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
173k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
173k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
173k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
173k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
173k
  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
173k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
20.1k
    {
185
20.1k
      filehdr_dst->f_nsyms = 0;
186
20.1k
      filehdr_dst->f_flags |= F_LSYMS;
187
20.1k
    }
188
189
173k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
173k
}
pei-loongarch64.c:coff_swap_filehdr_in
Line
Count
Source
170
173k
{
171
173k
  FILHDR *filehdr_src = (FILHDR *) src;
172
173k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
173k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
173k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
173k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
173k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
173k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
173k
  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
173k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
20.1k
    {
185
20.1k
      filehdr_dst->f_nsyms = 0;
186
20.1k
      filehdr_dst->f_flags |= F_LSYMS;
187
20.1k
    }
188
189
173k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
173k
}
pe-arm-wince.c:coff_swap_filehdr_in
Line
Count
Source
170
1.16M
{
171
1.16M
  FILHDR *filehdr_src = (FILHDR *) src;
172
1.16M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
1.16M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
1.16M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
1.16M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
1.16M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
1.16M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
1.16M
  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.16M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
88.6k
    {
185
88.6k
      filehdr_dst->f_nsyms = 0;
186
88.6k
      filehdr_dst->f_flags |= F_LSYMS;
187
88.6k
    }
188
189
1.16M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
1.16M
}
pe-arm.c:coff_swap_filehdr_in
Line
Count
Source
170
1.16M
{
171
1.16M
  FILHDR *filehdr_src = (FILHDR *) src;
172
1.16M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
1.16M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
1.16M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
1.16M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
1.16M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
1.16M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
1.16M
  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.16M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
88.6k
    {
185
88.6k
      filehdr_dst->f_nsyms = 0;
186
88.6k
      filehdr_dst->f_flags |= F_LSYMS;
187
88.6k
    }
188
189
1.16M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
1.16M
}
pe-i386.c:coff_swap_filehdr_in
Line
Count
Source
170
584k
{
171
584k
  FILHDR *filehdr_src = (FILHDR *) src;
172
584k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
584k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
584k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
584k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
584k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
584k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
584k
  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
584k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
44.3k
    {
185
44.3k
      filehdr_dst->f_nsyms = 0;
186
44.3k
      filehdr_dst->f_flags |= F_LSYMS;
187
44.3k
    }
188
189
584k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
584k
}
pe-mcore.c:coff_swap_filehdr_in
Line
Count
Source
170
1.17M
{
171
1.17M
  FILHDR *filehdr_src = (FILHDR *) src;
172
1.17M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
1.17M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
1.17M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
1.17M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
1.17M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
1.17M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
1.17M
  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.17M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
88.4k
    {
185
88.4k
      filehdr_dst->f_nsyms = 0;
186
88.4k
      filehdr_dst->f_flags |= F_LSYMS;
187
88.4k
    }
188
189
1.17M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
1.17M
}
pe-sh.c:coff_swap_filehdr_in
Line
Count
Source
170
585k
{
171
585k
  FILHDR *filehdr_src = (FILHDR *) src;
172
585k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
585k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
585k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
585k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
585k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
585k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
585k
  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
585k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
44.2k
    {
185
44.2k
      filehdr_dst->f_nsyms = 0;
186
44.2k
      filehdr_dst->f_flags |= F_LSYMS;
187
44.2k
    }
188
189
585k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
585k
}
pei-arm-wince.c:coff_swap_filehdr_in
Line
Count
Source
170
173k
{
171
173k
  FILHDR *filehdr_src = (FILHDR *) src;
172
173k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
173k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
173k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
173k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
173k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
173k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
173k
  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
173k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
20.1k
    {
185
20.1k
      filehdr_dst->f_nsyms = 0;
186
20.1k
      filehdr_dst->f_flags |= F_LSYMS;
187
20.1k
    }
188
189
173k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
173k
}
pei-arm.c:coff_swap_filehdr_in
Line
Count
Source
170
173k
{
171
173k
  FILHDR *filehdr_src = (FILHDR *) src;
172
173k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
173k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
173k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
173k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
173k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
173k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
173k
  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
173k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
20.1k
    {
185
20.1k
      filehdr_dst->f_nsyms = 0;
186
20.1k
      filehdr_dst->f_flags |= F_LSYMS;
187
20.1k
    }
188
189
173k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
173k
}
pei-mcore.c:coff_swap_filehdr_in
Line
Count
Source
170
173k
{
171
173k
  FILHDR *filehdr_src = (FILHDR *) src;
172
173k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
173k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
173k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
173k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
173k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
173k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
173k
  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
173k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
20.1k
    {
185
20.1k
      filehdr_dst->f_nsyms = 0;
186
20.1k
      filehdr_dst->f_flags |= F_LSYMS;
187
20.1k
    }
188
189
173k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
173k
}
pei-sh.c:coff_swap_filehdr_in
Line
Count
Source
170
173k
{
171
173k
  FILHDR *filehdr_src = (FILHDR *) src;
172
173k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
173k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
173k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
173k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
173k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
173k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
173k
  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
173k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
20.1k
    {
185
20.1k
      filehdr_dst->f_nsyms = 0;
186
20.1k
      filehdr_dst->f_flags |= F_LSYMS;
187
20.1k
    }
188
189
173k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
173k
}
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
1.14M
{
207
1.14M
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
1.14M
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
1.14M
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
1.14M
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
1.14M
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
1.14M
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
1.14M
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
1.14M
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
1.14M
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
1.14M
  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
485k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
485k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
  scnhdr_int->s_nreloc = 0;
227
#else
228
659k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
659k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
#endif
231
232
1.14M
  if (scnhdr_int->s_vaddr != 0)
233
512k
    {
234
512k
      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
512k
    }
240
241
1.14M
#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
1.14M
  if (scnhdr_int->s_paddr > 0
247
1.14M
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
498k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
498k
    || (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
188k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
1.14M
#endif
256
1.14M
}
pei-i386.c:coff_swap_scnhdr_in
Line
Count
Source
206
37.7k
{
207
37.7k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
37.7k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
37.7k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
37.7k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
37.7k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
37.7k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
37.7k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
37.7k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
37.7k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
37.7k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
37.7k
#ifdef COFF_IMAGE_WITH_PE
224
37.7k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
37.7k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
37.7k
  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
37.7k
  if (scnhdr_int->s_vaddr != 0)
233
30.5k
    {
234
30.5k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
30.5k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
30.5k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
30.5k
#endif
239
30.5k
    }
240
241
37.7k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
37.7k
  if (scnhdr_int->s_paddr > 0
247
37.7k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
31.5k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
31.5k
    || (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
13.7k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
37.7k
#endif
256
37.7k
}
pe-x86_64.c:coff_swap_scnhdr_in
Line
Count
Source
206
62.0k
{
207
62.0k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
62.0k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
62.0k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
62.0k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
62.0k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
62.0k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
62.0k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
62.0k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
62.0k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
62.0k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
#ifdef COFF_IMAGE_WITH_PE
224
  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
62.0k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
62.0k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
62.0k
#endif
231
232
62.0k
  if (scnhdr_int->s_vaddr != 0)
233
53.4k
    {
234
53.4k
      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
53.4k
    }
240
241
62.0k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
62.0k
  if (scnhdr_int->s_paddr > 0
247
62.0k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
53.5k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
53.5k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
10.1k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
62.0k
#endif
256
62.0k
}
pei-x86_64.c:coff_swap_scnhdr_in
Line
Count
Source
206
87.7k
{
207
87.7k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
87.7k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
87.7k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
87.7k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
87.7k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
87.7k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
87.7k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
87.7k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
87.7k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
87.7k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
87.7k
#ifdef COFF_IMAGE_WITH_PE
224
87.7k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
87.7k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
87.7k
  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
87.7k
  if (scnhdr_int->s_vaddr != 0)
233
63.5k
    {
234
63.5k
      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
63.5k
    }
240
241
87.7k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
87.7k
  if (scnhdr_int->s_paddr > 0
247
87.7k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
52.7k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
52.7k
    || (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
34.2k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
87.7k
#endif
256
87.7k
}
pei-aarch64.c:coff_swap_scnhdr_in
Line
Count
Source
206
32.4k
{
207
32.4k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
32.4k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
32.4k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
32.4k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
32.4k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
32.4k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
32.4k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
32.4k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
32.4k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
32.4k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
32.4k
#ifdef COFF_IMAGE_WITH_PE
224
32.4k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
32.4k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
32.4k
  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
32.4k
  if (scnhdr_int->s_vaddr != 0)
233
26.6k
    {
234
26.6k
      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
26.6k
    }
240
241
32.4k
#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
32.4k
  if (scnhdr_int->s_paddr > 0
247
32.4k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
25.6k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
25.6k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
10.4k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
32.4k
#endif
256
32.4k
}
pe-aarch64.c:coff_swap_scnhdr_in
Line
Count
Source
206
14.3k
{
207
14.3k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
14.3k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
14.3k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
14.3k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
14.3k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
14.3k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
14.3k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
14.3k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
14.3k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
14.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
14.3k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
14.3k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
14.3k
#endif
231
232
14.3k
  if (scnhdr_int->s_vaddr != 0)
233
8.11k
    {
234
8.11k
      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
8.11k
    }
240
241
14.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
14.3k
  if (scnhdr_int->s_paddr > 0
247
14.3k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
8.14k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
8.14k
    || (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
773
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
14.3k
#endif
256
14.3k
}
pei-ia64.c:coff_swap_scnhdr_in
Line
Count
Source
206
51.3k
{
207
51.3k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
51.3k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
51.3k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
51.3k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
51.3k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
51.3k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
51.3k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
51.3k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
51.3k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
51.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
51.3k
#ifdef COFF_IMAGE_WITH_PE
224
51.3k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
51.3k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
51.3k
  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
51.3k
  if (scnhdr_int->s_vaddr != 0)
233
42.0k
    {
234
42.0k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
42.0k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
42.0k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
42.0k
#endif
239
42.0k
    }
240
241
51.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
51.3k
  if (scnhdr_int->s_paddr > 0
247
51.3k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
42.7k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
42.7k
    || (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
15.3k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
51.3k
#endif
256
51.3k
}
pei-loongarch64.c:coff_swap_scnhdr_in
Line
Count
Source
206
104k
{
207
104k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
104k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
104k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
104k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
104k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
104k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
104k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
104k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
104k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
104k
  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
104k
#ifdef COFF_IMAGE_WITH_PE
224
104k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
104k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
104k
  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
104k
  if (scnhdr_int->s_vaddr != 0)
233
49.2k
    {
234
49.2k
      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
49.2k
    }
240
241
104k
#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
104k
  if (scnhdr_int->s_paddr > 0
247
104k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
50.6k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
50.6k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
16.2k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
104k
#endif
256
104k
}
pe-arm-wince.c:coff_swap_scnhdr_in
Line
Count
Source
206
9.74k
{
207
9.74k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
9.74k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
9.74k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
9.74k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
9.74k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
9.74k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
9.74k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
9.74k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
9.74k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
9.74k
  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
9.74k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
9.74k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
9.74k
#endif
231
232
9.74k
  if (scnhdr_int->s_vaddr != 0)
233
8.53k
    {
234
8.53k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
8.53k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
8.53k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
8.53k
#endif
239
8.53k
    }
240
241
9.74k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
9.74k
  if (scnhdr_int->s_paddr > 0
247
9.74k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
7.95k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
7.95k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
1.50k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
9.74k
#endif
256
9.74k
}
pe-arm.c:coff_swap_scnhdr_in
Line
Count
Source
206
9.74k
{
207
9.74k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
9.74k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
9.74k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
9.74k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
9.74k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
9.74k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
9.74k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
9.74k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
9.74k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
9.74k
  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
9.74k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
9.74k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
9.74k
#endif
231
232
9.74k
  if (scnhdr_int->s_vaddr != 0)
233
8.53k
    {
234
8.53k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
8.53k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
8.53k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
8.53k
#endif
239
8.53k
    }
240
241
9.74k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
9.74k
  if (scnhdr_int->s_paddr > 0
247
9.74k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
7.95k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
7.95k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
1.50k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
9.74k
#endif
256
9.74k
}
pe-i386.c:coff_swap_scnhdr_in
Line
Count
Source
206
41.0k
{
207
41.0k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
41.0k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
41.0k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
41.0k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
41.0k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
41.0k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
41.0k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
41.0k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
41.0k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
41.0k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
#ifdef COFF_IMAGE_WITH_PE
224
  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
41.0k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
41.0k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
41.0k
#endif
231
232
41.0k
  if (scnhdr_int->s_vaddr != 0)
233
32.7k
    {
234
32.7k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
32.7k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
32.7k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
32.7k
#endif
239
32.7k
    }
240
241
41.0k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
41.0k
  if (scnhdr_int->s_paddr > 0
247
41.0k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
30.2k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
30.2k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
11.5k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
41.0k
#endif
256
41.0k
}
pe-mcore.c:coff_swap_scnhdr_in
Line
Count
Source
206
492k
{
207
492k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
492k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
492k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
492k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
492k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
492k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
492k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
492k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
492k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
492k
  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
492k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
492k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
492k
#endif
231
232
492k
  if (scnhdr_int->s_vaddr != 0)
233
26.0k
    {
234
26.0k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
26.0k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
26.0k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
26.0k
#endif
239
26.0k
    }
240
241
492k
#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
492k
  if (scnhdr_int->s_paddr > 0
247
492k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
26.2k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
26.2k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
8.21k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
492k
#endif
256
492k
}
pe-sh.c:coff_swap_scnhdr_in
Line
Count
Source
206
30.0k
{
207
30.0k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
30.0k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
30.0k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
30.0k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
30.0k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
30.0k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
30.0k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
30.0k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
30.0k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
30.0k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
#ifdef COFF_IMAGE_WITH_PE
224
  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
30.0k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
30.0k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
30.0k
#endif
231
232
30.0k
  if (scnhdr_int->s_vaddr != 0)
233
25.9k
    {
234
25.9k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
25.9k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
25.9k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
25.9k
#endif
239
25.9k
    }
240
241
30.0k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
30.0k
  if (scnhdr_int->s_paddr > 0
247
30.0k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
24.1k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
24.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
6.46k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
30.0k
#endif
256
30.0k
}
pei-arm-wince.c:coff_swap_scnhdr_in
Line
Count
Source
206
33.3k
{
207
33.3k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
33.3k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
33.3k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
33.3k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
33.3k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
33.3k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
33.3k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
33.3k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
33.3k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
33.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
33.3k
#ifdef COFF_IMAGE_WITH_PE
224
33.3k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
33.3k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
33.3k
  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
33.3k
  if (scnhdr_int->s_vaddr != 0)
233
29.1k
    {
234
29.1k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
29.1k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
29.1k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
29.1k
#endif
239
29.1k
    }
240
241
33.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
33.3k
  if (scnhdr_int->s_paddr > 0
247
33.3k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
27.7k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
27.7k
    || (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
11.5k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
33.3k
#endif
256
33.3k
}
pei-arm.c:coff_swap_scnhdr_in
Line
Count
Source
206
39.7k
{
207
39.7k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
39.7k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
39.7k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
39.7k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
39.7k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
39.7k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
39.7k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
39.7k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
39.7k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
39.7k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
39.7k
#ifdef COFF_IMAGE_WITH_PE
224
39.7k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
39.7k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
39.7k
  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
39.7k
  if (scnhdr_int->s_vaddr != 0)
233
33.9k
    {
234
33.9k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
33.9k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
33.9k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
33.9k
#endif
239
33.9k
    }
240
241
39.7k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
39.7k
  if (scnhdr_int->s_paddr > 0
247
39.7k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
33.1k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
33.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
15.2k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
39.7k
#endif
256
39.7k
}
pei-mcore.c:coff_swap_scnhdr_in
Line
Count
Source
206
47.8k
{
207
47.8k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
47.8k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
47.8k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
47.8k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
47.8k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
47.8k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
47.8k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
47.8k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
47.8k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
47.8k
  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
47.8k
#ifdef COFF_IMAGE_WITH_PE
224
47.8k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
47.8k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
47.8k
  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
47.8k
  if (scnhdr_int->s_vaddr != 0)
233
40.4k
    {
234
40.4k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
40.4k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
40.4k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
40.4k
#endif
239
40.4k
    }
240
241
47.8k
#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
47.8k
  if (scnhdr_int->s_paddr > 0
247
47.8k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
39.3k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
39.3k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
15.8k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
47.8k
#endif
256
47.8k
}
pei-sh.c:coff_swap_scnhdr_in
Line
Count
Source
206
50.7k
{
207
50.7k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
50.7k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
50.7k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
50.7k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
50.7k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
50.7k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
50.7k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
50.7k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
50.7k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
50.7k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
50.7k
#ifdef COFF_IMAGE_WITH_PE
224
50.7k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
50.7k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
50.7k
  scnhdr_int->s_nreloc = 0;
227
#else
228
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
#endif
231
232
50.7k
  if (scnhdr_int->s_vaddr != 0)
233
33.5k
    {
234
33.5k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
33.5k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
33.5k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
33.5k
#endif
239
33.5k
    }
240
241
50.7k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
50.7k
  if (scnhdr_int->s_paddr > 0
247
50.7k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
36.3k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
36.3k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
15.4k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
50.7k
#endif
256
50.7k
}
257
258
static bool
259
pe_mkobject (bfd * abfd)
260
282k
{
261
282k
  pe_data_type *pe;
262
282k
  size_t amt = sizeof (pe_data_type);
263
264
282k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
282k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
282k
  pe = pe_data (abfd);
270
271
282k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
282k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
282k
  pe->dos_message[0]  = 0x0eba1f0e;
278
282k
  pe->dos_message[1]  = 0xcd09b400;
279
282k
  pe->dos_message[2]  = 0x4c01b821;
280
282k
  pe->dos_message[3]  = 0x685421cd;
281
282k
  pe->dos_message[4]  = 0x70207369;
282
282k
  pe->dos_message[5]  = 0x72676f72;
283
282k
  pe->dos_message[6]  = 0x63206d61;
284
282k
  pe->dos_message[7]  = 0x6f6e6e61;
285
282k
  pe->dos_message[8]  = 0x65622074;
286
282k
  pe->dos_message[9]  = 0x6e757220;
287
282k
  pe->dos_message[10] = 0x206e6920;
288
282k
  pe->dos_message[11] = 0x20534f44;
289
282k
  pe->dos_message[12] = 0x65646f6d;
290
282k
  pe->dos_message[13] = 0x0a0d0d2e;
291
282k
  pe->dos_message[14] = 0x24;
292
282k
  pe->dos_message[15] = 0x0;
293
294
282k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
282k
  bfd_coff_long_section_names (abfd)
297
282k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
282k
  return true;
300
282k
}
pei-i386.c:pe_mkobject
Line
Count
Source
260
24.1k
{
261
24.1k
  pe_data_type *pe;
262
24.1k
  size_t amt = sizeof (pe_data_type);
263
264
24.1k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
24.1k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
24.1k
  pe = pe_data (abfd);
270
271
24.1k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
24.1k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
24.1k
  pe->dos_message[0]  = 0x0eba1f0e;
278
24.1k
  pe->dos_message[1]  = 0xcd09b400;
279
24.1k
  pe->dos_message[2]  = 0x4c01b821;
280
24.1k
  pe->dos_message[3]  = 0x685421cd;
281
24.1k
  pe->dos_message[4]  = 0x70207369;
282
24.1k
  pe->dos_message[5]  = 0x72676f72;
283
24.1k
  pe->dos_message[6]  = 0x63206d61;
284
24.1k
  pe->dos_message[7]  = 0x6f6e6e61;
285
24.1k
  pe->dos_message[8]  = 0x65622074;
286
24.1k
  pe->dos_message[9]  = 0x6e757220;
287
24.1k
  pe->dos_message[10] = 0x206e6920;
288
24.1k
  pe->dos_message[11] = 0x20534f44;
289
24.1k
  pe->dos_message[12] = 0x65646f6d;
290
24.1k
  pe->dos_message[13] = 0x0a0d0d2e;
291
24.1k
  pe->dos_message[14] = 0x24;
292
24.1k
  pe->dos_message[15] = 0x0;
293
294
24.1k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
24.1k
  bfd_coff_long_section_names (abfd)
297
24.1k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
24.1k
  return true;
300
24.1k
}
pe-x86_64.c:pe_mkobject
Line
Count
Source
260
26.9k
{
261
26.9k
  pe_data_type *pe;
262
26.9k
  size_t amt = sizeof (pe_data_type);
263
264
26.9k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
26.9k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
26.9k
  pe = pe_data (abfd);
270
271
26.9k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
26.9k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
26.9k
  pe->dos_message[0]  = 0x0eba1f0e;
278
26.9k
  pe->dos_message[1]  = 0xcd09b400;
279
26.9k
  pe->dos_message[2]  = 0x4c01b821;
280
26.9k
  pe->dos_message[3]  = 0x685421cd;
281
26.9k
  pe->dos_message[4]  = 0x70207369;
282
26.9k
  pe->dos_message[5]  = 0x72676f72;
283
26.9k
  pe->dos_message[6]  = 0x63206d61;
284
26.9k
  pe->dos_message[7]  = 0x6f6e6e61;
285
26.9k
  pe->dos_message[8]  = 0x65622074;
286
26.9k
  pe->dos_message[9]  = 0x6e757220;
287
26.9k
  pe->dos_message[10] = 0x206e6920;
288
26.9k
  pe->dos_message[11] = 0x20534f44;
289
26.9k
  pe->dos_message[12] = 0x65646f6d;
290
26.9k
  pe->dos_message[13] = 0x0a0d0d2e;
291
26.9k
  pe->dos_message[14] = 0x24;
292
26.9k
  pe->dos_message[15] = 0x0;
293
294
26.9k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
26.9k
  bfd_coff_long_section_names (abfd)
297
26.9k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
26.9k
  return true;
300
26.9k
}
pei-x86_64.c:pe_mkobject
Line
Count
Source
260
36.1k
{
261
36.1k
  pe_data_type *pe;
262
36.1k
  size_t amt = sizeof (pe_data_type);
263
264
36.1k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
36.1k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
36.1k
  pe = pe_data (abfd);
270
271
36.1k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
36.1k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
36.1k
  pe->dos_message[0]  = 0x0eba1f0e;
278
36.1k
  pe->dos_message[1]  = 0xcd09b400;
279
36.1k
  pe->dos_message[2]  = 0x4c01b821;
280
36.1k
  pe->dos_message[3]  = 0x685421cd;
281
36.1k
  pe->dos_message[4]  = 0x70207369;
282
36.1k
  pe->dos_message[5]  = 0x72676f72;
283
36.1k
  pe->dos_message[6]  = 0x63206d61;
284
36.1k
  pe->dos_message[7]  = 0x6f6e6e61;
285
36.1k
  pe->dos_message[8]  = 0x65622074;
286
36.1k
  pe->dos_message[9]  = 0x6e757220;
287
36.1k
  pe->dos_message[10] = 0x206e6920;
288
36.1k
  pe->dos_message[11] = 0x20534f44;
289
36.1k
  pe->dos_message[12] = 0x65646f6d;
290
36.1k
  pe->dos_message[13] = 0x0a0d0d2e;
291
36.1k
  pe->dos_message[14] = 0x24;
292
36.1k
  pe->dos_message[15] = 0x0;
293
294
36.1k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
36.1k
  bfd_coff_long_section_names (abfd)
297
36.1k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
36.1k
  return true;
300
36.1k
}
pei-aarch64.c:pe_mkobject
Line
Count
Source
260
13.9k
{
261
13.9k
  pe_data_type *pe;
262
13.9k
  size_t amt = sizeof (pe_data_type);
263
264
13.9k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
13.9k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
13.9k
  pe = pe_data (abfd);
270
271
13.9k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
13.9k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
13.9k
  pe->dos_message[0]  = 0x0eba1f0e;
278
13.9k
  pe->dos_message[1]  = 0xcd09b400;
279
13.9k
  pe->dos_message[2]  = 0x4c01b821;
280
13.9k
  pe->dos_message[3]  = 0x685421cd;
281
13.9k
  pe->dos_message[4]  = 0x70207369;
282
13.9k
  pe->dos_message[5]  = 0x72676f72;
283
13.9k
  pe->dos_message[6]  = 0x63206d61;
284
13.9k
  pe->dos_message[7]  = 0x6f6e6e61;
285
13.9k
  pe->dos_message[8]  = 0x65622074;
286
13.9k
  pe->dos_message[9]  = 0x6e757220;
287
13.9k
  pe->dos_message[10] = 0x206e6920;
288
13.9k
  pe->dos_message[11] = 0x20534f44;
289
13.9k
  pe->dos_message[12] = 0x65646f6d;
290
13.9k
  pe->dos_message[13] = 0x0a0d0d2e;
291
13.9k
  pe->dos_message[14] = 0x24;
292
13.9k
  pe->dos_message[15] = 0x0;
293
294
13.9k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
13.9k
  bfd_coff_long_section_names (abfd)
297
13.9k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
13.9k
  return true;
300
13.9k
}
pe-aarch64.c:pe_mkobject
Line
Count
Source
260
5.96k
{
261
5.96k
  pe_data_type *pe;
262
5.96k
  size_t amt = sizeof (pe_data_type);
263
264
5.96k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
5.96k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
5.96k
  pe = pe_data (abfd);
270
271
5.96k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
5.96k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
5.96k
  pe->dos_message[0]  = 0x0eba1f0e;
278
5.96k
  pe->dos_message[1]  = 0xcd09b400;
279
5.96k
  pe->dos_message[2]  = 0x4c01b821;
280
5.96k
  pe->dos_message[3]  = 0x685421cd;
281
5.96k
  pe->dos_message[4]  = 0x70207369;
282
5.96k
  pe->dos_message[5]  = 0x72676f72;
283
5.96k
  pe->dos_message[6]  = 0x63206d61;
284
5.96k
  pe->dos_message[7]  = 0x6f6e6e61;
285
5.96k
  pe->dos_message[8]  = 0x65622074;
286
5.96k
  pe->dos_message[9]  = 0x6e757220;
287
5.96k
  pe->dos_message[10] = 0x206e6920;
288
5.96k
  pe->dos_message[11] = 0x20534f44;
289
5.96k
  pe->dos_message[12] = 0x65646f6d;
290
5.96k
  pe->dos_message[13] = 0x0a0d0d2e;
291
5.96k
  pe->dos_message[14] = 0x24;
292
5.96k
  pe->dos_message[15] = 0x0;
293
294
5.96k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
5.96k
  bfd_coff_long_section_names (abfd)
297
5.96k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
5.96k
  return true;
300
5.96k
}
pei-ia64.c:pe_mkobject
Line
Count
Source
260
25.6k
{
261
25.6k
  pe_data_type *pe;
262
25.6k
  size_t amt = sizeof (pe_data_type);
263
264
25.6k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
25.6k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
25.6k
  pe = pe_data (abfd);
270
271
25.6k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
25.6k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
25.6k
  pe->dos_message[0]  = 0x0eba1f0e;
278
25.6k
  pe->dos_message[1]  = 0xcd09b400;
279
25.6k
  pe->dos_message[2]  = 0x4c01b821;
280
25.6k
  pe->dos_message[3]  = 0x685421cd;
281
25.6k
  pe->dos_message[4]  = 0x70207369;
282
25.6k
  pe->dos_message[5]  = 0x72676f72;
283
25.6k
  pe->dos_message[6]  = 0x63206d61;
284
25.6k
  pe->dos_message[7]  = 0x6f6e6e61;
285
25.6k
  pe->dos_message[8]  = 0x65622074;
286
25.6k
  pe->dos_message[9]  = 0x6e757220;
287
25.6k
  pe->dos_message[10] = 0x206e6920;
288
25.6k
  pe->dos_message[11] = 0x20534f44;
289
25.6k
  pe->dos_message[12] = 0x65646f6d;
290
25.6k
  pe->dos_message[13] = 0x0a0d0d2e;
291
25.6k
  pe->dos_message[14] = 0x24;
292
25.6k
  pe->dos_message[15] = 0x0;
293
294
25.6k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
25.6k
  bfd_coff_long_section_names (abfd)
297
25.6k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
25.6k
  return true;
300
25.6k
}
pei-loongarch64.c:pe_mkobject
Line
Count
Source
260
22.1k
{
261
22.1k
  pe_data_type *pe;
262
22.1k
  size_t amt = sizeof (pe_data_type);
263
264
22.1k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
22.1k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
22.1k
  pe = pe_data (abfd);
270
271
22.1k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
22.1k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
22.1k
  pe->dos_message[0]  = 0x0eba1f0e;
278
22.1k
  pe->dos_message[1]  = 0xcd09b400;
279
22.1k
  pe->dos_message[2]  = 0x4c01b821;
280
22.1k
  pe->dos_message[3]  = 0x685421cd;
281
22.1k
  pe->dos_message[4]  = 0x70207369;
282
22.1k
  pe->dos_message[5]  = 0x72676f72;
283
22.1k
  pe->dos_message[6]  = 0x63206d61;
284
22.1k
  pe->dos_message[7]  = 0x6f6e6e61;
285
22.1k
  pe->dos_message[8]  = 0x65622074;
286
22.1k
  pe->dos_message[9]  = 0x6e757220;
287
22.1k
  pe->dos_message[10] = 0x206e6920;
288
22.1k
  pe->dos_message[11] = 0x20534f44;
289
22.1k
  pe->dos_message[12] = 0x65646f6d;
290
22.1k
  pe->dos_message[13] = 0x0a0d0d2e;
291
22.1k
  pe->dos_message[14] = 0x24;
292
22.1k
  pe->dos_message[15] = 0x0;
293
294
22.1k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
22.1k
  bfd_coff_long_section_names (abfd)
297
22.1k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
22.1k
  return true;
300
22.1k
}
pe-arm-wince.c:pe_mkobject
Line
Count
Source
260
4.95k
{
261
4.95k
  pe_data_type *pe;
262
4.95k
  size_t amt = sizeof (pe_data_type);
263
264
4.95k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
4.95k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
4.95k
  pe = pe_data (abfd);
270
271
4.95k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
4.95k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
4.95k
  pe->dos_message[0]  = 0x0eba1f0e;
278
4.95k
  pe->dos_message[1]  = 0xcd09b400;
279
4.95k
  pe->dos_message[2]  = 0x4c01b821;
280
4.95k
  pe->dos_message[3]  = 0x685421cd;
281
4.95k
  pe->dos_message[4]  = 0x70207369;
282
4.95k
  pe->dos_message[5]  = 0x72676f72;
283
4.95k
  pe->dos_message[6]  = 0x63206d61;
284
4.95k
  pe->dos_message[7]  = 0x6f6e6e61;
285
4.95k
  pe->dos_message[8]  = 0x65622074;
286
4.95k
  pe->dos_message[9]  = 0x6e757220;
287
4.95k
  pe->dos_message[10] = 0x206e6920;
288
4.95k
  pe->dos_message[11] = 0x20534f44;
289
4.95k
  pe->dos_message[12] = 0x65646f6d;
290
4.95k
  pe->dos_message[13] = 0x0a0d0d2e;
291
4.95k
  pe->dos_message[14] = 0x24;
292
4.95k
  pe->dos_message[15] = 0x0;
293
294
4.95k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
4.95k
  bfd_coff_long_section_names (abfd)
297
4.95k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
4.95k
  return true;
300
4.95k
}
pe-arm.c:pe_mkobject
Line
Count
Source
260
4.95k
{
261
4.95k
  pe_data_type *pe;
262
4.95k
  size_t amt = sizeof (pe_data_type);
263
264
4.95k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
4.95k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
4.95k
  pe = pe_data (abfd);
270
271
4.95k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
4.95k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
4.95k
  pe->dos_message[0]  = 0x0eba1f0e;
278
4.95k
  pe->dos_message[1]  = 0xcd09b400;
279
4.95k
  pe->dos_message[2]  = 0x4c01b821;
280
4.95k
  pe->dos_message[3]  = 0x685421cd;
281
4.95k
  pe->dos_message[4]  = 0x70207369;
282
4.95k
  pe->dos_message[5]  = 0x72676f72;
283
4.95k
  pe->dos_message[6]  = 0x63206d61;
284
4.95k
  pe->dos_message[7]  = 0x6f6e6e61;
285
4.95k
  pe->dos_message[8]  = 0x65622074;
286
4.95k
  pe->dos_message[9]  = 0x6e757220;
287
4.95k
  pe->dos_message[10] = 0x206e6920;
288
4.95k
  pe->dos_message[11] = 0x20534f44;
289
4.95k
  pe->dos_message[12] = 0x65646f6d;
290
4.95k
  pe->dos_message[13] = 0x0a0d0d2e;
291
4.95k
  pe->dos_message[14] = 0x24;
292
4.95k
  pe->dos_message[15] = 0x0;
293
294
4.95k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
4.95k
  bfd_coff_long_section_names (abfd)
297
4.95k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
4.95k
  return true;
300
4.95k
}
pe-i386.c:pe_mkobject
Line
Count
Source
260
17.6k
{
261
17.6k
  pe_data_type *pe;
262
17.6k
  size_t amt = sizeof (pe_data_type);
263
264
17.6k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
17.6k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
17.6k
  pe = pe_data (abfd);
270
271
17.6k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
17.6k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
17.6k
  pe->dos_message[0]  = 0x0eba1f0e;
278
17.6k
  pe->dos_message[1]  = 0xcd09b400;
279
17.6k
  pe->dos_message[2]  = 0x4c01b821;
280
17.6k
  pe->dos_message[3]  = 0x685421cd;
281
17.6k
  pe->dos_message[4]  = 0x70207369;
282
17.6k
  pe->dos_message[5]  = 0x72676f72;
283
17.6k
  pe->dos_message[6]  = 0x63206d61;
284
17.6k
  pe->dos_message[7]  = 0x6f6e6e61;
285
17.6k
  pe->dos_message[8]  = 0x65622074;
286
17.6k
  pe->dos_message[9]  = 0x6e757220;
287
17.6k
  pe->dos_message[10] = 0x206e6920;
288
17.6k
  pe->dos_message[11] = 0x20534f44;
289
17.6k
  pe->dos_message[12] = 0x65646f6d;
290
17.6k
  pe->dos_message[13] = 0x0a0d0d2e;
291
17.6k
  pe->dos_message[14] = 0x24;
292
17.6k
  pe->dos_message[15] = 0x0;
293
294
17.6k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
17.6k
  bfd_coff_long_section_names (abfd)
297
17.6k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
17.6k
  return true;
300
17.6k
}
pe-mcore.c:pe_mkobject
Line
Count
Source
260
8.63k
{
261
8.63k
  pe_data_type *pe;
262
8.63k
  size_t amt = sizeof (pe_data_type);
263
264
8.63k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
8.63k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
8.63k
  pe = pe_data (abfd);
270
271
8.63k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
8.63k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
8.63k
  pe->dos_message[0]  = 0x0eba1f0e;
278
8.63k
  pe->dos_message[1]  = 0xcd09b400;
279
8.63k
  pe->dos_message[2]  = 0x4c01b821;
280
8.63k
  pe->dos_message[3]  = 0x685421cd;
281
8.63k
  pe->dos_message[4]  = 0x70207369;
282
8.63k
  pe->dos_message[5]  = 0x72676f72;
283
8.63k
  pe->dos_message[6]  = 0x63206d61;
284
8.63k
  pe->dos_message[7]  = 0x6f6e6e61;
285
8.63k
  pe->dos_message[8]  = 0x65622074;
286
8.63k
  pe->dos_message[9]  = 0x6e757220;
287
8.63k
  pe->dos_message[10] = 0x206e6920;
288
8.63k
  pe->dos_message[11] = 0x20534f44;
289
8.63k
  pe->dos_message[12] = 0x65646f6d;
290
8.63k
  pe->dos_message[13] = 0x0a0d0d2e;
291
8.63k
  pe->dos_message[14] = 0x24;
292
8.63k
  pe->dos_message[15] = 0x0;
293
294
8.63k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
8.63k
  bfd_coff_long_section_names (abfd)
297
8.63k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
8.63k
  return true;
300
8.63k
}
pe-sh.c:pe_mkobject
Line
Count
Source
260
11.5k
{
261
11.5k
  pe_data_type *pe;
262
11.5k
  size_t amt = sizeof (pe_data_type);
263
264
11.5k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
11.5k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
11.5k
  pe = pe_data (abfd);
270
271
11.5k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
11.5k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
11.5k
  pe->dos_message[0]  = 0x0eba1f0e;
278
11.5k
  pe->dos_message[1]  = 0xcd09b400;
279
11.5k
  pe->dos_message[2]  = 0x4c01b821;
280
11.5k
  pe->dos_message[3]  = 0x685421cd;
281
11.5k
  pe->dos_message[4]  = 0x70207369;
282
11.5k
  pe->dos_message[5]  = 0x72676f72;
283
11.5k
  pe->dos_message[6]  = 0x63206d61;
284
11.5k
  pe->dos_message[7]  = 0x6f6e6e61;
285
11.5k
  pe->dos_message[8]  = 0x65622074;
286
11.5k
  pe->dos_message[9]  = 0x6e757220;
287
11.5k
  pe->dos_message[10] = 0x206e6920;
288
11.5k
  pe->dos_message[11] = 0x20534f44;
289
11.5k
  pe->dos_message[12] = 0x65646f6d;
290
11.5k
  pe->dos_message[13] = 0x0a0d0d2e;
291
11.5k
  pe->dos_message[14] = 0x24;
292
11.5k
  pe->dos_message[15] = 0x0;
293
294
11.5k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
11.5k
  bfd_coff_long_section_names (abfd)
297
11.5k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
11.5k
  return true;
300
11.5k
}
pei-arm-wince.c:pe_mkobject
Line
Count
Source
260
17.1k
{
261
17.1k
  pe_data_type *pe;
262
17.1k
  size_t amt = sizeof (pe_data_type);
263
264
17.1k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
17.1k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
17.1k
  pe = pe_data (abfd);
270
271
17.1k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
17.1k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
17.1k
  pe->dos_message[0]  = 0x0eba1f0e;
278
17.1k
  pe->dos_message[1]  = 0xcd09b400;
279
17.1k
  pe->dos_message[2]  = 0x4c01b821;
280
17.1k
  pe->dos_message[3]  = 0x685421cd;
281
17.1k
  pe->dos_message[4]  = 0x70207369;
282
17.1k
  pe->dos_message[5]  = 0x72676f72;
283
17.1k
  pe->dos_message[6]  = 0x63206d61;
284
17.1k
  pe->dos_message[7]  = 0x6f6e6e61;
285
17.1k
  pe->dos_message[8]  = 0x65622074;
286
17.1k
  pe->dos_message[9]  = 0x6e757220;
287
17.1k
  pe->dos_message[10] = 0x206e6920;
288
17.1k
  pe->dos_message[11] = 0x20534f44;
289
17.1k
  pe->dos_message[12] = 0x65646f6d;
290
17.1k
  pe->dos_message[13] = 0x0a0d0d2e;
291
17.1k
  pe->dos_message[14] = 0x24;
292
17.1k
  pe->dos_message[15] = 0x0;
293
294
17.1k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
17.1k
  bfd_coff_long_section_names (abfd)
297
17.1k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
17.1k
  return true;
300
17.1k
}
pei-arm.c:pe_mkobject
Line
Count
Source
260
22.8k
{
261
22.8k
  pe_data_type *pe;
262
22.8k
  size_t amt = sizeof (pe_data_type);
263
264
22.8k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
22.8k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
22.8k
  pe = pe_data (abfd);
270
271
22.8k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
22.8k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
22.8k
  pe->dos_message[0]  = 0x0eba1f0e;
278
22.8k
  pe->dos_message[1]  = 0xcd09b400;
279
22.8k
  pe->dos_message[2]  = 0x4c01b821;
280
22.8k
  pe->dos_message[3]  = 0x685421cd;
281
22.8k
  pe->dos_message[4]  = 0x70207369;
282
22.8k
  pe->dos_message[5]  = 0x72676f72;
283
22.8k
  pe->dos_message[6]  = 0x63206d61;
284
22.8k
  pe->dos_message[7]  = 0x6f6e6e61;
285
22.8k
  pe->dos_message[8]  = 0x65622074;
286
22.8k
  pe->dos_message[9]  = 0x6e757220;
287
22.8k
  pe->dos_message[10] = 0x206e6920;
288
22.8k
  pe->dos_message[11] = 0x20534f44;
289
22.8k
  pe->dos_message[12] = 0x65646f6d;
290
22.8k
  pe->dos_message[13] = 0x0a0d0d2e;
291
22.8k
  pe->dos_message[14] = 0x24;
292
22.8k
  pe->dos_message[15] = 0x0;
293
294
22.8k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
22.8k
  bfd_coff_long_section_names (abfd)
297
22.8k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
22.8k
  return true;
300
22.8k
}
pei-mcore.c:pe_mkobject
Line
Count
Source
260
22.1k
{
261
22.1k
  pe_data_type *pe;
262
22.1k
  size_t amt = sizeof (pe_data_type);
263
264
22.1k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
22.1k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
22.1k
  pe = pe_data (abfd);
270
271
22.1k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
22.1k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
22.1k
  pe->dos_message[0]  = 0x0eba1f0e;
278
22.1k
  pe->dos_message[1]  = 0xcd09b400;
279
22.1k
  pe->dos_message[2]  = 0x4c01b821;
280
22.1k
  pe->dos_message[3]  = 0x685421cd;
281
22.1k
  pe->dos_message[4]  = 0x70207369;
282
22.1k
  pe->dos_message[5]  = 0x72676f72;
283
22.1k
  pe->dos_message[6]  = 0x63206d61;
284
22.1k
  pe->dos_message[7]  = 0x6f6e6e61;
285
22.1k
  pe->dos_message[8]  = 0x65622074;
286
22.1k
  pe->dos_message[9]  = 0x6e757220;
287
22.1k
  pe->dos_message[10] = 0x206e6920;
288
22.1k
  pe->dos_message[11] = 0x20534f44;
289
22.1k
  pe->dos_message[12] = 0x65646f6d;
290
22.1k
  pe->dos_message[13] = 0x0a0d0d2e;
291
22.1k
  pe->dos_message[14] = 0x24;
292
22.1k
  pe->dos_message[15] = 0x0;
293
294
22.1k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
22.1k
  bfd_coff_long_section_names (abfd)
297
22.1k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
22.1k
  return true;
300
22.1k
}
pei-sh.c:pe_mkobject
Line
Count
Source
260
17.2k
{
261
17.2k
  pe_data_type *pe;
262
17.2k
  size_t amt = sizeof (pe_data_type);
263
264
17.2k
  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
265
266
17.2k
  if (abfd->tdata.pe_obj_data == 0)
267
0
    return false;
268
269
17.2k
  pe = pe_data (abfd);
270
271
17.2k
  pe->coff.pe = 1;
272
273
  /* in_reloc_p is architecture dependent.  */
274
17.2k
  pe->in_reloc_p = in_reloc_p;
275
276
  /* Default DOS message string.  */
277
17.2k
  pe->dos_message[0]  = 0x0eba1f0e;
278
17.2k
  pe->dos_message[1]  = 0xcd09b400;
279
17.2k
  pe->dos_message[2]  = 0x4c01b821;
280
17.2k
  pe->dos_message[3]  = 0x685421cd;
281
17.2k
  pe->dos_message[4]  = 0x70207369;
282
17.2k
  pe->dos_message[5]  = 0x72676f72;
283
17.2k
  pe->dos_message[6]  = 0x63206d61;
284
17.2k
  pe->dos_message[7]  = 0x6f6e6e61;
285
17.2k
  pe->dos_message[8]  = 0x65622074;
286
17.2k
  pe->dos_message[9]  = 0x6e757220;
287
17.2k
  pe->dos_message[10] = 0x206e6920;
288
17.2k
  pe->dos_message[11] = 0x20534f44;
289
17.2k
  pe->dos_message[12] = 0x65646f6d;
290
17.2k
  pe->dos_message[13] = 0x0a0d0d2e;
291
17.2k
  pe->dos_message[14] = 0x24;
292
17.2k
  pe->dos_message[15] = 0x0;
293
294
17.2k
  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
295
296
17.2k
  bfd_coff_long_section_names (abfd)
297
17.2k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
298
299
17.2k
  return true;
300
17.2k
}
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
282k
{
309
282k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
282k
  pe_data_type *pe;
311
312
282k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
282k
  pe = pe_data (abfd);
316
282k
  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
282k
  pe->coff.local_n_btmask = N_BTMASK;
321
282k
  pe->coff.local_n_btshft = N_BTSHFT;
322
282k
  pe->coff.local_n_tmask = N_TMASK;
323
282k
  pe->coff.local_n_tshift = N_TSHIFT;
324
282k
  pe->coff.local_symesz = SYMESZ;
325
282k
  pe->coff.local_auxesz = AUXESZ;
326
282k
  pe->coff.local_linesz = LINESZ;
327
328
282k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
282k
  obj_raw_syment_count (abfd) =
331
282k
    obj_conv_table_size (abfd) =
332
282k
      internal_f->f_nsyms;
333
334
282k
  pe->real_flags = internal_f->f_flags;
335
336
282k
  if ((internal_f->f_flags & F_DLL) != 0)
337
116k
    pe->dll = 1;
338
339
282k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
181k
    abfd->flags |= HAS_DEBUG;
341
342
#ifdef COFF_IMAGE_WITH_PE
343
201k
  if (aouthdr)
344
107k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
#endif
346
347
#ifdef ARM
348
49.8k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
349
0
    coff_data (abfd) ->flags = 0;
350
#endif
351
352
282k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
282k
    sizeof (pe->dos_message));
354
355
282k
  return (void *) pe;
356
282k
}
pei-i386.c:pe_mkobject_hook
Line
Count
Source
308
24.1k
{
309
24.1k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
24.1k
  pe_data_type *pe;
311
312
24.1k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
24.1k
  pe = pe_data (abfd);
316
24.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
24.1k
  pe->coff.local_n_btmask = N_BTMASK;
321
24.1k
  pe->coff.local_n_btshft = N_BTSHFT;
322
24.1k
  pe->coff.local_n_tmask = N_TMASK;
323
24.1k
  pe->coff.local_n_tshift = N_TSHIFT;
324
24.1k
  pe->coff.local_symesz = SYMESZ;
325
24.1k
  pe->coff.local_auxesz = AUXESZ;
326
24.1k
  pe->coff.local_linesz = LINESZ;
327
328
24.1k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
24.1k
  obj_raw_syment_count (abfd) =
331
24.1k
    obj_conv_table_size (abfd) =
332
24.1k
      internal_f->f_nsyms;
333
334
24.1k
  pe->real_flags = internal_f->f_flags;
335
336
24.1k
  if ((internal_f->f_flags & F_DLL) != 0)
337
13.4k
    pe->dll = 1;
338
339
24.1k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
17.8k
    abfd->flags |= HAS_DEBUG;
341
342
24.1k
#ifdef COFF_IMAGE_WITH_PE
343
24.1k
  if (aouthdr)
344
11.7k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
24.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
24.1k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
24.1k
    sizeof (pe->dos_message));
354
355
24.1k
  return (void *) pe;
356
24.1k
}
pe-x86_64.c:pe_mkobject_hook
Line
Count
Source
308
26.9k
{
309
26.9k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
26.9k
  pe_data_type *pe;
311
312
26.9k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
26.9k
  pe = pe_data (abfd);
316
26.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
26.9k
  pe->coff.local_n_btmask = N_BTMASK;
321
26.9k
  pe->coff.local_n_btshft = N_BTSHFT;
322
26.9k
  pe->coff.local_n_tmask = N_TMASK;
323
26.9k
  pe->coff.local_n_tshift = N_TSHIFT;
324
26.9k
  pe->coff.local_symesz = SYMESZ;
325
26.9k
  pe->coff.local_auxesz = AUXESZ;
326
26.9k
  pe->coff.local_linesz = LINESZ;
327
328
26.9k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
26.9k
  obj_raw_syment_count (abfd) =
331
26.9k
    obj_conv_table_size (abfd) =
332
26.9k
      internal_f->f_nsyms;
333
334
26.9k
  pe->real_flags = internal_f->f_flags;
335
336
26.9k
  if ((internal_f->f_flags & F_DLL) != 0)
337
9.80k
    pe->dll = 1;
338
339
26.9k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
20.4k
    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
26.9k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
26.9k
    sizeof (pe->dos_message));
354
355
26.9k
  return (void *) pe;
356
26.9k
}
pei-x86_64.c:pe_mkobject_hook
Line
Count
Source
308
36.1k
{
309
36.1k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
36.1k
  pe_data_type *pe;
311
312
36.1k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
36.1k
  pe = pe_data (abfd);
316
36.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
36.1k
  pe->coff.local_n_btmask = N_BTMASK;
321
36.1k
  pe->coff.local_n_btshft = N_BTSHFT;
322
36.1k
  pe->coff.local_n_tmask = N_TMASK;
323
36.1k
  pe->coff.local_n_tshift = N_TSHIFT;
324
36.1k
  pe->coff.local_symesz = SYMESZ;
325
36.1k
  pe->coff.local_auxesz = AUXESZ;
326
36.1k
  pe->coff.local_linesz = LINESZ;
327
328
36.1k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
36.1k
  obj_raw_syment_count (abfd) =
331
36.1k
    obj_conv_table_size (abfd) =
332
36.1k
      internal_f->f_nsyms;
333
334
36.1k
  pe->real_flags = internal_f->f_flags;
335
336
36.1k
  if ((internal_f->f_flags & F_DLL) != 0)
337
14.3k
    pe->dll = 1;
338
339
36.1k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
32.1k
    abfd->flags |= HAS_DEBUG;
341
342
36.1k
#ifdef COFF_IMAGE_WITH_PE
343
36.1k
  if (aouthdr)
344
17.0k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
36.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
36.1k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
36.1k
    sizeof (pe->dos_message));
354
355
36.1k
  return (void *) pe;
356
36.1k
}
pei-aarch64.c:pe_mkobject_hook
Line
Count
Source
308
13.9k
{
309
13.9k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
13.9k
  pe_data_type *pe;
311
312
13.9k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
13.9k
  pe = pe_data (abfd);
316
13.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
13.9k
  pe->coff.local_n_btmask = N_BTMASK;
321
13.9k
  pe->coff.local_n_btshft = N_BTSHFT;
322
13.9k
  pe->coff.local_n_tmask = N_TMASK;
323
13.9k
  pe->coff.local_n_tshift = N_TSHIFT;
324
13.9k
  pe->coff.local_symesz = SYMESZ;
325
13.9k
  pe->coff.local_auxesz = AUXESZ;
326
13.9k
  pe->coff.local_linesz = LINESZ;
327
328
13.9k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
13.9k
  obj_raw_syment_count (abfd) =
331
13.9k
    obj_conv_table_size (abfd) =
332
13.9k
      internal_f->f_nsyms;
333
334
13.9k
  pe->real_flags = internal_f->f_flags;
335
336
13.9k
  if ((internal_f->f_flags & F_DLL) != 0)
337
9.71k
    pe->dll = 1;
338
339
13.9k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
5.11k
    abfd->flags |= HAS_DEBUG;
341
342
13.9k
#ifdef COFF_IMAGE_WITH_PE
343
13.9k
  if (aouthdr)
344
10.4k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
13.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
13.9k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
13.9k
    sizeof (pe->dos_message));
354
355
13.9k
  return (void *) pe;
356
13.9k
}
pe-aarch64.c:pe_mkobject_hook
Line
Count
Source
308
5.96k
{
309
5.96k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
5.96k
  pe_data_type *pe;
311
312
5.96k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
5.96k
  pe = pe_data (abfd);
316
5.96k
  pe->coff.sym_filepos = internal_f->f_symptr;
317
  /* These members communicate important constants about the symbol
318
     table to GDB's symbol-reading code.  These `constants'
319
     unfortunately vary among coff implementations...  */
320
5.96k
  pe->coff.local_n_btmask = N_BTMASK;
321
5.96k
  pe->coff.local_n_btshft = N_BTSHFT;
322
5.96k
  pe->coff.local_n_tmask = N_TMASK;
323
5.96k
  pe->coff.local_n_tshift = N_TSHIFT;
324
5.96k
  pe->coff.local_symesz = SYMESZ;
325
5.96k
  pe->coff.local_auxesz = AUXESZ;
326
5.96k
  pe->coff.local_linesz = LINESZ;
327
328
5.96k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
5.96k
  obj_raw_syment_count (abfd) =
331
5.96k
    obj_conv_table_size (abfd) =
332
5.96k
      internal_f->f_nsyms;
333
334
5.96k
  pe->real_flags = internal_f->f_flags;
335
336
5.96k
  if ((internal_f->f_flags & F_DLL) != 0)
337
2.90k
    pe->dll = 1;
338
339
5.96k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
3.26k
    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
5.96k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
5.96k
    sizeof (pe->dos_message));
354
355
5.96k
  return (void *) pe;
356
5.96k
}
pei-ia64.c:pe_mkobject_hook
Line
Count
Source
308
25.6k
{
309
25.6k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
25.6k
  pe_data_type *pe;
311
312
25.6k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
25.6k
  pe = pe_data (abfd);
316
25.6k
  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
25.6k
  pe->coff.local_n_btmask = N_BTMASK;
321
25.6k
  pe->coff.local_n_btshft = N_BTSHFT;
322
25.6k
  pe->coff.local_n_tmask = N_TMASK;
323
25.6k
  pe->coff.local_n_tshift = N_TSHIFT;
324
25.6k
  pe->coff.local_symesz = SYMESZ;
325
25.6k
  pe->coff.local_auxesz = AUXESZ;
326
25.6k
  pe->coff.local_linesz = LINESZ;
327
328
25.6k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
25.6k
  obj_raw_syment_count (abfd) =
331
25.6k
    obj_conv_table_size (abfd) =
332
25.6k
      internal_f->f_nsyms;
333
334
25.6k
  pe->real_flags = internal_f->f_flags;
335
336
25.6k
  if ((internal_f->f_flags & F_DLL) != 0)
337
13.5k
    pe->dll = 1;
338
339
25.6k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
13.2k
    abfd->flags |= HAS_DEBUG;
341
342
25.6k
#ifdef COFF_IMAGE_WITH_PE
343
25.6k
  if (aouthdr)
344
15.0k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
25.6k
#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
25.6k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
25.6k
    sizeof (pe->dos_message));
354
355
25.6k
  return (void *) pe;
356
25.6k
}
pei-loongarch64.c:pe_mkobject_hook
Line
Count
Source
308
22.1k
{
309
22.1k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
22.1k
  pe_data_type *pe;
311
312
22.1k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
22.1k
  pe = pe_data (abfd);
316
22.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
22.1k
  pe->coff.local_n_btmask = N_BTMASK;
321
22.1k
  pe->coff.local_n_btshft = N_BTSHFT;
322
22.1k
  pe->coff.local_n_tmask = N_TMASK;
323
22.1k
  pe->coff.local_n_tshift = N_TSHIFT;
324
22.1k
  pe->coff.local_symesz = SYMESZ;
325
22.1k
  pe->coff.local_auxesz = AUXESZ;
326
22.1k
  pe->coff.local_linesz = LINESZ;
327
328
22.1k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
22.1k
  obj_raw_syment_count (abfd) =
331
22.1k
    obj_conv_table_size (abfd) =
332
22.1k
      internal_f->f_nsyms;
333
334
22.1k
  pe->real_flags = internal_f->f_flags;
335
336
22.1k
  if ((internal_f->f_flags & F_DLL) != 0)
337
2.21k
    pe->dll = 1;
338
339
22.1k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
16.1k
    abfd->flags |= HAS_DEBUG;
341
342
22.1k
#ifdef COFF_IMAGE_WITH_PE
343
22.1k
  if (aouthdr)
344
15.9k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
22.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
22.1k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
22.1k
    sizeof (pe->dos_message));
354
355
22.1k
  return (void *) pe;
356
22.1k
}
pe-arm-wince.c:pe_mkobject_hook
Line
Count
Source
308
4.95k
{
309
4.95k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
4.95k
  pe_data_type *pe;
311
312
4.95k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
4.95k
  pe = pe_data (abfd);
316
4.95k
  pe->coff.sym_filepos = internal_f->f_symptr;
317
  /* These members communicate important constants about the symbol
318
     table to GDB's symbol-reading code.  These `constants'
319
     unfortunately vary among coff implementations...  */
320
4.95k
  pe->coff.local_n_btmask = N_BTMASK;
321
4.95k
  pe->coff.local_n_btshft = N_BTSHFT;
322
4.95k
  pe->coff.local_n_tmask = N_TMASK;
323
4.95k
  pe->coff.local_n_tshift = N_TSHIFT;
324
4.95k
  pe->coff.local_symesz = SYMESZ;
325
4.95k
  pe->coff.local_auxesz = AUXESZ;
326
4.95k
  pe->coff.local_linesz = LINESZ;
327
328
4.95k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
4.95k
  obj_raw_syment_count (abfd) =
331
4.95k
    obj_conv_table_size (abfd) =
332
4.95k
      internal_f->f_nsyms;
333
334
4.95k
  pe->real_flags = internal_f->f_flags;
335
336
4.95k
  if ((internal_f->f_flags & F_DLL) != 0)
337
2.79k
    pe->dll = 1;
338
339
4.95k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
4.11k
    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
4.95k
#ifdef ARM
348
4.95k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
349
0
    coff_data (abfd) ->flags = 0;
350
4.95k
#endif
351
352
4.95k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
4.95k
    sizeof (pe->dos_message));
354
355
4.95k
  return (void *) pe;
356
4.95k
}
pe-arm.c:pe_mkobject_hook
Line
Count
Source
308
4.95k
{
309
4.95k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
4.95k
  pe_data_type *pe;
311
312
4.95k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
4.95k
  pe = pe_data (abfd);
316
4.95k
  pe->coff.sym_filepos = internal_f->f_symptr;
317
  /* These members communicate important constants about the symbol
318
     table to GDB's symbol-reading code.  These `constants'
319
     unfortunately vary among coff implementations...  */
320
4.95k
  pe->coff.local_n_btmask = N_BTMASK;
321
4.95k
  pe->coff.local_n_btshft = N_BTSHFT;
322
4.95k
  pe->coff.local_n_tmask = N_TMASK;
323
4.95k
  pe->coff.local_n_tshift = N_TSHIFT;
324
4.95k
  pe->coff.local_symesz = SYMESZ;
325
4.95k
  pe->coff.local_auxesz = AUXESZ;
326
4.95k
  pe->coff.local_linesz = LINESZ;
327
328
4.95k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
4.95k
  obj_raw_syment_count (abfd) =
331
4.95k
    obj_conv_table_size (abfd) =
332
4.95k
      internal_f->f_nsyms;
333
334
4.95k
  pe->real_flags = internal_f->f_flags;
335
336
4.95k
  if ((internal_f->f_flags & F_DLL) != 0)
337
2.79k
    pe->dll = 1;
338
339
4.95k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
4.11k
    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
4.95k
#ifdef ARM
348
4.95k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
349
0
    coff_data (abfd) ->flags = 0;
350
4.95k
#endif
351
352
4.95k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
4.95k
    sizeof (pe->dos_message));
354
355
4.95k
  return (void *) pe;
356
4.95k
}
pe-i386.c:pe_mkobject_hook
Line
Count
Source
308
17.6k
{
309
17.6k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
17.6k
  pe_data_type *pe;
311
312
17.6k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
17.6k
  pe = pe_data (abfd);
316
17.6k
  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
17.6k
  pe->coff.local_n_btmask = N_BTMASK;
321
17.6k
  pe->coff.local_n_btshft = N_BTSHFT;
322
17.6k
  pe->coff.local_n_tmask = N_TMASK;
323
17.6k
  pe->coff.local_n_tshift = N_TSHIFT;
324
17.6k
  pe->coff.local_symesz = SYMESZ;
325
17.6k
  pe->coff.local_auxesz = AUXESZ;
326
17.6k
  pe->coff.local_linesz = LINESZ;
327
328
17.6k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
17.6k
  obj_raw_syment_count (abfd) =
331
17.6k
    obj_conv_table_size (abfd) =
332
17.6k
      internal_f->f_nsyms;
333
334
17.6k
  pe->real_flags = internal_f->f_flags;
335
336
17.6k
  if ((internal_f->f_flags & F_DLL) != 0)
337
2.03k
    pe->dll = 1;
338
339
17.6k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
11.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
17.6k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
17.6k
    sizeof (pe->dos_message));
354
355
17.6k
  return (void *) pe;
356
17.6k
}
pe-mcore.c:pe_mkobject_hook
Line
Count
Source
308
8.63k
{
309
8.63k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
8.63k
  pe_data_type *pe;
311
312
8.63k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
8.63k
  pe = pe_data (abfd);
316
8.63k
  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
8.63k
  pe->coff.local_n_btmask = N_BTMASK;
321
8.63k
  pe->coff.local_n_btshft = N_BTSHFT;
322
8.63k
  pe->coff.local_n_tmask = N_TMASK;
323
8.63k
  pe->coff.local_n_tshift = N_TSHIFT;
324
8.63k
  pe->coff.local_symesz = SYMESZ;
325
8.63k
  pe->coff.local_auxesz = AUXESZ;
326
8.63k
  pe->coff.local_linesz = LINESZ;
327
328
8.63k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
8.63k
  obj_raw_syment_count (abfd) =
331
8.63k
    obj_conv_table_size (abfd) =
332
8.63k
      internal_f->f_nsyms;
333
334
8.63k
  pe->real_flags = internal_f->f_flags;
335
336
8.63k
  if ((internal_f->f_flags & F_DLL) != 0)
337
1.78k
    pe->dll = 1;
338
339
8.63k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
7.02k
    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
8.63k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
8.63k
    sizeof (pe->dos_message));
354
355
8.63k
  return (void *) pe;
356
8.63k
}
pe-sh.c:pe_mkobject_hook
Line
Count
Source
308
11.5k
{
309
11.5k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
11.5k
  pe_data_type *pe;
311
312
11.5k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
11.5k
  pe = pe_data (abfd);
316
11.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
11.5k
  pe->coff.local_n_btmask = N_BTMASK;
321
11.5k
  pe->coff.local_n_btshft = N_BTSHFT;
322
11.5k
  pe->coff.local_n_tmask = N_TMASK;
323
11.5k
  pe->coff.local_n_tshift = N_TSHIFT;
324
11.5k
  pe->coff.local_symesz = SYMESZ;
325
11.5k
  pe->coff.local_auxesz = AUXESZ;
326
11.5k
  pe->coff.local_linesz = LINESZ;
327
328
11.5k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
11.5k
  obj_raw_syment_count (abfd) =
331
11.5k
    obj_conv_table_size (abfd) =
332
11.5k
      internal_f->f_nsyms;
333
334
11.5k
  pe->real_flags = internal_f->f_flags;
335
336
11.5k
  if ((internal_f->f_flags & F_DLL) != 0)
337
7.08k
    pe->dll = 1;
338
339
11.5k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
6.71k
    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
11.5k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
11.5k
    sizeof (pe->dos_message));
354
355
11.5k
  return (void *) pe;
356
11.5k
}
pei-arm-wince.c:pe_mkobject_hook
Line
Count
Source
308
17.1k
{
309
17.1k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
17.1k
  pe_data_type *pe;
311
312
17.1k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
17.1k
  pe = pe_data (abfd);
316
17.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
17.1k
  pe->coff.local_n_btmask = N_BTMASK;
321
17.1k
  pe->coff.local_n_btshft = N_BTSHFT;
322
17.1k
  pe->coff.local_n_tmask = N_TMASK;
323
17.1k
  pe->coff.local_n_tshift = N_TSHIFT;
324
17.1k
  pe->coff.local_symesz = SYMESZ;
325
17.1k
  pe->coff.local_auxesz = AUXESZ;
326
17.1k
  pe->coff.local_linesz = LINESZ;
327
328
17.1k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
17.1k
  obj_raw_syment_count (abfd) =
331
17.1k
    obj_conv_table_size (abfd) =
332
17.1k
      internal_f->f_nsyms;
333
334
17.1k
  pe->real_flags = internal_f->f_flags;
335
336
17.1k
  if ((internal_f->f_flags & F_DLL) != 0)
337
3.67k
    pe->dll = 1;
338
339
17.1k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
10.5k
    abfd->flags |= HAS_DEBUG;
341
342
17.1k
#ifdef COFF_IMAGE_WITH_PE
343
17.1k
  if (aouthdr)
344
5.16k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
17.1k
#endif
346
347
17.1k
#ifdef ARM
348
17.1k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
349
0
    coff_data (abfd) ->flags = 0;
350
17.1k
#endif
351
352
17.1k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
17.1k
    sizeof (pe->dos_message));
354
355
17.1k
  return (void *) pe;
356
17.1k
}
pei-arm.c:pe_mkobject_hook
Line
Count
Source
308
22.8k
{
309
22.8k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
22.8k
  pe_data_type *pe;
311
312
22.8k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
22.8k
  pe = pe_data (abfd);
316
22.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
22.8k
  pe->coff.local_n_btmask = N_BTMASK;
321
22.8k
  pe->coff.local_n_btshft = N_BTSHFT;
322
22.8k
  pe->coff.local_n_tmask = N_TMASK;
323
22.8k
  pe->coff.local_n_tshift = N_TSHIFT;
324
22.8k
  pe->coff.local_symesz = SYMESZ;
325
22.8k
  pe->coff.local_auxesz = AUXESZ;
326
22.8k
  pe->coff.local_linesz = LINESZ;
327
328
22.8k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
22.8k
  obj_raw_syment_count (abfd) =
331
22.8k
    obj_conv_table_size (abfd) =
332
22.8k
      internal_f->f_nsyms;
333
334
22.8k
  pe->real_flags = internal_f->f_flags;
335
336
22.8k
  if ((internal_f->f_flags & F_DLL) != 0)
337
8.22k
    pe->dll = 1;
338
339
22.8k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
12.3k
    abfd->flags |= HAS_DEBUG;
341
342
22.8k
#ifdef COFF_IMAGE_WITH_PE
343
22.8k
  if (aouthdr)
344
9.10k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
22.8k
#endif
346
347
22.8k
#ifdef ARM
348
22.8k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
349
0
    coff_data (abfd) ->flags = 0;
350
22.8k
#endif
351
352
22.8k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
22.8k
    sizeof (pe->dos_message));
354
355
22.8k
  return (void *) pe;
356
22.8k
}
pei-mcore.c:pe_mkobject_hook
Line
Count
Source
308
22.1k
{
309
22.1k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
22.1k
  pe_data_type *pe;
311
312
22.1k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
22.1k
  pe = pe_data (abfd);
316
22.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
22.1k
  pe->coff.local_n_btmask = N_BTMASK;
321
22.1k
  pe->coff.local_n_btshft = N_BTSHFT;
322
22.1k
  pe->coff.local_n_tmask = N_TMASK;
323
22.1k
  pe->coff.local_n_tshift = N_TSHIFT;
324
22.1k
  pe->coff.local_symesz = SYMESZ;
325
22.1k
  pe->coff.local_auxesz = AUXESZ;
326
22.1k
  pe->coff.local_linesz = LINESZ;
327
328
22.1k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
22.1k
  obj_raw_syment_count (abfd) =
331
22.1k
    obj_conv_table_size (abfd) =
332
22.1k
      internal_f->f_nsyms;
333
334
22.1k
  pe->real_flags = internal_f->f_flags;
335
336
22.1k
  if ((internal_f->f_flags & F_DLL) != 0)
337
12.4k
    pe->dll = 1;
338
339
22.1k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
6.87k
    abfd->flags |= HAS_DEBUG;
341
342
22.1k
#ifdef COFF_IMAGE_WITH_PE
343
22.1k
  if (aouthdr)
344
14.4k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
22.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
22.1k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
22.1k
    sizeof (pe->dos_message));
354
355
22.1k
  return (void *) pe;
356
22.1k
}
pei-sh.c:pe_mkobject_hook
Line
Count
Source
308
17.2k
{
309
17.2k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
310
17.2k
  pe_data_type *pe;
311
312
17.2k
  if (! pe_mkobject (abfd))
313
0
    return NULL;
314
315
17.2k
  pe = pe_data (abfd);
316
17.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
17.2k
  pe->coff.local_n_btmask = N_BTMASK;
321
17.2k
  pe->coff.local_n_btshft = N_BTSHFT;
322
17.2k
  pe->coff.local_n_tmask = N_TMASK;
323
17.2k
  pe->coff.local_n_tshift = N_TSHIFT;
324
17.2k
  pe->coff.local_symesz = SYMESZ;
325
17.2k
  pe->coff.local_auxesz = AUXESZ;
326
17.2k
  pe->coff.local_linesz = LINESZ;
327
328
17.2k
  pe->coff.timestamp = internal_f->f_timdat;
329
330
17.2k
  obj_raw_syment_count (abfd) =
331
17.2k
    obj_conv_table_size (abfd) =
332
17.2k
      internal_f->f_nsyms;
333
334
17.2k
  pe->real_flags = internal_f->f_flags;
335
336
17.2k
  if ((internal_f->f_flags & F_DLL) != 0)
337
9.86k
    pe->dll = 1;
338
339
17.2k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
340
9.57k
    abfd->flags |= HAS_DEBUG;
341
342
17.2k
#ifdef COFF_IMAGE_WITH_PE
343
17.2k
  if (aouthdr)
344
8.30k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
345
17.2k
#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
17.2k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
353
17.2k
    sizeof (pe->dos_message));
354
355
17.2k
  return (void *) pe;
356
17.2k
}
357
358
static bool
359
pe_print_private_bfd_data (bfd *abfd, void * vfile)
360
0
{
361
0
  FILE *file = (FILE *) vfile;
362
363
0
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
364
0
    return false;
365
366
0
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
367
0
    return true;
368
369
0
  fputc ('\n', file);
370
371
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
372
0
}
Unexecuted instantiation: pei-i386.c:pe_print_private_bfd_data
Unexecuted instantiation: pe-x86_64.c:pe_print_private_bfd_data
Unexecuted instantiation: pei-x86_64.c:pe_print_private_bfd_data
Unexecuted instantiation: pei-aarch64.c:pe_print_private_bfd_data
Unexecuted instantiation: pe-aarch64.c:pe_print_private_bfd_data
Unexecuted instantiation: pei-ia64.c:pe_print_private_bfd_data
Unexecuted instantiation: pei-loongarch64.c:pe_print_private_bfd_data
Unexecuted instantiation: pe-arm-wince.c:pe_print_private_bfd_data
Unexecuted instantiation: pe-arm.c:pe_print_private_bfd_data
Unexecuted instantiation: pe-i386.c:pe_print_private_bfd_data
Unexecuted instantiation: pe-mcore.c:pe_print_private_bfd_data
Unexecuted instantiation: pe-sh.c:pe_print_private_bfd_data
Unexecuted instantiation: pei-arm-wince.c:pe_print_private_bfd_data
Unexecuted instantiation: pei-arm.c:pe_print_private_bfd_data
Unexecuted instantiation: pei-mcore.c:pe_print_private_bfd_data
Unexecuted instantiation: pei-sh.c:pe_print_private_bfd_data
373
374
/* Copy any private info we understand from the input bfd
375
   to the output bfd.  */
376
377
static bool
378
pe_bfd_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
379
0
{
380
  /* PR binutils/716: Copy the large address aware flag.
381
     XXX: Should we be copying other flags or other fields in the pe_data()
382
     structure ?  */
383
0
  if (pe_data (obfd) != NULL
384
0
      && pe_data (ibfd) != NULL
385
0
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
386
0
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
387
388
0
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
389
0
    return false;
390
391
0
  if (pe_saved_coff_bfd_copy_private_bfd_data)
392
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
393
394
0
  return true;
395
0
}
Unexecuted instantiation: pei-i386.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pe-x86_64.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pei-x86_64.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pei-aarch64.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pe-aarch64.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pei-ia64.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pei-loongarch64.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pe-arm-wince.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pe-arm.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pe-i386.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pe-mcore.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pe-sh.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pei-arm-wince.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pei-arm.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pei-mcore.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pei-sh.c:pe_bfd_copy_private_bfd_data
396
397
#define coff_bfd_copy_private_section_data \
398
  _bfd_XX_bfd_copy_private_section_data
399
400
#define coff_get_symbol_info _bfd_XX_get_symbol_info
401
402
#ifdef COFF_IMAGE_WITH_PE
403

404
/* Code to handle Microsoft's Import Library Format.
405
   Also known as LINK6 format.
406
   Documentation about this format can be found at:
407
408
   https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#import-library-format  */
409
410
/* The following constants specify the sizes of the various data
411
   structures that we have to create in order to build a bfd describing
412
   an ILF object file.  The final "+ 1" in the definitions of SIZEOF_IDATA6
413
   and SIZEOF_IDATA7 below is to allow for the possibility that we might
414
   need a padding byte in order to ensure 16 bit alignment for the section's
415
   contents.
416
417
   The value for SIZEOF_ILF_STRINGS is computed as follows:
418
419
      There will be NUM_ILF_SECTIONS section symbols.  Allow 9 characters
420
      per symbol for their names (longest section name is .idata$x).
421
422
      There will be two symbols for the imported value, one the symbol name
423
      and one with _imp__ prefixed.  Allowing for the terminating nul's this
424
      is strlen (symbol_name) * 2 + 8 + 21 + strlen (source_dll).
425
426
      The strings in the string table must start STRING__SIZE_SIZE bytes into
427
      the table in order to for the string lookup code in coffgen/coffcode to
428
      work.  */
429
51.0k
#define NUM_ILF_RELOCS    8
430
170k
#define NUM_ILF_SECTIONS  6
431
127k
#define NUM_ILF_SYMS    (2 + NUM_ILF_SECTIONS)
432
433
25.5k
#define SIZEOF_ILF_SYMS    (NUM_ILF_SYMS * sizeof (* vars.sym_cache))
434
25.5k
#define SIZEOF_ILF_SYM_TABLE   (NUM_ILF_SYMS * sizeof (* vars.sym_table))
435
25.5k
#define SIZEOF_ILF_NATIVE_SYMS   (NUM_ILF_SYMS * sizeof (* vars.native_syms))
436
25.5k
#define SIZEOF_ILF_SYM_PTR_TABLE (NUM_ILF_SYMS * sizeof (* vars.sym_ptr_table))
437
25.5k
#define SIZEOF_ILF_EXT_SYMS  (NUM_ILF_SYMS * sizeof (* vars.esym_table))
438
25.5k
#define SIZEOF_ILF_RELOCS  (NUM_ILF_RELOCS * sizeof (* vars.reltab))
439
25.5k
#define SIZEOF_ILF_INT_RELOCS  (NUM_ILF_RELOCS * sizeof (* vars.int_reltab))
440
25.5k
#define SIZEOF_ILF_STRINGS   (strlen (symbol_name) * 2 + 8 \
441
25.5k
          + 21 + strlen (source_dll) \
442
25.5k
          + NUM_ILF_SECTIONS * 9 \
443
25.5k
          + STRING_SIZE_SIZE)
444
17.0k
#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
6.36k
#define SIZEOF_IDATA4   (2 * 4)
449
6.36k
#define SIZEOF_IDATA5   (2 * 4)
450
#else
451
19.1k
#define SIZEOF_IDATA4   (1 * 4)
452
19.1k
#define SIZEOF_IDATA5   (1 * 4)
453
#endif
454
455
22.5k
#define SIZEOF_IDATA6   (2 + strlen (symbol_name) + 1 + 1)
456
17.0k
#define SIZEOF_IDATA7   (strlen (source_dll) + 1 + 1)
457
17.0k
#define SIZEOF_ILF_SECTIONS (NUM_ILF_SECTIONS * sizeof (struct coff_section_tdata))
458
459
#define ILF_DATA_SIZE       \
460
17.0k
    + SIZEOF_ILF_SYMS        \
461
17.0k
    + SIZEOF_ILF_SYM_TABLE      \
462
17.0k
    + SIZEOF_ILF_NATIVE_SYMS      \
463
17.0k
    + SIZEOF_ILF_SYM_PTR_TABLE      \
464
17.0k
    + SIZEOF_ILF_EXT_SYMS      \
465
17.0k
    + SIZEOF_ILF_RELOCS        \
466
17.0k
    + SIZEOF_ILF_INT_RELOCS      \
467
17.0k
    + SIZEOF_ILF_STRINGS      \
468
17.0k
    + SIZEOF_IDATA2        \
469
17.0k
    + SIZEOF_IDATA4        \
470
17.0k
    + SIZEOF_IDATA5        \
471
17.0k
    + SIZEOF_IDATA6        \
472
17.0k
    + SIZEOF_IDATA7        \
473
17.0k
    + SIZEOF_ILF_SECTIONS      \
474
17.0k
    + 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
15.4k
{
485
15.4k
  arelent * entry;
486
15.4k
  struct internal_reloc * internal;
487
488
15.4k
  entry = vars->reltab + vars->relcount;
489
15.4k
  internal = vars->int_reltab + vars->relcount;
490
491
15.4k
  entry->address     = address;
492
15.4k
  entry->addend      = 0;
493
15.4k
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
494
15.4k
  entry->sym_ptr_ptr = sym;
495
496
15.4k
  internal->r_vaddr  = address;
497
15.4k
  internal->r_symndx = sym_index;
498
15.4k
  internal->r_type   = entry->howto ? entry->howto->type : 0;
499
500
15.4k
  vars->relcount ++;
501
502
15.4k
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
503
15.4k
}
pei-i386.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
484
2.43k
{
485
2.43k
  arelent * entry;
486
2.43k
  struct internal_reloc * internal;
487
488
2.43k
  entry = vars->reltab + vars->relcount;
489
2.43k
  internal = vars->int_reltab + vars->relcount;
490
491
2.43k
  entry->address     = address;
492
2.43k
  entry->addend      = 0;
493
2.43k
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
494
2.43k
  entry->sym_ptr_ptr = sym;
495
496
2.43k
  internal->r_vaddr  = address;
497
2.43k
  internal->r_symndx = sym_index;
498
2.43k
  internal->r_type   = entry->howto ? entry->howto->type : 0;
499
500
2.43k
  vars->relcount ++;
501
502
2.43k
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
503
2.43k
}
pei-x86_64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
484
3.27k
{
485
3.27k
  arelent * entry;
486
3.27k
  struct internal_reloc * internal;
487
488
3.27k
  entry = vars->reltab + vars->relcount;
489
3.27k
  internal = vars->int_reltab + vars->relcount;
490
491
3.27k
  entry->address     = address;
492
3.27k
  entry->addend      = 0;
493
3.27k
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
494
3.27k
  entry->sym_ptr_ptr = sym;
495
496
3.27k
  internal->r_vaddr  = address;
497
3.27k
  internal->r_symndx = sym_index;
498
3.27k
  internal->r_type   = entry->howto ? entry->howto->type : 0;
499
500
3.27k
  vars->relcount ++;
501
502
3.27k
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
503
3.27k
}
pei-aarch64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
484
649
{
485
649
  arelent * entry;
486
649
  struct internal_reloc * internal;
487
488
649
  entry = vars->reltab + vars->relcount;
489
649
  internal = vars->int_reltab + vars->relcount;
490
491
649
  entry->address     = address;
492
649
  entry->addend      = 0;
493
649
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
494
649
  entry->sym_ptr_ptr = sym;
495
496
649
  internal->r_vaddr  = address;
497
649
  internal->r_symndx = sym_index;
498
649
  internal->r_type   = entry->howto ? entry->howto->type : 0;
499
500
649
  vars->relcount ++;
501
502
649
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
503
649
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_symbol_reloc
pei-loongarch64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
484
3.21k
{
485
3.21k
  arelent * entry;
486
3.21k
  struct internal_reloc * internal;
487
488
3.21k
  entry = vars->reltab + vars->relcount;
489
3.21k
  internal = vars->int_reltab + vars->relcount;
490
491
3.21k
  entry->address     = address;
492
3.21k
  entry->addend      = 0;
493
3.21k
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
494
3.21k
  entry->sym_ptr_ptr = sym;
495
496
3.21k
  internal->r_vaddr  = address;
497
3.21k
  internal->r_symndx = sym_index;
498
3.21k
  internal->r_type   = entry->howto ? entry->howto->type : 0;
499
500
3.21k
  vars->relcount ++;
501
502
3.21k
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
503
3.21k
}
pei-arm-wince.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
484
16
{
485
16
  arelent * entry;
486
16
  struct internal_reloc * internal;
487
488
16
  entry = vars->reltab + vars->relcount;
489
16
  internal = vars->int_reltab + vars->relcount;
490
491
16
  entry->address     = address;
492
16
  entry->addend      = 0;
493
16
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
494
16
  entry->sym_ptr_ptr = sym;
495
496
16
  internal->r_vaddr  = address;
497
16
  internal->r_symndx = sym_index;
498
16
  internal->r_type   = entry->howto ? entry->howto->type : 0;
499
500
16
  vars->relcount ++;
501
502
16
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
503
16
}
pei-arm.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
484
3.41k
{
485
3.41k
  arelent * entry;
486
3.41k
  struct internal_reloc * internal;
487
488
3.41k
  entry = vars->reltab + vars->relcount;
489
3.41k
  internal = vars->int_reltab + vars->relcount;
490
491
3.41k
  entry->address     = address;
492
3.41k
  entry->addend      = 0;
493
3.41k
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
494
3.41k
  entry->sym_ptr_ptr = sym;
495
496
3.41k
  internal->r_vaddr  = address;
497
3.41k
  internal->r_symndx = sym_index;
498
3.41k
  internal->r_type   = entry->howto ? entry->howto->type : 0;
499
500
3.41k
  vars->relcount ++;
501
502
3.41k
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
503
3.41k
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_symbol_reloc
pei-sh.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
484
2.43k
{
485
2.43k
  arelent * entry;
486
2.43k
  struct internal_reloc * internal;
487
488
2.43k
  entry = vars->reltab + vars->relcount;
489
2.43k
  internal = vars->int_reltab + vars->relcount;
490
491
2.43k
  entry->address     = address;
492
2.43k
  entry->addend      = 0;
493
2.43k
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
494
2.43k
  entry->sym_ptr_ptr = sym;
495
496
2.43k
  internal->r_vaddr  = address;
497
2.43k
  internal->r_symndx = sym_index;
498
2.43k
  internal->r_type   = entry->howto ? entry->howto->type : 0;
499
500
2.43k
  vars->relcount ++;
501
502
2.43k
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
503
2.43k
}
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
11.0k
{
513
11.0k
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, sec->symbol_ptr_ptr,
514
11.0k
            coff_section_data (vars->abfd, sec)->i);
515
11.0k
}
pei-i386.c:pe_ILF_make_a_reloc
Line
Count
Source
512
1.86k
{
513
1.86k
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, sec->symbol_ptr_ptr,
514
1.86k
            coff_section_data (vars->abfd, sec)->i);
515
1.86k
}
pei-x86_64.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
}
pei-aarch64.c:pe_ILF_make_a_reloc
Line
Count
Source
512
210
{
513
210
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, sec->symbol_ptr_ptr,
514
210
            coff_section_data (vars->abfd, sec)->i);
515
210
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_reloc
pei-loongarch64.c:pe_ILF_make_a_reloc
Line
Count
Source
512
2.21k
{
513
2.21k
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, sec->symbol_ptr_ptr,
514
2.21k
            coff_section_data (vars->abfd, sec)->i);
515
2.21k
}
pei-arm-wince.c:pe_ILF_make_a_reloc
Line
Count
Source
512
12
{
513
12
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, sec->symbol_ptr_ptr,
514
12
            coff_section_data (vars->abfd, sec)->i);
515
12
}
pei-arm.c:pe_ILF_make_a_reloc
Line
Count
Source
512
2.38k
{
513
2.38k
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, sec->symbol_ptr_ptr,
514
2.38k
            coff_section_data (vars->abfd, sec)->i);
515
2.38k
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_reloc
pei-sh.c:pe_ILF_make_a_reloc
Line
Count
Source
512
1.86k
{
513
1.86k
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, sec->symbol_ptr_ptr,
514
1.86k
            coff_section_data (vars->abfd, sec)->i);
515
1.86k
}
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
15.4k
{
523
  /* Make sure that there is somewhere to store the internal relocs.  */
524
15.4k
  if (coff_section_data (vars->abfd, sec) == NULL)
525
    /* We should probably return an error indication here.  */
526
0
    abort ();
527
528
15.4k
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
529
530
15.4k
  sec->relocation  = vars->reltab;
531
15.4k
  sec->reloc_count = vars->relcount;
532
15.4k
  sec->flags      |= SEC_RELOC;
533
534
15.4k
  vars->reltab     += vars->relcount;
535
15.4k
  vars->int_reltab += vars->relcount;
536
15.4k
  vars->relcount   = 0;
537
538
15.4k
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
539
15.4k
}
pei-i386.c:pe_ILF_save_relocs
Line
Count
Source
522
2.43k
{
523
  /* Make sure that there is somewhere to store the internal relocs.  */
524
2.43k
  if (coff_section_data (vars->abfd, sec) == NULL)
525
    /* We should probably return an error indication here.  */
526
0
    abort ();
527
528
2.43k
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
529
530
2.43k
  sec->relocation  = vars->reltab;
531
2.43k
  sec->reloc_count = vars->relcount;
532
2.43k
  sec->flags      |= SEC_RELOC;
533
534
2.43k
  vars->reltab     += vars->relcount;
535
2.43k
  vars->int_reltab += vars->relcount;
536
2.43k
  vars->relcount   = 0;
537
538
2.43k
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
539
2.43k
}
pei-x86_64.c:pe_ILF_save_relocs
Line
Count
Source
522
3.27k
{
523
  /* Make sure that there is somewhere to store the internal relocs.  */
524
3.27k
  if (coff_section_data (vars->abfd, sec) == NULL)
525
    /* We should probably return an error indication here.  */
526
0
    abort ();
527
528
3.27k
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
529
530
3.27k
  sec->relocation  = vars->reltab;
531
3.27k
  sec->reloc_count = vars->relcount;
532
3.27k
  sec->flags      |= SEC_RELOC;
533
534
3.27k
  vars->reltab     += vars->relcount;
535
3.27k
  vars->int_reltab += vars->relcount;
536
3.27k
  vars->relcount   = 0;
537
538
3.27k
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
539
3.27k
}
pei-aarch64.c:pe_ILF_save_relocs
Line
Count
Source
522
649
{
523
  /* Make sure that there is somewhere to store the internal relocs.  */
524
649
  if (coff_section_data (vars->abfd, sec) == NULL)
525
    /* We should probably return an error indication here.  */
526
0
    abort ();
527
528
649
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
529
530
649
  sec->relocation  = vars->reltab;
531
649
  sec->reloc_count = vars->relcount;
532
649
  sec->flags      |= SEC_RELOC;
533
534
649
  vars->reltab     += vars->relcount;
535
649
  vars->int_reltab += vars->relcount;
536
649
  vars->relcount   = 0;
537
538
649
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
539
649
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_save_relocs
pei-loongarch64.c:pe_ILF_save_relocs
Line
Count
Source
522
3.21k
{
523
  /* Make sure that there is somewhere to store the internal relocs.  */
524
3.21k
  if (coff_section_data (vars->abfd, sec) == NULL)
525
    /* We should probably return an error indication here.  */
526
0
    abort ();
527
528
3.21k
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
529
530
3.21k
  sec->relocation  = vars->reltab;
531
3.21k
  sec->reloc_count = vars->relcount;
532
3.21k
  sec->flags      |= SEC_RELOC;
533
534
3.21k
  vars->reltab     += vars->relcount;
535
3.21k
  vars->int_reltab += vars->relcount;
536
3.21k
  vars->relcount   = 0;
537
538
3.21k
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
539
3.21k
}
pei-arm-wince.c:pe_ILF_save_relocs
Line
Count
Source
522
16
{
523
  /* Make sure that there is somewhere to store the internal relocs.  */
524
16
  if (coff_section_data (vars->abfd, sec) == NULL)
525
    /* We should probably return an error indication here.  */
526
0
    abort ();
527
528
16
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
529
530
16
  sec->relocation  = vars->reltab;
531
16
  sec->reloc_count = vars->relcount;
532
16
  sec->flags      |= SEC_RELOC;
533
534
16
  vars->reltab     += vars->relcount;
535
16
  vars->int_reltab += vars->relcount;
536
16
  vars->relcount   = 0;
537
538
16
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
539
16
}
pei-arm.c:pe_ILF_save_relocs
Line
Count
Source
522
3.41k
{
523
  /* Make sure that there is somewhere to store the internal relocs.  */
524
3.41k
  if (coff_section_data (vars->abfd, sec) == NULL)
525
    /* We should probably return an error indication here.  */
526
0
    abort ();
527
528
3.41k
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
529
530
3.41k
  sec->relocation  = vars->reltab;
531
3.41k
  sec->reloc_count = vars->relcount;
532
3.41k
  sec->flags      |= SEC_RELOC;
533
534
3.41k
  vars->reltab     += vars->relcount;
535
3.41k
  vars->int_reltab += vars->relcount;
536
3.41k
  vars->relcount   = 0;
537
538
3.41k
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
539
3.41k
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_save_relocs
pei-sh.c:pe_ILF_save_relocs
Line
Count
Source
522
2.43k
{
523
  /* Make sure that there is somewhere to store the internal relocs.  */
524
2.43k
  if (coff_section_data (vars->abfd, sec) == NULL)
525
    /* We should probably return an error indication here.  */
526
0
    abort ();
527
528
2.43k
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
529
530
2.43k
  sec->relocation  = vars->reltab;
531
2.43k
  sec->reloc_count = vars->relcount;
532
2.43k
  sec->flags      |= SEC_RELOC;
533
534
2.43k
  vars->reltab     += vars->relcount;
535
2.43k
  vars->int_reltab += vars->relcount;
536
2.43k
  vars->relcount   = 0;
537
538
2.43k
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
539
2.43k
}
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
47.1k
{
550
47.1k
  coff_symbol_type * sym;
551
47.1k
  combined_entry_type * ent;
552
47.1k
  SYMENT * esym;
553
47.1k
  unsigned short sclass;
554
555
47.1k
  if (extra_flags & BSF_LOCAL)
556
26.9k
    sclass = C_STAT;
557
20.1k
  else
558
20.1k
    sclass = C_EXT;
559
560
#ifdef THUMBPEMAGIC
561
10.7k
  if (vars->magic == THUMBPEMAGIC)
562
4.55k
    {
563
4.55k
      if (extra_flags & BSF_FUNCTION)
564
236
  sclass = C_THUMBEXTFUNC;
565
4.31k
      else if (extra_flags & BSF_LOCAL)
566
2.84k
  sclass = C_THUMBSTAT;
567
1.46k
      else
568
1.46k
  sclass = C_THUMBEXT;
569
4.55k
    }
570
#endif
571
572
47.1k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
573
574
47.1k
  sym = vars->sym_ptr;
575
47.1k
  ent = vars->native_ptr;
576
47.1k
  esym = vars->esym_ptr;
577
578
  /* Copy the symbol's name into the string table.  */
579
47.1k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
580
581
47.1k
  if (section == NULL)
582
7.89k
    section = bfd_und_section_ptr;
583
584
  /* Initialise the external symbol.  */
585
47.1k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
586
47.1k
      esym->e.e.e_offset);
587
47.1k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
588
47.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
47.1k
  ent->u.syment.n_sclass    = sclass;
595
47.1k
  ent->u.syment.n_scnum     = section->target_index;
596
47.1k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
597
47.1k
  ent->is_sym = true;
598
599
47.1k
  sym->symbol.the_bfd = vars->abfd;
600
47.1k
  sym->symbol.name    = vars->string_ptr;
601
47.1k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
602
47.1k
  sym->symbol.section = section;
603
47.1k
  sym->native       = ent;
604
605
47.1k
  * vars->table_ptr = vars->sym_index;
606
47.1k
  * vars->sym_ptr_ptr = sym;
607
608
  /* Adjust pointers for the next symbol.  */
609
47.1k
  vars->sym_index ++;
610
47.1k
  vars->sym_ptr ++;
611
47.1k
  vars->sym_ptr_ptr ++;
612
47.1k
  vars->table_ptr ++;
613
47.1k
  vars->native_ptr ++;
614
47.1k
  vars->esym_ptr ++;
615
47.1k
  vars->string_ptr += len + 1;
616
617
47.1k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
618
47.1k
}
pei-i386.c:pe_ILF_make_a_symbol
Line
Count
Source
549
8.28k
{
550
8.28k
  coff_symbol_type * sym;
551
8.28k
  combined_entry_type * ent;
552
8.28k
  SYMENT * esym;
553
8.28k
  unsigned short sclass;
554
555
8.28k
  if (extra_flags & BSF_LOCAL)
556
4.71k
    sclass = C_STAT;
557
3.57k
  else
558
3.57k
    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
8.28k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
573
574
8.28k
  sym = vars->sym_ptr;
575
8.28k
  ent = vars->native_ptr;
576
8.28k
  esym = vars->esym_ptr;
577
578
  /* Copy the symbol's name into the string table.  */
579
8.28k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
580
581
8.28k
  if (section == NULL)
582
1.50k
    section = bfd_und_section_ptr;
583
584
  /* Initialise the external symbol.  */
585
8.28k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
586
8.28k
      esym->e.e.e_offset);
587
8.28k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
588
8.28k
  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
8.28k
  ent->u.syment.n_sclass    = sclass;
595
8.28k
  ent->u.syment.n_scnum     = section->target_index;
596
8.28k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
597
8.28k
  ent->is_sym = true;
598
599
8.28k
  sym->symbol.the_bfd = vars->abfd;
600
8.28k
  sym->symbol.name    = vars->string_ptr;
601
8.28k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
602
8.28k
  sym->symbol.section = section;
603
8.28k
  sym->native       = ent;
604
605
8.28k
  * vars->table_ptr = vars->sym_index;
606
8.28k
  * vars->sym_ptr_ptr = sym;
607
608
  /* Adjust pointers for the next symbol.  */
609
8.28k
  vars->sym_index ++;
610
8.28k
  vars->sym_ptr ++;
611
8.28k
  vars->sym_ptr_ptr ++;
612
8.28k
  vars->table_ptr ++;
613
8.28k
  vars->native_ptr ++;
614
8.28k
  vars->esym_ptr ++;
615
8.28k
  vars->string_ptr += len + 1;
616
617
8.28k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
618
8.28k
}
pei-x86_64.c:pe_ILF_make_a_symbol
Line
Count
Source
549
9.13k
{
550
9.13k
  coff_symbol_type * sym;
551
9.13k
  combined_entry_type * ent;
552
9.13k
  SYMENT * esym;
553
9.13k
  unsigned short sclass;
554
555
9.13k
  if (extra_flags & BSF_LOCAL)
556
5.39k
    sclass = C_STAT;
557
3.74k
  else
558
3.74k
    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
9.13k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
573
574
9.13k
  sym = vars->sym_ptr;
575
9.13k
  ent = vars->native_ptr;
576
9.13k
  esym = vars->esym_ptr;
577
578
  /* Copy the symbol's name into the string table.  */
579
9.13k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
580
581
9.13k
  if (section == NULL)
582
1.47k
    section = bfd_und_section_ptr;
583
584
  /* Initialise the external symbol.  */
585
9.13k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
586
9.13k
      esym->e.e.e_offset);
587
9.13k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
588
9.13k
  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
9.13k
  ent->u.syment.n_sclass    = sclass;
595
9.13k
  ent->u.syment.n_scnum     = section->target_index;
596
9.13k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
597
9.13k
  ent->is_sym = true;
598
599
9.13k
  sym->symbol.the_bfd = vars->abfd;
600
9.13k
  sym->symbol.name    = vars->string_ptr;
601
9.13k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
602
9.13k
  sym->symbol.section = section;
603
9.13k
  sym->native       = ent;
604
605
9.13k
  * vars->table_ptr = vars->sym_index;
606
9.13k
  * vars->sym_ptr_ptr = sym;
607
608
  /* Adjust pointers for the next symbol.  */
609
9.13k
  vars->sym_index ++;
610
9.13k
  vars->sym_ptr ++;
611
9.13k
  vars->sym_ptr_ptr ++;
612
9.13k
  vars->table_ptr ++;
613
9.13k
  vars->native_ptr ++;
614
9.13k
  vars->esym_ptr ++;
615
9.13k
  vars->string_ptr += len + 1;
616
617
9.13k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
618
9.13k
}
pei-aarch64.c:pe_ILF_make_a_symbol
Line
Count
Source
549
2.75k
{
550
2.75k
  coff_symbol_type * sym;
551
2.75k
  combined_entry_type * ent;
552
2.75k
  SYMENT * esym;
553
2.75k
  unsigned short sclass;
554
555
2.75k
  if (extra_flags & BSF_LOCAL)
556
1.43k
    sclass = C_STAT;
557
1.32k
  else
558
1.32k
    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
2.75k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
573
574
2.75k
  sym = vars->sym_ptr;
575
2.75k
  ent = vars->native_ptr;
576
2.75k
  esym = vars->esym_ptr;
577
578
  /* Copy the symbol's name into the string table.  */
579
2.75k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
580
581
2.75k
  if (section == NULL)
582
441
    section = bfd_und_section_ptr;
583
584
  /* Initialise the external symbol.  */
585
2.75k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
586
2.75k
      esym->e.e.e_offset);
587
2.75k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
588
2.75k
  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
2.75k
  ent->u.syment.n_sclass    = sclass;
595
2.75k
  ent->u.syment.n_scnum     = section->target_index;
596
2.75k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
597
2.75k
  ent->is_sym = true;
598
599
2.75k
  sym->symbol.the_bfd = vars->abfd;
600
2.75k
  sym->symbol.name    = vars->string_ptr;
601
2.75k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
602
2.75k
  sym->symbol.section = section;
603
2.75k
  sym->native       = ent;
604
605
2.75k
  * vars->table_ptr = vars->sym_index;
606
2.75k
  * vars->sym_ptr_ptr = sym;
607
608
  /* Adjust pointers for the next symbol.  */
609
2.75k
  vars->sym_index ++;
610
2.75k
  vars->sym_ptr ++;
611
2.75k
  vars->sym_ptr_ptr ++;
612
2.75k
  vars->table_ptr ++;
613
2.75k
  vars->native_ptr ++;
614
2.75k
  vars->esym_ptr ++;
615
2.75k
  vars->string_ptr += len + 1;
616
617
2.75k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
618
2.75k
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_symbol
pei-loongarch64.c:pe_ILF_make_a_symbol
Line
Count
Source
549
9.81k
{
550
9.81k
  coff_symbol_type * sym;
551
9.81k
  combined_entry_type * ent;
552
9.81k
  SYMENT * esym;
553
9.81k
  unsigned short sclass;
554
555
9.81k
  if (extra_flags & BSF_LOCAL)
556
5.46k
    sclass = C_STAT;
557
4.35k
  else
558
4.35k
    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
9.81k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
573
574
9.81k
  sym = vars->sym_ptr;
575
9.81k
  ent = vars->native_ptr;
576
9.81k
  esym = vars->esym_ptr;
577
578
  /* Copy the symbol's name into the string table.  */
579
9.81k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
580
581
9.81k
  if (section == NULL)
582
1.67k
    section = bfd_und_section_ptr;
583
584
  /* Initialise the external symbol.  */
585
9.81k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
586
9.81k
      esym->e.e.e_offset);
587
9.81k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
588
9.81k
  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
9.81k
  ent->u.syment.n_sclass    = sclass;
595
9.81k
  ent->u.syment.n_scnum     = section->target_index;
596
9.81k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
597
9.81k
  ent->is_sym = true;
598
599
9.81k
  sym->symbol.the_bfd = vars->abfd;
600
9.81k
  sym->symbol.name    = vars->string_ptr;
601
9.81k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
602
9.81k
  sym->symbol.section = section;
603
9.81k
  sym->native       = ent;
604
605
9.81k
  * vars->table_ptr = vars->sym_index;
606
9.81k
  * vars->sym_ptr_ptr = sym;
607
608
  /* Adjust pointers for the next symbol.  */
609
9.81k
  vars->sym_index ++;
610
9.81k
  vars->sym_ptr ++;
611
9.81k
  vars->sym_ptr_ptr ++;
612
9.81k
  vars->table_ptr ++;
613
9.81k
  vars->native_ptr ++;
614
9.81k
  vars->esym_ptr ++;
615
9.81k
  vars->string_ptr += len + 1;
616
617
9.81k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
618
9.81k
}
pei-arm-wince.c:pe_ILF_make_a_symbol
Line
Count
Source
549
254
{
550
254
  coff_symbol_type * sym;
551
254
  combined_entry_type * ent;
552
254
  SYMENT * esym;
553
254
  unsigned short sclass;
554
555
254
  if (extra_flags & BSF_LOCAL)
556
234
    sclass = C_STAT;
557
20
  else
558
20
    sclass = C_EXT;
559
560
254
#ifdef THUMBPEMAGIC
561
254
  if (vars->magic == THUMBPEMAGIC)
562
230
    {
563
230
      if (extra_flags & BSF_FUNCTION)
564
1
  sclass = C_THUMBEXTFUNC;
565
229
      else if (extra_flags & BSF_LOCAL)
566
221
  sclass = C_THUMBSTAT;
567
8
      else
568
8
  sclass = C_THUMBEXT;
569
230
    }
570
254
#endif
571
572
254
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
573
574
254
  sym = vars->sym_ptr;
575
254
  ent = vars->native_ptr;
576
254
  esym = vars->esym_ptr;
577
578
  /* Copy the symbol's name into the string table.  */
579
254
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
580
581
254
  if (section == NULL)
582
8
    section = bfd_und_section_ptr;
583
584
  /* Initialise the external symbol.  */
585
254
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
586
254
      esym->e.e.e_offset);
587
254
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
588
254
  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
254
  ent->u.syment.n_sclass    = sclass;
595
254
  ent->u.syment.n_scnum     = section->target_index;
596
254
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
597
254
  ent->is_sym = true;
598
599
254
  sym->symbol.the_bfd = vars->abfd;
600
254
  sym->symbol.name    = vars->string_ptr;
601
254
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
602
254
  sym->symbol.section = section;
603
254
  sym->native       = ent;
604
605
254
  * vars->table_ptr = vars->sym_index;
606
254
  * vars->sym_ptr_ptr = sym;
607
608
  /* Adjust pointers for the next symbol.  */
609
254
  vars->sym_index ++;
610
254
  vars->sym_ptr ++;
611
254
  vars->sym_ptr_ptr ++;
612
254
  vars->table_ptr ++;
613
254
  vars->native_ptr ++;
614
254
  vars->esym_ptr ++;
615
254
  vars->string_ptr += len + 1;
616
617
254
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
618
254
}
pei-arm.c:pe_ILF_make_a_symbol
Line
Count
Source
549
10.4k
{
550
10.4k
  coff_symbol_type * sym;
551
10.4k
  combined_entry_type * ent;
552
10.4k
  SYMENT * esym;
553
10.4k
  unsigned short sclass;
554
555
10.4k
  if (extra_flags & BSF_LOCAL)
556
5.94k
    sclass = C_STAT;
557
4.54k
  else
558
4.54k
    sclass = C_EXT;
559
560
10.4k
#ifdef THUMBPEMAGIC
561
10.4k
  if (vars->magic == THUMBPEMAGIC)
562
4.32k
    {
563
4.32k
      if (extra_flags & BSF_FUNCTION)
564
235
  sclass = C_THUMBEXTFUNC;
565
4.08k
      else if (extra_flags & BSF_LOCAL)
566
2.62k
  sclass = C_THUMBSTAT;
567
1.45k
      else
568
1.45k
  sclass = C_THUMBEXT;
569
4.32k
    }
570
10.4k
#endif
571
572
10.4k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
573
574
10.4k
  sym = vars->sym_ptr;
575
10.4k
  ent = vars->native_ptr;
576
10.4k
  esym = vars->esym_ptr;
577
578
  /* Copy the symbol's name into the string table.  */
579
10.4k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
580
581
10.4k
  if (section == NULL)
582
1.75k
    section = bfd_und_section_ptr;
583
584
  /* Initialise the external symbol.  */
585
10.4k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
586
10.4k
      esym->e.e.e_offset);
587
10.4k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
588
10.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
10.4k
  ent->u.syment.n_sclass    = sclass;
595
10.4k
  ent->u.syment.n_scnum     = section->target_index;
596
10.4k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
597
10.4k
  ent->is_sym = true;
598
599
10.4k
  sym->symbol.the_bfd = vars->abfd;
600
10.4k
  sym->symbol.name    = vars->string_ptr;
601
10.4k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
602
10.4k
  sym->symbol.section = section;
603
10.4k
  sym->native       = ent;
604
605
10.4k
  * vars->table_ptr = vars->sym_index;
606
10.4k
  * vars->sym_ptr_ptr = sym;
607
608
  /* Adjust pointers for the next symbol.  */
609
10.4k
  vars->sym_index ++;
610
10.4k
  vars->sym_ptr ++;
611
10.4k
  vars->sym_ptr_ptr ++;
612
10.4k
  vars->table_ptr ++;
613
10.4k
  vars->native_ptr ++;
614
10.4k
  vars->esym_ptr ++;
615
10.4k
  vars->string_ptr += len + 1;
616
617
10.4k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
618
10.4k
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_symbol
pei-sh.c:pe_ILF_make_a_symbol
Line
Count
Source
549
6.42k
{
550
6.42k
  coff_symbol_type * sym;
551
6.42k
  combined_entry_type * ent;
552
6.42k
  SYMENT * esym;
553
6.42k
  unsigned short sclass;
554
555
6.42k
  if (extra_flags & BSF_LOCAL)
556
3.78k
    sclass = C_STAT;
557
2.64k
  else
558
2.64k
    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
6.42k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
573
574
6.42k
  sym = vars->sym_ptr;
575
6.42k
  ent = vars->native_ptr;
576
6.42k
  esym = vars->esym_ptr;
577
578
  /* Copy the symbol's name into the string table.  */
579
6.42k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
580
581
6.42k
  if (section == NULL)
582
1.03k
    section = bfd_und_section_ptr;
583
584
  /* Initialise the external symbol.  */
585
6.42k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
586
6.42k
      esym->e.e.e_offset);
587
6.42k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
588
6.42k
  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
6.42k
  ent->u.syment.n_sclass    = sclass;
595
6.42k
  ent->u.syment.n_scnum     = section->target_index;
596
6.42k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
597
6.42k
  ent->is_sym = true;
598
599
6.42k
  sym->symbol.the_bfd = vars->abfd;
600
6.42k
  sym->symbol.name    = vars->string_ptr;
601
6.42k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
602
6.42k
  sym->symbol.section = section;
603
6.42k
  sym->native       = ent;
604
605
6.42k
  * vars->table_ptr = vars->sym_index;
606
6.42k
  * vars->sym_ptr_ptr = sym;
607
608
  /* Adjust pointers for the next symbol.  */
609
6.42k
  vars->sym_index ++;
610
6.42k
  vars->sym_ptr ++;
611
6.42k
  vars->sym_ptr_ptr ++;
612
6.42k
  vars->table_ptr ++;
613
6.42k
  vars->native_ptr ++;
614
6.42k
  vars->esym_ptr ++;
615
6.42k
  vars->string_ptr += len + 1;
616
617
6.42k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
618
6.42k
}
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
26.9k
{
628
26.9k
  asection_ptr sec;
629
26.9k
  flagword     flags;
630
26.9k
  intptr_t alignment;
631
632
26.9k
  sec = bfd_make_section_old_way (vars->abfd, name);
633
26.9k
  if (sec == NULL)
634
0
    return NULL;
635
636
26.9k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
637
638
26.9k
  bfd_set_section_flags (sec, flags | extra_flags);
639
640
26.9k
  bfd_set_section_alignment (sec, 2);
641
642
  /* Check that we will not run out of space.  */
643
26.9k
  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
26.9k
  bfd_set_section_size (sec, (bfd_size_type) size);
648
26.9k
  sec->contents = vars->data;
649
26.9k
  sec->target_index = vars->sec_index ++;
650
651
  /* Advance data pointer in the vars structure.  */
652
26.9k
  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
26.9k
  if (size & 1)
659
3.67k
    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
26.9k
#if GCC_VERSION >= 3000
666
26.9k
  alignment = __alignof__ (struct coff_section_tdata);
667
#else
668
  alignment = 8;
669
#endif
670
26.9k
  vars->data
671
26.9k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
672
673
  /* Create a coff_section_tdata structure for our use.  */
674
26.9k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
675
26.9k
  vars->data += sizeof (struct coff_section_tdata);
676
677
26.9k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
678
679
  /* Create a symbol to refer to this section.  */
680
26.9k
  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
26.9k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
684
685
26.9k
  return sec;
686
26.9k
}
pei-i386.c:pe_ILF_make_a_section
Line
Count
Source
627
4.71k
{
628
4.71k
  asection_ptr sec;
629
4.71k
  flagword     flags;
630
4.71k
  intptr_t alignment;
631
632
4.71k
  sec = bfd_make_section_old_way (vars->abfd, name);
633
4.71k
  if (sec == NULL)
634
0
    return NULL;
635
636
4.71k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
637
638
4.71k
  bfd_set_section_flags (sec, flags | extra_flags);
639
640
4.71k
  bfd_set_section_alignment (sec, 2);
641
642
  /* Check that we will not run out of space.  */
643
4.71k
  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
4.71k
  bfd_set_section_size (sec, (bfd_size_type) size);
648
4.71k
  sec->contents = vars->data;
649
4.71k
  sec->target_index = vars->sec_index ++;
650
651
  /* Advance data pointer in the vars structure.  */
652
4.71k
  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
4.71k
  if (size & 1)
659
932
    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
4.71k
#if GCC_VERSION >= 3000
666
4.71k
  alignment = __alignof__ (struct coff_section_tdata);
667
#else
668
  alignment = 8;
669
#endif
670
4.71k
  vars->data
671
4.71k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
672
673
  /* Create a coff_section_tdata structure for our use.  */
674
4.71k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
675
4.71k
  vars->data += sizeof (struct coff_section_tdata);
676
677
4.71k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
678
679
  /* Create a symbol to refer to this section.  */
680
4.71k
  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
4.71k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
684
685
4.71k
  return sec;
686
4.71k
}
pei-x86_64.c:pe_ILF_make_a_section
Line
Count
Source
627
5.39k
{
628
5.39k
  asection_ptr sec;
629
5.39k
  flagword     flags;
630
5.39k
  intptr_t alignment;
631
632
5.39k
  sec = bfd_make_section_old_way (vars->abfd, name);
633
5.39k
  if (sec == NULL)
634
0
    return NULL;
635
636
5.39k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
637
638
5.39k
  bfd_set_section_flags (sec, flags | extra_flags);
639
640
5.39k
  bfd_set_section_alignment (sec, 2);
641
642
  /* Check that we will not run out of space.  */
643
5.39k
  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
5.39k
  bfd_set_section_size (sec, (bfd_size_type) size);
648
5.39k
  sec->contents = vars->data;
649
5.39k
  sec->target_index = vars->sec_index ++;
650
651
  /* Advance data pointer in the vars structure.  */
652
5.39k
  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
5.39k
  if (size & 1)
659
670
    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
5.39k
#if GCC_VERSION >= 3000
666
5.39k
  alignment = __alignof__ (struct coff_section_tdata);
667
#else
668
  alignment = 8;
669
#endif
670
5.39k
  vars->data
671
5.39k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
672
673
  /* Create a coff_section_tdata structure for our use.  */
674
5.39k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
675
5.39k
  vars->data += sizeof (struct coff_section_tdata);
676
677
5.39k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
678
679
  /* Create a symbol to refer to this section.  */
680
5.39k
  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
5.39k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
684
685
5.39k
  return sec;
686
5.39k
}
pei-aarch64.c:pe_ILF_make_a_section
Line
Count
Source
627
1.43k
{
628
1.43k
  asection_ptr sec;
629
1.43k
  flagword     flags;
630
1.43k
  intptr_t alignment;
631
632
1.43k
  sec = bfd_make_section_old_way (vars->abfd, name);
633
1.43k
  if (sec == NULL)
634
0
    return NULL;
635
636
1.43k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
637
638
1.43k
  bfd_set_section_flags (sec, flags | extra_flags);
639
640
1.43k
  bfd_set_section_alignment (sec, 2);
641
642
  /* Check that we will not run out of space.  */
643
1.43k
  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
1.43k
  bfd_set_section_size (sec, (bfd_size_type) size);
648
1.43k
  sec->contents = vars->data;
649
1.43k
  sec->target_index = vars->sec_index ++;
650
651
  /* Advance data pointer in the vars structure.  */
652
1.43k
  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
1.43k
  if (size & 1)
659
102
    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
1.43k
#if GCC_VERSION >= 3000
666
1.43k
  alignment = __alignof__ (struct coff_section_tdata);
667
#else
668
  alignment = 8;
669
#endif
670
1.43k
  vars->data
671
1.43k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
672
673
  /* Create a coff_section_tdata structure for our use.  */
674
1.43k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
675
1.43k
  vars->data += sizeof (struct coff_section_tdata);
676
677
1.43k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
678
679
  /* Create a symbol to refer to this section.  */
680
1.43k
  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
1.43k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
684
685
1.43k
  return sec;
686
1.43k
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_section
pei-loongarch64.c:pe_ILF_make_a_section
Line
Count
Source
627
5.46k
{
628
5.46k
  asection_ptr sec;
629
5.46k
  flagword     flags;
630
5.46k
  intptr_t alignment;
631
632
5.46k
  sec = bfd_make_section_old_way (vars->abfd, name);
633
5.46k
  if (sec == NULL)
634
0
    return NULL;
635
636
5.46k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
637
638
5.46k
  bfd_set_section_flags (sec, flags | extra_flags);
639
640
5.46k
  bfd_set_section_alignment (sec, 2);
641
642
  /* Check that we will not run out of space.  */
643
5.46k
  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
5.46k
  bfd_set_section_size (sec, (bfd_size_type) size);
648
5.46k
  sec->contents = vars->data;
649
5.46k
  sec->target_index = vars->sec_index ++;
650
651
  /* Advance data pointer in the vars structure.  */
652
5.46k
  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
5.46k
  if (size & 1)
659
771
    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
5.46k
#if GCC_VERSION >= 3000
666
5.46k
  alignment = __alignof__ (struct coff_section_tdata);
667
#else
668
  alignment = 8;
669
#endif
670
5.46k
  vars->data
671
5.46k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
672
673
  /* Create a coff_section_tdata structure for our use.  */
674
5.46k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
675
5.46k
  vars->data += sizeof (struct coff_section_tdata);
676
677
5.46k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
678
679
  /* Create a symbol to refer to this section.  */
680
5.46k
  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
5.46k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
684
685
5.46k
  return sec;
686
5.46k
}
pei-arm-wince.c:pe_ILF_make_a_section
Line
Count
Source
627
234
{
628
234
  asection_ptr sec;
629
234
  flagword     flags;
630
234
  intptr_t alignment;
631
632
234
  sec = bfd_make_section_old_way (vars->abfd, name);
633
234
  if (sec == NULL)
634
0
    return NULL;
635
636
234
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
637
638
234
  bfd_set_section_flags (sec, flags | extra_flags);
639
640
234
  bfd_set_section_alignment (sec, 2);
641
642
  /* Check that we will not run out of space.  */
643
234
  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
234
  bfd_set_section_size (sec, (bfd_size_type) size);
648
234
  sec->contents = vars->data;
649
234
  sec->target_index = vars->sec_index ++;
650
651
  /* Advance data pointer in the vars structure.  */
652
234
  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
234
  if (size & 1)
659
4
    vars->data --;
660
661
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
662
     preserve host alignment requirements.  The BFD_ASSERTs in this
663
     functions will warn us if we run out of room, but we should
664
     already have enough padding built in to ILF_DATA_SIZE.  */
665
234
#if GCC_VERSION >= 3000
666
234
  alignment = __alignof__ (struct coff_section_tdata);
667
#else
668
  alignment = 8;
669
#endif
670
234
  vars->data
671
234
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
672
673
  /* Create a coff_section_tdata structure for our use.  */
674
234
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
675
234
  vars->data += sizeof (struct coff_section_tdata);
676
677
234
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
678
679
  /* Create a symbol to refer to this section.  */
680
234
  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
234
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
684
685
234
  return sec;
686
234
}
pei-arm.c:pe_ILF_make_a_section
Line
Count
Source
627
5.94k
{
628
5.94k
  asection_ptr sec;
629
5.94k
  flagword     flags;
630
5.94k
  intptr_t alignment;
631
632
5.94k
  sec = bfd_make_section_old_way (vars->abfd, name);
633
5.94k
  if (sec == NULL)
634
0
    return NULL;
635
636
5.94k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
637
638
5.94k
  bfd_set_section_flags (sec, flags | extra_flags);
639
640
5.94k
  bfd_set_section_alignment (sec, 2);
641
642
  /* Check that we will not run out of space.  */
643
5.94k
  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
5.94k
  bfd_set_section_size (sec, (bfd_size_type) size);
648
5.94k
  sec->contents = vars->data;
649
5.94k
  sec->target_index = vars->sec_index ++;
650
651
  /* Advance data pointer in the vars structure.  */
652
5.94k
  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
5.94k
  if (size & 1)
659
725
    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
5.94k
#if GCC_VERSION >= 3000
666
5.94k
  alignment = __alignof__ (struct coff_section_tdata);
667
#else
668
  alignment = 8;
669
#endif
670
5.94k
  vars->data
671
5.94k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
672
673
  /* Create a coff_section_tdata structure for our use.  */
674
5.94k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
675
5.94k
  vars->data += sizeof (struct coff_section_tdata);
676
677
5.94k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
678
679
  /* Create a symbol to refer to this section.  */
680
5.94k
  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
5.94k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
684
685
5.94k
  return sec;
686
5.94k
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_section
pei-sh.c:pe_ILF_make_a_section
Line
Count
Source
627
3.78k
{
628
3.78k
  asection_ptr sec;
629
3.78k
  flagword     flags;
630
3.78k
  intptr_t alignment;
631
632
3.78k
  sec = bfd_make_section_old_way (vars->abfd, name);
633
3.78k
  if (sec == NULL)
634
0
    return NULL;
635
636
3.78k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
637
638
3.78k
  bfd_set_section_flags (sec, flags | extra_flags);
639
640
3.78k
  bfd_set_section_alignment (sec, 2);
641
642
  /* Check that we will not run out of space.  */
643
3.78k
  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
3.78k
  bfd_set_section_size (sec, (bfd_size_type) size);
648
3.78k
  sec->contents = vars->data;
649
3.78k
  sec->target_index = vars->sec_index ++;
650
651
  /* Advance data pointer in the vars structure.  */
652
3.78k
  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
3.78k
  if (size & 1)
659
468
    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
3.78k
#if GCC_VERSION >= 3000
666
3.78k
  alignment = __alignof__ (struct coff_section_tdata);
667
#else
668
  alignment = 8;
669
#endif
670
3.78k
  vars->data
671
3.78k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
672
673
  /* Create a coff_section_tdata structure for our use.  */
674
3.78k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
675
3.78k
  vars->data += sizeof (struct coff_section_tdata);
676
677
3.78k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
678
679
  /* Create a symbol to refer to this section.  */
680
3.78k
  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
3.78k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
684
685
3.78k
  return sec;
686
3.78k
}
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
17.0k
#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
4.41k
#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
10.4k
{
799
10.4k
  bfd_byte *       ptr;
800
10.4k
  pe_ILF_vars      vars;
801
10.4k
  struct internal_filehdr  internal_f;
802
10.4k
  unsigned int       import_type;
803
10.4k
  unsigned int       import_name_type;
804
10.4k
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
805
10.4k
  coff_symbol_type **    imp_sym;
806
10.4k
  unsigned int       imp_index;
807
10.4k
  intptr_t alignment;
808
809
  /* Decode and verify the types field of the ILF structure.  */
810
10.4k
  import_type = types & 0x3;
811
10.4k
  import_name_type = (types & 0x1c) >> 2;
812
813
10.4k
  switch (import_type)
814
10.4k
    {
815
5.35k
    case IMPORT_CODE:
816
9.24k
    case IMPORT_DATA:
817
9.24k
      break;
818
819
624
    case IMPORT_CONST:
820
      /* XXX code yet to be written.  */
821
      /* xgettext:c-format */
822
624
      _bfd_error_handler (_("%pB: unhandled import type; %x"),
823
624
        abfd, import_type);
824
624
      return false;
825
826
624
    default:
827
      /* xgettext:c-format */
828
624
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
624
        abfd, import_type);
830
624
      return false;
831
10.4k
    }
832
833
9.24k
  switch (import_name_type)
834
9.24k
    {
835
3.00k
    case IMPORT_ORDINAL:
836
4.70k
    case IMPORT_NAME:
837
6.24k
    case IMPORT_NAME_NOPREFIX:
838
8.51k
    case IMPORT_NAME_UNDECORATE:
839
8.51k
      break;
840
841
728
    default:
842
      /* xgettext:c-format */
843
728
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
844
728
        abfd, import_name_type);
845
728
      return false;
846
9.24k
    }
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
8.51k
  vars.bim
856
8.51k
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
857
8.51k
  if (vars.bim == NULL)
858
0
    return false;
859
860
8.51k
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
861
8.51k
  vars.bim->buffer = ptr;
862
8.51k
  vars.bim->size   = ILF_DATA_SIZE;
863
8.51k
  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
8.51k
  vars.sym_cache = (coff_symbol_type *) ptr;
869
8.51k
  vars.sym_ptr   = (coff_symbol_type *) ptr;
870
8.51k
  vars.sym_index = 0;
871
8.51k
  ptr += SIZEOF_ILF_SYMS;
872
873
8.51k
  vars.sym_table = (unsigned int *) ptr;
874
8.51k
  vars.table_ptr = (unsigned int *) ptr;
875
8.51k
  ptr += SIZEOF_ILF_SYM_TABLE;
876
877
8.51k
  vars.native_syms = (combined_entry_type *) ptr;
878
8.51k
  vars.native_ptr  = (combined_entry_type *) ptr;
879
8.51k
  ptr += SIZEOF_ILF_NATIVE_SYMS;
880
881
8.51k
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
882
8.51k
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
883
8.51k
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
884
885
8.51k
  vars.esym_table = (SYMENT *) ptr;
886
8.51k
  vars.esym_ptr   = (SYMENT *) ptr;
887
8.51k
  ptr += SIZEOF_ILF_EXT_SYMS;
888
889
8.51k
  vars.reltab   = (arelent *) ptr;
890
8.51k
  vars.relcount = 0;
891
8.51k
  ptr += SIZEOF_ILF_RELOCS;
892
893
8.51k
  vars.int_reltab  = (struct internal_reloc *) ptr;
894
8.51k
  ptr += SIZEOF_ILF_INT_RELOCS;
895
896
8.51k
  vars.string_table = (char *) ptr;
897
8.51k
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
898
8.51k
  ptr += SIZEOF_ILF_STRINGS;
899
8.51k
  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
8.51k
#if GCC_VERSION >= 3000
909
8.51k
  alignment = __alignof__ (struct coff_section_tdata);
910
#else
911
  alignment = 8;
912
#endif
913
8.51k
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
914
915
8.51k
  vars.data = ptr;
916
8.51k
  vars.abfd = abfd;
917
8.51k
  vars.sec_index = 0;
918
8.51k
  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
8.51k
  id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
928
8.51k
  id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
929
8.51k
  if (id4 == NULL || id5 == NULL)
930
0
    goto error_return;
931
932
  /* Fill in the contents of these sections.  */
933
8.51k
  if (import_name_type == IMPORT_ORDINAL)
934
3.00k
    {
935
3.00k
      if (ordinal == 0)
936
  /* See PR 20907 for a reproducer.  */
937
626
  goto error_return;
938
939
#if defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) || defined(COFF_WITH_peLoongArch64)
940
1.13k
      ((unsigned int *) id4->contents)[0] = ordinal;
941
1.13k
      ((unsigned int *) id4->contents)[1] = 0x80000000;
942
1.13k
      ((unsigned int *) id5->contents)[0] = ordinal;
943
1.13k
      ((unsigned int *) id5->contents)[1] = 0x80000000;
944
#else
945
1.24k
      * (unsigned int *) id4->contents = ordinal | 0x80000000;
946
1.24k
      * (unsigned int *) id5->contents = ordinal | 0x80000000;
947
1.24k
#endif
948
1.24k
    }
949
5.51k
  else
950
5.51k
    {
951
5.51k
      char * symbol;
952
5.51k
      unsigned int len;
953
954
      /* Create .idata$6 - the Hint Name Table.  */
955
5.51k
      id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
956
5.51k
      if (id6 == NULL)
957
0
  goto error_return;
958
959
      /* If necessary, trim the import symbol name.  */
960
5.51k
      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
5.51k
      if (import_name_type != IMPORT_NAME)
970
3.80k
  {
971
3.80k
    char c = symbol[0];
972
973
    /* Check that we don't remove for targets with empty
974
       USER_LABEL_PREFIX the leading underscore.  */
975
3.80k
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
976
3.80k
        || c == '@' || c == '?')
977
567
      symbol++;
978
3.80k
  }
979
980
5.51k
      len = strlen (symbol);
981
5.51k
      if (import_name_type == IMPORT_NAME_UNDECORATE)
982
2.27k
  {
983
    /* Truncate at the first '@'.  */
984
2.27k
    char *at = strchr (symbol, '@');
985
986
2.27k
    if (at != NULL)
987
1.13k
      len = at - symbol;
988
2.27k
  }
989
990
5.51k
      id6->contents[0] = ordinal & 0xff;
991
5.51k
      id6->contents[1] = ordinal >> 8;
992
993
5.51k
      memcpy ((char *) id6->contents + 2, symbol, len);
994
5.51k
      id6->contents[len + 2] = '\0';
995
5.51k
    }
996
997
7.89k
  if (import_name_type != IMPORT_ORDINAL)
998
5.51k
    {
999
5.51k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1000
5.51k
      pe_ILF_save_relocs (&vars, id4);
1001
1002
5.51k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1003
5.51k
      pe_ILF_save_relocs (&vars, id5);
1004
5.51k
    }
1005
1006
  /* Create an import symbol.  */
1007
7.89k
  pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
1008
7.89k
  imp_sym   = vars.sym_ptr_ptr - 1;
1009
7.89k
  imp_index = vars.sym_index - 1;
1010
1011
  /* Create extra sections depending upon the type of import we are dealing with.  */
1012
7.89k
  switch (import_type)
1013
7.89k
    {
1014
0
      int i;
1015
1016
4.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
9.63k
      for (i = NUM_ENTRIES (jtab); i--;)
1021
9.63k
  {
1022
9.63k
    if (jtab[i].size == 0)
1023
4.41k
      continue;
1024
5.21k
    if (jtab[i].magic == magic)
1025
4.41k
      break;
1026
5.21k
  }
1027
      /* If we did not find a matching entry something is wrong.  */
1028
4.41k
      if (i < 0)
1029
0
  abort ();
1030
1031
      /* Create the .text section.  */
1032
4.41k
      text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
1033
4.41k
      if (text == NULL)
1034
0
  goto error_return;
1035
1036
      /* Copy in the jump code.  */
1037
4.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
803
      if (magic == AMD64MAGIC)
1055
803
  {
1056
803
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1057
803
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1058
803
              imp_index);
1059
803
  }
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
4.41k
      pe_ILF_save_relocs (& vars, text);
1067
4.41k
      break;
1068
1069
3.47k
    case IMPORT_DATA:
1070
3.47k
      break;
1071
1072
0
    default:
1073
      /* XXX code not yet written.  */
1074
0
      abort ();
1075
7.89k
    }
1076
1077
  /* Now create a symbol describing the imported value.  */
1078
7.89k
  switch (import_type)
1079
7.89k
    {
1080
4.41k
    case IMPORT_CODE:
1081
4.41k
      pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1082
4.41k
          BSF_NOT_AT_END | BSF_FUNCTION);
1083
1084
4.41k
      break;
1085
1086
3.47k
    case IMPORT_DATA:
1087
      /* Nothing to do here.  */
1088
3.47k
      break;
1089
1090
0
    default:
1091
      /* XXX code not yet written.  */
1092
0
      abort ();
1093
7.89k
    }
1094
1095
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1096
7.89k
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1097
7.89k
  if (ptr)
1098
1.63k
    * ptr = 0;
1099
7.89k
  pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1100
7.89k
  if (ptr)
1101
1.63k
    * ptr = '.';
1102
1103
  /* Initialise the bfd.  */
1104
7.89k
  memset (& internal_f, 0, sizeof (internal_f));
1105
1106
7.89k
  internal_f.f_magic  = magic;
1107
7.89k
  internal_f.f_symptr = 0;
1108
7.89k
  internal_f.f_nsyms  = 0;
1109
7.89k
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1110
1111
7.89k
  if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
1112
7.89k
      || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1113
0
    goto error_return;
1114
1115
7.89k
  if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL)
1116
0
    goto error_return;
1117
1118
7.89k
  obj_pe (abfd) = true;
1119
#ifdef THUMBPEMAGIC
1120
1.76k
  if (vars.magic == THUMBPEMAGIC)
1121
    /* Stop some linker warnings about thumb code not supporting interworking.  */
1122
733
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1123
#endif
1124
1125
  /* Switch from file contents to memory contents.  */
1126
7.89k
  bfd_cache_close (abfd);
1127
1128
7.89k
  abfd->iostream = (void *) vars.bim;
1129
7.89k
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1130
7.89k
  abfd->iovec = &_bfd_memory_iovec;
1131
7.89k
  abfd->where = 0;
1132
7.89k
  abfd->origin = 0;
1133
7.89k
  abfd->size = 0;
1134
7.89k
  obj_sym_filepos (abfd) = 0;
1135
1136
  /* Point the bfd at the symbol table.  */
1137
7.89k
  obj_symbols (abfd) = vars.sym_cache;
1138
7.89k
  abfd->symcount = vars.sym_index;
1139
1140
7.89k
  obj_raw_syments (abfd) = vars.native_syms;
1141
7.89k
  obj_raw_syment_count (abfd) = vars.sym_index;
1142
1143
7.89k
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1144
7.89k
  obj_coff_keep_syms (abfd) = true;
1145
1146
7.89k
  obj_convert (abfd) = vars.sym_table;
1147
7.89k
  obj_conv_table_size (abfd) = vars.sym_index;
1148
1149
7.89k
  obj_coff_strings (abfd) = vars.string_table;
1150
7.89k
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1151
7.89k
  obj_coff_keep_strings (abfd) = true;
1152
1153
7.89k
  return true;
1154
1155
626
 error_return:
1156
626
  free (vars.bim->buffer);
1157
626
  free (vars.bim);
1158
626
  return false;
1159
7.89k
}
pei-i386.c:pe_ILF_build_a_bfd
Line
Count
Source
798
1.81k
{
799
1.81k
  bfd_byte *       ptr;
800
1.81k
  pe_ILF_vars      vars;
801
1.81k
  struct internal_filehdr  internal_f;
802
1.81k
  unsigned int       import_type;
803
1.81k
  unsigned int       import_name_type;
804
1.81k
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
805
1.81k
  coff_symbol_type **    imp_sym;
806
1.81k
  unsigned int       imp_index;
807
1.81k
  intptr_t alignment;
808
809
  /* Decode and verify the types field of the ILF structure.  */
810
1.81k
  import_type = types & 0x3;
811
1.81k
  import_name_type = (types & 0x1c) >> 2;
812
813
1.81k
  switch (import_type)
814
1.81k
    {
815
672
    case IMPORT_CODE:
816
1.70k
    case IMPORT_DATA:
817
1.70k
      break;
818
819
2
    case IMPORT_CONST:
820
      /* XXX code yet to be written.  */
821
      /* xgettext:c-format */
822
2
      _bfd_error_handler (_("%pB: unhandled import type; %x"),
823
2
        abfd, import_type);
824
2
      return false;
825
826
103
    default:
827
      /* xgettext:c-format */
828
103
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
103
        abfd, import_type);
830
103
      return false;
831
1.81k
    }
832
833
1.70k
  switch (import_name_type)
834
1.70k
    {
835
673
    case IMPORT_ORDINAL:
836
673
    case IMPORT_NAME:
837
906
    case IMPORT_NAME_NOPREFIX:
838
1.60k
    case IMPORT_NAME_UNDECORATE:
839
1.60k
      break;
840
841
102
    default:
842
      /* xgettext:c-format */
843
102
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
844
102
        abfd, import_name_type);
845
102
      return false;
846
1.70k
    }
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
1.60k
  vars.bim
856
1.60k
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
857
1.60k
  if (vars.bim == NULL)
858
0
    return false;
859
860
1.60k
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
861
1.60k
  vars.bim->buffer = ptr;
862
1.60k
  vars.bim->size   = ILF_DATA_SIZE;
863
1.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
1.60k
  vars.sym_cache = (coff_symbol_type *) ptr;
869
1.60k
  vars.sym_ptr   = (coff_symbol_type *) ptr;
870
1.60k
  vars.sym_index = 0;
871
1.60k
  ptr += SIZEOF_ILF_SYMS;
872
873
1.60k
  vars.sym_table = (unsigned int *) ptr;
874
1.60k
  vars.table_ptr = (unsigned int *) ptr;
875
1.60k
  ptr += SIZEOF_ILF_SYM_TABLE;
876
877
1.60k
  vars.native_syms = (combined_entry_type *) ptr;
878
1.60k
  vars.native_ptr  = (combined_entry_type *) ptr;
879
1.60k
  ptr += SIZEOF_ILF_NATIVE_SYMS;
880
881
1.60k
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
882
1.60k
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
883
1.60k
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
884
885
1.60k
  vars.esym_table = (SYMENT *) ptr;
886
1.60k
  vars.esym_ptr   = (SYMENT *) ptr;
887
1.60k
  ptr += SIZEOF_ILF_EXT_SYMS;
888
889
1.60k
  vars.reltab   = (arelent *) ptr;
890
1.60k
  vars.relcount = 0;
891
1.60k
  ptr += SIZEOF_ILF_RELOCS;
892
893
1.60k
  vars.int_reltab  = (struct internal_reloc *) ptr;
894
1.60k
  ptr += SIZEOF_ILF_INT_RELOCS;
895
896
1.60k
  vars.string_table = (char *) ptr;
897
1.60k
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
898
1.60k
  ptr += SIZEOF_ILF_STRINGS;
899
1.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
1.60k
#if GCC_VERSION >= 3000
909
1.60k
  alignment = __alignof__ (struct coff_section_tdata);
910
#else
911
  alignment = 8;
912
#endif
913
1.60k
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
914
915
1.60k
  vars.data = ptr;
916
1.60k
  vars.abfd = abfd;
917
1.60k
  vars.sec_index = 0;
918
1.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
1.60k
  id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
928
1.60k
  id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
929
1.60k
  if (id4 == NULL || id5 == NULL)
930
0
    goto error_return;
931
932
  /* Fill in the contents of these sections.  */
933
1.60k
  if (import_name_type == IMPORT_ORDINAL)
934
673
    {
935
673
      if (ordinal == 0)
936
  /* See PR 20907 for a reproducer.  */
937
104
  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
569
      * (unsigned int *) id4->contents = ordinal | 0x80000000;
946
569
      * (unsigned int *) id5->contents = ordinal | 0x80000000;
947
569
#endif
948
569
    }
949
932
  else
950
932
    {
951
932
      char * symbol;
952
932
      unsigned int len;
953
954
      /* Create .idata$6 - the Hint Name Table.  */
955
932
      id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
956
932
      if (id6 == NULL)
957
0
  goto error_return;
958
959
      /* If necessary, trim the import symbol name.  */
960
932
      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
932
      if (import_name_type != IMPORT_NAME)
970
932
  {
971
932
    char c = symbol[0];
972
973
    /* Check that we don't remove for targets with empty
974
       USER_LABEL_PREFIX the leading underscore.  */
975
932
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
976
932
        || c == '@' || c == '?')
977
0
      symbol++;
978
932
  }
979
980
932
      len = strlen (symbol);
981
932
      if (import_name_type == IMPORT_NAME_UNDECORATE)
982
699
  {
983
    /* Truncate at the first '@'.  */
984
699
    char *at = strchr (symbol, '@');
985
986
699
    if (at != NULL)
987
466
      len = at - symbol;
988
699
  }
989
990
932
      id6->contents[0] = ordinal & 0xff;
991
932
      id6->contents[1] = ordinal >> 8;
992
993
932
      memcpy ((char *) id6->contents + 2, symbol, len);
994
932
      id6->contents[len + 2] = '\0';
995
932
    }
996
997
1.50k
  if (import_name_type != IMPORT_ORDINAL)
998
932
    {
999
932
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1000
932
      pe_ILF_save_relocs (&vars, id4);
1001
1002
932
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1003
932
      pe_ILF_save_relocs (&vars, id5);
1004
932
    }
1005
1006
  /* Create an import symbol.  */
1007
1.50k
  pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
1008
1.50k
  imp_sym   = vars.sym_ptr_ptr - 1;
1009
1.50k
  imp_index = vars.sym_index - 1;
1010
1011
  /* Create extra sections depending upon the type of import we are dealing with.  */
1012
1.50k
  switch (import_type)
1013
1.50k
    {
1014
0
      int i;
1015
1016
568
    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
1.13k
      for (i = NUM_ENTRIES (jtab); i--;)
1021
1.13k
  {
1022
1.13k
    if (jtab[i].size == 0)
1023
568
      continue;
1024
568
    if (jtab[i].magic == magic)
1025
568
      break;
1026
568
  }
1027
      /* If we did not find a matching entry something is wrong.  */
1028
568
      if (i < 0)
1029
0
  abort ();
1030
1031
      /* Create the .text section.  */
1032
568
      text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
1033
568
      if (text == NULL)
1034
0
  goto error_return;
1035
1036
      /* Copy in the jump code.  */
1037
568
      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
568
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1063
568
            BFD_RELOC_32, (asymbol **) imp_sym,
1064
568
            imp_index);
1065
1066
568
      pe_ILF_save_relocs (& vars, text);
1067
568
      break;
1068
1069
933
    case IMPORT_DATA:
1070
933
      break;
1071
1072
0
    default:
1073
      /* XXX code not yet written.  */
1074
0
      abort ();
1075
1.50k
    }
1076
1077
  /* Now create a symbol describing the imported value.  */
1078
1.50k
  switch (import_type)
1079
1.50k
    {
1080
568
    case IMPORT_CODE:
1081
568
      pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1082
568
          BSF_NOT_AT_END | BSF_FUNCTION);
1083
1084
568
      break;
1085
1086
933
    case IMPORT_DATA:
1087
      /* Nothing to do here.  */
1088
933
      break;
1089
1090
0
    default:
1091
      /* XXX code not yet written.  */
1092
0
      abort ();
1093
1.50k
    }
1094
1095
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1096
1.50k
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1097
1.50k
  if (ptr)
1098
0
    * ptr = 0;
1099
1.50k
  pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1100
1.50k
  if (ptr)
1101
0
    * ptr = '.';
1102
1103
  /* Initialise the bfd.  */
1104
1.50k
  memset (& internal_f, 0, sizeof (internal_f));
1105
1106
1.50k
  internal_f.f_magic  = magic;
1107
1.50k
  internal_f.f_symptr = 0;
1108
1.50k
  internal_f.f_nsyms  = 0;
1109
1.50k
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1110
1111
1.50k
  if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
1112
1.50k
      || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1113
0
    goto error_return;
1114
1115
1.50k
  if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL)
1116
0
    goto error_return;
1117
1118
1.50k
  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
1.50k
  bfd_cache_close (abfd);
1127
1128
1.50k
  abfd->iostream = (void *) vars.bim;
1129
1.50k
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1130
1.50k
  abfd->iovec = &_bfd_memory_iovec;
1131
1.50k
  abfd->where = 0;
1132
1.50k
  abfd->origin = 0;
1133
1.50k
  abfd->size = 0;
1134
1.50k
  obj_sym_filepos (abfd) = 0;
1135
1136
  /* Point the bfd at the symbol table.  */
1137
1.50k
  obj_symbols (abfd) = vars.sym_cache;
1138
1.50k
  abfd->symcount = vars.sym_index;
1139
1140
1.50k
  obj_raw_syments (abfd) = vars.native_syms;
1141
1.50k
  obj_raw_syment_count (abfd) = vars.sym_index;
1142
1143
1.50k
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1144
1.50k
  obj_coff_keep_syms (abfd) = true;
1145
1146
1.50k
  obj_convert (abfd) = vars.sym_table;
1147
1.50k
  obj_conv_table_size (abfd) = vars.sym_index;
1148
1149
1.50k
  obj_coff_strings (abfd) = vars.string_table;
1150
1.50k
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1151
1.50k
  obj_coff_keep_strings (abfd) = true;
1152
1153
1.50k
  return true;
1154
1155
104
 error_return:
1156
104
  free (vars.bim->buffer);
1157
104
  free (vars.bim);
1158
104
  return false;
1159
1.50k
}
pei-x86_64.c:pe_ILF_build_a_bfd
Line
Count
Source
798
1.98k
{
799
1.98k
  bfd_byte *       ptr;
800
1.98k
  pe_ILF_vars      vars;
801
1.98k
  struct internal_filehdr  internal_f;
802
1.98k
  unsigned int       import_type;
803
1.98k
  unsigned int       import_name_type;
804
1.98k
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
805
1.98k
  coff_symbol_type **    imp_sym;
806
1.98k
  unsigned int       imp_index;
807
1.98k
  intptr_t alignment;
808
809
  /* Decode and verify the types field of the ILF structure.  */
810
1.98k
  import_type = types & 0x3;
811
1.98k
  import_name_type = (types & 0x1c) >> 2;
812
813
1.98k
  switch (import_type)
814
1.98k
    {
815
1.11k
    case IMPORT_CODE:
816
1.78k
    case IMPORT_DATA:
817
1.78k
      break;
818
819
102
    case IMPORT_CONST:
820
      /* XXX code yet to be written.  */
821
      /* xgettext:c-format */
822
102
      _bfd_error_handler (_("%pB: unhandled import type; %x"),
823
102
        abfd, import_type);
824
102
      return false;
825
826
104
    default:
827
      /* xgettext:c-format */
828
104
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
104
        abfd, import_type);
830
104
      return false;
831
1.98k
    }
832
833
1.78k
  switch (import_name_type)
834
1.78k
    {
835
439
    case IMPORT_ORDINAL:
836
774
    case IMPORT_NAME:
837
1.10k
    case IMPORT_NAME_NOPREFIX:
838
1.67k
    case IMPORT_NAME_UNDECORATE:
839
1.67k
      break;
840
841
104
    default:
842
      /* xgettext:c-format */
843
104
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
844
104
        abfd, import_name_type);
845
104
      return false;
846
1.78k
    }
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
1.67k
  vars.bim
856
1.67k
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
857
1.67k
  if (vars.bim == NULL)
858
0
    return false;
859
860
1.67k
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
861
1.67k
  vars.bim->buffer = ptr;
862
1.67k
  vars.bim->size   = ILF_DATA_SIZE;
863
1.67k
  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
1.67k
  vars.sym_cache = (coff_symbol_type *) ptr;
869
1.67k
  vars.sym_ptr   = (coff_symbol_type *) ptr;
870
1.67k
  vars.sym_index = 0;
871
1.67k
  ptr += SIZEOF_ILF_SYMS;
872
873
1.67k
  vars.sym_table = (unsigned int *) ptr;
874
1.67k
  vars.table_ptr = (unsigned int *) ptr;
875
1.67k
  ptr += SIZEOF_ILF_SYM_TABLE;
876
877
1.67k
  vars.native_syms = (combined_entry_type *) ptr;
878
1.67k
  vars.native_ptr  = (combined_entry_type *) ptr;
879
1.67k
  ptr += SIZEOF_ILF_NATIVE_SYMS;
880
881
1.67k
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
882
1.67k
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
883
1.67k
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
884
885
1.67k
  vars.esym_table = (SYMENT *) ptr;
886
1.67k
  vars.esym_ptr   = (SYMENT *) ptr;
887
1.67k
  ptr += SIZEOF_ILF_EXT_SYMS;
888
889
1.67k
  vars.reltab   = (arelent *) ptr;
890
1.67k
  vars.relcount = 0;
891
1.67k
  ptr += SIZEOF_ILF_RELOCS;
892
893
1.67k
  vars.int_reltab  = (struct internal_reloc *) ptr;
894
1.67k
  ptr += SIZEOF_ILF_INT_RELOCS;
895
896
1.67k
  vars.string_table = (char *) ptr;
897
1.67k
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
898
1.67k
  ptr += SIZEOF_ILF_STRINGS;
899
1.67k
  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
1.67k
#if GCC_VERSION >= 3000
909
1.67k
  alignment = __alignof__ (struct coff_section_tdata);
910
#else
911
  alignment = 8;
912
#endif
913
1.67k
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
914
915
1.67k
  vars.data = ptr;
916
1.67k
  vars.abfd = abfd;
917
1.67k
  vars.sec_index = 0;
918
1.67k
  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
1.67k
  id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
928
1.67k
  id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
929
1.67k
  if (id4 == NULL || id5 == NULL)
930
0
    goto error_return;
931
932
  /* Fill in the contents of these sections.  */
933
1.67k
  if (import_name_type == IMPORT_ORDINAL)
934
439
    {
935
439
      if (ordinal == 0)
936
  /* See PR 20907 for a reproducer.  */
937
205
  goto error_return;
938
939
234
#if defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) || defined(COFF_WITH_peLoongArch64)
940
234
      ((unsigned int *) id4->contents)[0] = ordinal;
941
234
      ((unsigned int *) id4->contents)[1] = 0x80000000;
942
234
      ((unsigned int *) id5->contents)[0] = ordinal;
943
234
      ((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
234
    }
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
902
  {
971
902
    char c = symbol[0];
972
973
    /* Check that we don't remove for targets with empty
974
       USER_LABEL_PREFIX the leading underscore.  */
975
902
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
976
902
        || c == '@' || c == '?')
977
567
      symbol++;
978
902
  }
979
980
1.23k
      len = strlen (symbol);
981
1.23k
      if (import_name_type == IMPORT_NAME_UNDECORATE)
982
568
  {
983
    /* Truncate at the first '@'.  */
984
568
    char *at = strchr (symbol, '@');
985
986
568
    if (at != NULL)
987
233
      len = at - symbol;
988
568
  }
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
1.47k
  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
1.47k
  pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
1008
1.47k
  imp_sym   = vars.sym_ptr_ptr - 1;
1009
1.47k
  imp_index = vars.sym_index - 1;
1010
1011
  /* Create extra sections depending upon the type of import we are dealing with.  */
1012
1.47k
  switch (import_type)
1013
1.47k
    {
1014
0
      int i;
1015
1016
803
    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
1.60k
      for (i = NUM_ENTRIES (jtab); i--;)
1021
1.60k
  {
1022
1.60k
    if (jtab[i].size == 0)
1023
803
      continue;
1024
803
    if (jtab[i].magic == magic)
1025
803
      break;
1026
803
  }
1027
      /* If we did not find a matching entry something is wrong.  */
1028
803
      if (i < 0)
1029
0
  abort ();
1030
1031
      /* Create the .text section.  */
1032
803
      text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
1033
803
      if (text == NULL)
1034
0
  goto error_return;
1035
1036
      /* Copy in the jump code.  */
1037
803
      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
803
#ifdef AMD64MAGIC
1054
803
      if (magic == AMD64MAGIC)
1055
803
  {
1056
803
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1057
803
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1058
803
              imp_index);
1059
803
  }
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
803
      pe_ILF_save_relocs (& vars, text);
1067
803
      break;
1068
1069
668
    case IMPORT_DATA:
1070
668
      break;
1071
1072
0
    default:
1073
      /* XXX code not yet written.  */
1074
0
      abort ();
1075
1.47k
    }
1076
1077
  /* Now create a symbol describing the imported value.  */
1078
1.47k
  switch (import_type)
1079
1.47k
    {
1080
803
    case IMPORT_CODE:
1081
803
      pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1082
803
          BSF_NOT_AT_END | BSF_FUNCTION);
1083
1084
803
      break;
1085
1086
668
    case IMPORT_DATA:
1087
      /* Nothing to do here.  */
1088
668
      break;
1089
1090
0
    default:
1091
      /* XXX code not yet written.  */
1092
0
      abort ();
1093
1.47k
    }
1094
1095
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1096
1.47k
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1097
1.47k
  if (ptr)
1098
567
    * ptr = 0;
1099
1.47k
  pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1100
1.47k
  if (ptr)
1101
567
    * ptr = '.';
1102
1103
  /* Initialise the bfd.  */
1104
1.47k
  memset (& internal_f, 0, sizeof (internal_f));
1105
1106
1.47k
  internal_f.f_magic  = magic;
1107
1.47k
  internal_f.f_symptr = 0;
1108
1.47k
  internal_f.f_nsyms  = 0;
1109
1.47k
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1110
1111
1.47k
  if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
1112
1.47k
      || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1113
0
    goto error_return;
1114
1115
1.47k
  if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL)
1116
0
    goto error_return;
1117
1118
1.47k
  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
1.47k
  bfd_cache_close (abfd);
1127
1128
1.47k
  abfd->iostream = (void *) vars.bim;
1129
1.47k
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1130
1.47k
  abfd->iovec = &_bfd_memory_iovec;
1131
1.47k
  abfd->where = 0;
1132
1.47k
  abfd->origin = 0;
1133
1.47k
  abfd->size = 0;
1134
1.47k
  obj_sym_filepos (abfd) = 0;
1135
1136
  /* Point the bfd at the symbol table.  */
1137
1.47k
  obj_symbols (abfd) = vars.sym_cache;
1138
1.47k
  abfd->symcount = vars.sym_index;
1139
1140
1.47k
  obj_raw_syments (abfd) = vars.native_syms;
1141
1.47k
  obj_raw_syment_count (abfd) = vars.sym_index;
1142
1143
1.47k
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1144
1.47k
  obj_coff_keep_syms (abfd) = true;
1145
1146
1.47k
  obj_convert (abfd) = vars.sym_table;
1147
1.47k
  obj_conv_table_size (abfd) = vars.sym_index;
1148
1149
1.47k
  obj_coff_strings (abfd) = vars.string_table;
1150
1.47k
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1151
1.47k
  obj_coff_keep_strings (abfd) = true;
1152
1153
1.47k
  return true;
1154
1155
205
 error_return:
1156
205
  free (vars.bim->buffer);
1157
205
  free (vars.bim);
1158
205
  return false;
1159
1.47k
}
pei-aarch64.c:pe_ILF_build_a_bfd
Line
Count
Source
798
756
{
799
756
  bfd_byte *       ptr;
800
756
  pe_ILF_vars      vars;
801
756
  struct internal_filehdr  internal_f;
802
756
  unsigned int       import_type;
803
756
  unsigned int       import_name_type;
804
756
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
805
756
  coff_symbol_type **    imp_sym;
806
756
  unsigned int       imp_index;
807
756
  intptr_t alignment;
808
809
  /* Decode and verify the types field of the ILF structure.  */
810
756
  import_type = types & 0x3;
811
756
  import_name_type = (types & 0x1c) >> 2;
812
813
756
  switch (import_type)
814
756
    {
815
443
    case IMPORT_CODE:
816
548
    case IMPORT_DATA:
817
548
      break;
818
819
104
    case IMPORT_CONST:
820
      /* XXX code yet to be written.  */
821
      /* xgettext:c-format */
822
104
      _bfd_error_handler (_("%pB: unhandled import type; %x"),
823
104
        abfd, import_type);
824
104
      return false;
825
826
104
    default:
827
      /* xgettext:c-format */
828
104
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
104
        abfd, import_type);
830
104
      return false;
831
756
    }
832
833
548
  switch (import_name_type)
834
548
    {
835
341
    case IMPORT_ORDINAL:
836
443
    case IMPORT_NAME:
837
445
    case IMPORT_NAME_NOPREFIX:
838
446
    case IMPORT_NAME_UNDECORATE:
839
446
      break;
840
841
102
    default:
842
      /* xgettext:c-format */
843
102
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
844
102
        abfd, import_name_type);
845
102
      return false;
846
548
    }
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
446
  vars.bim
856
446
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
857
446
  if (vars.bim == NULL)
858
0
    return false;
859
860
446
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
861
446
  vars.bim->buffer = ptr;
862
446
  vars.bim->size   = ILF_DATA_SIZE;
863
446
  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
446
  vars.sym_cache = (coff_symbol_type *) ptr;
869
446
  vars.sym_ptr   = (coff_symbol_type *) ptr;
870
446
  vars.sym_index = 0;
871
446
  ptr += SIZEOF_ILF_SYMS;
872
873
446
  vars.sym_table = (unsigned int *) ptr;
874
446
  vars.table_ptr = (unsigned int *) ptr;
875
446
  ptr += SIZEOF_ILF_SYM_TABLE;
876
877
446
  vars.native_syms = (combined_entry_type *) ptr;
878
446
  vars.native_ptr  = (combined_entry_type *) ptr;
879
446
  ptr += SIZEOF_ILF_NATIVE_SYMS;
880
881
446
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
882
446
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
883
446
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
884
885
446
  vars.esym_table = (SYMENT *) ptr;
886
446
  vars.esym_ptr   = (SYMENT *) ptr;
887
446
  ptr += SIZEOF_ILF_EXT_SYMS;
888
889
446
  vars.reltab   = (arelent *) ptr;
890
446
  vars.relcount = 0;
891
446
  ptr += SIZEOF_ILF_RELOCS;
892
893
446
  vars.int_reltab  = (struct internal_reloc *) ptr;
894
446
  ptr += SIZEOF_ILF_INT_RELOCS;
895
896
446
  vars.string_table = (char *) ptr;
897
446
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
898
446
  ptr += SIZEOF_ILF_STRINGS;
899
446
  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
446
#if GCC_VERSION >= 3000
909
446
  alignment = __alignof__ (struct coff_section_tdata);
910
#else
911
  alignment = 8;
912
#endif
913
446
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
914
915
446
  vars.data = ptr;
916
446
  vars.abfd = abfd;
917
446
  vars.sec_index = 0;
918
446
  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
446
  id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
928
446
  id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
929
446
  if (id4 == NULL || id5 == NULL)
930
0
    goto error_return;
931
932
  /* Fill in the contents of these sections.  */
933
446
  if (import_name_type == IMPORT_ORDINAL)
934
341
    {
935
341
      if (ordinal == 0)
936
  /* See PR 20907 for a reproducer.  */
937
5
  goto error_return;
938
939
336
#if defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) || defined(COFF_WITH_peLoongArch64)
940
336
      ((unsigned int *) id4->contents)[0] = ordinal;
941
336
      ((unsigned int *) id4->contents)[1] = 0x80000000;
942
336
      ((unsigned int *) id5->contents)[0] = ordinal;
943
336
      ((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
336
    }
949
105
  else
950
105
    {
951
105
      char * symbol;
952
105
      unsigned int len;
953
954
      /* Create .idata$6 - the Hint Name Table.  */
955
105
      id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
956
105
      if (id6 == NULL)
957
0
  goto error_return;
958
959
      /* If necessary, trim the import symbol name.  */
960
105
      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
105
      if (import_name_type != IMPORT_NAME)
970
3
  {
971
3
    char c = symbol[0];
972
973
    /* Check that we don't remove for targets with empty
974
       USER_LABEL_PREFIX the leading underscore.  */
975
3
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
976
3
        || c == '@' || c == '?')
977
0
      symbol++;
978
3
  }
979
980
105
      len = strlen (symbol);
981
105
      if (import_name_type == IMPORT_NAME_UNDECORATE)
982
1
  {
983
    /* Truncate at the first '@'.  */
984
1
    char *at = strchr (symbol, '@');
985
986
1
    if (at != NULL)
987
0
      len = at - symbol;
988
1
  }
989
990
105
      id6->contents[0] = ordinal & 0xff;
991
105
      id6->contents[1] = ordinal >> 8;
992
993
105
      memcpy ((char *) id6->contents + 2, symbol, len);
994
105
      id6->contents[len + 2] = '\0';
995
105
    }
996
997
441
  if (import_name_type != IMPORT_ORDINAL)
998
105
    {
999
105
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1000
105
      pe_ILF_save_relocs (&vars, id4);
1001
1002
105
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1003
105
      pe_ILF_save_relocs (&vars, id5);
1004
105
    }
1005
1006
  /* Create an import symbol.  */
1007
441
  pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
1008
441
  imp_sym   = vars.sym_ptr_ptr - 1;
1009
441
  imp_index = vars.sym_index - 1;
1010
1011
  /* Create extra sections depending upon the type of import we are dealing with.  */
1012
441
  switch (import_type)
1013
441
    {
1014
0
      int i;
1015
1016
439
    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
878
      for (i = NUM_ENTRIES (jtab); i--;)
1021
878
  {
1022
878
    if (jtab[i].size == 0)
1023
439
      continue;
1024
439
    if (jtab[i].magic == magic)
1025
439
      break;
1026
439
  }
1027
      /* If we did not find a matching entry something is wrong.  */
1028
439
      if (i < 0)
1029
0
  abort ();
1030
1031
      /* Create the .text section.  */
1032
439
      text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
1033
439
      if (text == NULL)
1034
0
  goto error_return;
1035
1036
      /* Copy in the jump code.  */
1037
439
      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
439
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1063
439
            BFD_RELOC_32, (asymbol **) imp_sym,
1064
439
            imp_index);
1065
1066
439
      pe_ILF_save_relocs (& vars, text);
1067
439
      break;
1068
1069
2
    case IMPORT_DATA:
1070
2
      break;
1071
1072
0
    default:
1073
      /* XXX code not yet written.  */
1074
0
      abort ();
1075
441
    }
1076
1077
  /* Now create a symbol describing the imported value.  */
1078
441
  switch (import_type)
1079
441
    {
1080
439
    case IMPORT_CODE:
1081
439
      pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1082
439
          BSF_NOT_AT_END | BSF_FUNCTION);
1083
1084
439
      break;
1085
1086
2
    case IMPORT_DATA:
1087
      /* Nothing to do here.  */
1088
2
      break;
1089
1090
0
    default:
1091
      /* XXX code not yet written.  */
1092
0
      abort ();
1093
441
    }
1094
1095
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1096
441
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1097
441
  if (ptr)
1098
0
    * ptr = 0;
1099
441
  pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1100
441
  if (ptr)
1101
0
    * ptr = '.';
1102
1103
  /* Initialise the bfd.  */
1104
441
  memset (& internal_f, 0, sizeof (internal_f));
1105
1106
441
  internal_f.f_magic  = magic;
1107
441
  internal_f.f_symptr = 0;
1108
441
  internal_f.f_nsyms  = 0;
1109
441
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1110
1111
441
  if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
1112
441
      || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1113
0
    goto error_return;
1114
1115
441
  if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL)
1116
0
    goto error_return;
1117
1118
441
  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
441
  bfd_cache_close (abfd);
1127
1128
441
  abfd->iostream = (void *) vars.bim;
1129
441
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1130
441
  abfd->iovec = &_bfd_memory_iovec;
1131
441
  abfd->where = 0;
1132
441
  abfd->origin = 0;
1133
441
  abfd->size = 0;
1134
441
  obj_sym_filepos (abfd) = 0;
1135
1136
  /* Point the bfd at the symbol table.  */
1137
441
  obj_symbols (abfd) = vars.sym_cache;
1138
441
  abfd->symcount = vars.sym_index;
1139
1140
441
  obj_raw_syments (abfd) = vars.native_syms;
1141
441
  obj_raw_syment_count (abfd) = vars.sym_index;
1142
1143
441
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1144
441
  obj_coff_keep_syms (abfd) = true;
1145
1146
441
  obj_convert (abfd) = vars.sym_table;
1147
441
  obj_conv_table_size (abfd) = vars.sym_index;
1148
1149
441
  obj_coff_strings (abfd) = vars.string_table;
1150
441
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1151
441
  obj_coff_keep_strings (abfd) = true;
1152
1153
441
  return true;
1154
1155
5
 error_return:
1156
5
  free (vars.bim->buffer);
1157
5
  free (vars.bim);
1158
5
  return false;
1159
441
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_build_a_bfd
pei-loongarch64.c:pe_ILF_build_a_bfd
Line
Count
Source
798
1.98k
{
799
1.98k
  bfd_byte *       ptr;
800
1.98k
  pe_ILF_vars      vars;
801
1.98k
  struct internal_filehdr  internal_f;
802
1.98k
  unsigned int       import_type;
803
1.98k
  unsigned int       import_name_type;
804
1.98k
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
805
1.98k
  coff_symbol_type **    imp_sym;
806
1.98k
  unsigned int       imp_index;
807
1.98k
  intptr_t alignment;
808
809
  /* Decode and verify the types field of the ILF structure.  */
810
1.98k
  import_type = types & 0x3;
811
1.98k
  import_name_type = (types & 0x1c) >> 2;
812
813
1.98k
  switch (import_type)
814
1.98k
    {
815
1.10k
    case IMPORT_CODE:
816
1.78k
    case IMPORT_DATA:
817
1.78k
      break;
818
819
104
    case IMPORT_CONST:
820
      /* XXX code yet to be written.  */
821
      /* xgettext:c-format */
822
104
      _bfd_error_handler (_("%pB: unhandled import type; %x"),
823
104
        abfd, import_type);
824
104
      return false;
825
826
104
    default:
827
      /* xgettext:c-format */
828
104
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
104
        abfd, import_type);
830
104
      return false;
831
1.98k
    }
832
833
1.78k
  switch (import_name_type)
834
1.78k
    {
835
570
    case IMPORT_ORDINAL:
836
905
    case IMPORT_NAME:
837
907
    case IMPORT_NAME_NOPREFIX:
838
1.67k
    case IMPORT_NAME_UNDECORATE:
839
1.67k
      break;
840
841
104
    default:
842
      /* xgettext:c-format */
843
104
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
844
104
        abfd, import_name_type);
845
104
      return false;
846
1.78k
    }
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
1.67k
  vars.bim
856
1.67k
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
857
1.67k
  if (vars.bim == NULL)
858
0
    return false;
859
860
1.67k
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
861
1.67k
  vars.bim->buffer = ptr;
862
1.67k
  vars.bim->size   = ILF_DATA_SIZE;
863
1.67k
  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
1.67k
  vars.sym_cache = (coff_symbol_type *) ptr;
869
1.67k
  vars.sym_ptr   = (coff_symbol_type *) ptr;
870
1.67k
  vars.sym_index = 0;
871
1.67k
  ptr += SIZEOF_ILF_SYMS;
872
873
1.67k
  vars.sym_table = (unsigned int *) ptr;
874
1.67k
  vars.table_ptr = (unsigned int *) ptr;
875
1.67k
  ptr += SIZEOF_ILF_SYM_TABLE;
876
877
1.67k
  vars.native_syms = (combined_entry_type *) ptr;
878
1.67k
  vars.native_ptr  = (combined_entry_type *) ptr;
879
1.67k
  ptr += SIZEOF_ILF_NATIVE_SYMS;
880
881
1.67k
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
882
1.67k
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
883
1.67k
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
884
885
1.67k
  vars.esym_table = (SYMENT *) ptr;
886
1.67k
  vars.esym_ptr   = (SYMENT *) ptr;
887
1.67k
  ptr += SIZEOF_ILF_EXT_SYMS;
888
889
1.67k
  vars.reltab   = (arelent *) ptr;
890
1.67k
  vars.relcount = 0;
891
1.67k
  ptr += SIZEOF_ILF_RELOCS;
892
893
1.67k
  vars.int_reltab  = (struct internal_reloc *) ptr;
894
1.67k
  ptr += SIZEOF_ILF_INT_RELOCS;
895
896
1.67k
  vars.string_table = (char *) ptr;
897
1.67k
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
898
1.67k
  ptr += SIZEOF_ILF_STRINGS;
899
1.67k
  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
1.67k
#if GCC_VERSION >= 3000
909
1.67k
  alignment = __alignof__ (struct coff_section_tdata);
910
#else
911
  alignment = 8;
912
#endif
913
1.67k
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
914
915
1.67k
  vars.data = ptr;
916
1.67k
  vars.abfd = abfd;
917
1.67k
  vars.sec_index = 0;
918
1.67k
  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
1.67k
  id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
928
1.67k
  id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
929
1.67k
  if (id4 == NULL || id5 == NULL)
930
0
    goto error_return;
931
932
  /* Fill in the contents of these sections.  */
933
1.67k
  if (import_name_type == IMPORT_ORDINAL)
934
570
    {
935
570
      if (ordinal == 0)
936
  /* See PR 20907 for a reproducer.  */
937
2
  goto error_return;
938
939
568
#if defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) || defined(COFF_WITH_peLoongArch64)
940
568
      ((unsigned int *) id4->contents)[0] = ordinal;
941
568
      ((unsigned int *) id4->contents)[1] = 0x80000000;
942
568
      ((unsigned int *) id5->contents)[0] = ordinal;
943
568
      ((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
568
    }
949
1.10k
  else
950
1.10k
    {
951
1.10k
      char * symbol;
952
1.10k
      unsigned int len;
953
954
      /* Create .idata$6 - the Hint Name Table.  */
955
1.10k
      id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
956
1.10k
      if (id6 == NULL)
957
0
  goto error_return;
958
959
      /* If necessary, trim the import symbol name.  */
960
1.10k
      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.10k
      if (import_name_type != IMPORT_NAME)
970
771
  {
971
771
    char c = symbol[0];
972
973
    /* Check that we don't remove for targets with empty
974
       USER_LABEL_PREFIX the leading underscore.  */
975
771
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
976
771
        || c == '@' || c == '?')
977
0
      symbol++;
978
771
  }
979
980
1.10k
      len = strlen (symbol);
981
1.10k
      if (import_name_type == IMPORT_NAME_UNDECORATE)
982
769
  {
983
    /* Truncate at the first '@'.  */
984
769
    char *at = strchr (symbol, '@');
985
986
769
    if (at != NULL)
987
435
      len = at - symbol;
988
769
  }
989
990
1.10k
      id6->contents[0] = ordinal & 0xff;
991
1.10k
      id6->contents[1] = ordinal >> 8;
992
993
1.10k
      memcpy ((char *) id6->contents + 2, symbol, len);
994
1.10k
      id6->contents[len + 2] = '\0';
995
1.10k
    }
996
997
1.67k
  if (import_name_type != IMPORT_ORDINAL)
998
1.10k
    {
999
1.10k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1000
1.10k
      pe_ILF_save_relocs (&vars, id4);
1001
1002
1.10k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1003
1.10k
      pe_ILF_save_relocs (&vars, id5);
1004
1.10k
    }
1005
1006
  /* Create an import symbol.  */
1007
1.67k
  pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
1008
1.67k
  imp_sym   = vars.sym_ptr_ptr - 1;
1009
1.67k
  imp_index = vars.sym_index - 1;
1010
1011
  /* Create extra sections depending upon the type of import we are dealing with.  */
1012
1.67k
  switch (import_type)
1013
1.67k
    {
1014
0
      int i;
1015
1016
1.00k
    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.00k
      for (i = NUM_ENTRIES (jtab); i--;)
1021
2.00k
  {
1022
2.00k
    if (jtab[i].size == 0)
1023
1.00k
      continue;
1024
1.00k
    if (jtab[i].magic == magic)
1025
1.00k
      break;
1026
1.00k
  }
1027
      /* If we did not find a matching entry something is wrong.  */
1028
1.00k
      if (i < 0)
1029
0
  abort ();
1030
1031
      /* Create the .text section.  */
1032
1.00k
      text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
1033
1.00k
      if (text == NULL)
1034
0
  goto error_return;
1035
1036
      /* Copy in the jump code.  */
1037
1.00k
      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.00k
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1063
1.00k
            BFD_RELOC_32, (asymbol **) imp_sym,
1064
1.00k
            imp_index);
1065
1066
1.00k
      pe_ILF_save_relocs (& vars, text);
1067
1.00k
      break;
1068
1069
670
    case IMPORT_DATA:
1070
670
      break;
1071
1072
0
    default:
1073
      /* XXX code not yet written.  */
1074
0
      abort ();
1075
1.67k
    }
1076
1077
  /* Now create a symbol describing the imported value.  */
1078
1.67k
  switch (import_type)
1079
1.67k
    {
1080
1.00k
    case IMPORT_CODE:
1081
1.00k
      pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1082
1.00k
          BSF_NOT_AT_END | BSF_FUNCTION);
1083
1084
1.00k
      break;
1085
1086
670
    case IMPORT_DATA:
1087
      /* Nothing to do here.  */
1088
670
      break;
1089
1090
0
    default:
1091
      /* XXX code not yet written.  */
1092
0
      abort ();
1093
1.67k
    }
1094
1095
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1096
1.67k
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1097
1.67k
  if (ptr)
1098
335
    * ptr = 0;
1099
1.67k
  pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1100
1.67k
  if (ptr)
1101
335
    * ptr = '.';
1102
1103
  /* Initialise the bfd.  */
1104
1.67k
  memset (& internal_f, 0, sizeof (internal_f));
1105
1106
1.67k
  internal_f.f_magic  = magic;
1107
1.67k
  internal_f.f_symptr = 0;
1108
1.67k
  internal_f.f_nsyms  = 0;
1109
1.67k
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1110
1111
1.67k
  if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
1112
1.67k
      || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1113
0
    goto error_return;
1114
1115
1.67k
  if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL)
1116
0
    goto error_return;
1117
1118
1.67k
  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
1.67k
  bfd_cache_close (abfd);
1127
1128
1.67k
  abfd->iostream = (void *) vars.bim;
1129
1.67k
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1130
1.67k
  abfd->iovec = &_bfd_memory_iovec;
1131
1.67k
  abfd->where = 0;
1132
1.67k
  abfd->origin = 0;
1133
1.67k
  abfd->size = 0;
1134
1.67k
  obj_sym_filepos (abfd) = 0;
1135
1136
  /* Point the bfd at the symbol table.  */
1137
1.67k
  obj_symbols (abfd) = vars.sym_cache;
1138
1.67k
  abfd->symcount = vars.sym_index;
1139
1140
1.67k
  obj_raw_syments (abfd) = vars.native_syms;
1141
1.67k
  obj_raw_syment_count (abfd) = vars.sym_index;
1142
1143
1.67k
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1144
1.67k
  obj_coff_keep_syms (abfd) = true;
1145
1146
1.67k
  obj_convert (abfd) = vars.sym_table;
1147
1.67k
  obj_conv_table_size (abfd) = vars.sym_index;
1148
1149
1.67k
  obj_coff_strings (abfd) = vars.string_table;
1150
1.67k
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1151
1.67k
  obj_coff_keep_strings (abfd) = true;
1152
1153
1.67k
  return true;
1154
1155
2
 error_return:
1156
2
  free (vars.bim->buffer);
1157
2
  free (vars.bim);
1158
2
  return false;
1159
1.67k
}
pei-arm-wince.c:pe_ILF_build_a_bfd
Line
Count
Source
798
426
{
799
426
  bfd_byte *       ptr;
800
426
  pe_ILF_vars      vars;
801
426
  struct internal_filehdr  internal_f;
802
426
  unsigned int       import_type;
803
426
  unsigned int       import_name_type;
804
426
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
805
426
  coff_symbol_type **    imp_sym;
806
426
  unsigned int       imp_index;
807
426
  intptr_t alignment;
808
809
  /* Decode and verify the types field of the ILF structure.  */
810
426
  import_type = types & 0x3;
811
426
  import_name_type = (types & 0x1c) >> 2;
812
813
426
  switch (import_type)
814
426
    {
815
110
    case IMPORT_CODE:
816
218
    case IMPORT_DATA:
817
218
      break;
818
819
104
    case IMPORT_CONST:
820
      /* XXX code yet to be written.  */
821
      /* xgettext:c-format */
822
104
      _bfd_error_handler (_("%pB: unhandled import type; %x"),
823
104
        abfd, import_type);
824
104
      return false;
825
826
104
    default:
827
      /* xgettext:c-format */
828
104
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
104
        abfd, import_type);
830
104
      return false;
831
426
    }
832
833
218
  switch (import_name_type)
834
218
    {
835
106
    case IMPORT_ORDINAL:
836
108
    case IMPORT_NAME:
837
111
    case IMPORT_NAME_NOPREFIX:
838
112
    case IMPORT_NAME_UNDECORATE:
839
112
      break;
840
841
106
    default:
842
      /* xgettext:c-format */
843
106
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
844
106
        abfd, import_name_type);
845
106
      return false;
846
218
    }
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
112
  vars.bim
856
112
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
857
112
  if (vars.bim == NULL)
858
0
    return false;
859
860
112
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
861
112
  vars.bim->buffer = ptr;
862
112
  vars.bim->size   = ILF_DATA_SIZE;
863
112
  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
112
  vars.sym_cache = (coff_symbol_type *) ptr;
869
112
  vars.sym_ptr   = (coff_symbol_type *) ptr;
870
112
  vars.sym_index = 0;
871
112
  ptr += SIZEOF_ILF_SYMS;
872
873
112
  vars.sym_table = (unsigned int *) ptr;
874
112
  vars.table_ptr = (unsigned int *) ptr;
875
112
  ptr += SIZEOF_ILF_SYM_TABLE;
876
877
112
  vars.native_syms = (combined_entry_type *) ptr;
878
112
  vars.native_ptr  = (combined_entry_type *) ptr;
879
112
  ptr += SIZEOF_ILF_NATIVE_SYMS;
880
881
112
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
882
112
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
883
112
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
884
885
112
  vars.esym_table = (SYMENT *) ptr;
886
112
  vars.esym_ptr   = (SYMENT *) ptr;
887
112
  ptr += SIZEOF_ILF_EXT_SYMS;
888
889
112
  vars.reltab   = (arelent *) ptr;
890
112
  vars.relcount = 0;
891
112
  ptr += SIZEOF_ILF_RELOCS;
892
893
112
  vars.int_reltab  = (struct internal_reloc *) ptr;
894
112
  ptr += SIZEOF_ILF_INT_RELOCS;
895
896
112
  vars.string_table = (char *) ptr;
897
112
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
898
112
  ptr += SIZEOF_ILF_STRINGS;
899
112
  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
112
#if GCC_VERSION >= 3000
909
112
  alignment = __alignof__ (struct coff_section_tdata);
910
#else
911
  alignment = 8;
912
#endif
913
112
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
914
915
112
  vars.data = ptr;
916
112
  vars.abfd = abfd;
917
112
  vars.sec_index = 0;
918
112
  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
112
  id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
928
112
  id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
929
112
  if (id4 == NULL || id5 == NULL)
930
0
    goto error_return;
931
932
  /* Fill in the contents of these sections.  */
933
112
  if (import_name_type == IMPORT_ORDINAL)
934
106
    {
935
106
      if (ordinal == 0)
936
  /* See PR 20907 for a reproducer.  */
937
104
  goto error_return;
938
939
#if defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) || defined(COFF_WITH_peLoongArch64)
940
      ((unsigned int *) id4->contents)[0] = ordinal;
941
      ((unsigned int *) id4->contents)[1] = 0x80000000;
942
      ((unsigned int *) id5->contents)[0] = ordinal;
943
      ((unsigned int *) id5->contents)[1] = 0x80000000;
944
#else
945
2
      * (unsigned int *) id4->contents = ordinal | 0x80000000;
946
2
      * (unsigned int *) id5->contents = ordinal | 0x80000000;
947
2
#endif
948
2
    }
949
6
  else
950
6
    {
951
6
      char * symbol;
952
6
      unsigned int len;
953
954
      /* Create .idata$6 - the Hint Name Table.  */
955
6
      id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
956
6
      if (id6 == NULL)
957
0
  goto error_return;
958
959
      /* If necessary, trim the import symbol name.  */
960
6
      symbol = symbol_name;
961
962
      /* As used by MS compiler, '_', '@', and '?' are alternative
963
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
964
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
965
   of these is used for a symbol.  We strip this leading char for
966
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
967
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
968
969
6
      if (import_name_type != IMPORT_NAME)
970
4
  {
971
4
    char c = symbol[0];
972
973
    /* Check that we don't remove for targets with empty
974
       USER_LABEL_PREFIX the leading underscore.  */
975
4
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
976
4
        || c == '@' || c == '?')
977
0
      symbol++;
978
4
  }
979
980
6
      len = strlen (symbol);
981
6
      if (import_name_type == IMPORT_NAME_UNDECORATE)
982
1
  {
983
    /* Truncate at the first '@'.  */
984
1
    char *at = strchr (symbol, '@');
985
986
1
    if (at != NULL)
987
0
      len = at - symbol;
988
1
  }
989
990
6
      id6->contents[0] = ordinal & 0xff;
991
6
      id6->contents[1] = ordinal >> 8;
992
993
6
      memcpy ((char *) id6->contents + 2, symbol, len);
994
6
      id6->contents[len + 2] = '\0';
995
6
    }
996
997
8
  if (import_name_type != IMPORT_ORDINAL)
998
6
    {
999
6
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1000
6
      pe_ILF_save_relocs (&vars, id4);
1001
1002
6
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1003
6
      pe_ILF_save_relocs (&vars, id5);
1004
6
    }
1005
1006
  /* Create an import symbol.  */
1007
8
  pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
1008
8
  imp_sym   = vars.sym_ptr_ptr - 1;
1009
8
  imp_index = vars.sym_index - 1;
1010
1011
  /* Create extra sections depending upon the type of import we are dealing with.  */
1012
8
  switch (import_type)
1013
8
    {
1014
0
      int i;
1015
1016
4
    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
11
      for (i = NUM_ENTRIES (jtab); i--;)
1021
11
  {
1022
11
    if (jtab[i].size == 0)
1023
4
      continue;
1024
7
    if (jtab[i].magic == magic)
1025
4
      break;
1026
7
  }
1027
      /* If we did not find a matching entry something is wrong.  */
1028
4
      if (i < 0)
1029
0
  abort ();
1030
1031
      /* Create the .text section.  */
1032
4
      text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
1033
4
      if (text == NULL)
1034
0
  goto error_return;
1035
1036
      /* Copy in the jump code.  */
1037
4
      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
4
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1063
4
            BFD_RELOC_32, (asymbol **) imp_sym,
1064
4
            imp_index);
1065
1066
4
      pe_ILF_save_relocs (& vars, text);
1067
4
      break;
1068
1069
4
    case IMPORT_DATA:
1070
4
      break;
1071
1072
0
    default:
1073
      /* XXX code not yet written.  */
1074
0
      abort ();
1075
8
    }
1076
1077
  /* Now create a symbol describing the imported value.  */
1078
8
  switch (import_type)
1079
8
    {
1080
4
    case IMPORT_CODE:
1081
4
      pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1082
4
          BSF_NOT_AT_END | BSF_FUNCTION);
1083
1084
4
      break;
1085
1086
4
    case IMPORT_DATA:
1087
      /* Nothing to do here.  */
1088
4
      break;
1089
1090
0
    default:
1091
      /* XXX code not yet written.  */
1092
0
      abort ();
1093
8
    }
1094
1095
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1096
8
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1097
8
  if (ptr)
1098
4
    * ptr = 0;
1099
8
  pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1100
8
  if (ptr)
1101
4
    * ptr = '.';
1102
1103
  /* Initialise the bfd.  */
1104
8
  memset (& internal_f, 0, sizeof (internal_f));
1105
1106
8
  internal_f.f_magic  = magic;
1107
8
  internal_f.f_symptr = 0;
1108
8
  internal_f.f_nsyms  = 0;
1109
8
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1110
1111
8
  if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
1112
8
      || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1113
0
    goto error_return;
1114
1115
8
  if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL)
1116
0
    goto error_return;
1117
1118
8
  obj_pe (abfd) = true;
1119
8
#ifdef THUMBPEMAGIC
1120
8
  if (vars.magic == THUMBPEMAGIC)
1121
    /* Stop some linker warnings about thumb code not supporting interworking.  */
1122
4
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1123
8
#endif
1124
1125
  /* Switch from file contents to memory contents.  */
1126
8
  bfd_cache_close (abfd);
1127
1128
8
  abfd->iostream = (void *) vars.bim;
1129
8
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1130
8
  abfd->iovec = &_bfd_memory_iovec;
1131
8
  abfd->where = 0;
1132
8
  abfd->origin = 0;
1133
8
  abfd->size = 0;
1134
8
  obj_sym_filepos (abfd) = 0;
1135
1136
  /* Point the bfd at the symbol table.  */
1137
8
  obj_symbols (abfd) = vars.sym_cache;
1138
8
  abfd->symcount = vars.sym_index;
1139
1140
8
  obj_raw_syments (abfd) = vars.native_syms;
1141
8
  obj_raw_syment_count (abfd) = vars.sym_index;
1142
1143
8
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1144
8
  obj_coff_keep_syms (abfd) = true;
1145
1146
8
  obj_convert (abfd) = vars.sym_table;
1147
8
  obj_conv_table_size (abfd) = vars.sym_index;
1148
1149
8
  obj_coff_strings (abfd) = vars.string_table;
1150
8
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1151
8
  obj_coff_keep_strings (abfd) = true;
1152
1153
8
  return true;
1154
1155
104
 error_return:
1156
104
  free (vars.bim->buffer);
1157
104
  free (vars.bim);
1158
104
  return false;
1159
8
}
pei-arm.c:pe_ILF_build_a_bfd
Line
Count
Source
798
2.17k
{
799
2.17k
  bfd_byte *       ptr;
800
2.17k
  pe_ILF_vars      vars;
801
2.17k
  struct internal_filehdr  internal_f;
802
2.17k
  unsigned int       import_type;
803
2.17k
  unsigned int       import_name_type;
804
2.17k
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
805
2.17k
  coff_symbol_type **    imp_sym;
806
2.17k
  unsigned int       imp_index;
807
2.17k
  intptr_t alignment;
808
809
  /* Decode and verify the types field of the ILF structure.  */
810
2.17k
  import_type = types & 0x3;
811
2.17k
  import_name_type = (types & 0x1c) >> 2;
812
813
2.17k
  switch (import_type)
814
2.17k
    {
815
1.13k
    case IMPORT_CODE:
816
1.96k
    case IMPORT_DATA:
817
1.96k
      break;
818
819
104
    case IMPORT_CONST:
820
      /* XXX code yet to be written.  */
821
      /* xgettext:c-format */
822
104
      _bfd_error_handler (_("%pB: unhandled import type; %x"),
823
104
        abfd, import_type);
824
104
      return false;
825
826
104
    default:
827
      /* xgettext:c-format */
828
104
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
104
        abfd, import_type);
830
104
      return false;
831
2.17k
    }
832
833
1.96k
  switch (import_name_type)
834
1.96k
    {
835
671
    case IMPORT_ORDINAL:
836
1.13k
    case IMPORT_NAME:
837
1.63k
    case IMPORT_NAME_NOPREFIX:
838
1.86k
    case IMPORT_NAME_UNDECORATE:
839
1.86k
      break;
840
841
106
    default:
842
      /* xgettext:c-format */
843
106
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
844
106
        abfd, import_name_type);
845
106
      return false;
846
1.96k
    }
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
1.86k
  vars.bim
856
1.86k
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
857
1.86k
  if (vars.bim == NULL)
858
0
    return false;
859
860
1.86k
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
861
1.86k
  vars.bim->buffer = ptr;
862
1.86k
  vars.bim->size   = ILF_DATA_SIZE;
863
1.86k
  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
1.86k
  vars.sym_cache = (coff_symbol_type *) ptr;
869
1.86k
  vars.sym_ptr   = (coff_symbol_type *) ptr;
870
1.86k
  vars.sym_index = 0;
871
1.86k
  ptr += SIZEOF_ILF_SYMS;
872
873
1.86k
  vars.sym_table = (unsigned int *) ptr;
874
1.86k
  vars.table_ptr = (unsigned int *) ptr;
875
1.86k
  ptr += SIZEOF_ILF_SYM_TABLE;
876
877
1.86k
  vars.native_syms = (combined_entry_type *) ptr;
878
1.86k
  vars.native_ptr  = (combined_entry_type *) ptr;
879
1.86k
  ptr += SIZEOF_ILF_NATIVE_SYMS;
880
881
1.86k
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
882
1.86k
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
883
1.86k
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
884
885
1.86k
  vars.esym_table = (SYMENT *) ptr;
886
1.86k
  vars.esym_ptr   = (SYMENT *) ptr;
887
1.86k
  ptr += SIZEOF_ILF_EXT_SYMS;
888
889
1.86k
  vars.reltab   = (arelent *) ptr;
890
1.86k
  vars.relcount = 0;
891
1.86k
  ptr += SIZEOF_ILF_RELOCS;
892
893
1.86k
  vars.int_reltab  = (struct internal_reloc *) ptr;
894
1.86k
  ptr += SIZEOF_ILF_INT_RELOCS;
895
896
1.86k
  vars.string_table = (char *) ptr;
897
1.86k
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
898
1.86k
  ptr += SIZEOF_ILF_STRINGS;
899
1.86k
  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
1.86k
#if GCC_VERSION >= 3000
909
1.86k
  alignment = __alignof__ (struct coff_section_tdata);
910
#else
911
  alignment = 8;
912
#endif
913
1.86k
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
914
915
1.86k
  vars.data = ptr;
916
1.86k
  vars.abfd = abfd;
917
1.86k
  vars.sec_index = 0;
918
1.86k
  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
1.86k
  id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
928
1.86k
  id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
929
1.86k
  if (id4 == NULL || id5 == NULL)
930
0
    goto error_return;
931
932
  /* Fill in the contents of these sections.  */
933
1.86k
  if (import_name_type == IMPORT_ORDINAL)
934
671
    {
935
671
      if (ordinal == 0)
936
  /* See PR 20907 for a reproducer.  */
937
104
  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
567
      * (unsigned int *) id4->contents = ordinal | 0x80000000;
946
567
      * (unsigned int *) id5->contents = ordinal | 0x80000000;
947
567
#endif
948
567
    }
949
1.19k
  else
950
1.19k
    {
951
1.19k
      char * symbol;
952
1.19k
      unsigned int len;
953
954
      /* Create .idata$6 - the Hint Name Table.  */
955
1.19k
      id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
956
1.19k
      if (id6 == NULL)
957
0
  goto error_return;
958
959
      /* If necessary, trim the import symbol name.  */
960
1.19k
      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.19k
      if (import_name_type != IMPORT_NAME)
970
727
  {
971
727
    char c = symbol[0];
972
973
    /* Check that we don't remove for targets with empty
974
       USER_LABEL_PREFIX the leading underscore.  */
975
727
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
976
727
        || c == '@' || c == '?')
977
0
      symbol++;
978
727
  }
979
980
1.19k
      len = strlen (symbol);
981
1.19k
      if (import_name_type == IMPORT_NAME_UNDECORATE)
982
232
  {
983
    /* Truncate at the first '@'.  */
984
232
    char *at = strchr (symbol, '@');
985
986
232
    if (at != NULL)
987
0
      len = at - symbol;
988
232
  }
989
990
1.19k
      id6->contents[0] = ordinal & 0xff;
991
1.19k
      id6->contents[1] = ordinal >> 8;
992
993
1.19k
      memcpy ((char *) id6->contents + 2, symbol, len);
994
1.19k
      id6->contents[len + 2] = '\0';
995
1.19k
    }
996
997
1.75k
  if (import_name_type != IMPORT_ORDINAL)
998
1.19k
    {
999
1.19k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1000
1.19k
      pe_ILF_save_relocs (&vars, id4);
1001
1002
1.19k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1003
1.19k
      pe_ILF_save_relocs (&vars, id5);
1004
1.19k
    }
1005
1006
  /* Create an import symbol.  */
1007
1.75k
  pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
1008
1.75k
  imp_sym   = vars.sym_ptr_ptr - 1;
1009
1.75k
  imp_index = vars.sym_index - 1;
1010
1011
  /* Create extra sections depending upon the type of import we are dealing with.  */
1012
1.75k
  switch (import_type)
1013
1.75k
    {
1014
0
      int i;
1015
1016
1.03k
    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.86k
      for (i = NUM_ENTRIES (jtab); i--;)
1021
2.86k
  {
1022
2.86k
    if (jtab[i].size == 0)
1023
1.03k
      continue;
1024
1.82k
    if (jtab[i].magic == magic)
1025
1.03k
      break;
1026
1.82k
  }
1027
      /* If we did not find a matching entry something is wrong.  */
1028
1.03k
      if (i < 0)
1029
0
  abort ();
1030
1031
      /* Create the .text section.  */
1032
1.03k
      text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
1033
1.03k
      if (text == NULL)
1034
0
  goto error_return;
1035
1036
      /* Copy in the jump code.  */
1037
1.03k
      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.03k
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1063
1.03k
            BFD_RELOC_32, (asymbol **) imp_sym,
1064
1.03k
            imp_index);
1065
1066
1.03k
      pe_ILF_save_relocs (& vars, text);
1067
1.03k
      break;
1068
1069
726
    case IMPORT_DATA:
1070
726
      break;
1071
1072
0
    default:
1073
      /* XXX code not yet written.  */
1074
0
      abort ();
1075
1.75k
    }
1076
1077
  /* Now create a symbol describing the imported value.  */
1078
1.75k
  switch (import_type)
1079
1.75k
    {
1080
1.03k
    case IMPORT_CODE:
1081
1.03k
      pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1082
1.03k
          BSF_NOT_AT_END | BSF_FUNCTION);
1083
1084
1.03k
      break;
1085
1086
726
    case IMPORT_DATA:
1087
      /* Nothing to do here.  */
1088
726
      break;
1089
1090
0
    default:
1091
      /* XXX code not yet written.  */
1092
0
      abort ();
1093
1.75k
    }
1094
1095
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1096
1.75k
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1097
1.75k
  if (ptr)
1098
724
    * ptr = 0;
1099
1.75k
  pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1100
1.75k
  if (ptr)
1101
724
    * ptr = '.';
1102
1103
  /* Initialise the bfd.  */
1104
1.75k
  memset (& internal_f, 0, sizeof (internal_f));
1105
1106
1.75k
  internal_f.f_magic  = magic;
1107
1.75k
  internal_f.f_symptr = 0;
1108
1.75k
  internal_f.f_nsyms  = 0;
1109
1.75k
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1110
1111
1.75k
  if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
1112
1.75k
      || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1113
0
    goto error_return;
1114
1115
1.75k
  if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL)
1116
0
    goto error_return;
1117
1118
1.75k
  obj_pe (abfd) = true;
1119
1.75k
#ifdef THUMBPEMAGIC
1120
1.75k
  if (vars.magic == THUMBPEMAGIC)
1121
    /* Stop some linker warnings about thumb code not supporting interworking.  */
1122
729
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1123
1.75k
#endif
1124
1125
  /* Switch from file contents to memory contents.  */
1126
1.75k
  bfd_cache_close (abfd);
1127
1128
1.75k
  abfd->iostream = (void *) vars.bim;
1129
1.75k
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1130
1.75k
  abfd->iovec = &_bfd_memory_iovec;
1131
1.75k
  abfd->where = 0;
1132
1.75k
  abfd->origin = 0;
1133
1.75k
  abfd->size = 0;
1134
1.75k
  obj_sym_filepos (abfd) = 0;
1135
1136
  /* Point the bfd at the symbol table.  */
1137
1.75k
  obj_symbols (abfd) = vars.sym_cache;
1138
1.75k
  abfd->symcount = vars.sym_index;
1139
1140
1.75k
  obj_raw_syments (abfd) = vars.native_syms;
1141
1.75k
  obj_raw_syment_count (abfd) = vars.sym_index;
1142
1143
1.75k
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1144
1.75k
  obj_coff_keep_syms (abfd) = true;
1145
1146
1.75k
  obj_convert (abfd) = vars.sym_table;
1147
1.75k
  obj_conv_table_size (abfd) = vars.sym_index;
1148
1149
1.75k
  obj_coff_strings (abfd) = vars.string_table;
1150
1.75k
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1151
1.75k
  obj_coff_keep_strings (abfd) = true;
1152
1153
1.75k
  return true;
1154
1155
104
 error_return:
1156
104
  free (vars.bim->buffer);
1157
104
  free (vars.bim);
1158
104
  return false;
1159
1.75k
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_build_a_bfd
pei-sh.c:pe_ILF_build_a_bfd
Line
Count
Source
798
1.34k
{
799
1.34k
  bfd_byte *       ptr;
800
1.34k
  pe_ILF_vars      vars;
801
1.34k
  struct internal_filehdr  internal_f;
802
1.34k
  unsigned int       import_type;
803
1.34k
  unsigned int       import_name_type;
804
1.34k
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
805
1.34k
  coff_symbol_type **    imp_sym;
806
1.34k
  unsigned int       imp_index;
807
1.34k
  intptr_t alignment;
808
809
  /* Decode and verify the types field of the ILF structure.  */
810
1.34k
  import_type = types & 0x3;
811
1.34k
  import_name_type = (types & 0x1c) >> 2;
812
813
1.34k
  switch (import_type)
814
1.34k
    {
815
775
    case IMPORT_CODE:
816
1.24k
    case IMPORT_DATA:
817
1.24k
      break;
818
819
104
    case IMPORT_CONST:
820
      /* XXX code yet to be written.  */
821
      /* xgettext:c-format */
822
104
      _bfd_error_handler (_("%pB: unhandled import type; %x"),
823
104
        abfd, import_type);
824
104
      return false;
825
826
1
    default:
827
      /* xgettext:c-format */
828
1
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
1
        abfd, import_type);
830
1
      return false;
831
1.34k
    }
832
833
1.24k
  switch (import_name_type)
834
1.24k
    {
835
205
    case IMPORT_ORDINAL:
836
671
    case IMPORT_NAME:
837
1.13k
    case IMPORT_NAME_NOPREFIX:
838
1.13k
    case IMPORT_NAME_UNDECORATE:
839
1.13k
      break;
840
841
104
    default:
842
      /* xgettext:c-format */
843
104
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
844
104
        abfd, import_name_type);
845
104
      return false;
846
1.24k
    }
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
1.13k
  vars.bim
856
1.13k
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
857
1.13k
  if (vars.bim == NULL)
858
0
    return false;
859
860
1.13k
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
861
1.13k
  vars.bim->buffer = ptr;
862
1.13k
  vars.bim->size   = ILF_DATA_SIZE;
863
1.13k
  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
1.13k
  vars.sym_cache = (coff_symbol_type *) ptr;
869
1.13k
  vars.sym_ptr   = (coff_symbol_type *) ptr;
870
1.13k
  vars.sym_index = 0;
871
1.13k
  ptr += SIZEOF_ILF_SYMS;
872
873
1.13k
  vars.sym_table = (unsigned int *) ptr;
874
1.13k
  vars.table_ptr = (unsigned int *) ptr;
875
1.13k
  ptr += SIZEOF_ILF_SYM_TABLE;
876
877
1.13k
  vars.native_syms = (combined_entry_type *) ptr;
878
1.13k
  vars.native_ptr  = (combined_entry_type *) ptr;
879
1.13k
  ptr += SIZEOF_ILF_NATIVE_SYMS;
880
881
1.13k
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
882
1.13k
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
883
1.13k
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
884
885
1.13k
  vars.esym_table = (SYMENT *) ptr;
886
1.13k
  vars.esym_ptr   = (SYMENT *) ptr;
887
1.13k
  ptr += SIZEOF_ILF_EXT_SYMS;
888
889
1.13k
  vars.reltab   = (arelent *) ptr;
890
1.13k
  vars.relcount = 0;
891
1.13k
  ptr += SIZEOF_ILF_RELOCS;
892
893
1.13k
  vars.int_reltab  = (struct internal_reloc *) ptr;
894
1.13k
  ptr += SIZEOF_ILF_INT_RELOCS;
895
896
1.13k
  vars.string_table = (char *) ptr;
897
1.13k
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
898
1.13k
  ptr += SIZEOF_ILF_STRINGS;
899
1.13k
  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
1.13k
#if GCC_VERSION >= 3000
909
1.13k
  alignment = __alignof__ (struct coff_section_tdata);
910
#else
911
  alignment = 8;
912
#endif
913
1.13k
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
914
915
1.13k
  vars.data = ptr;
916
1.13k
  vars.abfd = abfd;
917
1.13k
  vars.sec_index = 0;
918
1.13k
  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
1.13k
  id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
928
1.13k
  id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
929
1.13k
  if (id4 == NULL || id5 == NULL)
930
0
    goto error_return;
931
932
  /* Fill in the contents of these sections.  */
933
1.13k
  if (import_name_type == IMPORT_ORDINAL)
934
205
    {
935
205
      if (ordinal == 0)
936
  /* See PR 20907 for a reproducer.  */
937
102
  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
103
      * (unsigned int *) id4->contents = ordinal | 0x80000000;
946
103
      * (unsigned int *) id5->contents = ordinal | 0x80000000;
947
103
#endif
948
103
    }
949
934
  else
950
934
    {
951
934
      char * symbol;
952
934
      unsigned int len;
953
954
      /* Create .idata$6 - the Hint Name Table.  */
955
934
      id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
956
934
      if (id6 == NULL)
957
0
  goto error_return;
958
959
      /* If necessary, trim the import symbol name.  */
960
934
      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
934
      if (import_name_type != IMPORT_NAME)
970
468
  {
971
468
    char c = symbol[0];
972
973
    /* Check that we don't remove for targets with empty
974
       USER_LABEL_PREFIX the leading underscore.  */
975
468
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
976
468
        || c == '@' || c == '?')
977
0
      symbol++;
978
468
  }
979
980
934
      len = strlen (symbol);
981
934
      if (import_name_type == IMPORT_NAME_UNDECORATE)
982
1
  {
983
    /* Truncate at the first '@'.  */
984
1
    char *at = strchr (symbol, '@');
985
986
1
    if (at != NULL)
987
0
      len = at - symbol;
988
1
  }
989
990
934
      id6->contents[0] = ordinal & 0xff;
991
934
      id6->contents[1] = ordinal >> 8;
992
993
934
      memcpy ((char *) id6->contents + 2, symbol, len);
994
934
      id6->contents[len + 2] = '\0';
995
934
    }
996
997
1.03k
  if (import_name_type != IMPORT_ORDINAL)
998
934
    {
999
934
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1000
934
      pe_ILF_save_relocs (&vars, id4);
1001
1002
934
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1003
934
      pe_ILF_save_relocs (&vars, id5);
1004
934
    }
1005
1006
  /* Create an import symbol.  */
1007
1.03k
  pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
1008
1.03k
  imp_sym   = vars.sym_ptr_ptr - 1;
1009
1.03k
  imp_index = vars.sym_index - 1;
1010
1011
  /* Create extra sections depending upon the type of import we are dealing with.  */
1012
1.03k
  switch (import_type)
1013
1.03k
    {
1014
0
      int i;
1015
1016
569
    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
1.13k
      for (i = NUM_ENTRIES (jtab); i--;)
1021
1.13k
  {
1022
1.13k
    if (jtab[i].size == 0)
1023
569
      continue;
1024
569
    if (jtab[i].magic == magic)
1025
569
      break;
1026
569
  }
1027
      /* If we did not find a matching entry something is wrong.  */
1028
569
      if (i < 0)
1029
0
  abort ();
1030
1031
      /* Create the .text section.  */
1032
569
      text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
1033
569
      if (text == NULL)
1034
0
  goto error_return;
1035
1036
      /* Copy in the jump code.  */
1037
569
      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
569
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1063
569
            BFD_RELOC_32, (asymbol **) imp_sym,
1064
569
            imp_index);
1065
1066
569
      pe_ILF_save_relocs (& vars, text);
1067
569
      break;
1068
1069
468
    case IMPORT_DATA:
1070
468
      break;
1071
1072
0
    default:
1073
      /* XXX code not yet written.  */
1074
0
      abort ();
1075
1.03k
    }
1076
1077
  /* Now create a symbol describing the imported value.  */
1078
1.03k
  switch (import_type)
1079
1.03k
    {
1080
569
    case IMPORT_CODE:
1081
569
      pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1082
569
          BSF_NOT_AT_END | BSF_FUNCTION);
1083
1084
569
      break;
1085
1086
468
    case IMPORT_DATA:
1087
      /* Nothing to do here.  */
1088
468
      break;
1089
1090
0
    default:
1091
      /* XXX code not yet written.  */
1092
0
      abort ();
1093
1.03k
    }
1094
1095
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1096
1.03k
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1097
1.03k
  if (ptr)
1098
0
    * ptr = 0;
1099
1.03k
  pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1100
1.03k
  if (ptr)
1101
0
    * ptr = '.';
1102
1103
  /* Initialise the bfd.  */
1104
1.03k
  memset (& internal_f, 0, sizeof (internal_f));
1105
1106
1.03k
  internal_f.f_magic  = magic;
1107
1.03k
  internal_f.f_symptr = 0;
1108
1.03k
  internal_f.f_nsyms  = 0;
1109
1.03k
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1110
1111
1.03k
  if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
1112
1.03k
      || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1113
0
    goto error_return;
1114
1115
1.03k
  if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL)
1116
0
    goto error_return;
1117
1118
1.03k
  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
1.03k
  bfd_cache_close (abfd);
1127
1128
1.03k
  abfd->iostream = (void *) vars.bim;
1129
1.03k
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1130
1.03k
  abfd->iovec = &_bfd_memory_iovec;
1131
1.03k
  abfd->where = 0;
1132
1.03k
  abfd->origin = 0;
1133
1.03k
  abfd->size = 0;
1134
1.03k
  obj_sym_filepos (abfd) = 0;
1135
1136
  /* Point the bfd at the symbol table.  */
1137
1.03k
  obj_symbols (abfd) = vars.sym_cache;
1138
1.03k
  abfd->symcount = vars.sym_index;
1139
1140
1.03k
  obj_raw_syments (abfd) = vars.native_syms;
1141
1.03k
  obj_raw_syment_count (abfd) = vars.sym_index;
1142
1143
1.03k
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1144
1.03k
  obj_coff_keep_syms (abfd) = true;
1145
1146
1.03k
  obj_convert (abfd) = vars.sym_table;
1147
1.03k
  obj_conv_table_size (abfd) = vars.sym_index;
1148
1149
1.03k
  obj_coff_strings (abfd) = vars.string_table;
1150
1.03k
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1151
1.03k
  obj_coff_keep_strings (abfd) = true;
1152
1153
1.03k
  return true;
1154
1155
102
 error_return:
1156
102
  free (vars.bim->buffer);
1157
102
  free (vars.bim);
1158
102
  return false;
1159
1.03k
}
1160
1161
/* Cleanup function, returned from check_format hook.  */
1162
1163
static void
1164
pe_ILF_cleanup (bfd *abfd)
1165
0
{
1166
0
  struct bfd_in_memory *bim = abfd->iostream;
1167
0
  free (bim->buffer);
1168
0
  free (bim);
1169
0
  abfd->iostream = NULL;
1170
0
}
Unexecuted instantiation: pei-i386.c:pe_ILF_cleanup
Unexecuted instantiation: pei-x86_64.c:pe_ILF_cleanup
Unexecuted instantiation: pei-aarch64.c:pe_ILF_cleanup
Unexecuted instantiation: pei-ia64.c:pe_ILF_cleanup
Unexecuted instantiation: pei-loongarch64.c:pe_ILF_cleanup
Unexecuted instantiation: pei-arm-wince.c:pe_ILF_cleanup
Unexecuted instantiation: pei-arm.c:pe_ILF_cleanup
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
96.7k
{
1178
96.7k
  bfd_byte    buffer[14];
1179
96.7k
  bfd_byte *    ptr;
1180
96.7k
  char *    symbol_name;
1181
96.7k
  char *    source_dll;
1182
96.7k
  unsigned int    machine;
1183
96.7k
  bfd_size_type   size;
1184
96.7k
  unsigned int    ordinal;
1185
96.7k
  unsigned int    types;
1186
96.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
96.7k
  if (bfd_bread (buffer, (bfd_size_type) 14, abfd) != 14)
1191
1.66k
    return NULL;
1192
1193
95.0k
  ptr = buffer;
1194
1195
95.0k
  machine = H_GET_16 (abfd, ptr);
1196
95.0k
  ptr += 2;
1197
1198
  /* Check that the machine type is recognised.  */
1199
95.0k
  magic = 0;
1200
1201
95.0k
  switch (machine)
1202
95.0k
    {
1203
832
    case IMAGE_FILE_MACHINE_UNKNOWN:
1204
832
    case IMAGE_FILE_MACHINE_ALPHA:
1205
832
    case IMAGE_FILE_MACHINE_ALPHA64:
1206
832
    case IMAGE_FILE_MACHINE_IA64:
1207
832
      break;
1208
1209
11.8k
    case IMAGE_FILE_MACHINE_I386:
1210
#ifdef I386MAGIC
1211
2.23k
      magic = I386MAGIC;
1212
#endif
1213
11.8k
      break;
1214
1215
18.6k
    case IMAGE_FILE_MACHINE_AMD64:
1216
#ifdef AMD64MAGIC
1217
2.51k
      magic = AMD64MAGIC;
1218
#endif
1219
18.6k
      break;
1220
1221
0
    case IMAGE_FILE_MACHINE_R3000:
1222
0
    case IMAGE_FILE_MACHINE_R4000:
1223
816
    case IMAGE_FILE_MACHINE_R10000:
1224
1225
816
    case IMAGE_FILE_MACHINE_MIPS16:
1226
816
    case IMAGE_FILE_MACHINE_MIPSFPU:
1227
816
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1228
#ifdef MIPS_ARCH_MAGIC_WINCE
1229
      magic = MIPS_ARCH_MAGIC_WINCE;
1230
#endif
1231
816
      break;
1232
1233
1.62k
    case IMAGE_FILE_MACHINE_SH3:
1234
12.0k
    case IMAGE_FILE_MACHINE_SH4:
1235
#ifdef SH_ARCH_MAGIC_WINCE
1236
1.76k
      magic = SH_ARCH_MAGIC_WINCE;
1237
#endif
1238
12.0k
      break;
1239
1240
8.59k
    case IMAGE_FILE_MACHINE_ARM:
1241
#ifdef ARMPEMAGIC
1242
2.66k
      magic = ARMPEMAGIC;
1243
#endif
1244
8.59k
      break;
1245
1246
7.23k
    case IMAGE_FILE_MACHINE_ARM64:
1247
#ifdef AARCH64MAGIC
1248
1.28k
      magic = AARCH64MAGIC;
1249
#endif
1250
7.23k
      break;
1251
1252
20.0k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1253
#ifdef LOONGARCH64MAGIC
1254
2.51k
      magic = LOONGARCH64MAGIC;
1255
#endif
1256
20.0k
      break;
1257
1258
5.74k
    case IMAGE_FILE_MACHINE_THUMB:
1259
#ifdef THUMBPEMAGIC
1260
      {
1261
  extern const bfd_target TARGET_LITTLE_SYM;
1262
1263
1.79k
  if (abfd->xvec == & TARGET_LITTLE_SYM)
1264
1.79k
    magic = THUMBPEMAGIC;
1265
      }
1266
#endif
1267
5.74k
      break;
1268
1269
0
    case IMAGE_FILE_MACHINE_POWERPC:
1270
      /* We no longer support PowerPC.  */
1271
9.26k
    default:
1272
9.26k
      _bfd_error_handler
1273
  /* xgettext:c-format */
1274
9.26k
  (_("%pB: unrecognised machine type (0x%x)"
1275
9.26k
     " in Import Library Format archive"),
1276
9.26k
   abfd, machine);
1277
9.26k
      bfd_set_error (bfd_error_malformed_archive);
1278
1279
9.26k
      return NULL;
1280
0
      break;
1281
95.0k
    }
1282
1283
85.8k
  if (magic == 0)
1284
71.0k
    {
1285
71.0k
      _bfd_error_handler
1286
  /* xgettext:c-format */
1287
71.0k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1288
71.0k
     " in Import Library Format archive"),
1289
71.0k
   abfd, machine);
1290
71.0k
      bfd_set_error (bfd_error_wrong_format);
1291
1292
71.0k
      return NULL;
1293
71.0k
    }
1294
1295
  /* We do not bother to check the date.
1296
     date = H_GET_32 (abfd, ptr);  */
1297
14.7k
  ptr += 4;
1298
1299
14.7k
  size = H_GET_32 (abfd, ptr);
1300
14.7k
  ptr += 4;
1301
1302
14.7k
  if (size == 0)
1303
523
    {
1304
523
      _bfd_error_handler
1305
523
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1306
523
      bfd_set_error (bfd_error_malformed_archive);
1307
1308
523
      return NULL;
1309
523
    }
1310
1311
14.2k
  ordinal = H_GET_16 (abfd, ptr);
1312
14.2k
  ptr += 2;
1313
1314
14.2k
  types = H_GET_16 (abfd, ptr);
1315
  /* ptr += 2; */
1316
1317
  /* Now read in the two strings that follow.  */
1318
14.2k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1319
14.2k
  if (ptr == NULL)
1320
2.91k
    return NULL;
1321
1322
11.3k
  symbol_name = (char *) ptr;
1323
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1324
11.3k
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1325
1326
  /* Verify that the strings are null terminated.  */
1327
11.3k
  if (ptr[size - 1] != 0
1328
11.3k
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1329
845
    {
1330
845
      _bfd_error_handler
1331
845
  (_("%pB: string not null terminated in ILF object file"), abfd);
1332
845
      bfd_set_error (bfd_error_malformed_archive);
1333
845
      bfd_release (abfd, ptr);
1334
845
      return NULL;
1335
845
    }
1336
1337
  /* Now construct the bfd.  */
1338
10.4k
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1339
10.4k
          source_dll, ordinal, types))
1340
2.60k
    {
1341
2.60k
      bfd_release (abfd, ptr);
1342
2.60k
      return NULL;
1343
2.60k
    }
1344
1345
7.89k
  return pe_ILF_cleanup;
1346
10.4k
}
pei-i386.c:pe_ILF_object_p
Line
Count
Source
1177
12.7k
{
1178
12.7k
  bfd_byte    buffer[14];
1179
12.7k
  bfd_byte *    ptr;
1180
12.7k
  char *    symbol_name;
1181
12.7k
  char *    source_dll;
1182
12.7k
  unsigned int    machine;
1183
12.7k
  bfd_size_type   size;
1184
12.7k
  unsigned int    ordinal;
1185
12.7k
  unsigned int    types;
1186
12.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
12.7k
  if (bfd_bread (buffer, (bfd_size_type) 14, abfd) != 14)
1191
208
    return NULL;
1192
1193
12.5k
  ptr = buffer;
1194
1195
12.5k
  machine = H_GET_16 (abfd, ptr);
1196
12.5k
  ptr += 2;
1197
1198
  /* Check that the machine type is recognised.  */
1199
12.5k
  magic = 0;
1200
1201
12.5k
  switch (machine)
1202
12.5k
    {
1203
104
    case IMAGE_FILE_MACHINE_UNKNOWN:
1204
104
    case IMAGE_FILE_MACHINE_ALPHA:
1205
104
    case IMAGE_FILE_MACHINE_ALPHA64:
1206
104
    case IMAGE_FILE_MACHINE_IA64:
1207
104
      break;
1208
1209
2.23k
    case IMAGE_FILE_MACHINE_I386:
1210
2.23k
#ifdef I386MAGIC
1211
2.23k
      magic = I386MAGIC;
1212
2.23k
#endif
1213
2.23k
      break;
1214
1215
2.51k
    case IMAGE_FILE_MACHINE_AMD64:
1216
#ifdef AMD64MAGIC
1217
      magic = AMD64MAGIC;
1218
#endif
1219
2.51k
      break;
1220
1221
0
    case IMAGE_FILE_MACHINE_R3000:
1222
0
    case IMAGE_FILE_MACHINE_R4000:
1223
102
    case IMAGE_FILE_MACHINE_R10000:
1224
1225
102
    case IMAGE_FILE_MACHINE_MIPS16:
1226
102
    case IMAGE_FILE_MACHINE_MIPSFPU:
1227
102
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1228
#ifdef MIPS_ARCH_MAGIC_WINCE
1229
      magic = MIPS_ARCH_MAGIC_WINCE;
1230
#endif
1231
102
      break;
1232
1233
203
    case IMAGE_FILE_MACHINE_SH3:
1234
1.76k
    case IMAGE_FILE_MACHINE_SH4:
1235
#ifdef SH_ARCH_MAGIC_WINCE
1236
      magic = SH_ARCH_MAGIC_WINCE;
1237
#endif
1238
1.76k
      break;
1239
1240
818
    case IMAGE_FILE_MACHINE_ARM:
1241
#ifdef ARMPEMAGIC
1242
      magic = ARMPEMAGIC;
1243
#endif
1244
818
      break;
1245
1246
849
    case IMAGE_FILE_MACHINE_ARM64:
1247
#ifdef AARCH64MAGIC
1248
      magic = AARCH64MAGIC;
1249
#endif
1250
849
      break;
1251
1252
2.50k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1253
#ifdef LOONGARCH64MAGIC
1254
      magic = LOONGARCH64MAGIC;
1255
#endif
1256
2.50k
      break;
1257
1258
537
    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
537
      break;
1268
1269
0
    case IMAGE_FILE_MACHINE_POWERPC:
1270
      /* We no longer support PowerPC.  */
1271
1.15k
    default:
1272
1.15k
      _bfd_error_handler
1273
  /* xgettext:c-format */
1274
1.15k
  (_("%pB: unrecognised machine type (0x%x)"
1275
1.15k
     " in Import Library Format archive"),
1276
1.15k
   abfd, machine);
1277
1.15k
      bfd_set_error (bfd_error_malformed_archive);
1278
1279
1.15k
      return NULL;
1280
0
      break;
1281
12.5k
    }
1282
1283
11.4k
  if (magic == 0)
1284
9.18k
    {
1285
9.18k
      _bfd_error_handler
1286
  /* xgettext:c-format */
1287
9.18k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1288
9.18k
     " in Import Library Format archive"),
1289
9.18k
   abfd, machine);
1290
9.18k
      bfd_set_error (bfd_error_wrong_format);
1291
1292
9.18k
      return NULL;
1293
9.18k
    }
1294
1295
  /* We do not bother to check the date.
1296
     date = H_GET_32 (abfd, ptr);  */
1297
2.23k
  ptr += 4;
1298
1299
2.23k
  size = H_GET_32 (abfd, ptr);
1300
2.23k
  ptr += 4;
1301
1302
2.23k
  if (size == 0)
1303
2
    {
1304
2
      _bfd_error_handler
1305
2
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1306
2
      bfd_set_error (bfd_error_malformed_archive);
1307
1308
2
      return NULL;
1309
2
    }
1310
1311
2.23k
  ordinal = H_GET_16 (abfd, ptr);
1312
2.23k
  ptr += 2;
1313
1314
2.23k
  types = H_GET_16 (abfd, ptr);
1315
  /* ptr += 2; */
1316
1317
  /* Now read in the two strings that follow.  */
1318
2.23k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1319
2.23k
  if (ptr == NULL)
1320
313
    return NULL;
1321
1322
1.91k
  symbol_name = (char *) ptr;
1323
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1324
1.91k
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1325
1326
  /* Verify that the strings are null terminated.  */
1327
1.91k
  if (ptr[size - 1] != 0
1328
1.91k
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1329
107
    {
1330
107
      _bfd_error_handler
1331
107
  (_("%pB: string not null terminated in ILF object file"), abfd);
1332
107
      bfd_set_error (bfd_error_malformed_archive);
1333
107
      bfd_release (abfd, ptr);
1334
107
      return NULL;
1335
107
    }
1336
1337
  /* Now construct the bfd.  */
1338
1.81k
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1339
1.81k
          source_dll, ordinal, types))
1340
311
    {
1341
311
      bfd_release (abfd, ptr);
1342
311
      return NULL;
1343
311
    }
1344
1345
1.50k
  return pe_ILF_cleanup;
1346
1.81k
}
pei-x86_64.c:pe_ILF_object_p
Line
Count
Source
1177
10.2k
{
1178
10.2k
  bfd_byte    buffer[14];
1179
10.2k
  bfd_byte *    ptr;
1180
10.2k
  char *    symbol_name;
1181
10.2k
  char *    source_dll;
1182
10.2k
  unsigned int    machine;
1183
10.2k
  bfd_size_type   size;
1184
10.2k
  unsigned int    ordinal;
1185
10.2k
  unsigned int    types;
1186
10.2k
  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
10.2k
  if (bfd_bread (buffer, (bfd_size_type) 14, abfd) != 14)
1191
208
    return NULL;
1192
1193
10.0k
  ptr = buffer;
1194
1195
10.0k
  machine = H_GET_16 (abfd, ptr);
1196
10.0k
  ptr += 2;
1197
1198
  /* Check that the machine type is recognised.  */
1199
10.0k
  magic = 0;
1200
1201
10.0k
  switch (machine)
1202
10.0k
    {
1203
104
    case IMAGE_FILE_MACHINE_UNKNOWN:
1204
104
    case IMAGE_FILE_MACHINE_ALPHA:
1205
104
    case IMAGE_FILE_MACHINE_ALPHA64:
1206
104
    case IMAGE_FILE_MACHINE_IA64:
1207
104
      break;
1208
1209
739
    case IMAGE_FILE_MACHINE_I386:
1210
#ifdef I386MAGIC
1211
      magic = I386MAGIC;
1212
#endif
1213
739
      break;
1214
1215
2.51k
    case IMAGE_FILE_MACHINE_AMD64:
1216
2.51k
#ifdef AMD64MAGIC
1217
2.51k
      magic = AMD64MAGIC;
1218
2.51k
#endif
1219
2.51k
      break;
1220
1221
0
    case IMAGE_FILE_MACHINE_R3000:
1222
0
    case IMAGE_FILE_MACHINE_R4000:
1223
102
    case IMAGE_FILE_MACHINE_R10000:
1224
1225
102
    case IMAGE_FILE_MACHINE_MIPS16:
1226
102
    case IMAGE_FILE_MACHINE_MIPSFPU:
1227
102
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1228
#ifdef MIPS_ARCH_MAGIC_WINCE
1229
      magic = MIPS_ARCH_MAGIC_WINCE;
1230
#endif
1231
102
      break;
1232
1233
203
    case IMAGE_FILE_MACHINE_SH3:
1234
735
    case IMAGE_FILE_MACHINE_SH4:
1235
#ifdef SH_ARCH_MAGIC_WINCE
1236
      magic = SH_ARCH_MAGIC_WINCE;
1237
#endif
1238
735
      break;
1239
1240
818
    case IMAGE_FILE_MACHINE_ARM:
1241
#ifdef ARMPEMAGIC
1242
      magic = ARMPEMAGIC;
1243
#endif
1244
818
      break;
1245
1246
849
    case IMAGE_FILE_MACHINE_ARM64:
1247
#ifdef AARCH64MAGIC
1248
      magic = AARCH64MAGIC;
1249
#endif
1250
849
      break;
1251
1252
2.50k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1253
#ifdef LOONGARCH64MAGIC
1254
      magic = LOONGARCH64MAGIC;
1255
#endif
1256
2.50k
      break;
1257
1258
537
    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
537
      break;
1268
1269
0
    case IMAGE_FILE_MACHINE_POWERPC:
1270
      /* We no longer support PowerPC.  */
1271
1.15k
    default:
1272
1.15k
      _bfd_error_handler
1273
  /* xgettext:c-format */
1274
1.15k
  (_("%pB: unrecognised machine type (0x%x)"
1275
1.15k
     " in Import Library Format archive"),
1276
1.15k
   abfd, machine);
1277
1.15k
      bfd_set_error (bfd_error_malformed_archive);
1278
1279
1.15k
      return NULL;
1280
0
      break;
1281
10.0k
    }
1282
1283
8.90k
  if (magic == 0)
1284
6.38k
    {
1285
6.38k
      _bfd_error_handler
1286
  /* xgettext:c-format */
1287
6.38k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1288
6.38k
     " in Import Library Format archive"),
1289
6.38k
   abfd, machine);
1290
6.38k
      bfd_set_error (bfd_error_wrong_format);
1291
1292
6.38k
      return NULL;
1293
6.38k
    }
1294
1295
  /* We do not bother to check the date.
1296
     date = H_GET_32 (abfd, ptr);  */
1297
2.51k
  ptr += 4;
1298
1299
2.51k
  size = H_GET_32 (abfd, ptr);
1300
2.51k
  ptr += 4;
1301
1302
2.51k
  if (size == 0)
1303
104
    {
1304
104
      _bfd_error_handler
1305
104
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1306
104
      bfd_set_error (bfd_error_malformed_archive);
1307
1308
104
      return NULL;
1309
104
    }
1310
1311
2.41k
  ordinal = H_GET_16 (abfd, ptr);
1312
2.41k
  ptr += 2;
1313
1314
2.41k
  types = H_GET_16 (abfd, ptr);
1315
  /* ptr += 2; */
1316
1317
  /* Now read in the two strings that follow.  */
1318
2.41k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1319
2.41k
  if (ptr == NULL)
1320
220
    return NULL;
1321
1322
2.19k
  symbol_name = (char *) ptr;
1323
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1324
2.19k
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1325
1326
  /* Verify that the strings are null terminated.  */
1327
2.19k
  if (ptr[size - 1] != 0
1328
2.19k
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1329
207
    {
1330
207
      _bfd_error_handler
1331
207
  (_("%pB: string not null terminated in ILF object file"), abfd);
1332
207
      bfd_set_error (bfd_error_malformed_archive);
1333
207
      bfd_release (abfd, ptr);
1334
207
      return NULL;
1335
207
    }
1336
1337
  /* Now construct the bfd.  */
1338
1.98k
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1339
1.98k
          source_dll, ordinal, types))
1340
515
    {
1341
515
      bfd_release (abfd, ptr);
1342
515
      return NULL;
1343
515
    }
1344
1345
1.47k
  return pe_ILF_cleanup;
1346
1.98k
}
pei-aarch64.c:pe_ILF_object_p
Line
Count
Source
1177
14.9k
{
1178
14.9k
  bfd_byte    buffer[14];
1179
14.9k
  bfd_byte *    ptr;
1180
14.9k
  char *    symbol_name;
1181
14.9k
  char *    source_dll;
1182
14.9k
  unsigned int    machine;
1183
14.9k
  bfd_size_type   size;
1184
14.9k
  unsigned int    ordinal;
1185
14.9k
  unsigned int    types;
1186
14.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
14.9k
  if (bfd_bread (buffer, (bfd_size_type) 14, abfd) != 14)
1191
208
    return NULL;
1192
1193
14.7k
  ptr = buffer;
1194
1195
14.7k
  machine = H_GET_16 (abfd, ptr);
1196
14.7k
  ptr += 2;
1197
1198
  /* Check that the machine type is recognised.  */
1199
14.7k
  magic = 0;
1200
1201
14.7k
  switch (machine)
1202
14.7k
    {
1203
104
    case IMAGE_FILE_MACHINE_UNKNOWN:
1204
104
    case IMAGE_FILE_MACHINE_ALPHA:
1205
104
    case IMAGE_FILE_MACHINE_ALPHA64:
1206
104
    case IMAGE_FILE_MACHINE_IA64:
1207
104
      break;
1208
1209
2.22k
    case IMAGE_FILE_MACHINE_I386:
1210
#ifdef I386MAGIC
1211
      magic = I386MAGIC;
1212
#endif
1213
2.22k
      break;
1214
1215
2.51k
    case IMAGE_FILE_MACHINE_AMD64:
1216
#ifdef AMD64MAGIC
1217
      magic = AMD64MAGIC;
1218
#endif
1219
2.51k
      break;
1220
1221
0
    case IMAGE_FILE_MACHINE_R3000:
1222
0
    case IMAGE_FILE_MACHINE_R4000:
1223
102
    case IMAGE_FILE_MACHINE_R10000:
1224
1225
102
    case IMAGE_FILE_MACHINE_MIPS16:
1226
102
    case IMAGE_FILE_MACHINE_MIPSFPU:
1227
102
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1228
#ifdef MIPS_ARCH_MAGIC_WINCE
1229
      magic = MIPS_ARCH_MAGIC_WINCE;
1230
#endif
1231
102
      break;
1232
1233
203
    case IMAGE_FILE_MACHINE_SH3:
1234
1.76k
    case IMAGE_FILE_MACHINE_SH4:
1235
#ifdef SH_ARCH_MAGIC_WINCE
1236
      magic = SH_ARCH_MAGIC_WINCE;
1237
#endif
1238
1.76k
      break;
1239
1240
1.83k
    case IMAGE_FILE_MACHINE_ARM:
1241
#ifdef ARMPEMAGIC
1242
      magic = ARMPEMAGIC;
1243
#endif
1244
1.83k
      break;
1245
1246
1.28k
    case IMAGE_FILE_MACHINE_ARM64:
1247
1.28k
#ifdef AARCH64MAGIC
1248
1.28k
      magic = AARCH64MAGIC;
1249
1.28k
#endif
1250
1.28k
      break;
1251
1252
2.50k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1253
#ifdef LOONGARCH64MAGIC
1254
      magic = LOONGARCH64MAGIC;
1255
#endif
1256
2.50k
      break;
1257
1258
1.25k
    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.25k
      break;
1268
1269
0
    case IMAGE_FILE_MACHINE_POWERPC:
1270
      /* We no longer support PowerPC.  */
1271
1.15k
    default:
1272
1.15k
      _bfd_error_handler
1273
  /* xgettext:c-format */
1274
1.15k
  (_("%pB: unrecognised machine type (0x%x)"
1275
1.15k
     " in Import Library Format archive"),
1276
1.15k
   abfd, machine);
1277
1.15k
      bfd_set_error (bfd_error_malformed_archive);
1278
1279
1.15k
      return NULL;
1280
0
      break;
1281
14.7k
    }
1282
1283
13.5k
  if (magic == 0)
1284
12.3k
    {
1285
12.3k
      _bfd_error_handler
1286
  /* xgettext:c-format */
1287
12.3k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1288
12.3k
     " in Import Library Format archive"),
1289
12.3k
   abfd, machine);
1290
12.3k
      bfd_set_error (bfd_error_wrong_format);
1291
1292
12.3k
      return NULL;
1293
12.3k
    }
1294
1295
  /* We do not bother to check the date.
1296
     date = H_GET_32 (abfd, ptr);  */
1297
1.28k
  ptr += 4;
1298
1299
1.28k
  size = H_GET_32 (abfd, ptr);
1300
1.28k
  ptr += 4;
1301
1302
1.28k
  if (size == 0)
1303
3
    {
1304
3
      _bfd_error_handler
1305
3
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1306
3
      bfd_set_error (bfd_error_malformed_archive);
1307
1308
3
      return NULL;
1309
3
    }
1310
1311
1.28k
  ordinal = H_GET_16 (abfd, ptr);
1312
1.28k
  ptr += 2;
1313
1314
1.28k
  types = H_GET_16 (abfd, ptr);
1315
  /* ptr += 2; */
1316
1317
  /* Now read in the two strings that follow.  */
1318
1.28k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1319
1.28k
  if (ptr == NULL)
1320
420
    return NULL;
1321
1322
866
  symbol_name = (char *) ptr;
1323
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1324
866
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1325
1326
  /* Verify that the strings are null terminated.  */
1327
866
  if (ptr[size - 1] != 0
1328
866
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1329
110
    {
1330
110
      _bfd_error_handler
1331
110
  (_("%pB: string not null terminated in ILF object file"), abfd);
1332
110
      bfd_set_error (bfd_error_malformed_archive);
1333
110
      bfd_release (abfd, ptr);
1334
110
      return NULL;
1335
110
    }
1336
1337
  /* Now construct the bfd.  */
1338
756
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1339
756
          source_dll, ordinal, types))
1340
315
    {
1341
315
      bfd_release (abfd, ptr);
1342
315
      return NULL;
1343
315
    }
1344
1345
441
  return pe_ILF_cleanup;
1346
756
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_object_p
pei-loongarch64.c:pe_ILF_object_p
Line
Count
Source
1177
8.81k
{
1178
8.81k
  bfd_byte    buffer[14];
1179
8.81k
  bfd_byte *    ptr;
1180
8.81k
  char *    symbol_name;
1181
8.81k
  char *    source_dll;
1182
8.81k
  unsigned int    machine;
1183
8.81k
  bfd_size_type   size;
1184
8.81k
  unsigned int    ordinal;
1185
8.81k
  unsigned int    types;
1186
8.81k
  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
8.81k
  if (bfd_bread (buffer, (bfd_size_type) 14, abfd) != 14)
1191
208
    return NULL;
1192
1193
8.60k
  ptr = buffer;
1194
1195
8.60k
  machine = H_GET_16 (abfd, ptr);
1196
8.60k
  ptr += 2;
1197
1198
  /* Check that the machine type is recognised.  */
1199
8.60k
  magic = 0;
1200
1201
8.60k
  switch (machine)
1202
8.60k
    {
1203
104
    case IMAGE_FILE_MACHINE_UNKNOWN:
1204
104
    case IMAGE_FILE_MACHINE_ALPHA:
1205
104
    case IMAGE_FILE_MACHINE_ALPHA64:
1206
104
    case IMAGE_FILE_MACHINE_IA64:
1207
104
      break;
1208
1209
739
    case IMAGE_FILE_MACHINE_I386:
1210
#ifdef I386MAGIC
1211
      magic = I386MAGIC;
1212
#endif
1213
739
      break;
1214
1215
1.05k
    case IMAGE_FILE_MACHINE_AMD64:
1216
#ifdef AMD64MAGIC
1217
      magic = AMD64MAGIC;
1218
#endif
1219
1.05k
      break;
1220
1221
0
    case IMAGE_FILE_MACHINE_R3000:
1222
0
    case IMAGE_FILE_MACHINE_R4000:
1223
102
    case IMAGE_FILE_MACHINE_R10000:
1224
1225
102
    case IMAGE_FILE_MACHINE_MIPS16:
1226
102
    case IMAGE_FILE_MACHINE_MIPSFPU:
1227
102
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1228
#ifdef MIPS_ARCH_MAGIC_WINCE
1229
      magic = MIPS_ARCH_MAGIC_WINCE;
1230
#endif
1231
102
      break;
1232
1233
203
    case IMAGE_FILE_MACHINE_SH3:
1234
735
    case IMAGE_FILE_MACHINE_SH4:
1235
#ifdef SH_ARCH_MAGIC_WINCE
1236
      magic = SH_ARCH_MAGIC_WINCE;
1237
#endif
1238
735
      break;
1239
1240
818
    case IMAGE_FILE_MACHINE_ARM:
1241
#ifdef ARMPEMAGIC
1242
      magic = ARMPEMAGIC;
1243
#endif
1244
818
      break;
1245
1246
849
    case IMAGE_FILE_MACHINE_ARM64:
1247
#ifdef AARCH64MAGIC
1248
      magic = AARCH64MAGIC;
1249
#endif
1250
849
      break;
1251
1252
2.51k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1253
2.51k
#ifdef LOONGARCH64MAGIC
1254
2.51k
      magic = LOONGARCH64MAGIC;
1255
2.51k
#endif
1256
2.51k
      break;
1257
1258
537
    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
537
      break;
1268
1269
0
    case IMAGE_FILE_MACHINE_POWERPC:
1270
      /* We no longer support PowerPC.  */
1271
1.15k
    default:
1272
1.15k
      _bfd_error_handler
1273
  /* xgettext:c-format */
1274
1.15k
  (_("%pB: unrecognised machine type (0x%x)"
1275
1.15k
     " in Import Library Format archive"),
1276
1.15k
   abfd, machine);
1277
1.15k
      bfd_set_error (bfd_error_malformed_archive);
1278
1279
1.15k
      return NULL;
1280
0
      break;
1281
8.60k
    }
1282
1283
7.44k
  if (magic == 0)
1284
4.93k
    {
1285
4.93k
      _bfd_error_handler
1286
  /* xgettext:c-format */
1287
4.93k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1288
4.93k
     " in Import Library Format archive"),
1289
4.93k
   abfd, machine);
1290
4.93k
      bfd_set_error (bfd_error_wrong_format);
1291
1292
4.93k
      return NULL;
1293
4.93k
    }
1294
1295
  /* We do not bother to check the date.
1296
     date = H_GET_32 (abfd, ptr);  */
1297
2.51k
  ptr += 4;
1298
1299
2.51k
  size = H_GET_32 (abfd, ptr);
1300
2.51k
  ptr += 4;
1301
1302
2.51k
  if (size == 0)
1303
104
    {
1304
104
      _bfd_error_handler
1305
104
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1306
104
      bfd_set_error (bfd_error_malformed_archive);
1307
1308
104
      return NULL;
1309
104
    }
1310
1311
2.40k
  ordinal = H_GET_16 (abfd, ptr);
1312
2.40k
  ptr += 2;
1313
1314
2.40k
  types = H_GET_16 (abfd, ptr);
1315
  /* ptr += 2; */
1316
1317
  /* Now read in the two strings that follow.  */
1318
2.40k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1319
2.40k
  if (ptr == NULL)
1320
313
    return NULL;
1321
1322
2.09k
  symbol_name = (char *) ptr;
1323
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1324
2.09k
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1325
1326
  /* Verify that the strings are null terminated.  */
1327
2.09k
  if (ptr[size - 1] != 0
1328
2.09k
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1329
105
    {
1330
105
      _bfd_error_handler
1331
105
  (_("%pB: string not null terminated in ILF object file"), abfd);
1332
105
      bfd_set_error (bfd_error_malformed_archive);
1333
105
      bfd_release (abfd, ptr);
1334
105
      return NULL;
1335
105
    }
1336
1337
  /* Now construct the bfd.  */
1338
1.98k
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1339
1.98k
          source_dll, ordinal, types))
1340
314
    {
1341
314
      bfd_release (abfd, ptr);
1342
314
      return NULL;
1343
314
    }
1344
1345
1.67k
  return pe_ILF_cleanup;
1346
1.98k
}
pei-arm-wince.c:pe_ILF_object_p
Line
Count
Source
1177
12.7k
{
1178
12.7k
  bfd_byte    buffer[14];
1179
12.7k
  bfd_byte *    ptr;
1180
12.7k
  char *    symbol_name;
1181
12.7k
  char *    source_dll;
1182
12.7k
  unsigned int    machine;
1183
12.7k
  bfd_size_type   size;
1184
12.7k
  unsigned int    ordinal;
1185
12.7k
  unsigned int    types;
1186
12.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
12.7k
  if (bfd_bread (buffer, (bfd_size_type) 14, abfd) != 14)
1191
208
    return NULL;
1192
1193
12.5k
  ptr = buffer;
1194
1195
12.5k
  machine = H_GET_16 (abfd, ptr);
1196
12.5k
  ptr += 2;
1197
1198
  /* Check that the machine type is recognised.  */
1199
12.5k
  magic = 0;
1200
1201
12.5k
  switch (machine)
1202
12.5k
    {
1203
104
    case IMAGE_FILE_MACHINE_UNKNOWN:
1204
104
    case IMAGE_FILE_MACHINE_ALPHA:
1205
104
    case IMAGE_FILE_MACHINE_ALPHA64:
1206
104
    case IMAGE_FILE_MACHINE_IA64:
1207
104
      break;
1208
1209
2.22k
    case IMAGE_FILE_MACHINE_I386:
1210
#ifdef I386MAGIC
1211
      magic = I386MAGIC;
1212
#endif
1213
2.22k
      break;
1214
1215
2.51k
    case IMAGE_FILE_MACHINE_AMD64:
1216
#ifdef AMD64MAGIC
1217
      magic = AMD64MAGIC;
1218
#endif
1219
2.51k
      break;
1220
1221
0
    case IMAGE_FILE_MACHINE_R3000:
1222
0
    case IMAGE_FILE_MACHINE_R4000:
1223
102
    case IMAGE_FILE_MACHINE_R10000:
1224
1225
102
    case IMAGE_FILE_MACHINE_MIPS16:
1226
102
    case IMAGE_FILE_MACHINE_MIPSFPU:
1227
102
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1228
#ifdef MIPS_ARCH_MAGIC_WINCE
1229
      magic = MIPS_ARCH_MAGIC_WINCE;
1230
#endif
1231
102
      break;
1232
1233
203
    case IMAGE_FILE_MACHINE_SH3:
1234
1.76k
    case IMAGE_FILE_MACHINE_SH4:
1235
#ifdef SH_ARCH_MAGIC_WINCE
1236
      magic = SH_ARCH_MAGIC_WINCE;
1237
#endif
1238
1.76k
      break;
1239
1240
818
    case IMAGE_FILE_MACHINE_ARM:
1241
818
#ifdef ARMPEMAGIC
1242
818
      magic = ARMPEMAGIC;
1243
818
#endif
1244
818
      break;
1245
1246
849
    case IMAGE_FILE_MACHINE_ARM64:
1247
#ifdef AARCH64MAGIC
1248
      magic = AARCH64MAGIC;
1249
#endif
1250
849
      break;
1251
1252
2.50k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1253
#ifdef LOONGARCH64MAGIC
1254
      magic = LOONGARCH64MAGIC;
1255
#endif
1256
2.50k
      break;
1257
1258
537
    case IMAGE_FILE_MACHINE_THUMB:
1259
537
#ifdef THUMBPEMAGIC
1260
537
      {
1261
537
  extern const bfd_target TARGET_LITTLE_SYM;
1262
1263
537
  if (abfd->xvec == & TARGET_LITTLE_SYM)
1264
537
    magic = THUMBPEMAGIC;
1265
537
      }
1266
537
#endif
1267
537
      break;
1268
1269
0
    case IMAGE_FILE_MACHINE_POWERPC:
1270
      /* We no longer support PowerPC.  */
1271
1.15k
    default:
1272
1.15k
      _bfd_error_handler
1273
  /* xgettext:c-format */
1274
1.15k
  (_("%pB: unrecognised machine type (0x%x)"
1275
1.15k
     " in Import Library Format archive"),
1276
1.15k
   abfd, machine);
1277
1.15k
      bfd_set_error (bfd_error_malformed_archive);
1278
1279
1.15k
      return NULL;
1280
0
      break;
1281
12.5k
    }
1282
1283
11.4k
  if (magic == 0)
1284
10.0k
    {
1285
10.0k
      _bfd_error_handler
1286
  /* xgettext:c-format */
1287
10.0k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1288
10.0k
     " in Import Library Format archive"),
1289
10.0k
   abfd, machine);
1290
10.0k
      bfd_set_error (bfd_error_wrong_format);
1291
1292
10.0k
      return NULL;
1293
10.0k
    }
1294
1295
  /* We do not bother to check the date.
1296
     date = H_GET_32 (abfd, ptr);  */
1297
1.35k
  ptr += 4;
1298
1299
1.35k
  size = H_GET_32 (abfd, ptr);
1300
1.35k
  ptr += 4;
1301
1302
1.35k
  if (size == 0)
1303
104
    {
1304
104
      _bfd_error_handler
1305
104
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1306
104
      bfd_set_error (bfd_error_malformed_archive);
1307
1308
104
      return NULL;
1309
104
    }
1310
1311
1.25k
  ordinal = H_GET_16 (abfd, ptr);
1312
1.25k
  ptr += 2;
1313
1314
1.25k
  types = H_GET_16 (abfd, ptr);
1315
  /* ptr += 2; */
1316
1317
  /* Now read in the two strings that follow.  */
1318
1.25k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1319
1.25k
  if (ptr == NULL)
1320
721
    return NULL;
1321
1322
530
  symbol_name = (char *) ptr;
1323
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1324
530
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1325
1326
  /* Verify that the strings are null terminated.  */
1327
530
  if (ptr[size - 1] != 0
1328
530
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1329
104
    {
1330
104
      _bfd_error_handler
1331
104
  (_("%pB: string not null terminated in ILF object file"), abfd);
1332
104
      bfd_set_error (bfd_error_malformed_archive);
1333
104
      bfd_release (abfd, ptr);
1334
104
      return NULL;
1335
104
    }
1336
1337
  /* Now construct the bfd.  */
1338
426
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1339
426
          source_dll, ordinal, types))
1340
418
    {
1341
418
      bfd_release (abfd, ptr);
1342
418
      return NULL;
1343
418
    }
1344
1345
8
  return pe_ILF_cleanup;
1346
426
}
pei-arm.c:pe_ILF_object_p
Line
Count
Source
1177
14.5k
{
1178
14.5k
  bfd_byte    buffer[14];
1179
14.5k
  bfd_byte *    ptr;
1180
14.5k
  char *    symbol_name;
1181
14.5k
  char *    source_dll;
1182
14.5k
  unsigned int    machine;
1183
14.5k
  bfd_size_type   size;
1184
14.5k
  unsigned int    ordinal;
1185
14.5k
  unsigned int    types;
1186
14.5k
  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
14.5k
  if (bfd_bread (buffer, (bfd_size_type) 14, abfd) != 14)
1191
208
    return NULL;
1192
1193
14.3k
  ptr = buffer;
1194
1195
14.3k
  machine = H_GET_16 (abfd, ptr);
1196
14.3k
  ptr += 2;
1197
1198
  /* Check that the machine type is recognised.  */
1199
14.3k
  magic = 0;
1200
1201
14.3k
  switch (machine)
1202
14.3k
    {
1203
104
    case IMAGE_FILE_MACHINE_UNKNOWN:
1204
104
    case IMAGE_FILE_MACHINE_ALPHA:
1205
104
    case IMAGE_FILE_MACHINE_ALPHA64:
1206
104
    case IMAGE_FILE_MACHINE_IA64:
1207
104
      break;
1208
1209
2.22k
    case IMAGE_FILE_MACHINE_I386:
1210
#ifdef I386MAGIC
1211
      magic = I386MAGIC;
1212
#endif
1213
2.22k
      break;
1214
1215
2.51k
    case IMAGE_FILE_MACHINE_AMD64:
1216
#ifdef AMD64MAGIC
1217
      magic = AMD64MAGIC;
1218
#endif
1219
2.51k
      break;
1220
1221
0
    case IMAGE_FILE_MACHINE_R3000:
1222
0
    case IMAGE_FILE_MACHINE_R4000:
1223
102
    case IMAGE_FILE_MACHINE_R10000:
1224
1225
102
    case IMAGE_FILE_MACHINE_MIPS16:
1226
102
    case IMAGE_FILE_MACHINE_MIPSFPU:
1227
102
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1228
#ifdef MIPS_ARCH_MAGIC_WINCE
1229
      magic = MIPS_ARCH_MAGIC_WINCE;
1230
#endif
1231
102
      break;
1232
1233
203
    case IMAGE_FILE_MACHINE_SH3:
1234
1.76k
    case IMAGE_FILE_MACHINE_SH4:
1235
#ifdef SH_ARCH_MAGIC_WINCE
1236
      magic = SH_ARCH_MAGIC_WINCE;
1237
#endif
1238
1.76k
      break;
1239
1240
1.84k
    case IMAGE_FILE_MACHINE_ARM:
1241
1.84k
#ifdef ARMPEMAGIC
1242
1.84k
      magic = ARMPEMAGIC;
1243
1.84k
#endif
1244
1.84k
      break;
1245
1246
849
    case IMAGE_FILE_MACHINE_ARM64:
1247
#ifdef AARCH64MAGIC
1248
      magic = AARCH64MAGIC;
1249
#endif
1250
849
      break;
1251
1252
2.50k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1253
#ifdef LOONGARCH64MAGIC
1254
      magic = LOONGARCH64MAGIC;
1255
#endif
1256
2.50k
      break;
1257
1258
1.26k
    case IMAGE_FILE_MACHINE_THUMB:
1259
1.26k
#ifdef THUMBPEMAGIC
1260
1.26k
      {
1261
1.26k
  extern const bfd_target TARGET_LITTLE_SYM;
1262
1263
1.26k
  if (abfd->xvec == & TARGET_LITTLE_SYM)
1264
1.26k
    magic = THUMBPEMAGIC;
1265
1.26k
      }
1266
1.26k
#endif
1267
1.26k
      break;
1268
1269
0
    case IMAGE_FILE_MACHINE_POWERPC:
1270
      /* We no longer support PowerPC.  */
1271
1.15k
    default:
1272
1.15k
      _bfd_error_handler
1273
  /* xgettext:c-format */
1274
1.15k
  (_("%pB: unrecognised machine type (0x%x)"
1275
1.15k
     " in Import Library Format archive"),
1276
1.15k
   abfd, machine);
1277
1.15k
      bfd_set_error (bfd_error_malformed_archive);
1278
1279
1.15k
      return NULL;
1280
0
      break;
1281
14.3k
    }
1282
1283
13.1k
  if (magic == 0)
1284
10.0k
    {
1285
10.0k
      _bfd_error_handler
1286
  /* xgettext:c-format */
1287
10.0k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1288
10.0k
     " in Import Library Format archive"),
1289
10.0k
   abfd, machine);
1290
10.0k
      bfd_set_error (bfd_error_wrong_format);
1291
1292
10.0k
      return NULL;
1293
10.0k
    }
1294
1295
  /* We do not bother to check the date.
1296
     date = H_GET_32 (abfd, ptr);  */
1297
3.10k
  ptr += 4;
1298
1299
3.10k
  size = H_GET_32 (abfd, ptr);
1300
3.10k
  ptr += 4;
1301
1302
3.10k
  if (size == 0)
1303
104
    {
1304
104
      _bfd_error_handler
1305
104
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1306
104
      bfd_set_error (bfd_error_malformed_archive);
1307
1308
104
      return NULL;
1309
104
    }
1310
1311
3.00k
  ordinal = H_GET_16 (abfd, ptr);
1312
3.00k
  ptr += 2;
1313
1314
3.00k
  types = H_GET_16 (abfd, ptr);
1315
  /* ptr += 2; */
1316
1317
  /* Now read in the two strings that follow.  */
1318
3.00k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1319
3.00k
  if (ptr == NULL)
1320
721
    return NULL;
1321
1322
2.28k
  symbol_name = (char *) ptr;
1323
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1324
2.28k
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1325
1326
  /* Verify that the strings are null terminated.  */
1327
2.28k
  if (ptr[size - 1] != 0
1328
2.28k
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1329
104
    {
1330
104
      _bfd_error_handler
1331
104
  (_("%pB: string not null terminated in ILF object file"), abfd);
1332
104
      bfd_set_error (bfd_error_malformed_archive);
1333
104
      bfd_release (abfd, ptr);
1334
104
      return NULL;
1335
104
    }
1336
1337
  /* Now construct the bfd.  */
1338
2.17k
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1339
2.17k
          source_dll, ordinal, types))
1340
418
    {
1341
418
      bfd_release (abfd, ptr);
1342
418
      return NULL;
1343
418
    }
1344
1345
1.75k
  return pe_ILF_cleanup;
1346
2.17k
}
pei-mcore.c:pe_ILF_object_p
Line
Count
Source
1177
11.2k
{
1178
11.2k
  bfd_byte    buffer[14];
1179
11.2k
  bfd_byte *    ptr;
1180
11.2k
  char *    symbol_name;
1181
11.2k
  char *    source_dll;
1182
11.2k
  unsigned int    machine;
1183
11.2k
  bfd_size_type   size;
1184
11.2k
  unsigned int    ordinal;
1185
11.2k
  unsigned int    types;
1186
11.2k
  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
11.2k
  if (bfd_bread (buffer, (bfd_size_type) 14, abfd) != 14)
1191
208
    return NULL;
1192
1193
11.0k
  ptr = buffer;
1194
1195
11.0k
  machine = H_GET_16 (abfd, ptr);
1196
11.0k
  ptr += 2;
1197
1198
  /* Check that the machine type is recognised.  */
1199
11.0k
  magic = 0;
1200
1201
11.0k
  switch (machine)
1202
11.0k
    {
1203
104
    case IMAGE_FILE_MACHINE_UNKNOWN:
1204
104
    case IMAGE_FILE_MACHINE_ALPHA:
1205
104
    case IMAGE_FILE_MACHINE_ALPHA64:
1206
104
    case IMAGE_FILE_MACHINE_IA64:
1207
104
      break;
1208
1209
739
    case IMAGE_FILE_MACHINE_I386:
1210
#ifdef I386MAGIC
1211
      magic = I386MAGIC;
1212
#endif
1213
739
      break;
1214
1215
2.51k
    case IMAGE_FILE_MACHINE_AMD64:
1216
#ifdef AMD64MAGIC
1217
      magic = AMD64MAGIC;
1218
#endif
1219
2.51k
      break;
1220
1221
0
    case IMAGE_FILE_MACHINE_R3000:
1222
0
    case IMAGE_FILE_MACHINE_R4000:
1223
102
    case IMAGE_FILE_MACHINE_R10000:
1224
1225
102
    case IMAGE_FILE_MACHINE_MIPS16:
1226
102
    case IMAGE_FILE_MACHINE_MIPSFPU:
1227
102
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1228
#ifdef MIPS_ARCH_MAGIC_WINCE
1229
      magic = MIPS_ARCH_MAGIC_WINCE;
1230
#endif
1231
102
      break;
1232
1233
203
    case IMAGE_FILE_MACHINE_SH3:
1234
1.76k
    case IMAGE_FILE_MACHINE_SH4:
1235
#ifdef SH_ARCH_MAGIC_WINCE
1236
      magic = SH_ARCH_MAGIC_WINCE;
1237
#endif
1238
1.76k
      break;
1239
1240
818
    case IMAGE_FILE_MACHINE_ARM:
1241
#ifdef ARMPEMAGIC
1242
      magic = ARMPEMAGIC;
1243
#endif
1244
818
      break;
1245
1246
849
    case IMAGE_FILE_MACHINE_ARM64:
1247
#ifdef AARCH64MAGIC
1248
      magic = AARCH64MAGIC;
1249
#endif
1250
849
      break;
1251
1252
2.50k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1253
#ifdef LOONGARCH64MAGIC
1254
      magic = LOONGARCH64MAGIC;
1255
#endif
1256
2.50k
      break;
1257
1258
537
    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
537
      break;
1268
1269
0
    case IMAGE_FILE_MACHINE_POWERPC:
1270
      /* We no longer support PowerPC.  */
1271
1.15k
    default:
1272
1.15k
      _bfd_error_handler
1273
  /* xgettext:c-format */
1274
1.15k
  (_("%pB: unrecognised machine type (0x%x)"
1275
1.15k
     " in Import Library Format archive"),
1276
1.15k
   abfd, machine);
1277
1.15k
      bfd_set_error (bfd_error_malformed_archive);
1278
1279
1.15k
      return NULL;
1280
0
      break;
1281
11.0k
    }
1282
1283
9.92k
  if (magic == 0)
1284
9.92k
    {
1285
9.92k
      _bfd_error_handler
1286
  /* xgettext:c-format */
1287
9.92k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1288
9.92k
     " in Import Library Format archive"),
1289
9.92k
   abfd, machine);
1290
9.92k
      bfd_set_error (bfd_error_wrong_format);
1291
1292
9.92k
      return NULL;
1293
9.92k
    }
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
11.2k
{
1178
11.2k
  bfd_byte    buffer[14];
1179
11.2k
  bfd_byte *    ptr;
1180
11.2k
  char *    symbol_name;
1181
11.2k
  char *    source_dll;
1182
11.2k
  unsigned int    machine;
1183
11.2k
  bfd_size_type   size;
1184
11.2k
  unsigned int    ordinal;
1185
11.2k
  unsigned int    types;
1186
11.2k
  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
11.2k
  if (bfd_bread (buffer, (bfd_size_type) 14, abfd) != 14)
1191
208
    return NULL;
1192
1193
11.0k
  ptr = buffer;
1194
1195
11.0k
  machine = H_GET_16 (abfd, ptr);
1196
11.0k
  ptr += 2;
1197
1198
  /* Check that the machine type is recognised.  */
1199
11.0k
  magic = 0;
1200
1201
11.0k
  switch (machine)
1202
11.0k
    {
1203
104
    case IMAGE_FILE_MACHINE_UNKNOWN:
1204
104
    case IMAGE_FILE_MACHINE_ALPHA:
1205
104
    case IMAGE_FILE_MACHINE_ALPHA64:
1206
104
    case IMAGE_FILE_MACHINE_IA64:
1207
104
      break;
1208
1209
739
    case IMAGE_FILE_MACHINE_I386:
1210
#ifdef I386MAGIC
1211
      magic = I386MAGIC;
1212
#endif
1213
739
      break;
1214
1215
2.51k
    case IMAGE_FILE_MACHINE_AMD64:
1216
#ifdef AMD64MAGIC
1217
      magic = AMD64MAGIC;
1218
#endif
1219
2.51k
      break;
1220
1221
0
    case IMAGE_FILE_MACHINE_R3000:
1222
0
    case IMAGE_FILE_MACHINE_R4000:
1223
102
    case IMAGE_FILE_MACHINE_R10000:
1224
1225
102
    case IMAGE_FILE_MACHINE_MIPS16:
1226
102
    case IMAGE_FILE_MACHINE_MIPSFPU:
1227
102
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1228
#ifdef MIPS_ARCH_MAGIC_WINCE
1229
      magic = MIPS_ARCH_MAGIC_WINCE;
1230
#endif
1231
102
      break;
1232
1233
203
    case IMAGE_FILE_MACHINE_SH3:
1234
1.76k
    case IMAGE_FILE_MACHINE_SH4:
1235
1.76k
#ifdef SH_ARCH_MAGIC_WINCE
1236
1.76k
      magic = SH_ARCH_MAGIC_WINCE;
1237
1.76k
#endif
1238
1.76k
      break;
1239
1240
818
    case IMAGE_FILE_MACHINE_ARM:
1241
#ifdef ARMPEMAGIC
1242
      magic = ARMPEMAGIC;
1243
#endif
1244
818
      break;
1245
1246
849
    case IMAGE_FILE_MACHINE_ARM64:
1247
#ifdef AARCH64MAGIC
1248
      magic = AARCH64MAGIC;
1249
#endif
1250
849
      break;
1251
1252
2.50k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1253
#ifdef LOONGARCH64MAGIC
1254
      magic = LOONGARCH64MAGIC;
1255
#endif
1256
2.50k
      break;
1257
1258
537
    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
537
      break;
1268
1269
0
    case IMAGE_FILE_MACHINE_POWERPC:
1270
      /* We no longer support PowerPC.  */
1271
1.15k
    default:
1272
1.15k
      _bfd_error_handler
1273
  /* xgettext:c-format */
1274
1.15k
  (_("%pB: unrecognised machine type (0x%x)"
1275
1.15k
     " in Import Library Format archive"),
1276
1.15k
   abfd, machine);
1277
1.15k
      bfd_set_error (bfd_error_malformed_archive);
1278
1279
1.15k
      return NULL;
1280
0
      break;
1281
11.0k
    }
1282
1283
9.93k
  if (magic == 0)
1284
8.16k
    {
1285
8.16k
      _bfd_error_handler
1286
  /* xgettext:c-format */
1287
8.16k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1288
8.16k
     " in Import Library Format archive"),
1289
8.16k
   abfd, machine);
1290
8.16k
      bfd_set_error (bfd_error_wrong_format);
1291
1292
8.16k
      return NULL;
1293
8.16k
    }
1294
1295
  /* We do not bother to check the date.
1296
     date = H_GET_32 (abfd, ptr);  */
1297
1.76k
  ptr += 4;
1298
1299
1.76k
  size = H_GET_32 (abfd, ptr);
1300
1.76k
  ptr += 4;
1301
1302
1.76k
  if (size == 0)
1303
102
    {
1304
102
      _bfd_error_handler
1305
102
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1306
102
      bfd_set_error (bfd_error_malformed_archive);
1307
1308
102
      return NULL;
1309
102
    }
1310
1311
1.66k
  ordinal = H_GET_16 (abfd, ptr);
1312
1.66k
  ptr += 2;
1313
1314
1.66k
  types = H_GET_16 (abfd, ptr);
1315
  /* ptr += 2; */
1316
1317
  /* Now read in the two strings that follow.  */
1318
1.66k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1319
1.66k
  if (ptr == NULL)
1320
210
    return NULL;
1321
1322
1.45k
  symbol_name = (char *) ptr;
1323
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1324
1.45k
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1325
1326
  /* Verify that the strings are null terminated.  */
1327
1.45k
  if (ptr[size - 1] != 0
1328
1.45k
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1329
108
    {
1330
108
      _bfd_error_handler
1331
108
  (_("%pB: string not null terminated in ILF object file"), abfd);
1332
108
      bfd_set_error (bfd_error_malformed_archive);
1333
108
      bfd_release (abfd, ptr);
1334
108
      return NULL;
1335
108
    }
1336
1337
  /* Now construct the bfd.  */
1338
1.34k
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1339
1.34k
          source_dll, ordinal, types))
1340
311
    {
1341
311
      bfd_release (abfd, ptr);
1342
311
      return NULL;
1343
311
    }
1344
1345
1.03k
  return pe_ILF_cleanup;
1346
1.34k
}
1347
1348
static void
1349
pe_bfd_read_buildid (bfd *abfd)
1350
114k
{
1351
114k
  pe_data_type *pe = pe_data (abfd);
1352
114k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1353
114k
  asection *section;
1354
114k
  bfd_byte *data = 0;
1355
114k
  bfd_size_type dataoff;
1356
114k
  unsigned int i;
1357
114k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1358
114k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1359
1360
114k
  if (size == 0)
1361
43.9k
    return;
1362
1363
70.3k
  addr += extra->ImageBase;
1364
1365
  /* Search for the section containing the DebugDirectory.  */
1366
182k
  for (section = abfd->sections; section != NULL; section = section->next)
1367
144k
    {
1368
144k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1369
32.0k
  break;
1370
144k
    }
1371
1372
70.3k
  if (section == NULL)
1373
38.3k
    return;
1374
1375
32.0k
  if (!(section->flags & SEC_HAS_CONTENTS))
1376
2.82k
    return;
1377
1378
29.1k
  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
29.1k
  if (dataoff >= section->size
1384
29.1k
      || size > section->size - dataoff)
1385
10.7k
    {
1386
10.7k
      _bfd_error_handler
1387
10.7k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1388
10.7k
   abfd);
1389
10.7k
      return;
1390
10.7k
    }
1391
1392
  /* Read the whole section. */
1393
18.4k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1394
6.71k
    {
1395
6.71k
      free (data);
1396
6.71k
      return;
1397
6.71k
    }
1398
1399
  /* Search for a CodeView entry in the DebugDirectory */
1400
7.32M
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1401
7.31M
    {
1402
7.31M
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1403
7.31M
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1404
7.31M
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1405
1406
7.31M
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1407
1408
7.31M
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1409
6.62k
  {
1410
6.62k
    char buffer[256 + 1];
1411
6.62k
    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.62k
    if (_bfd_XXi_slurp_codeview_record (abfd,
1418
6.62k
                (file_ptr) idd.PointerToRawData,
1419
6.62k
                idd.SizeOfData, cvinfo, NULL))
1420
0
      {
1421
0
        struct bfd_build_id* build_id = bfd_alloc (abfd,
1422
0
       sizeof (struct bfd_build_id) + cvinfo->SignatureLength);
1423
0
        if (build_id)
1424
0
    {
1425
0
      build_id->size = cvinfo->SignatureLength;
1426
0
      memcpy(build_id->data,  cvinfo->Signature,
1427
0
       cvinfo->SignatureLength);
1428
0
      abfd->build_id = build_id;
1429
0
    }
1430
0
      }
1431
6.62k
    break;
1432
6.62k
  }
1433
7.31M
    }
1434
1435
11.7k
  free (data);
1436
11.7k
}
pei-i386.c:pe_bfd_read_buildid
Line
Count
Source
1350
14.6k
{
1351
14.6k
  pe_data_type *pe = pe_data (abfd);
1352
14.6k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1353
14.6k
  asection *section;
1354
14.6k
  bfd_byte *data = 0;
1355
14.6k
  bfd_size_type dataoff;
1356
14.6k
  unsigned int i;
1357
14.6k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1358
14.6k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1359
1360
14.6k
  if (size == 0)
1361
6.59k
    return;
1362
1363
8.01k
  addr += extra->ImageBase;
1364
1365
  /* Search for the section containing the DebugDirectory.  */
1366
16.1k
  for (section = abfd->sections; section != NULL; section = section->next)
1367
12.0k
    {
1368
12.0k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1369
3.93k
  break;
1370
12.0k
    }
1371
1372
8.01k
  if (section == NULL)
1373
4.08k
    return;
1374
1375
3.93k
  if (!(section->flags & SEC_HAS_CONTENTS))
1376
135
    return;
1377
1378
3.79k
  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
3.79k
  if (dataoff >= section->size
1384
3.79k
      || size > section->size - dataoff)
1385
1.82k
    {
1386
1.82k
      _bfd_error_handler
1387
1.82k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1388
1.82k
   abfd);
1389
1.82k
      return;
1390
1.82k
    }
1391
1392
  /* Read the whole section. */
1393
1.96k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1394
1.02k
    {
1395
1.02k
      free (data);
1396
1.02k
      return;
1397
1.02k
    }
1398
1399
  /* Search for a CodeView entry in the DebugDirectory */
1400
1.90k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1401
1.43k
    {
1402
1.43k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1403
1.43k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1404
1.43k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1405
1406
1.43k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1407
1408
1.43k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1409
466
  {
1410
466
    char buffer[256 + 1];
1411
466
    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
466
    if (_bfd_XXi_slurp_codeview_record (abfd,
1418
466
                (file_ptr) idd.PointerToRawData,
1419
466
                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
466
    break;
1432
466
  }
1433
1.43k
    }
1434
1435
941
  free (data);
1436
941
}
pei-x86_64.c:pe_bfd_read_buildid
Line
Count
Source
1350
24.6k
{
1351
24.6k
  pe_data_type *pe = pe_data (abfd);
1352
24.6k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1353
24.6k
  asection *section;
1354
24.6k
  bfd_byte *data = 0;
1355
24.6k
  bfd_size_type dataoff;
1356
24.6k
  unsigned int i;
1357
24.6k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1358
24.6k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1359
1360
24.6k
  if (size == 0)
1361
13.3k
    return;
1362
1363
11.2k
  addr += extra->ImageBase;
1364
1365
  /* Search for the section containing the DebugDirectory.  */
1366
21.4k
  for (section = abfd->sections; section != NULL; section = section->next)
1367
17.4k
    {
1368
17.4k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1369
7.24k
  break;
1370
17.4k
    }
1371
1372
11.2k
  if (section == NULL)
1373
4.00k
    return;
1374
1375
7.24k
  if (!(section->flags & SEC_HAS_CONTENTS))
1376
499
    return;
1377
1378
6.75k
  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.75k
  if (dataoff >= section->size
1384
6.75k
      || size > section->size - dataoff)
1385
500
    {
1386
500
      _bfd_error_handler
1387
500
  (_("%pB: error: debug data ends beyond end of debug directory"),
1388
500
   abfd);
1389
500
      return;
1390
500
    }
1391
1392
  /* Read the whole section. */
1393
6.25k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1394
731
    {
1395
731
      free (data);
1396
731
      return;
1397
731
    }
1398
1399
  /* Search for a CodeView entry in the DebugDirectory */
1400
7.28M
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1401
7.27M
    {
1402
7.27M
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1403
7.27M
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1404
7.27M
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1405
1406
7.27M
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1407
1408
7.27M
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1409
4.86k
  {
1410
4.86k
    char buffer[256 + 1];
1411
4.86k
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1412
1413
    /*
1414
      The debug entry doesn't have to have to be in a section, in which
1415
      case AddressOfRawData is 0, so always use PointerToRawData.
1416
    */
1417
4.86k
    if (_bfd_XXi_slurp_codeview_record (abfd,
1418
4.86k
                (file_ptr) idd.PointerToRawData,
1419
4.86k
                idd.SizeOfData, cvinfo, NULL))
1420
0
      {
1421
0
        struct bfd_build_id* build_id = bfd_alloc (abfd,
1422
0
       sizeof (struct bfd_build_id) + cvinfo->SignatureLength);
1423
0
        if (build_id)
1424
0
    {
1425
0
      build_id->size = cvinfo->SignatureLength;
1426
0
      memcpy(build_id->data,  cvinfo->Signature,
1427
0
       cvinfo->SignatureLength);
1428
0
      abfd->build_id = build_id;
1429
0
    }
1430
0
      }
1431
4.86k
    break;
1432
4.86k
  }
1433
7.27M
    }
1434
1435
5.51k
  free (data);
1436
5.51k
}
pei-aarch64.c:pe_bfd_read_buildid
Line
Count
Source
1350
9.39k
{
1351
9.39k
  pe_data_type *pe = pe_data (abfd);
1352
9.39k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1353
9.39k
  asection *section;
1354
9.39k
  bfd_byte *data = 0;
1355
9.39k
  bfd_size_type dataoff;
1356
9.39k
  unsigned int i;
1357
9.39k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1358
9.39k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1359
1360
9.39k
  if (size == 0)
1361
3.03k
    return;
1362
1363
6.35k
  addr += extra->ImageBase;
1364
1365
  /* Search for the section containing the DebugDirectory.  */
1366
10.5k
  for (section = abfd->sections; section != NULL; section = section->next)
1367
6.71k
    {
1368
6.71k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1369
2.55k
  break;
1370
6.71k
    }
1371
1372
6.35k
  if (section == NULL)
1373
3.80k
    return;
1374
1375
2.55k
  if (!(section->flags & SEC_HAS_CONTENTS))
1376
340
    return;
1377
1378
2.21k
  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
2.21k
  if (dataoff >= section->size
1384
2.21k
      || size > section->size - dataoff)
1385
1.87k
    {
1386
1.87k
      _bfd_error_handler
1387
1.87k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1388
1.87k
   abfd);
1389
1.87k
      return;
1390
1.87k
    }
1391
1392
  /* Read the whole section. */
1393
343
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1394
343
    {
1395
343
      free (data);
1396
343
      return;
1397
343
    }
1398
1399
  /* Search for a CodeView entry in the DebugDirectory */
1400
0
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1401
0
    {
1402
0
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1403
0
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1404
0
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1405
1406
0
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1407
1408
0
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1409
0
  {
1410
0
    char buffer[256 + 1];
1411
0
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1412
1413
    /*
1414
      The debug entry doesn't have to have to be in a section, in which
1415
      case AddressOfRawData is 0, so always use PointerToRawData.
1416
    */
1417
0
    if (_bfd_XXi_slurp_codeview_record (abfd,
1418
0
                (file_ptr) idd.PointerToRawData,
1419
0
                idd.SizeOfData, cvinfo, NULL))
1420
0
      {
1421
0
        struct bfd_build_id* build_id = bfd_alloc (abfd,
1422
0
       sizeof (struct bfd_build_id) + cvinfo->SignatureLength);
1423
0
        if (build_id)
1424
0
    {
1425
0
      build_id->size = cvinfo->SignatureLength;
1426
0
      memcpy(build_id->data,  cvinfo->Signature,
1427
0
       cvinfo->SignatureLength);
1428
0
      abfd->build_id = build_id;
1429
0
    }
1430
0
      }
1431
0
    break;
1432
0
  }
1433
0
    }
1434
1435
0
  free (data);
1436
0
}
pei-ia64.c:pe_bfd_read_buildid
Line
Count
Source
1350
13.4k
{
1351
13.4k
  pe_data_type *pe = pe_data (abfd);
1352
13.4k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1353
13.4k
  asection *section;
1354
13.4k
  bfd_byte *data = 0;
1355
13.4k
  bfd_size_type dataoff;
1356
13.4k
  unsigned int i;
1357
13.4k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1358
13.4k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1359
1360
13.4k
  if (size == 0)
1361
5.00k
    return;
1362
1363
8.49k
  addr += extra->ImageBase;
1364
1365
  /* Search for the section containing the DebugDirectory.  */
1366
19.0k
  for (section = abfd->sections; section != NULL; section = section->next)
1367
12.8k
    {
1368
12.8k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1369
2.26k
  break;
1370
12.8k
    }
1371
1372
8.49k
  if (section == NULL)
1373
6.22k
    return;
1374
1375
2.26k
  if (!(section->flags & SEC_HAS_CONTENTS))
1376
336
    return;
1377
1378
1.92k
  dataoff = addr - section->vma;
1379
1380
  /* PR 20605 and 22373: Make sure that the data is really there.
1381
     Note - since we are dealing with unsigned quantities we have
1382
     to be careful to check for potential overflows.  */
1383
1.92k
  if (dataoff >= section->size
1384
1.92k
      || size > section->size - dataoff)
1385
1.34k
    {
1386
1.34k
      _bfd_error_handler
1387
1.34k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1388
1.34k
   abfd);
1389
1.34k
      return;
1390
1.34k
    }
1391
1392
  /* Read the whole section. */
1393
581
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1394
581
    {
1395
581
      free (data);
1396
581
      return;
1397
581
    }
1398
1399
  /* Search for a CodeView entry in the DebugDirectory */
1400
0
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1401
0
    {
1402
0
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1403
0
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1404
0
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1405
1406
0
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1407
1408
0
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1409
0
  {
1410
0
    char buffer[256 + 1];
1411
0
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1412
1413
    /*
1414
      The debug entry doesn't have to have to be in a section, in which
1415
      case AddressOfRawData is 0, so always use PointerToRawData.
1416
    */
1417
0
    if (_bfd_XXi_slurp_codeview_record (abfd,
1418
0
                (file_ptr) idd.PointerToRawData,
1419
0
                idd.SizeOfData, cvinfo, NULL))
1420
0
      {
1421
0
        struct bfd_build_id* build_id = bfd_alloc (abfd,
1422
0
       sizeof (struct bfd_build_id) + cvinfo->SignatureLength);
1423
0
        if (build_id)
1424
0
    {
1425
0
      build_id->size = cvinfo->SignatureLength;
1426
0
      memcpy(build_id->data,  cvinfo->Signature,
1427
0
       cvinfo->SignatureLength);
1428
0
      abfd->build_id = build_id;
1429
0
    }
1430
0
      }
1431
0
    break;
1432
0
  }
1433
0
    }
1434
1435
0
  free (data);
1436
0
}
pei-loongarch64.c:pe_bfd_read_buildid
Line
Count
Source
1350
18.5k
{
1351
18.5k
  pe_data_type *pe = pe_data (abfd);
1352
18.5k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1353
18.5k
  asection *section;
1354
18.5k
  bfd_byte *data = 0;
1355
18.5k
  bfd_size_type dataoff;
1356
18.5k
  unsigned int i;
1357
18.5k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1358
18.5k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1359
1360
18.5k
  if (size == 0)
1361
4.66k
    return;
1362
1363
13.8k
  addr += extra->ImageBase;
1364
1365
  /* Search for the section containing the DebugDirectory.  */
1366
68.0k
  for (section = abfd->sections; section != NULL; section = section->next)
1367
58.6k
    {
1368
58.6k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1369
4.44k
  break;
1370
58.6k
    }
1371
1372
13.8k
  if (section == NULL)
1373
9.44k
    return;
1374
1375
4.44k
  if (!(section->flags & SEC_HAS_CONTENTS))
1376
340
    return;
1377
1378
4.10k
  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
4.10k
  if (dataoff >= section->size
1384
4.10k
      || size > section->size - dataoff)
1385
481
    {
1386
481
      _bfd_error_handler
1387
481
  (_("%pB: error: debug data ends beyond end of debug directory"),
1388
481
   abfd);
1389
481
      return;
1390
481
    }
1391
1392
  /* Read the whole section. */
1393
3.61k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1394
778
    {
1395
778
      free (data);
1396
778
      return;
1397
778
    }
1398
1399
  /* Search for a CodeView entry in the DebugDirectory */
1400
28.8k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1401
26.7k
    {
1402
26.7k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1403
26.7k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1404
26.7k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1405
1406
26.7k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1407
1408
26.7k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1409
711
  {
1410
711
    char buffer[256 + 1];
1411
711
    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
711
    if (_bfd_XXi_slurp_codeview_record (abfd,
1418
711
                (file_ptr) idd.PointerToRawData,
1419
711
                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
711
    break;
1432
711
  }
1433
26.7k
    }
1434
1435
2.84k
  free (data);
1436
2.84k
}
pei-arm-wince.c:pe_bfd_read_buildid
Line
Count
Source
1350
3.98k
{
1351
3.98k
  pe_data_type *pe = pe_data (abfd);
1352
3.98k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1353
3.98k
  asection *section;
1354
3.98k
  bfd_byte *data = 0;
1355
3.98k
  bfd_size_type dataoff;
1356
3.98k
  unsigned int i;
1357
3.98k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1358
3.98k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1359
1360
3.98k
  if (size == 0)
1361
460
    return;
1362
1363
3.52k
  addr += extra->ImageBase;
1364
1365
  /* Search for the section containing the DebugDirectory.  */
1366
5.45k
  for (section = abfd->sections; section != NULL; section = section->next)
1367
4.61k
    {
1368
4.61k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1369
2.68k
  break;
1370
4.61k
    }
1371
1372
3.52k
  if (section == NULL)
1373
840
    return;
1374
1375
2.68k
  if (!(section->flags & SEC_HAS_CONTENTS))
1376
137
    return;
1377
1378
2.55k
  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
2.55k
  if (dataoff >= section->size
1384
2.55k
      || size > section->size - dataoff)
1385
550
    {
1386
550
      _bfd_error_handler
1387
550
  (_("%pB: error: debug data ends beyond end of debug directory"),
1388
550
   abfd);
1389
550
      return;
1390
550
    }
1391
1392
  /* Read the whole section. */
1393
2.00k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1394
369
    {
1395
369
      free (data);
1396
369
      return;
1397
369
    }
1398
1399
  /* Search for a CodeView entry in the DebugDirectory */
1400
9.78k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1401
8.15k
    {
1402
8.15k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1403
8.15k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1404
8.15k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1405
1406
8.15k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1407
1408
8.15k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1409
0
  {
1410
0
    char buffer[256 + 1];
1411
0
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1412
1413
    /*
1414
      The debug entry doesn't have to have to be in a section, in which
1415
      case AddressOfRawData is 0, so always use PointerToRawData.
1416
    */
1417
0
    if (_bfd_XXi_slurp_codeview_record (abfd,
1418
0
                (file_ptr) idd.PointerToRawData,
1419
0
                idd.SizeOfData, cvinfo, NULL))
1420
0
      {
1421
0
        struct bfd_build_id* build_id = bfd_alloc (abfd,
1422
0
       sizeof (struct bfd_build_id) + cvinfo->SignatureLength);
1423
0
        if (build_id)
1424
0
    {
1425
0
      build_id->size = cvinfo->SignatureLength;
1426
0
      memcpy(build_id->data,  cvinfo->Signature,
1427
0
       cvinfo->SignatureLength);
1428
0
      abfd->build_id = build_id;
1429
0
    }
1430
0
      }
1431
0
    break;
1432
0
  }
1433
8.15k
    }
1434
1435
1.63k
  free (data);
1436
1.63k
}
pei-arm.c:pe_bfd_read_buildid
Line
Count
Source
1350
5.96k
{
1351
5.96k
  pe_data_type *pe = pe_data (abfd);
1352
5.96k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1353
5.96k
  asection *section;
1354
5.96k
  bfd_byte *data = 0;
1355
5.96k
  bfd_size_type dataoff;
1356
5.96k
  unsigned int i;
1357
5.96k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1358
5.96k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1359
1360
5.96k
  if (size == 0)
1361
1.93k
    return;
1362
1363
4.02k
  addr += extra->ImageBase;
1364
1365
  /* Search for the section containing the DebugDirectory.  */
1366
8.21k
  for (section = abfd->sections; section != NULL; section = section->next)
1367
5.96k
    {
1368
5.96k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1369
1.76k
  break;
1370
5.96k
    }
1371
1372
4.02k
  if (section == NULL)
1373
2.25k
    return;
1374
1375
1.76k
  if (!(section->flags & SEC_HAS_CONTENTS))
1376
236
    return;
1377
1378
1.53k
  dataoff = addr - section->vma;
1379
1380
  /* PR 20605 and 22373: Make sure that the data is really there.
1381
     Note - since we are dealing with unsigned quantities we have
1382
     to be careful to check for potential overflows.  */
1383
1.53k
  if (dataoff >= section->size
1384
1.53k
      || size > section->size - dataoff)
1385
687
    {
1386
687
      _bfd_error_handler
1387
687
  (_("%pB: error: debug data ends beyond end of debug directory"),
1388
687
   abfd);
1389
687
      return;
1390
687
    }
1391
1392
  /* Read the whole section. */
1393
846
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1394
836
    {
1395
836
      free (data);
1396
836
      return;
1397
836
    }
1398
1399
  /* Search for a CodeView entry in the DebugDirectory */
1400
25
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1401
21
    {
1402
21
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1403
21
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1404
21
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1405
1406
21
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1407
1408
21
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1409
6
  {
1410
6
    char buffer[256 + 1];
1411
6
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1412
1413
    /*
1414
      The debug entry doesn't have to have to be in a section, in which
1415
      case AddressOfRawData is 0, so always use PointerToRawData.
1416
    */
1417
6
    if (_bfd_XXi_slurp_codeview_record (abfd,
1418
6
                (file_ptr) idd.PointerToRawData,
1419
6
                idd.SizeOfData, cvinfo, NULL))
1420
0
      {
1421
0
        struct bfd_build_id* build_id = bfd_alloc (abfd,
1422
0
       sizeof (struct bfd_build_id) + cvinfo->SignatureLength);
1423
0
        if (build_id)
1424
0
    {
1425
0
      build_id->size = cvinfo->SignatureLength;
1426
0
      memcpy(build_id->data,  cvinfo->Signature,
1427
0
       cvinfo->SignatureLength);
1428
0
      abfd->build_id = build_id;
1429
0
    }
1430
0
      }
1431
6
    break;
1432
6
  }
1433
21
    }
1434
1435
10
  free (data);
1436
10
}
pei-mcore.c:pe_bfd_read_buildid
Line
Count
Source
1350
13.3k
{
1351
13.3k
  pe_data_type *pe = pe_data (abfd);
1352
13.3k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1353
13.3k
  asection *section;
1354
13.3k
  bfd_byte *data = 0;
1355
13.3k
  bfd_size_type dataoff;
1356
13.3k
  unsigned int i;
1357
13.3k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1358
13.3k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1359
1360
13.3k
  if (size == 0)
1361
4.06k
    return;
1362
1363
9.28k
  addr += extra->ImageBase;
1364
1365
  /* Search for the section containing the DebugDirectory.  */
1366
21.4k
  for (section = abfd->sections; section != NULL; section = section->next)
1367
16.8k
    {
1368
16.8k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1369
4.68k
  break;
1370
16.8k
    }
1371
1372
9.28k
  if (section == NULL)
1373
4.59k
    return;
1374
1375
4.68k
  if (!(section->flags & SEC_HAS_CONTENTS))
1376
572
    return;
1377
1378
4.11k
  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
4.11k
  if (dataoff >= section->size
1384
4.11k
      || size > section->size - dataoff)
1385
1.88k
    {
1386
1.88k
      _bfd_error_handler
1387
1.88k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1388
1.88k
   abfd);
1389
1.88k
      return;
1390
1.88k
    }
1391
1392
  /* Read the whole section. */
1393
2.23k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1394
1.41k
    {
1395
1.41k
      free (data);
1396
1.41k
      return;
1397
1.41k
    }
1398
1399
  /* Search for a CodeView entry in the DebugDirectory */
1400
3.53k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1401
3.28k
    {
1402
3.28k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1403
3.28k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1404
3.28k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1405
1406
3.28k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1407
1408
3.28k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1409
569
  {
1410
569
    char buffer[256 + 1];
1411
569
    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
569
    if (_bfd_XXi_slurp_codeview_record (abfd,
1418
569
                (file_ptr) idd.PointerToRawData,
1419
569
                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
569
    break;
1432
569
  }
1433
3.28k
    }
1434
1435
814
  free (data);
1436
814
}
pei-sh.c:pe_bfd_read_buildid
Line
Count
Source
1350
10.3k
{
1351
10.3k
  pe_data_type *pe = pe_data (abfd);
1352
10.3k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1353
10.3k
  asection *section;
1354
10.3k
  bfd_byte *data = 0;
1355
10.3k
  bfd_size_type dataoff;
1356
10.3k
  unsigned int i;
1357
10.3k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1358
10.3k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1359
1360
10.3k
  if (size == 0)
1361
4.87k
    return;
1362
1363
5.51k
  addr += extra->ImageBase;
1364
1365
  /* Search for the section containing the DebugDirectory.  */
1366
12.1k
  for (section = abfd->sections; section != NULL; section = section->next)
1367
9.02k
    {
1368
9.02k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1369
2.44k
  break;
1370
9.02k
    }
1371
1372
5.51k
  if (section == NULL)
1373
3.07k
    return;
1374
1375
2.44k
  if (!(section->flags & SEC_HAS_CONTENTS))
1376
234
    return;
1377
1378
2.20k
  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
2.20k
  if (dataoff >= section->size
1384
2.20k
      || size > section->size - dataoff)
1385
1.55k
    {
1386
1.55k
      _bfd_error_handler
1387
1.55k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1388
1.55k
   abfd);
1389
1.55k
      return;
1390
1.55k
    }
1391
1392
  /* Read the whole section. */
1393
647
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1394
636
    {
1395
636
      free (data);
1396
636
      return;
1397
636
    }
1398
1399
  /* Search for a CodeView entry in the DebugDirectory */
1400
52
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1401
49
    {
1402
49
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1403
49
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1404
49
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1405
1406
49
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1407
1408
49
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1409
8
  {
1410
8
    char buffer[256 + 1];
1411
8
    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
8
    if (_bfd_XXi_slurp_codeview_record (abfd,
1418
8
                (file_ptr) idd.PointerToRawData,
1419
8
                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
8
    break;
1432
8
  }
1433
49
    }
1434
1435
11
  free (data);
1436
11
}
1437
1438
static bfd_cleanup
1439
pe_bfd_object_p (bfd * abfd)
1440
6.69M
{
1441
6.69M
  bfd_byte buffer[6];
1442
6.69M
  struct external_DOS_hdr dos_hdr;
1443
6.69M
  struct external_PEI_IMAGE_hdr image_hdr;
1444
6.69M
  struct internal_filehdr internal_f;
1445
6.69M
  struct internal_aouthdr internal_a;
1446
6.69M
  bfd_size_type opt_hdr_size;
1447
6.69M
  file_ptr offset;
1448
6.69M
  bfd_cleanup result;
1449
1450
  /* Detect if this a Microsoft Import Library Format element.  */
1451
  /* First read the beginning of the header.  */
1452
6.69M
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1453
6.69M
      || bfd_bread (buffer, (bfd_size_type) 6, abfd) != 6)
1454
14.0k
    {
1455
14.0k
      if (bfd_get_error () != bfd_error_system_call)
1456
12.8k
  bfd_set_error (bfd_error_wrong_format);
1457
14.0k
      return NULL;
1458
14.0k
    }
1459
1460
  /* Then check the magic and the version (only 0 is supported).  */
1461
6.67M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1462
6.67M
      && H_GET_16 (abfd, buffer + 4) == 0)
1463
96.7k
    return pe_ILF_object_p (abfd);
1464
1465
6.58M
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1466
6.58M
      || bfd_bread (&dos_hdr, (bfd_size_type) sizeof (dos_hdr), abfd)
1467
6.58M
   != sizeof (dos_hdr))
1468
1.25M
    {
1469
1.25M
      if (bfd_get_error () != bfd_error_system_call)
1470
1.25M
  bfd_set_error (bfd_error_wrong_format);
1471
1.25M
      return NULL;
1472
1.25M
    }
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
5.32M
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1485
3.70M
    {
1486
3.70M
      bfd_set_error (bfd_error_wrong_format);
1487
3.70M
      return NULL;
1488
3.70M
    }
1489
1490
1.61M
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1491
1.61M
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1492
1.61M
      || (bfd_bread (&image_hdr, (bfd_size_type) sizeof (image_hdr), abfd)
1493
1.61M
    != sizeof (image_hdr)))
1494
6.75k
    {
1495
6.75k
      if (bfd_get_error () != bfd_error_system_call)
1496
6.75k
  bfd_set_error (bfd_error_wrong_format);
1497
6.75k
      return NULL;
1498
6.75k
    }
1499
1500
1.61M
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1501
34.7k
    {
1502
34.7k
      bfd_set_error (bfd_error_wrong_format);
1503
34.7k
      return NULL;
1504
34.7k
    }
1505
1506
  /* Swap file header, so that we get the location for calling
1507
     real_object_p.  */
1508
1.57M
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1509
1510
1.57M
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1511
1.57M
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1512
1.36M
    {
1513
1.36M
      bfd_set_error (bfd_error_wrong_format);
1514
1.36M
      return NULL;
1515
1.36M
    }
1516
1517
211k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1518
211k
    sizeof (internal_f.pe.dos_message));
1519
1520
  /* Read the optional header, which has variable size.  */
1521
211k
  opt_hdr_size = internal_f.f_opthdr;
1522
1523
211k
  if (opt_hdr_size != 0)
1524
125k
    {
1525
125k
      bfd_size_type amt = opt_hdr_size;
1526
125k
      bfd_byte * opthdr;
1527
1528
      /* PR 17521 file: 230-131433-0.004.  */
1529
125k
      if (amt < sizeof (PEAOUTHDR))
1530
109k
  amt = sizeof (PEAOUTHDR);
1531
1532
125k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1533
125k
      if (opthdr == NULL)
1534
3.72k
  return NULL;
1535
121k
      if (amt > opt_hdr_size)
1536
107k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1537
1538
121k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1539
1540
121k
      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
14.2k
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1547
#else
1548
14.2k
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1549
5.13k
#endif
1550
14.2k
  {
1551
14.2k
    bfd_set_error (bfd_error_wrong_format);
1552
14.2k
    return NULL;
1553
14.2k
  }
1554
14.2k
#endif
1555
1556
107k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1557
107k
    || a->SectionAlignment >= 0x80000000)
1558
52.2k
  {
1559
52.2k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1560
52.2k
        abfd);
1561
52.2k
    a->SectionAlignment &= -a->SectionAlignment;
1562
52.2k
    if (a->SectionAlignment >= 0x80000000)
1563
1.00k
      a->SectionAlignment = 0x40000000;
1564
52.2k
  }
1565
1566
107k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1567
107k
    || a->FileAlignment > a->SectionAlignment)
1568
88.2k
  {
1569
88.2k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1570
88.2k
            abfd);
1571
88.2k
    a->FileAlignment &= -a->FileAlignment;
1572
88.2k
    if (a->FileAlignment > a->SectionAlignment)
1573
52.3k
      a->FileAlignment = a->SectionAlignment;
1574
88.2k
  }
1575
1576
107k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1577
81.1k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1578
14.2k
    }
1579
1580
193k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1581
193k
             (opt_hdr_size != 0
1582
193k
        ? &internal_a
1583
193k
        : (struct internal_aouthdr *) NULL));
1584
1585
193k
  if (result)
1586
114k
    {
1587
      /* Now the whole header has been processed, see if there is a build-id */
1588
114k
      pe_bfd_read_buildid(abfd);
1589
114k
    }
1590
1591
193k
  return result;
1592
211k
}
pei-i386.c:pe_bfd_object_p
Line
Count
Source
1440
595k
{
1441
595k
  bfd_byte buffer[6];
1442
595k
  struct external_DOS_hdr dos_hdr;
1443
595k
  struct external_PEI_IMAGE_hdr image_hdr;
1444
595k
  struct internal_filehdr internal_f;
1445
595k
  struct internal_aouthdr internal_a;
1446
595k
  bfd_size_type opt_hdr_size;
1447
595k
  file_ptr offset;
1448
595k
  bfd_cleanup result;
1449
1450
  /* Detect if this a Microsoft Import Library Format element.  */
1451
  /* First read the beginning of the header.  */
1452
595k
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1453
595k
      || bfd_bread (buffer, (bfd_size_type) 6, abfd) != 6)
1454
1.27k
    {
1455
1.27k
      if (bfd_get_error () != bfd_error_system_call)
1456
1.16k
  bfd_set_error (bfd_error_wrong_format);
1457
1.27k
      return NULL;
1458
1.27k
    }
1459
1460
  /* Then check the magic and the version (only 0 is supported).  */
1461
594k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1462
594k
      && H_GET_16 (abfd, buffer + 4) == 0)
1463
12.7k
    return pe_ILF_object_p (abfd);
1464
1465
581k
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1466
581k
      || bfd_bread (&dos_hdr, (bfd_size_type) sizeof (dos_hdr), abfd)
1467
581k
   != sizeof (dos_hdr))
1468
111k
    {
1469
111k
      if (bfd_get_error () != bfd_error_system_call)
1470
111k
  bfd_set_error (bfd_error_wrong_format);
1471
111k
      return NULL;
1472
111k
    }
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
470k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1485
287k
    {
1486
287k
      bfd_set_error (bfd_error_wrong_format);
1487
287k
      return NULL;
1488
287k
    }
1489
1490
182k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1491
182k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1492
182k
      || (bfd_bread (&image_hdr, (bfd_size_type) sizeof (image_hdr), abfd)
1493
182k
    != sizeof (image_hdr)))
1494
844
    {
1495
844
      if (bfd_get_error () != bfd_error_system_call)
1496
844
  bfd_set_error (bfd_error_wrong_format);
1497
844
      return NULL;
1498
844
    }
1499
1500
181k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1501
4.33k
    {
1502
4.33k
      bfd_set_error (bfd_error_wrong_format);
1503
4.33k
      return NULL;
1504
4.33k
    }
1505
1506
  /* Swap file header, so that we get the location for calling
1507
     real_object_p.  */
1508
177k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1509
1510
177k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1511
177k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1512
154k
    {
1513
154k
      bfd_set_error (bfd_error_wrong_format);
1514
154k
      return NULL;
1515
154k
    }
1516
1517
23.1k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1518
23.1k
    sizeof (internal_f.pe.dos_message));
1519
1520
  /* Read the optional header, which has variable size.  */
1521
23.1k
  opt_hdr_size = internal_f.f_opthdr;
1522
1523
23.1k
  if (opt_hdr_size != 0)
1524
12.2k
    {
1525
12.2k
      bfd_size_type amt = opt_hdr_size;
1526
12.2k
      bfd_byte * opthdr;
1527
1528
      /* PR 17521 file: 230-131433-0.004.  */
1529
12.2k
      if (amt < sizeof (PEAOUTHDR))
1530
12.1k
  amt = sizeof (PEAOUTHDR);
1531
1532
12.2k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1533
12.2k
      if (opthdr == NULL)
1534
470
  return NULL;
1535
11.7k
      if (amt > opt_hdr_size)
1536
11.7k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1537
1538
11.7k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1539
1540
11.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
11.7k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1557
11.7k
    || a->SectionAlignment >= 0x80000000)
1558
5.86k
  {
1559
5.86k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1560
5.86k
        abfd);
1561
5.86k
    a->SectionAlignment &= -a->SectionAlignment;
1562
5.86k
    if (a->SectionAlignment >= 0x80000000)
1563
102
      a->SectionAlignment = 0x40000000;
1564
5.86k
  }
1565
1566
11.7k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1567
11.7k
    || a->FileAlignment > a->SectionAlignment)
1568
7.01k
  {
1569
7.01k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1570
7.01k
            abfd);
1571
7.01k
    a->FileAlignment &= -a->FileAlignment;
1572
7.01k
    if (a->FileAlignment > a->SectionAlignment)
1573
4.84k
      a->FileAlignment = a->SectionAlignment;
1574
7.01k
  }
1575
1576
11.7k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1577
8.67k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1578
11.7k
    }
1579
1580
22.6k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1581
22.6k
             (opt_hdr_size != 0
1582
22.6k
        ? &internal_a
1583
22.6k
        : (struct internal_aouthdr *) NULL));
1584
1585
22.6k
  if (result)
1586
14.6k
    {
1587
      /* Now the whole header has been processed, see if there is a build-id */
1588
14.6k
      pe_bfd_read_buildid(abfd);
1589
14.6k
    }
1590
1591
22.6k
  return result;
1592
23.1k
}
pei-x86_64.c:pe_bfd_object_p
Line
Count
Source
1440
601k
{
1441
601k
  bfd_byte buffer[6];
1442
601k
  struct external_DOS_hdr dos_hdr;
1443
601k
  struct external_PEI_IMAGE_hdr image_hdr;
1444
601k
  struct internal_filehdr internal_f;
1445
601k
  struct internal_aouthdr internal_a;
1446
601k
  bfd_size_type opt_hdr_size;
1447
601k
  file_ptr offset;
1448
601k
  bfd_cleanup result;
1449
1450
  /* Detect if this a Microsoft Import Library Format element.  */
1451
  /* First read the beginning of the header.  */
1452
601k
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1453
601k
      || bfd_bread (buffer, (bfd_size_type) 6, abfd) != 6)
1454
1.27k
    {
1455
1.27k
      if (bfd_get_error () != bfd_error_system_call)
1456
1.16k
  bfd_set_error (bfd_error_wrong_format);
1457
1.27k
      return NULL;
1458
1.27k
    }
1459
1460
  /* Then check the magic and the version (only 0 is supported).  */
1461
599k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1462
599k
      && H_GET_16 (abfd, buffer + 4) == 0)
1463
10.2k
    return pe_ILF_object_p (abfd);
1464
1465
589k
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1466
589k
      || bfd_bread (&dos_hdr, (bfd_size_type) sizeof (dos_hdr), abfd)
1467
589k
   != sizeof (dos_hdr))
1468
111k
    {
1469
111k
      if (bfd_get_error () != bfd_error_system_call)
1470
111k
  bfd_set_error (bfd_error_wrong_format);
1471
111k
      return NULL;
1472
111k
    }
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
477k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1485
289k
    {
1486
289k
      bfd_set_error (bfd_error_wrong_format);
1487
289k
      return NULL;
1488
289k
    }
1489
1490
188k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1491
188k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1492
188k
      || (bfd_bread (&image_hdr, (bfd_size_type) sizeof (image_hdr), abfd)
1493
188k
    != sizeof (image_hdr)))
1494
844
    {
1495
844
      if (bfd_get_error () != bfd_error_system_call)
1496
844
  bfd_set_error (bfd_error_wrong_format);
1497
844
      return NULL;
1498
844
    }
1499
1500
187k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1501
4.33k
    {
1502
4.33k
      bfd_set_error (bfd_error_wrong_format);
1503
4.33k
      return NULL;
1504
4.33k
    }
1505
1506
  /* Swap file header, so that we get the location for calling
1507
     real_object_p.  */
1508
183k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1509
1510
183k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1511
183k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1512
147k
    {
1513
147k
      bfd_set_error (bfd_error_wrong_format);
1514
147k
      return NULL;
1515
147k
    }
1516
1517
35.3k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1518
35.3k
    sizeof (internal_f.pe.dos_message));
1519
1520
  /* Read the optional header, which has variable size.  */
1521
35.3k
  opt_hdr_size = internal_f.f_opthdr;
1522
1523
35.3k
  if (opt_hdr_size != 0)
1524
17.6k
    {
1525
17.6k
      bfd_size_type amt = opt_hdr_size;
1526
17.6k
      bfd_byte * opthdr;
1527
1528
      /* PR 17521 file: 230-131433-0.004.  */
1529
17.6k
      if (amt < sizeof (PEAOUTHDR))
1530
15.6k
  amt = sizeof (PEAOUTHDR);
1531
1532
17.6k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1533
17.6k
      if (opthdr == NULL)
1534
673
  return NULL;
1535
17.0k
      if (amt > opt_hdr_size)
1536
15.2k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1537
1538
17.0k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1539
1540
17.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
17.0k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1557
17.0k
    || a->SectionAlignment >= 0x80000000)
1558
13.7k
  {
1559
13.7k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1560
13.7k
        abfd);
1561
13.7k
    a->SectionAlignment &= -a->SectionAlignment;
1562
13.7k
    if (a->SectionAlignment >= 0x80000000)
1563
5
      a->SectionAlignment = 0x40000000;
1564
13.7k
  }
1565
1566
17.0k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1567
17.0k
    || a->FileAlignment > a->SectionAlignment)
1568
14.2k
  {
1569
14.2k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1570
14.2k
            abfd);
1571
14.2k
    a->FileAlignment &= -a->FileAlignment;
1572
14.2k
    if (a->FileAlignment > a->SectionAlignment)
1573
11.2k
      a->FileAlignment = a->SectionAlignment;
1574
14.2k
  }
1575
1576
17.0k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1577
13.8k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1578
17.0k
    }
1579
1580
34.6k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1581
34.6k
             (opt_hdr_size != 0
1582
34.6k
        ? &internal_a
1583
34.6k
        : (struct internal_aouthdr *) NULL));
1584
1585
34.6k
  if (result)
1586
24.6k
    {
1587
      /* Now the whole header has been processed, see if there is a build-id */
1588
24.6k
      pe_bfd_read_buildid(abfd);
1589
24.6k
    }
1590
1591
34.6k
  return result;
1592
35.3k
}
pei-aarch64.c:pe_bfd_object_p
Line
Count
Source
1440
591k
{
1441
591k
  bfd_byte buffer[6];
1442
591k
  struct external_DOS_hdr dos_hdr;
1443
591k
  struct external_PEI_IMAGE_hdr image_hdr;
1444
591k
  struct internal_filehdr internal_f;
1445
591k
  struct internal_aouthdr internal_a;
1446
591k
  bfd_size_type opt_hdr_size;
1447
591k
  file_ptr offset;
1448
591k
  bfd_cleanup result;
1449
1450
  /* Detect if this a Microsoft Import Library Format element.  */
1451
  /* First read the beginning of the header.  */
1452
591k
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1453
591k
      || bfd_bread (buffer, (bfd_size_type) 6, abfd) != 6)
1454
1.27k
    {
1455
1.27k
      if (bfd_get_error () != bfd_error_system_call)
1456
1.16k
  bfd_set_error (bfd_error_wrong_format);
1457
1.27k
      return NULL;
1458
1.27k
    }
1459
1460
  /* Then check the magic and the version (only 0 is supported).  */
1461
590k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1462
590k
      && H_GET_16 (abfd, buffer + 4) == 0)
1463
14.9k
    return pe_ILF_object_p (abfd);
1464
1465
575k
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1466
575k
      || bfd_bread (&dos_hdr, (bfd_size_type) sizeof (dos_hdr), abfd)
1467
575k
   != sizeof (dos_hdr))
1468
110k
    {
1469
110k
      if (bfd_get_error () != bfd_error_system_call)
1470
110k
  bfd_set_error (bfd_error_wrong_format);
1471
110k
      return NULL;
1472
110k
    }
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
464k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1485
285k
    {
1486
285k
      bfd_set_error (bfd_error_wrong_format);
1487
285k
      return NULL;
1488
285k
    }
1489
1490
178k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1491
178k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1492
178k
      || (bfd_bread (&image_hdr, (bfd_size_type) sizeof (image_hdr), abfd)
1493
178k
    != sizeof (image_hdr)))
1494
844
    {
1495
844
      if (bfd_get_error () != bfd_error_system_call)
1496
844
  bfd_set_error (bfd_error_wrong_format);
1497
844
      return NULL;
1498
844
    }
1499
1500
178k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1501
4.33k
    {
1502
4.33k
      bfd_set_error (bfd_error_wrong_format);
1503
4.33k
      return NULL;
1504
4.33k
    }
1505
1506
  /* Swap file header, so that we get the location for calling
1507
     real_object_p.  */
1508
173k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1509
1510
173k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1511
173k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1512
159k
    {
1513
159k
      bfd_set_error (bfd_error_wrong_format);
1514
159k
      return NULL;
1515
159k
    }
1516
1517
13.8k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1518
13.8k
    sizeof (internal_f.pe.dos_message));
1519
1520
  /* Read the optional header, which has variable size.  */
1521
13.8k
  opt_hdr_size = internal_f.f_opthdr;
1522
1523
13.8k
  if (opt_hdr_size != 0)
1524
10.7k
    {
1525
10.7k
      bfd_size_type amt = opt_hdr_size;
1526
10.7k
      bfd_byte * opthdr;
1527
1528
      /* PR 17521 file: 230-131433-0.004.  */
1529
10.7k
      if (amt < sizeof (PEAOUTHDR))
1530
4.47k
  amt = sizeof (PEAOUTHDR);
1531
1532
10.7k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1533
10.7k
      if (opthdr == NULL)
1534
340
  return NULL;
1535
10.4k
      if (amt > opt_hdr_size)
1536
4.34k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1537
1538
10.4k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1539
1540
10.4k
      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
10.4k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1557
10.4k
    || a->SectionAlignment >= 0x80000000)
1558
537
  {
1559
537
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1560
537
        abfd);
1561
537
    a->SectionAlignment &= -a->SectionAlignment;
1562
537
    if (a->SectionAlignment >= 0x80000000)
1563
0
      a->SectionAlignment = 0x40000000;
1564
537
  }
1565
1566
10.4k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1567
10.4k
    || a->FileAlignment > a->SectionAlignment)
1568
8.59k
  {
1569
8.59k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1570
8.59k
            abfd);
1571
8.59k
    a->FileAlignment &= -a->FileAlignment;
1572
8.59k
    if (a->FileAlignment > a->SectionAlignment)
1573
4.86k
      a->FileAlignment = a->SectionAlignment;
1574
8.59k
  }
1575
1576
10.4k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1577
7.78k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1578
10.4k
    }
1579
1580
13.5k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1581
13.5k
             (opt_hdr_size != 0
1582
13.5k
        ? &internal_a
1583
13.5k
        : (struct internal_aouthdr *) NULL));
1584
1585
13.5k
  if (result)
1586
9.39k
    {
1587
      /* Now the whole header has been processed, see if there is a build-id */
1588
9.39k
      pe_bfd_read_buildid(abfd);
1589
9.39k
    }
1590
1591
13.5k
  return result;
1592
13.8k
}
pei-ia64.c:pe_bfd_object_p
Line
Count
Source
1440
173k
{
1441
173k
  bfd_byte buffer[6];
1442
173k
  struct external_DOS_hdr dos_hdr;
1443
173k
  struct external_PEI_IMAGE_hdr image_hdr;
1444
173k
  struct internal_filehdr internal_f;
1445
173k
  struct internal_aouthdr internal_a;
1446
173k
  bfd_size_type opt_hdr_size;
1447
173k
  file_ptr offset;
1448
173k
  bfd_cleanup result;
1449
1450
  /* Detect if this a Microsoft Import Library Format element.  */
1451
  /* First read the beginning of the header.  */
1452
173k
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1453
173k
      || 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
173k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1462
173k
      && H_GET_16 (abfd, buffer + 4) == 0)
1463
0
    return pe_ILF_object_p (abfd);
1464
1465
173k
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1466
173k
      || bfd_bread (&dos_hdr, (bfd_size_type) sizeof (dos_hdr), abfd)
1467
173k
   != 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
173k
  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
173k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1491
173k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1492
173k
      || (bfd_bread (&image_hdr, (bfd_size_type) sizeof (image_hdr), abfd)
1493
173k
    != 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
173k
  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
173k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1509
1510
173k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1511
173k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1512
147k
    {
1513
147k
      bfd_set_error (bfd_error_wrong_format);
1514
147k
      return NULL;
1515
147k
    }
1516
1517
26.2k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1518
26.2k
    sizeof (internal_f.pe.dos_message));
1519
1520
  /* Read the optional header, which has variable size.  */
1521
26.2k
  opt_hdr_size = internal_f.f_opthdr;
1522
1523
26.2k
  if (opt_hdr_size != 0)
1524
15.6k
    {
1525
15.6k
      bfd_size_type amt = opt_hdr_size;
1526
15.6k
      bfd_byte * opthdr;
1527
1528
      /* PR 17521 file: 230-131433-0.004.  */
1529
15.6k
      if (amt < sizeof (PEAOUTHDR))
1530
14.5k
  amt = sizeof (PEAOUTHDR);
1531
1532
15.6k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1533
15.6k
      if (opthdr == NULL)
1534
579
  return NULL;
1535
15.0k
      if (amt > opt_hdr_size)
1536
14.0k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1537
1538
15.0k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1539
1540
15.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
15.0k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1557
15.0k
    || a->SectionAlignment >= 0x80000000)
1558
8.59k
  {
1559
8.59k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1560
8.59k
        abfd);
1561
8.59k
    a->SectionAlignment &= -a->SectionAlignment;
1562
8.59k
    if (a->SectionAlignment >= 0x80000000)
1563
335
      a->SectionAlignment = 0x40000000;
1564
8.59k
  }
1565
1566
15.0k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1567
15.0k
    || a->FileAlignment > a->SectionAlignment)
1568
10.8k
  {
1569
10.8k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1570
10.8k
            abfd);
1571
10.8k
    a->FileAlignment &= -a->FileAlignment;
1572
10.8k
    if (a->FileAlignment > a->SectionAlignment)
1573
5.00k
      a->FileAlignment = a->SectionAlignment;
1574
10.8k
  }
1575
1576
15.0k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1577
12.6k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1578
15.0k
    }
1579
1580
25.6k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1581
25.6k
             (opt_hdr_size != 0
1582
25.6k
        ? &internal_a
1583
25.6k
        : (struct internal_aouthdr *) NULL));
1584
1585
25.6k
  if (result)
1586
13.4k
    {
1587
      /* Now the whole header has been processed, see if there is a build-id */
1588
13.4k
      pe_bfd_read_buildid(abfd);
1589
13.4k
    }
1590
1591
25.6k
  return result;
1592
26.2k
}
pei-loongarch64.c:pe_bfd_object_p
Line
Count
Source
1440
591k
{
1441
591k
  bfd_byte buffer[6];
1442
591k
  struct external_DOS_hdr dos_hdr;
1443
591k
  struct external_PEI_IMAGE_hdr image_hdr;
1444
591k
  struct internal_filehdr internal_f;
1445
591k
  struct internal_aouthdr internal_a;
1446
591k
  bfd_size_type opt_hdr_size;
1447
591k
  file_ptr offset;
1448
591k
  bfd_cleanup result;
1449
1450
  /* Detect if this a Microsoft Import Library Format element.  */
1451
  /* First read the beginning of the header.  */
1452
591k
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1453
591k
      || bfd_bread (buffer, (bfd_size_type) 6, abfd) != 6)
1454
1.27k
    {
1455
1.27k
      if (bfd_get_error () != bfd_error_system_call)
1456
1.16k
  bfd_set_error (bfd_error_wrong_format);
1457
1.27k
      return NULL;
1458
1.27k
    }
1459
1460
  /* Then check the magic and the version (only 0 is supported).  */
1461
590k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1462
590k
      && H_GET_16 (abfd, buffer + 4) == 0)
1463
8.81k
    return pe_ILF_object_p (abfd);
1464
1465
581k
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1466
581k
      || bfd_bread (&dos_hdr, (bfd_size_type) sizeof (dos_hdr), abfd)
1467
581k
   != sizeof (dos_hdr))
1468
113k
    {
1469
113k
      if (bfd_get_error () != bfd_error_system_call)
1470
113k
  bfd_set_error (bfd_error_wrong_format);
1471
113k
      return NULL;
1472
113k
    }
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
468k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1485
289k
    {
1486
289k
      bfd_set_error (bfd_error_wrong_format);
1487
289k
      return NULL;
1488
289k
    }
1489
1490
178k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1491
178k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1492
178k
      || (bfd_bread (&image_hdr, (bfd_size_type) sizeof (image_hdr), abfd)
1493
178k
    != sizeof (image_hdr)))
1494
844
    {
1495
844
      if (bfd_get_error () != bfd_error_system_call)
1496
844
  bfd_set_error (bfd_error_wrong_format);
1497
844
      return NULL;
1498
844
    }
1499
1500
178k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1501
4.33k
    {
1502
4.33k
      bfd_set_error (bfd_error_wrong_format);
1503
4.33k
      return NULL;
1504
4.33k
    }
1505
1506
  /* Swap file header, so that we get the location for calling
1507
     real_object_p.  */
1508
173k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1509
1510
173k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1511
173k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1512
152k
    {
1513
152k
      bfd_set_error (bfd_error_wrong_format);
1514
152k
      return NULL;
1515
152k
    }
1516
1517
20.7k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1518
20.7k
    sizeof (internal_f.pe.dos_message));
1519
1520
  /* Read the optional header, which has variable size.  */
1521
20.7k
  opt_hdr_size = internal_f.f_opthdr;
1522
1523
20.7k
  if (opt_hdr_size != 0)
1524
16.2k
    {
1525
16.2k
      bfd_size_type amt = opt_hdr_size;
1526
16.2k
      bfd_byte * opthdr;
1527
1528
      /* PR 17521 file: 230-131433-0.004.  */
1529
16.2k
      if (amt < sizeof (PEAOUTHDR))
1530
11.7k
  amt = sizeof (PEAOUTHDR);
1531
1532
16.2k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1533
16.2k
      if (opthdr == NULL)
1534
237
  return NULL;
1535
15.9k
      if (amt > opt_hdr_size)
1536
11.5k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1537
1538
15.9k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1539
1540
15.9k
      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
15.9k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1557
15.9k
    || a->SectionAlignment >= 0x80000000)
1558
21
  {
1559
21
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1560
21
        abfd);
1561
21
    a->SectionAlignment &= -a->SectionAlignment;
1562
21
    if (a->SectionAlignment >= 0x80000000)
1563
0
      a->SectionAlignment = 0x40000000;
1564
21
  }
1565
1566
15.9k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1567
15.9k
    || a->FileAlignment > a->SectionAlignment)
1568
15.0k
  {
1569
15.0k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1570
15.0k
            abfd);
1571
15.0k
    a->FileAlignment &= -a->FileAlignment;
1572
15.0k
    if (a->FileAlignment > a->SectionAlignment)
1573
13.2k
      a->FileAlignment = a->SectionAlignment;
1574
15.0k
  }
1575
1576
15.9k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1577
11.2k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1578
15.9k
    }
1579
1580
20.5k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1581
20.5k
             (opt_hdr_size != 0
1582
20.5k
        ? &internal_a
1583
20.5k
        : (struct internal_aouthdr *) NULL));
1584
1585
20.5k
  if (result)
1586
18.5k
    {
1587
      /* Now the whole header has been processed, see if there is a build-id */
1588
18.5k
      pe_bfd_read_buildid(abfd);
1589
18.5k
    }
1590
1591
20.5k
  return result;
1592
20.7k
}
pei-arm-wince.c:pe_bfd_object_p
Line
Count
Source
1440
1.18M
{
1441
1.18M
  bfd_byte buffer[6];
1442
1.18M
  struct external_DOS_hdr dos_hdr;
1443
1.18M
  struct external_PEI_IMAGE_hdr image_hdr;
1444
1.18M
  struct internal_filehdr internal_f;
1445
1.18M
  struct internal_aouthdr internal_a;
1446
1.18M
  bfd_size_type opt_hdr_size;
1447
1.18M
  file_ptr offset;
1448
1.18M
  bfd_cleanup result;
1449
1450
  /* Detect if this a Microsoft Import Library Format element.  */
1451
  /* First read the beginning of the header.  */
1452
1.18M
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1453
1.18M
      || bfd_bread (buffer, (bfd_size_type) 6, abfd) != 6)
1454
2.54k
    {
1455
2.54k
      if (bfd_get_error () != bfd_error_system_call)
1456
2.33k
  bfd_set_error (bfd_error_wrong_format);
1457
2.54k
      return NULL;
1458
2.54k
    }
1459
1460
  /* Then check the magic and the version (only 0 is supported).  */
1461
1.18M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1462
1.18M
      && H_GET_16 (abfd, buffer + 4) == 0)
1463
12.7k
    return pe_ILF_object_p (abfd);
1464
1465
1.16M
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1466
1.16M
      || bfd_bread (&dos_hdr, (bfd_size_type) sizeof (dos_hdr), abfd)
1467
1.16M
   != sizeof (dos_hdr))
1468
232k
    {
1469
232k
      if (bfd_get_error () != bfd_error_system_call)
1470
232k
  bfd_set_error (bfd_error_wrong_format);
1471
232k
      return NULL;
1472
232k
    }
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
934k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1485
755k
    {
1486
755k
      bfd_set_error (bfd_error_wrong_format);
1487
755k
      return NULL;
1488
755k
    }
1489
1490
178k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1491
178k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1492
178k
      || (bfd_bread (&image_hdr, (bfd_size_type) sizeof (image_hdr), abfd)
1493
178k
    != sizeof (image_hdr)))
1494
844
    {
1495
844
      if (bfd_get_error () != bfd_error_system_call)
1496
844
  bfd_set_error (bfd_error_wrong_format);
1497
844
      return NULL;
1498
844
    }
1499
1500
177k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1501
4.34k
    {
1502
4.34k
      bfd_set_error (bfd_error_wrong_format);
1503
4.34k
      return NULL;
1504
4.34k
    }
1505
1506
  /* Swap file header, so that we get the location for calling
1507
     real_object_p.  */
1508
173k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1509
1510
173k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1511
173k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1512
146k
    {
1513
146k
      bfd_set_error (bfd_error_wrong_format);
1514
146k
      return NULL;
1515
146k
    }
1516
1517
26.6k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1518
26.6k
    sizeof (internal_f.pe.dos_message));
1519
1520
  /* Read the optional header, which has variable size.  */
1521
26.6k
  opt_hdr_size = internal_f.f_opthdr;
1522
1523
26.6k
  if (opt_hdr_size != 0)
1524
14.7k
    {
1525
14.7k
      bfd_size_type amt = opt_hdr_size;
1526
14.7k
      bfd_byte * opthdr;
1527
1528
      /* PR 17521 file: 230-131433-0.004.  */
1529
14.7k
      if (amt < sizeof (PEAOUTHDR))
1530
14.3k
  amt = sizeof (PEAOUTHDR);
1531
1532
14.7k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1533
14.7k
      if (opthdr == NULL)
1534
474
  return NULL;
1535
14.2k
      if (amt > opt_hdr_size)
1536
14.1k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1537
1538
14.2k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1539
1540
14.2k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1541
1542
14.2k
#ifdef ARM
1543
      /* Use Subsystem to distinguish between pei-arm-little and
1544
   pei-arm-wince-little.  */
1545
14.2k
#ifdef WINCE
1546
14.2k
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1547
#else
1548
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1549
#endif
1550
9.06k
  {
1551
9.06k
    bfd_set_error (bfd_error_wrong_format);
1552
9.06k
    return NULL;
1553
9.06k
  }
1554
5.16k
#endif
1555
1556
5.16k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1557
5.16k
    || a->SectionAlignment >= 0x80000000)
1558
4.30k
  {
1559
4.30k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1560
4.30k
        abfd);
1561
4.30k
    a->SectionAlignment &= -a->SectionAlignment;
1562
4.30k
    if (a->SectionAlignment >= 0x80000000)
1563
101
      a->SectionAlignment = 0x40000000;
1564
4.30k
  }
1565
1566
5.16k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1567
5.16k
    || a->FileAlignment > a->SectionAlignment)
1568
4.93k
  {
1569
4.93k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1570
4.93k
            abfd);
1571
4.93k
    a->FileAlignment &= -a->FileAlignment;
1572
4.93k
    if (a->FileAlignment > a->SectionAlignment)
1573
1.40k
      a->FileAlignment = a->SectionAlignment;
1574
4.93k
  }
1575
1576
5.16k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1577
3.30k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1578
5.16k
    }
1579
1580
17.1k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1581
17.1k
             (opt_hdr_size != 0
1582
17.1k
        ? &internal_a
1583
17.1k
        : (struct internal_aouthdr *) NULL));
1584
1585
17.1k
  if (result)
1586
3.98k
    {
1587
      /* Now the whole header has been processed, see if there is a build-id */
1588
3.98k
      pe_bfd_read_buildid(abfd);
1589
3.98k
    }
1590
1591
17.1k
  return result;
1592
26.6k
}
pei-arm.c:pe_bfd_object_p
Line
Count
Source
1440
1.18M
{
1441
1.18M
  bfd_byte buffer[6];
1442
1.18M
  struct external_DOS_hdr dos_hdr;
1443
1.18M
  struct external_PEI_IMAGE_hdr image_hdr;
1444
1.18M
  struct internal_filehdr internal_f;
1445
1.18M
  struct internal_aouthdr internal_a;
1446
1.18M
  bfd_size_type opt_hdr_size;
1447
1.18M
  file_ptr offset;
1448
1.18M
  bfd_cleanup result;
1449
1450
  /* Detect if this a Microsoft Import Library Format element.  */
1451
  /* First read the beginning of the header.  */
1452
1.18M
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1453
1.18M
      || bfd_bread (buffer, (bfd_size_type) 6, abfd) != 6)
1454
2.54k
    {
1455
2.54k
      if (bfd_get_error () != bfd_error_system_call)
1456
2.33k
  bfd_set_error (bfd_error_wrong_format);
1457
2.54k
      return NULL;
1458
2.54k
    }
1459
1460
  /* Then check the magic and the version (only 0 is supported).  */
1461
1.18M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1462
1.18M
      && H_GET_16 (abfd, buffer + 4) == 0)
1463
14.5k
    return pe_ILF_object_p (abfd);
1464
1465
1.16M
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1466
1.16M
      || bfd_bread (&dos_hdr, (bfd_size_type) sizeof (dos_hdr), abfd)
1467
1.16M
   != sizeof (dos_hdr))
1468
234k
    {
1469
234k
      if (bfd_get_error () != bfd_error_system_call)
1470
234k
  bfd_set_error (bfd_error_wrong_format);
1471
234k
      return NULL;
1472
234k
    }
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
931k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1485
752k
    {
1486
752k
      bfd_set_error (bfd_error_wrong_format);
1487
752k
      return NULL;
1488
752k
    }
1489
1490
178k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1491
178k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1492
178k
      || (bfd_bread (&image_hdr, (bfd_size_type) sizeof (image_hdr), abfd)
1493
178k
    != sizeof (image_hdr)))
1494
844
    {
1495
844
      if (bfd_get_error () != bfd_error_system_call)
1496
844
  bfd_set_error (bfd_error_wrong_format);
1497
844
      return NULL;
1498
844
    }
1499
1500
177k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1501
4.34k
    {
1502
4.34k
      bfd_set_error (bfd_error_wrong_format);
1503
4.34k
      return NULL;
1504
4.34k
    }
1505
1506
  /* Swap file header, so that we get the location for calling
1507
     real_object_p.  */
1508
173k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1509
1510
173k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1511
173k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1512
146k
    {
1513
146k
      bfd_set_error (bfd_error_wrong_format);
1514
146k
      return NULL;
1515
146k
    }
1516
1517
26.6k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1518
26.6k
    sizeof (internal_f.pe.dos_message));
1519
1520
  /* Read the optional header, which has variable size.  */
1521
26.6k
  opt_hdr_size = internal_f.f_opthdr;
1522
1523
26.6k
  if (opt_hdr_size != 0)
1524
14.7k
    {
1525
14.7k
      bfd_size_type amt = opt_hdr_size;
1526
14.7k
      bfd_byte * opthdr;
1527
1528
      /* PR 17521 file: 230-131433-0.004.  */
1529
14.7k
      if (amt < sizeof (PEAOUTHDR))
1530
14.3k
  amt = sizeof (PEAOUTHDR);
1531
1532
14.7k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1533
14.7k
      if (opthdr == NULL)
1534
474
  return NULL;
1535
14.2k
      if (amt > opt_hdr_size)
1536
14.1k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1537
1538
14.2k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1539
1540
14.2k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1541
1542
14.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
14.2k
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1549
5.13k
#endif
1550
5.13k
  {
1551
5.13k
    bfd_set_error (bfd_error_wrong_format);
1552
5.13k
    return NULL;
1553
5.13k
  }
1554
9.10k
#endif
1555
1556
9.10k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1557
9.10k
    || a->SectionAlignment >= 0x80000000)
1558
6.37k
  {
1559
6.37k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1560
6.37k
        abfd);
1561
6.37k
    a->SectionAlignment &= -a->SectionAlignment;
1562
6.37k
    if (a->SectionAlignment >= 0x80000000)
1563
101
      a->SectionAlignment = 0x40000000;
1564
6.37k
  }
1565
1566
9.10k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1567
9.10k
    || a->FileAlignment > a->SectionAlignment)
1568
6.96k
  {
1569
6.96k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1570
6.96k
            abfd);
1571
6.96k
    a->FileAlignment &= -a->FileAlignment;
1572
6.96k
    if (a->FileAlignment > a->SectionAlignment)
1573
3.27k
      a->FileAlignment = a->SectionAlignment;
1574
6.96k
  }
1575
1576
9.10k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1577
6.33k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1578
9.10k
    }
1579
1580
21.0k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1581
21.0k
             (opt_hdr_size != 0
1582
21.0k
        ? &internal_a
1583
21.0k
        : (struct internal_aouthdr *) NULL));
1584
1585
21.0k
  if (result)
1586
5.96k
    {
1587
      /* Now the whole header has been processed, see if there is a build-id */
1588
5.96k
      pe_bfd_read_buildid(abfd);
1589
5.96k
    }
1590
1591
21.0k
  return result;
1592
26.6k
}
pei-mcore.c:pe_bfd_object_p
Line
Count
Source
1440
1.18M
{
1441
1.18M
  bfd_byte buffer[6];
1442
1.18M
  struct external_DOS_hdr dos_hdr;
1443
1.18M
  struct external_PEI_IMAGE_hdr image_hdr;
1444
1.18M
  struct internal_filehdr internal_f;
1445
1.18M
  struct internal_aouthdr internal_a;
1446
1.18M
  bfd_size_type opt_hdr_size;
1447
1.18M
  file_ptr offset;
1448
1.18M
  bfd_cleanup result;
1449
1450
  /* Detect if this a Microsoft Import Library Format element.  */
1451
  /* First read the beginning of the header.  */
1452
1.18M
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1453
1.18M
      || bfd_bread (buffer, (bfd_size_type) 6, abfd) != 6)
1454
2.54k
    {
1455
2.54k
      if (bfd_get_error () != bfd_error_system_call)
1456
2.33k
  bfd_set_error (bfd_error_wrong_format);
1457
2.54k
      return NULL;
1458
2.54k
    }
1459
1460
  /* Then check the magic and the version (only 0 is supported).  */
1461
1.18M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1462
1.18M
      && H_GET_16 (abfd, buffer + 4) == 0)
1463
11.2k
    return pe_ILF_object_p (abfd);
1464
1465
1.16M
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1466
1.16M
      || bfd_bread (&dos_hdr, (bfd_size_type) sizeof (dos_hdr), abfd)
1467
1.16M
   != sizeof (dos_hdr))
1468
233k
    {
1469
233k
      if (bfd_get_error () != bfd_error_system_call)
1470
233k
  bfd_set_error (bfd_error_wrong_format);
1471
233k
      return NULL;
1472
233k
    }
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
935k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1485
756k
    {
1486
756k
      bfd_set_error (bfd_error_wrong_format);
1487
756k
      return NULL;
1488
756k
    }
1489
1490
178k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1491
178k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1492
178k
      || (bfd_bread (&image_hdr, (bfd_size_type) sizeof (image_hdr), abfd)
1493
178k
    != sizeof (image_hdr)))
1494
844
    {
1495
844
      if (bfd_get_error () != bfd_error_system_call)
1496
844
  bfd_set_error (bfd_error_wrong_format);
1497
844
      return NULL;
1498
844
    }
1499
1500
178k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1501
4.34k
    {
1502
4.34k
      bfd_set_error (bfd_error_wrong_format);
1503
4.34k
      return NULL;
1504
4.34k
    }
1505
1506
  /* Swap file header, so that we get the location for calling
1507
     real_object_p.  */
1508
173k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1509
1510
173k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1511
173k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1512
151k
    {
1513
151k
      bfd_set_error (bfd_error_wrong_format);
1514
151k
      return NULL;
1515
151k
    }
1516
1517
22.3k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1518
22.3k
    sizeof (internal_f.pe.dos_message));
1519
1520
  /* Read the optional header, which has variable size.  */
1521
22.3k
  opt_hdr_size = internal_f.f_opthdr;
1522
1523
22.3k
  if (opt_hdr_size != 0)
1524
14.6k
    {
1525
14.6k
      bfd_size_type amt = opt_hdr_size;
1526
14.6k
      bfd_byte * opthdr;
1527
1528
      /* PR 17521 file: 230-131433-0.004.  */
1529
14.6k
      if (amt < sizeof (PEAOUTHDR))
1530
14.5k
  amt = sizeof (PEAOUTHDR);
1531
1532
14.6k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1533
14.6k
      if (opthdr == NULL)
1534
240
  return NULL;
1535
14.4k
      if (amt > opt_hdr_size)
1536
14.4k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1537
1538
14.4k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1539
1540
14.4k
      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
14.4k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1557
14.4k
    || a->SectionAlignment >= 0x80000000)
1558
10.4k
  {
1559
10.4k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1560
10.4k
        abfd);
1561
10.4k
    a->SectionAlignment &= -a->SectionAlignment;
1562
10.4k
    if (a->SectionAlignment >= 0x80000000)
1563
240
      a->SectionAlignment = 0x40000000;
1564
10.4k
  }
1565
1566
14.4k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1567
14.4k
    || a->FileAlignment > a->SectionAlignment)
1568
13.4k
  {
1569
13.4k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1570
13.4k
            abfd);
1571
13.4k
    a->FileAlignment &= -a->FileAlignment;
1572
13.4k
    if (a->FileAlignment > a->SectionAlignment)
1573
3.68k
      a->FileAlignment = a->SectionAlignment;
1574
13.4k
  }
1575
1576
14.4k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1577
10.9k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1578
14.4k
    }
1579
1580
22.1k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1581
22.1k
             (opt_hdr_size != 0
1582
22.1k
        ? &internal_a
1583
22.1k
        : (struct internal_aouthdr *) NULL));
1584
1585
22.1k
  if (result)
1586
13.3k
    {
1587
      /* Now the whole header has been processed, see if there is a build-id */
1588
13.3k
      pe_bfd_read_buildid(abfd);
1589
13.3k
    }
1590
1591
22.1k
  return result;
1592
22.3k
}
pei-sh.c:pe_bfd_object_p
Line
Count
Source
1440
591k
{
1441
591k
  bfd_byte buffer[6];
1442
591k
  struct external_DOS_hdr dos_hdr;
1443
591k
  struct external_PEI_IMAGE_hdr image_hdr;
1444
591k
  struct internal_filehdr internal_f;
1445
591k
  struct internal_aouthdr internal_a;
1446
591k
  bfd_size_type opt_hdr_size;
1447
591k
  file_ptr offset;
1448
591k
  bfd_cleanup result;
1449
1450
  /* Detect if this a Microsoft Import Library Format element.  */
1451
  /* First read the beginning of the header.  */
1452
591k
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1453
591k
      || bfd_bread (buffer, (bfd_size_type) 6, abfd) != 6)
1454
1.27k
    {
1455
1.27k
      if (bfd_get_error () != bfd_error_system_call)
1456
1.16k
  bfd_set_error (bfd_error_wrong_format);
1457
1.27k
      return NULL;
1458
1.27k
    }
1459
1460
  /* Then check the magic and the version (only 0 is supported).  */
1461
590k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1462
590k
      && H_GET_16 (abfd, buffer + 4) == 0)
1463
11.2k
    return pe_ILF_object_p (abfd);
1464
1465
578k
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1466
578k
      || bfd_bread (&dos_hdr, (bfd_size_type) sizeof (dos_hdr), abfd)
1467
578k
   != sizeof (dos_hdr))
1468
111k
    {
1469
111k
      if (bfd_get_error () != bfd_error_system_call)
1470
111k
  bfd_set_error (bfd_error_wrong_format);
1471
111k
      return NULL;
1472
111k
    }
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
466k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1485
288k
    {
1486
288k
      bfd_set_error (bfd_error_wrong_format);
1487
288k
      return NULL;
1488
288k
    }
1489
1490
178k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1491
178k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1492
178k
      || (bfd_bread (&image_hdr, (bfd_size_type) sizeof (image_hdr), abfd)
1493
178k
    != sizeof (image_hdr)))
1494
844
    {
1495
844
      if (bfd_get_error () != bfd_error_system_call)
1496
844
  bfd_set_error (bfd_error_wrong_format);
1497
844
      return NULL;
1498
844
    }
1499
1500
178k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1501
4.33k
    {
1502
4.33k
      bfd_set_error (bfd_error_wrong_format);
1503
4.33k
      return NULL;
1504
4.33k
    }
1505
1506
  /* Swap file header, so that we get the location for calling
1507
     real_object_p.  */
1508
173k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1509
1510
173k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1511
173k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1512
157k
    {
1513
157k
      bfd_set_error (bfd_error_wrong_format);
1514
157k
      return NULL;
1515
157k
    }
1516
1517
16.4k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1518
16.4k
    sizeof (internal_f.pe.dos_message));
1519
1520
  /* Read the optional header, which has variable size.  */
1521
16.4k
  opt_hdr_size = internal_f.f_opthdr;
1522
1523
16.4k
  if (opt_hdr_size != 0)
1524
8.54k
    {
1525
8.54k
      bfd_size_type amt = opt_hdr_size;
1526
8.54k
      bfd_byte * opthdr;
1527
1528
      /* PR 17521 file: 230-131433-0.004.  */
1529
8.54k
      if (amt < sizeof (PEAOUTHDR))
1530
7.97k
  amt = sizeof (PEAOUTHDR);
1531
1532
8.54k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1533
8.54k
      if (opthdr == NULL)
1534
240
  return NULL;
1535
8.30k
      if (amt > opt_hdr_size)
1536
7.96k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1537
1538
8.30k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1539
1540
8.30k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1541
1542
#ifdef ARM
1543
      /* Use Subsystem to distinguish between pei-arm-little and
1544
   pei-arm-wince-little.  */
1545
#ifdef WINCE
1546
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1547
#else
1548
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1549
#endif
1550
  {
1551
    bfd_set_error (bfd_error_wrong_format);
1552
    return NULL;
1553
  }
1554
#endif
1555
1556
8.30k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1557
8.30k
    || a->SectionAlignment >= 0x80000000)
1558
2.27k
  {
1559
2.27k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1560
2.27k
        abfd);
1561
2.27k
    a->SectionAlignment &= -a->SectionAlignment;
1562
2.27k
    if (a->SectionAlignment >= 0x80000000)
1563
117
      a->SectionAlignment = 0x40000000;
1564
2.27k
  }
1565
1566
8.30k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1567
8.30k
    || a->FileAlignment > a->SectionAlignment)
1568
7.11k
  {
1569
7.11k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1570
7.11k
            abfd);
1571
7.11k
    a->FileAlignment &= -a->FileAlignment;
1572
7.11k
    if (a->FileAlignment > a->SectionAlignment)
1573
4.75k
      a->FileAlignment = a->SectionAlignment;
1574
7.11k
  }
1575
1576
8.30k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1577
6.37k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1578
8.30k
    }
1579
1580
16.2k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1581
16.2k
             (opt_hdr_size != 0
1582
16.2k
        ? &internal_a
1583
16.2k
        : (struct internal_aouthdr *) NULL));
1584
1585
16.2k
  if (result)
1586
10.3k
    {
1587
      /* Now the whole header has been processed, see if there is a build-id */
1588
10.3k
      pe_bfd_read_buildid(abfd);
1589
10.3k
    }
1590
1591
16.2k
  return result;
1592
16.4k
}
1593
1594
173k
#define coff_object_p pe_bfd_object_p
1595
#endif /* COFF_IMAGE_WITH_PE */