Coverage Report

Created: 2023-08-28 06:30

/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
837
{
132
837
  RELOC *reloc_src = (RELOC *) src;
133
837
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
837
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
837
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
837
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
#ifdef SWAP_IN_RELOC_OFFSET
139
244
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
#endif
141
837
}
pei-i386.c:coff_swap_reloc_in
Line
Count
Source
131
16
{
132
16
  RELOC *reloc_src = (RELOC *) src;
133
16
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
16
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
16
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
16
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
#ifdef SWAP_IN_RELOC_OFFSET
139
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
#endif
141
16
}
pe-x86_64.c:coff_swap_reloc_in
Line
Count
Source
131
119
{
132
119
  RELOC *reloc_src = (RELOC *) src;
133
119
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
119
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
119
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
119
  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
119
}
pei-x86_64.c:coff_swap_reloc_in
Line
Count
Source
131
13
{
132
13
  RELOC *reloc_src = (RELOC *) src;
133
13
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
13
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
13
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
13
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
#ifdef SWAP_IN_RELOC_OFFSET
139
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
#endif
141
13
}
pe-aarch64.c:coff_swap_reloc_in
Line
Count
Source
131
93
{
132
93
  RELOC *reloc_src = (RELOC *) src;
133
93
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
93
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
93
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
93
  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
93
}
pei-aarch64.c:coff_swap_reloc_in
Line
Count
Source
131
50
{
132
50
  RELOC *reloc_src = (RELOC *) src;
133
50
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
50
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
50
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
50
  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
50
}
pei-ia64.c:coff_swap_reloc_in
Line
Count
Source
131
48
{
132
48
  RELOC *reloc_src = (RELOC *) src;
133
48
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
48
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
48
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
48
  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
48
}
pei-loongarch64.c:coff_swap_reloc_in
Line
Count
Source
131
23
{
132
23
  RELOC *reloc_src = (RELOC *) src;
133
23
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
23
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
23
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
23
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
23
#ifdef SWAP_IN_RELOC_OFFSET
139
23
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
23
#endif
141
23
}
pe-arm-wince.c:coff_swap_reloc_in
Line
Count
Source
131
10
{
132
10
  RELOC *reloc_src = (RELOC *) src;
133
10
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
10
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
10
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
10
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
10
#ifdef SWAP_IN_RELOC_OFFSET
139
10
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
10
#endif
141
10
}
pe-arm.c:coff_swap_reloc_in
Line
Count
Source
131
10
{
132
10
  RELOC *reloc_src = (RELOC *) src;
133
10
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
10
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
10
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
10
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
10
#ifdef SWAP_IN_RELOC_OFFSET
139
10
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
10
#endif
141
10
}
pe-i386.c:coff_swap_reloc_in
Line
Count
Source
131
210
{
132
210
  RELOC *reloc_src = (RELOC *) src;
133
210
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
210
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
210
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
210
  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
210
}
pe-mcore.c:coff_swap_reloc_in
Line
Count
Source
131
21
{
132
21
  RELOC *reloc_src = (RELOC *) src;
133
21
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
21
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
21
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
21
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
21
#ifdef SWAP_IN_RELOC_OFFSET
139
21
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
21
#endif
141
21
}
pe-sh.c:coff_swap_reloc_in
Line
Count
Source
131
35
{
132
35
  RELOC *reloc_src = (RELOC *) src;
133
35
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
35
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
35
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
35
  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
35
}
pei-arm-wince.c:coff_swap_reloc_in
Line
Count
Source
131
8
{
132
8
  RELOC *reloc_src = (RELOC *) src;
133
8
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
8
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
8
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
8
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
8
#ifdef SWAP_IN_RELOC_OFFSET
139
8
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
8
#endif
141
8
}
pei-arm.c:coff_swap_reloc_in
Line
Count
Source
131
145
{
132
145
  RELOC *reloc_src = (RELOC *) src;
133
145
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
145
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
145
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
145
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
145
#ifdef SWAP_IN_RELOC_OFFSET
139
145
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
145
#endif
141
145
}
pei-mcore.c:coff_swap_reloc_in
Line
Count
Source
131
27
{
132
27
  RELOC *reloc_src = (RELOC *) src;
133
27
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
27
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
27
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
27
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
27
#ifdef SWAP_IN_RELOC_OFFSET
139
27
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
27
#endif
141
27
}
pei-sh.c:coff_swap_reloc_in
Line
Count
Source
131
9
{
132
9
  RELOC *reloc_src = (RELOC *) src;
133
9
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
9
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
9
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
9
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
#ifdef SWAP_IN_RELOC_OFFSET
139
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
#endif
141
9
}
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
34.3k
#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
355k
{
171
355k
  FILHDR *filehdr_src = (FILHDR *) src;
172
355k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
355k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
355k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
355k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
355k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
355k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
355k
  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
355k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
95.4k
    {
185
95.4k
      filehdr_dst->f_nsyms = 0;
186
95.4k
      filehdr_dst->f_flags |= F_LSYMS;
187
95.4k
    }
188
189
355k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
355k
}
pei-i386.c:coff_swap_filehdr_in
Line
Count
Source
170
4.35k
{
171
4.35k
  FILHDR *filehdr_src = (FILHDR *) src;
172
4.35k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
4.35k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
4.35k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
4.35k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
4.35k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
4.35k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
4.35k
  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
4.35k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
3.16k
    {
185
3.16k
      filehdr_dst->f_nsyms = 0;
186
3.16k
      filehdr_dst->f_flags |= F_LSYMS;
187
3.16k
    }
188
189
4.35k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
4.35k
}
pe-x86_64.c:coff_swap_filehdr_in
Line
Count
Source
170
40.3k
{
171
40.3k
  FILHDR *filehdr_src = (FILHDR *) src;
172
40.3k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
40.3k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
40.3k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
40.3k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
40.3k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
40.3k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
40.3k
  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
40.3k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
9.45k
    {
185
9.45k
      filehdr_dst->f_nsyms = 0;
186
9.45k
      filehdr_dst->f_flags |= F_LSYMS;
187
9.45k
    }
188
189
40.3k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
40.3k
}
pei-x86_64.c:coff_swap_filehdr_in
Line
Count
Source
170
4.39k
{
171
4.39k
  FILHDR *filehdr_src = (FILHDR *) src;
172
4.39k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
4.39k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
4.39k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
4.39k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
4.39k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
4.39k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
4.39k
  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
4.39k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
3.18k
    {
185
3.18k
      filehdr_dst->f_nsyms = 0;
186
3.18k
      filehdr_dst->f_flags |= F_LSYMS;
187
3.18k
    }
188
189
4.39k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
4.39k
}
pe-aarch64.c:coff_swap_filehdr_in
Line
Count
Source
170
40.2k
{
171
40.2k
  FILHDR *filehdr_src = (FILHDR *) src;
172
40.2k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
40.2k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
40.2k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
40.2k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
40.2k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
40.2k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
40.2k
  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
40.2k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
9.45k
    {
185
9.45k
      filehdr_dst->f_nsyms = 0;
186
9.45k
      filehdr_dst->f_flags |= F_LSYMS;
187
9.45k
    }
188
189
40.2k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
40.2k
}
pei-aarch64.c:coff_swap_filehdr_in
Line
Count
Source
170
4.35k
{
171
4.35k
  FILHDR *filehdr_src = (FILHDR *) src;
172
4.35k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
4.35k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
4.35k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
4.35k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
4.35k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
4.35k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
4.35k
  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
4.35k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
3.16k
    {
185
3.16k
      filehdr_dst->f_nsyms = 0;
186
3.16k
      filehdr_dst->f_flags |= F_LSYMS;
187
3.16k
    }
188
189
4.35k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
4.35k
}
pei-ia64.c:coff_swap_filehdr_in
Line
Count
Source
170
698
{
171
698
  FILHDR *filehdr_src = (FILHDR *) src;
172
698
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
698
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
698
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
698
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
698
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
698
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
698
  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
698
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
82
    {
185
82
      filehdr_dst->f_nsyms = 0;
186
82
      filehdr_dst->f_flags |= F_LSYMS;
187
82
    }
188
189
698
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
698
}
pei-loongarch64.c:coff_swap_filehdr_in
Line
Count
Source
170
4.33k
{
171
4.33k
  FILHDR *filehdr_src = (FILHDR *) src;
172
4.33k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
4.33k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
4.33k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
4.33k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
4.33k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
4.33k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
4.33k
  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
4.33k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
3.16k
    {
185
3.16k
      filehdr_dst->f_nsyms = 0;
186
3.16k
      filehdr_dst->f_flags |= F_LSYMS;
187
3.16k
    }
188
189
4.33k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
4.33k
}
pe-arm-wince.c:coff_swap_filehdr_in
Line
Count
Source
170
57.1k
{
171
57.1k
  FILHDR *filehdr_src = (FILHDR *) src;
172
57.1k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
57.1k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
57.1k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
57.1k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
57.1k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
57.1k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
57.1k
  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
57.1k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
11.9k
    {
185
11.9k
      filehdr_dst->f_nsyms = 0;
186
11.9k
      filehdr_dst->f_flags |= F_LSYMS;
187
11.9k
    }
188
189
57.1k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
57.1k
}
pe-arm.c:coff_swap_filehdr_in
Line
Count
Source
170
57.1k
{
171
57.1k
  FILHDR *filehdr_src = (FILHDR *) src;
172
57.1k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
57.1k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
57.1k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
57.1k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
57.1k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
57.1k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
57.1k
  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
57.1k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
11.9k
    {
185
11.9k
      filehdr_dst->f_nsyms = 0;
186
11.9k
      filehdr_dst->f_flags |= F_LSYMS;
187
11.9k
    }
188
189
57.1k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
57.1k
}
pe-i386.c:coff_swap_filehdr_in
Line
Count
Source
170
40.2k
{
171
40.2k
  FILHDR *filehdr_src = (FILHDR *) src;
172
40.2k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
40.2k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
40.2k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
40.2k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
40.2k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
40.2k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
40.2k
  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
40.2k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
9.45k
    {
185
9.45k
      filehdr_dst->f_nsyms = 0;
186
9.45k
      filehdr_dst->f_flags |= F_LSYMS;
187
9.45k
    }
188
189
40.2k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
40.2k
}
pe-mcore.c:coff_swap_filehdr_in
Line
Count
Source
170
57.1k
{
171
57.1k
  FILHDR *filehdr_src = (FILHDR *) src;
172
57.1k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
57.1k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
57.1k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
57.1k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
57.1k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
57.1k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
57.1k
  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
57.1k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
11.9k
    {
185
11.9k
      filehdr_dst->f_nsyms = 0;
186
11.9k
      filehdr_dst->f_flags |= F_LSYMS;
187
11.9k
    }
188
189
57.1k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
57.1k
}
pe-sh.c:coff_swap_filehdr_in
Line
Count
Source
170
28.5k
{
171
28.5k
  FILHDR *filehdr_src = (FILHDR *) src;
172
28.5k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
28.5k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
28.5k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
28.5k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
28.5k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
28.5k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
28.5k
  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
28.5k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
5.99k
    {
185
5.99k
      filehdr_dst->f_nsyms = 0;
186
5.99k
      filehdr_dst->f_flags |= F_LSYMS;
187
5.99k
    }
188
189
28.5k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
28.5k
}
pei-arm-wince.c:coff_swap_filehdr_in
Line
Count
Source
170
4.06k
{
171
4.06k
  FILHDR *filehdr_src = (FILHDR *) src;
172
4.06k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
4.06k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
4.06k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
4.06k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
4.06k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
4.06k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
4.06k
  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
4.06k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
3.07k
    {
185
3.07k
      filehdr_dst->f_nsyms = 0;
186
3.07k
      filehdr_dst->f_flags |= F_LSYMS;
187
3.07k
    }
188
189
4.06k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
4.06k
}
pei-arm.c:coff_swap_filehdr_in
Line
Count
Source
170
4.06k
{
171
4.06k
  FILHDR *filehdr_src = (FILHDR *) src;
172
4.06k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
4.06k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
4.06k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
4.06k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
4.06k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
4.06k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
4.06k
  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
4.06k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
3.07k
    {
185
3.07k
      filehdr_dst->f_nsyms = 0;
186
3.07k
      filehdr_dst->f_flags |= F_LSYMS;
187
3.07k
    }
188
189
4.06k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
4.06k
}
pei-mcore.c:coff_swap_filehdr_in
Line
Count
Source
170
4.05k
{
171
4.05k
  FILHDR *filehdr_src = (FILHDR *) src;
172
4.05k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
4.05k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
4.05k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
4.05k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
4.05k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
4.05k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
4.05k
  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
4.05k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
3.07k
    {
185
3.07k
      filehdr_dst->f_nsyms = 0;
186
3.07k
      filehdr_dst->f_flags |= F_LSYMS;
187
3.07k
    }
188
189
4.05k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
4.05k
}
pei-sh.c:coff_swap_filehdr_in
Line
Count
Source
170
4.05k
{
171
4.05k
  FILHDR *filehdr_src = (FILHDR *) src;
172
4.05k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
4.05k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
4.05k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
4.05k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
4.05k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
4.05k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
4.05k
  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
4.05k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
3.07k
    {
185
3.07k
      filehdr_dst->f_nsyms = 0;
186
3.07k
      filehdr_dst->f_flags |= F_LSYMS;
187
3.07k
    }
188
189
4.05k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
4.05k
}
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
30.5k
{
207
30.5k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
30.5k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
30.5k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
30.5k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
30.5k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
30.5k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
30.5k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
30.5k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
30.5k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
30.5k
  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
23.2k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
23.2k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
  scnhdr_int->s_nreloc = 0;
227
#else
228
7.29k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
7.29k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
#endif
231
232
30.5k
  if (scnhdr_int->s_vaddr != 0)
233
25.4k
    {
234
25.4k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
      scnhdr_int->s_vaddr &= 0xffffffff;
238
#endif
239
25.4k
    }
240
241
30.5k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
30.5k
  if (scnhdr_int->s_paddr > 0
247
30.5k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
22.9k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
22.9k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
9.37k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
30.5k
#endif
256
30.5k
}
pei-i386.c:coff_swap_scnhdr_in
Line
Count
Source
206
1.14k
{
207
1.14k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
1.14k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
1.14k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
1.14k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
1.14k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
1.14k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
1.14k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
1.14k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
1.14k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
1.14k
  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
1.14k
#ifdef COFF_IMAGE_WITH_PE
224
1.14k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
1.14k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
1.14k
  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
1.14k
  if (scnhdr_int->s_vaddr != 0)
233
958
    {
234
958
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
958
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
958
      scnhdr_int->s_vaddr &= 0xffffffff;
238
958
#endif
239
958
    }
240
241
1.14k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
1.14k
  if (scnhdr_int->s_paddr > 0
247
1.14k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
988
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
988
    || (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
642
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
1.14k
#endif
256
1.14k
}
pe-x86_64.c:coff_swap_scnhdr_in
Line
Count
Source
206
1.91k
{
207
1.91k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
1.91k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
1.91k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
1.91k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
1.91k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
1.91k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
1.91k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
1.91k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
1.91k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
1.91k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
#ifdef COFF_IMAGE_WITH_PE
224
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
  scnhdr_int->s_nreloc = 0;
227
#else
228
1.91k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
1.91k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
1.91k
#endif
231
232
1.91k
  if (scnhdr_int->s_vaddr != 0)
233
1.19k
    {
234
1.19k
      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.19k
    }
240
241
1.91k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
1.91k
  if (scnhdr_int->s_paddr > 0
247
1.91k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
1.24k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
1.24k
    || (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
259
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
1.91k
#endif
256
1.91k
}
pei-x86_64.c:coff_swap_scnhdr_in
Line
Count
Source
206
923
{
207
923
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
923
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
923
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
923
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
923
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
923
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
923
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
923
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
923
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
923
  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
923
#ifdef COFF_IMAGE_WITH_PE
224
923
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
923
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
923
  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
923
  if (scnhdr_int->s_vaddr != 0)
233
694
    {
234
694
      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
694
    }
240
241
923
#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
923
  if (scnhdr_int->s_paddr > 0
247
923
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
655
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
655
    || (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
309
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
923
#endif
256
923
}
pe-aarch64.c:coff_swap_scnhdr_in
Line
Count
Source
206
2.30k
{
207
2.30k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
2.30k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
2.30k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
2.30k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
2.30k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
2.30k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
2.30k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
2.30k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
2.30k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
2.30k
  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.30k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
2.30k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
2.30k
#endif
231
232
2.30k
  if (scnhdr_int->s_vaddr != 0)
233
2.03k
    {
234
2.03k
      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
2.03k
    }
240
241
2.30k
#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.30k
  if (scnhdr_int->s_paddr > 0
247
2.30k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
1.86k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
1.86k
    || (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
67
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
2.30k
#endif
256
2.30k
}
pei-aarch64.c:coff_swap_scnhdr_in
Line
Count
Source
206
15.0k
{
207
15.0k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
15.0k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
15.0k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
15.0k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
15.0k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
15.0k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
15.0k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
15.0k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
15.0k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
15.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
15.0k
#ifdef COFF_IMAGE_WITH_PE
224
15.0k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
15.0k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
15.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
15.0k
  if (scnhdr_int->s_vaddr != 0)
233
14.4k
    {
234
14.4k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
      scnhdr_int->s_vaddr &= 0xffffffff;
238
#endif
239
14.4k
    }
240
241
15.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
15.0k
  if (scnhdr_int->s_paddr > 0
247
15.0k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
12.2k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
12.2k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
5.93k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
15.0k
#endif
256
15.0k
}
pei-ia64.c:coff_swap_scnhdr_in
Line
Count
Source
206
2.43k
{
207
2.43k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
2.43k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
2.43k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
2.43k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
2.43k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
2.43k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
2.43k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
2.43k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
2.43k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
2.43k
  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.43k
#ifdef COFF_IMAGE_WITH_PE
224
2.43k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
2.43k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
2.43k
  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.43k
  if (scnhdr_int->s_vaddr != 0)
233
1.53k
    {
234
1.53k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
1.53k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
1.53k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
1.53k
#endif
239
1.53k
    }
240
241
2.43k
#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.43k
  if (scnhdr_int->s_paddr > 0
247
2.43k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
1.34k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
1.34k
    || (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
717
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
2.43k
#endif
256
2.43k
}
pei-loongarch64.c:coff_swap_scnhdr_in
Line
Count
Source
206
673
{
207
673
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
673
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
673
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
673
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
673
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
673
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
673
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
673
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
673
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
673
  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
673
#ifdef COFF_IMAGE_WITH_PE
224
673
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
673
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
673
  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
673
  if (scnhdr_int->s_vaddr != 0)
233
604
    {
234
604
      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
604
    }
240
241
673
#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
673
  if (scnhdr_int->s_paddr > 0
247
673
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
528
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
528
    || (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
226
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
673
#endif
256
673
}
pe-arm-wince.c:coff_swap_scnhdr_in
Line
Count
Source
206
119
{
207
119
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
119
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
119
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
119
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
119
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
119
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
119
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
119
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
119
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
119
  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
119
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
119
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
119
#endif
231
232
119
  if (scnhdr_int->s_vaddr != 0)
233
91
    {
234
91
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
91
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
91
      scnhdr_int->s_vaddr &= 0xffffffff;
238
91
#endif
239
91
    }
240
241
119
#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
119
  if (scnhdr_int->s_paddr > 0
247
119
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
85
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
85
    || (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
31
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
119
#endif
256
119
}
pe-arm.c:coff_swap_scnhdr_in
Line
Count
Source
206
119
{
207
119
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
119
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
119
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
119
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
119
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
119
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
119
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
119
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
119
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
119
  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
119
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
119
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
119
#endif
231
232
119
  if (scnhdr_int->s_vaddr != 0)
233
91
    {
234
91
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
91
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
91
      scnhdr_int->s_vaddr &= 0xffffffff;
238
91
#endif
239
91
    }
240
241
119
#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
119
  if (scnhdr_int->s_paddr > 0
247
119
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
85
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
85
    || (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
31
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
119
#endif
256
119
}
pe-i386.c:coff_swap_scnhdr_in
Line
Count
Source
206
2.02k
{
207
2.02k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
2.02k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
2.02k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
2.02k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
2.02k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
2.02k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
2.02k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
2.02k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
2.02k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
2.02k
  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.02k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
2.02k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
2.02k
#endif
231
232
2.02k
  if (scnhdr_int->s_vaddr != 0)
233
1.33k
    {
234
1.33k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
1.33k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
1.33k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
1.33k
#endif
239
1.33k
    }
240
241
2.02k
#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.02k
  if (scnhdr_int->s_paddr > 0
247
2.02k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
1.28k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
1.28k
    || (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
176
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
2.02k
#endif
256
2.02k
}
pe-mcore.c:coff_swap_scnhdr_in
Line
Count
Source
206
531
{
207
531
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
531
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
531
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
531
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
531
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
531
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
531
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
531
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
531
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
531
  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
531
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
531
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
531
#endif
231
232
531
  if (scnhdr_int->s_vaddr != 0)
233
181
    {
234
181
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
181
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
181
      scnhdr_int->s_vaddr &= 0xffffffff;
238
181
#endif
239
181
    }
240
241
531
#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
531
  if (scnhdr_int->s_paddr > 0
247
531
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
185
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
185
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
26
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
531
#endif
256
531
}
pe-sh.c:coff_swap_scnhdr_in
Line
Count
Source
206
287
{
207
287
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
287
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
287
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
287
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
287
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
287
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
287
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
287
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
287
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
287
  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
287
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
287
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
287
#endif
231
232
287
  if (scnhdr_int->s_vaddr != 0)
233
181
    {
234
181
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
181
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
181
      scnhdr_int->s_vaddr &= 0xffffffff;
238
181
#endif
239
181
    }
240
241
287
#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
287
  if (scnhdr_int->s_paddr > 0
247
287
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
194
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
194
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
57
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
287
#endif
256
287
}
pei-arm-wince.c:coff_swap_scnhdr_in
Line
Count
Source
206
333
{
207
333
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
333
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
333
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
333
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
333
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
333
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
333
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
333
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
333
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
333
  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
333
#ifdef COFF_IMAGE_WITH_PE
224
333
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
333
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
333
  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
333
  if (scnhdr_int->s_vaddr != 0)
233
240
    {
234
240
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
240
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
240
      scnhdr_int->s_vaddr &= 0xffffffff;
238
240
#endif
239
240
    }
240
241
333
#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
333
  if (scnhdr_int->s_paddr > 0
247
333
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
267
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
267
    || (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
112
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
333
#endif
256
333
}
pei-arm.c:coff_swap_scnhdr_in
Line
Count
Source
206
1.03k
{
207
1.03k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
1.03k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
1.03k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
1.03k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
1.03k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
1.03k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
1.03k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
1.03k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
1.03k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
1.03k
  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
1.03k
#ifdef COFF_IMAGE_WITH_PE
224
1.03k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
1.03k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
1.03k
  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
1.03k
  if (scnhdr_int->s_vaddr != 0)
233
785
    {
234
785
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
785
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
785
      scnhdr_int->s_vaddr &= 0xffffffff;
238
785
#endif
239
785
    }
240
241
1.03k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
1.03k
  if (scnhdr_int->s_paddr > 0
247
1.03k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
762
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
762
    || (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
364
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
1.03k
#endif
256
1.03k
}
pei-mcore.c:coff_swap_scnhdr_in
Line
Count
Source
206
851
{
207
851
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
851
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
851
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
851
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
851
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
851
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
851
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
851
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
851
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
851
  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
851
#ifdef COFF_IMAGE_WITH_PE
224
851
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
851
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
851
  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
851
  if (scnhdr_int->s_vaddr != 0)
233
565
    {
234
565
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
565
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
565
      scnhdr_int->s_vaddr &= 0xffffffff;
238
565
#endif
239
565
    }
240
241
851
#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
851
  if (scnhdr_int->s_paddr > 0
247
851
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
606
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
606
    || (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
247
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
851
#endif
256
851
}
pei-sh.c:coff_swap_scnhdr_in
Line
Count
Source
206
790
{
207
790
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
790
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
790
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
790
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
790
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
790
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
790
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
790
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
790
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
790
  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
790
#ifdef COFF_IMAGE_WITH_PE
224
790
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
790
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
790
  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
790
  if (scnhdr_int->s_vaddr != 0)
233
551
    {
234
551
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
551
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
551
      scnhdr_int->s_vaddr &= 0xffffffff;
238
551
#endif
239
551
    }
240
241
790
#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
790
  if (scnhdr_int->s_paddr > 0
247
790
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
685
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
685
    || (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
182
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
790
#endif
256
790
}
257
258
static bool
259
pe_mkobject (bfd * abfd)
260
9.14k
{
261
  /* Some x86 code followed by an ascii string.  */
262
9.14k
  static const char default_dos_message[64] = {
263
9.14k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
264
9.14k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
265
9.14k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
266
9.14k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
267
9.14k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
268
9.14k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
269
9.14k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
270
9.14k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
271
272
9.14k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
273
9.14k
  abfd->tdata.pe_obj_data = pe;
274
9.14k
  if (pe == NULL)
275
0
    return false;
276
277
9.14k
  pe->coff.pe = 1;
278
279
  /* in_reloc_p is architecture dependent.  */
280
9.14k
  pe->in_reloc_p = in_reloc_p;
281
282
9.14k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
283
284
9.14k
  bfd_coff_long_section_names (abfd)
285
9.14k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
286
287
9.14k
  return true;
288
9.14k
}
pei-i386.c:pe_mkobject
Line
Count
Source
260
238
{
261
  /* Some x86 code followed by an ascii string.  */
262
238
  static const char default_dos_message[64] = {
263
238
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
264
238
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
265
238
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
266
238
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
267
238
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
268
238
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
269
238
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
270
238
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
271
272
238
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
273
238
  abfd->tdata.pe_obj_data = pe;
274
238
  if (pe == NULL)
275
0
    return false;
276
277
238
  pe->coff.pe = 1;
278
279
  /* in_reloc_p is architecture dependent.  */
280
238
  pe->in_reloc_p = in_reloc_p;
281
282
238
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
283
284
238
  bfd_coff_long_section_names (abfd)
285
238
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
286
287
238
  return true;
288
238
}
pe-x86_64.c:pe_mkobject
Line
Count
Source
260
726
{
261
  /* Some x86 code followed by an ascii string.  */
262
726
  static const char default_dos_message[64] = {
263
726
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
264
726
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
265
726
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
266
726
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
267
726
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
268
726
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
269
726
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
270
726
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
271
272
726
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
273
726
  abfd->tdata.pe_obj_data = pe;
274
726
  if (pe == NULL)
275
0
    return false;
276
277
726
  pe->coff.pe = 1;
278
279
  /* in_reloc_p is architecture dependent.  */
280
726
  pe->in_reloc_p = in_reloc_p;
281
282
726
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
283
284
726
  bfd_coff_long_section_names (abfd)
285
726
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
286
287
726
  return true;
288
726
}
pei-x86_64.c:pe_mkobject
Line
Count
Source
260
259
{
261
  /* Some x86 code followed by an ascii string.  */
262
259
  static const char default_dos_message[64] = {
263
259
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
264
259
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
265
259
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
266
259
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
267
259
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
268
259
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
269
259
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
270
259
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
271
272
259
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
273
259
  abfd->tdata.pe_obj_data = pe;
274
259
  if (pe == NULL)
275
0
    return false;
276
277
259
  pe->coff.pe = 1;
278
279
  /* in_reloc_p is architecture dependent.  */
280
259
  pe->in_reloc_p = in_reloc_p;
281
282
259
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
283
284
259
  bfd_coff_long_section_names (abfd)
285
259
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
286
287
259
  return true;
288
259
}
pe-aarch64.c:pe_mkobject
Line
Count
Source
260
1.83k
{
261
  /* Some x86 code followed by an ascii string.  */
262
1.83k
  static const char default_dos_message[64] = {
263
1.83k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
264
1.83k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
265
1.83k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
266
1.83k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
267
1.83k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
268
1.83k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
269
1.83k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
270
1.83k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
271
272
1.83k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
273
1.83k
  abfd->tdata.pe_obj_data = pe;
274
1.83k
  if (pe == NULL)
275
0
    return false;
276
277
1.83k
  pe->coff.pe = 1;
278
279
  /* in_reloc_p is architecture dependent.  */
280
1.83k
  pe->in_reloc_p = in_reloc_p;
281
282
1.83k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
283
284
1.83k
  bfd_coff_long_section_names (abfd)
285
1.83k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
286
287
1.83k
  return true;
288
1.83k
}
pei-aarch64.c:pe_mkobject
Line
Count
Source
260
2.98k
{
261
  /* Some x86 code followed by an ascii string.  */
262
2.98k
  static const char default_dos_message[64] = {
263
2.98k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
264
2.98k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
265
2.98k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
266
2.98k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
267
2.98k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
268
2.98k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
269
2.98k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
270
2.98k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
271
272
2.98k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
273
2.98k
  abfd->tdata.pe_obj_data = pe;
274
2.98k
  if (pe == NULL)
275
0
    return false;
276
277
2.98k
  pe->coff.pe = 1;
278
279
  /* in_reloc_p is architecture dependent.  */
280
2.98k
  pe->in_reloc_p = in_reloc_p;
281
282
2.98k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
283
284
2.98k
  bfd_coff_long_section_names (abfd)
285
2.98k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
286
287
2.98k
  return true;
288
2.98k
}
pei-ia64.c:pe_mkobject
Line
Count
Source
260
323
{
261
  /* Some x86 code followed by an ascii string.  */
262
323
  static const char default_dos_message[64] = {
263
323
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
264
323
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
265
323
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
266
323
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
267
323
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
268
323
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
269
323
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
270
323
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
271
272
323
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
273
323
  abfd->tdata.pe_obj_data = pe;
274
323
  if (pe == NULL)
275
0
    return false;
276
277
323
  pe->coff.pe = 1;
278
279
  /* in_reloc_p is architecture dependent.  */
280
323
  pe->in_reloc_p = in_reloc_p;
281
282
323
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
283
284
323
  bfd_coff_long_section_names (abfd)
285
323
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
286
287
323
  return true;
288
323
}
pei-loongarch64.c:pe_mkobject
Line
Count
Source
260
230
{
261
  /* Some x86 code followed by an ascii string.  */
262
230
  static const char default_dos_message[64] = {
263
230
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
264
230
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
265
230
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
266
230
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
267
230
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
268
230
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
269
230
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
270
230
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
271
272
230
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
273
230
  abfd->tdata.pe_obj_data = pe;
274
230
  if (pe == NULL)
275
0
    return false;
276
277
230
  pe->coff.pe = 1;
278
279
  /* in_reloc_p is architecture dependent.  */
280
230
  pe->in_reloc_p = in_reloc_p;
281
282
230
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
283
284
230
  bfd_coff_long_section_names (abfd)
285
230
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
286
287
230
  return true;
288
230
}
pe-arm-wince.c:pe_mkobject
Line
Count
Source
260
47
{
261
  /* Some x86 code followed by an ascii string.  */
262
47
  static const char default_dos_message[64] = {
263
47
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
264
47
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
265
47
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
266
47
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
267
47
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
268
47
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
269
47
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
270
47
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
271
272
47
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
273
47
  abfd->tdata.pe_obj_data = pe;
274
47
  if (pe == NULL)
275
0
    return false;
276
277
47
  pe->coff.pe = 1;
278
279
  /* in_reloc_p is architecture dependent.  */
280
47
  pe->in_reloc_p = in_reloc_p;
281
282
47
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
283
284
47
  bfd_coff_long_section_names (abfd)
285
47
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
286
287
47
  return true;
288
47
}
pe-arm.c:pe_mkobject
Line
Count
Source
260
47
{
261
  /* Some x86 code followed by an ascii string.  */
262
47
  static const char default_dos_message[64] = {
263
47
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
264
47
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
265
47
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
266
47
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
267
47
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
268
47
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
269
47
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
270
47
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
271
272
47
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
273
47
  abfd->tdata.pe_obj_data = pe;
274
47
  if (pe == NULL)
275
0
    return false;
276
277
47
  pe->coff.pe = 1;
278
279
  /* in_reloc_p is architecture dependent.  */
280
47
  pe->in_reloc_p = in_reloc_p;
281
282
47
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
283
284
47
  bfd_coff_long_section_names (abfd)
285
47
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
286
287
47
  return true;
288
47
}
pe-i386.c:pe_mkobject
Line
Count
Source
260
1.77k
{
261
  /* Some x86 code followed by an ascii string.  */
262
1.77k
  static const char default_dos_message[64] = {
263
1.77k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
264
1.77k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
265
1.77k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
266
1.77k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
267
1.77k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
268
1.77k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
269
1.77k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
270
1.77k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
271
272
1.77k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
273
1.77k
  abfd->tdata.pe_obj_data = pe;
274
1.77k
  if (pe == NULL)
275
0
    return false;
276
277
1.77k
  pe->coff.pe = 1;
278
279
  /* in_reloc_p is architecture dependent.  */
280
1.77k
  pe->in_reloc_p = in_reloc_p;
281
282
1.77k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
283
284
1.77k
  bfd_coff_long_section_names (abfd)
285
1.77k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
286
287
1.77k
  return true;
288
1.77k
}
pe-mcore.c:pe_mkobject
Line
Count
Source
260
145
{
261
  /* Some x86 code followed by an ascii string.  */
262
145
  static const char default_dos_message[64] = {
263
145
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
264
145
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
265
145
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
266
145
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
267
145
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
268
145
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
269
145
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
270
145
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
271
272
145
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
273
145
  abfd->tdata.pe_obj_data = pe;
274
145
  if (pe == NULL)
275
0
    return false;
276
277
145
  pe->coff.pe = 1;
278
279
  /* in_reloc_p is architecture dependent.  */
280
145
  pe->in_reloc_p = in_reloc_p;
281
282
145
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
283
284
145
  bfd_coff_long_section_names (abfd)
285
145
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
286
287
145
  return true;
288
145
}
pe-sh.c:pe_mkobject
Line
Count
Source
260
134
{
261
  /* Some x86 code followed by an ascii string.  */
262
134
  static const char default_dos_message[64] = {
263
134
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
264
134
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
265
134
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
266
134
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
267
134
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
268
134
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
269
134
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
270
134
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
271
272
134
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
273
134
  abfd->tdata.pe_obj_data = pe;
274
134
  if (pe == NULL)
275
0
    return false;
276
277
134
  pe->coff.pe = 1;
278
279
  /* in_reloc_p is architecture dependent.  */
280
134
  pe->in_reloc_p = in_reloc_p;
281
282
134
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
283
284
134
  bfd_coff_long_section_names (abfd)
285
134
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
286
287
134
  return true;
288
134
}
pei-arm-wince.c:pe_mkobject
Line
Count
Source
260
67
{
261
  /* Some x86 code followed by an ascii string.  */
262
67
  static const char default_dos_message[64] = {
263
67
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
264
67
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
265
67
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
266
67
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
267
67
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
268
67
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
269
67
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
270
67
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
271
272
67
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
273
67
  abfd->tdata.pe_obj_data = pe;
274
67
  if (pe == NULL)
275
0
    return false;
276
277
67
  pe->coff.pe = 1;
278
279
  /* in_reloc_p is architecture dependent.  */
280
67
  pe->in_reloc_p = in_reloc_p;
281
282
67
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
283
284
67
  bfd_coff_long_section_names (abfd)
285
67
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
286
287
67
  return true;
288
67
}
pei-arm.c:pe_mkobject
Line
Count
Source
260
122
{
261
  /* Some x86 code followed by an ascii string.  */
262
122
  static const char default_dos_message[64] = {
263
122
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
264
122
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
265
122
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
266
122
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
267
122
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
268
122
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
269
122
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
270
122
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
271
272
122
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
273
122
  abfd->tdata.pe_obj_data = pe;
274
122
  if (pe == NULL)
275
0
    return false;
276
277
122
  pe->coff.pe = 1;
278
279
  /* in_reloc_p is architecture dependent.  */
280
122
  pe->in_reloc_p = in_reloc_p;
281
282
122
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
283
284
122
  bfd_coff_long_section_names (abfd)
285
122
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
286
287
122
  return true;
288
122
}
pei-mcore.c:pe_mkobject
Line
Count
Source
260
99
{
261
  /* Some x86 code followed by an ascii string.  */
262
99
  static const char default_dos_message[64] = {
263
99
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
264
99
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
265
99
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
266
99
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
267
99
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
268
99
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
269
99
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
270
99
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
271
272
99
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
273
99
  abfd->tdata.pe_obj_data = pe;
274
99
  if (pe == NULL)
275
0
    return false;
276
277
99
  pe->coff.pe = 1;
278
279
  /* in_reloc_p is architecture dependent.  */
280
99
  pe->in_reloc_p = in_reloc_p;
281
282
99
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
283
284
99
  bfd_coff_long_section_names (abfd)
285
99
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
286
287
99
  return true;
288
99
}
pei-sh.c:pe_mkobject
Line
Count
Source
260
123
{
261
  /* Some x86 code followed by an ascii string.  */
262
123
  static const char default_dos_message[64] = {
263
123
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
264
123
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
265
123
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
266
123
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
267
123
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
268
123
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
269
123
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
270
123
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
271
272
123
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
273
123
  abfd->tdata.pe_obj_data = pe;
274
123
  if (pe == NULL)
275
0
    return false;
276
277
123
  pe->coff.pe = 1;
278
279
  /* in_reloc_p is architecture dependent.  */
280
123
  pe->in_reloc_p = in_reloc_p;
281
282
123
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
283
284
123
  bfd_coff_long_section_names (abfd)
285
123
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
286
287
123
  return true;
288
123
}
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
9.14k
{
297
9.14k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
298
9.14k
  pe_data_type *pe;
299
300
9.14k
  if (! pe_mkobject (abfd))
301
0
    return NULL;
302
303
9.14k
  pe = pe_data (abfd);
304
9.14k
  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
9.14k
  pe->coff.local_n_btmask = N_BTMASK;
309
9.14k
  pe->coff.local_n_btshft = N_BTSHFT;
310
9.14k
  pe->coff.local_n_tmask = N_TMASK;
311
9.14k
  pe->coff.local_n_tshift = N_TSHIFT;
312
9.14k
  pe->coff.local_symesz = SYMESZ;
313
9.14k
  pe->coff.local_auxesz = AUXESZ;
314
9.14k
  pe->coff.local_linesz = LINESZ;
315
316
9.14k
  pe->coff.timestamp = internal_f->f_timdat;
317
318
9.14k
  obj_raw_syment_count (abfd) =
319
9.14k
    obj_conv_table_size (abfd) =
320
9.14k
      internal_f->f_nsyms;
321
322
9.14k
  pe->real_flags = internal_f->f_flags;
323
324
9.14k
  if ((internal_f->f_flags & F_DLL) != 0)
325
994
    pe->dll = 1;
326
327
9.14k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
328
5.28k
    abfd->flags |= HAS_DEBUG;
329
330
#ifdef COFF_IMAGE_WITH_PE
331
4.44k
  if (aouthdr)
332
3.69k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
333
#endif
334
335
#ifdef ARM
336
283
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
337
0
    coff_data (abfd) ->flags = 0;
338
#endif
339
340
9.14k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
341
9.14k
    sizeof (pe->dos_message));
342
343
9.14k
  return (void *) pe;
344
9.14k
}
pei-i386.c:pe_mkobject_hook
Line
Count
Source
296
238
{
297
238
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
298
238
  pe_data_type *pe;
299
300
238
  if (! pe_mkobject (abfd))
301
0
    return NULL;
302
303
238
  pe = pe_data (abfd);
304
238
  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
238
  pe->coff.local_n_btmask = N_BTMASK;
309
238
  pe->coff.local_n_btshft = N_BTSHFT;
310
238
  pe->coff.local_n_tmask = N_TMASK;
311
238
  pe->coff.local_n_tshift = N_TSHIFT;
312
238
  pe->coff.local_symesz = SYMESZ;
313
238
  pe->coff.local_auxesz = AUXESZ;
314
238
  pe->coff.local_linesz = LINESZ;
315
316
238
  pe->coff.timestamp = internal_f->f_timdat;
317
318
238
  obj_raw_syment_count (abfd) =
319
238
    obj_conv_table_size (abfd) =
320
238
      internal_f->f_nsyms;
321
322
238
  pe->real_flags = internal_f->f_flags;
323
324
238
  if ((internal_f->f_flags & F_DLL) != 0)
325
18
    pe->dll = 1;
326
327
238
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
328
173
    abfd->flags |= HAS_DEBUG;
329
330
238
#ifdef COFF_IMAGE_WITH_PE
331
238
  if (aouthdr)
332
146
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
333
238
#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
238
  memcpy (pe->dos_message, internal_f->pe.dos_message,
341
238
    sizeof (pe->dos_message));
342
343
238
  return (void *) pe;
344
238
}
pe-x86_64.c:pe_mkobject_hook
Line
Count
Source
296
726
{
297
726
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
298
726
  pe_data_type *pe;
299
300
726
  if (! pe_mkobject (abfd))
301
0
    return NULL;
302
303
726
  pe = pe_data (abfd);
304
726
  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
726
  pe->coff.local_n_btmask = N_BTMASK;
309
726
  pe->coff.local_n_btshft = N_BTSHFT;
310
726
  pe->coff.local_n_tmask = N_TMASK;
311
726
  pe->coff.local_n_tshift = N_TSHIFT;
312
726
  pe->coff.local_symesz = SYMESZ;
313
726
  pe->coff.local_auxesz = AUXESZ;
314
726
  pe->coff.local_linesz = LINESZ;
315
316
726
  pe->coff.timestamp = internal_f->f_timdat;
317
318
726
  obj_raw_syment_count (abfd) =
319
726
    obj_conv_table_size (abfd) =
320
726
      internal_f->f_nsyms;
321
322
726
  pe->real_flags = internal_f->f_flags;
323
324
726
  if ((internal_f->f_flags & F_DLL) != 0)
325
182
    pe->dll = 1;
326
327
726
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
328
412
    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
726
  memcpy (pe->dos_message, internal_f->pe.dos_message,
341
726
    sizeof (pe->dos_message));
342
343
726
  return (void *) pe;
344
726
}
pei-x86_64.c:pe_mkobject_hook
Line
Count
Source
296
259
{
297
259
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
298
259
  pe_data_type *pe;
299
300
259
  if (! pe_mkobject (abfd))
301
0
    return NULL;
302
303
259
  pe = pe_data (abfd);
304
259
  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
259
  pe->coff.local_n_btmask = N_BTMASK;
309
259
  pe->coff.local_n_btshft = N_BTSHFT;
310
259
  pe->coff.local_n_tmask = N_TMASK;
311
259
  pe->coff.local_n_tshift = N_TSHIFT;
312
259
  pe->coff.local_symesz = SYMESZ;
313
259
  pe->coff.local_auxesz = AUXESZ;
314
259
  pe->coff.local_linesz = LINESZ;
315
316
259
  pe->coff.timestamp = internal_f->f_timdat;
317
318
259
  obj_raw_syment_count (abfd) =
319
259
    obj_conv_table_size (abfd) =
320
259
      internal_f->f_nsyms;
321
322
259
  pe->real_flags = internal_f->f_flags;
323
324
259
  if ((internal_f->f_flags & F_DLL) != 0)
325
39
    pe->dll = 1;
326
327
259
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
328
240
    abfd->flags |= HAS_DEBUG;
329
330
259
#ifdef COFF_IMAGE_WITH_PE
331
259
  if (aouthdr)
332
167
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
333
259
#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
259
  memcpy (pe->dos_message, internal_f->pe.dos_message,
341
259
    sizeof (pe->dos_message));
342
343
259
  return (void *) pe;
344
259
}
pe-aarch64.c:pe_mkobject_hook
Line
Count
Source
296
1.83k
{
297
1.83k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
298
1.83k
  pe_data_type *pe;
299
300
1.83k
  if (! pe_mkobject (abfd))
301
0
    return NULL;
302
303
1.83k
  pe = pe_data (abfd);
304
1.83k
  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.83k
  pe->coff.local_n_btmask = N_BTMASK;
309
1.83k
  pe->coff.local_n_btshft = N_BTSHFT;
310
1.83k
  pe->coff.local_n_tmask = N_TMASK;
311
1.83k
  pe->coff.local_n_tshift = N_TSHIFT;
312
1.83k
  pe->coff.local_symesz = SYMESZ;
313
1.83k
  pe->coff.local_auxesz = AUXESZ;
314
1.83k
  pe->coff.local_linesz = LINESZ;
315
316
1.83k
  pe->coff.timestamp = internal_f->f_timdat;
317
318
1.83k
  obj_raw_syment_count (abfd) =
319
1.83k
    obj_conv_table_size (abfd) =
320
1.83k
      internal_f->f_nsyms;
321
322
1.83k
  pe->real_flags = internal_f->f_flags;
323
324
1.83k
  if ((internal_f->f_flags & F_DLL) != 0)
325
29
    pe->dll = 1;
326
327
1.83k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
328
141
    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.83k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
341
1.83k
    sizeof (pe->dos_message));
342
343
1.83k
  return (void *) pe;
344
1.83k
}
pei-aarch64.c:pe_mkobject_hook
Line
Count
Source
296
2.98k
{
297
2.98k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
298
2.98k
  pe_data_type *pe;
299
300
2.98k
  if (! pe_mkobject (abfd))
301
0
    return NULL;
302
303
2.98k
  pe = pe_data (abfd);
304
2.98k
  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
2.98k
  pe->coff.local_n_btmask = N_BTMASK;
309
2.98k
  pe->coff.local_n_btshft = N_BTSHFT;
310
2.98k
  pe->coff.local_n_tmask = N_TMASK;
311
2.98k
  pe->coff.local_n_tshift = N_TSHIFT;
312
2.98k
  pe->coff.local_symesz = SYMESZ;
313
2.98k
  pe->coff.local_auxesz = AUXESZ;
314
2.98k
  pe->coff.local_linesz = LINESZ;
315
316
2.98k
  pe->coff.timestamp = internal_f->f_timdat;
317
318
2.98k
  obj_raw_syment_count (abfd) =
319
2.98k
    obj_conv_table_size (abfd) =
320
2.98k
      internal_f->f_nsyms;
321
322
2.98k
  pe->real_flags = internal_f->f_flags;
323
324
2.98k
  if ((internal_f->f_flags & F_DLL) != 0)
325
89
    pe->dll = 1;
326
327
2.98k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
328
2.89k
    abfd->flags |= HAS_DEBUG;
329
330
2.98k
#ifdef COFF_IMAGE_WITH_PE
331
2.98k
  if (aouthdr)
332
2.89k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
333
2.98k
#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
2.98k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
341
2.98k
    sizeof (pe->dos_message));
342
343
2.98k
  return (void *) pe;
344
2.98k
}
pei-ia64.c:pe_mkobject_hook
Line
Count
Source
296
323
{
297
323
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
298
323
  pe_data_type *pe;
299
300
323
  if (! pe_mkobject (abfd))
301
0
    return NULL;
302
303
323
  pe = pe_data (abfd);
304
323
  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
323
  pe->coff.local_n_btmask = N_BTMASK;
309
323
  pe->coff.local_n_btshft = N_BTSHFT;
310
323
  pe->coff.local_n_tmask = N_TMASK;
311
323
  pe->coff.local_n_tshift = N_TSHIFT;
312
323
  pe->coff.local_symesz = SYMESZ;
313
323
  pe->coff.local_auxesz = AUXESZ;
314
323
  pe->coff.local_linesz = LINESZ;
315
316
323
  pe->coff.timestamp = internal_f->f_timdat;
317
318
323
  obj_raw_syment_count (abfd) =
319
323
    obj_conv_table_size (abfd) =
320
323
      internal_f->f_nsyms;
321
322
323
  pe->real_flags = internal_f->f_flags;
323
324
323
  if ((internal_f->f_flags & F_DLL) != 0)
325
50
    pe->dll = 1;
326
327
323
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
328
265
    abfd->flags |= HAS_DEBUG;
329
330
323
#ifdef COFF_IMAGE_WITH_PE
331
323
  if (aouthdr)
332
166
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
333
323
#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
323
  memcpy (pe->dos_message, internal_f->pe.dos_message,
341
323
    sizeof (pe->dos_message));
342
343
323
  return (void *) pe;
344
323
}
pei-loongarch64.c:pe_mkobject_hook
Line
Count
Source
296
230
{
297
230
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
298
230
  pe_data_type *pe;
299
300
230
  if (! pe_mkobject (abfd))
301
0
    return NULL;
302
303
230
  pe = pe_data (abfd);
304
230
  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
230
  pe->coff.local_n_btmask = N_BTMASK;
309
230
  pe->coff.local_n_btshft = N_BTSHFT;
310
230
  pe->coff.local_n_tmask = N_TMASK;
311
230
  pe->coff.local_n_tshift = N_TSHIFT;
312
230
  pe->coff.local_symesz = SYMESZ;
313
230
  pe->coff.local_auxesz = AUXESZ;
314
230
  pe->coff.local_linesz = LINESZ;
315
316
230
  pe->coff.timestamp = internal_f->f_timdat;
317
318
230
  obj_raw_syment_count (abfd) =
319
230
    obj_conv_table_size (abfd) =
320
230
      internal_f->f_nsyms;
321
322
230
  pe->real_flags = internal_f->f_flags;
323
324
230
  if ((internal_f->f_flags & F_DLL) != 0)
325
110
    pe->dll = 1;
326
327
230
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
328
120
    abfd->flags |= HAS_DEBUG;
329
330
230
#ifdef COFF_IMAGE_WITH_PE
331
230
  if (aouthdr)
332
178
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
333
230
#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
230
  memcpy (pe->dos_message, internal_f->pe.dos_message,
341
230
    sizeof (pe->dos_message));
342
343
230
  return (void *) pe;
344
230
}
pe-arm-wince.c:pe_mkobject_hook
Line
Count
Source
296
47
{
297
47
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
298
47
  pe_data_type *pe;
299
300
47
  if (! pe_mkobject (abfd))
301
0
    return NULL;
302
303
47
  pe = pe_data (abfd);
304
47
  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
47
  pe->coff.local_n_btmask = N_BTMASK;
309
47
  pe->coff.local_n_btshft = N_BTSHFT;
310
47
  pe->coff.local_n_tmask = N_TMASK;
311
47
  pe->coff.local_n_tshift = N_TSHIFT;
312
47
  pe->coff.local_symesz = SYMESZ;
313
47
  pe->coff.local_auxesz = AUXESZ;
314
47
  pe->coff.local_linesz = LINESZ;
315
316
47
  pe->coff.timestamp = internal_f->f_timdat;
317
318
47
  obj_raw_syment_count (abfd) =
319
47
    obj_conv_table_size (abfd) =
320
47
      internal_f->f_nsyms;
321
322
47
  pe->real_flags = internal_f->f_flags;
323
324
47
  if ((internal_f->f_flags & F_DLL) != 0)
325
13
    pe->dll = 1;
326
327
47
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
328
36
    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
47
#ifdef ARM
336
47
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
337
0
    coff_data (abfd) ->flags = 0;
338
47
#endif
339
340
47
  memcpy (pe->dos_message, internal_f->pe.dos_message,
341
47
    sizeof (pe->dos_message));
342
343
47
  return (void *) pe;
344
47
}
pe-arm.c:pe_mkobject_hook
Line
Count
Source
296
47
{
297
47
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
298
47
  pe_data_type *pe;
299
300
47
  if (! pe_mkobject (abfd))
301
0
    return NULL;
302
303
47
  pe = pe_data (abfd);
304
47
  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
47
  pe->coff.local_n_btmask = N_BTMASK;
309
47
  pe->coff.local_n_btshft = N_BTSHFT;
310
47
  pe->coff.local_n_tmask = N_TMASK;
311
47
  pe->coff.local_n_tshift = N_TSHIFT;
312
47
  pe->coff.local_symesz = SYMESZ;
313
47
  pe->coff.local_auxesz = AUXESZ;
314
47
  pe->coff.local_linesz = LINESZ;
315
316
47
  pe->coff.timestamp = internal_f->f_timdat;
317
318
47
  obj_raw_syment_count (abfd) =
319
47
    obj_conv_table_size (abfd) =
320
47
      internal_f->f_nsyms;
321
322
47
  pe->real_flags = internal_f->f_flags;
323
324
47
  if ((internal_f->f_flags & F_DLL) != 0)
325
13
    pe->dll = 1;
326
327
47
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
328
36
    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
47
#ifdef ARM
336
47
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
337
0
    coff_data (abfd) ->flags = 0;
338
47
#endif
339
340
47
  memcpy (pe->dos_message, internal_f->pe.dos_message,
341
47
    sizeof (pe->dos_message));
342
343
47
  return (void *) pe;
344
47
}
pe-i386.c:pe_mkobject_hook
Line
Count
Source
296
1.77k
{
297
1.77k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
298
1.77k
  pe_data_type *pe;
299
300
1.77k
  if (! pe_mkobject (abfd))
301
0
    return NULL;
302
303
1.77k
  pe = pe_data (abfd);
304
1.77k
  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.77k
  pe->coff.local_n_btmask = N_BTMASK;
309
1.77k
  pe->coff.local_n_btshft = N_BTSHFT;
310
1.77k
  pe->coff.local_n_tmask = N_TMASK;
311
1.77k
  pe->coff.local_n_tshift = N_TSHIFT;
312
1.77k
  pe->coff.local_symesz = SYMESZ;
313
1.77k
  pe->coff.local_auxesz = AUXESZ;
314
1.77k
  pe->coff.local_linesz = LINESZ;
315
316
1.77k
  pe->coff.timestamp = internal_f->f_timdat;
317
318
1.77k
  obj_raw_syment_count (abfd) =
319
1.77k
    obj_conv_table_size (abfd) =
320
1.77k
      internal_f->f_nsyms;
321
322
1.77k
  pe->real_flags = internal_f->f_flags;
323
324
1.77k
  if ((internal_f->f_flags & F_DLL) != 0)
325
309
    pe->dll = 1;
326
327
1.77k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
328
429
    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.77k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
341
1.77k
    sizeof (pe->dos_message));
342
343
1.77k
  return (void *) pe;
344
1.77k
}
pe-mcore.c:pe_mkobject_hook
Line
Count
Source
296
145
{
297
145
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
298
145
  pe_data_type *pe;
299
300
145
  if (! pe_mkobject (abfd))
301
0
    return NULL;
302
303
145
  pe = pe_data (abfd);
304
145
  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
145
  pe->coff.local_n_btmask = N_BTMASK;
309
145
  pe->coff.local_n_btshft = N_BTSHFT;
310
145
  pe->coff.local_n_tmask = N_TMASK;
311
145
  pe->coff.local_n_tshift = N_TSHIFT;
312
145
  pe->coff.local_symesz = SYMESZ;
313
145
  pe->coff.local_auxesz = AUXESZ;
314
145
  pe->coff.local_linesz = LINESZ;
315
316
145
  pe->coff.timestamp = internal_f->f_timdat;
317
318
145
  obj_raw_syment_count (abfd) =
319
145
    obj_conv_table_size (abfd) =
320
145
      internal_f->f_nsyms;
321
322
145
  pe->real_flags = internal_f->f_flags;
323
324
145
  if ((internal_f->f_flags & F_DLL) != 0)
325
18
    pe->dll = 1;
326
327
145
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
328
130
    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
145
  memcpy (pe->dos_message, internal_f->pe.dos_message,
341
145
    sizeof (pe->dos_message));
342
343
145
  return (void *) pe;
344
145
}
pe-sh.c:pe_mkobject_hook
Line
Count
Source
296
134
{
297
134
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
298
134
  pe_data_type *pe;
299
300
134
  if (! pe_mkobject (abfd))
301
0
    return NULL;
302
303
134
  pe = pe_data (abfd);
304
134
  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
134
  pe->coff.local_n_btmask = N_BTMASK;
309
134
  pe->coff.local_n_btshft = N_BTSHFT;
310
134
  pe->coff.local_n_tmask = N_TMASK;
311
134
  pe->coff.local_n_tshift = N_TSHIFT;
312
134
  pe->coff.local_symesz = SYMESZ;
313
134
  pe->coff.local_auxesz = AUXESZ;
314
134
  pe->coff.local_linesz = LINESZ;
315
316
134
  pe->coff.timestamp = internal_f->f_timdat;
317
318
134
  obj_raw_syment_count (abfd) =
319
134
    obj_conv_table_size (abfd) =
320
134
      internal_f->f_nsyms;
321
322
134
  pe->real_flags = internal_f->f_flags;
323
324
134
  if ((internal_f->f_flags & F_DLL) != 0)
325
36
    pe->dll = 1;
326
327
134
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
328
104
    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
134
  memcpy (pe->dos_message, internal_f->pe.dos_message,
341
134
    sizeof (pe->dos_message));
342
343
134
  return (void *) pe;
344
134
}
pei-arm-wince.c:pe_mkobject_hook
Line
Count
Source
296
67
{
297
67
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
298
67
  pe_data_type *pe;
299
300
67
  if (! pe_mkobject (abfd))
301
0
    return NULL;
302
303
67
  pe = pe_data (abfd);
304
67
  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
67
  pe->coff.local_n_btmask = N_BTMASK;
309
67
  pe->coff.local_n_btshft = N_BTSHFT;
310
67
  pe->coff.local_n_tmask = N_TMASK;
311
67
  pe->coff.local_n_tshift = N_TSHIFT;
312
67
  pe->coff.local_symesz = SYMESZ;
313
67
  pe->coff.local_auxesz = AUXESZ;
314
67
  pe->coff.local_linesz = LINESZ;
315
316
67
  pe->coff.timestamp = internal_f->f_timdat;
317
318
67
  obj_raw_syment_count (abfd) =
319
67
    obj_conv_table_size (abfd) =
320
67
      internal_f->f_nsyms;
321
322
67
  pe->real_flags = internal_f->f_flags;
323
324
67
  if ((internal_f->f_flags & F_DLL) != 0)
325
30
    pe->dll = 1;
326
327
67
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
328
33
    abfd->flags |= HAS_DEBUG;
329
330
67
#ifdef COFF_IMAGE_WITH_PE
331
67
  if (aouthdr)
332
0
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
333
67
#endif
334
335
67
#ifdef ARM
336
67
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
337
0
    coff_data (abfd) ->flags = 0;
338
67
#endif
339
340
67
  memcpy (pe->dos_message, internal_f->pe.dos_message,
341
67
    sizeof (pe->dos_message));
342
343
67
  return (void *) pe;
344
67
}
pei-arm.c:pe_mkobject_hook
Line
Count
Source
296
122
{
297
122
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
298
122
  pe_data_type *pe;
299
300
122
  if (! pe_mkobject (abfd))
301
0
    return NULL;
302
303
122
  pe = pe_data (abfd);
304
122
  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
122
  pe->coff.local_n_btmask = N_BTMASK;
309
122
  pe->coff.local_n_btshft = N_BTSHFT;
310
122
  pe->coff.local_n_tmask = N_TMASK;
311
122
  pe->coff.local_n_tshift = N_TSHIFT;
312
122
  pe->coff.local_symesz = SYMESZ;
313
122
  pe->coff.local_auxesz = AUXESZ;
314
122
  pe->coff.local_linesz = LINESZ;
315
316
122
  pe->coff.timestamp = internal_f->f_timdat;
317
318
122
  obj_raw_syment_count (abfd) =
319
122
    obj_conv_table_size (abfd) =
320
122
      internal_f->f_nsyms;
321
322
122
  pe->real_flags = internal_f->f_flags;
323
324
122
  if ((internal_f->f_flags & F_DLL) != 0)
325
44
    pe->dll = 1;
326
327
122
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
328
74
    abfd->flags |= HAS_DEBUG;
329
330
122
#ifdef COFF_IMAGE_WITH_PE
331
122
  if (aouthdr)
332
55
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
333
122
#endif
334
335
122
#ifdef ARM
336
122
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
337
0
    coff_data (abfd) ->flags = 0;
338
122
#endif
339
340
122
  memcpy (pe->dos_message, internal_f->pe.dos_message,
341
122
    sizeof (pe->dos_message));
342
343
122
  return (void *) pe;
344
122
}
pei-mcore.c:pe_mkobject_hook
Line
Count
Source
296
99
{
297
99
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
298
99
  pe_data_type *pe;
299
300
99
  if (! pe_mkobject (abfd))
301
0
    return NULL;
302
303
99
  pe = pe_data (abfd);
304
99
  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
99
  pe->coff.local_n_btmask = N_BTMASK;
309
99
  pe->coff.local_n_btshft = N_BTSHFT;
310
99
  pe->coff.local_n_tmask = N_TMASK;
311
99
  pe->coff.local_n_tshift = N_TSHIFT;
312
99
  pe->coff.local_symesz = SYMESZ;
313
99
  pe->coff.local_auxesz = AUXESZ;
314
99
  pe->coff.local_linesz = LINESZ;
315
316
99
  pe->coff.timestamp = internal_f->f_timdat;
317
318
99
  obj_raw_syment_count (abfd) =
319
99
    obj_conv_table_size (abfd) =
320
99
      internal_f->f_nsyms;
321
322
99
  pe->real_flags = internal_f->f_flags;
323
324
99
  if ((internal_f->f_flags & F_DLL) != 0)
325
6
    pe->dll = 1;
326
327
99
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
328
91
    abfd->flags |= HAS_DEBUG;
329
330
99
#ifdef COFF_IMAGE_WITH_PE
331
99
  if (aouthdr)
332
56
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
333
99
#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
99
  memcpy (pe->dos_message, internal_f->pe.dos_message,
341
99
    sizeof (pe->dos_message));
342
343
99
  return (void *) pe;
344
99
}
pei-sh.c:pe_mkobject_hook
Line
Count
Source
296
123
{
297
123
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
298
123
  pe_data_type *pe;
299
300
123
  if (! pe_mkobject (abfd))
301
0
    return NULL;
302
303
123
  pe = pe_data (abfd);
304
123
  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
123
  pe->coff.local_n_btmask = N_BTMASK;
309
123
  pe->coff.local_n_btshft = N_BTSHFT;
310
123
  pe->coff.local_n_tmask = N_TMASK;
311
123
  pe->coff.local_n_tshift = N_TSHIFT;
312
123
  pe->coff.local_symesz = SYMESZ;
313
123
  pe->coff.local_auxesz = AUXESZ;
314
123
  pe->coff.local_linesz = LINESZ;
315
316
123
  pe->coff.timestamp = internal_f->f_timdat;
317
318
123
  obj_raw_syment_count (abfd) =
319
123
    obj_conv_table_size (abfd) =
320
123
      internal_f->f_nsyms;
321
322
123
  pe->real_flags = internal_f->f_flags;
323
324
123
  if ((internal_f->f_flags & F_DLL) != 0)
325
8
    pe->dll = 1;
326
327
123
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
328
108
    abfd->flags |= HAS_DEBUG;
329
330
123
#ifdef COFF_IMAGE_WITH_PE
331
123
  if (aouthdr)
332
27
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
333
123
#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
123
  memcpy (pe->dos_message, internal_f->pe.dos_message,
341
123
    sizeof (pe->dos_message));
342
343
123
  return (void *) pe;
344
123
}
345
346
static bool
347
pe_print_private_bfd_data (bfd *abfd, void * vfile)
348
5.55k
{
349
5.55k
  FILE *file = (FILE *) vfile;
350
351
5.55k
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
352
0
    return false;
353
354
5.55k
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
355
5.53k
    return true;
356
357
13
  fputc ('\n', file);
358
359
13
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
360
5.55k
}
pei-i386.c:pe_print_private_bfd_data
Line
Count
Source
348
133
{
349
133
  FILE *file = (FILE *) vfile;
350
351
133
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
352
0
    return false;
353
354
133
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
355
133
    return true;
356
357
0
  fputc ('\n', file);
358
359
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
360
133
}
pe-x86_64.c:pe_print_private_bfd_data
Line
Count
Source
348
78
{
349
78
  FILE *file = (FILE *) vfile;
350
351
78
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
352
0
    return false;
353
354
78
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
355
78
    return true;
356
357
0
  fputc ('\n', file);
358
359
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
360
78
}
pei-x86_64.c:pe_print_private_bfd_data
Line
Count
Source
348
137
{
349
137
  FILE *file = (FILE *) vfile;
350
351
137
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
352
0
    return false;
353
354
137
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
355
137
    return true;
356
357
0
  fputc ('\n', file);
358
359
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
360
137
}
pe-aarch64.c:pe_print_private_bfd_data
Line
Count
Source
348
1.71k
{
349
1.71k
  FILE *file = (FILE *) vfile;
350
351
1.71k
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
352
0
    return false;
353
354
1.71k
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
355
1.71k
    return true;
356
357
0
  fputc ('\n', file);
358
359
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
360
1.71k
}
pei-aarch64.c:pe_print_private_bfd_data
Line
Count
Source
348
2.83k
{
349
2.83k
  FILE *file = (FILE *) vfile;
350
351
2.83k
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
352
0
    return false;
353
354
2.83k
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
355
2.83k
    return true;
356
357
0
  fputc ('\n', file);
358
359
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
360
2.83k
}
pei-ia64.c:pe_print_private_bfd_data
Line
Count
Source
348
192
{
349
192
  FILE *file = (FILE *) vfile;
350
351
192
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
352
0
    return false;
353
354
192
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
355
192
    return true;
356
357
0
  fputc ('\n', file);
358
359
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
360
192
}
pei-loongarch64.c:pe_print_private_bfd_data
Line
Count
Source
348
136
{
349
136
  FILE *file = (FILE *) vfile;
350
351
136
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
352
0
    return false;
353
354
136
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
355
136
    return true;
356
357
0
  fputc ('\n', file);
358
359
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
360
136
}
Unexecuted instantiation: pe-arm-wince.c:pe_print_private_bfd_data
Unexecuted instantiation: pe-arm.c:pe_print_private_bfd_data
pe-i386.c:pe_print_private_bfd_data
Line
Count
Source
348
53
{
349
53
  FILE *file = (FILE *) vfile;
350
351
53
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
352
0
    return false;
353
354
53
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
355
53
    return true;
356
357
0
  fputc ('\n', file);
358
359
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
360
53
}
pe-mcore.c:pe_print_private_bfd_data
Line
Count
Source
348
97
{
349
97
  FILE *file = (FILE *) vfile;
350
351
97
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
352
0
    return false;
353
354
97
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
355
97
    return true;
356
357
0
  fputc ('\n', file);
358
359
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
360
97
}
pe-sh.c:pe_print_private_bfd_data
Line
Count
Source
348
44
{
349
44
  FILE *file = (FILE *) vfile;
350
351
44
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
352
0
    return false;
353
354
44
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
355
44
    return true;
356
357
0
  fputc ('\n', file);
358
359
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
360
44
}
Unexecuted instantiation: pei-arm-wince.c:pe_print_private_bfd_data
pei-arm.c:pe_print_private_bfd_data
Line
Count
Source
348
13
{
349
13
  FILE *file = (FILE *) vfile;
350
351
13
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
352
0
    return false;
353
354
13
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
355
0
    return true;
356
357
13
  fputc ('\n', file);
358
359
13
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
360
13
}
pei-mcore.c:pe_print_private_bfd_data
Line
Count
Source
348
42
{
349
42
  FILE *file = (FILE *) vfile;
350
351
42
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
352
0
    return false;
353
354
42
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
355
42
    return true;
356
357
0
  fputc ('\n', file);
358
359
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
360
42
}
pei-sh.c:pe_print_private_bfd_data
Line
Count
Source
348
76
{
349
76
  FILE *file = (FILE *) vfile;
350
351
76
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
352
0
    return false;
353
354
76
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
355
76
    return true;
356
357
0
  fputc ('\n', file);
358
359
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
360
76
}
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
582
#define NUM_ILF_RELOCS    8
418
1.94k
#define NUM_ILF_SECTIONS  6
419
1.45k
#define NUM_ILF_SYMS    (2 + NUM_ILF_SECTIONS)
420
421
291
#define SIZEOF_ILF_SYMS    (NUM_ILF_SYMS * sizeof (* vars.sym_cache))
422
291
#define SIZEOF_ILF_SYM_TABLE   (NUM_ILF_SYMS * sizeof (* vars.sym_table))
423
291
#define SIZEOF_ILF_NATIVE_SYMS   (NUM_ILF_SYMS * sizeof (* vars.native_syms))
424
291
#define SIZEOF_ILF_SYM_PTR_TABLE (NUM_ILF_SYMS * sizeof (* vars.sym_ptr_table))
425
291
#define SIZEOF_ILF_EXT_SYMS  (NUM_ILF_SYMS * sizeof (* vars.esym_table))
426
291
#define SIZEOF_ILF_RELOCS  (NUM_ILF_RELOCS * sizeof (* vars.reltab))
427
291
#define SIZEOF_ILF_INT_RELOCS  (NUM_ILF_RELOCS * sizeof (* vars.int_reltab))
428
291
#define SIZEOF_ILF_STRINGS   (strlen (symbol_name) * 2 + 8 \
429
291
          + 21 + strlen (source_dll) \
430
291
          + NUM_ILF_SECTIONS * 9 \
431
291
          + STRING_SIZE_SIZE)
432
194
#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
15
#define SIZEOF_IDATA4   (2 * 4)
437
15
#define SIZEOF_IDATA5   (2 * 4)
438
#else
439
276
#define SIZEOF_IDATA4   (1 * 4)
440
276
#define SIZEOF_IDATA5   (1 * 4)
441
#endif
442
443
266
#define SIZEOF_IDATA6   (2 + strlen (symbol_name) + 1 + 1)
444
194
#define SIZEOF_IDATA7   (strlen (source_dll) + 1 + 1)
445
194
#define SIZEOF_ILF_SECTIONS (NUM_ILF_SECTIONS * sizeof (struct coff_section_tdata))
446
447
#define ILF_DATA_SIZE       \
448
194
    + SIZEOF_ILF_SYMS        \
449
194
    + SIZEOF_ILF_SYM_TABLE      \
450
194
    + SIZEOF_ILF_NATIVE_SYMS      \
451
194
    + SIZEOF_ILF_SYM_PTR_TABLE      \
452
194
    + SIZEOF_ILF_EXT_SYMS      \
453
194
    + SIZEOF_ILF_RELOCS        \
454
194
    + SIZEOF_ILF_INT_RELOCS      \
455
194
    + SIZEOF_ILF_STRINGS      \
456
194
    + SIZEOF_IDATA2        \
457
194
    + SIZEOF_IDATA4        \
458
194
    + SIZEOF_IDATA5        \
459
194
    + SIZEOF_IDATA6        \
460
194
    + SIZEOF_IDATA7        \
461
194
    + SIZEOF_ILF_SECTIONS      \
462
194
    + 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
188
{
473
188
  arelent * entry;
474
188
  struct internal_reloc * internal;
475
476
188
  entry = vars->reltab + vars->relcount;
477
188
  internal = vars->int_reltab + vars->relcount;
478
479
188
  entry->address     = address;
480
188
  entry->addend      = 0;
481
188
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
482
188
  entry->sym_ptr_ptr = sym;
483
484
188
  internal->r_vaddr  = address;
485
188
  internal->r_symndx = sym_index;
486
188
  internal->r_type   = entry->howto ? entry->howto->type : 0;
487
488
188
  vars->relcount ++;
489
490
188
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
491
188
}
pei-i386.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
472
5
{
473
5
  arelent * entry;
474
5
  struct internal_reloc * internal;
475
476
5
  entry = vars->reltab + vars->relcount;
477
5
  internal = vars->int_reltab + vars->relcount;
478
479
5
  entry->address     = address;
480
5
  entry->addend      = 0;
481
5
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
482
5
  entry->sym_ptr_ptr = sym;
483
484
5
  internal->r_vaddr  = address;
485
5
  internal->r_symndx = sym_index;
486
5
  internal->r_type   = entry->howto ? entry->howto->type : 0;
487
488
5
  vars->relcount ++;
489
490
5
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
491
5
}
pei-x86_64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
472
1
{
473
1
  arelent * entry;
474
1
  struct internal_reloc * internal;
475
476
1
  entry = vars->reltab + vars->relcount;
477
1
  internal = vars->int_reltab + vars->relcount;
478
479
1
  entry->address     = address;
480
1
  entry->addend      = 0;
481
1
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
482
1
  entry->sym_ptr_ptr = sym;
483
484
1
  internal->r_vaddr  = address;
485
1
  internal->r_symndx = sym_index;
486
1
  internal->r_type   = entry->howto ? entry->howto->type : 0;
487
488
1
  vars->relcount ++;
489
490
1
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
491
1
}
pei-aarch64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
472
1
{
473
1
  arelent * entry;
474
1
  struct internal_reloc * internal;
475
476
1
  entry = vars->reltab + vars->relcount;
477
1
  internal = vars->int_reltab + vars->relcount;
478
479
1
  entry->address     = address;
480
1
  entry->addend      = 0;
481
1
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
482
1
  entry->sym_ptr_ptr = sym;
483
484
1
  internal->r_vaddr  = address;
485
1
  internal->r_symndx = sym_index;
486
1
  internal->r_type   = entry->howto ? entry->howto->type : 0;
487
488
1
  vars->relcount ++;
489
490
1
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
491
1
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_symbol_reloc
pei-loongarch64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
472
11
{
473
11
  arelent * entry;
474
11
  struct internal_reloc * internal;
475
476
11
  entry = vars->reltab + vars->relcount;
477
11
  internal = vars->int_reltab + vars->relcount;
478
479
11
  entry->address     = address;
480
11
  entry->addend      = 0;
481
11
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
482
11
  entry->sym_ptr_ptr = sym;
483
484
11
  internal->r_vaddr  = address;
485
11
  internal->r_symndx = sym_index;
486
11
  internal->r_type   = entry->howto ? entry->howto->type : 0;
487
488
11
  vars->relcount ++;
489
490
11
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
491
11
}
pei-arm-wince.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
472
25
{
473
25
  arelent * entry;
474
25
  struct internal_reloc * internal;
475
476
25
  entry = vars->reltab + vars->relcount;
477
25
  internal = vars->int_reltab + vars->relcount;
478
479
25
  entry->address     = address;
480
25
  entry->addend      = 0;
481
25
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
482
25
  entry->sym_ptr_ptr = sym;
483
484
25
  internal->r_vaddr  = address;
485
25
  internal->r_symndx = sym_index;
486
25
  internal->r_type   = entry->howto ? entry->howto->type : 0;
487
488
25
  vars->relcount ++;
489
490
25
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
491
25
}
pei-arm.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
472
25
{
473
25
  arelent * entry;
474
25
  struct internal_reloc * internal;
475
476
25
  entry = vars->reltab + vars->relcount;
477
25
  internal = vars->int_reltab + vars->relcount;
478
479
25
  entry->address     = address;
480
25
  entry->addend      = 0;
481
25
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
482
25
  entry->sym_ptr_ptr = sym;
483
484
25
  internal->r_vaddr  = address;
485
25
  internal->r_symndx = sym_index;
486
25
  internal->r_type   = entry->howto ? entry->howto->type : 0;
487
488
25
  vars->relcount ++;
489
490
25
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
491
25
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_symbol_reloc
pei-sh.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
472
120
{
473
120
  arelent * entry;
474
120
  struct internal_reloc * internal;
475
476
120
  entry = vars->reltab + vars->relcount;
477
120
  internal = vars->int_reltab + vars->relcount;
478
479
120
  entry->address     = address;
480
120
  entry->addend      = 0;
481
120
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
482
120
  entry->sym_ptr_ptr = sym;
483
484
120
  internal->r_vaddr  = address;
485
120
  internal->r_symndx = sym_index;
486
120
  internal->r_type   = entry->howto ? entry->howto->type : 0;
487
488
120
  vars->relcount ++;
489
490
120
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
491
120
}
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
144
{
501
144
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, sec->symbol_ptr_ptr,
502
144
            coff_section_data (vars->abfd, sec)->i);
503
144
}
pei-i386.c:pe_ILF_make_a_reloc
Line
Count
Source
500
4
{
501
4
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, sec->symbol_ptr_ptr,
502
4
            coff_section_data (vars->abfd, sec)->i);
503
4
}
Unexecuted instantiation: pei-x86_64.c:pe_ILF_make_a_reloc
Unexecuted instantiation: pei-aarch64.c:pe_ILF_make_a_reloc
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_reloc
pei-loongarch64.c:pe_ILF_make_a_reloc
Line
Count
Source
500
6
{
501
6
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, sec->symbol_ptr_ptr,
502
6
            coff_section_data (vars->abfd, sec)->i);
503
6
}
pei-arm-wince.c:pe_ILF_make_a_reloc
Line
Count
Source
500
18
{
501
18
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, sec->symbol_ptr_ptr,
502
18
            coff_section_data (vars->abfd, sec)->i);
503
18
}
pei-arm.c:pe_ILF_make_a_reloc
Line
Count
Source
500
18
{
501
18
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, sec->symbol_ptr_ptr,
502
18
            coff_section_data (vars->abfd, sec)->i);
503
18
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_reloc
pei-sh.c:pe_ILF_make_a_reloc
Line
Count
Source
500
98
{
501
98
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, sec->symbol_ptr_ptr,
502
98
            coff_section_data (vars->abfd, sec)->i);
503
98
}
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
188
{
511
  /* Make sure that there is somewhere to store the internal relocs.  */
512
188
  if (coff_section_data (vars->abfd, sec) == NULL)
513
    /* We should probably return an error indication here.  */
514
0
    abort ();
515
516
188
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
517
518
188
  sec->relocation  = vars->reltab;
519
188
  sec->reloc_count = vars->relcount;
520
188
  sec->flags      |= SEC_RELOC;
521
522
188
  vars->reltab     += vars->relcount;
523
188
  vars->int_reltab += vars->relcount;
524
188
  vars->relcount   = 0;
525
526
188
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
527
188
}
pei-i386.c:pe_ILF_save_relocs
Line
Count
Source
510
5
{
511
  /* Make sure that there is somewhere to store the internal relocs.  */
512
5
  if (coff_section_data (vars->abfd, sec) == NULL)
513
    /* We should probably return an error indication here.  */
514
0
    abort ();
515
516
5
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
517
518
5
  sec->relocation  = vars->reltab;
519
5
  sec->reloc_count = vars->relcount;
520
5
  sec->flags      |= SEC_RELOC;
521
522
5
  vars->reltab     += vars->relcount;
523
5
  vars->int_reltab += vars->relcount;
524
5
  vars->relcount   = 0;
525
526
5
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
527
5
}
pei-x86_64.c:pe_ILF_save_relocs
Line
Count
Source
510
1
{
511
  /* Make sure that there is somewhere to store the internal relocs.  */
512
1
  if (coff_section_data (vars->abfd, sec) == NULL)
513
    /* We should probably return an error indication here.  */
514
0
    abort ();
515
516
1
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
517
518
1
  sec->relocation  = vars->reltab;
519
1
  sec->reloc_count = vars->relcount;
520
1
  sec->flags      |= SEC_RELOC;
521
522
1
  vars->reltab     += vars->relcount;
523
1
  vars->int_reltab += vars->relcount;
524
1
  vars->relcount   = 0;
525
526
1
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
527
1
}
pei-aarch64.c:pe_ILF_save_relocs
Line
Count
Source
510
1
{
511
  /* Make sure that there is somewhere to store the internal relocs.  */
512
1
  if (coff_section_data (vars->abfd, sec) == NULL)
513
    /* We should probably return an error indication here.  */
514
0
    abort ();
515
516
1
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
517
518
1
  sec->relocation  = vars->reltab;
519
1
  sec->reloc_count = vars->relcount;
520
1
  sec->flags      |= SEC_RELOC;
521
522
1
  vars->reltab     += vars->relcount;
523
1
  vars->int_reltab += vars->relcount;
524
1
  vars->relcount   = 0;
525
526
1
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
527
1
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_save_relocs
pei-loongarch64.c:pe_ILF_save_relocs
Line
Count
Source
510
11
{
511
  /* Make sure that there is somewhere to store the internal relocs.  */
512
11
  if (coff_section_data (vars->abfd, sec) == NULL)
513
    /* We should probably return an error indication here.  */
514
0
    abort ();
515
516
11
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
517
518
11
  sec->relocation  = vars->reltab;
519
11
  sec->reloc_count = vars->relcount;
520
11
  sec->flags      |= SEC_RELOC;
521
522
11
  vars->reltab     += vars->relcount;
523
11
  vars->int_reltab += vars->relcount;
524
11
  vars->relcount   = 0;
525
526
11
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
527
11
}
pei-arm-wince.c:pe_ILF_save_relocs
Line
Count
Source
510
25
{
511
  /* Make sure that there is somewhere to store the internal relocs.  */
512
25
  if (coff_section_data (vars->abfd, sec) == NULL)
513
    /* We should probably return an error indication here.  */
514
0
    abort ();
515
516
25
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
517
518
25
  sec->relocation  = vars->reltab;
519
25
  sec->reloc_count = vars->relcount;
520
25
  sec->flags      |= SEC_RELOC;
521
522
25
  vars->reltab     += vars->relcount;
523
25
  vars->int_reltab += vars->relcount;
524
25
  vars->relcount   = 0;
525
526
25
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
527
25
}
pei-arm.c:pe_ILF_save_relocs
Line
Count
Source
510
25
{
511
  /* Make sure that there is somewhere to store the internal relocs.  */
512
25
  if (coff_section_data (vars->abfd, sec) == NULL)
513
    /* We should probably return an error indication here.  */
514
0
    abort ();
515
516
25
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
517
518
25
  sec->relocation  = vars->reltab;
519
25
  sec->reloc_count = vars->relcount;
520
25
  sec->flags      |= SEC_RELOC;
521
522
25
  vars->reltab     += vars->relcount;
523
25
  vars->int_reltab += vars->relcount;
524
25
  vars->relcount   = 0;
525
526
25
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
527
25
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_save_relocs
pei-sh.c:pe_ILF_save_relocs
Line
Count
Source
510
120
{
511
  /* Make sure that there is somewhere to store the internal relocs.  */
512
120
  if (coff_section_data (vars->abfd, sec) == NULL)
513
    /* We should probably return an error indication here.  */
514
0
    abort ();
515
516
120
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
517
518
120
  sec->relocation  = vars->reltab;
519
120
  sec->reloc_count = vars->relcount;
520
120
  sec->flags      |= SEC_RELOC;
521
522
120
  vars->reltab     += vars->relcount;
523
120
  vars->int_reltab += vars->relcount;
524
120
  vars->relcount   = 0;
525
526
120
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
527
120
}
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
538
{
538
538
  coff_symbol_type * sym;
539
538
  combined_entry_type * ent;
540
538
  SYMENT * esym;
541
538
  unsigned short sclass;
542
543
538
  if (extra_flags & BSF_LOCAL)
544
310
    sclass = C_STAT;
545
228
  else
546
228
    sclass = C_EXT;
547
548
#ifdef THUMBPEMAGIC
549
138
  if (vars->magic == THUMBPEMAGIC)
550
124
    {
551
124
      if (extra_flags & BSF_FUNCTION)
552
12
  sclass = C_THUMBEXTFUNC;
553
112
      else if (extra_flags & BSF_LOCAL)
554
72
  sclass = C_THUMBSTAT;
555
40
      else
556
40
  sclass = C_THUMBEXT;
557
124
    }
558
#endif
559
560
538
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
561
562
538
  sym = vars->sym_ptr;
563
538
  ent = vars->native_ptr;
564
538
  esym = vars->esym_ptr;
565
566
  /* Copy the symbol's name into the string table.  */
567
538
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
568
569
538
  if (section == NULL)
570
92
    section = bfd_und_section_ptr;
571
572
  /* Initialise the external symbol.  */
573
538
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
574
538
      esym->e.e.e_offset);
575
538
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
576
538
  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
538
  ent->u.syment.n_sclass    = sclass;
583
538
  ent->u.syment.n_scnum     = section->target_index;
584
538
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
585
538
  ent->is_sym = true;
586
587
538
  sym->symbol.the_bfd = vars->abfd;
588
538
  sym->symbol.name    = vars->string_ptr;
589
538
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
590
538
  sym->symbol.section = section;
591
538
  sym->native       = ent;
592
593
538
  * vars->table_ptr = vars->sym_index;
594
538
  * vars->sym_ptr_ptr = sym;
595
596
  /* Adjust pointers for the next symbol.  */
597
538
  vars->sym_index ++;
598
538
  vars->sym_ptr ++;
599
538
  vars->sym_ptr_ptr ++;
600
538
  vars->table_ptr ++;
601
538
  vars->native_ptr ++;
602
538
  vars->esym_ptr ++;
603
538
  vars->string_ptr += len + 1;
604
605
538
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
606
538
}
pei-i386.c:pe_ILF_make_a_symbol
Line
Count
Source
537
16
{
538
16
  coff_symbol_type * sym;
539
16
  combined_entry_type * ent;
540
16
  SYMENT * esym;
541
16
  unsigned short sclass;
542
543
16
  if (extra_flags & BSF_LOCAL)
544
9
    sclass = C_STAT;
545
7
  else
546
7
    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
16
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
561
562
16
  sym = vars->sym_ptr;
563
16
  ent = vars->native_ptr;
564
16
  esym = vars->esym_ptr;
565
566
  /* Copy the symbol's name into the string table.  */
567
16
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
568
569
16
  if (section == NULL)
570
3
    section = bfd_und_section_ptr;
571
572
  /* Initialise the external symbol.  */
573
16
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
574
16
      esym->e.e.e_offset);
575
16
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
576
16
  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
16
  ent->u.syment.n_sclass    = sclass;
583
16
  ent->u.syment.n_scnum     = section->target_index;
584
16
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
585
16
  ent->is_sym = true;
586
587
16
  sym->symbol.the_bfd = vars->abfd;
588
16
  sym->symbol.name    = vars->string_ptr;
589
16
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
590
16
  sym->symbol.section = section;
591
16
  sym->native       = ent;
592
593
16
  * vars->table_ptr = vars->sym_index;
594
16
  * vars->sym_ptr_ptr = sym;
595
596
  /* Adjust pointers for the next symbol.  */
597
16
  vars->sym_index ++;
598
16
  vars->sym_ptr ++;
599
16
  vars->sym_ptr_ptr ++;
600
16
  vars->table_ptr ++;
601
16
  vars->native_ptr ++;
602
16
  vars->esym_ptr ++;
603
16
  vars->string_ptr += len + 1;
604
605
16
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
606
16
}
pei-x86_64.c:pe_ILF_make_a_symbol
Line
Count
Source
537
14
{
538
14
  coff_symbol_type * sym;
539
14
  combined_entry_type * ent;
540
14
  SYMENT * esym;
541
14
  unsigned short sclass;
542
543
14
  if (extra_flags & BSF_LOCAL)
544
7
    sclass = C_STAT;
545
7
  else
546
7
    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
14
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
561
562
14
  sym = vars->sym_ptr;
563
14
  ent = vars->native_ptr;
564
14
  esym = vars->esym_ptr;
565
566
  /* Copy the symbol's name into the string table.  */
567
14
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
568
569
14
  if (section == NULL)
570
3
    section = bfd_und_section_ptr;
571
572
  /* Initialise the external symbol.  */
573
14
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
574
14
      esym->e.e.e_offset);
575
14
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
576
14
  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
14
  ent->u.syment.n_sclass    = sclass;
583
14
  ent->u.syment.n_scnum     = section->target_index;
584
14
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
585
14
  ent->is_sym = true;
586
587
14
  sym->symbol.the_bfd = vars->abfd;
588
14
  sym->symbol.name    = vars->string_ptr;
589
14
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
590
14
  sym->symbol.section = section;
591
14
  sym->native       = ent;
592
593
14
  * vars->table_ptr = vars->sym_index;
594
14
  * vars->sym_ptr_ptr = sym;
595
596
  /* Adjust pointers for the next symbol.  */
597
14
  vars->sym_index ++;
598
14
  vars->sym_ptr ++;
599
14
  vars->sym_ptr_ptr ++;
600
14
  vars->table_ptr ++;
601
14
  vars->native_ptr ++;
602
14
  vars->esym_ptr ++;
603
14
  vars->string_ptr += len + 1;
604
605
14
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
606
14
}
pei-aarch64.c:pe_ILF_make_a_symbol
Line
Count
Source
537
10
{
538
10
  coff_symbol_type * sym;
539
10
  combined_entry_type * ent;
540
10
  SYMENT * esym;
541
10
  unsigned short sclass;
542
543
10
  if (extra_flags & BSF_LOCAL)
544
5
    sclass = C_STAT;
545
5
  else
546
5
    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
10
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
561
562
10
  sym = vars->sym_ptr;
563
10
  ent = vars->native_ptr;
564
10
  esym = vars->esym_ptr;
565
566
  /* Copy the symbol's name into the string table.  */
567
10
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
568
569
10
  if (section == NULL)
570
2
    section = bfd_und_section_ptr;
571
572
  /* Initialise the external symbol.  */
573
10
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
574
10
      esym->e.e.e_offset);
575
10
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
576
10
  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
10
  ent->u.syment.n_sclass    = sclass;
583
10
  ent->u.syment.n_scnum     = section->target_index;
584
10
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
585
10
  ent->is_sym = true;
586
587
10
  sym->symbol.the_bfd = vars->abfd;
588
10
  sym->symbol.name    = vars->string_ptr;
589
10
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
590
10
  sym->symbol.section = section;
591
10
  sym->native       = ent;
592
593
10
  * vars->table_ptr = vars->sym_index;
594
10
  * vars->sym_ptr_ptr = sym;
595
596
  /* Adjust pointers for the next symbol.  */
597
10
  vars->sym_index ++;
598
10
  vars->sym_ptr ++;
599
10
  vars->sym_ptr_ptr ++;
600
10
  vars->table_ptr ++;
601
10
  vars->native_ptr ++;
602
10
  vars->esym_ptr ++;
603
10
  vars->string_ptr += len + 1;
604
605
10
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
606
10
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_symbol
pei-loongarch64.c:pe_ILF_make_a_symbol
Line
Count
Source
537
45
{
538
45
  coff_symbol_type * sym;
539
45
  combined_entry_type * ent;
540
45
  SYMENT * esym;
541
45
  unsigned short sclass;
542
543
45
  if (extra_flags & BSF_LOCAL)
544
26
    sclass = C_STAT;
545
19
  else
546
19
    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
45
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
561
562
45
  sym = vars->sym_ptr;
563
45
  ent = vars->native_ptr;
564
45
  esym = vars->esym_ptr;
565
566
  /* Copy the symbol's name into the string table.  */
567
45
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
568
569
45
  if (section == NULL)
570
7
    section = bfd_und_section_ptr;
571
572
  /* Initialise the external symbol.  */
573
45
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
574
45
      esym->e.e.e_offset);
575
45
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
576
45
  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
45
  ent->u.syment.n_sclass    = sclass;
583
45
  ent->u.syment.n_scnum     = section->target_index;
584
45
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
585
45
  ent->is_sym = true;
586
587
45
  sym->symbol.the_bfd = vars->abfd;
588
45
  sym->symbol.name    = vars->string_ptr;
589
45
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
590
45
  sym->symbol.section = section;
591
45
  sym->native       = ent;
592
593
45
  * vars->table_ptr = vars->sym_index;
594
45
  * vars->sym_ptr_ptr = sym;
595
596
  /* Adjust pointers for the next symbol.  */
597
45
  vars->sym_index ++;
598
45
  vars->sym_ptr ++;
599
45
  vars->sym_ptr_ptr ++;
600
45
  vars->table_ptr ++;
601
45
  vars->native_ptr ++;
602
45
  vars->esym_ptr ++;
603
45
  vars->string_ptr += len + 1;
604
605
45
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
606
45
}
pei-arm-wince.c:pe_ILF_make_a_symbol
Line
Count
Source
537
69
{
538
69
  coff_symbol_type * sym;
539
69
  combined_entry_type * ent;
540
69
  SYMENT * esym;
541
69
  unsigned short sclass;
542
543
69
  if (extra_flags & BSF_LOCAL)
544
40
    sclass = C_STAT;
545
29
  else
546
29
    sclass = C_EXT;
547
548
69
#ifdef THUMBPEMAGIC
549
69
  if (vars->magic == THUMBPEMAGIC)
550
62
    {
551
62
      if (extra_flags & BSF_FUNCTION)
552
6
  sclass = C_THUMBEXTFUNC;
553
56
      else if (extra_flags & BSF_LOCAL)
554
36
  sclass = C_THUMBSTAT;
555
20
      else
556
20
  sclass = C_THUMBEXT;
557
62
    }
558
69
#endif
559
560
69
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
561
562
69
  sym = vars->sym_ptr;
563
69
  ent = vars->native_ptr;
564
69
  esym = vars->esym_ptr;
565
566
  /* Copy the symbol's name into the string table.  */
567
69
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
568
569
69
  if (section == NULL)
570
11
    section = bfd_und_section_ptr;
571
572
  /* Initialise the external symbol.  */
573
69
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
574
69
      esym->e.e.e_offset);
575
69
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
576
69
  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
69
  ent->u.syment.n_sclass    = sclass;
583
69
  ent->u.syment.n_scnum     = section->target_index;
584
69
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
585
69
  ent->is_sym = true;
586
587
69
  sym->symbol.the_bfd = vars->abfd;
588
69
  sym->symbol.name    = vars->string_ptr;
589
69
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
590
69
  sym->symbol.section = section;
591
69
  sym->native       = ent;
592
593
69
  * vars->table_ptr = vars->sym_index;
594
69
  * vars->sym_ptr_ptr = sym;
595
596
  /* Adjust pointers for the next symbol.  */
597
69
  vars->sym_index ++;
598
69
  vars->sym_ptr ++;
599
69
  vars->sym_ptr_ptr ++;
600
69
  vars->table_ptr ++;
601
69
  vars->native_ptr ++;
602
69
  vars->esym_ptr ++;
603
69
  vars->string_ptr += len + 1;
604
605
69
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
606
69
}
pei-arm.c:pe_ILF_make_a_symbol
Line
Count
Source
537
69
{
538
69
  coff_symbol_type * sym;
539
69
  combined_entry_type * ent;
540
69
  SYMENT * esym;
541
69
  unsigned short sclass;
542
543
69
  if (extra_flags & BSF_LOCAL)
544
40
    sclass = C_STAT;
545
29
  else
546
29
    sclass = C_EXT;
547
548
69
#ifdef THUMBPEMAGIC
549
69
  if (vars->magic == THUMBPEMAGIC)
550
62
    {
551
62
      if (extra_flags & BSF_FUNCTION)
552
6
  sclass = C_THUMBEXTFUNC;
553
56
      else if (extra_flags & BSF_LOCAL)
554
36
  sclass = C_THUMBSTAT;
555
20
      else
556
20
  sclass = C_THUMBEXT;
557
62
    }
558
69
#endif
559
560
69
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
561
562
69
  sym = vars->sym_ptr;
563
69
  ent = vars->native_ptr;
564
69
  esym = vars->esym_ptr;
565
566
  /* Copy the symbol's name into the string table.  */
567
69
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
568
569
69
  if (section == NULL)
570
11
    section = bfd_und_section_ptr;
571
572
  /* Initialise the external symbol.  */
573
69
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
574
69
      esym->e.e.e_offset);
575
69
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
576
69
  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
69
  ent->u.syment.n_sclass    = sclass;
583
69
  ent->u.syment.n_scnum     = section->target_index;
584
69
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
585
69
  ent->is_sym = true;
586
587
69
  sym->symbol.the_bfd = vars->abfd;
588
69
  sym->symbol.name    = vars->string_ptr;
589
69
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
590
69
  sym->symbol.section = section;
591
69
  sym->native       = ent;
592
593
69
  * vars->table_ptr = vars->sym_index;
594
69
  * vars->sym_ptr_ptr = sym;
595
596
  /* Adjust pointers for the next symbol.  */
597
69
  vars->sym_index ++;
598
69
  vars->sym_ptr ++;
599
69
  vars->sym_ptr_ptr ++;
600
69
  vars->table_ptr ++;
601
69
  vars->native_ptr ++;
602
69
  vars->esym_ptr ++;
603
69
  vars->string_ptr += len + 1;
604
605
69
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
606
69
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_symbol
pei-sh.c:pe_ILF_make_a_symbol
Line
Count
Source
537
315
{
538
315
  coff_symbol_type * sym;
539
315
  combined_entry_type * ent;
540
315
  SYMENT * esym;
541
315
  unsigned short sclass;
542
543
315
  if (extra_flags & BSF_LOCAL)
544
183
    sclass = C_STAT;
545
132
  else
546
132
    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
315
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
561
562
315
  sym = vars->sym_ptr;
563
315
  ent = vars->native_ptr;
564
315
  esym = vars->esym_ptr;
565
566
  /* Copy the symbol's name into the string table.  */
567
315
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
568
569
315
  if (section == NULL)
570
55
    section = bfd_und_section_ptr;
571
572
  /* Initialise the external symbol.  */
573
315
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
574
315
      esym->e.e.e_offset);
575
315
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
576
315
  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
315
  ent->u.syment.n_sclass    = sclass;
583
315
  ent->u.syment.n_scnum     = section->target_index;
584
315
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
585
315
  ent->is_sym = true;
586
587
315
  sym->symbol.the_bfd = vars->abfd;
588
315
  sym->symbol.name    = vars->string_ptr;
589
315
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
590
315
  sym->symbol.section = section;
591
315
  sym->native       = ent;
592
593
315
  * vars->table_ptr = vars->sym_index;
594
315
  * vars->sym_ptr_ptr = sym;
595
596
  /* Adjust pointers for the next symbol.  */
597
315
  vars->sym_index ++;
598
315
  vars->sym_ptr ++;
599
315
  vars->sym_ptr_ptr ++;
600
315
  vars->table_ptr ++;
601
315
  vars->native_ptr ++;
602
315
  vars->esym_ptr ++;
603
315
  vars->string_ptr += len + 1;
604
605
315
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
606
315
}
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
310
{
616
310
  asection_ptr sec;
617
310
  flagword     flags;
618
310
  intptr_t alignment;
619
620
310
  sec = bfd_make_section_old_way (vars->abfd, name);
621
310
  if (sec == NULL)
622
0
    return NULL;
623
624
310
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
625
626
310
  bfd_set_section_flags (sec, flags | extra_flags);
627
628
310
  bfd_set_section_alignment (sec, 2);
629
630
  /* Check that we will not run out of space.  */
631
310
  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
310
  bfd_set_section_size (sec, (bfd_size_type) size);
636
310
  sec->contents = vars->data;
637
310
  sec->target_index = vars->sec_index ++;
638
639
  /* Advance data pointer in the vars structure.  */
640
310
  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
310
  if (size & 1)
647
34
    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
310
#if GCC_VERSION >= 3000
654
310
  alignment = __alignof__ (struct coff_section_tdata);
655
#else
656
  alignment = 8;
657
#endif
658
310
  vars->data
659
310
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
660
661
  /* Create a coff_section_tdata structure for our use.  */
662
310
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
663
310
  vars->data += sizeof (struct coff_section_tdata);
664
665
310
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
666
667
  /* Create a symbol to refer to this section.  */
668
310
  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
310
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
672
673
310
  return sec;
674
310
}
pei-i386.c:pe_ILF_make_a_section
Line
Count
Source
615
9
{
616
9
  asection_ptr sec;
617
9
  flagword     flags;
618
9
  intptr_t alignment;
619
620
9
  sec = bfd_make_section_old_way (vars->abfd, name);
621
9
  if (sec == NULL)
622
0
    return NULL;
623
624
9
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
625
626
9
  bfd_set_section_flags (sec, flags | extra_flags);
627
628
9
  bfd_set_section_alignment (sec, 2);
629
630
  /* Check that we will not run out of space.  */
631
9
  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
9
  bfd_set_section_size (sec, (bfd_size_type) size);
636
9
  sec->contents = vars->data;
637
9
  sec->target_index = vars->sec_index ++;
638
639
  /* Advance data pointer in the vars structure.  */
640
9
  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
9
  if (size & 1)
647
0
    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
9
#if GCC_VERSION >= 3000
654
9
  alignment = __alignof__ (struct coff_section_tdata);
655
#else
656
  alignment = 8;
657
#endif
658
9
  vars->data
659
9
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
660
661
  /* Create a coff_section_tdata structure for our use.  */
662
9
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
663
9
  vars->data += sizeof (struct coff_section_tdata);
664
665
9
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
666
667
  /* Create a symbol to refer to this section.  */
668
9
  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
9
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
672
673
9
  return sec;
674
9
}
pei-x86_64.c:pe_ILF_make_a_section
Line
Count
Source
615
7
{
616
7
  asection_ptr sec;
617
7
  flagword     flags;
618
7
  intptr_t alignment;
619
620
7
  sec = bfd_make_section_old_way (vars->abfd, name);
621
7
  if (sec == NULL)
622
0
    return NULL;
623
624
7
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
625
626
7
  bfd_set_section_flags (sec, flags | extra_flags);
627
628
7
  bfd_set_section_alignment (sec, 2);
629
630
  /* Check that we will not run out of space.  */
631
7
  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
7
  bfd_set_section_size (sec, (bfd_size_type) size);
636
7
  sec->contents = vars->data;
637
7
  sec->target_index = vars->sec_index ++;
638
639
  /* Advance data pointer in the vars structure.  */
640
7
  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
7
  if (size & 1)
647
0
    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
7
#if GCC_VERSION >= 3000
654
7
  alignment = __alignof__ (struct coff_section_tdata);
655
#else
656
  alignment = 8;
657
#endif
658
7
  vars->data
659
7
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
660
661
  /* Create a coff_section_tdata structure for our use.  */
662
7
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
663
7
  vars->data += sizeof (struct coff_section_tdata);
664
665
7
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
666
667
  /* Create a symbol to refer to this section.  */
668
7
  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
7
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
672
673
7
  return sec;
674
7
}
pei-aarch64.c:pe_ILF_make_a_section
Line
Count
Source
615
5
{
616
5
  asection_ptr sec;
617
5
  flagword     flags;
618
5
  intptr_t alignment;
619
620
5
  sec = bfd_make_section_old_way (vars->abfd, name);
621
5
  if (sec == NULL)
622
0
    return NULL;
623
624
5
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
625
626
5
  bfd_set_section_flags (sec, flags | extra_flags);
627
628
5
  bfd_set_section_alignment (sec, 2);
629
630
  /* Check that we will not run out of space.  */
631
5
  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
5
  bfd_set_section_size (sec, (bfd_size_type) size);
636
5
  sec->contents = vars->data;
637
5
  sec->target_index = vars->sec_index ++;
638
639
  /* Advance data pointer in the vars structure.  */
640
5
  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
5
  if (size & 1)
647
0
    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
5
#if GCC_VERSION >= 3000
654
5
  alignment = __alignof__ (struct coff_section_tdata);
655
#else
656
  alignment = 8;
657
#endif
658
5
  vars->data
659
5
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
660
661
  /* Create a coff_section_tdata structure for our use.  */
662
5
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
663
5
  vars->data += sizeof (struct coff_section_tdata);
664
665
5
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
666
667
  /* Create a symbol to refer to this section.  */
668
5
  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
5
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
672
673
5
  return sec;
674
5
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_section
pei-loongarch64.c:pe_ILF_make_a_section
Line
Count
Source
615
26
{
616
26
  asection_ptr sec;
617
26
  flagword     flags;
618
26
  intptr_t alignment;
619
620
26
  sec = bfd_make_section_old_way (vars->abfd, name);
621
26
  if (sec == NULL)
622
0
    return NULL;
623
624
26
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
625
626
26
  bfd_set_section_flags (sec, flags | extra_flags);
627
628
26
  bfd_set_section_alignment (sec, 2);
629
630
  /* Check that we will not run out of space.  */
631
26
  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
26
  bfd_set_section_size (sec, (bfd_size_type) size);
636
26
  sec->contents = vars->data;
637
26
  sec->target_index = vars->sec_index ++;
638
639
  /* Advance data pointer in the vars structure.  */
640
26
  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
26
  if (size & 1)
647
1
    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
26
#if GCC_VERSION >= 3000
654
26
  alignment = __alignof__ (struct coff_section_tdata);
655
#else
656
  alignment = 8;
657
#endif
658
26
  vars->data
659
26
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
660
661
  /* Create a coff_section_tdata structure for our use.  */
662
26
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
663
26
  vars->data += sizeof (struct coff_section_tdata);
664
665
26
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
666
667
  /* Create a symbol to refer to this section.  */
668
26
  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
26
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
672
673
26
  return sec;
674
26
}
pei-arm-wince.c:pe_ILF_make_a_section
Line
Count
Source
615
40
{
616
40
  asection_ptr sec;
617
40
  flagword     flags;
618
40
  intptr_t alignment;
619
620
40
  sec = bfd_make_section_old_way (vars->abfd, name);
621
40
  if (sec == NULL)
622
0
    return NULL;
623
624
40
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
625
626
40
  bfd_set_section_flags (sec, flags | extra_flags);
627
628
40
  bfd_set_section_alignment (sec, 2);
629
630
  /* Check that we will not run out of space.  */
631
40
  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
40
  bfd_set_section_size (sec, (bfd_size_type) size);
636
40
  sec->contents = vars->data;
637
40
  sec->target_index = vars->sec_index ++;
638
639
  /* Advance data pointer in the vars structure.  */
640
40
  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
40
  if (size & 1)
647
5
    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
40
#if GCC_VERSION >= 3000
654
40
  alignment = __alignof__ (struct coff_section_tdata);
655
#else
656
  alignment = 8;
657
#endif
658
40
  vars->data
659
40
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
660
661
  /* Create a coff_section_tdata structure for our use.  */
662
40
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
663
40
  vars->data += sizeof (struct coff_section_tdata);
664
665
40
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
666
667
  /* Create a symbol to refer to this section.  */
668
40
  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
40
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
672
673
40
  return sec;
674
40
}
pei-arm.c:pe_ILF_make_a_section
Line
Count
Source
615
40
{
616
40
  asection_ptr sec;
617
40
  flagword     flags;
618
40
  intptr_t alignment;
619
620
40
  sec = bfd_make_section_old_way (vars->abfd, name);
621
40
  if (sec == NULL)
622
0
    return NULL;
623
624
40
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
625
626
40
  bfd_set_section_flags (sec, flags | extra_flags);
627
628
40
  bfd_set_section_alignment (sec, 2);
629
630
  /* Check that we will not run out of space.  */
631
40
  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
40
  bfd_set_section_size (sec, (bfd_size_type) size);
636
40
  sec->contents = vars->data;
637
40
  sec->target_index = vars->sec_index ++;
638
639
  /* Advance data pointer in the vars structure.  */
640
40
  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
40
  if (size & 1)
647
5
    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
40
#if GCC_VERSION >= 3000
654
40
  alignment = __alignof__ (struct coff_section_tdata);
655
#else
656
  alignment = 8;
657
#endif
658
40
  vars->data
659
40
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
660
661
  /* Create a coff_section_tdata structure for our use.  */
662
40
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
663
40
  vars->data += sizeof (struct coff_section_tdata);
664
665
40
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
666
667
  /* Create a symbol to refer to this section.  */
668
40
  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
40
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
672
673
40
  return sec;
674
40
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_section
pei-sh.c:pe_ILF_make_a_section
Line
Count
Source
615
183
{
616
183
  asection_ptr sec;
617
183
  flagword     flags;
618
183
  intptr_t alignment;
619
620
183
  sec = bfd_make_section_old_way (vars->abfd, name);
621
183
  if (sec == NULL)
622
0
    return NULL;
623
624
183
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
625
626
183
  bfd_set_section_flags (sec, flags | extra_flags);
627
628
183
  bfd_set_section_alignment (sec, 2);
629
630
  /* Check that we will not run out of space.  */
631
183
  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
183
  bfd_set_section_size (sec, (bfd_size_type) size);
636
183
  sec->contents = vars->data;
637
183
  sec->target_index = vars->sec_index ++;
638
639
  /* Advance data pointer in the vars structure.  */
640
183
  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
183
  if (size & 1)
647
23
    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
183
#if GCC_VERSION >= 3000
654
183
  alignment = __alignof__ (struct coff_section_tdata);
655
#else
656
  alignment = 8;
657
#endif
658
183
  vars->data
659
183
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
660
661
  /* Create a coff_section_tdata structure for our use.  */
662
183
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
663
183
  vars->data += sizeof (struct coff_section_tdata);
664
665
183
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
666
667
  /* Create a symbol to refer to this section.  */
668
183
  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
183
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
672
673
183
  return sec;
674
183
}
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
194
#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
44
#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
120
{
787
120
  bfd_byte *       ptr;
788
120
  pe_ILF_vars      vars;
789
120
  struct internal_filehdr  internal_f;
790
120
  unsigned int       import_type;
791
120
  unsigned int       import_name_type;
792
120
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
793
120
  coff_symbol_type **    imp_sym;
794
120
  unsigned int       imp_index;
795
120
  intptr_t alignment;
796
797
  /* Decode and verify the types field of the ILF structure.  */
798
120
  import_type = types & 0x3;
799
120
  import_name_type = (types & 0x1c) >> 2;
800
801
120
  switch (import_type)
802
120
    {
803
54
    case IMPORT_CODE:
804
108
    case IMPORT_DATA:
805
108
      break;
806
807
7
    case IMPORT_CONST:
808
      /* XXX code yet to be written.  */
809
      /* xgettext:c-format */
810
7
      _bfd_error_handler (_("%pB: unhandled import type; %x"),
811
7
        abfd, import_type);
812
7
      return false;
813
814
5
    default:
815
      /* xgettext:c-format */
816
5
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
817
5
        abfd, import_type);
818
5
      return false;
819
120
    }
820
821
108
  switch (import_name_type)
822
108
    {
823
25
    case IMPORT_ORDINAL:
824
44
    case IMPORT_NAME:
825
74
    case IMPORT_NAME_NOPREFIX:
826
97
    case IMPORT_NAME_UNDECORATE:
827
97
      break;
828
829
11
    default:
830
      /* xgettext:c-format */
831
11
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
832
11
        abfd, import_name_type);
833
11
      return false;
834
108
    }
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
97
  vars.bim
844
97
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
845
97
  if (vars.bim == NULL)
846
0
    return false;
847
848
97
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
849
97
  vars.bim->buffer = ptr;
850
97
  vars.bim->size   = ILF_DATA_SIZE;
851
97
  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
97
  vars.sym_cache = (coff_symbol_type *) ptr;
857
97
  vars.sym_ptr   = (coff_symbol_type *) ptr;
858
97
  vars.sym_index = 0;
859
97
  ptr += SIZEOF_ILF_SYMS;
860
861
97
  vars.sym_table = (unsigned int *) ptr;
862
97
  vars.table_ptr = (unsigned int *) ptr;
863
97
  ptr += SIZEOF_ILF_SYM_TABLE;
864
865
97
  vars.native_syms = (combined_entry_type *) ptr;
866
97
  vars.native_ptr  = (combined_entry_type *) ptr;
867
97
  ptr += SIZEOF_ILF_NATIVE_SYMS;
868
869
97
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
870
97
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
871
97
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
872
873
97
  vars.esym_table = (SYMENT *) ptr;
874
97
  vars.esym_ptr   = (SYMENT *) ptr;
875
97
  ptr += SIZEOF_ILF_EXT_SYMS;
876
877
97
  vars.reltab   = (arelent *) ptr;
878
97
  vars.relcount = 0;
879
97
  ptr += SIZEOF_ILF_RELOCS;
880
881
97
  vars.int_reltab  = (struct internal_reloc *) ptr;
882
97
  ptr += SIZEOF_ILF_INT_RELOCS;
883
884
97
  vars.string_table = (char *) ptr;
885
97
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
886
97
  ptr += SIZEOF_ILF_STRINGS;
887
97
  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
97
#if GCC_VERSION >= 3000
897
97
  alignment = __alignof__ (struct coff_section_tdata);
898
#else
899
  alignment = 8;
900
#endif
901
97
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
902
903
97
  vars.data = ptr;
904
97
  vars.abfd = abfd;
905
97
  vars.sec_index = 0;
906
97
  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
97
  id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
916
97
  id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
917
97
  if (id4 == NULL || id5 == NULL)
918
0
    goto error_return;
919
920
  /* Fill in the contents of these sections.  */
921
97
  if (import_name_type == IMPORT_ORDINAL)
922
25
    {
923
25
      if (ordinal == 0)
924
  /* See PR 20907 for a reproducer.  */
925
5
  goto error_return;
926
927
#if defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) || defined(COFF_WITH_peLoongArch64)
928
9
      ((unsigned int *) id4->contents)[0] = ordinal;
929
9
      ((unsigned int *) id4->contents)[1] = 0x80000000;
930
9
      ((unsigned int *) id5->contents)[0] = ordinal;
931
9
      ((unsigned int *) id5->contents)[1] = 0x80000000;
932
#else
933
11
      * (unsigned int *) id4->contents = ordinal | 0x80000000;
934
11
      * (unsigned int *) id5->contents = ordinal | 0x80000000;
935
11
#endif
936
11
    }
937
72
  else
938
72
    {
939
72
      char * symbol;
940
72
      unsigned int len;
941
942
      /* Create .idata$6 - the Hint Name Table.  */
943
72
      id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
944
72
      if (id6 == NULL)
945
0
  goto error_return;
946
947
      /* If necessary, trim the import symbol name.  */
948
72
      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
72
      if (import_name_type != IMPORT_NAME)
958
53
  {
959
53
    char c = symbol[0];
960
961
    /* Check that we don't remove for targets with empty
962
       USER_LABEL_PREFIX the leading underscore.  */
963
53
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
964
53
        || c == '@' || c == '?')
965
3
      symbol++;
966
53
  }
967
968
72
      len = strlen (symbol);
969
72
      if (import_name_type == IMPORT_NAME_UNDECORATE)
970
23
  {
971
    /* Truncate at the first '@'.  */
972
23
    char *at = strchr (symbol, '@');
973
974
23
    if (at != NULL)
975
3
      len = at - symbol;
976
23
  }
977
978
72
      id6->contents[0] = ordinal & 0xff;
979
72
      id6->contents[1] = ordinal >> 8;
980
981
72
      memcpy ((char *) id6->contents + 2, symbol, len);
982
72
      id6->contents[len + 2] = '\0';
983
72
    }
984
985
92
  if (import_name_type != IMPORT_ORDINAL)
986
72
    {
987
72
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
988
72
      pe_ILF_save_relocs (&vars, id4);
989
990
72
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
991
72
      pe_ILF_save_relocs (&vars, id5);
992
72
    }
993
994
  /* Create an import symbol.  */
995
92
  pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
996
92
  imp_sym   = vars.sym_ptr_ptr - 1;
997
92
  imp_index = vars.sym_index - 1;
998
999
  /* Create extra sections depending upon the type of import we are dealing with.  */
1000
92
  switch (import_type)
1001
92
    {
1002
0
      int i;
1003
1004
44
    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
90
      for (i = NUM_ENTRIES (jtab); i--;)
1009
90
  {
1010
90
    if (jtab[i].size == 0)
1011
44
      continue;
1012
46
    if (jtab[i].magic == magic)
1013
44
      break;
1014
46
  }
1015
      /* If we did not find a matching entry something is wrong.  */
1016
44
      if (i < 0)
1017
0
  abort ();
1018
1019
      /* Create the .text section.  */
1020
44
      text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
1021
44
      if (text == NULL)
1022
0
  goto error_return;
1023
1024
      /* Copy in the jump code.  */
1025
44
      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
1
      if (magic == AMD64MAGIC)
1043
1
  {
1044
1
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1045
1
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1046
1
              imp_index);
1047
1
  }
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
44
      pe_ILF_save_relocs (& vars, text);
1055
44
      break;
1056
1057
48
    case IMPORT_DATA:
1058
48
      break;
1059
1060
0
    default:
1061
      /* XXX code not yet written.  */
1062
0
      abort ();
1063
92
    }
1064
1065
  /* Now create a symbol describing the imported value.  */
1066
92
  switch (import_type)
1067
92
    {
1068
44
    case IMPORT_CODE:
1069
44
      pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1070
44
          BSF_NOT_AT_END | BSF_FUNCTION);
1071
1072
44
      break;
1073
1074
48
    case IMPORT_DATA:
1075
      /* Nothing to do here.  */
1076
48
      break;
1077
1078
0
    default:
1079
      /* XXX code not yet written.  */
1080
0
      abort ();
1081
92
    }
1082
1083
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1084
92
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1085
92
  if (ptr)
1086
4
    * ptr = 0;
1087
92
  pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1088
92
  if (ptr)
1089
4
    * ptr = '.';
1090
1091
  /* Initialise the bfd.  */
1092
92
  memset (& internal_f, 0, sizeof (internal_f));
1093
1094
92
  internal_f.f_magic  = magic;
1095
92
  internal_f.f_symptr = 0;
1096
92
  internal_f.f_nsyms  = 0;
1097
92
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1098
1099
92
  if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
1100
92
      || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1101
0
    goto error_return;
1102
1103
92
  if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL)
1104
0
    goto error_return;
1105
1106
92
  obj_pe (abfd) = true;
1107
#ifdef THUMBPEMAGIC
1108
22
  if (vars.magic == THUMBPEMAGIC)
1109
    /* Stop some linker warnings about thumb code not supporting interworking.  */
1110
20
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1111
#endif
1112
1113
  /* Switch from file contents to memory contents.  */
1114
92
  bfd_cache_close (abfd);
1115
1116
92
  abfd->iostream = (void *) vars.bim;
1117
92
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1118
92
  abfd->iovec = &_bfd_memory_iovec;
1119
92
  abfd->where = 0;
1120
92
  abfd->origin = 0;
1121
92
  abfd->size = 0;
1122
92
  obj_sym_filepos (abfd) = 0;
1123
1124
  /* Point the bfd at the symbol table.  */
1125
92
  obj_symbols (abfd) = vars.sym_cache;
1126
92
  abfd->symcount = vars.sym_index;
1127
1128
92
  obj_raw_syments (abfd) = vars.native_syms;
1129
92
  obj_raw_syment_count (abfd) = vars.sym_index;
1130
1131
92
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1132
92
  obj_coff_keep_syms (abfd) = true;
1133
1134
92
  obj_convert (abfd) = vars.sym_table;
1135
92
  obj_conv_table_size (abfd) = vars.sym_index;
1136
1137
92
  obj_coff_strings (abfd) = vars.string_table;
1138
92
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1139
92
  obj_coff_keep_strings (abfd) = true;
1140
1141
92
  return true;
1142
1143
5
 error_return:
1144
5
  free (vars.bim->buffer);
1145
5
  free (vars.bim);
1146
5
  return false;
1147
92
}
pei-i386.c:pe_ILF_build_a_bfd
Line
Count
Source
786
7
{
787
7
  bfd_byte *       ptr;
788
7
  pe_ILF_vars      vars;
789
7
  struct internal_filehdr  internal_f;
790
7
  unsigned int       import_type;
791
7
  unsigned int       import_name_type;
792
7
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
793
7
  coff_symbol_type **    imp_sym;
794
7
  unsigned int       imp_index;
795
7
  intptr_t alignment;
796
797
  /* Decode and verify the types field of the ILF structure.  */
798
7
  import_type = types & 0x3;
799
7
  import_name_type = (types & 0x1c) >> 2;
800
801
7
  switch (import_type)
802
7
    {
803
1
    case IMPORT_CODE:
804
5
    case IMPORT_DATA:
805
5
      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
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
7
    }
820
821
5
  switch (import_name_type)
822
5
    {
823
1
    case IMPORT_ORDINAL:
824
2
    case IMPORT_NAME:
825
2
    case IMPORT_NAME_NOPREFIX:
826
3
    case IMPORT_NAME_UNDECORATE:
827
3
      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
5
    }
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
3
  vars.bim
844
3
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
845
3
  if (vars.bim == NULL)
846
0
    return false;
847
848
3
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
849
3
  vars.bim->buffer = ptr;
850
3
  vars.bim->size   = ILF_DATA_SIZE;
851
3
  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
3
  vars.sym_cache = (coff_symbol_type *) ptr;
857
3
  vars.sym_ptr   = (coff_symbol_type *) ptr;
858
3
  vars.sym_index = 0;
859
3
  ptr += SIZEOF_ILF_SYMS;
860
861
3
  vars.sym_table = (unsigned int *) ptr;
862
3
  vars.table_ptr = (unsigned int *) ptr;
863
3
  ptr += SIZEOF_ILF_SYM_TABLE;
864
865
3
  vars.native_syms = (combined_entry_type *) ptr;
866
3
  vars.native_ptr  = (combined_entry_type *) ptr;
867
3
  ptr += SIZEOF_ILF_NATIVE_SYMS;
868
869
3
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
870
3
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
871
3
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
872
873
3
  vars.esym_table = (SYMENT *) ptr;
874
3
  vars.esym_ptr   = (SYMENT *) ptr;
875
3
  ptr += SIZEOF_ILF_EXT_SYMS;
876
877
3
  vars.reltab   = (arelent *) ptr;
878
3
  vars.relcount = 0;
879
3
  ptr += SIZEOF_ILF_RELOCS;
880
881
3
  vars.int_reltab  = (struct internal_reloc *) ptr;
882
3
  ptr += SIZEOF_ILF_INT_RELOCS;
883
884
3
  vars.string_table = (char *) ptr;
885
3
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
886
3
  ptr += SIZEOF_ILF_STRINGS;
887
3
  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
3
#if GCC_VERSION >= 3000
897
3
  alignment = __alignof__ (struct coff_section_tdata);
898
#else
899
  alignment = 8;
900
#endif
901
3
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
902
903
3
  vars.data = ptr;
904
3
  vars.abfd = abfd;
905
3
  vars.sec_index = 0;
906
3
  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
3
  id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
916
3
  id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
917
3
  if (id4 == NULL || id5 == NULL)
918
0
    goto error_return;
919
920
  /* Fill in the contents of these sections.  */
921
3
  if (import_name_type == IMPORT_ORDINAL)
922
1
    {
923
1
      if (ordinal == 0)
924
  /* See PR 20907 for a reproducer.  */
925
0
  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
1
      * (unsigned int *) id4->contents = ordinal | 0x80000000;
934
1
      * (unsigned int *) id5->contents = ordinal | 0x80000000;
935
1
#endif
936
1
    }
937
2
  else
938
2
    {
939
2
      char * symbol;
940
2
      unsigned int len;
941
942
      /* Create .idata$6 - the Hint Name Table.  */
943
2
      id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
944
2
      if (id6 == NULL)
945
0
  goto error_return;
946
947
      /* If necessary, trim the import symbol name.  */
948
2
      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
2
      if (import_name_type != IMPORT_NAME)
958
1
  {
959
1
    char c = symbol[0];
960
961
    /* Check that we don't remove for targets with empty
962
       USER_LABEL_PREFIX the leading underscore.  */
963
1
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
964
1
        || c == '@' || c == '?')
965
0
      symbol++;
966
1
  }
967
968
2
      len = strlen (symbol);
969
2
      if (import_name_type == IMPORT_NAME_UNDECORATE)
970
1
  {
971
    /* Truncate at the first '@'.  */
972
1
    char *at = strchr (symbol, '@');
973
974
1
    if (at != NULL)
975
0
      len = at - symbol;
976
1
  }
977
978
2
      id6->contents[0] = ordinal & 0xff;
979
2
      id6->contents[1] = ordinal >> 8;
980
981
2
      memcpy ((char *) id6->contents + 2, symbol, len);
982
2
      id6->contents[len + 2] = '\0';
983
2
    }
984
985
3
  if (import_name_type != IMPORT_ORDINAL)
986
2
    {
987
2
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
988
2
      pe_ILF_save_relocs (&vars, id4);
989
990
2
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
991
2
      pe_ILF_save_relocs (&vars, id5);
992
2
    }
993
994
  /* Create an import symbol.  */
995
3
  pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
996
3
  imp_sym   = vars.sym_ptr_ptr - 1;
997
3
  imp_index = vars.sym_index - 1;
998
999
  /* Create extra sections depending upon the type of import we are dealing with.  */
1000
3
  switch (import_type)
1001
3
    {
1002
0
      int i;
1003
1004
1
    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
2
      for (i = NUM_ENTRIES (jtab); i--;)
1009
2
  {
1010
2
    if (jtab[i].size == 0)
1011
1
      continue;
1012
1
    if (jtab[i].magic == magic)
1013
1
      break;
1014
1
  }
1015
      /* If we did not find a matching entry something is wrong.  */
1016
1
      if (i < 0)
1017
0
  abort ();
1018
1019
      /* Create the .text section.  */
1020
1
      text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
1021
1
      if (text == NULL)
1022
0
  goto error_return;
1023
1024
      /* Copy in the jump code.  */
1025
1
      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
1
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1051
1
            BFD_RELOC_32, (asymbol **) imp_sym,
1052
1
            imp_index);
1053
1054
1
      pe_ILF_save_relocs (& vars, text);
1055
1
      break;
1056
1057
2
    case IMPORT_DATA:
1058
2
      break;
1059
1060
0
    default:
1061
      /* XXX code not yet written.  */
1062
0
      abort ();
1063
3
    }
1064
1065
  /* Now create a symbol describing the imported value.  */
1066
3
  switch (import_type)
1067
3
    {
1068
1
    case IMPORT_CODE:
1069
1
      pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1070
1
          BSF_NOT_AT_END | BSF_FUNCTION);
1071
1072
1
      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
3
    }
1082
1083
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1084
3
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1085
3
  if (ptr)
1086
0
    * ptr = 0;
1087
3
  pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1088
3
  if (ptr)
1089
0
    * ptr = '.';
1090
1091
  /* Initialise the bfd.  */
1092
3
  memset (& internal_f, 0, sizeof (internal_f));
1093
1094
3
  internal_f.f_magic  = magic;
1095
3
  internal_f.f_symptr = 0;
1096
3
  internal_f.f_nsyms  = 0;
1097
3
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1098
1099
3
  if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
1100
3
      || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1101
0
    goto error_return;
1102
1103
3
  if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL)
1104
0
    goto error_return;
1105
1106
3
  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
3
  bfd_cache_close (abfd);
1115
1116
3
  abfd->iostream = (void *) vars.bim;
1117
3
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1118
3
  abfd->iovec = &_bfd_memory_iovec;
1119
3
  abfd->where = 0;
1120
3
  abfd->origin = 0;
1121
3
  abfd->size = 0;
1122
3
  obj_sym_filepos (abfd) = 0;
1123
1124
  /* Point the bfd at the symbol table.  */
1125
3
  obj_symbols (abfd) = vars.sym_cache;
1126
3
  abfd->symcount = vars.sym_index;
1127
1128
3
  obj_raw_syments (abfd) = vars.native_syms;
1129
3
  obj_raw_syment_count (abfd) = vars.sym_index;
1130
1131
3
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1132
3
  obj_coff_keep_syms (abfd) = true;
1133
1134
3
  obj_convert (abfd) = vars.sym_table;
1135
3
  obj_conv_table_size (abfd) = vars.sym_index;
1136
1137
3
  obj_coff_strings (abfd) = vars.string_table;
1138
3
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1139
3
  obj_coff_keep_strings (abfd) = true;
1140
1141
3
  return true;
1142
1143
0
 error_return:
1144
0
  free (vars.bim->buffer);
1145
0
  free (vars.bim);
1146
0
  return false;
1147
3
}
pei-x86_64.c:pe_ILF_build_a_bfd
Line
Count
Source
786
7
{
787
7
  bfd_byte *       ptr;
788
7
  pe_ILF_vars      vars;
789
7
  struct internal_filehdr  internal_f;
790
7
  unsigned int       import_type;
791
7
  unsigned int       import_name_type;
792
7
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
793
7
  coff_symbol_type **    imp_sym;
794
7
  unsigned int       imp_index;
795
7
  intptr_t alignment;
796
797
  /* Decode and verify the types field of the ILF structure.  */
798
7
  import_type = types & 0x3;
799
7
  import_name_type = (types & 0x1c) >> 2;
800
801
7
  switch (import_type)
802
7
    {
803
1
    case IMPORT_CODE:
804
3
    case IMPORT_DATA:
805
3
      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
7
    }
820
821
3
  switch (import_name_type)
822
3
    {
823
3
    case IMPORT_ORDINAL:
824
3
    case IMPORT_NAME:
825
3
    case IMPORT_NAME_NOPREFIX:
826
3
    case IMPORT_NAME_UNDECORATE:
827
3
      break;
828
829
0
    default:
830
      /* xgettext:c-format */
831
0
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
832
0
        abfd, import_name_type);
833
0
      return false;
834
3
    }
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
3
  vars.bim
844
3
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
845
3
  if (vars.bim == NULL)
846
0
    return false;
847
848
3
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
849
3
  vars.bim->buffer = ptr;
850
3
  vars.bim->size   = ILF_DATA_SIZE;
851
3
  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
3
  vars.sym_cache = (coff_symbol_type *) ptr;
857
3
  vars.sym_ptr   = (coff_symbol_type *) ptr;
858
3
  vars.sym_index = 0;
859
3
  ptr += SIZEOF_ILF_SYMS;
860
861
3
  vars.sym_table = (unsigned int *) ptr;
862
3
  vars.table_ptr = (unsigned int *) ptr;
863
3
  ptr += SIZEOF_ILF_SYM_TABLE;
864
865
3
  vars.native_syms = (combined_entry_type *) ptr;
866
3
  vars.native_ptr  = (combined_entry_type *) ptr;
867
3
  ptr += SIZEOF_ILF_NATIVE_SYMS;
868
869
3
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
870
3
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
871
3
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
872
873
3
  vars.esym_table = (SYMENT *) ptr;
874
3
  vars.esym_ptr   = (SYMENT *) ptr;
875
3
  ptr += SIZEOF_ILF_EXT_SYMS;
876
877
3
  vars.reltab   = (arelent *) ptr;
878
3
  vars.relcount = 0;
879
3
  ptr += SIZEOF_ILF_RELOCS;
880
881
3
  vars.int_reltab  = (struct internal_reloc *) ptr;
882
3
  ptr += SIZEOF_ILF_INT_RELOCS;
883
884
3
  vars.string_table = (char *) ptr;
885
3
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
886
3
  ptr += SIZEOF_ILF_STRINGS;
887
3
  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
3
#if GCC_VERSION >= 3000
897
3
  alignment = __alignof__ (struct coff_section_tdata);
898
#else
899
  alignment = 8;
900
#endif
901
3
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
902
903
3
  vars.data = ptr;
904
3
  vars.abfd = abfd;
905
3
  vars.sec_index = 0;
906
3
  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
3
  id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
916
3
  id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
917
3
  if (id4 == NULL || id5 == NULL)
918
0
    goto error_return;
919
920
  /* Fill in the contents of these sections.  */
921
3
  if (import_name_type == IMPORT_ORDINAL)
922
3
    {
923
3
      if (ordinal == 0)
924
  /* See PR 20907 for a reproducer.  */
925
0
  goto error_return;
926
927
3
#if defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) || defined(COFF_WITH_peLoongArch64)
928
3
      ((unsigned int *) id4->contents)[0] = ordinal;
929
3
      ((unsigned int *) id4->contents)[1] = 0x80000000;
930
3
      ((unsigned int *) id5->contents)[0] = ordinal;
931
3
      ((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
3
    }
937
0
  else
938
0
    {
939
0
      char * symbol;
940
0
      unsigned int len;
941
942
      /* Create .idata$6 - the Hint Name Table.  */
943
0
      id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
944
0
      if (id6 == NULL)
945
0
  goto error_return;
946
947
      /* If necessary, trim the import symbol name.  */
948
0
      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
0
      if (import_name_type != IMPORT_NAME)
958
0
  {
959
0
    char c = symbol[0];
960
961
    /* Check that we don't remove for targets with empty
962
       USER_LABEL_PREFIX the leading underscore.  */
963
0
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
964
0
        || c == '@' || c == '?')
965
0
      symbol++;
966
0
  }
967
968
0
      len = strlen (symbol);
969
0
      if (import_name_type == IMPORT_NAME_UNDECORATE)
970
0
  {
971
    /* Truncate at the first '@'.  */
972
0
    char *at = strchr (symbol, '@');
973
974
0
    if (at != NULL)
975
0
      len = at - symbol;
976
0
  }
977
978
0
      id6->contents[0] = ordinal & 0xff;
979
0
      id6->contents[1] = ordinal >> 8;
980
981
0
      memcpy ((char *) id6->contents + 2, symbol, len);
982
0
      id6->contents[len + 2] = '\0';
983
0
    }
984
985
3
  if (import_name_type != IMPORT_ORDINAL)
986
0
    {
987
0
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
988
0
      pe_ILF_save_relocs (&vars, id4);
989
990
0
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
991
0
      pe_ILF_save_relocs (&vars, id5);
992
0
    }
993
994
  /* Create an import symbol.  */
995
3
  pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
996
3
  imp_sym   = vars.sym_ptr_ptr - 1;
997
3
  imp_index = vars.sym_index - 1;
998
999
  /* Create extra sections depending upon the type of import we are dealing with.  */
1000
3
  switch (import_type)
1001
3
    {
1002
0
      int i;
1003
1004
1
    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
2
      for (i = NUM_ENTRIES (jtab); i--;)
1009
2
  {
1010
2
    if (jtab[i].size == 0)
1011
1
      continue;
1012
1
    if (jtab[i].magic == magic)
1013
1
      break;
1014
1
  }
1015
      /* If we did not find a matching entry something is wrong.  */
1016
1
      if (i < 0)
1017
0
  abort ();
1018
1019
      /* Create the .text section.  */
1020
1
      text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
1021
1
      if (text == NULL)
1022
0
  goto error_return;
1023
1024
      /* Copy in the jump code.  */
1025
1
      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
1
#ifdef AMD64MAGIC
1042
1
      if (magic == AMD64MAGIC)
1043
1
  {
1044
1
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1045
1
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1046
1
              imp_index);
1047
1
  }
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
1
      pe_ILF_save_relocs (& vars, text);
1055
1
      break;
1056
1057
2
    case IMPORT_DATA:
1058
2
      break;
1059
1060
0
    default:
1061
      /* XXX code not yet written.  */
1062
0
      abort ();
1063
3
    }
1064
1065
  /* Now create a symbol describing the imported value.  */
1066
3
  switch (import_type)
1067
3
    {
1068
1
    case IMPORT_CODE:
1069
1
      pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1070
1
          BSF_NOT_AT_END | BSF_FUNCTION);
1071
1072
1
      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
3
    }
1082
1083
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1084
3
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1085
3
  if (ptr)
1086
0
    * ptr = 0;
1087
3
  pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1088
3
  if (ptr)
1089
0
    * ptr = '.';
1090
1091
  /* Initialise the bfd.  */
1092
3
  memset (& internal_f, 0, sizeof (internal_f));
1093
1094
3
  internal_f.f_magic  = magic;
1095
3
  internal_f.f_symptr = 0;
1096
3
  internal_f.f_nsyms  = 0;
1097
3
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1098
1099
3
  if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
1100
3
      || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1101
0
    goto error_return;
1102
1103
3
  if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL)
1104
0
    goto error_return;
1105
1106
3
  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
3
  bfd_cache_close (abfd);
1115
1116
3
  abfd->iostream = (void *) vars.bim;
1117
3
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1118
3
  abfd->iovec = &_bfd_memory_iovec;
1119
3
  abfd->where = 0;
1120
3
  abfd->origin = 0;
1121
3
  abfd->size = 0;
1122
3
  obj_sym_filepos (abfd) = 0;
1123
1124
  /* Point the bfd at the symbol table.  */
1125
3
  obj_symbols (abfd) = vars.sym_cache;
1126
3
  abfd->symcount = vars.sym_index;
1127
1128
3
  obj_raw_syments (abfd) = vars.native_syms;
1129
3
  obj_raw_syment_count (abfd) = vars.sym_index;
1130
1131
3
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1132
3
  obj_coff_keep_syms (abfd) = true;
1133
1134
3
  obj_convert (abfd) = vars.sym_table;
1135
3
  obj_conv_table_size (abfd) = vars.sym_index;
1136
1137
3
  obj_coff_strings (abfd) = vars.string_table;
1138
3
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1139
3
  obj_coff_keep_strings (abfd) = true;
1140
1141
3
  return true;
1142
1143
0
 error_return:
1144
0
  free (vars.bim->buffer);
1145
0
  free (vars.bim);
1146
0
  return false;
1147
3
}
pei-aarch64.c:pe_ILF_build_a_bfd
Line
Count
Source
786
6
{
787
6
  bfd_byte *       ptr;
788
6
  pe_ILF_vars      vars;
789
6
  struct internal_filehdr  internal_f;
790
6
  unsigned int       import_type;
791
6
  unsigned int       import_name_type;
792
6
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
793
6
  coff_symbol_type **    imp_sym;
794
6
  unsigned int       imp_index;
795
6
  intptr_t alignment;
796
797
  /* Decode and verify the types field of the ILF structure.  */
798
6
  import_type = types & 0x3;
799
6
  import_name_type = (types & 0x1c) >> 2;
800
801
6
  switch (import_type)
802
6
    {
803
3
    case IMPORT_CODE:
804
6
    case IMPORT_DATA:
805
6
      break;
806
807
0
    case IMPORT_CONST:
808
      /* XXX code yet to be written.  */
809
      /* xgettext:c-format */
810
0
      _bfd_error_handler (_("%pB: unhandled import type; %x"),
811
0
        abfd, import_type);
812
0
      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
6
    }
820
821
6
  switch (import_name_type)
822
6
    {
823
2
    case IMPORT_ORDINAL:
824
2
    case IMPORT_NAME:
825
2
    case IMPORT_NAME_NOPREFIX:
826
2
    case IMPORT_NAME_UNDECORATE:
827
2
      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
6
    }
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
2
  vars.bim
844
2
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
845
2
  if (vars.bim == NULL)
846
0
    return false;
847
848
2
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
849
2
  vars.bim->buffer = ptr;
850
2
  vars.bim->size   = ILF_DATA_SIZE;
851
2
  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
2
  vars.sym_cache = (coff_symbol_type *) ptr;
857
2
  vars.sym_ptr   = (coff_symbol_type *) ptr;
858
2
  vars.sym_index = 0;
859
2
  ptr += SIZEOF_ILF_SYMS;
860
861
2
  vars.sym_table = (unsigned int *) ptr;
862
2
  vars.table_ptr = (unsigned int *) ptr;
863
2
  ptr += SIZEOF_ILF_SYM_TABLE;
864
865
2
  vars.native_syms = (combined_entry_type *) ptr;
866
2
  vars.native_ptr  = (combined_entry_type *) ptr;
867
2
  ptr += SIZEOF_ILF_NATIVE_SYMS;
868
869
2
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
870
2
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
871
2
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
872
873
2
  vars.esym_table = (SYMENT *) ptr;
874
2
  vars.esym_ptr   = (SYMENT *) ptr;
875
2
  ptr += SIZEOF_ILF_EXT_SYMS;
876
877
2
  vars.reltab   = (arelent *) ptr;
878
2
  vars.relcount = 0;
879
2
  ptr += SIZEOF_ILF_RELOCS;
880
881
2
  vars.int_reltab  = (struct internal_reloc *) ptr;
882
2
  ptr += SIZEOF_ILF_INT_RELOCS;
883
884
2
  vars.string_table = (char *) ptr;
885
2
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
886
2
  ptr += SIZEOF_ILF_STRINGS;
887
2
  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
2
#if GCC_VERSION >= 3000
897
2
  alignment = __alignof__ (struct coff_section_tdata);
898
#else
899
  alignment = 8;
900
#endif
901
2
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
902
903
2
  vars.data = ptr;
904
2
  vars.abfd = abfd;
905
2
  vars.sec_index = 0;
906
2
  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
2
  id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
916
2
  id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
917
2
  if (id4 == NULL || id5 == NULL)
918
0
    goto error_return;
919
920
  /* Fill in the contents of these sections.  */
921
2
  if (import_name_type == IMPORT_ORDINAL)
922
2
    {
923
2
      if (ordinal == 0)
924
  /* See PR 20907 for a reproducer.  */
925
0
  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
0
  else
938
0
    {
939
0
      char * symbol;
940
0
      unsigned int len;
941
942
      /* Create .idata$6 - the Hint Name Table.  */
943
0
      id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
944
0
      if (id6 == NULL)
945
0
  goto error_return;
946
947
      /* If necessary, trim the import symbol name.  */
948
0
      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
0
      if (import_name_type != IMPORT_NAME)
958
0
  {
959
0
    char c = symbol[0];
960
961
    /* Check that we don't remove for targets with empty
962
       USER_LABEL_PREFIX the leading underscore.  */
963
0
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
964
0
        || c == '@' || c == '?')
965
0
      symbol++;
966
0
  }
967
968
0
      len = strlen (symbol);
969
0
      if (import_name_type == IMPORT_NAME_UNDECORATE)
970
0
  {
971
    /* Truncate at the first '@'.  */
972
0
    char *at = strchr (symbol, '@');
973
974
0
    if (at != NULL)
975
0
      len = at - symbol;
976
0
  }
977
978
0
      id6->contents[0] = ordinal & 0xff;
979
0
      id6->contents[1] = ordinal >> 8;
980
981
0
      memcpy ((char *) id6->contents + 2, symbol, len);
982
0
      id6->contents[len + 2] = '\0';
983
0
    }
984
985
2
  if (import_name_type != IMPORT_ORDINAL)
986
0
    {
987
0
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
988
0
      pe_ILF_save_relocs (&vars, id4);
989
990
0
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
991
0
      pe_ILF_save_relocs (&vars, id5);
992
0
    }
993
994
  /* Create an import symbol.  */
995
2
  pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
996
2
  imp_sym   = vars.sym_ptr_ptr - 1;
997
2
  imp_index = vars.sym_index - 1;
998
999
  /* Create extra sections depending upon the type of import we are dealing with.  */
1000
2
  switch (import_type)
1001
2
    {
1002
0
      int i;
1003
1004
1
    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
2
      for (i = NUM_ENTRIES (jtab); i--;)
1009
2
  {
1010
2
    if (jtab[i].size == 0)
1011
1
      continue;
1012
1
    if (jtab[i].magic == magic)
1013
1
      break;
1014
1
  }
1015
      /* If we did not find a matching entry something is wrong.  */
1016
1
      if (i < 0)
1017
0
  abort ();
1018
1019
      /* Create the .text section.  */
1020
1
      text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
1021
1
      if (text == NULL)
1022
0
  goto error_return;
1023
1024
      /* Copy in the jump code.  */
1025
1
      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
1
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1051
1
            BFD_RELOC_32, (asymbol **) imp_sym,
1052
1
            imp_index);
1053
1054
1
      pe_ILF_save_relocs (& vars, text);
1055
1
      break;
1056
1057
1
    case IMPORT_DATA:
1058
1
      break;
1059
1060
0
    default:
1061
      /* XXX code not yet written.  */
1062
0
      abort ();
1063
2
    }
1064
1065
  /* Now create a symbol describing the imported value.  */
1066
2
  switch (import_type)
1067
2
    {
1068
1
    case IMPORT_CODE:
1069
1
      pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1070
1
          BSF_NOT_AT_END | BSF_FUNCTION);
1071
1072
1
      break;
1073
1074
1
    case IMPORT_DATA:
1075
      /* Nothing to do here.  */
1076
1
      break;
1077
1078
0
    default:
1079
      /* XXX code not yet written.  */
1080
0
      abort ();
1081
2
    }
1082
1083
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1084
2
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1085
2
  if (ptr)
1086
0
    * ptr = 0;
1087
2
  pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1088
2
  if (ptr)
1089
0
    * ptr = '.';
1090
1091
  /* Initialise the bfd.  */
1092
2
  memset (& internal_f, 0, sizeof (internal_f));
1093
1094
2
  internal_f.f_magic  = magic;
1095
2
  internal_f.f_symptr = 0;
1096
2
  internal_f.f_nsyms  = 0;
1097
2
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1098
1099
2
  if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
1100
2
      || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1101
0
    goto error_return;
1102
1103
2
  if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL)
1104
0
    goto error_return;
1105
1106
2
  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
2
  bfd_cache_close (abfd);
1115
1116
2
  abfd->iostream = (void *) vars.bim;
1117
2
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1118
2
  abfd->iovec = &_bfd_memory_iovec;
1119
2
  abfd->where = 0;
1120
2
  abfd->origin = 0;
1121
2
  abfd->size = 0;
1122
2
  obj_sym_filepos (abfd) = 0;
1123
1124
  /* Point the bfd at the symbol table.  */
1125
2
  obj_symbols (abfd) = vars.sym_cache;
1126
2
  abfd->symcount = vars.sym_index;
1127
1128
2
  obj_raw_syments (abfd) = vars.native_syms;
1129
2
  obj_raw_syment_count (abfd) = vars.sym_index;
1130
1131
2
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1132
2
  obj_coff_keep_syms (abfd) = true;
1133
1134
2
  obj_convert (abfd) = vars.sym_table;
1135
2
  obj_conv_table_size (abfd) = vars.sym_index;
1136
1137
2
  obj_coff_strings (abfd) = vars.string_table;
1138
2
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1139
2
  obj_coff_keep_strings (abfd) = true;
1140
1141
2
  return true;
1142
1143
0
 error_return:
1144
0
  free (vars.bim->buffer);
1145
0
  free (vars.bim);
1146
0
  return false;
1147
2
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_build_a_bfd
pei-loongarch64.c:pe_ILF_build_a_bfd
Line
Count
Source
786
11
{
787
11
  bfd_byte *       ptr;
788
11
  pe_ILF_vars      vars;
789
11
  struct internal_filehdr  internal_f;
790
11
  unsigned int       import_type;
791
11
  unsigned int       import_name_type;
792
11
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
793
11
  coff_symbol_type **    imp_sym;
794
11
  unsigned int       imp_index;
795
11
  intptr_t alignment;
796
797
  /* Decode and verify the types field of the ILF structure.  */
798
11
  import_type = types & 0x3;
799
11
  import_name_type = (types & 0x1c) >> 2;
800
801
11
  switch (import_type)
802
11
    {
803
9
    case IMPORT_CODE:
804
11
    case IMPORT_DATA:
805
11
      break;
806
807
0
    case IMPORT_CONST:
808
      /* XXX code yet to be written.  */
809
      /* xgettext:c-format */
810
0
      _bfd_error_handler (_("%pB: unhandled import type; %x"),
811
0
        abfd, import_type);
812
0
      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
11
    }
820
821
11
  switch (import_name_type)
822
11
    {
823
6
    case IMPORT_ORDINAL:
824
9
    case IMPORT_NAME:
825
9
    case IMPORT_NAME_NOPREFIX:
826
9
    case IMPORT_NAME_UNDECORATE:
827
9
      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
11
    }
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
9
  vars.bim
844
9
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
845
9
  if (vars.bim == NULL)
846
0
    return false;
847
848
9
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
849
9
  vars.bim->buffer = ptr;
850
9
  vars.bim->size   = ILF_DATA_SIZE;
851
9
  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
9
  vars.sym_cache = (coff_symbol_type *) ptr;
857
9
  vars.sym_ptr   = (coff_symbol_type *) ptr;
858
9
  vars.sym_index = 0;
859
9
  ptr += SIZEOF_ILF_SYMS;
860
861
9
  vars.sym_table = (unsigned int *) ptr;
862
9
  vars.table_ptr = (unsigned int *) ptr;
863
9
  ptr += SIZEOF_ILF_SYM_TABLE;
864
865
9
  vars.native_syms = (combined_entry_type *) ptr;
866
9
  vars.native_ptr  = (combined_entry_type *) ptr;
867
9
  ptr += SIZEOF_ILF_NATIVE_SYMS;
868
869
9
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
870
9
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
871
9
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
872
873
9
  vars.esym_table = (SYMENT *) ptr;
874
9
  vars.esym_ptr   = (SYMENT *) ptr;
875
9
  ptr += SIZEOF_ILF_EXT_SYMS;
876
877
9
  vars.reltab   = (arelent *) ptr;
878
9
  vars.relcount = 0;
879
9
  ptr += SIZEOF_ILF_RELOCS;
880
881
9
  vars.int_reltab  = (struct internal_reloc *) ptr;
882
9
  ptr += SIZEOF_ILF_INT_RELOCS;
883
884
9
  vars.string_table = (char *) ptr;
885
9
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
886
9
  ptr += SIZEOF_ILF_STRINGS;
887
9
  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
9
#if GCC_VERSION >= 3000
897
9
  alignment = __alignof__ (struct coff_section_tdata);
898
#else
899
  alignment = 8;
900
#endif
901
9
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
902
903
9
  vars.data = ptr;
904
9
  vars.abfd = abfd;
905
9
  vars.sec_index = 0;
906
9
  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
9
  id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
916
9
  id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
917
9
  if (id4 == NULL || id5 == NULL)
918
0
    goto error_return;
919
920
  /* Fill in the contents of these sections.  */
921
9
  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
3
  else
938
3
    {
939
3
      char * symbol;
940
3
      unsigned int len;
941
942
      /* Create .idata$6 - the Hint Name Table.  */
943
3
      id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
944
3
      if (id6 == NULL)
945
0
  goto error_return;
946
947
      /* If necessary, trim the import symbol name.  */
948
3
      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
3
      if (import_name_type != IMPORT_NAME)
958
0
  {
959
0
    char c = symbol[0];
960
961
    /* Check that we don't remove for targets with empty
962
       USER_LABEL_PREFIX the leading underscore.  */
963
0
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
964
0
        || c == '@' || c == '?')
965
0
      symbol++;
966
0
  }
967
968
3
      len = strlen (symbol);
969
3
      if (import_name_type == IMPORT_NAME_UNDECORATE)
970
0
  {
971
    /* Truncate at the first '@'.  */
972
0
    char *at = strchr (symbol, '@');
973
974
0
    if (at != NULL)
975
0
      len = at - symbol;
976
0
  }
977
978
3
      id6->contents[0] = ordinal & 0xff;
979
3
      id6->contents[1] = ordinal >> 8;
980
981
3
      memcpy ((char *) id6->contents + 2, symbol, len);
982
3
      id6->contents[len + 2] = '\0';
983
3
    }
984
985
7
  if (import_name_type != IMPORT_ORDINAL)
986
3
    {
987
3
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
988
3
      pe_ILF_save_relocs (&vars, id4);
989
990
3
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
991
3
      pe_ILF_save_relocs (&vars, id5);
992
3
    }
993
994
  /* Create an import symbol.  */
995
7
  pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
996
7
  imp_sym   = vars.sym_ptr_ptr - 1;
997
7
  imp_index = vars.sym_index - 1;
998
999
  /* Create extra sections depending upon the type of import we are dealing with.  */
1000
7
  switch (import_type)
1001
7
    {
1002
0
      int i;
1003
1004
5
    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
10
      for (i = NUM_ENTRIES (jtab); i--;)
1009
10
  {
1010
10
    if (jtab[i].size == 0)
1011
5
      continue;
1012
5
    if (jtab[i].magic == magic)
1013
5
      break;
1014
5
  }
1015
      /* If we did not find a matching entry something is wrong.  */
1016
5
      if (i < 0)
1017
0
  abort ();
1018
1019
      /* Create the .text section.  */
1020
5
      text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
1021
5
      if (text == NULL)
1022
0
  goto error_return;
1023
1024
      /* Copy in the jump code.  */
1025
5
      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
5
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1051
5
            BFD_RELOC_32, (asymbol **) imp_sym,
1052
5
            imp_index);
1053
1054
5
      pe_ILF_save_relocs (& vars, text);
1055
5
      break;
1056
1057
2
    case IMPORT_DATA:
1058
2
      break;
1059
1060
0
    default:
1061
      /* XXX code not yet written.  */
1062
0
      abort ();
1063
7
    }
1064
1065
  /* Now create a symbol describing the imported value.  */
1066
7
  switch (import_type)
1067
7
    {
1068
5
    case IMPORT_CODE:
1069
5
      pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1070
5
          BSF_NOT_AT_END | BSF_FUNCTION);
1071
1072
5
      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
7
    }
1082
1083
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1084
7
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1085
7
  if (ptr)
1086
0
    * ptr = 0;
1087
7
  pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1088
7
  if (ptr)
1089
0
    * ptr = '.';
1090
1091
  /* Initialise the bfd.  */
1092
7
  memset (& internal_f, 0, sizeof (internal_f));
1093
1094
7
  internal_f.f_magic  = magic;
1095
7
  internal_f.f_symptr = 0;
1096
7
  internal_f.f_nsyms  = 0;
1097
7
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1098
1099
7
  if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
1100
7
      || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1101
0
    goto error_return;
1102
1103
7
  if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL)
1104
0
    goto error_return;
1105
1106
7
  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
7
  bfd_cache_close (abfd);
1115
1116
7
  abfd->iostream = (void *) vars.bim;
1117
7
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1118
7
  abfd->iovec = &_bfd_memory_iovec;
1119
7
  abfd->where = 0;
1120
7
  abfd->origin = 0;
1121
7
  abfd->size = 0;
1122
7
  obj_sym_filepos (abfd) = 0;
1123
1124
  /* Point the bfd at the symbol table.  */
1125
7
  obj_symbols (abfd) = vars.sym_cache;
1126
7
  abfd->symcount = vars.sym_index;
1127
1128
7
  obj_raw_syments (abfd) = vars.native_syms;
1129
7
  obj_raw_syment_count (abfd) = vars.sym_index;
1130
1131
7
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1132
7
  obj_coff_keep_syms (abfd) = true;
1133
1134
7
  obj_convert (abfd) = vars.sym_table;
1135
7
  obj_conv_table_size (abfd) = vars.sym_index;
1136
1137
7
  obj_coff_strings (abfd) = vars.string_table;
1138
7
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1139
7
  obj_coff_keep_strings (abfd) = true;
1140
1141
7
  return true;
1142
1143
2
 error_return:
1144
2
  free (vars.bim->buffer);
1145
2
  free (vars.bim);
1146
2
  return false;
1147
7
}
pei-arm-wince.c:pe_ILF_build_a_bfd
Line
Count
Source
786
15
{
787
15
  bfd_byte *       ptr;
788
15
  pe_ILF_vars      vars;
789
15
  struct internal_filehdr  internal_f;
790
15
  unsigned int       import_type;
791
15
  unsigned int       import_name_type;
792
15
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
793
15
  coff_symbol_type **    imp_sym;
794
15
  unsigned int       imp_index;
795
15
  intptr_t alignment;
796
797
  /* Decode and verify the types field of the ILF structure.  */
798
15
  import_type = types & 0x3;
799
15
  import_name_type = (types & 0x1c) >> 2;
800
801
15
  switch (import_type)
802
15
    {
803
8
    case IMPORT_CODE:
804
13
    case IMPORT_DATA:
805
13
      break;
806
807
1
    case IMPORT_CONST:
808
      /* XXX code yet to be written.  */
809
      /* xgettext:c-format */
810
1
      _bfd_error_handler (_("%pB: unhandled import type; %x"),
811
1
        abfd, import_type);
812
1
      return false;
813
814
1
    default:
815
      /* xgettext:c-format */
816
1
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
817
1
        abfd, import_type);
818
1
      return false;
819
15
    }
820
821
13
  switch (import_name_type)
822
13
    {
823
3
    case IMPORT_ORDINAL:
824
4
    case IMPORT_NAME:
825
9
    case IMPORT_NAME_NOPREFIX:
826
12
    case IMPORT_NAME_UNDECORATE:
827
12
      break;
828
829
1
    default:
830
      /* xgettext:c-format */
831
1
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
832
1
        abfd, import_name_type);
833
1
      return false;
834
13
    }
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
3
    {
923
3
      if (ordinal == 0)
924
  /* See PR 20907 for a reproducer.  */
925
1
  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
9
  else
938
9
    {
939
9
      char * symbol;
940
9
      unsigned int len;
941
942
      /* Create .idata$6 - the Hint Name Table.  */
943
9
      id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
944
9
      if (id6 == NULL)
945
0
  goto error_return;
946
947
      /* If necessary, trim the import symbol name.  */
948
9
      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
9
      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
1
      symbol++;
966
8
  }
967
968
9
      len = strlen (symbol);
969
9
      if (import_name_type == IMPORT_NAME_UNDECORATE)
970
3
  {
971
    /* Truncate at the first '@'.  */
972
3
    char *at = strchr (symbol, '@');
973
974
3
    if (at != NULL)
975
1
      len = at - symbol;
976
3
  }
977
978
9
      id6->contents[0] = ordinal & 0xff;
979
9
      id6->contents[1] = ordinal >> 8;
980
981
9
      memcpy ((char *) id6->contents + 2, symbol, len);
982
9
      id6->contents[len + 2] = '\0';
983
9
    }
984
985
11
  if (import_name_type != IMPORT_ORDINAL)
986
9
    {
987
9
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
988
9
      pe_ILF_save_relocs (&vars, id4);
989
990
9
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
991
9
      pe_ILF_save_relocs (&vars, id5);
992
9
    }
993
994
  /* Create an import symbol.  */
995
11
  pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
996
11
  imp_sym   = vars.sym_ptr_ptr - 1;
997
11
  imp_index = vars.sym_index - 1;
998
999
  /* Create extra sections depending upon the type of import we are dealing with.  */
1000
11
  switch (import_type)
1001
11
    {
1002
0
      int i;
1003
1004
7
    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
15
      for (i = NUM_ENTRIES (jtab); i--;)
1009
15
  {
1010
15
    if (jtab[i].size == 0)
1011
7
      continue;
1012
8
    if (jtab[i].magic == magic)
1013
7
      break;
1014
8
  }
1015
      /* If we did not find a matching entry something is wrong.  */
1016
7
      if (i < 0)
1017
0
  abort ();
1018
1019
      /* Create the .text section.  */
1020
7
      text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
1021
7
      if (text == NULL)
1022
0
  goto error_return;
1023
1024
      /* Copy in the jump code.  */
1025
7
      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
7
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1051
7
            BFD_RELOC_32, (asymbol **) imp_sym,
1052
7
            imp_index);
1053
1054
7
      pe_ILF_save_relocs (& vars, text);
1055
7
      break;
1056
1057
4
    case IMPORT_DATA:
1058
4
      break;
1059
1060
0
    default:
1061
      /* XXX code not yet written.  */
1062
0
      abort ();
1063
11
    }
1064
1065
  /* Now create a symbol describing the imported value.  */
1066
11
  switch (import_type)
1067
11
    {
1068
7
    case IMPORT_CODE:
1069
7
      pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1070
7
          BSF_NOT_AT_END | BSF_FUNCTION);
1071
1072
7
      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
11
    }
1082
1083
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1084
11
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1085
11
  if (ptr)
1086
1
    * ptr = 0;
1087
11
  pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1088
11
  if (ptr)
1089
1
    * ptr = '.';
1090
1091
  /* Initialise the bfd.  */
1092
11
  memset (& internal_f, 0, sizeof (internal_f));
1093
1094
11
  internal_f.f_magic  = magic;
1095
11
  internal_f.f_symptr = 0;
1096
11
  internal_f.f_nsyms  = 0;
1097
11
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1098
1099
11
  if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
1100
11
      || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1101
0
    goto error_return;
1102
1103
11
  if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL)
1104
0
    goto error_return;
1105
1106
11
  obj_pe (abfd) = true;
1107
11
#ifdef THUMBPEMAGIC
1108
11
  if (vars.magic == THUMBPEMAGIC)
1109
    /* Stop some linker warnings about thumb code not supporting interworking.  */
1110
10
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1111
11
#endif
1112
1113
  /* Switch from file contents to memory contents.  */
1114
11
  bfd_cache_close (abfd);
1115
1116
11
  abfd->iostream = (void *) vars.bim;
1117
11
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1118
11
  abfd->iovec = &_bfd_memory_iovec;
1119
11
  abfd->where = 0;
1120
11
  abfd->origin = 0;
1121
11
  abfd->size = 0;
1122
11
  obj_sym_filepos (abfd) = 0;
1123
1124
  /* Point the bfd at the symbol table.  */
1125
11
  obj_symbols (abfd) = vars.sym_cache;
1126
11
  abfd->symcount = vars.sym_index;
1127
1128
11
  obj_raw_syments (abfd) = vars.native_syms;
1129
11
  obj_raw_syment_count (abfd) = vars.sym_index;
1130
1131
11
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1132
11
  obj_coff_keep_syms (abfd) = true;
1133
1134
11
  obj_convert (abfd) = vars.sym_table;
1135
11
  obj_conv_table_size (abfd) = vars.sym_index;
1136
1137
11
  obj_coff_strings (abfd) = vars.string_table;
1138
11
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1139
11
  obj_coff_keep_strings (abfd) = true;
1140
1141
11
  return true;
1142
1143
1
 error_return:
1144
1
  free (vars.bim->buffer);
1145
1
  free (vars.bim);
1146
1
  return false;
1147
11
}
pei-arm.c:pe_ILF_build_a_bfd
Line
Count
Source
786
15
{
787
15
  bfd_byte *       ptr;
788
15
  pe_ILF_vars      vars;
789
15
  struct internal_filehdr  internal_f;
790
15
  unsigned int       import_type;
791
15
  unsigned int       import_name_type;
792
15
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
793
15
  coff_symbol_type **    imp_sym;
794
15
  unsigned int       imp_index;
795
15
  intptr_t alignment;
796
797
  /* Decode and verify the types field of the ILF structure.  */
798
15
  import_type = types & 0x3;
799
15
  import_name_type = (types & 0x1c) >> 2;
800
801
15
  switch (import_type)
802
15
    {
803
8
    case IMPORT_CODE:
804
13
    case IMPORT_DATA:
805
13
      break;
806
807
1
    case IMPORT_CONST:
808
      /* XXX code yet to be written.  */
809
      /* xgettext:c-format */
810
1
      _bfd_error_handler (_("%pB: unhandled import type; %x"),
811
1
        abfd, import_type);
812
1
      return false;
813
814
1
    default:
815
      /* xgettext:c-format */
816
1
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
817
1
        abfd, import_type);
818
1
      return false;
819
15
    }
820
821
13
  switch (import_name_type)
822
13
    {
823
3
    case IMPORT_ORDINAL:
824
4
    case IMPORT_NAME:
825
9
    case IMPORT_NAME_NOPREFIX:
826
12
    case IMPORT_NAME_UNDECORATE:
827
12
      break;
828
829
1
    default:
830
      /* xgettext:c-format */
831
1
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
832
1
        abfd, import_name_type);
833
1
      return false;
834
13
    }
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
3
    {
923
3
      if (ordinal == 0)
924
  /* See PR 20907 for a reproducer.  */
925
1
  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
9
  else
938
9
    {
939
9
      char * symbol;
940
9
      unsigned int len;
941
942
      /* Create .idata$6 - the Hint Name Table.  */
943
9
      id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
944
9
      if (id6 == NULL)
945
0
  goto error_return;
946
947
      /* If necessary, trim the import symbol name.  */
948
9
      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
9
      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
1
      symbol++;
966
8
  }
967
968
9
      len = strlen (symbol);
969
9
      if (import_name_type == IMPORT_NAME_UNDECORATE)
970
3
  {
971
    /* Truncate at the first '@'.  */
972
3
    char *at = strchr (symbol, '@');
973
974
3
    if (at != NULL)
975
1
      len = at - symbol;
976
3
  }
977
978
9
      id6->contents[0] = ordinal & 0xff;
979
9
      id6->contents[1] = ordinal >> 8;
980
981
9
      memcpy ((char *) id6->contents + 2, symbol, len);
982
9
      id6->contents[len + 2] = '\0';
983
9
    }
984
985
11
  if (import_name_type != IMPORT_ORDINAL)
986
9
    {
987
9
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
988
9
      pe_ILF_save_relocs (&vars, id4);
989
990
9
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
991
9
      pe_ILF_save_relocs (&vars, id5);
992
9
    }
993
994
  /* Create an import symbol.  */
995
11
  pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
996
11
  imp_sym   = vars.sym_ptr_ptr - 1;
997
11
  imp_index = vars.sym_index - 1;
998
999
  /* Create extra sections depending upon the type of import we are dealing with.  */
1000
11
  switch (import_type)
1001
11
    {
1002
0
      int i;
1003
1004
7
    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
15
      for (i = NUM_ENTRIES (jtab); i--;)
1009
15
  {
1010
15
    if (jtab[i].size == 0)
1011
7
      continue;
1012
8
    if (jtab[i].magic == magic)
1013
7
      break;
1014
8
  }
1015
      /* If we did not find a matching entry something is wrong.  */
1016
7
      if (i < 0)
1017
0
  abort ();
1018
1019
      /* Create the .text section.  */
1020
7
      text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
1021
7
      if (text == NULL)
1022
0
  goto error_return;
1023
1024
      /* Copy in the jump code.  */
1025
7
      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
7
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1051
7
            BFD_RELOC_32, (asymbol **) imp_sym,
1052
7
            imp_index);
1053
1054
7
      pe_ILF_save_relocs (& vars, text);
1055
7
      break;
1056
1057
4
    case IMPORT_DATA:
1058
4
      break;
1059
1060
0
    default:
1061
      /* XXX code not yet written.  */
1062
0
      abort ();
1063
11
    }
1064
1065
  /* Now create a symbol describing the imported value.  */
1066
11
  switch (import_type)
1067
11
    {
1068
7
    case IMPORT_CODE:
1069
7
      pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1070
7
          BSF_NOT_AT_END | BSF_FUNCTION);
1071
1072
7
      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
11
    }
1082
1083
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1084
11
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1085
11
  if (ptr)
1086
1
    * ptr = 0;
1087
11
  pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1088
11
  if (ptr)
1089
1
    * ptr = '.';
1090
1091
  /* Initialise the bfd.  */
1092
11
  memset (& internal_f, 0, sizeof (internal_f));
1093
1094
11
  internal_f.f_magic  = magic;
1095
11
  internal_f.f_symptr = 0;
1096
11
  internal_f.f_nsyms  = 0;
1097
11
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1098
1099
11
  if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
1100
11
      || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1101
0
    goto error_return;
1102
1103
11
  if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL)
1104
0
    goto error_return;
1105
1106
11
  obj_pe (abfd) = true;
1107
11
#ifdef THUMBPEMAGIC
1108
11
  if (vars.magic == THUMBPEMAGIC)
1109
    /* Stop some linker warnings about thumb code not supporting interworking.  */
1110
10
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1111
11
#endif
1112
1113
  /* Switch from file contents to memory contents.  */
1114
11
  bfd_cache_close (abfd);
1115
1116
11
  abfd->iostream = (void *) vars.bim;
1117
11
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1118
11
  abfd->iovec = &_bfd_memory_iovec;
1119
11
  abfd->where = 0;
1120
11
  abfd->origin = 0;
1121
11
  abfd->size = 0;
1122
11
  obj_sym_filepos (abfd) = 0;
1123
1124
  /* Point the bfd at the symbol table.  */
1125
11
  obj_symbols (abfd) = vars.sym_cache;
1126
11
  abfd->symcount = vars.sym_index;
1127
1128
11
  obj_raw_syments (abfd) = vars.native_syms;
1129
11
  obj_raw_syment_count (abfd) = vars.sym_index;
1130
1131
11
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1132
11
  obj_coff_keep_syms (abfd) = true;
1133
1134
11
  obj_convert (abfd) = vars.sym_table;
1135
11
  obj_conv_table_size (abfd) = vars.sym_index;
1136
1137
11
  obj_coff_strings (abfd) = vars.string_table;
1138
11
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1139
11
  obj_coff_keep_strings (abfd) = true;
1140
1141
11
  return true;
1142
1143
1
 error_return:
1144
1
  free (vars.bim->buffer);
1145
1
  free (vars.bim);
1146
1
  return false;
1147
11
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_build_a_bfd
pei-sh.c:pe_ILF_build_a_bfd
Line
Count
Source
786
59
{
787
59
  bfd_byte *       ptr;
788
59
  pe_ILF_vars      vars;
789
59
  struct internal_filehdr  internal_f;
790
59
  unsigned int       import_type;
791
59
  unsigned int       import_name_type;
792
59
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
793
59
  coff_symbol_type **    imp_sym;
794
59
  unsigned int       imp_index;
795
59
  intptr_t alignment;
796
797
  /* Decode and verify the types field of the ILF structure.  */
798
59
  import_type = types & 0x3;
799
59
  import_name_type = (types & 0x1c) >> 2;
800
801
59
  switch (import_type)
802
59
    {
803
24
    case IMPORT_CODE:
804
57
    case IMPORT_DATA:
805
57
      break;
806
807
1
    case IMPORT_CONST:
808
      /* XXX code yet to be written.  */
809
      /* xgettext:c-format */
810
1
      _bfd_error_handler (_("%pB: unhandled import type; %x"),
811
1
        abfd, import_type);
812
1
      return false;
813
814
1
    default:
815
      /* xgettext:c-format */
816
1
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
817
1
        abfd, import_type);
818
1
      return false;
819
59
    }
820
821
57
  switch (import_name_type)
822
57
    {
823
7
    case IMPORT_ORDINAL:
824
20
    case IMPORT_NAME:
825
40
    case IMPORT_NAME_NOPREFIX:
826
56
    case IMPORT_NAME_UNDECORATE:
827
56
      break;
828
829
1
    default:
830
      /* xgettext:c-format */
831
1
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
832
1
        abfd, import_name_type);
833
1
      return false;
834
57
    }
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
56
  vars.bim
844
56
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
845
56
  if (vars.bim == NULL)
846
0
    return false;
847
848
56
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
849
56
  vars.bim->buffer = ptr;
850
56
  vars.bim->size   = ILF_DATA_SIZE;
851
56
  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
56
  vars.sym_cache = (coff_symbol_type *) ptr;
857
56
  vars.sym_ptr   = (coff_symbol_type *) ptr;
858
56
  vars.sym_index = 0;
859
56
  ptr += SIZEOF_ILF_SYMS;
860
861
56
  vars.sym_table = (unsigned int *) ptr;
862
56
  vars.table_ptr = (unsigned int *) ptr;
863
56
  ptr += SIZEOF_ILF_SYM_TABLE;
864
865
56
  vars.native_syms = (combined_entry_type *) ptr;
866
56
  vars.native_ptr  = (combined_entry_type *) ptr;
867
56
  ptr += SIZEOF_ILF_NATIVE_SYMS;
868
869
56
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
870
56
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
871
56
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
872
873
56
  vars.esym_table = (SYMENT *) ptr;
874
56
  vars.esym_ptr   = (SYMENT *) ptr;
875
56
  ptr += SIZEOF_ILF_EXT_SYMS;
876
877
56
  vars.reltab   = (arelent *) ptr;
878
56
  vars.relcount = 0;
879
56
  ptr += SIZEOF_ILF_RELOCS;
880
881
56
  vars.int_reltab  = (struct internal_reloc *) ptr;
882
56
  ptr += SIZEOF_ILF_INT_RELOCS;
883
884
56
  vars.string_table = (char *) ptr;
885
56
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
886
56
  ptr += SIZEOF_ILF_STRINGS;
887
56
  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
56
#if GCC_VERSION >= 3000
897
56
  alignment = __alignof__ (struct coff_section_tdata);
898
#else
899
  alignment = 8;
900
#endif
901
56
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
902
903
56
  vars.data = ptr;
904
56
  vars.abfd = abfd;
905
56
  vars.sec_index = 0;
906
56
  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
56
  id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
916
56
  id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
917
56
  if (id4 == NULL || id5 == NULL)
918
0
    goto error_return;
919
920
  /* Fill in the contents of these sections.  */
921
56
  if (import_name_type == IMPORT_ORDINAL)
922
7
    {
923
7
      if (ordinal == 0)
924
  /* See PR 20907 for a reproducer.  */
925
1
  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
6
      * (unsigned int *) id4->contents = ordinal | 0x80000000;
934
6
      * (unsigned int *) id5->contents = ordinal | 0x80000000;
935
6
#endif
936
6
    }
937
49
  else
938
49
    {
939
49
      char * symbol;
940
49
      unsigned int len;
941
942
      /* Create .idata$6 - the Hint Name Table.  */
943
49
      id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
944
49
      if (id6 == NULL)
945
0
  goto error_return;
946
947
      /* If necessary, trim the import symbol name.  */
948
49
      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
49
      if (import_name_type != IMPORT_NAME)
958
36
  {
959
36
    char c = symbol[0];
960
961
    /* Check that we don't remove for targets with empty
962
       USER_LABEL_PREFIX the leading underscore.  */
963
36
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
964
36
        || c == '@' || c == '?')
965
1
      symbol++;
966
36
  }
967
968
49
      len = strlen (symbol);
969
49
      if (import_name_type == IMPORT_NAME_UNDECORATE)
970
16
  {
971
    /* Truncate at the first '@'.  */
972
16
    char *at = strchr (symbol, '@');
973
974
16
    if (at != NULL)
975
1
      len = at - symbol;
976
16
  }
977
978
49
      id6->contents[0] = ordinal & 0xff;
979
49
      id6->contents[1] = ordinal >> 8;
980
981
49
      memcpy ((char *) id6->contents + 2, symbol, len);
982
49
      id6->contents[len + 2] = '\0';
983
49
    }
984
985
55
  if (import_name_type != IMPORT_ORDINAL)
986
49
    {
987
49
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
988
49
      pe_ILF_save_relocs (&vars, id4);
989
990
49
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
991
49
      pe_ILF_save_relocs (&vars, id5);
992
49
    }
993
994
  /* Create an import symbol.  */
995
55
  pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
996
55
  imp_sym   = vars.sym_ptr_ptr - 1;
997
55
  imp_index = vars.sym_index - 1;
998
999
  /* Create extra sections depending upon the type of import we are dealing with.  */
1000
55
  switch (import_type)
1001
55
    {
1002
0
      int i;
1003
1004
22
    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
44
      for (i = NUM_ENTRIES (jtab); i--;)
1009
44
  {
1010
44
    if (jtab[i].size == 0)
1011
22
      continue;
1012
22
    if (jtab[i].magic == magic)
1013
22
      break;
1014
22
  }
1015
      /* If we did not find a matching entry something is wrong.  */
1016
22
      if (i < 0)
1017
0
  abort ();
1018
1019
      /* Create the .text section.  */
1020
22
      text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
1021
22
      if (text == NULL)
1022
0
  goto error_return;
1023
1024
      /* Copy in the jump code.  */
1025
22
      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
22
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1051
22
            BFD_RELOC_32, (asymbol **) imp_sym,
1052
22
            imp_index);
1053
1054
22
      pe_ILF_save_relocs (& vars, text);
1055
22
      break;
1056
1057
33
    case IMPORT_DATA:
1058
33
      break;
1059
1060
0
    default:
1061
      /* XXX code not yet written.  */
1062
0
      abort ();
1063
55
    }
1064
1065
  /* Now create a symbol describing the imported value.  */
1066
55
  switch (import_type)
1067
55
    {
1068
22
    case IMPORT_CODE:
1069
22
      pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1070
22
          BSF_NOT_AT_END | BSF_FUNCTION);
1071
1072
22
      break;
1073
1074
33
    case IMPORT_DATA:
1075
      /* Nothing to do here.  */
1076
33
      break;
1077
1078
0
    default:
1079
      /* XXX code not yet written.  */
1080
0
      abort ();
1081
55
    }
1082
1083
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1084
55
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1085
55
  if (ptr)
1086
2
    * ptr = 0;
1087
55
  pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1088
55
  if (ptr)
1089
2
    * ptr = '.';
1090
1091
  /* Initialise the bfd.  */
1092
55
  memset (& internal_f, 0, sizeof (internal_f));
1093
1094
55
  internal_f.f_magic  = magic;
1095
55
  internal_f.f_symptr = 0;
1096
55
  internal_f.f_nsyms  = 0;
1097
55
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1098
1099
55
  if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
1100
55
      || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1101
0
    goto error_return;
1102
1103
55
  if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL)
1104
0
    goto error_return;
1105
1106
55
  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
55
  bfd_cache_close (abfd);
1115
1116
55
  abfd->iostream = (void *) vars.bim;
1117
55
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1118
55
  abfd->iovec = &_bfd_memory_iovec;
1119
55
  abfd->where = 0;
1120
55
  abfd->origin = 0;
1121
55
  abfd->size = 0;
1122
55
  obj_sym_filepos (abfd) = 0;
1123
1124
  /* Point the bfd at the symbol table.  */
1125
55
  obj_symbols (abfd) = vars.sym_cache;
1126
55
  abfd->symcount = vars.sym_index;
1127
1128
55
  obj_raw_syments (abfd) = vars.native_syms;
1129
55
  obj_raw_syment_count (abfd) = vars.sym_index;
1130
1131
55
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1132
55
  obj_coff_keep_syms (abfd) = true;
1133
1134
55
  obj_convert (abfd) = vars.sym_table;
1135
55
  obj_conv_table_size (abfd) = vars.sym_index;
1136
1137
55
  obj_coff_strings (abfd) = vars.string_table;
1138
55
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1139
55
  obj_coff_keep_strings (abfd) = true;
1140
1141
55
  return true;
1142
1143
1
 error_return:
1144
1
  free (vars.bim->buffer);
1145
1
  free (vars.bim);
1146
1
  return false;
1147
55
}
1148
1149
/* Cleanup function, returned from check_format hook.  */
1150
1151
static void
1152
pe_ILF_cleanup (bfd *abfd)
1153
22
{
1154
22
  coff_object_cleanup (abfd);
1155
1156
22
  struct bfd_in_memory *bim = abfd->iostream;
1157
22
  free (bim->buffer);
1158
22
  free (bim);
1159
22
  abfd->iostream = NULL;
1160
22
}
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
11
{
1154
11
  coff_object_cleanup (abfd);
1155
1156
11
  struct bfd_in_memory *bim = abfd->iostream;
1157
11
  free (bim->buffer);
1158
11
  free (bim);
1159
11
  abfd->iostream = NULL;
1160
11
}
pei-arm.c:pe_ILF_cleanup
Line
Count
Source
1153
11
{
1154
11
  coff_object_cleanup (abfd);
1155
1156
11
  struct bfd_in_memory *bim = abfd->iostream;
1157
11
  free (bim->buffer);
1158
11
  free (bim);
1159
11
  abfd->iostream = NULL;
1160
11
}
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.70k
{
1168
1.70k
  bfd_byte    buffer[14];
1169
1.70k
  bfd_byte *    ptr;
1170
1.70k
  char *    symbol_name;
1171
1.70k
  char *    source_dll;
1172
1.70k
  unsigned int    machine;
1173
1.70k
  bfd_size_type   size;
1174
1.70k
  unsigned int    ordinal;
1175
1.70k
  unsigned int    types;
1176
1.70k
  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.70k
  if (bfd_read (buffer, 14, abfd) != 14)
1181
24
    return NULL;
1182
1183
1.68k
  ptr = buffer;
1184
1185
1.68k
  machine = H_GET_16 (abfd, ptr);
1186
1.68k
  ptr += 2;
1187
1188
  /* Check that the machine type is recognised.  */
1189
1.68k
  magic = 0;
1190
1191
1.68k
  switch (machine)
1192
1.68k
    {
1193
12
    case IMAGE_FILE_MACHINE_UNKNOWN:
1194
24
    case IMAGE_FILE_MACHINE_ALPHA:
1195
24
    case IMAGE_FILE_MACHINE_ALPHA64:
1196
36
    case IMAGE_FILE_MACHINE_IA64:
1197
36
      break;
1198
1199
156
    case IMAGE_FILE_MACHINE_I386:
1200
#ifdef I386MAGIC
1201
25
      magic = I386MAGIC;
1202
#endif
1203
156
      break;
1204
1205
108
    case IMAGE_FILE_MACHINE_AMD64:
1206
#ifdef AMD64MAGIC
1207
17
      magic = AMD64MAGIC;
1208
#endif
1209
108
      break;
1210
1211
12
    case IMAGE_FILE_MACHINE_R3000:
1212
12
    case IMAGE_FILE_MACHINE_R4000:
1213
24
    case IMAGE_FILE_MACHINE_R10000:
1214
1215
24
    case IMAGE_FILE_MACHINE_MIPS16:
1216
24
    case IMAGE_FILE_MACHINE_MIPSFPU:
1217
24
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1218
#ifdef MIPS_ARCH_MAGIC_WINCE
1219
      magic = MIPS_ARCH_MAGIC_WINCE;
1220
#endif
1221
24
      break;
1222
1223
528
    case IMAGE_FILE_MACHINE_SH3:
1224
572
    case IMAGE_FILE_MACHINE_SH4:
1225
#ifdef SH_ARCH_MAGIC_WINCE
1226
66
      magic = SH_ARCH_MAGIC_WINCE;
1227
#endif
1228
572
      break;
1229
1230
32
    case IMAGE_FILE_MACHINE_ARM:
1231
#ifdef ARMPEMAGIC
1232
6
      magic = ARMPEMAGIC;
1233
#endif
1234
32
      break;
1235
1236
88
    case IMAGE_FILE_MACHINE_ARM64:
1237
#ifdef AARCH64MAGIC
1238
14
      magic = AARCH64MAGIC;
1239
#endif
1240
88
      break;
1241
1242
104
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1243
#ifdef LOONGARCH64MAGIC
1244
15
      magic = LOONGARCH64MAGIC;
1245
#endif
1246
104
      break;
1247
1248
284
    case IMAGE_FILE_MACHINE_THUMB:
1249
#ifdef THUMBPEMAGIC
1250
      {
1251
  extern const bfd_target TARGET_LITTLE_SYM;
1252
1253
54
  if (abfd->xvec == & TARGET_LITTLE_SYM)
1254
54
    magic = THUMBPEMAGIC;
1255
      }
1256
#endif
1257
284
      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.68k
    }
1272
1273
1.40k
  if (magic == 0)
1274
1.20k
    {
1275
1.20k
      _bfd_error_handler
1276
  /* xgettext:c-format */
1277
1.20k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1278
1.20k
     " in Import Library Format archive"),
1279
1.20k
   abfd, machine);
1280
1.20k
      bfd_set_error (bfd_error_wrong_format);
1281
1282
1.20k
      return NULL;
1283
1.20k
    }
1284
1285
  /* We do not bother to check the date.
1286
     date = H_GET_32 (abfd, ptr);  */
1287
197
  ptr += 4;
1288
1289
197
  size = H_GET_32 (abfd, ptr);
1290
197
  ptr += 4;
1291
1292
197
  if (size == 0)
1293
9
    {
1294
9
      _bfd_error_handler
1295
9
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1296
9
      bfd_set_error (bfd_error_malformed_archive);
1297
1298
9
      return NULL;
1299
9
    }
1300
1301
188
  ordinal = H_GET_16 (abfd, ptr);
1302
188
  ptr += 2;
1303
1304
188
  types = H_GET_16 (abfd, ptr);
1305
  /* ptr += 2; */
1306
1307
  /* Now read in the two strings that follow.  */
1308
188
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1309
188
  if (ptr == NULL)
1310
48
    return NULL;
1311
1312
140
  symbol_name = (char *) ptr;
1313
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1314
140
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1315
1316
  /* Verify that the strings are null terminated.  */
1317
140
  if (ptr[size - 1] != 0
1318
140
      || (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
120
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1329
120
          source_dll, ordinal, types))
1330
28
    {
1331
28
      bfd_release (abfd, ptr);
1332
28
      return NULL;
1333
28
    }
1334
1335
92
  return pe_ILF_cleanup;
1336
120
}
pei-i386.c:pe_ILF_object_p
Line
Count
Source
1167
255
{
1168
255
  bfd_byte    buffer[14];
1169
255
  bfd_byte *    ptr;
1170
255
  char *    symbol_name;
1171
255
  char *    source_dll;
1172
255
  unsigned int    machine;
1173
255
  bfd_size_type   size;
1174
255
  unsigned int    ordinal;
1175
255
  unsigned int    types;
1176
255
  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
255
  if (bfd_read (buffer, 14, abfd) != 14)
1181
4
    return NULL;
1182
1183
251
  ptr = buffer;
1184
1185
251
  machine = H_GET_16 (abfd, ptr);
1186
251
  ptr += 2;
1187
1188
  /* Check that the machine type is recognised.  */
1189
251
  magic = 0;
1190
1191
251
  switch (machine)
1192
251
    {
1193
2
    case IMAGE_FILE_MACHINE_UNKNOWN:
1194
4
    case IMAGE_FILE_MACHINE_ALPHA:
1195
4
    case IMAGE_FILE_MACHINE_ALPHA64:
1196
6
    case IMAGE_FILE_MACHINE_IA64:
1197
6
      break;
1198
1199
25
    case IMAGE_FILE_MACHINE_I386:
1200
25
#ifdef I386MAGIC
1201
25
      magic = I386MAGIC;
1202
25
#endif
1203
25
      break;
1204
1205
17
    case IMAGE_FILE_MACHINE_AMD64:
1206
#ifdef AMD64MAGIC
1207
      magic = AMD64MAGIC;
1208
#endif
1209
17
      break;
1210
1211
2
    case IMAGE_FILE_MACHINE_R3000:
1212
2
    case IMAGE_FILE_MACHINE_R4000:
1213
4
    case IMAGE_FILE_MACHINE_R10000:
1214
1215
4
    case IMAGE_FILE_MACHINE_MIPS16:
1216
4
    case IMAGE_FILE_MACHINE_MIPSFPU:
1217
4
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1218
#ifdef MIPS_ARCH_MAGIC_WINCE
1219
      magic = MIPS_ARCH_MAGIC_WINCE;
1220
#endif
1221
4
      break;
1222
1223
71
    case IMAGE_FILE_MACHINE_SH3:
1224
77
    case IMAGE_FILE_MACHINE_SH4:
1225
#ifdef SH_ARCH_MAGIC_WINCE
1226
      magic = SH_ARCH_MAGIC_WINCE;
1227
#endif
1228
77
      break;
1229
1230
5
    case IMAGE_FILE_MACHINE_ARM:
1231
#ifdef ARMPEMAGIC
1232
      magic = ARMPEMAGIC;
1233
#endif
1234
5
      break;
1235
1236
14
    case IMAGE_FILE_MACHINE_ARM64:
1237
#ifdef AARCH64MAGIC
1238
      magic = AARCH64MAGIC;
1239
#endif
1240
14
      break;
1241
1242
15
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1243
#ifdef LOONGARCH64MAGIC
1244
      magic = LOONGARCH64MAGIC;
1245
#endif
1246
15
      break;
1247
1248
44
    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
44
      break;
1258
1259
0
    case IMAGE_FILE_MACHINE_POWERPC:
1260
      /* We no longer support PowerPC.  */
1261
44
    default:
1262
44
      _bfd_error_handler
1263
  /* xgettext:c-format */
1264
44
  (_("%pB: unrecognised machine type (0x%x)"
1265
44
     " in Import Library Format archive"),
1266
44
   abfd, machine);
1267
44
      bfd_set_error (bfd_error_malformed_archive);
1268
1269
44
      return NULL;
1270
0
      break;
1271
251
    }
1272
1273
207
  if (magic == 0)
1274
182
    {
1275
182
      _bfd_error_handler
1276
  /* xgettext:c-format */
1277
182
  (_("%pB: recognised but unhandled machine type (0x%x)"
1278
182
     " in Import Library Format archive"),
1279
182
   abfd, machine);
1280
182
      bfd_set_error (bfd_error_wrong_format);
1281
1282
182
      return NULL;
1283
182
    }
1284
1285
  /* We do not bother to check the date.
1286
     date = H_GET_32 (abfd, ptr);  */
1287
25
  ptr += 4;
1288
1289
25
  size = H_GET_32 (abfd, ptr);
1290
25
  ptr += 4;
1291
1292
25
  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
23
  ordinal = H_GET_16 (abfd, ptr);
1302
23
  ptr += 2;
1303
1304
23
  types = H_GET_16 (abfd, ptr);
1305
  /* ptr += 2; */
1306
1307
  /* Now read in the two strings that follow.  */
1308
23
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1309
23
  if (ptr == NULL)
1310
12
    return NULL;
1311
1312
11
  symbol_name = (char *) ptr;
1313
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1314
11
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1315
1316
  /* Verify that the strings are null terminated.  */
1317
11
  if (ptr[size - 1] != 0
1318
11
      || (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
7
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1329
7
          source_dll, ordinal, types))
1330
4
    {
1331
4
      bfd_release (abfd, ptr);
1332
4
      return NULL;
1333
4
    }
1334
1335
3
  return pe_ILF_cleanup;
1336
7
}
pei-x86_64.c:pe_ILF_object_p
Line
Count
Source
1167
255
{
1168
255
  bfd_byte    buffer[14];
1169
255
  bfd_byte *    ptr;
1170
255
  char *    symbol_name;
1171
255
  char *    source_dll;
1172
255
  unsigned int    machine;
1173
255
  bfd_size_type   size;
1174
255
  unsigned int    ordinal;
1175
255
  unsigned int    types;
1176
255
  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
255
  if (bfd_read (buffer, 14, abfd) != 14)
1181
4
    return NULL;
1182
1183
251
  ptr = buffer;
1184
1185
251
  machine = H_GET_16 (abfd, ptr);
1186
251
  ptr += 2;
1187
1188
  /* Check that the machine type is recognised.  */
1189
251
  magic = 0;
1190
1191
251
  switch (machine)
1192
251
    {
1193
2
    case IMAGE_FILE_MACHINE_UNKNOWN:
1194
4
    case IMAGE_FILE_MACHINE_ALPHA:
1195
4
    case IMAGE_FILE_MACHINE_ALPHA64:
1196
6
    case IMAGE_FILE_MACHINE_IA64:
1197
6
      break;
1198
1199
25
    case IMAGE_FILE_MACHINE_I386:
1200
#ifdef I386MAGIC
1201
      magic = I386MAGIC;
1202
#endif
1203
25
      break;
1204
1205
17
    case IMAGE_FILE_MACHINE_AMD64:
1206
17
#ifdef AMD64MAGIC
1207
17
      magic = AMD64MAGIC;
1208
17
#endif
1209
17
      break;
1210
1211
2
    case IMAGE_FILE_MACHINE_R3000:
1212
2
    case IMAGE_FILE_MACHINE_R4000:
1213
4
    case IMAGE_FILE_MACHINE_R10000:
1214
1215
4
    case IMAGE_FILE_MACHINE_MIPS16:
1216
4
    case IMAGE_FILE_MACHINE_MIPSFPU:
1217
4
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1218
#ifdef MIPS_ARCH_MAGIC_WINCE
1219
      magic = MIPS_ARCH_MAGIC_WINCE;
1220
#endif
1221
4
      break;
1222
1223
71
    case IMAGE_FILE_MACHINE_SH3:
1224
77
    case IMAGE_FILE_MACHINE_SH4:
1225
#ifdef SH_ARCH_MAGIC_WINCE
1226
      magic = SH_ARCH_MAGIC_WINCE;
1227
#endif
1228
77
      break;
1229
1230
5
    case IMAGE_FILE_MACHINE_ARM:
1231
#ifdef ARMPEMAGIC
1232
      magic = ARMPEMAGIC;
1233
#endif
1234
5
      break;
1235
1236
14
    case IMAGE_FILE_MACHINE_ARM64:
1237
#ifdef AARCH64MAGIC
1238
      magic = AARCH64MAGIC;
1239
#endif
1240
14
      break;
1241
1242
15
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1243
#ifdef LOONGARCH64MAGIC
1244
      magic = LOONGARCH64MAGIC;
1245
#endif
1246
15
      break;
1247
1248
44
    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
44
      break;
1258
1259
0
    case IMAGE_FILE_MACHINE_POWERPC:
1260
      /* We no longer support PowerPC.  */
1261
44
    default:
1262
44
      _bfd_error_handler
1263
  /* xgettext:c-format */
1264
44
  (_("%pB: unrecognised machine type (0x%x)"
1265
44
     " in Import Library Format archive"),
1266
44
   abfd, machine);
1267
44
      bfd_set_error (bfd_error_malformed_archive);
1268
1269
44
      return NULL;
1270
0
      break;
1271
251
    }
1272
1273
207
  if (magic == 0)
1274
190
    {
1275
190
      _bfd_error_handler
1276
  /* xgettext:c-format */
1277
190
  (_("%pB: recognised but unhandled machine type (0x%x)"
1278
190
     " in Import Library Format archive"),
1279
190
   abfd, machine);
1280
190
      bfd_set_error (bfd_error_wrong_format);
1281
1282
190
      return NULL;
1283
190
    }
1284
1285
  /* We do not bother to check the date.
1286
     date = H_GET_32 (abfd, ptr);  */
1287
17
  ptr += 4;
1288
1289
17
  size = H_GET_32 (abfd, ptr);
1290
17
  ptr += 4;
1291
1292
17
  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
15
  ordinal = H_GET_16 (abfd, ptr);
1302
15
  ptr += 2;
1303
1304
15
  types = H_GET_16 (abfd, ptr);
1305
  /* ptr += 2; */
1306
1307
  /* Now read in the two strings that follow.  */
1308
15
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1309
15
  if (ptr == NULL)
1310
4
    return NULL;
1311
1312
11
  symbol_name = (char *) ptr;
1313
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1314
11
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1315
1316
  /* Verify that the strings are null terminated.  */
1317
11
  if (ptr[size - 1] != 0
1318
11
      || (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
7
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1329
7
          source_dll, ordinal, types))
1330
4
    {
1331
4
      bfd_release (abfd, ptr);
1332
4
      return NULL;
1333
4
    }
1334
1335
3
  return pe_ILF_cleanup;
1336
7
}
pei-aarch64.c:pe_ILF_object_p
Line
Count
Source
1167
255
{
1168
255
  bfd_byte    buffer[14];
1169
255
  bfd_byte *    ptr;
1170
255
  char *    symbol_name;
1171
255
  char *    source_dll;
1172
255
  unsigned int    machine;
1173
255
  bfd_size_type   size;
1174
255
  unsigned int    ordinal;
1175
255
  unsigned int    types;
1176
255
  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
255
  if (bfd_read (buffer, 14, abfd) != 14)
1181
4
    return NULL;
1182
1183
251
  ptr = buffer;
1184
1185
251
  machine = H_GET_16 (abfd, ptr);
1186
251
  ptr += 2;
1187
1188
  /* Check that the machine type is recognised.  */
1189
251
  magic = 0;
1190
1191
251
  switch (machine)
1192
251
    {
1193
2
    case IMAGE_FILE_MACHINE_UNKNOWN:
1194
4
    case IMAGE_FILE_MACHINE_ALPHA:
1195
4
    case IMAGE_FILE_MACHINE_ALPHA64:
1196
6
    case IMAGE_FILE_MACHINE_IA64:
1197
6
      break;
1198
1199
25
    case IMAGE_FILE_MACHINE_I386:
1200
#ifdef I386MAGIC
1201
      magic = I386MAGIC;
1202
#endif
1203
25
      break;
1204
1205
17
    case IMAGE_FILE_MACHINE_AMD64:
1206
#ifdef AMD64MAGIC
1207
      magic = AMD64MAGIC;
1208
#endif
1209
17
      break;
1210
1211
2
    case IMAGE_FILE_MACHINE_R3000:
1212
2
    case IMAGE_FILE_MACHINE_R4000:
1213
4
    case IMAGE_FILE_MACHINE_R10000:
1214
1215
4
    case IMAGE_FILE_MACHINE_MIPS16:
1216
4
    case IMAGE_FILE_MACHINE_MIPSFPU:
1217
4
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1218
#ifdef MIPS_ARCH_MAGIC_WINCE
1219
      magic = MIPS_ARCH_MAGIC_WINCE;
1220
#endif
1221
4
      break;
1222
1223
71
    case IMAGE_FILE_MACHINE_SH3:
1224
77
    case IMAGE_FILE_MACHINE_SH4:
1225
#ifdef SH_ARCH_MAGIC_WINCE
1226
      magic = SH_ARCH_MAGIC_WINCE;
1227
#endif
1228
77
      break;
1229
1230
5
    case IMAGE_FILE_MACHINE_ARM:
1231
#ifdef ARMPEMAGIC
1232
      magic = ARMPEMAGIC;
1233
#endif
1234
5
      break;
1235
1236
14
    case IMAGE_FILE_MACHINE_ARM64:
1237
14
#ifdef AARCH64MAGIC
1238
14
      magic = AARCH64MAGIC;
1239
14
#endif
1240
14
      break;
1241
1242
15
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1243
#ifdef LOONGARCH64MAGIC
1244
      magic = LOONGARCH64MAGIC;
1245
#endif
1246
15
      break;
1247
1248
44
    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
44
      break;
1258
1259
0
    case IMAGE_FILE_MACHINE_POWERPC:
1260
      /* We no longer support PowerPC.  */
1261
44
    default:
1262
44
      _bfd_error_handler
1263
  /* xgettext:c-format */
1264
44
  (_("%pB: unrecognised machine type (0x%x)"
1265
44
     " in Import Library Format archive"),
1266
44
   abfd, machine);
1267
44
      bfd_set_error (bfd_error_malformed_archive);
1268
1269
44
      return NULL;
1270
0
      break;
1271
251
    }
1272
1273
207
  if (magic == 0)
1274
193
    {
1275
193
      _bfd_error_handler
1276
  /* xgettext:c-format */
1277
193
  (_("%pB: recognised but unhandled machine type (0x%x)"
1278
193
     " in Import Library Format archive"),
1279
193
   abfd, machine);
1280
193
      bfd_set_error (bfd_error_wrong_format);
1281
1282
193
      return NULL;
1283
193
    }
1284
1285
  /* We do not bother to check the date.
1286
     date = H_GET_32 (abfd, ptr);  */
1287
14
  ptr += 4;
1288
1289
14
  size = H_GET_32 (abfd, ptr);
1290
14
  ptr += 4;
1291
1292
14
  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
12
  ordinal = H_GET_16 (abfd, ptr);
1302
12
  ptr += 2;
1303
1304
12
  types = H_GET_16 (abfd, ptr);
1305
  /* ptr += 2; */
1306
1307
  /* Now read in the two strings that follow.  */
1308
12
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1309
12
  if (ptr == NULL)
1310
4
    return NULL;
1311
1312
8
  symbol_name = (char *) ptr;
1313
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1314
8
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1315
1316
  /* Verify that the strings are null terminated.  */
1317
8
  if (ptr[size - 1] != 0
1318
8
      || (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
6
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1329
6
          source_dll, ordinal, types))
1330
4
    {
1331
4
      bfd_release (abfd, ptr);
1332
4
      return NULL;
1333
4
    }
1334
1335
2
  return pe_ILF_cleanup;
1336
6
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_object_p
pei-loongarch64.c:pe_ILF_object_p
Line
Count
Source
1167
255
{
1168
255
  bfd_byte    buffer[14];
1169
255
  bfd_byte *    ptr;
1170
255
  char *    symbol_name;
1171
255
  char *    source_dll;
1172
255
  unsigned int    machine;
1173
255
  bfd_size_type   size;
1174
255
  unsigned int    ordinal;
1175
255
  unsigned int    types;
1176
255
  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
255
  if (bfd_read (buffer, 14, abfd) != 14)
1181
4
    return NULL;
1182
1183
251
  ptr = buffer;
1184
1185
251
  machine = H_GET_16 (abfd, ptr);
1186
251
  ptr += 2;
1187
1188
  /* Check that the machine type is recognised.  */
1189
251
  magic = 0;
1190
1191
251
  switch (machine)
1192
251
    {
1193
2
    case IMAGE_FILE_MACHINE_UNKNOWN:
1194
4
    case IMAGE_FILE_MACHINE_ALPHA:
1195
4
    case IMAGE_FILE_MACHINE_ALPHA64:
1196
6
    case IMAGE_FILE_MACHINE_IA64:
1197
6
      break;
1198
1199
25
    case IMAGE_FILE_MACHINE_I386:
1200
#ifdef I386MAGIC
1201
      magic = I386MAGIC;
1202
#endif
1203
25
      break;
1204
1205
17
    case IMAGE_FILE_MACHINE_AMD64:
1206
#ifdef AMD64MAGIC
1207
      magic = AMD64MAGIC;
1208
#endif
1209
17
      break;
1210
1211
2
    case IMAGE_FILE_MACHINE_R3000:
1212
2
    case IMAGE_FILE_MACHINE_R4000:
1213
4
    case IMAGE_FILE_MACHINE_R10000:
1214
1215
4
    case IMAGE_FILE_MACHINE_MIPS16:
1216
4
    case IMAGE_FILE_MACHINE_MIPSFPU:
1217
4
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1218
#ifdef MIPS_ARCH_MAGIC_WINCE
1219
      magic = MIPS_ARCH_MAGIC_WINCE;
1220
#endif
1221
4
      break;
1222
1223
71
    case IMAGE_FILE_MACHINE_SH3:
1224
77
    case IMAGE_FILE_MACHINE_SH4:
1225
#ifdef SH_ARCH_MAGIC_WINCE
1226
      magic = SH_ARCH_MAGIC_WINCE;
1227
#endif
1228
77
      break;
1229
1230
5
    case IMAGE_FILE_MACHINE_ARM:
1231
#ifdef ARMPEMAGIC
1232
      magic = ARMPEMAGIC;
1233
#endif
1234
5
      break;
1235
1236
14
    case IMAGE_FILE_MACHINE_ARM64:
1237
#ifdef AARCH64MAGIC
1238
      magic = AARCH64MAGIC;
1239
#endif
1240
14
      break;
1241
1242
15
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1243
15
#ifdef LOONGARCH64MAGIC
1244
15
      magic = LOONGARCH64MAGIC;
1245
15
#endif
1246
15
      break;
1247
1248
44
    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
44
      break;
1258
1259
0
    case IMAGE_FILE_MACHINE_POWERPC:
1260
      /* We no longer support PowerPC.  */
1261
44
    default:
1262
44
      _bfd_error_handler
1263
  /* xgettext:c-format */
1264
44
  (_("%pB: unrecognised machine type (0x%x)"
1265
44
     " in Import Library Format archive"),
1266
44
   abfd, machine);
1267
44
      bfd_set_error (bfd_error_malformed_archive);
1268
1269
44
      return NULL;
1270
0
      break;
1271
251
    }
1272
1273
207
  if (magic == 0)
1274
192
    {
1275
192
      _bfd_error_handler
1276
  /* xgettext:c-format */
1277
192
  (_("%pB: recognised but unhandled machine type (0x%x)"
1278
192
     " in Import Library Format archive"),
1279
192
   abfd, machine);
1280
192
      bfd_set_error (bfd_error_wrong_format);
1281
1282
192
      return NULL;
1283
192
    }
1284
1285
  /* We do not bother to check the date.
1286
     date = H_GET_32 (abfd, ptr);  */
1287
15
  ptr += 4;
1288
1289
15
  size = H_GET_32 (abfd, ptr);
1290
15
  ptr += 4;
1291
1292
15
  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
15
  ordinal = H_GET_16 (abfd, ptr);
1302
15
  ptr += 2;
1303
1304
15
  types = H_GET_16 (abfd, ptr);
1305
  /* ptr += 2; */
1306
1307
  /* Now read in the two strings that follow.  */
1308
15
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1309
15
  if (ptr == NULL)
1310
2
    return NULL;
1311
1312
13
  symbol_name = (char *) ptr;
1313
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1314
13
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1315
1316
  /* Verify that the strings are null terminated.  */
1317
13
  if (ptr[size - 1] != 0
1318
13
      || (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
11
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1329
11
          source_dll, ordinal, types))
1330
4
    {
1331
4
      bfd_release (abfd, ptr);
1332
4
      return NULL;
1333
4
    }
1334
1335
7
  return pe_ILF_cleanup;
1336
11
}
pei-arm-wince.c:pe_ILF_object_p
Line
Count
Source
1167
172
{
1168
172
  bfd_byte    buffer[14];
1169
172
  bfd_byte *    ptr;
1170
172
  char *    symbol_name;
1171
172
  char *    source_dll;
1172
172
  unsigned int    machine;
1173
172
  bfd_size_type   size;
1174
172
  unsigned int    ordinal;
1175
172
  unsigned int    types;
1176
172
  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
172
  if (bfd_read (buffer, 14, abfd) != 14)
1181
2
    return NULL;
1182
1183
170
  ptr = buffer;
1184
1185
170
  machine = H_GET_16 (abfd, ptr);
1186
170
  ptr += 2;
1187
1188
  /* Check that the machine type is recognised.  */
1189
170
  magic = 0;
1190
1191
170
  switch (machine)
1192
170
    {
1193
1
    case IMAGE_FILE_MACHINE_UNKNOWN:
1194
2
    case IMAGE_FILE_MACHINE_ALPHA:
1195
2
    case IMAGE_FILE_MACHINE_ALPHA64:
1196
3
    case IMAGE_FILE_MACHINE_IA64:
1197
3
      break;
1198
1199
14
    case IMAGE_FILE_MACHINE_I386:
1200
#ifdef I386MAGIC
1201
      magic = I386MAGIC;
1202
#endif
1203
14
      break;
1204
1205
10
    case IMAGE_FILE_MACHINE_AMD64:
1206
#ifdef AMD64MAGIC
1207
      magic = AMD64MAGIC;
1208
#endif
1209
10
      break;
1210
1211
1
    case IMAGE_FILE_MACHINE_R3000:
1212
1
    case IMAGE_FILE_MACHINE_R4000:
1213
2
    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
61
    case IMAGE_FILE_MACHINE_SH3:
1224
66
    case IMAGE_FILE_MACHINE_SH4:
1225
#ifdef SH_ARCH_MAGIC_WINCE
1226
      magic = SH_ARCH_MAGIC_WINCE;
1227
#endif
1228
66
      break;
1229
1230
3
    case IMAGE_FILE_MACHINE_ARM:
1231
3
#ifdef ARMPEMAGIC
1232
3
      magic = ARMPEMAGIC;
1233
3
#endif
1234
3
      break;
1235
1236
8
    case IMAGE_FILE_MACHINE_ARM64:
1237
#ifdef AARCH64MAGIC
1238
      magic = AARCH64MAGIC;
1239
#endif
1240
8
      break;
1241
1242
11
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1243
#ifdef LOONGARCH64MAGIC
1244
      magic = LOONGARCH64MAGIC;
1245
#endif
1246
11
      break;
1247
1248
27
    case IMAGE_FILE_MACHINE_THUMB:
1249
27
#ifdef THUMBPEMAGIC
1250
27
      {
1251
27
  extern const bfd_target TARGET_LITTLE_SYM;
1252
1253
27
  if (abfd->xvec == & TARGET_LITTLE_SYM)
1254
27
    magic = THUMBPEMAGIC;
1255
27
      }
1256
27
#endif
1257
27
      break;
1258
1259
0
    case IMAGE_FILE_MACHINE_POWERPC:
1260
      /* We no longer support PowerPC.  */
1261
26
    default:
1262
26
      _bfd_error_handler
1263
  /* xgettext:c-format */
1264
26
  (_("%pB: unrecognised machine type (0x%x)"
1265
26
     " in Import Library Format archive"),
1266
26
   abfd, machine);
1267
26
      bfd_set_error (bfd_error_malformed_archive);
1268
1269
26
      return NULL;
1270
0
      break;
1271
170
    }
1272
1273
144
  if (magic == 0)
1274
114
    {
1275
114
      _bfd_error_handler
1276
  /* xgettext:c-format */
1277
114
  (_("%pB: recognised but unhandled machine type (0x%x)"
1278
114
     " in Import Library Format archive"),
1279
114
   abfd, machine);
1280
114
      bfd_set_error (bfd_error_wrong_format);
1281
1282
114
      return NULL;
1283
114
    }
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
1
    {
1294
1
      _bfd_error_handler
1295
1
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1296
1
      bfd_set_error (bfd_error_malformed_archive);
1297
1298
1
      return NULL;
1299
1
    }
1300
1301
29
  ordinal = H_GET_16 (abfd, ptr);
1302
29
  ptr += 2;
1303
1304
29
  types = H_GET_16 (abfd, ptr);
1305
  /* ptr += 2; */
1306
1307
  /* Now read in the two strings that follow.  */
1308
29
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1309
29
  if (ptr == NULL)
1310
11
    return NULL;
1311
1312
18
  symbol_name = (char *) ptr;
1313
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1314
18
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1315
1316
  /* Verify that the strings are null terminated.  */
1317
18
  if (ptr[size - 1] != 0
1318
18
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1319
3
    {
1320
3
      _bfd_error_handler
1321
3
  (_("%pB: string not null terminated in ILF object file"), abfd);
1322
3
      bfd_set_error (bfd_error_malformed_archive);
1323
3
      bfd_release (abfd, ptr);
1324
3
      return NULL;
1325
3
    }
1326
1327
  /* Now construct the bfd.  */
1328
15
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1329
15
          source_dll, ordinal, types))
1330
4
    {
1331
4
      bfd_release (abfd, ptr);
1332
4
      return NULL;
1333
4
    }
1334
1335
11
  return pe_ILF_cleanup;
1336
15
}
pei-arm.c:pe_ILF_object_p
Line
Count
Source
1167
172
{
1168
172
  bfd_byte    buffer[14];
1169
172
  bfd_byte *    ptr;
1170
172
  char *    symbol_name;
1171
172
  char *    source_dll;
1172
172
  unsigned int    machine;
1173
172
  bfd_size_type   size;
1174
172
  unsigned int    ordinal;
1175
172
  unsigned int    types;
1176
172
  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
172
  if (bfd_read (buffer, 14, abfd) != 14)
1181
2
    return NULL;
1182
1183
170
  ptr = buffer;
1184
1185
170
  machine = H_GET_16 (abfd, ptr);
1186
170
  ptr += 2;
1187
1188
  /* Check that the machine type is recognised.  */
1189
170
  magic = 0;
1190
1191
170
  switch (machine)
1192
170
    {
1193
1
    case IMAGE_FILE_MACHINE_UNKNOWN:
1194
2
    case IMAGE_FILE_MACHINE_ALPHA:
1195
2
    case IMAGE_FILE_MACHINE_ALPHA64:
1196
3
    case IMAGE_FILE_MACHINE_IA64:
1197
3
      break;
1198
1199
14
    case IMAGE_FILE_MACHINE_I386:
1200
#ifdef I386MAGIC
1201
      magic = I386MAGIC;
1202
#endif
1203
14
      break;
1204
1205
10
    case IMAGE_FILE_MACHINE_AMD64:
1206
#ifdef AMD64MAGIC
1207
      magic = AMD64MAGIC;
1208
#endif
1209
10
      break;
1210
1211
1
    case IMAGE_FILE_MACHINE_R3000:
1212
1
    case IMAGE_FILE_MACHINE_R4000:
1213
2
    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
61
    case IMAGE_FILE_MACHINE_SH3:
1224
66
    case IMAGE_FILE_MACHINE_SH4:
1225
#ifdef SH_ARCH_MAGIC_WINCE
1226
      magic = SH_ARCH_MAGIC_WINCE;
1227
#endif
1228
66
      break;
1229
1230
3
    case IMAGE_FILE_MACHINE_ARM:
1231
3
#ifdef ARMPEMAGIC
1232
3
      magic = ARMPEMAGIC;
1233
3
#endif
1234
3
      break;
1235
1236
8
    case IMAGE_FILE_MACHINE_ARM64:
1237
#ifdef AARCH64MAGIC
1238
      magic = AARCH64MAGIC;
1239
#endif
1240
8
      break;
1241
1242
11
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1243
#ifdef LOONGARCH64MAGIC
1244
      magic = LOONGARCH64MAGIC;
1245
#endif
1246
11
      break;
1247
1248
27
    case IMAGE_FILE_MACHINE_THUMB:
1249
27
#ifdef THUMBPEMAGIC
1250
27
      {
1251
27
  extern const bfd_target TARGET_LITTLE_SYM;
1252
1253
27
  if (abfd->xvec == & TARGET_LITTLE_SYM)
1254
27
    magic = THUMBPEMAGIC;
1255
27
      }
1256
27
#endif
1257
27
      break;
1258
1259
0
    case IMAGE_FILE_MACHINE_POWERPC:
1260
      /* We no longer support PowerPC.  */
1261
26
    default:
1262
26
      _bfd_error_handler
1263
  /* xgettext:c-format */
1264
26
  (_("%pB: unrecognised machine type (0x%x)"
1265
26
     " in Import Library Format archive"),
1266
26
   abfd, machine);
1267
26
      bfd_set_error (bfd_error_malformed_archive);
1268
1269
26
      return NULL;
1270
0
      break;
1271
170
    }
1272
1273
144
  if (magic == 0)
1274
114
    {
1275
114
      _bfd_error_handler
1276
  /* xgettext:c-format */
1277
114
  (_("%pB: recognised but unhandled machine type (0x%x)"
1278
114
     " in Import Library Format archive"),
1279
114
   abfd, machine);
1280
114
      bfd_set_error (bfd_error_wrong_format);
1281
1282
114
      return NULL;
1283
114
    }
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
1
    {
1294
1
      _bfd_error_handler
1295
1
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1296
1
      bfd_set_error (bfd_error_malformed_archive);
1297
1298
1
      return NULL;
1299
1
    }
1300
1301
29
  ordinal = H_GET_16 (abfd, ptr);
1302
29
  ptr += 2;
1303
1304
29
  types = H_GET_16 (abfd, ptr);
1305
  /* ptr += 2; */
1306
1307
  /* Now read in the two strings that follow.  */
1308
29
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1309
29
  if (ptr == NULL)
1310
11
    return NULL;
1311
1312
18
  symbol_name = (char *) ptr;
1313
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1314
18
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1315
1316
  /* Verify that the strings are null terminated.  */
1317
18
  if (ptr[size - 1] != 0
1318
18
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1319
3
    {
1320
3
      _bfd_error_handler
1321
3
  (_("%pB: string not null terminated in ILF object file"), abfd);
1322
3
      bfd_set_error (bfd_error_malformed_archive);
1323
3
      bfd_release (abfd, ptr);
1324
3
      return NULL;
1325
3
    }
1326
1327
  /* Now construct the bfd.  */
1328
15
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1329
15
          source_dll, ordinal, types))
1330
4
    {
1331
4
      bfd_release (abfd, ptr);
1332
4
      return NULL;
1333
4
    }
1334
1335
11
  return pe_ILF_cleanup;
1336
15
}
pei-mcore.c:pe_ILF_object_p
Line
Count
Source
1167
172
{
1168
172
  bfd_byte    buffer[14];
1169
172
  bfd_byte *    ptr;
1170
172
  char *    symbol_name;
1171
172
  char *    source_dll;
1172
172
  unsigned int    machine;
1173
172
  bfd_size_type   size;
1174
172
  unsigned int    ordinal;
1175
172
  unsigned int    types;
1176
172
  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
172
  if (bfd_read (buffer, 14, abfd) != 14)
1181
2
    return NULL;
1182
1183
170
  ptr = buffer;
1184
1185
170
  machine = H_GET_16 (abfd, ptr);
1186
170
  ptr += 2;
1187
1188
  /* Check that the machine type is recognised.  */
1189
170
  magic = 0;
1190
1191
170
  switch (machine)
1192
170
    {
1193
1
    case IMAGE_FILE_MACHINE_UNKNOWN:
1194
2
    case IMAGE_FILE_MACHINE_ALPHA:
1195
2
    case IMAGE_FILE_MACHINE_ALPHA64:
1196
3
    case IMAGE_FILE_MACHINE_IA64:
1197
3
      break;
1198
1199
14
    case IMAGE_FILE_MACHINE_I386:
1200
#ifdef I386MAGIC
1201
      magic = I386MAGIC;
1202
#endif
1203
14
      break;
1204
1205
10
    case IMAGE_FILE_MACHINE_AMD64:
1206
#ifdef AMD64MAGIC
1207
      magic = AMD64MAGIC;
1208
#endif
1209
10
      break;
1210
1211
1
    case IMAGE_FILE_MACHINE_R3000:
1212
1
    case IMAGE_FILE_MACHINE_R4000:
1213
2
    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
61
    case IMAGE_FILE_MACHINE_SH3:
1224
66
    case IMAGE_FILE_MACHINE_SH4:
1225
#ifdef SH_ARCH_MAGIC_WINCE
1226
      magic = SH_ARCH_MAGIC_WINCE;
1227
#endif
1228
66
      break;
1229
1230
3
    case IMAGE_FILE_MACHINE_ARM:
1231
#ifdef ARMPEMAGIC
1232
      magic = ARMPEMAGIC;
1233
#endif
1234
3
      break;
1235
1236
8
    case IMAGE_FILE_MACHINE_ARM64:
1237
#ifdef AARCH64MAGIC
1238
      magic = AARCH64MAGIC;
1239
#endif
1240
8
      break;
1241
1242
11
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1243
#ifdef LOONGARCH64MAGIC
1244
      magic = LOONGARCH64MAGIC;
1245
#endif
1246
11
      break;
1247
1248
27
    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
27
      break;
1258
1259
0
    case IMAGE_FILE_MACHINE_POWERPC:
1260
      /* We no longer support PowerPC.  */
1261
26
    default:
1262
26
      _bfd_error_handler
1263
  /* xgettext:c-format */
1264
26
  (_("%pB: unrecognised machine type (0x%x)"
1265
26
     " in Import Library Format archive"),
1266
26
   abfd, machine);
1267
26
      bfd_set_error (bfd_error_malformed_archive);
1268
1269
26
      return NULL;
1270
0
      break;
1271
170
    }
1272
1273
144
  if (magic == 0)
1274
144
    {
1275
144
      _bfd_error_handler
1276
  /* xgettext:c-format */
1277
144
  (_("%pB: recognised but unhandled machine type (0x%x)"
1278
144
     " in Import Library Format archive"),
1279
144
   abfd, machine);
1280
144
      bfd_set_error (bfd_error_wrong_format);
1281
1282
144
      return NULL;
1283
144
    }
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
168
{
1168
168
  bfd_byte    buffer[14];
1169
168
  bfd_byte *    ptr;
1170
168
  char *    symbol_name;
1171
168
  char *    source_dll;
1172
168
  unsigned int    machine;
1173
168
  bfd_size_type   size;
1174
168
  unsigned int    ordinal;
1175
168
  unsigned int    types;
1176
168
  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
168
  if (bfd_read (buffer, 14, abfd) != 14)
1181
2
    return NULL;
1182
1183
166
  ptr = buffer;
1184
1185
166
  machine = H_GET_16 (abfd, ptr);
1186
166
  ptr += 2;
1187
1188
  /* Check that the machine type is recognised.  */
1189
166
  magic = 0;
1190
1191
166
  switch (machine)
1192
166
    {
1193
1
    case IMAGE_FILE_MACHINE_UNKNOWN:
1194
2
    case IMAGE_FILE_MACHINE_ALPHA:
1195
2
    case IMAGE_FILE_MACHINE_ALPHA64:
1196
3
    case IMAGE_FILE_MACHINE_IA64:
1197
3
      break;
1198
1199
14
    case IMAGE_FILE_MACHINE_I386:
1200
#ifdef I386MAGIC
1201
      magic = I386MAGIC;
1202
#endif
1203
14
      break;
1204
1205
10
    case IMAGE_FILE_MACHINE_AMD64:
1206
#ifdef AMD64MAGIC
1207
      magic = AMD64MAGIC;
1208
#endif
1209
10
      break;
1210
1211
1
    case IMAGE_FILE_MACHINE_R3000:
1212
1
    case IMAGE_FILE_MACHINE_R4000:
1213
2
    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
61
    case IMAGE_FILE_MACHINE_SH3:
1224
66
    case IMAGE_FILE_MACHINE_SH4:
1225
66
#ifdef SH_ARCH_MAGIC_WINCE
1226
66
      magic = SH_ARCH_MAGIC_WINCE;
1227
66
#endif
1228
66
      break;
1229
1230
3
    case IMAGE_FILE_MACHINE_ARM:
1231
#ifdef ARMPEMAGIC
1232
      magic = ARMPEMAGIC;
1233
#endif
1234
3
      break;
1235
1236
8
    case IMAGE_FILE_MACHINE_ARM64:
1237
#ifdef AARCH64MAGIC
1238
      magic = AARCH64MAGIC;
1239
#endif
1240
8
      break;
1241
1242
11
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1243
#ifdef LOONGARCH64MAGIC
1244
      magic = LOONGARCH64MAGIC;
1245
#endif
1246
11
      break;
1247
1248
27
    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
27
      break;
1258
1259
0
    case IMAGE_FILE_MACHINE_POWERPC:
1260
      /* We no longer support PowerPC.  */
1261
22
    default:
1262
22
      _bfd_error_handler
1263
  /* xgettext:c-format */
1264
22
  (_("%pB: unrecognised machine type (0x%x)"
1265
22
     " in Import Library Format archive"),
1266
22
   abfd, machine);
1267
22
      bfd_set_error (bfd_error_malformed_archive);
1268
1269
22
      return NULL;
1270
0
      break;
1271
166
    }
1272
1273
144
  if (magic == 0)
1274
78
    {
1275
78
      _bfd_error_handler
1276
  /* xgettext:c-format */
1277
78
  (_("%pB: recognised but unhandled machine type (0x%x)"
1278
78
     " in Import Library Format archive"),
1279
78
   abfd, machine);
1280
78
      bfd_set_error (bfd_error_wrong_format);
1281
1282
78
      return NULL;
1283
78
    }
1284
1285
  /* We do not bother to check the date.
1286
     date = H_GET_32 (abfd, ptr);  */
1287
66
  ptr += 4;
1288
1289
66
  size = H_GET_32 (abfd, ptr);
1290
66
  ptr += 4;
1291
1292
66
  if (size == 0)
1293
1
    {
1294
1
      _bfd_error_handler
1295
1
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1296
1
      bfd_set_error (bfd_error_malformed_archive);
1297
1298
1
      return NULL;
1299
1
    }
1300
1301
65
  ordinal = H_GET_16 (abfd, ptr);
1302
65
  ptr += 2;
1303
1304
65
  types = H_GET_16 (abfd, ptr);
1305
  /* ptr += 2; */
1306
1307
  /* Now read in the two strings that follow.  */
1308
65
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1309
65
  if (ptr == NULL)
1310
4
    return NULL;
1311
1312
61
  symbol_name = (char *) ptr;
1313
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1314
61
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1315
1316
  /* Verify that the strings are null terminated.  */
1317
61
  if (ptr[size - 1] != 0
1318
61
      || (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
59
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1329
59
          source_dll, ordinal, types))
1330
4
    {
1331
4
      bfd_release (abfd, ptr);
1332
4
      return NULL;
1333
4
    }
1334
1335
55
  return pe_ILF_cleanup;
1336
59
}
1337
1338
static void
1339
pe_bfd_read_buildid (bfd *abfd)
1340
3.63k
{
1341
3.63k
  pe_data_type *pe = pe_data (abfd);
1342
3.63k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1343
3.63k
  asection *section;
1344
3.63k
  bfd_byte *data = 0;
1345
3.63k
  bfd_size_type dataoff;
1346
3.63k
  unsigned int i;
1347
3.63k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1348
3.63k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1349
1350
3.63k
  if (size == 0)
1351
501
    return;
1352
1353
3.12k
  addr += extra->ImageBase;
1354
1355
  /* Search for the section containing the DebugDirectory.  */
1356
15.4k
  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
2.78k
  break;
1360
15.1k
    }
1361
1362
3.12k
  if (section == NULL)
1363
343
    return;
1364
1365
2.78k
  if (!(section->flags & SEC_HAS_CONTENTS))
1366
13
    return;
1367
1368
2.77k
  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
2.77k
  if (dataoff >= section->size
1374
2.77k
      || size > section->size - dataoff)
1375
75
    {
1376
75
      _bfd_error_handler
1377
75
  (_("%pB: error: debug data ends beyond end of debug directory"),
1378
75
   abfd);
1379
75
      return;
1380
75
    }
1381
1382
  /* Read the whole section. */
1383
2.69k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1384
794
    {
1385
794
      free (data);
1386
794
      return;
1387
794
    }
1388
1389
  /* Search for a CodeView entry in the DebugDirectory */
1390
244k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1391
242k
    {
1392
242k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1393
242k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1394
242k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1395
1396
242k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1397
1398
242k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1399
304
  {
1400
304
    char buffer[256 + 1];
1401
304
    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
304
    if (_bfd_XXi_slurp_codeview_record (abfd,
1408
304
                (file_ptr) idd.PointerToRawData,
1409
304
                idd.SizeOfData, cvinfo, NULL))
1410
7
      {
1411
7
        struct bfd_build_id* build_id = bfd_alloc (abfd,
1412
7
       sizeof (struct bfd_build_id) + cvinfo->SignatureLength);
1413
7
        if (build_id)
1414
7
    {
1415
7
      build_id->size = cvinfo->SignatureLength;
1416
7
      memcpy(build_id->data,  cvinfo->Signature,
1417
7
       cvinfo->SignatureLength);
1418
7
      abfd->build_id = build_id;
1419
7
    }
1420
7
      }
1421
304
    break;
1422
304
  }
1423
242k
    }
1424
1425
1.90k
  free (data);
1426
1.90k
}
pei-i386.c:pe_bfd_read_buildid
Line
Count
Source
1340
157
{
1341
157
  pe_data_type *pe = pe_data (abfd);
1342
157
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1343
157
  asection *section;
1344
157
  bfd_byte *data = 0;
1345
157
  bfd_size_type dataoff;
1346
157
  unsigned int i;
1347
157
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1348
157
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1349
1350
157
  if (size == 0)
1351
56
    return;
1352
1353
101
  addr += extra->ImageBase;
1354
1355
  /* Search for the section containing the DebugDirectory.  */
1356
408
  for (section = abfd->sections; section != NULL; section = section->next)
1357
353
    {
1358
353
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1359
46
  break;
1360
353
    }
1361
1362
101
  if (section == NULL)
1363
55
    return;
1364
1365
46
  if (!(section->flags & SEC_HAS_CONTENTS))
1366
2
    return;
1367
1368
44
  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
44
  if (dataoff >= section->size
1374
44
      || size > section->size - dataoff)
1375
12
    {
1376
12
      _bfd_error_handler
1377
12
  (_("%pB: error: debug data ends beyond end of debug directory"),
1378
12
   abfd);
1379
12
      return;
1380
12
    }
1381
1382
  /* Read the whole section. */
1383
32
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1384
6
    {
1385
6
      free (data);
1386
6
      return;
1387
6
    }
1388
1389
  /* Search for a CodeView entry in the DebugDirectory */
1390
253
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1391
231
    {
1392
231
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1393
231
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1394
231
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1395
1396
231
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1397
1398
231
      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
2
      {
1411
2
        struct bfd_build_id* build_id = bfd_alloc (abfd,
1412
2
       sizeof (struct bfd_build_id) + cvinfo->SignatureLength);
1413
2
        if (build_id)
1414
2
    {
1415
2
      build_id->size = cvinfo->SignatureLength;
1416
2
      memcpy(build_id->data,  cvinfo->Signature,
1417
2
       cvinfo->SignatureLength);
1418
2
      abfd->build_id = build_id;
1419
2
    }
1420
2
      }
1421
4
    break;
1422
4
  }
1423
231
    }
1424
1425
26
  free (data);
1426
26
}
pei-x86_64.c:pe_bfd_read_buildid
Line
Count
Source
1340
194
{
1341
194
  pe_data_type *pe = pe_data (abfd);
1342
194
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1343
194
  asection *section;
1344
194
  bfd_byte *data = 0;
1345
194
  bfd_size_type dataoff;
1346
194
  unsigned int i;
1347
194
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1348
194
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1349
1350
194
  if (size == 0)
1351
88
    return;
1352
1353
106
  addr += extra->ImageBase;
1354
1355
  /* Search for the section containing the DebugDirectory.  */
1356
383
  for (section = abfd->sections; section != NULL; section = section->next)
1357
335
    {
1358
335
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1359
58
  break;
1360
335
    }
1361
1362
106
  if (section == NULL)
1363
48
    return;
1364
1365
58
  if (!(section->flags & SEC_HAS_CONTENTS))
1366
2
    return;
1367
1368
56
  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
56
  if (dataoff >= section->size
1374
56
      || size > section->size - dataoff)
1375
3
    {
1376
3
      _bfd_error_handler
1377
3
  (_("%pB: error: debug data ends beyond end of debug directory"),
1378
3
   abfd);
1379
3
      return;
1380
3
    }
1381
1382
  /* Read the whole section. */
1383
53
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1384
37
    {
1385
37
      free (data);
1386
37
      return;
1387
37
    }
1388
1389
  /* Search for a CodeView entry in the DebugDirectory */
1390
661
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1391
650
    {
1392
650
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1393
650
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1394
650
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1395
1396
650
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1397
1398
650
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1399
5
  {
1400
5
    char buffer[256 + 1];
1401
5
    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
5
    if (_bfd_XXi_slurp_codeview_record (abfd,
1408
5
                (file_ptr) idd.PointerToRawData,
1409
5
                idd.SizeOfData, cvinfo, NULL))
1410
4
      {
1411
4
        struct bfd_build_id* build_id = bfd_alloc (abfd,
1412
4
       sizeof (struct bfd_build_id) + cvinfo->SignatureLength);
1413
4
        if (build_id)
1414
4
    {
1415
4
      build_id->size = cvinfo->SignatureLength;
1416
4
      memcpy(build_id->data,  cvinfo->Signature,
1417
4
       cvinfo->SignatureLength);
1418
4
      abfd->build_id = build_id;
1419
4
    }
1420
4
      }
1421
5
    break;
1422
5
  }
1423
650
    }
1424
1425
16
  free (data);
1426
16
}
pei-aarch64.c:pe_bfd_read_buildid
Line
Count
Source
1340
2.83k
{
1341
2.83k
  pe_data_type *pe = pe_data (abfd);
1342
2.83k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1343
2.83k
  asection *section;
1344
2.83k
  bfd_byte *data = 0;
1345
2.83k
  bfd_size_type dataoff;
1346
2.83k
  unsigned int i;
1347
2.83k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1348
2.83k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1349
1350
2.83k
  if (size == 0)
1351
108
    return;
1352
1353
2.73k
  addr += extra->ImageBase;
1354
1355
  /* Search for the section containing the DebugDirectory.  */
1356
13.7k
  for (section = abfd->sections; section != NULL; section = section->next)
1357
13.5k
    {
1358
13.5k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1359
2.55k
  break;
1360
13.5k
    }
1361
1362
2.73k
  if (section == NULL)
1363
177
    return;
1364
1365
2.55k
  if (!(section->flags & SEC_HAS_CONTENTS))
1366
1
    return;
1367
1368
2.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
2.55k
  if (dataoff >= section->size
1374
2.55k
      || size > section->size - dataoff)
1375
47
    {
1376
47
      _bfd_error_handler
1377
47
  (_("%pB: error: debug data ends beyond end of debug directory"),
1378
47
   abfd);
1379
47
      return;
1380
47
    }
1381
1382
  /* Read the whole section. */
1383
2.50k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1384
723
    {
1385
723
      free (data);
1386
723
      return;
1387
723
    }
1388
1389
  /* Search for a CodeView entry in the DebugDirectory */
1390
238k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1391
236k
    {
1392
236k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1393
236k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1394
236k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1395
1396
236k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1397
1398
236k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1399
279
  {
1400
279
    char buffer[256 + 1];
1401
279
    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
279
    if (_bfd_XXi_slurp_codeview_record (abfd,
1408
279
                (file_ptr) idd.PointerToRawData,
1409
279
                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
279
    break;
1422
279
  }
1423
236k
    }
1424
1425
1.78k
  free (data);
1426
1.78k
}
pei-ia64.c:pe_bfd_read_buildid
Line
Count
Source
1340
199
{
1341
199
  pe_data_type *pe = pe_data (abfd);
1342
199
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1343
199
  asection *section;
1344
199
  bfd_byte *data = 0;
1345
199
  bfd_size_type dataoff;
1346
199
  unsigned int i;
1347
199
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1348
199
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1349
1350
199
  if (size == 0)
1351
165
    return;
1352
1353
34
  addr += extra->ImageBase;
1354
1355
  /* Search for the section containing the DebugDirectory.  */
1356
90
  for (section = abfd->sections; section != NULL; section = section->next)
1357
67
    {
1358
67
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1359
11
  break;
1360
67
    }
1361
1362
34
  if (section == NULL)
1363
23
    return;
1364
1365
11
  if (!(section->flags & SEC_HAS_CONTENTS))
1366
1
    return;
1367
1368
10
  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
10
  if (dataoff >= section->size
1374
10
      || size > section->size - dataoff)
1375
2
    {
1376
2
      _bfd_error_handler
1377
2
  (_("%pB: error: debug data ends beyond end of debug directory"),
1378
2
   abfd);
1379
2
      return;
1380
2
    }
1381
1382
  /* Read the whole section. */
1383
8
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1384
3
    {
1385
3
      free (data);
1386
3
      return;
1387
3
    }
1388
1389
  /* Search for a CodeView entry in the DebugDirectory */
1390
11
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1391
10
    {
1392
10
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1393
10
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1394
10
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1395
1396
10
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1397
1398
10
      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
10
    }
1424
1425
5
  free (data);
1426
5
}
pei-loongarch64.c:pe_bfd_read_buildid
Line
Count
Source
1340
129
{
1341
129
  pe_data_type *pe = pe_data (abfd);
1342
129
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1343
129
  asection *section;
1344
129
  bfd_byte *data = 0;
1345
129
  bfd_size_type dataoff;
1346
129
  unsigned int i;
1347
129
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1348
129
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1349
1350
129
  if (size == 0)
1351
33
    return;
1352
1353
96
  addr += extra->ImageBase;
1354
1355
  /* Search for the section containing the DebugDirectory.  */
1356
430
  for (section = abfd->sections; section != NULL; section = section->next)
1357
407
    {
1358
407
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1359
73
  break;
1360
407
    }
1361
1362
96
  if (section == NULL)
1363
23
    return;
1364
1365
73
  if (!(section->flags & SEC_HAS_CONTENTS))
1366
2
    return;
1367
1368
71
  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
71
  if (dataoff >= section->size
1374
71
      || size > section->size - dataoff)
1375
4
    {
1376
4
      _bfd_error_handler
1377
4
  (_("%pB: error: debug data ends beyond end of debug directory"),
1378
4
   abfd);
1379
4
      return;
1380
4
    }
1381
1382
  /* Read the whole section. */
1383
67
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1384
16
    {
1385
16
      free (data);
1386
16
      return;
1387
16
    }
1388
1389
  /* Search for a CodeView entry in the DebugDirectory */
1390
4.83k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1391
4.78k
    {
1392
4.78k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1393
4.78k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1394
4.78k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1395
1396
4.78k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1397
1398
4.78k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1399
10
  {
1400
10
    char buffer[256 + 1];
1401
10
    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
10
    if (_bfd_XXi_slurp_codeview_record (abfd,
1408
10
                (file_ptr) idd.PointerToRawData,
1409
10
                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
10
    break;
1422
10
  }
1423
4.78k
    }
1424
1425
51
  free (data);
1426
51
}
pei-arm-wince.c:pe_bfd_read_buildid
Line
Count
Source
1340
5
{
1341
5
  pe_data_type *pe = pe_data (abfd);
1342
5
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1343
5
  asection *section;
1344
5
  bfd_byte *data = 0;
1345
5
  bfd_size_type dataoff;
1346
5
  unsigned int i;
1347
5
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1348
5
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1349
1350
5
  if (size == 0)
1351
5
    return;
1352
1353
0
  addr += extra->ImageBase;
1354
1355
  /* Search for the section containing the DebugDirectory.  */
1356
0
  for (section = abfd->sections; section != NULL; section = section->next)
1357
0
    {
1358
0
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1359
0
  break;
1360
0
    }
1361
1362
0
  if (section == NULL)
1363
0
    return;
1364
1365
0
  if (!(section->flags & SEC_HAS_CONTENTS))
1366
0
    return;
1367
1368
0
  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
0
  if (dataoff >= section->size
1374
0
      || size > section->size - dataoff)
1375
0
    {
1376
0
      _bfd_error_handler
1377
0
  (_("%pB: error: debug data ends beyond end of debug directory"),
1378
0
   abfd);
1379
0
      return;
1380
0
    }
1381
1382
  /* Read the whole section. */
1383
0
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1384
0
    {
1385
0
      free (data);
1386
0
      return;
1387
0
    }
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-arm.c:pe_bfd_read_buildid
Line
Count
Source
1340
33
{
1341
33
  pe_data_type *pe = pe_data (abfd);
1342
33
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1343
33
  asection *section;
1344
33
  bfd_byte *data = 0;
1345
33
  bfd_size_type dataoff;
1346
33
  unsigned int i;
1347
33
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1348
33
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1349
1350
33
  if (size == 0)
1351
9
    return;
1352
1353
24
  addr += extra->ImageBase;
1354
1355
  /* Search for the section containing the DebugDirectory.  */
1356
300
  for (section = abfd->sections; section != NULL; section = section->next)
1357
291
    {
1358
291
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1359
15
  break;
1360
291
    }
1361
1362
24
  if (section == NULL)
1363
9
    return;
1364
1365
15
  if (!(section->flags & SEC_HAS_CONTENTS))
1366
0
    return;
1367
1368
15
  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
15
  if (dataoff >= section->size
1374
15
      || size > section->size - dataoff)
1375
3
    {
1376
3
      _bfd_error_handler
1377
3
  (_("%pB: error: debug data ends beyond end of debug directory"),
1378
3
   abfd);
1379
3
      return;
1380
3
    }
1381
1382
  /* Read the whole section. */
1383
12
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1384
4
    {
1385
4
      free (data);
1386
4
      return;
1387
4
    }
1388
1389
  /* Search for a CodeView entry in the DebugDirectory */
1390
22
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1391
16
    {
1392
16
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1393
16
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1394
16
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1395
1396
16
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1397
1398
16
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1399
2
  {
1400
2
    char buffer[256 + 1];
1401
2
    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
2
    if (_bfd_XXi_slurp_codeview_record (abfd,
1408
2
                (file_ptr) idd.PointerToRawData,
1409
2
                idd.SizeOfData, cvinfo, NULL))
1410
1
      {
1411
1
        struct bfd_build_id* build_id = bfd_alloc (abfd,
1412
1
       sizeof (struct bfd_build_id) + cvinfo->SignatureLength);
1413
1
        if (build_id)
1414
1
    {
1415
1
      build_id->size = cvinfo->SignatureLength;
1416
1
      memcpy(build_id->data,  cvinfo->Signature,
1417
1
       cvinfo->SignatureLength);
1418
1
      abfd->build_id = build_id;
1419
1
    }
1420
1
      }
1421
2
    break;
1422
2
  }
1423
16
    }
1424
1425
8
  free (data);
1426
8
}
pei-mcore.c:pe_bfd_read_buildid
Line
Count
Source
1340
47
{
1341
47
  pe_data_type *pe = pe_data (abfd);
1342
47
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1343
47
  asection *section;
1344
47
  bfd_byte *data = 0;
1345
47
  bfd_size_type dataoff;
1346
47
  unsigned int i;
1347
47
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1348
47
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1349
1350
47
  if (size == 0)
1351
15
    return;
1352
1353
32
  addr += extra->ImageBase;
1354
1355
  /* Search for the section containing the DebugDirectory.  */
1356
69
  for (section = abfd->sections; section != NULL; section = section->next)
1357
65
    {
1358
65
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1359
28
  break;
1360
65
    }
1361
1362
32
  if (section == NULL)
1363
4
    return;
1364
1365
28
  if (!(section->flags & SEC_HAS_CONTENTS))
1366
5
    return;
1367
1368
23
  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
23
  if (dataoff >= section->size
1374
23
      || size > section->size - dataoff)
1375
4
    {
1376
4
      _bfd_error_handler
1377
4
  (_("%pB: error: debug data ends beyond end of debug directory"),
1378
4
   abfd);
1379
4
      return;
1380
4
    }
1381
1382
  /* Read the whole section. */
1383
19
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1384
3
    {
1385
3
      free (data);
1386
3
      return;
1387
3
    }
1388
1389
  /* Search for a CodeView entry in the DebugDirectory */
1390
47
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1391
31
    {
1392
31
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1393
31
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1394
31
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1395
1396
31
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1397
1398
31
      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
31
    }
1424
1425
16
  free (data);
1426
16
}
pei-sh.c:pe_bfd_read_buildid
Line
Count
Source
1340
28
{
1341
28
  pe_data_type *pe = pe_data (abfd);
1342
28
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1343
28
  asection *section;
1344
28
  bfd_byte *data = 0;
1345
28
  bfd_size_type dataoff;
1346
28
  unsigned int i;
1347
28
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1348
28
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1349
1350
28
  if (size == 0)
1351
22
    return;
1352
1353
6
  addr += extra->ImageBase;
1354
1355
  /* Search for the section containing the DebugDirectory.  */
1356
29
  for (section = abfd->sections; section != NULL; section = section->next)
1357
25
    {
1358
25
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1359
2
  break;
1360
25
    }
1361
1362
6
  if (section == NULL)
1363
4
    return;
1364
1365
2
  if (!(section->flags & SEC_HAS_CONTENTS))
1366
0
    return;
1367
1368
2
  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
2
  if (dataoff >= section->size
1374
2
      || size > section->size - dataoff)
1375
0
    {
1376
0
      _bfd_error_handler
1377
0
  (_("%pB: error: debug data ends beyond end of debug directory"),
1378
0
   abfd);
1379
0
      return;
1380
0
    }
1381
1382
  /* Read the whole section. */
1383
2
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1384
2
    {
1385
2
      free (data);
1386
2
      return;
1387
2
    }
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
}
1427
1428
static bfd_cleanup
1429
pe_bfd_object_p (bfd * abfd)
1430
366k
{
1431
366k
  bfd_byte buffer[6];
1432
366k
  struct external_DOS_hdr dos_hdr;
1433
366k
  struct external_PEI_IMAGE_hdr image_hdr;
1434
366k
  struct internal_filehdr internal_f;
1435
366k
  struct internal_aouthdr internal_a;
1436
366k
  bfd_size_type opt_hdr_size;
1437
366k
  file_ptr offset;
1438
366k
  bfd_cleanup result;
1439
1440
  /* Detect if this a Microsoft Import Library Format element.  */
1441
  /* First read the beginning of the header.  */
1442
366k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1443
366k
      || bfd_read (buffer, 6, abfd) != 6)
1444
925
    {
1445
925
      if (bfd_get_error () != bfd_error_system_call)
1446
925
  bfd_set_error (bfd_error_wrong_format);
1447
925
      return NULL;
1448
925
    }
1449
1450
  /* Then check the magic and the version (only 0 is supported).  */
1451
365k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1452
365k
      && H_GET_16 (abfd, buffer + 4) == 0)
1453
1.70k
    return pe_ILF_object_p (abfd);
1454
1455
363k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1456
363k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1457
62.3k
    {
1458
62.3k
      if (bfd_get_error () != bfd_error_system_call)
1459
62.3k
  bfd_set_error (bfd_error_wrong_format);
1460
62.3k
      return NULL;
1461
62.3k
    }
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
301k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1474
262k
    {
1475
262k
      bfd_set_error (bfd_error_wrong_format);
1476
262k
      return NULL;
1477
262k
    }
1478
1479
38.6k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1480
38.6k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1481
38.6k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1482
3.42k
    {
1483
3.42k
      if (bfd_get_error () != bfd_error_system_call)
1484
3.42k
  bfd_set_error (bfd_error_wrong_format);
1485
3.42k
      return NULL;
1486
3.42k
    }
1487
1488
35.1k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1489
810
    {
1490
810
      bfd_set_error (bfd_error_wrong_format);
1491
810
      return NULL;
1492
810
    }
1493
1494
  /* Swap file header, so that we get the location for calling
1495
     real_object_p.  */
1496
34.3k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1497
1498
34.3k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1499
34.3k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1500
29.9k
    {
1501
29.9k
      bfd_set_error (bfd_error_wrong_format);
1502
29.9k
      return NULL;
1503
29.9k
    }
1504
1505
4.44k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1506
4.44k
    sizeof (internal_f.pe.dos_message));
1507
1508
  /* Read the optional header, which has variable size.  */
1509
4.44k
  opt_hdr_size = internal_f.f_opthdr;
1510
1511
4.44k
  if (opt_hdr_size != 0)
1512
3.78k
    {
1513
3.78k
      bfd_size_type amt = opt_hdr_size;
1514
3.78k
      bfd_byte * opthdr;
1515
1516
      /* PR 17521 file: 230-131433-0.004.  */
1517
3.78k
      if (amt < sizeof (PEAOUTHDR))
1518
3.52k
  amt = sizeof (PEAOUTHDR);
1519
1520
3.78k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1521
3.78k
      if (opthdr == NULL)
1522
39
  return NULL;
1523
3.74k
      if (amt > opt_hdr_size)
1524
3.49k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1525
1526
3.74k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1527
1528
3.74k
      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
55
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1535
#else
1536
55
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1537
0
#endif
1538
55
  {
1539
55
    bfd_set_error (bfd_error_wrong_format);
1540
55
    return NULL;
1541
55
  }
1542
55
#endif
1543
1544
3.69k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1545
3.69k
    || a->SectionAlignment >= 0x80000000)
1546
3.32k
  {
1547
3.32k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1548
3.32k
        abfd);
1549
3.32k
    a->SectionAlignment &= -a->SectionAlignment;
1550
3.32k
    if (a->SectionAlignment >= 0x80000000)
1551
2
      a->SectionAlignment = 0x40000000;
1552
3.32k
  }
1553
1554
3.69k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1555
3.69k
    || a->FileAlignment > a->SectionAlignment)
1556
3.32k
  {
1557
3.32k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1558
3.32k
            abfd);
1559
3.32k
    a->FileAlignment &= -a->FileAlignment;
1560
3.32k
    if (a->FileAlignment > a->SectionAlignment)
1561
3.05k
      a->FileAlignment = a->SectionAlignment;
1562
3.32k
  }
1563
1564
3.69k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1565
514
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1566
55
    }
1567
1568
4.35k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1569
4.35k
             (opt_hdr_size != 0
1570
4.35k
        ? &internal_a
1571
4.35k
        : (struct internal_aouthdr *) NULL));
1572
1573
4.35k
  if (result)
1574
3.63k
    {
1575
      /* Now the whole header has been processed, see if there is a build-id */
1576
3.63k
      pe_bfd_read_buildid(abfd);
1577
3.63k
    }
1578
1579
4.35k
  return result;
1580
4.44k
}
pei-i386.c:pe_bfd_object_p
Line
Count
Source
1430
40.8k
{
1431
40.8k
  bfd_byte buffer[6];
1432
40.8k
  struct external_DOS_hdr dos_hdr;
1433
40.8k
  struct external_PEI_IMAGE_hdr image_hdr;
1434
40.8k
  struct internal_filehdr internal_f;
1435
40.8k
  struct internal_aouthdr internal_a;
1436
40.8k
  bfd_size_type opt_hdr_size;
1437
40.8k
  file_ptr offset;
1438
40.8k
  bfd_cleanup result;
1439
1440
  /* Detect if this a Microsoft Import Library Format element.  */
1441
  /* First read the beginning of the header.  */
1442
40.8k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1443
40.8k
      || bfd_read (buffer, 6, abfd) != 6)
1444
121
    {
1445
121
      if (bfd_get_error () != bfd_error_system_call)
1446
121
  bfd_set_error (bfd_error_wrong_format);
1447
121
      return NULL;
1448
121
    }
1449
1450
  /* Then check the magic and the version (only 0 is supported).  */
1451
40.7k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1452
40.7k
      && H_GET_16 (abfd, buffer + 4) == 0)
1453
255
    return pe_ILF_object_p (abfd);
1454
1455
40.4k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1456
40.4k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1457
7.31k
    {
1458
7.31k
      if (bfd_get_error () != bfd_error_system_call)
1459
7.31k
  bfd_set_error (bfd_error_wrong_format);
1460
7.31k
      return NULL;
1461
7.31k
    }
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
33.1k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1474
28.2k
    {
1475
28.2k
      bfd_set_error (bfd_error_wrong_format);
1476
28.2k
      return NULL;
1477
28.2k
    }
1478
1479
4.86k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1480
4.86k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1481
4.86k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1482
421
    {
1483
421
      if (bfd_get_error () != bfd_error_system_call)
1484
421
  bfd_set_error (bfd_error_wrong_format);
1485
421
      return NULL;
1486
421
    }
1487
1488
4.44k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1489
85
    {
1490
85
      bfd_set_error (bfd_error_wrong_format);
1491
85
      return NULL;
1492
85
    }
1493
1494
  /* Swap file header, so that we get the location for calling
1495
     real_object_p.  */
1496
4.35k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1497
1498
4.35k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1499
4.35k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1500
4.11k
    {
1501
4.11k
      bfd_set_error (bfd_error_wrong_format);
1502
4.11k
      return NULL;
1503
4.11k
    }
1504
1505
241
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1506
241
    sizeof (internal_f.pe.dos_message));
1507
1508
  /* Read the optional header, which has variable size.  */
1509
241
  opt_hdr_size = internal_f.f_opthdr;
1510
1511
241
  if (opt_hdr_size != 0)
1512
152
    {
1513
152
      bfd_size_type amt = opt_hdr_size;
1514
152
      bfd_byte * opthdr;
1515
1516
      /* PR 17521 file: 230-131433-0.004.  */
1517
152
      if (amt < sizeof (PEAOUTHDR))
1518
36
  amt = sizeof (PEAOUTHDR);
1519
1520
152
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1521
152
      if (opthdr == NULL)
1522
6
  return NULL;
1523
146
      if (amt > opt_hdr_size)
1524
33
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1525
1526
146
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1527
1528
146
      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
146
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1545
146
    || a->SectionAlignment >= 0x80000000)
1546
28
  {
1547
28
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1548
28
        abfd);
1549
28
    a->SectionAlignment &= -a->SectionAlignment;
1550
28
    if (a->SectionAlignment >= 0x80000000)
1551
0
      a->SectionAlignment = 0x40000000;
1552
28
  }
1553
1554
146
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1555
146
    || a->FileAlignment > a->SectionAlignment)
1556
35
  {
1557
35
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1558
35
            abfd);
1559
35
    a->FileAlignment &= -a->FileAlignment;
1560
35
    if (a->FileAlignment > a->SectionAlignment)
1561
24
      a->FileAlignment = a->SectionAlignment;
1562
35
  }
1563
1564
146
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1565
21
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1566
146
    }
1567
1568
235
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1569
235
             (opt_hdr_size != 0
1570
235
        ? &internal_a
1571
235
        : (struct internal_aouthdr *) NULL));
1572
1573
235
  if (result)
1574
157
    {
1575
      /* Now the whole header has been processed, see if there is a build-id */
1576
157
      pe_bfd_read_buildid(abfd);
1577
157
    }
1578
1579
235
  return result;
1580
241
}
pei-x86_64.c:pe_bfd_object_p
Line
Count
Source
1430
40.8k
{
1431
40.8k
  bfd_byte buffer[6];
1432
40.8k
  struct external_DOS_hdr dos_hdr;
1433
40.8k
  struct external_PEI_IMAGE_hdr image_hdr;
1434
40.8k
  struct internal_filehdr internal_f;
1435
40.8k
  struct internal_aouthdr internal_a;
1436
40.8k
  bfd_size_type opt_hdr_size;
1437
40.8k
  file_ptr offset;
1438
40.8k
  bfd_cleanup result;
1439
1440
  /* Detect if this a Microsoft Import Library Format element.  */
1441
  /* First read the beginning of the header.  */
1442
40.8k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1443
40.8k
      || bfd_read (buffer, 6, abfd) != 6)
1444
121
    {
1445
121
      if (bfd_get_error () != bfd_error_system_call)
1446
121
  bfd_set_error (bfd_error_wrong_format);
1447
121
      return NULL;
1448
121
    }
1449
1450
  /* Then check the magic and the version (only 0 is supported).  */
1451
40.7k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1452
40.7k
      && H_GET_16 (abfd, buffer + 4) == 0)
1453
255
    return pe_ILF_object_p (abfd);
1454
1455
40.4k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1456
40.4k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1457
7.31k
    {
1458
7.31k
      if (bfd_get_error () != bfd_error_system_call)
1459
7.31k
  bfd_set_error (bfd_error_wrong_format);
1460
7.31k
      return NULL;
1461
7.31k
    }
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
33.1k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1474
28.2k
    {
1475
28.2k
      bfd_set_error (bfd_error_wrong_format);
1476
28.2k
      return NULL;
1477
28.2k
    }
1478
1479
4.89k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1480
4.89k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1481
4.89k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1482
421
    {
1483
421
      if (bfd_get_error () != bfd_error_system_call)
1484
421
  bfd_set_error (bfd_error_wrong_format);
1485
421
      return NULL;
1486
421
    }
1487
1488
4.47k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1489
85
    {
1490
85
      bfd_set_error (bfd_error_wrong_format);
1491
85
      return NULL;
1492
85
    }
1493
1494
  /* Swap file header, so that we get the location for calling
1495
     real_object_p.  */
1496
4.39k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1497
1498
4.39k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1499
4.39k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1500
4.13k
    {
1501
4.13k
      bfd_set_error (bfd_error_wrong_format);
1502
4.13k
      return NULL;
1503
4.13k
    }
1504
1505
262
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1506
262
    sizeof (internal_f.pe.dos_message));
1507
1508
  /* Read the optional header, which has variable size.  */
1509
262
  opt_hdr_size = internal_f.f_opthdr;
1510
1511
262
  if (opt_hdr_size != 0)
1512
173
    {
1513
173
      bfd_size_type amt = opt_hdr_size;
1514
173
      bfd_byte * opthdr;
1515
1516
      /* PR 17521 file: 230-131433-0.004.  */
1517
173
      if (amt < sizeof (PEAOUTHDR))
1518
117
  amt = sizeof (PEAOUTHDR);
1519
1520
173
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1521
173
      if (opthdr == NULL)
1522
6
  return NULL;
1523
167
      if (amt > opt_hdr_size)
1524
115
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1525
1526
167
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1527
1528
167
      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
167
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1545
167
    || a->SectionAlignment >= 0x80000000)
1546
110
  {
1547
110
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1548
110
        abfd);
1549
110
    a->SectionAlignment &= -a->SectionAlignment;
1550
110
    if (a->SectionAlignment >= 0x80000000)
1551
0
      a->SectionAlignment = 0x40000000;
1552
110
  }
1553
1554
167
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1555
167
    || a->FileAlignment > a->SectionAlignment)
1556
101
  {
1557
101
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1558
101
            abfd);
1559
101
    a->FileAlignment &= -a->FileAlignment;
1560
101
    if (a->FileAlignment > a->SectionAlignment)
1561
48
      a->FileAlignment = a->SectionAlignment;
1562
101
  }
1563
1564
167
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1565
61
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1566
167
    }
1567
1568
256
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1569
256
             (opt_hdr_size != 0
1570
256
        ? &internal_a
1571
256
        : (struct internal_aouthdr *) NULL));
1572
1573
256
  if (result)
1574
194
    {
1575
      /* Now the whole header has been processed, see if there is a build-id */
1576
194
      pe_bfd_read_buildid(abfd);
1577
194
    }
1578
1579
256
  return result;
1580
262
}
pei-aarch64.c:pe_bfd_object_p
Line
Count
Source
1430
40.8k
{
1431
40.8k
  bfd_byte buffer[6];
1432
40.8k
  struct external_DOS_hdr dos_hdr;
1433
40.8k
  struct external_PEI_IMAGE_hdr image_hdr;
1434
40.8k
  struct internal_filehdr internal_f;
1435
40.8k
  struct internal_aouthdr internal_a;
1436
40.8k
  bfd_size_type opt_hdr_size;
1437
40.8k
  file_ptr offset;
1438
40.8k
  bfd_cleanup result;
1439
1440
  /* Detect if this a Microsoft Import Library Format element.  */
1441
  /* First read the beginning of the header.  */
1442
40.8k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1443
40.8k
      || bfd_read (buffer, 6, abfd) != 6)
1444
121
    {
1445
121
      if (bfd_get_error () != bfd_error_system_call)
1446
121
  bfd_set_error (bfd_error_wrong_format);
1447
121
      return NULL;
1448
121
    }
1449
1450
  /* Then check the magic and the version (only 0 is supported).  */
1451
40.6k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1452
40.6k
      && H_GET_16 (abfd, buffer + 4) == 0)
1453
255
    return pe_ILF_object_p (abfd);
1454
1455
40.4k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1456
40.4k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1457
7.31k
    {
1458
7.31k
      if (bfd_get_error () != bfd_error_system_call)
1459
7.31k
  bfd_set_error (bfd_error_wrong_format);
1460
7.31k
      return NULL;
1461
7.31k
    }
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
33.1k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1474
28.1k
    {
1475
28.1k
      bfd_set_error (bfd_error_wrong_format);
1476
28.1k
      return NULL;
1477
28.1k
    }
1478
1479
4.92k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1480
4.92k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1481
4.92k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1482
443
    {
1483
443
      if (bfd_get_error () != bfd_error_system_call)
1484
443
  bfd_set_error (bfd_error_wrong_format);
1485
443
      return NULL;
1486
443
    }
1487
1488
4.48k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1489
135
    {
1490
135
      bfd_set_error (bfd_error_wrong_format);
1491
135
      return NULL;
1492
135
    }
1493
1494
  /* Swap file header, so that we get the location for calling
1495
     real_object_p.  */
1496
4.35k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1497
1498
4.35k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1499
4.35k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1500
1.36k
    {
1501
1.36k
      bfd_set_error (bfd_error_wrong_format);
1502
1.36k
      return NULL;
1503
1.36k
    }
1504
1505
2.98k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1506
2.98k
    sizeof (internal_f.pe.dos_message));
1507
1508
  /* Read the optional header, which has variable size.  */
1509
2.98k
  opt_hdr_size = internal_f.f_opthdr;
1510
1511
2.98k
  if (opt_hdr_size != 0)
1512
2.90k
    {
1513
2.90k
      bfd_size_type amt = opt_hdr_size;
1514
2.90k
      bfd_byte * opthdr;
1515
1516
      /* PR 17521 file: 230-131433-0.004.  */
1517
2.90k
      if (amt < sizeof (PEAOUTHDR))
1518
2.90k
  amt = sizeof (PEAOUTHDR);
1519
1520
2.90k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1521
2.90k
      if (opthdr == NULL)
1522
8
  return NULL;
1523
2.89k
      if (amt > opt_hdr_size)
1524
2.89k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1525
1526
2.89k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1527
1528
2.89k
      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.89k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1545
2.89k
    || a->SectionAlignment >= 0x80000000)
1546
2.84k
  {
1547
2.84k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1548
2.84k
        abfd);
1549
2.84k
    a->SectionAlignment &= -a->SectionAlignment;
1550
2.84k
    if (a->SectionAlignment >= 0x80000000)
1551
2
      a->SectionAlignment = 0x40000000;
1552
2.84k
  }
1553
1554
2.89k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1555
2.89k
    || a->FileAlignment > a->SectionAlignment)
1556
2.86k
  {
1557
2.86k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1558
2.86k
            abfd);
1559
2.86k
    a->FileAlignment &= -a->FileAlignment;
1560
2.86k
    if (a->FileAlignment > a->SectionAlignment)
1561
2.73k
      a->FileAlignment = a->SectionAlignment;
1562
2.86k
  }
1563
1564
2.89k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1565
205
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1566
2.89k
    }
1567
1568
2.98k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1569
2.98k
             (opt_hdr_size != 0
1570
2.98k
        ? &internal_a
1571
2.98k
        : (struct internal_aouthdr *) NULL));
1572
1573
2.98k
  if (result)
1574
2.83k
    {
1575
      /* Now the whole header has been processed, see if there is a build-id */
1576
2.83k
      pe_bfd_read_buildid(abfd);
1577
2.83k
    }
1578
1579
2.98k
  return result;
1580
2.98k
}
pei-ia64.c:pe_bfd_object_p
Line
Count
Source
1430
698
{
1431
698
  bfd_byte buffer[6];
1432
698
  struct external_DOS_hdr dos_hdr;
1433
698
  struct external_PEI_IMAGE_hdr image_hdr;
1434
698
  struct internal_filehdr internal_f;
1435
698
  struct internal_aouthdr internal_a;
1436
698
  bfd_size_type opt_hdr_size;
1437
698
  file_ptr offset;
1438
698
  bfd_cleanup result;
1439
1440
  /* Detect if this a Microsoft Import Library Format element.  */
1441
  /* First read the beginning of the header.  */
1442
698
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1443
698
      || 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
698
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1452
698
      && H_GET_16 (abfd, buffer + 4) == 0)
1453
0
    return pe_ILF_object_p (abfd);
1454
1455
698
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1456
698
      || 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
698
  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
698
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1480
698
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1481
698
      || 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
698
  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
698
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1497
1498
698
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1499
698
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1500
368
    {
1501
368
      bfd_set_error (bfd_error_wrong_format);
1502
368
      return NULL;
1503
368
    }
1504
1505
330
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1506
330
    sizeof (internal_f.pe.dos_message));
1507
1508
  /* Read the optional header, which has variable size.  */
1509
330
  opt_hdr_size = internal_f.f_opthdr;
1510
1511
330
  if (opt_hdr_size != 0)
1512
173
    {
1513
173
      bfd_size_type amt = opt_hdr_size;
1514
173
      bfd_byte * opthdr;
1515
1516
      /* PR 17521 file: 230-131433-0.004.  */
1517
173
      if (amt < sizeof (PEAOUTHDR))
1518
165
  amt = sizeof (PEAOUTHDR);
1519
1520
173
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1521
173
      if (opthdr == NULL)
1522
7
  return NULL;
1523
166
      if (amt > opt_hdr_size)
1524
160
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1525
1526
166
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1527
1528
166
      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
166
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1545
166
    || a->SectionAlignment >= 0x80000000)
1546
109
  {
1547
109
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1548
109
        abfd);
1549
109
    a->SectionAlignment &= -a->SectionAlignment;
1550
109
    if (a->SectionAlignment >= 0x80000000)
1551
0
      a->SectionAlignment = 0x40000000;
1552
109
  }
1553
1554
166
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1555
166
    || a->FileAlignment > a->SectionAlignment)
1556
107
  {
1557
107
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1558
107
            abfd);
1559
107
    a->FileAlignment &= -a->FileAlignment;
1560
107
    if (a->FileAlignment > a->SectionAlignment)
1561
74
      a->FileAlignment = a->SectionAlignment;
1562
107
  }
1563
1564
166
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1565
129
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1566
166
    }
1567
1568
323
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1569
323
             (opt_hdr_size != 0
1570
323
        ? &internal_a
1571
323
        : (struct internal_aouthdr *) NULL));
1572
1573
323
  if (result)
1574
199
    {
1575
      /* Now the whole header has been processed, see if there is a build-id */
1576
199
      pe_bfd_read_buildid(abfd);
1577
199
    }
1578
1579
323
  return result;
1580
330
}
pei-loongarch64.c:pe_bfd_object_p
Line
Count
Source
1430
40.8k
{
1431
40.8k
  bfd_byte buffer[6];
1432
40.8k
  struct external_DOS_hdr dos_hdr;
1433
40.8k
  struct external_PEI_IMAGE_hdr image_hdr;
1434
40.8k
  struct internal_filehdr internal_f;
1435
40.8k
  struct internal_aouthdr internal_a;
1436
40.8k
  bfd_size_type opt_hdr_size;
1437
40.8k
  file_ptr offset;
1438
40.8k
  bfd_cleanup result;
1439
1440
  /* Detect if this a Microsoft Import Library Format element.  */
1441
  /* First read the beginning of the header.  */
1442
40.8k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1443
40.8k
      || bfd_read (buffer, 6, abfd) != 6)
1444
121
    {
1445
121
      if (bfd_get_error () != bfd_error_system_call)
1446
121
  bfd_set_error (bfd_error_wrong_format);
1447
121
      return NULL;
1448
121
    }
1449
1450
  /* Then check the magic and the version (only 0 is supported).  */
1451
40.6k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1452
40.6k
      && H_GET_16 (abfd, buffer + 4) == 0)
1453
255
    return pe_ILF_object_p (abfd);
1454
1455
40.4k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1456
40.4k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1457
7.31k
    {
1458
7.31k
      if (bfd_get_error () != bfd_error_system_call)
1459
7.31k
  bfd_set_error (bfd_error_wrong_format);
1460
7.31k
      return NULL;
1461
7.31k
    }
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
33.1k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1474
28.2k
    {
1475
28.2k
      bfd_set_error (bfd_error_wrong_format);
1476
28.2k
      return NULL;
1477
28.2k
    }
1478
1479
4.83k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1480
4.83k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1481
4.83k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1482
421
    {
1483
421
      if (bfd_get_error () != bfd_error_system_call)
1484
421
  bfd_set_error (bfd_error_wrong_format);
1485
421
      return NULL;
1486
421
    }
1487
1488
4.41k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1489
85
    {
1490
85
      bfd_set_error (bfd_error_wrong_format);
1491
85
      return NULL;
1492
85
    }
1493
1494
  /* Swap file header, so that we get the location for calling
1495
     real_object_p.  */
1496
4.33k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1497
1498
4.33k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1499
4.33k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1500
4.10k
    {
1501
4.10k
      bfd_set_error (bfd_error_wrong_format);
1502
4.10k
      return NULL;
1503
4.10k
    }
1504
1505
228
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1506
228
    sizeof (internal_f.pe.dos_message));
1507
1508
  /* Read the optional header, which has variable size.  */
1509
228
  opt_hdr_size = internal_f.f_opthdr;
1510
1511
228
  if (opt_hdr_size != 0)
1512
183
    {
1513
183
      bfd_size_type amt = opt_hdr_size;
1514
183
      bfd_byte * opthdr;
1515
1516
      /* PR 17521 file: 230-131433-0.004.  */
1517
183
      if (amt < sizeof (PEAOUTHDR))
1518
166
  amt = sizeof (PEAOUTHDR);
1519
1520
183
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1521
183
      if (opthdr == NULL)
1522
5
  return NULL;
1523
178
      if (amt > opt_hdr_size)
1524
163
  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
161
  {
1547
161
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1548
161
        abfd);
1549
161
    a->SectionAlignment &= -a->SectionAlignment;
1550
161
    if (a->SectionAlignment >= 0x80000000)
1551
0
      a->SectionAlignment = 0x40000000;
1552
161
  }
1553
1554
178
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1555
178
    || a->FileAlignment > a->SectionAlignment)
1556
151
  {
1557
151
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1558
151
            abfd);
1559
151
    a->FileAlignment &= -a->FileAlignment;
1560
151
    if (a->FileAlignment > a->SectionAlignment)
1561
125
      a->FileAlignment = a->SectionAlignment;
1562
151
  }
1563
1564
178
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1565
80
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1566
178
    }
1567
1568
223
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1569
223
             (opt_hdr_size != 0
1570
223
        ? &internal_a
1571
223
        : (struct internal_aouthdr *) NULL));
1572
1573
223
  if (result)
1574
129
    {
1575
      /* Now the whole header has been processed, see if there is a build-id */
1576
129
      pe_bfd_read_buildid(abfd);
1577
129
    }
1578
1579
223
  return result;
1580
228
}
pei-arm-wince.c:pe_bfd_object_p
Line
Count
Source
1430
57.8k
{
1431
57.8k
  bfd_byte buffer[6];
1432
57.8k
  struct external_DOS_hdr dos_hdr;
1433
57.8k
  struct external_PEI_IMAGE_hdr image_hdr;
1434
57.8k
  struct internal_filehdr internal_f;
1435
57.8k
  struct internal_aouthdr internal_a;
1436
57.8k
  bfd_size_type opt_hdr_size;
1437
57.8k
  file_ptr offset;
1438
57.8k
  bfd_cleanup result;
1439
1440
  /* Detect if this a Microsoft Import Library Format element.  */
1441
  /* First read the beginning of the header.  */
1442
57.8k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1443
57.8k
      || bfd_read (buffer, 6, abfd) != 6)
1444
126
    {
1445
126
      if (bfd_get_error () != bfd_error_system_call)
1446
126
  bfd_set_error (bfd_error_wrong_format);
1447
126
      return NULL;
1448
126
    }
1449
1450
  /* Then check the magic and the version (only 0 is supported).  */
1451
57.6k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1452
57.6k
      && H_GET_16 (abfd, buffer + 4) == 0)
1453
172
    return pe_ILF_object_p (abfd);
1454
1455
57.5k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1456
57.5k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1457
9.46k
    {
1458
9.46k
      if (bfd_get_error () != bfd_error_system_call)
1459
9.46k
  bfd_set_error (bfd_error_wrong_format);
1460
9.46k
      return NULL;
1461
9.46k
    }
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
48.0k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1474
43.4k
    {
1475
43.4k
      bfd_set_error (bfd_error_wrong_format);
1476
43.4k
      return NULL;
1477
43.4k
    }
1478
1479
4.64k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1480
4.64k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1481
4.64k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1482
441
    {
1483
441
      if (bfd_get_error () != bfd_error_system_call)
1484
441
  bfd_set_error (bfd_error_wrong_format);
1485
441
      return NULL;
1486
441
    }
1487
1488
4.19k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1489
130
    {
1490
130
      bfd_set_error (bfd_error_wrong_format);
1491
130
      return NULL;
1492
130
    }
1493
1494
  /* Swap file header, so that we get the location for calling
1495
     real_object_p.  */
1496
4.06k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1497
1498
4.06k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1499
4.06k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1500
3.95k
    {
1501
3.95k
      bfd_set_error (bfd_error_wrong_format);
1502
3.95k
      return NULL;
1503
3.95k
    }
1504
1505
113
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1506
113
    sizeof (internal_f.pe.dos_message));
1507
1508
  /* Read the optional header, which has variable size.  */
1509
113
  opt_hdr_size = internal_f.f_opthdr;
1510
1511
113
  if (opt_hdr_size != 0)
1512
57
    {
1513
57
      bfd_size_type amt = opt_hdr_size;
1514
57
      bfd_byte * opthdr;
1515
1516
      /* PR 17521 file: 230-131433-0.004.  */
1517
57
      if (amt < sizeof (PEAOUTHDR))
1518
42
  amt = sizeof (PEAOUTHDR);
1519
1520
57
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1521
57
      if (opthdr == NULL)
1522
2
  return NULL;
1523
55
      if (amt > opt_hdr_size)
1524
40
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1525
1526
55
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1527
1528
55
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1529
1530
55
#ifdef ARM
1531
      /* Use Subsystem to distinguish between pei-arm-little and
1532
   pei-arm-wince-little.  */
1533
55
#ifdef WINCE
1534
55
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1535
#else
1536
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1537
#endif
1538
55
  {
1539
55
    bfd_set_error (bfd_error_wrong_format);
1540
55
    return NULL;
1541
55
  }
1542
0
#endif
1543
1544
0
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1545
0
    || a->SectionAlignment >= 0x80000000)
1546
0
  {
1547
0
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1548
0
        abfd);
1549
0
    a->SectionAlignment &= -a->SectionAlignment;
1550
0
    if (a->SectionAlignment >= 0x80000000)
1551
0
      a->SectionAlignment = 0x40000000;
1552
0
  }
1553
1554
0
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1555
0
    || a->FileAlignment > a->SectionAlignment)
1556
0
  {
1557
0
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1558
0
            abfd);
1559
0
    a->FileAlignment &= -a->FileAlignment;
1560
0
    if (a->FileAlignment > a->SectionAlignment)
1561
0
      a->FileAlignment = a->SectionAlignment;
1562
0
  }
1563
1564
0
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1565
0
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1566
0
    }
1567
1568
56
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1569
56
             (opt_hdr_size != 0
1570
56
        ? &internal_a
1571
56
        : (struct internal_aouthdr *) NULL));
1572
1573
56
  if (result)
1574
5
    {
1575
      /* Now the whole header has been processed, see if there is a build-id */
1576
5
      pe_bfd_read_buildid(abfd);
1577
5
    }
1578
1579
56
  return result;
1580
113
}
pei-arm.c:pe_bfd_object_p
Line
Count
Source
1430
57.8k
{
1431
57.8k
  bfd_byte buffer[6];
1432
57.8k
  struct external_DOS_hdr dos_hdr;
1433
57.8k
  struct external_PEI_IMAGE_hdr image_hdr;
1434
57.8k
  struct internal_filehdr internal_f;
1435
57.8k
  struct internal_aouthdr internal_a;
1436
57.8k
  bfd_size_type opt_hdr_size;
1437
57.8k
  file_ptr offset;
1438
57.8k
  bfd_cleanup result;
1439
1440
  /* Detect if this a Microsoft Import Library Format element.  */
1441
  /* First read the beginning of the header.  */
1442
57.8k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1443
57.8k
      || bfd_read (buffer, 6, abfd) != 6)
1444
126
    {
1445
126
      if (bfd_get_error () != bfd_error_system_call)
1446
126
  bfd_set_error (bfd_error_wrong_format);
1447
126
      return NULL;
1448
126
    }
1449
1450
  /* Then check the magic and the version (only 0 is supported).  */
1451
57.6k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1452
57.6k
      && H_GET_16 (abfd, buffer + 4) == 0)
1453
172
    return pe_ILF_object_p (abfd);
1454
1455
57.5k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1456
57.5k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1457
9.46k
    {
1458
9.46k
      if (bfd_get_error () != bfd_error_system_call)
1459
9.46k
  bfd_set_error (bfd_error_wrong_format);
1460
9.46k
      return NULL;
1461
9.46k
    }
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
48.0k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1474
43.4k
    {
1475
43.4k
      bfd_set_error (bfd_error_wrong_format);
1476
43.4k
      return NULL;
1477
43.4k
    }
1478
1479
4.64k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1480
4.64k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1481
4.64k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1482
441
    {
1483
441
      if (bfd_get_error () != bfd_error_system_call)
1484
441
  bfd_set_error (bfd_error_wrong_format);
1485
441
      return NULL;
1486
441
    }
1487
1488
4.19k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1489
130
    {
1490
130
      bfd_set_error (bfd_error_wrong_format);
1491
130
      return NULL;
1492
130
    }
1493
1494
  /* Swap file header, so that we get the location for calling
1495
     real_object_p.  */
1496
4.06k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1497
1498
4.06k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1499
4.06k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1500
3.95k
    {
1501
3.95k
      bfd_set_error (bfd_error_wrong_format);
1502
3.95k
      return NULL;
1503
3.95k
    }
1504
1505
113
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1506
113
    sizeof (internal_f.pe.dos_message));
1507
1508
  /* Read the optional header, which has variable size.  */
1509
113
  opt_hdr_size = internal_f.f_opthdr;
1510
1511
113
  if (opt_hdr_size != 0)
1512
57
    {
1513
57
      bfd_size_type amt = opt_hdr_size;
1514
57
      bfd_byte * opthdr;
1515
1516
      /* PR 17521 file: 230-131433-0.004.  */
1517
57
      if (amt < sizeof (PEAOUTHDR))
1518
42
  amt = sizeof (PEAOUTHDR);
1519
1520
57
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1521
57
      if (opthdr == NULL)
1522
2
  return NULL;
1523
55
      if (amt > opt_hdr_size)
1524
40
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1525
1526
55
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1527
1528
55
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1529
1530
55
#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
55
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1537
0
#endif
1538
0
  {
1539
0
    bfd_set_error (bfd_error_wrong_format);
1540
0
    return NULL;
1541
0
  }
1542
55
#endif
1543
1544
55
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1545
55
    || a->SectionAlignment >= 0x80000000)
1546
19
  {
1547
19
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1548
19
        abfd);
1549
19
    a->SectionAlignment &= -a->SectionAlignment;
1550
19
    if (a->SectionAlignment >= 0x80000000)
1551
0
      a->SectionAlignment = 0x40000000;
1552
19
  }
1553
1554
55
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1555
55
    || a->FileAlignment > a->SectionAlignment)
1556
19
  {
1557
19
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1558
19
            abfd);
1559
19
    a->FileAlignment &= -a->FileAlignment;
1560
19
    if (a->FileAlignment > a->SectionAlignment)
1561
18
      a->FileAlignment = a->SectionAlignment;
1562
19
  }
1563
1564
55
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1565
8
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1566
55
    }
1567
1568
111
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1569
111
             (opt_hdr_size != 0
1570
111
        ? &internal_a
1571
111
        : (struct internal_aouthdr *) NULL));
1572
1573
111
  if (result)
1574
33
    {
1575
      /* Now the whole header has been processed, see if there is a build-id */
1576
33
      pe_bfd_read_buildid(abfd);
1577
33
    }
1578
1579
111
  return result;
1580
113
}
pei-mcore.c:pe_bfd_object_p
Line
Count
Source
1430
57.8k
{
1431
57.8k
  bfd_byte buffer[6];
1432
57.8k
  struct external_DOS_hdr dos_hdr;
1433
57.8k
  struct external_PEI_IMAGE_hdr image_hdr;
1434
57.8k
  struct internal_filehdr internal_f;
1435
57.8k
  struct internal_aouthdr internal_a;
1436
57.8k
  bfd_size_type opt_hdr_size;
1437
57.8k
  file_ptr offset;
1438
57.8k
  bfd_cleanup result;
1439
1440
  /* Detect if this a Microsoft Import Library Format element.  */
1441
  /* First read the beginning of the header.  */
1442
57.8k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1443
57.8k
      || bfd_read (buffer, 6, abfd) != 6)
1444
126
    {
1445
126
      if (bfd_get_error () != bfd_error_system_call)
1446
126
  bfd_set_error (bfd_error_wrong_format);
1447
126
      return NULL;
1448
126
    }
1449
1450
  /* Then check the magic and the version (only 0 is supported).  */
1451
57.6k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1452
57.6k
      && H_GET_16 (abfd, buffer + 4) == 0)
1453
172
    return pe_ILF_object_p (abfd);
1454
1455
57.5k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1456
57.5k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1457
9.47k
    {
1458
9.47k
      if (bfd_get_error () != bfd_error_system_call)
1459
9.47k
  bfd_set_error (bfd_error_wrong_format);
1460
9.47k
      return NULL;
1461
9.47k
    }
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
48.0k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1474
43.4k
    {
1475
43.4k
      bfd_set_error (bfd_error_wrong_format);
1476
43.4k
      return NULL;
1477
43.4k
    }
1478
1479
4.55k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1480
4.55k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1481
4.55k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1482
419
    {
1483
419
      if (bfd_get_error () != bfd_error_system_call)
1484
419
  bfd_set_error (bfd_error_wrong_format);
1485
419
      return NULL;
1486
419
    }
1487
1488
4.13k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1489
80
    {
1490
80
      bfd_set_error (bfd_error_wrong_format);
1491
80
      return NULL;
1492
80
    }
1493
1494
  /* Swap file header, so that we get the location for calling
1495
     real_object_p.  */
1496
4.05k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1497
1498
4.05k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1499
4.05k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1500
3.95k
    {
1501
3.95k
      bfd_set_error (bfd_error_wrong_format);
1502
3.95k
      return NULL;
1503
3.95k
    }
1504
1505
100
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1506
100
    sizeof (internal_f.pe.dos_message));
1507
1508
  /* Read the optional header, which has variable size.  */
1509
100
  opt_hdr_size = internal_f.f_opthdr;
1510
1511
100
  if (opt_hdr_size != 0)
1512
57
    {
1513
57
      bfd_size_type amt = opt_hdr_size;
1514
57
      bfd_byte * opthdr;
1515
1516
      /* PR 17521 file: 230-131433-0.004.  */
1517
57
      if (amt < sizeof (PEAOUTHDR))
1518
25
  amt = sizeof (PEAOUTHDR);
1519
1520
57
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1521
57
      if (opthdr == NULL)
1522
1
  return NULL;
1523
56
      if (amt > opt_hdr_size)
1524
24
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1525
1526
56
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1527
1528
56
      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
56
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1545
56
    || a->SectionAlignment >= 0x80000000)
1546
42
  {
1547
42
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1548
42
        abfd);
1549
42
    a->SectionAlignment &= -a->SectionAlignment;
1550
42
    if (a->SectionAlignment >= 0x80000000)
1551
0
      a->SectionAlignment = 0x40000000;
1552
42
  }
1553
1554
56
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1555
56
    || a->FileAlignment > a->SectionAlignment)
1556
36
  {
1557
36
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1558
36
            abfd);
1559
36
    a->FileAlignment &= -a->FileAlignment;
1560
36
    if (a->FileAlignment > a->SectionAlignment)
1561
33
      a->FileAlignment = a->SectionAlignment;
1562
36
  }
1563
1564
56
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1565
4
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1566
56
    }
1567
1568
99
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1569
99
             (opt_hdr_size != 0
1570
99
        ? &internal_a
1571
99
        : (struct internal_aouthdr *) NULL));
1572
1573
99
  if (result)
1574
47
    {
1575
      /* Now the whole header has been processed, see if there is a build-id */
1576
47
      pe_bfd_read_buildid(abfd);
1577
47
    }
1578
1579
99
  return result;
1580
100
}
pei-sh.c:pe_bfd_object_p
Line
Count
Source
1430
28.9k
{
1431
28.9k
  bfd_byte buffer[6];
1432
28.9k
  struct external_DOS_hdr dos_hdr;
1433
28.9k
  struct external_PEI_IMAGE_hdr image_hdr;
1434
28.9k
  struct internal_filehdr internal_f;
1435
28.9k
  struct internal_aouthdr internal_a;
1436
28.9k
  bfd_size_type opt_hdr_size;
1437
28.9k
  file_ptr offset;
1438
28.9k
  bfd_cleanup result;
1439
1440
  /* Detect if this a Microsoft Import Library Format element.  */
1441
  /* First read the beginning of the header.  */
1442
28.9k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1443
28.9k
      || bfd_read (buffer, 6, abfd) != 6)
1444
63
    {
1445
63
      if (bfd_get_error () != bfd_error_system_call)
1446
63
  bfd_set_error (bfd_error_wrong_format);
1447
63
      return NULL;
1448
63
    }
1449
1450
  /* Then check the magic and the version (only 0 is supported).  */
1451
28.8k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1452
28.8k
      && H_GET_16 (abfd, buffer + 4) == 0)
1453
168
    return pe_ILF_object_p (abfd);
1454
1455
28.6k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1456
28.6k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1457
4.67k
    {
1458
4.67k
      if (bfd_get_error () != bfd_error_system_call)
1459
4.67k
  bfd_set_error (bfd_error_wrong_format);
1460
4.67k
      return NULL;
1461
4.67k
    }
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
24.0k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1474
19.4k
    {
1475
19.4k
      bfd_set_error (bfd_error_wrong_format);
1476
19.4k
      return NULL;
1477
19.4k
    }
1478
1479
4.55k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1480
4.55k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1481
4.55k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1482
419
    {
1483
419
      if (bfd_get_error () != bfd_error_system_call)
1484
419
  bfd_set_error (bfd_error_wrong_format);
1485
419
      return NULL;
1486
419
    }
1487
1488
4.13k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1489
80
    {
1490
80
      bfd_set_error (bfd_error_wrong_format);
1491
80
      return NULL;
1492
80
    }
1493
1494
  /* Swap file header, so that we get the location for calling
1495
     real_object_p.  */
1496
4.05k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1497
1498
4.05k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1499
4.05k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1500
3.98k
    {
1501
3.98k
      bfd_set_error (bfd_error_wrong_format);
1502
3.98k
      return NULL;
1503
3.98k
    }
1504
1505
70
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1506
70
    sizeof (internal_f.pe.dos_message));
1507
1508
  /* Read the optional header, which has variable size.  */
1509
70
  opt_hdr_size = internal_f.f_opthdr;
1510
1511
70
  if (opt_hdr_size != 0)
1512
29
    {
1513
29
      bfd_size_type amt = opt_hdr_size;
1514
29
      bfd_byte * opthdr;
1515
1516
      /* PR 17521 file: 230-131433-0.004.  */
1517
29
      if (amt < sizeof (PEAOUTHDR))
1518
25
  amt = sizeof (PEAOUTHDR);
1519
1520
29
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1521
29
      if (opthdr == NULL)
1522
2
  return NULL;
1523
27
      if (amt > opt_hdr_size)
1524
24
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1525
1526
27
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1527
1528
27
      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
27
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1545
27
    || a->SectionAlignment >= 0x80000000)
1546
8
  {
1547
8
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1548
8
        abfd);
1549
8
    a->SectionAlignment &= -a->SectionAlignment;
1550
8
    if (a->SectionAlignment >= 0x80000000)
1551
0
      a->SectionAlignment = 0x40000000;
1552
8
  }
1553
1554
27
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1555
27
    || a->FileAlignment > a->SectionAlignment)
1556
8
  {
1557
8
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1558
8
            abfd);
1559
8
    a->FileAlignment &= -a->FileAlignment;
1560
8
    if (a->FileAlignment > a->SectionAlignment)
1561
4
      a->FileAlignment = a->SectionAlignment;
1562
8
  }
1563
1564
27
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1565
6
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1566
27
    }
1567
1568
68
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1569
68
             (opt_hdr_size != 0
1570
68
        ? &internal_a
1571
68
        : (struct internal_aouthdr *) NULL));
1572
1573
68
  if (result)
1574
28
    {
1575
      /* Now the whole header has been processed, see if there is a build-id */
1576
28
      pe_bfd_read_buildid(abfd);
1577
28
    }
1578
1579
68
  return result;
1580
70
}
1581
1582
698
#define coff_object_p pe_bfd_object_p
1583
#endif /* COFF_IMAGE_WITH_PE */