Coverage Report

Created: 2026-07-25 10:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/binutils-gdb/bfd/peicode.h
Line
Count
Source
1
/* Support for the generic parts of PE/PEI, for BFD.
2
   Copyright (C) 1995-2026 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
86
/* For the case of linking ELF objects into a PE binary.  */
87
#undef TARGET_MERGE_SECTIONS
88
#define TARGET_MERGE_SECTIONS true
89
90
/* This structure contains static variables used by the ILF code.  */
91
typedef asection * asection_ptr;
92
93
typedef struct
94
{
95
  bfd *     abfd;
96
  bfd_byte *    data;
97
  struct bfd_in_memory * bim;
98
  unsigned short  magic;
99
100
  arelent *   reltab;
101
  unsigned int    relcount;
102
103
  coff_symbol_type *  sym_cache;
104
  coff_symbol_type *  sym_ptr;
105
  unsigned int    sym_index;
106
107
  unsigned int *  sym_table;
108
  unsigned int *  table_ptr;
109
110
  combined_entry_type * native_syms;
111
  combined_entry_type * native_ptr;
112
113
  coff_symbol_type ** sym_ptr_table;
114
  coff_symbol_type ** sym_ptr_ptr;
115
116
  unsigned int    sec_index;
117
118
  char *    string_table;
119
  char *    string_ptr;
120
  char *    end_string_ptr;
121
122
  SYMENT *    esym_table;
123
  SYMENT *    esym_ptr;
124
125
  struct internal_reloc * int_reltab;
126
}
127
pe_ILF_vars;
128
#endif /* COFF_IMAGE_WITH_PE */
129
130
bfd_cleanup coff_real_object_p
131
  (bfd *, unsigned, struct internal_filehdr *, struct internal_aouthdr *);
132

133
#ifndef NO_COFF_RELOCS
134
static void
135
coff_swap_reloc_in (bfd *abfd, void *src, void *dst)
136
70.8k
{
137
70.8k
  RELOC *reloc_src = (RELOC *) src;
138
70.8k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
70.8k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
70.8k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
70.8k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
#ifdef SWAP_IN_RELOC_OFFSET
144
27.7k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
#endif
146
70.8k
}
pei-i386.c:coff_swap_reloc_in
Line
Count
Source
136
4.13k
{
137
4.13k
  RELOC *reloc_src = (RELOC *) src;
138
4.13k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
4.13k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
4.13k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
4.13k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
#ifdef SWAP_IN_RELOC_OFFSET
144
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
#endif
146
4.13k
}
pe-x86_64.c:coff_swap_reloc_in
Line
Count
Source
136
3.67k
{
137
3.67k
  RELOC *reloc_src = (RELOC *) src;
138
3.67k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
3.67k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
3.67k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
3.67k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
#ifdef SWAP_IN_RELOC_OFFSET
144
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
#endif
146
3.67k
}
pei-x86_64.c:coff_swap_reloc_in
Line
Count
Source
136
5.66k
{
137
5.66k
  RELOC *reloc_src = (RELOC *) src;
138
5.66k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
5.66k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
5.66k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
5.66k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
#ifdef SWAP_IN_RELOC_OFFSET
144
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
#endif
146
5.66k
}
pe-aarch64.c:coff_swap_reloc_in
Line
Count
Source
136
10.7k
{
137
10.7k
  RELOC *reloc_src = (RELOC *) src;
138
10.7k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
10.7k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
10.7k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
10.7k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
#ifdef SWAP_IN_RELOC_OFFSET
144
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
#endif
146
10.7k
}
pei-aarch64.c:coff_swap_reloc_in
Line
Count
Source
136
4.76k
{
137
4.76k
  RELOC *reloc_src = (RELOC *) src;
138
4.76k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
4.76k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
4.76k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
4.76k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
#ifdef SWAP_IN_RELOC_OFFSET
144
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
#endif
146
4.76k
}
pei-ia64.c:coff_swap_reloc_in
Line
Count
Source
136
3.23k
{
137
3.23k
  RELOC *reloc_src = (RELOC *) src;
138
3.23k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
3.23k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
3.23k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
3.23k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
#ifdef SWAP_IN_RELOC_OFFSET
144
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
#endif
146
3.23k
}
pei-loongarch64.c:coff_swap_reloc_in
Line
Count
Source
136
3.53k
{
137
3.53k
  RELOC *reloc_src = (RELOC *) src;
138
3.53k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
3.53k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
3.53k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
3.53k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
3.53k
#ifdef SWAP_IN_RELOC_OFFSET
144
3.53k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
3.53k
#endif
146
3.53k
}
pei-riscv64.c:coff_swap_reloc_in
Line
Count
Source
136
3.82k
{
137
3.82k
  RELOC *reloc_src = (RELOC *) src;
138
3.82k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
3.82k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
3.82k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
3.82k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
3.82k
#ifdef SWAP_IN_RELOC_OFFSET
144
3.82k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
3.82k
#endif
146
3.82k
}
pe-arm-wince.c:coff_swap_reloc_in
Line
Count
Source
136
1.81k
{
137
1.81k
  RELOC *reloc_src = (RELOC *) src;
138
1.81k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
1.81k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
1.81k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
1.81k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
1.81k
#ifdef SWAP_IN_RELOC_OFFSET
144
1.81k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
1.81k
#endif
146
1.81k
}
pe-arm.c:coff_swap_reloc_in
Line
Count
Source
136
1.81k
{
137
1.81k
  RELOC *reloc_src = (RELOC *) src;
138
1.81k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
1.81k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
1.81k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
1.81k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
1.81k
#ifdef SWAP_IN_RELOC_OFFSET
144
1.81k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
1.81k
#endif
146
1.81k
}
pe-i386.c:coff_swap_reloc_in
Line
Count
Source
136
4.95k
{
137
4.95k
  RELOC *reloc_src = (RELOC *) src;
138
4.95k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
4.95k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
4.95k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
4.95k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
#ifdef SWAP_IN_RELOC_OFFSET
144
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
#endif
146
4.95k
}
pe-mcore.c:coff_swap_reloc_in
Line
Count
Source
136
4.32k
{
137
4.32k
  RELOC *reloc_src = (RELOC *) src;
138
4.32k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
4.32k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
4.32k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
4.32k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
4.32k
#ifdef SWAP_IN_RELOC_OFFSET
144
4.32k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
4.32k
#endif
146
4.32k
}
pe-sh.c:coff_swap_reloc_in
Line
Count
Source
136
3.54k
{
137
3.54k
  RELOC *reloc_src = (RELOC *) src;
138
3.54k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
3.54k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
3.54k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
3.54k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
#ifdef SWAP_IN_RELOC_OFFSET
144
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
#endif
146
3.54k
}
pei-arm-wince.c:coff_swap_reloc_in
Line
Count
Source
136
4.38k
{
137
4.38k
  RELOC *reloc_src = (RELOC *) src;
138
4.38k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
4.38k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
4.38k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
4.38k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
4.38k
#ifdef SWAP_IN_RELOC_OFFSET
144
4.38k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
4.38k
#endif
146
4.38k
}
pei-arm.c:coff_swap_reloc_in
Line
Count
Source
136
4.57k
{
137
4.57k
  RELOC *reloc_src = (RELOC *) src;
138
4.57k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
4.57k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
4.57k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
4.57k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
4.57k
#ifdef SWAP_IN_RELOC_OFFSET
144
4.57k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
4.57k
#endif
146
4.57k
}
pei-mcore.c:coff_swap_reloc_in
Line
Count
Source
136
3.46k
{
137
3.46k
  RELOC *reloc_src = (RELOC *) src;
138
3.46k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
3.46k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
3.46k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
3.46k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
3.46k
#ifdef SWAP_IN_RELOC_OFFSET
144
3.46k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
3.46k
#endif
146
3.46k
}
pei-sh.c:coff_swap_reloc_in
Line
Count
Source
136
2.44k
{
137
2.44k
  RELOC *reloc_src = (RELOC *) src;
138
2.44k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
2.44k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
2.44k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
2.44k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
#ifdef SWAP_IN_RELOC_OFFSET
144
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
#endif
146
2.44k
}
147
148
static unsigned int
149
coff_swap_reloc_out (bfd *abfd, void *src, void *dst)
150
198
{
151
198
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
152
198
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
153
154
198
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
155
198
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
156
198
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
157
158
#ifdef SWAP_OUT_RELOC_OFFSET
159
117
  SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
160
#endif
161
#ifdef SWAP_OUT_RELOC_EXTRA
162
  SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
163
#endif
164
198
  return RELSZ;
165
198
}
pei-i386.c:coff_swap_reloc_out
Line
Count
Source
150
21
{
151
21
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
152
21
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
153
154
21
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
155
21
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
156
21
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
157
158
#ifdef SWAP_OUT_RELOC_OFFSET
159
  SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
160
#endif
161
#ifdef SWAP_OUT_RELOC_EXTRA
162
  SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
163
#endif
164
21
  return RELSZ;
165
21
}
pe-x86_64.c:coff_swap_reloc_out
Line
Count
Source
150
5
{
151
5
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
152
5
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
153
154
5
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
155
5
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
156
5
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
157
158
#ifdef SWAP_OUT_RELOC_OFFSET
159
  SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
160
#endif
161
#ifdef SWAP_OUT_RELOC_EXTRA
162
  SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
163
#endif
164
5
  return RELSZ;
165
5
}
pei-x86_64.c:coff_swap_reloc_out
Line
Count
Source
150
18
{
151
18
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
152
18
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
153
154
18
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
155
18
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
156
18
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
157
158
#ifdef SWAP_OUT_RELOC_OFFSET
159
  SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
160
#endif
161
#ifdef SWAP_OUT_RELOC_EXTRA
162
  SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
163
#endif
164
18
  return RELSZ;
165
18
}
pe-aarch64.c:coff_swap_reloc_out
Line
Count
Source
150
8
{
151
8
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
152
8
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
153
154
8
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
155
8
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
156
8
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
157
158
#ifdef SWAP_OUT_RELOC_OFFSET
159
  SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
160
#endif
161
#ifdef SWAP_OUT_RELOC_EXTRA
162
  SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
163
#endif
164
8
  return RELSZ;
165
8
}
pei-aarch64.c:coff_swap_reloc_out
Line
Count
Source
150
17
{
151
17
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
152
17
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
153
154
17
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
155
17
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
156
17
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
157
158
#ifdef SWAP_OUT_RELOC_OFFSET
159
  SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
160
#endif
161
#ifdef SWAP_OUT_RELOC_EXTRA
162
  SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
163
#endif
164
17
  return RELSZ;
165
17
}
Unexecuted instantiation: pei-ia64.c:coff_swap_reloc_out
pei-loongarch64.c:coff_swap_reloc_out
Line
Count
Source
150
24
{
151
24
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
152
24
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
153
154
24
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
155
24
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
156
24
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
157
158
24
#ifdef SWAP_OUT_RELOC_OFFSET
159
24
  SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
160
24
#endif
161
#ifdef SWAP_OUT_RELOC_EXTRA
162
  SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
163
#endif
164
24
  return RELSZ;
165
24
}
pei-riscv64.c:coff_swap_reloc_out
Line
Count
Source
150
12
{
151
12
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
152
12
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
153
154
12
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
155
12
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
156
12
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
157
158
12
#ifdef SWAP_OUT_RELOC_OFFSET
159
12
  SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
160
12
#endif
161
#ifdef SWAP_OUT_RELOC_EXTRA
162
  SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
163
#endif
164
12
  return RELSZ;
165
12
}
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
pe-mcore.c:coff_swap_reloc_out
Line
Count
Source
150
80
{
151
80
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
152
80
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
153
154
80
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
155
80
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
156
80
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
157
158
80
#ifdef SWAP_OUT_RELOC_OFFSET
159
80
  SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
160
80
#endif
161
#ifdef SWAP_OUT_RELOC_EXTRA
162
  SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
163
#endif
164
80
  return RELSZ;
165
80
}
Unexecuted instantiation: pe-sh.c:coff_swap_reloc_out
Unexecuted instantiation: pei-arm-wince.c:coff_swap_reloc_out
pei-arm.c:coff_swap_reloc_out
Line
Count
Source
150
1
{
151
1
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
152
1
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
153
154
1
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
155
1
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
156
1
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
157
158
1
#ifdef SWAP_OUT_RELOC_OFFSET
159
1
  SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
160
1
#endif
161
#ifdef SWAP_OUT_RELOC_EXTRA
162
  SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
163
#endif
164
1
  return RELSZ;
165
1
}
Unexecuted instantiation: pei-mcore.c:coff_swap_reloc_out
pei-sh.c:coff_swap_reloc_out
Line
Count
Source
150
12
{
151
12
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
152
12
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
153
154
12
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
155
12
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
156
12
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
157
158
#ifdef SWAP_OUT_RELOC_OFFSET
159
  SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
160
#endif
161
#ifdef SWAP_OUT_RELOC_EXTRA
162
  SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
163
#endif
164
12
  return RELSZ;
165
12
}
166
#endif /* not NO_COFF_RELOCS */
167
168
#ifdef COFF_IMAGE_WITH_PE
169
#undef FILHDR
170
522k
#define FILHDR struct external_PEI_IMAGE_hdr
171
#endif
172
173
static void
174
coff_swap_filehdr_in (bfd *abfd, void *src, void *dst)
175
2.64M
{
176
2.64M
  FILHDR *filehdr_src = (FILHDR *) src;
177
2.64M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
2.64M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
2.64M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
2.64M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
2.64M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
2.64M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
2.64M
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
2.64M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
264k
    {
190
264k
      filehdr_dst->f_nsyms = 0;
191
264k
      filehdr_dst->f_flags |= F_LSYMS;
192
264k
    }
193
194
2.64M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
2.64M
}
pei-i386.c:coff_swap_filehdr_in
Line
Count
Source
175
59.7k
{
176
59.7k
  FILHDR *filehdr_src = (FILHDR *) src;
177
59.7k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
59.7k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
59.7k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
59.7k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
59.7k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
59.7k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
59.7k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
59.7k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
5.73k
    {
190
5.73k
      filehdr_dst->f_nsyms = 0;
191
5.73k
      filehdr_dst->f_flags |= F_LSYMS;
192
5.73k
    }
193
194
59.7k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
59.7k
}
pe-x86_64.c:coff_swap_filehdr_in
Line
Count
Source
175
234k
{
176
234k
  FILHDR *filehdr_src = (FILHDR *) src;
177
234k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
234k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
234k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
234k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
234k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
234k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
234k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
234k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
24.8k
    {
190
24.8k
      filehdr_dst->f_nsyms = 0;
191
24.8k
      filehdr_dst->f_flags |= F_LSYMS;
192
24.8k
    }
193
194
234k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
234k
}
pei-x86_64.c:coff_swap_filehdr_in
Line
Count
Source
175
58.1k
{
176
58.1k
  FILHDR *filehdr_src = (FILHDR *) src;
177
58.1k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
58.1k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
58.1k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
58.1k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
58.1k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
58.1k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
58.1k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
58.1k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
5.45k
    {
190
5.45k
      filehdr_dst->f_nsyms = 0;
191
5.45k
      filehdr_dst->f_flags |= F_LSYMS;
192
5.45k
    }
193
194
58.1k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
58.1k
}
pe-aarch64.c:coff_swap_filehdr_in
Line
Count
Source
175
232k
{
176
232k
  FILHDR *filehdr_src = (FILHDR *) src;
177
232k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
232k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
232k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
232k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
232k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
232k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
232k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
232k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
24.6k
    {
190
24.6k
      filehdr_dst->f_nsyms = 0;
191
24.6k
      filehdr_dst->f_flags |= F_LSYMS;
192
24.6k
    }
193
194
232k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
232k
}
pei-aarch64.c:coff_swap_filehdr_in
Line
Count
Source
175
56.7k
{
176
56.7k
  FILHDR *filehdr_src = (FILHDR *) src;
177
56.7k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
56.7k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
56.7k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
56.7k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
56.7k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
56.7k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
56.7k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
56.7k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
5.39k
    {
190
5.39k
      filehdr_dst->f_nsyms = 0;
191
5.39k
      filehdr_dst->f_flags |= F_LSYMS;
192
5.39k
    }
193
194
56.7k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
56.7k
}
pei-ia64.c:coff_swap_filehdr_in
Line
Count
Source
175
17.2k
{
176
17.2k
  FILHDR *filehdr_src = (FILHDR *) src;
177
17.2k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
17.2k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
17.2k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
17.2k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
17.2k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
17.2k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
17.2k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
17.2k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
627
    {
190
627
      filehdr_dst->f_nsyms = 0;
191
627
      filehdr_dst->f_flags |= F_LSYMS;
192
627
    }
193
194
17.2k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
17.2k
}
pei-loongarch64.c:coff_swap_filehdr_in
Line
Count
Source
175
56.0k
{
176
56.0k
  FILHDR *filehdr_src = (FILHDR *) src;
177
56.0k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
56.0k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
56.0k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
56.0k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
56.0k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
56.0k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
56.0k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
56.0k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
5.30k
    {
190
5.30k
      filehdr_dst->f_nsyms = 0;
191
5.30k
      filehdr_dst->f_flags |= F_LSYMS;
192
5.30k
    }
193
194
56.0k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
56.0k
}
pei-riscv64.c:coff_swap_filehdr_in
Line
Count
Source
175
56.0k
{
176
56.0k
  FILHDR *filehdr_src = (FILHDR *) src;
177
56.0k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
56.0k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
56.0k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
56.0k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
56.0k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
56.0k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
56.0k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
56.0k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
5.23k
    {
190
5.23k
      filehdr_dst->f_nsyms = 0;
191
5.23k
      filehdr_dst->f_flags |= F_LSYMS;
192
5.23k
    }
193
194
56.0k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
56.0k
}
pe-arm-wince.c:coff_swap_filehdr_in
Line
Count
Source
175
405k
{
176
405k
  FILHDR *filehdr_src = (FILHDR *) src;
177
405k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
405k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
405k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
405k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
405k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
405k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
405k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
405k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
40.3k
    {
190
40.3k
      filehdr_dst->f_nsyms = 0;
191
40.3k
      filehdr_dst->f_flags |= F_LSYMS;
192
40.3k
    }
193
194
405k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
405k
}
pe-arm.c:coff_swap_filehdr_in
Line
Count
Source
175
405k
{
176
405k
  FILHDR *filehdr_src = (FILHDR *) src;
177
405k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
405k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
405k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
405k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
405k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
405k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
405k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
405k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
40.3k
    {
190
40.3k
      filehdr_dst->f_nsyms = 0;
191
40.3k
      filehdr_dst->f_flags |= F_LSYMS;
192
40.3k
    }
193
194
405k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
405k
}
pe-i386.c:coff_swap_filehdr_in
Line
Count
Source
175
231k
{
176
231k
  FILHDR *filehdr_src = (FILHDR *) src;
177
231k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
231k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
231k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
231k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
231k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
231k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
231k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
231k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
24.7k
    {
190
24.7k
      filehdr_dst->f_nsyms = 0;
191
24.7k
      filehdr_dst->f_flags |= F_LSYMS;
192
24.7k
    }
193
194
231k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
231k
}
pe-mcore.c:coff_swap_filehdr_in
Line
Count
Source
175
405k
{
176
405k
  FILHDR *filehdr_src = (FILHDR *) src;
177
405k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
405k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
405k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
405k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
405k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
405k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
405k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
405k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
40.6k
    {
190
40.6k
      filehdr_dst->f_nsyms = 0;
191
40.6k
      filehdr_dst->f_flags |= F_LSYMS;
192
40.6k
    }
193
194
405k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
405k
}
pe-sh.c:coff_swap_filehdr_in
Line
Count
Source
175
204k
{
176
204k
  FILHDR *filehdr_src = (FILHDR *) src;
177
204k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
204k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
204k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
204k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
204k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
204k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
204k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
204k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
20.4k
    {
190
20.4k
      filehdr_dst->f_nsyms = 0;
191
20.4k
      filehdr_dst->f_flags |= F_LSYMS;
192
20.4k
    }
193
194
204k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
204k
}
pei-arm-wince.c:coff_swap_filehdr_in
Line
Count
Source
175
54.7k
{
176
54.7k
  FILHDR *filehdr_src = (FILHDR *) src;
177
54.7k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
54.7k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
54.7k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
54.7k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
54.7k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
54.7k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
54.7k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
54.7k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
5.26k
    {
190
5.26k
      filehdr_dst->f_nsyms = 0;
191
5.26k
      filehdr_dst->f_flags |= F_LSYMS;
192
5.26k
    }
193
194
54.7k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
54.7k
}
pei-arm.c:coff_swap_filehdr_in
Line
Count
Source
175
54.7k
{
176
54.7k
  FILHDR *filehdr_src = (FILHDR *) src;
177
54.7k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
54.7k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
54.7k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
54.7k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
54.7k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
54.7k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
54.7k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
54.7k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
5.26k
    {
190
5.26k
      filehdr_dst->f_nsyms = 0;
191
5.26k
      filehdr_dst->f_flags |= F_LSYMS;
192
5.26k
    }
193
194
54.7k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
54.7k
}
pei-mcore.c:coff_swap_filehdr_in
Line
Count
Source
175
54.3k
{
176
54.3k
  FILHDR *filehdr_src = (FILHDR *) src;
177
54.3k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
54.3k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
54.3k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
54.3k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
54.3k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
54.3k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
54.3k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
54.3k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
5.16k
    {
190
5.16k
      filehdr_dst->f_nsyms = 0;
191
5.16k
      filehdr_dst->f_flags |= F_LSYMS;
192
5.16k
    }
193
194
54.3k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
54.3k
}
pei-sh.c:coff_swap_filehdr_in
Line
Count
Source
175
54.2k
{
176
54.2k
  FILHDR *filehdr_src = (FILHDR *) src;
177
54.2k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
54.2k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
54.2k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
54.2k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
54.2k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
54.2k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
54.2k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
54.2k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
5.19k
    {
190
5.19k
      filehdr_dst->f_nsyms = 0;
191
5.19k
      filehdr_dst->f_flags |= F_LSYMS;
192
5.19k
    }
193
194
54.2k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
54.2k
}
196
197
#ifdef COFF_IMAGE_WITH_PE
198
# define coff_swap_filehdr_out _bfd_XXi_only_swap_filehdr_out
199
#elif defined COFF_WITH_peAArch64
200
# define coff_swap_filehdr_out _bfd_XX_only_swap_filehdr_out
201
#elif defined COFF_WITH_pex64
202
# define coff_swap_filehdr_out _bfd_pex64_only_swap_filehdr_out
203
#elif defined COFF_WITH_pep
204
# define coff_swap_filehdr_out _bfd_pep_only_swap_filehdr_out
205
#else
206
# define coff_swap_filehdr_out _bfd_pe_only_swap_filehdr_out
207
#endif
208
209
static void
210
coff_swap_scnhdr_in (bfd *abfd, void *ext, void *in)
211
872k
{
212
872k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
872k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
872k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
872k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
872k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
872k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
872k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
872k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
872k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
872k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
#ifdef COFF_IMAGE_WITH_PE
229
575k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
575k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
  scnhdr_int->s_nreloc = 0;
232
#else
233
297k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
297k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
#endif
236
237
872k
  if (scnhdr_int->s_vaddr != 0)
238
566k
    {
239
566k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
      scnhdr_int->s_vaddr &= 0xffffffff;
244
#endif
245
566k
    }
246
247
872k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
872k
  if (scnhdr_int->s_paddr > 0
253
627k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
140k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
571k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
176k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
872k
#endif
262
872k
}
pei-i386.c:coff_swap_scnhdr_in
Line
Count
Source
211
59.9k
{
212
59.9k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
59.9k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
59.9k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
59.9k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
59.9k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
59.9k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
59.9k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
59.9k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
59.9k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
59.9k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
59.9k
#ifdef COFF_IMAGE_WITH_PE
229
59.9k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
59.9k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
59.9k
  scnhdr_int->s_nreloc = 0;
232
#else
233
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
#endif
236
237
59.9k
  if (scnhdr_int->s_vaddr != 0)
238
39.5k
    {
239
39.5k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
39.5k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
39.5k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
39.5k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
39.5k
#endif
245
39.5k
    }
246
247
59.9k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
59.9k
  if (scnhdr_int->s_paddr > 0
253
44.2k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
9.35k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
43.0k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
16.4k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
59.9k
#endif
262
59.9k
}
pe-x86_64.c:coff_swap_scnhdr_in
Line
Count
Source
211
66.9k
{
212
66.9k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
66.9k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
66.9k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
66.9k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
66.9k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
66.9k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
66.9k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
66.9k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
66.9k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
66.9k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
#ifdef COFF_IMAGE_WITH_PE
229
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
  scnhdr_int->s_nreloc = 0;
232
#else
233
66.9k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
66.9k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
66.9k
#endif
236
237
66.9k
  if (scnhdr_int->s_vaddr != 0)
238
36.2k
    {
239
36.2k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
      scnhdr_int->s_vaddr &= 0xffffffff;
244
#endif
245
36.2k
    }
246
247
66.9k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
66.9k
  if (scnhdr_int->s_paddr > 0
253
38.8k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
7.17k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
31.6k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
7.17k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
66.9k
#endif
262
66.9k
}
pei-x86_64.c:coff_swap_scnhdr_in
Line
Count
Source
211
69.5k
{
212
69.5k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
69.5k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
69.5k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
69.5k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
69.5k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
69.5k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
69.5k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
69.5k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
69.5k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
69.5k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
69.5k
#ifdef COFF_IMAGE_WITH_PE
229
69.5k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
69.5k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
69.5k
  scnhdr_int->s_nreloc = 0;
232
#else
233
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
#endif
236
237
69.5k
  if (scnhdr_int->s_vaddr != 0)
238
44.1k
    {
239
44.1k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
      scnhdr_int->s_vaddr &= 0xffffffff;
244
#endif
245
44.1k
    }
246
247
69.5k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
69.5k
  if (scnhdr_int->s_paddr > 0
253
48.2k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
10.9k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
46.6k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
15.9k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
69.5k
#endif
262
69.5k
}
pe-aarch64.c:coff_swap_scnhdr_in
Line
Count
Source
211
50.8k
{
212
50.8k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
50.8k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
50.8k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
50.8k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
50.8k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
50.8k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
50.8k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
50.8k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
50.8k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
50.8k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
#ifdef COFF_IMAGE_WITH_PE
229
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
  scnhdr_int->s_nreloc = 0;
232
#else
233
50.8k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
50.8k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
50.8k
#endif
236
237
50.8k
  if (scnhdr_int->s_vaddr != 0)
238
33.4k
    {
239
33.4k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
      scnhdr_int->s_vaddr &= 0xffffffff;
244
#endif
245
33.4k
    }
246
247
50.8k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
50.8k
  if (scnhdr_int->s_paddr > 0
253
35.7k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
5.43k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
30.2k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
5.43k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
50.8k
#endif
262
50.8k
}
pei-aarch64.c:coff_swap_scnhdr_in
Line
Count
Source
211
74.9k
{
212
74.9k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
74.9k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
74.9k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
74.9k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
74.9k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
74.9k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
74.9k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
74.9k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
74.9k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
74.9k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
74.9k
#ifdef COFF_IMAGE_WITH_PE
229
74.9k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
74.9k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
74.9k
  scnhdr_int->s_nreloc = 0;
232
#else
233
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
#endif
236
237
74.9k
  if (scnhdr_int->s_vaddr != 0)
238
52.2k
    {
239
52.2k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
      scnhdr_int->s_vaddr &= 0xffffffff;
244
#endif
245
52.2k
    }
246
247
74.9k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
74.9k
  if (scnhdr_int->s_paddr > 0
253
54.9k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
11.8k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
53.0k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
20.0k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
74.9k
#endif
262
74.9k
}
pei-ia64.c:coff_swap_scnhdr_in
Line
Count
Source
211
53.6k
{
212
53.6k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
53.6k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
53.6k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
53.6k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
53.6k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
53.6k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
53.6k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
53.6k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
53.6k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
53.6k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
53.6k
#ifdef COFF_IMAGE_WITH_PE
229
53.6k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
53.6k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
53.6k
  scnhdr_int->s_nreloc = 0;
232
#else
233
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
#endif
236
237
53.6k
  if (scnhdr_int->s_vaddr != 0)
238
35.0k
    {
239
35.0k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
35.0k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
35.0k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
35.0k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
35.0k
#endif
245
35.0k
    }
246
247
53.6k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
53.6k
  if (scnhdr_int->s_paddr > 0
253
39.0k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
9.90k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
37.2k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
12.3k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
53.6k
#endif
262
53.6k
}
pei-loongarch64.c:coff_swap_scnhdr_in
Line
Count
Source
211
53.2k
{
212
53.2k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
53.2k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
53.2k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
53.2k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
53.2k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
53.2k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
53.2k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
53.2k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
53.2k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
53.2k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
53.2k
#ifdef COFF_IMAGE_WITH_PE
229
53.2k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
53.2k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
53.2k
  scnhdr_int->s_nreloc = 0;
232
#else
233
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
#endif
236
237
53.2k
  if (scnhdr_int->s_vaddr != 0)
238
35.6k
    {
239
35.6k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
      scnhdr_int->s_vaddr &= 0xffffffff;
244
#endif
245
35.6k
    }
246
247
53.2k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
53.2k
  if (scnhdr_int->s_paddr > 0
253
40.0k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
7.85k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
38.3k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
12.9k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
53.2k
#endif
262
53.2k
}
pei-riscv64.c:coff_swap_scnhdr_in
Line
Count
Source
211
59.9k
{
212
59.9k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
59.9k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
59.9k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
59.9k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
59.9k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
59.9k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
59.9k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
59.9k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
59.9k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
59.9k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
59.9k
#ifdef COFF_IMAGE_WITH_PE
229
59.9k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
59.9k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
59.9k
  scnhdr_int->s_nreloc = 0;
232
#else
233
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
#endif
236
237
59.9k
  if (scnhdr_int->s_vaddr != 0)
238
38.5k
    {
239
38.5k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
      scnhdr_int->s_vaddr &= 0xffffffff;
244
#endif
245
38.5k
    }
246
247
59.9k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
59.9k
  if (scnhdr_int->s_paddr > 0
253
44.2k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
11.6k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
42.6k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
12.4k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
59.9k
#endif
262
59.9k
}
pe-arm-wince.c:coff_swap_scnhdr_in
Line
Count
Source
211
23.1k
{
212
23.1k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
23.1k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
23.1k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
23.1k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
23.1k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
23.1k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
23.1k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
23.1k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
23.1k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
23.1k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
#ifdef COFF_IMAGE_WITH_PE
229
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
  scnhdr_int->s_nreloc = 0;
232
#else
233
23.1k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
23.1k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
23.1k
#endif
236
237
23.1k
  if (scnhdr_int->s_vaddr != 0)
238
15.3k
    {
239
15.3k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
15.3k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
15.3k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
15.3k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
15.3k
#endif
245
15.3k
    }
246
247
23.1k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
23.1k
  if (scnhdr_int->s_paddr > 0
253
16.1k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
3.57k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
12.6k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
3.57k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
23.1k
#endif
262
23.1k
}
pe-arm.c:coff_swap_scnhdr_in
Line
Count
Source
211
23.1k
{
212
23.1k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
23.1k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
23.1k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
23.1k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
23.1k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
23.1k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
23.1k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
23.1k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
23.1k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
23.1k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
#ifdef COFF_IMAGE_WITH_PE
229
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
  scnhdr_int->s_nreloc = 0;
232
#else
233
23.1k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
23.1k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
23.1k
#endif
236
237
23.1k
  if (scnhdr_int->s_vaddr != 0)
238
15.3k
    {
239
15.3k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
15.3k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
15.3k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
15.3k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
15.3k
#endif
245
15.3k
    }
246
247
23.1k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
23.1k
  if (scnhdr_int->s_paddr > 0
253
16.1k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
3.57k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
12.6k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
3.57k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
23.1k
#endif
262
23.1k
}
pe-i386.c:coff_swap_scnhdr_in
Line
Count
Source
211
57.4k
{
212
57.4k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
57.4k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
57.4k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
57.4k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
57.4k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
57.4k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
57.4k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
57.4k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
57.4k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
57.4k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
#ifdef COFF_IMAGE_WITH_PE
229
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
  scnhdr_int->s_nreloc = 0;
232
#else
233
57.4k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
57.4k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
57.4k
#endif
236
237
57.4k
  if (scnhdr_int->s_vaddr != 0)
238
37.5k
    {
239
37.5k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
37.5k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
37.5k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
37.5k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
37.5k
#endif
245
37.5k
    }
246
247
57.4k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
57.4k
  if (scnhdr_int->s_paddr > 0
253
42.5k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
8.82k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
33.7k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
8.82k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
57.4k
#endif
262
57.4k
}
pe-mcore.c:coff_swap_scnhdr_in
Line
Count
Source
211
29.5k
{
212
29.5k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
29.5k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
29.5k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
29.5k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
29.5k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
29.5k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
29.5k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
29.5k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
29.5k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
29.5k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
#ifdef COFF_IMAGE_WITH_PE
229
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
  scnhdr_int->s_nreloc = 0;
232
#else
233
29.5k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
29.5k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
29.5k
#endif
236
237
29.5k
  if (scnhdr_int->s_vaddr != 0)
238
18.4k
    {
239
18.4k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
18.4k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
18.4k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
18.4k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
18.4k
#endif
245
18.4k
    }
246
247
29.5k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
29.5k
  if (scnhdr_int->s_paddr > 0
253
20.9k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
4.34k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
16.5k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
4.34k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
29.5k
#endif
262
29.5k
}
pe-sh.c:coff_swap_scnhdr_in
Line
Count
Source
211
46.1k
{
212
46.1k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
46.1k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
46.1k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
46.1k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
46.1k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
46.1k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
46.1k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
46.1k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
46.1k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
46.1k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
#ifdef COFF_IMAGE_WITH_PE
229
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
  scnhdr_int->s_nreloc = 0;
232
#else
233
46.1k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
46.1k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
46.1k
#endif
236
237
46.1k
  if (scnhdr_int->s_vaddr != 0)
238
30.0k
    {
239
30.0k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
30.0k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
30.0k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
30.0k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
30.0k
#endif
245
30.0k
    }
246
247
46.1k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
46.1k
  if (scnhdr_int->s_paddr > 0
253
32.8k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
6.85k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
26.0k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
6.85k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
46.1k
#endif
262
46.1k
}
pei-arm-wince.c:coff_swap_scnhdr_in
Line
Count
Source
211
45.3k
{
212
45.3k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
45.3k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
45.3k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
45.3k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
45.3k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
45.3k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
45.3k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
45.3k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
45.3k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
45.3k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
45.3k
#ifdef COFF_IMAGE_WITH_PE
229
45.3k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
45.3k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
45.3k
  scnhdr_int->s_nreloc = 0;
232
#else
233
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
#endif
236
237
45.3k
  if (scnhdr_int->s_vaddr != 0)
238
29.5k
    {
239
29.5k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
29.5k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
29.5k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
29.5k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
29.5k
#endif
245
29.5k
    }
246
247
45.3k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
45.3k
  if (scnhdr_int->s_paddr > 0
253
34.3k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
9.43k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
32.8k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
10.7k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
45.3k
#endif
262
45.3k
}
pei-arm.c:coff_swap_scnhdr_in
Line
Count
Source
211
60.2k
{
212
60.2k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
60.2k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
60.2k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
60.2k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
60.2k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
60.2k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
60.2k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
60.2k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
60.2k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
60.2k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
60.2k
#ifdef COFF_IMAGE_WITH_PE
229
60.2k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
60.2k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
60.2k
  scnhdr_int->s_nreloc = 0;
232
#else
233
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
#endif
236
237
60.2k
  if (scnhdr_int->s_vaddr != 0)
238
38.8k
    {
239
38.8k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
38.8k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
38.8k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
38.8k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
38.8k
#endif
245
38.8k
    }
246
247
60.2k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
60.2k
  if (scnhdr_int->s_paddr > 0
253
44.2k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
11.4k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
42.5k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
13.0k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
60.2k
#endif
262
60.2k
}
pei-mcore.c:coff_swap_scnhdr_in
Line
Count
Source
211
52.5k
{
212
52.5k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
52.5k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
52.5k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
52.5k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
52.5k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
52.5k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
52.5k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
52.5k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
52.5k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
52.5k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
52.5k
#ifdef COFF_IMAGE_WITH_PE
229
52.5k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
52.5k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
52.5k
  scnhdr_int->s_nreloc = 0;
232
#else
233
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
#endif
236
237
52.5k
  if (scnhdr_int->s_vaddr != 0)
238
35.1k
    {
239
35.1k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
35.1k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
35.1k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
35.1k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
35.1k
#endif
245
35.1k
    }
246
247
52.5k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
52.5k
  if (scnhdr_int->s_paddr > 0
253
39.1k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
8.01k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
37.9k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
11.0k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
52.5k
#endif
262
52.5k
}
pei-sh.c:coff_swap_scnhdr_in
Line
Count
Source
211
46.1k
{
212
46.1k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
46.1k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
46.1k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
46.1k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
46.1k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
46.1k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
46.1k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
46.1k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
46.1k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
46.1k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
46.1k
#ifdef COFF_IMAGE_WITH_PE
229
46.1k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
46.1k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
46.1k
  scnhdr_int->s_nreloc = 0;
232
#else
233
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
#endif
236
237
46.1k
  if (scnhdr_int->s_vaddr != 0)
238
31.2k
    {
239
31.2k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
31.2k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
31.2k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
31.2k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
31.2k
#endif
245
31.2k
    }
246
247
46.1k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
46.1k
  if (scnhdr_int->s_paddr > 0
253
35.3k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
9.68k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
33.8k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
11.2k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
46.1k
#endif
262
46.1k
}
263
264
static bool
265
pe_mkobject (bfd *abfd)
266
126k
{
267
  /* Some x86 code followed by an ascii string.  */
268
126k
  static const char default_dos_message[64] = {
269
126k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
126k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
126k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
126k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
126k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
126k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
126k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
126k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
126k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
126k
  abfd->tdata.pe_obj_data = pe;
280
126k
  if (pe == NULL)
281
0
    return false;
282
283
126k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
126k
  pe->in_reloc_p = in_reloc_p;
287
288
126k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
126k
  bfd_coff_long_section_names (abfd)
291
126k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
126k
  return true;
294
126k
}
pei-i386.c:pe_mkobject
Line
Count
Source
266
11.8k
{
267
  /* Some x86 code followed by an ascii string.  */
268
11.8k
  static const char default_dos_message[64] = {
269
11.8k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
11.8k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
11.8k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
11.8k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
11.8k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
11.8k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
11.8k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
11.8k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
11.8k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
11.8k
  abfd->tdata.pe_obj_data = pe;
280
11.8k
  if (pe == NULL)
281
0
    return false;
282
283
11.8k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
11.8k
  pe->in_reloc_p = in_reloc_p;
287
288
11.8k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
11.8k
  bfd_coff_long_section_names (abfd)
291
11.8k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
11.8k
}
pe-x86_64.c:pe_mkobject
Line
Count
Source
266
11.0k
{
267
  /* Some x86 code followed by an ascii string.  */
268
11.0k
  static const char default_dos_message[64] = {
269
11.0k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
11.0k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
11.0k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
11.0k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
11.0k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
11.0k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
11.0k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
11.0k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
11.0k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
11.0k
  abfd->tdata.pe_obj_data = pe;
280
11.0k
  if (pe == NULL)
281
0
    return false;
282
283
11.0k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
11.0k
  pe->in_reloc_p = in_reloc_p;
287
288
11.0k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
11.0k
  bfd_coff_long_section_names (abfd)
291
11.0k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
11.0k
}
pei-x86_64.c:pe_mkobject
Line
Count
Source
266
8.75k
{
267
  /* Some x86 code followed by an ascii string.  */
268
8.75k
  static const char default_dos_message[64] = {
269
8.75k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
8.75k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
8.75k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
8.75k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
8.75k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
8.75k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
8.75k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
8.75k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
8.75k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
8.75k
  abfd->tdata.pe_obj_data = pe;
280
8.75k
  if (pe == NULL)
281
0
    return false;
282
283
8.75k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
8.75k
  pe->in_reloc_p = in_reloc_p;
287
288
8.75k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
8.75k
  bfd_coff_long_section_names (abfd)
291
8.75k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
8.75k
}
pe-aarch64.c:pe_mkobject
Line
Count
Source
266
10.7k
{
267
  /* Some x86 code followed by an ascii string.  */
268
10.7k
  static const char default_dos_message[64] = {
269
10.7k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
10.7k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
10.7k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
10.7k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
10.7k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
10.7k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
10.7k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
10.7k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
10.7k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
10.7k
  abfd->tdata.pe_obj_data = pe;
280
10.7k
  if (pe == NULL)
281
0
    return false;
282
283
10.7k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
10.7k
  pe->in_reloc_p = in_reloc_p;
287
288
10.7k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
10.7k
  bfd_coff_long_section_names (abfd)
291
10.7k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
10.7k
}
pei-aarch64.c:pe_mkobject
Line
Count
Source
266
9.64k
{
267
  /* Some x86 code followed by an ascii string.  */
268
9.64k
  static const char default_dos_message[64] = {
269
9.64k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
9.64k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
9.64k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
9.64k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
9.64k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
9.64k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
9.64k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
9.64k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
9.64k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
9.64k
  abfd->tdata.pe_obj_data = pe;
280
9.64k
  if (pe == NULL)
281
0
    return false;
282
283
9.64k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
9.64k
  pe->in_reloc_p = in_reloc_p;
287
288
9.64k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
9.64k
  bfd_coff_long_section_names (abfd)
291
9.64k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
9.64k
}
pei-ia64.c:pe_mkobject
Line
Count
Source
266
6.58k
{
267
  /* Some x86 code followed by an ascii string.  */
268
6.58k
  static const char default_dos_message[64] = {
269
6.58k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
6.58k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
6.58k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
6.58k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
6.58k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
6.58k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
6.58k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
6.58k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
6.58k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
6.58k
  abfd->tdata.pe_obj_data = pe;
280
6.58k
  if (pe == NULL)
281
0
    return false;
282
283
6.58k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
6.58k
  pe->in_reloc_p = in_reloc_p;
287
288
6.58k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
6.58k
  bfd_coff_long_section_names (abfd)
291
6.58k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
6.58k
}
pei-loongarch64.c:pe_mkobject
Line
Count
Source
266
7.05k
{
267
  /* Some x86 code followed by an ascii string.  */
268
7.05k
  static const char default_dos_message[64] = {
269
7.05k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
7.05k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
7.05k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
7.05k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
7.05k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
7.05k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
7.05k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
7.05k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
7.05k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
7.05k
  abfd->tdata.pe_obj_data = pe;
280
7.05k
  if (pe == NULL)
281
0
    return false;
282
283
7.05k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
7.05k
  pe->in_reloc_p = in_reloc_p;
287
288
7.05k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
7.05k
  bfd_coff_long_section_names (abfd)
291
7.05k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
7.05k
}
pei-riscv64.c:pe_mkobject
Line
Count
Source
266
7.28k
{
267
  /* Some x86 code followed by an ascii string.  */
268
7.28k
  static const char default_dos_message[64] = {
269
7.28k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
7.28k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
7.28k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
7.28k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
7.28k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
7.28k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
7.28k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
7.28k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
7.28k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
7.28k
  abfd->tdata.pe_obj_data = pe;
280
7.28k
  if (pe == NULL)
281
0
    return false;
282
283
7.28k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
7.28k
  pe->in_reloc_p = in_reloc_p;
287
288
7.28k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
7.28k
  bfd_coff_long_section_names (abfd)
291
7.28k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
7.28k
}
pe-arm-wince.c:pe_mkobject
Line
Count
Source
266
3.05k
{
267
  /* Some x86 code followed by an ascii string.  */
268
3.05k
  static const char default_dos_message[64] = {
269
3.05k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
3.05k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
3.05k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
3.05k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
3.05k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
3.05k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
3.05k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
3.05k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
3.05k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
3.05k
  abfd->tdata.pe_obj_data = pe;
280
3.05k
  if (pe == NULL)
281
0
    return false;
282
283
3.05k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
3.05k
  pe->in_reloc_p = in_reloc_p;
287
288
3.05k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
3.05k
  bfd_coff_long_section_names (abfd)
291
3.05k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
3.05k
}
pe-arm.c:pe_mkobject
Line
Count
Source
266
3.05k
{
267
  /* Some x86 code followed by an ascii string.  */
268
3.05k
  static const char default_dos_message[64] = {
269
3.05k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
3.05k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
3.05k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
3.05k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
3.05k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
3.05k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
3.05k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
3.05k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
3.05k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
3.05k
  abfd->tdata.pe_obj_data = pe;
280
3.05k
  if (pe == NULL)
281
0
    return false;
282
283
3.05k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
3.05k
  pe->in_reloc_p = in_reloc_p;
287
288
3.05k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
3.05k
  bfd_coff_long_section_names (abfd)
291
3.05k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
3.05k
}
pe-i386.c:pe_mkobject
Line
Count
Source
266
10.7k
{
267
  /* Some x86 code followed by an ascii string.  */
268
10.7k
  static const char default_dos_message[64] = {
269
10.7k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
10.7k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
10.7k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
10.7k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
10.7k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
10.7k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
10.7k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
10.7k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
10.7k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
10.7k
  abfd->tdata.pe_obj_data = pe;
280
10.7k
  if (pe == NULL)
281
0
    return false;
282
283
10.7k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
10.7k
  pe->in_reloc_p = in_reloc_p;
287
288
10.7k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
10.7k
  bfd_coff_long_section_names (abfd)
291
10.7k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
10.7k
}
pe-mcore.c:pe_mkobject
Line
Count
Source
266
4.36k
{
267
  /* Some x86 code followed by an ascii string.  */
268
4.36k
  static const char default_dos_message[64] = {
269
4.36k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
4.36k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
4.36k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
4.36k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
4.36k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
4.36k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
4.36k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
4.36k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
4.36k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
4.36k
  abfd->tdata.pe_obj_data = pe;
280
4.36k
  if (pe == NULL)
281
0
    return false;
282
283
4.36k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
4.36k
  pe->in_reloc_p = in_reloc_p;
287
288
4.36k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
4.36k
  bfd_coff_long_section_names (abfd)
291
4.36k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
4.36k
}
pe-sh.c:pe_mkobject
Line
Count
Source
266
6.12k
{
267
  /* Some x86 code followed by an ascii string.  */
268
6.12k
  static const char default_dos_message[64] = {
269
6.12k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
6.12k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
6.12k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
6.12k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
6.12k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
6.12k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
6.12k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
6.12k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
6.12k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
6.12k
  abfd->tdata.pe_obj_data = pe;
280
6.12k
  if (pe == NULL)
281
0
    return false;
282
283
6.12k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
6.12k
  pe->in_reloc_p = in_reloc_p;
287
288
6.12k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
6.12k
  bfd_coff_long_section_names (abfd)
291
6.12k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
6.12k
}
pei-arm-wince.c:pe_mkobject
Line
Count
Source
266
6.50k
{
267
  /* Some x86 code followed by an ascii string.  */
268
6.50k
  static const char default_dos_message[64] = {
269
6.50k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
6.50k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
6.50k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
6.50k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
6.50k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
6.50k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
6.50k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
6.50k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
6.50k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
6.50k
  abfd->tdata.pe_obj_data = pe;
280
6.50k
  if (pe == NULL)
281
0
    return false;
282
283
6.50k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
6.50k
  pe->in_reloc_p = in_reloc_p;
287
288
6.50k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
6.50k
  bfd_coff_long_section_names (abfd)
291
6.50k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
6.50k
}
pei-arm.c:pe_mkobject
Line
Count
Source
266
7.78k
{
267
  /* Some x86 code followed by an ascii string.  */
268
7.78k
  static const char default_dos_message[64] = {
269
7.78k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
7.78k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
7.78k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
7.78k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
7.78k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
7.78k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
7.78k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
7.78k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
7.78k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
7.78k
  abfd->tdata.pe_obj_data = pe;
280
7.78k
  if (pe == NULL)
281
0
    return false;
282
283
7.78k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
7.78k
  pe->in_reloc_p = in_reloc_p;
287
288
7.78k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
7.78k
  bfd_coff_long_section_names (abfd)
291
7.78k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
7.78k
}
pei-mcore.c:pe_mkobject
Line
Count
Source
266
5.84k
{
267
  /* Some x86 code followed by an ascii string.  */
268
5.84k
  static const char default_dos_message[64] = {
269
5.84k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
5.84k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
5.84k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
5.84k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
5.84k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
5.84k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
5.84k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
5.84k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
5.84k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
5.84k
  abfd->tdata.pe_obj_data = pe;
280
5.84k
  if (pe == NULL)
281
0
    return false;
282
283
5.84k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
5.84k
  pe->in_reloc_p = in_reloc_p;
287
288
5.84k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
5.84k
  bfd_coff_long_section_names (abfd)
291
5.84k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
5.84k
}
pei-sh.c:pe_mkobject
Line
Count
Source
266
6.05k
{
267
  /* Some x86 code followed by an ascii string.  */
268
6.05k
  static const char default_dos_message[64] = {
269
6.05k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
6.05k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
6.05k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
6.05k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
6.05k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
6.05k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
6.05k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
6.05k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
6.05k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
6.05k
  abfd->tdata.pe_obj_data = pe;
280
6.05k
  if (pe == NULL)
281
0
    return false;
282
283
6.05k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
6.05k
  pe->in_reloc_p = in_reloc_p;
287
288
6.05k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
6.05k
  bfd_coff_long_section_names (abfd)
291
6.05k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
6.05k
}
295
296
/* Create the COFF backend specific information.  */
297
298
static void *
299
pe_mkobject_hook (bfd *abfd,
300
      void *filehdr,
301
      void *aouthdr ATTRIBUTE_UNUSED)
302
120k
{
303
120k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
120k
  pe_data_type *pe;
305
306
120k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
120k
  pe = pe_data (abfd);
310
120k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
120k
  pe->coff.local_n_btmask = N_BTMASK;
315
120k
  pe->coff.local_n_btshft = N_BTSHFT;
316
120k
  pe->coff.local_n_tmask = N_TMASK;
317
120k
  pe->coff.local_n_tshift = N_TSHIFT;
318
120k
  pe->coff.local_symesz = SYMESZ;
319
120k
  pe->coff.local_auxesz = AUXESZ;
320
120k
  pe->coff.local_linesz = LINESZ;
321
322
120k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
120k
  obj_raw_syment_count (abfd) =
325
120k
    obj_conv_table_size (abfd) =
326
120k
      internal_f->f_nsyms;
327
328
120k
  pe->real_flags = internal_f->f_flags;
329
330
120k
  if ((internal_f->f_flags & F_DLL) != 0)
331
36.0k
    pe->dll = 1;
332
333
120k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
83.1k
    abfd->flags |= HAS_DEBUG;
335
336
#ifdef COFF_IMAGE_WITH_PE
337
73.3k
  if (aouthdr)
338
41.5k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
#endif
340
341
#ifdef ARM
342
19.7k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
0
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
120k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
120k
    sizeof (pe->dos_message));
348
349
120k
  return (void *) pe;
350
120k
}
pei-i386.c:pe_mkobject_hook
Line
Count
Source
302
11.3k
{
303
11.3k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
11.3k
  pe_data_type *pe;
305
306
11.3k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
11.3k
  pe = pe_data (abfd);
310
11.3k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
11.3k
  pe->coff.local_n_btmask = N_BTMASK;
315
11.3k
  pe->coff.local_n_btshft = N_BTSHFT;
316
11.3k
  pe->coff.local_n_tmask = N_TMASK;
317
11.3k
  pe->coff.local_n_tshift = N_TSHIFT;
318
11.3k
  pe->coff.local_symesz = SYMESZ;
319
11.3k
  pe->coff.local_auxesz = AUXESZ;
320
11.3k
  pe->coff.local_linesz = LINESZ;
321
322
11.3k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
11.3k
  obj_raw_syment_count (abfd) =
325
11.3k
    obj_conv_table_size (abfd) =
326
11.3k
      internal_f->f_nsyms;
327
328
11.3k
  pe->real_flags = internal_f->f_flags;
329
330
11.3k
  if ((internal_f->f_flags & F_DLL) != 0)
331
3.29k
    pe->dll = 1;
332
333
11.3k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
8.95k
    abfd->flags |= HAS_DEBUG;
335
336
11.3k
#ifdef COFF_IMAGE_WITH_PE
337
11.3k
  if (aouthdr)
338
5.65k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
11.3k
#endif
340
341
#ifdef ARM
342
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
11.3k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
11.3k
    sizeof (pe->dos_message));
348
349
11.3k
  return (void *) pe;
350
11.3k
}
pe-x86_64.c:pe_mkobject_hook
Line
Count
Source
302
10.2k
{
303
10.2k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
10.2k
  pe_data_type *pe;
305
306
10.2k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
10.2k
  pe = pe_data (abfd);
310
10.2k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
10.2k
  pe->coff.local_n_btmask = N_BTMASK;
315
10.2k
  pe->coff.local_n_btshft = N_BTSHFT;
316
10.2k
  pe->coff.local_n_tmask = N_TMASK;
317
10.2k
  pe->coff.local_n_tshift = N_TSHIFT;
318
10.2k
  pe->coff.local_symesz = SYMESZ;
319
10.2k
  pe->coff.local_auxesz = AUXESZ;
320
10.2k
  pe->coff.local_linesz = LINESZ;
321
322
10.2k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
10.2k
  obj_raw_syment_count (abfd) =
325
10.2k
    obj_conv_table_size (abfd) =
326
10.2k
      internal_f->f_nsyms;
327
328
10.2k
  pe->real_flags = internal_f->f_flags;
329
330
10.2k
  if ((internal_f->f_flags & F_DLL) != 0)
331
2.59k
    pe->dll = 1;
332
333
10.2k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
7.68k
    abfd->flags |= HAS_DEBUG;
335
336
#ifdef COFF_IMAGE_WITH_PE
337
  if (aouthdr)
338
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
#endif
340
341
#ifdef ARM
342
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
10.2k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
10.2k
    sizeof (pe->dos_message));
348
349
10.2k
  return (void *) pe;
350
10.2k
}
pei-x86_64.c:pe_mkobject_hook
Line
Count
Source
302
8.34k
{
303
8.34k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
8.34k
  pe_data_type *pe;
305
306
8.34k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
8.34k
  pe = pe_data (abfd);
310
8.34k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
8.34k
  pe->coff.local_n_btmask = N_BTMASK;
315
8.34k
  pe->coff.local_n_btshft = N_BTSHFT;
316
8.34k
  pe->coff.local_n_tmask = N_TMASK;
317
8.34k
  pe->coff.local_n_tshift = N_TSHIFT;
318
8.34k
  pe->coff.local_symesz = SYMESZ;
319
8.34k
  pe->coff.local_auxesz = AUXESZ;
320
8.34k
  pe->coff.local_linesz = LINESZ;
321
322
8.34k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
8.34k
  obj_raw_syment_count (abfd) =
325
8.34k
    obj_conv_table_size (abfd) =
326
8.34k
      internal_f->f_nsyms;
327
328
8.34k
  pe->real_flags = internal_f->f_flags;
329
330
8.34k
  if ((internal_f->f_flags & F_DLL) != 0)
331
2.95k
    pe->dll = 1;
332
333
8.34k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
5.53k
    abfd->flags |= HAS_DEBUG;
335
336
8.34k
#ifdef COFF_IMAGE_WITH_PE
337
8.34k
  if (aouthdr)
338
5.04k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
8.34k
#endif
340
341
#ifdef ARM
342
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
8.34k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
8.34k
    sizeof (pe->dos_message));
348
349
8.34k
  return (void *) pe;
350
8.34k
}
pe-aarch64.c:pe_mkobject_hook
Line
Count
Source
302
10.2k
{
303
10.2k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
10.2k
  pe_data_type *pe;
305
306
10.2k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
10.2k
  pe = pe_data (abfd);
310
10.2k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
10.2k
  pe->coff.local_n_btmask = N_BTMASK;
315
10.2k
  pe->coff.local_n_btshft = N_BTSHFT;
316
10.2k
  pe->coff.local_n_tmask = N_TMASK;
317
10.2k
  pe->coff.local_n_tshift = N_TSHIFT;
318
10.2k
  pe->coff.local_symesz = SYMESZ;
319
10.2k
  pe->coff.local_auxesz = AUXESZ;
320
10.2k
  pe->coff.local_linesz = LINESZ;
321
322
10.2k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
10.2k
  obj_raw_syment_count (abfd) =
325
10.2k
    obj_conv_table_size (abfd) =
326
10.2k
      internal_f->f_nsyms;
327
328
10.2k
  pe->real_flags = internal_f->f_flags;
329
330
10.2k
  if ((internal_f->f_flags & F_DLL) != 0)
331
2.02k
    pe->dll = 1;
332
333
10.2k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
4.65k
    abfd->flags |= HAS_DEBUG;
335
336
#ifdef COFF_IMAGE_WITH_PE
337
  if (aouthdr)
338
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
#endif
340
341
#ifdef ARM
342
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
10.2k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
10.2k
    sizeof (pe->dos_message));
348
349
10.2k
  return (void *) pe;
350
10.2k
}
pei-aarch64.c:pe_mkobject_hook
Line
Count
Source
302
9.24k
{
303
9.24k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
9.24k
  pe_data_type *pe;
305
306
9.24k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
9.24k
  pe = pe_data (abfd);
310
9.24k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
9.24k
  pe->coff.local_n_btmask = N_BTMASK;
315
9.24k
  pe->coff.local_n_btshft = N_BTSHFT;
316
9.24k
  pe->coff.local_n_tmask = N_TMASK;
317
9.24k
  pe->coff.local_n_tshift = N_TSHIFT;
318
9.24k
  pe->coff.local_symesz = SYMESZ;
319
9.24k
  pe->coff.local_auxesz = AUXESZ;
320
9.24k
  pe->coff.local_linesz = LINESZ;
321
322
9.24k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
9.24k
  obj_raw_syment_count (abfd) =
325
9.24k
    obj_conv_table_size (abfd) =
326
9.24k
      internal_f->f_nsyms;
327
328
9.24k
  pe->real_flags = internal_f->f_flags;
329
330
9.24k
  if ((internal_f->f_flags & F_DLL) != 0)
331
2.50k
    pe->dll = 1;
332
333
9.24k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
7.06k
    abfd->flags |= HAS_DEBUG;
335
336
9.24k
#ifdef COFF_IMAGE_WITH_PE
337
9.24k
  if (aouthdr)
338
6.87k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
9.24k
#endif
340
341
#ifdef ARM
342
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
9.24k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
9.24k
    sizeof (pe->dos_message));
348
349
9.24k
  return (void *) pe;
350
9.24k
}
pei-ia64.c:pe_mkobject_hook
Line
Count
Source
302
6.15k
{
303
6.15k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
6.15k
  pe_data_type *pe;
305
306
6.15k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
6.15k
  pe = pe_data (abfd);
310
6.15k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
6.15k
  pe->coff.local_n_btmask = N_BTMASK;
315
6.15k
  pe->coff.local_n_btshft = N_BTSHFT;
316
6.15k
  pe->coff.local_n_tmask = N_TMASK;
317
6.15k
  pe->coff.local_n_tshift = N_TSHIFT;
318
6.15k
  pe->coff.local_symesz = SYMESZ;
319
6.15k
  pe->coff.local_auxesz = AUXESZ;
320
6.15k
  pe->coff.local_linesz = LINESZ;
321
322
6.15k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
6.15k
  obj_raw_syment_count (abfd) =
325
6.15k
    obj_conv_table_size (abfd) =
326
6.15k
      internal_f->f_nsyms;
327
328
6.15k
  pe->real_flags = internal_f->f_flags;
329
330
6.15k
  if ((internal_f->f_flags & F_DLL) != 0)
331
1.86k
    pe->dll = 1;
332
333
6.15k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
4.25k
    abfd->flags |= HAS_DEBUG;
335
336
6.15k
#ifdef COFF_IMAGE_WITH_PE
337
6.15k
  if (aouthdr)
338
2.50k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
6.15k
#endif
340
341
#ifdef ARM
342
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
6.15k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
6.15k
    sizeof (pe->dos_message));
348
349
6.15k
  return (void *) pe;
350
6.15k
}
pei-loongarch64.c:pe_mkobject_hook
Line
Count
Source
302
6.55k
{
303
6.55k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
6.55k
  pe_data_type *pe;
305
306
6.55k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
6.55k
  pe = pe_data (abfd);
310
6.55k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
6.55k
  pe->coff.local_n_btmask = N_BTMASK;
315
6.55k
  pe->coff.local_n_btshft = N_BTSHFT;
316
6.55k
  pe->coff.local_n_tmask = N_TMASK;
317
6.55k
  pe->coff.local_n_tshift = N_TSHIFT;
318
6.55k
  pe->coff.local_symesz = SYMESZ;
319
6.55k
  pe->coff.local_auxesz = AUXESZ;
320
6.55k
  pe->coff.local_linesz = LINESZ;
321
322
6.55k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
6.55k
  obj_raw_syment_count (abfd) =
325
6.55k
    obj_conv_table_size (abfd) =
326
6.55k
      internal_f->f_nsyms;
327
328
6.55k
  pe->real_flags = internal_f->f_flags;
329
330
6.55k
  if ((internal_f->f_flags & F_DLL) != 0)
331
1.88k
    pe->dll = 1;
332
333
6.55k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
4.92k
    abfd->flags |= HAS_DEBUG;
335
336
6.55k
#ifdef COFF_IMAGE_WITH_PE
337
6.55k
  if (aouthdr)
338
3.95k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
6.55k
#endif
340
341
#ifdef ARM
342
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
6.55k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
6.55k
    sizeof (pe->dos_message));
348
349
6.55k
  return (void *) pe;
350
6.55k
}
pei-riscv64.c:pe_mkobject_hook
Line
Count
Source
302
6.77k
{
303
6.77k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
6.77k
  pe_data_type *pe;
305
306
6.77k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
6.77k
  pe = pe_data (abfd);
310
6.77k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
6.77k
  pe->coff.local_n_btmask = N_BTMASK;
315
6.77k
  pe->coff.local_n_btshft = N_BTSHFT;
316
6.77k
  pe->coff.local_n_tmask = N_TMASK;
317
6.77k
  pe->coff.local_n_tshift = N_TSHIFT;
318
6.77k
  pe->coff.local_symesz = SYMESZ;
319
6.77k
  pe->coff.local_auxesz = AUXESZ;
320
6.77k
  pe->coff.local_linesz = LINESZ;
321
322
6.77k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
6.77k
  obj_raw_syment_count (abfd) =
325
6.77k
    obj_conv_table_size (abfd) =
326
6.77k
      internal_f->f_nsyms;
327
328
6.77k
  pe->real_flags = internal_f->f_flags;
329
330
6.77k
  if ((internal_f->f_flags & F_DLL) != 0)
331
1.91k
    pe->dll = 1;
332
333
6.77k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
4.95k
    abfd->flags |= HAS_DEBUG;
335
336
6.77k
#ifdef COFF_IMAGE_WITH_PE
337
6.77k
  if (aouthdr)
338
4.51k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
6.77k
#endif
340
341
#ifdef ARM
342
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
6.77k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
6.77k
    sizeof (pe->dos_message));
348
349
6.77k
  return (void *) pe;
350
6.77k
}
pe-arm-wince.c:pe_mkobject_hook
Line
Count
Source
302
3.05k
{
303
3.05k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
3.05k
  pe_data_type *pe;
305
306
3.05k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
3.05k
  pe = pe_data (abfd);
310
3.05k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
3.05k
  pe->coff.local_n_btmask = N_BTMASK;
315
3.05k
  pe->coff.local_n_btshft = N_BTSHFT;
316
3.05k
  pe->coff.local_n_tmask = N_TMASK;
317
3.05k
  pe->coff.local_n_tshift = N_TSHIFT;
318
3.05k
  pe->coff.local_symesz = SYMESZ;
319
3.05k
  pe->coff.local_auxesz = AUXESZ;
320
3.05k
  pe->coff.local_linesz = LINESZ;
321
322
3.05k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
3.05k
  obj_raw_syment_count (abfd) =
325
3.05k
    obj_conv_table_size (abfd) =
326
3.05k
      internal_f->f_nsyms;
327
328
3.05k
  pe->real_flags = internal_f->f_flags;
329
330
3.05k
  if ((internal_f->f_flags & F_DLL) != 0)
331
913
    pe->dll = 1;
332
333
3.05k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
2.24k
    abfd->flags |= HAS_DEBUG;
335
336
#ifdef COFF_IMAGE_WITH_PE
337
  if (aouthdr)
338
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
#endif
340
341
3.05k
#ifdef ARM
342
3.05k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
0
    coff_data (abfd) ->flags = 0;
344
3.05k
#endif
345
346
3.05k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
3.05k
    sizeof (pe->dos_message));
348
349
3.05k
  return (void *) pe;
350
3.05k
}
pe-arm.c:pe_mkobject_hook
Line
Count
Source
302
3.05k
{
303
3.05k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
3.05k
  pe_data_type *pe;
305
306
3.05k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
3.05k
  pe = pe_data (abfd);
310
3.05k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
3.05k
  pe->coff.local_n_btmask = N_BTMASK;
315
3.05k
  pe->coff.local_n_btshft = N_BTSHFT;
316
3.05k
  pe->coff.local_n_tmask = N_TMASK;
317
3.05k
  pe->coff.local_n_tshift = N_TSHIFT;
318
3.05k
  pe->coff.local_symesz = SYMESZ;
319
3.05k
  pe->coff.local_auxesz = AUXESZ;
320
3.05k
  pe->coff.local_linesz = LINESZ;
321
322
3.05k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
3.05k
  obj_raw_syment_count (abfd) =
325
3.05k
    obj_conv_table_size (abfd) =
326
3.05k
      internal_f->f_nsyms;
327
328
3.05k
  pe->real_flags = internal_f->f_flags;
329
330
3.05k
  if ((internal_f->f_flags & F_DLL) != 0)
331
913
    pe->dll = 1;
332
333
3.05k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
2.24k
    abfd->flags |= HAS_DEBUG;
335
336
#ifdef COFF_IMAGE_WITH_PE
337
  if (aouthdr)
338
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
#endif
340
341
3.05k
#ifdef ARM
342
3.05k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
0
    coff_data (abfd) ->flags = 0;
344
3.05k
#endif
345
346
3.05k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
3.05k
    sizeof (pe->dos_message));
348
349
3.05k
  return (void *) pe;
350
3.05k
}
pe-i386.c:pe_mkobject_hook
Line
Count
Source
302
10.4k
{
303
10.4k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
10.4k
  pe_data_type *pe;
305
306
10.4k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
10.4k
  pe = pe_data (abfd);
310
10.4k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
10.4k
  pe->coff.local_n_btmask = N_BTMASK;
315
10.4k
  pe->coff.local_n_btshft = N_BTSHFT;
316
10.4k
  pe->coff.local_n_tmask = N_TMASK;
317
10.4k
  pe->coff.local_n_tshift = N_TSHIFT;
318
10.4k
  pe->coff.local_symesz = SYMESZ;
319
10.4k
  pe->coff.local_auxesz = AUXESZ;
320
10.4k
  pe->coff.local_linesz = LINESZ;
321
322
10.4k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
10.4k
  obj_raw_syment_count (abfd) =
325
10.4k
    obj_conv_table_size (abfd) =
326
10.4k
      internal_f->f_nsyms;
327
328
10.4k
  pe->real_flags = internal_f->f_flags;
329
330
10.4k
  if ((internal_f->f_flags & F_DLL) != 0)
331
2.87k
    pe->dll = 1;
332
333
10.4k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
7.06k
    abfd->flags |= HAS_DEBUG;
335
336
#ifdef COFF_IMAGE_WITH_PE
337
  if (aouthdr)
338
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
#endif
340
341
#ifdef ARM
342
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
10.4k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
10.4k
    sizeof (pe->dos_message));
348
349
10.4k
  return (void *) pe;
350
10.4k
}
pe-mcore.c:pe_mkobject_hook
Line
Count
Source
302
3.99k
{
303
3.99k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
3.99k
  pe_data_type *pe;
305
306
3.99k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
3.99k
  pe = pe_data (abfd);
310
3.99k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
3.99k
  pe->coff.local_n_btmask = N_BTMASK;
315
3.99k
  pe->coff.local_n_btshft = N_BTSHFT;
316
3.99k
  pe->coff.local_n_tmask = N_TMASK;
317
3.99k
  pe->coff.local_n_tshift = N_TSHIFT;
318
3.99k
  pe->coff.local_symesz = SYMESZ;
319
3.99k
  pe->coff.local_auxesz = AUXESZ;
320
3.99k
  pe->coff.local_linesz = LINESZ;
321
322
3.99k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
3.99k
  obj_raw_syment_count (abfd) =
325
3.99k
    obj_conv_table_size (abfd) =
326
3.99k
      internal_f->f_nsyms;
327
328
3.99k
  pe->real_flags = internal_f->f_flags;
329
330
3.99k
  if ((internal_f->f_flags & F_DLL) != 0)
331
1.20k
    pe->dll = 1;
332
333
3.99k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
3.16k
    abfd->flags |= HAS_DEBUG;
335
336
#ifdef COFF_IMAGE_WITH_PE
337
  if (aouthdr)
338
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
#endif
340
341
#ifdef ARM
342
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
3.99k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
3.99k
    sizeof (pe->dos_message));
348
349
3.99k
  return (void *) pe;
350
3.99k
}
pe-sh.c:pe_mkobject_hook
Line
Count
Source
302
5.82k
{
303
5.82k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
5.82k
  pe_data_type *pe;
305
306
5.82k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
5.82k
  pe = pe_data (abfd);
310
5.82k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
5.82k
  pe->coff.local_n_btmask = N_BTMASK;
315
5.82k
  pe->coff.local_n_btshft = N_BTSHFT;
316
5.82k
  pe->coff.local_n_tmask = N_TMASK;
317
5.82k
  pe->coff.local_n_tshift = N_TSHIFT;
318
5.82k
  pe->coff.local_symesz = SYMESZ;
319
5.82k
  pe->coff.local_auxesz = AUXESZ;
320
5.82k
  pe->coff.local_linesz = LINESZ;
321
322
5.82k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
5.82k
  obj_raw_syment_count (abfd) =
325
5.82k
    obj_conv_table_size (abfd) =
326
5.82k
      internal_f->f_nsyms;
327
328
5.82k
  pe->real_flags = internal_f->f_flags;
329
330
5.82k
  if ((internal_f->f_flags & F_DLL) != 0)
331
1.68k
    pe->dll = 1;
332
333
5.82k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
4.39k
    abfd->flags |= HAS_DEBUG;
335
336
#ifdef COFF_IMAGE_WITH_PE
337
  if (aouthdr)
338
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
#endif
340
341
#ifdef ARM
342
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
5.82k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
5.82k
    sizeof (pe->dos_message));
348
349
5.82k
  return (void *) pe;
350
5.82k
}
pei-arm-wince.c:pe_mkobject_hook
Line
Count
Source
302
6.24k
{
303
6.24k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
6.24k
  pe_data_type *pe;
305
306
6.24k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
6.24k
  pe = pe_data (abfd);
310
6.24k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
6.24k
  pe->coff.local_n_btmask = N_BTMASK;
315
6.24k
  pe->coff.local_n_btshft = N_BTSHFT;
316
6.24k
  pe->coff.local_n_tmask = N_TMASK;
317
6.24k
  pe->coff.local_n_tshift = N_TSHIFT;
318
6.24k
  pe->coff.local_symesz = SYMESZ;
319
6.24k
  pe->coff.local_auxesz = AUXESZ;
320
6.24k
  pe->coff.local_linesz = LINESZ;
321
322
6.24k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
6.24k
  obj_raw_syment_count (abfd) =
325
6.24k
    obj_conv_table_size (abfd) =
326
6.24k
      internal_f->f_nsyms;
327
328
6.24k
  pe->real_flags = internal_f->f_flags;
329
330
6.24k
  if ((internal_f->f_flags & F_DLL) != 0)
331
2.41k
    pe->dll = 1;
332
333
6.24k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
3.97k
    abfd->flags |= HAS_DEBUG;
335
336
6.24k
#ifdef COFF_IMAGE_WITH_PE
337
6.24k
  if (aouthdr)
338
2.58k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
6.24k
#endif
340
341
6.24k
#ifdef ARM
342
6.24k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
0
    coff_data (abfd) ->flags = 0;
344
6.24k
#endif
345
346
6.24k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
6.24k
    sizeof (pe->dos_message));
348
349
6.24k
  return (void *) pe;
350
6.24k
}
pei-arm.c:pe_mkobject_hook
Line
Count
Source
302
7.39k
{
303
7.39k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
7.39k
  pe_data_type *pe;
305
306
7.39k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
7.39k
  pe = pe_data (abfd);
310
7.39k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
7.39k
  pe->coff.local_n_btmask = N_BTMASK;
315
7.39k
  pe->coff.local_n_btshft = N_BTSHFT;
316
7.39k
  pe->coff.local_n_tmask = N_TMASK;
317
7.39k
  pe->coff.local_n_tshift = N_TSHIFT;
318
7.39k
  pe->coff.local_symesz = SYMESZ;
319
7.39k
  pe->coff.local_auxesz = AUXESZ;
320
7.39k
  pe->coff.local_linesz = LINESZ;
321
322
7.39k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
7.39k
  obj_raw_syment_count (abfd) =
325
7.39k
    obj_conv_table_size (abfd) =
326
7.39k
      internal_f->f_nsyms;
327
328
7.39k
  pe->real_flags = internal_f->f_flags;
329
330
7.39k
  if ((internal_f->f_flags & F_DLL) != 0)
331
2.73k
    pe->dll = 1;
332
333
7.39k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
4.93k
    abfd->flags |= HAS_DEBUG;
335
336
7.39k
#ifdef COFF_IMAGE_WITH_PE
337
7.39k
  if (aouthdr)
338
3.73k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
7.39k
#endif
340
341
7.39k
#ifdef ARM
342
7.39k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
0
    coff_data (abfd) ->flags = 0;
344
7.39k
#endif
345
346
7.39k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
7.39k
    sizeof (pe->dos_message));
348
349
7.39k
  return (void *) pe;
350
7.39k
}
pei-mcore.c:pe_mkobject_hook
Line
Count
Source
302
5.52k
{
303
5.52k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
5.52k
  pe_data_type *pe;
305
306
5.52k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
5.52k
  pe = pe_data (abfd);
310
5.52k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
5.52k
  pe->coff.local_n_btmask = N_BTMASK;
315
5.52k
  pe->coff.local_n_btshft = N_BTSHFT;
316
5.52k
  pe->coff.local_n_tmask = N_TMASK;
317
5.52k
  pe->coff.local_n_tshift = N_TSHIFT;
318
5.52k
  pe->coff.local_symesz = SYMESZ;
319
5.52k
  pe->coff.local_auxesz = AUXESZ;
320
5.52k
  pe->coff.local_linesz = LINESZ;
321
322
5.52k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
5.52k
  obj_raw_syment_count (abfd) =
325
5.52k
    obj_conv_table_size (abfd) =
326
5.52k
      internal_f->f_nsyms;
327
328
5.52k
  pe->real_flags = internal_f->f_flags;
329
330
5.52k
  if ((internal_f->f_flags & F_DLL) != 0)
331
2.12k
    pe->dll = 1;
332
333
5.52k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
3.48k
    abfd->flags |= HAS_DEBUG;
335
336
5.52k
#ifdef COFF_IMAGE_WITH_PE
337
5.52k
  if (aouthdr)
338
3.25k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
5.52k
#endif
340
341
#ifdef ARM
342
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
5.52k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
5.52k
    sizeof (pe->dos_message));
348
349
5.52k
  return (void *) pe;
350
5.52k
}
pei-sh.c:pe_mkobject_hook
Line
Count
Source
302
5.67k
{
303
5.67k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
5.67k
  pe_data_type *pe;
305
306
5.67k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
5.67k
  pe = pe_data (abfd);
310
5.67k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
5.67k
  pe->coff.local_n_btmask = N_BTMASK;
315
5.67k
  pe->coff.local_n_btshft = N_BTSHFT;
316
5.67k
  pe->coff.local_n_tmask = N_TMASK;
317
5.67k
  pe->coff.local_n_tshift = N_TSHIFT;
318
5.67k
  pe->coff.local_symesz = SYMESZ;
319
5.67k
  pe->coff.local_auxesz = AUXESZ;
320
5.67k
  pe->coff.local_linesz = LINESZ;
321
322
5.67k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
5.67k
  obj_raw_syment_count (abfd) =
325
5.67k
    obj_conv_table_size (abfd) =
326
5.67k
      internal_f->f_nsyms;
327
328
5.67k
  pe->real_flags = internal_f->f_flags;
329
330
5.67k
  if ((internal_f->f_flags & F_DLL) != 0)
331
2.21k
    pe->dll = 1;
332
333
5.67k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
3.59k
    abfd->flags |= HAS_DEBUG;
335
336
5.67k
#ifdef COFF_IMAGE_WITH_PE
337
5.67k
  if (aouthdr)
338
3.40k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
5.67k
#endif
340
341
#ifdef ARM
342
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
5.67k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
5.67k
    sizeof (pe->dos_message));
348
349
5.67k
  return (void *) pe;
350
5.67k
}
351
352
static bool
353
pe_print_private_bfd_data (bfd *abfd, void *vfile)
354
10.4k
{
355
10.4k
  FILE *file = (FILE *) vfile;
356
357
10.4k
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
10.4k
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
10.2k
    return true;
362
363
225
  fputc ('\n', file);
364
365
225
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
10.4k
}
pei-i386.c:pe_print_private_bfd_data
Line
Count
Source
354
177
{
355
177
  FILE *file = (FILE *) vfile;
356
357
177
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
177
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
177
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
177
}
pe-x86_64.c:pe_print_private_bfd_data
Line
Count
Source
354
198
{
355
198
  FILE *file = (FILE *) vfile;
356
357
198
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
198
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
198
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
198
}
pei-x86_64.c:pe_print_private_bfd_data
Line
Count
Source
354
200
{
355
200
  FILE *file = (FILE *) vfile;
356
357
200
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
200
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
200
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
200
}
pe-aarch64.c:pe_print_private_bfd_data
Line
Count
Source
354
5.62k
{
355
5.62k
  FILE *file = (FILE *) vfile;
356
357
5.62k
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
5.62k
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
5.62k
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
5.62k
}
pei-aarch64.c:pe_print_private_bfd_data
Line
Count
Source
354
2.81k
{
355
2.81k
  FILE *file = (FILE *) vfile;
356
357
2.81k
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
2.81k
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
2.81k
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
2.81k
}
pei-ia64.c:pe_print_private_bfd_data
Line
Count
Source
354
313
{
355
313
  FILE *file = (FILE *) vfile;
356
357
313
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
313
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
313
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
313
}
pei-loongarch64.c:pe_print_private_bfd_data
Line
Count
Source
354
224
{
355
224
  FILE *file = (FILE *) vfile;
356
357
224
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
224
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
224
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
224
}
pei-riscv64.c:pe_print_private_bfd_data
Line
Count
Source
354
251
{
355
251
  FILE *file = (FILE *) vfile;
356
357
251
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
251
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
251
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
251
}
Unexecuted instantiation: pe-arm-wince.c:pe_print_private_bfd_data
Unexecuted instantiation: pe-arm.c:pe_print_private_bfd_data
pe-i386.c:pe_print_private_bfd_data
Line
Count
Source
354
62
{
355
62
  FILE *file = (FILE *) vfile;
356
357
62
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
62
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
62
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
62
}
pe-mcore.c:pe_print_private_bfd_data
Line
Count
Source
354
106
{
355
106
  FILE *file = (FILE *) vfile;
356
357
106
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
106
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
106
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
106
}
pe-sh.c:pe_print_private_bfd_data
Line
Count
Source
354
62
{
355
62
  FILE *file = (FILE *) vfile;
356
357
62
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
62
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
62
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
62
}
pei-arm-wince.c:pe_print_private_bfd_data
Line
Count
Source
354
14
{
355
14
  FILE *file = (FILE *) vfile;
356
357
14
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
14
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
0
    return true;
362
363
14
  fputc ('\n', file);
364
365
14
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
14
}
pei-arm.c:pe_print_private_bfd_data
Line
Count
Source
354
211
{
355
211
  FILE *file = (FILE *) vfile;
356
357
211
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
211
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
0
    return true;
362
363
211
  fputc ('\n', file);
364
365
211
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
211
}
pei-mcore.c:pe_print_private_bfd_data
Line
Count
Source
354
125
{
355
125
  FILE *file = (FILE *) vfile;
356
357
125
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
125
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
125
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
125
}
pei-sh.c:pe_print_private_bfd_data
Line
Count
Source
354
111
{
355
111
  FILE *file = (FILE *) vfile;
356
357
111
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
111
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
111
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
111
}
367
368
/* Copy any private info we understand from the input bfd
369
   to the output bfd.  */
370
371
static bool
372
pe_bfd_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
373
1.36k
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
1.36k
  if (pe_data (obfd) != NULL
378
1.36k
      && pe_data (ibfd) != NULL
379
1.36k
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
493
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
1.36k
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
16
    return false;
384
385
1.34k
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
134
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
1.21k
  return true;
389
1.34k
}
pei-i386.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
85
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
85
  if (pe_data (obfd) != NULL
378
85
      && pe_data (ibfd) != NULL
379
85
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
16
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
85
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
3
    return false;
384
385
82
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
82
  return true;
389
82
}
pe-x86_64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
159
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
159
  if (pe_data (obfd) != NULL
378
159
      && pe_data (ibfd) != NULL
379
159
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
34
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
159
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
0
    return false;
384
385
159
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
159
  return true;
389
159
}
pei-x86_64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
99
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
99
  if (pe_data (obfd) != NULL
378
99
      && pe_data (ibfd) != NULL
379
99
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
40
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
99
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
1
    return false;
384
385
98
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
98
  return true;
389
98
}
pe-aarch64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
79
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
79
  if (pe_data (obfd) != NULL
378
79
      && pe_data (ibfd) != NULL
379
79
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
29
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
79
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
0
    return false;
384
385
79
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
79
  return true;
389
79
}
pei-aarch64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
110
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
110
  if (pe_data (obfd) != NULL
378
110
      && pe_data (ibfd) != NULL
379
110
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
45
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
110
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
2
    return false;
384
385
108
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
108
  return true;
389
108
}
pei-ia64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
108
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
108
  if (pe_data (obfd) != NULL
378
108
      && pe_data (ibfd) != NULL
379
108
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
31
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
108
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
3
    return false;
384
385
105
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
105
  return true;
389
105
}
pei-loongarch64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
127
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
127
  if (pe_data (obfd) != NULL
378
127
      && pe_data (ibfd) != NULL
379
127
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
43
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
127
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
4
    return false;
384
385
123
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
123
  return true;
389
123
}
pei-riscv64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
130
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
130
  if (pe_data (obfd) != NULL
378
130
      && pe_data (ibfd) != NULL
379
130
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
87
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
130
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
2
    return false;
384
385
128
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
128
  return true;
389
128
}
Unexecuted instantiation: pe-arm-wince.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pe-arm.c:pe_bfd_copy_private_bfd_data
pe-i386.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
47
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
47
  if (pe_data (obfd) != NULL
378
47
      && pe_data (ibfd) != NULL
379
47
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
15
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
47
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
0
    return false;
384
385
47
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
47
  return true;
389
47
}
pe-mcore.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
63
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
63
  if (pe_data (obfd) != NULL
378
63
      && pe_data (ibfd) != NULL
379
63
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
14
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
63
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
0
    return false;
384
385
63
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
63
  return true;
389
63
}
pe-sh.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
78
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
78
  if (pe_data (obfd) != NULL
378
78
      && pe_data (ibfd) != NULL
379
78
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
21
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
78
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
0
    return false;
384
385
78
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
78
  return true;
389
78
}
pei-arm-wince.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
49
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
49
  if (pe_data (obfd) != NULL
378
49
      && pe_data (ibfd) != NULL
379
49
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
25
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
49
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
0
    return false;
384
385
49
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
49
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
0
  return true;
389
49
}
pei-arm.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
86
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
86
  if (pe_data (obfd) != NULL
378
86
      && pe_data (ibfd) != NULL
379
86
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
48
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
86
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
1
    return false;
384
385
85
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
85
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
0
  return true;
389
85
}
pei-mcore.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
50
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
50
  if (pe_data (obfd) != NULL
378
50
      && pe_data (ibfd) != NULL
379
50
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
23
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
50
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
0
    return false;
384
385
50
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
50
  return true;
389
50
}
pei-sh.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
92
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
92
  if (pe_data (obfd) != NULL
378
92
      && pe_data (ibfd) != NULL
379
92
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
22
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
92
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
0
    return false;
384
385
92
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
92
  return true;
389
92
}
390
391
#define coff_bfd_copy_private_section_data \
392
  _bfd_XX_bfd_copy_private_section_data
393
394
#define coff_get_symbol_info _bfd_XX_get_symbol_info
395
396
#ifdef COFF_IMAGE_WITH_PE
397

398
/* Code to handle Microsoft's Import Library Format.
399
   Also known as LINK6 format.
400
   Documentation about this format can be found at:
401
402
   https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#import-library-format  */
403
404
/* The following constants specify the sizes of the various data
405
   structures that we have to create in order to build a bfd describing
406
   an ILF object file.  The final "+ 1" in the definitions of SIZEOF_IDATA6
407
   and SIZEOF_IDATA7 below is to allow for the possibility that we might
408
   need a padding byte in order to ensure 16 bit alignment for the section's
409
   contents.
410
411
   The value for SIZEOF_ILF_STRINGS is computed as follows:
412
413
      There will be NUM_ILF_SECTIONS section symbols.  Allow 9 characters
414
      per symbol for their names (longest section name is .idata$x).
415
416
      There will be two symbols for the imported value, one the symbol name
417
      and one with _imp__ prefixed.  Allowing for the terminating nul's this
418
      is strlen (symbol_name) * 2 + 8 + 21 + strlen (source_dll).
419
420
      The strings in the string table must start STRING__SIZE_SIZE bytes into
421
      the table in order to for the string lookup code in coffgen/coffcode to
422
      work.  */
423
6.48k
#define NUM_ILF_RELOCS    8
424
21.6k
#define NUM_ILF_SECTIONS  6
425
16.2k
#define NUM_ILF_SYMS    (2 + NUM_ILF_SECTIONS)
426
427
3.24k
#define SIZEOF_ILF_SYMS    (NUM_ILF_SYMS * sizeof (*vars.sym_cache))
428
3.24k
#define SIZEOF_ILF_SYM_TABLE   (NUM_ILF_SYMS * sizeof (*vars.sym_table))
429
3.24k
#define SIZEOF_ILF_NATIVE_SYMS   (NUM_ILF_SYMS * sizeof (*vars.native_syms))
430
3.24k
#define SIZEOF_ILF_SYM_PTR_TABLE (NUM_ILF_SYMS * sizeof (*vars.sym_ptr_table))
431
3.24k
#define SIZEOF_ILF_EXT_SYMS  (NUM_ILF_SYMS * sizeof (*vars.esym_table))
432
3.24k
#define SIZEOF_ILF_RELOCS  (NUM_ILF_RELOCS * sizeof (*vars.reltab))
433
3.24k
#define SIZEOF_ILF_INT_RELOCS  (NUM_ILF_RELOCS * sizeof (*vars.int_reltab))
434
3.24k
#define SIZEOF_ILF_STRINGS   (strlen (symbol_name) * 2 + 8 \
435
3.24k
          + 21 + strlen (source_dll)   \
436
3.24k
          + NUM_ILF_SECTIONS * 9       \
437
3.24k
          + STRING_SIZE_SIZE)
438
2.16k
#define SIZEOF_IDATA2   (5 * 4)
439
440
/* For PEx64 idata4 & 5 have thumb size of 8 bytes.  */
441
#if defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64)
442
831
#define SIZEOF_IDATA4   (2 * 4)
443
831
#define SIZEOF_IDATA5   (2 * 4)
444
#else
445
2.40k
#define SIZEOF_IDATA4   (1 * 4)
446
2.40k
#define SIZEOF_IDATA5   (1 * 4)
447
#endif
448
449
2.92k
#define SIZEOF_IDATA6   (2 + strlen (import_name) + 1 + 1)
450
2.16k
#define SIZEOF_IDATA7   (strlen (source_dll) + 1 + 1)
451
2.16k
#define SIZEOF_ILF_SECTIONS (NUM_ILF_SECTIONS \
452
2.16k
         * sizeof (struct coff_section_tdata))
453
454
#define ILF_DATA_SIZE       \
455
2.16k
    + SIZEOF_ILF_SYMS        \
456
2.16k
    + SIZEOF_ILF_SYM_TABLE      \
457
2.16k
    + SIZEOF_ILF_NATIVE_SYMS      \
458
2.16k
    + SIZEOF_ILF_SYM_PTR_TABLE      \
459
2.16k
    + SIZEOF_ILF_EXT_SYMS      \
460
2.16k
    + SIZEOF_ILF_RELOCS        \
461
2.16k
    + SIZEOF_ILF_INT_RELOCS      \
462
2.16k
    + SIZEOF_ILF_STRINGS      \
463
2.16k
    + SIZEOF_IDATA2        \
464
2.16k
    + SIZEOF_IDATA4        \
465
2.16k
    + SIZEOF_IDATA5        \
466
2.16k
    + SIZEOF_IDATA6        \
467
2.16k
    + SIZEOF_IDATA7        \
468
2.16k
    + SIZEOF_ILF_SECTIONS      \
469
2.16k
    + MAX_TEXT_SECTION_SIZE
470
471
/* Create an empty relocation against the given symbol.  */
472
473
static void
474
pe_ILF_make_a_symbol_reloc (pe_ILF_vars *   vars,
475
          bfd_vma     address,
476
          bfd_reloc_code_real_type  reloc,
477
          struct bfd_symbol **  sym,
478
          unsigned int    sym_index)
479
1.97k
{
480
1.97k
  arelent *entry;
481
1.97k
  struct internal_reloc *internal;
482
483
1.97k
  entry = vars->reltab + vars->relcount;
484
1.97k
  internal = vars->int_reltab + vars->relcount;
485
486
1.97k
  entry->address     = address;
487
1.97k
  entry->addend      = 0;
488
1.97k
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
489
1.97k
  entry->sym_ptr_ptr = sym;
490
491
1.97k
  internal->r_vaddr  = address;
492
1.97k
  internal->r_symndx = sym_index;
493
1.97k
  internal->r_type   = entry->howto ? entry->howto->type : 0;
494
495
1.97k
  vars->relcount ++;
496
497
1.97k
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
498
1.97k
}
pei-i386.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
479
271
{
480
271
  arelent *entry;
481
271
  struct internal_reloc *internal;
482
483
271
  entry = vars->reltab + vars->relcount;
484
271
  internal = vars->int_reltab + vars->relcount;
485
486
271
  entry->address     = address;
487
271
  entry->addend      = 0;
488
271
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
489
271
  entry->sym_ptr_ptr = sym;
490
491
271
  internal->r_vaddr  = address;
492
271
  internal->r_symndx = sym_index;
493
271
  internal->r_type   = entry->howto ? entry->howto->type : 0;
494
495
271
  vars->relcount ++;
496
497
271
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
498
271
}
pei-x86_64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
479
259
{
480
259
  arelent *entry;
481
259
  struct internal_reloc *internal;
482
483
259
  entry = vars->reltab + vars->relcount;
484
259
  internal = vars->int_reltab + vars->relcount;
485
486
259
  entry->address     = address;
487
259
  entry->addend      = 0;
488
259
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
489
259
  entry->sym_ptr_ptr = sym;
490
491
259
  internal->r_vaddr  = address;
492
259
  internal->r_symndx = sym_index;
493
259
  internal->r_type   = entry->howto ? entry->howto->type : 0;
494
495
259
  vars->relcount ++;
496
497
259
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
498
259
}
pei-aarch64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
479
245
{
480
245
  arelent *entry;
481
245
  struct internal_reloc *internal;
482
483
245
  entry = vars->reltab + vars->relcount;
484
245
  internal = vars->int_reltab + vars->relcount;
485
486
245
  entry->address     = address;
487
245
  entry->addend      = 0;
488
245
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
489
245
  entry->sym_ptr_ptr = sym;
490
491
245
  internal->r_vaddr  = address;
492
245
  internal->r_symndx = sym_index;
493
245
  internal->r_type   = entry->howto ? entry->howto->type : 0;
494
495
245
  vars->relcount ++;
496
497
245
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
498
245
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_symbol_reloc
pei-loongarch64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
479
256
{
480
256
  arelent *entry;
481
256
  struct internal_reloc *internal;
482
483
256
  entry = vars->reltab + vars->relcount;
484
256
  internal = vars->int_reltab + vars->relcount;
485
486
256
  entry->address     = address;
487
256
  entry->addend      = 0;
488
256
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
489
256
  entry->sym_ptr_ptr = sym;
490
491
256
  internal->r_vaddr  = address;
492
256
  internal->r_symndx = sym_index;
493
256
  internal->r_type   = entry->howto ? entry->howto->type : 0;
494
495
256
  vars->relcount ++;
496
497
256
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
498
256
}
pei-riscv64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
479
238
{
480
238
  arelent *entry;
481
238
  struct internal_reloc *internal;
482
483
238
  entry = vars->reltab + vars->relcount;
484
238
  internal = vars->int_reltab + vars->relcount;
485
486
238
  entry->address     = address;
487
238
  entry->addend      = 0;
488
238
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
489
238
  entry->sym_ptr_ptr = sym;
490
491
238
  internal->r_vaddr  = address;
492
238
  internal->r_symndx = sym_index;
493
238
  internal->r_type   = entry->howto ? entry->howto->type : 0;
494
495
238
  vars->relcount ++;
496
497
238
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
498
238
}
pei-arm-wince.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
479
185
{
480
185
  arelent *entry;
481
185
  struct internal_reloc *internal;
482
483
185
  entry = vars->reltab + vars->relcount;
484
185
  internal = vars->int_reltab + vars->relcount;
485
486
185
  entry->address     = address;
487
185
  entry->addend      = 0;
488
185
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
489
185
  entry->sym_ptr_ptr = sym;
490
491
185
  internal->r_vaddr  = address;
492
185
  internal->r_symndx = sym_index;
493
185
  internal->r_type   = entry->howto ? entry->howto->type : 0;
494
495
185
  vars->relcount ++;
496
497
185
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
498
185
}
pei-arm.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
479
188
{
480
188
  arelent *entry;
481
188
  struct internal_reloc *internal;
482
483
188
  entry = vars->reltab + vars->relcount;
484
188
  internal = vars->int_reltab + vars->relcount;
485
486
188
  entry->address     = address;
487
188
  entry->addend      = 0;
488
188
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
489
188
  entry->sym_ptr_ptr = sym;
490
491
188
  internal->r_vaddr  = address;
492
188
  internal->r_symndx = sym_index;
493
188
  internal->r_type   = entry->howto ? entry->howto->type : 0;
494
495
188
  vars->relcount ++;
496
497
188
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
498
188
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_symbol_reloc
pei-sh.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
479
328
{
480
328
  arelent *entry;
481
328
  struct internal_reloc *internal;
482
483
328
  entry = vars->reltab + vars->relcount;
484
328
  internal = vars->int_reltab + vars->relcount;
485
486
328
  entry->address     = address;
487
328
  entry->addend      = 0;
488
328
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
489
328
  entry->sym_ptr_ptr = sym;
490
491
328
  internal->r_vaddr  = address;
492
328
  internal->r_symndx = sym_index;
493
328
  internal->r_type   = entry->howto ? entry->howto->type : 0;
494
495
328
  vars->relcount ++;
496
497
328
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
498
328
}
499
500
/* Create an empty relocation against the given section.  */
501
502
static void
503
pe_ILF_make_a_reloc (pe_ILF_vars *         vars,
504
         bfd_vma           address,
505
         bfd_reloc_code_real_type  reloc,
506
         asection_ptr        sec)
507
1.53k
{
508
1.53k
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
509
1.53k
            coff_section_data (vars->abfd, sec)->i);
510
1.53k
}
pei-i386.c:pe_ILF_make_a_reloc
Line
Count
Source
507
198
{
508
198
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
509
198
            coff_section_data (vars->abfd, sec)->i);
510
198
}
pei-x86_64.c:pe_ILF_make_a_reloc
Line
Count
Source
507
204
{
508
204
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
509
204
            coff_section_data (vars->abfd, sec)->i);
510
204
}
pei-aarch64.c:pe_ILF_make_a_reloc
Line
Count
Source
507
190
{
508
190
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
509
190
            coff_section_data (vars->abfd, sec)->i);
510
190
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_reloc
pei-loongarch64.c:pe_ILF_make_a_reloc
Line
Count
Source
507
196
{
508
196
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
509
196
            coff_section_data (vars->abfd, sec)->i);
510
196
}
pei-riscv64.c:pe_ILF_make_a_reloc
Line
Count
Source
507
202
{
508
202
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
509
202
            coff_section_data (vars->abfd, sec)->i);
510
202
}
pei-arm-wince.c:pe_ILF_make_a_reloc
Line
Count
Source
507
136
{
508
136
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
509
136
            coff_section_data (vars->abfd, sec)->i);
510
136
}
pei-arm.c:pe_ILF_make_a_reloc
Line
Count
Source
507
138
{
508
138
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
509
138
            coff_section_data (vars->abfd, sec)->i);
510
138
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_reloc
pei-sh.c:pe_ILF_make_a_reloc
Line
Count
Source
507
270
{
508
270
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
509
270
            coff_section_data (vars->abfd, sec)->i);
510
270
}
511
512
/* Move the queued relocs into the given section.  */
513
514
static void
515
pe_ILF_save_relocs (pe_ILF_vars *vars,
516
        asection_ptr sec)
517
1.97k
{
518
  /* Make sure that there is somewhere to store the internal relocs.  */
519
1.97k
  if (coff_section_data (vars->abfd, sec) == NULL)
520
    /* We should probably return an error indication here.  */
521
0
    abort ();
522
523
1.97k
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
524
525
1.97k
  sec->relocation  = vars->reltab;
526
1.97k
  sec->reloc_count = vars->relcount;
527
1.97k
  sec->flags      |= SEC_RELOC;
528
529
1.97k
  vars->reltab     += vars->relcount;
530
1.97k
  vars->int_reltab += vars->relcount;
531
1.97k
  vars->relcount   = 0;
532
533
1.97k
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
534
1.97k
}
pei-i386.c:pe_ILF_save_relocs
Line
Count
Source
517
271
{
518
  /* Make sure that there is somewhere to store the internal relocs.  */
519
271
  if (coff_section_data (vars->abfd, sec) == NULL)
520
    /* We should probably return an error indication here.  */
521
0
    abort ();
522
523
271
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
524
525
271
  sec->relocation  = vars->reltab;
526
271
  sec->reloc_count = vars->relcount;
527
271
  sec->flags      |= SEC_RELOC;
528
529
271
  vars->reltab     += vars->relcount;
530
271
  vars->int_reltab += vars->relcount;
531
271
  vars->relcount   = 0;
532
533
271
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
534
271
}
pei-x86_64.c:pe_ILF_save_relocs
Line
Count
Source
517
259
{
518
  /* Make sure that there is somewhere to store the internal relocs.  */
519
259
  if (coff_section_data (vars->abfd, sec) == NULL)
520
    /* We should probably return an error indication here.  */
521
0
    abort ();
522
523
259
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
524
525
259
  sec->relocation  = vars->reltab;
526
259
  sec->reloc_count = vars->relcount;
527
259
  sec->flags      |= SEC_RELOC;
528
529
259
  vars->reltab     += vars->relcount;
530
259
  vars->int_reltab += vars->relcount;
531
259
  vars->relcount   = 0;
532
533
259
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
534
259
}
pei-aarch64.c:pe_ILF_save_relocs
Line
Count
Source
517
245
{
518
  /* Make sure that there is somewhere to store the internal relocs.  */
519
245
  if (coff_section_data (vars->abfd, sec) == NULL)
520
    /* We should probably return an error indication here.  */
521
0
    abort ();
522
523
245
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
524
525
245
  sec->relocation  = vars->reltab;
526
245
  sec->reloc_count = vars->relcount;
527
245
  sec->flags      |= SEC_RELOC;
528
529
245
  vars->reltab     += vars->relcount;
530
245
  vars->int_reltab += vars->relcount;
531
245
  vars->relcount   = 0;
532
533
245
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
534
245
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_save_relocs
pei-loongarch64.c:pe_ILF_save_relocs
Line
Count
Source
517
256
{
518
  /* Make sure that there is somewhere to store the internal relocs.  */
519
256
  if (coff_section_data (vars->abfd, sec) == NULL)
520
    /* We should probably return an error indication here.  */
521
0
    abort ();
522
523
256
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
524
525
256
  sec->relocation  = vars->reltab;
526
256
  sec->reloc_count = vars->relcount;
527
256
  sec->flags      |= SEC_RELOC;
528
529
256
  vars->reltab     += vars->relcount;
530
256
  vars->int_reltab += vars->relcount;
531
256
  vars->relcount   = 0;
532
533
256
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
534
256
}
pei-riscv64.c:pe_ILF_save_relocs
Line
Count
Source
517
238
{
518
  /* Make sure that there is somewhere to store the internal relocs.  */
519
238
  if (coff_section_data (vars->abfd, sec) == NULL)
520
    /* We should probably return an error indication here.  */
521
0
    abort ();
522
523
238
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
524
525
238
  sec->relocation  = vars->reltab;
526
238
  sec->reloc_count = vars->relcount;
527
238
  sec->flags      |= SEC_RELOC;
528
529
238
  vars->reltab     += vars->relcount;
530
238
  vars->int_reltab += vars->relcount;
531
238
  vars->relcount   = 0;
532
533
238
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
534
238
}
pei-arm-wince.c:pe_ILF_save_relocs
Line
Count
Source
517
185
{
518
  /* Make sure that there is somewhere to store the internal relocs.  */
519
185
  if (coff_section_data (vars->abfd, sec) == NULL)
520
    /* We should probably return an error indication here.  */
521
0
    abort ();
522
523
185
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
524
525
185
  sec->relocation  = vars->reltab;
526
185
  sec->reloc_count = vars->relcount;
527
185
  sec->flags      |= SEC_RELOC;
528
529
185
  vars->reltab     += vars->relcount;
530
185
  vars->int_reltab += vars->relcount;
531
185
  vars->relcount   = 0;
532
533
185
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
534
185
}
pei-arm.c:pe_ILF_save_relocs
Line
Count
Source
517
188
{
518
  /* Make sure that there is somewhere to store the internal relocs.  */
519
188
  if (coff_section_data (vars->abfd, sec) == NULL)
520
    /* We should probably return an error indication here.  */
521
0
    abort ();
522
523
188
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
524
525
188
  sec->relocation  = vars->reltab;
526
188
  sec->reloc_count = vars->relcount;
527
188
  sec->flags      |= SEC_RELOC;
528
529
188
  vars->reltab     += vars->relcount;
530
188
  vars->int_reltab += vars->relcount;
531
188
  vars->relcount   = 0;
532
533
188
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
534
188
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_save_relocs
pei-sh.c:pe_ILF_save_relocs
Line
Count
Source
517
328
{
518
  /* Make sure that there is somewhere to store the internal relocs.  */
519
328
  if (coff_section_data (vars->abfd, sec) == NULL)
520
    /* We should probably return an error indication here.  */
521
0
    abort ();
522
523
328
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
524
525
328
  sec->relocation  = vars->reltab;
526
328
  sec->reloc_count = vars->relcount;
527
328
  sec->flags      |= SEC_RELOC;
528
529
328
  vars->reltab     += vars->relcount;
530
328
  vars->int_reltab += vars->relcount;
531
328
  vars->relcount   = 0;
532
533
328
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
534
328
}
535
536
/* Create a global symbol and add it to the relevant tables.  */
537
538
static void
539
pe_ILF_make_a_symbol (pe_ILF_vars *  vars,
540
          const char *   prefix,
541
          const char *   symbol_name,
542
          asection_ptr   section,
543
          flagword       extra_flags)
544
6.05k
{
545
6.05k
  coff_symbol_type *sym;
546
6.05k
  combined_entry_type *ent;
547
6.05k
  SYMENT *esym;
548
6.05k
  unsigned short sclass;
549
550
6.05k
  if (extra_flags & BSF_LOCAL)
551
3.36k
    sclass = C_STAT;
552
2.69k
  else
553
2.69k
    sclass = C_EXT;
554
555
#ifdef THUMBPEMAGIC
556
1.18k
  if (vars->magic == THUMBPEMAGIC)
557
602
    {
558
602
      if (extra_flags & BSF_FUNCTION)
559
48
  sclass = C_THUMBEXTFUNC;
560
554
      else if (extra_flags & BSF_LOCAL)
561
332
  sclass = C_THUMBSTAT;
562
222
      else
563
222
  sclass = C_THUMBEXT;
564
602
    }
565
#endif
566
567
6.05k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
568
569
6.05k
  sym = vars->sym_ptr;
570
6.05k
  ent = vars->native_ptr;
571
6.05k
  esym = vars->esym_ptr;
572
573
  /* Copy the symbol's name into the string table.  */
574
6.05k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
575
576
6.05k
  if (section == NULL)
577
1.00k
    section = bfd_und_section_ptr;
578
579
  /* Initialise the external symbol.  */
580
6.05k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
581
6.05k
      esym->e.e.e_offset);
582
6.05k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
583
6.05k
  esym->e_sclass[0] = sclass;
584
585
  /* The following initialisations are unnecessary - the memory is
586
     zero initialised.  They are just kept here as reminders.  */
587
588
  /* Initialise the internal symbol structure.  */
589
6.05k
  ent->u.syment.n_sclass    = sclass;
590
6.05k
  ent->u.syment.n_scnum     = section->target_index;
591
6.05k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
592
6.05k
  ent->is_sym = true;
593
594
6.05k
  sym->symbol.the_bfd = vars->abfd;
595
6.05k
  sym->symbol.name    = vars->string_ptr;
596
6.05k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
597
6.05k
  sym->symbol.section = section;
598
6.05k
  sym->native       = ent;
599
600
6.05k
  *vars->table_ptr = vars->sym_index;
601
6.05k
  *vars->sym_ptr_ptr = sym;
602
603
  /* Adjust pointers for the next symbol.  */
604
6.05k
  vars->sym_index ++;
605
6.05k
  vars->sym_ptr ++;
606
6.05k
  vars->sym_ptr_ptr ++;
607
6.05k
  vars->table_ptr ++;
608
6.05k
  vars->native_ptr ++;
609
6.05k
  vars->esym_ptr ++;
610
6.05k
  vars->string_ptr += len + 1;
611
612
6.05k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
613
6.05k
}
pei-i386.c:pe_ILF_make_a_symbol
Line
Count
Source
544
810
{
545
810
  coff_symbol_type *sym;
546
810
  combined_entry_type *ent;
547
810
  SYMENT *esym;
548
810
  unsigned short sclass;
549
550
810
  if (extra_flags & BSF_LOCAL)
551
450
    sclass = C_STAT;
552
360
  else
553
360
    sclass = C_EXT;
554
555
#ifdef THUMBPEMAGIC
556
  if (vars->magic == THUMBPEMAGIC)
557
    {
558
      if (extra_flags & BSF_FUNCTION)
559
  sclass = C_THUMBEXTFUNC;
560
      else if (extra_flags & BSF_LOCAL)
561
  sclass = C_THUMBSTAT;
562
      else
563
  sclass = C_THUMBEXT;
564
    }
565
#endif
566
567
810
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
568
569
810
  sym = vars->sym_ptr;
570
810
  ent = vars->native_ptr;
571
810
  esym = vars->esym_ptr;
572
573
  /* Copy the symbol's name into the string table.  */
574
810
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
575
576
810
  if (section == NULL)
577
128
    section = bfd_und_section_ptr;
578
579
  /* Initialise the external symbol.  */
580
810
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
581
810
      esym->e.e.e_offset);
582
810
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
583
810
  esym->e_sclass[0] = sclass;
584
585
  /* The following initialisations are unnecessary - the memory is
586
     zero initialised.  They are just kept here as reminders.  */
587
588
  /* Initialise the internal symbol structure.  */
589
810
  ent->u.syment.n_sclass    = sclass;
590
810
  ent->u.syment.n_scnum     = section->target_index;
591
810
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
592
810
  ent->is_sym = true;
593
594
810
  sym->symbol.the_bfd = vars->abfd;
595
810
  sym->symbol.name    = vars->string_ptr;
596
810
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
597
810
  sym->symbol.section = section;
598
810
  sym->native       = ent;
599
600
810
  *vars->table_ptr = vars->sym_index;
601
810
  *vars->sym_ptr_ptr = sym;
602
603
  /* Adjust pointers for the next symbol.  */
604
810
  vars->sym_index ++;
605
810
  vars->sym_ptr ++;
606
810
  vars->sym_ptr_ptr ++;
607
810
  vars->table_ptr ++;
608
810
  vars->native_ptr ++;
609
810
  vars->esym_ptr ++;
610
810
  vars->string_ptr += len + 1;
611
612
810
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
613
810
}
pei-x86_64.c:pe_ILF_make_a_symbol
Line
Count
Source
544
821
{
545
821
  coff_symbol_type *sym;
546
821
  combined_entry_type *ent;
547
821
  SYMENT *esym;
548
821
  unsigned short sclass;
549
550
821
  if (extra_flags & BSF_LOCAL)
551
449
    sclass = C_STAT;
552
372
  else
553
372
    sclass = C_EXT;
554
555
#ifdef THUMBPEMAGIC
556
  if (vars->magic == THUMBPEMAGIC)
557
    {
558
      if (extra_flags & BSF_FUNCTION)
559
  sclass = C_THUMBEXTFUNC;
560
      else if (extra_flags & BSF_LOCAL)
561
  sclass = C_THUMBSTAT;
562
      else
563
  sclass = C_THUMBEXT;
564
    }
565
#endif
566
567
821
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
568
569
821
  sym = vars->sym_ptr;
570
821
  ent = vars->native_ptr;
571
821
  esym = vars->esym_ptr;
572
573
  /* Copy the symbol's name into the string table.  */
574
821
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
575
576
821
  if (section == NULL)
577
138
    section = bfd_und_section_ptr;
578
579
  /* Initialise the external symbol.  */
580
821
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
581
821
      esym->e.e.e_offset);
582
821
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
583
821
  esym->e_sclass[0] = sclass;
584
585
  /* The following initialisations are unnecessary - the memory is
586
     zero initialised.  They are just kept here as reminders.  */
587
588
  /* Initialise the internal symbol structure.  */
589
821
  ent->u.syment.n_sclass    = sclass;
590
821
  ent->u.syment.n_scnum     = section->target_index;
591
821
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
592
821
  ent->is_sym = true;
593
594
821
  sym->symbol.the_bfd = vars->abfd;
595
821
  sym->symbol.name    = vars->string_ptr;
596
821
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
597
821
  sym->symbol.section = section;
598
821
  sym->native       = ent;
599
600
821
  *vars->table_ptr = vars->sym_index;
601
821
  *vars->sym_ptr_ptr = sym;
602
603
  /* Adjust pointers for the next symbol.  */
604
821
  vars->sym_index ++;
605
821
  vars->sym_ptr ++;
606
821
  vars->sym_ptr_ptr ++;
607
821
  vars->table_ptr ++;
608
821
  vars->native_ptr ++;
609
821
  vars->esym_ptr ++;
610
821
  vars->string_ptr += len + 1;
611
612
821
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
613
821
}
pei-aarch64.c:pe_ILF_make_a_symbol
Line
Count
Source
544
730
{
545
730
  coff_symbol_type *sym;
546
730
  combined_entry_type *ent;
547
730
  SYMENT *esym;
548
730
  unsigned short sclass;
549
550
730
  if (extra_flags & BSF_LOCAL)
551
412
    sclass = C_STAT;
552
318
  else
553
318
    sclass = C_EXT;
554
555
#ifdef THUMBPEMAGIC
556
  if (vars->magic == THUMBPEMAGIC)
557
    {
558
      if (extra_flags & BSF_FUNCTION)
559
  sclass = C_THUMBEXTFUNC;
560
      else if (extra_flags & BSF_LOCAL)
561
  sclass = C_THUMBSTAT;
562
      else
563
  sclass = C_THUMBEXT;
564
    }
565
#endif
566
567
730
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
568
569
730
  sym = vars->sym_ptr;
570
730
  ent = vars->native_ptr;
571
730
  esym = vars->esym_ptr;
572
573
  /* Copy the symbol's name into the string table.  */
574
730
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
575
576
730
  if (section == NULL)
577
122
    section = bfd_und_section_ptr;
578
579
  /* Initialise the external symbol.  */
580
730
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
581
730
      esym->e.e.e_offset);
582
730
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
583
730
  esym->e_sclass[0] = sclass;
584
585
  /* The following initialisations are unnecessary - the memory is
586
     zero initialised.  They are just kept here as reminders.  */
587
588
  /* Initialise the internal symbol structure.  */
589
730
  ent->u.syment.n_sclass    = sclass;
590
730
  ent->u.syment.n_scnum     = section->target_index;
591
730
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
592
730
  ent->is_sym = true;
593
594
730
  sym->symbol.the_bfd = vars->abfd;
595
730
  sym->symbol.name    = vars->string_ptr;
596
730
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
597
730
  sym->symbol.section = section;
598
730
  sym->native       = ent;
599
600
730
  *vars->table_ptr = vars->sym_index;
601
730
  *vars->sym_ptr_ptr = sym;
602
603
  /* Adjust pointers for the next symbol.  */
604
730
  vars->sym_index ++;
605
730
  vars->sym_ptr ++;
606
730
  vars->sym_ptr_ptr ++;
607
730
  vars->table_ptr ++;
608
730
  vars->native_ptr ++;
609
730
  vars->esym_ptr ++;
610
730
  vars->string_ptr += len + 1;
611
612
730
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
613
730
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_symbol
pei-loongarch64.c:pe_ILF_make_a_symbol
Line
Count
Source
544
790
{
545
790
  coff_symbol_type *sym;
546
790
  combined_entry_type *ent;
547
790
  SYMENT *esym;
548
790
  unsigned short sclass;
549
550
790
  if (extra_flags & BSF_LOCAL)
551
442
    sclass = C_STAT;
552
348
  else
553
348
    sclass = C_EXT;
554
555
#ifdef THUMBPEMAGIC
556
  if (vars->magic == THUMBPEMAGIC)
557
    {
558
      if (extra_flags & BSF_FUNCTION)
559
  sclass = C_THUMBEXTFUNC;
560
      else if (extra_flags & BSF_LOCAL)
561
  sclass = C_THUMBSTAT;
562
      else
563
  sclass = C_THUMBEXT;
564
    }
565
#endif
566
567
790
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
568
569
790
  sym = vars->sym_ptr;
570
790
  ent = vars->native_ptr;
571
790
  esym = vars->esym_ptr;
572
573
  /* Copy the symbol's name into the string table.  */
574
790
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
575
576
790
  if (section == NULL)
577
133
    section = bfd_und_section_ptr;
578
579
  /* Initialise the external symbol.  */
580
790
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
581
790
      esym->e.e.e_offset);
582
790
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
583
790
  esym->e_sclass[0] = sclass;
584
585
  /* The following initialisations are unnecessary - the memory is
586
     zero initialised.  They are just kept here as reminders.  */
587
588
  /* Initialise the internal symbol structure.  */
589
790
  ent->u.syment.n_sclass    = sclass;
590
790
  ent->u.syment.n_scnum     = section->target_index;
591
790
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
592
790
  ent->is_sym = true;
593
594
790
  sym->symbol.the_bfd = vars->abfd;
595
790
  sym->symbol.name    = vars->string_ptr;
596
790
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
597
790
  sym->symbol.section = section;
598
790
  sym->native       = ent;
599
600
790
  *vars->table_ptr = vars->sym_index;
601
790
  *vars->sym_ptr_ptr = sym;
602
603
  /* Adjust pointers for the next symbol.  */
604
790
  vars->sym_index ++;
605
790
  vars->sym_ptr ++;
606
790
  vars->sym_ptr_ptr ++;
607
790
  vars->table_ptr ++;
608
790
  vars->native_ptr ++;
609
790
  vars->esym_ptr ++;
610
790
  vars->string_ptr += len + 1;
611
612
790
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
613
790
}
pei-riscv64.c:pe_ILF_make_a_symbol
Line
Count
Source
544
735
{
545
735
  coff_symbol_type *sym;
546
735
  combined_entry_type *ent;
547
735
  SYMENT *esym;
548
735
  unsigned short sclass;
549
550
735
  if (extra_flags & BSF_LOCAL)
551
401
    sclass = C_STAT;
552
334
  else
553
334
    sclass = C_EXT;
554
555
#ifdef THUMBPEMAGIC
556
  if (vars->magic == THUMBPEMAGIC)
557
    {
558
      if (extra_flags & BSF_FUNCTION)
559
  sclass = C_THUMBEXTFUNC;
560
      else if (extra_flags & BSF_LOCAL)
561
  sclass = C_THUMBSTAT;
562
      else
563
  sclass = C_THUMBEXT;
564
    }
565
#endif
566
567
735
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
568
569
735
  sym = vars->sym_ptr;
570
735
  ent = vars->native_ptr;
571
735
  esym = vars->esym_ptr;
572
573
  /* Copy the symbol's name into the string table.  */
574
735
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
575
576
735
  if (section == NULL)
577
124
    section = bfd_und_section_ptr;
578
579
  /* Initialise the external symbol.  */
580
735
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
581
735
      esym->e.e.e_offset);
582
735
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
583
735
  esym->e_sclass[0] = sclass;
584
585
  /* The following initialisations are unnecessary - the memory is
586
     zero initialised.  They are just kept here as reminders.  */
587
588
  /* Initialise the internal symbol structure.  */
589
735
  ent->u.syment.n_sclass    = sclass;
590
735
  ent->u.syment.n_scnum     = section->target_index;
591
735
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
592
735
  ent->is_sym = true;
593
594
735
  sym->symbol.the_bfd = vars->abfd;
595
735
  sym->symbol.name    = vars->string_ptr;
596
735
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
597
735
  sym->symbol.section = section;
598
735
  sym->native       = ent;
599
600
735
  *vars->table_ptr = vars->sym_index;
601
735
  *vars->sym_ptr_ptr = sym;
602
603
  /* Adjust pointers for the next symbol.  */
604
735
  vars->sym_index ++;
605
735
  vars->sym_ptr ++;
606
735
  vars->sym_ptr_ptr ++;
607
735
  vars->table_ptr ++;
608
735
  vars->native_ptr ++;
609
735
  vars->esym_ptr ++;
610
735
  vars->string_ptr += len + 1;
611
612
735
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
613
735
}
pei-arm-wince.c:pe_ILF_make_a_symbol
Line
Count
Source
544
588
{
545
588
  coff_symbol_type *sym;
546
588
  combined_entry_type *ent;
547
588
  SYMENT *esym;
548
588
  unsigned short sclass;
549
550
588
  if (extra_flags & BSF_LOCAL)
551
329
    sclass = C_STAT;
552
259
  else
553
259
    sclass = C_EXT;
554
555
588
#ifdef THUMBPEMAGIC
556
588
  if (vars->magic == THUMBPEMAGIC)
557
301
    {
558
301
      if (extra_flags & BSF_FUNCTION)
559
24
  sclass = C_THUMBEXTFUNC;
560
277
      else if (extra_flags & BSF_LOCAL)
561
166
  sclass = C_THUMBSTAT;
562
111
      else
563
111
  sclass = C_THUMBEXT;
564
301
    }
565
588
#endif
566
567
588
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
568
569
588
  sym = vars->sym_ptr;
570
588
  ent = vars->native_ptr;
571
588
  esym = vars->esym_ptr;
572
573
  /* Copy the symbol's name into the string table.  */
574
588
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
575
576
588
  if (section == NULL)
577
95
    section = bfd_und_section_ptr;
578
579
  /* Initialise the external symbol.  */
580
588
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
581
588
      esym->e.e.e_offset);
582
588
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
583
588
  esym->e_sclass[0] = sclass;
584
585
  /* The following initialisations are unnecessary - the memory is
586
     zero initialised.  They are just kept here as reminders.  */
587
588
  /* Initialise the internal symbol structure.  */
589
588
  ent->u.syment.n_sclass    = sclass;
590
588
  ent->u.syment.n_scnum     = section->target_index;
591
588
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
592
588
  ent->is_sym = true;
593
594
588
  sym->symbol.the_bfd = vars->abfd;
595
588
  sym->symbol.name    = vars->string_ptr;
596
588
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
597
588
  sym->symbol.section = section;
598
588
  sym->native       = ent;
599
600
588
  *vars->table_ptr = vars->sym_index;
601
588
  *vars->sym_ptr_ptr = sym;
602
603
  /* Adjust pointers for the next symbol.  */
604
588
  vars->sym_index ++;
605
588
  vars->sym_ptr ++;
606
588
  vars->sym_ptr_ptr ++;
607
588
  vars->table_ptr ++;
608
588
  vars->native_ptr ++;
609
588
  vars->esym_ptr ++;
610
588
  vars->string_ptr += len + 1;
611
612
588
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
613
588
}
pei-arm.c:pe_ILF_make_a_symbol
Line
Count
Source
544
600
{
545
600
  coff_symbol_type *sym;
546
600
  combined_entry_type *ent;
547
600
  SYMENT *esym;
548
600
  unsigned short sclass;
549
550
600
  if (extra_flags & BSF_LOCAL)
551
335
    sclass = C_STAT;
552
265
  else
553
265
    sclass = C_EXT;
554
555
600
#ifdef THUMBPEMAGIC
556
600
  if (vars->magic == THUMBPEMAGIC)
557
301
    {
558
301
      if (extra_flags & BSF_FUNCTION)
559
24
  sclass = C_THUMBEXTFUNC;
560
277
      else if (extra_flags & BSF_LOCAL)
561
166
  sclass = C_THUMBSTAT;
562
111
      else
563
111
  sclass = C_THUMBEXT;
564
301
    }
565
600
#endif
566
567
600
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
568
569
600
  sym = vars->sym_ptr;
570
600
  ent = vars->native_ptr;
571
600
  esym = vars->esym_ptr;
572
573
  /* Copy the symbol's name into the string table.  */
574
600
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
575
576
600
  if (section == NULL)
577
97
    section = bfd_und_section_ptr;
578
579
  /* Initialise the external symbol.  */
580
600
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
581
600
      esym->e.e.e_offset);
582
600
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
583
600
  esym->e_sclass[0] = sclass;
584
585
  /* The following initialisations are unnecessary - the memory is
586
     zero initialised.  They are just kept here as reminders.  */
587
588
  /* Initialise the internal symbol structure.  */
589
600
  ent->u.syment.n_sclass    = sclass;
590
600
  ent->u.syment.n_scnum     = section->target_index;
591
600
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
592
600
  ent->is_sym = true;
593
594
600
  sym->symbol.the_bfd = vars->abfd;
595
600
  sym->symbol.name    = vars->string_ptr;
596
600
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
597
600
  sym->symbol.section = section;
598
600
  sym->native       = ent;
599
600
600
  *vars->table_ptr = vars->sym_index;
601
600
  *vars->sym_ptr_ptr = sym;
602
603
  /* Adjust pointers for the next symbol.  */
604
600
  vars->sym_index ++;
605
600
  vars->sym_ptr ++;
606
600
  vars->sym_ptr_ptr ++;
607
600
  vars->table_ptr ++;
608
600
  vars->native_ptr ++;
609
600
  vars->esym_ptr ++;
610
600
  vars->string_ptr += len + 1;
611
612
600
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
613
600
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_symbol
pei-sh.c:pe_ILF_make_a_symbol
Line
Count
Source
544
980
{
545
980
  coff_symbol_type *sym;
546
980
  combined_entry_type *ent;
547
980
  SYMENT *esym;
548
980
  unsigned short sclass;
549
550
980
  if (extra_flags & BSF_LOCAL)
551
545
    sclass = C_STAT;
552
435
  else
553
435
    sclass = C_EXT;
554
555
#ifdef THUMBPEMAGIC
556
  if (vars->magic == THUMBPEMAGIC)
557
    {
558
      if (extra_flags & BSF_FUNCTION)
559
  sclass = C_THUMBEXTFUNC;
560
      else if (extra_flags & BSF_LOCAL)
561
  sclass = C_THUMBSTAT;
562
      else
563
  sclass = C_THUMBEXT;
564
    }
565
#endif
566
567
980
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
568
569
980
  sym = vars->sym_ptr;
570
980
  ent = vars->native_ptr;
571
980
  esym = vars->esym_ptr;
572
573
  /* Copy the symbol's name into the string table.  */
574
980
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
575
576
980
  if (section == NULL)
577
165
    section = bfd_und_section_ptr;
578
579
  /* Initialise the external symbol.  */
580
980
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
581
980
      esym->e.e.e_offset);
582
980
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
583
980
  esym->e_sclass[0] = sclass;
584
585
  /* The following initialisations are unnecessary - the memory is
586
     zero initialised.  They are just kept here as reminders.  */
587
588
  /* Initialise the internal symbol structure.  */
589
980
  ent->u.syment.n_sclass    = sclass;
590
980
  ent->u.syment.n_scnum     = section->target_index;
591
980
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
592
980
  ent->is_sym = true;
593
594
980
  sym->symbol.the_bfd = vars->abfd;
595
980
  sym->symbol.name    = vars->string_ptr;
596
980
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
597
980
  sym->symbol.section = section;
598
980
  sym->native       = ent;
599
600
980
  *vars->table_ptr = vars->sym_index;
601
980
  *vars->sym_ptr_ptr = sym;
602
603
  /* Adjust pointers for the next symbol.  */
604
980
  vars->sym_index ++;
605
980
  vars->sym_ptr ++;
606
980
  vars->sym_ptr_ptr ++;
607
980
  vars->table_ptr ++;
608
980
  vars->native_ptr ++;
609
980
  vars->esym_ptr ++;
610
980
  vars->string_ptr += len + 1;
611
612
980
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
613
980
}
614
615
/* Create a section.  */
616
617
static asection_ptr
618
pe_ILF_make_a_section (pe_ILF_vars * vars,
619
           const char *  name,
620
           unsigned int  size,
621
           flagword      extra_flags)
622
3.36k
{
623
3.36k
  asection_ptr sec;
624
3.36k
  flagword     flags;
625
3.36k
  intptr_t alignment;
626
627
3.36k
  sec = bfd_make_section_old_way (vars->abfd, name);
628
3.36k
  if (sec == NULL)
629
0
    return NULL;
630
631
3.36k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
632
633
3.36k
  bfd_set_section_flags (sec, flags | extra_flags);
634
635
3.36k
  bfd_set_section_alignment (sec, 2);
636
637
  /* Check that we will not run out of space.  */
638
3.36k
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
639
640
  /* Set the section size and contents.  The actual
641
     contents are filled in by our parent.  */
642
3.36k
  bfd_set_section_size (sec, (bfd_size_type) size);
643
3.36k
  sec->contents = vars->data;
644
3.36k
  sec->target_index = vars->sec_index ++;
645
646
  /* Advance data pointer in the vars structure.  */
647
3.36k
  vars->data += size;
648
649
  /* Skip the padding byte if it was not needed.
650
     The logic here is that if the string length is odd,
651
     then the entire string length, including the null byte,
652
     is even and so the extra, padding byte, is not needed.  */
653
3.36k
  if (size & 1)
654
395
    vars->data --;
655
656
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
657
     preserve host alignment requirements.  The BFD_ASSERTs in this
658
     functions will warn us if we run out of room, but we should
659
     already have enough padding built in to ILF_DATA_SIZE.  */
660
3.36k
#if GCC_VERSION >= 3000
661
3.36k
  alignment = __alignof__ (struct coff_section_tdata);
662
#else
663
  alignment = 8;
664
#endif
665
3.36k
  vars->data
666
3.36k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
667
668
  /* Create a coff_section_tdata structure for our use.  */
669
3.36k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
670
3.36k
  vars->data += sizeof (struct coff_section_tdata);
671
672
3.36k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
673
674
  /* Create a symbol to refer to this section.  */
675
3.36k
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
676
677
  /* Cache the index to the symbol in the coff_section_data structure.  */
678
3.36k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
679
680
3.36k
  return sec;
681
3.36k
}
pei-i386.c:pe_ILF_make_a_section
Line
Count
Source
622
450
{
623
450
  asection_ptr sec;
624
450
  flagword     flags;
625
450
  intptr_t alignment;
626
627
450
  sec = bfd_make_section_old_way (vars->abfd, name);
628
450
  if (sec == NULL)
629
0
    return NULL;
630
631
450
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
632
633
450
  bfd_set_section_flags (sec, flags | extra_flags);
634
635
450
  bfd_set_section_alignment (sec, 2);
636
637
  /* Check that we will not run out of space.  */
638
450
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
639
640
  /* Set the section size and contents.  The actual
641
     contents are filled in by our parent.  */
642
450
  bfd_set_section_size (sec, (bfd_size_type) size);
643
450
  sec->contents = vars->data;
644
450
  sec->target_index = vars->sec_index ++;
645
646
  /* Advance data pointer in the vars structure.  */
647
450
  vars->data += size;
648
649
  /* Skip the padding byte if it was not needed.
650
     The logic here is that if the string length is odd,
651
     then the entire string length, including the null byte,
652
     is even and so the extra, padding byte, is not needed.  */
653
450
  if (size & 1)
654
42
    vars->data --;
655
656
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
657
     preserve host alignment requirements.  The BFD_ASSERTs in this
658
     functions will warn us if we run out of room, but we should
659
     already have enough padding built in to ILF_DATA_SIZE.  */
660
450
#if GCC_VERSION >= 3000
661
450
  alignment = __alignof__ (struct coff_section_tdata);
662
#else
663
  alignment = 8;
664
#endif
665
450
  vars->data
666
450
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
667
668
  /* Create a coff_section_tdata structure for our use.  */
669
450
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
670
450
  vars->data += sizeof (struct coff_section_tdata);
671
672
450
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
673
674
  /* Create a symbol to refer to this section.  */
675
450
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
676
677
  /* Cache the index to the symbol in the coff_section_data structure.  */
678
450
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
679
680
450
  return sec;
681
450
}
pei-x86_64.c:pe_ILF_make_a_section
Line
Count
Source
622
449
{
623
449
  asection_ptr sec;
624
449
  flagword     flags;
625
449
  intptr_t alignment;
626
627
449
  sec = bfd_make_section_old_way (vars->abfd, name);
628
449
  if (sec == NULL)
629
0
    return NULL;
630
631
449
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
632
633
449
  bfd_set_section_flags (sec, flags | extra_flags);
634
635
449
  bfd_set_section_alignment (sec, 2);
636
637
  /* Check that we will not run out of space.  */
638
449
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
639
640
  /* Set the section size and contents.  The actual
641
     contents are filled in by our parent.  */
642
449
  bfd_set_section_size (sec, (bfd_size_type) size);
643
449
  sec->contents = vars->data;
644
449
  sec->target_index = vars->sec_index ++;
645
646
  /* Advance data pointer in the vars structure.  */
647
449
  vars->data += size;
648
649
  /* Skip the padding byte if it was not needed.
650
     The logic here is that if the string length is odd,
651
     then the entire string length, including the null byte,
652
     is even and so the extra, padding byte, is not needed.  */
653
449
  if (size & 1)
654
54
    vars->data --;
655
656
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
657
     preserve host alignment requirements.  The BFD_ASSERTs in this
658
     functions will warn us if we run out of room, but we should
659
     already have enough padding built in to ILF_DATA_SIZE.  */
660
449
#if GCC_VERSION >= 3000
661
449
  alignment = __alignof__ (struct coff_section_tdata);
662
#else
663
  alignment = 8;
664
#endif
665
449
  vars->data
666
449
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
667
668
  /* Create a coff_section_tdata structure for our use.  */
669
449
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
670
449
  vars->data += sizeof (struct coff_section_tdata);
671
672
449
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
673
674
  /* Create a symbol to refer to this section.  */
675
449
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
676
677
  /* Cache the index to the symbol in the coff_section_data structure.  */
678
449
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
679
680
449
  return sec;
681
449
}
pei-aarch64.c:pe_ILF_make_a_section
Line
Count
Source
622
412
{
623
412
  asection_ptr sec;
624
412
  flagword     flags;
625
412
  intptr_t alignment;
626
627
412
  sec = bfd_make_section_old_way (vars->abfd, name);
628
412
  if (sec == NULL)
629
0
    return NULL;
630
631
412
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
632
633
412
  bfd_set_section_flags (sec, flags | extra_flags);
634
635
412
  bfd_set_section_alignment (sec, 2);
636
637
  /* Check that we will not run out of space.  */
638
412
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
639
640
  /* Set the section size and contents.  The actual
641
     contents are filled in by our parent.  */
642
412
  bfd_set_section_size (sec, (bfd_size_type) size);
643
412
  sec->contents = vars->data;
644
412
  sec->target_index = vars->sec_index ++;
645
646
  /* Advance data pointer in the vars structure.  */
647
412
  vars->data += size;
648
649
  /* Skip the padding byte if it was not needed.
650
     The logic here is that if the string length is odd,
651
     then the entire string length, including the null byte,
652
     is even and so the extra, padding byte, is not needed.  */
653
412
  if (size & 1)
654
48
    vars->data --;
655
656
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
657
     preserve host alignment requirements.  The BFD_ASSERTs in this
658
     functions will warn us if we run out of room, but we should
659
     already have enough padding built in to ILF_DATA_SIZE.  */
660
412
#if GCC_VERSION >= 3000
661
412
  alignment = __alignof__ (struct coff_section_tdata);
662
#else
663
  alignment = 8;
664
#endif
665
412
  vars->data
666
412
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
667
668
  /* Create a coff_section_tdata structure for our use.  */
669
412
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
670
412
  vars->data += sizeof (struct coff_section_tdata);
671
672
412
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
673
674
  /* Create a symbol to refer to this section.  */
675
412
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
676
677
  /* Cache the index to the symbol in the coff_section_data structure.  */
678
412
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
679
680
412
  return sec;
681
412
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_section
pei-loongarch64.c:pe_ILF_make_a_section
Line
Count
Source
622
442
{
623
442
  asection_ptr sec;
624
442
  flagword     flags;
625
442
  intptr_t alignment;
626
627
442
  sec = bfd_make_section_old_way (vars->abfd, name);
628
442
  if (sec == NULL)
629
0
    return NULL;
630
631
442
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
632
633
442
  bfd_set_section_flags (sec, flags | extra_flags);
634
635
442
  bfd_set_section_alignment (sec, 2);
636
637
  /* Check that we will not run out of space.  */
638
442
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
639
640
  /* Set the section size and contents.  The actual
641
     contents are filled in by our parent.  */
642
442
  bfd_set_section_size (sec, (bfd_size_type) size);
643
442
  sec->contents = vars->data;
644
442
  sec->target_index = vars->sec_index ++;
645
646
  /* Advance data pointer in the vars structure.  */
647
442
  vars->data += size;
648
649
  /* Skip the padding byte if it was not needed.
650
     The logic here is that if the string length is odd,
651
     then the entire string length, including the null byte,
652
     is even and so the extra, padding byte, is not needed.  */
653
442
  if (size & 1)
654
60
    vars->data --;
655
656
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
657
     preserve host alignment requirements.  The BFD_ASSERTs in this
658
     functions will warn us if we run out of room, but we should
659
     already have enough padding built in to ILF_DATA_SIZE.  */
660
442
#if GCC_VERSION >= 3000
661
442
  alignment = __alignof__ (struct coff_section_tdata);
662
#else
663
  alignment = 8;
664
#endif
665
442
  vars->data
666
442
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
667
668
  /* Create a coff_section_tdata structure for our use.  */
669
442
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
670
442
  vars->data += sizeof (struct coff_section_tdata);
671
672
442
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
673
674
  /* Create a symbol to refer to this section.  */
675
442
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
676
677
  /* Cache the index to the symbol in the coff_section_data structure.  */
678
442
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
679
680
442
  return sec;
681
442
}
pei-riscv64.c:pe_ILF_make_a_section
Line
Count
Source
622
401
{
623
401
  asection_ptr sec;
624
401
  flagword     flags;
625
401
  intptr_t alignment;
626
627
401
  sec = bfd_make_section_old_way (vars->abfd, name);
628
401
  if (sec == NULL)
629
0
    return NULL;
630
631
401
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
632
633
401
  bfd_set_section_flags (sec, flags | extra_flags);
634
635
401
  bfd_set_section_alignment (sec, 2);
636
637
  /* Check that we will not run out of space.  */
638
401
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
639
640
  /* Set the section size and contents.  The actual
641
     contents are filled in by our parent.  */
642
401
  bfd_set_section_size (sec, (bfd_size_type) size);
643
401
  sec->contents = vars->data;
644
401
  sec->target_index = vars->sec_index ++;
645
646
  /* Advance data pointer in the vars structure.  */
647
401
  vars->data += size;
648
649
  /* Skip the padding byte if it was not needed.
650
     The logic here is that if the string length is odd,
651
     then the entire string length, including the null byte,
652
     is even and so the extra, padding byte, is not needed.  */
653
401
  if (size & 1)
654
51
    vars->data --;
655
656
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
657
     preserve host alignment requirements.  The BFD_ASSERTs in this
658
     functions will warn us if we run out of room, but we should
659
     already have enough padding built in to ILF_DATA_SIZE.  */
660
401
#if GCC_VERSION >= 3000
661
401
  alignment = __alignof__ (struct coff_section_tdata);
662
#else
663
  alignment = 8;
664
#endif
665
401
  vars->data
666
401
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
667
668
  /* Create a coff_section_tdata structure for our use.  */
669
401
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
670
401
  vars->data += sizeof (struct coff_section_tdata);
671
672
401
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
673
674
  /* Create a symbol to refer to this section.  */
675
401
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
676
677
  /* Cache the index to the symbol in the coff_section_data structure.  */
678
401
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
679
680
401
  return sec;
681
401
}
pei-arm-wince.c:pe_ILF_make_a_section
Line
Count
Source
622
329
{
623
329
  asection_ptr sec;
624
329
  flagword     flags;
625
329
  intptr_t alignment;
626
627
329
  sec = bfd_make_section_old_way (vars->abfd, name);
628
329
  if (sec == NULL)
629
0
    return NULL;
630
631
329
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
632
633
329
  bfd_set_section_flags (sec, flags | extra_flags);
634
635
329
  bfd_set_section_alignment (sec, 2);
636
637
  /* Check that we will not run out of space.  */
638
329
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
639
640
  /* Set the section size and contents.  The actual
641
     contents are filled in by our parent.  */
642
329
  bfd_set_section_size (sec, (bfd_size_type) size);
643
329
  sec->contents = vars->data;
644
329
  sec->target_index = vars->sec_index ++;
645
646
  /* Advance data pointer in the vars structure.  */
647
329
  vars->data += size;
648
649
  /* Skip the padding byte if it was not needed.
650
     The logic here is that if the string length is odd,
651
     then the entire string length, including the null byte,
652
     is even and so the extra, padding byte, is not needed.  */
653
329
  if (size & 1)
654
38
    vars->data --;
655
656
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
657
     preserve host alignment requirements.  The BFD_ASSERTs in this
658
     functions will warn us if we run out of room, but we should
659
     already have enough padding built in to ILF_DATA_SIZE.  */
660
329
#if GCC_VERSION >= 3000
661
329
  alignment = __alignof__ (struct coff_section_tdata);
662
#else
663
  alignment = 8;
664
#endif
665
329
  vars->data
666
329
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
667
668
  /* Create a coff_section_tdata structure for our use.  */
669
329
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
670
329
  vars->data += sizeof (struct coff_section_tdata);
671
672
329
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
673
674
  /* Create a symbol to refer to this section.  */
675
329
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
676
677
  /* Cache the index to the symbol in the coff_section_data structure.  */
678
329
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
679
680
329
  return sec;
681
329
}
pei-arm.c:pe_ILF_make_a_section
Line
Count
Source
622
335
{
623
335
  asection_ptr sec;
624
335
  flagword     flags;
625
335
  intptr_t alignment;
626
627
335
  sec = bfd_make_section_old_way (vars->abfd, name);
628
335
  if (sec == NULL)
629
0
    return NULL;
630
631
335
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
632
633
335
  bfd_set_section_flags (sec, flags | extra_flags);
634
635
335
  bfd_set_section_alignment (sec, 2);
636
637
  /* Check that we will not run out of space.  */
638
335
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
639
640
  /* Set the section size and contents.  The actual
641
     contents are filled in by our parent.  */
642
335
  bfd_set_section_size (sec, (bfd_size_type) size);
643
335
  sec->contents = vars->data;
644
335
  sec->target_index = vars->sec_index ++;
645
646
  /* Advance data pointer in the vars structure.  */
647
335
  vars->data += size;
648
649
  /* Skip the padding byte if it was not needed.
650
     The logic here is that if the string length is odd,
651
     then the entire string length, including the null byte,
652
     is even and so the extra, padding byte, is not needed.  */
653
335
  if (size & 1)
654
38
    vars->data --;
655
656
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
657
     preserve host alignment requirements.  The BFD_ASSERTs in this
658
     functions will warn us if we run out of room, but we should
659
     already have enough padding built in to ILF_DATA_SIZE.  */
660
335
#if GCC_VERSION >= 3000
661
335
  alignment = __alignof__ (struct coff_section_tdata);
662
#else
663
  alignment = 8;
664
#endif
665
335
  vars->data
666
335
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
667
668
  /* Create a coff_section_tdata structure for our use.  */
669
335
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
670
335
  vars->data += sizeof (struct coff_section_tdata);
671
672
335
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
673
674
  /* Create a symbol to refer to this section.  */
675
335
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
676
677
  /* Cache the index to the symbol in the coff_section_data structure.  */
678
335
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
679
680
335
  return sec;
681
335
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_section
pei-sh.c:pe_ILF_make_a_section
Line
Count
Source
622
545
{
623
545
  asection_ptr sec;
624
545
  flagword     flags;
625
545
  intptr_t alignment;
626
627
545
  sec = bfd_make_section_old_way (vars->abfd, name);
628
545
  if (sec == NULL)
629
0
    return NULL;
630
631
545
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
632
633
545
  bfd_set_section_flags (sec, flags | extra_flags);
634
635
545
  bfd_set_section_alignment (sec, 2);
636
637
  /* Check that we will not run out of space.  */
638
545
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
639
640
  /* Set the section size and contents.  The actual
641
     contents are filled in by our parent.  */
642
545
  bfd_set_section_size (sec, (bfd_size_type) size);
643
545
  sec->contents = vars->data;
644
545
  sec->target_index = vars->sec_index ++;
645
646
  /* Advance data pointer in the vars structure.  */
647
545
  vars->data += size;
648
649
  /* Skip the padding byte if it was not needed.
650
     The logic here is that if the string length is odd,
651
     then the entire string length, including the null byte,
652
     is even and so the extra, padding byte, is not needed.  */
653
545
  if (size & 1)
654
64
    vars->data --;
655
656
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
657
     preserve host alignment requirements.  The BFD_ASSERTs in this
658
     functions will warn us if we run out of room, but we should
659
     already have enough padding built in to ILF_DATA_SIZE.  */
660
545
#if GCC_VERSION >= 3000
661
545
  alignment = __alignof__ (struct coff_section_tdata);
662
#else
663
  alignment = 8;
664
#endif
665
545
  vars->data
666
545
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
667
668
  /* Create a coff_section_tdata structure for our use.  */
669
545
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
670
545
  vars->data += sizeof (struct coff_section_tdata);
671
672
545
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
673
674
  /* Create a symbol to refer to this section.  */
675
545
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
676
677
  /* Cache the index to the symbol in the coff_section_data structure.  */
678
545
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
679
680
545
  return sec;
681
545
}
682
683
/* This structure contains the code that goes into the .text section
684
   in order to perform a jump into the DLL lookup table.  The entries
685
   in the table are index by the magic number used to represent the
686
   machine type in the PE file.  The contents of the data[] arrays in
687
   these entries are stolen from the jtab[] arrays in ld/pe-dll.c.
688
   The SIZE field says how many bytes in the DATA array are actually
689
   used.  The OFFSET field says where in the data array the address
690
   of the .idata$5 section should be placed.  */
691
2.16k
#define MAX_TEXT_SECTION_SIZE 32
692
693
typedef struct
694
{
695
  unsigned short magic;
696
  unsigned char  data[MAX_TEXT_SECTION_SIZE];
697
  unsigned int   size;
698
  unsigned int   offset;
699
}
700
jump_table;
701
702
static const jump_table jtab[] =
703
{
704
#ifdef I386MAGIC
705
  { I386MAGIC,
706
    { 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, 0x90, 0x90 },
707
    8, 2
708
  },
709
#endif
710
711
#ifdef AMD64MAGIC
712
  { AMD64MAGIC,
713
    { 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, 0x90, 0x90 },
714
    8, 2
715
  },
716
#endif
717
718
#ifdef  MC68MAGIC
719
  { MC68MAGIC,
720
    { /* XXX fill me in */ },
721
    0, 0
722
  },
723
#endif
724
725
#ifdef  MIPS_ARCH_MAGIC_WINCE
726
  { MIPS_ARCH_MAGIC_WINCE,
727
    { 0x00, 0x00, 0x08, 0x3c, 0x00, 0x00, 0x08, 0x8d,
728
      0x08, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00 },
729
    16, 0
730
  },
731
#endif
732
733
#ifdef  SH_ARCH_MAGIC_WINCE
734
  { SH_ARCH_MAGIC_WINCE,
735
    { 0x01, 0xd0, 0x02, 0x60, 0x2b, 0x40,
736
      0x09, 0x00, 0x00, 0x00, 0x00, 0x00 },
737
    12, 8
738
  },
739
#endif
740
741
#ifdef AARCH64MAGIC
742
/* We don't currently support jumping to DLLs, so if
743
   someone does try emit a runtime trap.  Through UDF #0.  */
744
  { AARCH64MAGIC,
745
    { 0x00, 0x00, 0x00, 0x00 },
746
    4, 0
747
  },
748
749
#endif
750
751
#ifdef  ARMPEMAGIC
752
  { ARMPEMAGIC,
753
    { 0x00, 0xc0, 0x9f, 0xe5, 0x00, 0xf0,
754
      0x9c, 0xe5, 0x00, 0x00, 0x00, 0x00},
755
    12, 8
756
  },
757
#endif
758
759
#ifdef  THUMBPEMAGIC
760
  { THUMBPEMAGIC,
761
    { 0x40, 0xb4, 0x02, 0x4e, 0x36, 0x68, 0xb4, 0x46,
762
      0x40, 0xbc, 0x60, 0x47, 0x00, 0x00, 0x00, 0x00 },
763
    16, 12
764
  },
765
#endif
766
767
#ifdef LOONGARCH64MAGIC
768
/* We don't currently support jumping to DLLs, so if
769
   someone does try emit a runtime trap.  Through BREAK 0.  */
770
  { LOONGARCH64MAGIC,
771
    { 0x00, 0x00, 0x2a, 0x00 },
772
    4, 0
773
  },
774
775
#endif
776
777
#ifdef RISCV64MAGIC
778
  /* We don't currently support jumping to DLLs, so if
779
     someone does try emit a runtime trap.  Through EBREAK.  */
780
  { RISCV64MAGIC,
781
    { 0x73, 0x00, 0x10, 0x00 },
782
    4, 0
783
  },
784
785
#endif
786
787
  { 0, { 0 }, 0, 0 }
788
};
789
790
#ifndef NUM_ENTRIES
791
436
#define NUM_ENTRIES(a) (sizeof (a) / sizeof (a)[0])
792
#endif
793
794
/* Build a full BFD from the information supplied in a ILF object.  */
795
796
static bool
797
pe_ILF_build_a_bfd (bfd *     abfd,
798
        unsigned int    magic,
799
        char *      symbol_name,
800
        char *      source_dll,
801
        unsigned int    ordinal,
802
        unsigned int    types,
803
        char *      import_name)
804
1.39k
{
805
1.39k
  bfd_byte *       ptr;
806
1.39k
  pe_ILF_vars      vars;
807
1.39k
  struct internal_filehdr  internal_f;
808
1.39k
  unsigned int       import_type;
809
1.39k
  unsigned int       import_name_type;
810
1.39k
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
811
1.39k
  coff_symbol_type **    imp_sym;
812
1.39k
  unsigned int       imp_index;
813
1.39k
  intptr_t alignment;
814
815
  /* Decode and verify the types field of the ILF structure.  */
816
1.39k
  import_type = types & 0x3;
817
1.39k
  import_name_type = (types & 0x1c) >> 2;
818
819
1.39k
  switch (import_type)
820
1.39k
    {
821
590
    case IMPORT_CODE:
822
990
    case IMPORT_DATA:
823
1.29k
    case IMPORT_CONST:
824
1.29k
      break;
825
826
99
    default:
827
      /* xgettext:c-format */
828
99
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
99
        abfd, import_type);
830
99
      return false;
831
1.39k
    }
832
833
1.29k
  switch (import_name_type)
834
1.29k
    {
835
313
    case IMPORT_ORDINAL:
836
441
    case IMPORT_NAME:
837
641
    case IMPORT_NAME_NOPREFIX:
838
982
    case IMPORT_NAME_UNDECORATE:
839
982
      import_name = symbol_name;
840
982
      break;
841
842
240
    case IMPORT_NAME_EXPORTAS:
843
240
      if (!import_name || !import_name[0])
844
142
  {
845
142
    _bfd_error_handler (_("%pB: missing import name for "
846
142
        "IMPORT_NAME_EXPORTAS for %s"),
847
142
            abfd, symbol_name);
848
142
    return false;
849
142
  }
850
98
      break;
851
852
98
    default:
853
      /* xgettext:c-format */
854
73
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
855
73
        abfd, import_name_type);
856
73
      return false;
857
1.29k
    }
858
859
  /* Initialise local variables.
860
861
     Note these are kept in a structure rather than being
862
     declared as statics since bfd frowns on global variables.
863
864
     We are going to construct the contents of the BFD in memory,
865
     so allocate all the space that we will need right now.  */
866
1.08k
  vars.bim
867
1.08k
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
868
1.08k
  if (vars.bim == NULL)
869
0
    return false;
870
871
1.08k
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
872
1.08k
  vars.bim->buffer = ptr;
873
1.08k
  vars.bim->size   = ILF_DATA_SIZE;
874
1.08k
  if (ptr == NULL)
875
0
    goto error_return;
876
877
  /* Initialise the pointers to regions of the memory and the
878
     other contents of the pe_ILF_vars structure as well.  */
879
1.08k
  vars.sym_cache = (coff_symbol_type *) ptr;
880
1.08k
  vars.sym_ptr   = (coff_symbol_type *) ptr;
881
1.08k
  vars.sym_index = 0;
882
1.08k
  ptr += SIZEOF_ILF_SYMS;
883
884
1.08k
  vars.sym_table = (unsigned int *) ptr;
885
1.08k
  vars.table_ptr = (unsigned int *) ptr;
886
1.08k
  ptr += SIZEOF_ILF_SYM_TABLE;
887
888
1.08k
  vars.native_syms = (combined_entry_type *) ptr;
889
1.08k
  vars.native_ptr  = (combined_entry_type *) ptr;
890
1.08k
  ptr += SIZEOF_ILF_NATIVE_SYMS;
891
892
1.08k
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
893
1.08k
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
894
1.08k
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
895
896
1.08k
  vars.esym_table = (SYMENT *) ptr;
897
1.08k
  vars.esym_ptr   = (SYMENT *) ptr;
898
1.08k
  ptr += SIZEOF_ILF_EXT_SYMS;
899
900
1.08k
  vars.reltab   = (arelent *) ptr;
901
1.08k
  vars.relcount = 0;
902
1.08k
  ptr += SIZEOF_ILF_RELOCS;
903
904
1.08k
  vars.int_reltab  = (struct internal_reloc *) ptr;
905
1.08k
  ptr += SIZEOF_ILF_INT_RELOCS;
906
907
1.08k
  vars.string_table = (char *) ptr;
908
1.08k
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
909
1.08k
  ptr += SIZEOF_ILF_STRINGS;
910
1.08k
  vars.end_string_ptr = (char *) ptr;
911
912
  /* The remaining space in bim->buffer is used
913
     by the pe_ILF_make_a_section() function.  */
914
915
  /* PR 18758: Make sure that the data area is sufficiently aligned for
916
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
917
     the test of GCC_VERSION.  For other compilers we assume 8 byte
918
     alignment.  */
919
1.08k
#if GCC_VERSION >= 3000
920
1.08k
  alignment = __alignof__ (struct coff_section_tdata);
921
#else
922
  alignment = 8;
923
#endif
924
1.08k
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
925
926
1.08k
  vars.data = ptr;
927
1.08k
  vars.abfd = abfd;
928
1.08k
  vars.sec_index = 0;
929
1.08k
  vars.magic = magic;
930
931
  /* Create the initial .idata$<n> sections:
932
     [.idata$2:  Import Directory Table -- not needed]
933
     .idata$4:  Import Lookup Table
934
     .idata$5:  Import Address Table
935
936
     Note we do not create a .idata$3 section as this is
937
     created for us by the linker script.  */
938
1.08k
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
939
1.08k
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
940
1.08k
  if (id4 == NULL || id5 == NULL)
941
0
    goto error_return;
942
943
  /* Fill in the contents of these sections.  */
944
1.08k
  if (import_name_type == IMPORT_ORDINAL)
945
313
    {
946
313
      if (ordinal == 0)
947
  /* See PR 20907 for a reproducer.  */
948
78
  goto error_return;
949
950
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
951
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
952
121
      ((unsigned int *) id4->contents)[0] = ordinal;
953
121
      ((unsigned int *) id4->contents)[1] = 0x80000000;
954
121
      ((unsigned int *) id5->contents)[0] = ordinal;
955
121
      ((unsigned int *) id5->contents)[1] = 0x80000000;
956
#else
957
114
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
958
114
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
959
114
#endif
960
114
    }
961
767
  else
962
767
    {
963
767
      char *symbol;
964
767
      unsigned int len;
965
966
      /* Create .idata$6 - the Hint Name Table.  */
967
767
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
968
767
      if (id6 == NULL)
969
0
  goto error_return;
970
971
      /* If necessary, trim the import symbol name.  */
972
767
      symbol = import_name;
973
974
      /* As used by MS compiler, '_', '@', and '?' are alternative
975
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
976
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
977
   of these is used for a symbol.  We strip this leading char for
978
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
979
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
980
981
767
      if (import_name_type != IMPORT_NAME
982
639
    && import_name_type != IMPORT_NAME_EXPORTAS)
983
541
  {
984
541
    char c = symbol[0];
985
986
    /* Check that we don't remove for targets with empty
987
       USER_LABEL_PREFIX the leading underscore.  */
988
541
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
989
511
        || c == '@' || c == '?')
990
167
      symbol++;
991
541
  }
992
993
767
      len = strlen (symbol);
994
767
      if (import_name_type == IMPORT_NAME_UNDECORATE)
995
341
  {
996
    /* Truncate at the first '@'.  */
997
341
    char *at = strchr (symbol, '@');
998
999
341
    if (at != NULL)
1000
85
      len = at - symbol;
1001
341
  }
1002
1003
767
      id6->contents[0] = ordinal & 0xff;
1004
767
      id6->contents[1] = ordinal >> 8;
1005
1006
767
      memcpy ((char *) id6->contents + 2, symbol, len);
1007
767
      id6->contents[len + 2] = '\0';
1008
767
    }
1009
1010
1.00k
  if (import_name_type != IMPORT_ORDINAL)
1011
767
    {
1012
767
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1013
767
      pe_ILF_save_relocs (&vars, id4);
1014
1015
767
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1016
767
      pe_ILF_save_relocs (&vars, id5);
1017
767
    }
1018
1019
  /* Create an import symbol.  */
1020
1.00k
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1021
1.00k
  imp_sym   = vars.sym_ptr_ptr - 1;
1022
1.00k
  imp_index = vars.sym_index - 1;
1023
1024
  /* Create extra sections depending upon the type of import we are
1025
     dealing with.  */
1026
1.00k
  switch (import_type)
1027
1.00k
    {
1028
0
      int i;
1029
1030
436
    case IMPORT_CODE:
1031
      /* CODE functions are special, in that they get a trampoline that
1032
   jumps to the main import symbol.  Create a .text section to hold it.
1033
   First we need to look up its contents in the jump table.  */
1034
923
      for (i = NUM_ENTRIES (jtab); i--;)
1035
923
  {
1036
923
    if (jtab[i].size == 0)
1037
436
      continue;
1038
487
    if (jtab[i].magic == magic)
1039
436
      break;
1040
487
  }
1041
      /* If we did not find a matching entry something is wrong.  */
1042
436
      if (i < 0)
1043
0
  abort ();
1044
1045
      /* Create the .text section.  */
1046
436
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1047
436
      if (text == NULL)
1048
0
  goto error_return;
1049
1050
      /* Copy in the jump code.  */
1051
436
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1052
1053
      /* Create a reloc for the data in the text section.  */
1054
#ifdef MIPS_ARCH_MAGIC_WINCE
1055
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1056
  {
1057
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1058
              (struct bfd_symbol **) imp_sym,
1059
              imp_index);
1060
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1061
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1062
              (struct bfd_symbol **) imp_sym,
1063
              imp_index);
1064
  }
1065
      else
1066
#endif
1067
#ifdef AMD64MAGIC
1068
55
      if (magic == AMD64MAGIC)
1069
55
  {
1070
55
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1071
55
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1072
55
              imp_index);
1073
55
  }
1074
0
      else
1075
0
#endif
1076
0
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1077
0
            BFD_RELOC_32, (asymbol **) imp_sym,
1078
0
            imp_index);
1079
1080
436
      pe_ILF_save_relocs (&vars, text);
1081
436
      break;
1082
1083
315
    case IMPORT_DATA:
1084
566
    case IMPORT_CONST:
1085
566
      break;
1086
1087
0
    default:
1088
      /* XXX code not yet written.  */
1089
0
      abort ();
1090
1.00k
    }
1091
1092
  /* Now create a symbol describing the imported value.  */
1093
1.00k
  switch (import_type)
1094
1.00k
    {
1095
436
    case IMPORT_CODE:
1096
436
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1097
436
          BSF_NOT_AT_END | BSF_FUNCTION);
1098
1099
436
      break;
1100
1101
315
    case IMPORT_DATA:
1102
      /* Nothing to do here.  */
1103
315
      break;
1104
1105
251
    case IMPORT_CONST:
1106
251
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1107
251
      break;
1108
1109
0
    default:
1110
      /* XXX code not yet written.  */
1111
0
      abort ();
1112
1.00k
    }
1113
1114
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1115
1.00k
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1116
1.00k
  if (ptr)
1117
128
    *ptr = 0;
1118
1.00k
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1119
1.00k
  if (ptr)
1120
128
    *ptr = '.';
1121
1122
  /* Initialise the bfd.  */
1123
1.00k
  memset (&internal_f, 0, sizeof (internal_f));
1124
1125
1.00k
  internal_f.f_magic  = magic;
1126
1.00k
  internal_f.f_symptr = 0;
1127
1.00k
  internal_f.f_nsyms  = 0;
1128
1.00k
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1129
1130
1.00k
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1131
1.00k
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1132
0
    goto error_return;
1133
1134
1.00k
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1135
0
    goto error_return;
1136
1137
1.00k
  obj_pe (abfd) = true;
1138
#ifdef THUMBPEMAGIC
1139
192
  if (vars.magic == THUMBPEMAGIC)
1140
    /* Stop some linker warnings about thumb code not supporting
1141
       interworking.  */
1142
100
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1143
#endif
1144
1145
  /* Switch from file contents to memory contents.  */
1146
1.00k
  bfd_cache_close (abfd);
1147
1148
1.00k
  abfd->iostream = (void *) vars.bim;
1149
1.00k
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1150
1.00k
  abfd->iovec = &_bfd_memory_iovec;
1151
1.00k
  abfd->where = 0;
1152
1.00k
  abfd->origin = 0;
1153
1.00k
  abfd->size = 0;
1154
1.00k
  obj_sym_filepos (abfd) = 0;
1155
1156
  /* Point the bfd at the symbol table.  */
1157
1.00k
  obj_symbols (abfd) = vars.sym_cache;
1158
1.00k
  abfd->symcount = vars.sym_index;
1159
1160
1.00k
  obj_raw_syments (abfd) = vars.native_syms;
1161
1.00k
  obj_raw_syment_count (abfd) = vars.sym_index;
1162
1.00k
  obj_coff_keep_raw_syms (abfd) = true;
1163
1164
1.00k
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1165
1.00k
  obj_coff_keep_syms (abfd) = true;
1166
1167
1.00k
  obj_convert (abfd) = vars.sym_table;
1168
1.00k
  obj_conv_table_size (abfd) = vars.sym_index;
1169
1170
1.00k
  obj_coff_strings (abfd) = vars.string_table;
1171
1.00k
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1172
1.00k
  obj_coff_keep_strings (abfd) = true;
1173
1174
1.00k
  return true;
1175
1176
78
 error_return:
1177
78
  free (vars.bim->buffer);
1178
78
  free (vars.bim);
1179
78
  return false;
1180
1.00k
}
pei-i386.c:pe_ILF_build_a_bfd
Line
Count
Source
804
172
{
805
172
  bfd_byte *       ptr;
806
172
  pe_ILF_vars      vars;
807
172
  struct internal_filehdr  internal_f;
808
172
  unsigned int       import_type;
809
172
  unsigned int       import_name_type;
810
172
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
811
172
  coff_symbol_type **    imp_sym;
812
172
  unsigned int       imp_index;
813
172
  intptr_t alignment;
814
815
  /* Decode and verify the types field of the ILF structure.  */
816
172
  import_type = types & 0x3;
817
172
  import_name_type = (types & 0x1c) >> 2;
818
819
172
  switch (import_type)
820
172
    {
821
97
    case IMPORT_CODE:
822
127
    case IMPORT_DATA:
823
164
    case IMPORT_CONST:
824
164
      break;
825
826
8
    default:
827
      /* xgettext:c-format */
828
8
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
8
        abfd, import_type);
830
8
      return false;
831
172
    }
832
833
164
  switch (import_name_type)
834
164
    {
835
40
    case IMPORT_ORDINAL:
836
61
    case IMPORT_NAME:
837
92
    case IMPORT_NAME_NOPREFIX:
838
129
    case IMPORT_NAME_UNDECORATE:
839
129
      import_name = symbol_name;
840
129
      break;
841
842
27
    case IMPORT_NAME_EXPORTAS:
843
27
      if (!import_name || !import_name[0])
844
17
  {
845
17
    _bfd_error_handler (_("%pB: missing import name for "
846
17
        "IMPORT_NAME_EXPORTAS for %s"),
847
17
            abfd, symbol_name);
848
17
    return false;
849
17
  }
850
10
      break;
851
852
10
    default:
853
      /* xgettext:c-format */
854
8
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
855
8
        abfd, import_name_type);
856
8
      return false;
857
164
    }
858
859
  /* Initialise local variables.
860
861
     Note these are kept in a structure rather than being
862
     declared as statics since bfd frowns on global variables.
863
864
     We are going to construct the contents of the BFD in memory,
865
     so allocate all the space that we will need right now.  */
866
139
  vars.bim
867
139
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
868
139
  if (vars.bim == NULL)
869
0
    return false;
870
871
139
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
872
139
  vars.bim->buffer = ptr;
873
139
  vars.bim->size   = ILF_DATA_SIZE;
874
139
  if (ptr == NULL)
875
0
    goto error_return;
876
877
  /* Initialise the pointers to regions of the memory and the
878
     other contents of the pe_ILF_vars structure as well.  */
879
139
  vars.sym_cache = (coff_symbol_type *) ptr;
880
139
  vars.sym_ptr   = (coff_symbol_type *) ptr;
881
139
  vars.sym_index = 0;
882
139
  ptr += SIZEOF_ILF_SYMS;
883
884
139
  vars.sym_table = (unsigned int *) ptr;
885
139
  vars.table_ptr = (unsigned int *) ptr;
886
139
  ptr += SIZEOF_ILF_SYM_TABLE;
887
888
139
  vars.native_syms = (combined_entry_type *) ptr;
889
139
  vars.native_ptr  = (combined_entry_type *) ptr;
890
139
  ptr += SIZEOF_ILF_NATIVE_SYMS;
891
892
139
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
893
139
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
894
139
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
895
896
139
  vars.esym_table = (SYMENT *) ptr;
897
139
  vars.esym_ptr   = (SYMENT *) ptr;
898
139
  ptr += SIZEOF_ILF_EXT_SYMS;
899
900
139
  vars.reltab   = (arelent *) ptr;
901
139
  vars.relcount = 0;
902
139
  ptr += SIZEOF_ILF_RELOCS;
903
904
139
  vars.int_reltab  = (struct internal_reloc *) ptr;
905
139
  ptr += SIZEOF_ILF_INT_RELOCS;
906
907
139
  vars.string_table = (char *) ptr;
908
139
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
909
139
  ptr += SIZEOF_ILF_STRINGS;
910
139
  vars.end_string_ptr = (char *) ptr;
911
912
  /* The remaining space in bim->buffer is used
913
     by the pe_ILF_make_a_section() function.  */
914
915
  /* PR 18758: Make sure that the data area is sufficiently aligned for
916
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
917
     the test of GCC_VERSION.  For other compilers we assume 8 byte
918
     alignment.  */
919
139
#if GCC_VERSION >= 3000
920
139
  alignment = __alignof__ (struct coff_section_tdata);
921
#else
922
  alignment = 8;
923
#endif
924
139
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
925
926
139
  vars.data = ptr;
927
139
  vars.abfd = abfd;
928
139
  vars.sec_index = 0;
929
139
  vars.magic = magic;
930
931
  /* Create the initial .idata$<n> sections:
932
     [.idata$2:  Import Directory Table -- not needed]
933
     .idata$4:  Import Lookup Table
934
     .idata$5:  Import Address Table
935
936
     Note we do not create a .idata$3 section as this is
937
     created for us by the linker script.  */
938
139
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
939
139
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
940
139
  if (id4 == NULL || id5 == NULL)
941
0
    goto error_return;
942
943
  /* Fill in the contents of these sections.  */
944
139
  if (import_name_type == IMPORT_ORDINAL)
945
40
    {
946
40
      if (ordinal == 0)
947
  /* See PR 20907 for a reproducer.  */
948
11
  goto error_return;
949
950
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
951
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
952
      ((unsigned int *) id4->contents)[0] = ordinal;
953
      ((unsigned int *) id4->contents)[1] = 0x80000000;
954
      ((unsigned int *) id5->contents)[0] = ordinal;
955
      ((unsigned int *) id5->contents)[1] = 0x80000000;
956
#else
957
29
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
958
29
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
959
29
#endif
960
29
    }
961
99
  else
962
99
    {
963
99
      char *symbol;
964
99
      unsigned int len;
965
966
      /* Create .idata$6 - the Hint Name Table.  */
967
99
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
968
99
      if (id6 == NULL)
969
0
  goto error_return;
970
971
      /* If necessary, trim the import symbol name.  */
972
99
      symbol = import_name;
973
974
      /* As used by MS compiler, '_', '@', and '?' are alternative
975
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
976
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
977
   of these is used for a symbol.  We strip this leading char for
978
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
979
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
980
981
99
      if (import_name_type != IMPORT_NAME
982
78
    && import_name_type != IMPORT_NAME_EXPORTAS)
983
68
  {
984
68
    char c = symbol[0];
985
986
    /* Check that we don't remove for targets with empty
987
       USER_LABEL_PREFIX the leading underscore.  */
988
68
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
989
58
        || c == '@' || c == '?')
990
30
      symbol++;
991
68
  }
992
993
99
      len = strlen (symbol);
994
99
      if (import_name_type == IMPORT_NAME_UNDECORATE)
995
37
  {
996
    /* Truncate at the first '@'.  */
997
37
    char *at = strchr (symbol, '@');
998
999
37
    if (at != NULL)
1000
7
      len = at - symbol;
1001
37
  }
1002
1003
99
      id6->contents[0] = ordinal & 0xff;
1004
99
      id6->contents[1] = ordinal >> 8;
1005
1006
99
      memcpy ((char *) id6->contents + 2, symbol, len);
1007
99
      id6->contents[len + 2] = '\0';
1008
99
    }
1009
1010
128
  if (import_name_type != IMPORT_ORDINAL)
1011
99
    {
1012
99
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1013
99
      pe_ILF_save_relocs (&vars, id4);
1014
1015
99
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1016
99
      pe_ILF_save_relocs (&vars, id5);
1017
99
    }
1018
1019
  /* Create an import symbol.  */
1020
128
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1021
128
  imp_sym   = vars.sym_ptr_ptr - 1;
1022
128
  imp_index = vars.sym_index - 1;
1023
1024
  /* Create extra sections depending upon the type of import we are
1025
     dealing with.  */
1026
128
  switch (import_type)
1027
128
    {
1028
0
      int i;
1029
1030
73
    case IMPORT_CODE:
1031
      /* CODE functions are special, in that they get a trampoline that
1032
   jumps to the main import symbol.  Create a .text section to hold it.
1033
   First we need to look up its contents in the jump table.  */
1034
146
      for (i = NUM_ENTRIES (jtab); i--;)
1035
146
  {
1036
146
    if (jtab[i].size == 0)
1037
73
      continue;
1038
73
    if (jtab[i].magic == magic)
1039
73
      break;
1040
73
  }
1041
      /* If we did not find a matching entry something is wrong.  */
1042
73
      if (i < 0)
1043
0
  abort ();
1044
1045
      /* Create the .text section.  */
1046
73
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1047
73
      if (text == NULL)
1048
0
  goto error_return;
1049
1050
      /* Copy in the jump code.  */
1051
73
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1052
1053
      /* Create a reloc for the data in the text section.  */
1054
#ifdef MIPS_ARCH_MAGIC_WINCE
1055
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1056
  {
1057
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1058
              (struct bfd_symbol **) imp_sym,
1059
              imp_index);
1060
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1061
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1062
              (struct bfd_symbol **) imp_sym,
1063
              imp_index);
1064
  }
1065
      else
1066
#endif
1067
#ifdef AMD64MAGIC
1068
      if (magic == AMD64MAGIC)
1069
  {
1070
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1071
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1072
              imp_index);
1073
  }
1074
      else
1075
#endif
1076
73
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1077
73
            BFD_RELOC_32, (asymbol **) imp_sym,
1078
73
            imp_index);
1079
1080
73
      pe_ILF_save_relocs (&vars, text);
1081
73
      break;
1082
1083
24
    case IMPORT_DATA:
1084
55
    case IMPORT_CONST:
1085
55
      break;
1086
1087
0
    default:
1088
      /* XXX code not yet written.  */
1089
0
      abort ();
1090
128
    }
1091
1092
  /* Now create a symbol describing the imported value.  */
1093
128
  switch (import_type)
1094
128
    {
1095
73
    case IMPORT_CODE:
1096
73
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1097
73
          BSF_NOT_AT_END | BSF_FUNCTION);
1098
1099
73
      break;
1100
1101
24
    case IMPORT_DATA:
1102
      /* Nothing to do here.  */
1103
24
      break;
1104
1105
31
    case IMPORT_CONST:
1106
31
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1107
31
      break;
1108
1109
0
    default:
1110
      /* XXX code not yet written.  */
1111
0
      abort ();
1112
128
    }
1113
1114
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1115
128
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1116
128
  if (ptr)
1117
18
    *ptr = 0;
1118
128
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1119
128
  if (ptr)
1120
18
    *ptr = '.';
1121
1122
  /* Initialise the bfd.  */
1123
128
  memset (&internal_f, 0, sizeof (internal_f));
1124
1125
128
  internal_f.f_magic  = magic;
1126
128
  internal_f.f_symptr = 0;
1127
128
  internal_f.f_nsyms  = 0;
1128
128
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1129
1130
128
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1131
128
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1132
0
    goto error_return;
1133
1134
128
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1135
0
    goto error_return;
1136
1137
128
  obj_pe (abfd) = true;
1138
#ifdef THUMBPEMAGIC
1139
  if (vars.magic == THUMBPEMAGIC)
1140
    /* Stop some linker warnings about thumb code not supporting
1141
       interworking.  */
1142
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1143
#endif
1144
1145
  /* Switch from file contents to memory contents.  */
1146
128
  bfd_cache_close (abfd);
1147
1148
128
  abfd->iostream = (void *) vars.bim;
1149
128
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1150
128
  abfd->iovec = &_bfd_memory_iovec;
1151
128
  abfd->where = 0;
1152
128
  abfd->origin = 0;
1153
128
  abfd->size = 0;
1154
128
  obj_sym_filepos (abfd) = 0;
1155
1156
  /* Point the bfd at the symbol table.  */
1157
128
  obj_symbols (abfd) = vars.sym_cache;
1158
128
  abfd->symcount = vars.sym_index;
1159
1160
128
  obj_raw_syments (abfd) = vars.native_syms;
1161
128
  obj_raw_syment_count (abfd) = vars.sym_index;
1162
128
  obj_coff_keep_raw_syms (abfd) = true;
1163
1164
128
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1165
128
  obj_coff_keep_syms (abfd) = true;
1166
1167
128
  obj_convert (abfd) = vars.sym_table;
1168
128
  obj_conv_table_size (abfd) = vars.sym_index;
1169
1170
128
  obj_coff_strings (abfd) = vars.string_table;
1171
128
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1172
128
  obj_coff_keep_strings (abfd) = true;
1173
1174
128
  return true;
1175
1176
11
 error_return:
1177
11
  free (vars.bim->buffer);
1178
11
  free (vars.bim);
1179
  return false;
1180
128
}
pei-x86_64.c:pe_ILF_build_a_bfd
Line
Count
Source
804
184
{
805
184
  bfd_byte *       ptr;
806
184
  pe_ILF_vars      vars;
807
184
  struct internal_filehdr  internal_f;
808
184
  unsigned int       import_type;
809
184
  unsigned int       import_name_type;
810
184
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
811
184
  coff_symbol_type **    imp_sym;
812
184
  unsigned int       imp_index;
813
184
  intptr_t alignment;
814
815
  /* Decode and verify the types field of the ILF structure.  */
816
184
  import_type = types & 0x3;
817
184
  import_name_type = (types & 0x1c) >> 2;
818
819
184
  switch (import_type)
820
184
    {
821
68
    case IMPORT_CODE:
822
119
    case IMPORT_DATA:
823
175
    case IMPORT_CONST:
824
175
      break;
825
826
9
    default:
827
      /* xgettext:c-format */
828
9
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
9
        abfd, import_type);
830
9
      return false;
831
184
    }
832
833
175
  switch (import_name_type)
834
175
    {
835
44
    case IMPORT_ORDINAL:
836
65
    case IMPORT_NAME:
837
87
    case IMPORT_NAME_NOPREFIX:
838
133
    case IMPORT_NAME_UNDECORATE:
839
133
      import_name = symbol_name;
840
133
      break;
841
842
31
    case IMPORT_NAME_EXPORTAS:
843
31
      if (!import_name || !import_name[0])
844
18
  {
845
18
    _bfd_error_handler (_("%pB: missing import name for "
846
18
        "IMPORT_NAME_EXPORTAS for %s"),
847
18
            abfd, symbol_name);
848
18
    return false;
849
18
  }
850
13
      break;
851
852
13
    default:
853
      /* xgettext:c-format */
854
11
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
855
11
        abfd, import_name_type);
856
11
      return false;
857
175
    }
858
859
  /* Initialise local variables.
860
861
     Note these are kept in a structure rather than being
862
     declared as statics since bfd frowns on global variables.
863
864
     We are going to construct the contents of the BFD in memory,
865
     so allocate all the space that we will need right now.  */
866
146
  vars.bim
867
146
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
868
146
  if (vars.bim == NULL)
869
0
    return false;
870
871
146
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
872
146
  vars.bim->buffer = ptr;
873
146
  vars.bim->size   = ILF_DATA_SIZE;
874
146
  if (ptr == NULL)
875
0
    goto error_return;
876
877
  /* Initialise the pointers to regions of the memory and the
878
     other contents of the pe_ILF_vars structure as well.  */
879
146
  vars.sym_cache = (coff_symbol_type *) ptr;
880
146
  vars.sym_ptr   = (coff_symbol_type *) ptr;
881
146
  vars.sym_index = 0;
882
146
  ptr += SIZEOF_ILF_SYMS;
883
884
146
  vars.sym_table = (unsigned int *) ptr;
885
146
  vars.table_ptr = (unsigned int *) ptr;
886
146
  ptr += SIZEOF_ILF_SYM_TABLE;
887
888
146
  vars.native_syms = (combined_entry_type *) ptr;
889
146
  vars.native_ptr  = (combined_entry_type *) ptr;
890
146
  ptr += SIZEOF_ILF_NATIVE_SYMS;
891
892
146
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
893
146
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
894
146
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
895
896
146
  vars.esym_table = (SYMENT *) ptr;
897
146
  vars.esym_ptr   = (SYMENT *) ptr;
898
146
  ptr += SIZEOF_ILF_EXT_SYMS;
899
900
146
  vars.reltab   = (arelent *) ptr;
901
146
  vars.relcount = 0;
902
146
  ptr += SIZEOF_ILF_RELOCS;
903
904
146
  vars.int_reltab  = (struct internal_reloc *) ptr;
905
146
  ptr += SIZEOF_ILF_INT_RELOCS;
906
907
146
  vars.string_table = (char *) ptr;
908
146
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
909
146
  ptr += SIZEOF_ILF_STRINGS;
910
146
  vars.end_string_ptr = (char *) ptr;
911
912
  /* The remaining space in bim->buffer is used
913
     by the pe_ILF_make_a_section() function.  */
914
915
  /* PR 18758: Make sure that the data area is sufficiently aligned for
916
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
917
     the test of GCC_VERSION.  For other compilers we assume 8 byte
918
     alignment.  */
919
146
#if GCC_VERSION >= 3000
920
146
  alignment = __alignof__ (struct coff_section_tdata);
921
#else
922
  alignment = 8;
923
#endif
924
146
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
925
926
146
  vars.data = ptr;
927
146
  vars.abfd = abfd;
928
146
  vars.sec_index = 0;
929
146
  vars.magic = magic;
930
931
  /* Create the initial .idata$<n> sections:
932
     [.idata$2:  Import Directory Table -- not needed]
933
     .idata$4:  Import Lookup Table
934
     .idata$5:  Import Address Table
935
936
     Note we do not create a .idata$3 section as this is
937
     created for us by the linker script.  */
938
146
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
939
146
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
940
146
  if (id4 == NULL || id5 == NULL)
941
0
    goto error_return;
942
943
  /* Fill in the contents of these sections.  */
944
146
  if (import_name_type == IMPORT_ORDINAL)
945
44
    {
946
44
      if (ordinal == 0)
947
  /* See PR 20907 for a reproducer.  */
948
8
  goto error_return;
949
950
36
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
951
36
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
952
36
      ((unsigned int *) id4->contents)[0] = ordinal;
953
36
      ((unsigned int *) id4->contents)[1] = 0x80000000;
954
36
      ((unsigned int *) id5->contents)[0] = ordinal;
955
36
      ((unsigned int *) id5->contents)[1] = 0x80000000;
956
#else
957
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
958
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
959
#endif
960
36
    }
961
102
  else
962
102
    {
963
102
      char *symbol;
964
102
      unsigned int len;
965
966
      /* Create .idata$6 - the Hint Name Table.  */
967
102
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
968
102
      if (id6 == NULL)
969
0
  goto error_return;
970
971
      /* If necessary, trim the import symbol name.  */
972
102
      symbol = import_name;
973
974
      /* As used by MS compiler, '_', '@', and '?' are alternative
975
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
976
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
977
   of these is used for a symbol.  We strip this leading char for
978
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
979
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
980
981
102
      if (import_name_type != IMPORT_NAME
982
81
    && import_name_type != IMPORT_NAME_EXPORTAS)
983
68
  {
984
68
    char c = symbol[0];
985
986
    /* Check that we don't remove for targets with empty
987
       USER_LABEL_PREFIX the leading underscore.  */
988
68
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
989
68
        || c == '@' || c == '?')
990
22
      symbol++;
991
68
  }
992
993
102
      len = strlen (symbol);
994
102
      if (import_name_type == IMPORT_NAME_UNDECORATE)
995
46
  {
996
    /* Truncate at the first '@'.  */
997
46
    char *at = strchr (symbol, '@');
998
999
46
    if (at != NULL)
1000
19
      len = at - symbol;
1001
46
  }
1002
1003
102
      id6->contents[0] = ordinal & 0xff;
1004
102
      id6->contents[1] = ordinal >> 8;
1005
1006
102
      memcpy ((char *) id6->contents + 2, symbol, len);
1007
102
      id6->contents[len + 2] = '\0';
1008
102
    }
1009
1010
138
  if (import_name_type != IMPORT_ORDINAL)
1011
102
    {
1012
102
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1013
102
      pe_ILF_save_relocs (&vars, id4);
1014
1015
102
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1016
102
      pe_ILF_save_relocs (&vars, id5);
1017
102
    }
1018
1019
  /* Create an import symbol.  */
1020
138
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1021
138
  imp_sym   = vars.sym_ptr_ptr - 1;
1022
138
  imp_index = vars.sym_index - 1;
1023
1024
  /* Create extra sections depending upon the type of import we are
1025
     dealing with.  */
1026
138
  switch (import_type)
1027
138
    {
1028
0
      int i;
1029
1030
55
    case IMPORT_CODE:
1031
      /* CODE functions are special, in that they get a trampoline that
1032
   jumps to the main import symbol.  Create a .text section to hold it.
1033
   First we need to look up its contents in the jump table.  */
1034
110
      for (i = NUM_ENTRIES (jtab); i--;)
1035
110
  {
1036
110
    if (jtab[i].size == 0)
1037
55
      continue;
1038
55
    if (jtab[i].magic == magic)
1039
55
      break;
1040
55
  }
1041
      /* If we did not find a matching entry something is wrong.  */
1042
55
      if (i < 0)
1043
0
  abort ();
1044
1045
      /* Create the .text section.  */
1046
55
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1047
55
      if (text == NULL)
1048
0
  goto error_return;
1049
1050
      /* Copy in the jump code.  */
1051
55
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1052
1053
      /* Create a reloc for the data in the text section.  */
1054
#ifdef MIPS_ARCH_MAGIC_WINCE
1055
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1056
  {
1057
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1058
              (struct bfd_symbol **) imp_sym,
1059
              imp_index);
1060
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1061
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1062
              (struct bfd_symbol **) imp_sym,
1063
              imp_index);
1064
  }
1065
      else
1066
#endif
1067
55
#ifdef AMD64MAGIC
1068
55
      if (magic == AMD64MAGIC)
1069
55
  {
1070
55
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1071
55
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1072
55
              imp_index);
1073
55
  }
1074
0
      else
1075
0
#endif
1076
0
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1077
0
            BFD_RELOC_32, (asymbol **) imp_sym,
1078
0
            imp_index);
1079
1080
55
      pe_ILF_save_relocs (&vars, text);
1081
55
      break;
1082
1083
42
    case IMPORT_DATA:
1084
83
    case IMPORT_CONST:
1085
83
      break;
1086
1087
0
    default:
1088
      /* XXX code not yet written.  */
1089
0
      abort ();
1090
138
    }
1091
1092
  /* Now create a symbol describing the imported value.  */
1093
138
  switch (import_type)
1094
138
    {
1095
55
    case IMPORT_CODE:
1096
55
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1097
55
          BSF_NOT_AT_END | BSF_FUNCTION);
1098
1099
55
      break;
1100
1101
42
    case IMPORT_DATA:
1102
      /* Nothing to do here.  */
1103
42
      break;
1104
1105
41
    case IMPORT_CONST:
1106
41
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1107
41
      break;
1108
1109
0
    default:
1110
      /* XXX code not yet written.  */
1111
0
      abort ();
1112
138
    }
1113
1114
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1115
138
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1116
138
  if (ptr)
1117
13
    *ptr = 0;
1118
138
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1119
138
  if (ptr)
1120
13
    *ptr = '.';
1121
1122
  /* Initialise the bfd.  */
1123
138
  memset (&internal_f, 0, sizeof (internal_f));
1124
1125
138
  internal_f.f_magic  = magic;
1126
138
  internal_f.f_symptr = 0;
1127
138
  internal_f.f_nsyms  = 0;
1128
138
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1129
1130
138
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1131
138
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1132
0
    goto error_return;
1133
1134
138
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1135
0
    goto error_return;
1136
1137
138
  obj_pe (abfd) = true;
1138
#ifdef THUMBPEMAGIC
1139
  if (vars.magic == THUMBPEMAGIC)
1140
    /* Stop some linker warnings about thumb code not supporting
1141
       interworking.  */
1142
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1143
#endif
1144
1145
  /* Switch from file contents to memory contents.  */
1146
138
  bfd_cache_close (abfd);
1147
1148
138
  abfd->iostream = (void *) vars.bim;
1149
138
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1150
138
  abfd->iovec = &_bfd_memory_iovec;
1151
138
  abfd->where = 0;
1152
138
  abfd->origin = 0;
1153
138
  abfd->size = 0;
1154
138
  obj_sym_filepos (abfd) = 0;
1155
1156
  /* Point the bfd at the symbol table.  */
1157
138
  obj_symbols (abfd) = vars.sym_cache;
1158
138
  abfd->symcount = vars.sym_index;
1159
1160
138
  obj_raw_syments (abfd) = vars.native_syms;
1161
138
  obj_raw_syment_count (abfd) = vars.sym_index;
1162
138
  obj_coff_keep_raw_syms (abfd) = true;
1163
1164
138
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1165
138
  obj_coff_keep_syms (abfd) = true;
1166
1167
138
  obj_convert (abfd) = vars.sym_table;
1168
138
  obj_conv_table_size (abfd) = vars.sym_index;
1169
1170
138
  obj_coff_strings (abfd) = vars.string_table;
1171
138
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1172
138
  obj_coff_keep_strings (abfd) = true;
1173
1174
138
  return true;
1175
1176
8
 error_return:
1177
8
  free (vars.bim->buffer);
1178
8
  free (vars.bim);
1179
  return false;
1180
138
}
pei-aarch64.c:pe_ILF_build_a_bfd
Line
Count
Source
804
165
{
805
165
  bfd_byte *       ptr;
806
165
  pe_ILF_vars      vars;
807
165
  struct internal_filehdr  internal_f;
808
165
  unsigned int       import_type;
809
165
  unsigned int       import_name_type;
810
165
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
811
165
  coff_symbol_type **    imp_sym;
812
165
  unsigned int       imp_index;
813
165
  intptr_t alignment;
814
815
  /* Decode and verify the types field of the ILF structure.  */
816
165
  import_type = types & 0x3;
817
165
  import_name_type = (types & 0x1c) >> 2;
818
819
165
  switch (import_type)
820
165
    {
821
68
    case IMPORT_CODE:
822
129
    case IMPORT_DATA:
823
156
    case IMPORT_CONST:
824
156
      break;
825
826
9
    default:
827
      /* xgettext:c-format */
828
9
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
9
        abfd, import_type);
830
9
      return false;
831
165
    }
832
833
156
  switch (import_name_type)
834
156
    {
835
36
    case IMPORT_ORDINAL:
836
54
    case IMPORT_NAME:
837
76
    case IMPORT_NAME_NOPREFIX:
838
118
    case IMPORT_NAME_UNDECORATE:
839
118
      import_name = symbol_name;
840
118
      break;
841
842
29
    case IMPORT_NAME_EXPORTAS:
843
29
      if (!import_name || !import_name[0])
844
16
  {
845
16
    _bfd_error_handler (_("%pB: missing import name for "
846
16
        "IMPORT_NAME_EXPORTAS for %s"),
847
16
            abfd, symbol_name);
848
16
    return false;
849
16
  }
850
13
      break;
851
852
13
    default:
853
      /* xgettext:c-format */
854
9
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
855
9
        abfd, import_name_type);
856
9
      return false;
857
156
    }
858
859
  /* Initialise local variables.
860
861
     Note these are kept in a structure rather than being
862
     declared as statics since bfd frowns on global variables.
863
864
     We are going to construct the contents of the BFD in memory,
865
     so allocate all the space that we will need right now.  */
866
131
  vars.bim
867
131
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
868
131
  if (vars.bim == NULL)
869
0
    return false;
870
871
131
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
872
131
  vars.bim->buffer = ptr;
873
131
  vars.bim->size   = ILF_DATA_SIZE;
874
131
  if (ptr == NULL)
875
0
    goto error_return;
876
877
  /* Initialise the pointers to regions of the memory and the
878
     other contents of the pe_ILF_vars structure as well.  */
879
131
  vars.sym_cache = (coff_symbol_type *) ptr;
880
131
  vars.sym_ptr   = (coff_symbol_type *) ptr;
881
131
  vars.sym_index = 0;
882
131
  ptr += SIZEOF_ILF_SYMS;
883
884
131
  vars.sym_table = (unsigned int *) ptr;
885
131
  vars.table_ptr = (unsigned int *) ptr;
886
131
  ptr += SIZEOF_ILF_SYM_TABLE;
887
888
131
  vars.native_syms = (combined_entry_type *) ptr;
889
131
  vars.native_ptr  = (combined_entry_type *) ptr;
890
131
  ptr += SIZEOF_ILF_NATIVE_SYMS;
891
892
131
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
893
131
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
894
131
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
895
896
131
  vars.esym_table = (SYMENT *) ptr;
897
131
  vars.esym_ptr   = (SYMENT *) ptr;
898
131
  ptr += SIZEOF_ILF_EXT_SYMS;
899
900
131
  vars.reltab   = (arelent *) ptr;
901
131
  vars.relcount = 0;
902
131
  ptr += SIZEOF_ILF_RELOCS;
903
904
131
  vars.int_reltab  = (struct internal_reloc *) ptr;
905
131
  ptr += SIZEOF_ILF_INT_RELOCS;
906
907
131
  vars.string_table = (char *) ptr;
908
131
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
909
131
  ptr += SIZEOF_ILF_STRINGS;
910
131
  vars.end_string_ptr = (char *) ptr;
911
912
  /* The remaining space in bim->buffer is used
913
     by the pe_ILF_make_a_section() function.  */
914
915
  /* PR 18758: Make sure that the data area is sufficiently aligned for
916
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
917
     the test of GCC_VERSION.  For other compilers we assume 8 byte
918
     alignment.  */
919
131
#if GCC_VERSION >= 3000
920
131
  alignment = __alignof__ (struct coff_section_tdata);
921
#else
922
  alignment = 8;
923
#endif
924
131
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
925
926
131
  vars.data = ptr;
927
131
  vars.abfd = abfd;
928
131
  vars.sec_index = 0;
929
131
  vars.magic = magic;
930
931
  /* Create the initial .idata$<n> sections:
932
     [.idata$2:  Import Directory Table -- not needed]
933
     .idata$4:  Import Lookup Table
934
     .idata$5:  Import Address Table
935
936
     Note we do not create a .idata$3 section as this is
937
     created for us by the linker script.  */
938
131
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
939
131
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
940
131
  if (id4 == NULL || id5 == NULL)
941
0
    goto error_return;
942
943
  /* Fill in the contents of these sections.  */
944
131
  if (import_name_type == IMPORT_ORDINAL)
945
36
    {
946
36
      if (ordinal == 0)
947
  /* See PR 20907 for a reproducer.  */
948
9
  goto error_return;
949
950
27
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
951
27
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
952
27
      ((unsigned int *) id4->contents)[0] = ordinal;
953
27
      ((unsigned int *) id4->contents)[1] = 0x80000000;
954
27
      ((unsigned int *) id5->contents)[0] = ordinal;
955
27
      ((unsigned int *) id5->contents)[1] = 0x80000000;
956
#else
957
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
958
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
959
#endif
960
27
    }
961
95
  else
962
95
    {
963
95
      char *symbol;
964
95
      unsigned int len;
965
966
      /* Create .idata$6 - the Hint Name Table.  */
967
95
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
968
95
      if (id6 == NULL)
969
0
  goto error_return;
970
971
      /* If necessary, trim the import symbol name.  */
972
95
      symbol = import_name;
973
974
      /* As used by MS compiler, '_', '@', and '?' are alternative
975
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
976
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
977
   of these is used for a symbol.  We strip this leading char for
978
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
979
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
980
981
95
      if (import_name_type != IMPORT_NAME
982
77
    && import_name_type != IMPORT_NAME_EXPORTAS)
983
64
  {
984
64
    char c = symbol[0];
985
986
    /* Check that we don't remove for targets with empty
987
       USER_LABEL_PREFIX the leading underscore.  */
988
64
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
989
64
        || c == '@' || c == '?')
990
14
      symbol++;
991
64
  }
992
993
95
      len = strlen (symbol);
994
95
      if (import_name_type == IMPORT_NAME_UNDECORATE)
995
42
  {
996
    /* Truncate at the first '@'.  */
997
42
    char *at = strchr (symbol, '@');
998
999
42
    if (at != NULL)
1000
8
      len = at - symbol;
1001
42
  }
1002
1003
95
      id6->contents[0] = ordinal & 0xff;
1004
95
      id6->contents[1] = ordinal >> 8;
1005
1006
95
      memcpy ((char *) id6->contents + 2, symbol, len);
1007
95
      id6->contents[len + 2] = '\0';
1008
95
    }
1009
1010
122
  if (import_name_type != IMPORT_ORDINAL)
1011
95
    {
1012
95
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1013
95
      pe_ILF_save_relocs (&vars, id4);
1014
1015
95
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1016
95
      pe_ILF_save_relocs (&vars, id5);
1017
95
    }
1018
1019
  /* Create an import symbol.  */
1020
122
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1021
122
  imp_sym   = vars.sym_ptr_ptr - 1;
1022
122
  imp_index = vars.sym_index - 1;
1023
1024
  /* Create extra sections depending upon the type of import we are
1025
     dealing with.  */
1026
122
  switch (import_type)
1027
122
    {
1028
0
      int i;
1029
1030
55
    case IMPORT_CODE:
1031
      /* CODE functions are special, in that they get a trampoline that
1032
   jumps to the main import symbol.  Create a .text section to hold it.
1033
   First we need to look up its contents in the jump table.  */
1034
110
      for (i = NUM_ENTRIES (jtab); i--;)
1035
110
  {
1036
110
    if (jtab[i].size == 0)
1037
55
      continue;
1038
55
    if (jtab[i].magic == magic)
1039
55
      break;
1040
55
  }
1041
      /* If we did not find a matching entry something is wrong.  */
1042
55
      if (i < 0)
1043
0
  abort ();
1044
1045
      /* Create the .text section.  */
1046
55
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1047
55
      if (text == NULL)
1048
0
  goto error_return;
1049
1050
      /* Copy in the jump code.  */
1051
55
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1052
1053
      /* Create a reloc for the data in the text section.  */
1054
#ifdef MIPS_ARCH_MAGIC_WINCE
1055
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1056
  {
1057
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1058
              (struct bfd_symbol **) imp_sym,
1059
              imp_index);
1060
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1061
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1062
              (struct bfd_symbol **) imp_sym,
1063
              imp_index);
1064
  }
1065
      else
1066
#endif
1067
#ifdef AMD64MAGIC
1068
      if (magic == AMD64MAGIC)
1069
  {
1070
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1071
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1072
              imp_index);
1073
  }
1074
      else
1075
#endif
1076
55
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1077
55
            BFD_RELOC_32, (asymbol **) imp_sym,
1078
55
            imp_index);
1079
1080
55
      pe_ILF_save_relocs (&vars, text);
1081
55
      break;
1082
1083
48
    case IMPORT_DATA:
1084
67
    case IMPORT_CONST:
1085
67
      break;
1086
1087
0
    default:
1088
      /* XXX code not yet written.  */
1089
0
      abort ();
1090
122
    }
1091
1092
  /* Now create a symbol describing the imported value.  */
1093
122
  switch (import_type)
1094
122
    {
1095
55
    case IMPORT_CODE:
1096
55
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1097
55
          BSF_NOT_AT_END | BSF_FUNCTION);
1098
1099
55
      break;
1100
1101
48
    case IMPORT_DATA:
1102
      /* Nothing to do here.  */
1103
48
      break;
1104
1105
19
    case IMPORT_CONST:
1106
19
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1107
19
      break;
1108
1109
0
    default:
1110
      /* XXX code not yet written.  */
1111
0
      abort ();
1112
122
    }
1113
1114
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1115
122
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1116
122
  if (ptr)
1117
19
    *ptr = 0;
1118
122
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1119
122
  if (ptr)
1120
19
    *ptr = '.';
1121
1122
  /* Initialise the bfd.  */
1123
122
  memset (&internal_f, 0, sizeof (internal_f));
1124
1125
122
  internal_f.f_magic  = magic;
1126
122
  internal_f.f_symptr = 0;
1127
122
  internal_f.f_nsyms  = 0;
1128
122
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1129
1130
122
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1131
122
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1132
0
    goto error_return;
1133
1134
122
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1135
0
    goto error_return;
1136
1137
122
  obj_pe (abfd) = true;
1138
#ifdef THUMBPEMAGIC
1139
  if (vars.magic == THUMBPEMAGIC)
1140
    /* Stop some linker warnings about thumb code not supporting
1141
       interworking.  */
1142
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1143
#endif
1144
1145
  /* Switch from file contents to memory contents.  */
1146
122
  bfd_cache_close (abfd);
1147
1148
122
  abfd->iostream = (void *) vars.bim;
1149
122
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1150
122
  abfd->iovec = &_bfd_memory_iovec;
1151
122
  abfd->where = 0;
1152
122
  abfd->origin = 0;
1153
122
  abfd->size = 0;
1154
122
  obj_sym_filepos (abfd) = 0;
1155
1156
  /* Point the bfd at the symbol table.  */
1157
122
  obj_symbols (abfd) = vars.sym_cache;
1158
122
  abfd->symcount = vars.sym_index;
1159
1160
122
  obj_raw_syments (abfd) = vars.native_syms;
1161
122
  obj_raw_syment_count (abfd) = vars.sym_index;
1162
122
  obj_coff_keep_raw_syms (abfd) = true;
1163
1164
122
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1165
122
  obj_coff_keep_syms (abfd) = true;
1166
1167
122
  obj_convert (abfd) = vars.sym_table;
1168
122
  obj_conv_table_size (abfd) = vars.sym_index;
1169
1170
122
  obj_coff_strings (abfd) = vars.string_table;
1171
122
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1172
122
  obj_coff_keep_strings (abfd) = true;
1173
1174
122
  return true;
1175
1176
9
 error_return:
1177
9
  free (vars.bim->buffer);
1178
9
  free (vars.bim);
1179
  return false;
1180
122
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_build_a_bfd
pei-loongarch64.c:pe_ILF_build_a_bfd
Line
Count
Source
804
177
{
805
177
  bfd_byte *       ptr;
806
177
  pe_ILF_vars      vars;
807
177
  struct internal_filehdr  internal_f;
808
177
  unsigned int       import_type;
809
177
  unsigned int       import_name_type;
810
177
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
811
177
  coff_symbol_type **    imp_sym;
812
177
  unsigned int       imp_index;
813
177
  intptr_t alignment;
814
815
  /* Decode and verify the types field of the ILF structure.  */
816
177
  import_type = types & 0x3;
817
177
  import_name_type = (types & 0x1c) >> 2;
818
819
177
  switch (import_type)
820
177
    {
821
78
    case IMPORT_CODE:
822
140
    case IMPORT_DATA:
823
168
    case IMPORT_CONST:
824
168
      break;
825
826
9
    default:
827
      /* xgettext:c-format */
828
9
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
9
        abfd, import_type);
830
9
      return false;
831
177
    }
832
833
168
  switch (import_name_type)
834
168
    {
835
44
    case IMPORT_ORDINAL:
836
60
    case IMPORT_NAME:
837
77
    case IMPORT_NAME_NOPREFIX:
838
124
    case IMPORT_NAME_UNDECORATE:
839
124
      import_name = symbol_name;
840
124
      break;
841
842
35
    case IMPORT_NAME_EXPORTAS:
843
35
      if (!import_name || !import_name[0])
844
17
  {
845
17
    _bfd_error_handler (_("%pB: missing import name for "
846
17
        "IMPORT_NAME_EXPORTAS for %s"),
847
17
            abfd, symbol_name);
848
17
    return false;
849
17
  }
850
18
      break;
851
852
18
    default:
853
      /* xgettext:c-format */
854
9
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
855
9
        abfd, import_name_type);
856
9
      return false;
857
168
    }
858
859
  /* Initialise local variables.
860
861
     Note these are kept in a structure rather than being
862
     declared as statics since bfd frowns on global variables.
863
864
     We are going to construct the contents of the BFD in memory,
865
     so allocate all the space that we will need right now.  */
866
142
  vars.bim
867
142
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
868
142
  if (vars.bim == NULL)
869
0
    return false;
870
871
142
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
872
142
  vars.bim->buffer = ptr;
873
142
  vars.bim->size   = ILF_DATA_SIZE;
874
142
  if (ptr == NULL)
875
0
    goto error_return;
876
877
  /* Initialise the pointers to regions of the memory and the
878
     other contents of the pe_ILF_vars structure as well.  */
879
142
  vars.sym_cache = (coff_symbol_type *) ptr;
880
142
  vars.sym_ptr   = (coff_symbol_type *) ptr;
881
142
  vars.sym_index = 0;
882
142
  ptr += SIZEOF_ILF_SYMS;
883
884
142
  vars.sym_table = (unsigned int *) ptr;
885
142
  vars.table_ptr = (unsigned int *) ptr;
886
142
  ptr += SIZEOF_ILF_SYM_TABLE;
887
888
142
  vars.native_syms = (combined_entry_type *) ptr;
889
142
  vars.native_ptr  = (combined_entry_type *) ptr;
890
142
  ptr += SIZEOF_ILF_NATIVE_SYMS;
891
892
142
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
893
142
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
894
142
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
895
896
142
  vars.esym_table = (SYMENT *) ptr;
897
142
  vars.esym_ptr   = (SYMENT *) ptr;
898
142
  ptr += SIZEOF_ILF_EXT_SYMS;
899
900
142
  vars.reltab   = (arelent *) ptr;
901
142
  vars.relcount = 0;
902
142
  ptr += SIZEOF_ILF_RELOCS;
903
904
142
  vars.int_reltab  = (struct internal_reloc *) ptr;
905
142
  ptr += SIZEOF_ILF_INT_RELOCS;
906
907
142
  vars.string_table = (char *) ptr;
908
142
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
909
142
  ptr += SIZEOF_ILF_STRINGS;
910
142
  vars.end_string_ptr = (char *) ptr;
911
912
  /* The remaining space in bim->buffer is used
913
     by the pe_ILF_make_a_section() function.  */
914
915
  /* PR 18758: Make sure that the data area is sufficiently aligned for
916
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
917
     the test of GCC_VERSION.  For other compilers we assume 8 byte
918
     alignment.  */
919
142
#if GCC_VERSION >= 3000
920
142
  alignment = __alignof__ (struct coff_section_tdata);
921
#else
922
  alignment = 8;
923
#endif
924
142
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
925
926
142
  vars.data = ptr;
927
142
  vars.abfd = abfd;
928
142
  vars.sec_index = 0;
929
142
  vars.magic = magic;
930
931
  /* Create the initial .idata$<n> sections:
932
     [.idata$2:  Import Directory Table -- not needed]
933
     .idata$4:  Import Lookup Table
934
     .idata$5:  Import Address Table
935
936
     Note we do not create a .idata$3 section as this is
937
     created for us by the linker script.  */
938
142
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
939
142
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
940
142
  if (id4 == NULL || id5 == NULL)
941
0
    goto error_return;
942
943
  /* Fill in the contents of these sections.  */
944
142
  if (import_name_type == IMPORT_ORDINAL)
945
44
    {
946
44
      if (ordinal == 0)
947
  /* See PR 20907 for a reproducer.  */
948
9
  goto error_return;
949
950
35
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
951
35
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
952
35
      ((unsigned int *) id4->contents)[0] = ordinal;
953
35
      ((unsigned int *) id4->contents)[1] = 0x80000000;
954
35
      ((unsigned int *) id5->contents)[0] = ordinal;
955
35
      ((unsigned int *) id5->contents)[1] = 0x80000000;
956
#else
957
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
958
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
959
#endif
960
35
    }
961
98
  else
962
98
    {
963
98
      char *symbol;
964
98
      unsigned int len;
965
966
      /* Create .idata$6 - the Hint Name Table.  */
967
98
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
968
98
      if (id6 == NULL)
969
0
  goto error_return;
970
971
      /* If necessary, trim the import symbol name.  */
972
98
      symbol = import_name;
973
974
      /* As used by MS compiler, '_', '@', and '?' are alternative
975
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
976
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
977
   of these is used for a symbol.  We strip this leading char for
978
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
979
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
980
981
98
      if (import_name_type != IMPORT_NAME
982
82
    && import_name_type != IMPORT_NAME_EXPORTAS)
983
64
  {
984
64
    char c = symbol[0];
985
986
    /* Check that we don't remove for targets with empty
987
       USER_LABEL_PREFIX the leading underscore.  */
988
64
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
989
64
        || c == '@' || c == '?')
990
17
      symbol++;
991
64
  }
992
993
98
      len = strlen (symbol);
994
98
      if (import_name_type == IMPORT_NAME_UNDECORATE)
995
47
  {
996
    /* Truncate at the first '@'.  */
997
47
    char *at = strchr (symbol, '@');
998
999
47
    if (at != NULL)
1000
10
      len = at - symbol;
1001
47
  }
1002
1003
98
      id6->contents[0] = ordinal & 0xff;
1004
98
      id6->contents[1] = ordinal >> 8;
1005
1006
98
      memcpy ((char *) id6->contents + 2, symbol, len);
1007
98
      id6->contents[len + 2] = '\0';
1008
98
    }
1009
1010
133
  if (import_name_type != IMPORT_ORDINAL)
1011
98
    {
1012
98
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1013
98
      pe_ILF_save_relocs (&vars, id4);
1014
1015
98
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1016
98
      pe_ILF_save_relocs (&vars, id5);
1017
98
    }
1018
1019
  /* Create an import symbol.  */
1020
133
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1021
133
  imp_sym   = vars.sym_ptr_ptr - 1;
1022
133
  imp_index = vars.sym_index - 1;
1023
1024
  /* Create extra sections depending upon the type of import we are
1025
     dealing with.  */
1026
133
  switch (import_type)
1027
133
    {
1028
0
      int i;
1029
1030
60
    case IMPORT_CODE:
1031
      /* CODE functions are special, in that they get a trampoline that
1032
   jumps to the main import symbol.  Create a .text section to hold it.
1033
   First we need to look up its contents in the jump table.  */
1034
120
      for (i = NUM_ENTRIES (jtab); i--;)
1035
120
  {
1036
120
    if (jtab[i].size == 0)
1037
60
      continue;
1038
60
    if (jtab[i].magic == magic)
1039
60
      break;
1040
60
  }
1041
      /* If we did not find a matching entry something is wrong.  */
1042
60
      if (i < 0)
1043
0
  abort ();
1044
1045
      /* Create the .text section.  */
1046
60
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1047
60
      if (text == NULL)
1048
0
  goto error_return;
1049
1050
      /* Copy in the jump code.  */
1051
60
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1052
1053
      /* Create a reloc for the data in the text section.  */
1054
#ifdef MIPS_ARCH_MAGIC_WINCE
1055
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1056
  {
1057
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1058
              (struct bfd_symbol **) imp_sym,
1059
              imp_index);
1060
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1061
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1062
              (struct bfd_symbol **) imp_sym,
1063
              imp_index);
1064
  }
1065
      else
1066
#endif
1067
#ifdef AMD64MAGIC
1068
      if (magic == AMD64MAGIC)
1069
  {
1070
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1071
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1072
              imp_index);
1073
  }
1074
      else
1075
#endif
1076
60
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1077
60
            BFD_RELOC_32, (asymbol **) imp_sym,
1078
60
            imp_index);
1079
1080
60
      pe_ILF_save_relocs (&vars, text);
1081
60
      break;
1082
1083
51
    case IMPORT_DATA:
1084
73
    case IMPORT_CONST:
1085
73
      break;
1086
1087
0
    default:
1088
      /* XXX code not yet written.  */
1089
0
      abort ();
1090
133
    }
1091
1092
  /* Now create a symbol describing the imported value.  */
1093
133
  switch (import_type)
1094
133
    {
1095
60
    case IMPORT_CODE:
1096
60
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1097
60
          BSF_NOT_AT_END | BSF_FUNCTION);
1098
1099
60
      break;
1100
1101
51
    case IMPORT_DATA:
1102
      /* Nothing to do here.  */
1103
51
      break;
1104
1105
22
    case IMPORT_CONST:
1106
22
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1107
22
      break;
1108
1109
0
    default:
1110
      /* XXX code not yet written.  */
1111
0
      abort ();
1112
133
    }
1113
1114
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1115
133
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1116
133
  if (ptr)
1117
18
    *ptr = 0;
1118
133
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1119
133
  if (ptr)
1120
18
    *ptr = '.';
1121
1122
  /* Initialise the bfd.  */
1123
133
  memset (&internal_f, 0, sizeof (internal_f));
1124
1125
133
  internal_f.f_magic  = magic;
1126
133
  internal_f.f_symptr = 0;
1127
133
  internal_f.f_nsyms  = 0;
1128
133
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1129
1130
133
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1131
133
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1132
0
    goto error_return;
1133
1134
133
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1135
0
    goto error_return;
1136
1137
133
  obj_pe (abfd) = true;
1138
#ifdef THUMBPEMAGIC
1139
  if (vars.magic == THUMBPEMAGIC)
1140
    /* Stop some linker warnings about thumb code not supporting
1141
       interworking.  */
1142
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1143
#endif
1144
1145
  /* Switch from file contents to memory contents.  */
1146
133
  bfd_cache_close (abfd);
1147
1148
133
  abfd->iostream = (void *) vars.bim;
1149
133
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1150
133
  abfd->iovec = &_bfd_memory_iovec;
1151
133
  abfd->where = 0;
1152
133
  abfd->origin = 0;
1153
133
  abfd->size = 0;
1154
133
  obj_sym_filepos (abfd) = 0;
1155
1156
  /* Point the bfd at the symbol table.  */
1157
133
  obj_symbols (abfd) = vars.sym_cache;
1158
133
  abfd->symcount = vars.sym_index;
1159
1160
133
  obj_raw_syments (abfd) = vars.native_syms;
1161
133
  obj_raw_syment_count (abfd) = vars.sym_index;
1162
133
  obj_coff_keep_raw_syms (abfd) = true;
1163
1164
133
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1165
133
  obj_coff_keep_syms (abfd) = true;
1166
1167
133
  obj_convert (abfd) = vars.sym_table;
1168
133
  obj_conv_table_size (abfd) = vars.sym_index;
1169
1170
133
  obj_coff_strings (abfd) = vars.string_table;
1171
133
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1172
133
  obj_coff_keep_strings (abfd) = true;
1173
1174
133
  return true;
1175
1176
9
 error_return:
1177
9
  free (vars.bim->buffer);
1178
9
  free (vars.bim);
1179
  return false;
1180
133
}
pei-riscv64.c:pe_ILF_build_a_bfd
Line
Count
Source
804
167
{
805
167
  bfd_byte *       ptr;
806
167
  pe_ILF_vars      vars;
807
167
  struct internal_filehdr  internal_f;
808
167
  unsigned int       import_type;
809
167
  unsigned int       import_name_type;
810
167
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
811
167
  coff_symbol_type **    imp_sym;
812
167
  unsigned int       imp_index;
813
167
  intptr_t alignment;
814
815
  /* Decode and verify the types field of the ILF structure.  */
816
167
  import_type = types & 0x3;
817
167
  import_name_type = (types & 0x1c) >> 2;
818
819
167
  switch (import_type)
820
167
    {
821
61
    case IMPORT_CODE:
822
105
    case IMPORT_DATA:
823
158
    case IMPORT_CONST:
824
158
      break;
825
826
9
    default:
827
      /* xgettext:c-format */
828
9
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
9
        abfd, import_type);
830
9
      return false;
831
167
    }
832
833
158
  switch (import_name_type)
834
158
    {
835
31
    case IMPORT_ORDINAL:
836
45
    case IMPORT_NAME:
837
67
    case IMPORT_NAME_NOPREFIX:
838
117
    case IMPORT_NAME_UNDECORATE:
839
117
      import_name = symbol_name;
840
117
      break;
841
842
30
    case IMPORT_NAME_EXPORTAS:
843
30
      if (!import_name || !import_name[0])
844
15
  {
845
15
    _bfd_error_handler (_("%pB: missing import name for "
846
15
        "IMPORT_NAME_EXPORTAS for %s"),
847
15
            abfd, symbol_name);
848
15
    return false;
849
15
  }
850
15
      break;
851
852
15
    default:
853
      /* xgettext:c-format */
854
11
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
855
11
        abfd, import_name_type);
856
11
      return false;
857
158
    }
858
859
  /* Initialise local variables.
860
861
     Note these are kept in a structure rather than being
862
     declared as statics since bfd frowns on global variables.
863
864
     We are going to construct the contents of the BFD in memory,
865
     so allocate all the space that we will need right now.  */
866
132
  vars.bim
867
132
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
868
132
  if (vars.bim == NULL)
869
0
    return false;
870
871
132
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
872
132
  vars.bim->buffer = ptr;
873
132
  vars.bim->size   = ILF_DATA_SIZE;
874
132
  if (ptr == NULL)
875
0
    goto error_return;
876
877
  /* Initialise the pointers to regions of the memory and the
878
     other contents of the pe_ILF_vars structure as well.  */
879
132
  vars.sym_cache = (coff_symbol_type *) ptr;
880
132
  vars.sym_ptr   = (coff_symbol_type *) ptr;
881
132
  vars.sym_index = 0;
882
132
  ptr += SIZEOF_ILF_SYMS;
883
884
132
  vars.sym_table = (unsigned int *) ptr;
885
132
  vars.table_ptr = (unsigned int *) ptr;
886
132
  ptr += SIZEOF_ILF_SYM_TABLE;
887
888
132
  vars.native_syms = (combined_entry_type *) ptr;
889
132
  vars.native_ptr  = (combined_entry_type *) ptr;
890
132
  ptr += SIZEOF_ILF_NATIVE_SYMS;
891
892
132
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
893
132
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
894
132
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
895
896
132
  vars.esym_table = (SYMENT *) ptr;
897
132
  vars.esym_ptr   = (SYMENT *) ptr;
898
132
  ptr += SIZEOF_ILF_EXT_SYMS;
899
900
132
  vars.reltab   = (arelent *) ptr;
901
132
  vars.relcount = 0;
902
132
  ptr += SIZEOF_ILF_RELOCS;
903
904
132
  vars.int_reltab  = (struct internal_reloc *) ptr;
905
132
  ptr += SIZEOF_ILF_INT_RELOCS;
906
907
132
  vars.string_table = (char *) ptr;
908
132
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
909
132
  ptr += SIZEOF_ILF_STRINGS;
910
132
  vars.end_string_ptr = (char *) ptr;
911
912
  /* The remaining space in bim->buffer is used
913
     by the pe_ILF_make_a_section() function.  */
914
915
  /* PR 18758: Make sure that the data area is sufficiently aligned for
916
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
917
     the test of GCC_VERSION.  For other compilers we assume 8 byte
918
     alignment.  */
919
132
#if GCC_VERSION >= 3000
920
132
  alignment = __alignof__ (struct coff_section_tdata);
921
#else
922
  alignment = 8;
923
#endif
924
132
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
925
926
132
  vars.data = ptr;
927
132
  vars.abfd = abfd;
928
132
  vars.sec_index = 0;
929
132
  vars.magic = magic;
930
931
  /* Create the initial .idata$<n> sections:
932
     [.idata$2:  Import Directory Table -- not needed]
933
     .idata$4:  Import Lookup Table
934
     .idata$5:  Import Address Table
935
936
     Note we do not create a .idata$3 section as this is
937
     created for us by the linker script.  */
938
132
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
939
132
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
940
132
  if (id4 == NULL || id5 == NULL)
941
0
    goto error_return;
942
943
  /* Fill in the contents of these sections.  */
944
132
  if (import_name_type == IMPORT_ORDINAL)
945
31
    {
946
31
      if (ordinal == 0)
947
  /* See PR 20907 for a reproducer.  */
948
8
  goto error_return;
949
950
23
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
951
23
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
952
23
      ((unsigned int *) id4->contents)[0] = ordinal;
953
23
      ((unsigned int *) id4->contents)[1] = 0x80000000;
954
23
      ((unsigned int *) id5->contents)[0] = ordinal;
955
23
      ((unsigned int *) id5->contents)[1] = 0x80000000;
956
#else
957
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
958
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
959
#endif
960
23
    }
961
101
  else
962
101
    {
963
101
      char *symbol;
964
101
      unsigned int len;
965
966
      /* Create .idata$6 - the Hint Name Table.  */
967
101
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
968
101
      if (id6 == NULL)
969
0
  goto error_return;
970
971
      /* If necessary, trim the import symbol name.  */
972
101
      symbol = import_name;
973
974
      /* As used by MS compiler, '_', '@', and '?' are alternative
975
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
976
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
977
   of these is used for a symbol.  We strip this leading char for
978
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
979
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
980
981
101
      if (import_name_type != IMPORT_NAME
982
87
    && import_name_type != IMPORT_NAME_EXPORTAS)
983
72
  {
984
72
    char c = symbol[0];
985
986
    /* Check that we don't remove for targets with empty
987
       USER_LABEL_PREFIX the leading underscore.  */
988
72
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
989
72
        || c == '@' || c == '?')
990
22
      symbol++;
991
72
  }
992
993
101
      len = strlen (symbol);
994
101
      if (import_name_type == IMPORT_NAME_UNDECORATE)
995
50
  {
996
    /* Truncate at the first '@'.  */
997
50
    char *at = strchr (symbol, '@');
998
999
50
    if (at != NULL)
1000
14
      len = at - symbol;
1001
50
  }
1002
1003
101
      id6->contents[0] = ordinal & 0xff;
1004
101
      id6->contents[1] = ordinal >> 8;
1005
1006
101
      memcpy ((char *) id6->contents + 2, symbol, len);
1007
101
      id6->contents[len + 2] = '\0';
1008
101
    }
1009
1010
124
  if (import_name_type != IMPORT_ORDINAL)
1011
101
    {
1012
101
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1013
101
      pe_ILF_save_relocs (&vars, id4);
1014
1015
101
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1016
101
      pe_ILF_save_relocs (&vars, id5);
1017
101
    }
1018
1019
  /* Create an import symbol.  */
1020
124
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1021
124
  imp_sym   = vars.sym_ptr_ptr - 1;
1022
124
  imp_index = vars.sym_index - 1;
1023
1024
  /* Create extra sections depending upon the type of import we are
1025
     dealing with.  */
1026
124
  switch (import_type)
1027
124
    {
1028
0
      int i;
1029
1030
36
    case IMPORT_CODE:
1031
      /* CODE functions are special, in that they get a trampoline that
1032
   jumps to the main import symbol.  Create a .text section to hold it.
1033
   First we need to look up its contents in the jump table.  */
1034
72
      for (i = NUM_ENTRIES (jtab); i--;)
1035
72
  {
1036
72
    if (jtab[i].size == 0)
1037
36
      continue;
1038
36
    if (jtab[i].magic == magic)
1039
36
      break;
1040
36
  }
1041
      /* If we did not find a matching entry something is wrong.  */
1042
36
      if (i < 0)
1043
0
  abort ();
1044
1045
      /* Create the .text section.  */
1046
36
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1047
36
      if (text == NULL)
1048
0
  goto error_return;
1049
1050
      /* Copy in the jump code.  */
1051
36
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1052
1053
      /* Create a reloc for the data in the text section.  */
1054
#ifdef MIPS_ARCH_MAGIC_WINCE
1055
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1056
  {
1057
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1058
              (struct bfd_symbol **) imp_sym,
1059
              imp_index);
1060
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1061
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1062
              (struct bfd_symbol **) imp_sym,
1063
              imp_index);
1064
  }
1065
      else
1066
#endif
1067
#ifdef AMD64MAGIC
1068
      if (magic == AMD64MAGIC)
1069
  {
1070
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1071
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1072
              imp_index);
1073
  }
1074
      else
1075
#endif
1076
36
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1077
36
            BFD_RELOC_32, (asymbol **) imp_sym,
1078
36
            imp_index);
1079
1080
36
      pe_ILF_save_relocs (&vars, text);
1081
36
      break;
1082
1083
38
    case IMPORT_DATA:
1084
88
    case IMPORT_CONST:
1085
88
      break;
1086
1087
0
    default:
1088
      /* XXX code not yet written.  */
1089
0
      abort ();
1090
124
    }
1091
1092
  /* Now create a symbol describing the imported value.  */
1093
124
  switch (import_type)
1094
124
    {
1095
36
    case IMPORT_CODE:
1096
36
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1097
36
          BSF_NOT_AT_END | BSF_FUNCTION);
1098
1099
36
      break;
1100
1101
38
    case IMPORT_DATA:
1102
      /* Nothing to do here.  */
1103
38
      break;
1104
1105
50
    case IMPORT_CONST:
1106
50
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1107
50
      break;
1108
1109
0
    default:
1110
      /* XXX code not yet written.  */
1111
0
      abort ();
1112
124
    }
1113
1114
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1115
124
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1116
124
  if (ptr)
1117
22
    *ptr = 0;
1118
124
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1119
124
  if (ptr)
1120
22
    *ptr = '.';
1121
1122
  /* Initialise the bfd.  */
1123
124
  memset (&internal_f, 0, sizeof (internal_f));
1124
1125
124
  internal_f.f_magic  = magic;
1126
124
  internal_f.f_symptr = 0;
1127
124
  internal_f.f_nsyms  = 0;
1128
124
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1129
1130
124
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1131
124
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1132
0
    goto error_return;
1133
1134
124
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1135
0
    goto error_return;
1136
1137
124
  obj_pe (abfd) = true;
1138
#ifdef THUMBPEMAGIC
1139
  if (vars.magic == THUMBPEMAGIC)
1140
    /* Stop some linker warnings about thumb code not supporting
1141
       interworking.  */
1142
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1143
#endif
1144
1145
  /* Switch from file contents to memory contents.  */
1146
124
  bfd_cache_close (abfd);
1147
1148
124
  abfd->iostream = (void *) vars.bim;
1149
124
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1150
124
  abfd->iovec = &_bfd_memory_iovec;
1151
124
  abfd->where = 0;
1152
124
  abfd->origin = 0;
1153
124
  abfd->size = 0;
1154
124
  obj_sym_filepos (abfd) = 0;
1155
1156
  /* Point the bfd at the symbol table.  */
1157
124
  obj_symbols (abfd) = vars.sym_cache;
1158
124
  abfd->symcount = vars.sym_index;
1159
1160
124
  obj_raw_syments (abfd) = vars.native_syms;
1161
124
  obj_raw_syment_count (abfd) = vars.sym_index;
1162
124
  obj_coff_keep_raw_syms (abfd) = true;
1163
1164
124
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1165
124
  obj_coff_keep_syms (abfd) = true;
1166
1167
124
  obj_convert (abfd) = vars.sym_table;
1168
124
  obj_conv_table_size (abfd) = vars.sym_index;
1169
1170
124
  obj_coff_strings (abfd) = vars.string_table;
1171
124
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1172
124
  obj_coff_keep_strings (abfd) = true;
1173
1174
124
  return true;
1175
1176
8
 error_return:
1177
8
  free (vars.bim->buffer);
1178
8
  free (vars.bim);
1179
  return false;
1180
124
}
pei-arm-wince.c:pe_ILF_build_a_bfd
Line
Count
Source
804
142
{
805
142
  bfd_byte *       ptr;
806
142
  pe_ILF_vars      vars;
807
142
  struct internal_filehdr  internal_f;
808
142
  unsigned int       import_type;
809
142
  unsigned int       import_name_type;
810
142
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
811
142
  coff_symbol_type **    imp_sym;
812
142
  unsigned int       imp_index;
813
142
  intptr_t alignment;
814
815
  /* Decode and verify the types field of the ILF structure.  */
816
142
  import_type = types & 0x3;
817
142
  import_name_type = (types & 0x1c) >> 2;
818
819
142
  switch (import_type)
820
142
    {
821
65
    case IMPORT_CODE:
822
108
    case IMPORT_DATA:
823
133
    case IMPORT_CONST:
824
133
      break;
825
826
9
    default:
827
      /* xgettext:c-format */
828
9
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
9
        abfd, import_type);
830
9
      return false;
831
142
    }
832
833
133
  switch (import_name_type)
834
133
    {
835
38
    case IMPORT_ORDINAL:
836
46
    case IMPORT_NAME:
837
72
    case IMPORT_NAME_NOPREFIX:
838
100
    case IMPORT_NAME_UNDECORATE:
839
100
      import_name = symbol_name;
840
100
      break;
841
842
24
    case IMPORT_NAME_EXPORTAS:
843
24
      if (!import_name || !import_name[0])
844
18
  {
845
18
    _bfd_error_handler (_("%pB: missing import name for "
846
18
        "IMPORT_NAME_EXPORTAS for %s"),
847
18
            abfd, symbol_name);
848
18
    return false;
849
18
  }
850
6
      break;
851
852
9
    default:
853
      /* xgettext:c-format */
854
9
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
855
9
        abfd, import_name_type);
856
9
      return false;
857
133
    }
858
859
  /* Initialise local variables.
860
861
     Note these are kept in a structure rather than being
862
     declared as statics since bfd frowns on global variables.
863
864
     We are going to construct the contents of the BFD in memory,
865
     so allocate all the space that we will need right now.  */
866
106
  vars.bim
867
106
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
868
106
  if (vars.bim == NULL)
869
0
    return false;
870
871
106
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
872
106
  vars.bim->buffer = ptr;
873
106
  vars.bim->size   = ILF_DATA_SIZE;
874
106
  if (ptr == NULL)
875
0
    goto error_return;
876
877
  /* Initialise the pointers to regions of the memory and the
878
     other contents of the pe_ILF_vars structure as well.  */
879
106
  vars.sym_cache = (coff_symbol_type *) ptr;
880
106
  vars.sym_ptr   = (coff_symbol_type *) ptr;
881
106
  vars.sym_index = 0;
882
106
  ptr += SIZEOF_ILF_SYMS;
883
884
106
  vars.sym_table = (unsigned int *) ptr;
885
106
  vars.table_ptr = (unsigned int *) ptr;
886
106
  ptr += SIZEOF_ILF_SYM_TABLE;
887
888
106
  vars.native_syms = (combined_entry_type *) ptr;
889
106
  vars.native_ptr  = (combined_entry_type *) ptr;
890
106
  ptr += SIZEOF_ILF_NATIVE_SYMS;
891
892
106
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
893
106
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
894
106
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
895
896
106
  vars.esym_table = (SYMENT *) ptr;
897
106
  vars.esym_ptr   = (SYMENT *) ptr;
898
106
  ptr += SIZEOF_ILF_EXT_SYMS;
899
900
106
  vars.reltab   = (arelent *) ptr;
901
106
  vars.relcount = 0;
902
106
  ptr += SIZEOF_ILF_RELOCS;
903
904
106
  vars.int_reltab  = (struct internal_reloc *) ptr;
905
106
  ptr += SIZEOF_ILF_INT_RELOCS;
906
907
106
  vars.string_table = (char *) ptr;
908
106
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
909
106
  ptr += SIZEOF_ILF_STRINGS;
910
106
  vars.end_string_ptr = (char *) ptr;
911
912
  /* The remaining space in bim->buffer is used
913
     by the pe_ILF_make_a_section() function.  */
914
915
  /* PR 18758: Make sure that the data area is sufficiently aligned for
916
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
917
     the test of GCC_VERSION.  For other compilers we assume 8 byte
918
     alignment.  */
919
106
#if GCC_VERSION >= 3000
920
106
  alignment = __alignof__ (struct coff_section_tdata);
921
#else
922
  alignment = 8;
923
#endif
924
106
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
925
926
106
  vars.data = ptr;
927
106
  vars.abfd = abfd;
928
106
  vars.sec_index = 0;
929
106
  vars.magic = magic;
930
931
  /* Create the initial .idata$<n> sections:
932
     [.idata$2:  Import Directory Table -- not needed]
933
     .idata$4:  Import Lookup Table
934
     .idata$5:  Import Address Table
935
936
     Note we do not create a .idata$3 section as this is
937
     created for us by the linker script.  */
938
106
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
939
106
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
940
106
  if (id4 == NULL || id5 == NULL)
941
0
    goto error_return;
942
943
  /* Fill in the contents of these sections.  */
944
106
  if (import_name_type == IMPORT_ORDINAL)
945
38
    {
946
38
      if (ordinal == 0)
947
  /* See PR 20907 for a reproducer.  */
948
11
  goto error_return;
949
950
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
951
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
952
      ((unsigned int *) id4->contents)[0] = ordinal;
953
      ((unsigned int *) id4->contents)[1] = 0x80000000;
954
      ((unsigned int *) id5->contents)[0] = ordinal;
955
      ((unsigned int *) id5->contents)[1] = 0x80000000;
956
#else
957
27
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
958
27
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
959
27
#endif
960
27
    }
961
68
  else
962
68
    {
963
68
      char *symbol;
964
68
      unsigned int len;
965
966
      /* Create .idata$6 - the Hint Name Table.  */
967
68
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
968
68
      if (id6 == NULL)
969
0
  goto error_return;
970
971
      /* If necessary, trim the import symbol name.  */
972
68
      symbol = import_name;
973
974
      /* As used by MS compiler, '_', '@', and '?' are alternative
975
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
976
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
977
   of these is used for a symbol.  We strip this leading char for
978
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
979
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
980
981
68
      if (import_name_type != IMPORT_NAME
982
60
    && import_name_type != IMPORT_NAME_EXPORTAS)
983
54
  {
984
54
    char c = symbol[0];
985
986
    /* Check that we don't remove for targets with empty
987
       USER_LABEL_PREFIX the leading underscore.  */
988
54
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
989
54
        || c == '@' || c == '?')
990
12
      symbol++;
991
54
  }
992
993
68
      len = strlen (symbol);
994
68
      if (import_name_type == IMPORT_NAME_UNDECORATE)
995
28
  {
996
    /* Truncate at the first '@'.  */
997
28
    char *at = strchr (symbol, '@');
998
999
28
    if (at != NULL)
1000
5
      len = at - symbol;
1001
28
  }
1002
1003
68
      id6->contents[0] = ordinal & 0xff;
1004
68
      id6->contents[1] = ordinal >> 8;
1005
1006
68
      memcpy ((char *) id6->contents + 2, symbol, len);
1007
68
      id6->contents[len + 2] = '\0';
1008
68
    }
1009
1010
95
  if (import_name_type != IMPORT_ORDINAL)
1011
68
    {
1012
68
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1013
68
      pe_ILF_save_relocs (&vars, id4);
1014
1015
68
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1016
68
      pe_ILF_save_relocs (&vars, id5);
1017
68
    }
1018
1019
  /* Create an import symbol.  */
1020
95
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1021
95
  imp_sym   = vars.sym_ptr_ptr - 1;
1022
95
  imp_index = vars.sym_index - 1;
1023
1024
  /* Create extra sections depending upon the type of import we are
1025
     dealing with.  */
1026
95
  switch (import_type)
1027
95
    {
1028
0
      int i;
1029
1030
49
    case IMPORT_CODE:
1031
      /* CODE functions are special, in that they get a trampoline that
1032
   jumps to the main import symbol.  Create a .text section to hold it.
1033
   First we need to look up its contents in the jump table.  */
1034
123
      for (i = NUM_ENTRIES (jtab); i--;)
1035
123
  {
1036
123
    if (jtab[i].size == 0)
1037
49
      continue;
1038
74
    if (jtab[i].magic == magic)
1039
49
      break;
1040
74
  }
1041
      /* If we did not find a matching entry something is wrong.  */
1042
49
      if (i < 0)
1043
0
  abort ();
1044
1045
      /* Create the .text section.  */
1046
49
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1047
49
      if (text == NULL)
1048
0
  goto error_return;
1049
1050
      /* Copy in the jump code.  */
1051
49
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1052
1053
      /* Create a reloc for the data in the text section.  */
1054
#ifdef MIPS_ARCH_MAGIC_WINCE
1055
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1056
  {
1057
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1058
              (struct bfd_symbol **) imp_sym,
1059
              imp_index);
1060
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1061
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1062
              (struct bfd_symbol **) imp_sym,
1063
              imp_index);
1064
  }
1065
      else
1066
#endif
1067
#ifdef AMD64MAGIC
1068
      if (magic == AMD64MAGIC)
1069
  {
1070
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1071
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1072
              imp_index);
1073
  }
1074
      else
1075
#endif
1076
49
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1077
49
            BFD_RELOC_32, (asymbol **) imp_sym,
1078
49
            imp_index);
1079
1080
49
      pe_ILF_save_relocs (&vars, text);
1081
49
      break;
1082
1083
26
    case IMPORT_DATA:
1084
46
    case IMPORT_CONST:
1085
46
      break;
1086
1087
0
    default:
1088
      /* XXX code not yet written.  */
1089
0
      abort ();
1090
95
    }
1091
1092
  /* Now create a symbol describing the imported value.  */
1093
95
  switch (import_type)
1094
95
    {
1095
49
    case IMPORT_CODE:
1096
49
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1097
49
          BSF_NOT_AT_END | BSF_FUNCTION);
1098
1099
49
      break;
1100
1101
26
    case IMPORT_DATA:
1102
      /* Nothing to do here.  */
1103
26
      break;
1104
1105
20
    case IMPORT_CONST:
1106
20
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1107
20
      break;
1108
1109
0
    default:
1110
      /* XXX code not yet written.  */
1111
0
      abort ();
1112
95
    }
1113
1114
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1115
95
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1116
95
  if (ptr)
1117
8
    *ptr = 0;
1118
95
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1119
95
  if (ptr)
1120
8
    *ptr = '.';
1121
1122
  /* Initialise the bfd.  */
1123
95
  memset (&internal_f, 0, sizeof (internal_f));
1124
1125
95
  internal_f.f_magic  = magic;
1126
95
  internal_f.f_symptr = 0;
1127
95
  internal_f.f_nsyms  = 0;
1128
95
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1129
1130
95
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1131
95
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1132
0
    goto error_return;
1133
1134
95
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1135
0
    goto error_return;
1136
1137
95
  obj_pe (abfd) = true;
1138
95
#ifdef THUMBPEMAGIC
1139
95
  if (vars.magic == THUMBPEMAGIC)
1140
    /* Stop some linker warnings about thumb code not supporting
1141
       interworking.  */
1142
50
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1143
95
#endif
1144
1145
  /* Switch from file contents to memory contents.  */
1146
95
  bfd_cache_close (abfd);
1147
1148
95
  abfd->iostream = (void *) vars.bim;
1149
95
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1150
95
  abfd->iovec = &_bfd_memory_iovec;
1151
95
  abfd->where = 0;
1152
95
  abfd->origin = 0;
1153
95
  abfd->size = 0;
1154
95
  obj_sym_filepos (abfd) = 0;
1155
1156
  /* Point the bfd at the symbol table.  */
1157
95
  obj_symbols (abfd) = vars.sym_cache;
1158
95
  abfd->symcount = vars.sym_index;
1159
1160
95
  obj_raw_syments (abfd) = vars.native_syms;
1161
95
  obj_raw_syment_count (abfd) = vars.sym_index;
1162
95
  obj_coff_keep_raw_syms (abfd) = true;
1163
1164
95
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1165
95
  obj_coff_keep_syms (abfd) = true;
1166
1167
95
  obj_convert (abfd) = vars.sym_table;
1168
95
  obj_conv_table_size (abfd) = vars.sym_index;
1169
1170
95
  obj_coff_strings (abfd) = vars.string_table;
1171
95
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1172
95
  obj_coff_keep_strings (abfd) = true;
1173
1174
95
  return true;
1175
1176
11
 error_return:
1177
11
  free (vars.bim->buffer);
1178
11
  free (vars.bim);
1179
  return false;
1180
95
}
pei-arm.c:pe_ILF_build_a_bfd
Line
Count
Source
804
144
{
805
144
  bfd_byte *       ptr;
806
144
  pe_ILF_vars      vars;
807
144
  struct internal_filehdr  internal_f;
808
144
  unsigned int       import_type;
809
144
  unsigned int       import_name_type;
810
144
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
811
144
  coff_symbol_type **    imp_sym;
812
144
  unsigned int       imp_index;
813
144
  intptr_t alignment;
814
815
  /* Decode and verify the types field of the ILF structure.  */
816
144
  import_type = types & 0x3;
817
144
  import_name_type = (types & 0x1c) >> 2;
818
819
144
  switch (import_type)
820
144
    {
821
66
    case IMPORT_CODE:
822
109
    case IMPORT_DATA:
823
135
    case IMPORT_CONST:
824
135
      break;
825
826
9
    default:
827
      /* xgettext:c-format */
828
9
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
9
        abfd, import_type);
830
9
      return false;
831
144
    }
832
833
135
  switch (import_name_type)
834
135
    {
835
39
    case IMPORT_ORDINAL:
836
47
    case IMPORT_NAME:
837
74
    case IMPORT_NAME_NOPREFIX:
838
102
    case IMPORT_NAME_UNDECORATE:
839
102
      import_name = symbol_name;
840
102
      break;
841
842
24
    case IMPORT_NAME_EXPORTAS:
843
24
      if (!import_name || !import_name[0])
844
18
  {
845
18
    _bfd_error_handler (_("%pB: missing import name for "
846
18
        "IMPORT_NAME_EXPORTAS for %s"),
847
18
            abfd, symbol_name);
848
18
    return false;
849
18
  }
850
6
      break;
851
852
9
    default:
853
      /* xgettext:c-format */
854
9
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
855
9
        abfd, import_name_type);
856
9
      return false;
857
135
    }
858
859
  /* Initialise local variables.
860
861
     Note these are kept in a structure rather than being
862
     declared as statics since bfd frowns on global variables.
863
864
     We are going to construct the contents of the BFD in memory,
865
     so allocate all the space that we will need right now.  */
866
108
  vars.bim
867
108
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
868
108
  if (vars.bim == NULL)
869
0
    return false;
870
871
108
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
872
108
  vars.bim->buffer = ptr;
873
108
  vars.bim->size   = ILF_DATA_SIZE;
874
108
  if (ptr == NULL)
875
0
    goto error_return;
876
877
  /* Initialise the pointers to regions of the memory and the
878
     other contents of the pe_ILF_vars structure as well.  */
879
108
  vars.sym_cache = (coff_symbol_type *) ptr;
880
108
  vars.sym_ptr   = (coff_symbol_type *) ptr;
881
108
  vars.sym_index = 0;
882
108
  ptr += SIZEOF_ILF_SYMS;
883
884
108
  vars.sym_table = (unsigned int *) ptr;
885
108
  vars.table_ptr = (unsigned int *) ptr;
886
108
  ptr += SIZEOF_ILF_SYM_TABLE;
887
888
108
  vars.native_syms = (combined_entry_type *) ptr;
889
108
  vars.native_ptr  = (combined_entry_type *) ptr;
890
108
  ptr += SIZEOF_ILF_NATIVE_SYMS;
891
892
108
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
893
108
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
894
108
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
895
896
108
  vars.esym_table = (SYMENT *) ptr;
897
108
  vars.esym_ptr   = (SYMENT *) ptr;
898
108
  ptr += SIZEOF_ILF_EXT_SYMS;
899
900
108
  vars.reltab   = (arelent *) ptr;
901
108
  vars.relcount = 0;
902
108
  ptr += SIZEOF_ILF_RELOCS;
903
904
108
  vars.int_reltab  = (struct internal_reloc *) ptr;
905
108
  ptr += SIZEOF_ILF_INT_RELOCS;
906
907
108
  vars.string_table = (char *) ptr;
908
108
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
909
108
  ptr += SIZEOF_ILF_STRINGS;
910
108
  vars.end_string_ptr = (char *) ptr;
911
912
  /* The remaining space in bim->buffer is used
913
     by the pe_ILF_make_a_section() function.  */
914
915
  /* PR 18758: Make sure that the data area is sufficiently aligned for
916
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
917
     the test of GCC_VERSION.  For other compilers we assume 8 byte
918
     alignment.  */
919
108
#if GCC_VERSION >= 3000
920
108
  alignment = __alignof__ (struct coff_section_tdata);
921
#else
922
  alignment = 8;
923
#endif
924
108
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
925
926
108
  vars.data = ptr;
927
108
  vars.abfd = abfd;
928
108
  vars.sec_index = 0;
929
108
  vars.magic = magic;
930
931
  /* Create the initial .idata$<n> sections:
932
     [.idata$2:  Import Directory Table -- not needed]
933
     .idata$4:  Import Lookup Table
934
     .idata$5:  Import Address Table
935
936
     Note we do not create a .idata$3 section as this is
937
     created for us by the linker script.  */
938
108
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
939
108
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
940
108
  if (id4 == NULL || id5 == NULL)
941
0
    goto error_return;
942
943
  /* Fill in the contents of these sections.  */
944
108
  if (import_name_type == IMPORT_ORDINAL)
945
39
    {
946
39
      if (ordinal == 0)
947
  /* See PR 20907 for a reproducer.  */
948
11
  goto error_return;
949
950
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
951
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
952
      ((unsigned int *) id4->contents)[0] = ordinal;
953
      ((unsigned int *) id4->contents)[1] = 0x80000000;
954
      ((unsigned int *) id5->contents)[0] = ordinal;
955
      ((unsigned int *) id5->contents)[1] = 0x80000000;
956
#else
957
28
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
958
28
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
959
28
#endif
960
28
    }
961
69
  else
962
69
    {
963
69
      char *symbol;
964
69
      unsigned int len;
965
966
      /* Create .idata$6 - the Hint Name Table.  */
967
69
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
968
69
      if (id6 == NULL)
969
0
  goto error_return;
970
971
      /* If necessary, trim the import symbol name.  */
972
69
      symbol = import_name;
973
974
      /* As used by MS compiler, '_', '@', and '?' are alternative
975
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
976
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
977
   of these is used for a symbol.  We strip this leading char for
978
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
979
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
980
981
69
      if (import_name_type != IMPORT_NAME
982
61
    && import_name_type != IMPORT_NAME_EXPORTAS)
983
55
  {
984
55
    char c = symbol[0];
985
986
    /* Check that we don't remove for targets with empty
987
       USER_LABEL_PREFIX the leading underscore.  */
988
55
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
989
49
        || c == '@' || c == '?')
990
18
      symbol++;
991
55
  }
992
993
69
      len = strlen (symbol);
994
69
      if (import_name_type == IMPORT_NAME_UNDECORATE)
995
28
  {
996
    /* Truncate at the first '@'.  */
997
28
    char *at = strchr (symbol, '@');
998
999
28
    if (at != NULL)
1000
5
      len = at - symbol;
1001
28
  }
1002
1003
69
      id6->contents[0] = ordinal & 0xff;
1004
69
      id6->contents[1] = ordinal >> 8;
1005
1006
69
      memcpy ((char *) id6->contents + 2, symbol, len);
1007
69
      id6->contents[len + 2] = '\0';
1008
69
    }
1009
1010
97
  if (import_name_type != IMPORT_ORDINAL)
1011
69
    {
1012
69
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1013
69
      pe_ILF_save_relocs (&vars, id4);
1014
1015
69
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1016
69
      pe_ILF_save_relocs (&vars, id5);
1017
69
    }
1018
1019
  /* Create an import symbol.  */
1020
97
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1021
97
  imp_sym   = vars.sym_ptr_ptr - 1;
1022
97
  imp_index = vars.sym_index - 1;
1023
1024
  /* Create extra sections depending upon the type of import we are
1025
     dealing with.  */
1026
97
  switch (import_type)
1027
97
    {
1028
0
      int i;
1029
1030
50
    case IMPORT_CODE:
1031
      /* CODE functions are special, in that they get a trampoline that
1032
   jumps to the main import symbol.  Create a .text section to hold it.
1033
   First we need to look up its contents in the jump table.  */
1034
126
      for (i = NUM_ENTRIES (jtab); i--;)
1035
126
  {
1036
126
    if (jtab[i].size == 0)
1037
50
      continue;
1038
76
    if (jtab[i].magic == magic)
1039
50
      break;
1040
76
  }
1041
      /* If we did not find a matching entry something is wrong.  */
1042
50
      if (i < 0)
1043
0
  abort ();
1044
1045
      /* Create the .text section.  */
1046
50
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1047
50
      if (text == NULL)
1048
0
  goto error_return;
1049
1050
      /* Copy in the jump code.  */
1051
50
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1052
1053
      /* Create a reloc for the data in the text section.  */
1054
#ifdef MIPS_ARCH_MAGIC_WINCE
1055
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1056
  {
1057
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1058
              (struct bfd_symbol **) imp_sym,
1059
              imp_index);
1060
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1061
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1062
              (struct bfd_symbol **) imp_sym,
1063
              imp_index);
1064
  }
1065
      else
1066
#endif
1067
#ifdef AMD64MAGIC
1068
      if (magic == AMD64MAGIC)
1069
  {
1070
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1071
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1072
              imp_index);
1073
  }
1074
      else
1075
#endif
1076
50
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1077
50
            BFD_RELOC_32, (asymbol **) imp_sym,
1078
50
            imp_index);
1079
1080
50
      pe_ILF_save_relocs (&vars, text);
1081
50
      break;
1082
1083
26
    case IMPORT_DATA:
1084
47
    case IMPORT_CONST:
1085
47
      break;
1086
1087
0
    default:
1088
      /* XXX code not yet written.  */
1089
0
      abort ();
1090
97
    }
1091
1092
  /* Now create a symbol describing the imported value.  */
1093
97
  switch (import_type)
1094
97
    {
1095
50
    case IMPORT_CODE:
1096
50
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1097
50
          BSF_NOT_AT_END | BSF_FUNCTION);
1098
1099
50
      break;
1100
1101
26
    case IMPORT_DATA:
1102
      /* Nothing to do here.  */
1103
26
      break;
1104
1105
21
    case IMPORT_CONST:
1106
21
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1107
21
      break;
1108
1109
0
    default:
1110
      /* XXX code not yet written.  */
1111
0
      abort ();
1112
97
    }
1113
1114
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1115
97
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1116
97
  if (ptr)
1117
8
    *ptr = 0;
1118
97
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1119
97
  if (ptr)
1120
8
    *ptr = '.';
1121
1122
  /* Initialise the bfd.  */
1123
97
  memset (&internal_f, 0, sizeof (internal_f));
1124
1125
97
  internal_f.f_magic  = magic;
1126
97
  internal_f.f_symptr = 0;
1127
97
  internal_f.f_nsyms  = 0;
1128
97
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1129
1130
97
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1131
97
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1132
0
    goto error_return;
1133
1134
97
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1135
0
    goto error_return;
1136
1137
97
  obj_pe (abfd) = true;
1138
97
#ifdef THUMBPEMAGIC
1139
97
  if (vars.magic == THUMBPEMAGIC)
1140
    /* Stop some linker warnings about thumb code not supporting
1141
       interworking.  */
1142
50
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1143
97
#endif
1144
1145
  /* Switch from file contents to memory contents.  */
1146
97
  bfd_cache_close (abfd);
1147
1148
97
  abfd->iostream = (void *) vars.bim;
1149
97
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1150
97
  abfd->iovec = &_bfd_memory_iovec;
1151
97
  abfd->where = 0;
1152
97
  abfd->origin = 0;
1153
97
  abfd->size = 0;
1154
97
  obj_sym_filepos (abfd) = 0;
1155
1156
  /* Point the bfd at the symbol table.  */
1157
97
  obj_symbols (abfd) = vars.sym_cache;
1158
97
  abfd->symcount = vars.sym_index;
1159
1160
97
  obj_raw_syments (abfd) = vars.native_syms;
1161
97
  obj_raw_syment_count (abfd) = vars.sym_index;
1162
97
  obj_coff_keep_raw_syms (abfd) = true;
1163
1164
97
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1165
97
  obj_coff_keep_syms (abfd) = true;
1166
1167
97
  obj_convert (abfd) = vars.sym_table;
1168
97
  obj_conv_table_size (abfd) = vars.sym_index;
1169
1170
97
  obj_coff_strings (abfd) = vars.string_table;
1171
97
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1172
97
  obj_coff_keep_strings (abfd) = true;
1173
1174
97
  return true;
1175
1176
11
 error_return:
1177
11
  free (vars.bim->buffer);
1178
11
  free (vars.bim);
1179
  return false;
1180
97
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_build_a_bfd
pei-sh.c:pe_ILF_build_a_bfd
Line
Count
Source
804
243
{
805
243
  bfd_byte *       ptr;
806
243
  pe_ILF_vars      vars;
807
243
  struct internal_filehdr  internal_f;
808
243
  unsigned int       import_type;
809
243
  unsigned int       import_name_type;
810
243
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
811
243
  coff_symbol_type **    imp_sym;
812
243
  unsigned int       imp_index;
813
243
  intptr_t alignment;
814
815
  /* Decode and verify the types field of the ILF structure.  */
816
243
  import_type = types & 0x3;
817
243
  import_name_type = (types & 0x1c) >> 2;
818
819
243
  switch (import_type)
820
243
    {
821
87
    case IMPORT_CODE:
822
153
    case IMPORT_DATA:
823
206
    case IMPORT_CONST:
824
206
      break;
825
826
37
    default:
827
      /* xgettext:c-format */
828
37
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
37
        abfd, import_type);
830
37
      return false;
831
243
    }
832
833
206
  switch (import_name_type)
834
206
    {
835
41
    case IMPORT_ORDINAL:
836
63
    case IMPORT_NAME:
837
96
    case IMPORT_NAME_NOPREFIX:
838
159
    case IMPORT_NAME_UNDECORATE:
839
159
      import_name = symbol_name;
840
159
      break;
841
842
40
    case IMPORT_NAME_EXPORTAS:
843
40
      if (!import_name || !import_name[0])
844
23
  {
845
23
    _bfd_error_handler (_("%pB: missing import name for "
846
23
        "IMPORT_NAME_EXPORTAS for %s"),
847
23
            abfd, symbol_name);
848
23
    return false;
849
23
  }
850
17
      break;
851
852
17
    default:
853
      /* xgettext:c-format */
854
7
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
855
7
        abfd, import_name_type);
856
7
      return false;
857
206
    }
858
859
  /* Initialise local variables.
860
861
     Note these are kept in a structure rather than being
862
     declared as statics since bfd frowns on global variables.
863
864
     We are going to construct the contents of the BFD in memory,
865
     so allocate all the space that we will need right now.  */
866
176
  vars.bim
867
176
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
868
176
  if (vars.bim == NULL)
869
0
    return false;
870
871
176
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
872
176
  vars.bim->buffer = ptr;
873
176
  vars.bim->size   = ILF_DATA_SIZE;
874
176
  if (ptr == NULL)
875
0
    goto error_return;
876
877
  /* Initialise the pointers to regions of the memory and the
878
     other contents of the pe_ILF_vars structure as well.  */
879
176
  vars.sym_cache = (coff_symbol_type *) ptr;
880
176
  vars.sym_ptr   = (coff_symbol_type *) ptr;
881
176
  vars.sym_index = 0;
882
176
  ptr += SIZEOF_ILF_SYMS;
883
884
176
  vars.sym_table = (unsigned int *) ptr;
885
176
  vars.table_ptr = (unsigned int *) ptr;
886
176
  ptr += SIZEOF_ILF_SYM_TABLE;
887
888
176
  vars.native_syms = (combined_entry_type *) ptr;
889
176
  vars.native_ptr  = (combined_entry_type *) ptr;
890
176
  ptr += SIZEOF_ILF_NATIVE_SYMS;
891
892
176
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
893
176
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
894
176
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
895
896
176
  vars.esym_table = (SYMENT *) ptr;
897
176
  vars.esym_ptr   = (SYMENT *) ptr;
898
176
  ptr += SIZEOF_ILF_EXT_SYMS;
899
900
176
  vars.reltab   = (arelent *) ptr;
901
176
  vars.relcount = 0;
902
176
  ptr += SIZEOF_ILF_RELOCS;
903
904
176
  vars.int_reltab  = (struct internal_reloc *) ptr;
905
176
  ptr += SIZEOF_ILF_INT_RELOCS;
906
907
176
  vars.string_table = (char *) ptr;
908
176
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
909
176
  ptr += SIZEOF_ILF_STRINGS;
910
176
  vars.end_string_ptr = (char *) ptr;
911
912
  /* The remaining space in bim->buffer is used
913
     by the pe_ILF_make_a_section() function.  */
914
915
  /* PR 18758: Make sure that the data area is sufficiently aligned for
916
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
917
     the test of GCC_VERSION.  For other compilers we assume 8 byte
918
     alignment.  */
919
176
#if GCC_VERSION >= 3000
920
176
  alignment = __alignof__ (struct coff_section_tdata);
921
#else
922
  alignment = 8;
923
#endif
924
176
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
925
926
176
  vars.data = ptr;
927
176
  vars.abfd = abfd;
928
176
  vars.sec_index = 0;
929
176
  vars.magic = magic;
930
931
  /* Create the initial .idata$<n> sections:
932
     [.idata$2:  Import Directory Table -- not needed]
933
     .idata$4:  Import Lookup Table
934
     .idata$5:  Import Address Table
935
936
     Note we do not create a .idata$3 section as this is
937
     created for us by the linker script.  */
938
176
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
939
176
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
940
176
  if (id4 == NULL || id5 == NULL)
941
0
    goto error_return;
942
943
  /* Fill in the contents of these sections.  */
944
176
  if (import_name_type == IMPORT_ORDINAL)
945
41
    {
946
41
      if (ordinal == 0)
947
  /* See PR 20907 for a reproducer.  */
948
11
  goto error_return;
949
950
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
951
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
952
      ((unsigned int *) id4->contents)[0] = ordinal;
953
      ((unsigned int *) id4->contents)[1] = 0x80000000;
954
      ((unsigned int *) id5->contents)[0] = ordinal;
955
      ((unsigned int *) id5->contents)[1] = 0x80000000;
956
#else
957
30
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
958
30
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
959
30
#endif
960
30
    }
961
135
  else
962
135
    {
963
135
      char *symbol;
964
135
      unsigned int len;
965
966
      /* Create .idata$6 - the Hint Name Table.  */
967
135
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
968
135
      if (id6 == NULL)
969
0
  goto error_return;
970
971
      /* If necessary, trim the import symbol name.  */
972
135
      symbol = import_name;
973
974
      /* As used by MS compiler, '_', '@', and '?' are alternative
975
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
976
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
977
   of these is used for a symbol.  We strip this leading char for
978
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
979
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
980
981
135
      if (import_name_type != IMPORT_NAME
982
113
    && import_name_type != IMPORT_NAME_EXPORTAS)
983
96
  {
984
96
    char c = symbol[0];
985
986
    /* Check that we don't remove for targets with empty
987
       USER_LABEL_PREFIX the leading underscore.  */
988
96
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
989
82
        || c == '@' || c == '?')
990
32
      symbol++;
991
96
  }
992
993
135
      len = strlen (symbol);
994
135
      if (import_name_type == IMPORT_NAME_UNDECORATE)
995
63
  {
996
    /* Truncate at the first '@'.  */
997
63
    char *at = strchr (symbol, '@');
998
999
63
    if (at != NULL)
1000
17
      len = at - symbol;
1001
63
  }
1002
1003
135
      id6->contents[0] = ordinal & 0xff;
1004
135
      id6->contents[1] = ordinal >> 8;
1005
1006
135
      memcpy ((char *) id6->contents + 2, symbol, len);
1007
135
      id6->contents[len + 2] = '\0';
1008
135
    }
1009
1010
165
  if (import_name_type != IMPORT_ORDINAL)
1011
135
    {
1012
135
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1013
135
      pe_ILF_save_relocs (&vars, id4);
1014
1015
135
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1016
135
      pe_ILF_save_relocs (&vars, id5);
1017
135
    }
1018
1019
  /* Create an import symbol.  */
1020
165
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1021
165
  imp_sym   = vars.sym_ptr_ptr - 1;
1022
165
  imp_index = vars.sym_index - 1;
1023
1024
  /* Create extra sections depending upon the type of import we are
1025
     dealing with.  */
1026
165
  switch (import_type)
1027
165
    {
1028
0
      int i;
1029
1030
58
    case IMPORT_CODE:
1031
      /* CODE functions are special, in that they get a trampoline that
1032
   jumps to the main import symbol.  Create a .text section to hold it.
1033
   First we need to look up its contents in the jump table.  */
1034
116
      for (i = NUM_ENTRIES (jtab); i--;)
1035
116
  {
1036
116
    if (jtab[i].size == 0)
1037
58
      continue;
1038
58
    if (jtab[i].magic == magic)
1039
58
      break;
1040
58
  }
1041
      /* If we did not find a matching entry something is wrong.  */
1042
58
      if (i < 0)
1043
0
  abort ();
1044
1045
      /* Create the .text section.  */
1046
58
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1047
58
      if (text == NULL)
1048
0
  goto error_return;
1049
1050
      /* Copy in the jump code.  */
1051
58
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1052
1053
      /* Create a reloc for the data in the text section.  */
1054
#ifdef MIPS_ARCH_MAGIC_WINCE
1055
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1056
  {
1057
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1058
              (struct bfd_symbol **) imp_sym,
1059
              imp_index);
1060
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1061
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1062
              (struct bfd_symbol **) imp_sym,
1063
              imp_index);
1064
  }
1065
      else
1066
#endif
1067
#ifdef AMD64MAGIC
1068
      if (magic == AMD64MAGIC)
1069
  {
1070
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1071
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1072
              imp_index);
1073
  }
1074
      else
1075
#endif
1076
58
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1077
58
            BFD_RELOC_32, (asymbol **) imp_sym,
1078
58
            imp_index);
1079
1080
58
      pe_ILF_save_relocs (&vars, text);
1081
58
      break;
1082
1083
60
    case IMPORT_DATA:
1084
107
    case IMPORT_CONST:
1085
107
      break;
1086
1087
0
    default:
1088
      /* XXX code not yet written.  */
1089
0
      abort ();
1090
165
    }
1091
1092
  /* Now create a symbol describing the imported value.  */
1093
165
  switch (import_type)
1094
165
    {
1095
58
    case IMPORT_CODE:
1096
58
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1097
58
          BSF_NOT_AT_END | BSF_FUNCTION);
1098
1099
58
      break;
1100
1101
60
    case IMPORT_DATA:
1102
      /* Nothing to do here.  */
1103
60
      break;
1104
1105
47
    case IMPORT_CONST:
1106
47
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1107
47
      break;
1108
1109
0
    default:
1110
      /* XXX code not yet written.  */
1111
0
      abort ();
1112
165
    }
1113
1114
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1115
165
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1116
165
  if (ptr)
1117
22
    *ptr = 0;
1118
165
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1119
165
  if (ptr)
1120
22
    *ptr = '.';
1121
1122
  /* Initialise the bfd.  */
1123
165
  memset (&internal_f, 0, sizeof (internal_f));
1124
1125
165
  internal_f.f_magic  = magic;
1126
165
  internal_f.f_symptr = 0;
1127
165
  internal_f.f_nsyms  = 0;
1128
165
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1129
1130
165
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1131
165
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1132
0
    goto error_return;
1133
1134
165
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1135
0
    goto error_return;
1136
1137
165
  obj_pe (abfd) = true;
1138
#ifdef THUMBPEMAGIC
1139
  if (vars.magic == THUMBPEMAGIC)
1140
    /* Stop some linker warnings about thumb code not supporting
1141
       interworking.  */
1142
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1143
#endif
1144
1145
  /* Switch from file contents to memory contents.  */
1146
165
  bfd_cache_close (abfd);
1147
1148
165
  abfd->iostream = (void *) vars.bim;
1149
165
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1150
165
  abfd->iovec = &_bfd_memory_iovec;
1151
165
  abfd->where = 0;
1152
165
  abfd->origin = 0;
1153
165
  abfd->size = 0;
1154
165
  obj_sym_filepos (abfd) = 0;
1155
1156
  /* Point the bfd at the symbol table.  */
1157
165
  obj_symbols (abfd) = vars.sym_cache;
1158
165
  abfd->symcount = vars.sym_index;
1159
1160
165
  obj_raw_syments (abfd) = vars.native_syms;
1161
165
  obj_raw_syment_count (abfd) = vars.sym_index;
1162
165
  obj_coff_keep_raw_syms (abfd) = true;
1163
1164
165
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1165
165
  obj_coff_keep_syms (abfd) = true;
1166
1167
165
  obj_convert (abfd) = vars.sym_table;
1168
165
  obj_conv_table_size (abfd) = vars.sym_index;
1169
1170
165
  obj_coff_strings (abfd) = vars.string_table;
1171
165
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1172
165
  obj_coff_keep_strings (abfd) = true;
1173
1174
165
  return true;
1175
1176
11
 error_return:
1177
11
  free (vars.bim->buffer);
1178
11
  free (vars.bim);
1179
  return false;
1180
165
}
1181
1182
/* Cleanup function, returned from check_format hook.  */
1183
1184
static void
1185
pe_ILF_cleanup (bfd *abfd)
1186
98
{
1187
98
  coff_object_cleanup (abfd);
1188
1189
98
  struct bfd_in_memory *bim = abfd->iostream;
1190
98
  free (bim->buffer);
1191
98
  free (bim);
1192
98
  abfd->iostream = NULL;
1193
98
}
Unexecuted instantiation: pei-i386.c:pe_ILF_cleanup
Unexecuted instantiation: pei-x86_64.c:pe_ILF_cleanup
Unexecuted instantiation: pei-aarch64.c:pe_ILF_cleanup
Unexecuted instantiation: pei-ia64.c:pe_ILF_cleanup
Unexecuted instantiation: pei-loongarch64.c:pe_ILF_cleanup
Unexecuted instantiation: pei-riscv64.c:pe_ILF_cleanup
pei-arm-wince.c:pe_ILF_cleanup
Line
Count
Source
1186
49
{
1187
49
  coff_object_cleanup (abfd);
1188
1189
49
  struct bfd_in_memory *bim = abfd->iostream;
1190
49
  free (bim->buffer);
1191
49
  free (bim);
1192
  abfd->iostream = NULL;
1193
49
}
pei-arm.c:pe_ILF_cleanup
Line
Count
Source
1186
49
{
1187
49
  coff_object_cleanup (abfd);
1188
1189
49
  struct bfd_in_memory *bim = abfd->iostream;
1190
49
  free (bim->buffer);
1191
49
  free (bim);
1192
  abfd->iostream = NULL;
1193
49
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_cleanup
Unexecuted instantiation: pei-sh.c:pe_ILF_cleanup
1194
1195
/* We have detected an Import Library Format archive element.
1196
   Decode the element and return the appropriate target.  */
1197
1198
static bfd_cleanup
1199
pe_ILF_object_p (bfd *abfd)
1200
37.4k
{
1201
37.4k
  bfd_byte    buffer[14];
1202
37.4k
  bfd_byte *    ptr;
1203
37.4k
  char *    symbol_name;
1204
37.4k
  char *    source_dll;
1205
37.4k
  char *    import_name;
1206
37.4k
  unsigned int    machine;
1207
37.4k
  bfd_size_type   size;
1208
37.4k
  unsigned int    ordinal;
1209
37.4k
  unsigned int    types;
1210
37.4k
  unsigned int    magic;
1211
1212
  /* Upon entry the first six bytes of the ILF header have
1213
     already been read.  Now read the rest of the header.  */
1214
37.4k
  if (bfd_read (buffer, 14, abfd) != 14)
1215
612
    return NULL;
1216
1217
36.8k
  ptr = buffer;
1218
1219
36.8k
  machine = H_GET_16 (abfd, ptr);
1220
36.8k
  ptr += 2;
1221
1222
  /* Check that the machine type is recognised.  */
1223
36.8k
  magic = 0;
1224
1225
36.8k
  switch (machine)
1226
36.8k
    {
1227
113
    case IMAGE_FILE_MACHINE_UNKNOWN:
1228
167
    case IMAGE_FILE_MACHINE_ALPHA:
1229
221
    case IMAGE_FILE_MACHINE_ALPHA64:
1230
307
    case IMAGE_FILE_MACHINE_IA64:
1231
307
      break;
1232
1233
3.30k
    case IMAGE_FILE_MACHINE_I386:
1234
#ifdef I386MAGIC
1235
425
      magic = I386MAGIC;
1236
#endif
1237
3.30k
      break;
1238
1239
2.82k
    case IMAGE_FILE_MACHINE_AMD64:
1240
#ifdef AMD64MAGIC
1241
378
      magic = AMD64MAGIC;
1242
#endif
1243
2.82k
      break;
1244
1245
53
    case IMAGE_FILE_MACHINE_R3000:
1246
139
    case IMAGE_FILE_MACHINE_R4000:
1247
216
    case IMAGE_FILE_MACHINE_R10000:
1248
1249
261
    case IMAGE_FILE_MACHINE_MIPS16:
1250
342
    case IMAGE_FILE_MACHINE_MIPSFPU:
1251
428
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1252
#ifdef MIPS_ARCH_MAGIC_WINCE
1253
      magic = MIPS_ARCH_MAGIC_WINCE;
1254
#endif
1255
428
      break;
1256
1257
5.99k
    case IMAGE_FILE_MACHINE_SH3:
1258
8.01k
    case IMAGE_FILE_MACHINE_SH4:
1259
#ifdef SH_ARCH_MAGIC_WINCE
1260
935
      magic = SH_ARCH_MAGIC_WINCE;
1261
#endif
1262
8.01k
      break;
1263
1264
1.69k
    case IMAGE_FILE_MACHINE_ARM:
1265
#ifdef ARMPEMAGIC
1266
410
      magic = ARMPEMAGIC;
1267
#endif
1268
1.69k
      break;
1269
1270
3.48k
    case IMAGE_FILE_MACHINE_ARM64:
1271
#ifdef AARCH64MAGIC
1272
450
      magic = AARCH64MAGIC;
1273
#endif
1274
3.48k
      break;
1275
1276
3.45k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1277
#ifdef LOONGARCH64MAGIC
1278
451
      magic = LOONGARCH64MAGIC;
1279
#endif
1280
3.45k
      break;
1281
1282
3.26k
    case IMAGE_FILE_MACHINE_RISCV64:
1283
#ifdef RISCV64MAGIC
1284
421
      magic = RISCV64MAGIC;
1285
#endif
1286
3.26k
      break;
1287
1288
1.83k
    case IMAGE_FILE_MACHINE_THUMB:
1289
#ifdef THUMBPEMAGIC
1290
      {
1291
  extern const bfd_target TARGET_LITTLE_SYM;
1292
1293
388
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1294
382
    magic = THUMBPEMAGIC;
1295
      }
1296
#endif
1297
1.83k
      break;
1298
1299
0
    case IMAGE_FILE_MACHINE_POWERPC:
1300
      /* We no longer support PowerPC.  */
1301
8.23k
    default:
1302
8.23k
      _bfd_error_handler
1303
  /* xgettext:c-format */
1304
8.23k
  (_("%pB: unrecognised machine type (0x%x)"
1305
8.23k
     " in Import Library Format archive"),
1306
8.23k
   abfd, machine);
1307
8.23k
      bfd_set_error (bfd_error_malformed_archive);
1308
1309
8.23k
      return NULL;
1310
0
      break;
1311
36.8k
    }
1312
1313
28.6k
  if (magic == 0)
1314
24.7k
    {
1315
24.7k
      _bfd_error_handler
1316
  /* xgettext:c-format */
1317
24.7k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1318
24.7k
     " in Import Library Format archive"),
1319
24.7k
   abfd, machine);
1320
24.7k
      bfd_set_error (bfd_error_wrong_format);
1321
1322
24.7k
      return NULL;
1323
24.7k
    }
1324
1325
  /* We do not bother to check the date.
1326
     date = H_GET_32 (abfd, ptr);  */
1327
3.85k
  ptr += 4;
1328
1329
3.85k
  size = H_GET_32 (abfd, ptr);
1330
3.85k
  ptr += 4;
1331
1332
3.85k
  if (size == 0)
1333
83
    {
1334
83
      _bfd_error_handler
1335
83
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1336
83
      bfd_set_error (bfd_error_malformed_archive);
1337
1338
83
      return NULL;
1339
83
    }
1340
1341
3.76k
  ordinal = H_GET_16 (abfd, ptr);
1342
3.76k
  ptr += 2;
1343
1344
3.76k
  types = H_GET_16 (abfd, ptr);
1345
  /* ptr += 2; */
1346
1347
  /* Now read in the two strings that follow.  */
1348
3.76k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1349
3.76k
  if (ptr == NULL)
1350
1.77k
    return NULL;
1351
1352
1.99k
  symbol_name = (char *) ptr;
1353
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1354
1.99k
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1355
1356
  /* Verify that the strings are null terminated.  */
1357
1.99k
  if (ptr[size - 1] != 0
1358
1.46k
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1359
596
    {
1360
596
      _bfd_error_handler
1361
596
  (_("%pB: string not null terminated in ILF object file"), abfd);
1362
596
      bfd_set_error (bfd_error_malformed_archive);
1363
596
      bfd_release (abfd, ptr);
1364
596
      return NULL;
1365
596
    }
1366
1367
  /* An ILF file may contain a third string, after source_dll; this is
1368
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1369
     block of data is null terminated, ptr[size-1]==0, but we don't
1370
     know how many individual null terminated strings we have in there.
1371
1372
     First find the end of source_dll.  */
1373
1.39k
  import_name = source_dll + strlen (source_dll) + 1;
1374
1.39k
  if ((bfd_byte *) import_name >= ptr + size)
1375
464
    {
1376
      /* If this points at the end of the ptr+size block, we only had
1377
   two strings. */
1378
464
      import_name = NULL;
1379
464
    }
1380
1381
  /* Now construct the bfd.  */
1382
1.39k
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1383
1.39k
          source_dll, ordinal, types,
1384
1.39k
          import_name))
1385
392
    {
1386
392
      bfd_release (abfd, ptr);
1387
392
      return NULL;
1388
392
    }
1389
1390
1.00k
  return pe_ILF_cleanup;
1391
1.39k
}
pei-i386.c:pe_ILF_object_p
Line
Count
Source
1200
4.32k
{
1201
4.32k
  bfd_byte    buffer[14];
1202
4.32k
  bfd_byte *    ptr;
1203
4.32k
  char *    symbol_name;
1204
4.32k
  char *    source_dll;
1205
4.32k
  char *    import_name;
1206
4.32k
  unsigned int    machine;
1207
4.32k
  bfd_size_type   size;
1208
4.32k
  unsigned int    ordinal;
1209
4.32k
  unsigned int    types;
1210
4.32k
  unsigned int    magic;
1211
1212
  /* Upon entry the first six bytes of the ILF header have
1213
     already been read.  Now read the rest of the header.  */
1214
4.32k
  if (bfd_read (buffer, 14, abfd) != 14)
1215
68
    return NULL;
1216
1217
4.25k
  ptr = buffer;
1218
1219
4.25k
  machine = H_GET_16 (abfd, ptr);
1220
4.25k
  ptr += 2;
1221
1222
  /* Check that the machine type is recognised.  */
1223
4.25k
  magic = 0;
1224
1225
4.25k
  switch (machine)
1226
4.25k
    {
1227
12
    case IMAGE_FILE_MACHINE_UNKNOWN:
1228
18
    case IMAGE_FILE_MACHINE_ALPHA:
1229
24
    case IMAGE_FILE_MACHINE_ALPHA64:
1230
34
    case IMAGE_FILE_MACHINE_IA64:
1231
34
      break;
1232
1233
425
    case IMAGE_FILE_MACHINE_I386:
1234
425
#ifdef I386MAGIC
1235
425
      magic = I386MAGIC;
1236
425
#endif
1237
425
      break;
1238
1239
318
    case IMAGE_FILE_MACHINE_AMD64:
1240
#ifdef AMD64MAGIC
1241
      magic = AMD64MAGIC;
1242
#endif
1243
318
      break;
1244
1245
6
    case IMAGE_FILE_MACHINE_R3000:
1246
16
    case IMAGE_FILE_MACHINE_R4000:
1247
25
    case IMAGE_FILE_MACHINE_R10000:
1248
1249
30
    case IMAGE_FILE_MACHINE_MIPS16:
1250
39
    case IMAGE_FILE_MACHINE_MIPSFPU:
1251
49
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1252
#ifdef MIPS_ARCH_MAGIC_WINCE
1253
      magic = MIPS_ARCH_MAGIC_WINCE;
1254
#endif
1255
49
      break;
1256
1257
667
    case IMAGE_FILE_MACHINE_SH3:
1258
904
    case IMAGE_FILE_MACHINE_SH4:
1259
#ifdef SH_ARCH_MAGIC_WINCE
1260
      magic = SH_ARCH_MAGIC_WINCE;
1261
#endif
1262
904
      break;
1263
1264
183
    case IMAGE_FILE_MACHINE_ARM:
1265
#ifdef ARMPEMAGIC
1266
      magic = ARMPEMAGIC;
1267
#endif
1268
183
      break;
1269
1270
400
    case IMAGE_FILE_MACHINE_ARM64:
1271
#ifdef AARCH64MAGIC
1272
      magic = AARCH64MAGIC;
1273
#endif
1274
400
      break;
1275
1276
399
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1277
#ifdef LOONGARCH64MAGIC
1278
      magic = LOONGARCH64MAGIC;
1279
#endif
1280
399
      break;
1281
1282
373
    case IMAGE_FILE_MACHINE_RISCV64:
1283
#ifdef RISCV64MAGIC
1284
      magic = RISCV64MAGIC;
1285
#endif
1286
373
      break;
1287
1288
212
    case IMAGE_FILE_MACHINE_THUMB:
1289
#ifdef THUMBPEMAGIC
1290
      {
1291
  extern const bfd_target TARGET_LITTLE_SYM;
1292
1293
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1294
    magic = THUMBPEMAGIC;
1295
      }
1296
#endif
1297
212
      break;
1298
1299
0
    case IMAGE_FILE_MACHINE_POWERPC:
1300
      /* We no longer support PowerPC.  */
1301
960
    default:
1302
960
      _bfd_error_handler
1303
  /* xgettext:c-format */
1304
960
  (_("%pB: unrecognised machine type (0x%x)"
1305
960
     " in Import Library Format archive"),
1306
960
   abfd, machine);
1307
960
      bfd_set_error (bfd_error_malformed_archive);
1308
1309
960
      return NULL;
1310
0
      break;
1311
4.25k
    }
1312
1313
3.29k
  if (magic == 0)
1314
2.87k
    {
1315
2.87k
      _bfd_error_handler
1316
  /* xgettext:c-format */
1317
2.87k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1318
2.87k
     " in Import Library Format archive"),
1319
2.87k
   abfd, machine);
1320
2.87k
      bfd_set_error (bfd_error_wrong_format);
1321
1322
2.87k
      return NULL;
1323
2.87k
    }
1324
1325
  /* We do not bother to check the date.
1326
     date = H_GET_32 (abfd, ptr);  */
1327
425
  ptr += 4;
1328
1329
425
  size = H_GET_32 (abfd, ptr);
1330
425
  ptr += 4;
1331
1332
425
  if (size == 0)
1333
11
    {
1334
11
      _bfd_error_handler
1335
11
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1336
11
      bfd_set_error (bfd_error_malformed_archive);
1337
1338
11
      return NULL;
1339
11
    }
1340
1341
414
  ordinal = H_GET_16 (abfd, ptr);
1342
414
  ptr += 2;
1343
1344
414
  types = H_GET_16 (abfd, ptr);
1345
  /* ptr += 2; */
1346
1347
  /* Now read in the two strings that follow.  */
1348
414
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1349
414
  if (ptr == NULL)
1350
223
    return NULL;
1351
1352
191
  symbol_name = (char *) ptr;
1353
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1354
191
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1355
1356
  /* Verify that the strings are null terminated.  */
1357
191
  if (ptr[size - 1] != 0
1358
181
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1359
19
    {
1360
19
      _bfd_error_handler
1361
19
  (_("%pB: string not null terminated in ILF object file"), abfd);
1362
19
      bfd_set_error (bfd_error_malformed_archive);
1363
19
      bfd_release (abfd, ptr);
1364
19
      return NULL;
1365
19
    }
1366
1367
  /* An ILF file may contain a third string, after source_dll; this is
1368
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1369
     block of data is null terminated, ptr[size-1]==0, but we don't
1370
     know how many individual null terminated strings we have in there.
1371
1372
     First find the end of source_dll.  */
1373
172
  import_name = source_dll + strlen (source_dll) + 1;
1374
172
  if ((bfd_byte *) import_name >= ptr + size)
1375
54
    {
1376
      /* If this points at the end of the ptr+size block, we only had
1377
   two strings. */
1378
54
      import_name = NULL;
1379
54
    }
1380
1381
  /* Now construct the bfd.  */
1382
172
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1383
172
          source_dll, ordinal, types,
1384
172
          import_name))
1385
44
    {
1386
44
      bfd_release (abfd, ptr);
1387
44
      return NULL;
1388
44
    }
1389
1390
128
  return pe_ILF_cleanup;
1391
172
}
pei-x86_64.c:pe_ILF_object_p
Line
Count
Source
1200
4.31k
{
1201
4.31k
  bfd_byte    buffer[14];
1202
4.31k
  bfd_byte *    ptr;
1203
4.31k
  char *    symbol_name;
1204
4.31k
  char *    source_dll;
1205
4.31k
  char *    import_name;
1206
4.31k
  unsigned int    machine;
1207
4.31k
  bfd_size_type   size;
1208
4.31k
  unsigned int    ordinal;
1209
4.31k
  unsigned int    types;
1210
4.31k
  unsigned int    magic;
1211
1212
  /* Upon entry the first six bytes of the ILF header have
1213
     already been read.  Now read the rest of the header.  */
1214
4.31k
  if (bfd_read (buffer, 14, abfd) != 14)
1215
68
    return NULL;
1216
1217
4.24k
  ptr = buffer;
1218
1219
4.24k
  machine = H_GET_16 (abfd, ptr);
1220
4.24k
  ptr += 2;
1221
1222
  /* Check that the machine type is recognised.  */
1223
4.24k
  magic = 0;
1224
1225
4.24k
  switch (machine)
1226
4.24k
    {
1227
12
    case IMAGE_FILE_MACHINE_UNKNOWN:
1228
18
    case IMAGE_FILE_MACHINE_ALPHA:
1229
24
    case IMAGE_FILE_MACHINE_ALPHA64:
1230
34
    case IMAGE_FILE_MACHINE_IA64:
1231
34
      break;
1232
1233
372
    case IMAGE_FILE_MACHINE_I386:
1234
#ifdef I386MAGIC
1235
      magic = I386MAGIC;
1236
#endif
1237
372
      break;
1238
1239
378
    case IMAGE_FILE_MACHINE_AMD64:
1240
378
#ifdef AMD64MAGIC
1241
378
      magic = AMD64MAGIC;
1242
378
#endif
1243
378
      break;
1244
1245
6
    case IMAGE_FILE_MACHINE_R3000:
1246
16
    case IMAGE_FILE_MACHINE_R4000:
1247
25
    case IMAGE_FILE_MACHINE_R10000:
1248
1249
30
    case IMAGE_FILE_MACHINE_MIPS16:
1250
39
    case IMAGE_FILE_MACHINE_MIPSFPU:
1251
49
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1252
#ifdef MIPS_ARCH_MAGIC_WINCE
1253
      magic = MIPS_ARCH_MAGIC_WINCE;
1254
#endif
1255
49
      break;
1256
1257
657
    case IMAGE_FILE_MACHINE_SH3:
1258
891
    case IMAGE_FILE_MACHINE_SH4:
1259
#ifdef SH_ARCH_MAGIC_WINCE
1260
      magic = SH_ARCH_MAGIC_WINCE;
1261
#endif
1262
891
      break;
1263
1264
183
    case IMAGE_FILE_MACHINE_ARM:
1265
#ifdef ARMPEMAGIC
1266
      magic = ARMPEMAGIC;
1267
#endif
1268
183
      break;
1269
1270
400
    case IMAGE_FILE_MACHINE_ARM64:
1271
#ifdef AARCH64MAGIC
1272
      magic = AARCH64MAGIC;
1273
#endif
1274
400
      break;
1275
1276
399
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1277
#ifdef LOONGARCH64MAGIC
1278
      magic = LOONGARCH64MAGIC;
1279
#endif
1280
399
      break;
1281
1282
370
    case IMAGE_FILE_MACHINE_RISCV64:
1283
#ifdef RISCV64MAGIC
1284
      magic = RISCV64MAGIC;
1285
#endif
1286
370
      break;
1287
1288
212
    case IMAGE_FILE_MACHINE_THUMB:
1289
#ifdef THUMBPEMAGIC
1290
      {
1291
  extern const bfd_target TARGET_LITTLE_SYM;
1292
1293
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1294
    magic = THUMBPEMAGIC;
1295
      }
1296
#endif
1297
212
      break;
1298
1299
0
    case IMAGE_FILE_MACHINE_POWERPC:
1300
      /* We no longer support PowerPC.  */
1301
960
    default:
1302
960
      _bfd_error_handler
1303
  /* xgettext:c-format */
1304
960
  (_("%pB: unrecognised machine type (0x%x)"
1305
960
     " in Import Library Format archive"),
1306
960
   abfd, machine);
1307
960
      bfd_set_error (bfd_error_malformed_archive);
1308
1309
960
      return NULL;
1310
0
      break;
1311
4.24k
    }
1312
1313
3.28k
  if (magic == 0)
1314
2.91k
    {
1315
2.91k
      _bfd_error_handler
1316
  /* xgettext:c-format */
1317
2.91k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1318
2.91k
     " in Import Library Format archive"),
1319
2.91k
   abfd, machine);
1320
2.91k
      bfd_set_error (bfd_error_wrong_format);
1321
1322
2.91k
      return NULL;
1323
2.91k
    }
1324
1325
  /* We do not bother to check the date.
1326
     date = H_GET_32 (abfd, ptr);  */
1327
378
  ptr += 4;
1328
1329
378
  size = H_GET_32 (abfd, ptr);
1330
378
  ptr += 4;
1331
1332
378
  if (size == 0)
1333
9
    {
1334
9
      _bfd_error_handler
1335
9
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1336
9
      bfd_set_error (bfd_error_malformed_archive);
1337
1338
9
      return NULL;
1339
9
    }
1340
1341
369
  ordinal = H_GET_16 (abfd, ptr);
1342
369
  ptr += 2;
1343
1344
369
  types = H_GET_16 (abfd, ptr);
1345
  /* ptr += 2; */
1346
1347
  /* Now read in the two strings that follow.  */
1348
369
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1349
369
  if (ptr == NULL)
1350
166
    return NULL;
1351
1352
203
  symbol_name = (char *) ptr;
1353
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1354
203
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1355
1356
  /* Verify that the strings are null terminated.  */
1357
203
  if (ptr[size - 1] != 0
1358
193
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1359
19
    {
1360
19
      _bfd_error_handler
1361
19
  (_("%pB: string not null terminated in ILF object file"), abfd);
1362
19
      bfd_set_error (bfd_error_malformed_archive);
1363
19
      bfd_release (abfd, ptr);
1364
19
      return NULL;
1365
19
    }
1366
1367
  /* An ILF file may contain a third string, after source_dll; this is
1368
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1369
     block of data is null terminated, ptr[size-1]==0, but we don't
1370
     know how many individual null terminated strings we have in there.
1371
1372
     First find the end of source_dll.  */
1373
184
  import_name = source_dll + strlen (source_dll) + 1;
1374
184
  if ((bfd_byte *) import_name >= ptr + size)
1375
59
    {
1376
      /* If this points at the end of the ptr+size block, we only had
1377
   two strings. */
1378
59
      import_name = NULL;
1379
59
    }
1380
1381
  /* Now construct the bfd.  */
1382
184
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1383
184
          source_dll, ordinal, types,
1384
184
          import_name))
1385
46
    {
1386
46
      bfd_release (abfd, ptr);
1387
46
      return NULL;
1388
46
    }
1389
1390
138
  return pe_ILF_cleanup;
1391
184
}
pei-aarch64.c:pe_ILF_object_p
Line
Count
Source
1200
4.32k
{
1201
4.32k
  bfd_byte    buffer[14];
1202
4.32k
  bfd_byte *    ptr;
1203
4.32k
  char *    symbol_name;
1204
4.32k
  char *    source_dll;
1205
4.32k
  char *    import_name;
1206
4.32k
  unsigned int    machine;
1207
4.32k
  bfd_size_type   size;
1208
4.32k
  unsigned int    ordinal;
1209
4.32k
  unsigned int    types;
1210
4.32k
  unsigned int    magic;
1211
1212
  /* Upon entry the first six bytes of the ILF header have
1213
     already been read.  Now read the rest of the header.  */
1214
4.32k
  if (bfd_read (buffer, 14, abfd) != 14)
1215
68
    return NULL;
1216
1217
4.25k
  ptr = buffer;
1218
1219
4.25k
  machine = H_GET_16 (abfd, ptr);
1220
4.25k
  ptr += 2;
1221
1222
  /* Check that the machine type is recognised.  */
1223
4.25k
  magic = 0;
1224
1225
4.25k
  switch (machine)
1226
4.25k
    {
1227
12
    case IMAGE_FILE_MACHINE_UNKNOWN:
1228
18
    case IMAGE_FILE_MACHINE_ALPHA:
1229
24
    case IMAGE_FILE_MACHINE_ALPHA64:
1230
34
    case IMAGE_FILE_MACHINE_IA64:
1231
34
      break;
1232
1233
375
    case IMAGE_FILE_MACHINE_I386:
1234
#ifdef I386MAGIC
1235
      magic = I386MAGIC;
1236
#endif
1237
375
      break;
1238
1239
318
    case IMAGE_FILE_MACHINE_AMD64:
1240
#ifdef AMD64MAGIC
1241
      magic = AMD64MAGIC;
1242
#endif
1243
318
      break;
1244
1245
6
    case IMAGE_FILE_MACHINE_R3000:
1246
16
    case IMAGE_FILE_MACHINE_R4000:
1247
25
    case IMAGE_FILE_MACHINE_R10000:
1248
1249
30
    case IMAGE_FILE_MACHINE_MIPS16:
1250
39
    case IMAGE_FILE_MACHINE_MIPSFPU:
1251
49
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1252
#ifdef MIPS_ARCH_MAGIC_WINCE
1253
      magic = MIPS_ARCH_MAGIC_WINCE;
1254
#endif
1255
49
      break;
1256
1257
667
    case IMAGE_FILE_MACHINE_SH3:
1258
904
    case IMAGE_FILE_MACHINE_SH4:
1259
#ifdef SH_ARCH_MAGIC_WINCE
1260
      magic = SH_ARCH_MAGIC_WINCE;
1261
#endif
1262
904
      break;
1263
1264
185
    case IMAGE_FILE_MACHINE_ARM:
1265
#ifdef ARMPEMAGIC
1266
      magic = ARMPEMAGIC;
1267
#endif
1268
185
      break;
1269
1270
450
    case IMAGE_FILE_MACHINE_ARM64:
1271
450
#ifdef AARCH64MAGIC
1272
450
      magic = AARCH64MAGIC;
1273
450
#endif
1274
450
      break;
1275
1276
399
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1277
#ifdef LOONGARCH64MAGIC
1278
      magic = LOONGARCH64MAGIC;
1279
#endif
1280
399
      break;
1281
1282
373
    case IMAGE_FILE_MACHINE_RISCV64:
1283
#ifdef RISCV64MAGIC
1284
      magic = RISCV64MAGIC;
1285
#endif
1286
373
      break;
1287
1288
212
    case IMAGE_FILE_MACHINE_THUMB:
1289
#ifdef THUMBPEMAGIC
1290
      {
1291
  extern const bfd_target TARGET_LITTLE_SYM;
1292
1293
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1294
    magic = THUMBPEMAGIC;
1295
      }
1296
#endif
1297
212
      break;
1298
1299
0
    case IMAGE_FILE_MACHINE_POWERPC:
1300
      /* We no longer support PowerPC.  */
1301
960
    default:
1302
960
      _bfd_error_handler
1303
  /* xgettext:c-format */
1304
960
  (_("%pB: unrecognised machine type (0x%x)"
1305
960
     " in Import Library Format archive"),
1306
960
   abfd, machine);
1307
960
      bfd_set_error (bfd_error_malformed_archive);
1308
1309
960
      return NULL;
1310
0
      break;
1311
4.25k
    }
1312
1313
3.29k
  if (magic == 0)
1314
2.84k
    {
1315
2.84k
      _bfd_error_handler
1316
  /* xgettext:c-format */
1317
2.84k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1318
2.84k
     " in Import Library Format archive"),
1319
2.84k
   abfd, machine);
1320
2.84k
      bfd_set_error (bfd_error_wrong_format);
1321
1322
2.84k
      return NULL;
1323
2.84k
    }
1324
1325
  /* We do not bother to check the date.
1326
     date = H_GET_32 (abfd, ptr);  */
1327
450
  ptr += 4;
1328
1329
450
  size = H_GET_32 (abfd, ptr);
1330
450
  ptr += 4;
1331
1332
450
  if (size == 0)
1333
11
    {
1334
11
      _bfd_error_handler
1335
11
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1336
11
      bfd_set_error (bfd_error_malformed_archive);
1337
1338
11
      return NULL;
1339
11
    }
1340
1341
439
  ordinal = H_GET_16 (abfd, ptr);
1342
439
  ptr += 2;
1343
1344
439
  types = H_GET_16 (abfd, ptr);
1345
  /* ptr += 2; */
1346
1347
  /* Now read in the two strings that follow.  */
1348
439
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1349
439
  if (ptr == NULL)
1350
258
    return NULL;
1351
1352
181
  symbol_name = (char *) ptr;
1353
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1354
181
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1355
1356
  /* Verify that the strings are null terminated.  */
1357
181
  if (ptr[size - 1] != 0
1358
172
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1359
16
    {
1360
16
      _bfd_error_handler
1361
16
  (_("%pB: string not null terminated in ILF object file"), abfd);
1362
16
      bfd_set_error (bfd_error_malformed_archive);
1363
16
      bfd_release (abfd, ptr);
1364
16
      return NULL;
1365
16
    }
1366
1367
  /* An ILF file may contain a third string, after source_dll; this is
1368
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1369
     block of data is null terminated, ptr[size-1]==0, but we don't
1370
     know how many individual null terminated strings we have in there.
1371
1372
     First find the end of source_dll.  */
1373
165
  import_name = source_dll + strlen (source_dll) + 1;
1374
165
  if ((bfd_byte *) import_name >= ptr + size)
1375
37
    {
1376
      /* If this points at the end of the ptr+size block, we only had
1377
   two strings. */
1378
37
      import_name = NULL;
1379
37
    }
1380
1381
  /* Now construct the bfd.  */
1382
165
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1383
165
          source_dll, ordinal, types,
1384
165
          import_name))
1385
43
    {
1386
43
      bfd_release (abfd, ptr);
1387
43
      return NULL;
1388
43
    }
1389
1390
122
  return pe_ILF_cleanup;
1391
165
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_object_p
pei-loongarch64.c:pe_ILF_object_p
Line
Count
Source
1200
4.30k
{
1201
4.30k
  bfd_byte    buffer[14];
1202
4.30k
  bfd_byte *    ptr;
1203
4.30k
  char *    symbol_name;
1204
4.30k
  char *    source_dll;
1205
4.30k
  char *    import_name;
1206
4.30k
  unsigned int    machine;
1207
4.30k
  bfd_size_type   size;
1208
4.30k
  unsigned int    ordinal;
1209
4.30k
  unsigned int    types;
1210
4.30k
  unsigned int    magic;
1211
1212
  /* Upon entry the first six bytes of the ILF header have
1213
     already been read.  Now read the rest of the header.  */
1214
4.30k
  if (bfd_read (buffer, 14, abfd) != 14)
1215
68
    return NULL;
1216
1217
4.23k
  ptr = buffer;
1218
1219
4.23k
  machine = H_GET_16 (abfd, ptr);
1220
4.23k
  ptr += 2;
1221
1222
  /* Check that the machine type is recognised.  */
1223
4.23k
  magic = 0;
1224
1225
4.23k
  switch (machine)
1226
4.23k
    {
1227
12
    case IMAGE_FILE_MACHINE_UNKNOWN:
1228
18
    case IMAGE_FILE_MACHINE_ALPHA:
1229
24
    case IMAGE_FILE_MACHINE_ALPHA64:
1230
34
    case IMAGE_FILE_MACHINE_IA64:
1231
34
      break;
1232
1233
372
    case IMAGE_FILE_MACHINE_I386:
1234
#ifdef I386MAGIC
1235
      magic = I386MAGIC;
1236
#endif
1237
372
      break;
1238
1239
312
    case IMAGE_FILE_MACHINE_AMD64:
1240
#ifdef AMD64MAGIC
1241
      magic = AMD64MAGIC;
1242
#endif
1243
312
      break;
1244
1245
6
    case IMAGE_FILE_MACHINE_R3000:
1246
16
    case IMAGE_FILE_MACHINE_R4000:
1247
25
    case IMAGE_FILE_MACHINE_R10000:
1248
1249
30
    case IMAGE_FILE_MACHINE_MIPS16:
1250
39
    case IMAGE_FILE_MACHINE_MIPSFPU:
1251
49
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1252
#ifdef MIPS_ARCH_MAGIC_WINCE
1253
      magic = MIPS_ARCH_MAGIC_WINCE;
1254
#endif
1255
49
      break;
1256
1257
657
    case IMAGE_FILE_MACHINE_SH3:
1258
891
    case IMAGE_FILE_MACHINE_SH4:
1259
#ifdef SH_ARCH_MAGIC_WINCE
1260
      magic = SH_ARCH_MAGIC_WINCE;
1261
#endif
1262
891
      break;
1263
1264
183
    case IMAGE_FILE_MACHINE_ARM:
1265
#ifdef ARMPEMAGIC
1266
      magic = ARMPEMAGIC;
1267
#endif
1268
183
      break;
1269
1270
400
    case IMAGE_FILE_MACHINE_ARM64:
1271
#ifdef AARCH64MAGIC
1272
      magic = AARCH64MAGIC;
1273
#endif
1274
400
      break;
1275
1276
451
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1277
451
#ifdef LOONGARCH64MAGIC
1278
451
      magic = LOONGARCH64MAGIC;
1279
451
#endif
1280
451
      break;
1281
1282
370
    case IMAGE_FILE_MACHINE_RISCV64:
1283
#ifdef RISCV64MAGIC
1284
      magic = RISCV64MAGIC;
1285
#endif
1286
370
      break;
1287
1288
212
    case IMAGE_FILE_MACHINE_THUMB:
1289
#ifdef THUMBPEMAGIC
1290
      {
1291
  extern const bfd_target TARGET_LITTLE_SYM;
1292
1293
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1294
    magic = THUMBPEMAGIC;
1295
      }
1296
#endif
1297
212
      break;
1298
1299
0
    case IMAGE_FILE_MACHINE_POWERPC:
1300
      /* We no longer support PowerPC.  */
1301
960
    default:
1302
960
      _bfd_error_handler
1303
  /* xgettext:c-format */
1304
960
  (_("%pB: unrecognised machine type (0x%x)"
1305
960
     " in Import Library Format archive"),
1306
960
   abfd, machine);
1307
960
      bfd_set_error (bfd_error_malformed_archive);
1308
1309
960
      return NULL;
1310
0
      break;
1311
4.23k
    }
1312
1313
3.27k
  if (magic == 0)
1314
2.82k
    {
1315
2.82k
      _bfd_error_handler
1316
  /* xgettext:c-format */
1317
2.82k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1318
2.82k
     " in Import Library Format archive"),
1319
2.82k
   abfd, machine);
1320
2.82k
      bfd_set_error (bfd_error_wrong_format);
1321
1322
2.82k
      return NULL;
1323
2.82k
    }
1324
1325
  /* We do not bother to check the date.
1326
     date = H_GET_32 (abfd, ptr);  */
1327
451
  ptr += 4;
1328
1329
451
  size = H_GET_32 (abfd, ptr);
1330
451
  ptr += 4;
1331
1332
451
  if (size == 0)
1333
9
    {
1334
9
      _bfd_error_handler
1335
9
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1336
9
      bfd_set_error (bfd_error_malformed_archive);
1337
1338
9
      return NULL;
1339
9
    }
1340
1341
442
  ordinal = H_GET_16 (abfd, ptr);
1342
442
  ptr += 2;
1343
1344
442
  types = H_GET_16 (abfd, ptr);
1345
  /* ptr += 2; */
1346
1347
  /* Now read in the two strings that follow.  */
1348
442
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1349
442
  if (ptr == NULL)
1350
247
    return NULL;
1351
1352
195
  symbol_name = (char *) ptr;
1353
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1354
195
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1355
1356
  /* Verify that the strings are null terminated.  */
1357
195
  if (ptr[size - 1] != 0
1358
184
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1359
18
    {
1360
18
      _bfd_error_handler
1361
18
  (_("%pB: string not null terminated in ILF object file"), abfd);
1362
18
      bfd_set_error (bfd_error_malformed_archive);
1363
18
      bfd_release (abfd, ptr);
1364
18
      return NULL;
1365
18
    }
1366
1367
  /* An ILF file may contain a third string, after source_dll; this is
1368
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1369
     block of data is null terminated, ptr[size-1]==0, but we don't
1370
     know how many individual null terminated strings we have in there.
1371
1372
     First find the end of source_dll.  */
1373
177
  import_name = source_dll + strlen (source_dll) + 1;
1374
177
  if ((bfd_byte *) import_name >= ptr + size)
1375
68
    {
1376
      /* If this points at the end of the ptr+size block, we only had
1377
   two strings. */
1378
68
      import_name = NULL;
1379
68
    }
1380
1381
  /* Now construct the bfd.  */
1382
177
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1383
177
          source_dll, ordinal, types,
1384
177
          import_name))
1385
44
    {
1386
44
      bfd_release (abfd, ptr);
1387
44
      return NULL;
1388
44
    }
1389
1390
133
  return pe_ILF_cleanup;
1391
177
}
pei-riscv64.c:pe_ILF_object_p
Line
Count
Source
1200
4.32k
{
1201
4.32k
  bfd_byte    buffer[14];
1202
4.32k
  bfd_byte *    ptr;
1203
4.32k
  char *    symbol_name;
1204
4.32k
  char *    source_dll;
1205
4.32k
  char *    import_name;
1206
4.32k
  unsigned int    machine;
1207
4.32k
  bfd_size_type   size;
1208
4.32k
  unsigned int    ordinal;
1209
4.32k
  unsigned int    types;
1210
4.32k
  unsigned int    magic;
1211
1212
  /* Upon entry the first six bytes of the ILF header have
1213
     already been read.  Now read the rest of the header.  */
1214
4.32k
  if (bfd_read (buffer, 14, abfd) != 14)
1215
68
    return NULL;
1216
1217
4.25k
  ptr = buffer;
1218
1219
4.25k
  machine = H_GET_16 (abfd, ptr);
1220
4.25k
  ptr += 2;
1221
1222
  /* Check that the machine type is recognised.  */
1223
4.25k
  magic = 0;
1224
1225
4.25k
  switch (machine)
1226
4.25k
    {
1227
12
    case IMAGE_FILE_MACHINE_UNKNOWN:
1228
18
    case IMAGE_FILE_MACHINE_ALPHA:
1229
24
    case IMAGE_FILE_MACHINE_ALPHA64:
1230
34
    case IMAGE_FILE_MACHINE_IA64:
1231
34
      break;
1232
1233
372
    case IMAGE_FILE_MACHINE_I386:
1234
#ifdef I386MAGIC
1235
      magic = I386MAGIC;
1236
#endif
1237
372
      break;
1238
1239
318
    case IMAGE_FILE_MACHINE_AMD64:
1240
#ifdef AMD64MAGIC
1241
      magic = AMD64MAGIC;
1242
#endif
1243
318
      break;
1244
1245
6
    case IMAGE_FILE_MACHINE_R3000:
1246
16
    case IMAGE_FILE_MACHINE_R4000:
1247
25
    case IMAGE_FILE_MACHINE_R10000:
1248
1249
30
    case IMAGE_FILE_MACHINE_MIPS16:
1250
39
    case IMAGE_FILE_MACHINE_MIPSFPU:
1251
49
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1252
#ifdef MIPS_ARCH_MAGIC_WINCE
1253
      magic = MIPS_ARCH_MAGIC_WINCE;
1254
#endif
1255
49
      break;
1256
1257
667
    case IMAGE_FILE_MACHINE_SH3:
1258
904
    case IMAGE_FILE_MACHINE_SH4:
1259
#ifdef SH_ARCH_MAGIC_WINCE
1260
      magic = SH_ARCH_MAGIC_WINCE;
1261
#endif
1262
904
      break;
1263
1264
183
    case IMAGE_FILE_MACHINE_ARM:
1265
#ifdef ARMPEMAGIC
1266
      magic = ARMPEMAGIC;
1267
#endif
1268
183
      break;
1269
1270
400
    case IMAGE_FILE_MACHINE_ARM64:
1271
#ifdef AARCH64MAGIC
1272
      magic = AARCH64MAGIC;
1273
#endif
1274
400
      break;
1275
1276
399
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1277
#ifdef LOONGARCH64MAGIC
1278
      magic = LOONGARCH64MAGIC;
1279
#endif
1280
399
      break;
1281
1282
421
    case IMAGE_FILE_MACHINE_RISCV64:
1283
421
#ifdef RISCV64MAGIC
1284
421
      magic = RISCV64MAGIC;
1285
421
#endif
1286
421
      break;
1287
1288
212
    case IMAGE_FILE_MACHINE_THUMB:
1289
#ifdef THUMBPEMAGIC
1290
      {
1291
  extern const bfd_target TARGET_LITTLE_SYM;
1292
1293
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1294
    magic = THUMBPEMAGIC;
1295
      }
1296
#endif
1297
212
      break;
1298
1299
0
    case IMAGE_FILE_MACHINE_POWERPC:
1300
      /* We no longer support PowerPC.  */
1301
960
    default:
1302
960
      _bfd_error_handler
1303
  /* xgettext:c-format */
1304
960
  (_("%pB: unrecognised machine type (0x%x)"
1305
960
     " in Import Library Format archive"),
1306
960
   abfd, machine);
1307
960
      bfd_set_error (bfd_error_malformed_archive);
1308
1309
960
      return NULL;
1310
0
      break;
1311
4.25k
    }
1312
1313
3.29k
  if (magic == 0)
1314
2.87k
    {
1315
2.87k
      _bfd_error_handler
1316
  /* xgettext:c-format */
1317
2.87k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1318
2.87k
     " in Import Library Format archive"),
1319
2.87k
   abfd, machine);
1320
2.87k
      bfd_set_error (bfd_error_wrong_format);
1321
1322
2.87k
      return NULL;
1323
2.87k
    }
1324
1325
  /* We do not bother to check the date.
1326
     date = H_GET_32 (abfd, ptr);  */
1327
421
  ptr += 4;
1328
1329
421
  size = H_GET_32 (abfd, ptr);
1330
421
  ptr += 4;
1331
1332
421
  if (size == 0)
1333
11
    {
1334
11
      _bfd_error_handler
1335
11
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1336
11
      bfd_set_error (bfd_error_malformed_archive);
1337
1338
11
      return NULL;
1339
11
    }
1340
1341
410
  ordinal = H_GET_16 (abfd, ptr);
1342
410
  ptr += 2;
1343
1344
410
  types = H_GET_16 (abfd, ptr);
1345
  /* ptr += 2; */
1346
1347
  /* Now read in the two strings that follow.  */
1348
410
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1349
410
  if (ptr == NULL)
1350
225
    return NULL;
1351
1352
185
  symbol_name = (char *) ptr;
1353
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1354
185
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1355
1356
  /* Verify that the strings are null terminated.  */
1357
185
  if (ptr[size - 1] != 0
1358
176
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1359
18
    {
1360
18
      _bfd_error_handler
1361
18
  (_("%pB: string not null terminated in ILF object file"), abfd);
1362
18
      bfd_set_error (bfd_error_malformed_archive);
1363
18
      bfd_release (abfd, ptr);
1364
18
      return NULL;
1365
18
    }
1366
1367
  /* An ILF file may contain a third string, after source_dll; this is
1368
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1369
     block of data is null terminated, ptr[size-1]==0, but we don't
1370
     know how many individual null terminated strings we have in there.
1371
1372
     First find the end of source_dll.  */
1373
167
  import_name = source_dll + strlen (source_dll) + 1;
1374
167
  if ((bfd_byte *) import_name >= ptr + size)
1375
36
    {
1376
      /* If this points at the end of the ptr+size block, we only had
1377
   two strings. */
1378
36
      import_name = NULL;
1379
36
    }
1380
1381
  /* Now construct the bfd.  */
1382
167
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1383
167
          source_dll, ordinal, types,
1384
167
          import_name))
1385
43
    {
1386
43
      bfd_release (abfd, ptr);
1387
43
      return NULL;
1388
43
    }
1389
1390
124
  return pe_ILF_cleanup;
1391
167
}
pei-arm-wince.c:pe_ILF_object_p
Line
Count
Source
1200
3.97k
{
1201
3.97k
  bfd_byte    buffer[14];
1202
3.97k
  bfd_byte *    ptr;
1203
3.97k
  char *    symbol_name;
1204
3.97k
  char *    source_dll;
1205
3.97k
  char *    import_name;
1206
3.97k
  unsigned int    machine;
1207
3.97k
  bfd_size_type   size;
1208
3.97k
  unsigned int    ordinal;
1209
3.97k
  unsigned int    types;
1210
3.97k
  unsigned int    magic;
1211
1212
  /* Upon entry the first six bytes of the ILF header have
1213
     already been read.  Now read the rest of the header.  */
1214
3.97k
  if (bfd_read (buffer, 14, abfd) != 14)
1215
70
    return NULL;
1216
1217
3.90k
  ptr = buffer;
1218
1219
3.90k
  machine = H_GET_16 (abfd, ptr);
1220
3.90k
  ptr += 2;
1221
1222
  /* Check that the machine type is recognised.  */
1223
3.90k
  magic = 0;
1224
1225
3.90k
  switch (machine)
1226
3.90k
    {
1227
14
    case IMAGE_FILE_MACHINE_UNKNOWN:
1228
20
    case IMAGE_FILE_MACHINE_ALPHA:
1229
26
    case IMAGE_FILE_MACHINE_ALPHA64:
1230
35
    case IMAGE_FILE_MACHINE_IA64:
1231
35
      break;
1232
1233
349
    case IMAGE_FILE_MACHINE_I386:
1234
#ifdef I386MAGIC
1235
      magic = I386MAGIC;
1236
#endif
1237
349
      break;
1238
1239
294
    case IMAGE_FILE_MACHINE_AMD64:
1240
#ifdef AMD64MAGIC
1241
      magic = AMD64MAGIC;
1242
#endif
1243
294
      break;
1244
1245
6
    case IMAGE_FILE_MACHINE_R3000:
1246
15
    case IMAGE_FILE_MACHINE_R4000:
1247
23
    case IMAGE_FILE_MACHINE_R10000:
1248
1249
28
    case IMAGE_FILE_MACHINE_MIPS16:
1250
37
    case IMAGE_FILE_MACHINE_MIPSFPU:
1251
46
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1252
#ifdef MIPS_ARCH_MAGIC_WINCE
1253
      magic = MIPS_ARCH_MAGIC_WINCE;
1254
#endif
1255
46
      break;
1256
1257
659
    case IMAGE_FILE_MACHINE_SH3:
1258
862
    case IMAGE_FILE_MACHINE_SH4:
1259
#ifdef SH_ARCH_MAGIC_WINCE
1260
      magic = SH_ARCH_MAGIC_WINCE;
1261
#endif
1262
862
      break;
1263
1264
204
    case IMAGE_FILE_MACHINE_ARM:
1265
204
#ifdef ARMPEMAGIC
1266
204
      magic = ARMPEMAGIC;
1267
204
#endif
1268
204
      break;
1269
1270
359
    case IMAGE_FILE_MACHINE_ARM64:
1271
#ifdef AARCH64MAGIC
1272
      magic = AARCH64MAGIC;
1273
#endif
1274
359
      break;
1275
1276
353
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1277
#ifdef LOONGARCH64MAGIC
1278
      magic = LOONGARCH64MAGIC;
1279
#endif
1280
353
      break;
1281
1282
341
    case IMAGE_FILE_MACHINE_RISCV64:
1283
#ifdef RISCV64MAGIC
1284
      magic = RISCV64MAGIC;
1285
#endif
1286
341
      break;
1287
1288
194
    case IMAGE_FILE_MACHINE_THUMB:
1289
194
#ifdef THUMBPEMAGIC
1290
194
      {
1291
194
  extern const bfd_target TARGET_LITTLE_SYM;
1292
1293
194
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1294
191
    magic = THUMBPEMAGIC;
1295
194
      }
1296
194
#endif
1297
194
      break;
1298
1299
0
    case IMAGE_FILE_MACHINE_POWERPC:
1300
      /* We no longer support PowerPC.  */
1301
869
    default:
1302
869
      _bfd_error_handler
1303
  /* xgettext:c-format */
1304
869
  (_("%pB: unrecognised machine type (0x%x)"
1305
869
     " in Import Library Format archive"),
1306
869
   abfd, machine);
1307
869
      bfd_set_error (bfd_error_malformed_archive);
1308
1309
869
      return NULL;
1310
0
      break;
1311
3.90k
    }
1312
1313
3.03k
  if (magic == 0)
1314
2.64k
    {
1315
2.64k
      _bfd_error_handler
1316
  /* xgettext:c-format */
1317
2.64k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1318
2.64k
     " in Import Library Format archive"),
1319
2.64k
   abfd, machine);
1320
2.64k
      bfd_set_error (bfd_error_wrong_format);
1321
1322
2.64k
      return NULL;
1323
2.64k
    }
1324
1325
  /* We do not bother to check the date.
1326
     date = H_GET_32 (abfd, ptr);  */
1327
395
  ptr += 4;
1328
1329
395
  size = H_GET_32 (abfd, ptr);
1330
395
  ptr += 4;
1331
1332
395
  if (size == 0)
1333
10
    {
1334
10
      _bfd_error_handler
1335
10
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1336
10
      bfd_set_error (bfd_error_malformed_archive);
1337
1338
10
      return NULL;
1339
10
    }
1340
1341
385
  ordinal = H_GET_16 (abfd, ptr);
1342
385
  ptr += 2;
1343
1344
385
  types = H_GET_16 (abfd, ptr);
1345
  /* ptr += 2; */
1346
1347
  /* Now read in the two strings that follow.  */
1348
385
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1349
385
  if (ptr == NULL)
1350
221
    return NULL;
1351
1352
164
  symbol_name = (char *) ptr;
1353
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1354
164
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1355
1356
  /* Verify that the strings are null terminated.  */
1357
164
  if (ptr[size - 1] != 0
1358
151
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1359
22
    {
1360
22
      _bfd_error_handler
1361
22
  (_("%pB: string not null terminated in ILF object file"), abfd);
1362
22
      bfd_set_error (bfd_error_malformed_archive);
1363
22
      bfd_release (abfd, ptr);
1364
22
      return NULL;
1365
22
    }
1366
1367
  /* An ILF file may contain a third string, after source_dll; this is
1368
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1369
     block of data is null terminated, ptr[size-1]==0, but we don't
1370
     know how many individual null terminated strings we have in there.
1371
1372
     First find the end of source_dll.  */
1373
142
  import_name = source_dll + strlen (source_dll) + 1;
1374
142
  if ((bfd_byte *) import_name >= ptr + size)
1375
67
    {
1376
      /* If this points at the end of the ptr+size block, we only had
1377
   two strings. */
1378
67
      import_name = NULL;
1379
67
    }
1380
1381
  /* Now construct the bfd.  */
1382
142
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1383
142
          source_dll, ordinal, types,
1384
142
          import_name))
1385
47
    {
1386
47
      bfd_release (abfd, ptr);
1387
47
      return NULL;
1388
47
    }
1389
1390
95
  return pe_ILF_cleanup;
1391
142
}
pei-arm.c:pe_ILF_object_p
Line
Count
Source
1200
3.97k
{
1201
3.97k
  bfd_byte    buffer[14];
1202
3.97k
  bfd_byte *    ptr;
1203
3.97k
  char *    symbol_name;
1204
3.97k
  char *    source_dll;
1205
3.97k
  char *    import_name;
1206
3.97k
  unsigned int    machine;
1207
3.97k
  bfd_size_type   size;
1208
3.97k
  unsigned int    ordinal;
1209
3.97k
  unsigned int    types;
1210
3.97k
  unsigned int    magic;
1211
1212
  /* Upon entry the first six bytes of the ILF header have
1213
     already been read.  Now read the rest of the header.  */
1214
3.97k
  if (bfd_read (buffer, 14, abfd) != 14)
1215
70
    return NULL;
1216
1217
3.90k
  ptr = buffer;
1218
1219
3.90k
  machine = H_GET_16 (abfd, ptr);
1220
3.90k
  ptr += 2;
1221
1222
  /* Check that the machine type is recognised.  */
1223
3.90k
  magic = 0;
1224
1225
3.90k
  switch (machine)
1226
3.90k
    {
1227
14
    case IMAGE_FILE_MACHINE_UNKNOWN:
1228
20
    case IMAGE_FILE_MACHINE_ALPHA:
1229
26
    case IMAGE_FILE_MACHINE_ALPHA64:
1230
35
    case IMAGE_FILE_MACHINE_IA64:
1231
35
      break;
1232
1233
349
    case IMAGE_FILE_MACHINE_I386:
1234
#ifdef I386MAGIC
1235
      magic = I386MAGIC;
1236
#endif
1237
349
      break;
1238
1239
294
    case IMAGE_FILE_MACHINE_AMD64:
1240
#ifdef AMD64MAGIC
1241
      magic = AMD64MAGIC;
1242
#endif
1243
294
      break;
1244
1245
6
    case IMAGE_FILE_MACHINE_R3000:
1246
15
    case IMAGE_FILE_MACHINE_R4000:
1247
23
    case IMAGE_FILE_MACHINE_R10000:
1248
1249
28
    case IMAGE_FILE_MACHINE_MIPS16:
1250
37
    case IMAGE_FILE_MACHINE_MIPSFPU:
1251
46
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1252
#ifdef MIPS_ARCH_MAGIC_WINCE
1253
      magic = MIPS_ARCH_MAGIC_WINCE;
1254
#endif
1255
46
      break;
1256
1257
659
    case IMAGE_FILE_MACHINE_SH3:
1258
862
    case IMAGE_FILE_MACHINE_SH4:
1259
#ifdef SH_ARCH_MAGIC_WINCE
1260
      magic = SH_ARCH_MAGIC_WINCE;
1261
#endif
1262
862
      break;
1263
1264
206
    case IMAGE_FILE_MACHINE_ARM:
1265
206
#ifdef ARMPEMAGIC
1266
206
      magic = ARMPEMAGIC;
1267
206
#endif
1268
206
      break;
1269
1270
359
    case IMAGE_FILE_MACHINE_ARM64:
1271
#ifdef AARCH64MAGIC
1272
      magic = AARCH64MAGIC;
1273
#endif
1274
359
      break;
1275
1276
353
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1277
#ifdef LOONGARCH64MAGIC
1278
      magic = LOONGARCH64MAGIC;
1279
#endif
1280
353
      break;
1281
1282
341
    case IMAGE_FILE_MACHINE_RISCV64:
1283
#ifdef RISCV64MAGIC
1284
      magic = RISCV64MAGIC;
1285
#endif
1286
341
      break;
1287
1288
194
    case IMAGE_FILE_MACHINE_THUMB:
1289
194
#ifdef THUMBPEMAGIC
1290
194
      {
1291
194
  extern const bfd_target TARGET_LITTLE_SYM;
1292
1293
194
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1294
191
    magic = THUMBPEMAGIC;
1295
194
      }
1296
194
#endif
1297
194
      break;
1298
1299
0
    case IMAGE_FILE_MACHINE_POWERPC:
1300
      /* We no longer support PowerPC.  */
1301
869
    default:
1302
869
      _bfd_error_handler
1303
  /* xgettext:c-format */
1304
869
  (_("%pB: unrecognised machine type (0x%x)"
1305
869
     " in Import Library Format archive"),
1306
869
   abfd, machine);
1307
869
      bfd_set_error (bfd_error_malformed_archive);
1308
1309
869
      return NULL;
1310
0
      break;
1311
3.90k
    }
1312
1313
3.03k
  if (magic == 0)
1314
2.64k
    {
1315
2.64k
      _bfd_error_handler
1316
  /* xgettext:c-format */
1317
2.64k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1318
2.64k
     " in Import Library Format archive"),
1319
2.64k
   abfd, machine);
1320
2.64k
      bfd_set_error (bfd_error_wrong_format);
1321
1322
2.64k
      return NULL;
1323
2.64k
    }
1324
1325
  /* We do not bother to check the date.
1326
     date = H_GET_32 (abfd, ptr);  */
1327
397
  ptr += 4;
1328
1329
397
  size = H_GET_32 (abfd, ptr);
1330
397
  ptr += 4;
1331
1332
397
  if (size == 0)
1333
10
    {
1334
10
      _bfd_error_handler
1335
10
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1336
10
      bfd_set_error (bfd_error_malformed_archive);
1337
1338
10
      return NULL;
1339
10
    }
1340
1341
387
  ordinal = H_GET_16 (abfd, ptr);
1342
387
  ptr += 2;
1343
1344
387
  types = H_GET_16 (abfd, ptr);
1345
  /* ptr += 2; */
1346
1347
  /* Now read in the two strings that follow.  */
1348
387
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1349
387
  if (ptr == NULL)
1350
221
    return NULL;
1351
1352
166
  symbol_name = (char *) ptr;
1353
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1354
166
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1355
1356
  /* Verify that the strings are null terminated.  */
1357
166
  if (ptr[size - 1] != 0
1358
153
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1359
22
    {
1360
22
      _bfd_error_handler
1361
22
  (_("%pB: string not null terminated in ILF object file"), abfd);
1362
22
      bfd_set_error (bfd_error_malformed_archive);
1363
22
      bfd_release (abfd, ptr);
1364
22
      return NULL;
1365
22
    }
1366
1367
  /* An ILF file may contain a third string, after source_dll; this is
1368
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1369
     block of data is null terminated, ptr[size-1]==0, but we don't
1370
     know how many individual null terminated strings we have in there.
1371
1372
     First find the end of source_dll.  */
1373
144
  import_name = source_dll + strlen (source_dll) + 1;
1374
144
  if ((bfd_byte *) import_name >= ptr + size)
1375
68
    {
1376
      /* If this points at the end of the ptr+size block, we only had
1377
   two strings. */
1378
68
      import_name = NULL;
1379
68
    }
1380
1381
  /* Now construct the bfd.  */
1382
144
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1383
144
          source_dll, ordinal, types,
1384
144
          import_name))
1385
47
    {
1386
47
      bfd_release (abfd, ptr);
1387
47
      return NULL;
1388
47
    }
1389
1390
97
  return pe_ILF_cleanup;
1391
144
}
pei-mcore.c:pe_ILF_object_p
Line
Count
Source
1200
3.97k
{
1201
3.97k
  bfd_byte    buffer[14];
1202
3.97k
  bfd_byte *    ptr;
1203
3.97k
  char *    symbol_name;
1204
3.97k
  char *    source_dll;
1205
3.97k
  char *    import_name;
1206
3.97k
  unsigned int    machine;
1207
3.97k
  bfd_size_type   size;
1208
3.97k
  unsigned int    ordinal;
1209
3.97k
  unsigned int    types;
1210
3.97k
  unsigned int    magic;
1211
1212
  /* Upon entry the first six bytes of the ILF header have
1213
     already been read.  Now read the rest of the header.  */
1214
3.97k
  if (bfd_read (buffer, 14, abfd) != 14)
1215
70
    return NULL;
1216
1217
3.90k
  ptr = buffer;
1218
1219
3.90k
  machine = H_GET_16 (abfd, ptr);
1220
3.90k
  ptr += 2;
1221
1222
  /* Check that the machine type is recognised.  */
1223
3.90k
  magic = 0;
1224
1225
3.90k
  switch (machine)
1226
3.90k
    {
1227
14
    case IMAGE_FILE_MACHINE_UNKNOWN:
1228
20
    case IMAGE_FILE_MACHINE_ALPHA:
1229
26
    case IMAGE_FILE_MACHINE_ALPHA64:
1230
35
    case IMAGE_FILE_MACHINE_IA64:
1231
35
      break;
1232
1233
346
    case IMAGE_FILE_MACHINE_I386:
1234
#ifdef I386MAGIC
1235
      magic = I386MAGIC;
1236
#endif
1237
346
      break;
1238
1239
294
    case IMAGE_FILE_MACHINE_AMD64:
1240
#ifdef AMD64MAGIC
1241
      magic = AMD64MAGIC;
1242
#endif
1243
294
      break;
1244
1245
6
    case IMAGE_FILE_MACHINE_R3000:
1246
15
    case IMAGE_FILE_MACHINE_R4000:
1247
23
    case IMAGE_FILE_MACHINE_R10000:
1248
1249
28
    case IMAGE_FILE_MACHINE_MIPS16:
1250
37
    case IMAGE_FILE_MACHINE_MIPSFPU:
1251
46
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1252
#ifdef MIPS_ARCH_MAGIC_WINCE
1253
      magic = MIPS_ARCH_MAGIC_WINCE;
1254
#endif
1255
46
      break;
1256
1257
659
    case IMAGE_FILE_MACHINE_SH3:
1258
862
    case IMAGE_FILE_MACHINE_SH4:
1259
#ifdef SH_ARCH_MAGIC_WINCE
1260
      magic = SH_ARCH_MAGIC_WINCE;
1261
#endif
1262
862
      break;
1263
1264
204
    case IMAGE_FILE_MACHINE_ARM:
1265
#ifdef ARMPEMAGIC
1266
      magic = ARMPEMAGIC;
1267
#endif
1268
204
      break;
1269
1270
359
    case IMAGE_FILE_MACHINE_ARM64:
1271
#ifdef AARCH64MAGIC
1272
      magic = AARCH64MAGIC;
1273
#endif
1274
359
      break;
1275
1276
353
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1277
#ifdef LOONGARCH64MAGIC
1278
      magic = LOONGARCH64MAGIC;
1279
#endif
1280
353
      break;
1281
1282
341
    case IMAGE_FILE_MACHINE_RISCV64:
1283
#ifdef RISCV64MAGIC
1284
      magic = RISCV64MAGIC;
1285
#endif
1286
341
      break;
1287
1288
194
    case IMAGE_FILE_MACHINE_THUMB:
1289
#ifdef THUMBPEMAGIC
1290
      {
1291
  extern const bfd_target TARGET_LITTLE_SYM;
1292
1293
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1294
    magic = THUMBPEMAGIC;
1295
      }
1296
#endif
1297
194
      break;
1298
1299
0
    case IMAGE_FILE_MACHINE_POWERPC:
1300
      /* We no longer support PowerPC.  */
1301
869
    default:
1302
869
      _bfd_error_handler
1303
  /* xgettext:c-format */
1304
869
  (_("%pB: unrecognised machine type (0x%x)"
1305
869
     " in Import Library Format archive"),
1306
869
   abfd, machine);
1307
869
      bfd_set_error (bfd_error_malformed_archive);
1308
1309
869
      return NULL;
1310
0
      break;
1311
3.90k
    }
1312
1313
3.03k
  if (magic == 0)
1314
3.03k
    {
1315
3.03k
      _bfd_error_handler
1316
  /* xgettext:c-format */
1317
3.03k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1318
3.03k
     " in Import Library Format archive"),
1319
3.03k
   abfd, machine);
1320
3.03k
      bfd_set_error (bfd_error_wrong_format);
1321
1322
3.03k
      return NULL;
1323
3.03k
    }
1324
1325
  /* We do not bother to check the date.
1326
     date = H_GET_32 (abfd, ptr);  */
1327
0
  ptr += 4;
1328
1329
0
  size = H_GET_32 (abfd, ptr);
1330
0
  ptr += 4;
1331
1332
0
  if (size == 0)
1333
0
    {
1334
0
      _bfd_error_handler
1335
0
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1336
0
      bfd_set_error (bfd_error_malformed_archive);
1337
1338
0
      return NULL;
1339
0
    }
1340
1341
0
  ordinal = H_GET_16 (abfd, ptr);
1342
0
  ptr += 2;
1343
1344
0
  types = H_GET_16 (abfd, ptr);
1345
  /* ptr += 2; */
1346
1347
  /* Now read in the two strings that follow.  */
1348
0
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1349
0
  if (ptr == NULL)
1350
0
    return NULL;
1351
1352
0
  symbol_name = (char *) ptr;
1353
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1354
0
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1355
1356
  /* Verify that the strings are null terminated.  */
1357
0
  if (ptr[size - 1] != 0
1358
0
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1359
0
    {
1360
0
      _bfd_error_handler
1361
0
  (_("%pB: string not null terminated in ILF object file"), abfd);
1362
0
      bfd_set_error (bfd_error_malformed_archive);
1363
0
      bfd_release (abfd, ptr);
1364
0
      return NULL;
1365
0
    }
1366
1367
  /* An ILF file may contain a third string, after source_dll; this is
1368
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1369
     block of data is null terminated, ptr[size-1]==0, but we don't
1370
     know how many individual null terminated strings we have in there.
1371
1372
     First find the end of source_dll.  */
1373
0
  import_name = source_dll + strlen (source_dll) + 1;
1374
0
  if ((bfd_byte *) import_name >= ptr + size)
1375
0
    {
1376
      /* If this points at the end of the ptr+size block, we only had
1377
   two strings. */
1378
0
      import_name = NULL;
1379
0
    }
1380
1381
  /* Now construct the bfd.  */
1382
0
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1383
0
          source_dll, ordinal, types,
1384
0
          import_name))
1385
0
    {
1386
0
      bfd_release (abfd, ptr);
1387
0
      return NULL;
1388
0
    }
1389
1390
0
  return pe_ILF_cleanup;
1391
0
}
pei-sh.c:pe_ILF_object_p
Line
Count
Source
1200
3.94k
{
1201
3.94k
  bfd_byte    buffer[14];
1202
3.94k
  bfd_byte *    ptr;
1203
3.94k
  char *    symbol_name;
1204
3.94k
  char *    source_dll;
1205
3.94k
  char *    import_name;
1206
3.94k
  unsigned int    machine;
1207
3.94k
  bfd_size_type   size;
1208
3.94k
  unsigned int    ordinal;
1209
3.94k
  unsigned int    types;
1210
3.94k
  unsigned int    magic;
1211
1212
  /* Upon entry the first six bytes of the ILF header have
1213
     already been read.  Now read the rest of the header.  */
1214
3.94k
  if (bfd_read (buffer, 14, abfd) != 14)
1215
62
    return NULL;
1216
1217
3.88k
  ptr = buffer;
1218
1219
3.88k
  machine = H_GET_16 (abfd, ptr);
1220
3.88k
  ptr += 2;
1221
1222
  /* Check that the machine type is recognised.  */
1223
3.88k
  magic = 0;
1224
1225
3.88k
  switch (machine)
1226
3.88k
    {
1227
11
    case IMAGE_FILE_MACHINE_UNKNOWN:
1228
17
    case IMAGE_FILE_MACHINE_ALPHA:
1229
23
    case IMAGE_FILE_MACHINE_ALPHA64:
1230
32
    case IMAGE_FILE_MACHINE_IA64:
1231
32
      break;
1232
1233
346
    case IMAGE_FILE_MACHINE_I386:
1234
#ifdef I386MAGIC
1235
      magic = I386MAGIC;
1236
#endif
1237
346
      break;
1238
1239
294
    case IMAGE_FILE_MACHINE_AMD64:
1240
#ifdef AMD64MAGIC
1241
      magic = AMD64MAGIC;
1242
#endif
1243
294
      break;
1244
1245
5
    case IMAGE_FILE_MACHINE_R3000:
1246
14
    case IMAGE_FILE_MACHINE_R4000:
1247
22
    case IMAGE_FILE_MACHINE_R10000:
1248
1249
27
    case IMAGE_FILE_MACHINE_MIPS16:
1250
36
    case IMAGE_FILE_MACHINE_MIPSFPU:
1251
45
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1252
#ifdef MIPS_ARCH_MAGIC_WINCE
1253
      magic = MIPS_ARCH_MAGIC_WINCE;
1254
#endif
1255
45
      break;
1256
1257
699
    case IMAGE_FILE_MACHINE_SH3:
1258
935
    case IMAGE_FILE_MACHINE_SH4:
1259
935
#ifdef SH_ARCH_MAGIC_WINCE
1260
935
      magic = SH_ARCH_MAGIC_WINCE;
1261
935
#endif
1262
935
      break;
1263
1264
163
    case IMAGE_FILE_MACHINE_ARM:
1265
#ifdef ARMPEMAGIC
1266
      magic = ARMPEMAGIC;
1267
#endif
1268
163
      break;
1269
1270
359
    case IMAGE_FILE_MACHINE_ARM64:
1271
#ifdef AARCH64MAGIC
1272
      magic = AARCH64MAGIC;
1273
#endif
1274
359
      break;
1275
1276
353
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1277
#ifdef LOONGARCH64MAGIC
1278
      magic = LOONGARCH64MAGIC;
1279
#endif
1280
353
      break;
1281
1282
338
    case IMAGE_FILE_MACHINE_RISCV64:
1283
#ifdef RISCV64MAGIC
1284
      magic = RISCV64MAGIC;
1285
#endif
1286
338
      break;
1287
1288
191
    case IMAGE_FILE_MACHINE_THUMB:
1289
#ifdef THUMBPEMAGIC
1290
      {
1291
  extern const bfd_target TARGET_LITTLE_SYM;
1292
1293
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1294
    magic = THUMBPEMAGIC;
1295
      }
1296
#endif
1297
191
      break;
1298
1299
0
    case IMAGE_FILE_MACHINE_POWERPC:
1300
      /* We no longer support PowerPC.  */
1301
828
    default:
1302
828
      _bfd_error_handler
1303
  /* xgettext:c-format */
1304
828
  (_("%pB: unrecognised machine type (0x%x)"
1305
828
     " in Import Library Format archive"),
1306
828
   abfd, machine);
1307
828
      bfd_set_error (bfd_error_malformed_archive);
1308
1309
828
      return NULL;
1310
0
      break;
1311
3.88k
    }
1312
1313
3.05k
  if (magic == 0)
1314
2.12k
    {
1315
2.12k
      _bfd_error_handler
1316
  /* xgettext:c-format */
1317
2.12k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1318
2.12k
     " in Import Library Format archive"),
1319
2.12k
   abfd, machine);
1320
2.12k
      bfd_set_error (bfd_error_wrong_format);
1321
1322
2.12k
      return NULL;
1323
2.12k
    }
1324
1325
  /* We do not bother to check the date.
1326
     date = H_GET_32 (abfd, ptr);  */
1327
935
  ptr += 4;
1328
1329
935
  size = H_GET_32 (abfd, ptr);
1330
935
  ptr += 4;
1331
1332
935
  if (size == 0)
1333
12
    {
1334
12
      _bfd_error_handler
1335
12
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1336
12
      bfd_set_error (bfd_error_malformed_archive);
1337
1338
12
      return NULL;
1339
12
    }
1340
1341
923
  ordinal = H_GET_16 (abfd, ptr);
1342
923
  ptr += 2;
1343
1344
923
  types = H_GET_16 (abfd, ptr);
1345
  /* ptr += 2; */
1346
1347
  /* Now read in the two strings that follow.  */
1348
923
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1349
923
  if (ptr == NULL)
1350
218
    return NULL;
1351
1352
705
  symbol_name = (char *) ptr;
1353
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1354
705
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1355
1356
  /* Verify that the strings are null terminated.  */
1357
705
  if (ptr[size - 1] != 0
1358
250
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1359
462
    {
1360
462
      _bfd_error_handler
1361
462
  (_("%pB: string not null terminated in ILF object file"), abfd);
1362
462
      bfd_set_error (bfd_error_malformed_archive);
1363
462
      bfd_release (abfd, ptr);
1364
462
      return NULL;
1365
462
    }
1366
1367
  /* An ILF file may contain a third string, after source_dll; this is
1368
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1369
     block of data is null terminated, ptr[size-1]==0, but we don't
1370
     know how many individual null terminated strings we have in there.
1371
1372
     First find the end of source_dll.  */
1373
243
  import_name = source_dll + strlen (source_dll) + 1;
1374
243
  if ((bfd_byte *) import_name >= ptr + size)
1375
75
    {
1376
      /* If this points at the end of the ptr+size block, we only had
1377
   two strings. */
1378
75
      import_name = NULL;
1379
75
    }
1380
1381
  /* Now construct the bfd.  */
1382
243
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1383
243
          source_dll, ordinal, types,
1384
243
          import_name))
1385
78
    {
1386
78
      bfd_release (abfd, ptr);
1387
78
      return NULL;
1388
78
    }
1389
1390
165
  return pe_ILF_cleanup;
1391
243
}
1392
1393
static void
1394
pe_bfd_read_buildid (bfd *abfd)
1395
48.5k
{
1396
48.5k
  pe_data_type *pe = pe_data (abfd);
1397
48.5k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
48.5k
  asection *section;
1399
48.5k
  bfd_byte *data = 0;
1400
48.5k
  bfd_size_type dataoff;
1401
48.5k
  unsigned int i;
1402
48.5k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
48.5k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
48.5k
  if (size == 0)
1406
28.6k
    return;
1407
1408
19.8k
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
128k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
118k
    {
1413
118k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
9.90k
  break;
1415
118k
    }
1416
1417
19.8k
  if (section == NULL)
1418
9.98k
    return;
1419
1420
9.90k
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
451
    return;
1422
1423
9.44k
  dataoff = addr - section->vma;
1424
1425
  /* PR 20605 and 22373: Make sure that the data is really there.
1426
     Note - since we are dealing with unsigned quantities we have
1427
     to be careful to check for potential overflows.  */
1428
9.44k
  if (dataoff >= section->size
1429
9.44k
      || size > section->size - dataoff)
1430
3.35k
    {
1431
3.35k
      _bfd_error_handler
1432
3.35k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
3.35k
   abfd);
1434
3.35k
      return;
1435
3.35k
    }
1436
1437
  /* Read the whole section. */
1438
6.09k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
1.80k
    {
1440
1.80k
      free (data);
1441
1.80k
      return;
1442
1.80k
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
282k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
279k
    {
1447
279k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
279k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
279k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
279k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
279k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
1.75k
  {
1455
1.75k
    char buffer[256 + 1];
1456
1.75k
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1457
1458
    /*
1459
      The debug entry doesn't have to have to be in a section, in which
1460
      case AddressOfRawData is 0, so always use PointerToRawData.
1461
    */
1462
1.75k
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
1.75k
                (file_ptr) idd.PointerToRawData,
1464
1.75k
                idd.SizeOfData, cvinfo, NULL))
1465
103
      {
1466
103
        struct bfd_build_id *build_id;
1467
103
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1468
1469
103
        build_id = bfd_alloc (abfd, bidlen);
1470
103
        if (build_id)
1471
103
    {
1472
103
      build_id->size = cvinfo->SignatureLength;
1473
103
      memcpy(build_id->data, cvinfo->Signature,
1474
103
       cvinfo->SignatureLength);
1475
103
      abfd->build_id = build_id;
1476
103
    }
1477
103
      }
1478
1.75k
    break;
1479
1.75k
  }
1480
279k
    }
1481
1482
4.29k
  free (data);
1483
4.29k
}
pei-i386.c:pe_bfd_read_buildid
Line
Count
Source
1395
9.66k
{
1396
9.66k
  pe_data_type *pe = pe_data (abfd);
1397
9.66k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
9.66k
  asection *section;
1399
9.66k
  bfd_byte *data = 0;
1400
9.66k
  bfd_size_type dataoff;
1401
9.66k
  unsigned int i;
1402
9.66k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
9.66k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
9.66k
  if (size == 0)
1406
7.21k
    return;
1407
1408
2.45k
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
13.9k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
12.6k
    {
1413
12.6k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
1.11k
  break;
1415
12.6k
    }
1416
1417
2.45k
  if (section == NULL)
1418
1.33k
    return;
1419
1420
1.11k
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
68
    return;
1422
1423
1.04k
  dataoff = addr - section->vma;
1424
1425
  /* PR 20605 and 22373: Make sure that the data is really there.
1426
     Note - since we are dealing with unsigned quantities we have
1427
     to be careful to check for potential overflows.  */
1428
1.04k
  if (dataoff >= section->size
1429
1.04k
      || size > section->size - dataoff)
1430
516
    {
1431
516
      _bfd_error_handler
1432
516
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
516
   abfd);
1434
516
      return;
1435
516
    }
1436
1437
  /* Read the whole section. */
1438
533
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
217
    {
1440
217
      free (data);
1441
217
      return;
1442
217
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
5.77k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
5.64k
    {
1447
5.64k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
5.64k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
5.64k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
5.64k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
5.64k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
192
  {
1455
192
    char buffer[256 + 1];
1456
192
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1457
1458
    /*
1459
      The debug entry doesn't have to have to be in a section, in which
1460
      case AddressOfRawData is 0, so always use PointerToRawData.
1461
    */
1462
192
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
192
                (file_ptr) idd.PointerToRawData,
1464
192
                idd.SizeOfData, cvinfo, NULL))
1465
14
      {
1466
14
        struct bfd_build_id *build_id;
1467
14
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1468
1469
14
        build_id = bfd_alloc (abfd, bidlen);
1470
14
        if (build_id)
1471
14
    {
1472
14
      build_id->size = cvinfo->SignatureLength;
1473
14
      memcpy(build_id->data, cvinfo->Signature,
1474
14
       cvinfo->SignatureLength);
1475
14
      abfd->build_id = build_id;
1476
14
    }
1477
14
      }
1478
192
    break;
1479
192
  }
1480
5.64k
    }
1481
1482
316
  free (data);
1483
316
}
pei-x86_64.c:pe_bfd_read_buildid
Line
Count
Source
1395
6.37k
{
1396
6.37k
  pe_data_type *pe = pe_data (abfd);
1397
6.37k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
6.37k
  asection *section;
1399
6.37k
  bfd_byte *data = 0;
1400
6.37k
  bfd_size_type dataoff;
1401
6.37k
  unsigned int i;
1402
6.37k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
6.37k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
6.37k
  if (size == 0)
1406
4.11k
    return;
1407
1408
2.26k
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
24.0k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
22.7k
    {
1413
22.7k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
952
  break;
1415
22.7k
    }
1416
1417
2.26k
  if (section == NULL)
1418
1.30k
    return;
1419
1420
952
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
38
    return;
1422
1423
914
  dataoff = addr - section->vma;
1424
1425
  /* PR 20605 and 22373: Make sure that the data is really there.
1426
     Note - since we are dealing with unsigned quantities we have
1427
     to be careful to check for potential overflows.  */
1428
914
  if (dataoff >= section->size
1429
914
      || size > section->size - dataoff)
1430
313
    {
1431
313
      _bfd_error_handler
1432
313
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
313
   abfd);
1434
313
      return;
1435
313
    }
1436
1437
  /* Read the whole section. */
1438
601
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
186
    {
1440
186
      free (data);
1441
186
      return;
1442
186
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
9.44k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
9.33k
    {
1447
9.33k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
9.33k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
9.33k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
9.33k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
9.33k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
299
  {
1455
299
    char buffer[256 + 1];
1456
299
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1457
1458
    /*
1459
      The debug entry doesn't have to have to be in a section, in which
1460
      case AddressOfRawData is 0, so always use PointerToRawData.
1461
    */
1462
299
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
299
                (file_ptr) idd.PointerToRawData,
1464
299
                idd.SizeOfData, cvinfo, NULL))
1465
38
      {
1466
38
        struct bfd_build_id *build_id;
1467
38
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1468
1469
38
        build_id = bfd_alloc (abfd, bidlen);
1470
38
        if (build_id)
1471
38
    {
1472
38
      build_id->size = cvinfo->SignatureLength;
1473
38
      memcpy(build_id->data, cvinfo->Signature,
1474
38
       cvinfo->SignatureLength);
1475
38
      abfd->build_id = build_id;
1476
38
    }
1477
38
      }
1478
299
    break;
1479
299
  }
1480
9.33k
    }
1481
1482
415
  free (data);
1483
415
}
pei-aarch64.c:pe_bfd_read_buildid
Line
Count
Source
1395
6.82k
{
1396
6.82k
  pe_data_type *pe = pe_data (abfd);
1397
6.82k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
6.82k
  asection *section;
1399
6.82k
  bfd_byte *data = 0;
1400
6.82k
  bfd_size_type dataoff;
1401
6.82k
  unsigned int i;
1402
6.82k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
6.82k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
6.82k
  if (size == 0)
1406
2.39k
    return;
1407
1408
4.43k
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
24.9k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
23.5k
    {
1413
23.5k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
2.97k
  break;
1415
23.5k
    }
1416
1417
4.43k
  if (section == NULL)
1418
1.45k
    return;
1419
1420
2.97k
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
36
    return;
1422
1423
2.94k
  dataoff = addr - section->vma;
1424
1425
  /* PR 20605 and 22373: Make sure that the data is really there.
1426
     Note - since we are dealing with unsigned quantities we have
1427
     to be careful to check for potential overflows.  */
1428
2.94k
  if (dataoff >= section->size
1429
2.94k
      || size > section->size - dataoff)
1430
509
    {
1431
509
      _bfd_error_handler
1432
509
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
509
   abfd);
1434
509
      return;
1435
509
    }
1436
1437
  /* Read the whole section. */
1438
2.43k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
403
    {
1440
403
      free (data);
1441
403
      return;
1442
403
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
234k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
232k
    {
1447
232k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
232k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
232k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
232k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
232k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
478
  {
1455
478
    char buffer[256 + 1];
1456
478
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1457
1458
    /*
1459
      The debug entry doesn't have to have to be in a section, in which
1460
      case AddressOfRawData is 0, so always use PointerToRawData.
1461
    */
1462
478
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
478
                (file_ptr) idd.PointerToRawData,
1464
478
                idd.SizeOfData, cvinfo, NULL))
1465
8
      {
1466
8
        struct bfd_build_id *build_id;
1467
8
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1468
1469
8
        build_id = bfd_alloc (abfd, bidlen);
1470
8
        if (build_id)
1471
8
    {
1472
8
      build_id->size = cvinfo->SignatureLength;
1473
8
      memcpy(build_id->data, cvinfo->Signature,
1474
8
       cvinfo->SignatureLength);
1475
8
      abfd->build_id = build_id;
1476
8
    }
1477
8
      }
1478
478
    break;
1479
478
  }
1480
232k
    }
1481
1482
2.03k
  free (data);
1483
2.03k
}
pei-ia64.c:pe_bfd_read_buildid
Line
Count
Source
1395
3.86k
{
1396
3.86k
  pe_data_type *pe = pe_data (abfd);
1397
3.86k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
3.86k
  asection *section;
1399
3.86k
  bfd_byte *data = 0;
1400
3.86k
  bfd_size_type dataoff;
1401
3.86k
  unsigned int i;
1402
3.86k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
3.86k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
3.86k
  if (size == 0)
1406
2.99k
    return;
1407
1408
874
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
5.39k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
4.84k
    {
1413
4.84k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
329
  break;
1415
4.84k
    }
1416
1417
874
  if (section == NULL)
1418
545
    return;
1419
1420
329
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
33
    return;
1422
1423
296
  dataoff = addr - section->vma;
1424
1425
  /* PR 20605 and 22373: Make sure that the data is really there.
1426
     Note - since we are dealing with unsigned quantities we have
1427
     to be careful to check for potential overflows.  */
1428
296
  if (dataoff >= section->size
1429
296
      || size > section->size - dataoff)
1430
53
    {
1431
53
      _bfd_error_handler
1432
53
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
53
   abfd);
1434
53
      return;
1435
53
    }
1436
1437
  /* Read the whole section. */
1438
243
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
37
    {
1440
37
      free (data);
1441
37
      return;
1442
37
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
3.67k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
3.61k
    {
1447
3.61k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
3.61k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
3.61k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
3.61k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
3.61k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
141
  {
1455
141
    char buffer[256 + 1];
1456
141
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1457
1458
    /*
1459
      The debug entry doesn't have to have to be in a section, in which
1460
      case AddressOfRawData is 0, so always use PointerToRawData.
1461
    */
1462
141
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
141
                (file_ptr) idd.PointerToRawData,
1464
141
                idd.SizeOfData, cvinfo, NULL))
1465
1
      {
1466
1
        struct bfd_build_id *build_id;
1467
1
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1468
1469
1
        build_id = bfd_alloc (abfd, bidlen);
1470
1
        if (build_id)
1471
1
    {
1472
1
      build_id->size = cvinfo->SignatureLength;
1473
1
      memcpy(build_id->data, cvinfo->Signature,
1474
1
       cvinfo->SignatureLength);
1475
1
      abfd->build_id = build_id;
1476
1
    }
1477
1
      }
1478
141
    break;
1479
141
  }
1480
3.61k
    }
1481
1482
206
  free (data);
1483
206
}
pei-loongarch64.c:pe_bfd_read_buildid
Line
Count
Source
1395
4.01k
{
1396
4.01k
  pe_data_type *pe = pe_data (abfd);
1397
4.01k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
4.01k
  asection *section;
1399
4.01k
  bfd_byte *data = 0;
1400
4.01k
  bfd_size_type dataoff;
1401
4.01k
  unsigned int i;
1402
4.01k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
4.01k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
4.01k
  if (size == 0)
1406
2.52k
    return;
1407
1408
1.48k
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
9.97k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
9.12k
    {
1413
9.12k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
639
  break;
1415
9.12k
    }
1416
1417
1.48k
  if (section == NULL)
1418
847
    return;
1419
1420
639
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
31
    return;
1422
1423
608
  dataoff = addr - section->vma;
1424
1425
  /* PR 20605 and 22373: Make sure that the data is really there.
1426
     Note - since we are dealing with unsigned quantities we have
1427
     to be careful to check for potential overflows.  */
1428
608
  if (dataoff >= section->size
1429
608
      || size > section->size - dataoff)
1430
201
    {
1431
201
      _bfd_error_handler
1432
201
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
201
   abfd);
1434
201
      return;
1435
201
    }
1436
1437
  /* Read the whole section. */
1438
407
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
63
    {
1440
63
      free (data);
1441
63
      return;
1442
63
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
8.40k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
8.26k
    {
1447
8.26k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
8.26k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
8.26k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
8.26k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
8.26k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
208
  {
1455
208
    char buffer[256 + 1];
1456
208
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1457
1458
    /*
1459
      The debug entry doesn't have to have to be in a section, in which
1460
      case AddressOfRawData is 0, so always use PointerToRawData.
1461
    */
1462
208
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
208
                (file_ptr) idd.PointerToRawData,
1464
208
                idd.SizeOfData, cvinfo, NULL))
1465
7
      {
1466
7
        struct bfd_build_id *build_id;
1467
7
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1468
1469
7
        build_id = bfd_alloc (abfd, bidlen);
1470
7
        if (build_id)
1471
7
    {
1472
7
      build_id->size = cvinfo->SignatureLength;
1473
7
      memcpy(build_id->data, cvinfo->Signature,
1474
7
       cvinfo->SignatureLength);
1475
7
      abfd->build_id = build_id;
1476
7
    }
1477
7
      }
1478
208
    break;
1479
208
  }
1480
8.26k
    }
1481
1482
344
  free (data);
1483
344
}
pei-riscv64.c:pe_bfd_read_buildid
Line
Count
Source
1395
4.11k
{
1396
4.11k
  pe_data_type *pe = pe_data (abfd);
1397
4.11k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
4.11k
  asection *section;
1399
4.11k
  bfd_byte *data = 0;
1400
4.11k
  bfd_size_type dataoff;
1401
4.11k
  unsigned int i;
1402
4.11k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
4.11k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
4.11k
  if (size == 0)
1406
2.35k
    return;
1407
1408
1.76k
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
17.1k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
16.0k
    {
1413
16.0k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
692
  break;
1415
16.0k
    }
1416
1417
1.76k
  if (section == NULL)
1418
1.06k
    return;
1419
1420
692
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
36
    return;
1422
1423
656
  dataoff = addr - section->vma;
1424
1425
  /* PR 20605 and 22373: Make sure that the data is really there.
1426
     Note - since we are dealing with unsigned quantities we have
1427
     to be careful to check for potential overflows.  */
1428
656
  if (dataoff >= section->size
1429
656
      || size > section->size - dataoff)
1430
335
    {
1431
335
      _bfd_error_handler
1432
335
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
335
   abfd);
1434
335
      return;
1435
335
    }
1436
1437
  /* Read the whole section. */
1438
321
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
126
    {
1440
126
      free (data);
1441
126
      return;
1442
126
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
2.57k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
2.50k
    {
1447
2.50k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
2.50k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
2.50k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
2.50k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
2.50k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
131
  {
1455
131
    char buffer[256 + 1];
1456
131
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1457
1458
    /*
1459
      The debug entry doesn't have to have to be in a section, in which
1460
      case AddressOfRawData is 0, so always use PointerToRawData.
1461
    */
1462
131
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
131
                (file_ptr) idd.PointerToRawData,
1464
131
                idd.SizeOfData, cvinfo, NULL))
1465
6
      {
1466
6
        struct bfd_build_id *build_id;
1467
6
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1468
1469
6
        build_id = bfd_alloc (abfd, bidlen);
1470
6
        if (build_id)
1471
6
    {
1472
6
      build_id->size = cvinfo->SignatureLength;
1473
6
      memcpy(build_id->data, cvinfo->Signature,
1474
6
       cvinfo->SignatureLength);
1475
6
      abfd->build_id = build_id;
1476
6
    }
1477
6
      }
1478
131
    break;
1479
131
  }
1480
2.50k
    }
1481
1482
195
  free (data);
1483
195
}
pei-arm-wince.c:pe_bfd_read_buildid
Line
Count
Source
1395
2.94k
{
1396
2.94k
  pe_data_type *pe = pe_data (abfd);
1397
2.94k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
2.94k
  asection *section;
1399
2.94k
  bfd_byte *data = 0;
1400
2.94k
  bfd_size_type dataoff;
1401
2.94k
  unsigned int i;
1402
2.94k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
2.94k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
2.94k
  if (size == 0)
1406
1.08k
    return;
1407
1408
1.85k
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
7.03k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
5.99k
    {
1413
5.99k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
824
  break;
1415
5.99k
    }
1416
1417
1.85k
  if (section == NULL)
1418
1.03k
    return;
1419
1420
824
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
55
    return;
1422
1423
769
  dataoff = addr - section->vma;
1424
1425
  /* PR 20605 and 22373: Make sure that the data is really there.
1426
     Note - since we are dealing with unsigned quantities we have
1427
     to be careful to check for potential overflows.  */
1428
769
  if (dataoff >= section->size
1429
769
      || size > section->size - dataoff)
1430
423
    {
1431
423
      _bfd_error_handler
1432
423
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
423
   abfd);
1434
423
      return;
1435
423
    }
1436
1437
  /* Read the whole section. */
1438
346
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
186
    {
1440
186
      free (data);
1441
186
      return;
1442
186
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
2.54k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
2.45k
    {
1447
2.45k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
2.45k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
2.45k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
2.45k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
2.45k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
70
  {
1455
70
    char buffer[256 + 1];
1456
70
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1457
1458
    /*
1459
      The debug entry doesn't have to have to be in a section, in which
1460
      case AddressOfRawData is 0, so always use PointerToRawData.
1461
    */
1462
70
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
70
                (file_ptr) idd.PointerToRawData,
1464
70
                idd.SizeOfData, cvinfo, NULL))
1465
3
      {
1466
3
        struct bfd_build_id *build_id;
1467
3
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1468
1469
3
        build_id = bfd_alloc (abfd, bidlen);
1470
3
        if (build_id)
1471
3
    {
1472
3
      build_id->size = cvinfo->SignatureLength;
1473
3
      memcpy(build_id->data, cvinfo->Signature,
1474
3
       cvinfo->SignatureLength);
1475
3
      abfd->build_id = build_id;
1476
3
    }
1477
3
      }
1478
70
    break;
1479
70
  }
1480
2.45k
    }
1481
1482
160
  free (data);
1483
160
}
pei-arm.c:pe_bfd_read_buildid
Line
Count
Source
1395
3.61k
{
1396
3.61k
  pe_data_type *pe = pe_data (abfd);
1397
3.61k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
3.61k
  asection *section;
1399
3.61k
  bfd_byte *data = 0;
1400
3.61k
  bfd_size_type dataoff;
1401
3.61k
  unsigned int i;
1402
3.61k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
3.61k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
3.61k
  if (size == 0)
1406
1.88k
    return;
1407
1408
1.73k
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
9.19k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
8.33k
    {
1413
8.33k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
872
  break;
1415
8.33k
    }
1416
1417
1.73k
  if (section == NULL)
1418
858
    return;
1419
1420
872
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
45
    return;
1422
1423
827
  dataoff = addr - section->vma;
1424
1425
  /* PR 20605 and 22373: Make sure that the data is really there.
1426
     Note - since we are dealing with unsigned quantities we have
1427
     to be careful to check for potential overflows.  */
1428
827
  if (dataoff >= section->size
1429
827
      || size > section->size - dataoff)
1430
327
    {
1431
327
      _bfd_error_handler
1432
327
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
327
   abfd);
1434
327
      return;
1435
327
    }
1436
1437
  /* Read the whole section. */
1438
500
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
229
    {
1440
229
      free (data);
1441
229
      return;
1442
229
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
4.02k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
3.83k
    {
1447
3.83k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
3.83k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
3.83k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
3.83k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
3.83k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
75
  {
1455
75
    char buffer[256 + 1];
1456
75
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1457
1458
    /*
1459
      The debug entry doesn't have to have to be in a section, in which
1460
      case AddressOfRawData is 0, so always use PointerToRawData.
1461
    */
1462
75
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
75
                (file_ptr) idd.PointerToRawData,
1464
75
                idd.SizeOfData, cvinfo, NULL))
1465
20
      {
1466
20
        struct bfd_build_id *build_id;
1467
20
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1468
1469
20
        build_id = bfd_alloc (abfd, bidlen);
1470
20
        if (build_id)
1471
20
    {
1472
20
      build_id->size = cvinfo->SignatureLength;
1473
20
      memcpy(build_id->data, cvinfo->Signature,
1474
20
       cvinfo->SignatureLength);
1475
20
      abfd->build_id = build_id;
1476
20
    }
1477
20
      }
1478
75
    break;
1479
75
  }
1480
3.83k
    }
1481
1482
271
  free (data);
1483
271
}
pei-mcore.c:pe_bfd_read_buildid
Line
Count
Source
1395
3.54k
{
1396
3.54k
  pe_data_type *pe = pe_data (abfd);
1397
3.54k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
3.54k
  asection *section;
1399
3.54k
  bfd_byte *data = 0;
1400
3.54k
  bfd_size_type dataoff;
1401
3.54k
  unsigned int i;
1402
3.54k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
3.54k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
3.54k
  if (size == 0)
1406
2.11k
    return;
1407
1408
1.42k
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
7.74k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
7.01k
    {
1413
7.01k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
699
  break;
1415
7.01k
    }
1416
1417
1.42k
  if (section == NULL)
1418
729
    return;
1419
1420
699
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
60
    return;
1422
1423
639
  dataoff = addr - section->vma;
1424
1425
  /* PR 20605 and 22373: Make sure that the data is really there.
1426
     Note - since we are dealing with unsigned quantities we have
1427
     to be careful to check for potential overflows.  */
1428
639
  if (dataoff >= section->size
1429
639
      || size > section->size - dataoff)
1430
307
    {
1431
307
      _bfd_error_handler
1432
307
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
307
   abfd);
1434
307
      return;
1435
307
    }
1436
1437
  /* Read the whole section. */
1438
332
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
153
    {
1440
153
      free (data);
1441
153
      return;
1442
153
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
6.38k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
6.28k
    {
1447
6.28k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
6.28k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
6.28k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
6.28k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
6.28k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
74
  {
1455
74
    char buffer[256 + 1];
1456
74
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1457
1458
    /*
1459
      The debug entry doesn't have to have to be in a section, in which
1460
      case AddressOfRawData is 0, so always use PointerToRawData.
1461
    */
1462
74
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
74
                (file_ptr) idd.PointerToRawData,
1464
74
                idd.SizeOfData, cvinfo, NULL))
1465
3
      {
1466
3
        struct bfd_build_id *build_id;
1467
3
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1468
1469
3
        build_id = bfd_alloc (abfd, bidlen);
1470
3
        if (build_id)
1471
3
    {
1472
3
      build_id->size = cvinfo->SignatureLength;
1473
3
      memcpy(build_id->data, cvinfo->Signature,
1474
3
       cvinfo->SignatureLength);
1475
3
      abfd->build_id = build_id;
1476
3
    }
1477
3
      }
1478
74
    break;
1479
74
  }
1480
6.28k
    }
1481
1482
179
  free (data);
1483
179
}
pei-sh.c:pe_bfd_read_buildid
Line
Count
Source
1395
3.62k
{
1396
3.62k
  pe_data_type *pe = pe_data (abfd);
1397
3.62k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
3.62k
  asection *section;
1399
3.62k
  bfd_byte *data = 0;
1400
3.62k
  bfd_size_type dataoff;
1401
3.62k
  unsigned int i;
1402
3.62k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
3.62k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
3.62k
  if (size == 0)
1406
2.02k
    return;
1407
1408
1.60k
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
8.67k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
7.86k
    {
1413
7.86k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
798
  break;
1415
7.86k
    }
1416
1417
1.60k
  if (section == NULL)
1418
809
    return;
1419
1420
798
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
49
    return;
1422
1423
749
  dataoff = addr - section->vma;
1424
1425
  /* PR 20605 and 22373: Make sure that the data is really there.
1426
     Note - since we are dealing with unsigned quantities we have
1427
     to be careful to check for potential overflows.  */
1428
749
  if (dataoff >= section->size
1429
749
      || size > section->size - dataoff)
1430
371
    {
1431
371
      _bfd_error_handler
1432
371
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
371
   abfd);
1434
371
      return;
1435
371
    }
1436
1437
  /* Read the whole section. */
1438
378
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
203
    {
1440
203
      free (data);
1441
203
      return;
1442
203
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
4.82k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
4.73k
    {
1447
4.73k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
4.73k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
4.73k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
4.73k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
4.73k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
84
  {
1455
84
    char buffer[256 + 1];
1456
84
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1457
1458
    /*
1459
      The debug entry doesn't have to have to be in a section, in which
1460
      case AddressOfRawData is 0, so always use PointerToRawData.
1461
    */
1462
84
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
84
                (file_ptr) idd.PointerToRawData,
1464
84
                idd.SizeOfData, cvinfo, NULL))
1465
3
      {
1466
3
        struct bfd_build_id *build_id;
1467
3
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1468
1469
3
        build_id = bfd_alloc (abfd, bidlen);
1470
3
        if (build_id)
1471
3
    {
1472
3
      build_id->size = cvinfo->SignatureLength;
1473
3
      memcpy(build_id->data, cvinfo->Signature,
1474
3
       cvinfo->SignatureLength);
1475
3
      abfd->build_id = build_id;
1476
3
    }
1477
3
      }
1478
84
    break;
1479
84
  }
1480
4.73k
    }
1481
1482
175
  free (data);
1483
175
}
1484
1485
static bfd_cleanup
1486
pe_bfd_object_p (bfd *abfd)
1487
2.68M
{
1488
2.68M
  bfd_byte buffer[6];
1489
2.68M
  struct external_DOS_hdr dos_hdr;
1490
2.68M
  struct external_PEI_IMAGE_hdr image_hdr;
1491
2.68M
  struct internal_filehdr internal_f;
1492
2.68M
  struct internal_aouthdr internal_a;
1493
2.68M
  bfd_size_type opt_hdr_size;
1494
2.68M
  file_ptr offset;
1495
2.68M
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
2.68M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
2.68M
      || bfd_read (buffer, 6, abfd) != 6)
1501
23.5k
    {
1502
23.5k
      if (bfd_get_error () != bfd_error_system_call)
1503
23.1k
  bfd_set_error (bfd_error_wrong_format);
1504
23.5k
      return NULL;
1505
23.5k
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
2.66M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
44.8k
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
37.4k
    return pe_ILF_object_p (abfd);
1511
1512
2.62M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
2.62M
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
641k
    {
1515
641k
      if (bfd_get_error () != bfd_error_system_call)
1516
641k
  bfd_set_error (bfd_error_wrong_format);
1517
641k
      return NULL;
1518
641k
    }
1519
1520
  /* There are really two magic numbers involved; the magic number
1521
     that says this is a NT executable (PEI) and the magic number that
1522
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1523
     the e_magic field.  The latter is stored in the f_magic field.
1524
     If the NT magic number isn't valid, the architecture magic number
1525
     could be mimicked by some other field (specifically, the number
1526
     of relocs in section 3).  Since this routine can only be called
1527
     correctly for a PEI file, check the e_magic number here, and, if
1528
     it doesn't match, clobber the f_magic number so that we don't get
1529
     a false match.  */
1530
1.98M
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
1.45M
    {
1532
1.45M
      bfd_set_error (bfd_error_wrong_format);
1533
1.45M
      return NULL;
1534
1.45M
    }
1535
1536
532k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
532k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
532k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
4.09k
    {
1540
4.09k
      if (bfd_get_error () != bfd_error_system_call)
1541
4.09k
  bfd_set_error (bfd_error_wrong_format);
1542
4.09k
      return NULL;
1543
4.09k
    }
1544
1545
528k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
6.23k
    {
1547
6.23k
      bfd_set_error (bfd_error_wrong_format);
1548
6.23k
      return NULL;
1549
6.23k
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
522k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
522k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
77.8k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
444k
    {
1558
444k
      bfd_set_error (bfd_error_wrong_format);
1559
444k
      return NULL;
1560
444k
    }
1561
1562
77.6k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
77.6k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
77.6k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
77.6k
  if (opt_hdr_size != 0)
1569
46.8k
    {
1570
46.8k
      bfd_size_type amt = opt_hdr_size;
1571
46.8k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
46.8k
      if (amt < sizeof (PEAOUTHDR))
1575
43.0k
  amt = sizeof (PEAOUTHDR);
1576
1577
46.8k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
46.8k
      if (opthdr == NULL)
1579
432
  return NULL;
1580
46.4k
      if (amt > opt_hdr_size)
1581
42.6k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
46.4k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
46.4k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1586
1587
#ifdef ARM
1588
      /* Use Subsystem to distinguish between pei-arm-little and
1589
   pei-arm-wince-little.  */
1590
#ifdef WINCE
1591
5.59k
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1592
#else
1593
5.64k
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1594
1.91k
#endif
1595
4.92k
  {
1596
4.92k
    bfd_set_error (bfd_error_wrong_format);
1597
4.92k
    return NULL;
1598
4.92k
  }
1599
6.31k
#endif
1600
1601
41.5k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
19.0k
    || a->SectionAlignment >= 0x80000000)
1603
22.8k
  {
1604
22.8k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
22.8k
            abfd);
1606
22.8k
    a->SectionAlignment &= -a->SectionAlignment;
1607
22.8k
    if (a->SectionAlignment >= 0x80000000)
1608
367
      a->SectionAlignment = 0x40000000;
1609
22.8k
  }
1610
1611
41.5k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
20.3k
    || a->FileAlignment > a->SectionAlignment)
1613
27.5k
  {
1614
27.5k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
27.5k
            abfd);
1616
27.5k
    a->FileAlignment &= -a->FileAlignment;
1617
27.5k
    if (a->FileAlignment > a->SectionAlignment)
1618
19.0k
      a->FileAlignment = a->SectionAlignment;
1619
27.5k
  }
1620
1621
41.5k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
22.5k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
6.31k
    }
1624
1625
72.2k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
72.2k
             (opt_hdr_size != 0
1627
72.2k
        ? &internal_a
1628
72.2k
        : (struct internal_aouthdr *) NULL));
1629
1630
72.2k
  if (result)
1631
48.5k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
48.5k
      pe_bfd_read_buildid(abfd);
1634
48.5k
    }
1635
1636
72.2k
  return result;
1637
77.6k
}
pei-i386.c:pe_bfd_object_p
Line
Count
Source
1487
243k
{
1488
243k
  bfd_byte buffer[6];
1489
243k
  struct external_DOS_hdr dos_hdr;
1490
243k
  struct external_PEI_IMAGE_hdr image_hdr;
1491
243k
  struct internal_filehdr internal_f;
1492
243k
  struct internal_aouthdr internal_a;
1493
243k
  bfd_size_type opt_hdr_size;
1494
243k
  file_ptr offset;
1495
243k
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
243k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
243k
      || bfd_read (buffer, 6, abfd) != 6)
1501
2.05k
    {
1502
2.05k
      if (bfd_get_error () != bfd_error_system_call)
1503
2.02k
  bfd_set_error (bfd_error_wrong_format);
1504
2.05k
      return NULL;
1505
2.05k
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
241k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
5.18k
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
4.32k
    return pe_ILF_object_p (abfd);
1511
1512
236k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
236k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
57.5k
    {
1515
57.5k
      if (bfd_get_error () != bfd_error_system_call)
1516
57.5k
  bfd_set_error (bfd_error_wrong_format);
1517
57.5k
      return NULL;
1518
57.5k
    }
1519
1520
  /* There are really two magic numbers involved; the magic number
1521
     that says this is a NT executable (PEI) and the magic number that
1522
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1523
     the e_magic field.  The latter is stored in the f_magic field.
1524
     If the NT magic number isn't valid, the architecture magic number
1525
     could be mimicked by some other field (specifically, the number
1526
     of relocs in section 3).  Since this routine can only be called
1527
     correctly for a PEI file, check the e_magic number here, and, if
1528
     it doesn't match, clobber the f_magic number so that we don't get
1529
     a false match.  */
1530
179k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
118k
    {
1532
118k
      bfd_set_error (bfd_error_wrong_format);
1533
118k
      return NULL;
1534
118k
    }
1535
1536
60.3k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
60.3k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
60.3k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
216
    {
1540
216
      if (bfd_get_error () != bfd_error_system_call)
1541
216
  bfd_set_error (bfd_error_wrong_format);
1542
216
      return NULL;
1543
216
    }
1544
1545
60.1k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
447
    {
1547
447
      bfd_set_error (bfd_error_wrong_format);
1548
447
      return NULL;
1549
447
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
59.7k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
59.7k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
11.3k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
48.4k
    {
1558
48.4k
      bfd_set_error (bfd_error_wrong_format);
1559
48.4k
      return NULL;
1560
48.4k
    }
1561
1562
11.2k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
11.2k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
11.2k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
11.2k
  if (opt_hdr_size != 0)
1569
5.69k
    {
1570
5.69k
      bfd_size_type amt = opt_hdr_size;
1571
5.69k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
5.69k
      if (amt < sizeof (PEAOUTHDR))
1575
4.85k
  amt = sizeof (PEAOUTHDR);
1576
1577
5.69k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
5.69k
      if (opthdr == NULL)
1579
40
  return NULL;
1580
5.65k
      if (amt > opt_hdr_size)
1581
4.82k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
5.65k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
5.65k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1586
1587
#ifdef ARM
1588
      /* Use Subsystem to distinguish between pei-arm-little and
1589
   pei-arm-wince-little.  */
1590
#ifdef WINCE
1591
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1592
#else
1593
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1594
#endif
1595
  {
1596
    bfd_set_error (bfd_error_wrong_format);
1597
    return NULL;
1598
  }
1599
#endif
1600
1601
5.65k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
2.91k
    || a->SectionAlignment >= 0x80000000)
1603
2.80k
  {
1604
2.80k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
2.80k
            abfd);
1606
2.80k
    a->SectionAlignment &= -a->SectionAlignment;
1607
2.80k
    if (a->SectionAlignment >= 0x80000000)
1608
63
      a->SectionAlignment = 0x40000000;
1609
2.80k
  }
1610
1611
5.65k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
2.92k
    || a->FileAlignment > a->SectionAlignment)
1613
3.30k
  {
1614
3.30k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
3.30k
            abfd);
1616
3.30k
    a->FileAlignment &= -a->FileAlignment;
1617
3.30k
    if (a->FileAlignment > a->SectionAlignment)
1618
2.08k
      a->FileAlignment = a->SectionAlignment;
1619
3.30k
  }
1620
1621
5.65k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
2.96k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
5.65k
    }
1624
1625
11.2k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
11.2k
             (opt_hdr_size != 0
1627
11.2k
        ? &internal_a
1628
11.2k
        : (struct internal_aouthdr *) NULL));
1629
1630
11.2k
  if (result)
1631
9.66k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
9.66k
      pe_bfd_read_buildid(abfd);
1634
9.66k
    }
1635
1636
11.2k
  return result;
1637
11.2k
}
pei-x86_64.c:pe_bfd_object_p
Line
Count
Source
1487
241k
{
1488
241k
  bfd_byte buffer[6];
1489
241k
  struct external_DOS_hdr dos_hdr;
1490
241k
  struct external_PEI_IMAGE_hdr image_hdr;
1491
241k
  struct internal_filehdr internal_f;
1492
241k
  struct internal_aouthdr internal_a;
1493
241k
  bfd_size_type opt_hdr_size;
1494
241k
  file_ptr offset;
1495
241k
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
241k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
241k
      || bfd_read (buffer, 6, abfd) != 6)
1501
2.05k
    {
1502
2.05k
      if (bfd_get_error () != bfd_error_system_call)
1503
2.02k
  bfd_set_error (bfd_error_wrong_format);
1504
2.05k
      return NULL;
1505
2.05k
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
239k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
5.18k
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
4.31k
    return pe_ILF_object_p (abfd);
1511
1512
235k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
235k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
57.5k
    {
1515
57.5k
      if (bfd_get_error () != bfd_error_system_call)
1516
57.5k
  bfd_set_error (bfd_error_wrong_format);
1517
57.5k
      return NULL;
1518
57.5k
    }
1519
1520
  /* There are really two magic numbers involved; the magic number
1521
     that says this is a NT executable (PEI) and the magic number that
1522
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1523
     the e_magic field.  The latter is stored in the f_magic field.
1524
     If the NT magic number isn't valid, the architecture magic number
1525
     could be mimicked by some other field (specifically, the number
1526
     of relocs in section 3).  Since this routine can only be called
1527
     correctly for a PEI file, check the e_magic number here, and, if
1528
     it doesn't match, clobber the f_magic number so that we don't get
1529
     a false match.  */
1530
177k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
118k
    {
1532
118k
      bfd_set_error (bfd_error_wrong_format);
1533
118k
      return NULL;
1534
118k
    }
1535
1536
58.8k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
58.8k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
58.8k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
216
    {
1540
216
      if (bfd_get_error () != bfd_error_system_call)
1541
216
  bfd_set_error (bfd_error_wrong_format);
1542
216
      return NULL;
1543
216
    }
1544
1545
58.5k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
447
    {
1547
447
      bfd_set_error (bfd_error_wrong_format);
1548
447
      return NULL;
1549
447
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
58.1k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
58.1k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
8.27k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
49.8k
    {
1558
49.8k
      bfd_set_error (bfd_error_wrong_format);
1559
49.8k
      return NULL;
1560
49.8k
    }
1561
1562
8.25k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
8.25k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
8.25k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
8.25k
  if (opt_hdr_size != 0)
1569
5.09k
    {
1570
5.09k
      bfd_size_type amt = opt_hdr_size;
1571
5.09k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
5.09k
      if (amt < sizeof (PEAOUTHDR))
1575
4.70k
  amt = sizeof (PEAOUTHDR);
1576
1577
5.09k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
5.09k
      if (opthdr == NULL)
1579
44
  return NULL;
1580
5.04k
      if (amt > opt_hdr_size)
1581
4.66k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
5.04k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
5.04k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1586
1587
#ifdef ARM
1588
      /* Use Subsystem to distinguish between pei-arm-little and
1589
   pei-arm-wince-little.  */
1590
#ifdef WINCE
1591
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1592
#else
1593
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1594
#endif
1595
  {
1596
    bfd_set_error (bfd_error_wrong_format);
1597
    return NULL;
1598
  }
1599
#endif
1600
1601
5.04k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
2.76k
    || a->SectionAlignment >= 0x80000000)
1603
2.31k
  {
1604
2.31k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
2.31k
            abfd);
1606
2.31k
    a->SectionAlignment &= -a->SectionAlignment;
1607
2.31k
    if (a->SectionAlignment >= 0x80000000)
1608
36
      a->SectionAlignment = 0x40000000;
1609
2.31k
  }
1610
1611
5.04k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
2.40k
    || a->FileAlignment > a->SectionAlignment)
1613
3.12k
  {
1614
3.12k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
3.12k
            abfd);
1616
3.12k
    a->FileAlignment &= -a->FileAlignment;
1617
3.12k
    if (a->FileAlignment > a->SectionAlignment)
1618
1.65k
      a->FileAlignment = a->SectionAlignment;
1619
3.12k
  }
1620
1621
5.04k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
2.54k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
5.04k
    }
1624
1625
8.20k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
8.20k
             (opt_hdr_size != 0
1627
8.20k
        ? &internal_a
1628
8.20k
        : (struct internal_aouthdr *) NULL));
1629
1630
8.20k
  if (result)
1631
6.37k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
6.37k
      pe_bfd_read_buildid(abfd);
1634
6.37k
    }
1635
1636
8.20k
  return result;
1637
8.25k
}
pei-aarch64.c:pe_bfd_object_p
Line
Count
Source
1487
239k
{
1488
239k
  bfd_byte buffer[6];
1489
239k
  struct external_DOS_hdr dos_hdr;
1490
239k
  struct external_PEI_IMAGE_hdr image_hdr;
1491
239k
  struct internal_filehdr internal_f;
1492
239k
  struct internal_aouthdr internal_a;
1493
239k
  bfd_size_type opt_hdr_size;
1494
239k
  file_ptr offset;
1495
239k
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
239k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
239k
      || bfd_read (buffer, 6, abfd) != 6)
1501
2.05k
    {
1502
2.05k
      if (bfd_get_error () != bfd_error_system_call)
1503
2.02k
  bfd_set_error (bfd_error_wrong_format);
1504
2.05k
      return NULL;
1505
2.05k
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
237k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
5.19k
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
4.32k
    return pe_ILF_object_p (abfd);
1511
1512
233k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
233k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
57.4k
    {
1515
57.4k
      if (bfd_get_error () != bfd_error_system_call)
1516
57.4k
  bfd_set_error (bfd_error_wrong_format);
1517
57.4k
      return NULL;
1518
57.4k
    }
1519
1520
  /* There are really two magic numbers involved; the magic number
1521
     that says this is a NT executable (PEI) and the magic number that
1522
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1523
     the e_magic field.  The latter is stored in the f_magic field.
1524
     If the NT magic number isn't valid, the architecture magic number
1525
     could be mimicked by some other field (specifically, the number
1526
     of relocs in section 3).  Since this routine can only be called
1527
     correctly for a PEI file, check the e_magic number here, and, if
1528
     it doesn't match, clobber the f_magic number so that we don't get
1529
     a false match.  */
1530
175k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
116k
    {
1532
116k
      bfd_set_error (bfd_error_wrong_format);
1533
116k
      return NULL;
1534
116k
    }
1535
1536
58.9k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
58.9k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
58.9k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
973
    {
1540
973
      if (bfd_get_error () != bfd_error_system_call)
1541
973
  bfd_set_error (bfd_error_wrong_format);
1542
973
      return NULL;
1543
973
    }
1544
1545
58.0k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
1.25k
    {
1547
1.25k
      bfd_set_error (bfd_error_wrong_format);
1548
1.25k
      return NULL;
1549
1.25k
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
56.7k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
56.7k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
9.20k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
47.5k
    {
1558
47.5k
      bfd_set_error (bfd_error_wrong_format);
1559
47.5k
      return NULL;
1560
47.5k
    }
1561
1562
9.18k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
9.18k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
9.18k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
9.18k
  if (opt_hdr_size != 0)
1569
6.93k
    {
1570
6.93k
      bfd_size_type amt = opt_hdr_size;
1571
6.93k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
6.93k
      if (amt < sizeof (PEAOUTHDR))
1575
6.60k
  amt = sizeof (PEAOUTHDR);
1576
1577
6.93k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
6.93k
      if (opthdr == NULL)
1579
61
  return NULL;
1580
6.87k
      if (amt > opt_hdr_size)
1581
6.55k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
6.87k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
6.87k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1586
1587
#ifdef ARM
1588
      /* Use Subsystem to distinguish between pei-arm-little and
1589
   pei-arm-wince-little.  */
1590
#ifdef WINCE
1591
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1592
#else
1593
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1594
#endif
1595
  {
1596
    bfd_set_error (bfd_error_wrong_format);
1597
    return NULL;
1598
  }
1599
#endif
1600
1601
6.87k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
2.38k
    || a->SectionAlignment >= 0x80000000)
1603
4.51k
  {
1604
4.51k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
4.51k
            abfd);
1606
4.51k
    a->SectionAlignment &= -a->SectionAlignment;
1607
4.51k
    if (a->SectionAlignment >= 0x80000000)
1608
32
      a->SectionAlignment = 0x40000000;
1609
4.51k
  }
1610
1611
6.87k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
4.35k
    || a->FileAlignment > a->SectionAlignment)
1613
5.21k
  {
1614
5.21k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
5.21k
            abfd);
1616
5.21k
    a->FileAlignment &= -a->FileAlignment;
1617
5.21k
    if (a->FileAlignment > a->SectionAlignment)
1618
4.10k
      a->FileAlignment = a->SectionAlignment;
1619
5.21k
  }
1620
1621
6.87k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
3.11k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
6.87k
    }
1624
1625
9.11k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
9.11k
             (opt_hdr_size != 0
1627
9.11k
        ? &internal_a
1628
9.11k
        : (struct internal_aouthdr *) NULL));
1629
1630
9.11k
  if (result)
1631
6.82k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
6.82k
      pe_bfd_read_buildid(abfd);
1634
6.82k
    }
1635
1636
9.11k
  return result;
1637
9.18k
}
pei-ia64.c:pe_bfd_object_p
Line
Count
Source
1487
17.2k
{
1488
17.2k
  bfd_byte buffer[6];
1489
17.2k
  struct external_DOS_hdr dos_hdr;
1490
17.2k
  struct external_PEI_IMAGE_hdr image_hdr;
1491
17.2k
  struct internal_filehdr internal_f;
1492
17.2k
  struct internal_aouthdr internal_a;
1493
17.2k
  bfd_size_type opt_hdr_size;
1494
17.2k
  file_ptr offset;
1495
17.2k
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
17.2k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
17.2k
      || bfd_read (buffer, 6, abfd) != 6)
1501
0
    {
1502
0
      if (bfd_get_error () != bfd_error_system_call)
1503
0
  bfd_set_error (bfd_error_wrong_format);
1504
0
      return NULL;
1505
0
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
17.2k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
0
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
0
    return pe_ILF_object_p (abfd);
1511
1512
17.2k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
17.2k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
0
    {
1515
0
      if (bfd_get_error () != bfd_error_system_call)
1516
0
  bfd_set_error (bfd_error_wrong_format);
1517
0
      return NULL;
1518
0
    }
1519
1520
  /* There are really two magic numbers involved; the magic number
1521
     that says this is a NT executable (PEI) and the magic number that
1522
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1523
     the e_magic field.  The latter is stored in the f_magic field.
1524
     If the NT magic number isn't valid, the architecture magic number
1525
     could be mimicked by some other field (specifically, the number
1526
     of relocs in section 3).  Since this routine can only be called
1527
     correctly for a PEI file, check the e_magic number here, and, if
1528
     it doesn't match, clobber the f_magic number so that we don't get
1529
     a false match.  */
1530
17.2k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
0
    {
1532
0
      bfd_set_error (bfd_error_wrong_format);
1533
0
      return NULL;
1534
0
    }
1535
1536
17.2k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
17.2k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
17.2k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
0
    {
1540
0
      if (bfd_get_error () != bfd_error_system_call)
1541
0
  bfd_set_error (bfd_error_wrong_format);
1542
0
      return NULL;
1543
0
    }
1544
1545
17.2k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
0
    {
1547
0
      bfd_set_error (bfd_error_wrong_format);
1548
0
      return NULL;
1549
0
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
17.2k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
17.2k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
6.21k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
11.0k
    {
1558
11.0k
      bfd_set_error (bfd_error_wrong_format);
1559
11.0k
      return NULL;
1560
11.0k
    }
1561
1562
6.19k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
6.19k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
6.19k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
6.19k
  if (opt_hdr_size != 0)
1569
2.53k
    {
1570
2.53k
      bfd_size_type amt = opt_hdr_size;
1571
2.53k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
2.53k
      if (amt < sizeof (PEAOUTHDR))
1575
2.40k
  amt = sizeof (PEAOUTHDR);
1576
1577
2.53k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
2.53k
      if (opthdr == NULL)
1579
38
  return NULL;
1580
2.50k
      if (amt > opt_hdr_size)
1581
2.37k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
2.50k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
2.50k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1586
1587
#ifdef ARM
1588
      /* Use Subsystem to distinguish between pei-arm-little and
1589
   pei-arm-wince-little.  */
1590
#ifdef WINCE
1591
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1592
#else
1593
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1594
#endif
1595
  {
1596
    bfd_set_error (bfd_error_wrong_format);
1597
    return NULL;
1598
  }
1599
#endif
1600
1601
2.50k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
1.13k
    || a->SectionAlignment >= 0x80000000)
1603
1.39k
  {
1604
1.39k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
1.39k
            abfd);
1606
1.39k
    a->SectionAlignment &= -a->SectionAlignment;
1607
1.39k
    if (a->SectionAlignment >= 0x80000000)
1608
28
      a->SectionAlignment = 0x40000000;
1609
1.39k
  }
1610
1611
2.50k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
1.10k
    || a->FileAlignment > a->SectionAlignment)
1613
1.74k
  {
1614
1.74k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
1.74k
            abfd);
1616
1.74k
    a->FileAlignment &= -a->FileAlignment;
1617
1.74k
    if (a->FileAlignment > a->SectionAlignment)
1618
908
      a->FileAlignment = a->SectionAlignment;
1619
1.74k
  }
1620
1621
2.50k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
1.48k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
2.50k
    }
1624
1625
6.15k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
6.15k
             (opt_hdr_size != 0
1627
6.15k
        ? &internal_a
1628
6.15k
        : (struct internal_aouthdr *) NULL));
1629
1630
6.15k
  if (result)
1631
3.86k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
3.86k
      pe_bfd_read_buildid(abfd);
1634
3.86k
    }
1635
1636
6.15k
  return result;
1637
6.19k
}
pei-loongarch64.c:pe_bfd_object_p
Line
Count
Source
1487
239k
{
1488
239k
  bfd_byte buffer[6];
1489
239k
  struct external_DOS_hdr dos_hdr;
1490
239k
  struct external_PEI_IMAGE_hdr image_hdr;
1491
239k
  struct internal_filehdr internal_f;
1492
239k
  struct internal_aouthdr internal_a;
1493
239k
  bfd_size_type opt_hdr_size;
1494
239k
  file_ptr offset;
1495
239k
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
239k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
239k
      || bfd_read (buffer, 6, abfd) != 6)
1501
2.05k
    {
1502
2.05k
      if (bfd_get_error () != bfd_error_system_call)
1503
2.02k
  bfd_set_error (bfd_error_wrong_format);
1504
2.05k
      return NULL;
1505
2.05k
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
237k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
5.16k
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
4.30k
    return pe_ILF_object_p (abfd);
1511
1512
233k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
233k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
57.5k
    {
1515
57.5k
      if (bfd_get_error () != bfd_error_system_call)
1516
57.5k
  bfd_set_error (bfd_error_wrong_format);
1517
57.5k
      return NULL;
1518
57.5k
    }
1519
1520
  /* There are really two magic numbers involved; the magic number
1521
     that says this is a NT executable (PEI) and the magic number that
1522
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1523
     the e_magic field.  The latter is stored in the f_magic field.
1524
     If the NT magic number isn't valid, the architecture magic number
1525
     could be mimicked by some other field (specifically, the number
1526
     of relocs in section 3).  Since this routine can only be called
1527
     correctly for a PEI file, check the e_magic number here, and, if
1528
     it doesn't match, clobber the f_magic number so that we don't get
1529
     a false match.  */
1530
175k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
118k
    {
1532
118k
      bfd_set_error (bfd_error_wrong_format);
1533
118k
      return NULL;
1534
118k
    }
1535
1536
56.7k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
56.7k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
56.7k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
216
    {
1540
216
      if (bfd_get_error () != bfd_error_system_call)
1541
216
  bfd_set_error (bfd_error_wrong_format);
1542
216
      return NULL;
1543
216
    }
1544
1545
56.5k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
447
    {
1547
447
      bfd_set_error (bfd_error_wrong_format);
1548
447
      return NULL;
1549
447
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
56.0k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
56.0k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
6.47k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
49.6k
    {
1558
49.6k
      bfd_set_error (bfd_error_wrong_format);
1559
49.6k
      return NULL;
1560
49.6k
    }
1561
1562
6.45k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
6.45k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
6.45k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
6.45k
  if (opt_hdr_size != 0)
1569
3.98k
    {
1570
3.98k
      bfd_size_type amt = opt_hdr_size;
1571
3.98k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
3.98k
      if (amt < sizeof (PEAOUTHDR))
1575
3.67k
  amt = sizeof (PEAOUTHDR);
1576
1577
3.98k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
3.98k
      if (opthdr == NULL)
1579
33
  return NULL;
1580
3.95k
      if (amt > opt_hdr_size)
1581
3.64k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
3.95k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
3.95k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1586
1587
#ifdef ARM
1588
      /* Use Subsystem to distinguish between pei-arm-little and
1589
   pei-arm-wince-little.  */
1590
#ifdef WINCE
1591
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1592
#else
1593
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1594
#endif
1595
  {
1596
    bfd_set_error (bfd_error_wrong_format);
1597
    return NULL;
1598
  }
1599
#endif
1600
1601
3.95k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
2.14k
    || a->SectionAlignment >= 0x80000000)
1603
1.84k
  {
1604
1.84k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
1.84k
            abfd);
1606
1.84k
    a->SectionAlignment &= -a->SectionAlignment;
1607
1.84k
    if (a->SectionAlignment >= 0x80000000)
1608
38
      a->SectionAlignment = 0x40000000;
1609
1.84k
  }
1610
1611
3.95k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
1.84k
    || a->FileAlignment > a->SectionAlignment)
1613
2.49k
  {
1614
2.49k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
2.49k
            abfd);
1616
2.49k
    a->FileAlignment &= -a->FileAlignment;
1617
2.49k
    if (a->FileAlignment > a->SectionAlignment)
1618
1.57k
      a->FileAlignment = a->SectionAlignment;
1619
2.49k
  }
1620
1621
3.95k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
2.15k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
3.95k
    }
1624
1625
6.42k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
6.42k
             (opt_hdr_size != 0
1627
6.42k
        ? &internal_a
1628
6.42k
        : (struct internal_aouthdr *) NULL));
1629
1630
6.42k
  if (result)
1631
4.01k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
4.01k
      pe_bfd_read_buildid(abfd);
1634
4.01k
    }
1635
1636
6.42k
  return result;
1637
6.45k
}
pei-riscv64.c:pe_bfd_object_p
Line
Count
Source
1487
239k
{
1488
239k
  bfd_byte buffer[6];
1489
239k
  struct external_DOS_hdr dos_hdr;
1490
239k
  struct external_PEI_IMAGE_hdr image_hdr;
1491
239k
  struct internal_filehdr internal_f;
1492
239k
  struct internal_aouthdr internal_a;
1493
239k
  bfd_size_type opt_hdr_size;
1494
239k
  file_ptr offset;
1495
239k
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
239k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
239k
      || bfd_read (buffer, 6, abfd) != 6)
1501
2.05k
    {
1502
2.05k
      if (bfd_get_error () != bfd_error_system_call)
1503
2.02k
  bfd_set_error (bfd_error_wrong_format);
1504
2.05k
      return NULL;
1505
2.05k
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
237k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
5.18k
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
4.32k
    return pe_ILF_object_p (abfd);
1511
1512
233k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
233k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
57.5k
    {
1515
57.5k
      if (bfd_get_error () != bfd_error_system_call)
1516
57.5k
  bfd_set_error (bfd_error_wrong_format);
1517
57.5k
      return NULL;
1518
57.5k
    }
1519
1520
  /* There are really two magic numbers involved; the magic number
1521
     that says this is a NT executable (PEI) and the magic number that
1522
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1523
     the e_magic field.  The latter is stored in the f_magic field.
1524
     If the NT magic number isn't valid, the architecture magic number
1525
     could be mimicked by some other field (specifically, the number
1526
     of relocs in section 3).  Since this routine can only be called
1527
     correctly for a PEI file, check the e_magic number here, and, if
1528
     it doesn't match, clobber the f_magic number so that we don't get
1529
     a false match.  */
1530
175k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
118k
    {
1532
118k
      bfd_set_error (bfd_error_wrong_format);
1533
118k
      return NULL;
1534
118k
    }
1535
1536
56.7k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
56.7k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
56.7k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
216
    {
1540
216
      if (bfd_get_error () != bfd_error_system_call)
1541
216
  bfd_set_error (bfd_error_wrong_format);
1542
216
      return NULL;
1543
216
    }
1544
1545
56.5k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
447
    {
1547
447
      bfd_set_error (bfd_error_wrong_format);
1548
447
      return NULL;
1549
447
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
56.0k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
56.0k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
6.70k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
49.3k
    {
1558
49.3k
      bfd_set_error (bfd_error_wrong_format);
1559
49.3k
      return NULL;
1560
49.3k
    }
1561
1562
6.68k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
6.68k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
6.68k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
6.68k
  if (opt_hdr_size != 0)
1569
4.55k
    {
1570
4.55k
      bfd_size_type amt = opt_hdr_size;
1571
4.55k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
4.55k
      if (amt < sizeof (PEAOUTHDR))
1575
3.99k
  amt = sizeof (PEAOUTHDR);
1576
1577
4.55k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
4.55k
      if (opthdr == NULL)
1579
33
  return NULL;
1580
4.51k
      if (amt > opt_hdr_size)
1581
3.97k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
4.51k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
4.51k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1586
1587
#ifdef ARM
1588
      /* Use Subsystem to distinguish between pei-arm-little and
1589
   pei-arm-wince-little.  */
1590
#ifdef WINCE
1591
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1592
#else
1593
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1594
#endif
1595
  {
1596
    bfd_set_error (bfd_error_wrong_format);
1597
    return NULL;
1598
  }
1599
#endif
1600
1601
4.51k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
2.46k
    || a->SectionAlignment >= 0x80000000)
1603
2.09k
  {
1604
2.09k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
2.09k
            abfd);
1606
2.09k
    a->SectionAlignment &= -a->SectionAlignment;
1607
2.09k
    if (a->SectionAlignment >= 0x80000000)
1608
43
      a->SectionAlignment = 0x40000000;
1609
2.09k
  }
1610
1611
4.51k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
1.98k
    || a->FileAlignment > a->SectionAlignment)
1613
2.93k
  {
1614
2.93k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
2.93k
            abfd);
1616
2.93k
    a->FileAlignment &= -a->FileAlignment;
1617
2.93k
    if (a->FileAlignment > a->SectionAlignment)
1618
1.93k
      a->FileAlignment = a->SectionAlignment;
1619
2.93k
  }
1620
1621
4.51k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
2.59k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
4.51k
    }
1624
1625
6.65k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
6.65k
             (opt_hdr_size != 0
1627
6.65k
        ? &internal_a
1628
6.65k
        : (struct internal_aouthdr *) NULL));
1629
1630
6.65k
  if (result)
1631
4.11k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
4.11k
      pe_bfd_read_buildid(abfd);
1634
4.11k
    }
1635
1636
6.65k
  return result;
1637
6.68k
}
pei-arm-wince.c:pe_bfd_object_p
Line
Count
Source
1487
417k
{
1488
417k
  bfd_byte buffer[6];
1489
417k
  struct external_DOS_hdr dos_hdr;
1490
417k
  struct external_PEI_IMAGE_hdr image_hdr;
1491
417k
  struct internal_filehdr internal_f;
1492
417k
  struct internal_aouthdr internal_a;
1493
417k
  bfd_size_type opt_hdr_size;
1494
417k
  file_ptr offset;
1495
417k
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
417k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
417k
      || bfd_read (buffer, 6, abfd) != 6)
1501
3.78k
    {
1502
3.78k
      if (bfd_get_error () != bfd_error_system_call)
1503
3.71k
  bfd_set_error (bfd_error_wrong_format);
1504
3.78k
      return NULL;
1505
3.78k
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
414k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
4.73k
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
3.97k
    return pe_ILF_object_p (abfd);
1511
1512
410k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
410k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
101k
    {
1515
101k
      if (bfd_get_error () != bfd_error_system_call)
1516
101k
  bfd_set_error (bfd_error_wrong_format);
1517
101k
      return NULL;
1518
101k
    }
1519
1520
  /* There are really two magic numbers involved; the magic number
1521
     that says this is a NT executable (PEI) and the magic number that
1522
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1523
     the e_magic field.  The latter is stored in the f_magic field.
1524
     If the NT magic number isn't valid, the architecture magic number
1525
     could be mimicked by some other field (specifically, the number
1526
     of relocs in section 3).  Since this routine can only be called
1527
     correctly for a PEI file, check the e_magic number here, and, if
1528
     it doesn't match, clobber the f_magic number so that we don't get
1529
     a false match.  */
1530
308k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
251k
    {
1532
251k
      bfd_set_error (bfd_error_wrong_format);
1533
251k
      return NULL;
1534
251k
    }
1535
1536
56.7k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
56.7k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
56.7k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
918
    {
1540
918
      if (bfd_get_error () != bfd_error_system_call)
1541
918
  bfd_set_error (bfd_error_wrong_format);
1542
918
      return NULL;
1543
918
    }
1544
1545
55.8k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
1.15k
    {
1547
1.15k
      bfd_set_error (bfd_error_wrong_format);
1548
1.15k
      return NULL;
1549
1.15k
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
54.7k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
54.7k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
9.26k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
45.5k
    {
1558
45.5k
      bfd_set_error (bfd_error_wrong_format);
1559
45.5k
      return NULL;
1560
45.5k
    }
1561
1562
9.20k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
9.20k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
9.20k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
9.20k
  if (opt_hdr_size != 0)
1569
5.64k
    {
1570
5.64k
      bfd_size_type amt = opt_hdr_size;
1571
5.64k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
5.64k
      if (amt < sizeof (PEAOUTHDR))
1575
5.21k
  amt = sizeof (PEAOUTHDR);
1576
1577
5.64k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
5.64k
      if (opthdr == NULL)
1579
52
  return NULL;
1580
5.59k
      if (amt > opt_hdr_size)
1581
5.16k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
5.59k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
5.59k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1586
1587
5.59k
#ifdef ARM
1588
      /* Use Subsystem to distinguish between pei-arm-little and
1589
   pei-arm-wince-little.  */
1590
5.59k
#ifdef WINCE
1591
5.59k
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1592
#else
1593
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1594
#endif
1595
3.01k
  {
1596
3.01k
    bfd_set_error (bfd_error_wrong_format);
1597
3.01k
    return NULL;
1598
3.01k
  }
1599
2.58k
#endif
1600
1601
2.58k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
503
    || a->SectionAlignment >= 0x80000000)
1603
2.11k
  {
1604
2.11k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
2.11k
            abfd);
1606
2.11k
    a->SectionAlignment &= -a->SectionAlignment;
1607
2.11k
    if (a->SectionAlignment >= 0x80000000)
1608
28
      a->SectionAlignment = 0x40000000;
1609
2.11k
  }
1610
1611
2.58k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
666
    || a->FileAlignment > a->SectionAlignment)
1613
2.27k
  {
1614
2.27k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
2.27k
            abfd);
1616
2.27k
    a->FileAlignment &= -a->FileAlignment;
1617
2.27k
    if (a->FileAlignment > a->SectionAlignment)
1618
1.77k
      a->FileAlignment = a->SectionAlignment;
1619
2.27k
  }
1620
1621
2.58k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
1.99k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
2.58k
    }
1624
1625
6.14k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
6.14k
             (opt_hdr_size != 0
1627
6.14k
        ? &internal_a
1628
6.14k
        : (struct internal_aouthdr *) NULL));
1629
1630
6.14k
  if (result)
1631
2.94k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
2.94k
      pe_bfd_read_buildid(abfd);
1634
2.94k
    }
1635
1636
6.14k
  return result;
1637
9.20k
}
pei-arm.c:pe_bfd_object_p
Line
Count
Source
1487
417k
{
1488
417k
  bfd_byte buffer[6];
1489
417k
  struct external_DOS_hdr dos_hdr;
1490
417k
  struct external_PEI_IMAGE_hdr image_hdr;
1491
417k
  struct internal_filehdr internal_f;
1492
417k
  struct internal_aouthdr internal_a;
1493
417k
  bfd_size_type opt_hdr_size;
1494
417k
  file_ptr offset;
1495
417k
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
417k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
417k
      || bfd_read (buffer, 6, abfd) != 6)
1501
3.78k
    {
1502
3.78k
      if (bfd_get_error () != bfd_error_system_call)
1503
3.71k
  bfd_set_error (bfd_error_wrong_format);
1504
3.78k
      return NULL;
1505
3.78k
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
414k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
4.73k
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
3.97k
    return pe_ILF_object_p (abfd);
1511
1512
410k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
410k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
101k
    {
1515
101k
      if (bfd_get_error () != bfd_error_system_call)
1516
101k
  bfd_set_error (bfd_error_wrong_format);
1517
101k
      return NULL;
1518
101k
    }
1519
1520
  /* There are really two magic numbers involved; the magic number
1521
     that says this is a NT executable (PEI) and the magic number that
1522
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1523
     the e_magic field.  The latter is stored in the f_magic field.
1524
     If the NT magic number isn't valid, the architecture magic number
1525
     could be mimicked by some other field (specifically, the number
1526
     of relocs in section 3).  Since this routine can only be called
1527
     correctly for a PEI file, check the e_magic number here, and, if
1528
     it doesn't match, clobber the f_magic number so that we don't get
1529
     a false match.  */
1530
308k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
251k
    {
1532
251k
      bfd_set_error (bfd_error_wrong_format);
1533
251k
      return NULL;
1534
251k
    }
1535
1536
56.8k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
56.8k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
56.8k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
918
    {
1540
918
      if (bfd_get_error () != bfd_error_system_call)
1541
918
  bfd_set_error (bfd_error_wrong_format);
1542
918
      return NULL;
1543
918
    }
1544
1545
55.9k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
1.15k
    {
1547
1.15k
      bfd_set_error (bfd_error_wrong_format);
1548
1.15k
      return NULL;
1549
1.15k
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
54.7k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
54.7k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
9.31k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
45.5k
    {
1558
45.5k
      bfd_set_error (bfd_error_wrong_format);
1559
45.5k
      return NULL;
1560
45.5k
    }
1561
1562
9.26k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
9.26k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
9.26k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
9.26k
  if (opt_hdr_size != 0)
1569
5.69k
    {
1570
5.69k
      bfd_size_type amt = opt_hdr_size;
1571
5.69k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
5.69k
      if (amt < sizeof (PEAOUTHDR))
1575
5.27k
  amt = sizeof (PEAOUTHDR);
1576
1577
5.69k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
5.69k
      if (opthdr == NULL)
1579
52
  return NULL;
1580
5.64k
      if (amt > opt_hdr_size)
1581
5.22k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
5.64k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
5.64k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1586
1587
5.64k
#ifdef ARM
1588
      /* Use Subsystem to distinguish between pei-arm-little and
1589
   pei-arm-wince-little.  */
1590
#ifdef WINCE
1591
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1592
#else
1593
5.64k
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1594
1.91k
#endif
1595
1.91k
  {
1596
1.91k
    bfd_set_error (bfd_error_wrong_format);
1597
1.91k
    return NULL;
1598
1.91k
  }
1599
3.73k
#endif
1600
1601
3.73k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
1.55k
    || a->SectionAlignment >= 0x80000000)
1603
2.22k
  {
1604
2.22k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
2.22k
            abfd);
1606
2.22k
    a->SectionAlignment &= -a->SectionAlignment;
1607
2.22k
    if (a->SectionAlignment >= 0x80000000)
1608
47
      a->SectionAlignment = 0x40000000;
1609
2.22k
  }
1610
1611
3.73k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
1.74k
    || a->FileAlignment > a->SectionAlignment)
1613
2.42k
  {
1614
2.42k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
2.42k
            abfd);
1616
2.42k
    a->FileAlignment &= -a->FileAlignment;
1617
2.42k
    if (a->FileAlignment > a->SectionAlignment)
1618
1.87k
      a->FileAlignment = a->SectionAlignment;
1619
2.42k
  }
1620
1621
3.73k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
2.00k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
3.73k
    }
1624
1625
7.29k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
7.29k
             (opt_hdr_size != 0
1627
7.29k
        ? &internal_a
1628
7.29k
        : (struct internal_aouthdr *) NULL));
1629
1630
7.29k
  if (result)
1631
3.61k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
3.61k
      pe_bfd_read_buildid(abfd);
1634
3.61k
    }
1635
1636
7.29k
  return result;
1637
9.26k
}
pei-mcore.c:pe_bfd_object_p
Line
Count
Source
1487
418k
{
1488
418k
  bfd_byte buffer[6];
1489
418k
  struct external_DOS_hdr dos_hdr;
1490
418k
  struct external_PEI_IMAGE_hdr image_hdr;
1491
418k
  struct internal_filehdr internal_f;
1492
418k
  struct internal_aouthdr internal_a;
1493
418k
  bfd_size_type opt_hdr_size;
1494
418k
  file_ptr offset;
1495
418k
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
418k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
418k
      || bfd_read (buffer, 6, abfd) != 6)
1501
3.78k
    {
1502
3.78k
      if (bfd_get_error () != bfd_error_system_call)
1503
3.71k
  bfd_set_error (bfd_error_wrong_format);
1504
3.78k
      return NULL;
1505
3.78k
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
414k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
4.73k
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
3.97k
    return pe_ILF_object_p (abfd);
1511
1512
410k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
410k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
101k
    {
1515
101k
      if (bfd_get_error () != bfd_error_system_call)
1516
101k
  bfd_set_error (bfd_error_wrong_format);
1517
101k
      return NULL;
1518
101k
    }
1519
1520
  /* There are really two magic numbers involved; the magic number
1521
     that says this is a NT executable (PEI) and the magic number that
1522
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1523
     the e_magic field.  The latter is stored in the f_magic field.
1524
     If the NT magic number isn't valid, the architecture magic number
1525
     could be mimicked by some other field (specifically, the number
1526
     of relocs in section 3).  Since this routine can only be called
1527
     correctly for a PEI file, check the e_magic number here, and, if
1528
     it doesn't match, clobber the f_magic number so that we don't get
1529
     a false match.  */
1530
308k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
253k
    {
1532
253k
      bfd_set_error (bfd_error_wrong_format);
1533
253k
      return NULL;
1534
253k
    }
1535
1536
55.0k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
55.0k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
55.0k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
213
    {
1540
213
      if (bfd_get_error () != bfd_error_system_call)
1541
213
  bfd_set_error (bfd_error_wrong_format);
1542
213
      return NULL;
1543
213
    }
1544
1545
54.8k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
444
    {
1547
444
      bfd_set_error (bfd_error_wrong_format);
1548
444
      return NULL;
1549
444
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
54.3k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
54.3k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
5.57k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
48.8k
    {
1558
48.8k
      bfd_set_error (bfd_error_wrong_format);
1559
48.8k
      return NULL;
1560
48.8k
    }
1561
1562
5.56k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
5.56k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
5.56k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
5.56k
  if (opt_hdr_size != 0)
1569
3.28k
    {
1570
3.28k
      bfd_size_type amt = opt_hdr_size;
1571
3.28k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
3.28k
      if (amt < sizeof (PEAOUTHDR))
1575
3.07k
  amt = sizeof (PEAOUTHDR);
1576
1577
3.28k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
3.28k
      if (opthdr == NULL)
1579
35
  return NULL;
1580
3.25k
      if (amt > opt_hdr_size)
1581
3.05k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
3.25k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
3.25k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1586
1587
#ifdef ARM
1588
      /* Use Subsystem to distinguish between pei-arm-little and
1589
   pei-arm-wince-little.  */
1590
#ifdef WINCE
1591
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1592
#else
1593
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1594
#endif
1595
  {
1596
    bfd_set_error (bfd_error_wrong_format);
1597
    return NULL;
1598
  }
1599
#endif
1600
1601
3.25k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
1.46k
    || a->SectionAlignment >= 0x80000000)
1603
1.82k
  {
1604
1.82k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
1.82k
            abfd);
1606
1.82k
    a->SectionAlignment &= -a->SectionAlignment;
1607
1.82k
    if (a->SectionAlignment >= 0x80000000)
1608
36
      a->SectionAlignment = 0x40000000;
1609
1.82k
  }
1610
1611
3.25k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
1.61k
    || a->FileAlignment > a->SectionAlignment)
1613
2.00k
  {
1614
2.00k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
2.00k
            abfd);
1616
2.00k
    a->FileAlignment &= -a->FileAlignment;
1617
2.00k
    if (a->FileAlignment > a->SectionAlignment)
1618
1.60k
      a->FileAlignment = a->SectionAlignment;
1619
2.00k
  }
1620
1621
3.25k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
1.74k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
3.25k
    }
1624
1625
5.52k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
5.52k
             (opt_hdr_size != 0
1627
5.52k
        ? &internal_a
1628
5.52k
        : (struct internal_aouthdr *) NULL));
1629
1630
5.52k
  if (result)
1631
3.54k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
3.54k
      pe_bfd_read_buildid(abfd);
1634
3.54k
    }
1635
1636
5.52k
  return result;
1637
5.56k
}
pei-sh.c:pe_bfd_object_p
Line
Count
Source
1487
211k
{
1488
211k
  bfd_byte buffer[6];
1489
211k
  struct external_DOS_hdr dos_hdr;
1490
211k
  struct external_PEI_IMAGE_hdr image_hdr;
1491
211k
  struct internal_filehdr internal_f;
1492
211k
  struct internal_aouthdr internal_a;
1493
211k
  bfd_size_type opt_hdr_size;
1494
211k
  file_ptr offset;
1495
211k
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
211k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
211k
      || bfd_read (buffer, 6, abfd) != 6)
1501
1.88k
    {
1502
1.88k
      if (bfd_get_error () != bfd_error_system_call)
1503
1.85k
  bfd_set_error (bfd_error_wrong_format);
1504
1.88k
      return NULL;
1505
1.88k
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
209k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
4.68k
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
3.94k
    return pe_ILF_object_p (abfd);
1511
1512
205k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
205k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
49.1k
    {
1515
49.1k
      if (bfd_get_error () != bfd_error_system_call)
1516
49.1k
  bfd_set_error (bfd_error_wrong_format);
1517
49.1k
      return NULL;
1518
49.1k
    }
1519
1520
  /* There are really two magic numbers involved; the magic number
1521
     that says this is a NT executable (PEI) and the magic number that
1522
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1523
     the e_magic field.  The latter is stored in the f_magic field.
1524
     If the NT magic number isn't valid, the architecture magic number
1525
     could be mimicked by some other field (specifically, the number
1526
     of relocs in section 3).  Since this routine can only be called
1527
     correctly for a PEI file, check the e_magic number here, and, if
1528
     it doesn't match, clobber the f_magic number so that we don't get
1529
     a false match.  */
1530
156k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
101k
    {
1532
101k
      bfd_set_error (bfd_error_wrong_format);
1533
101k
      return NULL;
1534
101k
    }
1535
1536
54.9k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
54.9k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
54.9k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
212
    {
1540
212
      if (bfd_get_error () != bfd_error_system_call)
1541
212
  bfd_set_error (bfd_error_wrong_format);
1542
212
      return NULL;
1543
212
    }
1544
1545
54.7k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
442
    {
1547
442
      bfd_set_error (bfd_error_wrong_format);
1548
442
      return NULL;
1549
442
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
54.2k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
54.2k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
5.56k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
48.7k
    {
1558
48.7k
      bfd_set_error (bfd_error_wrong_format);
1559
48.7k
      return NULL;
1560
48.7k
    }
1561
1562
5.55k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
5.55k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
5.55k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
5.55k
  if (opt_hdr_size != 0)
1569
3.45k
    {
1570
3.45k
      bfd_size_type amt = opt_hdr_size;
1571
3.45k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
3.45k
      if (amt < sizeof (PEAOUTHDR))
1575
3.22k
  amt = sizeof (PEAOUTHDR);
1576
1577
3.45k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
3.45k
      if (opthdr == NULL)
1579
44
  return NULL;
1580
3.40k
      if (amt > opt_hdr_size)
1581
3.19k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
3.40k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
3.40k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1586
1587
#ifdef ARM
1588
      /* Use Subsystem to distinguish between pei-arm-little and
1589
   pei-arm-wince-little.  */
1590
#ifdef WINCE
1591
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1592
#else
1593
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1594
#endif
1595
  {
1596
    bfd_set_error (bfd_error_wrong_format);
1597
    return NULL;
1598
  }
1599
#endif
1600
1601
3.40k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
1.70k
    || a->SectionAlignment >= 0x80000000)
1603
1.72k
  {
1604
1.72k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
1.72k
            abfd);
1606
1.72k
    a->SectionAlignment &= -a->SectionAlignment;
1607
1.72k
    if (a->SectionAlignment >= 0x80000000)
1608
16
      a->SectionAlignment = 0x40000000;
1609
1.72k
  }
1610
1611
3.40k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
1.76k
    || a->FileAlignment > a->SectionAlignment)
1613
2.00k
  {
1614
2.00k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
2.00k
            abfd);
1616
2.00k
    a->FileAlignment &= -a->FileAlignment;
1617
2.00k
    if (a->FileAlignment > a->SectionAlignment)
1618
1.54k
      a->FileAlignment = a->SectionAlignment;
1619
2.00k
  }
1620
1621
3.40k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
1.91k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
3.40k
    }
1624
1625
5.51k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
5.51k
             (opt_hdr_size != 0
1627
5.51k
        ? &internal_a
1628
5.51k
        : (struct internal_aouthdr *) NULL));
1629
1630
5.51k
  if (result)
1631
3.62k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
3.62k
      pe_bfd_read_buildid(abfd);
1634
3.62k
    }
1635
1636
5.51k
  return result;
1637
5.55k
}
1638
1639
17.2k
#define coff_object_p pe_bfd_object_p
1640
#endif /* COFF_IMAGE_WITH_PE */