Coverage Report

Created: 2023-08-28 06:28

/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
21.8k
{
132
21.8k
  RELOC *reloc_src = (RELOC *) src;
133
21.8k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
21.8k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
21.8k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
21.8k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
#ifdef SWAP_IN_RELOC_OFFSET
139
9.25k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
#endif
141
21.8k
}
pei-i386.c:coff_swap_reloc_in
Line
Count
Source
131
3.62k
{
132
3.62k
  RELOC *reloc_src = (RELOC *) src;
133
3.62k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
3.62k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
3.62k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
3.62k
  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
3.62k
}
pe-x86_64.c:coff_swap_reloc_in
Line
Count
Source
131
1.35k
{
132
1.35k
  RELOC *reloc_src = (RELOC *) src;
133
1.35k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
1.35k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
1.35k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
1.35k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
#ifdef SWAP_IN_RELOC_OFFSET
139
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
#endif
141
1.35k
}
pei-x86_64.c:coff_swap_reloc_in
Line
Count
Source
131
1.31k
{
132
1.31k
  RELOC *reloc_src = (RELOC *) src;
133
1.31k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
1.31k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
1.31k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
1.31k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
#ifdef SWAP_IN_RELOC_OFFSET
139
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
#endif
141
1.31k
}
pe-aarch64.c:coff_swap_reloc_in
Line
Count
Source
131
716
{
132
716
  RELOC *reloc_src = (RELOC *) src;
133
716
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
716
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
716
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
716
  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
716
}
pei-aarch64.c:coff_swap_reloc_in
Line
Count
Source
131
937
{
132
937
  RELOC *reloc_src = (RELOC *) src;
133
937
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
937
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
937
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
937
  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
937
}
pei-ia64.c:coff_swap_reloc_in
Line
Count
Source
131
1.34k
{
132
1.34k
  RELOC *reloc_src = (RELOC *) src;
133
1.34k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
1.34k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
1.34k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
1.34k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
#ifdef SWAP_IN_RELOC_OFFSET
139
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
#endif
141
1.34k
}
pei-loongarch64.c:coff_swap_reloc_in
Line
Count
Source
131
958
{
132
958
  RELOC *reloc_src = (RELOC *) src;
133
958
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
958
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
958
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
958
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
958
#ifdef SWAP_IN_RELOC_OFFSET
139
958
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
958
#endif
141
958
}
pe-arm-wince.c:coff_swap_reloc_in
Line
Count
Source
131
868
{
132
868
  RELOC *reloc_src = (RELOC *) src;
133
868
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
868
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
868
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
868
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
868
#ifdef SWAP_IN_RELOC_OFFSET
139
868
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
868
#endif
141
868
}
pe-arm.c:coff_swap_reloc_in
Line
Count
Source
131
868
{
132
868
  RELOC *reloc_src = (RELOC *) src;
133
868
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
868
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
868
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
868
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
868
#ifdef SWAP_IN_RELOC_OFFSET
139
868
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
868
#endif
141
868
}
pe-i386.c:coff_swap_reloc_in
Line
Count
Source
131
1.13k
{
132
1.13k
  RELOC *reloc_src = (RELOC *) src;
133
1.13k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
1.13k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
1.13k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
1.13k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
#ifdef SWAP_IN_RELOC_OFFSET
139
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
#endif
141
1.13k
}
pe-mcore.c:coff_swap_reloc_in
Line
Count
Source
131
598
{
132
598
  RELOC *reloc_src = (RELOC *) src;
133
598
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
598
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
598
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
598
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
598
#ifdef SWAP_IN_RELOC_OFFSET
139
598
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
598
#endif
141
598
}
pe-sh.c:coff_swap_reloc_in
Line
Count
Source
131
989
{
132
989
  RELOC *reloc_src = (RELOC *) src;
133
989
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
989
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
989
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
989
  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
989
}
pei-arm-wince.c:coff_swap_reloc_in
Line
Count
Source
131
2.26k
{
132
2.26k
  RELOC *reloc_src = (RELOC *) src;
133
2.26k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
2.26k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
2.26k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
2.26k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
2.26k
#ifdef SWAP_IN_RELOC_OFFSET
139
2.26k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
2.26k
#endif
141
2.26k
}
pei-arm.c:coff_swap_reloc_in
Line
Count
Source
131
1.84k
{
132
1.84k
  RELOC *reloc_src = (RELOC *) src;
133
1.84k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
1.84k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
1.84k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
1.84k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
1.84k
#ifdef SWAP_IN_RELOC_OFFSET
139
1.84k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
1.84k
#endif
141
1.84k
}
pei-mcore.c:coff_swap_reloc_in
Line
Count
Source
131
1.85k
{
132
1.85k
  RELOC *reloc_src = (RELOC *) src;
133
1.85k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
1.85k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
1.85k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
1.85k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
1.85k
#ifdef SWAP_IN_RELOC_OFFSET
139
1.85k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
1.85k
#endif
141
1.85k
}
pei-sh.c:coff_swap_reloc_in
Line
Count
Source
131
1.21k
{
132
1.21k
  RELOC *reloc_src = (RELOC *) src;
133
1.21k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
134
135
1.21k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
136
1.21k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
137
1.21k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
138
#ifdef SWAP_IN_RELOC_OFFSET
139
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
140
#endif
141
1.21k
}
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
632k
#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
3.22M
{
171
3.22M
  FILHDR *filehdr_src = (FILHDR *) src;
172
3.22M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
3.22M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
3.22M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
3.22M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
3.22M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
3.22M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
3.22M
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
3.22M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
355k
    {
185
355k
      filehdr_dst->f_nsyms = 0;
186
355k
      filehdr_dst->f_flags |= F_LSYMS;
187
355k
    }
188
189
3.22M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
3.22M
}
pei-i386.c:coff_swap_filehdr_in
Line
Count
Source
170
71.7k
{
171
71.7k
  FILHDR *filehdr_src = (FILHDR *) src;
172
71.7k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
71.7k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
71.7k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
71.7k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
71.7k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
71.7k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
71.7k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
71.7k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
3.22k
    {
185
3.22k
      filehdr_dst->f_nsyms = 0;
186
3.22k
      filehdr_dst->f_flags |= F_LSYMS;
187
3.22k
    }
188
189
71.7k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
71.7k
}
pe-x86_64.c:coff_swap_filehdr_in
Line
Count
Source
170
262k
{
171
262k
  FILHDR *filehdr_src = (FILHDR *) src;
172
262k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
262k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
262k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
262k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
262k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
262k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
262k
  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
262k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
32.7k
    {
185
32.7k
      filehdr_dst->f_nsyms = 0;
186
32.7k
      filehdr_dst->f_flags |= F_LSYMS;
187
32.7k
    }
188
189
262k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
262k
}
pei-x86_64.c:coff_swap_filehdr_in
Line
Count
Source
170
72.4k
{
171
72.4k
  FILHDR *filehdr_src = (FILHDR *) src;
172
72.4k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
72.4k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
72.4k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
72.4k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
72.4k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
72.4k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
72.4k
  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
72.4k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
3.22k
    {
185
3.22k
      filehdr_dst->f_nsyms = 0;
186
3.22k
      filehdr_dst->f_flags |= F_LSYMS;
187
3.22k
    }
188
189
72.4k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
72.4k
}
pe-aarch64.c:coff_swap_filehdr_in
Line
Count
Source
170
258k
{
171
258k
  FILHDR *filehdr_src = (FILHDR *) src;
172
258k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
258k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
258k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
258k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
258k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
258k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
258k
  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
258k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
32.8k
    {
185
32.8k
      filehdr_dst->f_nsyms = 0;
186
32.8k
      filehdr_dst->f_flags |= F_LSYMS;
187
32.8k
    }
188
189
258k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
258k
}
pei-aarch64.c:coff_swap_filehdr_in
Line
Count
Source
170
69.9k
{
171
69.9k
  FILHDR *filehdr_src = (FILHDR *) src;
172
69.9k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
69.9k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
69.9k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
69.9k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
69.9k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
69.9k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
69.9k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
69.9k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
3.23k
    {
185
3.23k
      filehdr_dst->f_nsyms = 0;
186
3.23k
      filehdr_dst->f_flags |= F_LSYMS;
187
3.23k
    }
188
189
69.9k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
69.9k
}
pei-ia64.c:coff_swap_filehdr_in
Line
Count
Source
170
68.3k
{
171
68.3k
  FILHDR *filehdr_src = (FILHDR *) src;
172
68.3k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
68.3k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
68.3k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
68.3k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
68.3k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
68.3k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
68.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
68.3k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
3.13k
    {
185
3.13k
      filehdr_dst->f_nsyms = 0;
186
3.13k
      filehdr_dst->f_flags |= F_LSYMS;
187
3.13k
    }
188
189
68.3k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
68.3k
}
pei-loongarch64.c:coff_swap_filehdr_in
Line
Count
Source
170
69.9k
{
171
69.9k
  FILHDR *filehdr_src = (FILHDR *) src;
172
69.9k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
69.9k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
69.9k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
69.9k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
69.9k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
69.9k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
69.9k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
69.9k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
3.21k
    {
185
3.21k
      filehdr_dst->f_nsyms = 0;
186
3.21k
      filehdr_dst->f_flags |= F_LSYMS;
187
3.21k
    }
188
189
69.9k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
69.9k
}
pe-arm-wince.c:coff_swap_filehdr_in
Line
Count
Source
170
517k
{
171
517k
  FILHDR *filehdr_src = (FILHDR *) src;
172
517k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
517k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
517k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
517k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
517k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
517k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
517k
  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
517k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
65.2k
    {
185
65.2k
      filehdr_dst->f_nsyms = 0;
186
65.2k
      filehdr_dst->f_flags |= F_LSYMS;
187
65.2k
    }
188
189
517k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
517k
}
pe-arm.c:coff_swap_filehdr_in
Line
Count
Source
170
517k
{
171
517k
  FILHDR *filehdr_src = (FILHDR *) src;
172
517k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
517k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
517k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
517k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
517k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
517k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
517k
  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
517k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
65.2k
    {
185
65.2k
      filehdr_dst->f_nsyms = 0;
186
65.2k
      filehdr_dst->f_flags |= F_LSYMS;
187
65.2k
    }
188
189
517k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
517k
}
pe-i386.c:coff_swap_filehdr_in
Line
Count
Source
170
258k
{
171
258k
  FILHDR *filehdr_src = (FILHDR *) src;
172
258k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
258k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
258k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
258k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
258k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
258k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
258k
  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
258k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
32.6k
    {
185
32.6k
      filehdr_dst->f_nsyms = 0;
186
32.6k
      filehdr_dst->f_flags |= F_LSYMS;
187
32.6k
    }
188
189
258k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
258k
}
pe-mcore.c:coff_swap_filehdr_in
Line
Count
Source
170
517k
{
171
517k
  FILHDR *filehdr_src = (FILHDR *) src;
172
517k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
517k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
517k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
517k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
517k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
517k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
517k
  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
517k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
65.2k
    {
185
65.2k
      filehdr_dst->f_nsyms = 0;
186
65.2k
      filehdr_dst->f_flags |= F_LSYMS;
187
65.2k
    }
188
189
517k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
517k
}
pe-sh.c:coff_swap_filehdr_in
Line
Count
Source
170
258k
{
171
258k
  FILHDR *filehdr_src = (FILHDR *) src;
172
258k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
258k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
258k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
258k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
258k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
258k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
258k
  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
258k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
32.6k
    {
185
32.6k
      filehdr_dst->f_nsyms = 0;
186
32.6k
      filehdr_dst->f_flags |= F_LSYMS;
187
32.6k
    }
188
189
258k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
258k
}
pei-arm-wince.c:coff_swap_filehdr_in
Line
Count
Source
170
69.9k
{
171
69.9k
  FILHDR *filehdr_src = (FILHDR *) src;
172
69.9k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
69.9k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
69.9k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
69.9k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
69.9k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
69.9k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
69.9k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
69.9k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
3.23k
    {
185
3.23k
      filehdr_dst->f_nsyms = 0;
186
3.23k
      filehdr_dst->f_flags |= F_LSYMS;
187
3.23k
    }
188
189
69.9k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
69.9k
}
pei-arm.c:coff_swap_filehdr_in
Line
Count
Source
170
69.9k
{
171
69.9k
  FILHDR *filehdr_src = (FILHDR *) src;
172
69.9k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
69.9k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
69.9k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
69.9k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
69.9k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
69.9k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
69.9k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
69.9k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
3.23k
    {
185
3.23k
      filehdr_dst->f_nsyms = 0;
186
3.23k
      filehdr_dst->f_flags |= F_LSYMS;
187
3.23k
    }
188
189
69.9k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
69.9k
}
pei-mcore.c:coff_swap_filehdr_in
Line
Count
Source
170
69.9k
{
171
69.9k
  FILHDR *filehdr_src = (FILHDR *) src;
172
69.9k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
69.9k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
69.9k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
69.9k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
69.9k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
69.9k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
69.9k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
69.9k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
3.21k
    {
185
3.21k
      filehdr_dst->f_nsyms = 0;
186
3.21k
      filehdr_dst->f_flags |= F_LSYMS;
187
3.21k
    }
188
189
69.9k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
69.9k
}
pei-sh.c:coff_swap_filehdr_in
Line
Count
Source
170
69.9k
{
171
69.9k
  FILHDR *filehdr_src = (FILHDR *) src;
172
69.9k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
173
174
69.9k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
175
69.9k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
176
69.9k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
177
69.9k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
178
69.9k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
179
69.9k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
180
181
  /* Other people's tools sometimes generate headers with an nsyms but
182
     a zero symptr.  */
183
69.9k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
184
3.21k
    {
185
3.21k
      filehdr_dst->f_nsyms = 0;
186
3.21k
      filehdr_dst->f_flags |= F_LSYMS;
187
3.21k
    }
188
189
69.9k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
190
69.9k
}
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
440k
{
207
440k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
440k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
440k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
440k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
440k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
440k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
440k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
440k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
440k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
440k
  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
291k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
291k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
  scnhdr_int->s_nreloc = 0;
227
#else
228
148k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
148k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
#endif
231
232
440k
  if (scnhdr_int->s_vaddr != 0)
233
269k
    {
234
269k
      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
269k
    }
240
241
440k
#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
440k
  if (scnhdr_int->s_paddr > 0
247
440k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
327k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
327k
    || (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
120k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
440k
#endif
256
440k
}
pei-i386.c:coff_swap_scnhdr_in
Line
Count
Source
206
121k
{
207
121k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
121k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
121k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
121k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
121k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
121k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
121k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
121k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
121k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
121k
  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
121k
#ifdef COFF_IMAGE_WITH_PE
224
121k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
121k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
121k
  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
121k
  if (scnhdr_int->s_vaddr != 0)
233
55.1k
    {
234
55.1k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
55.1k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
55.1k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
55.1k
#endif
239
55.1k
    }
240
241
121k
#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
121k
  if (scnhdr_int->s_paddr > 0
247
121k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
115k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
115k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
55.6k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
121k
#endif
256
121k
}
pe-x86_64.c:coff_swap_scnhdr_in
Line
Count
Source
206
42.2k
{
207
42.2k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
42.2k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
42.2k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
42.2k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
42.2k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
42.2k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
42.2k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
42.2k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
42.2k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
42.2k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
#ifdef COFF_IMAGE_WITH_PE
224
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
  scnhdr_int->s_nreloc = 0;
227
#else
228
42.2k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
42.2k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
42.2k
#endif
231
232
42.2k
  if (scnhdr_int->s_vaddr != 0)
233
34.5k
    {
234
34.5k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
      scnhdr_int->s_vaddr &= 0xffffffff;
238
#endif
239
34.5k
    }
240
241
42.2k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
42.2k
  if (scnhdr_int->s_paddr > 0
247
42.2k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
32.4k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
32.4k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
4.08k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
42.2k
#endif
256
42.2k
}
pei-x86_64.c:coff_swap_scnhdr_in
Line
Count
Source
206
23.6k
{
207
23.6k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
23.6k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
23.6k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
23.6k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
23.6k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
23.6k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
23.6k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
23.6k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
23.6k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
23.6k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
23.6k
#ifdef COFF_IMAGE_WITH_PE
224
23.6k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
23.6k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
23.6k
  scnhdr_int->s_nreloc = 0;
227
#else
228
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
#endif
231
232
23.6k
  if (scnhdr_int->s_vaddr != 0)
233
15.6k
    {
234
15.6k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
      scnhdr_int->s_vaddr &= 0xffffffff;
238
#endif
239
15.6k
    }
240
241
23.6k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
23.6k
  if (scnhdr_int->s_paddr > 0
247
23.6k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
15.6k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
15.6k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
7.68k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
23.6k
#endif
256
23.6k
}
pe-aarch64.c:coff_swap_scnhdr_in
Line
Count
Source
206
35.8k
{
207
35.8k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
35.8k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
35.8k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
35.8k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
35.8k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
35.8k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
35.8k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
35.8k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
35.8k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
35.8k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
#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
35.8k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
35.8k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
35.8k
#endif
231
232
35.8k
  if (scnhdr_int->s_vaddr != 0)
233
18.0k
    {
234
18.0k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
      scnhdr_int->s_vaddr &= 0xffffffff;
238
#endif
239
18.0k
    }
240
241
35.8k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
35.8k
  if (scnhdr_int->s_paddr > 0
247
35.8k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
18.5k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
18.5k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
10.4k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
35.8k
#endif
256
35.8k
}
pei-aarch64.c:coff_swap_scnhdr_in
Line
Count
Source
206
10.4k
{
207
10.4k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
10.4k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
10.4k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
10.4k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
10.4k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
10.4k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
10.4k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
10.4k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
10.4k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
10.4k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
10.4k
#ifdef COFF_IMAGE_WITH_PE
224
10.4k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
10.4k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
10.4k
  scnhdr_int->s_nreloc = 0;
227
#else
228
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
#endif
231
232
10.4k
  if (scnhdr_int->s_vaddr != 0)
233
7.62k
    {
234
7.62k
      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
7.62k
    }
240
241
10.4k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
10.4k
  if (scnhdr_int->s_paddr > 0
247
10.4k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
7.34k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
7.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
2.63k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
10.4k
#endif
256
10.4k
}
pei-ia64.c:coff_swap_scnhdr_in
Line
Count
Source
206
16.6k
{
207
16.6k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
16.6k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
16.6k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
16.6k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
16.6k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
16.6k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
16.6k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
16.6k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
16.6k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
16.6k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
16.6k
#ifdef COFF_IMAGE_WITH_PE
224
16.6k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
16.6k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
16.6k
  scnhdr_int->s_nreloc = 0;
227
#else
228
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
#endif
231
232
16.6k
  if (scnhdr_int->s_vaddr != 0)
233
9.86k
    {
234
9.86k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
9.86k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
9.86k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
9.86k
#endif
239
9.86k
    }
240
241
16.6k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
16.6k
  if (scnhdr_int->s_paddr > 0
247
16.6k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
9.18k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
9.18k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
2.78k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
16.6k
#endif
256
16.6k
}
pei-loongarch64.c:coff_swap_scnhdr_in
Line
Count
Source
206
14.3k
{
207
14.3k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
14.3k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
14.3k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
14.3k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
14.3k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
14.3k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
14.3k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
14.3k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
14.3k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
14.3k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
14.3k
#ifdef COFF_IMAGE_WITH_PE
224
14.3k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
14.3k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
14.3k
  scnhdr_int->s_nreloc = 0;
227
#else
228
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
#endif
231
232
14.3k
  if (scnhdr_int->s_vaddr != 0)
233
12.5k
    {
234
12.5k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
      scnhdr_int->s_vaddr &= 0xffffffff;
238
#endif
239
12.5k
    }
240
241
14.3k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
14.3k
  if (scnhdr_int->s_paddr > 0
247
14.3k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
12.0k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
12.0k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
4.12k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
14.3k
#endif
256
14.3k
}
pe-arm-wince.c:coff_swap_scnhdr_in
Line
Count
Source
206
11.0k
{
207
11.0k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
11.0k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
11.0k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
11.0k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
11.0k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
11.0k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
11.0k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
11.0k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
11.0k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
11.0k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
#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
11.0k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
11.0k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
11.0k
#endif
231
232
11.0k
  if (scnhdr_int->s_vaddr != 0)
233
5.45k
    {
234
5.45k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
5.45k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
5.45k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
5.45k
#endif
239
5.45k
    }
240
241
11.0k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
11.0k
  if (scnhdr_int->s_paddr > 0
247
11.0k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
6.36k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
6.36k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
1.41k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
11.0k
#endif
256
11.0k
}
pe-arm.c:coff_swap_scnhdr_in
Line
Count
Source
206
11.0k
{
207
11.0k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
11.0k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
11.0k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
11.0k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
11.0k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
11.0k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
11.0k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
11.0k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
11.0k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
11.0k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
#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
11.0k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
11.0k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
11.0k
#endif
231
232
11.0k
  if (scnhdr_int->s_vaddr != 0)
233
5.45k
    {
234
5.45k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
5.45k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
5.45k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
5.45k
#endif
239
5.45k
    }
240
241
11.0k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
11.0k
  if (scnhdr_int->s_paddr > 0
247
11.0k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
6.36k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
6.36k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
1.41k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
11.0k
#endif
256
11.0k
}
pe-i386.c:coff_swap_scnhdr_in
Line
Count
Source
206
16.9k
{
207
16.9k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
16.9k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
16.9k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
16.9k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
16.9k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
16.9k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
16.9k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
16.9k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
16.9k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
16.9k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
#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
16.9k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
16.9k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
16.9k
#endif
231
232
16.9k
  if (scnhdr_int->s_vaddr != 0)
233
11.5k
    {
234
11.5k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
11.5k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
11.5k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
11.5k
#endif
239
11.5k
    }
240
241
16.9k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
16.9k
  if (scnhdr_int->s_paddr > 0
247
16.9k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
13.4k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
13.4k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
1.25k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
16.9k
#endif
256
16.9k
}
pe-mcore.c:coff_swap_scnhdr_in
Line
Count
Source
206
10.9k
{
207
10.9k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
10.9k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
10.9k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
10.9k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
10.9k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
10.9k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
10.9k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
10.9k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
10.9k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
10.9k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
#ifdef COFF_IMAGE_WITH_PE
224
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
  scnhdr_int->s_nreloc = 0;
227
#else
228
10.9k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
10.9k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
10.9k
#endif
231
232
10.9k
  if (scnhdr_int->s_vaddr != 0)
233
8.40k
    {
234
8.40k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
8.40k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
8.40k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
8.40k
#endif
239
8.40k
    }
240
241
10.9k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
10.9k
  if (scnhdr_int->s_paddr > 0
247
10.9k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
8.27k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
8.27k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
1.66k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
10.9k
#endif
256
10.9k
}
pe-sh.c:coff_swap_scnhdr_in
Line
Count
Source
206
20.5k
{
207
20.5k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
20.5k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
20.5k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
20.5k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
20.5k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
20.5k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
20.5k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
20.5k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
20.5k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
20.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
  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
20.5k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
20.5k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
20.5k
#endif
231
232
20.5k
  if (scnhdr_int->s_vaddr != 0)
233
17.1k
    {
234
17.1k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
17.1k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
17.1k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
17.1k
#endif
239
17.1k
    }
240
241
20.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
20.5k
  if (scnhdr_int->s_paddr > 0
247
20.5k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
16.6k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
16.6k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
2.34k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
20.5k
#endif
256
20.5k
}
pei-arm-wince.c:coff_swap_scnhdr_in
Line
Count
Source
206
23.2k
{
207
23.2k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
23.2k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
23.2k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
23.2k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
23.2k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
23.2k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
23.2k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
23.2k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
23.2k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
23.2k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
23.2k
#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
23.2k
  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
23.2k
  if (scnhdr_int->s_vaddr != 0)
233
17.3k
    {
234
17.3k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
17.3k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
17.3k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
17.3k
#endif
239
17.3k
    }
240
241
23.2k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
23.2k
  if (scnhdr_int->s_paddr > 0
247
23.2k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
16.2k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
16.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
6.41k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
23.2k
#endif
256
23.2k
}
pei-arm.c:coff_swap_scnhdr_in
Line
Count
Source
206
28.4k
{
207
28.4k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
28.4k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
28.4k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
28.4k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
28.4k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
28.4k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
28.4k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
28.4k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
28.4k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
28.4k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
28.4k
#ifdef COFF_IMAGE_WITH_PE
224
28.4k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
28.4k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
28.4k
  scnhdr_int->s_nreloc = 0;
227
#else
228
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
#endif
231
232
28.4k
  if (scnhdr_int->s_vaddr != 0)
233
20.0k
    {
234
20.0k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
20.0k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
20.0k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
20.0k
#endif
239
20.0k
    }
240
241
28.4k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
28.4k
  if (scnhdr_int->s_paddr > 0
247
28.4k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
19.0k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
19.0k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
6.43k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
28.4k
#endif
256
28.4k
}
pei-mcore.c:coff_swap_scnhdr_in
Line
Count
Source
206
25.3k
{
207
25.3k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
25.3k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
25.3k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
25.3k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
25.3k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
25.3k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
25.3k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
25.3k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
25.3k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
25.3k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
25.3k
#ifdef COFF_IMAGE_WITH_PE
224
25.3k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
25.3k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
25.3k
  scnhdr_int->s_nreloc = 0;
227
#else
228
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
229
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
230
#endif
231
232
25.3k
  if (scnhdr_int->s_vaddr != 0)
233
18.1k
    {
234
18.1k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
18.1k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
18.1k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
18.1k
#endif
239
18.1k
    }
240
241
25.3k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
25.3k
  if (scnhdr_int->s_paddr > 0
247
25.3k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
17.7k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
17.7k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
250
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
251
     coff_set_alignment_hook stores s_paddr in virt_size, which
252
     only works if it correctly holds the virtual size of the
253
     section.  */
254
7.44k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
25.3k
#endif
256
25.3k
}
pei-sh.c:coff_swap_scnhdr_in
Line
Count
Source
206
28.2k
{
207
28.2k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
208
28.2k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
209
210
28.2k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
211
212
28.2k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
213
28.2k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
214
28.2k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
215
28.2k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
216
28.2k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
217
28.2k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
218
28.2k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
219
220
  /* MS handles overflow of line numbers by carrying into the reloc
221
     field (it appears).  Since it's supposed to be zero for PE
222
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
223
28.2k
#ifdef COFF_IMAGE_WITH_PE
224
28.2k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
225
28.2k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
226
28.2k
  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
28.2k
  if (scnhdr_int->s_vaddr != 0)
233
12.4k
    {
234
12.4k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
235
      /* Do not cut upper 32-bits for 64-bit vma.  */
236
12.4k
#if !defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) && !defined(COFF_WITH_peLoongArch64)
237
12.4k
      scnhdr_int->s_vaddr &= 0xffffffff;
238
12.4k
#endif
239
12.4k
    }
240
241
28.2k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
242
  /* If this section holds uninitialized data and is from an object file
243
     or from an executable image that has not initialized the field,
244
     or if the image is an executable file and the physical size is padded,
245
     use the virtual size (stored in s_paddr) instead.  */
246
28.2k
  if (scnhdr_int->s_paddr > 0
247
28.2k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
248
12.9k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
249
12.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
4.82k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
255
28.2k
#endif
256
28.2k
}
257
258
static bool
259
pe_mkobject (bfd * abfd)
260
125k
{
261
  /* Some x86 code followed by an ascii string.  */
262
125k
  static const char default_dos_message[64] = {
263
125k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
264
125k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
265
125k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
266
125k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
267
125k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
268
125k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
269
125k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
270
125k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
271
272
125k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
273
125k
  abfd->tdata.pe_obj_data = pe;
274
125k
  if (pe == NULL)
275
0
    return false;
276
277
125k
  pe->coff.pe = 1;
278
279
  /* in_reloc_p is architecture dependent.  */
280
125k
  pe->in_reloc_p = in_reloc_p;
281
282
125k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
283
284
125k
  bfd_coff_long_section_names (abfd)
285
125k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
286
287
125k
  return true;
288
125k
}
pei-i386.c:pe_mkobject
Line
Count
Source
260
11.5k
{
261
  /* Some x86 code followed by an ascii string.  */
262
11.5k
  static const char default_dos_message[64] = {
263
11.5k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
264
11.5k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
265
11.5k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
266
11.5k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
267
11.5k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
268
11.5k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
269
11.5k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
270
11.5k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
271
272
11.5k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
273
11.5k
  abfd->tdata.pe_obj_data = pe;
274
11.5k
  if (pe == NULL)
275
0
    return false;
276
277
11.5k
  pe->coff.pe = 1;
278
279
  /* in_reloc_p is architecture dependent.  */
280
11.5k
  pe->in_reloc_p = in_reloc_p;
281
282
11.5k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
283
284
11.5k
  bfd_coff_long_section_names (abfd)
285
11.5k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
286
287
11.5k
  return true;
288
11.5k
}
pe-x86_64.c:pe_mkobject
Line
Count
Source
260
15.9k
{
261
  /* Some x86 code followed by an ascii string.  */
262
15.9k
  static const char default_dos_message[64] = {
263
15.9k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
264
15.9k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
265
15.9k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
266
15.9k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
267
15.9k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
268
15.9k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
269
15.9k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
270
15.9k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
271
272
15.9k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
273
15.9k
  abfd->tdata.pe_obj_data = pe;
274
15.9k
  if (pe == NULL)
275
0
    return false;
276
277
15.9k
  pe->coff.pe = 1;
278
279
  /* in_reloc_p is architecture dependent.  */
280
15.9k
  pe->in_reloc_p = in_reloc_p;
281
282
15.9k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
283
284
15.9k
  bfd_coff_long_section_names (abfd)
285
15.9k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
286
287
15.9k
  return true;
288
15.9k
}
pei-x86_64.c:pe_mkobject
Line
Count
Source
260
11.5k
{
261
  /* Some x86 code followed by an ascii string.  */
262
11.5k
  static const char default_dos_message[64] = {
263
11.5k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
264
11.5k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
265
11.5k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
266
11.5k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
267
11.5k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
268
11.5k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
269
11.5k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
270
11.5k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
271
272
11.5k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
273
11.5k
  abfd->tdata.pe_obj_data = pe;
274
11.5k
  if (pe == NULL)
275
0
    return false;
276
277
11.5k
  pe->coff.pe = 1;
278
279
  /* in_reloc_p is architecture dependent.  */
280
11.5k
  pe->in_reloc_p = in_reloc_p;
281
282
11.5k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
283
284
11.5k
  bfd_coff_long_section_names (abfd)
285
11.5k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
286
287
11.5k
  return true;
288
11.5k
}
pe-aarch64.c:pe_mkobject
Line
Count
Source
260
5.21k
{
261
  /* Some x86 code followed by an ascii string.  */
262
5.21k
  static const char default_dos_message[64] = {
263
5.21k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
264
5.21k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
265
5.21k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
266
5.21k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
267
5.21k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
268
5.21k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
269
5.21k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
270
5.21k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
271
272
5.21k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
273
5.21k
  abfd->tdata.pe_obj_data = pe;
274
5.21k
  if (pe == NULL)
275
0
    return false;
276
277
5.21k
  pe->coff.pe = 1;
278
279
  /* in_reloc_p is architecture dependent.  */
280
5.21k
  pe->in_reloc_p = in_reloc_p;
281
282
5.21k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
283
284
5.21k
  bfd_coff_long_section_names (abfd)
285
5.21k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
286
287
5.21k
  return true;
288
5.21k
}
pei-aarch64.c:pe_mkobject
Line
Count
Source
260
5.46k
{
261
  /* Some x86 code followed by an ascii string.  */
262
5.46k
  static const char default_dos_message[64] = {
263
5.46k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
264
5.46k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
265
5.46k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
266
5.46k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
267
5.46k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
268
5.46k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
269
5.46k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
270
5.46k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
271
272
5.46k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
273
5.46k
  abfd->tdata.pe_obj_data = pe;
274
5.46k
  if (pe == NULL)
275
0
    return false;
276
277
5.46k
  pe->coff.pe = 1;
278
279
  /* in_reloc_p is architecture dependent.  */
280
5.46k
  pe->in_reloc_p = in_reloc_p;
281
282
5.46k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
283
284
5.46k
  bfd_coff_long_section_names (abfd)
285
5.46k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
286
287
5.46k
  return true;
288
5.46k
}
pei-ia64.c:pe_mkobject
Line
Count
Source
260
6.43k
{
261
  /* Some x86 code followed by an ascii string.  */
262
6.43k
  static const char default_dos_message[64] = {
263
6.43k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
264
6.43k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
265
6.43k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
266
6.43k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
267
6.43k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
268
6.43k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
269
6.43k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
270
6.43k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
271
272
6.43k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
273
6.43k
  abfd->tdata.pe_obj_data = pe;
274
6.43k
  if (pe == NULL)
275
0
    return false;
276
277
6.43k
  pe->coff.pe = 1;
278
279
  /* in_reloc_p is architecture dependent.  */
280
6.43k
  pe->in_reloc_p = in_reloc_p;
281
282
6.43k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
283
284
6.43k
  bfd_coff_long_section_names (abfd)
285
6.43k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
286
287
6.43k
  return true;
288
6.43k
}
pei-loongarch64.c:pe_mkobject
Line
Count
Source
260
7.67k
{
261
  /* Some x86 code followed by an ascii string.  */
262
7.67k
  static const char default_dos_message[64] = {
263
7.67k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
264
7.67k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
265
7.67k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
266
7.67k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
267
7.67k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
268
7.67k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
269
7.67k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
270
7.67k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
271
272
7.67k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
273
7.67k
  abfd->tdata.pe_obj_data = pe;
274
7.67k
  if (pe == NULL)
275
0
    return false;
276
277
7.67k
  pe->coff.pe = 1;
278
279
  /* in_reloc_p is architecture dependent.  */
280
7.67k
  pe->in_reloc_p = in_reloc_p;
281
282
7.67k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
283
284
7.67k
  bfd_coff_long_section_names (abfd)
285
7.67k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
286
287
7.67k
  return true;
288
7.67k
}
pe-arm-wince.c:pe_mkobject
Line
Count
Source
260
2.97k
{
261
  /* Some x86 code followed by an ascii string.  */
262
2.97k
  static const char default_dos_message[64] = {
263
2.97k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
264
2.97k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
265
2.97k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
266
2.97k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
267
2.97k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
268
2.97k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
269
2.97k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
270
2.97k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
271
272
2.97k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
273
2.97k
  abfd->tdata.pe_obj_data = pe;
274
2.97k
  if (pe == NULL)
275
0
    return false;
276
277
2.97k
  pe->coff.pe = 1;
278
279
  /* in_reloc_p is architecture dependent.  */
280
2.97k
  pe->in_reloc_p = in_reloc_p;
281
282
2.97k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
283
284
2.97k
  bfd_coff_long_section_names (abfd)
285
2.97k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
286
287
2.97k
  return true;
288
2.97k
}
pe-arm.c:pe_mkobject
Line
Count
Source
260
2.97k
{
261
  /* Some x86 code followed by an ascii string.  */
262
2.97k
  static const char default_dos_message[64] = {
263
2.97k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
264
2.97k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
265
2.97k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
266
2.97k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
267
2.97k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
268
2.97k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
269
2.97k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
270
2.97k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
271
272
2.97k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
273
2.97k
  abfd->tdata.pe_obj_data = pe;
274
2.97k
  if (pe == NULL)
275
0
    return false;
276
277
2.97k
  pe->coff.pe = 1;
278
279
  /* in_reloc_p is architecture dependent.  */
280
2.97k
  pe->in_reloc_p = in_reloc_p;
281
282
2.97k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
283
284
2.97k
  bfd_coff_long_section_names (abfd)
285
2.97k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
286
287
2.97k
  return true;
288
2.97k
}
pe-i386.c:pe_mkobject
Line
Count
Source
260
8.42k
{
261
  /* Some x86 code followed by an ascii string.  */
262
8.42k
  static const char default_dos_message[64] = {
263
8.42k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
264
8.42k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
265
8.42k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
266
8.42k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
267
8.42k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
268
8.42k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
269
8.42k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
270
8.42k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
271
272
8.42k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
273
8.42k
  abfd->tdata.pe_obj_data = pe;
274
8.42k
  if (pe == NULL)
275
0
    return false;
276
277
8.42k
  pe->coff.pe = 1;
278
279
  /* in_reloc_p is architecture dependent.  */
280
8.42k
  pe->in_reloc_p = in_reloc_p;
281
282
8.42k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
283
284
8.42k
  bfd_coff_long_section_names (abfd)
285
8.42k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
286
287
8.42k
  return true;
288
8.42k
}
pe-mcore.c:pe_mkobject
Line
Count
Source
260
4.06k
{
261
  /* Some x86 code followed by an ascii string.  */
262
4.06k
  static const char default_dos_message[64] = {
263
4.06k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
264
4.06k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
265
4.06k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
266
4.06k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
267
4.06k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
268
4.06k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
269
4.06k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
270
4.06k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
271
272
4.06k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
273
4.06k
  abfd->tdata.pe_obj_data = pe;
274
4.06k
  if (pe == NULL)
275
0
    return false;
276
277
4.06k
  pe->coff.pe = 1;
278
279
  /* in_reloc_p is architecture dependent.  */
280
4.06k
  pe->in_reloc_p = in_reloc_p;
281
282
4.06k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
283
284
4.06k
  bfd_coff_long_section_names (abfd)
285
4.06k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
286
287
4.06k
  return true;
288
4.06k
}
pe-sh.c:pe_mkobject
Line
Count
Source
260
7.10k
{
261
  /* Some x86 code followed by an ascii string.  */
262
7.10k
  static const char default_dos_message[64] = {
263
7.10k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
264
7.10k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
265
7.10k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
266
7.10k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
267
7.10k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
268
7.10k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
269
7.10k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
270
7.10k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
271
272
7.10k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
273
7.10k
  abfd->tdata.pe_obj_data = pe;
274
7.10k
  if (pe == NULL)
275
0
    return false;
276
277
7.10k
  pe->coff.pe = 1;
278
279
  /* in_reloc_p is architecture dependent.  */
280
7.10k
  pe->in_reloc_p = in_reloc_p;
281
282
7.10k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
283
284
7.10k
  bfd_coff_long_section_names (abfd)
285
7.10k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
286
287
7.10k
  return true;
288
7.10k
}
pei-arm-wince.c:pe_mkobject
Line
Count
Source
260
9.29k
{
261
  /* Some x86 code followed by an ascii string.  */
262
9.29k
  static const char default_dos_message[64] = {
263
9.29k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
264
9.29k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
265
9.29k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
266
9.29k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
267
9.29k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
268
9.29k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
269
9.29k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
270
9.29k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
271
272
9.29k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
273
9.29k
  abfd->tdata.pe_obj_data = pe;
274
9.29k
  if (pe == NULL)
275
0
    return false;
276
277
9.29k
  pe->coff.pe = 1;
278
279
  /* in_reloc_p is architecture dependent.  */
280
9.29k
  pe->in_reloc_p = in_reloc_p;
281
282
9.29k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
283
284
9.29k
  bfd_coff_long_section_names (abfd)
285
9.29k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
286
287
9.29k
  return true;
288
9.29k
}
pei-arm.c:pe_mkobject
Line
Count
Source
260
10.3k
{
261
  /* Some x86 code followed by an ascii string.  */
262
10.3k
  static const char default_dos_message[64] = {
263
10.3k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
264
10.3k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
265
10.3k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
266
10.3k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
267
10.3k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
268
10.3k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
269
10.3k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
270
10.3k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
271
272
10.3k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
273
10.3k
  abfd->tdata.pe_obj_data = pe;
274
10.3k
  if (pe == NULL)
275
0
    return false;
276
277
10.3k
  pe->coff.pe = 1;
278
279
  /* in_reloc_p is architecture dependent.  */
280
10.3k
  pe->in_reloc_p = in_reloc_p;
281
282
10.3k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
283
284
10.3k
  bfd_coff_long_section_names (abfd)
285
10.3k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
286
287
10.3k
  return true;
288
10.3k
}
pei-mcore.c:pe_mkobject
Line
Count
Source
260
8.33k
{
261
  /* Some x86 code followed by an ascii string.  */
262
8.33k
  static const char default_dos_message[64] = {
263
8.33k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
264
8.33k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
265
8.33k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
266
8.33k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
267
8.33k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
268
8.33k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
269
8.33k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
270
8.33k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
271
272
8.33k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
273
8.33k
  abfd->tdata.pe_obj_data = pe;
274
8.33k
  if (pe == NULL)
275
0
    return false;
276
277
8.33k
  pe->coff.pe = 1;
278
279
  /* in_reloc_p is architecture dependent.  */
280
8.33k
  pe->in_reloc_p = in_reloc_p;
281
282
8.33k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
283
284
8.33k
  bfd_coff_long_section_names (abfd)
285
8.33k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
286
287
8.33k
  return true;
288
8.33k
}
pei-sh.c:pe_mkobject
Line
Count
Source
260
7.77k
{
261
  /* Some x86 code followed by an ascii string.  */
262
7.77k
  static const char default_dos_message[64] = {
263
7.77k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
264
7.77k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
265
7.77k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
266
7.77k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
267
7.77k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
268
7.77k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
269
7.77k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
270
7.77k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
271
272
7.77k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
273
7.77k
  abfd->tdata.pe_obj_data = pe;
274
7.77k
  if (pe == NULL)
275
0
    return false;
276
277
7.77k
  pe->coff.pe = 1;
278
279
  /* in_reloc_p is architecture dependent.  */
280
7.77k
  pe->in_reloc_p = in_reloc_p;
281
282
7.77k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
283
284
7.77k
  bfd_coff_long_section_names (abfd)
285
7.77k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
286
287
7.77k
  return true;
288
7.77k
}
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
125k
{
297
125k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
298
125k
  pe_data_type *pe;
299
300
125k
  if (! pe_mkobject (abfd))
301
0
    return NULL;
302
303
125k
  pe = pe_data (abfd);
304
125k
  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
125k
  pe->coff.local_n_btmask = N_BTMASK;
309
125k
  pe->coff.local_n_btshft = N_BTSHFT;
310
125k
  pe->coff.local_n_tmask = N_TMASK;
311
125k
  pe->coff.local_n_tshift = N_TSHIFT;
312
125k
  pe->coff.local_symesz = SYMESZ;
313
125k
  pe->coff.local_auxesz = AUXESZ;
314
125k
  pe->coff.local_linesz = LINESZ;
315
316
125k
  pe->coff.timestamp = internal_f->f_timdat;
317
318
125k
  obj_raw_syment_count (abfd) =
319
125k
    obj_conv_table_size (abfd) =
320
125k
      internal_f->f_nsyms;
321
322
125k
  pe->real_flags = internal_f->f_flags;
323
324
125k
  if ((internal_f->f_flags & F_DLL) != 0)
325
32.4k
    pe->dll = 1;
326
327
125k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
328
93.5k
    abfd->flags |= HAS_DEBUG;
329
330
#ifdef COFF_IMAGE_WITH_PE
331
78.4k
  if (aouthdr)
332
49.3k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
333
#endif
334
335
#ifdef ARM
336
25.6k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
337
0
    coff_data (abfd) ->flags = 0;
338
#endif
339
340
125k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
341
125k
    sizeof (pe->dos_message));
342
343
125k
  return (void *) pe;
344
125k
}
pei-i386.c:pe_mkobject_hook
Line
Count
Source
296
11.5k
{
297
11.5k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
298
11.5k
  pe_data_type *pe;
299
300
11.5k
  if (! pe_mkobject (abfd))
301
0
    return NULL;
302
303
11.5k
  pe = pe_data (abfd);
304
11.5k
  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
11.5k
  pe->coff.local_n_btmask = N_BTMASK;
309
11.5k
  pe->coff.local_n_btshft = N_BTSHFT;
310
11.5k
  pe->coff.local_n_tmask = N_TMASK;
311
11.5k
  pe->coff.local_n_tshift = N_TSHIFT;
312
11.5k
  pe->coff.local_symesz = SYMESZ;
313
11.5k
  pe->coff.local_auxesz = AUXESZ;
314
11.5k
  pe->coff.local_linesz = LINESZ;
315
316
11.5k
  pe->coff.timestamp = internal_f->f_timdat;
317
318
11.5k
  obj_raw_syment_count (abfd) =
319
11.5k
    obj_conv_table_size (abfd) =
320
11.5k
      internal_f->f_nsyms;
321
322
11.5k
  pe->real_flags = internal_f->f_flags;
323
324
11.5k
  if ((internal_f->f_flags & F_DLL) != 0)
325
2.66k
    pe->dll = 1;
326
327
11.5k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
328
8.60k
    abfd->flags |= HAS_DEBUG;
329
330
11.5k
#ifdef COFF_IMAGE_WITH_PE
331
11.5k
  if (aouthdr)
332
9.17k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
333
11.5k
#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
11.5k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
341
11.5k
    sizeof (pe->dos_message));
342
343
11.5k
  return (void *) pe;
344
11.5k
}
pe-x86_64.c:pe_mkobject_hook
Line
Count
Source
296
15.9k
{
297
15.9k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
298
15.9k
  pe_data_type *pe;
299
300
15.9k
  if (! pe_mkobject (abfd))
301
0
    return NULL;
302
303
15.9k
  pe = pe_data (abfd);
304
15.9k
  pe->coff.sym_filepos = internal_f->f_symptr;
305
  /* These members communicate important constants about the symbol
306
     table to GDB's symbol-reading code.  These `constants'
307
     unfortunately vary among coff implementations...  */
308
15.9k
  pe->coff.local_n_btmask = N_BTMASK;
309
15.9k
  pe->coff.local_n_btshft = N_BTSHFT;
310
15.9k
  pe->coff.local_n_tmask = N_TMASK;
311
15.9k
  pe->coff.local_n_tshift = N_TSHIFT;
312
15.9k
  pe->coff.local_symesz = SYMESZ;
313
15.9k
  pe->coff.local_auxesz = AUXESZ;
314
15.9k
  pe->coff.local_linesz = LINESZ;
315
316
15.9k
  pe->coff.timestamp = internal_f->f_timdat;
317
318
15.9k
  obj_raw_syment_count (abfd) =
319
15.9k
    obj_conv_table_size (abfd) =
320
15.9k
      internal_f->f_nsyms;
321
322
15.9k
  pe->real_flags = internal_f->f_flags;
323
324
15.9k
  if ((internal_f->f_flags & F_DLL) != 0)
325
2.06k
    pe->dll = 1;
326
327
15.9k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
328
12.0k
    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
15.9k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
341
15.9k
    sizeof (pe->dos_message));
342
343
15.9k
  return (void *) pe;
344
15.9k
}
pei-x86_64.c:pe_mkobject_hook
Line
Count
Source
296
11.5k
{
297
11.5k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
298
11.5k
  pe_data_type *pe;
299
300
11.5k
  if (! pe_mkobject (abfd))
301
0
    return NULL;
302
303
11.5k
  pe = pe_data (abfd);
304
11.5k
  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
11.5k
  pe->coff.local_n_btmask = N_BTMASK;
309
11.5k
  pe->coff.local_n_btshft = N_BTSHFT;
310
11.5k
  pe->coff.local_n_tmask = N_TMASK;
311
11.5k
  pe->coff.local_n_tshift = N_TSHIFT;
312
11.5k
  pe->coff.local_symesz = SYMESZ;
313
11.5k
  pe->coff.local_auxesz = AUXESZ;
314
11.5k
  pe->coff.local_linesz = LINESZ;
315
316
11.5k
  pe->coff.timestamp = internal_f->f_timdat;
317
318
11.5k
  obj_raw_syment_count (abfd) =
319
11.5k
    obj_conv_table_size (abfd) =
320
11.5k
      internal_f->f_nsyms;
321
322
11.5k
  pe->real_flags = internal_f->f_flags;
323
324
11.5k
  if ((internal_f->f_flags & F_DLL) != 0)
325
4.56k
    pe->dll = 1;
326
327
11.5k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
328
7.31k
    abfd->flags |= HAS_DEBUG;
329
330
11.5k
#ifdef COFF_IMAGE_WITH_PE
331
11.5k
  if (aouthdr)
332
7.34k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
333
11.5k
#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
11.5k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
341
11.5k
    sizeof (pe->dos_message));
342
343
11.5k
  return (void *) pe;
344
11.5k
}
pe-aarch64.c:pe_mkobject_hook
Line
Count
Source
296
5.21k
{
297
5.21k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
298
5.21k
  pe_data_type *pe;
299
300
5.21k
  if (! pe_mkobject (abfd))
301
0
    return NULL;
302
303
5.21k
  pe = pe_data (abfd);
304
5.21k
  pe->coff.sym_filepos = internal_f->f_symptr;
305
  /* These members communicate important constants about the symbol
306
     table to GDB's symbol-reading code.  These `constants'
307
     unfortunately vary among coff implementations...  */
308
5.21k
  pe->coff.local_n_btmask = N_BTMASK;
309
5.21k
  pe->coff.local_n_btshft = N_BTSHFT;
310
5.21k
  pe->coff.local_n_tmask = N_TMASK;
311
5.21k
  pe->coff.local_n_tshift = N_TSHIFT;
312
5.21k
  pe->coff.local_symesz = SYMESZ;
313
5.21k
  pe->coff.local_auxesz = AUXESZ;
314
5.21k
  pe->coff.local_linesz = LINESZ;
315
316
5.21k
  pe->coff.timestamp = internal_f->f_timdat;
317
318
5.21k
  obj_raw_syment_count (abfd) =
319
5.21k
    obj_conv_table_size (abfd) =
320
5.21k
      internal_f->f_nsyms;
321
322
5.21k
  pe->real_flags = internal_f->f_flags;
323
324
5.21k
  if ((internal_f->f_flags & F_DLL) != 0)
325
1.00k
    pe->dll = 1;
326
327
5.21k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
328
4.22k
    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
5.21k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
341
5.21k
    sizeof (pe->dos_message));
342
343
5.21k
  return (void *) pe;
344
5.21k
}
pei-aarch64.c:pe_mkobject_hook
Line
Count
Source
296
5.46k
{
297
5.46k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
298
5.46k
  pe_data_type *pe;
299
300
5.46k
  if (! pe_mkobject (abfd))
301
0
    return NULL;
302
303
5.46k
  pe = pe_data (abfd);
304
5.46k
  pe->coff.sym_filepos = internal_f->f_symptr;
305
  /* These members communicate important constants about the symbol
306
     table to GDB's symbol-reading code.  These `constants'
307
     unfortunately vary among coff implementations...  */
308
5.46k
  pe->coff.local_n_btmask = N_BTMASK;
309
5.46k
  pe->coff.local_n_btshft = N_BTSHFT;
310
5.46k
  pe->coff.local_n_tmask = N_TMASK;
311
5.46k
  pe->coff.local_n_tshift = N_TSHIFT;
312
5.46k
  pe->coff.local_symesz = SYMESZ;
313
5.46k
  pe->coff.local_auxesz = AUXESZ;
314
5.46k
  pe->coff.local_linesz = LINESZ;
315
316
5.46k
  pe->coff.timestamp = internal_f->f_timdat;
317
318
5.46k
  obj_raw_syment_count (abfd) =
319
5.46k
    obj_conv_table_size (abfd) =
320
5.46k
      internal_f->f_nsyms;
321
322
5.46k
  pe->real_flags = internal_f->f_flags;
323
324
5.46k
  if ((internal_f->f_flags & F_DLL) != 0)
325
1.06k
    pe->dll = 1;
326
327
5.46k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
328
4.35k
    abfd->flags |= HAS_DEBUG;
329
330
5.46k
#ifdef COFF_IMAGE_WITH_PE
331
5.46k
  if (aouthdr)
332
3.75k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
333
5.46k
#endif
334
335
#ifdef ARM
336
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
337
    coff_data (abfd) ->flags = 0;
338
#endif
339
340
5.46k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
341
5.46k
    sizeof (pe->dos_message));
342
343
5.46k
  return (void *) pe;
344
5.46k
}
pei-ia64.c:pe_mkobject_hook
Line
Count
Source
296
6.43k
{
297
6.43k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
298
6.43k
  pe_data_type *pe;
299
300
6.43k
  if (! pe_mkobject (abfd))
301
0
    return NULL;
302
303
6.43k
  pe = pe_data (abfd);
304
6.43k
  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
6.43k
  pe->coff.local_n_btmask = N_BTMASK;
309
6.43k
  pe->coff.local_n_btshft = N_BTSHFT;
310
6.43k
  pe->coff.local_n_tmask = N_TMASK;
311
6.43k
  pe->coff.local_n_tshift = N_TSHIFT;
312
6.43k
  pe->coff.local_symesz = SYMESZ;
313
6.43k
  pe->coff.local_auxesz = AUXESZ;
314
6.43k
  pe->coff.local_linesz = LINESZ;
315
316
6.43k
  pe->coff.timestamp = internal_f->f_timdat;
317
318
6.43k
  obj_raw_syment_count (abfd) =
319
6.43k
    obj_conv_table_size (abfd) =
320
6.43k
      internal_f->f_nsyms;
321
322
6.43k
  pe->real_flags = internal_f->f_flags;
323
324
6.43k
  if ((internal_f->f_flags & F_DLL) != 0)
325
2.01k
    pe->dll = 1;
326
327
6.43k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
328
3.90k
    abfd->flags |= HAS_DEBUG;
329
330
6.43k
#ifdef COFF_IMAGE_WITH_PE
331
6.43k
  if (aouthdr)
332
4.48k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
333
6.43k
#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
6.43k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
341
6.43k
    sizeof (pe->dos_message));
342
343
6.43k
  return (void *) pe;
344
6.43k
}
pei-loongarch64.c:pe_mkobject_hook
Line
Count
Source
296
7.67k
{
297
7.67k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
298
7.67k
  pe_data_type *pe;
299
300
7.67k
  if (! pe_mkobject (abfd))
301
0
    return NULL;
302
303
7.67k
  pe = pe_data (abfd);
304
7.67k
  pe->coff.sym_filepos = internal_f->f_symptr;
305
  /* These members communicate important constants about the symbol
306
     table to GDB's symbol-reading code.  These `constants'
307
     unfortunately vary among coff implementations...  */
308
7.67k
  pe->coff.local_n_btmask = N_BTMASK;
309
7.67k
  pe->coff.local_n_btshft = N_BTSHFT;
310
7.67k
  pe->coff.local_n_tmask = N_TMASK;
311
7.67k
  pe->coff.local_n_tshift = N_TSHIFT;
312
7.67k
  pe->coff.local_symesz = SYMESZ;
313
7.67k
  pe->coff.local_auxesz = AUXESZ;
314
7.67k
  pe->coff.local_linesz = LINESZ;
315
316
7.67k
  pe->coff.timestamp = internal_f->f_timdat;
317
318
7.67k
  obj_raw_syment_count (abfd) =
319
7.67k
    obj_conv_table_size (abfd) =
320
7.67k
      internal_f->f_nsyms;
321
322
7.67k
  pe->real_flags = internal_f->f_flags;
323
324
7.67k
  if ((internal_f->f_flags & F_DLL) != 0)
325
3.71k
    pe->dll = 1;
326
327
7.67k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
328
5.98k
    abfd->flags |= HAS_DEBUG;
329
330
7.67k
#ifdef COFF_IMAGE_WITH_PE
331
7.67k
  if (aouthdr)
332
5.77k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
333
7.67k
#endif
334
335
#ifdef ARM
336
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
337
    coff_data (abfd) ->flags = 0;
338
#endif
339
340
7.67k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
341
7.67k
    sizeof (pe->dos_message));
342
343
7.67k
  return (void *) pe;
344
7.67k
}
pe-arm-wince.c:pe_mkobject_hook
Line
Count
Source
296
2.97k
{
297
2.97k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
298
2.97k
  pe_data_type *pe;
299
300
2.97k
  if (! pe_mkobject (abfd))
301
0
    return NULL;
302
303
2.97k
  pe = pe_data (abfd);
304
2.97k
  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.97k
  pe->coff.local_n_btmask = N_BTMASK;
309
2.97k
  pe->coff.local_n_btshft = N_BTSHFT;
310
2.97k
  pe->coff.local_n_tmask = N_TMASK;
311
2.97k
  pe->coff.local_n_tshift = N_TSHIFT;
312
2.97k
  pe->coff.local_symesz = SYMESZ;
313
2.97k
  pe->coff.local_auxesz = AUXESZ;
314
2.97k
  pe->coff.local_linesz = LINESZ;
315
316
2.97k
  pe->coff.timestamp = internal_f->f_timdat;
317
318
2.97k
  obj_raw_syment_count (abfd) =
319
2.97k
    obj_conv_table_size (abfd) =
320
2.97k
      internal_f->f_nsyms;
321
322
2.97k
  pe->real_flags = internal_f->f_flags;
323
324
2.97k
  if ((internal_f->f_flags & F_DLL) != 0)
325
254
    pe->dll = 1;
326
327
2.97k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
328
2.82k
    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
2.97k
#ifdef ARM
336
2.97k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
337
0
    coff_data (abfd) ->flags = 0;
338
2.97k
#endif
339
340
2.97k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
341
2.97k
    sizeof (pe->dos_message));
342
343
2.97k
  return (void *) pe;
344
2.97k
}
pe-arm.c:pe_mkobject_hook
Line
Count
Source
296
2.97k
{
297
2.97k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
298
2.97k
  pe_data_type *pe;
299
300
2.97k
  if (! pe_mkobject (abfd))
301
0
    return NULL;
302
303
2.97k
  pe = pe_data (abfd);
304
2.97k
  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.97k
  pe->coff.local_n_btmask = N_BTMASK;
309
2.97k
  pe->coff.local_n_btshft = N_BTSHFT;
310
2.97k
  pe->coff.local_n_tmask = N_TMASK;
311
2.97k
  pe->coff.local_n_tshift = N_TSHIFT;
312
2.97k
  pe->coff.local_symesz = SYMESZ;
313
2.97k
  pe->coff.local_auxesz = AUXESZ;
314
2.97k
  pe->coff.local_linesz = LINESZ;
315
316
2.97k
  pe->coff.timestamp = internal_f->f_timdat;
317
318
2.97k
  obj_raw_syment_count (abfd) =
319
2.97k
    obj_conv_table_size (abfd) =
320
2.97k
      internal_f->f_nsyms;
321
322
2.97k
  pe->real_flags = internal_f->f_flags;
323
324
2.97k
  if ((internal_f->f_flags & F_DLL) != 0)
325
254
    pe->dll = 1;
326
327
2.97k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
328
2.82k
    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
2.97k
#ifdef ARM
336
2.97k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
337
0
    coff_data (abfd) ->flags = 0;
338
2.97k
#endif
339
340
2.97k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
341
2.97k
    sizeof (pe->dos_message));
342
343
2.97k
  return (void *) pe;
344
2.97k
}
pe-i386.c:pe_mkobject_hook
Line
Count
Source
296
8.42k
{
297
8.42k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
298
8.42k
  pe_data_type *pe;
299
300
8.42k
  if (! pe_mkobject (abfd))
301
0
    return NULL;
302
303
8.42k
  pe = pe_data (abfd);
304
8.42k
  pe->coff.sym_filepos = internal_f->f_symptr;
305
  /* These members communicate important constants about the symbol
306
     table to GDB's symbol-reading code.  These `constants'
307
     unfortunately vary among coff implementations...  */
308
8.42k
  pe->coff.local_n_btmask = N_BTMASK;
309
8.42k
  pe->coff.local_n_btshft = N_BTSHFT;
310
8.42k
  pe->coff.local_n_tmask = N_TMASK;
311
8.42k
  pe->coff.local_n_tshift = N_TSHIFT;
312
8.42k
  pe->coff.local_symesz = SYMESZ;
313
8.42k
  pe->coff.local_auxesz = AUXESZ;
314
8.42k
  pe->coff.local_linesz = LINESZ;
315
316
8.42k
  pe->coff.timestamp = internal_f->f_timdat;
317
318
8.42k
  obj_raw_syment_count (abfd) =
319
8.42k
    obj_conv_table_size (abfd) =
320
8.42k
      internal_f->f_nsyms;
321
322
8.42k
  pe->real_flags = internal_f->f_flags;
323
324
8.42k
  if ((internal_f->f_flags & F_DLL) != 0)
325
2.30k
    pe->dll = 1;
326
327
8.42k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
328
7.38k
    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
8.42k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
341
8.42k
    sizeof (pe->dos_message));
342
343
8.42k
  return (void *) pe;
344
8.42k
}
pe-mcore.c:pe_mkobject_hook
Line
Count
Source
296
4.06k
{
297
4.06k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
298
4.06k
  pe_data_type *pe;
299
300
4.06k
  if (! pe_mkobject (abfd))
301
0
    return NULL;
302
303
4.06k
  pe = pe_data (abfd);
304
4.06k
  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
4.06k
  pe->coff.local_n_btmask = N_BTMASK;
309
4.06k
  pe->coff.local_n_btshft = N_BTSHFT;
310
4.06k
  pe->coff.local_n_tmask = N_TMASK;
311
4.06k
  pe->coff.local_n_tshift = N_TSHIFT;
312
4.06k
  pe->coff.local_symesz = SYMESZ;
313
4.06k
  pe->coff.local_auxesz = AUXESZ;
314
4.06k
  pe->coff.local_linesz = LINESZ;
315
316
4.06k
  pe->coff.timestamp = internal_f->f_timdat;
317
318
4.06k
  obj_raw_syment_count (abfd) =
319
4.06k
    obj_conv_table_size (abfd) =
320
4.06k
      internal_f->f_nsyms;
321
322
4.06k
  pe->real_flags = internal_f->f_flags;
323
324
4.06k
  if ((internal_f->f_flags & F_DLL) != 0)
325
637
    pe->dll = 1;
326
327
4.06k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
328
3.50k
    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
4.06k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
341
4.06k
    sizeof (pe->dos_message));
342
343
4.06k
  return (void *) pe;
344
4.06k
}
pe-sh.c:pe_mkobject_hook
Line
Count
Source
296
7.10k
{
297
7.10k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
298
7.10k
  pe_data_type *pe;
299
300
7.10k
  if (! pe_mkobject (abfd))
301
0
    return NULL;
302
303
7.10k
  pe = pe_data (abfd);
304
7.10k
  pe->coff.sym_filepos = internal_f->f_symptr;
305
  /* These members communicate important constants about the symbol
306
     table to GDB's symbol-reading code.  These `constants'
307
     unfortunately vary among coff implementations...  */
308
7.10k
  pe->coff.local_n_btmask = N_BTMASK;
309
7.10k
  pe->coff.local_n_btshft = N_BTSHFT;
310
7.10k
  pe->coff.local_n_tmask = N_TMASK;
311
7.10k
  pe->coff.local_n_tshift = N_TSHIFT;
312
7.10k
  pe->coff.local_symesz = SYMESZ;
313
7.10k
  pe->coff.local_auxesz = AUXESZ;
314
7.10k
  pe->coff.local_linesz = LINESZ;
315
316
7.10k
  pe->coff.timestamp = internal_f->f_timdat;
317
318
7.10k
  obj_raw_syment_count (abfd) =
319
7.10k
    obj_conv_table_size (abfd) =
320
7.10k
      internal_f->f_nsyms;
321
322
7.10k
  pe->real_flags = internal_f->f_flags;
323
324
7.10k
  if ((internal_f->f_flags & F_DLL) != 0)
325
2.23k
    pe->dll = 1;
326
327
7.10k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
328
5.46k
    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
7.10k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
341
7.10k
    sizeof (pe->dos_message));
342
343
7.10k
  return (void *) pe;
344
7.10k
}
pei-arm-wince.c:pe_mkobject_hook
Line
Count
Source
296
9.29k
{
297
9.29k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
298
9.29k
  pe_data_type *pe;
299
300
9.29k
  if (! pe_mkobject (abfd))
301
0
    return NULL;
302
303
9.29k
  pe = pe_data (abfd);
304
9.29k
  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.29k
  pe->coff.local_n_btmask = N_BTMASK;
309
9.29k
  pe->coff.local_n_btshft = N_BTSHFT;
310
9.29k
  pe->coff.local_n_tmask = N_TMASK;
311
9.29k
  pe->coff.local_n_tshift = N_TSHIFT;
312
9.29k
  pe->coff.local_symesz = SYMESZ;
313
9.29k
  pe->coff.local_auxesz = AUXESZ;
314
9.29k
  pe->coff.local_linesz = LINESZ;
315
316
9.29k
  pe->coff.timestamp = internal_f->f_timdat;
317
318
9.29k
  obj_raw_syment_count (abfd) =
319
9.29k
    obj_conv_table_size (abfd) =
320
9.29k
      internal_f->f_nsyms;
321
322
9.29k
  pe->real_flags = internal_f->f_flags;
323
324
9.29k
  if ((internal_f->f_flags & F_DLL) != 0)
325
3.11k
    pe->dll = 1;
326
327
9.29k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
328
5.44k
    abfd->flags |= HAS_DEBUG;
329
330
9.29k
#ifdef COFF_IMAGE_WITH_PE
331
9.29k
  if (aouthdr)
332
4.35k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
333
9.29k
#endif
334
335
9.29k
#ifdef ARM
336
9.29k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
337
0
    coff_data (abfd) ->flags = 0;
338
9.29k
#endif
339
340
9.29k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
341
9.29k
    sizeof (pe->dos_message));
342
343
9.29k
  return (void *) pe;
344
9.29k
}
pei-arm.c:pe_mkobject_hook
Line
Count
Source
296
10.3k
{
297
10.3k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
298
10.3k
  pe_data_type *pe;
299
300
10.3k
  if (! pe_mkobject (abfd))
301
0
    return NULL;
302
303
10.3k
  pe = pe_data (abfd);
304
10.3k
  pe->coff.sym_filepos = internal_f->f_symptr;
305
  /* These members communicate important constants about the symbol
306
     table to GDB's symbol-reading code.  These `constants'
307
     unfortunately vary among coff implementations...  */
308
10.3k
  pe->coff.local_n_btmask = N_BTMASK;
309
10.3k
  pe->coff.local_n_btshft = N_BTSHFT;
310
10.3k
  pe->coff.local_n_tmask = N_TMASK;
311
10.3k
  pe->coff.local_n_tshift = N_TSHIFT;
312
10.3k
  pe->coff.local_symesz = SYMESZ;
313
10.3k
  pe->coff.local_auxesz = AUXESZ;
314
10.3k
  pe->coff.local_linesz = LINESZ;
315
316
10.3k
  pe->coff.timestamp = internal_f->f_timdat;
317
318
10.3k
  obj_raw_syment_count (abfd) =
319
10.3k
    obj_conv_table_size (abfd) =
320
10.3k
      internal_f->f_nsyms;
321
322
10.3k
  pe->real_flags = internal_f->f_flags;
323
324
10.3k
  if ((internal_f->f_flags & F_DLL) != 0)
325
2.95k
    pe->dll = 1;
326
327
10.3k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
328
7.02k
    abfd->flags |= HAS_DEBUG;
329
330
10.3k
#ifdef COFF_IMAGE_WITH_PE
331
10.3k
  if (aouthdr)
332
4.61k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
333
10.3k
#endif
334
335
10.3k
#ifdef ARM
336
10.3k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
337
0
    coff_data (abfd) ->flags = 0;
338
10.3k
#endif
339
340
10.3k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
341
10.3k
    sizeof (pe->dos_message));
342
343
10.3k
  return (void *) pe;
344
10.3k
}
pei-mcore.c:pe_mkobject_hook
Line
Count
Source
296
8.33k
{
297
8.33k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
298
8.33k
  pe_data_type *pe;
299
300
8.33k
  if (! pe_mkobject (abfd))
301
0
    return NULL;
302
303
8.33k
  pe = pe_data (abfd);
304
8.33k
  pe->coff.sym_filepos = internal_f->f_symptr;
305
  /* These members communicate important constants about the symbol
306
     table to GDB's symbol-reading code.  These `constants'
307
     unfortunately vary among coff implementations...  */
308
8.33k
  pe->coff.local_n_btmask = N_BTMASK;
309
8.33k
  pe->coff.local_n_btshft = N_BTSHFT;
310
8.33k
  pe->coff.local_n_tmask = N_TMASK;
311
8.33k
  pe->coff.local_n_tshift = N_TSHIFT;
312
8.33k
  pe->coff.local_symesz = SYMESZ;
313
8.33k
  pe->coff.local_auxesz = AUXESZ;
314
8.33k
  pe->coff.local_linesz = LINESZ;
315
316
8.33k
  pe->coff.timestamp = internal_f->f_timdat;
317
318
8.33k
  obj_raw_syment_count (abfd) =
319
8.33k
    obj_conv_table_size (abfd) =
320
8.33k
      internal_f->f_nsyms;
321
322
8.33k
  pe->real_flags = internal_f->f_flags;
323
324
8.33k
  if ((internal_f->f_flags & F_DLL) != 0)
325
2.52k
    pe->dll = 1;
326
327
8.33k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
328
5.80k
    abfd->flags |= HAS_DEBUG;
329
330
8.33k
#ifdef COFF_IMAGE_WITH_PE
331
8.33k
  if (aouthdr)
332
6.10k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
333
8.33k
#endif
334
335
#ifdef ARM
336
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
337
    coff_data (abfd) ->flags = 0;
338
#endif
339
340
8.33k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
341
8.33k
    sizeof (pe->dos_message));
342
343
8.33k
  return (void *) pe;
344
8.33k
}
pei-sh.c:pe_mkobject_hook
Line
Count
Source
296
7.77k
{
297
7.77k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
298
7.77k
  pe_data_type *pe;
299
300
7.77k
  if (! pe_mkobject (abfd))
301
0
    return NULL;
302
303
7.77k
  pe = pe_data (abfd);
304
7.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
7.77k
  pe->coff.local_n_btmask = N_BTMASK;
309
7.77k
  pe->coff.local_n_btshft = N_BTSHFT;
310
7.77k
  pe->coff.local_n_tmask = N_TMASK;
311
7.77k
  pe->coff.local_n_tshift = N_TSHIFT;
312
7.77k
  pe->coff.local_symesz = SYMESZ;
313
7.77k
  pe->coff.local_auxesz = AUXESZ;
314
7.77k
  pe->coff.local_linesz = LINESZ;
315
316
7.77k
  pe->coff.timestamp = internal_f->f_timdat;
317
318
7.77k
  obj_raw_syment_count (abfd) =
319
7.77k
    obj_conv_table_size (abfd) =
320
7.77k
      internal_f->f_nsyms;
321
322
7.77k
  pe->real_flags = internal_f->f_flags;
323
324
7.77k
  if ((internal_f->f_flags & F_DLL) != 0)
325
1.05k
    pe->dll = 1;
326
327
7.77k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
328
6.92k
    abfd->flags |= HAS_DEBUG;
329
330
7.77k
#ifdef COFF_IMAGE_WITH_PE
331
7.77k
  if (aouthdr)
332
3.72k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
333
7.77k
#endif
334
335
#ifdef ARM
336
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
337
    coff_data (abfd) ->flags = 0;
338
#endif
339
340
7.77k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
341
7.77k
    sizeof (pe->dos_message));
342
343
7.77k
  return (void *) pe;
344
7.77k
}
345
346
static bool
347
pe_print_private_bfd_data (bfd *abfd, void * vfile)
348
0
{
349
0
  FILE *file = (FILE *) vfile;
350
351
0
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
352
0
    return false;
353
354
0
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
355
0
    return true;
356
357
0
  fputc ('\n', file);
358
359
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
360
0
}
Unexecuted instantiation: pei-i386.c:pe_print_private_bfd_data
Unexecuted instantiation: pe-x86_64.c:pe_print_private_bfd_data
Unexecuted instantiation: pei-x86_64.c:pe_print_private_bfd_data
Unexecuted instantiation: pe-aarch64.c:pe_print_private_bfd_data
Unexecuted instantiation: pei-aarch64.c:pe_print_private_bfd_data
Unexecuted instantiation: pei-ia64.c:pe_print_private_bfd_data
Unexecuted instantiation: pei-loongarch64.c:pe_print_private_bfd_data
Unexecuted instantiation: pe-arm-wince.c:pe_print_private_bfd_data
Unexecuted instantiation: pe-arm.c:pe_print_private_bfd_data
Unexecuted instantiation: pe-i386.c:pe_print_private_bfd_data
Unexecuted instantiation: pe-mcore.c:pe_print_private_bfd_data
Unexecuted instantiation: pe-sh.c:pe_print_private_bfd_data
Unexecuted instantiation: pei-arm-wince.c:pe_print_private_bfd_data
Unexecuted instantiation: pei-arm.c:pe_print_private_bfd_data
Unexecuted instantiation: pei-mcore.c:pe_print_private_bfd_data
Unexecuted instantiation: pei-sh.c:pe_print_private_bfd_data
361
362
/* Copy any private info we understand from the input bfd
363
   to the output bfd.  */
364
365
static bool
366
pe_bfd_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
367
0
{
368
  /* PR binutils/716: Copy the large address aware flag.
369
     XXX: Should we be copying other flags or other fields in the pe_data()
370
     structure ?  */
371
0
  if (pe_data (obfd) != NULL
372
0
      && pe_data (ibfd) != NULL
373
0
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
374
0
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
375
376
0
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
377
0
    return false;
378
379
0
  if (pe_saved_coff_bfd_copy_private_bfd_data)
380
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
381
382
0
  return true;
383
0
}
Unexecuted instantiation: pei-i386.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pe-x86_64.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pei-x86_64.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pe-aarch64.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pei-aarch64.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pei-ia64.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pei-loongarch64.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pe-arm-wince.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pe-arm.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pe-i386.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pe-mcore.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pe-sh.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pei-arm-wince.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pei-arm.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pei-mcore.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pei-sh.c:pe_bfd_copy_private_bfd_data
384
385
#define coff_bfd_copy_private_section_data \
386
  _bfd_XX_bfd_copy_private_section_data
387
388
#define coff_get_symbol_info _bfd_XX_get_symbol_info
389
390
#ifdef COFF_IMAGE_WITH_PE
391

392
/* Code to handle Microsoft's Import Library Format.
393
   Also known as LINK6 format.
394
   Documentation about this format can be found at:
395
396
   https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#import-library-format  */
397
398
/* The following constants specify the sizes of the various data
399
   structures that we have to create in order to build a bfd describing
400
   an ILF object file.  The final "+ 1" in the definitions of SIZEOF_IDATA6
401
   and SIZEOF_IDATA7 below is to allow for the possibility that we might
402
   need a padding byte in order to ensure 16 bit alignment for the section's
403
   contents.
404
405
   The value for SIZEOF_ILF_STRINGS is computed as follows:
406
407
      There will be NUM_ILF_SECTIONS section symbols.  Allow 9 characters
408
      per symbol for their names (longest section name is .idata$x).
409
410
      There will be two symbols for the imported value, one the symbol name
411
      and one with _imp__ prefixed.  Allowing for the terminating nul's this
412
      is strlen (symbol_name) * 2 + 8 + 21 + strlen (source_dll).
413
414
      The strings in the string table must start STRING__SIZE_SIZE bytes into
415
      the table in order to for the string lookup code in coffgen/coffcode to
416
      work.  */
417
25.0k
#define NUM_ILF_RELOCS    8
418
83.5k
#define NUM_ILF_SECTIONS  6
419
62.6k
#define NUM_ILF_SYMS    (2 + NUM_ILF_SECTIONS)
420
421
12.5k
#define SIZEOF_ILF_SYMS    (NUM_ILF_SYMS * sizeof (* vars.sym_cache))
422
12.5k
#define SIZEOF_ILF_SYM_TABLE   (NUM_ILF_SYMS * sizeof (* vars.sym_table))
423
12.5k
#define SIZEOF_ILF_NATIVE_SYMS   (NUM_ILF_SYMS * sizeof (* vars.native_syms))
424
12.5k
#define SIZEOF_ILF_SYM_PTR_TABLE (NUM_ILF_SYMS * sizeof (* vars.sym_ptr_table))
425
12.5k
#define SIZEOF_ILF_EXT_SYMS  (NUM_ILF_SYMS * sizeof (* vars.esym_table))
426
12.5k
#define SIZEOF_ILF_RELOCS  (NUM_ILF_RELOCS * sizeof (* vars.reltab))
427
12.5k
#define SIZEOF_ILF_INT_RELOCS  (NUM_ILF_RELOCS * sizeof (* vars.int_reltab))
428
12.5k
#define SIZEOF_ILF_STRINGS   (strlen (symbol_name) * 2 + 8 \
429
12.5k
          + 21 + strlen (source_dll) \
430
12.5k
          + NUM_ILF_SECTIONS * 9 \
431
12.5k
          + STRING_SIZE_SIZE)
432
8.35k
#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
4.98k
#define SIZEOF_IDATA4   (2 * 4)
437
4.98k
#define SIZEOF_IDATA5   (2 * 4)
438
#else
439
7.54k
#define SIZEOF_IDATA4   (1 * 4)
440
7.54k
#define SIZEOF_IDATA5   (1 * 4)
441
#endif
442
443
10.9k
#define SIZEOF_IDATA6   (2 + strlen (symbol_name) + 1 + 1)
444
8.35k
#define SIZEOF_IDATA7   (strlen (source_dll) + 1 + 1)
445
8.35k
#define SIZEOF_ILF_SECTIONS (NUM_ILF_SECTIONS * sizeof (struct coff_section_tdata))
446
447
#define ILF_DATA_SIZE       \
448
8.35k
    + SIZEOF_ILF_SYMS        \
449
8.35k
    + SIZEOF_ILF_SYM_TABLE      \
450
8.35k
    + SIZEOF_ILF_NATIVE_SYMS      \
451
8.35k
    + SIZEOF_ILF_SYM_PTR_TABLE      \
452
8.35k
    + SIZEOF_ILF_EXT_SYMS      \
453
8.35k
    + SIZEOF_ILF_RELOCS        \
454
8.35k
    + SIZEOF_ILF_INT_RELOCS      \
455
8.35k
    + SIZEOF_ILF_STRINGS      \
456
8.35k
    + SIZEOF_IDATA2        \
457
8.35k
    + SIZEOF_IDATA4        \
458
8.35k
    + SIZEOF_IDATA5        \
459
8.35k
    + SIZEOF_IDATA6        \
460
8.35k
    + SIZEOF_IDATA7        \
461
8.35k
    + SIZEOF_ILF_SECTIONS      \
462
8.35k
    + 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
7.59k
{
473
7.59k
  arelent * entry;
474
7.59k
  struct internal_reloc * internal;
475
476
7.59k
  entry = vars->reltab + vars->relcount;
477
7.59k
  internal = vars->int_reltab + vars->relcount;
478
479
7.59k
  entry->address     = address;
480
7.59k
  entry->addend      = 0;
481
7.59k
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
482
7.59k
  entry->sym_ptr_ptr = sym;
483
484
7.59k
  internal->r_vaddr  = address;
485
7.59k
  internal->r_symndx = sym_index;
486
7.59k
  internal->r_type   = entry->howto ? entry->howto->type : 0;
487
488
7.59k
  vars->relcount ++;
489
490
7.59k
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
491
7.59k
}
pei-i386.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
472
449
{
473
449
  arelent * entry;
474
449
  struct internal_reloc * internal;
475
476
449
  entry = vars->reltab + vars->relcount;
477
449
  internal = vars->int_reltab + vars->relcount;
478
479
449
  entry->address     = address;
480
449
  entry->addend      = 0;
481
449
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
482
449
  entry->sym_ptr_ptr = sym;
483
484
449
  internal->r_vaddr  = address;
485
449
  internal->r_symndx = sym_index;
486
449
  internal->r_type   = entry->howto ? entry->howto->type : 0;
487
488
449
  vars->relcount ++;
489
490
449
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
491
449
}
pei-x86_64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
472
1.72k
{
473
1.72k
  arelent * entry;
474
1.72k
  struct internal_reloc * internal;
475
476
1.72k
  entry = vars->reltab + vars->relcount;
477
1.72k
  internal = vars->int_reltab + vars->relcount;
478
479
1.72k
  entry->address     = address;
480
1.72k
  entry->addend      = 0;
481
1.72k
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
482
1.72k
  entry->sym_ptr_ptr = sym;
483
484
1.72k
  internal->r_vaddr  = address;
485
1.72k
  internal->r_symndx = sym_index;
486
1.72k
  internal->r_type   = entry->howto ? entry->howto->type : 0;
487
488
1.72k
  vars->relcount ++;
489
490
1.72k
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
491
1.72k
}
pei-aarch64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
472
1.01k
{
473
1.01k
  arelent * entry;
474
1.01k
  struct internal_reloc * internal;
475
476
1.01k
  entry = vars->reltab + vars->relcount;
477
1.01k
  internal = vars->int_reltab + vars->relcount;
478
479
1.01k
  entry->address     = address;
480
1.01k
  entry->addend      = 0;
481
1.01k
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
482
1.01k
  entry->sym_ptr_ptr = sym;
483
484
1.01k
  internal->r_vaddr  = address;
485
1.01k
  internal->r_symndx = sym_index;
486
1.01k
  internal->r_type   = entry->howto ? entry->howto->type : 0;
487
488
1.01k
  vars->relcount ++;
489
490
1.01k
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
491
1.01k
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_symbol_reloc
pei-loongarch64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
472
487
{
473
487
  arelent * entry;
474
487
  struct internal_reloc * internal;
475
476
487
  entry = vars->reltab + vars->relcount;
477
487
  internal = vars->int_reltab + vars->relcount;
478
479
487
  entry->address     = address;
480
487
  entry->addend      = 0;
481
487
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
482
487
  entry->sym_ptr_ptr = sym;
483
484
487
  internal->r_vaddr  = address;
485
487
  internal->r_symndx = sym_index;
486
487
  internal->r_type   = entry->howto ? entry->howto->type : 0;
487
488
487
  vars->relcount ++;
489
490
487
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
491
487
}
pei-arm-wince.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
472
17
{
473
17
  arelent * entry;
474
17
  struct internal_reloc * internal;
475
476
17
  entry = vars->reltab + vars->relcount;
477
17
  internal = vars->int_reltab + vars->relcount;
478
479
17
  entry->address     = address;
480
17
  entry->addend      = 0;
481
17
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
482
17
  entry->sym_ptr_ptr = sym;
483
484
17
  internal->r_vaddr  = address;
485
17
  internal->r_symndx = sym_index;
486
17
  internal->r_type   = entry->howto ? entry->howto->type : 0;
487
488
17
  vars->relcount ++;
489
490
17
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
491
17
}
pei-arm.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
472
1.54k
{
473
1.54k
  arelent * entry;
474
1.54k
  struct internal_reloc * internal;
475
476
1.54k
  entry = vars->reltab + vars->relcount;
477
1.54k
  internal = vars->int_reltab + vars->relcount;
478
479
1.54k
  entry->address     = address;
480
1.54k
  entry->addend      = 0;
481
1.54k
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
482
1.54k
  entry->sym_ptr_ptr = sym;
483
484
1.54k
  internal->r_vaddr  = address;
485
1.54k
  internal->r_symndx = sym_index;
486
1.54k
  internal->r_type   = entry->howto ? entry->howto->type : 0;
487
488
1.54k
  vars->relcount ++;
489
490
1.54k
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
491
1.54k
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_symbol_reloc
pei-sh.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
472
2.35k
{
473
2.35k
  arelent * entry;
474
2.35k
  struct internal_reloc * internal;
475
476
2.35k
  entry = vars->reltab + vars->relcount;
477
2.35k
  internal = vars->int_reltab + vars->relcount;
478
479
2.35k
  entry->address     = address;
480
2.35k
  entry->addend      = 0;
481
2.35k
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
482
2.35k
  entry->sym_ptr_ptr = sym;
483
484
2.35k
  internal->r_vaddr  = address;
485
2.35k
  internal->r_symndx = sym_index;
486
2.35k
  internal->r_type   = entry->howto ? entry->howto->type : 0;
487
488
2.35k
  vars->relcount ++;
489
490
2.35k
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
491
2.35k
}
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
5.23k
{
501
5.23k
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, sec->symbol_ptr_ptr,
502
5.23k
            coff_section_data (vars->abfd, sec)->i);
503
5.23k
}
pei-i386.c:pe_ILF_make_a_reloc
Line
Count
Source
500
210
{
501
210
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, sec->symbol_ptr_ptr,
502
210
            coff_section_data (vars->abfd, sec)->i);
503
210
}
pei-x86_64.c:pe_ILF_make_a_reloc
Line
Count
Source
500
1.15k
{
501
1.15k
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, sec->symbol_ptr_ptr,
502
1.15k
            coff_section_data (vars->abfd, sec)->i);
503
1.15k
}
pei-aarch64.c:pe_ILF_make_a_reloc
Line
Count
Source
500
1.01k
{
501
1.01k
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, sec->symbol_ptr_ptr,
502
1.01k
            coff_section_data (vars->abfd, sec)->i);
503
1.01k
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_reloc
pei-loongarch64.c:pe_ILF_make_a_reloc
Line
Count
Source
500
482
{
501
482
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, sec->symbol_ptr_ptr,
502
482
            coff_section_data (vars->abfd, sec)->i);
503
482
}
pei-arm-wince.c:pe_ILF_make_a_reloc
Line
Count
Source
500
8
{
501
8
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, sec->symbol_ptr_ptr,
502
8
            coff_section_data (vars->abfd, sec)->i);
503
8
}
pei-arm.c:pe_ILF_make_a_reloc
Line
Count
Source
500
958
{
501
958
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, sec->symbol_ptr_ptr,
502
958
            coff_section_data (vars->abfd, sec)->i);
503
958
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_reloc
pei-sh.c:pe_ILF_make_a_reloc
Line
Count
Source
500
1.41k
{
501
1.41k
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, sec->symbol_ptr_ptr,
502
1.41k
            coff_section_data (vars->abfd, sec)->i);
503
1.41k
}
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
7.59k
{
511
  /* Make sure that there is somewhere to store the internal relocs.  */
512
7.59k
  if (coff_section_data (vars->abfd, sec) == NULL)
513
    /* We should probably return an error indication here.  */
514
0
    abort ();
515
516
7.59k
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
517
518
7.59k
  sec->relocation  = vars->reltab;
519
7.59k
  sec->reloc_count = vars->relcount;
520
7.59k
  sec->flags      |= SEC_RELOC;
521
522
7.59k
  vars->reltab     += vars->relcount;
523
7.59k
  vars->int_reltab += vars->relcount;
524
7.59k
  vars->relcount   = 0;
525
526
7.59k
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
527
7.59k
}
pei-i386.c:pe_ILF_save_relocs
Line
Count
Source
510
449
{
511
  /* Make sure that there is somewhere to store the internal relocs.  */
512
449
  if (coff_section_data (vars->abfd, sec) == NULL)
513
    /* We should probably return an error indication here.  */
514
0
    abort ();
515
516
449
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
517
518
449
  sec->relocation  = vars->reltab;
519
449
  sec->reloc_count = vars->relcount;
520
449
  sec->flags      |= SEC_RELOC;
521
522
449
  vars->reltab     += vars->relcount;
523
449
  vars->int_reltab += vars->relcount;
524
449
  vars->relcount   = 0;
525
526
449
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
527
449
}
pei-x86_64.c:pe_ILF_save_relocs
Line
Count
Source
510
1.72k
{
511
  /* Make sure that there is somewhere to store the internal relocs.  */
512
1.72k
  if (coff_section_data (vars->abfd, sec) == NULL)
513
    /* We should probably return an error indication here.  */
514
0
    abort ();
515
516
1.72k
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
517
518
1.72k
  sec->relocation  = vars->reltab;
519
1.72k
  sec->reloc_count = vars->relcount;
520
1.72k
  sec->flags      |= SEC_RELOC;
521
522
1.72k
  vars->reltab     += vars->relcount;
523
1.72k
  vars->int_reltab += vars->relcount;
524
1.72k
  vars->relcount   = 0;
525
526
1.72k
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
527
1.72k
}
pei-aarch64.c:pe_ILF_save_relocs
Line
Count
Source
510
1.01k
{
511
  /* Make sure that there is somewhere to store the internal relocs.  */
512
1.01k
  if (coff_section_data (vars->abfd, sec) == NULL)
513
    /* We should probably return an error indication here.  */
514
0
    abort ();
515
516
1.01k
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
517
518
1.01k
  sec->relocation  = vars->reltab;
519
1.01k
  sec->reloc_count = vars->relcount;
520
1.01k
  sec->flags      |= SEC_RELOC;
521
522
1.01k
  vars->reltab     += vars->relcount;
523
1.01k
  vars->int_reltab += vars->relcount;
524
1.01k
  vars->relcount   = 0;
525
526
1.01k
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
527
1.01k
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_save_relocs
pei-loongarch64.c:pe_ILF_save_relocs
Line
Count
Source
510
487
{
511
  /* Make sure that there is somewhere to store the internal relocs.  */
512
487
  if (coff_section_data (vars->abfd, sec) == NULL)
513
    /* We should probably return an error indication here.  */
514
0
    abort ();
515
516
487
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
517
518
487
  sec->relocation  = vars->reltab;
519
487
  sec->reloc_count = vars->relcount;
520
487
  sec->flags      |= SEC_RELOC;
521
522
487
  vars->reltab     += vars->relcount;
523
487
  vars->int_reltab += vars->relcount;
524
487
  vars->relcount   = 0;
525
526
487
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
527
487
}
pei-arm-wince.c:pe_ILF_save_relocs
Line
Count
Source
510
17
{
511
  /* Make sure that there is somewhere to store the internal relocs.  */
512
17
  if (coff_section_data (vars->abfd, sec) == NULL)
513
    /* We should probably return an error indication here.  */
514
0
    abort ();
515
516
17
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
517
518
17
  sec->relocation  = vars->reltab;
519
17
  sec->reloc_count = vars->relcount;
520
17
  sec->flags      |= SEC_RELOC;
521
522
17
  vars->reltab     += vars->relcount;
523
17
  vars->int_reltab += vars->relcount;
524
17
  vars->relcount   = 0;
525
526
17
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
527
17
}
pei-arm.c:pe_ILF_save_relocs
Line
Count
Source
510
1.54k
{
511
  /* Make sure that there is somewhere to store the internal relocs.  */
512
1.54k
  if (coff_section_data (vars->abfd, sec) == NULL)
513
    /* We should probably return an error indication here.  */
514
0
    abort ();
515
516
1.54k
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
517
518
1.54k
  sec->relocation  = vars->reltab;
519
1.54k
  sec->reloc_count = vars->relcount;
520
1.54k
  sec->flags      |= SEC_RELOC;
521
522
1.54k
  vars->reltab     += vars->relcount;
523
1.54k
  vars->int_reltab += vars->relcount;
524
1.54k
  vars->relcount   = 0;
525
526
1.54k
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
527
1.54k
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_save_relocs
pei-sh.c:pe_ILF_save_relocs
Line
Count
Source
510
2.35k
{
511
  /* Make sure that there is somewhere to store the internal relocs.  */
512
2.35k
  if (coff_section_data (vars->abfd, sec) == NULL)
513
    /* We should probably return an error indication here.  */
514
0
    abort ();
515
516
2.35k
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
517
518
2.35k
  sec->relocation  = vars->reltab;
519
2.35k
  sec->reloc_count = vars->relcount;
520
2.35k
  sec->flags      |= SEC_RELOC;
521
522
2.35k
  vars->reltab     += vars->relcount;
523
2.35k
  vars->int_reltab += vars->relcount;
524
2.35k
  vars->relcount   = 0;
525
526
2.35k
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
527
2.35k
}
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
23.6k
{
538
23.6k
  coff_symbol_type * sym;
539
23.6k
  combined_entry_type * ent;
540
23.6k
  SYMENT * esym;
541
23.6k
  unsigned short sclass;
542
543
23.6k
  if (extra_flags & BSF_LOCAL)
544
13.3k
    sclass = C_STAT;
545
10.2k
  else
546
10.2k
    sclass = C_EXT;
547
548
#ifdef THUMBPEMAGIC
549
5.04k
  if (vars->magic == THUMBPEMAGIC)
550
1.28k
    {
551
1.28k
      if (extra_flags & BSF_FUNCTION)
552
12
  sclass = C_THUMBEXTFUNC;
553
1.27k
      else if (extra_flags & BSF_LOCAL)
554
771
  sclass = C_THUMBSTAT;
555
506
      else
556
506
  sclass = C_THUMBEXT;
557
1.28k
    }
558
#endif
559
560
23.6k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
561
562
23.6k
  sym = vars->sym_ptr;
563
23.6k
  ent = vars->native_ptr;
564
23.6k
  esym = vars->esym_ptr;
565
566
  /* Copy the symbol's name into the string table.  */
567
23.6k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
568
569
23.6k
  if (section == NULL)
570
3.95k
    section = bfd_und_section_ptr;
571
572
  /* Initialise the external symbol.  */
573
23.6k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
574
23.6k
      esym->e.e.e_offset);
575
23.6k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
576
23.6k
  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
23.6k
  ent->u.syment.n_sclass    = sclass;
583
23.6k
  ent->u.syment.n_scnum     = section->target_index;
584
23.6k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
585
23.6k
  ent->is_sym = true;
586
587
23.6k
  sym->symbol.the_bfd = vars->abfd;
588
23.6k
  sym->symbol.name    = vars->string_ptr;
589
23.6k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
590
23.6k
  sym->symbol.section = section;
591
23.6k
  sym->native       = ent;
592
593
23.6k
  * vars->table_ptr = vars->sym_index;
594
23.6k
  * vars->sym_ptr_ptr = sym;
595
596
  /* Adjust pointers for the next symbol.  */
597
23.6k
  vars->sym_index ++;
598
23.6k
  vars->sym_ptr ++;
599
23.6k
  vars->sym_ptr_ptr ++;
600
23.6k
  vars->table_ptr ++;
601
23.6k
  vars->native_ptr ++;
602
23.6k
  vars->esym_ptr ++;
603
23.6k
  vars->string_ptr += len + 1;
604
605
23.6k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
606
23.6k
}
pei-i386.c:pe_ILF_make_a_symbol
Line
Count
Source
537
1.75k
{
538
1.75k
  coff_symbol_type * sym;
539
1.75k
  combined_entry_type * ent;
540
1.75k
  SYMENT * esym;
541
1.75k
  unsigned short sclass;
542
543
1.75k
  if (extra_flags & BSF_LOCAL)
544
1.03k
    sclass = C_STAT;
545
721
  else
546
721
    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
1.75k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
561
562
1.75k
  sym = vars->sym_ptr;
563
1.75k
  ent = vars->native_ptr;
564
1.75k
  esym = vars->esym_ptr;
565
566
  /* Copy the symbol's name into the string table.  */
567
1.75k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
568
569
1.75k
  if (section == NULL)
570
241
    section = bfd_und_section_ptr;
571
572
  /* Initialise the external symbol.  */
573
1.75k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
574
1.75k
      esym->e.e.e_offset);
575
1.75k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
576
1.75k
  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
1.75k
  ent->u.syment.n_sclass    = sclass;
583
1.75k
  ent->u.syment.n_scnum     = section->target_index;
584
1.75k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
585
1.75k
  ent->is_sym = true;
586
587
1.75k
  sym->symbol.the_bfd = vars->abfd;
588
1.75k
  sym->symbol.name    = vars->string_ptr;
589
1.75k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
590
1.75k
  sym->symbol.section = section;
591
1.75k
  sym->native       = ent;
592
593
1.75k
  * vars->table_ptr = vars->sym_index;
594
1.75k
  * vars->sym_ptr_ptr = sym;
595
596
  /* Adjust pointers for the next symbol.  */
597
1.75k
  vars->sym_index ++;
598
1.75k
  vars->sym_ptr ++;
599
1.75k
  vars->sym_ptr_ptr ++;
600
1.75k
  vars->table_ptr ++;
601
1.75k
  vars->native_ptr ++;
602
1.75k
  vars->esym_ptr ++;
603
1.75k
  vars->string_ptr += len + 1;
604
605
1.75k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
606
1.75k
}
pei-x86_64.c:pe_ILF_make_a_symbol
Line
Count
Source
537
6.13k
{
538
6.13k
  coff_symbol_type * sym;
539
6.13k
  combined_entry_type * ent;
540
6.13k
  SYMENT * esym;
541
6.13k
  unsigned short sclass;
542
543
6.13k
  if (extra_flags & BSF_LOCAL)
544
3.45k
    sclass = C_STAT;
545
2.67k
  else
546
2.67k
    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
6.13k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
561
562
6.13k
  sym = vars->sym_ptr;
563
6.13k
  ent = vars->native_ptr;
564
6.13k
  esym = vars->esym_ptr;
565
566
  /* Copy the symbol's name into the string table.  */
567
6.13k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
568
569
6.13k
  if (section == NULL)
570
1.04k
    section = bfd_und_section_ptr;
571
572
  /* Initialise the external symbol.  */
573
6.13k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
574
6.13k
      esym->e.e.e_offset);
575
6.13k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
576
6.13k
  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
6.13k
  ent->u.syment.n_sclass    = sclass;
583
6.13k
  ent->u.syment.n_scnum     = section->target_index;
584
6.13k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
585
6.13k
  ent->is_sym = true;
586
587
6.13k
  sym->symbol.the_bfd = vars->abfd;
588
6.13k
  sym->symbol.name    = vars->string_ptr;
589
6.13k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
590
6.13k
  sym->symbol.section = section;
591
6.13k
  sym->native       = ent;
592
593
6.13k
  * vars->table_ptr = vars->sym_index;
594
6.13k
  * vars->sym_ptr_ptr = sym;
595
596
  /* Adjust pointers for the next symbol.  */
597
6.13k
  vars->sym_index ++;
598
6.13k
  vars->sym_ptr ++;
599
6.13k
  vars->sym_ptr_ptr ++;
600
6.13k
  vars->table_ptr ++;
601
6.13k
  vars->native_ptr ++;
602
6.13k
  vars->esym_ptr ++;
603
6.13k
  vars->string_ptr += len + 1;
604
605
6.13k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
606
6.13k
}
pei-aarch64.c:pe_ILF_make_a_symbol
Line
Count
Source
537
2.55k
{
538
2.55k
  coff_symbol_type * sym;
539
2.55k
  combined_entry_type * ent;
540
2.55k
  SYMENT * esym;
541
2.55k
  unsigned short sclass;
542
543
2.55k
  if (extra_flags & BSF_LOCAL)
544
1.53k
    sclass = C_STAT;
545
1.02k
  else
546
1.02k
    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
2.55k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
561
562
2.55k
  sym = vars->sym_ptr;
563
2.55k
  ent = vars->native_ptr;
564
2.55k
  esym = vars->esym_ptr;
565
566
  /* Copy the symbol's name into the string table.  */
567
2.55k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
568
569
2.55k
  if (section == NULL)
570
509
    section = bfd_und_section_ptr;
571
572
  /* Initialise the external symbol.  */
573
2.55k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
574
2.55k
      esym->e.e.e_offset);
575
2.55k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
576
2.55k
  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
2.55k
  ent->u.syment.n_sclass    = sclass;
583
2.55k
  ent->u.syment.n_scnum     = section->target_index;
584
2.55k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
585
2.55k
  ent->is_sym = true;
586
587
2.55k
  sym->symbol.the_bfd = vars->abfd;
588
2.55k
  sym->symbol.name    = vars->string_ptr;
589
2.55k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
590
2.55k
  sym->symbol.section = section;
591
2.55k
  sym->native       = ent;
592
593
2.55k
  * vars->table_ptr = vars->sym_index;
594
2.55k
  * vars->sym_ptr_ptr = sym;
595
596
  /* Adjust pointers for the next symbol.  */
597
2.55k
  vars->sym_index ++;
598
2.55k
  vars->sym_ptr ++;
599
2.55k
  vars->sym_ptr_ptr ++;
600
2.55k
  vars->table_ptr ++;
601
2.55k
  vars->native_ptr ++;
602
2.55k
  vars->esym_ptr ++;
603
2.55k
  vars->string_ptr += len + 1;
604
605
2.55k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
606
2.55k
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_symbol
pei-loongarch64.c:pe_ILF_make_a_symbol
Line
Count
Source
537
1.76k
{
538
1.76k
  coff_symbol_type * sym;
539
1.76k
  combined_entry_type * ent;
540
1.76k
  SYMENT * esym;
541
1.76k
  unsigned short sclass;
542
543
1.76k
  if (extra_flags & BSF_LOCAL)
544
1.00k
    sclass = C_STAT;
545
759
  else
546
759
    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
1.76k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
561
562
1.76k
  sym = vars->sym_ptr;
563
1.76k
  ent = vars->native_ptr;
564
1.76k
  esym = vars->esym_ptr;
565
566
  /* Copy the symbol's name into the string table.  */
567
1.76k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
568
569
1.76k
  if (section == NULL)
570
377
    section = bfd_und_section_ptr;
571
572
  /* Initialise the external symbol.  */
573
1.76k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
574
1.76k
      esym->e.e.e_offset);
575
1.76k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
576
1.76k
  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
1.76k
  ent->u.syment.n_sclass    = sclass;
583
1.76k
  ent->u.syment.n_scnum     = section->target_index;
584
1.76k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
585
1.76k
  ent->is_sym = true;
586
587
1.76k
  sym->symbol.the_bfd = vars->abfd;
588
1.76k
  sym->symbol.name    = vars->string_ptr;
589
1.76k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
590
1.76k
  sym->symbol.section = section;
591
1.76k
  sym->native       = ent;
592
593
1.76k
  * vars->table_ptr = vars->sym_index;
594
1.76k
  * vars->sym_ptr_ptr = sym;
595
596
  /* Adjust pointers for the next symbol.  */
597
1.76k
  vars->sym_index ++;
598
1.76k
  vars->sym_ptr ++;
599
1.76k
  vars->sym_ptr_ptr ++;
600
1.76k
  vars->table_ptr ++;
601
1.76k
  vars->native_ptr ++;
602
1.76k
  vars->esym_ptr ++;
603
1.76k
  vars->string_ptr += len + 1;
604
605
1.76k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
606
1.76k
}
pei-arm-wince.c:pe_ILF_make_a_symbol
Line
Count
Source
537
82
{
538
82
  coff_symbol_type * sym;
539
82
  combined_entry_type * ent;
540
82
  SYMENT * esym;
541
82
  unsigned short sclass;
542
543
82
  if (extra_flags & BSF_LOCAL)
544
47
    sclass = C_STAT;
545
35
  else
546
35
    sclass = C_EXT;
547
548
82
#ifdef THUMBPEMAGIC
549
82
  if (vars->magic == THUMBPEMAGIC)
550
52
    {
551
52
      if (extra_flags & BSF_FUNCTION)
552
6
  sclass = C_THUMBEXTFUNC;
553
46
      else if (extra_flags & BSF_LOCAL)
554
30
  sclass = C_THUMBSTAT;
555
16
      else
556
16
  sclass = C_THUMBEXT;
557
52
    }
558
82
#endif
559
560
82
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
561
562
82
  sym = vars->sym_ptr;
563
82
  ent = vars->native_ptr;
564
82
  esym = vars->esym_ptr;
565
566
  /* Copy the symbol's name into the string table.  */
567
82
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
568
569
82
  if (section == NULL)
570
13
    section = bfd_und_section_ptr;
571
572
  /* Initialise the external symbol.  */
573
82
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
574
82
      esym->e.e.e_offset);
575
82
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
576
82
  esym->e_sclass[0] = sclass;
577
578
  /* The following initialisations are unnecessary - the memory is
579
     zero initialised.  They are just kept here as reminders.  */
580
581
  /* Initialise the internal symbol structure.  */
582
82
  ent->u.syment.n_sclass    = sclass;
583
82
  ent->u.syment.n_scnum     = section->target_index;
584
82
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
585
82
  ent->is_sym = true;
586
587
82
  sym->symbol.the_bfd = vars->abfd;
588
82
  sym->symbol.name    = vars->string_ptr;
589
82
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
590
82
  sym->symbol.section = section;
591
82
  sym->native       = ent;
592
593
82
  * vars->table_ptr = vars->sym_index;
594
82
  * vars->sym_ptr_ptr = sym;
595
596
  /* Adjust pointers for the next symbol.  */
597
82
  vars->sym_index ++;
598
82
  vars->sym_ptr ++;
599
82
  vars->sym_ptr_ptr ++;
600
82
  vars->table_ptr ++;
601
82
  vars->native_ptr ++;
602
82
  vars->esym_ptr ++;
603
82
  vars->string_ptr += len + 1;
604
605
82
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
606
82
}
pei-arm.c:pe_ILF_make_a_symbol
Line
Count
Source
537
4.96k
{
538
4.96k
  coff_symbol_type * sym;
539
4.96k
  combined_entry_type * ent;
540
4.96k
  SYMENT * esym;
541
4.96k
  unsigned short sclass;
542
543
4.96k
  if (extra_flags & BSF_LOCAL)
544
2.72k
    sclass = C_STAT;
545
2.23k
  else
546
2.23k
    sclass = C_EXT;
547
548
4.96k
#ifdef THUMBPEMAGIC
549
4.96k
  if (vars->magic == THUMBPEMAGIC)
550
1.23k
    {
551
1.23k
      if (extra_flags & BSF_FUNCTION)
552
6
  sclass = C_THUMBEXTFUNC;
553
1.23k
      else if (extra_flags & BSF_LOCAL)
554
741
  sclass = C_THUMBSTAT;
555
490
      else
556
490
  sclass = C_THUMBEXT;
557
1.23k
    }
558
4.96k
#endif
559
560
4.96k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
561
562
4.96k
  sym = vars->sym_ptr;
563
4.96k
  ent = vars->native_ptr;
564
4.96k
  esym = vars->esym_ptr;
565
566
  /* Copy the symbol's name into the string table.  */
567
4.96k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
568
569
4.96k
  if (section == NULL)
570
826
    section = bfd_und_section_ptr;
571
572
  /* Initialise the external symbol.  */
573
4.96k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
574
4.96k
      esym->e.e.e_offset);
575
4.96k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
576
4.96k
  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
4.96k
  ent->u.syment.n_sclass    = sclass;
583
4.96k
  ent->u.syment.n_scnum     = section->target_index;
584
4.96k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
585
4.96k
  ent->is_sym = true;
586
587
4.96k
  sym->symbol.the_bfd = vars->abfd;
588
4.96k
  sym->symbol.name    = vars->string_ptr;
589
4.96k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
590
4.96k
  sym->symbol.section = section;
591
4.96k
  sym->native       = ent;
592
593
4.96k
  * vars->table_ptr = vars->sym_index;
594
4.96k
  * vars->sym_ptr_ptr = sym;
595
596
  /* Adjust pointers for the next symbol.  */
597
4.96k
  vars->sym_index ++;
598
4.96k
  vars->sym_ptr ++;
599
4.96k
  vars->sym_ptr_ptr ++;
600
4.96k
  vars->table_ptr ++;
601
4.96k
  vars->native_ptr ++;
602
4.96k
  vars->esym_ptr ++;
603
4.96k
  vars->string_ptr += len + 1;
604
605
4.96k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
606
4.96k
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_symbol
pei-sh.c:pe_ILF_make_a_symbol
Line
Count
Source
537
6.36k
{
538
6.36k
  coff_symbol_type * sym;
539
6.36k
  combined_entry_type * ent;
540
6.36k
  SYMENT * esym;
541
6.36k
  unsigned short sclass;
542
543
6.36k
  if (extra_flags & BSF_LOCAL)
544
3.53k
    sclass = C_STAT;
545
2.82k
  else
546
2.82k
    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
6.36k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
561
562
6.36k
  sym = vars->sym_ptr;
563
6.36k
  ent = vars->native_ptr;
564
6.36k
  esym = vars->esym_ptr;
565
566
  /* Copy the symbol's name into the string table.  */
567
6.36k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
568
569
6.36k
  if (section == NULL)
570
943
    section = bfd_und_section_ptr;
571
572
  /* Initialise the external symbol.  */
573
6.36k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
574
6.36k
      esym->e.e.e_offset);
575
6.36k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
576
6.36k
  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
6.36k
  ent->u.syment.n_sclass    = sclass;
583
6.36k
  ent->u.syment.n_scnum     = section->target_index;
584
6.36k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
585
6.36k
  ent->is_sym = true;
586
587
6.36k
  sym->symbol.the_bfd = vars->abfd;
588
6.36k
  sym->symbol.name    = vars->string_ptr;
589
6.36k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
590
6.36k
  sym->symbol.section = section;
591
6.36k
  sym->native       = ent;
592
593
6.36k
  * vars->table_ptr = vars->sym_index;
594
6.36k
  * vars->sym_ptr_ptr = sym;
595
596
  /* Adjust pointers for the next symbol.  */
597
6.36k
  vars->sym_index ++;
598
6.36k
  vars->sym_ptr ++;
599
6.36k
  vars->sym_ptr_ptr ++;
600
6.36k
  vars->table_ptr ++;
601
6.36k
  vars->native_ptr ++;
602
6.36k
  vars->esym_ptr ++;
603
6.36k
  vars->string_ptr += len + 1;
604
605
6.36k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
606
6.36k
}
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
13.3k
{
616
13.3k
  asection_ptr sec;
617
13.3k
  flagword     flags;
618
13.3k
  intptr_t alignment;
619
620
13.3k
  sec = bfd_make_section_old_way (vars->abfd, name);
621
13.3k
  if (sec == NULL)
622
0
    return NULL;
623
624
13.3k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
625
626
13.3k
  bfd_set_section_flags (sec, flags | extra_flags);
627
628
13.3k
  bfd_set_section_alignment (sec, 2);
629
630
  /* Check that we will not run out of space.  */
631
13.3k
  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
13.3k
  bfd_set_section_size (sec, (bfd_size_type) size);
636
13.3k
  sec->contents = vars->data;
637
13.3k
  sec->target_index = vars->sec_index ++;
638
639
  /* Advance data pointer in the vars structure.  */
640
13.3k
  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
13.3k
  if (size & 1)
647
1.53k
    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
13.3k
#if GCC_VERSION >= 3000
654
13.3k
  alignment = __alignof__ (struct coff_section_tdata);
655
#else
656
  alignment = 8;
657
#endif
658
13.3k
  vars->data
659
13.3k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
660
661
  /* Create a coff_section_tdata structure for our use.  */
662
13.3k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
663
13.3k
  vars->data += sizeof (struct coff_section_tdata);
664
665
13.3k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
666
667
  /* Create a symbol to refer to this section.  */
668
13.3k
  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
13.3k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
672
673
13.3k
  return sec;
674
13.3k
}
pei-i386.c:pe_ILF_make_a_section
Line
Count
Source
615
1.03k
{
616
1.03k
  asection_ptr sec;
617
1.03k
  flagword     flags;
618
1.03k
  intptr_t alignment;
619
620
1.03k
  sec = bfd_make_section_old_way (vars->abfd, name);
621
1.03k
  if (sec == NULL)
622
0
    return NULL;
623
624
1.03k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
625
626
1.03k
  bfd_set_section_flags (sec, flags | extra_flags);
627
628
1.03k
  bfd_set_section_alignment (sec, 2);
629
630
  /* Check that we will not run out of space.  */
631
1.03k
  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
1.03k
  bfd_set_section_size (sec, (bfd_size_type) size);
636
1.03k
  sec->contents = vars->data;
637
1.03k
  sec->target_index = vars->sec_index ++;
638
639
  /* Advance data pointer in the vars structure.  */
640
1.03k
  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
1.03k
  if (size & 1)
647
102
    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
1.03k
#if GCC_VERSION >= 3000
654
1.03k
  alignment = __alignof__ (struct coff_section_tdata);
655
#else
656
  alignment = 8;
657
#endif
658
1.03k
  vars->data
659
1.03k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
660
661
  /* Create a coff_section_tdata structure for our use.  */
662
1.03k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
663
1.03k
  vars->data += sizeof (struct coff_section_tdata);
664
665
1.03k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
666
667
  /* Create a symbol to refer to this section.  */
668
1.03k
  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
1.03k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
672
673
1.03k
  return sec;
674
1.03k
}
pei-x86_64.c:pe_ILF_make_a_section
Line
Count
Source
615
3.45k
{
616
3.45k
  asection_ptr sec;
617
3.45k
  flagword     flags;
618
3.45k
  intptr_t alignment;
619
620
3.45k
  sec = bfd_make_section_old_way (vars->abfd, name);
621
3.45k
  if (sec == NULL)
622
0
    return NULL;
623
624
3.45k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
625
626
3.45k
  bfd_set_section_flags (sec, flags | extra_flags);
627
628
3.45k
  bfd_set_section_alignment (sec, 2);
629
630
  /* Check that we will not run out of space.  */
631
3.45k
  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
3.45k
  bfd_set_section_size (sec, (bfd_size_type) size);
636
3.45k
  sec->contents = vars->data;
637
3.45k
  sec->target_index = vars->sec_index ++;
638
639
  /* Advance data pointer in the vars structure.  */
640
3.45k
  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
3.45k
  if (size & 1)
647
104
    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
3.45k
#if GCC_VERSION >= 3000
654
3.45k
  alignment = __alignof__ (struct coff_section_tdata);
655
#else
656
  alignment = 8;
657
#endif
658
3.45k
  vars->data
659
3.45k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
660
661
  /* Create a coff_section_tdata structure for our use.  */
662
3.45k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
663
3.45k
  vars->data += sizeof (struct coff_section_tdata);
664
665
3.45k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
666
667
  /* Create a symbol to refer to this section.  */
668
3.45k
  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
3.45k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
672
673
3.45k
  return sec;
674
3.45k
}
pei-aarch64.c:pe_ILF_make_a_section
Line
Count
Source
615
1.53k
{
616
1.53k
  asection_ptr sec;
617
1.53k
  flagword     flags;
618
1.53k
  intptr_t alignment;
619
620
1.53k
  sec = bfd_make_section_old_way (vars->abfd, name);
621
1.53k
  if (sec == NULL)
622
0
    return NULL;
623
624
1.53k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
625
626
1.53k
  bfd_set_section_flags (sec, flags | extra_flags);
627
628
1.53k
  bfd_set_section_alignment (sec, 2);
629
630
  /* Check that we will not run out of space.  */
631
1.53k
  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
1.53k
  bfd_set_section_size (sec, (bfd_size_type) size);
636
1.53k
  sec->contents = vars->data;
637
1.53k
  sec->target_index = vars->sec_index ++;
638
639
  /* Advance data pointer in the vars structure.  */
640
1.53k
  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
1.53k
  if (size & 1)
647
505
    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
1.53k
#if GCC_VERSION >= 3000
654
1.53k
  alignment = __alignof__ (struct coff_section_tdata);
655
#else
656
  alignment = 8;
657
#endif
658
1.53k
  vars->data
659
1.53k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
660
661
  /* Create a coff_section_tdata structure for our use.  */
662
1.53k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
663
1.53k
  vars->data += sizeof (struct coff_section_tdata);
664
665
1.53k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
666
667
  /* Create a symbol to refer to this section.  */
668
1.53k
  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
1.53k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
672
673
1.53k
  return sec;
674
1.53k
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_section
pei-loongarch64.c:pe_ILF_make_a_section
Line
Count
Source
615
1.00k
{
616
1.00k
  asection_ptr sec;
617
1.00k
  flagword     flags;
618
1.00k
  intptr_t alignment;
619
620
1.00k
  sec = bfd_make_section_old_way (vars->abfd, name);
621
1.00k
  if (sec == NULL)
622
0
    return NULL;
623
624
1.00k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
625
626
1.00k
  bfd_set_section_flags (sec, flags | extra_flags);
627
628
1.00k
  bfd_set_section_alignment (sec, 2);
629
630
  /* Check that we will not run out of space.  */
631
1.00k
  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
1.00k
  bfd_set_section_size (sec, (bfd_size_type) size);
636
1.00k
  sec->contents = vars->data;
637
1.00k
  sec->target_index = vars->sec_index ++;
638
639
  /* Advance data pointer in the vars structure.  */
640
1.00k
  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
1.00k
  if (size & 1)
647
103
    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
1.00k
#if GCC_VERSION >= 3000
654
1.00k
  alignment = __alignof__ (struct coff_section_tdata);
655
#else
656
  alignment = 8;
657
#endif
658
1.00k
  vars->data
659
1.00k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
660
661
  /* Create a coff_section_tdata structure for our use.  */
662
1.00k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
663
1.00k
  vars->data += sizeof (struct coff_section_tdata);
664
665
1.00k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
666
667
  /* Create a symbol to refer to this section.  */
668
1.00k
  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
1.00k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
672
673
1.00k
  return sec;
674
1.00k
}
pei-arm-wince.c:pe_ILF_make_a_section
Line
Count
Source
615
47
{
616
47
  asection_ptr sec;
617
47
  flagword     flags;
618
47
  intptr_t alignment;
619
620
47
  sec = bfd_make_section_old_way (vars->abfd, name);
621
47
  if (sec == NULL)
622
0
    return NULL;
623
624
47
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
625
626
47
  bfd_set_section_flags (sec, flags | extra_flags);
627
628
47
  bfd_set_section_alignment (sec, 2);
629
630
  /* Check that we will not run out of space.  */
631
47
  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
47
  bfd_set_section_size (sec, (bfd_size_type) size);
636
47
  sec->contents = vars->data;
637
47
  sec->target_index = vars->sec_index ++;
638
639
  /* Advance data pointer in the vars structure.  */
640
47
  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
47
  if (size & 1)
647
3
    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
47
#if GCC_VERSION >= 3000
654
47
  alignment = __alignof__ (struct coff_section_tdata);
655
#else
656
  alignment = 8;
657
#endif
658
47
  vars->data
659
47
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
660
661
  /* Create a coff_section_tdata structure for our use.  */
662
47
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
663
47
  vars->data += sizeof (struct coff_section_tdata);
664
665
47
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
666
667
  /* Create a symbol to refer to this section.  */
668
47
  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
47
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
672
673
47
  return sec;
674
47
}
pei-arm.c:pe_ILF_make_a_section
Line
Count
Source
615
2.72k
{
616
2.72k
  asection_ptr sec;
617
2.72k
  flagword     flags;
618
2.72k
  intptr_t alignment;
619
620
2.72k
  sec = bfd_make_section_old_way (vars->abfd, name);
621
2.72k
  if (sec == NULL)
622
0
    return NULL;
623
624
2.72k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
625
626
2.72k
  bfd_set_section_flags (sec, flags | extra_flags);
627
628
2.72k
  bfd_set_section_alignment (sec, 2);
629
630
  /* Check that we will not run out of space.  */
631
2.72k
  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
2.72k
  bfd_set_section_size (sec, (bfd_size_type) size);
636
2.72k
  sec->contents = vars->data;
637
2.72k
  sec->target_index = vars->sec_index ++;
638
639
  /* Advance data pointer in the vars structure.  */
640
2.72k
  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
2.72k
  if (size & 1)
647
478
    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
2.72k
#if GCC_VERSION >= 3000
654
2.72k
  alignment = __alignof__ (struct coff_section_tdata);
655
#else
656
  alignment = 8;
657
#endif
658
2.72k
  vars->data
659
2.72k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
660
661
  /* Create a coff_section_tdata structure for our use.  */
662
2.72k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
663
2.72k
  vars->data += sizeof (struct coff_section_tdata);
664
665
2.72k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
666
667
  /* Create a symbol to refer to this section.  */
668
2.72k
  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
2.72k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
672
673
2.72k
  return sec;
674
2.72k
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_section
pei-sh.c:pe_ILF_make_a_section
Line
Count
Source
615
3.53k
{
616
3.53k
  asection_ptr sec;
617
3.53k
  flagword     flags;
618
3.53k
  intptr_t alignment;
619
620
3.53k
  sec = bfd_make_section_old_way (vars->abfd, name);
621
3.53k
  if (sec == NULL)
622
0
    return NULL;
623
624
3.53k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
625
626
3.53k
  bfd_set_section_flags (sec, flags | extra_flags);
627
628
3.53k
  bfd_set_section_alignment (sec, 2);
629
630
  /* Check that we will not run out of space.  */
631
3.53k
  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
3.53k
  bfd_set_section_size (sec, (bfd_size_type) size);
636
3.53k
  sec->contents = vars->data;
637
3.53k
  sec->target_index = vars->sec_index ++;
638
639
  /* Advance data pointer in the vars structure.  */
640
3.53k
  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
3.53k
  if (size & 1)
647
235
    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
3.53k
#if GCC_VERSION >= 3000
654
3.53k
  alignment = __alignof__ (struct coff_section_tdata);
655
#else
656
  alignment = 8;
657
#endif
658
3.53k
  vars->data
659
3.53k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
660
661
  /* Create a coff_section_tdata structure for our use.  */
662
3.53k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
663
3.53k
  vars->data += sizeof (struct coff_section_tdata);
664
665
3.53k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
666
667
  /* Create a symbol to refer to this section.  */
668
3.53k
  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
3.53k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
672
673
3.53k
  return sec;
674
3.53k
}
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
8.35k
#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
2.35k
#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
4.82k
{
787
4.82k
  bfd_byte *       ptr;
788
4.82k
  pe_ILF_vars      vars;
789
4.82k
  struct internal_filehdr  internal_f;
790
4.82k
  unsigned int       import_type;
791
4.82k
  unsigned int       import_name_type;
792
4.82k
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
793
4.82k
  coff_symbol_type **    imp_sym;
794
4.82k
  unsigned int       imp_index;
795
4.82k
  intptr_t alignment;
796
797
  /* Decode and verify the types field of the ILF structure.  */
798
4.82k
  import_type = types & 0x3;
799
4.82k
  import_name_type = (types & 0x1c) >> 2;
800
801
4.82k
  switch (import_type)
802
4.82k
    {
803
2.68k
    case IMPORT_CODE:
804
4.49k
    case IMPORT_DATA:
805
4.49k
      break;
806
807
116
    case IMPORT_CONST:
808
      /* XXX code yet to be written.  */
809
      /* xgettext:c-format */
810
116
      _bfd_error_handler (_("%pB: unhandled import type; %x"),
811
116
        abfd, import_type);
812
116
      return false;
813
814
213
    default:
815
      /* xgettext:c-format */
816
213
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
817
213
        abfd, import_type);
818
213
      return false;
819
4.82k
    }
820
821
4.49k
  switch (import_name_type)
822
4.49k
    {
823
1.56k
    case IMPORT_ORDINAL:
824
2.37k
    case IMPORT_NAME:
825
2.96k
    case IMPORT_NAME_NOPREFIX:
826
4.17k
    case IMPORT_NAME_UNDECORATE:
827
4.17k
      break;
828
829
320
    default:
830
      /* xgettext:c-format */
831
320
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
832
320
        abfd, import_name_type);
833
320
      return false;
834
4.49k
    }
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
4.17k
  vars.bim
844
4.17k
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
845
4.17k
  if (vars.bim == NULL)
846
0
    return false;
847
848
4.17k
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
849
4.17k
  vars.bim->buffer = ptr;
850
4.17k
  vars.bim->size   = ILF_DATA_SIZE;
851
4.17k
  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
4.17k
  vars.sym_cache = (coff_symbol_type *) ptr;
857
4.17k
  vars.sym_ptr   = (coff_symbol_type *) ptr;
858
4.17k
  vars.sym_index = 0;
859
4.17k
  ptr += SIZEOF_ILF_SYMS;
860
861
4.17k
  vars.sym_table = (unsigned int *) ptr;
862
4.17k
  vars.table_ptr = (unsigned int *) ptr;
863
4.17k
  ptr += SIZEOF_ILF_SYM_TABLE;
864
865
4.17k
  vars.native_syms = (combined_entry_type *) ptr;
866
4.17k
  vars.native_ptr  = (combined_entry_type *) ptr;
867
4.17k
  ptr += SIZEOF_ILF_NATIVE_SYMS;
868
869
4.17k
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
870
4.17k
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
871
4.17k
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
872
873
4.17k
  vars.esym_table = (SYMENT *) ptr;
874
4.17k
  vars.esym_ptr   = (SYMENT *) ptr;
875
4.17k
  ptr += SIZEOF_ILF_EXT_SYMS;
876
877
4.17k
  vars.reltab   = (arelent *) ptr;
878
4.17k
  vars.relcount = 0;
879
4.17k
  ptr += SIZEOF_ILF_RELOCS;
880
881
4.17k
  vars.int_reltab  = (struct internal_reloc *) ptr;
882
4.17k
  ptr += SIZEOF_ILF_INT_RELOCS;
883
884
4.17k
  vars.string_table = (char *) ptr;
885
4.17k
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
886
4.17k
  ptr += SIZEOF_ILF_STRINGS;
887
4.17k
  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
4.17k
#if GCC_VERSION >= 3000
897
4.17k
  alignment = __alignof__ (struct coff_section_tdata);
898
#else
899
  alignment = 8;
900
#endif
901
4.17k
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
902
903
4.17k
  vars.data = ptr;
904
4.17k
  vars.abfd = abfd;
905
4.17k
  vars.sec_index = 0;
906
4.17k
  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
4.17k
  id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
916
4.17k
  id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
917
4.17k
  if (id4 == NULL || id5 == NULL)
918
0
    goto error_return;
919
920
  /* Fill in the contents of these sections.  */
921
4.17k
  if (import_name_type == IMPORT_ORDINAL)
922
1.56k
    {
923
1.56k
      if (ordinal == 0)
924
  /* See PR 20907 for a reproducer.  */
925
221
  goto error_return;
926
927
#if defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) || defined(COFF_WITH_peLoongArch64)
928
612
      ((unsigned int *) id4->contents)[0] = ordinal;
929
612
      ((unsigned int *) id4->contents)[1] = 0x80000000;
930
612
      ((unsigned int *) id5->contents)[0] = ordinal;
931
612
      ((unsigned int *) id5->contents)[1] = 0x80000000;
932
#else
933
729
      * (unsigned int *) id4->contents = ordinal | 0x80000000;
934
729
      * (unsigned int *) id5->contents = ordinal | 0x80000000;
935
729
#endif
936
729
    }
937
2.61k
  else
938
2.61k
    {
939
2.61k
      char * symbol;
940
2.61k
      unsigned int len;
941
942
      /* Create .idata$6 - the Hint Name Table.  */
943
2.61k
      id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
944
2.61k
      if (id6 == NULL)
945
0
  goto error_return;
946
947
      /* If necessary, trim the import symbol name.  */
948
2.61k
      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.61k
      if (import_name_type != IMPORT_NAME)
958
1.80k
  {
959
1.80k
    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.80k
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
964
1.80k
        || c == '@' || c == '?')
965
137
      symbol++;
966
1.80k
  }
967
968
2.61k
      len = strlen (symbol);
969
2.61k
      if (import_name_type == IMPORT_NAME_UNDECORATE)
970
1.21k
  {
971
    /* Truncate at the first '@'.  */
972
1.21k
    char *at = strchr (symbol, '@');
973
974
1.21k
    if (at != NULL)
975
235
      len = at - symbol;
976
1.21k
  }
977
978
2.61k
      id6->contents[0] = ordinal & 0xff;
979
2.61k
      id6->contents[1] = ordinal >> 8;
980
981
2.61k
      memcpy ((char *) id6->contents + 2, symbol, len);
982
2.61k
      id6->contents[len + 2] = '\0';
983
2.61k
    }
984
985
3.95k
  if (import_name_type != IMPORT_ORDINAL)
986
2.61k
    {
987
2.61k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
988
2.61k
      pe_ILF_save_relocs (&vars, id4);
989
990
2.61k
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
991
2.61k
      pe_ILF_save_relocs (&vars, id5);
992
2.61k
    }
993
994
  /* Create an import symbol.  */
995
3.95k
  pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
996
3.95k
  imp_sym   = vars.sym_ptr_ptr - 1;
997
3.95k
  imp_index = vars.sym_index - 1;
998
999
  /* Create extra sections depending upon the type of import we are dealing with.  */
1000
3.95k
  switch (import_type)
1001
3.95k
    {
1002
0
      int i;
1003
1004
2.35k
    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
5.29k
      for (i = NUM_ENTRIES (jtab); i--;)
1009
5.29k
  {
1010
5.29k
    if (jtab[i].size == 0)
1011
2.35k
      continue;
1012
2.94k
    if (jtab[i].magic == magic)
1013
2.35k
      break;
1014
2.94k
  }
1015
      /* If we did not find a matching entry something is wrong.  */
1016
2.35k
      if (i < 0)
1017
0
  abort ();
1018
1019
      /* Create the .text section.  */
1020
2.35k
      text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
1021
2.35k
      if (text == NULL)
1022
0
  goto error_return;
1023
1024
      /* Copy in the jump code.  */
1025
2.35k
      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
575
      if (magic == AMD64MAGIC)
1043
575
  {
1044
575
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1045
575
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1046
575
              imp_index);
1047
575
  }
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
2.35k
      pe_ILF_save_relocs (& vars, text);
1055
2.35k
      break;
1056
1057
1.60k
    case IMPORT_DATA:
1058
1.60k
      break;
1059
1060
0
    default:
1061
      /* XXX code not yet written.  */
1062
0
      abort ();
1063
3.95k
    }
1064
1065
  /* Now create a symbol describing the imported value.  */
1066
3.95k
  switch (import_type)
1067
3.95k
    {
1068
2.35k
    case IMPORT_CODE:
1069
2.35k
      pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1070
2.35k
          BSF_NOT_AT_END | BSF_FUNCTION);
1071
1072
2.35k
      break;
1073
1074
1.60k
    case IMPORT_DATA:
1075
      /* Nothing to do here.  */
1076
1.60k
      break;
1077
1078
0
    default:
1079
      /* XXX code not yet written.  */
1080
0
      abort ();
1081
3.95k
    }
1082
1083
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1084
3.95k
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1085
3.95k
  if (ptr)
1086
480
    * ptr = 0;
1087
3.95k
  pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1088
3.95k
  if (ptr)
1089
480
    * ptr = '.';
1090
1091
  /* Initialise the bfd.  */
1092
3.95k
  memset (& internal_f, 0, sizeof (internal_f));
1093
1094
3.95k
  internal_f.f_magic  = magic;
1095
3.95k
  internal_f.f_symptr = 0;
1096
3.95k
  internal_f.f_nsyms  = 0;
1097
3.95k
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1098
1099
3.95k
  if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
1100
3.95k
      || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1101
0
    goto error_return;
1102
1103
3.95k
  if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL)
1104
0
    goto error_return;
1105
1106
3.95k
  obj_pe (abfd) = true;
1107
#ifdef THUMBPEMAGIC
1108
839
  if (vars.magic == THUMBPEMAGIC)
1109
    /* Stop some linker warnings about thumb code not supporting interworking.  */
1110
253
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1111
#endif
1112
1113
  /* Switch from file contents to memory contents.  */
1114
3.95k
  bfd_cache_close (abfd);
1115
1116
3.95k
  abfd->iostream = (void *) vars.bim;
1117
3.95k
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1118
3.95k
  abfd->iovec = &_bfd_memory_iovec;
1119
3.95k
  abfd->where = 0;
1120
3.95k
  abfd->origin = 0;
1121
3.95k
  abfd->size = 0;
1122
3.95k
  obj_sym_filepos (abfd) = 0;
1123
1124
  /* Point the bfd at the symbol table.  */
1125
3.95k
  obj_symbols (abfd) = vars.sym_cache;
1126
3.95k
  abfd->symcount = vars.sym_index;
1127
1128
3.95k
  obj_raw_syments (abfd) = vars.native_syms;
1129
3.95k
  obj_raw_syment_count (abfd) = vars.sym_index;
1130
1131
3.95k
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1132
3.95k
  obj_coff_keep_syms (abfd) = true;
1133
1134
3.95k
  obj_convert (abfd) = vars.sym_table;
1135
3.95k
  obj_conv_table_size (abfd) = vars.sym_index;
1136
1137
3.95k
  obj_coff_strings (abfd) = vars.string_table;
1138
3.95k
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1139
3.95k
  obj_coff_keep_strings (abfd) = true;
1140
1141
3.95k
  return true;
1142
1143
221
 error_return:
1144
221
  free (vars.bim->buffer);
1145
221
  free (vars.bim);
1146
221
  return false;
1147
3.95k
}
pei-i386.c:pe_ILF_build_a_bfd
Line
Count
Source
786
354
{
787
354
  bfd_byte *       ptr;
788
354
  pe_ILF_vars      vars;
789
354
  struct internal_filehdr  internal_f;
790
354
  unsigned int       import_type;
791
354
  unsigned int       import_name_type;
792
354
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
793
354
  coff_symbol_type **    imp_sym;
794
354
  unsigned int       imp_index;
795
354
  intptr_t alignment;
796
797
  /* Decode and verify the types field of the ILF structure.  */
798
354
  import_type = types & 0x3;
799
354
  import_name_type = (types & 0x1c) >> 2;
800
801
354
  switch (import_type)
802
354
    {
803
344
    case IMPORT_CODE:
804
348
    case IMPORT_DATA:
805
348
      break;
806
807
3
    case IMPORT_CONST:
808
      /* XXX code yet to be written.  */
809
      /* xgettext:c-format */
810
3
      _bfd_error_handler (_("%pB: unhandled import type; %x"),
811
3
        abfd, import_type);
812
3
      return false;
813
814
3
    default:
815
      /* xgettext:c-format */
816
3
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
817
3
        abfd, import_type);
818
3
      return false;
819
354
    }
820
821
348
  switch (import_name_type)
822
348
    {
823
238
    case IMPORT_ORDINAL:
824
239
    case IMPORT_NAME:
825
240
    case IMPORT_NAME_NOPREFIX:
826
343
    case IMPORT_NAME_UNDECORATE:
827
343
      break;
828
829
5
    default:
830
      /* xgettext:c-format */
831
5
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
832
5
        abfd, import_name_type);
833
5
      return false;
834
348
    }
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
343
  vars.bim
844
343
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
845
343
  if (vars.bim == NULL)
846
0
    return false;
847
848
343
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
849
343
  vars.bim->buffer = ptr;
850
343
  vars.bim->size   = ILF_DATA_SIZE;
851
343
  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
343
  vars.sym_cache = (coff_symbol_type *) ptr;
857
343
  vars.sym_ptr   = (coff_symbol_type *) ptr;
858
343
  vars.sym_index = 0;
859
343
  ptr += SIZEOF_ILF_SYMS;
860
861
343
  vars.sym_table = (unsigned int *) ptr;
862
343
  vars.table_ptr = (unsigned int *) ptr;
863
343
  ptr += SIZEOF_ILF_SYM_TABLE;
864
865
343
  vars.native_syms = (combined_entry_type *) ptr;
866
343
  vars.native_ptr  = (combined_entry_type *) ptr;
867
343
  ptr += SIZEOF_ILF_NATIVE_SYMS;
868
869
343
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
870
343
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
871
343
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
872
873
343
  vars.esym_table = (SYMENT *) ptr;
874
343
  vars.esym_ptr   = (SYMENT *) ptr;
875
343
  ptr += SIZEOF_ILF_EXT_SYMS;
876
877
343
  vars.reltab   = (arelent *) ptr;
878
343
  vars.relcount = 0;
879
343
  ptr += SIZEOF_ILF_RELOCS;
880
881
343
  vars.int_reltab  = (struct internal_reloc *) ptr;
882
343
  ptr += SIZEOF_ILF_INT_RELOCS;
883
884
343
  vars.string_table = (char *) ptr;
885
343
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
886
343
  ptr += SIZEOF_ILF_STRINGS;
887
343
  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
343
#if GCC_VERSION >= 3000
897
343
  alignment = __alignof__ (struct coff_section_tdata);
898
#else
899
  alignment = 8;
900
#endif
901
343
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
902
903
343
  vars.data = ptr;
904
343
  vars.abfd = abfd;
905
343
  vars.sec_index = 0;
906
343
  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
343
  id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
916
343
  id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
917
343
  if (id4 == NULL || id5 == NULL)
918
0
    goto error_return;
919
920
  /* Fill in the contents of these sections.  */
921
343
  if (import_name_type == IMPORT_ORDINAL)
922
238
    {
923
238
      if (ordinal == 0)
924
  /* See PR 20907 for a reproducer.  */
925
102
  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
136
      * (unsigned int *) id4->contents = ordinal | 0x80000000;
934
136
      * (unsigned int *) id5->contents = ordinal | 0x80000000;
935
136
#endif
936
136
    }
937
105
  else
938
105
    {
939
105
      char * symbol;
940
105
      unsigned int len;
941
942
      /* Create .idata$6 - the Hint Name Table.  */
943
105
      id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
944
105
      if (id6 == NULL)
945
0
  goto error_return;
946
947
      /* If necessary, trim the import symbol name.  */
948
105
      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
105
      if (import_name_type != IMPORT_NAME)
958
104
  {
959
104
    char c = symbol[0];
960
961
    /* Check that we don't remove for targets with empty
962
       USER_LABEL_PREFIX the leading underscore.  */
963
104
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
964
104
        || c == '@' || c == '?')
965
0
      symbol++;
966
104
  }
967
968
105
      len = strlen (symbol);
969
105
      if (import_name_type == IMPORT_NAME_UNDECORATE)
970
103
  {
971
    /* Truncate at the first '@'.  */
972
103
    char *at = strchr (symbol, '@');
973
974
103
    if (at != NULL)
975
0
      len = at - symbol;
976
103
  }
977
978
105
      id6->contents[0] = ordinal & 0xff;
979
105
      id6->contents[1] = ordinal >> 8;
980
981
105
      memcpy ((char *) id6->contents + 2, symbol, len);
982
105
      id6->contents[len + 2] = '\0';
983
105
    }
984
985
241
  if (import_name_type != IMPORT_ORDINAL)
986
105
    {
987
105
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
988
105
      pe_ILF_save_relocs (&vars, id4);
989
990
105
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
991
105
      pe_ILF_save_relocs (&vars, id5);
992
105
    }
993
994
  /* Create an import symbol.  */
995
241
  pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
996
241
  imp_sym   = vars.sym_ptr_ptr - 1;
997
241
  imp_index = vars.sym_index - 1;
998
999
  /* Create extra sections depending upon the type of import we are dealing with.  */
1000
241
  switch (import_type)
1001
241
    {
1002
0
      int i;
1003
1004
239
    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
478
      for (i = NUM_ENTRIES (jtab); i--;)
1009
478
  {
1010
478
    if (jtab[i].size == 0)
1011
239
      continue;
1012
239
    if (jtab[i].magic == magic)
1013
239
      break;
1014
239
  }
1015
      /* If we did not find a matching entry something is wrong.  */
1016
239
      if (i < 0)
1017
0
  abort ();
1018
1019
      /* Create the .text section.  */
1020
239
      text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
1021
239
      if (text == NULL)
1022
0
  goto error_return;
1023
1024
      /* Copy in the jump code.  */
1025
239
      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
239
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1051
239
            BFD_RELOC_32, (asymbol **) imp_sym,
1052
239
            imp_index);
1053
1054
239
      pe_ILF_save_relocs (& vars, text);
1055
239
      break;
1056
1057
2
    case IMPORT_DATA:
1058
2
      break;
1059
1060
0
    default:
1061
      /* XXX code not yet written.  */
1062
0
      abort ();
1063
241
    }
1064
1065
  /* Now create a symbol describing the imported value.  */
1066
241
  switch (import_type)
1067
241
    {
1068
239
    case IMPORT_CODE:
1069
239
      pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1070
239
          BSF_NOT_AT_END | BSF_FUNCTION);
1071
1072
239
      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
241
    }
1082
1083
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1084
241
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1085
241
  if (ptr)
1086
1
    * ptr = 0;
1087
241
  pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1088
241
  if (ptr)
1089
1
    * ptr = '.';
1090
1091
  /* Initialise the bfd.  */
1092
241
  memset (& internal_f, 0, sizeof (internal_f));
1093
1094
241
  internal_f.f_magic  = magic;
1095
241
  internal_f.f_symptr = 0;
1096
241
  internal_f.f_nsyms  = 0;
1097
241
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1098
1099
241
  if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
1100
241
      || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1101
0
    goto error_return;
1102
1103
241
  if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL)
1104
0
    goto error_return;
1105
1106
241
  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
241
  bfd_cache_close (abfd);
1115
1116
241
  abfd->iostream = (void *) vars.bim;
1117
241
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1118
241
  abfd->iovec = &_bfd_memory_iovec;
1119
241
  abfd->where = 0;
1120
241
  abfd->origin = 0;
1121
241
  abfd->size = 0;
1122
241
  obj_sym_filepos (abfd) = 0;
1123
1124
  /* Point the bfd at the symbol table.  */
1125
241
  obj_symbols (abfd) = vars.sym_cache;
1126
241
  abfd->symcount = vars.sym_index;
1127
1128
241
  obj_raw_syments (abfd) = vars.native_syms;
1129
241
  obj_raw_syment_count (abfd) = vars.sym_index;
1130
1131
241
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1132
241
  obj_coff_keep_syms (abfd) = true;
1133
1134
241
  obj_convert (abfd) = vars.sym_table;
1135
241
  obj_conv_table_size (abfd) = vars.sym_index;
1136
1137
241
  obj_coff_strings (abfd) = vars.string_table;
1138
241
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1139
241
  obj_coff_keep_strings (abfd) = true;
1140
1141
241
  return true;
1142
1143
102
 error_return:
1144
102
  free (vars.bim->buffer);
1145
102
  free (vars.bim);
1146
102
  return false;
1147
241
}
pei-x86_64.c:pe_ILF_build_a_bfd
Line
Count
Source
786
1.25k
{
787
1.25k
  bfd_byte *       ptr;
788
1.25k
  pe_ILF_vars      vars;
789
1.25k
  struct internal_filehdr  internal_f;
790
1.25k
  unsigned int       import_type;
791
1.25k
  unsigned int       import_name_type;
792
1.25k
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
793
1.25k
  coff_symbol_type **    imp_sym;
794
1.25k
  unsigned int       imp_index;
795
1.25k
  intptr_t alignment;
796
797
  /* Decode and verify the types field of the ILF structure.  */
798
1.25k
  import_type = types & 0x3;
799
1.25k
  import_name_type = (types & 0x1c) >> 2;
800
801
1.25k
  switch (import_type)
802
1.25k
    {
803
778
    case IMPORT_CODE:
804
1.25k
    case IMPORT_DATA:
805
1.25k
      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
1.25k
    }
820
821
1.25k
  switch (import_name_type)
822
1.25k
    {
823
577
    case IMPORT_ORDINAL:
824
680
    case IMPORT_NAME:
825
1.01k
    case IMPORT_NAME_NOPREFIX:
826
1.15k
    case IMPORT_NAME_UNDECORATE:
827
1.15k
      break;
828
829
102
    default:
830
      /* xgettext:c-format */
831
102
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
832
102
        abfd, import_name_type);
833
102
      return false;
834
1.25k
    }
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
1.15k
  vars.bim
844
1.15k
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
845
1.15k
  if (vars.bim == NULL)
846
0
    return false;
847
848
1.15k
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
849
1.15k
  vars.bim->buffer = ptr;
850
1.15k
  vars.bim->size   = ILF_DATA_SIZE;
851
1.15k
  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
1.15k
  vars.sym_cache = (coff_symbol_type *) ptr;
857
1.15k
  vars.sym_ptr   = (coff_symbol_type *) ptr;
858
1.15k
  vars.sym_index = 0;
859
1.15k
  ptr += SIZEOF_ILF_SYMS;
860
861
1.15k
  vars.sym_table = (unsigned int *) ptr;
862
1.15k
  vars.table_ptr = (unsigned int *) ptr;
863
1.15k
  ptr += SIZEOF_ILF_SYM_TABLE;
864
865
1.15k
  vars.native_syms = (combined_entry_type *) ptr;
866
1.15k
  vars.native_ptr  = (combined_entry_type *) ptr;
867
1.15k
  ptr += SIZEOF_ILF_NATIVE_SYMS;
868
869
1.15k
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
870
1.15k
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
871
1.15k
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
872
873
1.15k
  vars.esym_table = (SYMENT *) ptr;
874
1.15k
  vars.esym_ptr   = (SYMENT *) ptr;
875
1.15k
  ptr += SIZEOF_ILF_EXT_SYMS;
876
877
1.15k
  vars.reltab   = (arelent *) ptr;
878
1.15k
  vars.relcount = 0;
879
1.15k
  ptr += SIZEOF_ILF_RELOCS;
880
881
1.15k
  vars.int_reltab  = (struct internal_reloc *) ptr;
882
1.15k
  ptr += SIZEOF_ILF_INT_RELOCS;
883
884
1.15k
  vars.string_table = (char *) ptr;
885
1.15k
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
886
1.15k
  ptr += SIZEOF_ILF_STRINGS;
887
1.15k
  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
1.15k
#if GCC_VERSION >= 3000
897
1.15k
  alignment = __alignof__ (struct coff_section_tdata);
898
#else
899
  alignment = 8;
900
#endif
901
1.15k
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
902
903
1.15k
  vars.data = ptr;
904
1.15k
  vars.abfd = abfd;
905
1.15k
  vars.sec_index = 0;
906
1.15k
  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
1.15k
  id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
916
1.15k
  id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
917
1.15k
  if (id4 == NULL || id5 == NULL)
918
0
    goto error_return;
919
920
  /* Fill in the contents of these sections.  */
921
1.15k
  if (import_name_type == IMPORT_ORDINAL)
922
577
    {
923
577
      if (ordinal == 0)
924
  /* See PR 20907 for a reproducer.  */
925
104
  goto error_return;
926
927
473
#if defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) || defined(COFF_WITH_peLoongArch64)
928
473
      ((unsigned int *) id4->contents)[0] = ordinal;
929
473
      ((unsigned int *) id4->contents)[1] = 0x80000000;
930
473
      ((unsigned int *) id5->contents)[0] = ordinal;
931
473
      ((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
473
    }
937
576
  else
938
576
    {
939
576
      char * symbol;
940
576
      unsigned int len;
941
942
      /* Create .idata$6 - the Hint Name Table.  */
943
576
      id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
944
576
      if (id6 == NULL)
945
0
  goto error_return;
946
947
      /* If necessary, trim the import symbol name.  */
948
576
      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
576
      if (import_name_type != IMPORT_NAME)
958
473
  {
959
473
    char c = symbol[0];
960
961
    /* Check that we don't remove for targets with empty
962
       USER_LABEL_PREFIX the leading underscore.  */
963
473
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
964
473
        || c == '@' || c == '?')
965
1
      symbol++;
966
473
  }
967
968
576
      len = strlen (symbol);
969
576
      if (import_name_type == IMPORT_NAME_UNDECORATE)
970
135
  {
971
    /* Truncate at the first '@'.  */
972
135
    char *at = strchr (symbol, '@');
973
974
135
    if (at != NULL)
975
0
      len = at - symbol;
976
135
  }
977
978
576
      id6->contents[0] = ordinal & 0xff;
979
576
      id6->contents[1] = ordinal >> 8;
980
981
576
      memcpy ((char *) id6->contents + 2, symbol, len);
982
576
      id6->contents[len + 2] = '\0';
983
576
    }
984
985
1.04k
  if (import_name_type != IMPORT_ORDINAL)
986
576
    {
987
576
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
988
576
      pe_ILF_save_relocs (&vars, id4);
989
990
576
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
991
576
      pe_ILF_save_relocs (&vars, id5);
992
576
    }
993
994
  /* Create an import symbol.  */
995
1.04k
  pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
996
1.04k
  imp_sym   = vars.sym_ptr_ptr - 1;
997
1.04k
  imp_index = vars.sym_index - 1;
998
999
  /* Create extra sections depending upon the type of import we are dealing with.  */
1000
1.04k
  switch (import_type)
1001
1.04k
    {
1002
0
      int i;
1003
1004
575
    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
1.15k
      for (i = NUM_ENTRIES (jtab); i--;)
1009
1.15k
  {
1010
1.15k
    if (jtab[i].size == 0)
1011
575
      continue;
1012
575
    if (jtab[i].magic == magic)
1013
575
      break;
1014
575
  }
1015
      /* If we did not find a matching entry something is wrong.  */
1016
575
      if (i < 0)
1017
0
  abort ();
1018
1019
      /* Create the .text section.  */
1020
575
      text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
1021
575
      if (text == NULL)
1022
0
  goto error_return;
1023
1024
      /* Copy in the jump code.  */
1025
575
      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
575
#ifdef AMD64MAGIC
1042
575
      if (magic == AMD64MAGIC)
1043
575
  {
1044
575
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1045
575
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1046
575
              imp_index);
1047
575
  }
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
575
      pe_ILF_save_relocs (& vars, text);
1055
575
      break;
1056
1057
474
    case IMPORT_DATA:
1058
474
      break;
1059
1060
0
    default:
1061
      /* XXX code not yet written.  */
1062
0
      abort ();
1063
1.04k
    }
1064
1065
  /* Now create a symbol describing the imported value.  */
1066
1.04k
  switch (import_type)
1067
1.04k
    {
1068
575
    case IMPORT_CODE:
1069
575
      pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1070
575
          BSF_NOT_AT_END | BSF_FUNCTION);
1071
1072
575
      break;
1073
1074
474
    case IMPORT_DATA:
1075
      /* Nothing to do here.  */
1076
474
      break;
1077
1078
0
    default:
1079
      /* XXX code not yet written.  */
1080
0
      abort ();
1081
1.04k
    }
1082
1083
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1084
1.04k
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1085
1.04k
  if (ptr)
1086
101
    * ptr = 0;
1087
1.04k
  pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1088
1.04k
  if (ptr)
1089
101
    * ptr = '.';
1090
1091
  /* Initialise the bfd.  */
1092
1.04k
  memset (& internal_f, 0, sizeof (internal_f));
1093
1094
1.04k
  internal_f.f_magic  = magic;
1095
1.04k
  internal_f.f_symptr = 0;
1096
1.04k
  internal_f.f_nsyms  = 0;
1097
1.04k
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1098
1099
1.04k
  if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
1100
1.04k
      || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1101
0
    goto error_return;
1102
1103
1.04k
  if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL)
1104
0
    goto error_return;
1105
1106
1.04k
  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
1.04k
  bfd_cache_close (abfd);
1115
1116
1.04k
  abfd->iostream = (void *) vars.bim;
1117
1.04k
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1118
1.04k
  abfd->iovec = &_bfd_memory_iovec;
1119
1.04k
  abfd->where = 0;
1120
1.04k
  abfd->origin = 0;
1121
1.04k
  abfd->size = 0;
1122
1.04k
  obj_sym_filepos (abfd) = 0;
1123
1124
  /* Point the bfd at the symbol table.  */
1125
1.04k
  obj_symbols (abfd) = vars.sym_cache;
1126
1.04k
  abfd->symcount = vars.sym_index;
1127
1128
1.04k
  obj_raw_syments (abfd) = vars.native_syms;
1129
1.04k
  obj_raw_syment_count (abfd) = vars.sym_index;
1130
1131
1.04k
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1132
1.04k
  obj_coff_keep_syms (abfd) = true;
1133
1134
1.04k
  obj_convert (abfd) = vars.sym_table;
1135
1.04k
  obj_conv_table_size (abfd) = vars.sym_index;
1136
1137
1.04k
  obj_coff_strings (abfd) = vars.string_table;
1138
1.04k
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1139
1.04k
  obj_coff_keep_strings (abfd) = true;
1140
1141
1.04k
  return true;
1142
1143
104
 error_return:
1144
104
  free (vars.bim->buffer);
1145
104
  free (vars.bim);
1146
104
  return false;
1147
1.04k
}
pei-aarch64.c:pe_ILF_build_a_bfd
Line
Count
Source
786
515
{
787
515
  bfd_byte *       ptr;
788
515
  pe_ILF_vars      vars;
789
515
  struct internal_filehdr  internal_f;
790
515
  unsigned int       import_type;
791
515
  unsigned int       import_name_type;
792
515
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
793
515
  coff_symbol_type **    imp_sym;
794
515
  unsigned int       imp_index;
795
515
  intptr_t alignment;
796
797
  /* Decode and verify the types field of the ILF structure.  */
798
515
  import_type = types & 0x3;
799
515
  import_name_type = (types & 0x1c) >> 2;
800
801
515
  switch (import_type)
802
515
    {
803
6
    case IMPORT_CODE:
804
511
    case IMPORT_DATA:
805
511
      break;
806
807
3
    case IMPORT_CONST:
808
      /* XXX code yet to be written.  */
809
      /* xgettext:c-format */
810
3
      _bfd_error_handler (_("%pB: unhandled import type; %x"),
811
3
        abfd, import_type);
812
3
      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
515
    }
820
821
511
  switch (import_name_type)
822
511
    {
823
4
    case IMPORT_ORDINAL:
824
240
    case IMPORT_NAME:
825
241
    case IMPORT_NAME_NOPREFIX:
826
510
    case IMPORT_NAME_UNDECORATE:
827
510
      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
511
    }
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
510
  vars.bim
844
510
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
845
510
  if (vars.bim == NULL)
846
0
    return false;
847
848
510
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
849
510
  vars.bim->buffer = ptr;
850
510
  vars.bim->size   = ILF_DATA_SIZE;
851
510
  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
510
  vars.sym_cache = (coff_symbol_type *) ptr;
857
510
  vars.sym_ptr   = (coff_symbol_type *) ptr;
858
510
  vars.sym_index = 0;
859
510
  ptr += SIZEOF_ILF_SYMS;
860
861
510
  vars.sym_table = (unsigned int *) ptr;
862
510
  vars.table_ptr = (unsigned int *) ptr;
863
510
  ptr += SIZEOF_ILF_SYM_TABLE;
864
865
510
  vars.native_syms = (combined_entry_type *) ptr;
866
510
  vars.native_ptr  = (combined_entry_type *) ptr;
867
510
  ptr += SIZEOF_ILF_NATIVE_SYMS;
868
869
510
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
870
510
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
871
510
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
872
873
510
  vars.esym_table = (SYMENT *) ptr;
874
510
  vars.esym_ptr   = (SYMENT *) ptr;
875
510
  ptr += SIZEOF_ILF_EXT_SYMS;
876
877
510
  vars.reltab   = (arelent *) ptr;
878
510
  vars.relcount = 0;
879
510
  ptr += SIZEOF_ILF_RELOCS;
880
881
510
  vars.int_reltab  = (struct internal_reloc *) ptr;
882
510
  ptr += SIZEOF_ILF_INT_RELOCS;
883
884
510
  vars.string_table = (char *) ptr;
885
510
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
886
510
  ptr += SIZEOF_ILF_STRINGS;
887
510
  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
510
#if GCC_VERSION >= 3000
897
510
  alignment = __alignof__ (struct coff_section_tdata);
898
#else
899
  alignment = 8;
900
#endif
901
510
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
902
903
510
  vars.data = ptr;
904
510
  vars.abfd = abfd;
905
510
  vars.sec_index = 0;
906
510
  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
510
  id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
916
510
  id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
917
510
  if (id4 == NULL || id5 == NULL)
918
0
    goto error_return;
919
920
  /* Fill in the contents of these sections.  */
921
510
  if (import_name_type == IMPORT_ORDINAL)
922
4
    {
923
4
      if (ordinal == 0)
924
  /* See PR 20907 for a reproducer.  */
925
1
  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
506
  else
938
506
    {
939
506
      char * symbol;
940
506
      unsigned int len;
941
942
      /* Create .idata$6 - the Hint Name Table.  */
943
506
      id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
944
506
      if (id6 == NULL)
945
0
  goto error_return;
946
947
      /* If necessary, trim the import symbol name.  */
948
506
      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
506
      if (import_name_type != IMPORT_NAME)
958
270
  {
959
270
    char c = symbol[0];
960
961
    /* Check that we don't remove for targets with empty
962
       USER_LABEL_PREFIX the leading underscore.  */
963
270
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
964
270
        || c == '@' || c == '?')
965
0
      symbol++;
966
270
  }
967
968
506
      len = strlen (symbol);
969
506
      if (import_name_type == IMPORT_NAME_UNDECORATE)
970
269
  {
971
    /* Truncate at the first '@'.  */
972
269
    char *at = strchr (symbol, '@');
973
974
269
    if (at != NULL)
975
0
      len = at - symbol;
976
269
  }
977
978
506
      id6->contents[0] = ordinal & 0xff;
979
506
      id6->contents[1] = ordinal >> 8;
980
981
506
      memcpy ((char *) id6->contents + 2, symbol, len);
982
506
      id6->contents[len + 2] = '\0';
983
506
    }
984
985
509
  if (import_name_type != IMPORT_ORDINAL)
986
506
    {
987
506
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
988
506
      pe_ILF_save_relocs (&vars, id4);
989
990
506
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
991
506
      pe_ILF_save_relocs (&vars, id5);
992
506
    }
993
994
  /* Create an import symbol.  */
995
509
  pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
996
509
  imp_sym   = vars.sym_ptr_ptr - 1;
997
509
  imp_index = vars.sym_index - 1;
998
999
  /* Create extra sections depending upon the type of import we are dealing with.  */
1000
509
  switch (import_type)
1001
509
    {
1002
0
      int i;
1003
1004
4
    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
8
      for (i = NUM_ENTRIES (jtab); i--;)
1009
8
  {
1010
8
    if (jtab[i].size == 0)
1011
4
      continue;
1012
4
    if (jtab[i].magic == magic)
1013
4
      break;
1014
4
  }
1015
      /* If we did not find a matching entry something is wrong.  */
1016
4
      if (i < 0)
1017
0
  abort ();
1018
1019
      /* Create the .text section.  */
1020
4
      text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
1021
4
      if (text == NULL)
1022
0
  goto error_return;
1023
1024
      /* Copy in the jump code.  */
1025
4
      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
4
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1051
4
            BFD_RELOC_32, (asymbol **) imp_sym,
1052
4
            imp_index);
1053
1054
4
      pe_ILF_save_relocs (& vars, text);
1055
4
      break;
1056
1057
505
    case IMPORT_DATA:
1058
505
      break;
1059
1060
0
    default:
1061
      /* XXX code not yet written.  */
1062
0
      abort ();
1063
509
    }
1064
1065
  /* Now create a symbol describing the imported value.  */
1066
509
  switch (import_type)
1067
509
    {
1068
4
    case IMPORT_CODE:
1069
4
      pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1070
4
          BSF_NOT_AT_END | BSF_FUNCTION);
1071
1072
4
      break;
1073
1074
505
    case IMPORT_DATA:
1075
      /* Nothing to do here.  */
1076
505
      break;
1077
1078
0
    default:
1079
      /* XXX code not yet written.  */
1080
0
      abort ();
1081
509
    }
1082
1083
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1084
509
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1085
509
  if (ptr)
1086
1
    * ptr = 0;
1087
509
  pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1088
509
  if (ptr)
1089
1
    * ptr = '.';
1090
1091
  /* Initialise the bfd.  */
1092
509
  memset (& internal_f, 0, sizeof (internal_f));
1093
1094
509
  internal_f.f_magic  = magic;
1095
509
  internal_f.f_symptr = 0;
1096
509
  internal_f.f_nsyms  = 0;
1097
509
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1098
1099
509
  if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
1100
509
      || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1101
0
    goto error_return;
1102
1103
509
  if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL)
1104
0
    goto error_return;
1105
1106
509
  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
509
  bfd_cache_close (abfd);
1115
1116
509
  abfd->iostream = (void *) vars.bim;
1117
509
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1118
509
  abfd->iovec = &_bfd_memory_iovec;
1119
509
  abfd->where = 0;
1120
509
  abfd->origin = 0;
1121
509
  abfd->size = 0;
1122
509
  obj_sym_filepos (abfd) = 0;
1123
1124
  /* Point the bfd at the symbol table.  */
1125
509
  obj_symbols (abfd) = vars.sym_cache;
1126
509
  abfd->symcount = vars.sym_index;
1127
1128
509
  obj_raw_syments (abfd) = vars.native_syms;
1129
509
  obj_raw_syment_count (abfd) = vars.sym_index;
1130
1131
509
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1132
509
  obj_coff_keep_syms (abfd) = true;
1133
1134
509
  obj_convert (abfd) = vars.sym_table;
1135
509
  obj_conv_table_size (abfd) = vars.sym_index;
1136
1137
509
  obj_coff_strings (abfd) = vars.string_table;
1138
509
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1139
509
  obj_coff_keep_strings (abfd) = true;
1140
1141
509
  return true;
1142
1143
1
 error_return:
1144
1
  free (vars.bim->buffer);
1145
1
  free (vars.bim);
1146
1
  return false;
1147
509
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_build_a_bfd
pei-loongarch64.c:pe_ILF_build_a_bfd
Line
Count
Source
786
486
{
787
486
  bfd_byte *       ptr;
788
486
  pe_ILF_vars      vars;
789
486
  struct internal_filehdr  internal_f;
790
486
  unsigned int       import_type;
791
486
  unsigned int       import_name_type;
792
486
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
793
486
  coff_symbol_type **    imp_sym;
794
486
  unsigned int       imp_index;
795
486
  intptr_t alignment;
796
797
  /* Decode and verify the types field of the ILF structure.  */
798
486
  import_type = types & 0x3;
799
486
  import_name_type = (types & 0x1c) >> 2;
800
801
486
  switch (import_type)
802
486
    {
803
8
    case IMPORT_CODE:
804
381
    case IMPORT_DATA:
805
381
      break;
806
807
104
    case IMPORT_CONST:
808
      /* XXX code yet to be written.  */
809
      /* xgettext:c-format */
810
104
      _bfd_error_handler (_("%pB: unhandled import type; %x"),
811
104
        abfd, import_type);
812
104
      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
486
    }
820
821
381
  switch (import_name_type)
822
381
    {
823
139
    case IMPORT_ORDINAL:
824
140
    case IMPORT_NAME:
825
144
    case IMPORT_NAME_NOPREFIX:
826
380
    case IMPORT_NAME_UNDECORATE:
827
380
      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
381
    }
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
380
  vars.bim
844
380
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
845
380
  if (vars.bim == NULL)
846
0
    return false;
847
848
380
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
849
380
  vars.bim->buffer = ptr;
850
380
  vars.bim->size   = ILF_DATA_SIZE;
851
380
  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
380
  vars.sym_cache = (coff_symbol_type *) ptr;
857
380
  vars.sym_ptr   = (coff_symbol_type *) ptr;
858
380
  vars.sym_index = 0;
859
380
  ptr += SIZEOF_ILF_SYMS;
860
861
380
  vars.sym_table = (unsigned int *) ptr;
862
380
  vars.table_ptr = (unsigned int *) ptr;
863
380
  ptr += SIZEOF_ILF_SYM_TABLE;
864
865
380
  vars.native_syms = (combined_entry_type *) ptr;
866
380
  vars.native_ptr  = (combined_entry_type *) ptr;
867
380
  ptr += SIZEOF_ILF_NATIVE_SYMS;
868
869
380
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
870
380
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
871
380
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
872
873
380
  vars.esym_table = (SYMENT *) ptr;
874
380
  vars.esym_ptr   = (SYMENT *) ptr;
875
380
  ptr += SIZEOF_ILF_EXT_SYMS;
876
877
380
  vars.reltab   = (arelent *) ptr;
878
380
  vars.relcount = 0;
879
380
  ptr += SIZEOF_ILF_RELOCS;
880
881
380
  vars.int_reltab  = (struct internal_reloc *) ptr;
882
380
  ptr += SIZEOF_ILF_INT_RELOCS;
883
884
380
  vars.string_table = (char *) ptr;
885
380
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
886
380
  ptr += SIZEOF_ILF_STRINGS;
887
380
  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
380
#if GCC_VERSION >= 3000
897
380
  alignment = __alignof__ (struct coff_section_tdata);
898
#else
899
  alignment = 8;
900
#endif
901
380
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
902
903
380
  vars.data = ptr;
904
380
  vars.abfd = abfd;
905
380
  vars.sec_index = 0;
906
380
  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
380
  id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
916
380
  id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
917
380
  if (id4 == NULL || id5 == NULL)
918
0
    goto error_return;
919
920
  /* Fill in the contents of these sections.  */
921
380
  if (import_name_type == IMPORT_ORDINAL)
922
139
    {
923
139
      if (ordinal == 0)
924
  /* See PR 20907 for a reproducer.  */
925
3
  goto error_return;
926
927
136
#if defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) || defined(COFF_WITH_peLoongArch64)
928
136
      ((unsigned int *) id4->contents)[0] = ordinal;
929
136
      ((unsigned int *) id4->contents)[1] = 0x80000000;
930
136
      ((unsigned int *) id5->contents)[0] = ordinal;
931
136
      ((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
136
    }
937
241
  else
938
241
    {
939
241
      char * symbol;
940
241
      unsigned int len;
941
942
      /* Create .idata$6 - the Hint Name Table.  */
943
241
      id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
944
241
      if (id6 == NULL)
945
0
  goto error_return;
946
947
      /* If necessary, trim the import symbol name.  */
948
241
      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
241
      if (import_name_type != IMPORT_NAME)
958
240
  {
959
240
    char c = symbol[0];
960
961
    /* Check that we don't remove for targets with empty
962
       USER_LABEL_PREFIX the leading underscore.  */
963
240
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
964
240
        || c == '@' || c == '?')
965
135
      symbol++;
966
240
  }
967
968
241
      len = strlen (symbol);
969
241
      if (import_name_type == IMPORT_NAME_UNDECORATE)
970
236
  {
971
    /* Truncate at the first '@'.  */
972
236
    char *at = strchr (symbol, '@');
973
974
236
    if (at != NULL)
975
0
      len = at - symbol;
976
236
  }
977
978
241
      id6->contents[0] = ordinal & 0xff;
979
241
      id6->contents[1] = ordinal >> 8;
980
981
241
      memcpy ((char *) id6->contents + 2, symbol, len);
982
241
      id6->contents[len + 2] = '\0';
983
241
    }
984
985
377
  if (import_name_type != IMPORT_ORDINAL)
986
241
    {
987
241
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
988
241
      pe_ILF_save_relocs (&vars, id4);
989
990
241
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
991
241
      pe_ILF_save_relocs (&vars, id5);
992
241
    }
993
994
  /* Create an import symbol.  */
995
377
  pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
996
377
  imp_sym   = vars.sym_ptr_ptr - 1;
997
377
  imp_index = vars.sym_index - 1;
998
999
  /* Create extra sections depending upon the type of import we are dealing with.  */
1000
377
  switch (import_type)
1001
377
    {
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
372
    case IMPORT_DATA:
1058
372
      break;
1059
1060
0
    default:
1061
      /* XXX code not yet written.  */
1062
0
      abort ();
1063
377
    }
1064
1065
  /* Now create a symbol describing the imported value.  */
1066
377
  switch (import_type)
1067
377
    {
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
372
    case IMPORT_DATA:
1075
      /* Nothing to do here.  */
1076
372
      break;
1077
1078
0
    default:
1079
      /* XXX code not yet written.  */
1080
0
      abort ();
1081
377
    }
1082
1083
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1084
377
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1085
377
  if (ptr)
1086
135
    * ptr = 0;
1087
377
  pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1088
377
  if (ptr)
1089
135
    * ptr = '.';
1090
1091
  /* Initialise the bfd.  */
1092
377
  memset (& internal_f, 0, sizeof (internal_f));
1093
1094
377
  internal_f.f_magic  = magic;
1095
377
  internal_f.f_symptr = 0;
1096
377
  internal_f.f_nsyms  = 0;
1097
377
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1098
1099
377
  if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
1100
377
      || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1101
0
    goto error_return;
1102
1103
377
  if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL)
1104
0
    goto error_return;
1105
1106
377
  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
377
  bfd_cache_close (abfd);
1115
1116
377
  abfd->iostream = (void *) vars.bim;
1117
377
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1118
377
  abfd->iovec = &_bfd_memory_iovec;
1119
377
  abfd->where = 0;
1120
377
  abfd->origin = 0;
1121
377
  abfd->size = 0;
1122
377
  obj_sym_filepos (abfd) = 0;
1123
1124
  /* Point the bfd at the symbol table.  */
1125
377
  obj_symbols (abfd) = vars.sym_cache;
1126
377
  abfd->symcount = vars.sym_index;
1127
1128
377
  obj_raw_syments (abfd) = vars.native_syms;
1129
377
  obj_raw_syment_count (abfd) = vars.sym_index;
1130
1131
377
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1132
377
  obj_coff_keep_syms (abfd) = true;
1133
1134
377
  obj_convert (abfd) = vars.sym_table;
1135
377
  obj_conv_table_size (abfd) = vars.sym_index;
1136
1137
377
  obj_coff_strings (abfd) = vars.string_table;
1138
377
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1139
377
  obj_coff_keep_strings (abfd) = true;
1140
1141
377
  return true;
1142
1143
3
 error_return:
1144
3
  free (vars.bim->buffer);
1145
3
  free (vars.bim);
1146
3
  return false;
1147
377
}
pei-arm-wince.c:pe_ILF_build_a_bfd
Line
Count
Source
786
225
{
787
225
  bfd_byte *       ptr;
788
225
  pe_ILF_vars      vars;
789
225
  struct internal_filehdr  internal_f;
790
225
  unsigned int       import_type;
791
225
  unsigned int       import_name_type;
792
225
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
793
225
  coff_symbol_type **    imp_sym;
794
225
  unsigned int       imp_index;
795
225
  intptr_t alignment;
796
797
  /* Decode and verify the types field of the ILF structure.  */
798
225
  import_type = types & 0x3;
799
225
  import_name_type = (types & 0x1c) >> 2;
800
801
225
  switch (import_type)
802
225
    {
803
16
    case IMPORT_CODE:
804
121
    case IMPORT_DATA:
805
121
      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
102
    default:
815
      /* xgettext:c-format */
816
102
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
817
102
        abfd, import_type);
818
102
      return false;
819
225
    }
820
821
121
  switch (import_name_type)
822
121
    {
823
13
    case IMPORT_ORDINAL:
824
15
    case IMPORT_NAME:
825
16
    case IMPORT_NAME_NOPREFIX:
826
17
    case IMPORT_NAME_UNDECORATE:
827
17
      break;
828
829
104
    default:
830
      /* xgettext:c-format */
831
104
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
832
104
        abfd, import_name_type);
833
104
      return false;
834
121
    }
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
17
  vars.bim
844
17
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
845
17
  if (vars.bim == NULL)
846
0
    return false;
847
848
17
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
849
17
  vars.bim->buffer = ptr;
850
17
  vars.bim->size   = ILF_DATA_SIZE;
851
17
  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
17
  vars.sym_cache = (coff_symbol_type *) ptr;
857
17
  vars.sym_ptr   = (coff_symbol_type *) ptr;
858
17
  vars.sym_index = 0;
859
17
  ptr += SIZEOF_ILF_SYMS;
860
861
17
  vars.sym_table = (unsigned int *) ptr;
862
17
  vars.table_ptr = (unsigned int *) ptr;
863
17
  ptr += SIZEOF_ILF_SYM_TABLE;
864
865
17
  vars.native_syms = (combined_entry_type *) ptr;
866
17
  vars.native_ptr  = (combined_entry_type *) ptr;
867
17
  ptr += SIZEOF_ILF_NATIVE_SYMS;
868
869
17
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
870
17
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
871
17
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
872
873
17
  vars.esym_table = (SYMENT *) ptr;
874
17
  vars.esym_ptr   = (SYMENT *) ptr;
875
17
  ptr += SIZEOF_ILF_EXT_SYMS;
876
877
17
  vars.reltab   = (arelent *) ptr;
878
17
  vars.relcount = 0;
879
17
  ptr += SIZEOF_ILF_RELOCS;
880
881
17
  vars.int_reltab  = (struct internal_reloc *) ptr;
882
17
  ptr += SIZEOF_ILF_INT_RELOCS;
883
884
17
  vars.string_table = (char *) ptr;
885
17
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
886
17
  ptr += SIZEOF_ILF_STRINGS;
887
17
  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
17
#if GCC_VERSION >= 3000
897
17
  alignment = __alignof__ (struct coff_section_tdata);
898
#else
899
  alignment = 8;
900
#endif
901
17
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
902
903
17
  vars.data = ptr;
904
17
  vars.abfd = abfd;
905
17
  vars.sec_index = 0;
906
17
  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
17
  id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
916
17
  id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
917
17
  if (id4 == NULL || id5 == NULL)
918
0
    goto error_return;
919
920
  /* Fill in the contents of these sections.  */
921
17
  if (import_name_type == IMPORT_ORDINAL)
922
13
    {
923
13
      if (ordinal == 0)
924
  /* See PR 20907 for a reproducer.  */
925
4
  goto error_return;
926
927
#if defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) || defined(COFF_WITH_peLoongArch64)
928
      ((unsigned int *) id4->contents)[0] = ordinal;
929
      ((unsigned int *) id4->contents)[1] = 0x80000000;
930
      ((unsigned int *) id5->contents)[0] = ordinal;
931
      ((unsigned int *) id5->contents)[1] = 0x80000000;
932
#else
933
9
      * (unsigned int *) id4->contents = ordinal | 0x80000000;
934
9
      * (unsigned int *) id5->contents = ordinal | 0x80000000;
935
9
#endif
936
9
    }
937
4
  else
938
4
    {
939
4
      char * symbol;
940
4
      unsigned int len;
941
942
      /* Create .idata$6 - the Hint Name Table.  */
943
4
      id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
944
4
      if (id6 == NULL)
945
0
  goto error_return;
946
947
      /* If necessary, trim the import symbol name.  */
948
4
      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
4
      if (import_name_type != IMPORT_NAME)
958
2
  {
959
2
    char c = symbol[0];
960
961
    /* Check that we don't remove for targets with empty
962
       USER_LABEL_PREFIX the leading underscore.  */
963
2
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
964
2
        || c == '@' || c == '?')
965
0
      symbol++;
966
2
  }
967
968
4
      len = strlen (symbol);
969
4
      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
4
      id6->contents[0] = ordinal & 0xff;
979
4
      id6->contents[1] = ordinal >> 8;
980
981
4
      memcpy ((char *) id6->contents + 2, symbol, len);
982
4
      id6->contents[len + 2] = '\0';
983
4
    }
984
985
13
  if (import_name_type != IMPORT_ORDINAL)
986
4
    {
987
4
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
988
4
      pe_ILF_save_relocs (&vars, id4);
989
990
4
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
991
4
      pe_ILF_save_relocs (&vars, id5);
992
4
    }
993
994
  /* Create an import symbol.  */
995
13
  pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
996
13
  imp_sym   = vars.sym_ptr_ptr - 1;
997
13
  imp_index = vars.sym_index - 1;
998
999
  /* Create extra sections depending upon the type of import we are dealing with.  */
1000
13
  switch (import_type)
1001
13
    {
1002
0
      int i;
1003
1004
9
    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
21
      for (i = NUM_ENTRIES (jtab); i--;)
1009
21
  {
1010
21
    if (jtab[i].size == 0)
1011
9
      continue;
1012
12
    if (jtab[i].magic == magic)
1013
9
      break;
1014
12
  }
1015
      /* If we did not find a matching entry something is wrong.  */
1016
9
      if (i < 0)
1017
0
  abort ();
1018
1019
      /* Create the .text section.  */
1020
9
      text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
1021
9
      if (text == NULL)
1022
0
  goto error_return;
1023
1024
      /* Copy in the jump code.  */
1025
9
      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
9
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1051
9
            BFD_RELOC_32, (asymbol **) imp_sym,
1052
9
            imp_index);
1053
1054
9
      pe_ILF_save_relocs (& vars, text);
1055
9
      break;
1056
1057
4
    case IMPORT_DATA:
1058
4
      break;
1059
1060
0
    default:
1061
      /* XXX code not yet written.  */
1062
0
      abort ();
1063
13
    }
1064
1065
  /* Now create a symbol describing the imported value.  */
1066
13
  switch (import_type)
1067
13
    {
1068
9
    case IMPORT_CODE:
1069
9
      pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1070
9
          BSF_NOT_AT_END | BSF_FUNCTION);
1071
1072
9
      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
13
    }
1082
1083
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1084
13
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1085
13
  if (ptr)
1086
2
    * ptr = 0;
1087
13
  pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1088
13
  if (ptr)
1089
2
    * ptr = '.';
1090
1091
  /* Initialise the bfd.  */
1092
13
  memset (& internal_f, 0, sizeof (internal_f));
1093
1094
13
  internal_f.f_magic  = magic;
1095
13
  internal_f.f_symptr = 0;
1096
13
  internal_f.f_nsyms  = 0;
1097
13
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1098
1099
13
  if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
1100
13
      || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1101
0
    goto error_return;
1102
1103
13
  if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL)
1104
0
    goto error_return;
1105
1106
13
  obj_pe (abfd) = true;
1107
13
#ifdef THUMBPEMAGIC
1108
13
  if (vars.magic == THUMBPEMAGIC)
1109
    /* Stop some linker warnings about thumb code not supporting interworking.  */
1110
8
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1111
13
#endif
1112
1113
  /* Switch from file contents to memory contents.  */
1114
13
  bfd_cache_close (abfd);
1115
1116
13
  abfd->iostream = (void *) vars.bim;
1117
13
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1118
13
  abfd->iovec = &_bfd_memory_iovec;
1119
13
  abfd->where = 0;
1120
13
  abfd->origin = 0;
1121
13
  abfd->size = 0;
1122
13
  obj_sym_filepos (abfd) = 0;
1123
1124
  /* Point the bfd at the symbol table.  */
1125
13
  obj_symbols (abfd) = vars.sym_cache;
1126
13
  abfd->symcount = vars.sym_index;
1127
1128
13
  obj_raw_syments (abfd) = vars.native_syms;
1129
13
  obj_raw_syment_count (abfd) = vars.sym_index;
1130
1131
13
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1132
13
  obj_coff_keep_syms (abfd) = true;
1133
1134
13
  obj_convert (abfd) = vars.sym_table;
1135
13
  obj_conv_table_size (abfd) = vars.sym_index;
1136
1137
13
  obj_coff_strings (abfd) = vars.string_table;
1138
13
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1139
13
  obj_coff_keep_strings (abfd) = true;
1140
1141
13
  return true;
1142
1143
4
 error_return:
1144
4
  free (vars.bim->buffer);
1145
4
  free (vars.bim);
1146
4
  return false;
1147
13
}
pei-arm.c:pe_ILF_build_a_bfd
Line
Count
Source
786
1.03k
{
787
1.03k
  bfd_byte *       ptr;
788
1.03k
  pe_ILF_vars      vars;
789
1.03k
  struct internal_filehdr  internal_f;
790
1.03k
  unsigned int       import_type;
791
1.03k
  unsigned int       import_name_type;
792
1.03k
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
793
1.03k
  coff_symbol_type **    imp_sym;
794
1.03k
  unsigned int       imp_index;
795
1.03k
  intptr_t alignment;
796
797
  /* Decode and verify the types field of the ILF structure.  */
798
1.03k
  import_type = types & 0x3;
799
1.03k
  import_name_type = (types & 0x1c) >> 2;
800
801
1.03k
  switch (import_type)
802
1.03k
    {
803
592
    case IMPORT_CODE:
804
934
    case IMPORT_DATA:
805
934
      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
102
    default:
815
      /* xgettext:c-format */
816
102
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
817
102
        abfd, import_type);
818
102
      return false;
819
1.03k
    }
820
821
934
  switch (import_name_type)
822
934
    {
823
351
    case IMPORT_ORDINAL:
824
590
    case IMPORT_NAME:
825
828
    case IMPORT_NAME_NOPREFIX:
826
830
    case IMPORT_NAME_UNDECORATE:
827
830
      break;
828
829
104
    default:
830
      /* xgettext:c-format */
831
104
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
832
104
        abfd, import_name_type);
833
104
      return false;
834
934
    }
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
830
  vars.bim
844
830
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
845
830
  if (vars.bim == NULL)
846
0
    return false;
847
848
830
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
849
830
  vars.bim->buffer = ptr;
850
830
  vars.bim->size   = ILF_DATA_SIZE;
851
830
  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
830
  vars.sym_cache = (coff_symbol_type *) ptr;
857
830
  vars.sym_ptr   = (coff_symbol_type *) ptr;
858
830
  vars.sym_index = 0;
859
830
  ptr += SIZEOF_ILF_SYMS;
860
861
830
  vars.sym_table = (unsigned int *) ptr;
862
830
  vars.table_ptr = (unsigned int *) ptr;
863
830
  ptr += SIZEOF_ILF_SYM_TABLE;
864
865
830
  vars.native_syms = (combined_entry_type *) ptr;
866
830
  vars.native_ptr  = (combined_entry_type *) ptr;
867
830
  ptr += SIZEOF_ILF_NATIVE_SYMS;
868
869
830
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
870
830
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
871
830
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
872
873
830
  vars.esym_table = (SYMENT *) ptr;
874
830
  vars.esym_ptr   = (SYMENT *) ptr;
875
830
  ptr += SIZEOF_ILF_EXT_SYMS;
876
877
830
  vars.reltab   = (arelent *) ptr;
878
830
  vars.relcount = 0;
879
830
  ptr += SIZEOF_ILF_RELOCS;
880
881
830
  vars.int_reltab  = (struct internal_reloc *) ptr;
882
830
  ptr += SIZEOF_ILF_INT_RELOCS;
883
884
830
  vars.string_table = (char *) ptr;
885
830
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
886
830
  ptr += SIZEOF_ILF_STRINGS;
887
830
  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
830
#if GCC_VERSION >= 3000
897
830
  alignment = __alignof__ (struct coff_section_tdata);
898
#else
899
  alignment = 8;
900
#endif
901
830
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
902
903
830
  vars.data = ptr;
904
830
  vars.abfd = abfd;
905
830
  vars.sec_index = 0;
906
830
  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
830
  id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
916
830
  id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
917
830
  if (id4 == NULL || id5 == NULL)
918
0
    goto error_return;
919
920
  /* Fill in the contents of these sections.  */
921
830
  if (import_name_type == IMPORT_ORDINAL)
922
351
    {
923
351
      if (ordinal == 0)
924
  /* See PR 20907 for a reproducer.  */
925
4
  goto error_return;
926
927
#if defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) || defined(COFF_WITH_peLoongArch64)
928
      ((unsigned int *) id4->contents)[0] = ordinal;
929
      ((unsigned int *) id4->contents)[1] = 0x80000000;
930
      ((unsigned int *) id5->contents)[0] = ordinal;
931
      ((unsigned int *) id5->contents)[1] = 0x80000000;
932
#else
933
347
      * (unsigned int *) id4->contents = ordinal | 0x80000000;
934
347
      * (unsigned int *) id5->contents = ordinal | 0x80000000;
935
347
#endif
936
347
    }
937
479
  else
938
479
    {
939
479
      char * symbol;
940
479
      unsigned int len;
941
942
      /* Create .idata$6 - the Hint Name Table.  */
943
479
      id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
944
479
      if (id6 == NULL)
945
0
  goto error_return;
946
947
      /* If necessary, trim the import symbol name.  */
948
479
      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
479
      if (import_name_type != IMPORT_NAME)
958
240
  {
959
240
    char c = symbol[0];
960
961
    /* Check that we don't remove for targets with empty
962
       USER_LABEL_PREFIX the leading underscore.  */
963
240
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
964
240
        || c == '@' || c == '?')
965
1
      symbol++;
966
240
  }
967
968
479
      len = strlen (symbol);
969
479
      if (import_name_type == IMPORT_NAME_UNDECORATE)
970
2
  {
971
    /* Truncate at the first '@'.  */
972
2
    char *at = strchr (symbol, '@');
973
974
2
    if (at != NULL)
975
0
      len = at - symbol;
976
2
  }
977
978
479
      id6->contents[0] = ordinal & 0xff;
979
479
      id6->contents[1] = ordinal >> 8;
980
981
479
      memcpy ((char *) id6->contents + 2, symbol, len);
982
479
      id6->contents[len + 2] = '\0';
983
479
    }
984
985
826
  if (import_name_type != IMPORT_ORDINAL)
986
479
    {
987
479
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
988
479
      pe_ILF_save_relocs (&vars, id4);
989
990
479
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
991
479
      pe_ILF_save_relocs (&vars, id5);
992
479
    }
993
994
  /* Create an import symbol.  */
995
826
  pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
996
826
  imp_sym   = vars.sym_ptr_ptr - 1;
997
826
  imp_index = vars.sym_index - 1;
998
999
  /* Create extra sections depending upon the type of import we are dealing with.  */
1000
826
  switch (import_type)
1001
826
    {
1002
0
      int i;
1003
1004
585
    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
1.74k
      for (i = NUM_ENTRIES (jtab); i--;)
1009
1.74k
  {
1010
1.74k
    if (jtab[i].size == 0)
1011
585
      continue;
1012
1.16k
    if (jtab[i].magic == magic)
1013
585
      break;
1014
1.16k
  }
1015
      /* If we did not find a matching entry something is wrong.  */
1016
585
      if (i < 0)
1017
0
  abort ();
1018
1019
      /* Create the .text section.  */
1020
585
      text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
1021
585
      if (text == NULL)
1022
0
  goto error_return;
1023
1024
      /* Copy in the jump code.  */
1025
585
      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
585
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1051
585
            BFD_RELOC_32, (asymbol **) imp_sym,
1052
585
            imp_index);
1053
1054
585
      pe_ILF_save_relocs (& vars, text);
1055
585
      break;
1056
1057
241
    case IMPORT_DATA:
1058
241
      break;
1059
1060
0
    default:
1061
      /* XXX code not yet written.  */
1062
0
      abort ();
1063
826
    }
1064
1065
  /* Now create a symbol describing the imported value.  */
1066
826
  switch (import_type)
1067
826
    {
1068
585
    case IMPORT_CODE:
1069
585
      pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1070
585
          BSF_NOT_AT_END | BSF_FUNCTION);
1071
1072
585
      break;
1073
1074
241
    case IMPORT_DATA:
1075
      /* Nothing to do here.  */
1076
241
      break;
1077
1078
0
    default:
1079
      /* XXX code not yet written.  */
1080
0
      abort ();
1081
826
    }
1082
1083
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1084
826
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1085
826
  if (ptr)
1086
239
    * ptr = 0;
1087
826
  pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1088
826
  if (ptr)
1089
239
    * ptr = '.';
1090
1091
  /* Initialise the bfd.  */
1092
826
  memset (& internal_f, 0, sizeof (internal_f));
1093
1094
826
  internal_f.f_magic  = magic;
1095
826
  internal_f.f_symptr = 0;
1096
826
  internal_f.f_nsyms  = 0;
1097
826
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1098
1099
826
  if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
1100
826
      || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1101
0
    goto error_return;
1102
1103
826
  if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL)
1104
0
    goto error_return;
1105
1106
826
  obj_pe (abfd) = true;
1107
826
#ifdef THUMBPEMAGIC
1108
826
  if (vars.magic == THUMBPEMAGIC)
1109
    /* Stop some linker warnings about thumb code not supporting interworking.  */
1110
245
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1111
826
#endif
1112
1113
  /* Switch from file contents to memory contents.  */
1114
826
  bfd_cache_close (abfd);
1115
1116
826
  abfd->iostream = (void *) vars.bim;
1117
826
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1118
826
  abfd->iovec = &_bfd_memory_iovec;
1119
826
  abfd->where = 0;
1120
826
  abfd->origin = 0;
1121
826
  abfd->size = 0;
1122
826
  obj_sym_filepos (abfd) = 0;
1123
1124
  /* Point the bfd at the symbol table.  */
1125
826
  obj_symbols (abfd) = vars.sym_cache;
1126
826
  abfd->symcount = vars.sym_index;
1127
1128
826
  obj_raw_syments (abfd) = vars.native_syms;
1129
826
  obj_raw_syment_count (abfd) = vars.sym_index;
1130
1131
826
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1132
826
  obj_coff_keep_syms (abfd) = true;
1133
1134
826
  obj_convert (abfd) = vars.sym_table;
1135
826
  obj_conv_table_size (abfd) = vars.sym_index;
1136
1137
826
  obj_coff_strings (abfd) = vars.string_table;
1138
826
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1139
826
  obj_coff_keep_strings (abfd) = true;
1140
1141
826
  return true;
1142
1143
4
 error_return:
1144
4
  free (vars.bim->buffer);
1145
4
  free (vars.bim);
1146
4
  return false;
1147
826
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_build_a_bfd
pei-sh.c:pe_ILF_build_a_bfd
Line
Count
Source
786
953
{
787
953
  bfd_byte *       ptr;
788
953
  pe_ILF_vars      vars;
789
953
  struct internal_filehdr  internal_f;
790
953
  unsigned int       import_type;
791
953
  unsigned int       import_name_type;
792
953
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
793
953
  coff_symbol_type **    imp_sym;
794
953
  unsigned int       imp_index;
795
953
  intptr_t alignment;
796
797
  /* Decode and verify the types field of the ILF structure.  */
798
953
  import_type = types & 0x3;
799
953
  import_name_type = (types & 0x1c) >> 2;
800
801
953
  switch (import_type)
802
953
    {
803
944
    case IMPORT_CODE:
804
949
    case IMPORT_DATA:
805
949
      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
3
    default:
815
      /* xgettext:c-format */
816
3
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
817
3
        abfd, import_type);
818
3
      return false;
819
953
    }
820
821
949
  switch (import_name_type)
822
949
    {
823
240
    case IMPORT_ORDINAL:
824
475
    case IMPORT_NAME:
825
476
    case IMPORT_NAME_NOPREFIX:
826
946
    case IMPORT_NAME_UNDECORATE:
827
946
      break;
828
829
3
    default:
830
      /* xgettext:c-format */
831
3
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
832
3
        abfd, import_name_type);
833
3
      return false;
834
949
    }
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
946
  vars.bim
844
946
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
845
946
  if (vars.bim == NULL)
846
0
    return false;
847
848
946
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
849
946
  vars.bim->buffer = ptr;
850
946
  vars.bim->size   = ILF_DATA_SIZE;
851
946
  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
946
  vars.sym_cache = (coff_symbol_type *) ptr;
857
946
  vars.sym_ptr   = (coff_symbol_type *) ptr;
858
946
  vars.sym_index = 0;
859
946
  ptr += SIZEOF_ILF_SYMS;
860
861
946
  vars.sym_table = (unsigned int *) ptr;
862
946
  vars.table_ptr = (unsigned int *) ptr;
863
946
  ptr += SIZEOF_ILF_SYM_TABLE;
864
865
946
  vars.native_syms = (combined_entry_type *) ptr;
866
946
  vars.native_ptr  = (combined_entry_type *) ptr;
867
946
  ptr += SIZEOF_ILF_NATIVE_SYMS;
868
869
946
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
870
946
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
871
946
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
872
873
946
  vars.esym_table = (SYMENT *) ptr;
874
946
  vars.esym_ptr   = (SYMENT *) ptr;
875
946
  ptr += SIZEOF_ILF_EXT_SYMS;
876
877
946
  vars.reltab   = (arelent *) ptr;
878
946
  vars.relcount = 0;
879
946
  ptr += SIZEOF_ILF_RELOCS;
880
881
946
  vars.int_reltab  = (struct internal_reloc *) ptr;
882
946
  ptr += SIZEOF_ILF_INT_RELOCS;
883
884
946
  vars.string_table = (char *) ptr;
885
946
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
886
946
  ptr += SIZEOF_ILF_STRINGS;
887
946
  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
946
#if GCC_VERSION >= 3000
897
946
  alignment = __alignof__ (struct coff_section_tdata);
898
#else
899
  alignment = 8;
900
#endif
901
946
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
902
903
946
  vars.data = ptr;
904
946
  vars.abfd = abfd;
905
946
  vars.sec_index = 0;
906
946
  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
946
  id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
916
946
  id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
917
946
  if (id4 == NULL || id5 == NULL)
918
0
    goto error_return;
919
920
  /* Fill in the contents of these sections.  */
921
946
  if (import_name_type == IMPORT_ORDINAL)
922
240
    {
923
240
      if (ordinal == 0)
924
  /* See PR 20907 for a reproducer.  */
925
3
  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
237
      * (unsigned int *) id4->contents = ordinal | 0x80000000;
934
237
      * (unsigned int *) id5->contents = ordinal | 0x80000000;
935
237
#endif
936
237
    }
937
706
  else
938
706
    {
939
706
      char * symbol;
940
706
      unsigned int len;
941
942
      /* Create .idata$6 - the Hint Name Table.  */
943
706
      id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
944
706
      if (id6 == NULL)
945
0
  goto error_return;
946
947
      /* If necessary, trim the import symbol name.  */
948
706
      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
706
      if (import_name_type != IMPORT_NAME)
958
471
  {
959
471
    char c = symbol[0];
960
961
    /* Check that we don't remove for targets with empty
962
       USER_LABEL_PREFIX the leading underscore.  */
963
471
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
964
471
        || c == '@' || c == '?')
965
0
      symbol++;
966
471
  }
967
968
706
      len = strlen (symbol);
969
706
      if (import_name_type == IMPORT_NAME_UNDECORATE)
970
470
  {
971
    /* Truncate at the first '@'.  */
972
470
    char *at = strchr (symbol, '@');
973
974
470
    if (at != NULL)
975
235
      len = at - symbol;
976
470
  }
977
978
706
      id6->contents[0] = ordinal & 0xff;
979
706
      id6->contents[1] = ordinal >> 8;
980
981
706
      memcpy ((char *) id6->contents + 2, symbol, len);
982
706
      id6->contents[len + 2] = '\0';
983
706
    }
984
985
943
  if (import_name_type != IMPORT_ORDINAL)
986
706
    {
987
706
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
988
706
      pe_ILF_save_relocs (&vars, id4);
989
990
706
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
991
706
      pe_ILF_save_relocs (&vars, id5);
992
706
    }
993
994
  /* Create an import symbol.  */
995
943
  pe_ILF_make_a_symbol (& vars, "__imp_", symbol_name, id5, 0);
996
943
  imp_sym   = vars.sym_ptr_ptr - 1;
997
943
  imp_index = vars.sym_index - 1;
998
999
  /* Create extra sections depending upon the type of import we are dealing with.  */
1000
943
  switch (import_type)
1001
943
    {
1002
0
      int i;
1003
1004
941
    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
1.88k
      for (i = NUM_ENTRIES (jtab); i--;)
1009
1.88k
  {
1010
1.88k
    if (jtab[i].size == 0)
1011
941
      continue;
1012
941
    if (jtab[i].magic == magic)
1013
941
      break;
1014
941
  }
1015
      /* If we did not find a matching entry something is wrong.  */
1016
941
      if (i < 0)
1017
0
  abort ();
1018
1019
      /* Create the .text section.  */
1020
941
      text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
1021
941
      if (text == NULL)
1022
0
  goto error_return;
1023
1024
      /* Copy in the jump code.  */
1025
941
      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
941
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1051
941
            BFD_RELOC_32, (asymbol **) imp_sym,
1052
941
            imp_index);
1053
1054
941
      pe_ILF_save_relocs (& vars, text);
1055
941
      break;
1056
1057
2
    case IMPORT_DATA:
1058
2
      break;
1059
1060
0
    default:
1061
      /* XXX code not yet written.  */
1062
0
      abort ();
1063
943
    }
1064
1065
  /* Now create a symbol describing the imported value.  */
1066
943
  switch (import_type)
1067
943
    {
1068
941
    case IMPORT_CODE:
1069
941
      pe_ILF_make_a_symbol (& vars, "", symbol_name, text,
1070
941
          BSF_NOT_AT_END | BSF_FUNCTION);
1071
1072
941
      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
943
    }
1082
1083
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1084
943
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1085
943
  if (ptr)
1086
1
    * ptr = 0;
1087
943
  pe_ILF_make_a_symbol (& vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1088
943
  if (ptr)
1089
1
    * ptr = '.';
1090
1091
  /* Initialise the bfd.  */
1092
943
  memset (& internal_f, 0, sizeof (internal_f));
1093
1094
943
  internal_f.f_magic  = magic;
1095
943
  internal_f.f_symptr = 0;
1096
943
  internal_f.f_nsyms  = 0;
1097
943
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1098
1099
943
  if (   ! bfd_set_start_address (abfd, (bfd_vma) 0)
1100
943
      || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
1101
0
    goto error_return;
1102
1103
943
  if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL)
1104
0
    goto error_return;
1105
1106
943
  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
943
  bfd_cache_close (abfd);
1115
1116
943
  abfd->iostream = (void *) vars.bim;
1117
943
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1118
943
  abfd->iovec = &_bfd_memory_iovec;
1119
943
  abfd->where = 0;
1120
943
  abfd->origin = 0;
1121
943
  abfd->size = 0;
1122
943
  obj_sym_filepos (abfd) = 0;
1123
1124
  /* Point the bfd at the symbol table.  */
1125
943
  obj_symbols (abfd) = vars.sym_cache;
1126
943
  abfd->symcount = vars.sym_index;
1127
1128
943
  obj_raw_syments (abfd) = vars.native_syms;
1129
943
  obj_raw_syment_count (abfd) = vars.sym_index;
1130
1131
943
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1132
943
  obj_coff_keep_syms (abfd) = true;
1133
1134
943
  obj_convert (abfd) = vars.sym_table;
1135
943
  obj_conv_table_size (abfd) = vars.sym_index;
1136
1137
943
  obj_coff_strings (abfd) = vars.string_table;
1138
943
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1139
943
  obj_coff_keep_strings (abfd) = true;
1140
1141
943
  return true;
1142
1143
3
 error_return:
1144
3
  free (vars.bim->buffer);
1145
3
  free (vars.bim);
1146
3
  return false;
1147
943
}
1148
1149
/* Cleanup function, returned from check_format hook.  */
1150
1151
static void
1152
pe_ILF_cleanup (bfd *abfd)
1153
20
{
1154
20
  coff_object_cleanup (abfd);
1155
1156
20
  struct bfd_in_memory *bim = abfd->iostream;
1157
20
  free (bim->buffer);
1158
20
  free (bim);
1159
20
  abfd->iostream = NULL;
1160
20
}
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
10
{
1154
10
  coff_object_cleanup (abfd);
1155
1156
10
  struct bfd_in_memory *bim = abfd->iostream;
1157
10
  free (bim->buffer);
1158
10
  free (bim);
1159
10
  abfd->iostream = NULL;
1160
10
}
pei-arm.c:pe_ILF_cleanup
Line
Count
Source
1153
10
{
1154
10
  coff_object_cleanup (abfd);
1155
1156
10
  struct bfd_in_memory *bim = abfd->iostream;
1157
10
  free (bim->buffer);
1158
10
  free (bim);
1159
10
  abfd->iostream = NULL;
1160
10
}
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
42.0k
{
1168
42.0k
  bfd_byte    buffer[14];
1169
42.0k
  bfd_byte *    ptr;
1170
42.0k
  char *    symbol_name;
1171
42.0k
  char *    source_dll;
1172
42.0k
  unsigned int    machine;
1173
42.0k
  bfd_size_type   size;
1174
42.0k
  unsigned int    ordinal;
1175
42.0k
  unsigned int    types;
1176
42.0k
  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
42.0k
  if (bfd_read (buffer, 14, abfd) != 14)
1181
62
    return NULL;
1182
1183
41.9k
  ptr = buffer;
1184
1185
41.9k
  machine = H_GET_16 (abfd, ptr);
1186
41.9k
  ptr += 2;
1187
1188
  /* Check that the machine type is recognised.  */
1189
41.9k
  magic = 0;
1190
1191
41.9k
  switch (machine)
1192
41.9k
    {
1193
835
    case IMAGE_FILE_MACHINE_UNKNOWN:
1194
843
    case IMAGE_FILE_MACHINE_ALPHA:
1195
843
    case IMAGE_FILE_MACHINE_ALPHA64:
1196
867
    case IMAGE_FILE_MACHINE_IA64:
1197
867
      break;
1198
1199
5.25k
    case IMAGE_FILE_MACHINE_I386:
1200
#ifdef I386MAGIC
1201
774
      magic = I386MAGIC;
1202
#endif
1203
5.25k
      break;
1204
1205
12.3k
    case IMAGE_FILE_MACHINE_AMD64:
1206
#ifdef AMD64MAGIC
1207
1.67k
      magic = AMD64MAGIC;
1208
#endif
1209
12.3k
      break;
1210
1211
8
    case IMAGE_FILE_MACHINE_R3000:
1212
16
    case IMAGE_FILE_MACHINE_R4000:
1213
24
    case IMAGE_FILE_MACHINE_R10000:
1214
1215
32
    case IMAGE_FILE_MACHINE_MIPS16:
1216
32
    case IMAGE_FILE_MACHINE_MIPSFPU:
1217
40
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1218
#ifdef MIPS_ARCH_MAGIC_WINCE
1219
      magic = MIPS_ARCH_MAGIC_WINCE;
1220
#endif
1221
40
      break;
1222
1223
4.34k
    case IMAGE_FILE_MACHINE_SH3:
1224
7.47k
    case IMAGE_FILE_MACHINE_SH4:
1225
#ifdef SH_ARCH_MAGIC_WINCE
1226
1.17k
      magic = SH_ARCH_MAGIC_WINCE;
1227
#endif
1228
7.47k
      break;
1229
1230
6.15k
    case IMAGE_FILE_MACHINE_ARM:
1231
#ifdef ARMPEMAGIC
1232
1.83k
      magic = ARMPEMAGIC;
1233
#endif
1234
6.15k
      break;
1235
1236
756
    case IMAGE_FILE_MACHINE_ARM64:
1237
#ifdef AARCH64MAGIC
1238
532
      magic = AARCH64MAGIC;
1239
#endif
1240
756
      break;
1241
1242
6.40k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1243
#ifdef LOONGARCH64MAGIC
1244
803
      magic = LOONGARCH64MAGIC;
1245
#endif
1246
6.40k
      break;
1247
1248
684
    case IMAGE_FILE_MACHINE_THUMB:
1249
#ifdef THUMBPEMAGIC
1250
      {
1251
  extern const bfd_target TARGET_LITTLE_SYM;
1252
1253
291
  if (abfd->xvec == & TARGET_LITTLE_SYM)
1254
289
    magic = THUMBPEMAGIC;
1255
      }
1256
#endif
1257
684
      break;
1258
1259
0
    case IMAGE_FILE_MACHINE_POWERPC:
1260
      /* We no longer support PowerPC.  */
1261
2.01k
    default:
1262
2.01k
      _bfd_error_handler
1263
  /* xgettext:c-format */
1264
2.01k
  (_("%pB: unrecognised machine type (0x%x)"
1265
2.01k
     " in Import Library Format archive"),
1266
2.01k
   abfd, machine);
1267
2.01k
      bfd_set_error (bfd_error_malformed_archive);
1268
1269
2.01k
      return NULL;
1270
0
      break;
1271
41.9k
    }
1272
1273
39.9k
  if (magic == 0)
1274
32.9k
    {
1275
32.9k
      _bfd_error_handler
1276
  /* xgettext:c-format */
1277
32.9k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1278
32.9k
     " in Import Library Format archive"),
1279
32.9k
   abfd, machine);
1280
32.9k
      bfd_set_error (bfd_error_wrong_format);
1281
1282
32.9k
      return NULL;
1283
32.9k
    }
1284
1285
  /* We do not bother to check the date.
1286
     date = H_GET_32 (abfd, ptr);  */
1287
7.08k
  ptr += 4;
1288
1289
7.08k
  size = H_GET_32 (abfd, ptr);
1290
7.08k
  ptr += 4;
1291
1292
7.08k
  if (size == 0)
1293
626
    {
1294
626
      _bfd_error_handler
1295
626
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1296
626
      bfd_set_error (bfd_error_malformed_archive);
1297
1298
626
      return NULL;
1299
626
    }
1300
1301
6.45k
  ordinal = H_GET_16 (abfd, ptr);
1302
6.45k
  ptr += 2;
1303
1304
6.45k
  types = H_GET_16 (abfd, ptr);
1305
  /* ptr += 2; */
1306
1307
  /* Now read in the two strings that follow.  */
1308
6.45k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1309
6.45k
  if (ptr == NULL)
1310
1.08k
    return NULL;
1311
1312
5.36k
  symbol_name = (char *) ptr;
1313
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1314
5.36k
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1315
1316
  /* Verify that the strings are null terminated.  */
1317
5.36k
  if (ptr[size - 1] != 0
1318
5.36k
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1319
541
    {
1320
541
      _bfd_error_handler
1321
541
  (_("%pB: string not null terminated in ILF object file"), abfd);
1322
541
      bfd_set_error (bfd_error_malformed_archive);
1323
541
      bfd_release (abfd, ptr);
1324
541
      return NULL;
1325
541
    }
1326
1327
  /* Now construct the bfd.  */
1328
4.82k
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1329
4.82k
          source_dll, ordinal, types))
1330
870
    {
1331
870
      bfd_release (abfd, ptr);
1332
870
      return NULL;
1333
870
    }
1334
1335
3.95k
  return pe_ILF_cleanup;
1336
4.82k
}
pei-i386.c:pe_ILF_object_p
Line
Count
Source
1167
5.46k
{
1168
5.46k
  bfd_byte    buffer[14];
1169
5.46k
  bfd_byte *    ptr;
1170
5.46k
  char *    symbol_name;
1171
5.46k
  char *    source_dll;
1172
5.46k
  unsigned int    machine;
1173
5.46k
  bfd_size_type   size;
1174
5.46k
  unsigned int    ordinal;
1175
5.46k
  unsigned int    types;
1176
5.46k
  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
5.46k
  if (bfd_read (buffer, 14, abfd) != 14)
1181
7
    return NULL;
1182
1183
5.45k
  ptr = buffer;
1184
1185
5.45k
  machine = H_GET_16 (abfd, ptr);
1186
5.45k
  ptr += 2;
1187
1188
  /* Check that the machine type is recognised.  */
1189
5.45k
  magic = 0;
1190
1191
5.45k
  switch (machine)
1192
5.45k
    {
1193
104
    case IMAGE_FILE_MACHINE_UNKNOWN:
1194
105
    case IMAGE_FILE_MACHINE_ALPHA:
1195
105
    case IMAGE_FILE_MACHINE_ALPHA64:
1196
108
    case IMAGE_FILE_MACHINE_IA64:
1197
108
      break;
1198
1199
774
    case IMAGE_FILE_MACHINE_I386:
1200
774
#ifdef I386MAGIC
1201
774
      magic = I386MAGIC;
1202
774
#endif
1203
774
      break;
1204
1205
1.67k
    case IMAGE_FILE_MACHINE_AMD64:
1206
#ifdef AMD64MAGIC
1207
      magic = AMD64MAGIC;
1208
#endif
1209
1.67k
      break;
1210
1211
1
    case IMAGE_FILE_MACHINE_R3000:
1212
2
    case IMAGE_FILE_MACHINE_R4000:
1213
3
    case IMAGE_FILE_MACHINE_R10000:
1214
1215
4
    case IMAGE_FILE_MACHINE_MIPS16:
1216
4
    case IMAGE_FILE_MACHINE_MIPSFPU:
1217
5
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1218
#ifdef MIPS_ARCH_MAGIC_WINCE
1219
      magic = MIPS_ARCH_MAGIC_WINCE;
1220
#endif
1221
5
      break;
1222
1223
717
    case IMAGE_FILE_MACHINE_SH3:
1224
1.16k
    case IMAGE_FILE_MACHINE_SH4:
1225
#ifdef SH_ARCH_MAGIC_WINCE
1226
      magic = SH_ARCH_MAGIC_WINCE;
1227
#endif
1228
1.16k
      break;
1229
1230
622
    case IMAGE_FILE_MACHINE_ARM:
1231
#ifdef ARMPEMAGIC
1232
      magic = ARMPEMAGIC;
1233
#endif
1234
622
      break;
1235
1236
32
    case IMAGE_FILE_MACHINE_ARM64:
1237
#ifdef AARCH64MAGIC
1238
      magic = AARCH64MAGIC;
1239
#endif
1240
32
      break;
1241
1242
800
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1243
#ifdef LOONGARCH64MAGIC
1244
      magic = LOONGARCH64MAGIC;
1245
#endif
1246
800
      break;
1247
1248
26
    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
26
      break;
1258
1259
0
    case IMAGE_FILE_MACHINE_POWERPC:
1260
      /* We no longer support PowerPC.  */
1261
247
    default:
1262
247
      _bfd_error_handler
1263
  /* xgettext:c-format */
1264
247
  (_("%pB: unrecognised machine type (0x%x)"
1265
247
     " in Import Library Format archive"),
1266
247
   abfd, machine);
1267
247
      bfd_set_error (bfd_error_malformed_archive);
1268
1269
247
      return NULL;
1270
0
      break;
1271
5.45k
    }
1272
1273
5.20k
  if (magic == 0)
1274
4.43k
    {
1275
4.43k
      _bfd_error_handler
1276
  /* xgettext:c-format */
1277
4.43k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1278
4.43k
     " in Import Library Format archive"),
1279
4.43k
   abfd, machine);
1280
4.43k
      bfd_set_error (bfd_error_wrong_format);
1281
1282
4.43k
      return NULL;
1283
4.43k
    }
1284
1285
  /* We do not bother to check the date.
1286
     date = H_GET_32 (abfd, ptr);  */
1287
774
  ptr += 4;
1288
1289
774
  size = H_GET_32 (abfd, ptr);
1290
774
  ptr += 4;
1291
1292
774
  if (size == 0)
1293
104
    {
1294
104
      _bfd_error_handler
1295
104
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1296
104
      bfd_set_error (bfd_error_malformed_archive);
1297
1298
104
      return NULL;
1299
104
    }
1300
1301
670
  ordinal = H_GET_16 (abfd, ptr);
1302
670
  ptr += 2;
1303
1304
670
  types = H_GET_16 (abfd, ptr);
1305
  /* ptr += 2; */
1306
1307
  /* Now read in the two strings that follow.  */
1308
670
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1309
670
  if (ptr == NULL)
1310
211
    return NULL;
1311
1312
459
  symbol_name = (char *) ptr;
1313
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1314
459
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1315
1316
  /* Verify that the strings are null terminated.  */
1317
459
  if (ptr[size - 1] != 0
1318
459
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1319
105
    {
1320
105
      _bfd_error_handler
1321
105
  (_("%pB: string not null terminated in ILF object file"), abfd);
1322
105
      bfd_set_error (bfd_error_malformed_archive);
1323
105
      bfd_release (abfd, ptr);
1324
105
      return NULL;
1325
105
    }
1326
1327
  /* Now construct the bfd.  */
1328
354
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1329
354
          source_dll, ordinal, types))
1330
113
    {
1331
113
      bfd_release (abfd, ptr);
1332
113
      return NULL;
1333
113
    }
1334
1335
241
  return pe_ILF_cleanup;
1336
354
}
pei-x86_64.c:pe_ILF_object_p
Line
Count
Source
1167
4.29k
{
1168
4.29k
  bfd_byte    buffer[14];
1169
4.29k
  bfd_byte *    ptr;
1170
4.29k
  char *    symbol_name;
1171
4.29k
  char *    source_dll;
1172
4.29k
  unsigned int    machine;
1173
4.29k
  bfd_size_type   size;
1174
4.29k
  unsigned int    ordinal;
1175
4.29k
  unsigned int    types;
1176
4.29k
  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
4.29k
  if (bfd_read (buffer, 14, abfd) != 14)
1181
7
    return NULL;
1182
1183
4.29k
  ptr = buffer;
1184
1185
4.29k
  machine = H_GET_16 (abfd, ptr);
1186
4.29k
  ptr += 2;
1187
1188
  /* Check that the machine type is recognised.  */
1189
4.29k
  magic = 0;
1190
1191
4.29k
  switch (machine)
1192
4.29k
    {
1193
104
    case IMAGE_FILE_MACHINE_UNKNOWN:
1194
105
    case IMAGE_FILE_MACHINE_ALPHA:
1195
105
    case IMAGE_FILE_MACHINE_ALPHA64:
1196
108
    case IMAGE_FILE_MACHINE_IA64:
1197
108
      break;
1198
1199
540
    case IMAGE_FILE_MACHINE_I386:
1200
#ifdef I386MAGIC
1201
      magic = I386MAGIC;
1202
#endif
1203
540
      break;
1204
1205
1.67k
    case IMAGE_FILE_MACHINE_AMD64:
1206
1.67k
#ifdef AMD64MAGIC
1207
1.67k
      magic = AMD64MAGIC;
1208
1.67k
#endif
1209
1.67k
      break;
1210
1211
1
    case IMAGE_FILE_MACHINE_R3000:
1212
2
    case IMAGE_FILE_MACHINE_R4000:
1213
3
    case IMAGE_FILE_MACHINE_R10000:
1214
1215
4
    case IMAGE_FILE_MACHINE_MIPS16:
1216
4
    case IMAGE_FILE_MACHINE_MIPSFPU:
1217
5
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1218
#ifdef MIPS_ARCH_MAGIC_WINCE
1219
      magic = MIPS_ARCH_MAGIC_WINCE;
1220
#endif
1221
5
      break;
1222
1223
18
    case IMAGE_FILE_MACHINE_SH3:
1224
235
    case IMAGE_FILE_MACHINE_SH4:
1225
#ifdef SH_ARCH_MAGIC_WINCE
1226
      magic = SH_ARCH_MAGIC_WINCE;
1227
#endif
1228
235
      break;
1229
1230
622
    case IMAGE_FILE_MACHINE_ARM:
1231
#ifdef ARMPEMAGIC
1232
      magic = ARMPEMAGIC;
1233
#endif
1234
622
      break;
1235
1236
32
    case IMAGE_FILE_MACHINE_ARM64:
1237
#ifdef AARCH64MAGIC
1238
      magic = AARCH64MAGIC;
1239
#endif
1240
32
      break;
1241
1242
800
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1243
#ifdef LOONGARCH64MAGIC
1244
      magic = LOONGARCH64MAGIC;
1245
#endif
1246
800
      break;
1247
1248
26
    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
26
      break;
1258
1259
0
    case IMAGE_FILE_MACHINE_POWERPC:
1260
      /* We no longer support PowerPC.  */
1261
247
    default:
1262
247
      _bfd_error_handler
1263
  /* xgettext:c-format */
1264
247
  (_("%pB: unrecognised machine type (0x%x)"
1265
247
     " in Import Library Format archive"),
1266
247
   abfd, machine);
1267
247
      bfd_set_error (bfd_error_malformed_archive);
1268
1269
247
      return NULL;
1270
0
      break;
1271
4.29k
    }
1272
1273
4.04k
  if (magic == 0)
1274
2.36k
    {
1275
2.36k
      _bfd_error_handler
1276
  /* xgettext:c-format */
1277
2.36k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1278
2.36k
     " in Import Library Format archive"),
1279
2.36k
   abfd, machine);
1280
2.36k
      bfd_set_error (bfd_error_wrong_format);
1281
1282
2.36k
      return NULL;
1283
2.36k
    }
1284
1285
  /* We do not bother to check the date.
1286
     date = H_GET_32 (abfd, ptr);  */
1287
1.67k
  ptr += 4;
1288
1289
1.67k
  size = H_GET_32 (abfd, ptr);
1290
1.67k
  ptr += 4;
1291
1292
1.67k
  if (size == 0)
1293
105
    {
1294
105
      _bfd_error_handler
1295
105
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1296
105
      bfd_set_error (bfd_error_malformed_archive);
1297
1298
105
      return NULL;
1299
105
    }
1300
1301
1.57k
  ordinal = H_GET_16 (abfd, ptr);
1302
1.57k
  ptr += 2;
1303
1304
1.57k
  types = H_GET_16 (abfd, ptr);
1305
  /* ptr += 2; */
1306
1307
  /* Now read in the two strings that follow.  */
1308
1.57k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1309
1.57k
  if (ptr == NULL)
1310
211
    return NULL;
1311
1312
1.36k
  symbol_name = (char *) ptr;
1313
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1314
1.36k
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1315
1316
  /* Verify that the strings are null terminated.  */
1317
1.36k
  if (ptr[size - 1] != 0
1318
1.36k
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1319
104
    {
1320
104
      _bfd_error_handler
1321
104
  (_("%pB: string not null terminated in ILF object file"), abfd);
1322
104
      bfd_set_error (bfd_error_malformed_archive);
1323
104
      bfd_release (abfd, ptr);
1324
104
      return NULL;
1325
104
    }
1326
1327
  /* Now construct the bfd.  */
1328
1.25k
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1329
1.25k
          source_dll, ordinal, types))
1330
208
    {
1331
208
      bfd_release (abfd, ptr);
1332
208
      return NULL;
1333
208
    }
1334
1335
1.04k
  return pe_ILF_cleanup;
1336
1.25k
}
pei-aarch64.c:pe_ILF_object_p
Line
Count
Source
1167
6.77k
{
1168
6.77k
  bfd_byte    buffer[14];
1169
6.77k
  bfd_byte *    ptr;
1170
6.77k
  char *    symbol_name;
1171
6.77k
  char *    source_dll;
1172
6.77k
  unsigned int    machine;
1173
6.77k
  bfd_size_type   size;
1174
6.77k
  unsigned int    ordinal;
1175
6.77k
  unsigned int    types;
1176
6.77k
  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
6.77k
  if (bfd_read (buffer, 14, abfd) != 14)
1181
7
    return NULL;
1182
1183
6.76k
  ptr = buffer;
1184
1185
6.76k
  machine = H_GET_16 (abfd, ptr);
1186
6.76k
  ptr += 2;
1187
1188
  /* Check that the machine type is recognised.  */
1189
6.76k
  magic = 0;
1190
1191
6.76k
  switch (machine)
1192
6.76k
    {
1193
104
    case IMAGE_FILE_MACHINE_UNKNOWN:
1194
105
    case IMAGE_FILE_MACHINE_ALPHA:
1195
105
    case IMAGE_FILE_MACHINE_ALPHA64:
1196
108
    case IMAGE_FILE_MACHINE_IA64:
1197
108
      break;
1198
1199
773
    case IMAGE_FILE_MACHINE_I386:
1200
#ifdef I386MAGIC
1201
      magic = I386MAGIC;
1202
#endif
1203
773
      break;
1204
1205
1.67k
    case IMAGE_FILE_MACHINE_AMD64:
1206
#ifdef AMD64MAGIC
1207
      magic = AMD64MAGIC;
1208
#endif
1209
1.67k
      break;
1210
1211
1
    case IMAGE_FILE_MACHINE_R3000:
1212
2
    case IMAGE_FILE_MACHINE_R4000:
1213
3
    case IMAGE_FILE_MACHINE_R10000:
1214
1215
4
    case IMAGE_FILE_MACHINE_MIPS16:
1216
4
    case IMAGE_FILE_MACHINE_MIPSFPU:
1217
5
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1218
#ifdef MIPS_ARCH_MAGIC_WINCE
1219
      magic = MIPS_ARCH_MAGIC_WINCE;
1220
#endif
1221
5
      break;
1222
1223
717
    case IMAGE_FILE_MACHINE_SH3:
1224
1.16k
    case IMAGE_FILE_MACHINE_SH4:
1225
#ifdef SH_ARCH_MAGIC_WINCE
1226
      magic = SH_ARCH_MAGIC_WINCE;
1227
#endif
1228
1.16k
      break;
1229
1230
1.19k
    case IMAGE_FILE_MACHINE_ARM:
1231
#ifdef ARMPEMAGIC
1232
      magic = ARMPEMAGIC;
1233
#endif
1234
1.19k
      break;
1235
1236
532
    case IMAGE_FILE_MACHINE_ARM64:
1237
532
#ifdef AARCH64MAGIC
1238
532
      magic = AARCH64MAGIC;
1239
532
#endif
1240
532
      break;
1241
1242
800
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1243
#ifdef LOONGARCH64MAGIC
1244
      magic = LOONGARCH64MAGIC;
1245
#endif
1246
800
      break;
1247
1248
262
    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
262
      break;
1258
1259
0
    case IMAGE_FILE_MACHINE_POWERPC:
1260
      /* We no longer support PowerPC.  */
1261
247
    default:
1262
247
      _bfd_error_handler
1263
  /* xgettext:c-format */
1264
247
  (_("%pB: unrecognised machine type (0x%x)"
1265
247
     " in Import Library Format archive"),
1266
247
   abfd, machine);
1267
247
      bfd_set_error (bfd_error_malformed_archive);
1268
1269
247
      return NULL;
1270
0
      break;
1271
6.76k
    }
1272
1273
6.51k
  if (magic == 0)
1274
5.98k
    {
1275
5.98k
      _bfd_error_handler
1276
  /* xgettext:c-format */
1277
5.98k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1278
5.98k
     " in Import Library Format archive"),
1279
5.98k
   abfd, machine);
1280
5.98k
      bfd_set_error (bfd_error_wrong_format);
1281
1282
5.98k
      return NULL;
1283
5.98k
    }
1284
1285
  /* We do not bother to check the date.
1286
     date = H_GET_32 (abfd, ptr);  */
1287
532
  ptr += 4;
1288
1289
532
  size = H_GET_32 (abfd, ptr);
1290
532
  ptr += 4;
1291
1292
532
  if (size == 0)
1293
3
    {
1294
3
      _bfd_error_handler
1295
3
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1296
3
      bfd_set_error (bfd_error_malformed_archive);
1297
1298
3
      return NULL;
1299
3
    }
1300
1301
529
  ordinal = H_GET_16 (abfd, ptr);
1302
529
  ptr += 2;
1303
1304
529
  types = H_GET_16 (abfd, ptr);
1305
  /* ptr += 2; */
1306
1307
  /* Now read in the two strings that follow.  */
1308
529
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1309
529
  if (ptr == NULL)
1310
7
    return NULL;
1311
1312
522
  symbol_name = (char *) ptr;
1313
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1314
522
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1315
1316
  /* Verify that the strings are null terminated.  */
1317
522
  if (ptr[size - 1] != 0
1318
522
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1319
7
    {
1320
7
      _bfd_error_handler
1321
7
  (_("%pB: string not null terminated in ILF object file"), abfd);
1322
7
      bfd_set_error (bfd_error_malformed_archive);
1323
7
      bfd_release (abfd, ptr);
1324
7
      return NULL;
1325
7
    }
1326
1327
  /* Now construct the bfd.  */
1328
515
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1329
515
          source_dll, ordinal, types))
1330
6
    {
1331
6
      bfd_release (abfd, ptr);
1332
6
      return NULL;
1333
6
    }
1334
1335
509
  return pe_ILF_cleanup;
1336
515
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_object_p
pei-loongarch64.c:pe_ILF_object_p
Line
Count
Source
1167
3.26k
{
1168
3.26k
  bfd_byte    buffer[14];
1169
3.26k
  bfd_byte *    ptr;
1170
3.26k
  char *    symbol_name;
1171
3.26k
  char *    source_dll;
1172
3.26k
  unsigned int    machine;
1173
3.26k
  bfd_size_type   size;
1174
3.26k
  unsigned int    ordinal;
1175
3.26k
  unsigned int    types;
1176
3.26k
  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
3.26k
  if (bfd_read (buffer, 14, abfd) != 14)
1181
7
    return NULL;
1182
1183
3.25k
  ptr = buffer;
1184
1185
3.25k
  machine = H_GET_16 (abfd, ptr);
1186
3.25k
  ptr += 2;
1187
1188
  /* Check that the machine type is recognised.  */
1189
3.25k
  magic = 0;
1190
1191
3.25k
  switch (machine)
1192
3.25k
    {
1193
104
    case IMAGE_FILE_MACHINE_UNKNOWN:
1194
105
    case IMAGE_FILE_MACHINE_ALPHA:
1195
105
    case IMAGE_FILE_MACHINE_ALPHA64:
1196
108
    case IMAGE_FILE_MACHINE_IA64:
1197
108
      break;
1198
1199
540
    case IMAGE_FILE_MACHINE_I386:
1200
#ifdef I386MAGIC
1201
      magic = I386MAGIC;
1202
#endif
1203
540
      break;
1204
1205
639
    case IMAGE_FILE_MACHINE_AMD64:
1206
#ifdef AMD64MAGIC
1207
      magic = AMD64MAGIC;
1208
#endif
1209
639
      break;
1210
1211
1
    case IMAGE_FILE_MACHINE_R3000:
1212
2
    case IMAGE_FILE_MACHINE_R4000:
1213
3
    case IMAGE_FILE_MACHINE_R10000:
1214
1215
4
    case IMAGE_FILE_MACHINE_MIPS16:
1216
4
    case IMAGE_FILE_MACHINE_MIPSFPU:
1217
5
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1218
#ifdef MIPS_ARCH_MAGIC_WINCE
1219
      magic = MIPS_ARCH_MAGIC_WINCE;
1220
#endif
1221
5
      break;
1222
1223
18
    case IMAGE_FILE_MACHINE_SH3:
1224
235
    case IMAGE_FILE_MACHINE_SH4:
1225
#ifdef SH_ARCH_MAGIC_WINCE
1226
      magic = SH_ARCH_MAGIC_WINCE;
1227
#endif
1228
235
      break;
1229
1230
622
    case IMAGE_FILE_MACHINE_ARM:
1231
#ifdef ARMPEMAGIC
1232
      magic = ARMPEMAGIC;
1233
#endif
1234
622
      break;
1235
1236
32
    case IMAGE_FILE_MACHINE_ARM64:
1237
#ifdef AARCH64MAGIC
1238
      magic = AARCH64MAGIC;
1239
#endif
1240
32
      break;
1241
1242
803
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1243
803
#ifdef LOONGARCH64MAGIC
1244
803
      magic = LOONGARCH64MAGIC;
1245
803
#endif
1246
803
      break;
1247
1248
26
    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
26
      break;
1258
1259
0
    case IMAGE_FILE_MACHINE_POWERPC:
1260
      /* We no longer support PowerPC.  */
1261
247
    default:
1262
247
      _bfd_error_handler
1263
  /* xgettext:c-format */
1264
247
  (_("%pB: unrecognised machine type (0x%x)"
1265
247
     " in Import Library Format archive"),
1266
247
   abfd, machine);
1267
247
      bfd_set_error (bfd_error_malformed_archive);
1268
1269
247
      return NULL;
1270
0
      break;
1271
3.25k
    }
1272
1273
3.01k
  if (magic == 0)
1274
2.20k
    {
1275
2.20k
      _bfd_error_handler
1276
  /* xgettext:c-format */
1277
2.20k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1278
2.20k
     " in Import Library Format archive"),
1279
2.20k
   abfd, machine);
1280
2.20k
      bfd_set_error (bfd_error_wrong_format);
1281
1282
2.20k
      return NULL;
1283
2.20k
    }
1284
1285
  /* We do not bother to check the date.
1286
     date = H_GET_32 (abfd, ptr);  */
1287
803
  ptr += 4;
1288
1289
803
  size = H_GET_32 (abfd, ptr);
1290
803
  ptr += 4;
1291
1292
803
  if (size == 0)
1293
104
    {
1294
104
      _bfd_error_handler
1295
104
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1296
104
      bfd_set_error (bfd_error_malformed_archive);
1297
1298
104
      return NULL;
1299
104
    }
1300
1301
699
  ordinal = H_GET_16 (abfd, ptr);
1302
699
  ptr += 2;
1303
1304
699
  types = H_GET_16 (abfd, ptr);
1305
  /* ptr += 2; */
1306
1307
  /* Now read in the two strings that follow.  */
1308
699
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1309
699
  if (ptr == NULL)
1310
108
    return NULL;
1311
1312
591
  symbol_name = (char *) ptr;
1313
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1314
591
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1315
1316
  /* Verify that the strings are null terminated.  */
1317
591
  if (ptr[size - 1] != 0
1318
591
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1319
105
    {
1320
105
      _bfd_error_handler
1321
105
  (_("%pB: string not null terminated in ILF object file"), abfd);
1322
105
      bfd_set_error (bfd_error_malformed_archive);
1323
105
      bfd_release (abfd, ptr);
1324
105
      return NULL;
1325
105
    }
1326
1327
  /* Now construct the bfd.  */
1328
486
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1329
486
          source_dll, ordinal, types))
1330
109
    {
1331
109
      bfd_release (abfd, ptr);
1332
109
      return NULL;
1333
109
    }
1334
1335
377
  return pe_ILF_cleanup;
1336
486
}
pei-arm-wince.c:pe_ILF_object_p
Line
Count
Source
1167
5.48k
{
1168
5.48k
  bfd_byte    buffer[14];
1169
5.48k
  bfd_byte *    ptr;
1170
5.48k
  char *    symbol_name;
1171
5.48k
  char *    source_dll;
1172
5.48k
  unsigned int    machine;
1173
5.48k
  bfd_size_type   size;
1174
5.48k
  unsigned int    ordinal;
1175
5.48k
  unsigned int    types;
1176
5.48k
  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
5.48k
  if (bfd_read (buffer, 14, abfd) != 14)
1181
9
    return NULL;
1182
1183
5.47k
  ptr = buffer;
1184
1185
5.47k
  machine = H_GET_16 (abfd, ptr);
1186
5.47k
  ptr += 2;
1187
1188
  /* Check that the machine type is recognised.  */
1189
5.47k
  magic = 0;
1190
1191
5.47k
  switch (machine)
1192
5.47k
    {
1193
105
    case IMAGE_FILE_MACHINE_UNKNOWN:
1194
106
    case IMAGE_FILE_MACHINE_ALPHA:
1195
106
    case IMAGE_FILE_MACHINE_ALPHA64:
1196
109
    case IMAGE_FILE_MACHINE_IA64:
1197
109
      break;
1198
1199
773
    case IMAGE_FILE_MACHINE_I386:
1200
#ifdef I386MAGIC
1201
      magic = I386MAGIC;
1202
#endif
1203
773
      break;
1204
1205
1.67k
    case IMAGE_FILE_MACHINE_AMD64:
1206
#ifdef AMD64MAGIC
1207
      magic = AMD64MAGIC;
1208
#endif
1209
1.67k
      break;
1210
1211
1
    case IMAGE_FILE_MACHINE_R3000:
1212
2
    case IMAGE_FILE_MACHINE_R4000:
1213
3
    case IMAGE_FILE_MACHINE_R10000:
1214
1215
4
    case IMAGE_FILE_MACHINE_MIPS16:
1216
4
    case IMAGE_FILE_MACHINE_MIPSFPU:
1217
5
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1218
#ifdef MIPS_ARCH_MAGIC_WINCE
1219
      magic = MIPS_ARCH_MAGIC_WINCE;
1220
#endif
1221
5
      break;
1222
1223
717
    case IMAGE_FILE_MACHINE_SH3:
1224
1.16k
    case IMAGE_FILE_MACHINE_SH4:
1225
#ifdef SH_ARCH_MAGIC_WINCE
1226
      magic = SH_ARCH_MAGIC_WINCE;
1227
#endif
1228
1.16k
      break;
1229
1230
630
    case IMAGE_FILE_MACHINE_ARM:
1231
630
#ifdef ARMPEMAGIC
1232
630
      magic = ARMPEMAGIC;
1233
630
#endif
1234
630
      break;
1235
1236
32
    case IMAGE_FILE_MACHINE_ARM64:
1237
#ifdef AARCH64MAGIC
1238
      magic = AARCH64MAGIC;
1239
#endif
1240
32
      break;
1241
1242
800
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1243
#ifdef LOONGARCH64MAGIC
1244
      magic = LOONGARCH64MAGIC;
1245
#endif
1246
800
      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
26
    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
259
    default:
1262
259
      _bfd_error_handler
1263
  /* xgettext:c-format */
1264
259
  (_("%pB: unrecognised machine type (0x%x)"
1265
259
     " in Import Library Format archive"),
1266
259
   abfd, machine);
1267
259
      bfd_set_error (bfd_error_malformed_archive);
1268
1269
259
      return NULL;
1270
0
      break;
1271
5.47k
    }
1272
1273
5.21k
  if (magic == 0)
1274
4.56k
    {
1275
4.56k
      _bfd_error_handler
1276
  /* xgettext:c-format */
1277
4.56k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1278
4.56k
     " in Import Library Format archive"),
1279
4.56k
   abfd, machine);
1280
4.56k
      bfd_set_error (bfd_error_wrong_format);
1281
1282
4.56k
      return NULL;
1283
4.56k
    }
1284
1285
  /* We do not bother to check the date.
1286
     date = H_GET_32 (abfd, ptr);  */
1287
656
  ptr += 4;
1288
1289
656
  size = H_GET_32 (abfd, ptr);
1290
656
  ptr += 4;
1291
1292
656
  if (size == 0)
1293
104
    {
1294
104
      _bfd_error_handler
1295
104
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1296
104
      bfd_set_error (bfd_error_malformed_archive);
1297
1298
104
      return NULL;
1299
104
    }
1300
1301
552
  ordinal = H_GET_16 (abfd, ptr);
1302
552
  ptr += 2;
1303
1304
552
  types = H_GET_16 (abfd, ptr);
1305
  /* ptr += 2; */
1306
1307
  /* Now read in the two strings that follow.  */
1308
552
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1309
552
  if (ptr == NULL)
1310
220
    return NULL;
1311
1312
332
  symbol_name = (char *) ptr;
1313
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1314
332
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1315
1316
  /* Verify that the strings are null terminated.  */
1317
332
  if (ptr[size - 1] != 0
1318
332
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1319
107
    {
1320
107
      _bfd_error_handler
1321
107
  (_("%pB: string not null terminated in ILF object file"), abfd);
1322
107
      bfd_set_error (bfd_error_malformed_archive);
1323
107
      bfd_release (abfd, ptr);
1324
107
      return NULL;
1325
107
    }
1326
1327
  /* Now construct the bfd.  */
1328
225
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1329
225
          source_dll, ordinal, types))
1330
212
    {
1331
212
      bfd_release (abfd, ptr);
1332
212
      return NULL;
1333
212
    }
1334
1335
13
  return pe_ILF_cleanup;
1336
225
}
pei-arm.c:pe_ILF_object_p
Line
Count
Source
1167
6.29k
{
1168
6.29k
  bfd_byte    buffer[14];
1169
6.29k
  bfd_byte *    ptr;
1170
6.29k
  char *    symbol_name;
1171
6.29k
  char *    source_dll;
1172
6.29k
  unsigned int    machine;
1173
6.29k
  bfd_size_type   size;
1174
6.29k
  unsigned int    ordinal;
1175
6.29k
  unsigned int    types;
1176
6.29k
  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
6.29k
  if (bfd_read (buffer, 14, abfd) != 14)
1181
9
    return NULL;
1182
1183
6.28k
  ptr = buffer;
1184
1185
6.28k
  machine = H_GET_16 (abfd, ptr);
1186
6.28k
  ptr += 2;
1187
1188
  /* Check that the machine type is recognised.  */
1189
6.28k
  magic = 0;
1190
1191
6.28k
  switch (machine)
1192
6.28k
    {
1193
105
    case IMAGE_FILE_MACHINE_UNKNOWN:
1194
106
    case IMAGE_FILE_MACHINE_ALPHA:
1195
106
    case IMAGE_FILE_MACHINE_ALPHA64:
1196
109
    case IMAGE_FILE_MACHINE_IA64:
1197
109
      break;
1198
1199
773
    case IMAGE_FILE_MACHINE_I386:
1200
#ifdef I386MAGIC
1201
      magic = I386MAGIC;
1202
#endif
1203
773
      break;
1204
1205
1.67k
    case IMAGE_FILE_MACHINE_AMD64:
1206
#ifdef AMD64MAGIC
1207
      magic = AMD64MAGIC;
1208
#endif
1209
1.67k
      break;
1210
1211
1
    case IMAGE_FILE_MACHINE_R3000:
1212
2
    case IMAGE_FILE_MACHINE_R4000:
1213
3
    case IMAGE_FILE_MACHINE_R10000:
1214
1215
4
    case IMAGE_FILE_MACHINE_MIPS16:
1216
4
    case IMAGE_FILE_MACHINE_MIPSFPU:
1217
5
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1218
#ifdef MIPS_ARCH_MAGIC_WINCE
1219
      magic = MIPS_ARCH_MAGIC_WINCE;
1220
#endif
1221
5
      break;
1222
1223
717
    case IMAGE_FILE_MACHINE_SH3:
1224
1.16k
    case IMAGE_FILE_MACHINE_SH4:
1225
#ifdef SH_ARCH_MAGIC_WINCE
1226
      magic = SH_ARCH_MAGIC_WINCE;
1227
#endif
1228
1.16k
      break;
1229
1230
1.20k
    case IMAGE_FILE_MACHINE_ARM:
1231
1.20k
#ifdef ARMPEMAGIC
1232
1.20k
      magic = ARMPEMAGIC;
1233
1.20k
#endif
1234
1.20k
      break;
1235
1236
32
    case IMAGE_FILE_MACHINE_ARM64:
1237
#ifdef AARCH64MAGIC
1238
      magic = AARCH64MAGIC;
1239
#endif
1240
32
      break;
1241
1242
800
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1243
#ifdef LOONGARCH64MAGIC
1244
      magic = LOONGARCH64MAGIC;
1245
#endif
1246
800
      break;
1247
1248
264
    case IMAGE_FILE_MACHINE_THUMB:
1249
264
#ifdef THUMBPEMAGIC
1250
264
      {
1251
264
  extern const bfd_target TARGET_LITTLE_SYM;
1252
1253
264
  if (abfd->xvec == & TARGET_LITTLE_SYM)
1254
263
    magic = THUMBPEMAGIC;
1255
264
      }
1256
264
#endif
1257
264
      break;
1258
1259
0
    case IMAGE_FILE_MACHINE_POWERPC:
1260
      /* We no longer support PowerPC.  */
1261
259
    default:
1262
259
      _bfd_error_handler
1263
  /* xgettext:c-format */
1264
259
  (_("%pB: unrecognised machine type (0x%x)"
1265
259
     " in Import Library Format archive"),
1266
259
   abfd, machine);
1267
259
      bfd_set_error (bfd_error_malformed_archive);
1268
1269
259
      return NULL;
1270
0
      break;
1271
6.28k
    }
1272
1273
6.02k
  if (magic == 0)
1274
4.56k
    {
1275
4.56k
      _bfd_error_handler
1276
  /* xgettext:c-format */
1277
4.56k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1278
4.56k
     " in Import Library Format archive"),
1279
4.56k
   abfd, machine);
1280
4.56k
      bfd_set_error (bfd_error_wrong_format);
1281
1282
4.56k
      return NULL;
1283
4.56k
    }
1284
1285
  /* We do not bother to check the date.
1286
     date = H_GET_32 (abfd, ptr);  */
1287
1.46k
  ptr += 4;
1288
1289
1.46k
  size = H_GET_32 (abfd, ptr);
1290
1.46k
  ptr += 4;
1291
1292
1.46k
  if (size == 0)
1293
104
    {
1294
104
      _bfd_error_handler
1295
104
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1296
104
      bfd_set_error (bfd_error_malformed_archive);
1297
1298
104
      return NULL;
1299
104
    }
1300
1301
1.36k
  ordinal = H_GET_16 (abfd, ptr);
1302
1.36k
  ptr += 2;
1303
1304
1.36k
  types = H_GET_16 (abfd, ptr);
1305
  /* ptr += 2; */
1306
1307
  /* Now read in the two strings that follow.  */
1308
1.36k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1309
1.36k
  if (ptr == NULL)
1310
220
    return NULL;
1311
1312
1.14k
  symbol_name = (char *) ptr;
1313
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1314
1.14k
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1315
1316
  /* Verify that the strings are null terminated.  */
1317
1.14k
  if (ptr[size - 1] != 0
1318
1.14k
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1319
107
    {
1320
107
      _bfd_error_handler
1321
107
  (_("%pB: string not null terminated in ILF object file"), abfd);
1322
107
      bfd_set_error (bfd_error_malformed_archive);
1323
107
      bfd_release (abfd, ptr);
1324
107
      return NULL;
1325
107
    }
1326
1327
  /* Now construct the bfd.  */
1328
1.03k
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1329
1.03k
          source_dll, ordinal, types))
1330
212
    {
1331
212
      bfd_release (abfd, ptr);
1332
212
      return NULL;
1333
212
    }
1334
1335
826
  return pe_ILF_cleanup;
1336
1.03k
}
pei-mcore.c:pe_ILF_object_p
Line
Count
Source
1167
5.25k
{
1168
5.25k
  bfd_byte    buffer[14];
1169
5.25k
  bfd_byte *    ptr;
1170
5.25k
  char *    symbol_name;
1171
5.25k
  char *    source_dll;
1172
5.25k
  unsigned int    machine;
1173
5.25k
  bfd_size_type   size;
1174
5.25k
  unsigned int    ordinal;
1175
5.25k
  unsigned int    types;
1176
5.25k
  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
5.25k
  if (bfd_read (buffer, 14, abfd) != 14)
1181
9
    return NULL;
1182
1183
5.24k
  ptr = buffer;
1184
1185
5.24k
  machine = H_GET_16 (abfd, ptr);
1186
5.24k
  ptr += 2;
1187
1188
  /* Check that the machine type is recognised.  */
1189
5.24k
  magic = 0;
1190
1191
5.24k
  switch (machine)
1192
5.24k
    {
1193
105
    case IMAGE_FILE_MACHINE_UNKNOWN:
1194
106
    case IMAGE_FILE_MACHINE_ALPHA:
1195
106
    case IMAGE_FILE_MACHINE_ALPHA64:
1196
109
    case IMAGE_FILE_MACHINE_IA64:
1197
109
      break;
1198
1199
540
    case IMAGE_FILE_MACHINE_I386:
1200
#ifdef I386MAGIC
1201
      magic = I386MAGIC;
1202
#endif
1203
540
      break;
1204
1205
1.67k
    case IMAGE_FILE_MACHINE_AMD64:
1206
#ifdef AMD64MAGIC
1207
      magic = AMD64MAGIC;
1208
#endif
1209
1.67k
      break;
1210
1211
1
    case IMAGE_FILE_MACHINE_R3000:
1212
2
    case IMAGE_FILE_MACHINE_R4000:
1213
3
    case IMAGE_FILE_MACHINE_R10000:
1214
1215
4
    case IMAGE_FILE_MACHINE_MIPS16:
1216
4
    case IMAGE_FILE_MACHINE_MIPSFPU:
1217
5
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1218
#ifdef MIPS_ARCH_MAGIC_WINCE
1219
      magic = MIPS_ARCH_MAGIC_WINCE;
1220
#endif
1221
5
      break;
1222
1223
717
    case IMAGE_FILE_MACHINE_SH3:
1224
1.16k
    case IMAGE_FILE_MACHINE_SH4:
1225
#ifdef SH_ARCH_MAGIC_WINCE
1226
      magic = SH_ARCH_MAGIC_WINCE;
1227
#endif
1228
1.16k
      break;
1229
1230
630
    case IMAGE_FILE_MACHINE_ARM:
1231
#ifdef ARMPEMAGIC
1232
      magic = ARMPEMAGIC;
1233
#endif
1234
630
      break;
1235
1236
32
    case IMAGE_FILE_MACHINE_ARM64:
1237
#ifdef AARCH64MAGIC
1238
      magic = AARCH64MAGIC;
1239
#endif
1240
32
      break;
1241
1242
800
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1243
#ifdef LOONGARCH64MAGIC
1244
      magic = LOONGARCH64MAGIC;
1245
#endif
1246
800
      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
259
    default:
1262
259
      _bfd_error_handler
1263
  /* xgettext:c-format */
1264
259
  (_("%pB: unrecognised machine type (0x%x)"
1265
259
     " in Import Library Format archive"),
1266
259
   abfd, machine);
1267
259
      bfd_set_error (bfd_error_malformed_archive);
1268
1269
259
      return NULL;
1270
0
      break;
1271
5.24k
    }
1272
1273
4.98k
  if (magic == 0)
1274
4.98k
    {
1275
4.98k
      _bfd_error_handler
1276
  /* xgettext:c-format */
1277
4.98k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1278
4.98k
     " in Import Library Format archive"),
1279
4.98k
   abfd, machine);
1280
4.98k
      bfd_set_error (bfd_error_wrong_format);
1281
1282
4.98k
      return NULL;
1283
4.98k
    }
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
5.23k
{
1168
5.23k
  bfd_byte    buffer[14];
1169
5.23k
  bfd_byte *    ptr;
1170
5.23k
  char *    symbol_name;
1171
5.23k
  char *    source_dll;
1172
5.23k
  unsigned int    machine;
1173
5.23k
  bfd_size_type   size;
1174
5.23k
  unsigned int    ordinal;
1175
5.23k
  unsigned int    types;
1176
5.23k
  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
5.23k
  if (bfd_read (buffer, 14, abfd) != 14)
1181
7
    return NULL;
1182
1183
5.22k
  ptr = buffer;
1184
1185
5.22k
  machine = H_GET_16 (abfd, ptr);
1186
5.22k
  ptr += 2;
1187
1188
  /* Check that the machine type is recognised.  */
1189
5.22k
  magic = 0;
1190
1191
5.22k
  switch (machine)
1192
5.22k
    {
1193
104
    case IMAGE_FILE_MACHINE_UNKNOWN:
1194
105
    case IMAGE_FILE_MACHINE_ALPHA:
1195
105
    case IMAGE_FILE_MACHINE_ALPHA64:
1196
108
    case IMAGE_FILE_MACHINE_IA64:
1197
108
      break;
1198
1199
540
    case IMAGE_FILE_MACHINE_I386:
1200
#ifdef I386MAGIC
1201
      magic = I386MAGIC;
1202
#endif
1203
540
      break;
1204
1205
1.67k
    case IMAGE_FILE_MACHINE_AMD64:
1206
#ifdef AMD64MAGIC
1207
      magic = AMD64MAGIC;
1208
#endif
1209
1.67k
      break;
1210
1211
1
    case IMAGE_FILE_MACHINE_R3000:
1212
2
    case IMAGE_FILE_MACHINE_R4000:
1213
3
    case IMAGE_FILE_MACHINE_R10000:
1214
1215
4
    case IMAGE_FILE_MACHINE_MIPS16:
1216
4
    case IMAGE_FILE_MACHINE_MIPSFPU:
1217
5
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1218
#ifdef MIPS_ARCH_MAGIC_WINCE
1219
      magic = MIPS_ARCH_MAGIC_WINCE;
1220
#endif
1221
5
      break;
1222
1223
720
    case IMAGE_FILE_MACHINE_SH3:
1224
1.17k
    case IMAGE_FILE_MACHINE_SH4:
1225
1.17k
#ifdef SH_ARCH_MAGIC_WINCE
1226
1.17k
      magic = SH_ARCH_MAGIC_WINCE;
1227
1.17k
#endif
1228
1.17k
      break;
1229
1230
622
    case IMAGE_FILE_MACHINE_ARM:
1231
#ifdef ARMPEMAGIC
1232
      magic = ARMPEMAGIC;
1233
#endif
1234
622
      break;
1235
1236
32
    case IMAGE_FILE_MACHINE_ARM64:
1237
#ifdef AARCH64MAGIC
1238
      magic = AARCH64MAGIC;
1239
#endif
1240
32
      break;
1241
1242
800
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1243
#ifdef LOONGARCH64MAGIC
1244
      magic = LOONGARCH64MAGIC;
1245
#endif
1246
800
      break;
1247
1248
26
    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
26
      break;
1258
1259
0
    case IMAGE_FILE_MACHINE_POWERPC:
1260
      /* We no longer support PowerPC.  */
1261
247
    default:
1262
247
      _bfd_error_handler
1263
  /* xgettext:c-format */
1264
247
  (_("%pB: unrecognised machine type (0x%x)"
1265
247
     " in Import Library Format archive"),
1266
247
   abfd, machine);
1267
247
      bfd_set_error (bfd_error_malformed_archive);
1268
1269
247
      return NULL;
1270
0
      break;
1271
5.22k
    }
1272
1273
4.97k
  if (magic == 0)
1274
3.80k
    {
1275
3.80k
      _bfd_error_handler
1276
  /* xgettext:c-format */
1277
3.80k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1278
3.80k
     " in Import Library Format archive"),
1279
3.80k
   abfd, machine);
1280
3.80k
      bfd_set_error (bfd_error_wrong_format);
1281
1282
3.80k
      return NULL;
1283
3.80k
    }
1284
1285
  /* We do not bother to check the date.
1286
     date = H_GET_32 (abfd, ptr);  */
1287
1.17k
  ptr += 4;
1288
1289
1.17k
  size = H_GET_32 (abfd, ptr);
1290
1.17k
  ptr += 4;
1291
1292
1.17k
  if (size == 0)
1293
102
    {
1294
102
      _bfd_error_handler
1295
102
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1296
102
      bfd_set_error (bfd_error_malformed_archive);
1297
1298
102
      return NULL;
1299
102
    }
1300
1301
1.06k
  ordinal = H_GET_16 (abfd, ptr);
1302
1.06k
  ptr += 2;
1303
1304
1.06k
  types = H_GET_16 (abfd, ptr);
1305
  /* ptr += 2; */
1306
1307
  /* Now read in the two strings that follow.  */
1308
1.06k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1309
1.06k
  if (ptr == NULL)
1310
110
    return NULL;
1311
1312
959
  symbol_name = (char *) ptr;
1313
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1314
959
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1315
1316
  /* Verify that the strings are null terminated.  */
1317
959
  if (ptr[size - 1] != 0
1318
959
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1319
6
    {
1320
6
      _bfd_error_handler
1321
6
  (_("%pB: string not null terminated in ILF object file"), abfd);
1322
6
      bfd_set_error (bfd_error_malformed_archive);
1323
6
      bfd_release (abfd, ptr);
1324
6
      return NULL;
1325
6
    }
1326
1327
  /* Now construct the bfd.  */
1328
953
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1329
953
          source_dll, ordinal, types))
1330
10
    {
1331
10
      bfd_release (abfd, ptr);
1332
10
      return NULL;
1333
10
    }
1334
1335
943
  return pe_ILF_cleanup;
1336
953
}
1337
1338
static void
1339
pe_bfd_read_buildid (bfd *abfd)
1340
32.5k
{
1341
32.5k
  pe_data_type *pe = pe_data (abfd);
1342
32.5k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1343
32.5k
  asection *section;
1344
32.5k
  bfd_byte *data = 0;
1345
32.5k
  bfd_size_type dataoff;
1346
32.5k
  unsigned int i;
1347
32.5k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1348
32.5k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1349
1350
32.5k
  if (size == 0)
1351
10.7k
    return;
1352
1353
21.8k
  addr += extra->ImageBase;
1354
1355
  /* Search for the section containing the DebugDirectory.  */
1356
54.8k
  for (section = abfd->sections; section != NULL; section = section->next)
1357
43.9k
    {
1358
43.9k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1359
10.9k
  break;
1360
43.9k
    }
1361
1362
21.8k
  if (section == NULL)
1363
10.8k
    return;
1364
1365
10.9k
  if (!(section->flags & SEC_HAS_CONTENTS))
1366
1.06k
    return;
1367
1368
9.86k
  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
9.86k
  if (dataoff >= section->size
1374
9.86k
      || size > section->size - dataoff)
1375
3.57k
    {
1376
3.57k
      _bfd_error_handler
1377
3.57k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1378
3.57k
   abfd);
1379
3.57k
      return;
1380
3.57k
    }
1381
1382
  /* Read the whole section. */
1383
6.28k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1384
4.33k
    {
1385
4.33k
      free (data);
1386
4.33k
      return;
1387
4.33k
    }
1388
1389
  /* Search for a CodeView entry in the DebugDirectory */
1390
52.7k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1391
51.4k
    {
1392
51.4k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1393
51.4k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1394
51.4k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1395
1396
51.4k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1397
1398
51.4k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1399
735
  {
1400
735
    char buffer[256 + 1];
1401
735
    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
735
    if (_bfd_XXi_slurp_codeview_record (abfd,
1408
735
                (file_ptr) idd.PointerToRawData,
1409
735
                idd.SizeOfData, cvinfo, NULL))
1410
6
      {
1411
6
        struct bfd_build_id* build_id = bfd_alloc (abfd,
1412
6
       sizeof (struct bfd_build_id) + cvinfo->SignatureLength);
1413
6
        if (build_id)
1414
6
    {
1415
6
      build_id->size = cvinfo->SignatureLength;
1416
6
      memcpy(build_id->data,  cvinfo->Signature,
1417
6
       cvinfo->SignatureLength);
1418
6
      abfd->build_id = build_id;
1419
6
    }
1420
6
      }
1421
735
    break;
1422
735
  }
1423
51.4k
    }
1424
1425
1.95k
  free (data);
1426
1.95k
}
pei-i386.c:pe_bfd_read_buildid
Line
Count
Source
1340
4.69k
{
1341
4.69k
  pe_data_type *pe = pe_data (abfd);
1342
4.69k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1343
4.69k
  asection *section;
1344
4.69k
  bfd_byte *data = 0;
1345
4.69k
  bfd_size_type dataoff;
1346
4.69k
  unsigned int i;
1347
4.69k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1348
4.69k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1349
1350
4.69k
  if (size == 0)
1351
1.56k
    return;
1352
1353
3.12k
  addr += extra->ImageBase;
1354
1355
  /* Search for the section containing the DebugDirectory.  */
1356
4.72k
  for (section = abfd->sections; section != NULL; section = section->next)
1357
3.24k
    {
1358
3.24k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1359
1.64k
  break;
1360
3.24k
    }
1361
1362
3.12k
  if (section == NULL)
1363
1.48k
    return;
1364
1365
1.64k
  if (!(section->flags & SEC_HAS_CONTENTS))
1366
3
    return;
1367
1368
1.64k
  dataoff = addr - section->vma;
1369
1370
  /* PR 20605 and 22373: Make sure that the data is really there.
1371
     Note - since we are dealing with unsigned quantities we have
1372
     to be careful to check for potential overflows.  */
1373
1.64k
  if (dataoff >= section->size
1374
1.64k
      || size > section->size - dataoff)
1375
848
    {
1376
848
      _bfd_error_handler
1377
848
  (_("%pB: error: debug data ends beyond end of debug directory"),
1378
848
   abfd);
1379
848
      return;
1380
848
    }
1381
1382
  /* Read the whole section. */
1383
797
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1384
779
    {
1385
779
      free (data);
1386
779
      return;
1387
779
    }
1388
1389
  /* Search for a CodeView entry in the DebugDirectory */
1390
118
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1391
109
    {
1392
109
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1393
109
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1394
109
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1395
1396
109
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1397
1398
109
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1399
9
  {
1400
9
    char buffer[256 + 1];
1401
9
    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
9
    if (_bfd_XXi_slurp_codeview_record (abfd,
1408
9
                (file_ptr) idd.PointerToRawData,
1409
9
                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
9
    break;
1422
9
  }
1423
109
    }
1424
1425
18
  free (data);
1426
18
}
pei-x86_64.c:pe_bfd_read_buildid
Line
Count
Source
1340
6.23k
{
1341
6.23k
  pe_data_type *pe = pe_data (abfd);
1342
6.23k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1343
6.23k
  asection *section;
1344
6.23k
  bfd_byte *data = 0;
1345
6.23k
  bfd_size_type dataoff;
1346
6.23k
  unsigned int i;
1347
6.23k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1348
6.23k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1349
1350
6.23k
  if (size == 0)
1351
2.85k
    return;
1352
1353
3.38k
  addr += extra->ImageBase;
1354
1355
  /* Search for the section containing the DebugDirectory.  */
1356
8.38k
  for (section = abfd->sections; section != NULL; section = section->next)
1357
6.72k
    {
1358
6.72k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1359
1.72k
  break;
1360
6.72k
    }
1361
1362
3.38k
  if (section == NULL)
1363
1.66k
    return;
1364
1365
1.72k
  if (!(section->flags & SEC_HAS_CONTENTS))
1366
241
    return;
1367
1368
1.48k
  dataoff = addr - section->vma;
1369
1370
  /* PR 20605 and 22373: Make sure that the data is really there.
1371
     Note - since we are dealing with unsigned quantities we have
1372
     to be careful to check for potential overflows.  */
1373
1.48k
  if (dataoff >= section->size
1374
1.48k
      || size > section->size - dataoff)
1375
613
    {
1376
613
      _bfd_error_handler
1377
613
  (_("%pB: error: debug data ends beyond end of debug directory"),
1378
613
   abfd);
1379
613
      return;
1380
613
    }
1381
1382
  /* Read the whole section. */
1383
869
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1384
375
    {
1385
375
      free (data);
1386
375
      return;
1387
375
    }
1388
1389
  /* Search for a CodeView entry in the DebugDirectory */
1390
3.28k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1391
2.81k
    {
1392
2.81k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1393
2.81k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1394
2.81k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1395
1396
2.81k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1397
1398
2.81k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1399
22
  {
1400
22
    char buffer[256 + 1];
1401
22
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1402
1403
    /*
1404
      The debug entry doesn't have to have to be in a section, in which
1405
      case AddressOfRawData is 0, so always use PointerToRawData.
1406
    */
1407
22
    if (_bfd_XXi_slurp_codeview_record (abfd,
1408
22
                (file_ptr) idd.PointerToRawData,
1409
22
                idd.SizeOfData, cvinfo, NULL))
1410
3
      {
1411
3
        struct bfd_build_id* build_id = bfd_alloc (abfd,
1412
3
       sizeof (struct bfd_build_id) + cvinfo->SignatureLength);
1413
3
        if (build_id)
1414
3
    {
1415
3
      build_id->size = cvinfo->SignatureLength;
1416
3
      memcpy(build_id->data,  cvinfo->Signature,
1417
3
       cvinfo->SignatureLength);
1418
3
      abfd->build_id = build_id;
1419
3
    }
1420
3
      }
1421
22
    break;
1422
22
  }
1423
2.81k
    }
1424
1425
494
  free (data);
1426
494
}
pei-aarch64.c:pe_bfd_read_buildid
Line
Count
Source
1340
1.96k
{
1341
1.96k
  pe_data_type *pe = pe_data (abfd);
1342
1.96k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1343
1.96k
  asection *section;
1344
1.96k
  bfd_byte *data = 0;
1345
1.96k
  bfd_size_type dataoff;
1346
1.96k
  unsigned int i;
1347
1.96k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1348
1.96k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1349
1350
1.96k
  if (size == 0)
1351
525
    return;
1352
1353
1.43k
  addr += extra->ImageBase;
1354
1355
  /* Search for the section containing the DebugDirectory.  */
1356
3.51k
  for (section = abfd->sections; section != NULL; section = section->next)
1357
2.20k
    {
1358
2.20k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1359
128
  break;
1360
2.20k
    }
1361
1362
1.43k
  if (section == NULL)
1363
1.31k
    return;
1364
1365
128
  if (!(section->flags & SEC_HAS_CONTENTS))
1366
1
    return;
1367
1368
127
  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
127
  if (dataoff >= section->size
1374
127
      || size > section->size - dataoff)
1375
115
    {
1376
115
      _bfd_error_handler
1377
115
  (_("%pB: error: debug data ends beyond end of debug directory"),
1378
115
   abfd);
1379
115
      return;
1380
115
    }
1381
1382
  /* Read the whole section. */
1383
12
  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
1.86k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1391
1.86k
    {
1392
1.86k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1393
1.86k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1394
1.86k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1395
1396
1.86k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1397
1398
1.86k
      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
1.86k
    }
1424
1425
6
  free (data);
1426
6
}
pei-ia64.c:pe_bfd_read_buildid
Line
Count
Source
1340
2.90k
{
1341
2.90k
  pe_data_type *pe = pe_data (abfd);
1342
2.90k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1343
2.90k
  asection *section;
1344
2.90k
  bfd_byte *data = 0;
1345
2.90k
  bfd_size_type dataoff;
1346
2.90k
  unsigned int i;
1347
2.90k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1348
2.90k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1349
1350
2.90k
  if (size == 0)
1351
992
    return;
1352
1353
1.91k
  addr += extra->ImageBase;
1354
1355
  /* Search for the section containing the DebugDirectory.  */
1356
5.65k
  for (section = abfd->sections; section != NULL; section = section->next)
1357
4.00k
    {
1358
4.00k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1359
273
  break;
1360
4.00k
    }
1361
1362
1.91k
  if (section == NULL)
1363
1.64k
    return;
1364
1365
273
  if (!(section->flags & SEC_HAS_CONTENTS))
1366
2
    return;
1367
1368
271
  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
271
  if (dataoff >= section->size
1374
271
      || size > section->size - dataoff)
1375
7
    {
1376
7
      _bfd_error_handler
1377
7
  (_("%pB: error: debug data ends beyond end of debug directory"),
1378
7
   abfd);
1379
7
      return;
1380
7
    }
1381
1382
  /* Read the whole section. */
1383
264
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1384
248
    {
1385
248
      free (data);
1386
248
      return;
1387
248
    }
1388
1389
  /* Search for a CodeView entry in the DebugDirectory */
1390
124
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1391
118
    {
1392
118
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1393
118
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1394
118
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1395
1396
118
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1397
1398
118
      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
118
    }
1424
1425
16
  free (data);
1426
16
}
pei-loongarch64.c:pe_bfd_read_buildid
Line
Count
Source
1340
2.42k
{
1341
2.42k
  pe_data_type *pe = pe_data (abfd);
1342
2.42k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1343
2.42k
  asection *section;
1344
2.42k
  bfd_byte *data = 0;
1345
2.42k
  bfd_size_type dataoff;
1346
2.42k
  unsigned int i;
1347
2.42k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1348
2.42k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1349
1350
2.42k
  if (size == 0)
1351
1.33k
    return;
1352
1353
1.09k
  addr += extra->ImageBase;
1354
1355
  /* Search for the section containing the DebugDirectory.  */
1356
2.44k
  for (section = abfd->sections; section != NULL; section = section->next)
1357
2.06k
    {
1358
2.06k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1359
707
  break;
1360
2.06k
    }
1361
1362
1.09k
  if (section == NULL)
1363
384
    return;
1364
1365
707
  if (!(section->flags & SEC_HAS_CONTENTS))
1366
2
    return;
1367
1368
705
  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
705
  if (dataoff >= section->size
1374
705
      || size > section->size - dataoff)
1375
349
    {
1376
349
      _bfd_error_handler
1377
349
  (_("%pB: error: debug data ends beyond end of debug directory"),
1378
349
   abfd);
1379
349
      return;
1380
349
    }
1381
1382
  /* Read the whole section. */
1383
356
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1384
347
    {
1385
347
      free (data);
1386
347
      return;
1387
347
    }
1388
1389
  /* Search for a CodeView entry in the DebugDirectory */
1390
104
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1391
103
    {
1392
103
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1393
103
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1394
103
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1395
1396
103
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1397
1398
103
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1399
8
  {
1400
8
    char buffer[256 + 1];
1401
8
    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
8
    if (_bfd_XXi_slurp_codeview_record (abfd,
1408
8
                (file_ptr) idd.PointerToRawData,
1409
8
                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
8
    break;
1422
8
  }
1423
103
    }
1424
1425
9
  free (data);
1426
9
}
pei-arm-wince.c:pe_bfd_read_buildid
Line
Count
Source
1340
3.71k
{
1341
3.71k
  pe_data_type *pe = pe_data (abfd);
1342
3.71k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1343
3.71k
  asection *section;
1344
3.71k
  bfd_byte *data = 0;
1345
3.71k
  bfd_size_type dataoff;
1346
3.71k
  unsigned int i;
1347
3.71k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1348
3.71k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1349
1350
3.71k
  if (size == 0)
1351
561
    return;
1352
1353
3.15k
  addr += extra->ImageBase;
1354
1355
  /* Search for the section containing the DebugDirectory.  */
1356
5.51k
  for (section = abfd->sections; section != NULL; section = section->next)
1357
4.50k
    {
1358
4.50k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1359
2.15k
  break;
1360
4.50k
    }
1361
1362
3.15k
  if (section == NULL)
1363
1.00k
    return;
1364
1365
2.15k
  if (!(section->flags & SEC_HAS_CONTENTS))
1366
240
    return;
1367
1368
1.91k
  dataoff = addr - section->vma;
1369
1370
  /* PR 20605 and 22373: Make sure that the data is really there.
1371
     Note - since we are dealing with unsigned quantities we have
1372
     to be careful to check for potential overflows.  */
1373
1.91k
  if (dataoff >= section->size
1374
1.91k
      || size > section->size - dataoff)
1375
817
    {
1376
817
      _bfd_error_handler
1377
817
  (_("%pB: error: debug data ends beyond end of debug directory"),
1378
817
   abfd);
1379
817
      return;
1380
817
    }
1381
1382
  /* Read the whole section. */
1383
1.09k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1384
883
    {
1385
883
      free (data);
1386
883
      return;
1387
883
    }
1388
1389
  /* Search for a CodeView entry in the DebugDirectory */
1390
8.01k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1391
7.91k
    {
1392
7.91k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1393
7.91k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1394
7.91k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1395
1396
7.91k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1397
1398
7.91k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1399
106
  {
1400
106
    char buffer[256 + 1];
1401
106
    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
106
    if (_bfd_XXi_slurp_codeview_record (abfd,
1408
106
                (file_ptr) idd.PointerToRawData,
1409
106
                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
106
    break;
1422
106
  }
1423
7.91k
    }
1424
1425
211
  free (data);
1426
211
}
pei-arm.c:pe_bfd_read_buildid
Line
Count
Source
1340
2.89k
{
1341
2.89k
  pe_data_type *pe = pe_data (abfd);
1342
2.89k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1343
2.89k
  asection *section;
1344
2.89k
  bfd_byte *data = 0;
1345
2.89k
  bfd_size_type dataoff;
1346
2.89k
  unsigned int i;
1347
2.89k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1348
2.89k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1349
1350
2.89k
  if (size == 0)
1351
821
    return;
1352
1353
2.07k
  addr += extra->ImageBase;
1354
1355
  /* Search for the section containing the DebugDirectory.  */
1356
4.00k
  for (section = abfd->sections; section != NULL; section = section->next)
1357
2.74k
    {
1358
2.74k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1359
815
  break;
1360
2.74k
    }
1361
1362
2.07k
  if (section == NULL)
1363
1.26k
    return;
1364
1365
815
  if (!(section->flags & SEC_HAS_CONTENTS))
1366
242
    return;
1367
1368
573
  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
573
  if (dataoff >= section->size
1374
573
      || size > section->size - dataoff)
1375
451
    {
1376
451
      _bfd_error_handler
1377
451
  (_("%pB: error: debug data ends beyond end of debug directory"),
1378
451
   abfd);
1379
451
      return;
1380
451
    }
1381
1382
  /* Read the whole section. */
1383
122
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1384
109
    {
1385
109
      free (data);
1386
109
      return;
1387
109
    }
1388
1389
  /* Search for a CodeView entry in the DebugDirectory */
1390
244
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1391
235
    {
1392
235
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1393
235
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1394
235
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1395
1396
235
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1397
1398
235
      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
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
4
    break;
1422
4
  }
1423
235
    }
1424
1425
13
  free (data);
1426
13
}
pei-mcore.c:pe_bfd_read_buildid
Line
Count
Source
1340
4.75k
{
1341
4.75k
  pe_data_type *pe = pe_data (abfd);
1342
4.75k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1343
4.75k
  asection *section;
1344
4.75k
  bfd_byte *data = 0;
1345
4.75k
  bfd_size_type dataoff;
1346
4.75k
  unsigned int i;
1347
4.75k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1348
4.75k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1349
1350
4.75k
  if (size == 0)
1351
838
    return;
1352
1353
3.91k
  addr += extra->ImageBase;
1354
1355
  /* Search for the section containing the DebugDirectory.  */
1356
16.9k
  for (section = abfd->sections; section != NULL; section = section->next)
1357
15.4k
    {
1358
15.4k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1359
2.40k
  break;
1360
15.4k
    }
1361
1362
3.91k
  if (section == NULL)
1363
1.51k
    return;
1364
1365
2.40k
  if (!(section->flags & SEC_HAS_CONTENTS))
1366
236
    return;
1367
1368
2.16k
  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.16k
  if (dataoff >= section->size
1374
2.16k
      || size > section->size - dataoff)
1375
139
    {
1376
139
      _bfd_error_handler
1377
139
  (_("%pB: error: debug data ends beyond end of debug directory"),
1378
139
   abfd);
1379
139
      return;
1380
139
    }
1381
1382
  /* Read the whole section. */
1383
2.02k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1384
1.24k
    {
1385
1.24k
      free (data);
1386
1.24k
      return;
1387
1.24k
    }
1388
1389
  /* Search for a CodeView entry in the DebugDirectory */
1390
36.9k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1391
36.6k
    {
1392
36.6k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1393
36.6k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1394
36.6k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1395
1396
36.6k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1397
1398
36.6k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1399
441
  {
1400
441
    char buffer[256 + 1];
1401
441
    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
441
    if (_bfd_XXi_slurp_codeview_record (abfd,
1408
441
                (file_ptr) idd.PointerToRawData,
1409
441
                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
441
    break;
1422
441
  }
1423
36.6k
    }
1424
1425
779
  free (data);
1426
779
}
pei-sh.c:pe_bfd_read_buildid
Line
Count
Source
1340
2.93k
{
1341
2.93k
  pe_data_type *pe = pe_data (abfd);
1342
2.93k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1343
2.93k
  asection *section;
1344
2.93k
  bfd_byte *data = 0;
1345
2.93k
  bfd_size_type dataoff;
1346
2.93k
  unsigned int i;
1347
2.93k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1348
2.93k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1349
1350
2.93k
  if (size == 0)
1351
1.21k
    return;
1352
1353
1.72k
  addr += extra->ImageBase;
1354
1355
  /* Search for the section containing the DebugDirectory.  */
1356
3.69k
  for (section = abfd->sections; section != NULL; section = section->next)
1357
3.06k
    {
1358
3.06k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1359
1.08k
  break;
1360
3.06k
    }
1361
1362
1.72k
  if (section == NULL)
1363
632
    return;
1364
1365
1.08k
  if (!(section->flags & SEC_HAS_CONTENTS))
1366
102
    return;
1367
1368
986
  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
986
  if (dataoff >= section->size
1374
986
      || size > section->size - dataoff)
1375
240
    {
1376
240
      _bfd_error_handler
1377
240
  (_("%pB: error: debug data ends beyond end of debug directory"),
1378
240
   abfd);
1379
240
      return;
1380
240
    }
1381
1382
  /* Read the whole section. */
1383
746
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1384
338
    {
1385
338
      free (data);
1386
338
      return;
1387
338
    }
1388
1389
  /* Search for a CodeView entry in the DebugDirectory */
1390
1.98k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1391
1.71k
    {
1392
1.71k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1393
1.71k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1394
1.71k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1395
1396
1.71k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1397
1398
1.71k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1399
135
  {
1400
135
    char buffer[256 + 1];
1401
135
    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
135
    if (_bfd_XXi_slurp_codeview_record (abfd,
1408
135
                (file_ptr) idd.PointerToRawData,
1409
135
                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
135
    break;
1422
135
  }
1423
1.71k
    }
1424
1425
408
  free (data);
1426
408
}
1427
1428
static bfd_cleanup
1429
pe_bfd_object_p (bfd * abfd)
1430
2.96M
{
1431
2.96M
  bfd_byte buffer[6];
1432
2.96M
  struct external_DOS_hdr dos_hdr;
1433
2.96M
  struct external_PEI_IMAGE_hdr image_hdr;
1434
2.96M
  struct internal_filehdr internal_f;
1435
2.96M
  struct internal_aouthdr internal_a;
1436
2.96M
  bfd_size_type opt_hdr_size;
1437
2.96M
  file_ptr offset;
1438
2.96M
  bfd_cleanup result;
1439
1440
  /* Detect if this a Microsoft Import Library Format element.  */
1441
  /* First read the beginning of the header.  */
1442
2.96M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1443
2.96M
      || bfd_read (buffer, 6, abfd) != 6)
1444
9.98k
    {
1445
9.98k
      if (bfd_get_error () != bfd_error_system_call)
1446
8.84k
  bfd_set_error (bfd_error_wrong_format);
1447
9.98k
      return NULL;
1448
9.98k
    }
1449
1450
  /* Then check the magic and the version (only 0 is supported).  */
1451
2.95M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1452
2.95M
      && H_GET_16 (abfd, buffer + 4) == 0)
1453
42.0k
    return pe_ILF_object_p (abfd);
1454
1455
2.90M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1456
2.90M
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1457
567k
    {
1458
567k
      if (bfd_get_error () != bfd_error_system_call)
1459
567k
  bfd_set_error (bfd_error_wrong_format);
1460
567k
      return NULL;
1461
567k
    }
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
2.34M
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1474
1.69M
    {
1475
1.69M
      bfd_set_error (bfd_error_wrong_format);
1476
1.69M
      return NULL;
1477
1.69M
    }
1478
1479
650k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1480
650k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1481
650k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1482
4.88k
    {
1483
4.88k
      if (bfd_get_error () != bfd_error_system_call)
1484
4.88k
  bfd_set_error (bfd_error_wrong_format);
1485
4.88k
      return NULL;
1486
4.88k
    }
1487
1488
645k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1489
12.9k
    {
1490
12.9k
      bfd_set_error (bfd_error_wrong_format);
1491
12.9k
      return NULL;
1492
12.9k
    }
1493
1494
  /* Swap file header, so that we get the location for calling
1495
     real_object_p.  */
1496
632k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1497
1498
632k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1499
632k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1500
545k
    {
1501
545k
      bfd_set_error (bfd_error_wrong_format);
1502
545k
      return NULL;
1503
545k
    }
1504
1505
86.5k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1506
86.5k
    sizeof (internal_f.pe.dos_message));
1507
1508
  /* Read the optional header, which has variable size.  */
1509
86.5k
  opt_hdr_size = internal_f.f_opthdr;
1510
1511
86.5k
  if (opt_hdr_size != 0)
1512
61.4k
    {
1513
61.4k
      bfd_size_type amt = opt_hdr_size;
1514
61.4k
      bfd_byte * opthdr;
1515
1516
      /* PR 17521 file: 230-131433-0.004.  */
1517
61.4k
      if (amt < sizeof (PEAOUTHDR))
1518
38.6k
  amt = sizeof (PEAOUTHDR);
1519
1520
61.4k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1521
61.4k
      if (opthdr == NULL)
1522
3.19k
  return NULL;
1523
58.2k
      if (amt > opt_hdr_size)
1524
37.5k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1525
1526
58.2k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1527
1528
58.2k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1529
1530
#ifdef ARM
1531
      /* Use Subsystem to distinguish between pei-arm-little and
1532
   pei-arm-wince-little.  */
1533
#ifdef WINCE
1534
8.96k
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1535
#else
1536
8.95k
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1537
4.34k
#endif
1538
8.94k
  {
1539
8.94k
    bfd_set_error (bfd_error_wrong_format);
1540
8.94k
    return NULL;
1541
8.94k
  }
1542
8.97k
#endif
1543
1544
49.3k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1545
49.3k
    || a->SectionAlignment >= 0x80000000)
1546
24.7k
  {
1547
24.7k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1548
24.7k
        abfd);
1549
24.7k
    a->SectionAlignment &= -a->SectionAlignment;
1550
24.7k
    if (a->SectionAlignment >= 0x80000000)
1551
494
      a->SectionAlignment = 0x40000000;
1552
24.7k
  }
1553
1554
49.3k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1555
49.3k
    || a->FileAlignment > a->SectionAlignment)
1556
35.7k
  {
1557
35.7k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1558
35.7k
            abfd);
1559
35.7k
    a->FileAlignment &= -a->FileAlignment;
1560
35.7k
    if (a->FileAlignment > a->SectionAlignment)
1561
17.7k
      a->FileAlignment = a->SectionAlignment;
1562
35.7k
  }
1563
1564
49.3k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1565
32.9k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1566
8.97k
    }
1567
1568
74.4k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1569
74.4k
             (opt_hdr_size != 0
1570
74.4k
        ? &internal_a
1571
74.4k
        : (struct internal_aouthdr *) NULL));
1572
1573
74.4k
  if (result)
1574
32.5k
    {
1575
      /* Now the whole header has been processed, see if there is a build-id */
1576
32.5k
      pe_bfd_read_buildid(abfd);
1577
32.5k
    }
1578
1579
74.4k
  return result;
1580
86.5k
}
pei-i386.c:pe_bfd_object_p
Line
Count
Source
1430
264k
{
1431
264k
  bfd_byte buffer[6];
1432
264k
  struct external_DOS_hdr dos_hdr;
1433
264k
  struct external_PEI_IMAGE_hdr image_hdr;
1434
264k
  struct internal_filehdr internal_f;
1435
264k
  struct internal_aouthdr internal_a;
1436
264k
  bfd_size_type opt_hdr_size;
1437
264k
  file_ptr offset;
1438
264k
  bfd_cleanup result;
1439
1440
  /* Detect if this a Microsoft Import Library Format element.  */
1441
  /* First read the beginning of the header.  */
1442
264k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1443
264k
      || bfd_read (buffer, 6, abfd) != 6)
1444
908
    {
1445
908
      if (bfd_get_error () != bfd_error_system_call)
1446
804
  bfd_set_error (bfd_error_wrong_format);
1447
908
      return NULL;
1448
908
    }
1449
1450
  /* Then check the magic and the version (only 0 is supported).  */
1451
263k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1452
263k
      && H_GET_16 (abfd, buffer + 4) == 0)
1453
5.46k
    return pe_ILF_object_p (abfd);
1454
1455
258k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1456
258k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1457
50.4k
    {
1458
50.4k
      if (bfd_get_error () != bfd_error_system_call)
1459
50.4k
  bfd_set_error (bfd_error_wrong_format);
1460
50.4k
      return NULL;
1461
50.4k
    }
1462
1463
  /* There are really two magic numbers involved; the magic number
1464
     that says this is a NT executable (PEI) and the magic number that
1465
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1466
     the e_magic field.  The latter is stored in the f_magic field.
1467
     If the NT magic number isn't valid, the architecture magic number
1468
     could be mimicked by some other field (specifically, the number
1469
     of relocs in section 3).  Since this routine can only be called
1470
     correctly for a PEI file, check the e_magic number here, and, if
1471
     it doesn't match, clobber the f_magic number so that we don't get
1472
     a false match.  */
1473
207k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1474
133k
    {
1475
133k
      bfd_set_error (bfd_error_wrong_format);
1476
133k
      return NULL;
1477
133k
    }
1478
1479
73.9k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1480
73.9k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1481
73.9k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1482
582
    {
1483
582
      if (bfd_get_error () != bfd_error_system_call)
1484
582
  bfd_set_error (bfd_error_wrong_format);
1485
582
      return NULL;
1486
582
    }
1487
1488
73.3k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1489
1.56k
    {
1490
1.56k
      bfd_set_error (bfd_error_wrong_format);
1491
1.56k
      return NULL;
1492
1.56k
    }
1493
1494
  /* Swap file header, so that we get the location for calling
1495
     real_object_p.  */
1496
71.7k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1497
1498
71.7k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1499
71.7k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1500
60.1k
    {
1501
60.1k
      bfd_set_error (bfd_error_wrong_format);
1502
60.1k
      return NULL;
1503
60.1k
    }
1504
1505
11.6k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1506
11.6k
    sizeof (internal_f.pe.dos_message));
1507
1508
  /* Read the optional header, which has variable size.  */
1509
11.6k
  opt_hdr_size = internal_f.f_opthdr;
1510
1511
11.6k
  if (opt_hdr_size != 0)
1512
9.52k
    {
1513
9.52k
      bfd_size_type amt = opt_hdr_size;
1514
9.52k
      bfd_byte * opthdr;
1515
1516
      /* PR 17521 file: 230-131433-0.004.  */
1517
9.52k
      if (amt < sizeof (PEAOUTHDR))
1518
2.37k
  amt = sizeof (PEAOUTHDR);
1519
1520
9.52k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1521
9.52k
      if (opthdr == NULL)
1522
344
  return NULL;
1523
9.17k
      if (amt > opt_hdr_size)
1524
2.37k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1525
1526
9.17k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1527
1528
9.17k
      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
9.17k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1545
9.17k
    || a->SectionAlignment >= 0x80000000)
1546
5.48k
  {
1547
5.48k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1548
5.48k
        abfd);
1549
5.48k
    a->SectionAlignment &= -a->SectionAlignment;
1550
5.48k
    if (a->SectionAlignment >= 0x80000000)
1551
3
      a->SectionAlignment = 0x40000000;
1552
5.48k
  }
1553
1554
9.17k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1555
9.17k
    || a->FileAlignment > a->SectionAlignment)
1556
6.02k
  {
1557
6.02k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1558
6.02k
            abfd);
1559
6.02k
    a->FileAlignment &= -a->FileAlignment;
1560
6.02k
    if (a->FileAlignment > a->SectionAlignment)
1561
1.87k
      a->FileAlignment = a->SectionAlignment;
1562
6.02k
  }
1563
1564
9.17k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1565
5.67k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1566
9.17k
    }
1567
1568
11.2k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1569
11.2k
             (opt_hdr_size != 0
1570
11.2k
        ? &internal_a
1571
11.2k
        : (struct internal_aouthdr *) NULL));
1572
1573
11.2k
  if (result)
1574
4.69k
    {
1575
      /* Now the whole header has been processed, see if there is a build-id */
1576
4.69k
      pe_bfd_read_buildid(abfd);
1577
4.69k
    }
1578
1579
11.2k
  return result;
1580
11.6k
}
pei-x86_64.c:pe_bfd_object_p
Line
Count
Source
1430
265k
{
1431
265k
  bfd_byte buffer[6];
1432
265k
  struct external_DOS_hdr dos_hdr;
1433
265k
  struct external_PEI_IMAGE_hdr image_hdr;
1434
265k
  struct internal_filehdr internal_f;
1435
265k
  struct internal_aouthdr internal_a;
1436
265k
  bfd_size_type opt_hdr_size;
1437
265k
  file_ptr offset;
1438
265k
  bfd_cleanup result;
1439
1440
  /* Detect if this a Microsoft Import Library Format element.  */
1441
  /* First read the beginning of the header.  */
1442
265k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1443
265k
      || bfd_read (buffer, 6, abfd) != 6)
1444
908
    {
1445
908
      if (bfd_get_error () != bfd_error_system_call)
1446
804
  bfd_set_error (bfd_error_wrong_format);
1447
908
      return NULL;
1448
908
    }
1449
1450
  /* Then check the magic and the version (only 0 is supported).  */
1451
264k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1452
264k
      && H_GET_16 (abfd, buffer + 4) == 0)
1453
4.29k
    return pe_ILF_object_p (abfd);
1454
1455
259k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1456
259k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1457
50.4k
    {
1458
50.4k
      if (bfd_get_error () != bfd_error_system_call)
1459
50.4k
  bfd_set_error (bfd_error_wrong_format);
1460
50.4k
      return NULL;
1461
50.4k
    }
1462
1463
  /* There are really two magic numbers involved; the magic number
1464
     that says this is a NT executable (PEI) and the magic number that
1465
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1466
     the e_magic field.  The latter is stored in the f_magic field.
1467
     If the NT magic number isn't valid, the architecture magic number
1468
     could be mimicked by some other field (specifically, the number
1469
     of relocs in section 3).  Since this routine can only be called
1470
     correctly for a PEI file, check the e_magic number here, and, if
1471
     it doesn't match, clobber the f_magic number so that we don't get
1472
     a false match.  */
1473
209k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1474
134k
    {
1475
134k
      bfd_set_error (bfd_error_wrong_format);
1476
134k
      return NULL;
1477
134k
    }
1478
1479
74.5k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1480
74.5k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1481
74.5k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1482
582
    {
1483
582
      if (bfd_get_error () != bfd_error_system_call)
1484
582
  bfd_set_error (bfd_error_wrong_format);
1485
582
      return NULL;
1486
582
    }
1487
1488
73.9k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1489
1.56k
    {
1490
1.56k
      bfd_set_error (bfd_error_wrong_format);
1491
1.56k
      return NULL;
1492
1.56k
    }
1493
1494
  /* Swap file header, so that we get the location for calling
1495
     real_object_p.  */
1496
72.4k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1497
1498
72.4k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1499
72.4k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1500
61.5k
    {
1501
61.5k
      bfd_set_error (bfd_error_wrong_format);
1502
61.5k
      return NULL;
1503
61.5k
    }
1504
1505
10.9k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1506
10.9k
    sizeof (internal_f.pe.dos_message));
1507
1508
  /* Read the optional header, which has variable size.  */
1509
10.9k
  opt_hdr_size = internal_f.f_opthdr;
1510
1511
10.9k
  if (opt_hdr_size != 0)
1512
7.78k
    {
1513
7.78k
      bfd_size_type amt = opt_hdr_size;
1514
7.78k
      bfd_byte * opthdr;
1515
1516
      /* PR 17521 file: 230-131433-0.004.  */
1517
7.78k
      if (amt < sizeof (PEAOUTHDR))
1518
6.65k
  amt = sizeof (PEAOUTHDR);
1519
1520
7.78k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1521
7.78k
      if (opthdr == NULL)
1522
442
  return NULL;
1523
7.34k
      if (amt > opt_hdr_size)
1524
6.31k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1525
1526
7.34k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1527
1528
7.34k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1529
1530
#ifdef ARM
1531
      /* Use Subsystem to distinguish between pei-arm-little and
1532
   pei-arm-wince-little.  */
1533
#ifdef WINCE
1534
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1535
#else
1536
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1537
#endif
1538
  {
1539
    bfd_set_error (bfd_error_wrong_format);
1540
    return NULL;
1541
  }
1542
#endif
1543
1544
7.34k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1545
7.34k
    || a->SectionAlignment >= 0x80000000)
1546
4.07k
  {
1547
4.07k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1548
4.07k
        abfd);
1549
4.07k
    a->SectionAlignment &= -a->SectionAlignment;
1550
4.07k
    if (a->SectionAlignment >= 0x80000000)
1551
1
      a->SectionAlignment = 0x40000000;
1552
4.07k
  }
1553
1554
7.34k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1555
7.34k
    || a->FileAlignment > a->SectionAlignment)
1556
5.68k
  {
1557
5.68k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1558
5.68k
            abfd);
1559
5.68k
    a->FileAlignment &= -a->FileAlignment;
1560
5.68k
    if (a->FileAlignment > a->SectionAlignment)
1561
2.82k
      a->FileAlignment = a->SectionAlignment;
1562
5.68k
  }
1563
1564
7.34k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1565
4.06k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1566
7.34k
    }
1567
1568
10.4k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1569
10.4k
             (opt_hdr_size != 0
1570
10.4k
        ? &internal_a
1571
10.4k
        : (struct internal_aouthdr *) NULL));
1572
1573
10.4k
  if (result)
1574
6.23k
    {
1575
      /* Now the whole header has been processed, see if there is a build-id */
1576
6.23k
      pe_bfd_read_buildid(abfd);
1577
6.23k
    }
1578
1579
10.4k
  return result;
1580
10.9k
}
pei-aarch64.c:pe_bfd_object_p
Line
Count
Source
1430
262k
{
1431
262k
  bfd_byte buffer[6];
1432
262k
  struct external_DOS_hdr dos_hdr;
1433
262k
  struct external_PEI_IMAGE_hdr image_hdr;
1434
262k
  struct internal_filehdr internal_f;
1435
262k
  struct internal_aouthdr internal_a;
1436
262k
  bfd_size_type opt_hdr_size;
1437
262k
  file_ptr offset;
1438
262k
  bfd_cleanup result;
1439
1440
  /* Detect if this a Microsoft Import Library Format element.  */
1441
  /* First read the beginning of the header.  */
1442
262k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1443
262k
      || bfd_read (buffer, 6, abfd) != 6)
1444
908
    {
1445
908
      if (bfd_get_error () != bfd_error_system_call)
1446
804
  bfd_set_error (bfd_error_wrong_format);
1447
908
      return NULL;
1448
908
    }
1449
1450
  /* Then check the magic and the version (only 0 is supported).  */
1451
261k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1452
261k
      && H_GET_16 (abfd, buffer + 4) == 0)
1453
6.77k
    return pe_ILF_object_p (abfd);
1454
1455
254k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1456
254k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1457
50.4k
    {
1458
50.4k
      if (bfd_get_error () != bfd_error_system_call)
1459
50.4k
  bfd_set_error (bfd_error_wrong_format);
1460
50.4k
      return NULL;
1461
50.4k
    }
1462
1463
  /* There are really two magic numbers involved; the magic number
1464
     that says this is a NT executable (PEI) and the magic number that
1465
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1466
     the e_magic field.  The latter is stored in the f_magic field.
1467
     If the NT magic number isn't valid, the architecture magic number
1468
     could be mimicked by some other field (specifically, the number
1469
     of relocs in section 3).  Since this routine can only be called
1470
     correctly for a PEI file, check the e_magic number here, and, if
1471
     it doesn't match, clobber the f_magic number so that we don't get
1472
     a false match.  */
1473
204k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1474
132k
    {
1475
132k
      bfd_set_error (bfd_error_wrong_format);
1476
132k
      return NULL;
1477
132k
    }
1478
1479
72.3k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1480
72.3k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1481
72.3k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1482
659
    {
1483
659
      if (bfd_get_error () != bfd_error_system_call)
1484
659
  bfd_set_error (bfd_error_wrong_format);
1485
659
      return NULL;
1486
659
    }
1487
1488
71.6k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1489
1.68k
    {
1490
1.68k
      bfd_set_error (bfd_error_wrong_format);
1491
1.68k
      return NULL;
1492
1.68k
    }
1493
1494
  /* Swap file header, so that we get the location for calling
1495
     real_object_p.  */
1496
69.9k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1497
1498
69.9k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1499
69.9k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1500
64.6k
    {
1501
64.6k
      bfd_set_error (bfd_error_wrong_format);
1502
64.6k
      return NULL;
1503
64.6k
    }
1504
1505
5.30k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1506
5.30k
    sizeof (internal_f.pe.dos_message));
1507
1508
  /* Read the optional header, which has variable size.  */
1509
5.30k
  opt_hdr_size = internal_f.f_opthdr;
1510
1511
5.30k
  if (opt_hdr_size != 0)
1512
4.09k
    {
1513
4.09k
      bfd_size_type amt = opt_hdr_size;
1514
4.09k
      bfd_byte * opthdr;
1515
1516
      /* PR 17521 file: 230-131433-0.004.  */
1517
4.09k
      if (amt < sizeof (PEAOUTHDR))
1518
1.68k
  amt = sizeof (PEAOUTHDR);
1519
1520
4.09k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1521
4.09k
      if (opthdr == NULL)
1522
346
  return NULL;
1523
3.75k
      if (amt > opt_hdr_size)
1524
1.57k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1525
1526
3.75k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1527
1528
3.75k
      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
3.75k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1545
3.75k
    || a->SectionAlignment >= 0x80000000)
1546
2.26k
  {
1547
2.26k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1548
2.26k
        abfd);
1549
2.26k
    a->SectionAlignment &= -a->SectionAlignment;
1550
2.26k
    if (a->SectionAlignment >= 0x80000000)
1551
240
      a->SectionAlignment = 0x40000000;
1552
2.26k
  }
1553
1554
3.75k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1555
3.75k
    || a->FileAlignment > a->SectionAlignment)
1556
2.41k
  {
1557
2.41k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1558
2.41k
            abfd);
1559
2.41k
    a->FileAlignment &= -a->FileAlignment;
1560
2.41k
    if (a->FileAlignment > a->SectionAlignment)
1561
896
      a->FileAlignment = a->SectionAlignment;
1562
2.41k
  }
1563
1564
3.75k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1565
2.65k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1566
3.75k
    }
1567
1568
4.95k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1569
4.95k
             (opt_hdr_size != 0
1570
4.95k
        ? &internal_a
1571
4.95k
        : (struct internal_aouthdr *) NULL));
1572
1573
4.95k
  if (result)
1574
1.96k
    {
1575
      /* Now the whole header has been processed, see if there is a build-id */
1576
1.96k
      pe_bfd_read_buildid(abfd);
1577
1.96k
    }
1578
1579
4.95k
  return result;
1580
5.30k
}
pei-ia64.c:pe_bfd_object_p
Line
Count
Source
1430
68.3k
{
1431
68.3k
  bfd_byte buffer[6];
1432
68.3k
  struct external_DOS_hdr dos_hdr;
1433
68.3k
  struct external_PEI_IMAGE_hdr image_hdr;
1434
68.3k
  struct internal_filehdr internal_f;
1435
68.3k
  struct internal_aouthdr internal_a;
1436
68.3k
  bfd_size_type opt_hdr_size;
1437
68.3k
  file_ptr offset;
1438
68.3k
  bfd_cleanup result;
1439
1440
  /* Detect if this a Microsoft Import Library Format element.  */
1441
  /* First read the beginning of the header.  */
1442
68.3k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1443
68.3k
      || 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
68.3k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1452
68.3k
      && H_GET_16 (abfd, buffer + 4) == 0)
1453
0
    return pe_ILF_object_p (abfd);
1454
1455
68.3k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1456
68.3k
      || 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
68.3k
  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
68.3k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1480
68.3k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1481
68.3k
      || 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
68.3k
  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
68.3k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1497
1498
68.3k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1499
68.3k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1500
61.7k
    {
1501
61.7k
      bfd_set_error (bfd_error_wrong_format);
1502
61.7k
      return NULL;
1503
61.7k
    }
1504
1505
6.68k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1506
6.68k
    sizeof (internal_f.pe.dos_message));
1507
1508
  /* Read the optional header, which has variable size.  */
1509
6.68k
  opt_hdr_size = internal_f.f_opthdr;
1510
1511
6.68k
  if (opt_hdr_size != 0)
1512
4.72k
    {
1513
4.72k
      bfd_size_type amt = opt_hdr_size;
1514
4.72k
      bfd_byte * opthdr;
1515
1516
      /* PR 17521 file: 230-131433-0.004.  */
1517
4.72k
      if (amt < sizeof (PEAOUTHDR))
1518
3.26k
  amt = sizeof (PEAOUTHDR);
1519
1520
4.72k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1521
4.72k
      if (opthdr == NULL)
1522
242
  return NULL;
1523
4.48k
      if (amt > opt_hdr_size)
1524
3.02k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1525
1526
4.48k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1527
1528
4.48k
      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
4.48k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1545
4.48k
    || a->SectionAlignment >= 0x80000000)
1546
2.99k
  {
1547
2.99k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1548
2.99k
        abfd);
1549
2.99k
    a->SectionAlignment &= -a->SectionAlignment;
1550
2.99k
    if (a->SectionAlignment >= 0x80000000)
1551
2
      a->SectionAlignment = 0x40000000;
1552
2.99k
  }
1553
1554
4.48k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1555
4.48k
    || a->FileAlignment > a->SectionAlignment)
1556
4.07k
  {
1557
4.07k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1558
4.07k
            abfd);
1559
4.07k
    a->FileAlignment &= -a->FileAlignment;
1560
4.07k
    if (a->FileAlignment > a->SectionAlignment)
1561
1.45k
      a->FileAlignment = a->SectionAlignment;
1562
4.07k
  }
1563
1564
4.48k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1565
2.99k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1566
4.48k
    }
1567
1568
6.43k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1569
6.43k
             (opt_hdr_size != 0
1570
6.43k
        ? &internal_a
1571
6.43k
        : (struct internal_aouthdr *) NULL));
1572
1573
6.43k
  if (result)
1574
2.90k
    {
1575
      /* Now the whole header has been processed, see if there is a build-id */
1576
2.90k
      pe_bfd_read_buildid(abfd);
1577
2.90k
    }
1578
1579
6.43k
  return result;
1580
6.68k
}
pei-loongarch64.c:pe_bfd_object_p
Line
Count
Source
1430
262k
{
1431
262k
  bfd_byte buffer[6];
1432
262k
  struct external_DOS_hdr dos_hdr;
1433
262k
  struct external_PEI_IMAGE_hdr image_hdr;
1434
262k
  struct internal_filehdr internal_f;
1435
262k
  struct internal_aouthdr internal_a;
1436
262k
  bfd_size_type opt_hdr_size;
1437
262k
  file_ptr offset;
1438
262k
  bfd_cleanup result;
1439
1440
  /* Detect if this a Microsoft Import Library Format element.  */
1441
  /* First read the beginning of the header.  */
1442
262k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1443
262k
      || bfd_read (buffer, 6, abfd) != 6)
1444
908
    {
1445
908
      if (bfd_get_error () != bfd_error_system_call)
1446
804
  bfd_set_error (bfd_error_wrong_format);
1447
908
      return NULL;
1448
908
    }
1449
1450
  /* Then check the magic and the version (only 0 is supported).  */
1451
261k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1452
261k
      && H_GET_16 (abfd, buffer + 4) == 0)
1453
3.26k
    return pe_ILF_object_p (abfd);
1454
1455
258k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1456
258k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1457
50.6k
    {
1458
50.6k
      if (bfd_get_error () != bfd_error_system_call)
1459
50.6k
  bfd_set_error (bfd_error_wrong_format);
1460
50.6k
      return NULL;
1461
50.6k
    }
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
207k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1474
135k
    {
1475
135k
      bfd_set_error (bfd_error_wrong_format);
1476
135k
      return NULL;
1477
135k
    }
1478
1479
72.0k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1480
72.0k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1481
72.0k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1482
582
    {
1483
582
      if (bfd_get_error () != bfd_error_system_call)
1484
582
  bfd_set_error (bfd_error_wrong_format);
1485
582
      return NULL;
1486
582
    }
1487
1488
71.4k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1489
1.56k
    {
1490
1.56k
      bfd_set_error (bfd_error_wrong_format);
1491
1.56k
      return NULL;
1492
1.56k
    }
1493
1494
  /* Swap file header, so that we get the location for calling
1495
     real_object_p.  */
1496
69.9k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1497
1498
69.9k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1499
69.9k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1500
62.2k
    {
1501
62.2k
      bfd_set_error (bfd_error_wrong_format);
1502
62.2k
      return NULL;
1503
62.2k
    }
1504
1505
7.64k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1506
7.64k
    sizeof (internal_f.pe.dos_message));
1507
1508
  /* Read the optional header, which has variable size.  */
1509
7.64k
  opt_hdr_size = internal_f.f_opthdr;
1510
1511
7.64k
  if (opt_hdr_size != 0)
1512
6.11k
    {
1513
6.11k
      bfd_size_type amt = opt_hdr_size;
1514
6.11k
      bfd_byte * opthdr;
1515
1516
      /* PR 17521 file: 230-131433-0.004.  */
1517
6.11k
      if (amt < sizeof (PEAOUTHDR))
1518
3.33k
  amt = sizeof (PEAOUTHDR);
1519
1520
6.11k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1521
6.11k
      if (opthdr == NULL)
1522
345
  return NULL;
1523
5.77k
      if (amt > opt_hdr_size)
1524
3.33k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1525
1526
5.77k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1527
1528
5.77k
      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
5.77k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1545
5.77k
    || a->SectionAlignment >= 0x80000000)
1546
3.10k
  {
1547
3.10k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1548
3.10k
        abfd);
1549
3.10k
    a->SectionAlignment &= -a->SectionAlignment;
1550
3.10k
    if (a->SectionAlignment >= 0x80000000)
1551
241
      a->SectionAlignment = 0x40000000;
1552
3.10k
  }
1553
1554
5.77k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1555
5.77k
    || a->FileAlignment > a->SectionAlignment)
1556
3.51k
  {
1557
3.51k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1558
3.51k
            abfd);
1559
3.51k
    a->FileAlignment &= -a->FileAlignment;
1560
3.51k
    if (a->FileAlignment > a->SectionAlignment)
1561
1.22k
      a->FileAlignment = a->SectionAlignment;
1562
3.51k
  }
1563
1564
5.77k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1565
3.13k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1566
5.77k
    }
1567
1568
7.29k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1569
7.29k
             (opt_hdr_size != 0
1570
7.29k
        ? &internal_a
1571
7.29k
        : (struct internal_aouthdr *) NULL));
1572
1573
7.29k
  if (result)
1574
2.42k
    {
1575
      /* Now the whole header has been processed, see if there is a build-id */
1576
2.42k
      pe_bfd_read_buildid(abfd);
1577
2.42k
    }
1578
1579
7.29k
  return result;
1580
7.64k
}
pei-arm-wince.c:pe_bfd_object_p
Line
Count
Source
1430
525k
{
1431
525k
  bfd_byte buffer[6];
1432
525k
  struct external_DOS_hdr dos_hdr;
1433
525k
  struct external_PEI_IMAGE_hdr image_hdr;
1434
525k
  struct internal_filehdr internal_f;
1435
525k
  struct internal_aouthdr internal_a;
1436
525k
  bfd_size_type opt_hdr_size;
1437
525k
  file_ptr offset;
1438
525k
  bfd_cleanup result;
1439
1440
  /* Detect if this a Microsoft Import Library Format element.  */
1441
  /* First read the beginning of the header.  */
1442
525k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1443
525k
      || bfd_read (buffer, 6, abfd) != 6)
1444
1.81k
    {
1445
1.81k
      if (bfd_get_error () != bfd_error_system_call)
1446
1.60k
  bfd_set_error (bfd_error_wrong_format);
1447
1.81k
      return NULL;
1448
1.81k
    }
1449
1450
  /* Then check the magic and the version (only 0 is supported).  */
1451
523k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1452
523k
      && H_GET_16 (abfd, buffer + 4) == 0)
1453
5.48k
    return pe_ILF_object_p (abfd);
1454
1455
518k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1456
518k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1457
104k
    {
1458
104k
      if (bfd_get_error () != bfd_error_system_call)
1459
104k
  bfd_set_error (bfd_error_wrong_format);
1460
104k
      return NULL;
1461
104k
    }
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
413k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1474
340k
    {
1475
340k
      bfd_set_error (bfd_error_wrong_format);
1476
340k
      return NULL;
1477
340k
    }
1478
1479
72.3k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1480
72.3k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1481
72.3k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1482
659
    {
1483
659
      if (bfd_get_error () != bfd_error_system_call)
1484
659
  bfd_set_error (bfd_error_wrong_format);
1485
659
      return NULL;
1486
659
    }
1487
1488
71.6k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1489
1.68k
    {
1490
1.68k
      bfd_set_error (bfd_error_wrong_format);
1491
1.68k
      return NULL;
1492
1.68k
    }
1493
1494
  /* Swap file header, so that we get the location for calling
1495
     real_object_p.  */
1496
69.9k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1497
1498
69.9k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1499
69.9k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1500
55.6k
    {
1501
55.6k
      bfd_set_error (bfd_error_wrong_format);
1502
55.6k
      return NULL;
1503
55.6k
    }
1504
1505
14.3k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1506
14.3k
    sizeof (internal_f.pe.dos_message));
1507
1508
  /* Read the optional header, which has variable size.  */
1509
14.3k
  opt_hdr_size = internal_f.f_opthdr;
1510
1511
14.3k
  if (opt_hdr_size != 0)
1512
9.41k
    {
1513
9.41k
      bfd_size_type amt = opt_hdr_size;
1514
9.41k
      bfd_byte * opthdr;
1515
1516
      /* PR 17521 file: 230-131433-0.004.  */
1517
9.41k
      if (amt < sizeof (PEAOUTHDR))
1518
7.01k
  amt = sizeof (PEAOUTHDR);
1519
1520
9.41k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1521
9.41k
      if (opthdr == NULL)
1522
447
  return NULL;
1523
8.96k
      if (amt > opt_hdr_size)
1524
6.90k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1525
1526
8.96k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1527
1528
8.96k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1529
1530
8.96k
#ifdef ARM
1531
      /* Use Subsystem to distinguish between pei-arm-little and
1532
   pei-arm-wince-little.  */
1533
8.96k
#ifdef WINCE
1534
8.96k
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1535
#else
1536
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1537
#endif
1538
4.60k
  {
1539
4.60k
    bfd_set_error (bfd_error_wrong_format);
1540
4.60k
    return NULL;
1541
4.60k
  }
1542
4.35k
#endif
1543
1544
4.35k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1545
4.35k
    || a->SectionAlignment >= 0x80000000)
1546
963
  {
1547
963
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1548
963
        abfd);
1549
963
    a->SectionAlignment &= -a->SectionAlignment;
1550
963
    if (a->SectionAlignment >= 0x80000000)
1551
0
      a->SectionAlignment = 0x40000000;
1552
963
  }
1553
1554
4.35k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1555
4.35k
    || a->FileAlignment > a->SectionAlignment)
1556
3.19k
  {
1557
3.19k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1558
3.19k
            abfd);
1559
3.19k
    a->FileAlignment &= -a->FileAlignment;
1560
3.19k
    if (a->FileAlignment > a->SectionAlignment)
1561
2.84k
      a->FileAlignment = a->SectionAlignment;
1562
3.19k
  }
1563
1564
4.35k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1565
4.00k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1566
4.35k
    }
1567
1568
9.28k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1569
9.28k
             (opt_hdr_size != 0
1570
9.28k
        ? &internal_a
1571
9.28k
        : (struct internal_aouthdr *) NULL));
1572
1573
9.28k
  if (result)
1574
3.71k
    {
1575
      /* Now the whole header has been processed, see if there is a build-id */
1576
3.71k
      pe_bfd_read_buildid(abfd);
1577
3.71k
    }
1578
1579
9.28k
  return result;
1580
14.3k
}
pei-arm.c:pe_bfd_object_p
Line
Count
Source
1430
525k
{
1431
525k
  bfd_byte buffer[6];
1432
525k
  struct external_DOS_hdr dos_hdr;
1433
525k
  struct external_PEI_IMAGE_hdr image_hdr;
1434
525k
  struct internal_filehdr internal_f;
1435
525k
  struct internal_aouthdr internal_a;
1436
525k
  bfd_size_type opt_hdr_size;
1437
525k
  file_ptr offset;
1438
525k
  bfd_cleanup result;
1439
1440
  /* Detect if this a Microsoft Import Library Format element.  */
1441
  /* First read the beginning of the header.  */
1442
525k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1443
525k
      || bfd_read (buffer, 6, abfd) != 6)
1444
1.81k
    {
1445
1.81k
      if (bfd_get_error () != bfd_error_system_call)
1446
1.60k
  bfd_set_error (bfd_error_wrong_format);
1447
1.81k
      return NULL;
1448
1.81k
    }
1449
1450
  /* Then check the magic and the version (only 0 is supported).  */
1451
523k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1452
523k
      && H_GET_16 (abfd, buffer + 4) == 0)
1453
6.29k
    return pe_ILF_object_p (abfd);
1454
1455
517k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1456
517k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1457
105k
    {
1458
105k
      if (bfd_get_error () != bfd_error_system_call)
1459
105k
  bfd_set_error (bfd_error_wrong_format);
1460
105k
      return NULL;
1461
105k
    }
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
411k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1474
339k
    {
1475
339k
      bfd_set_error (bfd_error_wrong_format);
1476
339k
      return NULL;
1477
339k
    }
1478
1479
72.3k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1480
72.3k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1481
72.3k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1482
659
    {
1483
659
      if (bfd_get_error () != bfd_error_system_call)
1484
659
  bfd_set_error (bfd_error_wrong_format);
1485
659
      return NULL;
1486
659
    }
1487
1488
71.6k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1489
1.68k
    {
1490
1.68k
      bfd_set_error (bfd_error_wrong_format);
1491
1.68k
      return NULL;
1492
1.68k
    }
1493
1494
  /* Swap file header, so that we get the location for calling
1495
     real_object_p.  */
1496
69.9k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1497
1498
69.9k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1499
69.9k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1500
55.6k
    {
1501
55.6k
      bfd_set_error (bfd_error_wrong_format);
1502
55.6k
      return NULL;
1503
55.6k
    }
1504
1505
14.3k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1506
14.3k
    sizeof (internal_f.pe.dos_message));
1507
1508
  /* Read the optional header, which has variable size.  */
1509
14.3k
  opt_hdr_size = internal_f.f_opthdr;
1510
1511
14.3k
  if (opt_hdr_size != 0)
1512
9.40k
    {
1513
9.40k
      bfd_size_type amt = opt_hdr_size;
1514
9.40k
      bfd_byte * opthdr;
1515
1516
      /* PR 17521 file: 230-131433-0.004.  */
1517
9.40k
      if (amt < sizeof (PEAOUTHDR))
1518
7.00k
  amt = sizeof (PEAOUTHDR);
1519
1520
9.40k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1521
9.40k
      if (opthdr == NULL)
1522
447
  return NULL;
1523
8.95k
      if (amt > opt_hdr_size)
1524
6.90k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1525
1526
8.95k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1527
1528
8.95k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1529
1530
8.95k
#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
8.95k
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1537
4.34k
#endif
1538
4.34k
  {
1539
4.34k
    bfd_set_error (bfd_error_wrong_format);
1540
4.34k
    return NULL;
1541
4.34k
  }
1542
4.61k
#endif
1543
1544
4.61k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1545
4.61k
    || a->SectionAlignment >= 0x80000000)
1546
1.29k
  {
1547
1.29k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1548
1.29k
        abfd);
1549
1.29k
    a->SectionAlignment &= -a->SectionAlignment;
1550
1.29k
    if (a->SectionAlignment >= 0x80000000)
1551
1
      a->SectionAlignment = 0x40000000;
1552
1.29k
  }
1553
1554
4.61k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1555
4.61k
    || a->FileAlignment > a->SectionAlignment)
1556
2.94k
  {
1557
2.94k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1558
2.94k
            abfd);
1559
2.94k
    a->FileAlignment &= -a->FileAlignment;
1560
2.94k
    if (a->FileAlignment > a->SectionAlignment)
1561
1.41k
      a->FileAlignment = a->SectionAlignment;
1562
2.94k
  }
1563
1564
4.61k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1565
3.15k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1566
4.61k
    }
1567
1568
9.53k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1569
9.53k
             (opt_hdr_size != 0
1570
9.53k
        ? &internal_a
1571
9.53k
        : (struct internal_aouthdr *) NULL));
1572
1573
9.53k
  if (result)
1574
2.89k
    {
1575
      /* Now the whole header has been processed, see if there is a build-id */
1576
2.89k
      pe_bfd_read_buildid(abfd);
1577
2.89k
    }
1578
1579
9.53k
  return result;
1580
14.3k
}
pei-mcore.c:pe_bfd_object_p
Line
Count
Source
1430
525k
{
1431
525k
  bfd_byte buffer[6];
1432
525k
  struct external_DOS_hdr dos_hdr;
1433
525k
  struct external_PEI_IMAGE_hdr image_hdr;
1434
525k
  struct internal_filehdr internal_f;
1435
525k
  struct internal_aouthdr internal_a;
1436
525k
  bfd_size_type opt_hdr_size;
1437
525k
  file_ptr offset;
1438
525k
  bfd_cleanup result;
1439
1440
  /* Detect if this a Microsoft Import Library Format element.  */
1441
  /* First read the beginning of the header.  */
1442
525k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1443
525k
      || bfd_read (buffer, 6, abfd) != 6)
1444
1.81k
    {
1445
1.81k
      if (bfd_get_error () != bfd_error_system_call)
1446
1.60k
  bfd_set_error (bfd_error_wrong_format);
1447
1.81k
      return NULL;
1448
1.81k
    }
1449
1450
  /* Then check the magic and the version (only 0 is supported).  */
1451
523k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1452
523k
      && H_GET_16 (abfd, buffer + 4) == 0)
1453
5.25k
    return pe_ILF_object_p (abfd);
1454
1455
518k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1456
518k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1457
104k
    {
1458
104k
      if (bfd_get_error () != bfd_error_system_call)
1459
104k
  bfd_set_error (bfd_error_wrong_format);
1460
104k
      return NULL;
1461
104k
    }
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
413k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1474
341k
    {
1475
341k
      bfd_set_error (bfd_error_wrong_format);
1476
341k
      return NULL;
1477
341k
    }
1478
1479
72.1k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1480
72.1k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1481
72.1k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1482
582
    {
1483
582
      if (bfd_get_error () != bfd_error_system_call)
1484
582
  bfd_set_error (bfd_error_wrong_format);
1485
582
      return NULL;
1486
582
    }
1487
1488
71.5k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1489
1.57k
    {
1490
1.57k
      bfd_set_error (bfd_error_wrong_format);
1491
1.57k
      return NULL;
1492
1.57k
    }
1493
1494
  /* Swap file header, so that we get the location for calling
1495
     real_object_p.  */
1496
69.9k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1497
1498
69.9k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1499
69.9k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1500
61.3k
    {
1501
61.3k
      bfd_set_error (bfd_error_wrong_format);
1502
61.3k
      return NULL;
1503
61.3k
    }
1504
1505
8.57k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1506
8.57k
    sizeof (internal_f.pe.dos_message));
1507
1508
  /* Read the optional header, which has variable size.  */
1509
8.57k
  opt_hdr_size = internal_f.f_opthdr;
1510
1511
8.57k
  if (opt_hdr_size != 0)
1512
6.34k
    {
1513
6.34k
      bfd_size_type amt = opt_hdr_size;
1514
6.34k
      bfd_byte * opthdr;
1515
1516
      /* PR 17521 file: 230-131433-0.004.  */
1517
6.34k
      if (amt < sizeof (PEAOUTHDR))
1518
3.77k
  amt = sizeof (PEAOUTHDR);
1519
1520
6.34k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1521
6.34k
      if (opthdr == NULL)
1522
241
  return NULL;
1523
6.10k
      if (amt > opt_hdr_size)
1524
3.63k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1525
1526
6.10k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1527
1528
6.10k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1529
1530
#ifdef ARM
1531
      /* Use Subsystem to distinguish between pei-arm-little and
1532
   pei-arm-wince-little.  */
1533
#ifdef WINCE
1534
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1535
#else
1536
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1537
#endif
1538
  {
1539
    bfd_set_error (bfd_error_wrong_format);
1540
    return NULL;
1541
  }
1542
#endif
1543
1544
6.10k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1545
6.10k
    || a->SectionAlignment >= 0x80000000)
1546
2.14k
  {
1547
2.14k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1548
2.14k
        abfd);
1549
2.14k
    a->SectionAlignment &= -a->SectionAlignment;
1550
2.14k
    if (a->SectionAlignment >= 0x80000000)
1551
1
      a->SectionAlignment = 0x40000000;
1552
2.14k
  }
1553
1554
6.10k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1555
6.10k
    || a->FileAlignment > a->SectionAlignment)
1556
5.00k
  {
1557
5.00k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1558
5.00k
            abfd);
1559
5.00k
    a->FileAlignment &= -a->FileAlignment;
1560
5.00k
    if (a->FileAlignment > a->SectionAlignment)
1561
3.80k
      a->FileAlignment = a->SectionAlignment;
1562
5.00k
  }
1563
1564
6.10k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1565
4.70k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1566
6.10k
    }
1567
1568
8.33k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1569
8.33k
             (opt_hdr_size != 0
1570
8.33k
        ? &internal_a
1571
8.33k
        : (struct internal_aouthdr *) NULL));
1572
1573
8.33k
  if (result)
1574
4.75k
    {
1575
      /* Now the whole header has been processed, see if there is a build-id */
1576
4.75k
      pe_bfd_read_buildid(abfd);
1577
4.75k
    }
1578
1579
8.33k
  return result;
1580
8.57k
}
pei-sh.c:pe_bfd_object_p
Line
Count
Source
1430
262k
{
1431
262k
  bfd_byte buffer[6];
1432
262k
  struct external_DOS_hdr dos_hdr;
1433
262k
  struct external_PEI_IMAGE_hdr image_hdr;
1434
262k
  struct internal_filehdr internal_f;
1435
262k
  struct internal_aouthdr internal_a;
1436
262k
  bfd_size_type opt_hdr_size;
1437
262k
  file_ptr offset;
1438
262k
  bfd_cleanup result;
1439
1440
  /* Detect if this a Microsoft Import Library Format element.  */
1441
  /* First read the beginning of the header.  */
1442
262k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1443
262k
      || bfd_read (buffer, 6, abfd) != 6)
1444
908
    {
1445
908
      if (bfd_get_error () != bfd_error_system_call)
1446
804
  bfd_set_error (bfd_error_wrong_format);
1447
908
      return NULL;
1448
908
    }
1449
1450
  /* Then check the magic and the version (only 0 is supported).  */
1451
261k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1452
261k
      && H_GET_16 (abfd, buffer + 4) == 0)
1453
5.23k
    return pe_ILF_object_p (abfd);
1454
1455
256k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1456
256k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1457
50.4k
    {
1458
50.4k
      if (bfd_get_error () != bfd_error_system_call)
1459
50.4k
  bfd_set_error (bfd_error_wrong_format);
1460
50.4k
      return NULL;
1461
50.4k
    }
1462
1463
  /* There are really two magic numbers involved; the magic number
1464
     that says this is a NT executable (PEI) and the magic number that
1465
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1466
     the e_magic field.  The latter is stored in the f_magic field.
1467
     If the NT magic number isn't valid, the architecture magic number
1468
     could be mimicked by some other field (specifically, the number
1469
     of relocs in section 3).  Since this routine can only be called
1470
     correctly for a PEI file, check the e_magic number here, and, if
1471
     it doesn't match, clobber the f_magic number so that we don't get
1472
     a false match.  */
1473
206k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1474
134k
    {
1475
134k
      bfd_set_error (bfd_error_wrong_format);
1476
134k
      return NULL;
1477
134k
    }
1478
1479
72.0k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1480
72.0k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1481
72.0k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1482
582
    {
1483
582
      if (bfd_get_error () != bfd_error_system_call)
1484
582
  bfd_set_error (bfd_error_wrong_format);
1485
582
      return NULL;
1486
582
    }
1487
1488
71.4k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1489
1.56k
    {
1490
1.56k
      bfd_set_error (bfd_error_wrong_format);
1491
1.56k
      return NULL;
1492
1.56k
    }
1493
1494
  /* Swap file header, so that we get the location for calling
1495
     real_object_p.  */
1496
69.9k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1497
1498
69.9k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1499
69.9k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1500
62.7k
    {
1501
62.7k
      bfd_set_error (bfd_error_wrong_format);
1502
62.7k
      return NULL;
1503
62.7k
    }
1504
1505
7.17k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1506
7.17k
    sizeof (internal_f.pe.dos_message));
1507
1508
  /* Read the optional header, which has variable size.  */
1509
7.17k
  opt_hdr_size = internal_f.f_opthdr;
1510
1511
7.17k
  if (opt_hdr_size != 0)
1512
4.06k
    {
1513
4.06k
      bfd_size_type amt = opt_hdr_size;
1514
4.06k
      bfd_byte * opthdr;
1515
1516
      /* PR 17521 file: 230-131433-0.004.  */
1517
4.06k
      if (amt < sizeof (PEAOUTHDR))
1518
3.59k
  amt = sizeof (PEAOUTHDR);
1519
1520
4.06k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1521
4.06k
      if (opthdr == NULL)
1522
343
  return NULL;
1523
3.72k
      if (amt > opt_hdr_size)
1524
3.48k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1525
1526
3.72k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1527
1528
3.72k
      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
3.72k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1545
3.72k
    || a->SectionAlignment >= 0x80000000)
1546
2.41k
  {
1547
2.41k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1548
2.41k
        abfd);
1549
2.41k
    a->SectionAlignment &= -a->SectionAlignment;
1550
2.41k
    if (a->SectionAlignment >= 0x80000000)
1551
5
      a->SectionAlignment = 0x40000000;
1552
2.41k
  }
1553
1554
3.72k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1555
3.72k
    || a->FileAlignment > a->SectionAlignment)
1556
2.88k
  {
1557
2.88k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1558
2.88k
            abfd);
1559
2.88k
    a->FileAlignment &= -a->FileAlignment;
1560
2.88k
    if (a->FileAlignment > a->SectionAlignment)
1561
1.44k
      a->FileAlignment = a->SectionAlignment;
1562
2.88k
  }
1563
1564
3.72k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1565
2.54k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1566
3.72k
    }
1567
1568
6.83k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1569
6.83k
             (opt_hdr_size != 0
1570
6.83k
        ? &internal_a
1571
6.83k
        : (struct internal_aouthdr *) NULL));
1572
1573
6.83k
  if (result)
1574
2.93k
    {
1575
      /* Now the whole header has been processed, see if there is a build-id */
1576
2.93k
      pe_bfd_read_buildid(abfd);
1577
2.93k
    }
1578
1579
6.83k
  return result;
1580
7.17k
}
1581
1582
68.3k
#define coff_object_p pe_bfd_object_p
1583
#endif /* COFF_IMAGE_WITH_PE */