Coverage Report

Created: 2023-08-28 06:25

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