Coverage Report

Created: 2026-09-14 08:07

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
67.3k
{
137
67.3k
  RELOC *reloc_src = src;
138
67.3k
  struct internal_reloc *reloc_dst = dst;
139
140
67.3k
  memset (reloc_dst, 0, sizeof (*reloc_dst));
141
67.3k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
142
67.3k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
143
67.3k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
144
#ifdef SWAP_IN_RELOC_OFFSET
145
27.5k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
146
#endif
147
67.3k
}
pei-i386.c:coff_swap_reloc_in
Line
Count
Source
136
4.25k
{
137
4.25k
  RELOC *reloc_src = src;
138
4.25k
  struct internal_reloc *reloc_dst = dst;
139
140
4.25k
  memset (reloc_dst, 0, sizeof (*reloc_dst));
141
4.25k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
142
4.25k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
143
4.25k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
144
#ifdef SWAP_IN_RELOC_OFFSET
145
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
146
#endif
147
4.25k
}
pe-x86_64.c:coff_swap_reloc_in
Line
Count
Source
136
3.64k
{
137
3.64k
  RELOC *reloc_src = src;
138
3.64k
  struct internal_reloc *reloc_dst = dst;
139
140
3.64k
  memset (reloc_dst, 0, sizeof (*reloc_dst));
141
3.64k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
142
3.64k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
143
3.64k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
144
#ifdef SWAP_IN_RELOC_OFFSET
145
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
146
#endif
147
3.64k
}
pei-x86_64.c:coff_swap_reloc_in
Line
Count
Source
136
5.04k
{
137
5.04k
  RELOC *reloc_src = src;
138
5.04k
  struct internal_reloc *reloc_dst = dst;
139
140
5.04k
  memset (reloc_dst, 0, sizeof (*reloc_dst));
141
5.04k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
142
5.04k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
143
5.04k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
144
#ifdef SWAP_IN_RELOC_OFFSET
145
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
146
#endif
147
5.04k
}
pe-aarch64.c:coff_swap_reloc_in
Line
Count
Source
136
8.68k
{
137
8.68k
  RELOC *reloc_src = src;
138
8.68k
  struct internal_reloc *reloc_dst = dst;
139
140
8.68k
  memset (reloc_dst, 0, sizeof (*reloc_dst));
141
8.68k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
142
8.68k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
143
8.68k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
144
#ifdef SWAP_IN_RELOC_OFFSET
145
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
146
#endif
147
8.68k
}
pei-aarch64.c:coff_swap_reloc_in
Line
Count
Source
136
4.19k
{
137
4.19k
  RELOC *reloc_src = src;
138
4.19k
  struct internal_reloc *reloc_dst = dst;
139
140
4.19k
  memset (reloc_dst, 0, sizeof (*reloc_dst));
141
4.19k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
142
4.19k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
143
4.19k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
144
#ifdef SWAP_IN_RELOC_OFFSET
145
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
146
#endif
147
4.19k
}
pei-ia64.c:coff_swap_reloc_in
Line
Count
Source
136
3.47k
{
137
3.47k
  RELOC *reloc_src = src;
138
3.47k
  struct internal_reloc *reloc_dst = dst;
139
140
3.47k
  memset (reloc_dst, 0, sizeof (*reloc_dst));
141
3.47k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
142
3.47k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
143
3.47k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
144
#ifdef SWAP_IN_RELOC_OFFSET
145
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
146
#endif
147
3.47k
}
pei-loongarch64.c:coff_swap_reloc_in
Line
Count
Source
136
3.64k
{
137
3.64k
  RELOC *reloc_src = src;
138
3.64k
  struct internal_reloc *reloc_dst = dst;
139
140
3.64k
  memset (reloc_dst, 0, sizeof (*reloc_dst));
141
3.64k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
142
3.64k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
143
3.64k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
144
3.64k
#ifdef SWAP_IN_RELOC_OFFSET
145
3.64k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
146
3.64k
#endif
147
3.64k
}
pei-riscv64.c:coff_swap_reloc_in
Line
Count
Source
136
3.40k
{
137
3.40k
  RELOC *reloc_src = src;
138
3.40k
  struct internal_reloc *reloc_dst = dst;
139
140
3.40k
  memset (reloc_dst, 0, sizeof (*reloc_dst));
141
3.40k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
142
3.40k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
143
3.40k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
144
3.40k
#ifdef SWAP_IN_RELOC_OFFSET
145
3.40k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
146
3.40k
#endif
147
3.40k
}
pe-arm-wince.c:coff_swap_reloc_in
Line
Count
Source
136
1.81k
{
137
1.81k
  RELOC *reloc_src = src;
138
1.81k
  struct internal_reloc *reloc_dst = dst;
139
140
1.81k
  memset (reloc_dst, 0, sizeof (*reloc_dst));
141
1.81k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
142
1.81k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
143
1.81k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
144
1.81k
#ifdef SWAP_IN_RELOC_OFFSET
145
1.81k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
146
1.81k
#endif
147
1.81k
}
pe-arm.c:coff_swap_reloc_in
Line
Count
Source
136
1.81k
{
137
1.81k
  RELOC *reloc_src = src;
138
1.81k
  struct internal_reloc *reloc_dst = dst;
139
140
1.81k
  memset (reloc_dst, 0, sizeof (*reloc_dst));
141
1.81k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
142
1.81k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
143
1.81k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
144
1.81k
#ifdef SWAP_IN_RELOC_OFFSET
145
1.81k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
146
1.81k
#endif
147
1.81k
}
pe-i386.c:coff_swap_reloc_in
Line
Count
Source
136
4.69k
{
137
4.69k
  RELOC *reloc_src = src;
138
4.69k
  struct internal_reloc *reloc_dst = dst;
139
140
4.69k
  memset (reloc_dst, 0, sizeof (*reloc_dst));
141
4.69k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
142
4.69k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
143
4.69k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
144
#ifdef SWAP_IN_RELOC_OFFSET
145
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
146
#endif
147
4.69k
}
pe-mcore.c:coff_swap_reloc_in
Line
Count
Source
136
4.62k
{
137
4.62k
  RELOC *reloc_src = src;
138
4.62k
  struct internal_reloc *reloc_dst = dst;
139
140
4.62k
  memset (reloc_dst, 0, sizeof (*reloc_dst));
141
4.62k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
142
4.62k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
143
4.62k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
144
4.62k
#ifdef SWAP_IN_RELOC_OFFSET
145
4.62k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
146
4.62k
#endif
147
4.62k
}
pe-sh.c:coff_swap_reloc_in
Line
Count
Source
136
3.19k
{
137
3.19k
  RELOC *reloc_src = src;
138
3.19k
  struct internal_reloc *reloc_dst = dst;
139
140
3.19k
  memset (reloc_dst, 0, sizeof (*reloc_dst));
141
3.19k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
142
3.19k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
143
3.19k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
144
#ifdef SWAP_IN_RELOC_OFFSET
145
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
146
#endif
147
3.19k
}
pei-arm-wince.c:coff_swap_reloc_in
Line
Count
Source
136
4.23k
{
137
4.23k
  RELOC *reloc_src = src;
138
4.23k
  struct internal_reloc *reloc_dst = dst;
139
140
4.23k
  memset (reloc_dst, 0, sizeof (*reloc_dst));
141
4.23k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
142
4.23k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
143
4.23k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
144
4.23k
#ifdef SWAP_IN_RELOC_OFFSET
145
4.23k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
146
4.23k
#endif
147
4.23k
}
pei-arm.c:coff_swap_reloc_in
Line
Count
Source
136
4.57k
{
137
4.57k
  RELOC *reloc_src = src;
138
4.57k
  struct internal_reloc *reloc_dst = dst;
139
140
4.57k
  memset (reloc_dst, 0, sizeof (*reloc_dst));
141
4.57k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
142
4.57k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
143
4.57k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
144
4.57k
#ifdef SWAP_IN_RELOC_OFFSET
145
4.57k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
146
4.57k
#endif
147
4.57k
}
pei-mcore.c:coff_swap_reloc_in
Line
Count
Source
136
3.47k
{
137
3.47k
  RELOC *reloc_src = src;
138
3.47k
  struct internal_reloc *reloc_dst = dst;
139
140
3.47k
  memset (reloc_dst, 0, sizeof (*reloc_dst));
141
3.47k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
142
3.47k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
143
3.47k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
144
3.47k
#ifdef SWAP_IN_RELOC_OFFSET
145
3.47k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
146
3.47k
#endif
147
3.47k
}
pei-sh.c:coff_swap_reloc_in
Line
Count
Source
136
2.53k
{
137
2.53k
  RELOC *reloc_src = src;
138
2.53k
  struct internal_reloc *reloc_dst = dst;
139
140
2.53k
  memset (reloc_dst, 0, sizeof (*reloc_dst));
141
2.53k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
142
2.53k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
143
2.53k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
144
#ifdef SWAP_IN_RELOC_OFFSET
145
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
146
#endif
147
2.53k
}
148
149
static unsigned int
150
coff_swap_reloc_out (bfd *abfd, void *src, void *dst)
151
89
{
152
89
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
153
89
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
154
155
89
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
156
89
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
157
89
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
158
159
#ifdef SWAP_OUT_RELOC_OFFSET
160
14
  SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
161
#endif
162
#ifdef SWAP_OUT_RELOC_EXTRA
163
  SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
164
#endif
165
89
  return RELSZ;
166
89
}
Unexecuted instantiation: pei-i386.c:coff_swap_reloc_out
pe-x86_64.c:coff_swap_reloc_out
Line
Count
Source
151
1
{
152
1
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
153
1
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
154
155
1
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
156
1
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
157
1
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
158
159
#ifdef SWAP_OUT_RELOC_OFFSET
160
  SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
161
#endif
162
#ifdef SWAP_OUT_RELOC_EXTRA
163
  SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
164
#endif
165
1
  return RELSZ;
166
1
}
pei-x86_64.c:coff_swap_reloc_out
Line
Count
Source
151
8
{
152
8
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
153
8
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
154
155
8
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
156
8
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
157
8
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
158
159
#ifdef SWAP_OUT_RELOC_OFFSET
160
  SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
161
#endif
162
#ifdef SWAP_OUT_RELOC_EXTRA
163
  SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
164
#endif
165
8
  return RELSZ;
166
8
}
pe-aarch64.c:coff_swap_reloc_out
Line
Count
Source
151
60
{
152
60
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
153
60
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
154
155
60
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
156
60
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
157
60
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
158
159
#ifdef SWAP_OUT_RELOC_OFFSET
160
  SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
161
#endif
162
#ifdef SWAP_OUT_RELOC_EXTRA
163
  SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
164
#endif
165
60
  return RELSZ;
166
60
}
pei-aarch64.c:coff_swap_reloc_out
Line
Count
Source
151
2
{
152
2
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
153
2
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
154
155
2
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
156
2
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
157
2
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
158
159
#ifdef SWAP_OUT_RELOC_OFFSET
160
  SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
161
#endif
162
#ifdef SWAP_OUT_RELOC_EXTRA
163
  SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
164
#endif
165
2
  return RELSZ;
166
2
}
Unexecuted instantiation: pei-ia64.c:coff_swap_reloc_out
pei-loongarch64.c:coff_swap_reloc_out
Line
Count
Source
151
5
{
152
5
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
153
5
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
154
155
5
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
156
5
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
157
5
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
158
159
5
#ifdef SWAP_OUT_RELOC_OFFSET
160
5
  SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
161
5
#endif
162
#ifdef SWAP_OUT_RELOC_EXTRA
163
  SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
164
#endif
165
5
  return RELSZ;
166
5
}
pei-riscv64.c:coff_swap_reloc_out
Line
Count
Source
151
5
{
152
5
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
153
5
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
154
155
5
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
156
5
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
157
5
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
158
159
5
#ifdef SWAP_OUT_RELOC_OFFSET
160
5
  SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
161
5
#endif
162
#ifdef SWAP_OUT_RELOC_EXTRA
163
  SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
164
#endif
165
5
  return RELSZ;
166
5
}
Unexecuted instantiation: pe-arm-wince.c:coff_swap_reloc_out
Unexecuted instantiation: pe-arm.c:coff_swap_reloc_out
Unexecuted instantiation: pe-i386.c:coff_swap_reloc_out
Unexecuted instantiation: pe-mcore.c:coff_swap_reloc_out
Unexecuted instantiation: pe-sh.c:coff_swap_reloc_out
Unexecuted instantiation: pei-arm-wince.c:coff_swap_reloc_out
pei-arm.c:coff_swap_reloc_out
Line
Count
Source
151
4
{
152
4
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
153
4
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
154
155
4
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
156
4
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
157
4
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
158
159
4
#ifdef SWAP_OUT_RELOC_OFFSET
160
4
  SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
161
4
#endif
162
#ifdef SWAP_OUT_RELOC_EXTRA
163
  SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
164
#endif
165
4
  return RELSZ;
166
4
}
Unexecuted instantiation: pei-mcore.c:coff_swap_reloc_out
pei-sh.c:coff_swap_reloc_out
Line
Count
Source
151
4
{
152
4
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
153
4
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
154
155
4
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
156
4
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
157
4
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
158
159
#ifdef SWAP_OUT_RELOC_OFFSET
160
  SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
161
#endif
162
#ifdef SWAP_OUT_RELOC_EXTRA
163
  SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
164
#endif
165
4
  return RELSZ;
166
4
}
167
#endif /* not NO_COFF_RELOCS */
168
169
#ifdef COFF_IMAGE_WITH_PE
170
#undef FILHDR
171
479k
#define FILHDR struct external_PEI_IMAGE_hdr
172
#endif
173
174
static void
175
coff_swap_filehdr_in (bfd *abfd, void *src, void *dst)
176
2.36M
{
177
2.36M
  FILHDR *filehdr_src = (FILHDR *) src;
178
2.36M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
179
180
2.36M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
181
2.36M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
182
2.36M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
183
2.36M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
184
2.36M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
185
2.36M
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
186
187
  /* Other people's tools sometimes generate headers with an nsyms but
188
     a zero symptr.  */
189
2.36M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
190
243k
    {
191
243k
      filehdr_dst->f_nsyms = 0;
192
243k
      filehdr_dst->f_flags |= F_LSYMS;
193
243k
    }
194
195
2.36M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
196
2.36M
}
pei-i386.c:coff_swap_filehdr_in
Line
Count
Source
176
54.6k
{
177
54.6k
  FILHDR *filehdr_src = (FILHDR *) src;
178
54.6k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
179
180
54.6k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
181
54.6k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
182
54.6k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
183
54.6k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
184
54.6k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
185
54.6k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
186
187
  /* Other people's tools sometimes generate headers with an nsyms but
188
     a zero symptr.  */
189
54.6k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
190
5.61k
    {
191
5.61k
      filehdr_dst->f_nsyms = 0;
192
5.61k
      filehdr_dst->f_flags |= F_LSYMS;
193
5.61k
    }
194
195
54.6k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
196
54.6k
}
pe-x86_64.c:coff_swap_filehdr_in
Line
Count
Source
176
206k
{
177
206k
  FILHDR *filehdr_src = (FILHDR *) src;
178
206k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
179
180
206k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
181
206k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
182
206k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
183
206k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
184
206k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
185
206k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
186
187
  /* Other people's tools sometimes generate headers with an nsyms but
188
     a zero symptr.  */
189
206k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
190
22.4k
    {
191
22.4k
      filehdr_dst->f_nsyms = 0;
192
22.4k
      filehdr_dst->f_flags |= F_LSYMS;
193
22.4k
    }
194
195
206k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
196
206k
}
pei-x86_64.c:coff_swap_filehdr_in
Line
Count
Source
176
53.6k
{
177
53.6k
  FILHDR *filehdr_src = (FILHDR *) src;
178
53.6k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
179
180
53.6k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
181
53.6k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
182
53.6k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
183
53.6k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
184
53.6k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
185
53.6k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
186
187
  /* Other people's tools sometimes generate headers with an nsyms but
188
     a zero symptr.  */
189
53.6k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
190
5.44k
    {
191
5.44k
      filehdr_dst->f_nsyms = 0;
192
5.44k
      filehdr_dst->f_flags |= F_LSYMS;
193
5.44k
    }
194
195
53.6k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
196
53.6k
}
pe-aarch64.c:coff_swap_filehdr_in
Line
Count
Source
176
204k
{
177
204k
  FILHDR *filehdr_src = (FILHDR *) src;
178
204k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
179
180
204k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
181
204k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
182
204k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
183
204k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
184
204k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
185
204k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
186
187
  /* Other people's tools sometimes generate headers with an nsyms but
188
     a zero symptr.  */
189
204k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
190
22.2k
    {
191
22.2k
      filehdr_dst->f_nsyms = 0;
192
22.2k
      filehdr_dst->f_flags |= F_LSYMS;
193
22.2k
    }
194
195
204k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
196
204k
}
pei-aarch64.c:coff_swap_filehdr_in
Line
Count
Source
176
52.1k
{
177
52.1k
  FILHDR *filehdr_src = (FILHDR *) src;
178
52.1k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
179
180
52.1k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
181
52.1k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
182
52.1k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
183
52.1k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
184
52.1k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
185
52.1k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
186
187
  /* Other people's tools sometimes generate headers with an nsyms but
188
     a zero symptr.  */
189
52.1k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
190
5.36k
    {
191
5.36k
      filehdr_dst->f_nsyms = 0;
192
5.36k
      filehdr_dst->f_flags |= F_LSYMS;
193
5.36k
    }
194
195
52.1k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
196
52.1k
}
pei-ia64.c:coff_swap_filehdr_in
Line
Count
Source
176
16.3k
{
177
16.3k
  FILHDR *filehdr_src = (FILHDR *) src;
178
16.3k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
179
180
16.3k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
181
16.3k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
182
16.3k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
183
16.3k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
184
16.3k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
185
16.3k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
186
187
  /* Other people's tools sometimes generate headers with an nsyms but
188
     a zero symptr.  */
189
16.3k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
190
582
    {
191
582
      filehdr_dst->f_nsyms = 0;
192
582
      filehdr_dst->f_flags |= F_LSYMS;
193
582
    }
194
195
16.3k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
196
16.3k
}
pei-loongarch64.c:coff_swap_filehdr_in
Line
Count
Source
176
51.6k
{
177
51.6k
  FILHDR *filehdr_src = (FILHDR *) src;
178
51.6k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
179
180
51.6k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
181
51.6k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
182
51.6k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
183
51.6k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
184
51.6k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
185
51.6k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
186
187
  /* Other people's tools sometimes generate headers with an nsyms but
188
     a zero symptr.  */
189
51.6k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
190
5.29k
    {
191
5.29k
      filehdr_dst->f_nsyms = 0;
192
5.29k
      filehdr_dst->f_flags |= F_LSYMS;
193
5.29k
    }
194
195
51.6k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
196
51.6k
}
pei-riscv64.c:coff_swap_filehdr_in
Line
Count
Source
176
51.6k
{
177
51.6k
  FILHDR *filehdr_src = (FILHDR *) src;
178
51.6k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
179
180
51.6k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
181
51.6k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
182
51.6k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
183
51.6k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
184
51.6k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
185
51.6k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
186
187
  /* Other people's tools sometimes generate headers with an nsyms but
188
     a zero symptr.  */
189
51.6k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
190
5.22k
    {
191
5.22k
      filehdr_dst->f_nsyms = 0;
192
5.22k
      filehdr_dst->f_flags |= F_LSYMS;
193
5.22k
    }
194
195
51.6k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
196
51.6k
}
pe-arm-wince.c:coff_swap_filehdr_in
Line
Count
Source
176
361k
{
177
361k
  FILHDR *filehdr_src = (FILHDR *) src;
178
361k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
179
180
361k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
181
361k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
182
361k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
183
361k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
184
361k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
185
361k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
186
187
  /* Other people's tools sometimes generate headers with an nsyms but
188
     a zero symptr.  */
189
361k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
190
36.6k
    {
191
36.6k
      filehdr_dst->f_nsyms = 0;
192
36.6k
      filehdr_dst->f_flags |= F_LSYMS;
193
36.6k
    }
194
195
361k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
196
361k
}
pe-arm.c:coff_swap_filehdr_in
Line
Count
Source
176
361k
{
177
361k
  FILHDR *filehdr_src = (FILHDR *) src;
178
361k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
179
180
361k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
181
361k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
182
361k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
183
361k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
184
361k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
185
361k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
186
187
  /* Other people's tools sometimes generate headers with an nsyms but
188
     a zero symptr.  */
189
361k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
190
36.6k
    {
191
36.6k
      filehdr_dst->f_nsyms = 0;
192
36.6k
      filehdr_dst->f_flags |= F_LSYMS;
193
36.6k
    }
194
195
361k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
196
361k
}
pe-i386.c:coff_swap_filehdr_in
Line
Count
Source
176
204k
{
177
204k
  FILHDR *filehdr_src = (FILHDR *) src;
178
204k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
179
180
204k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
181
204k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
182
204k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
183
204k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
184
204k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
185
204k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
186
187
  /* Other people's tools sometimes generate headers with an nsyms but
188
     a zero symptr.  */
189
204k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
190
22.3k
    {
191
22.3k
      filehdr_dst->f_nsyms = 0;
192
22.3k
      filehdr_dst->f_flags |= F_LSYMS;
193
22.3k
    }
194
195
204k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
196
204k
}
pe-mcore.c:coff_swap_filehdr_in
Line
Count
Source
176
362k
{
177
362k
  FILHDR *filehdr_src = (FILHDR *) src;
178
362k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
179
180
362k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
181
362k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
182
362k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
183
362k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
184
362k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
185
362k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
186
187
  /* Other people's tools sometimes generate headers with an nsyms but
188
     a zero symptr.  */
189
362k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
190
36.8k
    {
191
36.8k
      filehdr_dst->f_nsyms = 0;
192
36.8k
      filehdr_dst->f_flags |= F_LSYMS;
193
36.8k
    }
194
195
362k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
196
362k
}
pe-sh.c:coff_swap_filehdr_in
Line
Count
Source
176
182k
{
177
182k
  FILHDR *filehdr_src = (FILHDR *) src;
178
182k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
179
180
182k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
181
182k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
182
182k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
183
182k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
184
182k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
185
182k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
186
187
  /* Other people's tools sometimes generate headers with an nsyms but
188
     a zero symptr.  */
189
182k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
190
18.5k
    {
191
18.5k
      filehdr_dst->f_nsyms = 0;
192
18.5k
      filehdr_dst->f_flags |= F_LSYMS;
193
18.5k
    }
194
195
182k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
196
182k
}
pei-arm-wince.c:coff_swap_filehdr_in
Line
Count
Source
176
49.9k
{
177
49.9k
  FILHDR *filehdr_src = (FILHDR *) src;
178
49.9k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
179
180
49.9k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
181
49.9k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
182
49.9k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
183
49.9k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
184
49.9k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
185
49.9k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
186
187
  /* Other people's tools sometimes generate headers with an nsyms but
188
     a zero symptr.  */
189
49.9k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
190
5.25k
    {
191
5.25k
      filehdr_dst->f_nsyms = 0;
192
5.25k
      filehdr_dst->f_flags |= F_LSYMS;
193
5.25k
    }
194
195
49.9k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
196
49.9k
}
pei-arm.c:coff_swap_filehdr_in
Line
Count
Source
176
50.2k
{
177
50.2k
  FILHDR *filehdr_src = (FILHDR *) src;
178
50.2k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
179
180
50.2k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
181
50.2k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
182
50.2k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
183
50.2k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
184
50.2k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
185
50.2k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
186
187
  /* Other people's tools sometimes generate headers with an nsyms but
188
     a zero symptr.  */
189
50.2k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
190
5.24k
    {
191
5.24k
      filehdr_dst->f_nsyms = 0;
192
5.24k
      filehdr_dst->f_flags |= F_LSYMS;
193
5.24k
    }
194
195
50.2k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
196
50.2k
}
pei-mcore.c:coff_swap_filehdr_in
Line
Count
Source
176
49.8k
{
177
49.8k
  FILHDR *filehdr_src = (FILHDR *) src;
178
49.8k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
179
180
49.8k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
181
49.8k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
182
49.8k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
183
49.8k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
184
49.8k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
185
49.8k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
186
187
  /* Other people's tools sometimes generate headers with an nsyms but
188
     a zero symptr.  */
189
49.8k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
190
5.17k
    {
191
5.17k
      filehdr_dst->f_nsyms = 0;
192
5.17k
      filehdr_dst->f_flags |= F_LSYMS;
193
5.17k
    }
194
195
49.8k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
196
49.8k
}
pei-sh.c:coff_swap_filehdr_in
Line
Count
Source
176
49.7k
{
177
49.7k
  FILHDR *filehdr_src = (FILHDR *) src;
178
49.7k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
179
180
49.7k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
181
49.7k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
182
49.7k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
183
49.7k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
184
49.7k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
185
49.7k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
186
187
  /* Other people's tools sometimes generate headers with an nsyms but
188
     a zero symptr.  */
189
49.7k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
190
5.13k
    {
191
5.13k
      filehdr_dst->f_nsyms = 0;
192
5.13k
      filehdr_dst->f_flags |= F_LSYMS;
193
5.13k
    }
194
195
49.7k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
196
49.7k
}
197
198
#ifdef COFF_IMAGE_WITH_PE
199
# define coff_swap_filehdr_out _bfd_XXi_only_swap_filehdr_out
200
#elif defined COFF_WITH_peAArch64
201
# define coff_swap_filehdr_out _bfd_XX_only_swap_filehdr_out
202
#elif defined COFF_WITH_pex64
203
# define coff_swap_filehdr_out _bfd_pex64_only_swap_filehdr_out
204
#elif defined COFF_WITH_pep
205
# define coff_swap_filehdr_out _bfd_pep_only_swap_filehdr_out
206
#else
207
# define coff_swap_filehdr_out _bfd_pe_only_swap_filehdr_out
208
#endif
209
210
static void
211
coff_swap_scnhdr_in (bfd *abfd, void *ext, void *in)
212
859k
{
213
859k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
214
859k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
215
216
859k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
217
218
859k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
219
859k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
220
859k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
221
859k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
222
859k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
223
859k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
224
859k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
225
226
  /* MS handles overflow of line numbers by carrying into the reloc
227
     field (it appears).  Since it's supposed to be zero for PE
228
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
229
#ifdef COFF_IMAGE_WITH_PE
230
572k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
231
572k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
232
  scnhdr_int->s_nreloc = 0;
233
#else
234
286k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
235
286k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
236
#endif
237
238
859k
  if (scnhdr_int->s_vaddr != 0)
239
560k
    {
240
560k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
241
      /* Do not cut upper 32-bits for 64-bit vma.  */
242
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
243
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
244
      scnhdr_int->s_vaddr &= 0xffffffff;
245
#endif
246
560k
    }
247
248
859k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
249
  /* If this section holds uninitialized data and is from an object file
250
     or from an executable image that has not initialized the field,
251
     or if the image is an executable file and the physical size is padded,
252
     use the virtual size (stored in s_paddr) instead.  */
253
859k
  if (scnhdr_int->s_paddr > 0
254
621k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
255
141k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
256
563k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
257
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
258
     coff_set_alignment_hook stores s_paddr in virt_size, which
259
     only works if it correctly holds the virtual size of the
260
     section.  */
261
177k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
262
859k
#endif
263
859k
}
pei-i386.c:coff_swap_scnhdr_in
Line
Count
Source
212
60.0k
{
213
60.0k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
214
60.0k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
215
216
60.0k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
217
218
60.0k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
219
60.0k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
220
60.0k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
221
60.0k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
222
60.0k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
223
60.0k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
224
60.0k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
225
226
  /* MS handles overflow of line numbers by carrying into the reloc
227
     field (it appears).  Since it's supposed to be zero for PE
228
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
229
60.0k
#ifdef COFF_IMAGE_WITH_PE
230
60.0k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
231
60.0k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
232
60.0k
  scnhdr_int->s_nreloc = 0;
233
#else
234
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
235
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
236
#endif
237
238
60.0k
  if (scnhdr_int->s_vaddr != 0)
239
38.9k
    {
240
38.9k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
241
      /* Do not cut upper 32-bits for 64-bit vma.  */
242
38.9k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
243
38.9k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
244
38.9k
      scnhdr_int->s_vaddr &= 0xffffffff;
245
38.9k
#endif
246
38.9k
    }
247
248
60.0k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
249
  /* If this section holds uninitialized data and is from an object file
250
     or from an executable image that has not initialized the field,
251
     or if the image is an executable file and the physical size is padded,
252
     use the virtual size (stored in s_paddr) instead.  */
253
60.0k
  if (scnhdr_int->s_paddr > 0
254
43.8k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
255
9.63k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
256
42.6k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
257
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
258
     coff_set_alignment_hook stores s_paddr in virt_size, which
259
     only works if it correctly holds the virtual size of the
260
     section.  */
261
16.1k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
262
60.0k
#endif
263
60.0k
}
pe-x86_64.c:coff_swap_scnhdr_in
Line
Count
Source
212
60.2k
{
213
60.2k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
214
60.2k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
215
216
60.2k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
217
218
60.2k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
219
60.2k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
220
60.2k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
221
60.2k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
222
60.2k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
223
60.2k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
224
60.2k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
225
226
  /* MS handles overflow of line numbers by carrying into the reloc
227
     field (it appears).  Since it's supposed to be zero for PE
228
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
229
#ifdef COFF_IMAGE_WITH_PE
230
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
231
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
232
  scnhdr_int->s_nreloc = 0;
233
#else
234
60.2k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
235
60.2k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
236
60.2k
#endif
237
238
60.2k
  if (scnhdr_int->s_vaddr != 0)
239
31.8k
    {
240
31.8k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
241
      /* Do not cut upper 32-bits for 64-bit vma.  */
242
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
243
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
244
      scnhdr_int->s_vaddr &= 0xffffffff;
245
#endif
246
31.8k
    }
247
248
60.2k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
249
  /* If this section holds uninitialized data and is from an object file
250
     or from an executable image that has not initialized the field,
251
     or if the image is an executable file and the physical size is padded,
252
     use the virtual size (stored in s_paddr) instead.  */
253
60.2k
  if (scnhdr_int->s_paddr > 0
254
34.3k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
255
7.35k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
256
27.0k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
257
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
258
     coff_set_alignment_hook stores s_paddr in virt_size, which
259
     only works if it correctly holds the virtual size of the
260
     section.  */
261
7.35k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
262
60.2k
#endif
263
60.2k
}
pei-x86_64.c:coff_swap_scnhdr_in
Line
Count
Source
212
68.7k
{
213
68.7k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
214
68.7k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
215
216
68.7k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
217
218
68.7k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
219
68.7k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
220
68.7k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
221
68.7k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
222
68.7k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
223
68.7k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
224
68.7k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
225
226
  /* MS handles overflow of line numbers by carrying into the reloc
227
     field (it appears).  Since it's supposed to be zero for PE
228
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
229
68.7k
#ifdef COFF_IMAGE_WITH_PE
230
68.7k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
231
68.7k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
232
68.7k
  scnhdr_int->s_nreloc = 0;
233
#else
234
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
235
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
236
#endif
237
238
68.7k
  if (scnhdr_int->s_vaddr != 0)
239
44.3k
    {
240
44.3k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
241
      /* Do not cut upper 32-bits for 64-bit vma.  */
242
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
243
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
244
      scnhdr_int->s_vaddr &= 0xffffffff;
245
#endif
246
44.3k
    }
247
248
68.7k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
249
  /* If this section holds uninitialized data and is from an object file
250
     or from an executable image that has not initialized the field,
251
     or if the image is an executable file and the physical size is padded,
252
     use the virtual size (stored in s_paddr) instead.  */
253
68.7k
  if (scnhdr_int->s_paddr > 0
254
47.6k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
255
12.1k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
256
46.2k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
257
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
258
     coff_set_alignment_hook stores s_paddr in virt_size, which
259
     only works if it correctly holds the virtual size of the
260
     section.  */
261
15.6k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
262
68.7k
#endif
263
68.7k
}
pe-aarch64.c:coff_swap_scnhdr_in
Line
Count
Source
212
49.1k
{
213
49.1k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
214
49.1k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
215
216
49.1k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
217
218
49.1k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
219
49.1k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
220
49.1k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
221
49.1k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
222
49.1k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
223
49.1k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
224
49.1k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
225
226
  /* MS handles overflow of line numbers by carrying into the reloc
227
     field (it appears).  Since it's supposed to be zero for PE
228
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
229
#ifdef COFF_IMAGE_WITH_PE
230
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
231
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
232
  scnhdr_int->s_nreloc = 0;
233
#else
234
49.1k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
235
49.1k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
236
49.1k
#endif
237
238
49.1k
  if (scnhdr_int->s_vaddr != 0)
239
32.3k
    {
240
32.3k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
241
      /* Do not cut upper 32-bits for 64-bit vma.  */
242
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
243
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
244
      scnhdr_int->s_vaddr &= 0xffffffff;
245
#endif
246
32.3k
    }
247
248
49.1k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
249
  /* If this section holds uninitialized data and is from an object file
250
     or from an executable image that has not initialized the field,
251
     or if the image is an executable file and the physical size is padded,
252
     use the virtual size (stored in s_paddr) instead.  */
253
49.1k
  if (scnhdr_int->s_paddr > 0
254
34.2k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
255
5.54k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
256
28.7k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
257
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
258
     coff_set_alignment_hook stores s_paddr in virt_size, which
259
     only works if it correctly holds the virtual size of the
260
     section.  */
261
5.54k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
262
49.1k
#endif
263
49.1k
}
pei-aarch64.c:coff_swap_scnhdr_in
Line
Count
Source
212
72.4k
{
213
72.4k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
214
72.4k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
215
216
72.4k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
217
218
72.4k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
219
72.4k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
220
72.4k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
221
72.4k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
222
72.4k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
223
72.4k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
224
72.4k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
225
226
  /* MS handles overflow of line numbers by carrying into the reloc
227
     field (it appears).  Since it's supposed to be zero for PE
228
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
229
72.4k
#ifdef COFF_IMAGE_WITH_PE
230
72.4k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
231
72.4k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
232
72.4k
  scnhdr_int->s_nreloc = 0;
233
#else
234
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
235
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
236
#endif
237
238
72.4k
  if (scnhdr_int->s_vaddr != 0)
239
52.4k
    {
240
52.4k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
241
      /* Do not cut upper 32-bits for 64-bit vma.  */
242
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
243
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
244
      scnhdr_int->s_vaddr &= 0xffffffff;
245
#endif
246
52.4k
    }
247
248
72.4k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
249
  /* If this section holds uninitialized data and is from an object file
250
     or from an executable image that has not initialized the field,
251
     or if the image is an executable file and the physical size is padded,
252
     use the virtual size (stored in s_paddr) instead.  */
253
72.4k
  if (scnhdr_int->s_paddr > 0
254
53.9k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
255
10.9k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
256
52.1k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
257
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
258
     coff_set_alignment_hook stores s_paddr in virt_size, which
259
     only works if it correctly holds the virtual size of the
260
     section.  */
261
19.1k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
262
72.4k
#endif
263
72.4k
}
pei-ia64.c:coff_swap_scnhdr_in
Line
Count
Source
212
56.8k
{
213
56.8k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
214
56.8k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
215
216
56.8k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
217
218
56.8k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
219
56.8k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
220
56.8k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
221
56.8k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
222
56.8k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
223
56.8k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
224
56.8k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
225
226
  /* MS handles overflow of line numbers by carrying into the reloc
227
     field (it appears).  Since it's supposed to be zero for PE
228
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
229
56.8k
#ifdef COFF_IMAGE_WITH_PE
230
56.8k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
231
56.8k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
232
56.8k
  scnhdr_int->s_nreloc = 0;
233
#else
234
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
235
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
236
#endif
237
238
56.8k
  if (scnhdr_int->s_vaddr != 0)
239
37.9k
    {
240
37.9k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
241
      /* Do not cut upper 32-bits for 64-bit vma.  */
242
37.9k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
243
37.9k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
244
37.9k
      scnhdr_int->s_vaddr &= 0xffffffff;
245
37.9k
#endif
246
37.9k
    }
247
248
56.8k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
249
  /* If this section holds uninitialized data and is from an object file
250
     or from an executable image that has not initialized the field,
251
     or if the image is an executable file and the physical size is padded,
252
     use the virtual size (stored in s_paddr) instead.  */
253
56.8k
  if (scnhdr_int->s_paddr > 0
254
41.9k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
255
10.2k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
256
40.1k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
257
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
258
     coff_set_alignment_hook stores s_paddr in virt_size, which
259
     only works if it correctly holds the virtual size of the
260
     section.  */
261
13.2k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
262
56.8k
#endif
263
56.8k
}
pei-loongarch64.c:coff_swap_scnhdr_in
Line
Count
Source
212
53.0k
{
213
53.0k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
214
53.0k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
215
216
53.0k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
217
218
53.0k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
219
53.0k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
220
53.0k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
221
53.0k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
222
53.0k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
223
53.0k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
224
53.0k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
225
226
  /* MS handles overflow of line numbers by carrying into the reloc
227
     field (it appears).  Since it's supposed to be zero for PE
228
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
229
53.0k
#ifdef COFF_IMAGE_WITH_PE
230
53.0k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
231
53.0k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
232
53.0k
  scnhdr_int->s_nreloc = 0;
233
#else
234
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
235
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
236
#endif
237
238
53.0k
  if (scnhdr_int->s_vaddr != 0)
239
34.5k
    {
240
34.5k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
241
      /* Do not cut upper 32-bits for 64-bit vma.  */
242
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
243
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
244
      scnhdr_int->s_vaddr &= 0xffffffff;
245
#endif
246
34.5k
    }
247
248
53.0k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
249
  /* If this section holds uninitialized data and is from an object file
250
     or from an executable image that has not initialized the field,
251
     or if the image is an executable file and the physical size is padded,
252
     use the virtual size (stored in s_paddr) instead.  */
253
53.0k
  if (scnhdr_int->s_paddr > 0
254
38.5k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
255
7.13k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
256
36.8k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
257
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
258
     coff_set_alignment_hook stores s_paddr in virt_size, which
259
     only works if it correctly holds the virtual size of the
260
     section.  */
261
12.5k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
262
53.0k
#endif
263
53.0k
}
pei-riscv64.c:coff_swap_scnhdr_in
Line
Count
Source
212
57.8k
{
213
57.8k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
214
57.8k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
215
216
57.8k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
217
218
57.8k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
219
57.8k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
220
57.8k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
221
57.8k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
222
57.8k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
223
57.8k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
224
57.8k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
225
226
  /* MS handles overflow of line numbers by carrying into the reloc
227
     field (it appears).  Since it's supposed to be zero for PE
228
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
229
57.8k
#ifdef COFF_IMAGE_WITH_PE
230
57.8k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
231
57.8k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
232
57.8k
  scnhdr_int->s_nreloc = 0;
233
#else
234
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
235
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
236
#endif
237
238
57.8k
  if (scnhdr_int->s_vaddr != 0)
239
37.8k
    {
240
37.8k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
241
      /* Do not cut upper 32-bits for 64-bit vma.  */
242
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
243
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
244
      scnhdr_int->s_vaddr &= 0xffffffff;
245
#endif
246
37.8k
    }
247
248
57.8k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
249
  /* If this section holds uninitialized data and is from an object file
250
     or from an executable image that has not initialized the field,
251
     or if the image is an executable file and the physical size is padded,
252
     use the virtual size (stored in s_paddr) instead.  */
253
57.8k
  if (scnhdr_int->s_paddr > 0
254
43.7k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
255
12.0k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
256
41.7k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
257
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
258
     coff_set_alignment_hook stores s_paddr in virt_size, which
259
     only works if it correctly holds the virtual size of the
260
     section.  */
261
12.5k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
262
57.8k
#endif
263
57.8k
}
pe-arm-wince.c:coff_swap_scnhdr_in
Line
Count
Source
212
24.5k
{
213
24.5k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
214
24.5k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
215
216
24.5k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
217
218
24.5k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
219
24.5k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
220
24.5k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
221
24.5k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
222
24.5k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
223
24.5k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
224
24.5k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
225
226
  /* MS handles overflow of line numbers by carrying into the reloc
227
     field (it appears).  Since it's supposed to be zero for PE
228
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
229
#ifdef COFF_IMAGE_WITH_PE
230
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
231
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
232
  scnhdr_int->s_nreloc = 0;
233
#else
234
24.5k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
235
24.5k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
236
24.5k
#endif
237
238
24.5k
  if (scnhdr_int->s_vaddr != 0)
239
16.1k
    {
240
16.1k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
241
      /* Do not cut upper 32-bits for 64-bit vma.  */
242
16.1k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
243
16.1k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
244
16.1k
      scnhdr_int->s_vaddr &= 0xffffffff;
245
16.1k
#endif
246
16.1k
    }
247
248
24.5k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
249
  /* If this section holds uninitialized data and is from an object file
250
     or from an executable image that has not initialized the field,
251
     or if the image is an executable file and the physical size is padded,
252
     use the virtual size (stored in s_paddr) instead.  */
253
24.5k
  if (scnhdr_int->s_paddr > 0
254
17.9k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
255
4.05k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
256
13.9k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
257
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
258
     coff_set_alignment_hook stores s_paddr in virt_size, which
259
     only works if it correctly holds the virtual size of the
260
     section.  */
261
4.05k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
262
24.5k
#endif
263
24.5k
}
pe-arm.c:coff_swap_scnhdr_in
Line
Count
Source
212
24.5k
{
213
24.5k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
214
24.5k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
215
216
24.5k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
217
218
24.5k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
219
24.5k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
220
24.5k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
221
24.5k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
222
24.5k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
223
24.5k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
224
24.5k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
225
226
  /* MS handles overflow of line numbers by carrying into the reloc
227
     field (it appears).  Since it's supposed to be zero for PE
228
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
229
#ifdef COFF_IMAGE_WITH_PE
230
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
231
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
232
  scnhdr_int->s_nreloc = 0;
233
#else
234
24.5k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
235
24.5k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
236
24.5k
#endif
237
238
24.5k
  if (scnhdr_int->s_vaddr != 0)
239
16.1k
    {
240
16.1k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
241
      /* Do not cut upper 32-bits for 64-bit vma.  */
242
16.1k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
243
16.1k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
244
16.1k
      scnhdr_int->s_vaddr &= 0xffffffff;
245
16.1k
#endif
246
16.1k
    }
247
248
24.5k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
249
  /* If this section holds uninitialized data and is from an object file
250
     or from an executable image that has not initialized the field,
251
     or if the image is an executable file and the physical size is padded,
252
     use the virtual size (stored in s_paddr) instead.  */
253
24.5k
  if (scnhdr_int->s_paddr > 0
254
17.9k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
255
4.05k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
256
13.9k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
257
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
258
     coff_set_alignment_hook stores s_paddr in virt_size, which
259
     only works if it correctly holds the virtual size of the
260
     section.  */
261
4.05k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
262
24.5k
#endif
263
24.5k
}
pe-i386.c:coff_swap_scnhdr_in
Line
Count
Source
212
55.5k
{
213
55.5k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
214
55.5k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
215
216
55.5k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
217
218
55.5k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
219
55.5k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
220
55.5k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
221
55.5k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
222
55.5k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
223
55.5k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
224
55.5k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
225
226
  /* MS handles overflow of line numbers by carrying into the reloc
227
     field (it appears).  Since it's supposed to be zero for PE
228
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
229
#ifdef COFF_IMAGE_WITH_PE
230
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
231
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
232
  scnhdr_int->s_nreloc = 0;
233
#else
234
55.5k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
235
55.5k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
236
55.5k
#endif
237
238
55.5k
  if (scnhdr_int->s_vaddr != 0)
239
36.3k
    {
240
36.3k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
241
      /* Do not cut upper 32-bits for 64-bit vma.  */
242
36.3k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
243
36.3k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
244
36.3k
      scnhdr_int->s_vaddr &= 0xffffffff;
245
36.3k
#endif
246
36.3k
    }
247
248
55.5k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
249
  /* If this section holds uninitialized data and is from an object file
250
     or from an executable image that has not initialized the field,
251
     or if the image is an executable file and the physical size is padded,
252
     use the virtual size (stored in s_paddr) instead.  */
253
55.5k
  if (scnhdr_int->s_paddr > 0
254
41.6k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
255
8.85k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
256
32.7k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
257
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
258
     coff_set_alignment_hook stores s_paddr in virt_size, which
259
     only works if it correctly holds the virtual size of the
260
     section.  */
261
8.85k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
262
55.5k
#endif
263
55.5k
}
pe-mcore.c:coff_swap_scnhdr_in
Line
Count
Source
212
27.8k
{
213
27.8k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
214
27.8k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
215
216
27.8k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
217
218
27.8k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
219
27.8k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
220
27.8k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
221
27.8k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
222
27.8k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
223
27.8k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
224
27.8k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
225
226
  /* MS handles overflow of line numbers by carrying into the reloc
227
     field (it appears).  Since it's supposed to be zero for PE
228
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
229
#ifdef COFF_IMAGE_WITH_PE
230
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
231
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
232
  scnhdr_int->s_nreloc = 0;
233
#else
234
27.8k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
235
27.8k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
236
27.8k
#endif
237
238
27.8k
  if (scnhdr_int->s_vaddr != 0)
239
17.9k
    {
240
17.9k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
241
      /* Do not cut upper 32-bits for 64-bit vma.  */
242
17.9k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
243
17.9k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
244
17.9k
      scnhdr_int->s_vaddr &= 0xffffffff;
245
17.9k
#endif
246
17.9k
    }
247
248
27.8k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
249
  /* If this section holds uninitialized data and is from an object file
250
     or from an executable image that has not initialized the field,
251
     or if the image is an executable file and the physical size is padded,
252
     use the virtual size (stored in s_paddr) instead.  */
253
27.8k
  if (scnhdr_int->s_paddr > 0
254
19.8k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
255
4.14k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
256
15.7k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
257
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
258
     coff_set_alignment_hook stores s_paddr in virt_size, which
259
     only works if it correctly holds the virtual size of the
260
     section.  */
261
4.14k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
262
27.8k
#endif
263
27.8k
}
pe-sh.c:coff_swap_scnhdr_in
Line
Count
Source
212
44.8k
{
213
44.8k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
214
44.8k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
215
216
44.8k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
217
218
44.8k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
219
44.8k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
220
44.8k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
221
44.8k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
222
44.8k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
223
44.8k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
224
44.8k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
225
226
  /* MS handles overflow of line numbers by carrying into the reloc
227
     field (it appears).  Since it's supposed to be zero for PE
228
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
229
#ifdef COFF_IMAGE_WITH_PE
230
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
231
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
232
  scnhdr_int->s_nreloc = 0;
233
#else
234
44.8k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
235
44.8k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
236
44.8k
#endif
237
238
44.8k
  if (scnhdr_int->s_vaddr != 0)
239
28.9k
    {
240
28.9k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
241
      /* Do not cut upper 32-bits for 64-bit vma.  */
242
28.9k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
243
28.9k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
244
28.9k
      scnhdr_int->s_vaddr &= 0xffffffff;
245
28.9k
#endif
246
28.9k
    }
247
248
44.8k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
249
  /* If this section holds uninitialized data and is from an object file
250
     or from an executable image that has not initialized the field,
251
     or if the image is an executable file and the physical size is padded,
252
     use the virtual size (stored in s_paddr) instead.  */
253
44.8k
  if (scnhdr_int->s_paddr > 0
254
31.5k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
255
6.63k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
256
24.9k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
257
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
258
     coff_set_alignment_hook stores s_paddr in virt_size, which
259
     only works if it correctly holds the virtual size of the
260
     section.  */
261
6.63k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
262
44.8k
#endif
263
44.8k
}
pei-arm-wince.c:coff_swap_scnhdr_in
Line
Count
Source
212
44.1k
{
213
44.1k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
214
44.1k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
215
216
44.1k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
217
218
44.1k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
219
44.1k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
220
44.1k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
221
44.1k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
222
44.1k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
223
44.1k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
224
44.1k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
225
226
  /* MS handles overflow of line numbers by carrying into the reloc
227
     field (it appears).  Since it's supposed to be zero for PE
228
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
229
44.1k
#ifdef COFF_IMAGE_WITH_PE
230
44.1k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
231
44.1k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
232
44.1k
  scnhdr_int->s_nreloc = 0;
233
#else
234
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
235
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
236
#endif
237
238
44.1k
  if (scnhdr_int->s_vaddr != 0)
239
28.4k
    {
240
28.4k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
241
      /* Do not cut upper 32-bits for 64-bit vma.  */
242
28.4k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
243
28.4k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
244
28.4k
      scnhdr_int->s_vaddr &= 0xffffffff;
245
28.4k
#endif
246
28.4k
    }
247
248
44.1k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
249
  /* If this section holds uninitialized data and is from an object file
250
     or from an executable image that has not initialized the field,
251
     or if the image is an executable file and the physical size is padded,
252
     use the virtual size (stored in s_paddr) instead.  */
253
44.1k
  if (scnhdr_int->s_paddr > 0
254
33.7k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
255
8.65k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
256
32.2k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
257
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
258
     coff_set_alignment_hook stores s_paddr in virt_size, which
259
     only works if it correctly holds the virtual size of the
260
     section.  */
261
10.5k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
262
44.1k
#endif
263
44.1k
}
pei-arm.c:coff_swap_scnhdr_in
Line
Count
Source
212
59.7k
{
213
59.7k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
214
59.7k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
215
216
59.7k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
217
218
59.7k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
219
59.7k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
220
59.7k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
221
59.7k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
222
59.7k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
223
59.7k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
224
59.7k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
225
226
  /* MS handles overflow of line numbers by carrying into the reloc
227
     field (it appears).  Since it's supposed to be zero for PE
228
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
229
59.7k
#ifdef COFF_IMAGE_WITH_PE
230
59.7k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
231
59.7k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
232
59.7k
  scnhdr_int->s_nreloc = 0;
233
#else
234
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
235
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
236
#endif
237
238
59.7k
  if (scnhdr_int->s_vaddr != 0)
239
38.7k
    {
240
38.7k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
241
      /* Do not cut upper 32-bits for 64-bit vma.  */
242
38.7k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
243
38.7k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
244
38.7k
      scnhdr_int->s_vaddr &= 0xffffffff;
245
38.7k
#endif
246
38.7k
    }
247
248
59.7k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
249
  /* If this section holds uninitialized data and is from an object file
250
     or from an executable image that has not initialized the field,
251
     or if the image is an executable file and the physical size is padded,
252
     use the virtual size (stored in s_paddr) instead.  */
253
59.7k
  if (scnhdr_int->s_paddr > 0
254
45.1k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
255
11.1k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
256
43.3k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
257
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
258
     coff_set_alignment_hook stores s_paddr in virt_size, which
259
     only works if it correctly holds the virtual size of the
260
     section.  */
261
14.0k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
262
59.7k
#endif
263
59.7k
}
pei-mcore.c:coff_swap_scnhdr_in
Line
Count
Source
212
52.8k
{
213
52.8k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
214
52.8k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
215
216
52.8k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
217
218
52.8k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
219
52.8k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
220
52.8k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
221
52.8k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
222
52.8k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
223
52.8k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
224
52.8k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
225
226
  /* MS handles overflow of line numbers by carrying into the reloc
227
     field (it appears).  Since it's supposed to be zero for PE
228
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
229
52.8k
#ifdef COFF_IMAGE_WITH_PE
230
52.8k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
231
52.8k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
232
52.8k
  scnhdr_int->s_nreloc = 0;
233
#else
234
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
235
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
236
#endif
237
238
52.8k
  if (scnhdr_int->s_vaddr != 0)
239
35.9k
    {
240
35.9k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
241
      /* Do not cut upper 32-bits for 64-bit vma.  */
242
35.9k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
243
35.9k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
244
35.9k
      scnhdr_int->s_vaddr &= 0xffffffff;
245
35.9k
#endif
246
35.9k
    }
247
248
52.8k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
249
  /* If this section holds uninitialized data and is from an object file
250
     or from an executable image that has not initialized the field,
251
     or if the image is an executable file and the physical size is padded,
252
     use the virtual size (stored in s_paddr) instead.  */
253
52.8k
  if (scnhdr_int->s_paddr > 0
254
39.0k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
255
8.84k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
256
37.5k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
257
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
258
     coff_set_alignment_hook stores s_paddr in virt_size, which
259
     only works if it correctly holds the virtual size of the
260
     section.  */
261
11.5k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
262
52.8k
#endif
263
52.8k
}
pei-sh.c:coff_swap_scnhdr_in
Line
Count
Source
212
47.1k
{
213
47.1k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
214
47.1k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
215
216
47.1k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
217
218
47.1k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
219
47.1k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
220
47.1k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
221
47.1k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
222
47.1k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
223
47.1k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
224
47.1k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
225
226
  /* MS handles overflow of line numbers by carrying into the reloc
227
     field (it appears).  Since it's supposed to be zero for PE
228
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
229
47.1k
#ifdef COFF_IMAGE_WITH_PE
230
47.1k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
231
47.1k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
232
47.1k
  scnhdr_int->s_nreloc = 0;
233
#else
234
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
235
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
236
#endif
237
238
47.1k
  if (scnhdr_int->s_vaddr != 0)
239
31.2k
    {
240
31.2k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
241
      /* Do not cut upper 32-bits for 64-bit vma.  */
242
31.2k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
243
31.2k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
244
31.2k
      scnhdr_int->s_vaddr &= 0xffffffff;
245
31.2k
#endif
246
31.2k
    }
247
248
47.1k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
249
  /* If this section holds uninitialized data and is from an object file
250
     or from an executable image that has not initialized the field,
251
     or if the image is an executable file and the physical size is padded,
252
     use the virtual size (stored in s_paddr) instead.  */
253
47.1k
  if (scnhdr_int->s_paddr > 0
254
35.6k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
255
10.1k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
256
34.0k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
257
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
258
     coff_set_alignment_hook stores s_paddr in virt_size, which
259
     only works if it correctly holds the virtual size of the
260
     section.  */
261
10.9k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
262
47.1k
#endif
263
47.1k
}
264
265
static bool
266
pe_mkobject (bfd *abfd)
267
112k
{
268
  /* Some x86 code followed by an ascii string.  */
269
112k
  static const char default_dos_message[64] = {
270
112k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
271
112k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
272
112k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
273
112k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
274
112k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
275
112k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
276
112k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
277
112k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
278
279
112k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
280
112k
  abfd->tdata.pe_obj_data = pe;
281
112k
  if (pe == NULL)
282
0
    return false;
283
284
112k
  pe->coff.pe = 1;
285
286
  /* in_reloc_p is architecture dependent.  */
287
112k
  pe->in_reloc_p = in_reloc_p;
288
289
112k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
290
291
112k
  bfd_coff_long_section_names (abfd)
292
112k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
293
294
112k
  return true;
295
112k
}
pei-i386.c:pe_mkobject
Line
Count
Source
267
10.2k
{
268
  /* Some x86 code followed by an ascii string.  */
269
10.2k
  static const char default_dos_message[64] = {
270
10.2k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
271
10.2k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
272
10.2k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
273
10.2k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
274
10.2k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
275
10.2k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
276
10.2k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
277
10.2k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
278
279
10.2k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
280
10.2k
  abfd->tdata.pe_obj_data = pe;
281
10.2k
  if (pe == NULL)
282
0
    return false;
283
284
10.2k
  pe->coff.pe = 1;
285
286
  /* in_reloc_p is architecture dependent.  */
287
10.2k
  pe->in_reloc_p = in_reloc_p;
288
289
10.2k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
290
291
10.2k
  bfd_coff_long_section_names (abfd)
292
10.2k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
293
294
  return true;
295
10.2k
}
pe-x86_64.c:pe_mkobject
Line
Count
Source
267
8.93k
{
268
  /* Some x86 code followed by an ascii string.  */
269
8.93k
  static const char default_dos_message[64] = {
270
8.93k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
271
8.93k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
272
8.93k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
273
8.93k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
274
8.93k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
275
8.93k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
276
8.93k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
277
8.93k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
278
279
8.93k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
280
8.93k
  abfd->tdata.pe_obj_data = pe;
281
8.93k
  if (pe == NULL)
282
0
    return false;
283
284
8.93k
  pe->coff.pe = 1;
285
286
  /* in_reloc_p is architecture dependent.  */
287
8.93k
  pe->in_reloc_p = in_reloc_p;
288
289
8.93k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
290
291
8.93k
  bfd_coff_long_section_names (abfd)
292
8.93k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
293
294
  return true;
295
8.93k
}
pei-x86_64.c:pe_mkobject
Line
Count
Source
267
8.46k
{
268
  /* Some x86 code followed by an ascii string.  */
269
8.46k
  static const char default_dos_message[64] = {
270
8.46k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
271
8.46k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
272
8.46k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
273
8.46k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
274
8.46k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
275
8.46k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
276
8.46k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
277
8.46k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
278
279
8.46k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
280
8.46k
  abfd->tdata.pe_obj_data = pe;
281
8.46k
  if (pe == NULL)
282
0
    return false;
283
284
8.46k
  pe->coff.pe = 1;
285
286
  /* in_reloc_p is architecture dependent.  */
287
8.46k
  pe->in_reloc_p = in_reloc_p;
288
289
8.46k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
290
291
8.46k
  bfd_coff_long_section_names (abfd)
292
8.46k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
293
294
  return true;
295
8.46k
}
pe-aarch64.c:pe_mkobject
Line
Count
Source
267
8.89k
{
268
  /* Some x86 code followed by an ascii string.  */
269
8.89k
  static const char default_dos_message[64] = {
270
8.89k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
271
8.89k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
272
8.89k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
273
8.89k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
274
8.89k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
275
8.89k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
276
8.89k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
277
8.89k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
278
279
8.89k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
280
8.89k
  abfd->tdata.pe_obj_data = pe;
281
8.89k
  if (pe == NULL)
282
0
    return false;
283
284
8.89k
  pe->coff.pe = 1;
285
286
  /* in_reloc_p is architecture dependent.  */
287
8.89k
  pe->in_reloc_p = in_reloc_p;
288
289
8.89k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
290
291
8.89k
  bfd_coff_long_section_names (abfd)
292
8.89k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
293
294
  return true;
295
8.89k
}
pei-aarch64.c:pe_mkobject
Line
Count
Source
267
9.25k
{
268
  /* Some x86 code followed by an ascii string.  */
269
9.25k
  static const char default_dos_message[64] = {
270
9.25k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
271
9.25k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
272
9.25k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
273
9.25k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
274
9.25k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
275
9.25k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
276
9.25k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
277
9.25k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
278
279
9.25k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
280
9.25k
  abfd->tdata.pe_obj_data = pe;
281
9.25k
  if (pe == NULL)
282
0
    return false;
283
284
9.25k
  pe->coff.pe = 1;
285
286
  /* in_reloc_p is architecture dependent.  */
287
9.25k
  pe->in_reloc_p = in_reloc_p;
288
289
9.25k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
290
291
9.25k
  bfd_coff_long_section_names (abfd)
292
9.25k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
293
294
  return true;
295
9.25k
}
pei-ia64.c:pe_mkobject
Line
Count
Source
267
6.88k
{
268
  /* Some x86 code followed by an ascii string.  */
269
6.88k
  static const char default_dos_message[64] = {
270
6.88k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
271
6.88k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
272
6.88k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
273
6.88k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
274
6.88k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
275
6.88k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
276
6.88k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
277
6.88k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
278
279
6.88k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
280
6.88k
  abfd->tdata.pe_obj_data = pe;
281
6.88k
  if (pe == NULL)
282
0
    return false;
283
284
6.88k
  pe->coff.pe = 1;
285
286
  /* in_reloc_p is architecture dependent.  */
287
6.88k
  pe->in_reloc_p = in_reloc_p;
288
289
6.88k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
290
291
6.88k
  bfd_coff_long_section_names (abfd)
292
6.88k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
293
294
  return true;
295
6.88k
}
pei-loongarch64.c:pe_mkobject
Line
Count
Source
267
6.38k
{
268
  /* Some x86 code followed by an ascii string.  */
269
6.38k
  static const char default_dos_message[64] = {
270
6.38k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
271
6.38k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
272
6.38k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
273
6.38k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
274
6.38k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
275
6.38k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
276
6.38k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
277
6.38k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
278
279
6.38k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
280
6.38k
  abfd->tdata.pe_obj_data = pe;
281
6.38k
  if (pe == NULL)
282
0
    return false;
283
284
6.38k
  pe->coff.pe = 1;
285
286
  /* in_reloc_p is architecture dependent.  */
287
6.38k
  pe->in_reloc_p = in_reloc_p;
288
289
6.38k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
290
291
6.38k
  bfd_coff_long_section_names (abfd)
292
6.38k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
293
294
  return true;
295
6.38k
}
pei-riscv64.c:pe_mkobject
Line
Count
Source
267
6.65k
{
268
  /* Some x86 code followed by an ascii string.  */
269
6.65k
  static const char default_dos_message[64] = {
270
6.65k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
271
6.65k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
272
6.65k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
273
6.65k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
274
6.65k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
275
6.65k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
276
6.65k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
277
6.65k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
278
279
6.65k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
280
6.65k
  abfd->tdata.pe_obj_data = pe;
281
6.65k
  if (pe == NULL)
282
0
    return false;
283
284
6.65k
  pe->coff.pe = 1;
285
286
  /* in_reloc_p is architecture dependent.  */
287
6.65k
  pe->in_reloc_p = in_reloc_p;
288
289
6.65k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
290
291
6.65k
  bfd_coff_long_section_names (abfd)
292
6.65k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
293
294
  return true;
295
6.65k
}
pe-arm-wince.c:pe_mkobject
Line
Count
Source
267
2.94k
{
268
  /* Some x86 code followed by an ascii string.  */
269
2.94k
  static const char default_dos_message[64] = {
270
2.94k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
271
2.94k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
272
2.94k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
273
2.94k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
274
2.94k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
275
2.94k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
276
2.94k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
277
2.94k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
278
279
2.94k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
280
2.94k
  abfd->tdata.pe_obj_data = pe;
281
2.94k
  if (pe == NULL)
282
0
    return false;
283
284
2.94k
  pe->coff.pe = 1;
285
286
  /* in_reloc_p is architecture dependent.  */
287
2.94k
  pe->in_reloc_p = in_reloc_p;
288
289
2.94k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
290
291
2.94k
  bfd_coff_long_section_names (abfd)
292
2.94k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
293
294
  return true;
295
2.94k
}
pe-arm.c:pe_mkobject
Line
Count
Source
267
2.94k
{
268
  /* Some x86 code followed by an ascii string.  */
269
2.94k
  static const char default_dos_message[64] = {
270
2.94k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
271
2.94k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
272
2.94k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
273
2.94k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
274
2.94k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
275
2.94k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
276
2.94k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
277
2.94k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
278
279
2.94k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
280
2.94k
  abfd->tdata.pe_obj_data = pe;
281
2.94k
  if (pe == NULL)
282
0
    return false;
283
284
2.94k
  pe->coff.pe = 1;
285
286
  /* in_reloc_p is architecture dependent.  */
287
2.94k
  pe->in_reloc_p = in_reloc_p;
288
289
2.94k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
290
291
2.94k
  bfd_coff_long_section_names (abfd)
292
2.94k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
293
294
  return true;
295
2.94k
}
pe-i386.c:pe_mkobject
Line
Count
Source
267
9.09k
{
268
  /* Some x86 code followed by an ascii string.  */
269
9.09k
  static const char default_dos_message[64] = {
270
9.09k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
271
9.09k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
272
9.09k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
273
9.09k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
274
9.09k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
275
9.09k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
276
9.09k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
277
9.09k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
278
279
9.09k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
280
9.09k
  abfd->tdata.pe_obj_data = pe;
281
9.09k
  if (pe == NULL)
282
0
    return false;
283
284
9.09k
  pe->coff.pe = 1;
285
286
  /* in_reloc_p is architecture dependent.  */
287
9.09k
  pe->in_reloc_p = in_reloc_p;
288
289
9.09k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
290
291
9.09k
  bfd_coff_long_section_names (abfd)
292
9.09k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
293
294
  return true;
295
9.09k
}
pe-mcore.c:pe_mkobject
Line
Count
Source
267
3.50k
{
268
  /* Some x86 code followed by an ascii string.  */
269
3.50k
  static const char default_dos_message[64] = {
270
3.50k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
271
3.50k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
272
3.50k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
273
3.50k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
274
3.50k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
275
3.50k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
276
3.50k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
277
3.50k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
278
279
3.50k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
280
3.50k
  abfd->tdata.pe_obj_data = pe;
281
3.50k
  if (pe == NULL)
282
0
    return false;
283
284
3.50k
  pe->coff.pe = 1;
285
286
  /* in_reloc_p is architecture dependent.  */
287
3.50k
  pe->in_reloc_p = in_reloc_p;
288
289
3.50k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
290
291
3.50k
  bfd_coff_long_section_names (abfd)
292
3.50k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
293
294
  return true;
295
3.50k
}
pe-sh.c:pe_mkobject
Line
Count
Source
267
4.99k
{
268
  /* Some x86 code followed by an ascii string.  */
269
4.99k
  static const char default_dos_message[64] = {
270
4.99k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
271
4.99k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
272
4.99k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
273
4.99k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
274
4.99k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
275
4.99k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
276
4.99k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
277
4.99k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
278
279
4.99k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
280
4.99k
  abfd->tdata.pe_obj_data = pe;
281
4.99k
  if (pe == NULL)
282
0
    return false;
283
284
4.99k
  pe->coff.pe = 1;
285
286
  /* in_reloc_p is architecture dependent.  */
287
4.99k
  pe->in_reloc_p = in_reloc_p;
288
289
4.99k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
290
291
4.99k
  bfd_coff_long_section_names (abfd)
292
4.99k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
293
294
  return true;
295
4.99k
}
pei-arm-wince.c:pe_mkobject
Line
Count
Source
267
5.55k
{
268
  /* Some x86 code followed by an ascii string.  */
269
5.55k
  static const char default_dos_message[64] = {
270
5.55k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
271
5.55k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
272
5.55k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
273
5.55k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
274
5.55k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
275
5.55k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
276
5.55k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
277
5.55k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
278
279
5.55k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
280
5.55k
  abfd->tdata.pe_obj_data = pe;
281
5.55k
  if (pe == NULL)
282
0
    return false;
283
284
5.55k
  pe->coff.pe = 1;
285
286
  /* in_reloc_p is architecture dependent.  */
287
5.55k
  pe->in_reloc_p = in_reloc_p;
288
289
5.55k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
290
291
5.55k
  bfd_coff_long_section_names (abfd)
292
5.55k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
293
294
  return true;
295
5.55k
}
pei-arm.c:pe_mkobject
Line
Count
Source
267
7.20k
{
268
  /* Some x86 code followed by an ascii string.  */
269
7.20k
  static const char default_dos_message[64] = {
270
7.20k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
271
7.20k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
272
7.20k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
273
7.20k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
274
7.20k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
275
7.20k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
276
7.20k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
277
7.20k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
278
279
7.20k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
280
7.20k
  abfd->tdata.pe_obj_data = pe;
281
7.20k
  if (pe == NULL)
282
0
    return false;
283
284
7.20k
  pe->coff.pe = 1;
285
286
  /* in_reloc_p is architecture dependent.  */
287
7.20k
  pe->in_reloc_p = in_reloc_p;
288
289
7.20k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
290
291
7.20k
  bfd_coff_long_section_names (abfd)
292
7.20k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
293
294
  return true;
295
7.20k
}
pei-mcore.c:pe_mkobject
Line
Count
Source
267
5.42k
{
268
  /* Some x86 code followed by an ascii string.  */
269
5.42k
  static const char default_dos_message[64] = {
270
5.42k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
271
5.42k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
272
5.42k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
273
5.42k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
274
5.42k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
275
5.42k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
276
5.42k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
277
5.42k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
278
279
5.42k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
280
5.42k
  abfd->tdata.pe_obj_data = pe;
281
5.42k
  if (pe == NULL)
282
0
    return false;
283
284
5.42k
  pe->coff.pe = 1;
285
286
  /* in_reloc_p is architecture dependent.  */
287
5.42k
  pe->in_reloc_p = in_reloc_p;
288
289
5.42k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
290
291
5.42k
  bfd_coff_long_section_names (abfd)
292
5.42k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
293
294
  return true;
295
5.42k
}
pei-sh.c:pe_mkobject
Line
Count
Source
267
5.36k
{
268
  /* Some x86 code followed by an ascii string.  */
269
5.36k
  static const char default_dos_message[64] = {
270
5.36k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
271
5.36k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
272
5.36k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
273
5.36k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
274
5.36k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
275
5.36k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
276
5.36k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
277
5.36k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
278
279
5.36k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
280
5.36k
  abfd->tdata.pe_obj_data = pe;
281
5.36k
  if (pe == NULL)
282
0
    return false;
283
284
5.36k
  pe->coff.pe = 1;
285
286
  /* in_reloc_p is architecture dependent.  */
287
5.36k
  pe->in_reloc_p = in_reloc_p;
288
289
5.36k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
290
291
5.36k
  bfd_coff_long_section_names (abfd)
292
5.36k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
293
294
  return true;
295
5.36k
}
296
297
/* Create the COFF backend specific information.  */
298
299
static void *
300
pe_mkobject_hook (bfd *abfd,
301
      void *filehdr,
302
      void *aouthdr ATTRIBUTE_UNUSED)
303
107k
{
304
107k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
305
107k
  pe_data_type *pe;
306
307
107k
  if (! pe_mkobject (abfd))
308
0
    return NULL;
309
310
107k
  pe = pe_data (abfd);
311
107k
  pe->coff.sym_filepos = internal_f->f_symptr;
312
  /* These members communicate important constants about the symbol
313
     table to GDB's symbol-reading code.  These `constants'
314
     unfortunately vary among coff implementations...  */
315
107k
  pe->coff.local_n_btmask = N_BTMASK;
316
107k
  pe->coff.local_n_btshft = N_BTSHFT;
317
107k
  pe->coff.local_n_tmask = N_TMASK;
318
107k
  pe->coff.local_n_tshift = N_TSHIFT;
319
107k
  pe->coff.local_symesz = SYMESZ;
320
107k
  pe->coff.local_auxesz = AUXESZ;
321
107k
  pe->coff.local_linesz = LINESZ;
322
323
107k
  pe->coff.timestamp = internal_f->f_timdat;
324
325
107k
  obj_raw_syment_count (abfd) =
326
107k
    obj_conv_table_size (abfd) =
327
107k
      internal_f->f_nsyms;
328
329
107k
  pe->real_flags = internal_f->f_flags;
330
331
107k
  if ((internal_f->f_flags & F_DLL) != 0)
332
32.6k
    pe->dll = 1;
333
334
107k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
335
74.1k
    abfd->flags |= HAS_DEBUG;
336
337
#ifdef COFF_IMAGE_WITH_PE
338
67.5k
  if (aouthdr)
339
37.6k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
340
#endif
341
342
#ifdef ARM
343
18.0k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
344
0
    coff_data (abfd) ->flags = 0;
345
#endif
346
347
107k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
348
107k
    sizeof (pe->dos_message));
349
350
107k
  return (void *) pe;
351
107k
}
pei-i386.c:pe_mkobject_hook
Line
Count
Source
303
9.79k
{
304
9.79k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
305
9.79k
  pe_data_type *pe;
306
307
9.79k
  if (! pe_mkobject (abfd))
308
0
    return NULL;
309
310
9.79k
  pe = pe_data (abfd);
311
9.79k
  pe->coff.sym_filepos = internal_f->f_symptr;
312
  /* These members communicate important constants about the symbol
313
     table to GDB's symbol-reading code.  These `constants'
314
     unfortunately vary among coff implementations...  */
315
9.79k
  pe->coff.local_n_btmask = N_BTMASK;
316
9.79k
  pe->coff.local_n_btshft = N_BTSHFT;
317
9.79k
  pe->coff.local_n_tmask = N_TMASK;
318
9.79k
  pe->coff.local_n_tshift = N_TSHIFT;
319
9.79k
  pe->coff.local_symesz = SYMESZ;
320
9.79k
  pe->coff.local_auxesz = AUXESZ;
321
9.79k
  pe->coff.local_linesz = LINESZ;
322
323
9.79k
  pe->coff.timestamp = internal_f->f_timdat;
324
325
9.79k
  obj_raw_syment_count (abfd) =
326
9.79k
    obj_conv_table_size (abfd) =
327
9.79k
      internal_f->f_nsyms;
328
329
9.79k
  pe->real_flags = internal_f->f_flags;
330
331
9.79k
  if ((internal_f->f_flags & F_DLL) != 0)
332
2.64k
    pe->dll = 1;
333
334
9.79k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
335
7.46k
    abfd->flags |= HAS_DEBUG;
336
337
9.79k
#ifdef COFF_IMAGE_WITH_PE
338
9.79k
  if (aouthdr)
339
4.75k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
340
9.79k
#endif
341
342
#ifdef ARM
343
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
344
    coff_data (abfd) ->flags = 0;
345
#endif
346
347
9.79k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
348
9.79k
    sizeof (pe->dos_message));
349
350
9.79k
  return (void *) pe;
351
9.79k
}
pe-x86_64.c:pe_mkobject_hook
Line
Count
Source
303
8.53k
{
304
8.53k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
305
8.53k
  pe_data_type *pe;
306
307
8.53k
  if (! pe_mkobject (abfd))
308
0
    return NULL;
309
310
8.53k
  pe = pe_data (abfd);
311
8.53k
  pe->coff.sym_filepos = internal_f->f_symptr;
312
  /* These members communicate important constants about the symbol
313
     table to GDB's symbol-reading code.  These `constants'
314
     unfortunately vary among coff implementations...  */
315
8.53k
  pe->coff.local_n_btmask = N_BTMASK;
316
8.53k
  pe->coff.local_n_btshft = N_BTSHFT;
317
8.53k
  pe->coff.local_n_tmask = N_TMASK;
318
8.53k
  pe->coff.local_n_tshift = N_TSHIFT;
319
8.53k
  pe->coff.local_symesz = SYMESZ;
320
8.53k
  pe->coff.local_auxesz = AUXESZ;
321
8.53k
  pe->coff.local_linesz = LINESZ;
322
323
8.53k
  pe->coff.timestamp = internal_f->f_timdat;
324
325
8.53k
  obj_raw_syment_count (abfd) =
326
8.53k
    obj_conv_table_size (abfd) =
327
8.53k
      internal_f->f_nsyms;
328
329
8.53k
  pe->real_flags = internal_f->f_flags;
330
331
8.53k
  if ((internal_f->f_flags & F_DLL) != 0)
332
2.18k
    pe->dll = 1;
333
334
8.53k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
335
6.30k
    abfd->flags |= HAS_DEBUG;
336
337
#ifdef COFF_IMAGE_WITH_PE
338
  if (aouthdr)
339
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
340
#endif
341
342
#ifdef ARM
343
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
344
    coff_data (abfd) ->flags = 0;
345
#endif
346
347
8.53k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
348
8.53k
    sizeof (pe->dos_message));
349
350
8.53k
  return (void *) pe;
351
8.53k
}
pei-x86_64.c:pe_mkobject_hook
Line
Count
Source
303
8.09k
{
304
8.09k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
305
8.09k
  pe_data_type *pe;
306
307
8.09k
  if (! pe_mkobject (abfd))
308
0
    return NULL;
309
310
8.09k
  pe = pe_data (abfd);
311
8.09k
  pe->coff.sym_filepos = internal_f->f_symptr;
312
  /* These members communicate important constants about the symbol
313
     table to GDB's symbol-reading code.  These `constants'
314
     unfortunately vary among coff implementations...  */
315
8.09k
  pe->coff.local_n_btmask = N_BTMASK;
316
8.09k
  pe->coff.local_n_btshft = N_BTSHFT;
317
8.09k
  pe->coff.local_n_tmask = N_TMASK;
318
8.09k
  pe->coff.local_n_tshift = N_TSHIFT;
319
8.09k
  pe->coff.local_symesz = SYMESZ;
320
8.09k
  pe->coff.local_auxesz = AUXESZ;
321
8.09k
  pe->coff.local_linesz = LINESZ;
322
323
8.09k
  pe->coff.timestamp = internal_f->f_timdat;
324
325
8.09k
  obj_raw_syment_count (abfd) =
326
8.09k
    obj_conv_table_size (abfd) =
327
8.09k
      internal_f->f_nsyms;
328
329
8.09k
  pe->real_flags = internal_f->f_flags;
330
331
8.09k
  if ((internal_f->f_flags & F_DLL) != 0)
332
2.90k
    pe->dll = 1;
333
334
8.09k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
335
5.55k
    abfd->flags |= HAS_DEBUG;
336
337
8.09k
#ifdef COFF_IMAGE_WITH_PE
338
8.09k
  if (aouthdr)
339
4.76k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
340
8.09k
#endif
341
342
#ifdef ARM
343
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
344
    coff_data (abfd) ->flags = 0;
345
#endif
346
347
8.09k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
348
8.09k
    sizeof (pe->dos_message));
349
350
8.09k
  return (void *) pe;
351
8.09k
}
pe-aarch64.c:pe_mkobject_hook
Line
Count
Source
303
8.57k
{
304
8.57k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
305
8.57k
  pe_data_type *pe;
306
307
8.57k
  if (! pe_mkobject (abfd))
308
0
    return NULL;
309
310
8.57k
  pe = pe_data (abfd);
311
8.57k
  pe->coff.sym_filepos = internal_f->f_symptr;
312
  /* These members communicate important constants about the symbol
313
     table to GDB's symbol-reading code.  These `constants'
314
     unfortunately vary among coff implementations...  */
315
8.57k
  pe->coff.local_n_btmask = N_BTMASK;
316
8.57k
  pe->coff.local_n_btshft = N_BTSHFT;
317
8.57k
  pe->coff.local_n_tmask = N_TMASK;
318
8.57k
  pe->coff.local_n_tshift = N_TSHIFT;
319
8.57k
  pe->coff.local_symesz = SYMESZ;
320
8.57k
  pe->coff.local_auxesz = AUXESZ;
321
8.57k
  pe->coff.local_linesz = LINESZ;
322
323
8.57k
  pe->coff.timestamp = internal_f->f_timdat;
324
325
8.57k
  obj_raw_syment_count (abfd) =
326
8.57k
    obj_conv_table_size (abfd) =
327
8.57k
      internal_f->f_nsyms;
328
329
8.57k
  pe->real_flags = internal_f->f_flags;
330
331
8.57k
  if ((internal_f->f_flags & F_DLL) != 0)
332
1.77k
    pe->dll = 1;
333
334
8.57k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
335
3.79k
    abfd->flags |= HAS_DEBUG;
336
337
#ifdef COFF_IMAGE_WITH_PE
338
  if (aouthdr)
339
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
340
#endif
341
342
#ifdef ARM
343
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
344
    coff_data (abfd) ->flags = 0;
345
#endif
346
347
8.57k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
348
8.57k
    sizeof (pe->dos_message));
349
350
8.57k
  return (void *) pe;
351
8.57k
}
pei-aarch64.c:pe_mkobject_hook
Line
Count
Source
303
8.84k
{
304
8.84k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
305
8.84k
  pe_data_type *pe;
306
307
8.84k
  if (! pe_mkobject (abfd))
308
0
    return NULL;
309
310
8.84k
  pe = pe_data (abfd);
311
8.84k
  pe->coff.sym_filepos = internal_f->f_symptr;
312
  /* These members communicate important constants about the symbol
313
     table to GDB's symbol-reading code.  These `constants'
314
     unfortunately vary among coff implementations...  */
315
8.84k
  pe->coff.local_n_btmask = N_BTMASK;
316
8.84k
  pe->coff.local_n_btshft = N_BTSHFT;
317
8.84k
  pe->coff.local_n_tmask = N_TMASK;
318
8.84k
  pe->coff.local_n_tshift = N_TSHIFT;
319
8.84k
  pe->coff.local_symesz = SYMESZ;
320
8.84k
  pe->coff.local_auxesz = AUXESZ;
321
8.84k
  pe->coff.local_linesz = LINESZ;
322
323
8.84k
  pe->coff.timestamp = internal_f->f_timdat;
324
325
8.84k
  obj_raw_syment_count (abfd) =
326
8.84k
    obj_conv_table_size (abfd) =
327
8.84k
      internal_f->f_nsyms;
328
329
8.84k
  pe->real_flags = internal_f->f_flags;
330
331
8.84k
  if ((internal_f->f_flags & F_DLL) != 0)
332
2.22k
    pe->dll = 1;
333
334
8.84k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
335
6.99k
    abfd->flags |= HAS_DEBUG;
336
337
8.84k
#ifdef COFF_IMAGE_WITH_PE
338
8.84k
  if (aouthdr)
339
6.48k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
340
8.84k
#endif
341
342
#ifdef ARM
343
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
344
    coff_data (abfd) ->flags = 0;
345
#endif
346
347
8.84k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
348
8.84k
    sizeof (pe->dos_message));
349
350
8.84k
  return (void *) pe;
351
8.84k
}
pei-ia64.c:pe_mkobject_hook
Line
Count
Source
303
6.37k
{
304
6.37k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
305
6.37k
  pe_data_type *pe;
306
307
6.37k
  if (! pe_mkobject (abfd))
308
0
    return NULL;
309
310
6.37k
  pe = pe_data (abfd);
311
6.37k
  pe->coff.sym_filepos = internal_f->f_symptr;
312
  /* These members communicate important constants about the symbol
313
     table to GDB's symbol-reading code.  These `constants'
314
     unfortunately vary among coff implementations...  */
315
6.37k
  pe->coff.local_n_btmask = N_BTMASK;
316
6.37k
  pe->coff.local_n_btshft = N_BTSHFT;
317
6.37k
  pe->coff.local_n_tmask = N_TMASK;
318
6.37k
  pe->coff.local_n_tshift = N_TSHIFT;
319
6.37k
  pe->coff.local_symesz = SYMESZ;
320
6.37k
  pe->coff.local_auxesz = AUXESZ;
321
6.37k
  pe->coff.local_linesz = LINESZ;
322
323
6.37k
  pe->coff.timestamp = internal_f->f_timdat;
324
325
6.37k
  obj_raw_syment_count (abfd) =
326
6.37k
    obj_conv_table_size (abfd) =
327
6.37k
      internal_f->f_nsyms;
328
329
6.37k
  pe->real_flags = internal_f->f_flags;
330
331
6.37k
  if ((internal_f->f_flags & F_DLL) != 0)
332
2.04k
    pe->dll = 1;
333
334
6.37k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
335
4.33k
    abfd->flags |= HAS_DEBUG;
336
337
6.37k
#ifdef COFF_IMAGE_WITH_PE
338
6.37k
  if (aouthdr)
339
2.72k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
340
6.37k
#endif
341
342
#ifdef ARM
343
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
344
    coff_data (abfd) ->flags = 0;
345
#endif
346
347
6.37k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
348
6.37k
    sizeof (pe->dos_message));
349
350
6.37k
  return (void *) pe;
351
6.37k
}
pei-loongarch64.c:pe_mkobject_hook
Line
Count
Source
303
5.93k
{
304
5.93k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
305
5.93k
  pe_data_type *pe;
306
307
5.93k
  if (! pe_mkobject (abfd))
308
0
    return NULL;
309
310
5.93k
  pe = pe_data (abfd);
311
5.93k
  pe->coff.sym_filepos = internal_f->f_symptr;
312
  /* These members communicate important constants about the symbol
313
     table to GDB's symbol-reading code.  These `constants'
314
     unfortunately vary among coff implementations...  */
315
5.93k
  pe->coff.local_n_btmask = N_BTMASK;
316
5.93k
  pe->coff.local_n_btshft = N_BTSHFT;
317
5.93k
  pe->coff.local_n_tmask = N_TMASK;
318
5.93k
  pe->coff.local_n_tshift = N_TSHIFT;
319
5.93k
  pe->coff.local_symesz = SYMESZ;
320
5.93k
  pe->coff.local_auxesz = AUXESZ;
321
5.93k
  pe->coff.local_linesz = LINESZ;
322
323
5.93k
  pe->coff.timestamp = internal_f->f_timdat;
324
325
5.93k
  obj_raw_syment_count (abfd) =
326
5.93k
    obj_conv_table_size (abfd) =
327
5.93k
      internal_f->f_nsyms;
328
329
5.93k
  pe->real_flags = internal_f->f_flags;
330
331
5.93k
  if ((internal_f->f_flags & F_DLL) != 0)
332
1.75k
    pe->dll = 1;
333
334
5.93k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
335
4.57k
    abfd->flags |= HAS_DEBUG;
336
337
5.93k
#ifdef COFF_IMAGE_WITH_PE
338
5.93k
  if (aouthdr)
339
3.53k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
340
5.93k
#endif
341
342
#ifdef ARM
343
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
344
    coff_data (abfd) ->flags = 0;
345
#endif
346
347
5.93k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
348
5.93k
    sizeof (pe->dos_message));
349
350
5.93k
  return (void *) pe;
351
5.93k
}
pei-riscv64.c:pe_mkobject_hook
Line
Count
Source
303
6.19k
{
304
6.19k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
305
6.19k
  pe_data_type *pe;
306
307
6.19k
  if (! pe_mkobject (abfd))
308
0
    return NULL;
309
310
6.19k
  pe = pe_data (abfd);
311
6.19k
  pe->coff.sym_filepos = internal_f->f_symptr;
312
  /* These members communicate important constants about the symbol
313
     table to GDB's symbol-reading code.  These `constants'
314
     unfortunately vary among coff implementations...  */
315
6.19k
  pe->coff.local_n_btmask = N_BTMASK;
316
6.19k
  pe->coff.local_n_btshft = N_BTSHFT;
317
6.19k
  pe->coff.local_n_tmask = N_TMASK;
318
6.19k
  pe->coff.local_n_tshift = N_TSHIFT;
319
6.19k
  pe->coff.local_symesz = SYMESZ;
320
6.19k
  pe->coff.local_auxesz = AUXESZ;
321
6.19k
  pe->coff.local_linesz = LINESZ;
322
323
6.19k
  pe->coff.timestamp = internal_f->f_timdat;
324
325
6.19k
  obj_raw_syment_count (abfd) =
326
6.19k
    obj_conv_table_size (abfd) =
327
6.19k
      internal_f->f_nsyms;
328
329
6.19k
  pe->real_flags = internal_f->f_flags;
330
331
6.19k
  if ((internal_f->f_flags & F_DLL) != 0)
332
1.88k
    pe->dll = 1;
333
334
6.19k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
335
4.28k
    abfd->flags |= HAS_DEBUG;
336
337
6.19k
#ifdef COFF_IMAGE_WITH_PE
338
6.19k
  if (aouthdr)
339
4.04k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
340
6.19k
#endif
341
342
#ifdef ARM
343
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
344
    coff_data (abfd) ->flags = 0;
345
#endif
346
347
6.19k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
348
6.19k
    sizeof (pe->dos_message));
349
350
6.19k
  return (void *) pe;
351
6.19k
}
pe-arm-wince.c:pe_mkobject_hook
Line
Count
Source
303
2.94k
{
304
2.94k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
305
2.94k
  pe_data_type *pe;
306
307
2.94k
  if (! pe_mkobject (abfd))
308
0
    return NULL;
309
310
2.94k
  pe = pe_data (abfd);
311
2.94k
  pe->coff.sym_filepos = internal_f->f_symptr;
312
  /* These members communicate important constants about the symbol
313
     table to GDB's symbol-reading code.  These `constants'
314
     unfortunately vary among coff implementations...  */
315
2.94k
  pe->coff.local_n_btmask = N_BTMASK;
316
2.94k
  pe->coff.local_n_btshft = N_BTSHFT;
317
2.94k
  pe->coff.local_n_tmask = N_TMASK;
318
2.94k
  pe->coff.local_n_tshift = N_TSHIFT;
319
2.94k
  pe->coff.local_symesz = SYMESZ;
320
2.94k
  pe->coff.local_auxesz = AUXESZ;
321
2.94k
  pe->coff.local_linesz = LINESZ;
322
323
2.94k
  pe->coff.timestamp = internal_f->f_timdat;
324
325
2.94k
  obj_raw_syment_count (abfd) =
326
2.94k
    obj_conv_table_size (abfd) =
327
2.94k
      internal_f->f_nsyms;
328
329
2.94k
  pe->real_flags = internal_f->f_flags;
330
331
2.94k
  if ((internal_f->f_flags & F_DLL) != 0)
332
968
    pe->dll = 1;
333
334
2.94k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
335
2.17k
    abfd->flags |= HAS_DEBUG;
336
337
#ifdef COFF_IMAGE_WITH_PE
338
  if (aouthdr)
339
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
340
#endif
341
342
2.94k
#ifdef ARM
343
2.94k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
344
0
    coff_data (abfd) ->flags = 0;
345
2.94k
#endif
346
347
2.94k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
348
2.94k
    sizeof (pe->dos_message));
349
350
2.94k
  return (void *) pe;
351
2.94k
}
pe-arm.c:pe_mkobject_hook
Line
Count
Source
303
2.94k
{
304
2.94k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
305
2.94k
  pe_data_type *pe;
306
307
2.94k
  if (! pe_mkobject (abfd))
308
0
    return NULL;
309
310
2.94k
  pe = pe_data (abfd);
311
2.94k
  pe->coff.sym_filepos = internal_f->f_symptr;
312
  /* These members communicate important constants about the symbol
313
     table to GDB's symbol-reading code.  These `constants'
314
     unfortunately vary among coff implementations...  */
315
2.94k
  pe->coff.local_n_btmask = N_BTMASK;
316
2.94k
  pe->coff.local_n_btshft = N_BTSHFT;
317
2.94k
  pe->coff.local_n_tmask = N_TMASK;
318
2.94k
  pe->coff.local_n_tshift = N_TSHIFT;
319
2.94k
  pe->coff.local_symesz = SYMESZ;
320
2.94k
  pe->coff.local_auxesz = AUXESZ;
321
2.94k
  pe->coff.local_linesz = LINESZ;
322
323
2.94k
  pe->coff.timestamp = internal_f->f_timdat;
324
325
2.94k
  obj_raw_syment_count (abfd) =
326
2.94k
    obj_conv_table_size (abfd) =
327
2.94k
      internal_f->f_nsyms;
328
329
2.94k
  pe->real_flags = internal_f->f_flags;
330
331
2.94k
  if ((internal_f->f_flags & F_DLL) != 0)
332
968
    pe->dll = 1;
333
334
2.94k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
335
2.17k
    abfd->flags |= HAS_DEBUG;
336
337
#ifdef COFF_IMAGE_WITH_PE
338
  if (aouthdr)
339
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
340
#endif
341
342
2.94k
#ifdef ARM
343
2.94k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
344
0
    coff_data (abfd) ->flags = 0;
345
2.94k
#endif
346
347
2.94k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
348
2.94k
    sizeof (pe->dos_message));
349
350
2.94k
  return (void *) pe;
351
2.94k
}
pe-i386.c:pe_mkobject_hook
Line
Count
Source
303
8.84k
{
304
8.84k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
305
8.84k
  pe_data_type *pe;
306
307
8.84k
  if (! pe_mkobject (abfd))
308
0
    return NULL;
309
310
8.84k
  pe = pe_data (abfd);
311
8.84k
  pe->coff.sym_filepos = internal_f->f_symptr;
312
  /* These members communicate important constants about the symbol
313
     table to GDB's symbol-reading code.  These `constants'
314
     unfortunately vary among coff implementations...  */
315
8.84k
  pe->coff.local_n_btmask = N_BTMASK;
316
8.84k
  pe->coff.local_n_btshft = N_BTSHFT;
317
8.84k
  pe->coff.local_n_tmask = N_TMASK;
318
8.84k
  pe->coff.local_n_tshift = N_TSHIFT;
319
8.84k
  pe->coff.local_symesz = SYMESZ;
320
8.84k
  pe->coff.local_auxesz = AUXESZ;
321
8.84k
  pe->coff.local_linesz = LINESZ;
322
323
8.84k
  pe->coff.timestamp = internal_f->f_timdat;
324
325
8.84k
  obj_raw_syment_count (abfd) =
326
8.84k
    obj_conv_table_size (abfd) =
327
8.84k
      internal_f->f_nsyms;
328
329
8.84k
  pe->real_flags = internal_f->f_flags;
330
331
8.84k
  if ((internal_f->f_flags & F_DLL) != 0)
332
2.39k
    pe->dll = 1;
333
334
8.84k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
335
6.17k
    abfd->flags |= HAS_DEBUG;
336
337
#ifdef COFF_IMAGE_WITH_PE
338
  if (aouthdr)
339
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
340
#endif
341
342
#ifdef ARM
343
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
344
    coff_data (abfd) ->flags = 0;
345
#endif
346
347
8.84k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
348
8.84k
    sizeof (pe->dos_message));
349
350
8.84k
  return (void *) pe;
351
8.84k
}
pe-mcore.c:pe_mkobject_hook
Line
Count
Source
303
3.28k
{
304
3.28k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
305
3.28k
  pe_data_type *pe;
306
307
3.28k
  if (! pe_mkobject (abfd))
308
0
    return NULL;
309
310
3.28k
  pe = pe_data (abfd);
311
3.28k
  pe->coff.sym_filepos = internal_f->f_symptr;
312
  /* These members communicate important constants about the symbol
313
     table to GDB's symbol-reading code.  These `constants'
314
     unfortunately vary among coff implementations...  */
315
3.28k
  pe->coff.local_n_btmask = N_BTMASK;
316
3.28k
  pe->coff.local_n_btshft = N_BTSHFT;
317
3.28k
  pe->coff.local_n_tmask = N_TMASK;
318
3.28k
  pe->coff.local_n_tshift = N_TSHIFT;
319
3.28k
  pe->coff.local_symesz = SYMESZ;
320
3.28k
  pe->coff.local_auxesz = AUXESZ;
321
3.28k
  pe->coff.local_linesz = LINESZ;
322
323
3.28k
  pe->coff.timestamp = internal_f->f_timdat;
324
325
3.28k
  obj_raw_syment_count (abfd) =
326
3.28k
    obj_conv_table_size (abfd) =
327
3.28k
      internal_f->f_nsyms;
328
329
3.28k
  pe->real_flags = internal_f->f_flags;
330
331
3.28k
  if ((internal_f->f_flags & F_DLL) != 0)
332
1.01k
    pe->dll = 1;
333
334
3.28k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
335
2.65k
    abfd->flags |= HAS_DEBUG;
336
337
#ifdef COFF_IMAGE_WITH_PE
338
  if (aouthdr)
339
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
340
#endif
341
342
#ifdef ARM
343
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
344
    coff_data (abfd) ->flags = 0;
345
#endif
346
347
3.28k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
348
3.28k
    sizeof (pe->dos_message));
349
350
3.28k
  return (void *) pe;
351
3.28k
}
pe-sh.c:pe_mkobject_hook
Line
Count
Source
303
4.77k
{
304
4.77k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
305
4.77k
  pe_data_type *pe;
306
307
4.77k
  if (! pe_mkobject (abfd))
308
0
    return NULL;
309
310
4.77k
  pe = pe_data (abfd);
311
4.77k
  pe->coff.sym_filepos = internal_f->f_symptr;
312
  /* These members communicate important constants about the symbol
313
     table to GDB's symbol-reading code.  These `constants'
314
     unfortunately vary among coff implementations...  */
315
4.77k
  pe->coff.local_n_btmask = N_BTMASK;
316
4.77k
  pe->coff.local_n_btshft = N_BTSHFT;
317
4.77k
  pe->coff.local_n_tmask = N_TMASK;
318
4.77k
  pe->coff.local_n_tshift = N_TSHIFT;
319
4.77k
  pe->coff.local_symesz = SYMESZ;
320
4.77k
  pe->coff.local_auxesz = AUXESZ;
321
4.77k
  pe->coff.local_linesz = LINESZ;
322
323
4.77k
  pe->coff.timestamp = internal_f->f_timdat;
324
325
4.77k
  obj_raw_syment_count (abfd) =
326
4.77k
    obj_conv_table_size (abfd) =
327
4.77k
      internal_f->f_nsyms;
328
329
4.77k
  pe->real_flags = internal_f->f_flags;
330
331
4.77k
  if ((internal_f->f_flags & F_DLL) != 0)
332
1.31k
    pe->dll = 1;
333
334
4.77k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
335
3.67k
    abfd->flags |= HAS_DEBUG;
336
337
#ifdef COFF_IMAGE_WITH_PE
338
  if (aouthdr)
339
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
340
#endif
341
342
#ifdef ARM
343
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
344
    coff_data (abfd) ->flags = 0;
345
#endif
346
347
4.77k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
348
4.77k
    sizeof (pe->dos_message));
349
350
4.77k
  return (void *) pe;
351
4.77k
}
pei-arm-wince.c:pe_mkobject_hook
Line
Count
Source
303
5.30k
{
304
5.30k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
305
5.30k
  pe_data_type *pe;
306
307
5.30k
  if (! pe_mkobject (abfd))
308
0
    return NULL;
309
310
5.30k
  pe = pe_data (abfd);
311
5.30k
  pe->coff.sym_filepos = internal_f->f_symptr;
312
  /* These members communicate important constants about the symbol
313
     table to GDB's symbol-reading code.  These `constants'
314
     unfortunately vary among coff implementations...  */
315
5.30k
  pe->coff.local_n_btmask = N_BTMASK;
316
5.30k
  pe->coff.local_n_btshft = N_BTSHFT;
317
5.30k
  pe->coff.local_n_tmask = N_TMASK;
318
5.30k
  pe->coff.local_n_tshift = N_TSHIFT;
319
5.30k
  pe->coff.local_symesz = SYMESZ;
320
5.30k
  pe->coff.local_auxesz = AUXESZ;
321
5.30k
  pe->coff.local_linesz = LINESZ;
322
323
5.30k
  pe->coff.timestamp = internal_f->f_timdat;
324
325
5.30k
  obj_raw_syment_count (abfd) =
326
5.30k
    obj_conv_table_size (abfd) =
327
5.30k
      internal_f->f_nsyms;
328
329
5.30k
  pe->real_flags = internal_f->f_flags;
330
331
5.30k
  if ((internal_f->f_flags & F_DLL) != 0)
332
2.04k
    pe->dll = 1;
333
334
5.30k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
335
3.29k
    abfd->flags |= HAS_DEBUG;
336
337
5.30k
#ifdef COFF_IMAGE_WITH_PE
338
5.30k
  if (aouthdr)
339
2.00k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
340
5.30k
#endif
341
342
5.30k
#ifdef ARM
343
5.30k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
344
0
    coff_data (abfd) ->flags = 0;
345
5.30k
#endif
346
347
5.30k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
348
5.30k
    sizeof (pe->dos_message));
349
350
5.30k
  return (void *) pe;
351
5.30k
}
pei-arm.c:pe_mkobject_hook
Line
Count
Source
303
6.83k
{
304
6.83k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
305
6.83k
  pe_data_type *pe;
306
307
6.83k
  if (! pe_mkobject (abfd))
308
0
    return NULL;
309
310
6.83k
  pe = pe_data (abfd);
311
6.83k
  pe->coff.sym_filepos = internal_f->f_symptr;
312
  /* These members communicate important constants about the symbol
313
     table to GDB's symbol-reading code.  These `constants'
314
     unfortunately vary among coff implementations...  */
315
6.83k
  pe->coff.local_n_btmask = N_BTMASK;
316
6.83k
  pe->coff.local_n_btshft = N_BTSHFT;
317
6.83k
  pe->coff.local_n_tmask = N_TMASK;
318
6.83k
  pe->coff.local_n_tshift = N_TSHIFT;
319
6.83k
  pe->coff.local_symesz = SYMESZ;
320
6.83k
  pe->coff.local_auxesz = AUXESZ;
321
6.83k
  pe->coff.local_linesz = LINESZ;
322
323
6.83k
  pe->coff.timestamp = internal_f->f_timdat;
324
325
6.83k
  obj_raw_syment_count (abfd) =
326
6.83k
    obj_conv_table_size (abfd) =
327
6.83k
      internal_f->f_nsyms;
328
329
6.83k
  pe->real_flags = internal_f->f_flags;
330
331
6.83k
  if ((internal_f->f_flags & F_DLL) != 0)
332
2.49k
    pe->dll = 1;
333
334
6.83k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
335
4.43k
    abfd->flags |= HAS_DEBUG;
336
337
6.83k
#ifdef COFF_IMAGE_WITH_PE
338
6.83k
  if (aouthdr)
339
3.52k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
340
6.83k
#endif
341
342
6.83k
#ifdef ARM
343
6.83k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
344
0
    coff_data (abfd) ->flags = 0;
345
6.83k
#endif
346
347
6.83k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
348
6.83k
    sizeof (pe->dos_message));
349
350
6.83k
  return (void *) pe;
351
6.83k
}
pei-mcore.c:pe_mkobject_hook
Line
Count
Source
303
5.12k
{
304
5.12k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
305
5.12k
  pe_data_type *pe;
306
307
5.12k
  if (! pe_mkobject (abfd))
308
0
    return NULL;
309
310
5.12k
  pe = pe_data (abfd);
311
5.12k
  pe->coff.sym_filepos = internal_f->f_symptr;
312
  /* These members communicate important constants about the symbol
313
     table to GDB's symbol-reading code.  These `constants'
314
     unfortunately vary among coff implementations...  */
315
5.12k
  pe->coff.local_n_btmask = N_BTMASK;
316
5.12k
  pe->coff.local_n_btshft = N_BTSHFT;
317
5.12k
  pe->coff.local_n_tmask = N_TMASK;
318
5.12k
  pe->coff.local_n_tshift = N_TSHIFT;
319
5.12k
  pe->coff.local_symesz = SYMESZ;
320
5.12k
  pe->coff.local_auxesz = AUXESZ;
321
5.12k
  pe->coff.local_linesz = LINESZ;
322
323
5.12k
  pe->coff.timestamp = internal_f->f_timdat;
324
325
5.12k
  obj_raw_syment_count (abfd) =
326
5.12k
    obj_conv_table_size (abfd) =
327
5.12k
      internal_f->f_nsyms;
328
329
5.12k
  pe->real_flags = internal_f->f_flags;
330
331
5.12k
  if ((internal_f->f_flags & F_DLL) != 0)
332
1.96k
    pe->dll = 1;
333
334
5.12k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
335
3.18k
    abfd->flags |= HAS_DEBUG;
336
337
5.12k
#ifdef COFF_IMAGE_WITH_PE
338
5.12k
  if (aouthdr)
339
3.02k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
340
5.12k
#endif
341
342
#ifdef ARM
343
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
344
    coff_data (abfd) ->flags = 0;
345
#endif
346
347
5.12k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
348
5.12k
    sizeof (pe->dos_message));
349
350
5.12k
  return (void *) pe;
351
5.12k
}
pei-sh.c:pe_mkobject_hook
Line
Count
Source
303
5.02k
{
304
5.02k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
305
5.02k
  pe_data_type *pe;
306
307
5.02k
  if (! pe_mkobject (abfd))
308
0
    return NULL;
309
310
5.02k
  pe = pe_data (abfd);
311
5.02k
  pe->coff.sym_filepos = internal_f->f_symptr;
312
  /* These members communicate important constants about the symbol
313
     table to GDB's symbol-reading code.  These `constants'
314
     unfortunately vary among coff implementations...  */
315
5.02k
  pe->coff.local_n_btmask = N_BTMASK;
316
5.02k
  pe->coff.local_n_btshft = N_BTSHFT;
317
5.02k
  pe->coff.local_n_tmask = N_TMASK;
318
5.02k
  pe->coff.local_n_tshift = N_TSHIFT;
319
5.02k
  pe->coff.local_symesz = SYMESZ;
320
5.02k
  pe->coff.local_auxesz = AUXESZ;
321
5.02k
  pe->coff.local_linesz = LINESZ;
322
323
5.02k
  pe->coff.timestamp = internal_f->f_timdat;
324
325
5.02k
  obj_raw_syment_count (abfd) =
326
5.02k
    obj_conv_table_size (abfd) =
327
5.02k
      internal_f->f_nsyms;
328
329
5.02k
  pe->real_flags = internal_f->f_flags;
330
331
5.02k
  if ((internal_f->f_flags & F_DLL) != 0)
332
2.00k
    pe->dll = 1;
333
334
5.02k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
335
3.05k
    abfd->flags |= HAS_DEBUG;
336
337
5.02k
#ifdef COFF_IMAGE_WITH_PE
338
5.02k
  if (aouthdr)
339
2.82k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
340
5.02k
#endif
341
342
#ifdef ARM
343
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
344
    coff_data (abfd) ->flags = 0;
345
#endif
346
347
5.02k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
348
5.02k
    sizeof (pe->dos_message));
349
350
5.02k
  return (void *) pe;
351
5.02k
}
352
353
static bool
354
pe_print_private_bfd_data (bfd *abfd, void *vfile)
355
9.76k
{
356
9.76k
  FILE *file = (FILE *) vfile;
357
358
9.76k
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
359
0
    return false;
360
361
9.76k
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
362
9.53k
    return true;
363
364
230
  fputc ('\n', file);
365
366
230
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
367
9.76k
}
pei-i386.c:pe_print_private_bfd_data
Line
Count
Source
355
200
{
356
200
  FILE *file = (FILE *) vfile;
357
358
200
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
359
0
    return false;
360
361
200
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
362
200
    return true;
363
364
0
  fputc ('\n', file);
365
366
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
367
200
}
pe-x86_64.c:pe_print_private_bfd_data
Line
Count
Source
355
187
{
356
187
  FILE *file = (FILE *) vfile;
357
358
187
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
359
0
    return false;
360
361
187
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
362
187
    return true;
363
364
0
  fputc ('\n', file);
365
366
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
367
187
}
pei-x86_64.c:pe_print_private_bfd_data
Line
Count
Source
355
176
{
356
176
  FILE *file = (FILE *) vfile;
357
358
176
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
359
0
    return false;
360
361
176
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
362
176
    return true;
363
364
0
  fputc ('\n', file);
365
366
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
367
176
}
pe-aarch64.c:pe_print_private_bfd_data
Line
Count
Source
355
4.74k
{
356
4.74k
  FILE *file = (FILE *) vfile;
357
358
4.74k
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
359
0
    return false;
360
361
4.74k
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
362
4.74k
    return true;
363
364
0
  fputc ('\n', file);
365
366
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
367
4.74k
}
pei-aarch64.c:pe_print_private_bfd_data
Line
Count
Source
355
2.96k
{
356
2.96k
  FILE *file = (FILE *) vfile;
357
358
2.96k
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
359
0
    return false;
360
361
2.96k
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
362
2.96k
    return true;
363
364
0
  fputc ('\n', file);
365
366
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
367
2.96k
}
pei-ia64.c:pe_print_private_bfd_data
Line
Count
Source
355
359
{
356
359
  FILE *file = (FILE *) vfile;
357
358
359
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
359
0
    return false;
360
361
359
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
362
359
    return true;
363
364
0
  fputc ('\n', file);
365
366
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
367
359
}
pei-loongarch64.c:pe_print_private_bfd_data
Line
Count
Source
355
211
{
356
211
  FILE *file = (FILE *) vfile;
357
358
211
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
359
0
    return false;
360
361
211
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
362
211
    return true;
363
364
0
  fputc ('\n', file);
365
366
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
367
211
}
pei-riscv64.c:pe_print_private_bfd_data
Line
Count
Source
355
229
{
356
229
  FILE *file = (FILE *) vfile;
357
358
229
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
359
0
    return false;
360
361
229
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
362
229
    return true;
363
364
0
  fputc ('\n', file);
365
366
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
367
229
}
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
355
60
{
356
60
  FILE *file = (FILE *) vfile;
357
358
60
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
359
0
    return false;
360
361
60
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
362
60
    return true;
363
364
0
  fputc ('\n', file);
365
366
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
367
60
}
pe-mcore.c:pe_print_private_bfd_data
Line
Count
Source
355
106
{
356
106
  FILE *file = (FILE *) vfile;
357
358
106
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
359
0
    return false;
360
361
106
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
362
106
    return true;
363
364
0
  fputc ('\n', file);
365
366
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
367
106
}
pe-sh.c:pe_print_private_bfd_data
Line
Count
Source
355
70
{
356
70
  FILE *file = (FILE *) vfile;
357
358
70
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
359
0
    return false;
360
361
70
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
362
70
    return true;
363
364
0
  fputc ('\n', file);
365
366
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
367
70
}
pei-arm-wince.c:pe_print_private_bfd_data
Line
Count
Source
355
10
{
356
10
  FILE *file = (FILE *) vfile;
357
358
10
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
359
0
    return false;
360
361
10
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
362
0
    return true;
363
364
10
  fputc ('\n', file);
365
366
10
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
367
10
}
pei-arm.c:pe_print_private_bfd_data
Line
Count
Source
355
220
{
356
220
  FILE *file = (FILE *) vfile;
357
358
220
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
359
0
    return false;
360
361
220
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
362
0
    return true;
363
364
220
  fputc ('\n', file);
365
366
220
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
367
220
}
pei-mcore.c:pe_print_private_bfd_data
Line
Count
Source
355
121
{
356
121
  FILE *file = (FILE *) vfile;
357
358
121
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
359
0
    return false;
360
361
121
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
362
121
    return true;
363
364
0
  fputc ('\n', file);
365
366
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
367
121
}
pei-sh.c:pe_print_private_bfd_data
Line
Count
Source
355
109
{
356
109
  FILE *file = (FILE *) vfile;
357
358
109
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
359
0
    return false;
360
361
109
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
362
109
    return true;
363
364
0
  fputc ('\n', file);
365
366
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
367
109
}
368
369
/* Copy any private info we understand from the input bfd
370
   to the output bfd.  */
371
372
static bool
373
pe_bfd_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
374
1.09k
{
375
  /* PR binutils/716: Copy the large address aware flag.
376
     XXX: Should we be copying other flags or other fields in the pe_data()
377
     structure ?  */
378
1.09k
  if (pe_data (obfd) != NULL
379
1.09k
      && pe_data (ibfd) != NULL
380
1.09k
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
381
414
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
382
383
1.09k
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
384
18
    return false;
385
386
1.07k
  if (pe_saved_coff_bfd_copy_private_bfd_data)
387
143
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
388
389
932
  return true;
390
1.07k
}
pei-i386.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
374
84
{
375
  /* PR binutils/716: Copy the large address aware flag.
376
     XXX: Should we be copying other flags or other fields in the pe_data()
377
     structure ?  */
378
84
  if (pe_data (obfd) != NULL
379
84
      && pe_data (ibfd) != NULL
380
84
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
381
32
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
382
383
84
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
384
1
    return false;
385
386
83
  if (pe_saved_coff_bfd_copy_private_bfd_data)
387
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
388
389
83
  return true;
390
83
}
pe-x86_64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
374
56
{
375
  /* PR binutils/716: Copy the large address aware flag.
376
     XXX: Should we be copying other flags or other fields in the pe_data()
377
     structure ?  */
378
56
  if (pe_data (obfd) != NULL
379
56
      && pe_data (ibfd) != NULL
380
56
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
381
7
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
382
383
56
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
384
0
    return false;
385
386
56
  if (pe_saved_coff_bfd_copy_private_bfd_data)
387
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
388
389
56
  return true;
390
56
}
pei-x86_64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
374
71
{
375
  /* PR binutils/716: Copy the large address aware flag.
376
     XXX: Should we be copying other flags or other fields in the pe_data()
377
     structure ?  */
378
71
  if (pe_data (obfd) != NULL
379
71
      && pe_data (ibfd) != NULL
380
71
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
381
34
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
382
383
71
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
384
2
    return false;
385
386
69
  if (pe_saved_coff_bfd_copy_private_bfd_data)
387
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
388
389
69
  return true;
390
69
}
pe-aarch64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
374
46
{
375
  /* PR binutils/716: Copy the large address aware flag.
376
     XXX: Should we be copying other flags or other fields in the pe_data()
377
     structure ?  */
378
46
  if (pe_data (obfd) != NULL
379
46
      && pe_data (ibfd) != NULL
380
46
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
381
12
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
382
383
46
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
384
0
    return false;
385
386
46
  if (pe_saved_coff_bfd_copy_private_bfd_data)
387
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
388
389
46
  return true;
390
46
}
pei-aarch64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
374
86
{
375
  /* PR binutils/716: Copy the large address aware flag.
376
     XXX: Should we be copying other flags or other fields in the pe_data()
377
     structure ?  */
378
86
  if (pe_data (obfd) != NULL
379
86
      && pe_data (ibfd) != NULL
380
86
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
381
29
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
382
383
86
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
384
1
    return false;
385
386
85
  if (pe_saved_coff_bfd_copy_private_bfd_data)
387
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
388
389
85
  return true;
390
85
}
pei-ia64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
374
142
{
375
  /* PR binutils/716: Copy the large address aware flag.
376
     XXX: Should we be copying other flags or other fields in the pe_data()
377
     structure ?  */
378
142
  if (pe_data (obfd) != NULL
379
142
      && pe_data (ibfd) != NULL
380
142
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
381
28
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
382
383
142
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
384
4
    return false;
385
386
138
  if (pe_saved_coff_bfd_copy_private_bfd_data)
387
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
388
389
138
  return true;
390
138
}
pei-loongarch64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
374
98
{
375
  /* PR binutils/716: Copy the large address aware flag.
376
     XXX: Should we be copying other flags or other fields in the pe_data()
377
     structure ?  */
378
98
  if (pe_data (obfd) != NULL
379
98
      && pe_data (ibfd) != NULL
380
98
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
381
38
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
382
383
98
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
384
2
    return false;
385
386
96
  if (pe_saved_coff_bfd_copy_private_bfd_data)
387
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
388
389
96
  return true;
390
96
}
pei-riscv64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
374
112
{
375
  /* PR binutils/716: Copy the large address aware flag.
376
     XXX: Should we be copying other flags or other fields in the pe_data()
377
     structure ?  */
378
112
  if (pe_data (obfd) != NULL
379
112
      && pe_data (ibfd) != NULL
380
112
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
381
81
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
382
383
112
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
384
5
    return false;
385
386
107
  if (pe_saved_coff_bfd_copy_private_bfd_data)
387
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
388
389
107
  return true;
390
107
}
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
374
45
{
375
  /* PR binutils/716: Copy the large address aware flag.
376
     XXX: Should we be copying other flags or other fields in the pe_data()
377
     structure ?  */
378
45
  if (pe_data (obfd) != NULL
379
45
      && pe_data (ibfd) != NULL
380
45
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
381
7
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
382
383
45
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
384
0
    return false;
385
386
45
  if (pe_saved_coff_bfd_copy_private_bfd_data)
387
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
388
389
45
  return true;
390
45
}
pe-mcore.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
374
33
{
375
  /* PR binutils/716: Copy the large address aware flag.
376
     XXX: Should we be copying other flags or other fields in the pe_data()
377
     structure ?  */
378
33
  if (pe_data (obfd) != NULL
379
33
      && pe_data (ibfd) != NULL
380
33
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
381
9
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
382
383
33
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
384
0
    return false;
385
386
33
  if (pe_saved_coff_bfd_copy_private_bfd_data)
387
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
388
389
33
  return true;
390
33
}
pe-sh.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
374
64
{
375
  /* PR binutils/716: Copy the large address aware flag.
376
     XXX: Should we be copying other flags or other fields in the pe_data()
377
     structure ?  */
378
64
  if (pe_data (obfd) != NULL
379
64
      && pe_data (ibfd) != NULL
380
64
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
381
8
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
382
383
64
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
384
0
    return false;
385
386
64
  if (pe_saved_coff_bfd_copy_private_bfd_data)
387
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
388
389
64
  return true;
390
64
}
pei-arm-wince.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
374
50
{
375
  /* PR binutils/716: Copy the large address aware flag.
376
     XXX: Should we be copying other flags or other fields in the pe_data()
377
     structure ?  */
378
50
  if (pe_data (obfd) != NULL
379
50
      && pe_data (ibfd) != NULL
380
50
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
381
27
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
382
383
50
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
384
0
    return false;
385
386
50
  if (pe_saved_coff_bfd_copy_private_bfd_data)
387
50
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
388
389
0
  return true;
390
50
}
pei-arm.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
374
96
{
375
  /* PR binutils/716: Copy the large address aware flag.
376
     XXX: Should we be copying other flags or other fields in the pe_data()
377
     structure ?  */
378
96
  if (pe_data (obfd) != NULL
379
96
      && pe_data (ibfd) != NULL
380
96
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
381
61
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
382
383
96
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
384
3
    return false;
385
386
93
  if (pe_saved_coff_bfd_copy_private_bfd_data)
387
93
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
388
389
0
  return true;
390
93
}
pei-mcore.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
374
52
{
375
  /* PR binutils/716: Copy the large address aware flag.
376
     XXX: Should we be copying other flags or other fields in the pe_data()
377
     structure ?  */
378
52
  if (pe_data (obfd) != NULL
379
52
      && pe_data (ibfd) != NULL
380
52
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
381
28
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
382
383
52
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
384
0
    return false;
385
386
52
  if (pe_saved_coff_bfd_copy_private_bfd_data)
387
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
388
389
52
  return true;
390
52
}
pei-sh.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
374
58
{
375
  /* PR binutils/716: Copy the large address aware flag.
376
     XXX: Should we be copying other flags or other fields in the pe_data()
377
     structure ?  */
378
58
  if (pe_data (obfd) != NULL
379
58
      && pe_data (ibfd) != NULL
380
58
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
381
13
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
382
383
58
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
384
0
    return false;
385
386
58
  if (pe_saved_coff_bfd_copy_private_bfd_data)
387
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
388
389
58
  return true;
390
58
}
391
392
#define coff_bfd_copy_private_section_data \
393
  _bfd_XX_bfd_copy_private_section_data
394
395
#define coff_get_symbol_info _bfd_XX_get_symbol_info
396
397
#ifdef COFF_IMAGE_WITH_PE
398

399
/* Code to handle Microsoft's Import Library Format.
400
   Also known as LINK6 format.
401
   Documentation about this format can be found at:
402
403
   https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#import-library-format  */
404
405
/* The following constants specify the sizes of the various data
406
   structures that we have to create in order to build a bfd describing
407
   an ILF object file.  The final "+ 1" in the definitions of SIZEOF_IDATA6
408
   and SIZEOF_IDATA7 below is to allow for the possibility that we might
409
   need a padding byte in order to ensure 16 bit alignment for the section's
410
   contents.
411
412
   The value for SIZEOF_ILF_STRINGS is computed as follows:
413
414
      There will be NUM_ILF_SECTIONS section symbols.  Allow 9 characters
415
      per symbol for their names (longest section name is .idata$x).
416
417
      There will be two symbols for the imported value, one the symbol name
418
      and one with _imp__ prefixed.  Allowing for the terminating nul's this
419
      is strlen (symbol_name) * 2 + 8 + 21 + strlen (source_dll).
420
421
      The strings in the string table must start STRING__SIZE_SIZE bytes into
422
      the table in order to for the string lookup code in coffgen/coffcode to
423
      work.  */
424
5.80k
#define NUM_ILF_RELOCS    8
425
19.3k
#define NUM_ILF_SECTIONS  6
426
14.5k
#define NUM_ILF_SYMS    (2 + NUM_ILF_SECTIONS)
427
428
2.90k
#define SIZEOF_ILF_SYMS    (NUM_ILF_SYMS * sizeof (*vars.sym_cache))
429
2.90k
#define SIZEOF_ILF_SYM_TABLE   (NUM_ILF_SYMS * sizeof (*vars.sym_table))
430
2.90k
#define SIZEOF_ILF_NATIVE_SYMS   (NUM_ILF_SYMS * sizeof (*vars.native_syms))
431
2.90k
#define SIZEOF_ILF_SYM_PTR_TABLE (NUM_ILF_SYMS * sizeof (*vars.sym_ptr_table))
432
2.90k
#define SIZEOF_ILF_EXT_SYMS  (NUM_ILF_SYMS * sizeof (*vars.esym_table))
433
2.90k
#define SIZEOF_ILF_RELOCS  (NUM_ILF_RELOCS * sizeof (*vars.reltab))
434
2.90k
#define SIZEOF_ILF_INT_RELOCS  (NUM_ILF_RELOCS * sizeof (*vars.int_reltab))
435
2.90k
#define SIZEOF_ILF_STRINGS   (strlen (symbol_name) * 2 + 8 \
436
2.90k
          + 21 + strlen (source_dll)   \
437
2.90k
          + NUM_ILF_SECTIONS * 9       \
438
2.90k
          + STRING_SIZE_SIZE)
439
1.93k
#define SIZEOF_IDATA2   (5 * 4)
440
441
/* For PEx64 idata4 & 5 have thumb size of 8 bytes.  */
442
#if defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64)
443
732
#define SIZEOF_IDATA4   (2 * 4)
444
732
#define SIZEOF_IDATA5   (2 * 4)
445
#else
446
2.17k
#define SIZEOF_IDATA4   (1 * 4)
447
2.17k
#define SIZEOF_IDATA5   (1 * 4)
448
#endif
449
450
2.62k
#define SIZEOF_IDATA6   (2 + strlen (import_name) + 1 + 1)
451
1.93k
#define SIZEOF_IDATA7   (strlen (source_dll) + 1 + 1)
452
1.93k
#define SIZEOF_ILF_SECTIONS (NUM_ILF_SECTIONS \
453
1.93k
         * sizeof (struct coff_section_tdata))
454
455
#define ILF_DATA_SIZE       \
456
1.93k
    + SIZEOF_ILF_SYMS        \
457
1.93k
    + SIZEOF_ILF_SYM_TABLE      \
458
1.93k
    + SIZEOF_ILF_NATIVE_SYMS      \
459
1.93k
    + SIZEOF_ILF_SYM_PTR_TABLE      \
460
1.93k
    + SIZEOF_ILF_EXT_SYMS      \
461
1.93k
    + SIZEOF_ILF_RELOCS        \
462
1.93k
    + SIZEOF_ILF_INT_RELOCS      \
463
1.93k
    + SIZEOF_ILF_STRINGS      \
464
1.93k
    + SIZEOF_IDATA2        \
465
1.93k
    + SIZEOF_IDATA4        \
466
1.93k
    + SIZEOF_IDATA5        \
467
1.93k
    + SIZEOF_IDATA6        \
468
1.93k
    + SIZEOF_IDATA7        \
469
1.93k
    + SIZEOF_ILF_SECTIONS      \
470
1.93k
    + MAX_TEXT_SECTION_SIZE
471
472
/* Create an empty relocation against the given symbol.  */
473
474
static void
475
pe_ILF_make_a_symbol_reloc (pe_ILF_vars *   vars,
476
          bfd_vma     address,
477
          bfd_reloc_code_real_type  reloc,
478
          struct bfd_symbol **  sym,
479
          unsigned int    sym_index)
480
1.76k
{
481
1.76k
  arelent *entry;
482
1.76k
  struct internal_reloc *internal;
483
484
1.76k
  entry = vars->reltab + vars->relcount;
485
1.76k
  internal = vars->int_reltab + vars->relcount;
486
487
1.76k
  entry->address     = address;
488
1.76k
  entry->addend      = 0;
489
1.76k
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
490
1.76k
  entry->sym_ptr_ptr = sym;
491
492
1.76k
  internal->r_vaddr  = address;
493
1.76k
  internal->r_symndx = sym_index;
494
1.76k
  internal->r_type   = entry->howto ? entry->howto->type : 0;
495
496
1.76k
  vars->relcount ++;
497
498
1.76k
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
499
1.76k
}
pei-i386.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
480
219
{
481
219
  arelent *entry;
482
219
  struct internal_reloc *internal;
483
484
219
  entry = vars->reltab + vars->relcount;
485
219
  internal = vars->int_reltab + vars->relcount;
486
487
219
  entry->address     = address;
488
219
  entry->addend      = 0;
489
219
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
490
219
  entry->sym_ptr_ptr = sym;
491
492
219
  internal->r_vaddr  = address;
493
219
  internal->r_symndx = sym_index;
494
219
  internal->r_type   = entry->howto ? entry->howto->type : 0;
495
496
219
  vars->relcount ++;
497
498
219
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
499
219
}
pei-x86_64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
480
230
{
481
230
  arelent *entry;
482
230
  struct internal_reloc *internal;
483
484
230
  entry = vars->reltab + vars->relcount;
485
230
  internal = vars->int_reltab + vars->relcount;
486
487
230
  entry->address     = address;
488
230
  entry->addend      = 0;
489
230
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
490
230
  entry->sym_ptr_ptr = sym;
491
492
230
  internal->r_vaddr  = address;
493
230
  internal->r_symndx = sym_index;
494
230
  internal->r_type   = entry->howto ? entry->howto->type : 0;
495
496
230
  vars->relcount ++;
497
498
230
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
499
230
}
pei-aarch64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
480
214
{
481
214
  arelent *entry;
482
214
  struct internal_reloc *internal;
483
484
214
  entry = vars->reltab + vars->relcount;
485
214
  internal = vars->int_reltab + vars->relcount;
486
487
214
  entry->address     = address;
488
214
  entry->addend      = 0;
489
214
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
490
214
  entry->sym_ptr_ptr = sym;
491
492
214
  internal->r_vaddr  = address;
493
214
  internal->r_symndx = sym_index;
494
214
  internal->r_type   = entry->howto ? entry->howto->type : 0;
495
496
214
  vars->relcount ++;
497
498
214
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
499
214
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_symbol_reloc
pei-loongarch64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
480
217
{
481
217
  arelent *entry;
482
217
  struct internal_reloc *internal;
483
484
217
  entry = vars->reltab + vars->relcount;
485
217
  internal = vars->int_reltab + vars->relcount;
486
487
217
  entry->address     = address;
488
217
  entry->addend      = 0;
489
217
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
490
217
  entry->sym_ptr_ptr = sym;
491
492
217
  internal->r_vaddr  = address;
493
217
  internal->r_symndx = sym_index;
494
217
  internal->r_type   = entry->howto ? entry->howto->type : 0;
495
496
217
  vars->relcount ++;
497
498
217
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
499
217
}
pei-riscv64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
480
217
{
481
217
  arelent *entry;
482
217
  struct internal_reloc *internal;
483
484
217
  entry = vars->reltab + vars->relcount;
485
217
  internal = vars->int_reltab + vars->relcount;
486
487
217
  entry->address     = address;
488
217
  entry->addend      = 0;
489
217
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
490
217
  entry->sym_ptr_ptr = sym;
491
492
217
  internal->r_vaddr  = address;
493
217
  internal->r_symndx = sym_index;
494
217
  internal->r_type   = entry->howto ? entry->howto->type : 0;
495
496
217
  vars->relcount ++;
497
498
217
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
499
217
}
pei-arm-wince.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
480
162
{
481
162
  arelent *entry;
482
162
  struct internal_reloc *internal;
483
484
162
  entry = vars->reltab + vars->relcount;
485
162
  internal = vars->int_reltab + vars->relcount;
486
487
162
  entry->address     = address;
488
162
  entry->addend      = 0;
489
162
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
490
162
  entry->sym_ptr_ptr = sym;
491
492
162
  internal->r_vaddr  = address;
493
162
  internal->r_symndx = sym_index;
494
162
  internal->r_type   = entry->howto ? entry->howto->type : 0;
495
496
162
  vars->relcount ++;
497
498
162
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
499
162
}
pei-arm.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
480
169
{
481
169
  arelent *entry;
482
169
  struct internal_reloc *internal;
483
484
169
  entry = vars->reltab + vars->relcount;
485
169
  internal = vars->int_reltab + vars->relcount;
486
487
169
  entry->address     = address;
488
169
  entry->addend      = 0;
489
169
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
490
169
  entry->sym_ptr_ptr = sym;
491
492
169
  internal->r_vaddr  = address;
493
169
  internal->r_symndx = sym_index;
494
169
  internal->r_type   = entry->howto ? entry->howto->type : 0;
495
496
169
  vars->relcount ++;
497
498
169
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
499
169
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_symbol_reloc
pei-sh.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
480
341
{
481
341
  arelent *entry;
482
341
  struct internal_reloc *internal;
483
484
341
  entry = vars->reltab + vars->relcount;
485
341
  internal = vars->int_reltab + vars->relcount;
486
487
341
  entry->address     = address;
488
341
  entry->addend      = 0;
489
341
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
490
341
  entry->sym_ptr_ptr = sym;
491
492
341
  internal->r_vaddr  = address;
493
341
  internal->r_symndx = sym_index;
494
341
  internal->r_type   = entry->howto ? entry->howto->type : 0;
495
496
341
  vars->relcount ++;
497
498
341
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
499
341
}
500
501
/* Create an empty relocation against the given section.  */
502
503
static void
504
pe_ILF_make_a_reloc (pe_ILF_vars *         vars,
505
         bfd_vma           address,
506
         bfd_reloc_code_real_type  reloc,
507
         asection_ptr        sec)
508
1.36k
{
509
1.36k
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
510
1.36k
            coff_section_data (vars->abfd, sec)->i);
511
1.36k
}
pei-i386.c:pe_ILF_make_a_reloc
Line
Count
Source
508
162
{
509
162
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
510
162
            coff_section_data (vars->abfd, sec)->i);
511
162
}
pei-x86_64.c:pe_ILF_make_a_reloc
Line
Count
Source
508
186
{
509
186
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
510
186
            coff_section_data (vars->abfd, sec)->i);
511
186
}
pei-aarch64.c:pe_ILF_make_a_reloc
Line
Count
Source
508
164
{
509
164
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
510
164
            coff_section_data (vars->abfd, sec)->i);
511
164
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_reloc
pei-loongarch64.c:pe_ILF_make_a_reloc
Line
Count
Source
508
166
{
509
166
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
510
166
            coff_section_data (vars->abfd, sec)->i);
511
166
}
pei-riscv64.c:pe_ILF_make_a_reloc
Line
Count
Source
508
176
{
509
176
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
510
176
            coff_section_data (vars->abfd, sec)->i);
511
176
}
pei-arm-wince.c:pe_ILF_make_a_reloc
Line
Count
Source
508
118
{
509
118
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
510
118
            coff_section_data (vars->abfd, sec)->i);
511
118
}
pei-arm.c:pe_ILF_make_a_reloc
Line
Count
Source
508
122
{
509
122
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
510
122
            coff_section_data (vars->abfd, sec)->i);
511
122
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_reloc
pei-sh.c:pe_ILF_make_a_reloc
Line
Count
Source
508
274
{
509
274
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
510
274
            coff_section_data (vars->abfd, sec)->i);
511
274
}
512
513
/* Move the queued relocs into the given section.  */
514
515
static void
516
pe_ILF_save_relocs (pe_ILF_vars *vars,
517
        asection_ptr sec)
518
1.76k
{
519
  /* Make sure that there is somewhere to store the internal relocs.  */
520
1.76k
  if (coff_section_data (vars->abfd, sec) == NULL)
521
    /* We should probably return an error indication here.  */
522
0
    abort ();
523
524
1.76k
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
525
526
1.76k
  sec->relocation  = vars->reltab;
527
1.76k
  sec->reloc_count = vars->relcount;
528
1.76k
  sec->flags      |= SEC_RELOC;
529
530
1.76k
  vars->reltab     += vars->relcount;
531
1.76k
  vars->int_reltab += vars->relcount;
532
1.76k
  vars->relcount   = 0;
533
534
1.76k
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
535
1.76k
}
pei-i386.c:pe_ILF_save_relocs
Line
Count
Source
518
219
{
519
  /* Make sure that there is somewhere to store the internal relocs.  */
520
219
  if (coff_section_data (vars->abfd, sec) == NULL)
521
    /* We should probably return an error indication here.  */
522
0
    abort ();
523
524
219
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
525
526
219
  sec->relocation  = vars->reltab;
527
219
  sec->reloc_count = vars->relcount;
528
219
  sec->flags      |= SEC_RELOC;
529
530
219
  vars->reltab     += vars->relcount;
531
219
  vars->int_reltab += vars->relcount;
532
219
  vars->relcount   = 0;
533
534
219
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
535
219
}
pei-x86_64.c:pe_ILF_save_relocs
Line
Count
Source
518
230
{
519
  /* Make sure that there is somewhere to store the internal relocs.  */
520
230
  if (coff_section_data (vars->abfd, sec) == NULL)
521
    /* We should probably return an error indication here.  */
522
0
    abort ();
523
524
230
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
525
526
230
  sec->relocation  = vars->reltab;
527
230
  sec->reloc_count = vars->relcount;
528
230
  sec->flags      |= SEC_RELOC;
529
530
230
  vars->reltab     += vars->relcount;
531
230
  vars->int_reltab += vars->relcount;
532
230
  vars->relcount   = 0;
533
534
230
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
535
230
}
pei-aarch64.c:pe_ILF_save_relocs
Line
Count
Source
518
214
{
519
  /* Make sure that there is somewhere to store the internal relocs.  */
520
214
  if (coff_section_data (vars->abfd, sec) == NULL)
521
    /* We should probably return an error indication here.  */
522
0
    abort ();
523
524
214
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
525
526
214
  sec->relocation  = vars->reltab;
527
214
  sec->reloc_count = vars->relcount;
528
214
  sec->flags      |= SEC_RELOC;
529
530
214
  vars->reltab     += vars->relcount;
531
214
  vars->int_reltab += vars->relcount;
532
214
  vars->relcount   = 0;
533
534
214
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
535
214
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_save_relocs
pei-loongarch64.c:pe_ILF_save_relocs
Line
Count
Source
518
217
{
519
  /* Make sure that there is somewhere to store the internal relocs.  */
520
217
  if (coff_section_data (vars->abfd, sec) == NULL)
521
    /* We should probably return an error indication here.  */
522
0
    abort ();
523
524
217
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
525
526
217
  sec->relocation  = vars->reltab;
527
217
  sec->reloc_count = vars->relcount;
528
217
  sec->flags      |= SEC_RELOC;
529
530
217
  vars->reltab     += vars->relcount;
531
217
  vars->int_reltab += vars->relcount;
532
217
  vars->relcount   = 0;
533
534
217
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
535
217
}
pei-riscv64.c:pe_ILF_save_relocs
Line
Count
Source
518
217
{
519
  /* Make sure that there is somewhere to store the internal relocs.  */
520
217
  if (coff_section_data (vars->abfd, sec) == NULL)
521
    /* We should probably return an error indication here.  */
522
0
    abort ();
523
524
217
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
525
526
217
  sec->relocation  = vars->reltab;
527
217
  sec->reloc_count = vars->relcount;
528
217
  sec->flags      |= SEC_RELOC;
529
530
217
  vars->reltab     += vars->relcount;
531
217
  vars->int_reltab += vars->relcount;
532
217
  vars->relcount   = 0;
533
534
217
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
535
217
}
pei-arm-wince.c:pe_ILF_save_relocs
Line
Count
Source
518
162
{
519
  /* Make sure that there is somewhere to store the internal relocs.  */
520
162
  if (coff_section_data (vars->abfd, sec) == NULL)
521
    /* We should probably return an error indication here.  */
522
0
    abort ();
523
524
162
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
525
526
162
  sec->relocation  = vars->reltab;
527
162
  sec->reloc_count = vars->relcount;
528
162
  sec->flags      |= SEC_RELOC;
529
530
162
  vars->reltab     += vars->relcount;
531
162
  vars->int_reltab += vars->relcount;
532
162
  vars->relcount   = 0;
533
534
162
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
535
162
}
pei-arm.c:pe_ILF_save_relocs
Line
Count
Source
518
169
{
519
  /* Make sure that there is somewhere to store the internal relocs.  */
520
169
  if (coff_section_data (vars->abfd, sec) == NULL)
521
    /* We should probably return an error indication here.  */
522
0
    abort ();
523
524
169
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
525
526
169
  sec->relocation  = vars->reltab;
527
169
  sec->reloc_count = vars->relcount;
528
169
  sec->flags      |= SEC_RELOC;
529
530
169
  vars->reltab     += vars->relcount;
531
169
  vars->int_reltab += vars->relcount;
532
169
  vars->relcount   = 0;
533
534
169
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
535
169
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_save_relocs
pei-sh.c:pe_ILF_save_relocs
Line
Count
Source
518
341
{
519
  /* Make sure that there is somewhere to store the internal relocs.  */
520
341
  if (coff_section_data (vars->abfd, sec) == NULL)
521
    /* We should probably return an error indication here.  */
522
0
    abort ();
523
524
341
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
525
526
341
  sec->relocation  = vars->reltab;
527
341
  sec->reloc_count = vars->relcount;
528
341
  sec->flags      |= SEC_RELOC;
529
530
341
  vars->reltab     += vars->relcount;
531
341
  vars->int_reltab += vars->relcount;
532
341
  vars->relcount   = 0;
533
534
341
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
535
341
}
536
537
/* Create a global symbol and add it to the relevant tables.  */
538
539
static void
540
pe_ILF_make_a_symbol (pe_ILF_vars *  vars,
541
          const char *   prefix,
542
          const char *   symbol_name,
543
          asection_ptr   section,
544
          flagword       extra_flags)
545
5.45k
{
546
5.45k
  coff_symbol_type *sym;
547
5.45k
  combined_entry_type *ent;
548
5.45k
  SYMENT *esym;
549
5.45k
  unsigned short sclass;
550
551
5.45k
  if (extra_flags & BSF_LOCAL)
552
3.02k
    sclass = C_STAT;
553
2.43k
  else
554
2.43k
    sclass = C_EXT;
555
556
#ifdef THUMBPEMAGIC
557
1.08k
  if (vars->magic == THUMBPEMAGIC)
558
618
    {
559
618
      if (extra_flags & BSF_FUNCTION)
560
48
  sclass = C_THUMBEXTFUNC;
561
570
      else if (extra_flags & BSF_LOCAL)
562
340
  sclass = C_THUMBSTAT;
563
230
      else
564
230
  sclass = C_THUMBEXT;
565
618
    }
566
#endif
567
568
5.45k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
569
570
5.45k
  sym = vars->sym_ptr;
571
5.45k
  ent = vars->native_ptr;
572
5.45k
  esym = vars->esym_ptr;
573
574
  /* Copy the symbol's name into the string table.  */
575
5.45k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
576
577
5.45k
  if (section == NULL)
578
900
    section = bfd_und_section_ptr;
579
580
  /* Initialise the external symbol.  */
581
5.45k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
582
5.45k
      esym->e.e.e_offset);
583
5.45k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
584
5.45k
  esym->e_sclass[0] = sclass;
585
586
  /* The following initialisations are unnecessary - the memory is
587
     zero initialised.  They are just kept here as reminders.  */
588
589
  /* Initialise the internal symbol structure.  */
590
5.45k
  ent->u.syment.n_sclass    = sclass;
591
5.45k
  ent->u.syment.n_scnum     = section->target_index;
592
5.45k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
593
5.45k
  ent->is_sym = true;
594
595
5.45k
  sym->symbol.the_bfd = vars->abfd;
596
5.45k
  sym->symbol.name    = vars->string_ptr;
597
5.45k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
598
5.45k
  sym->symbol.section = section;
599
5.45k
  sym->native       = ent;
600
601
5.45k
  *vars->table_ptr = vars->sym_index;
602
5.45k
  *vars->sym_ptr_ptr = sym;
603
604
  /* Adjust pointers for the next symbol.  */
605
5.45k
  vars->sym_index ++;
606
5.45k
  vars->sym_ptr ++;
607
5.45k
  vars->sym_ptr_ptr ++;
608
5.45k
  vars->table_ptr ++;
609
5.45k
  vars->native_ptr ++;
610
5.45k
  vars->esym_ptr ++;
611
5.45k
  vars->string_ptr += len + 1;
612
613
5.45k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
614
5.45k
}
pei-i386.c:pe_ILF_make_a_symbol
Line
Count
Source
545
653
{
546
653
  coff_symbol_type *sym;
547
653
  combined_entry_type *ent;
548
653
  SYMENT *esym;
549
653
  unsigned short sclass;
550
551
653
  if (extra_flags & BSF_LOCAL)
552
358
    sclass = C_STAT;
553
295
  else
554
295
    sclass = C_EXT;
555
556
#ifdef THUMBPEMAGIC
557
  if (vars->magic == THUMBPEMAGIC)
558
    {
559
      if (extra_flags & BSF_FUNCTION)
560
  sclass = C_THUMBEXTFUNC;
561
      else if (extra_flags & BSF_LOCAL)
562
  sclass = C_THUMBSTAT;
563
      else
564
  sclass = C_THUMBEXT;
565
    }
566
#endif
567
568
653
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
569
570
653
  sym = vars->sym_ptr;
571
653
  ent = vars->native_ptr;
572
653
  esym = vars->esym_ptr;
573
574
  /* Copy the symbol's name into the string table.  */
575
653
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
576
577
653
  if (section == NULL)
578
104
    section = bfd_und_section_ptr;
579
580
  /* Initialise the external symbol.  */
581
653
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
582
653
      esym->e.e.e_offset);
583
653
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
584
653
  esym->e_sclass[0] = sclass;
585
586
  /* The following initialisations are unnecessary - the memory is
587
     zero initialised.  They are just kept here as reminders.  */
588
589
  /* Initialise the internal symbol structure.  */
590
653
  ent->u.syment.n_sclass    = sclass;
591
653
  ent->u.syment.n_scnum     = section->target_index;
592
653
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
593
653
  ent->is_sym = true;
594
595
653
  sym->symbol.the_bfd = vars->abfd;
596
653
  sym->symbol.name    = vars->string_ptr;
597
653
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
598
653
  sym->symbol.section = section;
599
653
  sym->native       = ent;
600
601
653
  *vars->table_ptr = vars->sym_index;
602
653
  *vars->sym_ptr_ptr = sym;
603
604
  /* Adjust pointers for the next symbol.  */
605
653
  vars->sym_index ++;
606
653
  vars->sym_ptr ++;
607
653
  vars->sym_ptr_ptr ++;
608
653
  vars->table_ptr ++;
609
653
  vars->native_ptr ++;
610
653
  vars->esym_ptr ++;
611
653
  vars->string_ptr += len + 1;
612
613
653
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
614
653
}
pei-x86_64.c:pe_ILF_make_a_symbol
Line
Count
Source
545
722
{
546
722
  coff_symbol_type *sym;
547
722
  combined_entry_type *ent;
548
722
  SYMENT *esym;
549
722
  unsigned short sclass;
550
551
722
  if (extra_flags & BSF_LOCAL)
552
391
    sclass = C_STAT;
553
331
  else
554
331
    sclass = C_EXT;
555
556
#ifdef THUMBPEMAGIC
557
  if (vars->magic == THUMBPEMAGIC)
558
    {
559
      if (extra_flags & BSF_FUNCTION)
560
  sclass = C_THUMBEXTFUNC;
561
      else if (extra_flags & BSF_LOCAL)
562
  sclass = C_THUMBSTAT;
563
      else
564
  sclass = C_THUMBEXT;
565
    }
566
#endif
567
568
722
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
569
570
722
  sym = vars->sym_ptr;
571
722
  ent = vars->native_ptr;
572
722
  esym = vars->esym_ptr;
573
574
  /* Copy the symbol's name into the string table.  */
575
722
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
576
577
722
  if (section == NULL)
578
120
    section = bfd_und_section_ptr;
579
580
  /* Initialise the external symbol.  */
581
722
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
582
722
      esym->e.e.e_offset);
583
722
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
584
722
  esym->e_sclass[0] = sclass;
585
586
  /* The following initialisations are unnecessary - the memory is
587
     zero initialised.  They are just kept here as reminders.  */
588
589
  /* Initialise the internal symbol structure.  */
590
722
  ent->u.syment.n_sclass    = sclass;
591
722
  ent->u.syment.n_scnum     = section->target_index;
592
722
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
593
722
  ent->is_sym = true;
594
595
722
  sym->symbol.the_bfd = vars->abfd;
596
722
  sym->symbol.name    = vars->string_ptr;
597
722
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
598
722
  sym->symbol.section = section;
599
722
  sym->native       = ent;
600
601
722
  *vars->table_ptr = vars->sym_index;
602
722
  *vars->sym_ptr_ptr = sym;
603
604
  /* Adjust pointers for the next symbol.  */
605
722
  vars->sym_index ++;
606
722
  vars->sym_ptr ++;
607
722
  vars->sym_ptr_ptr ++;
608
722
  vars->table_ptr ++;
609
722
  vars->native_ptr ++;
610
722
  vars->esym_ptr ++;
611
722
  vars->string_ptr += len + 1;
612
613
722
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
614
722
}
pei-aarch64.c:pe_ILF_make_a_symbol
Line
Count
Source
545
658
{
546
658
  coff_symbol_type *sym;
547
658
  combined_entry_type *ent;
548
658
  SYMENT *esym;
549
658
  unsigned short sclass;
550
551
658
  if (extra_flags & BSF_LOCAL)
552
366
    sclass = C_STAT;
553
292
  else
554
292
    sclass = C_EXT;
555
556
#ifdef THUMBPEMAGIC
557
  if (vars->magic == THUMBPEMAGIC)
558
    {
559
      if (extra_flags & BSF_FUNCTION)
560
  sclass = C_THUMBEXTFUNC;
561
      else if (extra_flags & BSF_LOCAL)
562
  sclass = C_THUMBSTAT;
563
      else
564
  sclass = C_THUMBEXT;
565
    }
566
#endif
567
568
658
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
569
570
658
  sym = vars->sym_ptr;
571
658
  ent = vars->native_ptr;
572
658
  esym = vars->esym_ptr;
573
574
  /* Copy the symbol's name into the string table.  */
575
658
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
576
577
658
  if (section == NULL)
578
109
    section = bfd_und_section_ptr;
579
580
  /* Initialise the external symbol.  */
581
658
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
582
658
      esym->e.e.e_offset);
583
658
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
584
658
  esym->e_sclass[0] = sclass;
585
586
  /* The following initialisations are unnecessary - the memory is
587
     zero initialised.  They are just kept here as reminders.  */
588
589
  /* Initialise the internal symbol structure.  */
590
658
  ent->u.syment.n_sclass    = sclass;
591
658
  ent->u.syment.n_scnum     = section->target_index;
592
658
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
593
658
  ent->is_sym = true;
594
595
658
  sym->symbol.the_bfd = vars->abfd;
596
658
  sym->symbol.name    = vars->string_ptr;
597
658
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
598
658
  sym->symbol.section = section;
599
658
  sym->native       = ent;
600
601
658
  *vars->table_ptr = vars->sym_index;
602
658
  *vars->sym_ptr_ptr = sym;
603
604
  /* Adjust pointers for the next symbol.  */
605
658
  vars->sym_index ++;
606
658
  vars->sym_ptr ++;
607
658
  vars->sym_ptr_ptr ++;
608
658
  vars->table_ptr ++;
609
658
  vars->native_ptr ++;
610
658
  vars->esym_ptr ++;
611
658
  vars->string_ptr += len + 1;
612
613
658
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
614
658
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_symbol
pei-loongarch64.c:pe_ILF_make_a_symbol
Line
Count
Source
545
631
{
546
631
  coff_symbol_type *sym;
547
631
  combined_entry_type *ent;
548
631
  SYMENT *esym;
549
631
  unsigned short sclass;
550
551
631
  if (extra_flags & BSF_LOCAL)
552
358
    sclass = C_STAT;
553
273
  else
554
273
    sclass = C_EXT;
555
556
#ifdef THUMBPEMAGIC
557
  if (vars->magic == THUMBPEMAGIC)
558
    {
559
      if (extra_flags & BSF_FUNCTION)
560
  sclass = C_THUMBEXTFUNC;
561
      else if (extra_flags & BSF_LOCAL)
562
  sclass = C_THUMBSTAT;
563
      else
564
  sclass = C_THUMBEXT;
565
    }
566
#endif
567
568
631
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
569
570
631
  sym = vars->sym_ptr;
571
631
  ent = vars->native_ptr;
572
631
  esym = vars->esym_ptr;
573
574
  /* Copy the symbol's name into the string table.  */
575
631
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
576
577
631
  if (section == NULL)
578
105
    section = bfd_und_section_ptr;
579
580
  /* Initialise the external symbol.  */
581
631
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
582
631
      esym->e.e.e_offset);
583
631
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
584
631
  esym->e_sclass[0] = sclass;
585
586
  /* The following initialisations are unnecessary - the memory is
587
     zero initialised.  They are just kept here as reminders.  */
588
589
  /* Initialise the internal symbol structure.  */
590
631
  ent->u.syment.n_sclass    = sclass;
591
631
  ent->u.syment.n_scnum     = section->target_index;
592
631
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
593
631
  ent->is_sym = true;
594
595
631
  sym->symbol.the_bfd = vars->abfd;
596
631
  sym->symbol.name    = vars->string_ptr;
597
631
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
598
631
  sym->symbol.section = section;
599
631
  sym->native       = ent;
600
601
631
  *vars->table_ptr = vars->sym_index;
602
631
  *vars->sym_ptr_ptr = sym;
603
604
  /* Adjust pointers for the next symbol.  */
605
631
  vars->sym_index ++;
606
631
  vars->sym_ptr ++;
607
631
  vars->sym_ptr_ptr ++;
608
631
  vars->table_ptr ++;
609
631
  vars->native_ptr ++;
610
631
  vars->esym_ptr ++;
611
631
  vars->string_ptr += len + 1;
612
613
631
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
614
631
}
pei-riscv64.c:pe_ILF_make_a_symbol
Line
Count
Source
545
686
{
546
686
  coff_symbol_type *sym;
547
686
  combined_entry_type *ent;
548
686
  SYMENT *esym;
549
686
  unsigned short sclass;
550
551
686
  if (extra_flags & BSF_LOCAL)
552
371
    sclass = C_STAT;
553
315
  else
554
315
    sclass = C_EXT;
555
556
#ifdef THUMBPEMAGIC
557
  if (vars->magic == THUMBPEMAGIC)
558
    {
559
      if (extra_flags & BSF_FUNCTION)
560
  sclass = C_THUMBEXTFUNC;
561
      else if (extra_flags & BSF_LOCAL)
562
  sclass = C_THUMBSTAT;
563
      else
564
  sclass = C_THUMBEXT;
565
    }
566
#endif
567
568
686
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
569
570
686
  sym = vars->sym_ptr;
571
686
  ent = vars->native_ptr;
572
686
  esym = vars->esym_ptr;
573
574
  /* Copy the symbol's name into the string table.  */
575
686
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
576
577
686
  if (section == NULL)
578
114
    section = bfd_und_section_ptr;
579
580
  /* Initialise the external symbol.  */
581
686
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
582
686
      esym->e.e.e_offset);
583
686
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
584
686
  esym->e_sclass[0] = sclass;
585
586
  /* The following initialisations are unnecessary - the memory is
587
     zero initialised.  They are just kept here as reminders.  */
588
589
  /* Initialise the internal symbol structure.  */
590
686
  ent->u.syment.n_sclass    = sclass;
591
686
  ent->u.syment.n_scnum     = section->target_index;
592
686
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
593
686
  ent->is_sym = true;
594
595
686
  sym->symbol.the_bfd = vars->abfd;
596
686
  sym->symbol.name    = vars->string_ptr;
597
686
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
598
686
  sym->symbol.section = section;
599
686
  sym->native       = ent;
600
601
686
  *vars->table_ptr = vars->sym_index;
602
686
  *vars->sym_ptr_ptr = sym;
603
604
  /* Adjust pointers for the next symbol.  */
605
686
  vars->sym_index ++;
606
686
  vars->sym_ptr ++;
607
686
  vars->sym_ptr_ptr ++;
608
686
  vars->table_ptr ++;
609
686
  vars->native_ptr ++;
610
686
  vars->esym_ptr ++;
611
686
  vars->string_ptr += len + 1;
612
613
686
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
614
686
}
pei-arm-wince.c:pe_ILF_make_a_symbol
Line
Count
Source
545
529
{
546
529
  coff_symbol_type *sym;
547
529
  combined_entry_type *ent;
548
529
  SYMENT *esym;
549
529
  unsigned short sclass;
550
551
529
  if (extra_flags & BSF_LOCAL)
552
297
    sclass = C_STAT;
553
232
  else
554
232
    sclass = C_EXT;
555
556
529
#ifdef THUMBPEMAGIC
557
529
  if (vars->magic == THUMBPEMAGIC)
558
309
    {
559
309
      if (extra_flags & BSF_FUNCTION)
560
24
  sclass = C_THUMBEXTFUNC;
561
285
      else if (extra_flags & BSF_LOCAL)
562
170
  sclass = C_THUMBSTAT;
563
115
      else
564
115
  sclass = C_THUMBEXT;
565
309
    }
566
529
#endif
567
568
529
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
569
570
529
  sym = vars->sym_ptr;
571
529
  ent = vars->native_ptr;
572
529
  esym = vars->esym_ptr;
573
574
  /* Copy the symbol's name into the string table.  */
575
529
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
576
577
529
  if (section == NULL)
578
86
    section = bfd_und_section_ptr;
579
580
  /* Initialise the external symbol.  */
581
529
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
582
529
      esym->e.e.e_offset);
583
529
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
584
529
  esym->e_sclass[0] = sclass;
585
586
  /* The following initialisations are unnecessary - the memory is
587
     zero initialised.  They are just kept here as reminders.  */
588
589
  /* Initialise the internal symbol structure.  */
590
529
  ent->u.syment.n_sclass    = sclass;
591
529
  ent->u.syment.n_scnum     = section->target_index;
592
529
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
593
529
  ent->is_sym = true;
594
595
529
  sym->symbol.the_bfd = vars->abfd;
596
529
  sym->symbol.name    = vars->string_ptr;
597
529
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
598
529
  sym->symbol.section = section;
599
529
  sym->native       = ent;
600
601
529
  *vars->table_ptr = vars->sym_index;
602
529
  *vars->sym_ptr_ptr = sym;
603
604
  /* Adjust pointers for the next symbol.  */
605
529
  vars->sym_index ++;
606
529
  vars->sym_ptr ++;
607
529
  vars->sym_ptr_ptr ++;
608
529
  vars->table_ptr ++;
609
529
  vars->native_ptr ++;
610
529
  vars->esym_ptr ++;
611
529
  vars->string_ptr += len + 1;
612
613
529
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
614
529
}
pei-arm.c:pe_ILF_make_a_symbol
Line
Count
Source
545
554
{
546
554
  coff_symbol_type *sym;
547
554
  combined_entry_type *ent;
548
554
  SYMENT *esym;
549
554
  unsigned short sclass;
550
551
554
  if (extra_flags & BSF_LOCAL)
552
310
    sclass = C_STAT;
553
244
  else
554
244
    sclass = C_EXT;
555
556
554
#ifdef THUMBPEMAGIC
557
554
  if (vars->magic == THUMBPEMAGIC)
558
309
    {
559
309
      if (extra_flags & BSF_FUNCTION)
560
24
  sclass = C_THUMBEXTFUNC;
561
285
      else if (extra_flags & BSF_LOCAL)
562
170
  sclass = C_THUMBSTAT;
563
115
      else
564
115
  sclass = C_THUMBEXT;
565
309
    }
566
554
#endif
567
568
554
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
569
570
554
  sym = vars->sym_ptr;
571
554
  ent = vars->native_ptr;
572
554
  esym = vars->esym_ptr;
573
574
  /* Copy the symbol's name into the string table.  */
575
554
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
576
577
554
  if (section == NULL)
578
90
    section = bfd_und_section_ptr;
579
580
  /* Initialise the external symbol.  */
581
554
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
582
554
      esym->e.e.e_offset);
583
554
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
584
554
  esym->e_sclass[0] = sclass;
585
586
  /* The following initialisations are unnecessary - the memory is
587
     zero initialised.  They are just kept here as reminders.  */
588
589
  /* Initialise the internal symbol structure.  */
590
554
  ent->u.syment.n_sclass    = sclass;
591
554
  ent->u.syment.n_scnum     = section->target_index;
592
554
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
593
554
  ent->is_sym = true;
594
595
554
  sym->symbol.the_bfd = vars->abfd;
596
554
  sym->symbol.name    = vars->string_ptr;
597
554
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
598
554
  sym->symbol.section = section;
599
554
  sym->native       = ent;
600
601
554
  *vars->table_ptr = vars->sym_index;
602
554
  *vars->sym_ptr_ptr = sym;
603
604
  /* Adjust pointers for the next symbol.  */
605
554
  vars->sym_index ++;
606
554
  vars->sym_ptr ++;
607
554
  vars->sym_ptr_ptr ++;
608
554
  vars->table_ptr ++;
609
554
  vars->native_ptr ++;
610
554
  vars->esym_ptr ++;
611
554
  vars->string_ptr += len + 1;
612
613
554
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
614
554
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_symbol
pei-sh.c:pe_ILF_make_a_symbol
Line
Count
Source
545
1.02k
{
546
1.02k
  coff_symbol_type *sym;
547
1.02k
  combined_entry_type *ent;
548
1.02k
  SYMENT *esym;
549
1.02k
  unsigned short sclass;
550
551
1.02k
  if (extra_flags & BSF_LOCAL)
552
570
    sclass = C_STAT;
553
455
  else
554
455
    sclass = C_EXT;
555
556
#ifdef THUMBPEMAGIC
557
  if (vars->magic == THUMBPEMAGIC)
558
    {
559
      if (extra_flags & BSF_FUNCTION)
560
  sclass = C_THUMBEXTFUNC;
561
      else if (extra_flags & BSF_LOCAL)
562
  sclass = C_THUMBSTAT;
563
      else
564
  sclass = C_THUMBEXT;
565
    }
566
#endif
567
568
1.02k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
569
570
1.02k
  sym = vars->sym_ptr;
571
1.02k
  ent = vars->native_ptr;
572
1.02k
  esym = vars->esym_ptr;
573
574
  /* Copy the symbol's name into the string table.  */
575
1.02k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
576
577
1.02k
  if (section == NULL)
578
172
    section = bfd_und_section_ptr;
579
580
  /* Initialise the external symbol.  */
581
1.02k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
582
1.02k
      esym->e.e.e_offset);
583
1.02k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
584
1.02k
  esym->e_sclass[0] = sclass;
585
586
  /* The following initialisations are unnecessary - the memory is
587
     zero initialised.  They are just kept here as reminders.  */
588
589
  /* Initialise the internal symbol structure.  */
590
1.02k
  ent->u.syment.n_sclass    = sclass;
591
1.02k
  ent->u.syment.n_scnum     = section->target_index;
592
1.02k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
593
1.02k
  ent->is_sym = true;
594
595
1.02k
  sym->symbol.the_bfd = vars->abfd;
596
1.02k
  sym->symbol.name    = vars->string_ptr;
597
1.02k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
598
1.02k
  sym->symbol.section = section;
599
1.02k
  sym->native       = ent;
600
601
1.02k
  *vars->table_ptr = vars->sym_index;
602
1.02k
  *vars->sym_ptr_ptr = sym;
603
604
  /* Adjust pointers for the next symbol.  */
605
1.02k
  vars->sym_index ++;
606
1.02k
  vars->sym_ptr ++;
607
1.02k
  vars->sym_ptr_ptr ++;
608
1.02k
  vars->table_ptr ++;
609
1.02k
  vars->native_ptr ++;
610
1.02k
  vars->esym_ptr ++;
611
1.02k
  vars->string_ptr += len + 1;
612
613
1.02k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
614
1.02k
}
615
616
/* Create a section.  */
617
618
static asection_ptr
619
pe_ILF_make_a_section (pe_ILF_vars * vars,
620
           const char *  name,
621
           unsigned int  size,
622
           flagword      extra_flags)
623
3.02k
{
624
3.02k
  asection_ptr sec;
625
3.02k
  flagword     flags;
626
3.02k
  intptr_t alignment;
627
628
3.02k
  sec = bfd_make_section_old_way (vars->abfd, name);
629
3.02k
  if (sec == NULL)
630
0
    return NULL;
631
632
3.02k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
633
634
3.02k
  bfd_set_section_flags (sec, flags | extra_flags);
635
636
3.02k
  bfd_set_section_alignment (sec, 2);
637
638
  /* Check that we will not run out of space.  */
639
3.02k
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
640
641
  /* Set the section size and contents.  The actual
642
     contents are filled in by our parent.  */
643
3.02k
  bfd_set_section_size (sec, (bfd_size_type) size);
644
3.02k
  sec->contents = vars->data;
645
3.02k
  sec->target_index = vars->sec_index ++;
646
647
  /* Advance data pointer in the vars structure.  */
648
3.02k
  vars->data += size;
649
650
  /* Skip the padding byte if it was not needed.
651
     The logic here is that if the string length is odd,
652
     then the entire string length, including the null byte,
653
     is even and so the extra, padding byte, is not needed.  */
654
3.02k
  if (size & 1)
655
351
    vars->data --;
656
657
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
658
     preserve host alignment requirements.  The BFD_ASSERTs in this
659
     functions will warn us if we run out of room, but we should
660
     already have enough padding built in to ILF_DATA_SIZE.  */
661
3.02k
#if GCC_VERSION >= 3000
662
3.02k
  alignment = __alignof__ (struct coff_section_tdata);
663
#else
664
  alignment = 8;
665
#endif
666
3.02k
  vars->data
667
3.02k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
668
669
  /* Create a coff_section_tdata structure for our use.  */
670
3.02k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
671
3.02k
  vars->data += sizeof (struct coff_section_tdata);
672
673
3.02k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
674
675
  /* Create a symbol to refer to this section.  */
676
3.02k
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
677
678
  /* Cache the index to the symbol in the coff_section_data structure.  */
679
3.02k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
680
681
3.02k
  return sec;
682
3.02k
}
pei-i386.c:pe_ILF_make_a_section
Line
Count
Source
623
358
{
624
358
  asection_ptr sec;
625
358
  flagword     flags;
626
358
  intptr_t alignment;
627
628
358
  sec = bfd_make_section_old_way (vars->abfd, name);
629
358
  if (sec == NULL)
630
0
    return NULL;
631
632
358
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
633
634
358
  bfd_set_section_flags (sec, flags | extra_flags);
635
636
358
  bfd_set_section_alignment (sec, 2);
637
638
  /* Check that we will not run out of space.  */
639
358
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
640
641
  /* Set the section size and contents.  The actual
642
     contents are filled in by our parent.  */
643
358
  bfd_set_section_size (sec, (bfd_size_type) size);
644
358
  sec->contents = vars->data;
645
358
  sec->target_index = vars->sec_index ++;
646
647
  /* Advance data pointer in the vars structure.  */
648
358
  vars->data += size;
649
650
  /* Skip the padding byte if it was not needed.
651
     The logic here is that if the string length is odd,
652
     then the entire string length, including the null byte,
653
     is even and so the extra, padding byte, is not needed.  */
654
358
  if (size & 1)
655
28
    vars->data --;
656
657
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
658
     preserve host alignment requirements.  The BFD_ASSERTs in this
659
     functions will warn us if we run out of room, but we should
660
     already have enough padding built in to ILF_DATA_SIZE.  */
661
358
#if GCC_VERSION >= 3000
662
358
  alignment = __alignof__ (struct coff_section_tdata);
663
#else
664
  alignment = 8;
665
#endif
666
358
  vars->data
667
358
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
668
669
  /* Create a coff_section_tdata structure for our use.  */
670
358
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
671
358
  vars->data += sizeof (struct coff_section_tdata);
672
673
358
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
674
675
  /* Create a symbol to refer to this section.  */
676
358
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
677
678
  /* Cache the index to the symbol in the coff_section_data structure.  */
679
358
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
680
681
358
  return sec;
682
358
}
pei-x86_64.c:pe_ILF_make_a_section
Line
Count
Source
623
391
{
624
391
  asection_ptr sec;
625
391
  flagword     flags;
626
391
  intptr_t alignment;
627
628
391
  sec = bfd_make_section_old_way (vars->abfd, name);
629
391
  if (sec == NULL)
630
0
    return NULL;
631
632
391
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
633
634
391
  bfd_set_section_flags (sec, flags | extra_flags);
635
636
391
  bfd_set_section_alignment (sec, 2);
637
638
  /* Check that we will not run out of space.  */
639
391
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
640
641
  /* Set the section size and contents.  The actual
642
     contents are filled in by our parent.  */
643
391
  bfd_set_section_size (sec, (bfd_size_type) size);
644
391
  sec->contents = vars->data;
645
391
  sec->target_index = vars->sec_index ++;
646
647
  /* Advance data pointer in the vars structure.  */
648
391
  vars->data += size;
649
650
  /* Skip the padding byte if it was not needed.
651
     The logic here is that if the string length is odd,
652
     then the entire string length, including the null byte,
653
     is even and so the extra, padding byte, is not needed.  */
654
391
  if (size & 1)
655
49
    vars->data --;
656
657
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
658
     preserve host alignment requirements.  The BFD_ASSERTs in this
659
     functions will warn us if we run out of room, but we should
660
     already have enough padding built in to ILF_DATA_SIZE.  */
661
391
#if GCC_VERSION >= 3000
662
391
  alignment = __alignof__ (struct coff_section_tdata);
663
#else
664
  alignment = 8;
665
#endif
666
391
  vars->data
667
391
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
668
669
  /* Create a coff_section_tdata structure for our use.  */
670
391
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
671
391
  vars->data += sizeof (struct coff_section_tdata);
672
673
391
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
674
675
  /* Create a symbol to refer to this section.  */
676
391
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
677
678
  /* Cache the index to the symbol in the coff_section_data structure.  */
679
391
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
680
681
391
  return sec;
682
391
}
pei-aarch64.c:pe_ILF_make_a_section
Line
Count
Source
623
366
{
624
366
  asection_ptr sec;
625
366
  flagword     flags;
626
366
  intptr_t alignment;
627
628
366
  sec = bfd_make_section_old_way (vars->abfd, name);
629
366
  if (sec == NULL)
630
0
    return NULL;
631
632
366
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
633
634
366
  bfd_set_section_flags (sec, flags | extra_flags);
635
636
366
  bfd_set_section_alignment (sec, 2);
637
638
  /* Check that we will not run out of space.  */
639
366
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
640
641
  /* Set the section size and contents.  The actual
642
     contents are filled in by our parent.  */
643
366
  bfd_set_section_size (sec, (bfd_size_type) size);
644
366
  sec->contents = vars->data;
645
366
  sec->target_index = vars->sec_index ++;
646
647
  /* Advance data pointer in the vars structure.  */
648
366
  vars->data += size;
649
650
  /* Skip the padding byte if it was not needed.
651
     The logic here is that if the string length is odd,
652
     then the entire string length, including the null byte,
653
     is even and so the extra, padding byte, is not needed.  */
654
366
  if (size & 1)
655
41
    vars->data --;
656
657
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
658
     preserve host alignment requirements.  The BFD_ASSERTs in this
659
     functions will warn us if we run out of room, but we should
660
     already have enough padding built in to ILF_DATA_SIZE.  */
661
366
#if GCC_VERSION >= 3000
662
366
  alignment = __alignof__ (struct coff_section_tdata);
663
#else
664
  alignment = 8;
665
#endif
666
366
  vars->data
667
366
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
668
669
  /* Create a coff_section_tdata structure for our use.  */
670
366
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
671
366
  vars->data += sizeof (struct coff_section_tdata);
672
673
366
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
674
675
  /* Create a symbol to refer to this section.  */
676
366
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
677
678
  /* Cache the index to the symbol in the coff_section_data structure.  */
679
366
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
680
681
366
  return sec;
682
366
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_section
pei-loongarch64.c:pe_ILF_make_a_section
Line
Count
Source
623
358
{
624
358
  asection_ptr sec;
625
358
  flagword     flags;
626
358
  intptr_t alignment;
627
628
358
  sec = bfd_make_section_old_way (vars->abfd, name);
629
358
  if (sec == NULL)
630
0
    return NULL;
631
632
358
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
633
634
358
  bfd_set_section_flags (sec, flags | extra_flags);
635
636
358
  bfd_set_section_alignment (sec, 2);
637
638
  /* Check that we will not run out of space.  */
639
358
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
640
641
  /* Set the section size and contents.  The actual
642
     contents are filled in by our parent.  */
643
358
  bfd_set_section_size (sec, (bfd_size_type) size);
644
358
  sec->contents = vars->data;
645
358
  sec->target_index = vars->sec_index ++;
646
647
  /* Advance data pointer in the vars structure.  */
648
358
  vars->data += size;
649
650
  /* Skip the padding byte if it was not needed.
651
     The logic here is that if the string length is odd,
652
     then the entire string length, including the null byte,
653
     is even and so the extra, padding byte, is not needed.  */
654
358
  if (size & 1)
655
50
    vars->data --;
656
657
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
658
     preserve host alignment requirements.  The BFD_ASSERTs in this
659
     functions will warn us if we run out of room, but we should
660
     already have enough padding built in to ILF_DATA_SIZE.  */
661
358
#if GCC_VERSION >= 3000
662
358
  alignment = __alignof__ (struct coff_section_tdata);
663
#else
664
  alignment = 8;
665
#endif
666
358
  vars->data
667
358
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
668
669
  /* Create a coff_section_tdata structure for our use.  */
670
358
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
671
358
  vars->data += sizeof (struct coff_section_tdata);
672
673
358
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
674
675
  /* Create a symbol to refer to this section.  */
676
358
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
677
678
  /* Cache the index to the symbol in the coff_section_data structure.  */
679
358
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
680
681
358
  return sec;
682
358
}
pei-riscv64.c:pe_ILF_make_a_section
Line
Count
Source
623
371
{
624
371
  asection_ptr sec;
625
371
  flagword     flags;
626
371
  intptr_t alignment;
627
628
371
  sec = bfd_make_section_old_way (vars->abfd, name);
629
371
  if (sec == NULL)
630
0
    return NULL;
631
632
371
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
633
634
371
  bfd_set_section_flags (sec, flags | extra_flags);
635
636
371
  bfd_set_section_alignment (sec, 2);
637
638
  /* Check that we will not run out of space.  */
639
371
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
640
641
  /* Set the section size and contents.  The actual
642
     contents are filled in by our parent.  */
643
371
  bfd_set_section_size (sec, (bfd_size_type) size);
644
371
  sec->contents = vars->data;
645
371
  sec->target_index = vars->sec_index ++;
646
647
  /* Advance data pointer in the vars structure.  */
648
371
  vars->data += size;
649
650
  /* Skip the padding byte if it was not needed.
651
     The logic here is that if the string length is odd,
652
     then the entire string length, including the null byte,
653
     is even and so the extra, padding byte, is not needed.  */
654
371
  if (size & 1)
655
37
    vars->data --;
656
657
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
658
     preserve host alignment requirements.  The BFD_ASSERTs in this
659
     functions will warn us if we run out of room, but we should
660
     already have enough padding built in to ILF_DATA_SIZE.  */
661
371
#if GCC_VERSION >= 3000
662
371
  alignment = __alignof__ (struct coff_section_tdata);
663
#else
664
  alignment = 8;
665
#endif
666
371
  vars->data
667
371
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
668
669
  /* Create a coff_section_tdata structure for our use.  */
670
371
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
671
371
  vars->data += sizeof (struct coff_section_tdata);
672
673
371
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
674
675
  /* Create a symbol to refer to this section.  */
676
371
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
677
678
  /* Cache the index to the symbol in the coff_section_data structure.  */
679
371
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
680
681
371
  return sec;
682
371
}
pei-arm-wince.c:pe_ILF_make_a_section
Line
Count
Source
623
297
{
624
297
  asection_ptr sec;
625
297
  flagword     flags;
626
297
  intptr_t alignment;
627
628
297
  sec = bfd_make_section_old_way (vars->abfd, name);
629
297
  if (sec == NULL)
630
0
    return NULL;
631
632
297
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
633
634
297
  bfd_set_section_flags (sec, flags | extra_flags);
635
636
297
  bfd_set_section_alignment (sec, 2);
637
638
  /* Check that we will not run out of space.  */
639
297
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
640
641
  /* Set the section size and contents.  The actual
642
     contents are filled in by our parent.  */
643
297
  bfd_set_section_size (sec, (bfd_size_type) size);
644
297
  sec->contents = vars->data;
645
297
  sec->target_index = vars->sec_index ++;
646
647
  /* Advance data pointer in the vars structure.  */
648
297
  vars->data += size;
649
650
  /* Skip the padding byte if it was not needed.
651
     The logic here is that if the string length is odd,
652
     then the entire string length, including the null byte,
653
     is even and so the extra, padding byte, is not needed.  */
654
297
  if (size & 1)
655
31
    vars->data --;
656
657
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
658
     preserve host alignment requirements.  The BFD_ASSERTs in this
659
     functions will warn us if we run out of room, but we should
660
     already have enough padding built in to ILF_DATA_SIZE.  */
661
297
#if GCC_VERSION >= 3000
662
297
  alignment = __alignof__ (struct coff_section_tdata);
663
#else
664
  alignment = 8;
665
#endif
666
297
  vars->data
667
297
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
668
669
  /* Create a coff_section_tdata structure for our use.  */
670
297
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
671
297
  vars->data += sizeof (struct coff_section_tdata);
672
673
297
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
674
675
  /* Create a symbol to refer to this section.  */
676
297
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
677
678
  /* Cache the index to the symbol in the coff_section_data structure.  */
679
297
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
680
681
297
  return sec;
682
297
}
pei-arm.c:pe_ILF_make_a_section
Line
Count
Source
623
310
{
624
310
  asection_ptr sec;
625
310
  flagword     flags;
626
310
  intptr_t alignment;
627
628
310
  sec = bfd_make_section_old_way (vars->abfd, name);
629
310
  if (sec == NULL)
630
0
    return NULL;
631
632
310
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
633
634
310
  bfd_set_section_flags (sec, flags | extra_flags);
635
636
310
  bfd_set_section_alignment (sec, 2);
637
638
  /* Check that we will not run out of space.  */
639
310
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
640
641
  /* Set the section size and contents.  The actual
642
     contents are filled in by our parent.  */
643
310
  bfd_set_section_size (sec, (bfd_size_type) size);
644
310
  sec->contents = vars->data;
645
310
  sec->target_index = vars->sec_index ++;
646
647
  /* Advance data pointer in the vars structure.  */
648
310
  vars->data += size;
649
650
  /* Skip the padding byte if it was not needed.
651
     The logic here is that if the string length is odd,
652
     then the entire string length, including the null byte,
653
     is even and so the extra, padding byte, is not needed.  */
654
310
  if (size & 1)
655
31
    vars->data --;
656
657
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
658
     preserve host alignment requirements.  The BFD_ASSERTs in this
659
     functions will warn us if we run out of room, but we should
660
     already have enough padding built in to ILF_DATA_SIZE.  */
661
310
#if GCC_VERSION >= 3000
662
310
  alignment = __alignof__ (struct coff_section_tdata);
663
#else
664
  alignment = 8;
665
#endif
666
310
  vars->data
667
310
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
668
669
  /* Create a coff_section_tdata structure for our use.  */
670
310
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
671
310
  vars->data += sizeof (struct coff_section_tdata);
672
673
310
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
674
675
  /* Create a symbol to refer to this section.  */
676
310
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
677
678
  /* Cache the index to the symbol in the coff_section_data structure.  */
679
310
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
680
681
310
  return sec;
682
310
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_section
pei-sh.c:pe_ILF_make_a_section
Line
Count
Source
623
570
{
624
570
  asection_ptr sec;
625
570
  flagword     flags;
626
570
  intptr_t alignment;
627
628
570
  sec = bfd_make_section_old_way (vars->abfd, name);
629
570
  if (sec == NULL)
630
0
    return NULL;
631
632
570
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
633
634
570
  bfd_set_section_flags (sec, flags | extra_flags);
635
636
570
  bfd_set_section_alignment (sec, 2);
637
638
  /* Check that we will not run out of space.  */
639
570
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
640
641
  /* Set the section size and contents.  The actual
642
     contents are filled in by our parent.  */
643
570
  bfd_set_section_size (sec, (bfd_size_type) size);
644
570
  sec->contents = vars->data;
645
570
  sec->target_index = vars->sec_index ++;
646
647
  /* Advance data pointer in the vars structure.  */
648
570
  vars->data += size;
649
650
  /* Skip the padding byte if it was not needed.
651
     The logic here is that if the string length is odd,
652
     then the entire string length, including the null byte,
653
     is even and so the extra, padding byte, is not needed.  */
654
570
  if (size & 1)
655
84
    vars->data --;
656
657
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
658
     preserve host alignment requirements.  The BFD_ASSERTs in this
659
     functions will warn us if we run out of room, but we should
660
     already have enough padding built in to ILF_DATA_SIZE.  */
661
570
#if GCC_VERSION >= 3000
662
570
  alignment = __alignof__ (struct coff_section_tdata);
663
#else
664
  alignment = 8;
665
#endif
666
570
  vars->data
667
570
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
668
669
  /* Create a coff_section_tdata structure for our use.  */
670
570
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
671
570
  vars->data += sizeof (struct coff_section_tdata);
672
673
570
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
674
675
  /* Create a symbol to refer to this section.  */
676
570
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
677
678
  /* Cache the index to the symbol in the coff_section_data structure.  */
679
570
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
680
681
570
  return sec;
682
570
}
683
684
/* This structure contains the code that goes into the .text section
685
   in order to perform a jump into the DLL lookup table.  The entries
686
   in the table are index by the magic number used to represent the
687
   machine type in the PE file.  The contents of the data[] arrays in
688
   these entries are stolen from the jtab[] arrays in ld/pe-dll.c.
689
   The SIZE field says how many bytes in the DATA array are actually
690
   used.  The OFFSET field says where in the data array the address
691
   of the .idata$5 section should be placed.  */
692
1.93k
#define MAX_TEXT_SECTION_SIZE 32
693
694
typedef struct
695
{
696
  unsigned short magic;
697
  unsigned char  data[MAX_TEXT_SECTION_SIZE];
698
  unsigned int   size;
699
  unsigned int   offset;
700
}
701
jump_table;
702
703
static const jump_table jtab[] =
704
{
705
#ifdef I386MAGIC
706
  { I386MAGIC,
707
    { 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, 0x90, 0x90 },
708
    8, 2
709
  },
710
#endif
711
712
#ifdef AMD64MAGIC
713
  { AMD64MAGIC,
714
    { 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, 0x90, 0x90 },
715
    8, 2
716
  },
717
#endif
718
719
#ifdef  MC68MAGIC
720
  { MC68MAGIC,
721
    { /* XXX fill me in */ },
722
    0, 0
723
  },
724
#endif
725
726
#ifdef  MIPS_ARCH_MAGIC_WINCE
727
  { MIPS_ARCH_MAGIC_WINCE,
728
    { 0x00, 0x00, 0x08, 0x3c, 0x00, 0x00, 0x08, 0x8d,
729
      0x08, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00 },
730
    16, 0
731
  },
732
#endif
733
734
#ifdef  SH_ARCH_MAGIC_WINCE
735
  { SH_ARCH_MAGIC_WINCE,
736
    { 0x01, 0xd0, 0x02, 0x60, 0x2b, 0x40,
737
      0x09, 0x00, 0x00, 0x00, 0x00, 0x00 },
738
    12, 8
739
  },
740
#endif
741
742
#ifdef AARCH64MAGIC
743
/* We don't currently support jumping to DLLs, so if
744
   someone does try emit a runtime trap.  Through UDF #0.  */
745
  { AARCH64MAGIC,
746
    { 0x00, 0x00, 0x00, 0x00 },
747
    4, 0
748
  },
749
750
#endif
751
752
#ifdef  ARMPEMAGIC
753
  { ARMPEMAGIC,
754
    { 0x00, 0xc0, 0x9f, 0xe5, 0x00, 0xf0,
755
      0x9c, 0xe5, 0x00, 0x00, 0x00, 0x00},
756
    12, 8
757
  },
758
#endif
759
760
#ifdef  THUMBPEMAGIC
761
  { THUMBPEMAGIC,
762
    { 0x40, 0xb4, 0x02, 0x4e, 0x36, 0x68, 0xb4, 0x46,
763
      0x40, 0xbc, 0x60, 0x47, 0x00, 0x00, 0x00, 0x00 },
764
    16, 12
765
  },
766
#endif
767
768
#ifdef LOONGARCH64MAGIC
769
/* We don't currently support jumping to DLLs, so if
770
   someone does try emit a runtime trap.  Through BREAK 0.  */
771
  { LOONGARCH64MAGIC,
772
    { 0x00, 0x00, 0x2a, 0x00 },
773
    4, 0
774
  },
775
776
#endif
777
778
#ifdef RISCV64MAGIC
779
  /* We don't currently support jumping to DLLs, so if
780
     someone does try emit a runtime trap.  Through EBREAK.  */
781
  { RISCV64MAGIC,
782
    { 0x73, 0x00, 0x10, 0x00 },
783
    4, 0
784
  },
785
786
#endif
787
788
  { 0, { 0 }, 0, 0 }
789
};
790
791
#ifndef NUM_ENTRIES
792
401
#define NUM_ENTRIES(a) (sizeof (a) / sizeof (a)[0])
793
#endif
794
795
/* Build a full BFD from the information supplied in a ILF object.  */
796
797
static bool
798
pe_ILF_build_a_bfd (bfd *     abfd,
799
        unsigned int    magic,
800
        char *      symbol_name,
801
        char *      source_dll,
802
        unsigned int    ordinal,
803
        unsigned int    types,
804
        char *      import_name)
805
1.27k
{
806
1.27k
  bfd_byte *       ptr;
807
1.27k
  pe_ILF_vars      vars;
808
1.27k
  struct internal_filehdr  internal_f;
809
1.27k
  unsigned int       import_type;
810
1.27k
  unsigned int       import_name_type;
811
1.27k
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
812
1.27k
  coff_symbol_type **    imp_sym;
813
1.27k
  unsigned int       imp_index;
814
1.27k
  intptr_t alignment;
815
816
  /* Decode and verify the types field of the ILF structure.  */
817
1.27k
  import_type = types & 0x3;
818
1.27k
  import_name_type = (types & 0x1c) >> 2;
819
820
1.27k
  switch (import_type)
821
1.27k
    {
822
544
    case IMPORT_CODE:
823
864
    case IMPORT_DATA:
824
1.15k
    case IMPORT_CONST:
825
1.15k
      break;
826
827
118
    default:
828
      /* xgettext:c-format */
829
118
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
830
118
        abfd, import_type);
831
118
      return false;
832
1.27k
    }
833
834
1.15k
  switch (import_name_type)
835
1.15k
    {
836
284
    case IMPORT_ORDINAL:
837
400
    case IMPORT_NAME:
838
560
    case IMPORT_NAME_NOPREFIX:
839
882
    case IMPORT_NAME_UNDECORATE:
840
882
      import_name = symbol_name;
841
882
      break;
842
843
214
    case IMPORT_NAME_EXPORTAS:
844
214
      if (!import_name || !import_name[0])
845
128
  {
846
128
    _bfd_error_handler (_("%pB: missing import name for "
847
128
        "IMPORT_NAME_EXPORTAS for %s"),
848
128
            abfd, symbol_name);
849
128
    return false;
850
128
  }
851
86
      break;
852
853
86
    default:
854
      /* xgettext:c-format */
855
60
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
856
60
        abfd, import_name_type);
857
60
      return false;
858
1.15k
    }
859
860
  /* Initialise local variables.
861
862
     Note these are kept in a structure rather than being
863
     declared as statics since bfd frowns on global variables.
864
865
     We are going to construct the contents of the BFD in memory,
866
     so allocate all the space that we will need right now.  */
867
968
  vars.bim
868
968
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
869
968
  if (vars.bim == NULL)
870
0
    return false;
871
872
968
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
873
968
  vars.bim->buffer = ptr;
874
968
  vars.bim->size   = ILF_DATA_SIZE;
875
968
  if (ptr == NULL)
876
0
    goto error_return;
877
878
  /* Initialise the pointers to regions of the memory and the
879
     other contents of the pe_ILF_vars structure as well.  */
880
968
  vars.sym_cache = (coff_symbol_type *) ptr;
881
968
  vars.sym_ptr   = (coff_symbol_type *) ptr;
882
968
  vars.sym_index = 0;
883
968
  ptr += SIZEOF_ILF_SYMS;
884
885
968
  vars.sym_table = (unsigned int *) ptr;
886
968
  vars.table_ptr = (unsigned int *) ptr;
887
968
  ptr += SIZEOF_ILF_SYM_TABLE;
888
889
968
  vars.native_syms = (combined_entry_type *) ptr;
890
968
  vars.native_ptr  = (combined_entry_type *) ptr;
891
968
  ptr += SIZEOF_ILF_NATIVE_SYMS;
892
893
968
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
894
968
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
895
968
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
896
897
968
  vars.esym_table = (SYMENT *) ptr;
898
968
  vars.esym_ptr   = (SYMENT *) ptr;
899
968
  ptr += SIZEOF_ILF_EXT_SYMS;
900
901
968
  vars.reltab   = (arelent *) ptr;
902
968
  vars.relcount = 0;
903
968
  ptr += SIZEOF_ILF_RELOCS;
904
905
968
  vars.int_reltab  = (struct internal_reloc *) ptr;
906
968
  ptr += SIZEOF_ILF_INT_RELOCS;
907
908
968
  vars.string_table = (char *) ptr;
909
968
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
910
968
  ptr += SIZEOF_ILF_STRINGS;
911
968
  vars.end_string_ptr = (char *) ptr;
912
913
  /* The remaining space in bim->buffer is used
914
     by the pe_ILF_make_a_section() function.  */
915
916
  /* PR 18758: Make sure that the data area is sufficiently aligned for
917
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
918
     the test of GCC_VERSION.  For other compilers we assume 8 byte
919
     alignment.  */
920
968
#if GCC_VERSION >= 3000
921
968
  alignment = __alignof__ (struct coff_section_tdata);
922
#else
923
  alignment = 8;
924
#endif
925
968
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
926
927
968
  vars.data = ptr;
928
968
  vars.abfd = abfd;
929
968
  vars.sec_index = 0;
930
968
  vars.magic = magic;
931
932
  /* Create the initial .idata$<n> sections:
933
     [.idata$2:  Import Directory Table -- not needed]
934
     .idata$4:  Import Lookup Table
935
     .idata$5:  Import Address Table
936
937
     Note we do not create a .idata$3 section as this is
938
     created for us by the linker script.  */
939
968
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
940
968
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
941
968
  if (id4 == NULL || id5 == NULL)
942
0
    goto error_return;
943
944
  /* Fill in the contents of these sections.  */
945
968
  if (import_name_type == IMPORT_ORDINAL)
946
284
    {
947
284
      if (ordinal == 0)
948
  /* See PR 20907 for a reproducer.  */
949
68
  goto error_return;
950
951
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
952
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
953
102
      ((unsigned int *) id4->contents)[0] = ordinal;
954
102
      ((unsigned int *) id4->contents)[1] = 0x80000000;
955
102
      ((unsigned int *) id5->contents)[0] = ordinal;
956
102
      ((unsigned int *) id5->contents)[1] = 0x80000000;
957
#else
958
114
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
959
114
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
960
114
#endif
961
114
    }
962
684
  else
963
684
    {
964
684
      char *symbol;
965
684
      unsigned int len;
966
967
      /* Create .idata$6 - the Hint Name Table.  */
968
684
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
969
684
      if (id6 == NULL)
970
0
  goto error_return;
971
972
      /* If necessary, trim the import symbol name.  */
973
684
      symbol = import_name;
974
975
      /* As used by MS compiler, '_', '@', and '?' are alternative
976
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
977
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
978
   of these is used for a symbol.  We strip this leading char for
979
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
980
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
981
982
684
      if (import_name_type != IMPORT_NAME
983
568
    && import_name_type != IMPORT_NAME_EXPORTAS)
984
482
  {
985
482
    char c = symbol[0];
986
987
    /* Check that we don't remove for targets with empty
988
       USER_LABEL_PREFIX the leading underscore.  */
989
482
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
990
457
        || c == '@' || c == '?')
991
142
      symbol++;
992
482
  }
993
994
684
      len = strlen (symbol);
995
684
      if (import_name_type == IMPORT_NAME_UNDECORATE)
996
322
  {
997
    /* Truncate at the first '@'.  */
998
322
    char *at = strchr (symbol, '@');
999
1000
322
    if (at != NULL)
1001
73
      len = at - symbol;
1002
322
  }
1003
1004
684
      id6->contents[0] = ordinal & 0xff;
1005
684
      id6->contents[1] = ordinal >> 8;
1006
1007
684
      memcpy ((char *) id6->contents + 2, symbol, len);
1008
684
      id6->contents[len + 2] = '\0';
1009
684
    }
1010
1011
900
  if (import_name_type != IMPORT_ORDINAL)
1012
684
    {
1013
684
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1014
684
      pe_ILF_save_relocs (&vars, id4);
1015
1016
684
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1017
684
      pe_ILF_save_relocs (&vars, id5);
1018
684
    }
1019
1020
  /* Create an import symbol.  */
1021
900
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1022
900
  imp_sym   = vars.sym_ptr_ptr - 1;
1023
900
  imp_index = vars.sym_index - 1;
1024
1025
  /* Create extra sections depending upon the type of import we are
1026
     dealing with.  */
1027
900
  switch (import_type)
1028
900
    {
1029
0
      int i;
1030
1031
401
    case IMPORT_CODE:
1032
      /* CODE functions are special, in that they get a trampoline that
1033
   jumps to the main import symbol.  Create a .text section to hold it.
1034
   First we need to look up its contents in the jump table.  */
1035
845
      for (i = NUM_ENTRIES (jtab); i--;)
1036
845
  {
1037
845
    if (jtab[i].size == 0)
1038
401
      continue;
1039
444
    if (jtab[i].magic == magic)
1040
401
      break;
1041
444
  }
1042
      /* If we did not find a matching entry something is wrong.  */
1043
401
      if (i < 0)
1044
0
  abort ();
1045
1046
      /* Create the .text section.  */
1047
401
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1048
401
      if (text == NULL)
1049
0
  goto error_return;
1050
1051
      /* Copy in the jump code.  */
1052
401
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1053
1054
      /* Create a reloc for the data in the text section.  */
1055
#ifdef MIPS_ARCH_MAGIC_WINCE
1056
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1057
  {
1058
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1059
              (struct bfd_symbol **) imp_sym,
1060
              imp_index);
1061
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1062
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1063
              (struct bfd_symbol **) imp_sym,
1064
              imp_index);
1065
  }
1066
      else
1067
#endif
1068
#ifdef AMD64MAGIC
1069
44
      if (magic == AMD64MAGIC)
1070
44
  {
1071
44
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1072
44
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1073
44
              imp_index);
1074
44
  }
1075
0
      else
1076
0
#endif
1077
0
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1078
0
            BFD_RELOC_32, (asymbol **) imp_sym,
1079
0
            imp_index);
1080
1081
401
      pe_ILF_save_relocs (&vars, text);
1082
401
      break;
1083
1084
263
    case IMPORT_DATA:
1085
499
    case IMPORT_CONST:
1086
499
      break;
1087
1088
0
    default:
1089
      /* XXX code not yet written.  */
1090
0
      abort ();
1091
900
    }
1092
1093
  /* Now create a symbol describing the imported value.  */
1094
900
  switch (import_type)
1095
900
    {
1096
401
    case IMPORT_CODE:
1097
401
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1098
401
          BSF_NOT_AT_END | BSF_FUNCTION);
1099
1100
401
      break;
1101
1102
263
    case IMPORT_DATA:
1103
      /* Nothing to do here.  */
1104
263
      break;
1105
1106
236
    case IMPORT_CONST:
1107
236
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1108
236
      break;
1109
1110
0
    default:
1111
      /* XXX code not yet written.  */
1112
0
      abort ();
1113
900
    }
1114
1115
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1116
900
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1117
900
  if (ptr)
1118
121
    *ptr = 0;
1119
900
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1120
900
  if (ptr)
1121
121
    *ptr = '.';
1122
1123
  /* Initialise the bfd.  */
1124
900
  memset (&internal_f, 0, sizeof (internal_f));
1125
1126
900
  internal_f.f_magic  = magic;
1127
900
  internal_f.f_symptr = 0;
1128
900
  internal_f.f_nsyms  = 0;
1129
900
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1130
1131
900
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1132
900
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1133
0
    goto error_return;
1134
1135
900
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1136
0
    goto error_return;
1137
1138
900
  obj_pe (abfd) = true;
1139
#ifdef THUMBPEMAGIC
1140
176
  if (vars.magic == THUMBPEMAGIC)
1141
    /* Stop some linker warnings about thumb code not supporting
1142
       interworking.  */
1143
104
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1144
#endif
1145
1146
  /* Switch from file contents to memory contents.  */
1147
900
  bfd_cache_close (abfd);
1148
1149
900
  abfd->iostream = (void *) vars.bim;
1150
900
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1151
900
  abfd->iovec = &_bfd_memory_iovec;
1152
900
  abfd->where = 0;
1153
900
  abfd->origin = 0;
1154
900
  abfd->size = 0;
1155
900
  obj_sym_filepos (abfd) = 0;
1156
1157
  /* Point the bfd at the symbol table.  */
1158
900
  obj_symbols (abfd) = vars.sym_cache;
1159
900
  abfd->symcount = vars.sym_index;
1160
1161
900
  obj_raw_syments (abfd) = vars.native_syms;
1162
900
  obj_raw_syment_count (abfd) = vars.sym_index;
1163
900
  obj_coff_keep_raw_syms (abfd) = true;
1164
1165
900
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1166
900
  obj_coff_keep_syms (abfd) = true;
1167
1168
900
  obj_convert (abfd) = vars.sym_table;
1169
900
  obj_conv_table_size (abfd) = vars.sym_index;
1170
1171
900
  obj_coff_strings (abfd) = vars.string_table;
1172
900
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1173
900
  obj_coff_keep_strings (abfd) = true;
1174
1175
900
  return true;
1176
1177
68
 error_return:
1178
68
  free (vars.bim->buffer);
1179
68
  free (vars.bim);
1180
68
  return false;
1181
900
}
pei-i386.c:pe_ILF_build_a_bfd
Line
Count
Source
805
137
{
806
137
  bfd_byte *       ptr;
807
137
  pe_ILF_vars      vars;
808
137
  struct internal_filehdr  internal_f;
809
137
  unsigned int       import_type;
810
137
  unsigned int       import_name_type;
811
137
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
812
137
  coff_symbol_type **    imp_sym;
813
137
  unsigned int       imp_index;
814
137
  intptr_t alignment;
815
816
  /* Decode and verify the types field of the ILF structure.  */
817
137
  import_type = types & 0x3;
818
137
  import_name_type = (types & 0x1c) >> 2;
819
820
137
  switch (import_type)
821
137
    {
822
71
    case IMPORT_CODE:
823
91
    case IMPORT_DATA:
824
130
    case IMPORT_CONST:
825
130
      break;
826
827
7
    default:
828
      /* xgettext:c-format */
829
7
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
830
7
        abfd, import_type);
831
7
      return false;
832
137
    }
833
834
130
  switch (import_name_type)
835
130
    {
836
29
    case IMPORT_ORDINAL:
837
52
    case IMPORT_NAME:
838
74
    case IMPORT_NAME_NOPREFIX:
839
101
    case IMPORT_NAME_UNDECORATE:
840
101
      import_name = symbol_name;
841
101
      break;
842
843
21
    case IMPORT_NAME_EXPORTAS:
844
21
      if (!import_name || !import_name[0])
845
12
  {
846
12
    _bfd_error_handler (_("%pB: missing import name for "
847
12
        "IMPORT_NAME_EXPORTAS for %s"),
848
12
            abfd, symbol_name);
849
12
    return false;
850
12
  }
851
9
      break;
852
853
9
    default:
854
      /* xgettext:c-format */
855
8
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
856
8
        abfd, import_name_type);
857
8
      return false;
858
130
    }
859
860
  /* Initialise local variables.
861
862
     Note these are kept in a structure rather than being
863
     declared as statics since bfd frowns on global variables.
864
865
     We are going to construct the contents of the BFD in memory,
866
     so allocate all the space that we will need right now.  */
867
110
  vars.bim
868
110
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
869
110
  if (vars.bim == NULL)
870
0
    return false;
871
872
110
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
873
110
  vars.bim->buffer = ptr;
874
110
  vars.bim->size   = ILF_DATA_SIZE;
875
110
  if (ptr == NULL)
876
0
    goto error_return;
877
878
  /* Initialise the pointers to regions of the memory and the
879
     other contents of the pe_ILF_vars structure as well.  */
880
110
  vars.sym_cache = (coff_symbol_type *) ptr;
881
110
  vars.sym_ptr   = (coff_symbol_type *) ptr;
882
110
  vars.sym_index = 0;
883
110
  ptr += SIZEOF_ILF_SYMS;
884
885
110
  vars.sym_table = (unsigned int *) ptr;
886
110
  vars.table_ptr = (unsigned int *) ptr;
887
110
  ptr += SIZEOF_ILF_SYM_TABLE;
888
889
110
  vars.native_syms = (combined_entry_type *) ptr;
890
110
  vars.native_ptr  = (combined_entry_type *) ptr;
891
110
  ptr += SIZEOF_ILF_NATIVE_SYMS;
892
893
110
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
894
110
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
895
110
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
896
897
110
  vars.esym_table = (SYMENT *) ptr;
898
110
  vars.esym_ptr   = (SYMENT *) ptr;
899
110
  ptr += SIZEOF_ILF_EXT_SYMS;
900
901
110
  vars.reltab   = (arelent *) ptr;
902
110
  vars.relcount = 0;
903
110
  ptr += SIZEOF_ILF_RELOCS;
904
905
110
  vars.int_reltab  = (struct internal_reloc *) ptr;
906
110
  ptr += SIZEOF_ILF_INT_RELOCS;
907
908
110
  vars.string_table = (char *) ptr;
909
110
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
910
110
  ptr += SIZEOF_ILF_STRINGS;
911
110
  vars.end_string_ptr = (char *) ptr;
912
913
  /* The remaining space in bim->buffer is used
914
     by the pe_ILF_make_a_section() function.  */
915
916
  /* PR 18758: Make sure that the data area is sufficiently aligned for
917
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
918
     the test of GCC_VERSION.  For other compilers we assume 8 byte
919
     alignment.  */
920
110
#if GCC_VERSION >= 3000
921
110
  alignment = __alignof__ (struct coff_section_tdata);
922
#else
923
  alignment = 8;
924
#endif
925
110
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
926
927
110
  vars.data = ptr;
928
110
  vars.abfd = abfd;
929
110
  vars.sec_index = 0;
930
110
  vars.magic = magic;
931
932
  /* Create the initial .idata$<n> sections:
933
     [.idata$2:  Import Directory Table -- not needed]
934
     .idata$4:  Import Lookup Table
935
     .idata$5:  Import Address Table
936
937
     Note we do not create a .idata$3 section as this is
938
     created for us by the linker script.  */
939
110
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
940
110
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
941
110
  if (id4 == NULL || id5 == NULL)
942
0
    goto error_return;
943
944
  /* Fill in the contents of these sections.  */
945
110
  if (import_name_type == IMPORT_ORDINAL)
946
29
    {
947
29
      if (ordinal == 0)
948
  /* See PR 20907 for a reproducer.  */
949
6
  goto error_return;
950
951
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
952
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
953
      ((unsigned int *) id4->contents)[0] = ordinal;
954
      ((unsigned int *) id4->contents)[1] = 0x80000000;
955
      ((unsigned int *) id5->contents)[0] = ordinal;
956
      ((unsigned int *) id5->contents)[1] = 0x80000000;
957
#else
958
23
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
959
23
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
960
23
#endif
961
23
    }
962
81
  else
963
81
    {
964
81
      char *symbol;
965
81
      unsigned int len;
966
967
      /* Create .idata$6 - the Hint Name Table.  */
968
81
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
969
81
      if (id6 == NULL)
970
0
  goto error_return;
971
972
      /* If necessary, trim the import symbol name.  */
973
81
      symbol = import_name;
974
975
      /* As used by MS compiler, '_', '@', and '?' are alternative
976
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
977
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
978
   of these is used for a symbol.  We strip this leading char for
979
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
980
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
981
982
81
      if (import_name_type != IMPORT_NAME
983
58
    && import_name_type != IMPORT_NAME_EXPORTAS)
984
49
  {
985
49
    char c = symbol[0];
986
987
    /* Check that we don't remove for targets with empty
988
       USER_LABEL_PREFIX the leading underscore.  */
989
49
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
990
42
        || c == '@' || c == '?')
991
23
      symbol++;
992
49
  }
993
994
81
      len = strlen (symbol);
995
81
      if (import_name_type == IMPORT_NAME_UNDECORATE)
996
27
  {
997
    /* Truncate at the first '@'.  */
998
27
    char *at = strchr (symbol, '@');
999
1000
27
    if (at != NULL)
1001
6
      len = at - symbol;
1002
27
  }
1003
1004
81
      id6->contents[0] = ordinal & 0xff;
1005
81
      id6->contents[1] = ordinal >> 8;
1006
1007
81
      memcpy ((char *) id6->contents + 2, symbol, len);
1008
81
      id6->contents[len + 2] = '\0';
1009
81
    }
1010
1011
104
  if (import_name_type != IMPORT_ORDINAL)
1012
81
    {
1013
81
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1014
81
      pe_ILF_save_relocs (&vars, id4);
1015
1016
81
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1017
81
      pe_ILF_save_relocs (&vars, id5);
1018
81
    }
1019
1020
  /* Create an import symbol.  */
1021
104
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1022
104
  imp_sym   = vars.sym_ptr_ptr - 1;
1023
104
  imp_index = vars.sym_index - 1;
1024
1025
  /* Create extra sections depending upon the type of import we are
1026
     dealing with.  */
1027
104
  switch (import_type)
1028
104
    {
1029
0
      int i;
1030
1031
57
    case IMPORT_CODE:
1032
      /* CODE functions are special, in that they get a trampoline that
1033
   jumps to the main import symbol.  Create a .text section to hold it.
1034
   First we need to look up its contents in the jump table.  */
1035
114
      for (i = NUM_ENTRIES (jtab); i--;)
1036
114
  {
1037
114
    if (jtab[i].size == 0)
1038
57
      continue;
1039
57
    if (jtab[i].magic == magic)
1040
57
      break;
1041
57
  }
1042
      /* If we did not find a matching entry something is wrong.  */
1043
57
      if (i < 0)
1044
0
  abort ();
1045
1046
      /* Create the .text section.  */
1047
57
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1048
57
      if (text == NULL)
1049
0
  goto error_return;
1050
1051
      /* Copy in the jump code.  */
1052
57
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1053
1054
      /* Create a reloc for the data in the text section.  */
1055
#ifdef MIPS_ARCH_MAGIC_WINCE
1056
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1057
  {
1058
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1059
              (struct bfd_symbol **) imp_sym,
1060
              imp_index);
1061
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1062
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1063
              (struct bfd_symbol **) imp_sym,
1064
              imp_index);
1065
  }
1066
      else
1067
#endif
1068
#ifdef AMD64MAGIC
1069
      if (magic == AMD64MAGIC)
1070
  {
1071
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1072
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1073
              imp_index);
1074
  }
1075
      else
1076
#endif
1077
57
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1078
57
            BFD_RELOC_32, (asymbol **) imp_sym,
1079
57
            imp_index);
1080
1081
57
      pe_ILF_save_relocs (&vars, text);
1082
57
      break;
1083
1084
17
    case IMPORT_DATA:
1085
47
    case IMPORT_CONST:
1086
47
      break;
1087
1088
0
    default:
1089
      /* XXX code not yet written.  */
1090
0
      abort ();
1091
104
    }
1092
1093
  /* Now create a symbol describing the imported value.  */
1094
104
  switch (import_type)
1095
104
    {
1096
57
    case IMPORT_CODE:
1097
57
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1098
57
          BSF_NOT_AT_END | BSF_FUNCTION);
1099
1100
57
      break;
1101
1102
17
    case IMPORT_DATA:
1103
      /* Nothing to do here.  */
1104
17
      break;
1105
1106
30
    case IMPORT_CONST:
1107
30
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1108
30
      break;
1109
1110
0
    default:
1111
      /* XXX code not yet written.  */
1112
0
      abort ();
1113
104
    }
1114
1115
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1116
104
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1117
104
  if (ptr)
1118
16
    *ptr = 0;
1119
104
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1120
104
  if (ptr)
1121
16
    *ptr = '.';
1122
1123
  /* Initialise the bfd.  */
1124
104
  memset (&internal_f, 0, sizeof (internal_f));
1125
1126
104
  internal_f.f_magic  = magic;
1127
104
  internal_f.f_symptr = 0;
1128
104
  internal_f.f_nsyms  = 0;
1129
104
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1130
1131
104
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1132
104
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1133
0
    goto error_return;
1134
1135
104
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1136
0
    goto error_return;
1137
1138
104
  obj_pe (abfd) = true;
1139
#ifdef THUMBPEMAGIC
1140
  if (vars.magic == THUMBPEMAGIC)
1141
    /* Stop some linker warnings about thumb code not supporting
1142
       interworking.  */
1143
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1144
#endif
1145
1146
  /* Switch from file contents to memory contents.  */
1147
104
  bfd_cache_close (abfd);
1148
1149
104
  abfd->iostream = (void *) vars.bim;
1150
104
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1151
104
  abfd->iovec = &_bfd_memory_iovec;
1152
104
  abfd->where = 0;
1153
104
  abfd->origin = 0;
1154
104
  abfd->size = 0;
1155
104
  obj_sym_filepos (abfd) = 0;
1156
1157
  /* Point the bfd at the symbol table.  */
1158
104
  obj_symbols (abfd) = vars.sym_cache;
1159
104
  abfd->symcount = vars.sym_index;
1160
1161
104
  obj_raw_syments (abfd) = vars.native_syms;
1162
104
  obj_raw_syment_count (abfd) = vars.sym_index;
1163
104
  obj_coff_keep_raw_syms (abfd) = true;
1164
1165
104
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1166
104
  obj_coff_keep_syms (abfd) = true;
1167
1168
104
  obj_convert (abfd) = vars.sym_table;
1169
104
  obj_conv_table_size (abfd) = vars.sym_index;
1170
1171
104
  obj_coff_strings (abfd) = vars.string_table;
1172
104
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1173
104
  obj_coff_keep_strings (abfd) = true;
1174
1175
104
  return true;
1176
1177
6
 error_return:
1178
6
  free (vars.bim->buffer);
1179
6
  free (vars.bim);
1180
  return false;
1181
104
}
pei-x86_64.c:pe_ILF_build_a_bfd
Line
Count
Source
805
158
{
806
158
  bfd_byte *       ptr;
807
158
  pe_ILF_vars      vars;
808
158
  struct internal_filehdr  internal_f;
809
158
  unsigned int       import_type;
810
158
  unsigned int       import_name_type;
811
158
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
812
158
  coff_symbol_type **    imp_sym;
813
158
  unsigned int       imp_index;
814
158
  intptr_t alignment;
815
816
  /* Decode and verify the types field of the ILF structure.  */
817
158
  import_type = types & 0x3;
818
158
  import_name_type = (types & 0x1c) >> 2;
819
820
158
  switch (import_type)
821
158
    {
822
57
    case IMPORT_CODE:
823
94
    case IMPORT_DATA:
824
150
    case IMPORT_CONST:
825
150
      break;
826
827
8
    default:
828
      /* xgettext:c-format */
829
8
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
830
8
        abfd, import_type);
831
8
      return false;
832
158
    }
833
834
150
  switch (import_name_type)
835
150
    {
836
34
    case IMPORT_ORDINAL:
837
48
    case IMPORT_NAME:
838
69
    case IMPORT_NAME_NOPREFIX:
839
115
    case IMPORT_NAME_UNDECORATE:
840
115
      import_name = symbol_name;
841
115
      break;
842
843
28
    case IMPORT_NAME_EXPORTAS:
844
28
      if (!import_name || !import_name[0])
845
16
  {
846
16
    _bfd_error_handler (_("%pB: missing import name for "
847
16
        "IMPORT_NAME_EXPORTAS for %s"),
848
16
            abfd, symbol_name);
849
16
    return false;
850
16
  }
851
12
      break;
852
853
12
    default:
854
      /* xgettext:c-format */
855
7
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
856
7
        abfd, import_name_type);
857
7
      return false;
858
150
    }
859
860
  /* Initialise local variables.
861
862
     Note these are kept in a structure rather than being
863
     declared as statics since bfd frowns on global variables.
864
865
     We are going to construct the contents of the BFD in memory,
866
     so allocate all the space that we will need right now.  */
867
127
  vars.bim
868
127
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
869
127
  if (vars.bim == NULL)
870
0
    return false;
871
872
127
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
873
127
  vars.bim->buffer = ptr;
874
127
  vars.bim->size   = ILF_DATA_SIZE;
875
127
  if (ptr == NULL)
876
0
    goto error_return;
877
878
  /* Initialise the pointers to regions of the memory and the
879
     other contents of the pe_ILF_vars structure as well.  */
880
127
  vars.sym_cache = (coff_symbol_type *) ptr;
881
127
  vars.sym_ptr   = (coff_symbol_type *) ptr;
882
127
  vars.sym_index = 0;
883
127
  ptr += SIZEOF_ILF_SYMS;
884
885
127
  vars.sym_table = (unsigned int *) ptr;
886
127
  vars.table_ptr = (unsigned int *) ptr;
887
127
  ptr += SIZEOF_ILF_SYM_TABLE;
888
889
127
  vars.native_syms = (combined_entry_type *) ptr;
890
127
  vars.native_ptr  = (combined_entry_type *) ptr;
891
127
  ptr += SIZEOF_ILF_NATIVE_SYMS;
892
893
127
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
894
127
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
895
127
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
896
897
127
  vars.esym_table = (SYMENT *) ptr;
898
127
  vars.esym_ptr   = (SYMENT *) ptr;
899
127
  ptr += SIZEOF_ILF_EXT_SYMS;
900
901
127
  vars.reltab   = (arelent *) ptr;
902
127
  vars.relcount = 0;
903
127
  ptr += SIZEOF_ILF_RELOCS;
904
905
127
  vars.int_reltab  = (struct internal_reloc *) ptr;
906
127
  ptr += SIZEOF_ILF_INT_RELOCS;
907
908
127
  vars.string_table = (char *) ptr;
909
127
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
910
127
  ptr += SIZEOF_ILF_STRINGS;
911
127
  vars.end_string_ptr = (char *) ptr;
912
913
  /* The remaining space in bim->buffer is used
914
     by the pe_ILF_make_a_section() function.  */
915
916
  /* PR 18758: Make sure that the data area is sufficiently aligned for
917
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
918
     the test of GCC_VERSION.  For other compilers we assume 8 byte
919
     alignment.  */
920
127
#if GCC_VERSION >= 3000
921
127
  alignment = __alignof__ (struct coff_section_tdata);
922
#else
923
  alignment = 8;
924
#endif
925
127
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
926
927
127
  vars.data = ptr;
928
127
  vars.abfd = abfd;
929
127
  vars.sec_index = 0;
930
127
  vars.magic = magic;
931
932
  /* Create the initial .idata$<n> sections:
933
     [.idata$2:  Import Directory Table -- not needed]
934
     .idata$4:  Import Lookup Table
935
     .idata$5:  Import Address Table
936
937
     Note we do not create a .idata$3 section as this is
938
     created for us by the linker script.  */
939
127
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
940
127
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
941
127
  if (id4 == NULL || id5 == NULL)
942
0
    goto error_return;
943
944
  /* Fill in the contents of these sections.  */
945
127
  if (import_name_type == IMPORT_ORDINAL)
946
34
    {
947
34
      if (ordinal == 0)
948
  /* See PR 20907 for a reproducer.  */
949
7
  goto error_return;
950
951
27
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
952
27
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
953
27
      ((unsigned int *) id4->contents)[0] = ordinal;
954
27
      ((unsigned int *) id4->contents)[1] = 0x80000000;
955
27
      ((unsigned int *) id5->contents)[0] = ordinal;
956
27
      ((unsigned int *) id5->contents)[1] = 0x80000000;
957
#else
958
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
959
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
960
#endif
961
27
    }
962
93
  else
963
93
    {
964
93
      char *symbol;
965
93
      unsigned int len;
966
967
      /* Create .idata$6 - the Hint Name Table.  */
968
93
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
969
93
      if (id6 == NULL)
970
0
  goto error_return;
971
972
      /* If necessary, trim the import symbol name.  */
973
93
      symbol = import_name;
974
975
      /* As used by MS compiler, '_', '@', and '?' are alternative
976
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
977
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
978
   of these is used for a symbol.  We strip this leading char for
979
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
980
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
981
982
93
      if (import_name_type != IMPORT_NAME
983
79
    && import_name_type != IMPORT_NAME_EXPORTAS)
984
67
  {
985
67
    char c = symbol[0];
986
987
    /* Check that we don't remove for targets with empty
988
       USER_LABEL_PREFIX the leading underscore.  */
989
67
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
990
67
        || c == '@' || c == '?')
991
18
      symbol++;
992
67
  }
993
994
93
      len = strlen (symbol);
995
93
      if (import_name_type == IMPORT_NAME_UNDECORATE)
996
46
  {
997
    /* Truncate at the first '@'.  */
998
46
    char *at = strchr (symbol, '@');
999
1000
46
    if (at != NULL)
1001
16
      len = at - symbol;
1002
46
  }
1003
1004
93
      id6->contents[0] = ordinal & 0xff;
1005
93
      id6->contents[1] = ordinal >> 8;
1006
1007
93
      memcpy ((char *) id6->contents + 2, symbol, len);
1008
93
      id6->contents[len + 2] = '\0';
1009
93
    }
1010
1011
120
  if (import_name_type != IMPORT_ORDINAL)
1012
93
    {
1013
93
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1014
93
      pe_ILF_save_relocs (&vars, id4);
1015
1016
93
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1017
93
      pe_ILF_save_relocs (&vars, id5);
1018
93
    }
1019
1020
  /* Create an import symbol.  */
1021
120
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1022
120
  imp_sym   = vars.sym_ptr_ptr - 1;
1023
120
  imp_index = vars.sym_index - 1;
1024
1025
  /* Create extra sections depending upon the type of import we are
1026
     dealing with.  */
1027
120
  switch (import_type)
1028
120
    {
1029
0
      int i;
1030
1031
44
    case IMPORT_CODE:
1032
      /* CODE functions are special, in that they get a trampoline that
1033
   jumps to the main import symbol.  Create a .text section to hold it.
1034
   First we need to look up its contents in the jump table.  */
1035
88
      for (i = NUM_ENTRIES (jtab); i--;)
1036
88
  {
1037
88
    if (jtab[i].size == 0)
1038
44
      continue;
1039
44
    if (jtab[i].magic == magic)
1040
44
      break;
1041
44
  }
1042
      /* If we did not find a matching entry something is wrong.  */
1043
44
      if (i < 0)
1044
0
  abort ();
1045
1046
      /* Create the .text section.  */
1047
44
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1048
44
      if (text == NULL)
1049
0
  goto error_return;
1050
1051
      /* Copy in the jump code.  */
1052
44
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1053
1054
      /* Create a reloc for the data in the text section.  */
1055
#ifdef MIPS_ARCH_MAGIC_WINCE
1056
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1057
  {
1058
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1059
              (struct bfd_symbol **) imp_sym,
1060
              imp_index);
1061
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1062
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1063
              (struct bfd_symbol **) imp_sym,
1064
              imp_index);
1065
  }
1066
      else
1067
#endif
1068
44
#ifdef AMD64MAGIC
1069
44
      if (magic == AMD64MAGIC)
1070
44
  {
1071
44
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1072
44
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1073
44
              imp_index);
1074
44
  }
1075
0
      else
1076
0
#endif
1077
0
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1078
0
            BFD_RELOC_32, (asymbol **) imp_sym,
1079
0
            imp_index);
1080
1081
44
      pe_ILF_save_relocs (&vars, text);
1082
44
      break;
1083
1084
29
    case IMPORT_DATA:
1085
76
    case IMPORT_CONST:
1086
76
      break;
1087
1088
0
    default:
1089
      /* XXX code not yet written.  */
1090
0
      abort ();
1091
120
    }
1092
1093
  /* Now create a symbol describing the imported value.  */
1094
120
  switch (import_type)
1095
120
    {
1096
44
    case IMPORT_CODE:
1097
44
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1098
44
          BSF_NOT_AT_END | BSF_FUNCTION);
1099
1100
44
      break;
1101
1102
29
    case IMPORT_DATA:
1103
      /* Nothing to do here.  */
1104
29
      break;
1105
1106
47
    case IMPORT_CONST:
1107
47
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1108
47
      break;
1109
1110
0
    default:
1111
      /* XXX code not yet written.  */
1112
0
      abort ();
1113
120
    }
1114
1115
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1116
120
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1117
120
  if (ptr)
1118
22
    *ptr = 0;
1119
120
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1120
120
  if (ptr)
1121
22
    *ptr = '.';
1122
1123
  /* Initialise the bfd.  */
1124
120
  memset (&internal_f, 0, sizeof (internal_f));
1125
1126
120
  internal_f.f_magic  = magic;
1127
120
  internal_f.f_symptr = 0;
1128
120
  internal_f.f_nsyms  = 0;
1129
120
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1130
1131
120
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1132
120
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1133
0
    goto error_return;
1134
1135
120
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1136
0
    goto error_return;
1137
1138
120
  obj_pe (abfd) = true;
1139
#ifdef THUMBPEMAGIC
1140
  if (vars.magic == THUMBPEMAGIC)
1141
    /* Stop some linker warnings about thumb code not supporting
1142
       interworking.  */
1143
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1144
#endif
1145
1146
  /* Switch from file contents to memory contents.  */
1147
120
  bfd_cache_close (abfd);
1148
1149
120
  abfd->iostream = (void *) vars.bim;
1150
120
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1151
120
  abfd->iovec = &_bfd_memory_iovec;
1152
120
  abfd->where = 0;
1153
120
  abfd->origin = 0;
1154
120
  abfd->size = 0;
1155
120
  obj_sym_filepos (abfd) = 0;
1156
1157
  /* Point the bfd at the symbol table.  */
1158
120
  obj_symbols (abfd) = vars.sym_cache;
1159
120
  abfd->symcount = vars.sym_index;
1160
1161
120
  obj_raw_syments (abfd) = vars.native_syms;
1162
120
  obj_raw_syment_count (abfd) = vars.sym_index;
1163
120
  obj_coff_keep_raw_syms (abfd) = true;
1164
1165
120
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1166
120
  obj_coff_keep_syms (abfd) = true;
1167
1168
120
  obj_convert (abfd) = vars.sym_table;
1169
120
  obj_conv_table_size (abfd) = vars.sym_index;
1170
1171
120
  obj_coff_strings (abfd) = vars.string_table;
1172
120
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1173
120
  obj_coff_keep_strings (abfd) = true;
1174
1175
120
  return true;
1176
1177
7
 error_return:
1178
7
  free (vars.bim->buffer);
1179
7
  free (vars.bim);
1180
  return false;
1181
120
}
pei-aarch64.c:pe_ILF_build_a_bfd
Line
Count
Source
805
143
{
806
143
  bfd_byte *       ptr;
807
143
  pe_ILF_vars      vars;
808
143
  struct internal_filehdr  internal_f;
809
143
  unsigned int       import_type;
810
143
  unsigned int       import_name_type;
811
143
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
812
143
  coff_symbol_type **    imp_sym;
813
143
  unsigned int       imp_index;
814
143
  intptr_t alignment;
815
816
  /* Decode and verify the types field of the ILF structure.  */
817
143
  import_type = types & 0x3;
818
143
  import_name_type = (types & 0x1c) >> 2;
819
820
143
  switch (import_type)
821
143
    {
822
62
    case IMPORT_CODE:
823
107
    case IMPORT_DATA:
824
136
    case IMPORT_CONST:
825
136
      break;
826
827
7
    default:
828
      /* xgettext:c-format */
829
7
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
830
7
        abfd, import_type);
831
7
      return false;
832
143
    }
833
834
136
  switch (import_name_type)
835
136
    {
836
35
    case IMPORT_ORDINAL:
837
54
    case IMPORT_NAME:
838
74
    case IMPORT_NAME_NOPREFIX:
839
105
    case IMPORT_NAME_UNDECORATE:
840
105
      import_name = symbol_name;
841
105
      break;
842
843
24
    case IMPORT_NAME_EXPORTAS:
844
24
      if (!import_name || !import_name[0])
845
12
  {
846
12
    _bfd_error_handler (_("%pB: missing import name for "
847
12
        "IMPORT_NAME_EXPORTAS for %s"),
848
12
            abfd, symbol_name);
849
12
    return false;
850
12
  }
851
12
      break;
852
853
12
    default:
854
      /* xgettext:c-format */
855
7
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
856
7
        abfd, import_name_type);
857
7
      return false;
858
136
    }
859
860
  /* Initialise local variables.
861
862
     Note these are kept in a structure rather than being
863
     declared as statics since bfd frowns on global variables.
864
865
     We are going to construct the contents of the BFD in memory,
866
     so allocate all the space that we will need right now.  */
867
117
  vars.bim
868
117
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
869
117
  if (vars.bim == NULL)
870
0
    return false;
871
872
117
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
873
117
  vars.bim->buffer = ptr;
874
117
  vars.bim->size   = ILF_DATA_SIZE;
875
117
  if (ptr == NULL)
876
0
    goto error_return;
877
878
  /* Initialise the pointers to regions of the memory and the
879
     other contents of the pe_ILF_vars structure as well.  */
880
117
  vars.sym_cache = (coff_symbol_type *) ptr;
881
117
  vars.sym_ptr   = (coff_symbol_type *) ptr;
882
117
  vars.sym_index = 0;
883
117
  ptr += SIZEOF_ILF_SYMS;
884
885
117
  vars.sym_table = (unsigned int *) ptr;
886
117
  vars.table_ptr = (unsigned int *) ptr;
887
117
  ptr += SIZEOF_ILF_SYM_TABLE;
888
889
117
  vars.native_syms = (combined_entry_type *) ptr;
890
117
  vars.native_ptr  = (combined_entry_type *) ptr;
891
117
  ptr += SIZEOF_ILF_NATIVE_SYMS;
892
893
117
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
894
117
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
895
117
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
896
897
117
  vars.esym_table = (SYMENT *) ptr;
898
117
  vars.esym_ptr   = (SYMENT *) ptr;
899
117
  ptr += SIZEOF_ILF_EXT_SYMS;
900
901
117
  vars.reltab   = (arelent *) ptr;
902
117
  vars.relcount = 0;
903
117
  ptr += SIZEOF_ILF_RELOCS;
904
905
117
  vars.int_reltab  = (struct internal_reloc *) ptr;
906
117
  ptr += SIZEOF_ILF_INT_RELOCS;
907
908
117
  vars.string_table = (char *) ptr;
909
117
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
910
117
  ptr += SIZEOF_ILF_STRINGS;
911
117
  vars.end_string_ptr = (char *) ptr;
912
913
  /* The remaining space in bim->buffer is used
914
     by the pe_ILF_make_a_section() function.  */
915
916
  /* PR 18758: Make sure that the data area is sufficiently aligned for
917
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
918
     the test of GCC_VERSION.  For other compilers we assume 8 byte
919
     alignment.  */
920
117
#if GCC_VERSION >= 3000
921
117
  alignment = __alignof__ (struct coff_section_tdata);
922
#else
923
  alignment = 8;
924
#endif
925
117
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
926
927
117
  vars.data = ptr;
928
117
  vars.abfd = abfd;
929
117
  vars.sec_index = 0;
930
117
  vars.magic = magic;
931
932
  /* Create the initial .idata$<n> sections:
933
     [.idata$2:  Import Directory Table -- not needed]
934
     .idata$4:  Import Lookup Table
935
     .idata$5:  Import Address Table
936
937
     Note we do not create a .idata$3 section as this is
938
     created for us by the linker script.  */
939
117
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
940
117
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
941
117
  if (id4 == NULL || id5 == NULL)
942
0
    goto error_return;
943
944
  /* Fill in the contents of these sections.  */
945
117
  if (import_name_type == IMPORT_ORDINAL)
946
35
    {
947
35
      if (ordinal == 0)
948
  /* See PR 20907 for a reproducer.  */
949
8
  goto error_return;
950
951
27
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
952
27
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
953
27
      ((unsigned int *) id4->contents)[0] = ordinal;
954
27
      ((unsigned int *) id4->contents)[1] = 0x80000000;
955
27
      ((unsigned int *) id5->contents)[0] = ordinal;
956
27
      ((unsigned int *) id5->contents)[1] = 0x80000000;
957
#else
958
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
959
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
960
#endif
961
27
    }
962
82
  else
963
82
    {
964
82
      char *symbol;
965
82
      unsigned int len;
966
967
      /* Create .idata$6 - the Hint Name Table.  */
968
82
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
969
82
      if (id6 == NULL)
970
0
  goto error_return;
971
972
      /* If necessary, trim the import symbol name.  */
973
82
      symbol = import_name;
974
975
      /* As used by MS compiler, '_', '@', and '?' are alternative
976
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
977
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
978
   of these is used for a symbol.  We strip this leading char for
979
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
980
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
981
982
82
      if (import_name_type != IMPORT_NAME
983
63
    && import_name_type != IMPORT_NAME_EXPORTAS)
984
51
  {
985
51
    char c = symbol[0];
986
987
    /* Check that we don't remove for targets with empty
988
       USER_LABEL_PREFIX the leading underscore.  */
989
51
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
990
51
        || c == '@' || c == '?')
991
12
      symbol++;
992
51
  }
993
994
82
      len = strlen (symbol);
995
82
      if (import_name_type == IMPORT_NAME_UNDECORATE)
996
31
  {
997
    /* Truncate at the first '@'.  */
998
31
    char *at = strchr (symbol, '@');
999
1000
31
    if (at != NULL)
1001
5
      len = at - symbol;
1002
31
  }
1003
1004
82
      id6->contents[0] = ordinal & 0xff;
1005
82
      id6->contents[1] = ordinal >> 8;
1006
1007
82
      memcpy ((char *) id6->contents + 2, symbol, len);
1008
82
      id6->contents[len + 2] = '\0';
1009
82
    }
1010
1011
109
  if (import_name_type != IMPORT_ORDINAL)
1012
82
    {
1013
82
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1014
82
      pe_ILF_save_relocs (&vars, id4);
1015
1016
82
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1017
82
      pe_ILF_save_relocs (&vars, id5);
1018
82
    }
1019
1020
  /* Create an import symbol.  */
1021
109
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1022
109
  imp_sym   = vars.sym_ptr_ptr - 1;
1023
109
  imp_index = vars.sym_index - 1;
1024
1025
  /* Create extra sections depending upon the type of import we are
1026
     dealing with.  */
1027
109
  switch (import_type)
1028
109
    {
1029
0
      int i;
1030
1031
50
    case IMPORT_CODE:
1032
      /* CODE functions are special, in that they get a trampoline that
1033
   jumps to the main import symbol.  Create a .text section to hold it.
1034
   First we need to look up its contents in the jump table.  */
1035
100
      for (i = NUM_ENTRIES (jtab); i--;)
1036
100
  {
1037
100
    if (jtab[i].size == 0)
1038
50
      continue;
1039
50
    if (jtab[i].magic == magic)
1040
50
      break;
1041
50
  }
1042
      /* If we did not find a matching entry something is wrong.  */
1043
50
      if (i < 0)
1044
0
  abort ();
1045
1046
      /* Create the .text section.  */
1047
50
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1048
50
      if (text == NULL)
1049
0
  goto error_return;
1050
1051
      /* Copy in the jump code.  */
1052
50
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1053
1054
      /* Create a reloc for the data in the text section.  */
1055
#ifdef MIPS_ARCH_MAGIC_WINCE
1056
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1057
  {
1058
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1059
              (struct bfd_symbol **) imp_sym,
1060
              imp_index);
1061
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1062
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1063
              (struct bfd_symbol **) imp_sym,
1064
              imp_index);
1065
  }
1066
      else
1067
#endif
1068
#ifdef AMD64MAGIC
1069
      if (magic == AMD64MAGIC)
1070
  {
1071
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1072
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1073
              imp_index);
1074
  }
1075
      else
1076
#endif
1077
50
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1078
50
            BFD_RELOC_32, (asymbol **) imp_sym,
1079
50
            imp_index);
1080
1081
50
      pe_ILF_save_relocs (&vars, text);
1082
50
      break;
1083
1084
35
    case IMPORT_DATA:
1085
59
    case IMPORT_CONST:
1086
59
      break;
1087
1088
0
    default:
1089
      /* XXX code not yet written.  */
1090
0
      abort ();
1091
109
    }
1092
1093
  /* Now create a symbol describing the imported value.  */
1094
109
  switch (import_type)
1095
109
    {
1096
50
    case IMPORT_CODE:
1097
50
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1098
50
          BSF_NOT_AT_END | BSF_FUNCTION);
1099
1100
50
      break;
1101
1102
35
    case IMPORT_DATA:
1103
      /* Nothing to do here.  */
1104
35
      break;
1105
1106
24
    case IMPORT_CONST:
1107
24
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1108
24
      break;
1109
1110
0
    default:
1111
      /* XXX code not yet written.  */
1112
0
      abort ();
1113
109
    }
1114
1115
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1116
109
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1117
109
  if (ptr)
1118
18
    *ptr = 0;
1119
109
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1120
109
  if (ptr)
1121
18
    *ptr = '.';
1122
1123
  /* Initialise the bfd.  */
1124
109
  memset (&internal_f, 0, sizeof (internal_f));
1125
1126
109
  internal_f.f_magic  = magic;
1127
109
  internal_f.f_symptr = 0;
1128
109
  internal_f.f_nsyms  = 0;
1129
109
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1130
1131
109
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1132
109
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1133
0
    goto error_return;
1134
1135
109
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1136
0
    goto error_return;
1137
1138
109
  obj_pe (abfd) = true;
1139
#ifdef THUMBPEMAGIC
1140
  if (vars.magic == THUMBPEMAGIC)
1141
    /* Stop some linker warnings about thumb code not supporting
1142
       interworking.  */
1143
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1144
#endif
1145
1146
  /* Switch from file contents to memory contents.  */
1147
109
  bfd_cache_close (abfd);
1148
1149
109
  abfd->iostream = (void *) vars.bim;
1150
109
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1151
109
  abfd->iovec = &_bfd_memory_iovec;
1152
109
  abfd->where = 0;
1153
109
  abfd->origin = 0;
1154
109
  abfd->size = 0;
1155
109
  obj_sym_filepos (abfd) = 0;
1156
1157
  /* Point the bfd at the symbol table.  */
1158
109
  obj_symbols (abfd) = vars.sym_cache;
1159
109
  abfd->symcount = vars.sym_index;
1160
1161
109
  obj_raw_syments (abfd) = vars.native_syms;
1162
109
  obj_raw_syment_count (abfd) = vars.sym_index;
1163
109
  obj_coff_keep_raw_syms (abfd) = true;
1164
1165
109
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1166
109
  obj_coff_keep_syms (abfd) = true;
1167
1168
109
  obj_convert (abfd) = vars.sym_table;
1169
109
  obj_conv_table_size (abfd) = vars.sym_index;
1170
1171
109
  obj_coff_strings (abfd) = vars.string_table;
1172
109
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1173
109
  obj_coff_keep_strings (abfd) = true;
1174
1175
109
  return true;
1176
1177
8
 error_return:
1178
8
  free (vars.bim->buffer);
1179
8
  free (vars.bim);
1180
  return false;
1181
109
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_build_a_bfd
pei-loongarch64.c:pe_ILF_build_a_bfd
Line
Count
Source
805
139
{
806
139
  bfd_byte *       ptr;
807
139
  pe_ILF_vars      vars;
808
139
  struct internal_filehdr  internal_f;
809
139
  unsigned int       import_type;
810
139
  unsigned int       import_name_type;
811
139
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
812
139
  coff_symbol_type **    imp_sym;
813
139
  unsigned int       imp_index;
814
139
  intptr_t alignment;
815
816
  /* Decode and verify the types field of the ILF structure.  */
817
139
  import_type = types & 0x3;
818
139
  import_name_type = (types & 0x1c) >> 2;
819
820
139
  switch (import_type)
821
139
    {
822
66
    case IMPORT_CODE:
823
114
    case IMPORT_DATA:
824
132
    case IMPORT_CONST:
825
132
      break;
826
827
7
    default:
828
      /* xgettext:c-format */
829
7
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
830
7
        abfd, import_type);
831
7
      return false;
832
139
    }
833
834
132
  switch (import_name_type)
835
132
    {
836
29
    case IMPORT_ORDINAL:
837
43
    case IMPORT_NAME:
838
60
    case IMPORT_NAME_NOPREFIX:
839
103
    case IMPORT_NAME_UNDECORATE:
840
103
      import_name = symbol_name;
841
103
      break;
842
843
22
    case IMPORT_NAME_EXPORTAS:
844
22
      if (!import_name || !import_name[0])
845
13
  {
846
13
    _bfd_error_handler (_("%pB: missing import name for "
847
13
        "IMPORT_NAME_EXPORTAS for %s"),
848
13
            abfd, symbol_name);
849
13
    return false;
850
13
  }
851
9
      break;
852
853
9
    default:
854
      /* xgettext:c-format */
855
7
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
856
7
        abfd, import_name_type);
857
7
      return false;
858
132
    }
859
860
  /* Initialise local variables.
861
862
     Note these are kept in a structure rather than being
863
     declared as statics since bfd frowns on global variables.
864
865
     We are going to construct the contents of the BFD in memory,
866
     so allocate all the space that we will need right now.  */
867
112
  vars.bim
868
112
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
869
112
  if (vars.bim == NULL)
870
0
    return false;
871
872
112
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
873
112
  vars.bim->buffer = ptr;
874
112
  vars.bim->size   = ILF_DATA_SIZE;
875
112
  if (ptr == NULL)
876
0
    goto error_return;
877
878
  /* Initialise the pointers to regions of the memory and the
879
     other contents of the pe_ILF_vars structure as well.  */
880
112
  vars.sym_cache = (coff_symbol_type *) ptr;
881
112
  vars.sym_ptr   = (coff_symbol_type *) ptr;
882
112
  vars.sym_index = 0;
883
112
  ptr += SIZEOF_ILF_SYMS;
884
885
112
  vars.sym_table = (unsigned int *) ptr;
886
112
  vars.table_ptr = (unsigned int *) ptr;
887
112
  ptr += SIZEOF_ILF_SYM_TABLE;
888
889
112
  vars.native_syms = (combined_entry_type *) ptr;
890
112
  vars.native_ptr  = (combined_entry_type *) ptr;
891
112
  ptr += SIZEOF_ILF_NATIVE_SYMS;
892
893
112
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
894
112
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
895
112
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
896
897
112
  vars.esym_table = (SYMENT *) ptr;
898
112
  vars.esym_ptr   = (SYMENT *) ptr;
899
112
  ptr += SIZEOF_ILF_EXT_SYMS;
900
901
112
  vars.reltab   = (arelent *) ptr;
902
112
  vars.relcount = 0;
903
112
  ptr += SIZEOF_ILF_RELOCS;
904
905
112
  vars.int_reltab  = (struct internal_reloc *) ptr;
906
112
  ptr += SIZEOF_ILF_INT_RELOCS;
907
908
112
  vars.string_table = (char *) ptr;
909
112
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
910
112
  ptr += SIZEOF_ILF_STRINGS;
911
112
  vars.end_string_ptr = (char *) ptr;
912
913
  /* The remaining space in bim->buffer is used
914
     by the pe_ILF_make_a_section() function.  */
915
916
  /* PR 18758: Make sure that the data area is sufficiently aligned for
917
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
918
     the test of GCC_VERSION.  For other compilers we assume 8 byte
919
     alignment.  */
920
112
#if GCC_VERSION >= 3000
921
112
  alignment = __alignof__ (struct coff_section_tdata);
922
#else
923
  alignment = 8;
924
#endif
925
112
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
926
927
112
  vars.data = ptr;
928
112
  vars.abfd = abfd;
929
112
  vars.sec_index = 0;
930
112
  vars.magic = magic;
931
932
  /* Create the initial .idata$<n> sections:
933
     [.idata$2:  Import Directory Table -- not needed]
934
     .idata$4:  Import Lookup Table
935
     .idata$5:  Import Address Table
936
937
     Note we do not create a .idata$3 section as this is
938
     created for us by the linker script.  */
939
112
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
940
112
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
941
112
  if (id4 == NULL || id5 == NULL)
942
0
    goto error_return;
943
944
  /* Fill in the contents of these sections.  */
945
112
  if (import_name_type == IMPORT_ORDINAL)
946
29
    {
947
29
      if (ordinal == 0)
948
  /* See PR 20907 for a reproducer.  */
949
7
  goto error_return;
950
951
22
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
952
22
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
953
22
      ((unsigned int *) id4->contents)[0] = ordinal;
954
22
      ((unsigned int *) id4->contents)[1] = 0x80000000;
955
22
      ((unsigned int *) id5->contents)[0] = ordinal;
956
22
      ((unsigned int *) id5->contents)[1] = 0x80000000;
957
#else
958
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
959
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
960
#endif
961
22
    }
962
83
  else
963
83
    {
964
83
      char *symbol;
965
83
      unsigned int len;
966
967
      /* Create .idata$6 - the Hint Name Table.  */
968
83
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
969
83
      if (id6 == NULL)
970
0
  goto error_return;
971
972
      /* If necessary, trim the import symbol name.  */
973
83
      symbol = import_name;
974
975
      /* As used by MS compiler, '_', '@', and '?' are alternative
976
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
977
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
978
   of these is used for a symbol.  We strip this leading char for
979
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
980
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
981
982
83
      if (import_name_type != IMPORT_NAME
983
69
    && import_name_type != IMPORT_NAME_EXPORTAS)
984
60
  {
985
60
    char c = symbol[0];
986
987
    /* Check that we don't remove for targets with empty
988
       USER_LABEL_PREFIX the leading underscore.  */
989
60
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
990
60
        || c == '@' || c == '?')
991
15
      symbol++;
992
60
  }
993
994
83
      len = strlen (symbol);
995
83
      if (import_name_type == IMPORT_NAME_UNDECORATE)
996
43
  {
997
    /* Truncate at the first '@'.  */
998
43
    char *at = strchr (symbol, '@');
999
1000
43
    if (at != NULL)
1001
8
      len = at - symbol;
1002
43
  }
1003
1004
83
      id6->contents[0] = ordinal & 0xff;
1005
83
      id6->contents[1] = ordinal >> 8;
1006
1007
83
      memcpy ((char *) id6->contents + 2, symbol, len);
1008
83
      id6->contents[len + 2] = '\0';
1009
83
    }
1010
1011
105
  if (import_name_type != IMPORT_ORDINAL)
1012
83
    {
1013
83
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1014
83
      pe_ILF_save_relocs (&vars, id4);
1015
1016
83
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1017
83
      pe_ILF_save_relocs (&vars, id5);
1018
83
    }
1019
1020
  /* Create an import symbol.  */
1021
105
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1022
105
  imp_sym   = vars.sym_ptr_ptr - 1;
1023
105
  imp_index = vars.sym_index - 1;
1024
1025
  /* Create extra sections depending upon the type of import we are
1026
     dealing with.  */
1027
105
  switch (import_type)
1028
105
    {
1029
0
      int i;
1030
1031
51
    case IMPORT_CODE:
1032
      /* CODE functions are special, in that they get a trampoline that
1033
   jumps to the main import symbol.  Create a .text section to hold it.
1034
   First we need to look up its contents in the jump table.  */
1035
102
      for (i = NUM_ENTRIES (jtab); i--;)
1036
102
  {
1037
102
    if (jtab[i].size == 0)
1038
51
      continue;
1039
51
    if (jtab[i].magic == magic)
1040
51
      break;
1041
51
  }
1042
      /* If we did not find a matching entry something is wrong.  */
1043
51
      if (i < 0)
1044
0
  abort ();
1045
1046
      /* Create the .text section.  */
1047
51
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1048
51
      if (text == NULL)
1049
0
  goto error_return;
1050
1051
      /* Copy in the jump code.  */
1052
51
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1053
1054
      /* Create a reloc for the data in the text section.  */
1055
#ifdef MIPS_ARCH_MAGIC_WINCE
1056
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1057
  {
1058
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1059
              (struct bfd_symbol **) imp_sym,
1060
              imp_index);
1061
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1062
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1063
              (struct bfd_symbol **) imp_sym,
1064
              imp_index);
1065
  }
1066
      else
1067
#endif
1068
#ifdef AMD64MAGIC
1069
      if (magic == AMD64MAGIC)
1070
  {
1071
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1072
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1073
              imp_index);
1074
  }
1075
      else
1076
#endif
1077
51
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1078
51
            BFD_RELOC_32, (asymbol **) imp_sym,
1079
51
            imp_index);
1080
1081
51
      pe_ILF_save_relocs (&vars, text);
1082
51
      break;
1083
1084
42
    case IMPORT_DATA:
1085
54
    case IMPORT_CONST:
1086
54
      break;
1087
1088
0
    default:
1089
      /* XXX code not yet written.  */
1090
0
      abort ();
1091
105
    }
1092
1093
  /* Now create a symbol describing the imported value.  */
1094
105
  switch (import_type)
1095
105
    {
1096
51
    case IMPORT_CODE:
1097
51
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1098
51
          BSF_NOT_AT_END | BSF_FUNCTION);
1099
1100
51
      break;
1101
1102
42
    case IMPORT_DATA:
1103
      /* Nothing to do here.  */
1104
42
      break;
1105
1106
12
    case IMPORT_CONST:
1107
12
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1108
12
      break;
1109
1110
0
    default:
1111
      /* XXX code not yet written.  */
1112
0
      abort ();
1113
105
    }
1114
1115
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1116
105
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1117
105
  if (ptr)
1118
14
    *ptr = 0;
1119
105
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1120
105
  if (ptr)
1121
14
    *ptr = '.';
1122
1123
  /* Initialise the bfd.  */
1124
105
  memset (&internal_f, 0, sizeof (internal_f));
1125
1126
105
  internal_f.f_magic  = magic;
1127
105
  internal_f.f_symptr = 0;
1128
105
  internal_f.f_nsyms  = 0;
1129
105
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1130
1131
105
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1132
105
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1133
0
    goto error_return;
1134
1135
105
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1136
0
    goto error_return;
1137
1138
105
  obj_pe (abfd) = true;
1139
#ifdef THUMBPEMAGIC
1140
  if (vars.magic == THUMBPEMAGIC)
1141
    /* Stop some linker warnings about thumb code not supporting
1142
       interworking.  */
1143
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1144
#endif
1145
1146
  /* Switch from file contents to memory contents.  */
1147
105
  bfd_cache_close (abfd);
1148
1149
105
  abfd->iostream = (void *) vars.bim;
1150
105
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1151
105
  abfd->iovec = &_bfd_memory_iovec;
1152
105
  abfd->where = 0;
1153
105
  abfd->origin = 0;
1154
105
  abfd->size = 0;
1155
105
  obj_sym_filepos (abfd) = 0;
1156
1157
  /* Point the bfd at the symbol table.  */
1158
105
  obj_symbols (abfd) = vars.sym_cache;
1159
105
  abfd->symcount = vars.sym_index;
1160
1161
105
  obj_raw_syments (abfd) = vars.native_syms;
1162
105
  obj_raw_syment_count (abfd) = vars.sym_index;
1163
105
  obj_coff_keep_raw_syms (abfd) = true;
1164
1165
105
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1166
105
  obj_coff_keep_syms (abfd) = true;
1167
1168
105
  obj_convert (abfd) = vars.sym_table;
1169
105
  obj_conv_table_size (abfd) = vars.sym_index;
1170
1171
105
  obj_coff_strings (abfd) = vars.string_table;
1172
105
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1173
105
  obj_coff_keep_strings (abfd) = true;
1174
1175
105
  return true;
1176
1177
7
 error_return:
1178
7
  free (vars.bim->buffer);
1179
7
  free (vars.bim);
1180
  return false;
1181
105
}
pei-riscv64.c:pe_ILF_build_a_bfd
Line
Count
Source
805
149
{
806
149
  bfd_byte *       ptr;
807
149
  pe_ILF_vars      vars;
808
149
  struct internal_filehdr  internal_f;
809
149
  unsigned int       import_type;
810
149
  unsigned int       import_name_type;
811
149
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
812
149
  coff_symbol_type **    imp_sym;
813
149
  unsigned int       imp_index;
814
149
  intptr_t alignment;
815
816
  /* Decode and verify the types field of the ILF structure.  */
817
149
  import_type = types & 0x3;
818
149
  import_name_type = (types & 0x1c) >> 2;
819
820
149
  switch (import_type)
821
149
    {
822
58
    case IMPORT_CODE:
823
89
    case IMPORT_DATA:
824
142
    case IMPORT_CONST:
825
142
      break;
826
827
7
    default:
828
      /* xgettext:c-format */
829
7
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
830
7
        abfd, import_type);
831
7
      return false;
832
149
    }
833
834
142
  switch (import_name_type)
835
142
    {
836
33
    case IMPORT_ORDINAL:
837
45
    case IMPORT_NAME:
838
63
    case IMPORT_NAME_NOPREFIX:
839
107
    case IMPORT_NAME_UNDECORATE:
840
107
      import_name = symbol_name;
841
107
      break;
842
843
28
    case IMPORT_NAME_EXPORTAS:
844
28
      if (!import_name || !import_name[0])
845
14
  {
846
14
    _bfd_error_handler (_("%pB: missing import name for "
847
14
        "IMPORT_NAME_EXPORTAS for %s"),
848
14
            abfd, symbol_name);
849
14
    return false;
850
14
  }
851
14
      break;
852
853
14
    default:
854
      /* xgettext:c-format */
855
7
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
856
7
        abfd, import_name_type);
857
7
      return false;
858
142
    }
859
860
  /* Initialise local variables.
861
862
     Note these are kept in a structure rather than being
863
     declared as statics since bfd frowns on global variables.
864
865
     We are going to construct the contents of the BFD in memory,
866
     so allocate all the space that we will need right now.  */
867
121
  vars.bim
868
121
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
869
121
  if (vars.bim == NULL)
870
0
    return false;
871
872
121
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
873
121
  vars.bim->buffer = ptr;
874
121
  vars.bim->size   = ILF_DATA_SIZE;
875
121
  if (ptr == NULL)
876
0
    goto error_return;
877
878
  /* Initialise the pointers to regions of the memory and the
879
     other contents of the pe_ILF_vars structure as well.  */
880
121
  vars.sym_cache = (coff_symbol_type *) ptr;
881
121
  vars.sym_ptr   = (coff_symbol_type *) ptr;
882
121
  vars.sym_index = 0;
883
121
  ptr += SIZEOF_ILF_SYMS;
884
885
121
  vars.sym_table = (unsigned int *) ptr;
886
121
  vars.table_ptr = (unsigned int *) ptr;
887
121
  ptr += SIZEOF_ILF_SYM_TABLE;
888
889
121
  vars.native_syms = (combined_entry_type *) ptr;
890
121
  vars.native_ptr  = (combined_entry_type *) ptr;
891
121
  ptr += SIZEOF_ILF_NATIVE_SYMS;
892
893
121
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
894
121
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
895
121
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
896
897
121
  vars.esym_table = (SYMENT *) ptr;
898
121
  vars.esym_ptr   = (SYMENT *) ptr;
899
121
  ptr += SIZEOF_ILF_EXT_SYMS;
900
901
121
  vars.reltab   = (arelent *) ptr;
902
121
  vars.relcount = 0;
903
121
  ptr += SIZEOF_ILF_RELOCS;
904
905
121
  vars.int_reltab  = (struct internal_reloc *) ptr;
906
121
  ptr += SIZEOF_ILF_INT_RELOCS;
907
908
121
  vars.string_table = (char *) ptr;
909
121
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
910
121
  ptr += SIZEOF_ILF_STRINGS;
911
121
  vars.end_string_ptr = (char *) ptr;
912
913
  /* The remaining space in bim->buffer is used
914
     by the pe_ILF_make_a_section() function.  */
915
916
  /* PR 18758: Make sure that the data area is sufficiently aligned for
917
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
918
     the test of GCC_VERSION.  For other compilers we assume 8 byte
919
     alignment.  */
920
121
#if GCC_VERSION >= 3000
921
121
  alignment = __alignof__ (struct coff_section_tdata);
922
#else
923
  alignment = 8;
924
#endif
925
121
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
926
927
121
  vars.data = ptr;
928
121
  vars.abfd = abfd;
929
121
  vars.sec_index = 0;
930
121
  vars.magic = magic;
931
932
  /* Create the initial .idata$<n> sections:
933
     [.idata$2:  Import Directory Table -- not needed]
934
     .idata$4:  Import Lookup Table
935
     .idata$5:  Import Address Table
936
937
     Note we do not create a .idata$3 section as this is
938
     created for us by the linker script.  */
939
121
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
940
121
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
941
121
  if (id4 == NULL || id5 == NULL)
942
0
    goto error_return;
943
944
  /* Fill in the contents of these sections.  */
945
121
  if (import_name_type == IMPORT_ORDINAL)
946
33
    {
947
33
      if (ordinal == 0)
948
  /* See PR 20907 for a reproducer.  */
949
7
  goto error_return;
950
951
26
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
952
26
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
953
26
      ((unsigned int *) id4->contents)[0] = ordinal;
954
26
      ((unsigned int *) id4->contents)[1] = 0x80000000;
955
26
      ((unsigned int *) id5->contents)[0] = ordinal;
956
26
      ((unsigned int *) id5->contents)[1] = 0x80000000;
957
#else
958
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
959
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
960
#endif
961
26
    }
962
88
  else
963
88
    {
964
88
      char *symbol;
965
88
      unsigned int len;
966
967
      /* Create .idata$6 - the Hint Name Table.  */
968
88
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
969
88
      if (id6 == NULL)
970
0
  goto error_return;
971
972
      /* If necessary, trim the import symbol name.  */
973
88
      symbol = import_name;
974
975
      /* As used by MS compiler, '_', '@', and '?' are alternative
976
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
977
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
978
   of these is used for a symbol.  We strip this leading char for
979
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
980
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
981
982
88
      if (import_name_type != IMPORT_NAME
983
76
    && import_name_type != IMPORT_NAME_EXPORTAS)
984
62
  {
985
62
    char c = symbol[0];
986
987
    /* Check that we don't remove for targets with empty
988
       USER_LABEL_PREFIX the leading underscore.  */
989
62
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
990
62
        || c == '@' || c == '?')
991
20
      symbol++;
992
62
  }
993
994
88
      len = strlen (symbol);
995
88
      if (import_name_type == IMPORT_NAME_UNDECORATE)
996
44
  {
997
    /* Truncate at the first '@'.  */
998
44
    char *at = strchr (symbol, '@');
999
1000
44
    if (at != NULL)
1001
13
      len = at - symbol;
1002
44
  }
1003
1004
88
      id6->contents[0] = ordinal & 0xff;
1005
88
      id6->contents[1] = ordinal >> 8;
1006
1007
88
      memcpy ((char *) id6->contents + 2, symbol, len);
1008
88
      id6->contents[len + 2] = '\0';
1009
88
    }
1010
1011
114
  if (import_name_type != IMPORT_ORDINAL)
1012
88
    {
1013
88
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1014
88
      pe_ILF_save_relocs (&vars, id4);
1015
1016
88
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1017
88
      pe_ILF_save_relocs (&vars, id5);
1018
88
    }
1019
1020
  /* Create an import symbol.  */
1021
114
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1022
114
  imp_sym   = vars.sym_ptr_ptr - 1;
1023
114
  imp_index = vars.sym_index - 1;
1024
1025
  /* Create extra sections depending upon the type of import we are
1026
     dealing with.  */
1027
114
  switch (import_type)
1028
114
    {
1029
0
      int i;
1030
1031
41
    case IMPORT_CODE:
1032
      /* CODE functions are special, in that they get a trampoline that
1033
   jumps to the main import symbol.  Create a .text section to hold it.
1034
   First we need to look up its contents in the jump table.  */
1035
82
      for (i = NUM_ENTRIES (jtab); i--;)
1036
82
  {
1037
82
    if (jtab[i].size == 0)
1038
41
      continue;
1039
41
    if (jtab[i].magic == magic)
1040
41
      break;
1041
41
  }
1042
      /* If we did not find a matching entry something is wrong.  */
1043
41
      if (i < 0)
1044
0
  abort ();
1045
1046
      /* Create the .text section.  */
1047
41
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1048
41
      if (text == NULL)
1049
0
  goto error_return;
1050
1051
      /* Copy in the jump code.  */
1052
41
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1053
1054
      /* Create a reloc for the data in the text section.  */
1055
#ifdef MIPS_ARCH_MAGIC_WINCE
1056
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1057
  {
1058
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1059
              (struct bfd_symbol **) imp_sym,
1060
              imp_index);
1061
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1062
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1063
              (struct bfd_symbol **) imp_sym,
1064
              imp_index);
1065
  }
1066
      else
1067
#endif
1068
#ifdef AMD64MAGIC
1069
      if (magic == AMD64MAGIC)
1070
  {
1071
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1072
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1073
              imp_index);
1074
  }
1075
      else
1076
#endif
1077
41
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1078
41
            BFD_RELOC_32, (asymbol **) imp_sym,
1079
41
            imp_index);
1080
1081
41
      pe_ILF_save_relocs (&vars, text);
1082
41
      break;
1083
1084
27
    case IMPORT_DATA:
1085
73
    case IMPORT_CONST:
1086
73
      break;
1087
1088
0
    default:
1089
      /* XXX code not yet written.  */
1090
0
      abort ();
1091
114
    }
1092
1093
  /* Now create a symbol describing the imported value.  */
1094
114
  switch (import_type)
1095
114
    {
1096
41
    case IMPORT_CODE:
1097
41
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1098
41
          BSF_NOT_AT_END | BSF_FUNCTION);
1099
1100
41
      break;
1101
1102
27
    case IMPORT_DATA:
1103
      /* Nothing to do here.  */
1104
27
      break;
1105
1106
46
    case IMPORT_CONST:
1107
46
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1108
46
      break;
1109
1110
0
    default:
1111
      /* XXX code not yet written.  */
1112
0
      abort ();
1113
114
    }
1114
1115
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1116
114
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1117
114
  if (ptr)
1118
20
    *ptr = 0;
1119
114
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1120
114
  if (ptr)
1121
20
    *ptr = '.';
1122
1123
  /* Initialise the bfd.  */
1124
114
  memset (&internal_f, 0, sizeof (internal_f));
1125
1126
114
  internal_f.f_magic  = magic;
1127
114
  internal_f.f_symptr = 0;
1128
114
  internal_f.f_nsyms  = 0;
1129
114
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1130
1131
114
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1132
114
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1133
0
    goto error_return;
1134
1135
114
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1136
0
    goto error_return;
1137
1138
114
  obj_pe (abfd) = true;
1139
#ifdef THUMBPEMAGIC
1140
  if (vars.magic == THUMBPEMAGIC)
1141
    /* Stop some linker warnings about thumb code not supporting
1142
       interworking.  */
1143
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1144
#endif
1145
1146
  /* Switch from file contents to memory contents.  */
1147
114
  bfd_cache_close (abfd);
1148
1149
114
  abfd->iostream = (void *) vars.bim;
1150
114
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1151
114
  abfd->iovec = &_bfd_memory_iovec;
1152
114
  abfd->where = 0;
1153
114
  abfd->origin = 0;
1154
114
  abfd->size = 0;
1155
114
  obj_sym_filepos (abfd) = 0;
1156
1157
  /* Point the bfd at the symbol table.  */
1158
114
  obj_symbols (abfd) = vars.sym_cache;
1159
114
  abfd->symcount = vars.sym_index;
1160
1161
114
  obj_raw_syments (abfd) = vars.native_syms;
1162
114
  obj_raw_syment_count (abfd) = vars.sym_index;
1163
114
  obj_coff_keep_raw_syms (abfd) = true;
1164
1165
114
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1166
114
  obj_coff_keep_syms (abfd) = true;
1167
1168
114
  obj_convert (abfd) = vars.sym_table;
1169
114
  obj_conv_table_size (abfd) = vars.sym_index;
1170
1171
114
  obj_coff_strings (abfd) = vars.string_table;
1172
114
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1173
114
  obj_coff_keep_strings (abfd) = true;
1174
1175
114
  return true;
1176
1177
7
 error_return:
1178
7
  free (vars.bim->buffer);
1179
7
  free (vars.bim);
1180
  return false;
1181
114
}
pei-arm-wince.c:pe_ILF_build_a_bfd
Line
Count
Source
805
131
{
806
131
  bfd_byte *       ptr;
807
131
  pe_ILF_vars      vars;
808
131
  struct internal_filehdr  internal_f;
809
131
  unsigned int       import_type;
810
131
  unsigned int       import_name_type;
811
131
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
812
131
  coff_symbol_type **    imp_sym;
813
131
  unsigned int       imp_index;
814
131
  intptr_t alignment;
815
816
  /* Decode and verify the types field of the ILF structure.  */
817
131
  import_type = types & 0x3;
818
131
  import_name_type = (types & 0x1c) >> 2;
819
820
131
  switch (import_type)
821
131
    {
822
66
    case IMPORT_CODE:
823
103
    case IMPORT_DATA:
824
123
    case IMPORT_CONST:
825
123
      break;
826
827
8
    default:
828
      /* xgettext:c-format */
829
8
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
830
8
        abfd, import_type);
831
8
      return false;
832
131
    }
833
834
123
  switch (import_name_type)
835
123
    {
836
38
    case IMPORT_ORDINAL:
837
46
    case IMPORT_NAME:
838
64
    case IMPORT_NAME_NOPREFIX:
839
91
    case IMPORT_NAME_UNDECORATE:
840
91
      import_name = symbol_name;
841
91
      break;
842
843
24
    case IMPORT_NAME_EXPORTAS:
844
24
      if (!import_name || !import_name[0])
845
18
  {
846
18
    _bfd_error_handler (_("%pB: missing import name for "
847
18
        "IMPORT_NAME_EXPORTAS for %s"),
848
18
            abfd, symbol_name);
849
18
    return false;
850
18
  }
851
6
      break;
852
853
8
    default:
854
      /* xgettext:c-format */
855
8
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
856
8
        abfd, import_name_type);
857
8
      return false;
858
123
    }
859
860
  /* Initialise local variables.
861
862
     Note these are kept in a structure rather than being
863
     declared as statics since bfd frowns on global variables.
864
865
     We are going to construct the contents of the BFD in memory,
866
     so allocate all the space that we will need right now.  */
867
97
  vars.bim
868
97
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
869
97
  if (vars.bim == NULL)
870
0
    return false;
871
872
97
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
873
97
  vars.bim->buffer = ptr;
874
97
  vars.bim->size   = ILF_DATA_SIZE;
875
97
  if (ptr == NULL)
876
0
    goto error_return;
877
878
  /* Initialise the pointers to regions of the memory and the
879
     other contents of the pe_ILF_vars structure as well.  */
880
97
  vars.sym_cache = (coff_symbol_type *) ptr;
881
97
  vars.sym_ptr   = (coff_symbol_type *) ptr;
882
97
  vars.sym_index = 0;
883
97
  ptr += SIZEOF_ILF_SYMS;
884
885
97
  vars.sym_table = (unsigned int *) ptr;
886
97
  vars.table_ptr = (unsigned int *) ptr;
887
97
  ptr += SIZEOF_ILF_SYM_TABLE;
888
889
97
  vars.native_syms = (combined_entry_type *) ptr;
890
97
  vars.native_ptr  = (combined_entry_type *) ptr;
891
97
  ptr += SIZEOF_ILF_NATIVE_SYMS;
892
893
97
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
894
97
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
895
97
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
896
897
97
  vars.esym_table = (SYMENT *) ptr;
898
97
  vars.esym_ptr   = (SYMENT *) ptr;
899
97
  ptr += SIZEOF_ILF_EXT_SYMS;
900
901
97
  vars.reltab   = (arelent *) ptr;
902
97
  vars.relcount = 0;
903
97
  ptr += SIZEOF_ILF_RELOCS;
904
905
97
  vars.int_reltab  = (struct internal_reloc *) ptr;
906
97
  ptr += SIZEOF_ILF_INT_RELOCS;
907
908
97
  vars.string_table = (char *) ptr;
909
97
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
910
97
  ptr += SIZEOF_ILF_STRINGS;
911
97
  vars.end_string_ptr = (char *) ptr;
912
913
  /* The remaining space in bim->buffer is used
914
     by the pe_ILF_make_a_section() function.  */
915
916
  /* PR 18758: Make sure that the data area is sufficiently aligned for
917
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
918
     the test of GCC_VERSION.  For other compilers we assume 8 byte
919
     alignment.  */
920
97
#if GCC_VERSION >= 3000
921
97
  alignment = __alignof__ (struct coff_section_tdata);
922
#else
923
  alignment = 8;
924
#endif
925
97
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
926
927
97
  vars.data = ptr;
928
97
  vars.abfd = abfd;
929
97
  vars.sec_index = 0;
930
97
  vars.magic = magic;
931
932
  /* Create the initial .idata$<n> sections:
933
     [.idata$2:  Import Directory Table -- not needed]
934
     .idata$4:  Import Lookup Table
935
     .idata$5:  Import Address Table
936
937
     Note we do not create a .idata$3 section as this is
938
     created for us by the linker script.  */
939
97
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
940
97
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
941
97
  if (id4 == NULL || id5 == NULL)
942
0
    goto error_return;
943
944
  /* Fill in the contents of these sections.  */
945
97
  if (import_name_type == IMPORT_ORDINAL)
946
38
    {
947
38
      if (ordinal == 0)
948
  /* See PR 20907 for a reproducer.  */
949
11
  goto error_return;
950
951
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
952
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
953
      ((unsigned int *) id4->contents)[0] = ordinal;
954
      ((unsigned int *) id4->contents)[1] = 0x80000000;
955
      ((unsigned int *) id5->contents)[0] = ordinal;
956
      ((unsigned int *) id5->contents)[1] = 0x80000000;
957
#else
958
27
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
959
27
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
960
27
#endif
961
27
    }
962
59
  else
963
59
    {
964
59
      char *symbol;
965
59
      unsigned int len;
966
967
      /* Create .idata$6 - the Hint Name Table.  */
968
59
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
969
59
      if (id6 == NULL)
970
0
  goto error_return;
971
972
      /* If necessary, trim the import symbol name.  */
973
59
      symbol = import_name;
974
975
      /* As used by MS compiler, '_', '@', and '?' are alternative
976
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
977
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
978
   of these is used for a symbol.  We strip this leading char for
979
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
980
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
981
982
59
      if (import_name_type != IMPORT_NAME
983
51
    && import_name_type != IMPORT_NAME_EXPORTAS)
984
45
  {
985
45
    char c = symbol[0];
986
987
    /* Check that we don't remove for targets with empty
988
       USER_LABEL_PREFIX the leading underscore.  */
989
45
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
990
45
        || c == '@' || c == '?')
991
9
      symbol++;
992
45
  }
993
994
59
      len = strlen (symbol);
995
59
      if (import_name_type == IMPORT_NAME_UNDECORATE)
996
27
  {
997
    /* Truncate at the first '@'.  */
998
27
    char *at = strchr (symbol, '@');
999
1000
27
    if (at != NULL)
1001
6
      len = at - symbol;
1002
27
  }
1003
1004
59
      id6->contents[0] = ordinal & 0xff;
1005
59
      id6->contents[1] = ordinal >> 8;
1006
1007
59
      memcpy ((char *) id6->contents + 2, symbol, len);
1008
59
      id6->contents[len + 2] = '\0';
1009
59
    }
1010
1011
86
  if (import_name_type != IMPORT_ORDINAL)
1012
59
    {
1013
59
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1014
59
      pe_ILF_save_relocs (&vars, id4);
1015
1016
59
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1017
59
      pe_ILF_save_relocs (&vars, id5);
1018
59
    }
1019
1020
  /* Create an import symbol.  */
1021
86
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1022
86
  imp_sym   = vars.sym_ptr_ptr - 1;
1023
86
  imp_index = vars.sym_index - 1;
1024
1025
  /* Create extra sections depending upon the type of import we are
1026
     dealing with.  */
1027
86
  switch (import_type)
1028
86
    {
1029
0
      int i;
1030
1031
44
    case IMPORT_CODE:
1032
      /* CODE functions are special, in that they get a trampoline that
1033
   jumps to the main import symbol.  Create a .text section to hold it.
1034
   First we need to look up its contents in the jump table.  */
1035
108
      for (i = NUM_ENTRIES (jtab); i--;)
1036
108
  {
1037
108
    if (jtab[i].size == 0)
1038
44
      continue;
1039
64
    if (jtab[i].magic == magic)
1040
44
      break;
1041
64
  }
1042
      /* If we did not find a matching entry something is wrong.  */
1043
44
      if (i < 0)
1044
0
  abort ();
1045
1046
      /* Create the .text section.  */
1047
44
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1048
44
      if (text == NULL)
1049
0
  goto error_return;
1050
1051
      /* Copy in the jump code.  */
1052
44
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1053
1054
      /* Create a reloc for the data in the text section.  */
1055
#ifdef MIPS_ARCH_MAGIC_WINCE
1056
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1057
  {
1058
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1059
              (struct bfd_symbol **) imp_sym,
1060
              imp_index);
1061
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1062
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1063
              (struct bfd_symbol **) imp_sym,
1064
              imp_index);
1065
  }
1066
      else
1067
#endif
1068
#ifdef AMD64MAGIC
1069
      if (magic == AMD64MAGIC)
1070
  {
1071
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1072
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1073
              imp_index);
1074
  }
1075
      else
1076
#endif
1077
44
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1078
44
            BFD_RELOC_32, (asymbol **) imp_sym,
1079
44
            imp_index);
1080
1081
44
      pe_ILF_save_relocs (&vars, text);
1082
44
      break;
1083
1084
26
    case IMPORT_DATA:
1085
42
    case IMPORT_CONST:
1086
42
      break;
1087
1088
0
    default:
1089
      /* XXX code not yet written.  */
1090
0
      abort ();
1091
86
    }
1092
1093
  /* Now create a symbol describing the imported value.  */
1094
86
  switch (import_type)
1095
86
    {
1096
44
    case IMPORT_CODE:
1097
44
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1098
44
          BSF_NOT_AT_END | BSF_FUNCTION);
1099
1100
44
      break;
1101
1102
26
    case IMPORT_DATA:
1103
      /* Nothing to do here.  */
1104
26
      break;
1105
1106
16
    case IMPORT_CONST:
1107
16
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1108
16
      break;
1109
1110
0
    default:
1111
      /* XXX code not yet written.  */
1112
0
      abort ();
1113
86
    }
1114
1115
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1116
86
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1117
86
  if (ptr)
1118
7
    *ptr = 0;
1119
86
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1120
86
  if (ptr)
1121
7
    *ptr = '.';
1122
1123
  /* Initialise the bfd.  */
1124
86
  memset (&internal_f, 0, sizeof (internal_f));
1125
1126
86
  internal_f.f_magic  = magic;
1127
86
  internal_f.f_symptr = 0;
1128
86
  internal_f.f_nsyms  = 0;
1129
86
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1130
1131
86
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1132
86
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1133
0
    goto error_return;
1134
1135
86
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1136
0
    goto error_return;
1137
1138
86
  obj_pe (abfd) = true;
1139
86
#ifdef THUMBPEMAGIC
1140
86
  if (vars.magic == THUMBPEMAGIC)
1141
    /* Stop some linker warnings about thumb code not supporting
1142
       interworking.  */
1143
52
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1144
86
#endif
1145
1146
  /* Switch from file contents to memory contents.  */
1147
86
  bfd_cache_close (abfd);
1148
1149
86
  abfd->iostream = (void *) vars.bim;
1150
86
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1151
86
  abfd->iovec = &_bfd_memory_iovec;
1152
86
  abfd->where = 0;
1153
86
  abfd->origin = 0;
1154
86
  abfd->size = 0;
1155
86
  obj_sym_filepos (abfd) = 0;
1156
1157
  /* Point the bfd at the symbol table.  */
1158
86
  obj_symbols (abfd) = vars.sym_cache;
1159
86
  abfd->symcount = vars.sym_index;
1160
1161
86
  obj_raw_syments (abfd) = vars.native_syms;
1162
86
  obj_raw_syment_count (abfd) = vars.sym_index;
1163
86
  obj_coff_keep_raw_syms (abfd) = true;
1164
1165
86
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1166
86
  obj_coff_keep_syms (abfd) = true;
1167
1168
86
  obj_convert (abfd) = vars.sym_table;
1169
86
  obj_conv_table_size (abfd) = vars.sym_index;
1170
1171
86
  obj_coff_strings (abfd) = vars.string_table;
1172
86
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1173
86
  obj_coff_keep_strings (abfd) = true;
1174
1175
86
  return true;
1176
1177
11
 error_return:
1178
11
  free (vars.bim->buffer);
1179
11
  free (vars.bim);
1180
  return false;
1181
86
}
pei-arm.c:pe_ILF_build_a_bfd
Line
Count
Source
805
135
{
806
135
  bfd_byte *       ptr;
807
135
  pe_ILF_vars      vars;
808
135
  struct internal_filehdr  internal_f;
809
135
  unsigned int       import_type;
810
135
  unsigned int       import_name_type;
811
135
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
812
135
  coff_symbol_type **    imp_sym;
813
135
  unsigned int       imp_index;
814
135
  intptr_t alignment;
815
816
  /* Decode and verify the types field of the ILF structure.  */
817
135
  import_type = types & 0x3;
818
135
  import_name_type = (types & 0x1c) >> 2;
819
820
135
  switch (import_type)
821
135
    {
822
69
    case IMPORT_CODE:
823
106
    case IMPORT_DATA:
824
127
    case IMPORT_CONST:
825
127
      break;
826
827
8
    default:
828
      /* xgettext:c-format */
829
8
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
830
8
        abfd, import_type);
831
8
      return false;
832
135
    }
833
834
127
  switch (import_name_type)
835
127
    {
836
40
    case IMPORT_ORDINAL:
837
49
    case IMPORT_NAME:
838
68
    case IMPORT_NAME_NOPREFIX:
839
95
    case IMPORT_NAME_UNDECORATE:
840
95
      import_name = symbol_name;
841
95
      break;
842
843
24
    case IMPORT_NAME_EXPORTAS:
844
24
      if (!import_name || !import_name[0])
845
18
  {
846
18
    _bfd_error_handler (_("%pB: missing import name for "
847
18
        "IMPORT_NAME_EXPORTAS for %s"),
848
18
            abfd, symbol_name);
849
18
    return false;
850
18
  }
851
6
      break;
852
853
8
    default:
854
      /* xgettext:c-format */
855
8
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
856
8
        abfd, import_name_type);
857
8
      return false;
858
127
    }
859
860
  /* Initialise local variables.
861
862
     Note these are kept in a structure rather than being
863
     declared as statics since bfd frowns on global variables.
864
865
     We are going to construct the contents of the BFD in memory,
866
     so allocate all the space that we will need right now.  */
867
101
  vars.bim
868
101
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
869
101
  if (vars.bim == NULL)
870
0
    return false;
871
872
101
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
873
101
  vars.bim->buffer = ptr;
874
101
  vars.bim->size   = ILF_DATA_SIZE;
875
101
  if (ptr == NULL)
876
0
    goto error_return;
877
878
  /* Initialise the pointers to regions of the memory and the
879
     other contents of the pe_ILF_vars structure as well.  */
880
101
  vars.sym_cache = (coff_symbol_type *) ptr;
881
101
  vars.sym_ptr   = (coff_symbol_type *) ptr;
882
101
  vars.sym_index = 0;
883
101
  ptr += SIZEOF_ILF_SYMS;
884
885
101
  vars.sym_table = (unsigned int *) ptr;
886
101
  vars.table_ptr = (unsigned int *) ptr;
887
101
  ptr += SIZEOF_ILF_SYM_TABLE;
888
889
101
  vars.native_syms = (combined_entry_type *) ptr;
890
101
  vars.native_ptr  = (combined_entry_type *) ptr;
891
101
  ptr += SIZEOF_ILF_NATIVE_SYMS;
892
893
101
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
894
101
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
895
101
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
896
897
101
  vars.esym_table = (SYMENT *) ptr;
898
101
  vars.esym_ptr   = (SYMENT *) ptr;
899
101
  ptr += SIZEOF_ILF_EXT_SYMS;
900
901
101
  vars.reltab   = (arelent *) ptr;
902
101
  vars.relcount = 0;
903
101
  ptr += SIZEOF_ILF_RELOCS;
904
905
101
  vars.int_reltab  = (struct internal_reloc *) ptr;
906
101
  ptr += SIZEOF_ILF_INT_RELOCS;
907
908
101
  vars.string_table = (char *) ptr;
909
101
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
910
101
  ptr += SIZEOF_ILF_STRINGS;
911
101
  vars.end_string_ptr = (char *) ptr;
912
913
  /* The remaining space in bim->buffer is used
914
     by the pe_ILF_make_a_section() function.  */
915
916
  /* PR 18758: Make sure that the data area is sufficiently aligned for
917
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
918
     the test of GCC_VERSION.  For other compilers we assume 8 byte
919
     alignment.  */
920
101
#if GCC_VERSION >= 3000
921
101
  alignment = __alignof__ (struct coff_section_tdata);
922
#else
923
  alignment = 8;
924
#endif
925
101
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
926
927
101
  vars.data = ptr;
928
101
  vars.abfd = abfd;
929
101
  vars.sec_index = 0;
930
101
  vars.magic = magic;
931
932
  /* Create the initial .idata$<n> sections:
933
     [.idata$2:  Import Directory Table -- not needed]
934
     .idata$4:  Import Lookup Table
935
     .idata$5:  Import Address Table
936
937
     Note we do not create a .idata$3 section as this is
938
     created for us by the linker script.  */
939
101
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
940
101
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
941
101
  if (id4 == NULL || id5 == NULL)
942
0
    goto error_return;
943
944
  /* Fill in the contents of these sections.  */
945
101
  if (import_name_type == IMPORT_ORDINAL)
946
40
    {
947
40
      if (ordinal == 0)
948
  /* See PR 20907 for a reproducer.  */
949
11
  goto error_return;
950
951
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
952
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
953
      ((unsigned int *) id4->contents)[0] = ordinal;
954
      ((unsigned int *) id4->contents)[1] = 0x80000000;
955
      ((unsigned int *) id5->contents)[0] = ordinal;
956
      ((unsigned int *) id5->contents)[1] = 0x80000000;
957
#else
958
29
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
959
29
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
960
29
#endif
961
29
    }
962
61
  else
963
61
    {
964
61
      char *symbol;
965
61
      unsigned int len;
966
967
      /* Create .idata$6 - the Hint Name Table.  */
968
61
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
969
61
      if (id6 == NULL)
970
0
  goto error_return;
971
972
      /* If necessary, trim the import symbol name.  */
973
61
      symbol = import_name;
974
975
      /* As used by MS compiler, '_', '@', and '?' are alternative
976
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
977
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
978
   of these is used for a symbol.  We strip this leading char for
979
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
980
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
981
982
61
      if (import_name_type != IMPORT_NAME
983
52
    && import_name_type != IMPORT_NAME_EXPORTAS)
984
46
  {
985
46
    char c = symbol[0];
986
987
    /* Check that we don't remove for targets with empty
988
       USER_LABEL_PREFIX the leading underscore.  */
989
46
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
990
41
        || c == '@' || c == '?')
991
14
      symbol++;
992
46
  }
993
994
61
      len = strlen (symbol);
995
61
      if (import_name_type == IMPORT_NAME_UNDECORATE)
996
27
  {
997
    /* Truncate at the first '@'.  */
998
27
    char *at = strchr (symbol, '@');
999
1000
27
    if (at != NULL)
1001
6
      len = at - symbol;
1002
27
  }
1003
1004
61
      id6->contents[0] = ordinal & 0xff;
1005
61
      id6->contents[1] = ordinal >> 8;
1006
1007
61
      memcpy ((char *) id6->contents + 2, symbol, len);
1008
61
      id6->contents[len + 2] = '\0';
1009
61
    }
1010
1011
90
  if (import_name_type != IMPORT_ORDINAL)
1012
61
    {
1013
61
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1014
61
      pe_ILF_save_relocs (&vars, id4);
1015
1016
61
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1017
61
      pe_ILF_save_relocs (&vars, id5);
1018
61
    }
1019
1020
  /* Create an import symbol.  */
1021
90
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1022
90
  imp_sym   = vars.sym_ptr_ptr - 1;
1023
90
  imp_index = vars.sym_index - 1;
1024
1025
  /* Create extra sections depending upon the type of import we are
1026
     dealing with.  */
1027
90
  switch (import_type)
1028
90
    {
1029
0
      int i;
1030
1031
47
    case IMPORT_CODE:
1032
      /* CODE functions are special, in that they get a trampoline that
1033
   jumps to the main import symbol.  Create a .text section to hold it.
1034
   First we need to look up its contents in the jump table.  */
1035
117
      for (i = NUM_ENTRIES (jtab); i--;)
1036
117
  {
1037
117
    if (jtab[i].size == 0)
1038
47
      continue;
1039
70
    if (jtab[i].magic == magic)
1040
47
      break;
1041
70
  }
1042
      /* If we did not find a matching entry something is wrong.  */
1043
47
      if (i < 0)
1044
0
  abort ();
1045
1046
      /* Create the .text section.  */
1047
47
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1048
47
      if (text == NULL)
1049
0
  goto error_return;
1050
1051
      /* Copy in the jump code.  */
1052
47
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1053
1054
      /* Create a reloc for the data in the text section.  */
1055
#ifdef MIPS_ARCH_MAGIC_WINCE
1056
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1057
  {
1058
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1059
              (struct bfd_symbol **) imp_sym,
1060
              imp_index);
1061
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1062
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1063
              (struct bfd_symbol **) imp_sym,
1064
              imp_index);
1065
  }
1066
      else
1067
#endif
1068
#ifdef AMD64MAGIC
1069
      if (magic == AMD64MAGIC)
1070
  {
1071
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1072
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1073
              imp_index);
1074
  }
1075
      else
1076
#endif
1077
47
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1078
47
            BFD_RELOC_32, (asymbol **) imp_sym,
1079
47
            imp_index);
1080
1081
47
      pe_ILF_save_relocs (&vars, text);
1082
47
      break;
1083
1084
26
    case IMPORT_DATA:
1085
43
    case IMPORT_CONST:
1086
43
      break;
1087
1088
0
    default:
1089
      /* XXX code not yet written.  */
1090
0
      abort ();
1091
90
    }
1092
1093
  /* Now create a symbol describing the imported value.  */
1094
90
  switch (import_type)
1095
90
    {
1096
47
    case IMPORT_CODE:
1097
47
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1098
47
          BSF_NOT_AT_END | BSF_FUNCTION);
1099
1100
47
      break;
1101
1102
26
    case IMPORT_DATA:
1103
      /* Nothing to do here.  */
1104
26
      break;
1105
1106
17
    case IMPORT_CONST:
1107
17
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1108
17
      break;
1109
1110
0
    default:
1111
      /* XXX code not yet written.  */
1112
0
      abort ();
1113
90
    }
1114
1115
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1116
90
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1117
90
  if (ptr)
1118
7
    *ptr = 0;
1119
90
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1120
90
  if (ptr)
1121
7
    *ptr = '.';
1122
1123
  /* Initialise the bfd.  */
1124
90
  memset (&internal_f, 0, sizeof (internal_f));
1125
1126
90
  internal_f.f_magic  = magic;
1127
90
  internal_f.f_symptr = 0;
1128
90
  internal_f.f_nsyms  = 0;
1129
90
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1130
1131
90
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1132
90
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1133
0
    goto error_return;
1134
1135
90
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1136
0
    goto error_return;
1137
1138
90
  obj_pe (abfd) = true;
1139
90
#ifdef THUMBPEMAGIC
1140
90
  if (vars.magic == THUMBPEMAGIC)
1141
    /* Stop some linker warnings about thumb code not supporting
1142
       interworking.  */
1143
52
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1144
90
#endif
1145
1146
  /* Switch from file contents to memory contents.  */
1147
90
  bfd_cache_close (abfd);
1148
1149
90
  abfd->iostream = (void *) vars.bim;
1150
90
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1151
90
  abfd->iovec = &_bfd_memory_iovec;
1152
90
  abfd->where = 0;
1153
90
  abfd->origin = 0;
1154
90
  abfd->size = 0;
1155
90
  obj_sym_filepos (abfd) = 0;
1156
1157
  /* Point the bfd at the symbol table.  */
1158
90
  obj_symbols (abfd) = vars.sym_cache;
1159
90
  abfd->symcount = vars.sym_index;
1160
1161
90
  obj_raw_syments (abfd) = vars.native_syms;
1162
90
  obj_raw_syment_count (abfd) = vars.sym_index;
1163
90
  obj_coff_keep_raw_syms (abfd) = true;
1164
1165
90
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1166
90
  obj_coff_keep_syms (abfd) = true;
1167
1168
90
  obj_convert (abfd) = vars.sym_table;
1169
90
  obj_conv_table_size (abfd) = vars.sym_index;
1170
1171
90
  obj_coff_strings (abfd) = vars.string_table;
1172
90
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1173
90
  obj_coff_keep_strings (abfd) = true;
1174
1175
90
  return true;
1176
1177
11
 error_return:
1178
11
  free (vars.bim->buffer);
1179
11
  free (vars.bim);
1180
  return false;
1181
90
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_build_a_bfd
pei-sh.c:pe_ILF_build_a_bfd
Line
Count
Source
805
282
{
806
282
  bfd_byte *       ptr;
807
282
  pe_ILF_vars      vars;
808
282
  struct internal_filehdr  internal_f;
809
282
  unsigned int       import_type;
810
282
  unsigned int       import_name_type;
811
282
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
812
282
  coff_symbol_type **    imp_sym;
813
282
  unsigned int       imp_index;
814
282
  intptr_t alignment;
815
816
  /* Decode and verify the types field of the ILF structure.  */
817
282
  import_type = types & 0x3;
818
282
  import_name_type = (types & 0x1c) >> 2;
819
820
282
  switch (import_type)
821
282
    {
822
95
    case IMPORT_CODE:
823
160
    case IMPORT_DATA:
824
216
    case IMPORT_CONST:
825
216
      break;
826
827
66
    default:
828
      /* xgettext:c-format */
829
66
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
830
66
        abfd, import_type);
831
66
      return false;
832
282
    }
833
834
216
  switch (import_name_type)
835
216
    {
836
46
    case IMPORT_ORDINAL:
837
63
    case IMPORT_NAME:
838
88
    case IMPORT_NAME_NOPREFIX:
839
165
    case IMPORT_NAME_UNDECORATE:
840
165
      import_name = symbol_name;
841
165
      break;
842
843
43
    case IMPORT_NAME_EXPORTAS:
844
43
      if (!import_name || !import_name[0])
845
25
  {
846
25
    _bfd_error_handler (_("%pB: missing import name for "
847
25
        "IMPORT_NAME_EXPORTAS for %s"),
848
25
            abfd, symbol_name);
849
25
    return false;
850
25
  }
851
18
      break;
852
853
18
    default:
854
      /* xgettext:c-format */
855
8
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
856
8
        abfd, import_name_type);
857
8
      return false;
858
216
    }
859
860
  /* Initialise local variables.
861
862
     Note these are kept in a structure rather than being
863
     declared as statics since bfd frowns on global variables.
864
865
     We are going to construct the contents of the BFD in memory,
866
     so allocate all the space that we will need right now.  */
867
183
  vars.bim
868
183
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
869
183
  if (vars.bim == NULL)
870
0
    return false;
871
872
183
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
873
183
  vars.bim->buffer = ptr;
874
183
  vars.bim->size   = ILF_DATA_SIZE;
875
183
  if (ptr == NULL)
876
0
    goto error_return;
877
878
  /* Initialise the pointers to regions of the memory and the
879
     other contents of the pe_ILF_vars structure as well.  */
880
183
  vars.sym_cache = (coff_symbol_type *) ptr;
881
183
  vars.sym_ptr   = (coff_symbol_type *) ptr;
882
183
  vars.sym_index = 0;
883
183
  ptr += SIZEOF_ILF_SYMS;
884
885
183
  vars.sym_table = (unsigned int *) ptr;
886
183
  vars.table_ptr = (unsigned int *) ptr;
887
183
  ptr += SIZEOF_ILF_SYM_TABLE;
888
889
183
  vars.native_syms = (combined_entry_type *) ptr;
890
183
  vars.native_ptr  = (combined_entry_type *) ptr;
891
183
  ptr += SIZEOF_ILF_NATIVE_SYMS;
892
893
183
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
894
183
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
895
183
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
896
897
183
  vars.esym_table = (SYMENT *) ptr;
898
183
  vars.esym_ptr   = (SYMENT *) ptr;
899
183
  ptr += SIZEOF_ILF_EXT_SYMS;
900
901
183
  vars.reltab   = (arelent *) ptr;
902
183
  vars.relcount = 0;
903
183
  ptr += SIZEOF_ILF_RELOCS;
904
905
183
  vars.int_reltab  = (struct internal_reloc *) ptr;
906
183
  ptr += SIZEOF_ILF_INT_RELOCS;
907
908
183
  vars.string_table = (char *) ptr;
909
183
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
910
183
  ptr += SIZEOF_ILF_STRINGS;
911
183
  vars.end_string_ptr = (char *) ptr;
912
913
  /* The remaining space in bim->buffer is used
914
     by the pe_ILF_make_a_section() function.  */
915
916
  /* PR 18758: Make sure that the data area is sufficiently aligned for
917
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
918
     the test of GCC_VERSION.  For other compilers we assume 8 byte
919
     alignment.  */
920
183
#if GCC_VERSION >= 3000
921
183
  alignment = __alignof__ (struct coff_section_tdata);
922
#else
923
  alignment = 8;
924
#endif
925
183
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
926
927
183
  vars.data = ptr;
928
183
  vars.abfd = abfd;
929
183
  vars.sec_index = 0;
930
183
  vars.magic = magic;
931
932
  /* Create the initial .idata$<n> sections:
933
     [.idata$2:  Import Directory Table -- not needed]
934
     .idata$4:  Import Lookup Table
935
     .idata$5:  Import Address Table
936
937
     Note we do not create a .idata$3 section as this is
938
     created for us by the linker script.  */
939
183
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
940
183
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
941
183
  if (id4 == NULL || id5 == NULL)
942
0
    goto error_return;
943
944
  /* Fill in the contents of these sections.  */
945
183
  if (import_name_type == IMPORT_ORDINAL)
946
46
    {
947
46
      if (ordinal == 0)
948
  /* See PR 20907 for a reproducer.  */
949
11
  goto error_return;
950
951
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
952
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
953
      ((unsigned int *) id4->contents)[0] = ordinal;
954
      ((unsigned int *) id4->contents)[1] = 0x80000000;
955
      ((unsigned int *) id5->contents)[0] = ordinal;
956
      ((unsigned int *) id5->contents)[1] = 0x80000000;
957
#else
958
35
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
959
35
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
960
35
#endif
961
35
    }
962
137
  else
963
137
    {
964
137
      char *symbol;
965
137
      unsigned int len;
966
967
      /* Create .idata$6 - the Hint Name Table.  */
968
137
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
969
137
      if (id6 == NULL)
970
0
  goto error_return;
971
972
      /* If necessary, trim the import symbol name.  */
973
137
      symbol = import_name;
974
975
      /* As used by MS compiler, '_', '@', and '?' are alternative
976
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
977
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
978
   of these is used for a symbol.  We strip this leading char for
979
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
980
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
981
982
137
      if (import_name_type != IMPORT_NAME
983
120
    && import_name_type != IMPORT_NAME_EXPORTAS)
984
102
  {
985
102
    char c = symbol[0];
986
987
    /* Check that we don't remove for targets with empty
988
       USER_LABEL_PREFIX the leading underscore.  */
989
102
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
990
89
        || c == '@' || c == '?')
991
31
      symbol++;
992
102
  }
993
994
137
      len = strlen (symbol);
995
137
      if (import_name_type == IMPORT_NAME_UNDECORATE)
996
77
  {
997
    /* Truncate at the first '@'.  */
998
77
    char *at = strchr (symbol, '@');
999
1000
77
    if (at != NULL)
1001
13
      len = at - symbol;
1002
77
  }
1003
1004
137
      id6->contents[0] = ordinal & 0xff;
1005
137
      id6->contents[1] = ordinal >> 8;
1006
1007
137
      memcpy ((char *) id6->contents + 2, symbol, len);
1008
137
      id6->contents[len + 2] = '\0';
1009
137
    }
1010
1011
172
  if (import_name_type != IMPORT_ORDINAL)
1012
137
    {
1013
137
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1014
137
      pe_ILF_save_relocs (&vars, id4);
1015
1016
137
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1017
137
      pe_ILF_save_relocs (&vars, id5);
1018
137
    }
1019
1020
  /* Create an import symbol.  */
1021
172
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1022
172
  imp_sym   = vars.sym_ptr_ptr - 1;
1023
172
  imp_index = vars.sym_index - 1;
1024
1025
  /* Create extra sections depending upon the type of import we are
1026
     dealing with.  */
1027
172
  switch (import_type)
1028
172
    {
1029
0
      int i;
1030
1031
67
    case IMPORT_CODE:
1032
      /* CODE functions are special, in that they get a trampoline that
1033
   jumps to the main import symbol.  Create a .text section to hold it.
1034
   First we need to look up its contents in the jump table.  */
1035
134
      for (i = NUM_ENTRIES (jtab); i--;)
1036
134
  {
1037
134
    if (jtab[i].size == 0)
1038
67
      continue;
1039
67
    if (jtab[i].magic == magic)
1040
67
      break;
1041
67
  }
1042
      /* If we did not find a matching entry something is wrong.  */
1043
67
      if (i < 0)
1044
0
  abort ();
1045
1046
      /* Create the .text section.  */
1047
67
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1048
67
      if (text == NULL)
1049
0
  goto error_return;
1050
1051
      /* Copy in the jump code.  */
1052
67
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1053
1054
      /* Create a reloc for the data in the text section.  */
1055
#ifdef MIPS_ARCH_MAGIC_WINCE
1056
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1057
  {
1058
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1059
              (struct bfd_symbol **) imp_sym,
1060
              imp_index);
1061
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1062
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1063
              (struct bfd_symbol **) imp_sym,
1064
              imp_index);
1065
  }
1066
      else
1067
#endif
1068
#ifdef AMD64MAGIC
1069
      if (magic == AMD64MAGIC)
1070
  {
1071
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1072
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1073
              imp_index);
1074
  }
1075
      else
1076
#endif
1077
67
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1078
67
            BFD_RELOC_32, (asymbol **) imp_sym,
1079
67
            imp_index);
1080
1081
67
      pe_ILF_save_relocs (&vars, text);
1082
67
      break;
1083
1084
61
    case IMPORT_DATA:
1085
105
    case IMPORT_CONST:
1086
105
      break;
1087
1088
0
    default:
1089
      /* XXX code not yet written.  */
1090
0
      abort ();
1091
172
    }
1092
1093
  /* Now create a symbol describing the imported value.  */
1094
172
  switch (import_type)
1095
172
    {
1096
67
    case IMPORT_CODE:
1097
67
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1098
67
          BSF_NOT_AT_END | BSF_FUNCTION);
1099
1100
67
      break;
1101
1102
61
    case IMPORT_DATA:
1103
      /* Nothing to do here.  */
1104
61
      break;
1105
1106
44
    case IMPORT_CONST:
1107
44
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1108
44
      break;
1109
1110
0
    default:
1111
      /* XXX code not yet written.  */
1112
0
      abort ();
1113
172
    }
1114
1115
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1116
172
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1117
172
  if (ptr)
1118
17
    *ptr = 0;
1119
172
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1120
172
  if (ptr)
1121
17
    *ptr = '.';
1122
1123
  /* Initialise the bfd.  */
1124
172
  memset (&internal_f, 0, sizeof (internal_f));
1125
1126
172
  internal_f.f_magic  = magic;
1127
172
  internal_f.f_symptr = 0;
1128
172
  internal_f.f_nsyms  = 0;
1129
172
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1130
1131
172
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1132
172
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1133
0
    goto error_return;
1134
1135
172
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1136
0
    goto error_return;
1137
1138
172
  obj_pe (abfd) = true;
1139
#ifdef THUMBPEMAGIC
1140
  if (vars.magic == THUMBPEMAGIC)
1141
    /* Stop some linker warnings about thumb code not supporting
1142
       interworking.  */
1143
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1144
#endif
1145
1146
  /* Switch from file contents to memory contents.  */
1147
172
  bfd_cache_close (abfd);
1148
1149
172
  abfd->iostream = (void *) vars.bim;
1150
172
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1151
172
  abfd->iovec = &_bfd_memory_iovec;
1152
172
  abfd->where = 0;
1153
172
  abfd->origin = 0;
1154
172
  abfd->size = 0;
1155
172
  obj_sym_filepos (abfd) = 0;
1156
1157
  /* Point the bfd at the symbol table.  */
1158
172
  obj_symbols (abfd) = vars.sym_cache;
1159
172
  abfd->symcount = vars.sym_index;
1160
1161
172
  obj_raw_syments (abfd) = vars.native_syms;
1162
172
  obj_raw_syment_count (abfd) = vars.sym_index;
1163
172
  obj_coff_keep_raw_syms (abfd) = true;
1164
1165
172
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1166
172
  obj_coff_keep_syms (abfd) = true;
1167
1168
172
  obj_convert (abfd) = vars.sym_table;
1169
172
  obj_conv_table_size (abfd) = vars.sym_index;
1170
1171
172
  obj_coff_strings (abfd) = vars.string_table;
1172
172
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1173
172
  obj_coff_keep_strings (abfd) = true;
1174
1175
172
  return true;
1176
1177
11
 error_return:
1178
11
  free (vars.bim->buffer);
1179
11
  free (vars.bim);
1180
  return false;
1181
172
}
1182
1183
/* Cleanup function, returned from check_format hook.  */
1184
1185
static void
1186
pe_ILF_cleanup (bfd *abfd)
1187
72
{
1188
72
  coff_object_cleanup (abfd);
1189
1190
72
  struct bfd_in_memory *bim = abfd->iostream;
1191
72
  free (bim->buffer);
1192
72
  free (bim);
1193
72
  abfd->iostream = NULL;
1194
72
}
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
1187
36
{
1188
36
  coff_object_cleanup (abfd);
1189
1190
36
  struct bfd_in_memory *bim = abfd->iostream;
1191
36
  free (bim->buffer);
1192
36
  free (bim);
1193
  abfd->iostream = NULL;
1194
36
}
pei-arm.c:pe_ILF_cleanup
Line
Count
Source
1187
36
{
1188
36
  coff_object_cleanup (abfd);
1189
1190
36
  struct bfd_in_memory *bim = abfd->iostream;
1191
36
  free (bim->buffer);
1192
36
  free (bim);
1193
  abfd->iostream = NULL;
1194
36
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_cleanup
Unexecuted instantiation: pei-sh.c:pe_ILF_cleanup
1195
1196
/* We have detected an Import Library Format archive element.
1197
   Decode the element and return the appropriate target.  */
1198
1199
static bfd_cleanup
1200
pe_ILF_object_p (bfd *abfd)
1201
35.8k
{
1202
35.8k
  bfd_byte    buffer[14];
1203
35.8k
  bfd_byte *    ptr;
1204
35.8k
  char *    symbol_name;
1205
35.8k
  char *    source_dll;
1206
35.8k
  char *    import_name;
1207
35.8k
  unsigned int    machine;
1208
35.8k
  bfd_size_type   size;
1209
35.8k
  unsigned int    ordinal;
1210
35.8k
  unsigned int    types;
1211
35.8k
  unsigned int    magic;
1212
1213
  /* Upon entry the first six bytes of the ILF header have
1214
     already been read.  Now read the rest of the header.  */
1215
35.8k
  if (bfd_read (buffer, 14, abfd) != 14)
1216
516
    return NULL;
1217
1218
35.2k
  ptr = buffer;
1219
1220
35.2k
  machine = H_GET_16 (abfd, ptr);
1221
35.2k
  ptr += 2;
1222
1223
  /* Check that the machine type is recognised.  */
1224
35.2k
  magic = 0;
1225
1226
35.2k
  switch (machine)
1227
35.2k
    {
1228
87
    case IMAGE_FILE_MACHINE_UNKNOWN:
1229
141
    case IMAGE_FILE_MACHINE_ALPHA:
1230
195
    case IMAGE_FILE_MACHINE_ALPHA64:
1231
267
    case IMAGE_FILE_MACHINE_IA64:
1232
267
      break;
1233
1234
2.71k
    case IMAGE_FILE_MACHINE_I386:
1235
#ifdef I386MAGIC
1236
342
      magic = I386MAGIC;
1237
#endif
1238
2.71k
      break;
1239
1240
2.20k
    case IMAGE_FILE_MACHINE_AMD64:
1241
#ifdef AMD64MAGIC
1242
293
      magic = AMD64MAGIC;
1243
#endif
1244
2.20k
      break;
1245
1246
39
    case IMAGE_FILE_MACHINE_R3000:
1247
93
    case IMAGE_FILE_MACHINE_R4000:
1248
174
    case IMAGE_FILE_MACHINE_R10000:
1249
1250
228
    case IMAGE_FILE_MACHINE_MIPS16:
1251
309
    case IMAGE_FILE_MACHINE_MIPSFPU:
1252
381
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1253
#ifdef MIPS_ARCH_MAGIC_WINCE
1254
      magic = MIPS_ARCH_MAGIC_WINCE;
1255
#endif
1256
381
      break;
1257
1258
11.2k
    case IMAGE_FILE_MACHINE_SH3:
1259
12.7k
    case IMAGE_FILE_MACHINE_SH4:
1260
#ifdef SH_ARCH_MAGIC_WINCE
1261
1.48k
      magic = SH_ARCH_MAGIC_WINCE;
1262
#endif
1263
12.7k
      break;
1264
1265
1.45k
    case IMAGE_FILE_MACHINE_ARM:
1266
#ifdef ARMPEMAGIC
1267
372
      magic = ARMPEMAGIC;
1268
#endif
1269
1.45k
      break;
1270
1271
2.52k
    case IMAGE_FILE_MACHINE_ARM64:
1272
#ifdef AARCH64MAGIC
1273
325
      magic = AARCH64MAGIC;
1274
#endif
1275
2.52k
      break;
1276
1277
2.25k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1278
#ifdef LOONGARCH64MAGIC
1279
288
      magic = LOONGARCH64MAGIC;
1280
#endif
1281
2.25k
      break;
1282
1283
2.57k
    case IMAGE_FILE_MACHINE_RISCV64:
1284
#ifdef RISCV64MAGIC
1285
330
      magic = RISCV64MAGIC;
1286
#endif
1287
2.57k
      break;
1288
1289
1.73k
    case IMAGE_FILE_MACHINE_THUMB:
1290
#ifdef THUMBPEMAGIC
1291
      {
1292
  extern const bfd_target TARGET_LITTLE_SYM;
1293
1294
390
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1295
384
    magic = THUMBPEMAGIC;
1296
      }
1297
#endif
1298
1.73k
      break;
1299
1300
0
    case IMAGE_FILE_MACHINE_POWERPC:
1301
      /* We no longer support PowerPC.  */
1302
6.42k
    default:
1303
6.42k
      _bfd_error_handler
1304
  /* xgettext:c-format */
1305
6.42k
  (_("%pB: unrecognised machine type (0x%x)"
1306
6.42k
     " in Import Library Format archive"),
1307
6.42k
   abfd, machine);
1308
6.42k
      bfd_set_error (bfd_error_malformed_archive);
1309
1310
6.42k
      return NULL;
1311
0
      break;
1312
35.2k
    }
1313
1314
28.8k
  if (magic == 0)
1315
25.0k
    {
1316
25.0k
      _bfd_error_handler
1317
  /* xgettext:c-format */
1318
25.0k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1319
25.0k
     " in Import Library Format archive"),
1320
25.0k
   abfd, machine);
1321
25.0k
      bfd_set_error (bfd_error_wrong_format);
1322
1323
25.0k
      return NULL;
1324
25.0k
    }
1325
1326
  /* We do not bother to check the date.
1327
     date = H_GET_32 (abfd, ptr);  */
1328
3.82k
  ptr += 4;
1329
1330
3.82k
  size = H_GET_32 (abfd, ptr);
1331
3.82k
  ptr += 4;
1332
1333
3.82k
  if (size == 0)
1334
63
    {
1335
63
      _bfd_error_handler
1336
63
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1337
63
      bfd_set_error (bfd_error_malformed_archive);
1338
1339
63
      return NULL;
1340
63
    }
1341
1342
3.76k
  ordinal = H_GET_16 (abfd, ptr);
1343
3.76k
  ptr += 2;
1344
1345
3.76k
  types = H_GET_16 (abfd, ptr);
1346
  /* ptr += 2; */
1347
1348
  /* Now read in the two strings that follow.  */
1349
3.76k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1350
3.76k
  if (ptr == NULL)
1351
1.49k
    return NULL;
1352
1353
2.26k
  symbol_name = (char *) ptr;
1354
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1355
2.26k
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1356
1357
  /* Verify that the strings are null terminated.  */
1358
2.26k
  if (ptr[size - 1] != 0
1359
1.33k
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1360
992
    {
1361
992
      _bfd_error_handler
1362
992
  (_("%pB: string not null terminated in ILF object file"), abfd);
1363
992
      bfd_set_error (bfd_error_malformed_archive);
1364
992
      bfd_release (abfd, ptr);
1365
992
      return NULL;
1366
992
    }
1367
1368
  /* An ILF file may contain a third string, after source_dll; this is
1369
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1370
     block of data is null terminated, ptr[size-1]==0, but we don't
1371
     know how many individual null terminated strings we have in there.
1372
1373
     First find the end of source_dll.  */
1374
1.27k
  import_name = source_dll + strlen (source_dll) + 1;
1375
1.27k
  if ((bfd_byte *) import_name >= ptr + size)
1376
396
    {
1377
      /* If this points at the end of the ptr+size block, we only had
1378
   two strings. */
1379
396
      import_name = NULL;
1380
396
    }
1381
1382
  /* Now construct the bfd.  */
1383
1.27k
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1384
1.27k
          source_dll, ordinal, types,
1385
1.27k
          import_name))
1386
374
    {
1387
374
      bfd_release (abfd, ptr);
1388
374
      return NULL;
1389
374
    }
1390
1391
900
  return pe_ILF_cleanup;
1392
1.27k
}
pei-i386.c:pe_ILF_object_p
Line
Count
Source
1201
3.97k
{
1202
3.97k
  bfd_byte    buffer[14];
1203
3.97k
  bfd_byte *    ptr;
1204
3.97k
  char *    symbol_name;
1205
3.97k
  char *    source_dll;
1206
3.97k
  char *    import_name;
1207
3.97k
  unsigned int    machine;
1208
3.97k
  bfd_size_type   size;
1209
3.97k
  unsigned int    ordinal;
1210
3.97k
  unsigned int    types;
1211
3.97k
  unsigned int    magic;
1212
1213
  /* Upon entry the first six bytes of the ILF header have
1214
     already been read.  Now read the rest of the header.  */
1215
3.97k
  if (bfd_read (buffer, 14, abfd) != 14)
1216
56
    return NULL;
1217
1218
3.91k
  ptr = buffer;
1219
1220
3.91k
  machine = H_GET_16 (abfd, ptr);
1221
3.91k
  ptr += 2;
1222
1223
  /* Check that the machine type is recognised.  */
1224
3.91k
  magic = 0;
1225
1226
3.91k
  switch (machine)
1227
3.91k
    {
1228
8
    case IMAGE_FILE_MACHINE_UNKNOWN:
1229
14
    case IMAGE_FILE_MACHINE_ALPHA:
1230
20
    case IMAGE_FILE_MACHINE_ALPHA64:
1231
28
    case IMAGE_FILE_MACHINE_IA64:
1232
28
      break;
1233
1234
342
    case IMAGE_FILE_MACHINE_I386:
1235
342
#ifdef I386MAGIC
1236
342
      magic = I386MAGIC;
1237
342
#endif
1238
342
      break;
1239
1240
239
    case IMAGE_FILE_MACHINE_AMD64:
1241
#ifdef AMD64MAGIC
1242
      magic = AMD64MAGIC;
1243
#endif
1244
239
      break;
1245
1246
4
    case IMAGE_FILE_MACHINE_R3000:
1247
10
    case IMAGE_FILE_MACHINE_R4000:
1248
19
    case IMAGE_FILE_MACHINE_R10000:
1249
1250
25
    case IMAGE_FILE_MACHINE_MIPS16:
1251
34
    case IMAGE_FILE_MACHINE_MIPSFPU:
1252
42
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1253
#ifdef MIPS_ARCH_MAGIC_WINCE
1254
      magic = MIPS_ARCH_MAGIC_WINCE;
1255
#endif
1256
42
      break;
1257
1258
1.25k
    case IMAGE_FILE_MACHINE_SH3:
1259
1.41k
    case IMAGE_FILE_MACHINE_SH4:
1260
#ifdef SH_ARCH_MAGIC_WINCE
1261
      magic = SH_ARCH_MAGIC_WINCE;
1262
#endif
1263
1.41k
      break;
1264
1265
149
    case IMAGE_FILE_MACHINE_ARM:
1266
#ifdef ARMPEMAGIC
1267
      magic = ARMPEMAGIC;
1268
#endif
1269
149
      break;
1270
1271
275
    case IMAGE_FILE_MACHINE_ARM64:
1272
#ifdef AARCH64MAGIC
1273
      magic = AARCH64MAGIC;
1274
#endif
1275
275
      break;
1276
1277
246
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1278
#ifdef LOONGARCH64MAGIC
1279
      magic = LOONGARCH64MAGIC;
1280
#endif
1281
246
      break;
1282
1283
282
    case IMAGE_FILE_MACHINE_RISCV64:
1284
#ifdef RISCV64MAGIC
1285
      magic = RISCV64MAGIC;
1286
#endif
1287
282
      break;
1288
1289
192
    case IMAGE_FILE_MACHINE_THUMB:
1290
#ifdef THUMBPEMAGIC
1291
      {
1292
  extern const bfd_target TARGET_LITTLE_SYM;
1293
1294
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1295
    magic = THUMBPEMAGIC;
1296
      }
1297
#endif
1298
192
      break;
1299
1300
0
    case IMAGE_FILE_MACHINE_POWERPC:
1301
      /* We no longer support PowerPC.  */
1302
704
    default:
1303
704
      _bfd_error_handler
1304
  /* xgettext:c-format */
1305
704
  (_("%pB: unrecognised machine type (0x%x)"
1306
704
     " in Import Library Format archive"),
1307
704
   abfd, machine);
1308
704
      bfd_set_error (bfd_error_malformed_archive);
1309
1310
704
      return NULL;
1311
0
      break;
1312
3.91k
    }
1313
1314
3.21k
  if (magic == 0)
1315
2.87k
    {
1316
2.87k
      _bfd_error_handler
1317
  /* xgettext:c-format */
1318
2.87k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1319
2.87k
     " in Import Library Format archive"),
1320
2.87k
   abfd, machine);
1321
2.87k
      bfd_set_error (bfd_error_wrong_format);
1322
1323
2.87k
      return NULL;
1324
2.87k
    }
1325
1326
  /* We do not bother to check the date.
1327
     date = H_GET_32 (abfd, ptr);  */
1328
342
  ptr += 4;
1329
1330
342
  size = H_GET_32 (abfd, ptr);
1331
342
  ptr += 4;
1332
1333
342
  if (size == 0)
1334
7
    {
1335
7
      _bfd_error_handler
1336
7
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1337
7
      bfd_set_error (bfd_error_malformed_archive);
1338
1339
7
      return NULL;
1340
7
    }
1341
1342
335
  ordinal = H_GET_16 (abfd, ptr);
1343
335
  ptr += 2;
1344
1345
335
  types = H_GET_16 (abfd, ptr);
1346
  /* ptr += 2; */
1347
1348
  /* Now read in the two strings that follow.  */
1349
335
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1350
335
  if (ptr == NULL)
1351
184
    return NULL;
1352
1353
151
  symbol_name = (char *) ptr;
1354
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1355
151
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1356
1357
  /* Verify that the strings are null terminated.  */
1358
151
  if (ptr[size - 1] != 0
1359
144
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1360
14
    {
1361
14
      _bfd_error_handler
1362
14
  (_("%pB: string not null terminated in ILF object file"), abfd);
1363
14
      bfd_set_error (bfd_error_malformed_archive);
1364
14
      bfd_release (abfd, ptr);
1365
14
      return NULL;
1366
14
    }
1367
1368
  /* An ILF file may contain a third string, after source_dll; this is
1369
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1370
     block of data is null terminated, ptr[size-1]==0, but we don't
1371
     know how many individual null terminated strings we have in there.
1372
1373
     First find the end of source_dll.  */
1374
137
  import_name = source_dll + strlen (source_dll) + 1;
1375
137
  if ((bfd_byte *) import_name >= ptr + size)
1376
39
    {
1377
      /* If this points at the end of the ptr+size block, we only had
1378
   two strings. */
1379
39
      import_name = NULL;
1380
39
    }
1381
1382
  /* Now construct the bfd.  */
1383
137
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1384
137
          source_dll, ordinal, types,
1385
137
          import_name))
1386
33
    {
1387
33
      bfd_release (abfd, ptr);
1388
33
      return NULL;
1389
33
    }
1390
1391
104
  return pe_ILF_cleanup;
1392
137
}
pei-x86_64.c:pe_ILF_object_p
Line
Count
Source
1201
3.94k
{
1202
3.94k
  bfd_byte    buffer[14];
1203
3.94k
  bfd_byte *    ptr;
1204
3.94k
  char *    symbol_name;
1205
3.94k
  char *    source_dll;
1206
3.94k
  char *    import_name;
1207
3.94k
  unsigned int    machine;
1208
3.94k
  bfd_size_type   size;
1209
3.94k
  unsigned int    ordinal;
1210
3.94k
  unsigned int    types;
1211
3.94k
  unsigned int    magic;
1212
1213
  /* Upon entry the first six bytes of the ILF header have
1214
     already been read.  Now read the rest of the header.  */
1215
3.94k
  if (bfd_read (buffer, 14, abfd) != 14)
1216
56
    return NULL;
1217
1218
3.89k
  ptr = buffer;
1219
1220
3.89k
  machine = H_GET_16 (abfd, ptr);
1221
3.89k
  ptr += 2;
1222
1223
  /* Check that the machine type is recognised.  */
1224
3.89k
  magic = 0;
1225
1226
3.89k
  switch (machine)
1227
3.89k
    {
1228
8
    case IMAGE_FILE_MACHINE_UNKNOWN:
1229
14
    case IMAGE_FILE_MACHINE_ALPHA:
1230
20
    case IMAGE_FILE_MACHINE_ALPHA64:
1231
28
    case IMAGE_FILE_MACHINE_IA64:
1232
28
      break;
1233
1234
296
    case IMAGE_FILE_MACHINE_I386:
1235
#ifdef I386MAGIC
1236
      magic = I386MAGIC;
1237
#endif
1238
296
      break;
1239
1240
293
    case IMAGE_FILE_MACHINE_AMD64:
1241
293
#ifdef AMD64MAGIC
1242
293
      magic = AMD64MAGIC;
1243
293
#endif
1244
293
      break;
1245
1246
4
    case IMAGE_FILE_MACHINE_R3000:
1247
10
    case IMAGE_FILE_MACHINE_R4000:
1248
19
    case IMAGE_FILE_MACHINE_R10000:
1249
1250
25
    case IMAGE_FILE_MACHINE_MIPS16:
1251
34
    case IMAGE_FILE_MACHINE_MIPSFPU:
1252
42
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1253
#ifdef MIPS_ARCH_MAGIC_WINCE
1254
      magic = MIPS_ARCH_MAGIC_WINCE;
1255
#endif
1256
42
      break;
1257
1258
1.22k
    case IMAGE_FILE_MACHINE_SH3:
1259
1.38k
    case IMAGE_FILE_MACHINE_SH4:
1260
#ifdef SH_ARCH_MAGIC_WINCE
1261
      magic = SH_ARCH_MAGIC_WINCE;
1262
#endif
1263
1.38k
      break;
1264
1265
149
    case IMAGE_FILE_MACHINE_ARM:
1266
#ifdef ARMPEMAGIC
1267
      magic = ARMPEMAGIC;
1268
#endif
1269
149
      break;
1270
1271
275
    case IMAGE_FILE_MACHINE_ARM64:
1272
#ifdef AARCH64MAGIC
1273
      magic = AARCH64MAGIC;
1274
#endif
1275
275
      break;
1276
1277
246
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1278
#ifdef LOONGARCH64MAGIC
1279
      magic = LOONGARCH64MAGIC;
1280
#endif
1281
246
      break;
1282
1283
279
    case IMAGE_FILE_MACHINE_RISCV64:
1284
#ifdef RISCV64MAGIC
1285
      magic = RISCV64MAGIC;
1286
#endif
1287
279
      break;
1288
1289
192
    case IMAGE_FILE_MACHINE_THUMB:
1290
#ifdef THUMBPEMAGIC
1291
      {
1292
  extern const bfd_target TARGET_LITTLE_SYM;
1293
1294
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1295
    magic = THUMBPEMAGIC;
1296
      }
1297
#endif
1298
192
      break;
1299
1300
0
    case IMAGE_FILE_MACHINE_POWERPC:
1301
      /* We no longer support PowerPC.  */
1302
704
    default:
1303
704
      _bfd_error_handler
1304
  /* xgettext:c-format */
1305
704
  (_("%pB: unrecognised machine type (0x%x)"
1306
704
     " in Import Library Format archive"),
1307
704
   abfd, machine);
1308
704
      bfd_set_error (bfd_error_malformed_archive);
1309
1310
704
      return NULL;
1311
0
      break;
1312
3.89k
    }
1313
1314
3.18k
  if (magic == 0)
1315
2.89k
    {
1316
2.89k
      _bfd_error_handler
1317
  /* xgettext:c-format */
1318
2.89k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1319
2.89k
     " in Import Library Format archive"),
1320
2.89k
   abfd, machine);
1321
2.89k
      bfd_set_error (bfd_error_wrong_format);
1322
1323
2.89k
      return NULL;
1324
2.89k
    }
1325
1326
  /* We do not bother to check the date.
1327
     date = H_GET_32 (abfd, ptr);  */
1328
293
  ptr += 4;
1329
1330
293
  size = H_GET_32 (abfd, ptr);
1331
293
  ptr += 4;
1332
1333
293
  if (size == 0)
1334
7
    {
1335
7
      _bfd_error_handler
1336
7
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1337
7
      bfd_set_error (bfd_error_malformed_archive);
1338
1339
7
      return NULL;
1340
7
    }
1341
1342
286
  ordinal = H_GET_16 (abfd, ptr);
1343
286
  ptr += 2;
1344
1345
286
  types = H_GET_16 (abfd, ptr);
1346
  /* ptr += 2; */
1347
1348
  /* Now read in the two strings that follow.  */
1349
286
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1350
286
  if (ptr == NULL)
1351
114
    return NULL;
1352
1353
172
  symbol_name = (char *) ptr;
1354
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1355
172
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1356
1357
  /* Verify that the strings are null terminated.  */
1358
172
  if (ptr[size - 1] != 0
1359
165
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1360
14
    {
1361
14
      _bfd_error_handler
1362
14
  (_("%pB: string not null terminated in ILF object file"), abfd);
1363
14
      bfd_set_error (bfd_error_malformed_archive);
1364
14
      bfd_release (abfd, ptr);
1365
14
      return NULL;
1366
14
    }
1367
1368
  /* An ILF file may contain a third string, after source_dll; this is
1369
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1370
     block of data is null terminated, ptr[size-1]==0, but we don't
1371
     know how many individual null terminated strings we have in there.
1372
1373
     First find the end of source_dll.  */
1374
158
  import_name = source_dll + strlen (source_dll) + 1;
1375
158
  if ((bfd_byte *) import_name >= ptr + size)
1376
48
    {
1377
      /* If this points at the end of the ptr+size block, we only had
1378
   two strings. */
1379
48
      import_name = NULL;
1380
48
    }
1381
1382
  /* Now construct the bfd.  */
1383
158
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1384
158
          source_dll, ordinal, types,
1385
158
          import_name))
1386
38
    {
1387
38
      bfd_release (abfd, ptr);
1388
38
      return NULL;
1389
38
    }
1390
1391
120
  return pe_ILF_cleanup;
1392
158
}
pei-aarch64.c:pe_ILF_object_p
Line
Count
Source
1201
3.98k
{
1202
3.98k
  bfd_byte    buffer[14];
1203
3.98k
  bfd_byte *    ptr;
1204
3.98k
  char *    symbol_name;
1205
3.98k
  char *    source_dll;
1206
3.98k
  char *    import_name;
1207
3.98k
  unsigned int    machine;
1208
3.98k
  bfd_size_type   size;
1209
3.98k
  unsigned int    ordinal;
1210
3.98k
  unsigned int    types;
1211
3.98k
  unsigned int    magic;
1212
1213
  /* Upon entry the first six bytes of the ILF header have
1214
     already been read.  Now read the rest of the header.  */
1215
3.98k
  if (bfd_read (buffer, 14, abfd) != 14)
1216
56
    return NULL;
1217
1218
3.92k
  ptr = buffer;
1219
1220
3.92k
  machine = H_GET_16 (abfd, ptr);
1221
3.92k
  ptr += 2;
1222
1223
  /* Check that the machine type is recognised.  */
1224
3.92k
  magic = 0;
1225
1226
3.92k
  switch (machine)
1227
3.92k
    {
1228
8
    case IMAGE_FILE_MACHINE_UNKNOWN:
1229
14
    case IMAGE_FILE_MACHINE_ALPHA:
1230
20
    case IMAGE_FILE_MACHINE_ALPHA64:
1231
28
    case IMAGE_FILE_MACHINE_IA64:
1232
28
      break;
1233
1234
299
    case IMAGE_FILE_MACHINE_I386:
1235
#ifdef I386MAGIC
1236
      magic = I386MAGIC;
1237
#endif
1238
299
      break;
1239
1240
239
    case IMAGE_FILE_MACHINE_AMD64:
1241
#ifdef AMD64MAGIC
1242
      magic = AMD64MAGIC;
1243
#endif
1244
239
      break;
1245
1246
4
    case IMAGE_FILE_MACHINE_R3000:
1247
10
    case IMAGE_FILE_MACHINE_R4000:
1248
19
    case IMAGE_FILE_MACHINE_R10000:
1249
1250
25
    case IMAGE_FILE_MACHINE_MIPS16:
1251
34
    case IMAGE_FILE_MACHINE_MIPSFPU:
1252
42
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1253
#ifdef MIPS_ARCH_MAGIC_WINCE
1254
      magic = MIPS_ARCH_MAGIC_WINCE;
1255
#endif
1256
42
      break;
1257
1258
1.25k
    case IMAGE_FILE_MACHINE_SH3:
1259
1.41k
    case IMAGE_FILE_MACHINE_SH4:
1260
#ifdef SH_ARCH_MAGIC_WINCE
1261
      magic = SH_ARCH_MAGIC_WINCE;
1262
#endif
1263
1.41k
      break;
1264
1265
153
    case IMAGE_FILE_MACHINE_ARM:
1266
#ifdef ARMPEMAGIC
1267
      magic = ARMPEMAGIC;
1268
#endif
1269
153
      break;
1270
1271
325
    case IMAGE_FILE_MACHINE_ARM64:
1272
325
#ifdef AARCH64MAGIC
1273
325
      magic = AARCH64MAGIC;
1274
325
#endif
1275
325
      break;
1276
1277
246
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1278
#ifdef LOONGARCH64MAGIC
1279
      magic = LOONGARCH64MAGIC;
1280
#endif
1281
246
      break;
1282
1283
282
    case IMAGE_FILE_MACHINE_RISCV64:
1284
#ifdef RISCV64MAGIC
1285
      magic = RISCV64MAGIC;
1286
#endif
1287
282
      break;
1288
1289
192
    case IMAGE_FILE_MACHINE_THUMB:
1290
#ifdef THUMBPEMAGIC
1291
      {
1292
  extern const bfd_target TARGET_LITTLE_SYM;
1293
1294
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1295
    magic = THUMBPEMAGIC;
1296
      }
1297
#endif
1298
192
      break;
1299
1300
0
    case IMAGE_FILE_MACHINE_POWERPC:
1301
      /* We no longer support PowerPC.  */
1302
704
    default:
1303
704
      _bfd_error_handler
1304
  /* xgettext:c-format */
1305
704
  (_("%pB: unrecognised machine type (0x%x)"
1306
704
     " in Import Library Format archive"),
1307
704
   abfd, machine);
1308
704
      bfd_set_error (bfd_error_malformed_archive);
1309
1310
704
      return NULL;
1311
0
      break;
1312
3.92k
    }
1313
1314
3.22k
  if (magic == 0)
1315
2.89k
    {
1316
2.89k
      _bfd_error_handler
1317
  /* xgettext:c-format */
1318
2.89k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1319
2.89k
     " in Import Library Format archive"),
1320
2.89k
   abfd, machine);
1321
2.89k
      bfd_set_error (bfd_error_wrong_format);
1322
1323
2.89k
      return NULL;
1324
2.89k
    }
1325
1326
  /* We do not bother to check the date.
1327
     date = H_GET_32 (abfd, ptr);  */
1328
325
  ptr += 4;
1329
1330
325
  size = H_GET_32 (abfd, ptr);
1331
325
  ptr += 4;
1332
1333
325
  if (size == 0)
1334
7
    {
1335
7
      _bfd_error_handler
1336
7
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1337
7
      bfd_set_error (bfd_error_malformed_archive);
1338
1339
7
      return NULL;
1340
7
    }
1341
1342
318
  ordinal = H_GET_16 (abfd, ptr);
1343
318
  ptr += 2;
1344
1345
318
  types = H_GET_16 (abfd, ptr);
1346
  /* ptr += 2; */
1347
1348
  /* Now read in the two strings that follow.  */
1349
318
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1350
318
  if (ptr == NULL)
1351
159
    return NULL;
1352
1353
159
  symbol_name = (char *) ptr;
1354
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1355
159
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1356
1357
  /* Verify that the strings are null terminated.  */
1358
159
  if (ptr[size - 1] != 0
1359
150
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1360
16
    {
1361
16
      _bfd_error_handler
1362
16
  (_("%pB: string not null terminated in ILF object file"), abfd);
1363
16
      bfd_set_error (bfd_error_malformed_archive);
1364
16
      bfd_release (abfd, ptr);
1365
16
      return NULL;
1366
16
    }
1367
1368
  /* An ILF file may contain a third string, after source_dll; this is
1369
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1370
     block of data is null terminated, ptr[size-1]==0, but we don't
1371
     know how many individual null terminated strings we have in there.
1372
1373
     First find the end of source_dll.  */
1374
143
  import_name = source_dll + strlen (source_dll) + 1;
1375
143
  if ((bfd_byte *) import_name >= ptr + size)
1376
46
    {
1377
      /* If this points at the end of the ptr+size block, we only had
1378
   two strings. */
1379
46
      import_name = NULL;
1380
46
    }
1381
1382
  /* Now construct the bfd.  */
1383
143
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1384
143
          source_dll, ordinal, types,
1385
143
          import_name))
1386
34
    {
1387
34
      bfd_release (abfd, ptr);
1388
34
      return NULL;
1389
34
    }
1390
1391
109
  return pe_ILF_cleanup;
1392
143
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_object_p
pei-loongarch64.c:pe_ILF_object_p
Line
Count
Source
1201
3.93k
{
1202
3.93k
  bfd_byte    buffer[14];
1203
3.93k
  bfd_byte *    ptr;
1204
3.93k
  char *    symbol_name;
1205
3.93k
  char *    source_dll;
1206
3.93k
  char *    import_name;
1207
3.93k
  unsigned int    machine;
1208
3.93k
  bfd_size_type   size;
1209
3.93k
  unsigned int    ordinal;
1210
3.93k
  unsigned int    types;
1211
3.93k
  unsigned int    magic;
1212
1213
  /* Upon entry the first six bytes of the ILF header have
1214
     already been read.  Now read the rest of the header.  */
1215
3.93k
  if (bfd_read (buffer, 14, abfd) != 14)
1216
56
    return NULL;
1217
1218
3.87k
  ptr = buffer;
1219
1220
3.87k
  machine = H_GET_16 (abfd, ptr);
1221
3.87k
  ptr += 2;
1222
1223
  /* Check that the machine type is recognised.  */
1224
3.87k
  magic = 0;
1225
1226
3.87k
  switch (machine)
1227
3.87k
    {
1228
8
    case IMAGE_FILE_MACHINE_UNKNOWN:
1229
14
    case IMAGE_FILE_MACHINE_ALPHA:
1230
20
    case IMAGE_FILE_MACHINE_ALPHA64:
1231
28
    case IMAGE_FILE_MACHINE_IA64:
1232
28
      break;
1233
1234
296
    case IMAGE_FILE_MACHINE_I386:
1235
#ifdef I386MAGIC
1236
      magic = I386MAGIC;
1237
#endif
1238
296
      break;
1239
1240
235
    case IMAGE_FILE_MACHINE_AMD64:
1241
#ifdef AMD64MAGIC
1242
      magic = AMD64MAGIC;
1243
#endif
1244
235
      break;
1245
1246
4
    case IMAGE_FILE_MACHINE_R3000:
1247
10
    case IMAGE_FILE_MACHINE_R4000:
1248
19
    case IMAGE_FILE_MACHINE_R10000:
1249
1250
25
    case IMAGE_FILE_MACHINE_MIPS16:
1251
34
    case IMAGE_FILE_MACHINE_MIPSFPU:
1252
42
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1253
#ifdef MIPS_ARCH_MAGIC_WINCE
1254
      magic = MIPS_ARCH_MAGIC_WINCE;
1255
#endif
1256
42
      break;
1257
1258
1.22k
    case IMAGE_FILE_MACHINE_SH3:
1259
1.38k
    case IMAGE_FILE_MACHINE_SH4:
1260
#ifdef SH_ARCH_MAGIC_WINCE
1261
      magic = SH_ARCH_MAGIC_WINCE;
1262
#endif
1263
1.38k
      break;
1264
1265
149
    case IMAGE_FILE_MACHINE_ARM:
1266
#ifdef ARMPEMAGIC
1267
      magic = ARMPEMAGIC;
1268
#endif
1269
149
      break;
1270
1271
275
    case IMAGE_FILE_MACHINE_ARM64:
1272
#ifdef AARCH64MAGIC
1273
      magic = AARCH64MAGIC;
1274
#endif
1275
275
      break;
1276
1277
288
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1278
288
#ifdef LOONGARCH64MAGIC
1279
288
      magic = LOONGARCH64MAGIC;
1280
288
#endif
1281
288
      break;
1282
1283
279
    case IMAGE_FILE_MACHINE_RISCV64:
1284
#ifdef RISCV64MAGIC
1285
      magic = RISCV64MAGIC;
1286
#endif
1287
279
      break;
1288
1289
192
    case IMAGE_FILE_MACHINE_THUMB:
1290
#ifdef THUMBPEMAGIC
1291
      {
1292
  extern const bfd_target TARGET_LITTLE_SYM;
1293
1294
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1295
    magic = THUMBPEMAGIC;
1296
      }
1297
#endif
1298
192
      break;
1299
1300
0
    case IMAGE_FILE_MACHINE_POWERPC:
1301
      /* We no longer support PowerPC.  */
1302
704
    default:
1303
704
      _bfd_error_handler
1304
  /* xgettext:c-format */
1305
704
  (_("%pB: unrecognised machine type (0x%x)"
1306
704
     " in Import Library Format archive"),
1307
704
   abfd, machine);
1308
704
      bfd_set_error (bfd_error_malformed_archive);
1309
1310
704
      return NULL;
1311
0
      break;
1312
3.87k
    }
1313
1314
3.17k
  if (magic == 0)
1315
2.88k
    {
1316
2.88k
      _bfd_error_handler
1317
  /* xgettext:c-format */
1318
2.88k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1319
2.88k
     " in Import Library Format archive"),
1320
2.88k
   abfd, machine);
1321
2.88k
      bfd_set_error (bfd_error_wrong_format);
1322
1323
2.88k
      return NULL;
1324
2.88k
    }
1325
1326
  /* We do not bother to check the date.
1327
     date = H_GET_32 (abfd, ptr);  */
1328
288
  ptr += 4;
1329
1330
288
  size = H_GET_32 (abfd, ptr);
1331
288
  ptr += 4;
1332
1333
288
  if (size == 0)
1334
7
    {
1335
7
      _bfd_error_handler
1336
7
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1337
7
      bfd_set_error (bfd_error_malformed_archive);
1338
1339
7
      return NULL;
1340
7
    }
1341
1342
281
  ordinal = H_GET_16 (abfd, ptr);
1343
281
  ptr += 2;
1344
1345
281
  types = H_GET_16 (abfd, ptr);
1346
  /* ptr += 2; */
1347
1348
  /* Now read in the two strings that follow.  */
1349
281
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1350
281
  if (ptr == NULL)
1351
128
    return NULL;
1352
1353
153
  symbol_name = (char *) ptr;
1354
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1355
153
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1356
1357
  /* Verify that the strings are null terminated.  */
1358
153
  if (ptr[size - 1] != 0
1359
146
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1360
14
    {
1361
14
      _bfd_error_handler
1362
14
  (_("%pB: string not null terminated in ILF object file"), abfd);
1363
14
      bfd_set_error (bfd_error_malformed_archive);
1364
14
      bfd_release (abfd, ptr);
1365
14
      return NULL;
1366
14
    }
1367
1368
  /* An ILF file may contain a third string, after source_dll; this is
1369
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1370
     block of data is null terminated, ptr[size-1]==0, but we don't
1371
     know how many individual null terminated strings we have in there.
1372
1373
     First find the end of source_dll.  */
1374
139
  import_name = source_dll + strlen (source_dll) + 1;
1375
139
  if ((bfd_byte *) import_name >= ptr + size)
1376
46
    {
1377
      /* If this points at the end of the ptr+size block, we only had
1378
   two strings. */
1379
46
      import_name = NULL;
1380
46
    }
1381
1382
  /* Now construct the bfd.  */
1383
139
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1384
139
          source_dll, ordinal, types,
1385
139
          import_name))
1386
34
    {
1387
34
      bfd_release (abfd, ptr);
1388
34
      return NULL;
1389
34
    }
1390
1391
105
  return pe_ILF_cleanup;
1392
139
}
pei-riscv64.c:pe_ILF_object_p
Line
Count
Source
1201
3.97k
{
1202
3.97k
  bfd_byte    buffer[14];
1203
3.97k
  bfd_byte *    ptr;
1204
3.97k
  char *    symbol_name;
1205
3.97k
  char *    source_dll;
1206
3.97k
  char *    import_name;
1207
3.97k
  unsigned int    machine;
1208
3.97k
  bfd_size_type   size;
1209
3.97k
  unsigned int    ordinal;
1210
3.97k
  unsigned int    types;
1211
3.97k
  unsigned int    magic;
1212
1213
  /* Upon entry the first six bytes of the ILF header have
1214
     already been read.  Now read the rest of the header.  */
1215
3.97k
  if (bfd_read (buffer, 14, abfd) != 14)
1216
56
    return NULL;
1217
1218
3.91k
  ptr = buffer;
1219
1220
3.91k
  machine = H_GET_16 (abfd, ptr);
1221
3.91k
  ptr += 2;
1222
1223
  /* Check that the machine type is recognised.  */
1224
3.91k
  magic = 0;
1225
1226
3.91k
  switch (machine)
1227
3.91k
    {
1228
8
    case IMAGE_FILE_MACHINE_UNKNOWN:
1229
14
    case IMAGE_FILE_MACHINE_ALPHA:
1230
20
    case IMAGE_FILE_MACHINE_ALPHA64:
1231
28
    case IMAGE_FILE_MACHINE_IA64:
1232
28
      break;
1233
1234
296
    case IMAGE_FILE_MACHINE_I386:
1235
#ifdef I386MAGIC
1236
      magic = I386MAGIC;
1237
#endif
1238
296
      break;
1239
1240
239
    case IMAGE_FILE_MACHINE_AMD64:
1241
#ifdef AMD64MAGIC
1242
      magic = AMD64MAGIC;
1243
#endif
1244
239
      break;
1245
1246
4
    case IMAGE_FILE_MACHINE_R3000:
1247
10
    case IMAGE_FILE_MACHINE_R4000:
1248
19
    case IMAGE_FILE_MACHINE_R10000:
1249
1250
25
    case IMAGE_FILE_MACHINE_MIPS16:
1251
34
    case IMAGE_FILE_MACHINE_MIPSFPU:
1252
42
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1253
#ifdef MIPS_ARCH_MAGIC_WINCE
1254
      magic = MIPS_ARCH_MAGIC_WINCE;
1255
#endif
1256
42
      break;
1257
1258
1.25k
    case IMAGE_FILE_MACHINE_SH3:
1259
1.41k
    case IMAGE_FILE_MACHINE_SH4:
1260
#ifdef SH_ARCH_MAGIC_WINCE
1261
      magic = SH_ARCH_MAGIC_WINCE;
1262
#endif
1263
1.41k
      break;
1264
1265
149
    case IMAGE_FILE_MACHINE_ARM:
1266
#ifdef ARMPEMAGIC
1267
      magic = ARMPEMAGIC;
1268
#endif
1269
149
      break;
1270
1271
275
    case IMAGE_FILE_MACHINE_ARM64:
1272
#ifdef AARCH64MAGIC
1273
      magic = AARCH64MAGIC;
1274
#endif
1275
275
      break;
1276
1277
246
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1278
#ifdef LOONGARCH64MAGIC
1279
      magic = LOONGARCH64MAGIC;
1280
#endif
1281
246
      break;
1282
1283
330
    case IMAGE_FILE_MACHINE_RISCV64:
1284
330
#ifdef RISCV64MAGIC
1285
330
      magic = RISCV64MAGIC;
1286
330
#endif
1287
330
      break;
1288
1289
192
    case IMAGE_FILE_MACHINE_THUMB:
1290
#ifdef THUMBPEMAGIC
1291
      {
1292
  extern const bfd_target TARGET_LITTLE_SYM;
1293
1294
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1295
    magic = THUMBPEMAGIC;
1296
      }
1297
#endif
1298
192
      break;
1299
1300
0
    case IMAGE_FILE_MACHINE_POWERPC:
1301
      /* We no longer support PowerPC.  */
1302
704
    default:
1303
704
      _bfd_error_handler
1304
  /* xgettext:c-format */
1305
704
  (_("%pB: unrecognised machine type (0x%x)"
1306
704
     " in Import Library Format archive"),
1307
704
   abfd, machine);
1308
704
      bfd_set_error (bfd_error_malformed_archive);
1309
1310
704
      return NULL;
1311
0
      break;
1312
3.91k
    }
1313
1314
3.21k
  if (magic == 0)
1315
2.88k
    {
1316
2.88k
      _bfd_error_handler
1317
  /* xgettext:c-format */
1318
2.88k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1319
2.88k
     " in Import Library Format archive"),
1320
2.88k
   abfd, machine);
1321
2.88k
      bfd_set_error (bfd_error_wrong_format);
1322
1323
2.88k
      return NULL;
1324
2.88k
    }
1325
1326
  /* We do not bother to check the date.
1327
     date = H_GET_32 (abfd, ptr);  */
1328
330
  ptr += 4;
1329
1330
330
  size = H_GET_32 (abfd, ptr);
1331
330
  ptr += 4;
1332
1333
330
  if (size == 0)
1334
7
    {
1335
7
      _bfd_error_handler
1336
7
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1337
7
      bfd_set_error (bfd_error_malformed_archive);
1338
1339
7
      return NULL;
1340
7
    }
1341
1342
323
  ordinal = H_GET_16 (abfd, ptr);
1343
323
  ptr += 2;
1344
1345
323
  types = H_GET_16 (abfd, ptr);
1346
  /* ptr += 2; */
1347
1348
  /* Now read in the two strings that follow.  */
1349
323
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1350
323
  if (ptr == NULL)
1351
160
    return NULL;
1352
1353
163
  symbol_name = (char *) ptr;
1354
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1355
163
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1356
1357
  /* Verify that the strings are null terminated.  */
1358
163
  if (ptr[size - 1] != 0
1359
156
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1360
14
    {
1361
14
      _bfd_error_handler
1362
14
  (_("%pB: string not null terminated in ILF object file"), abfd);
1363
14
      bfd_set_error (bfd_error_malformed_archive);
1364
14
      bfd_release (abfd, ptr);
1365
14
      return NULL;
1366
14
    }
1367
1368
  /* An ILF file may contain a third string, after source_dll; this is
1369
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1370
     block of data is null terminated, ptr[size-1]==0, but we don't
1371
     know how many individual null terminated strings we have in there.
1372
1373
     First find the end of source_dll.  */
1374
149
  import_name = source_dll + strlen (source_dll) + 1;
1375
149
  if ((bfd_byte *) import_name >= ptr + size)
1376
39
    {
1377
      /* If this points at the end of the ptr+size block, we only had
1378
   two strings. */
1379
39
      import_name = NULL;
1380
39
    }
1381
1382
  /* Now construct the bfd.  */
1383
149
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1384
149
          source_dll, ordinal, types,
1385
149
          import_name))
1386
35
    {
1387
35
      bfd_release (abfd, ptr);
1388
35
      return NULL;
1389
35
    }
1390
1391
114
  return pe_ILF_cleanup;
1392
149
}
pei-arm-wince.c:pe_ILF_object_p
Line
Count
Source
1201
4.00k
{
1202
4.00k
  bfd_byte    buffer[14];
1203
4.00k
  bfd_byte *    ptr;
1204
4.00k
  char *    symbol_name;
1205
4.00k
  char *    source_dll;
1206
4.00k
  char *    import_name;
1207
4.00k
  unsigned int    machine;
1208
4.00k
  bfd_size_type   size;
1209
4.00k
  unsigned int    ordinal;
1210
4.00k
  unsigned int    types;
1211
4.00k
  unsigned int    magic;
1212
1213
  /* Upon entry the first six bytes of the ILF header have
1214
     already been read.  Now read the rest of the header.  */
1215
4.00k
  if (bfd_read (buffer, 14, abfd) != 14)
1216
60
    return NULL;
1217
1218
3.94k
  ptr = buffer;
1219
1220
3.94k
  machine = H_GET_16 (abfd, ptr);
1221
3.94k
  ptr += 2;
1222
1223
  /* Check that the machine type is recognised.  */
1224
3.94k
  magic = 0;
1225
1226
3.94k
  switch (machine)
1227
3.94k
    {
1228
13
    case IMAGE_FILE_MACHINE_UNKNOWN:
1229
19
    case IMAGE_FILE_MACHINE_ALPHA:
1230
25
    case IMAGE_FILE_MACHINE_ALPHA64:
1231
33
    case IMAGE_FILE_MACHINE_IA64:
1232
33
      break;
1233
1234
298
    case IMAGE_FILE_MACHINE_I386:
1235
#ifdef I386MAGIC
1236
      magic = I386MAGIC;
1237
#endif
1238
298
      break;
1239
1240
239
    case IMAGE_FILE_MACHINE_AMD64:
1241
#ifdef AMD64MAGIC
1242
      magic = AMD64MAGIC;
1243
#endif
1244
239
      break;
1245
1246
5
    case IMAGE_FILE_MACHINE_R3000:
1247
11
    case IMAGE_FILE_MACHINE_R4000:
1248
20
    case IMAGE_FILE_MACHINE_R10000:
1249
1250
26
    case IMAGE_FILE_MACHINE_MIPS16:
1251
35
    case IMAGE_FILE_MACHINE_MIPSFPU:
1252
43
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1253
#ifdef MIPS_ARCH_MAGIC_WINCE
1254
      magic = MIPS_ARCH_MAGIC_WINCE;
1255
#endif
1256
43
      break;
1257
1258
1.24k
    case IMAGE_FILE_MACHINE_SH3:
1259
1.41k
    case IMAGE_FILE_MACHINE_SH4:
1260
#ifdef SH_ARCH_MAGIC_WINCE
1261
      magic = SH_ARCH_MAGIC_WINCE;
1262
#endif
1263
1.41k
      break;
1264
1265
184
    case IMAGE_FILE_MACHINE_ARM:
1266
184
#ifdef ARMPEMAGIC
1267
184
      magic = ARMPEMAGIC;
1268
184
#endif
1269
184
      break;
1270
1271
275
    case IMAGE_FILE_MACHINE_ARM64:
1272
#ifdef AARCH64MAGIC
1273
      magic = AARCH64MAGIC;
1274
#endif
1275
275
      break;
1276
1277
246
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1278
#ifdef LOONGARCH64MAGIC
1279
      magic = LOONGARCH64MAGIC;
1280
#endif
1281
246
      break;
1282
1283
282
    case IMAGE_FILE_MACHINE_RISCV64:
1284
#ifdef RISCV64MAGIC
1285
      magic = RISCV64MAGIC;
1286
#endif
1287
282
      break;
1288
1289
195
    case IMAGE_FILE_MACHINE_THUMB:
1290
195
#ifdef THUMBPEMAGIC
1291
195
      {
1292
195
  extern const bfd_target TARGET_LITTLE_SYM;
1293
1294
195
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1295
192
    magic = THUMBPEMAGIC;
1296
195
      }
1297
195
#endif
1298
195
      break;
1299
1300
0
    case IMAGE_FILE_MACHINE_POWERPC:
1301
      /* We no longer support PowerPC.  */
1302
732
    default:
1303
732
      _bfd_error_handler
1304
  /* xgettext:c-format */
1305
732
  (_("%pB: unrecognised machine type (0x%x)"
1306
732
     " in Import Library Format archive"),
1307
732
   abfd, machine);
1308
732
      bfd_set_error (bfd_error_malformed_archive);
1309
1310
732
      return NULL;
1311
0
      break;
1312
3.94k
    }
1313
1314
3.21k
  if (magic == 0)
1315
2.83k
    {
1316
2.83k
      _bfd_error_handler
1317
  /* xgettext:c-format */
1318
2.83k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1319
2.83k
     " in Import Library Format archive"),
1320
2.83k
   abfd, machine);
1321
2.83k
      bfd_set_error (bfd_error_wrong_format);
1322
1323
2.83k
      return NULL;
1324
2.83k
    }
1325
1326
  /* We do not bother to check the date.
1327
     date = H_GET_32 (abfd, ptr);  */
1328
376
  ptr += 4;
1329
1330
376
  size = H_GET_32 (abfd, ptr);
1331
376
  ptr += 4;
1332
1333
376
  if (size == 0)
1334
8
    {
1335
8
      _bfd_error_handler
1336
8
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1337
8
      bfd_set_error (bfd_error_malformed_archive);
1338
1339
8
      return NULL;
1340
8
    }
1341
1342
368
  ordinal = H_GET_16 (abfd, ptr);
1343
368
  ptr += 2;
1344
1345
368
  types = H_GET_16 (abfd, ptr);
1346
  /* ptr += 2; */
1347
1348
  /* Now read in the two strings that follow.  */
1349
368
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1350
368
  if (ptr == NULL)
1351
213
    return NULL;
1352
1353
155
  symbol_name = (char *) ptr;
1354
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1355
155
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1356
1357
  /* Verify that the strings are null terminated.  */
1358
155
  if (ptr[size - 1] != 0
1359
139
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1360
24
    {
1361
24
      _bfd_error_handler
1362
24
  (_("%pB: string not null terminated in ILF object file"), abfd);
1363
24
      bfd_set_error (bfd_error_malformed_archive);
1364
24
      bfd_release (abfd, ptr);
1365
24
      return NULL;
1366
24
    }
1367
1368
  /* An ILF file may contain a third string, after source_dll; this is
1369
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1370
     block of data is null terminated, ptr[size-1]==0, but we don't
1371
     know how many individual null terminated strings we have in there.
1372
1373
     First find the end of source_dll.  */
1374
131
  import_name = source_dll + strlen (source_dll) + 1;
1375
131
  if ((bfd_byte *) import_name >= ptr + size)
1376
56
    {
1377
      /* If this points at the end of the ptr+size block, we only had
1378
   two strings. */
1379
56
      import_name = NULL;
1380
56
    }
1381
1382
  /* Now construct the bfd.  */
1383
131
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1384
131
          source_dll, ordinal, types,
1385
131
          import_name))
1386
45
    {
1387
45
      bfd_release (abfd, ptr);
1388
45
      return NULL;
1389
45
    }
1390
1391
86
  return pe_ILF_cleanup;
1392
131
}
pei-arm.c:pe_ILF_object_p
Line
Count
Source
1201
4.00k
{
1202
4.00k
  bfd_byte    buffer[14];
1203
4.00k
  bfd_byte *    ptr;
1204
4.00k
  char *    symbol_name;
1205
4.00k
  char *    source_dll;
1206
4.00k
  char *    import_name;
1207
4.00k
  unsigned int    machine;
1208
4.00k
  bfd_size_type   size;
1209
4.00k
  unsigned int    ordinal;
1210
4.00k
  unsigned int    types;
1211
4.00k
  unsigned int    magic;
1212
1213
  /* Upon entry the first six bytes of the ILF header have
1214
     already been read.  Now read the rest of the header.  */
1215
4.00k
  if (bfd_read (buffer, 14, abfd) != 14)
1216
60
    return NULL;
1217
1218
3.94k
  ptr = buffer;
1219
1220
3.94k
  machine = H_GET_16 (abfd, ptr);
1221
3.94k
  ptr += 2;
1222
1223
  /* Check that the machine type is recognised.  */
1224
3.94k
  magic = 0;
1225
1226
3.94k
  switch (machine)
1227
3.94k
    {
1228
13
    case IMAGE_FILE_MACHINE_UNKNOWN:
1229
19
    case IMAGE_FILE_MACHINE_ALPHA:
1230
25
    case IMAGE_FILE_MACHINE_ALPHA64:
1231
33
    case IMAGE_FILE_MACHINE_IA64:
1232
33
      break;
1233
1234
298
    case IMAGE_FILE_MACHINE_I386:
1235
#ifdef I386MAGIC
1236
      magic = I386MAGIC;
1237
#endif
1238
298
      break;
1239
1240
239
    case IMAGE_FILE_MACHINE_AMD64:
1241
#ifdef AMD64MAGIC
1242
      magic = AMD64MAGIC;
1243
#endif
1244
239
      break;
1245
1246
5
    case IMAGE_FILE_MACHINE_R3000:
1247
11
    case IMAGE_FILE_MACHINE_R4000:
1248
20
    case IMAGE_FILE_MACHINE_R10000:
1249
1250
26
    case IMAGE_FILE_MACHINE_MIPS16:
1251
35
    case IMAGE_FILE_MACHINE_MIPSFPU:
1252
43
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1253
#ifdef MIPS_ARCH_MAGIC_WINCE
1254
      magic = MIPS_ARCH_MAGIC_WINCE;
1255
#endif
1256
43
      break;
1257
1258
1.24k
    case IMAGE_FILE_MACHINE_SH3:
1259
1.41k
    case IMAGE_FILE_MACHINE_SH4:
1260
#ifdef SH_ARCH_MAGIC_WINCE
1261
      magic = SH_ARCH_MAGIC_WINCE;
1262
#endif
1263
1.41k
      break;
1264
1265
188
    case IMAGE_FILE_MACHINE_ARM:
1266
188
#ifdef ARMPEMAGIC
1267
188
      magic = ARMPEMAGIC;
1268
188
#endif
1269
188
      break;
1270
1271
275
    case IMAGE_FILE_MACHINE_ARM64:
1272
#ifdef AARCH64MAGIC
1273
      magic = AARCH64MAGIC;
1274
#endif
1275
275
      break;
1276
1277
246
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1278
#ifdef LOONGARCH64MAGIC
1279
      magic = LOONGARCH64MAGIC;
1280
#endif
1281
246
      break;
1282
1283
282
    case IMAGE_FILE_MACHINE_RISCV64:
1284
#ifdef RISCV64MAGIC
1285
      magic = RISCV64MAGIC;
1286
#endif
1287
282
      break;
1288
1289
195
    case IMAGE_FILE_MACHINE_THUMB:
1290
195
#ifdef THUMBPEMAGIC
1291
195
      {
1292
195
  extern const bfd_target TARGET_LITTLE_SYM;
1293
1294
195
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1295
192
    magic = THUMBPEMAGIC;
1296
195
      }
1297
195
#endif
1298
195
      break;
1299
1300
0
    case IMAGE_FILE_MACHINE_POWERPC:
1301
      /* We no longer support PowerPC.  */
1302
732
    default:
1303
732
      _bfd_error_handler
1304
  /* xgettext:c-format */
1305
732
  (_("%pB: unrecognised machine type (0x%x)"
1306
732
     " in Import Library Format archive"),
1307
732
   abfd, machine);
1308
732
      bfd_set_error (bfd_error_malformed_archive);
1309
1310
732
      return NULL;
1311
0
      break;
1312
3.94k
    }
1313
1314
3.21k
  if (magic == 0)
1315
2.83k
    {
1316
2.83k
      _bfd_error_handler
1317
  /* xgettext:c-format */
1318
2.83k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1319
2.83k
     " in Import Library Format archive"),
1320
2.83k
   abfd, machine);
1321
2.83k
      bfd_set_error (bfd_error_wrong_format);
1322
1323
2.83k
      return NULL;
1324
2.83k
    }
1325
1326
  /* We do not bother to check the date.
1327
     date = H_GET_32 (abfd, ptr);  */
1328
380
  ptr += 4;
1329
1330
380
  size = H_GET_32 (abfd, ptr);
1331
380
  ptr += 4;
1332
1333
380
  if (size == 0)
1334
8
    {
1335
8
      _bfd_error_handler
1336
8
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1337
8
      bfd_set_error (bfd_error_malformed_archive);
1338
1339
8
      return NULL;
1340
8
    }
1341
1342
372
  ordinal = H_GET_16 (abfd, ptr);
1343
372
  ptr += 2;
1344
1345
372
  types = H_GET_16 (abfd, ptr);
1346
  /* ptr += 2; */
1347
1348
  /* Now read in the two strings that follow.  */
1349
372
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1350
372
  if (ptr == NULL)
1351
213
    return NULL;
1352
1353
159
  symbol_name = (char *) ptr;
1354
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1355
159
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1356
1357
  /* Verify that the strings are null terminated.  */
1358
159
  if (ptr[size - 1] != 0
1359
143
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1360
24
    {
1361
24
      _bfd_error_handler
1362
24
  (_("%pB: string not null terminated in ILF object file"), abfd);
1363
24
      bfd_set_error (bfd_error_malformed_archive);
1364
24
      bfd_release (abfd, ptr);
1365
24
      return NULL;
1366
24
    }
1367
1368
  /* An ILF file may contain a third string, after source_dll; this is
1369
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1370
     block of data is null terminated, ptr[size-1]==0, but we don't
1371
     know how many individual null terminated strings we have in there.
1372
1373
     First find the end of source_dll.  */
1374
135
  import_name = source_dll + strlen (source_dll) + 1;
1375
135
  if ((bfd_byte *) import_name >= ptr + size)
1376
57
    {
1377
      /* If this points at the end of the ptr+size block, we only had
1378
   two strings. */
1379
57
      import_name = NULL;
1380
57
    }
1381
1382
  /* Now construct the bfd.  */
1383
135
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1384
135
          source_dll, ordinal, types,
1385
135
          import_name))
1386
45
    {
1387
45
      bfd_release (abfd, ptr);
1388
45
      return NULL;
1389
45
    }
1390
1391
90
  return pe_ILF_cleanup;
1392
135
}
pei-mcore.c:pe_ILF_object_p
Line
Count
Source
1201
4.00k
{
1202
4.00k
  bfd_byte    buffer[14];
1203
4.00k
  bfd_byte *    ptr;
1204
4.00k
  char *    symbol_name;
1205
4.00k
  char *    source_dll;
1206
4.00k
  char *    import_name;
1207
4.00k
  unsigned int    machine;
1208
4.00k
  bfd_size_type   size;
1209
4.00k
  unsigned int    ordinal;
1210
4.00k
  unsigned int    types;
1211
4.00k
  unsigned int    magic;
1212
1213
  /* Upon entry the first six bytes of the ILF header have
1214
     already been read.  Now read the rest of the header.  */
1215
4.00k
  if (bfd_read (buffer, 14, abfd) != 14)
1216
60
    return NULL;
1217
1218
3.94k
  ptr = buffer;
1219
1220
3.94k
  machine = H_GET_16 (abfd, ptr);
1221
3.94k
  ptr += 2;
1222
1223
  /* Check that the machine type is recognised.  */
1224
3.94k
  magic = 0;
1225
1226
3.94k
  switch (machine)
1227
3.94k
    {
1228
13
    case IMAGE_FILE_MACHINE_UNKNOWN:
1229
19
    case IMAGE_FILE_MACHINE_ALPHA:
1230
25
    case IMAGE_FILE_MACHINE_ALPHA64:
1231
33
    case IMAGE_FILE_MACHINE_IA64:
1232
33
      break;
1233
1234
295
    case IMAGE_FILE_MACHINE_I386:
1235
#ifdef I386MAGIC
1236
      magic = I386MAGIC;
1237
#endif
1238
295
      break;
1239
1240
239
    case IMAGE_FILE_MACHINE_AMD64:
1241
#ifdef AMD64MAGIC
1242
      magic = AMD64MAGIC;
1243
#endif
1244
239
      break;
1245
1246
5
    case IMAGE_FILE_MACHINE_R3000:
1247
11
    case IMAGE_FILE_MACHINE_R4000:
1248
20
    case IMAGE_FILE_MACHINE_R10000:
1249
1250
26
    case IMAGE_FILE_MACHINE_MIPS16:
1251
35
    case IMAGE_FILE_MACHINE_MIPSFPU:
1252
43
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1253
#ifdef MIPS_ARCH_MAGIC_WINCE
1254
      magic = MIPS_ARCH_MAGIC_WINCE;
1255
#endif
1256
43
      break;
1257
1258
1.24k
    case IMAGE_FILE_MACHINE_SH3:
1259
1.41k
    case IMAGE_FILE_MACHINE_SH4:
1260
#ifdef SH_ARCH_MAGIC_WINCE
1261
      magic = SH_ARCH_MAGIC_WINCE;
1262
#endif
1263
1.41k
      break;
1264
1265
184
    case IMAGE_FILE_MACHINE_ARM:
1266
#ifdef ARMPEMAGIC
1267
      magic = ARMPEMAGIC;
1268
#endif
1269
184
      break;
1270
1271
275
    case IMAGE_FILE_MACHINE_ARM64:
1272
#ifdef AARCH64MAGIC
1273
      magic = AARCH64MAGIC;
1274
#endif
1275
275
      break;
1276
1277
246
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1278
#ifdef LOONGARCH64MAGIC
1279
      magic = LOONGARCH64MAGIC;
1280
#endif
1281
246
      break;
1282
1283
282
    case IMAGE_FILE_MACHINE_RISCV64:
1284
#ifdef RISCV64MAGIC
1285
      magic = RISCV64MAGIC;
1286
#endif
1287
282
      break;
1288
1289
195
    case IMAGE_FILE_MACHINE_THUMB:
1290
#ifdef THUMBPEMAGIC
1291
      {
1292
  extern const bfd_target TARGET_LITTLE_SYM;
1293
1294
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1295
    magic = THUMBPEMAGIC;
1296
      }
1297
#endif
1298
195
      break;
1299
1300
0
    case IMAGE_FILE_MACHINE_POWERPC:
1301
      /* We no longer support PowerPC.  */
1302
732
    default:
1303
732
      _bfd_error_handler
1304
  /* xgettext:c-format */
1305
732
  (_("%pB: unrecognised machine type (0x%x)"
1306
732
     " in Import Library Format archive"),
1307
732
   abfd, machine);
1308
732
      bfd_set_error (bfd_error_malformed_archive);
1309
1310
732
      return NULL;
1311
0
      break;
1312
3.94k
    }
1313
1314
3.20k
  if (magic == 0)
1315
3.20k
    {
1316
3.20k
      _bfd_error_handler
1317
  /* xgettext:c-format */
1318
3.20k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1319
3.20k
     " in Import Library Format archive"),
1320
3.20k
   abfd, machine);
1321
3.20k
      bfd_set_error (bfd_error_wrong_format);
1322
1323
3.20k
      return NULL;
1324
3.20k
    }
1325
1326
  /* We do not bother to check the date.
1327
     date = H_GET_32 (abfd, ptr);  */
1328
0
  ptr += 4;
1329
1330
0
  size = H_GET_32 (abfd, ptr);
1331
0
  ptr += 4;
1332
1333
0
  if (size == 0)
1334
0
    {
1335
0
      _bfd_error_handler
1336
0
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1337
0
      bfd_set_error (bfd_error_malformed_archive);
1338
1339
0
      return NULL;
1340
0
    }
1341
1342
0
  ordinal = H_GET_16 (abfd, ptr);
1343
0
  ptr += 2;
1344
1345
0
  types = H_GET_16 (abfd, ptr);
1346
  /* ptr += 2; */
1347
1348
  /* Now read in the two strings that follow.  */
1349
0
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1350
0
  if (ptr == NULL)
1351
0
    return NULL;
1352
1353
0
  symbol_name = (char *) ptr;
1354
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1355
0
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1356
1357
  /* Verify that the strings are null terminated.  */
1358
0
  if (ptr[size - 1] != 0
1359
0
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1360
0
    {
1361
0
      _bfd_error_handler
1362
0
  (_("%pB: string not null terminated in ILF object file"), abfd);
1363
0
      bfd_set_error (bfd_error_malformed_archive);
1364
0
      bfd_release (abfd, ptr);
1365
0
      return NULL;
1366
0
    }
1367
1368
  /* An ILF file may contain a third string, after source_dll; this is
1369
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1370
     block of data is null terminated, ptr[size-1]==0, but we don't
1371
     know how many individual null terminated strings we have in there.
1372
1373
     First find the end of source_dll.  */
1374
0
  import_name = source_dll + strlen (source_dll) + 1;
1375
0
  if ((bfd_byte *) import_name >= ptr + size)
1376
0
    {
1377
      /* If this points at the end of the ptr+size block, we only had
1378
   two strings. */
1379
0
      import_name = NULL;
1380
0
    }
1381
1382
  /* Now construct the bfd.  */
1383
0
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1384
0
          source_dll, ordinal, types,
1385
0
          import_name))
1386
0
    {
1387
0
      bfd_release (abfd, ptr);
1388
0
      return NULL;
1389
0
    }
1390
1391
0
  return pe_ILF_cleanup;
1392
0
}
pei-sh.c:pe_ILF_object_p
Line
Count
Source
1201
3.99k
{
1202
3.99k
  bfd_byte    buffer[14];
1203
3.99k
  bfd_byte *    ptr;
1204
3.99k
  char *    symbol_name;
1205
3.99k
  char *    source_dll;
1206
3.99k
  char *    import_name;
1207
3.99k
  unsigned int    machine;
1208
3.99k
  bfd_size_type   size;
1209
3.99k
  unsigned int    ordinal;
1210
3.99k
  unsigned int    types;
1211
3.99k
  unsigned int    magic;
1212
1213
  /* Upon entry the first six bytes of the ILF header have
1214
     already been read.  Now read the rest of the header.  */
1215
3.99k
  if (bfd_read (buffer, 14, abfd) != 14)
1216
56
    return NULL;
1217
1218
3.93k
  ptr = buffer;
1219
1220
3.93k
  machine = H_GET_16 (abfd, ptr);
1221
3.93k
  ptr += 2;
1222
1223
  /* Check that the machine type is recognised.  */
1224
3.93k
  magic = 0;
1225
1226
3.93k
  switch (machine)
1227
3.93k
    {
1228
8
    case IMAGE_FILE_MACHINE_UNKNOWN:
1229
14
    case IMAGE_FILE_MACHINE_ALPHA:
1230
20
    case IMAGE_FILE_MACHINE_ALPHA64:
1231
28
    case IMAGE_FILE_MACHINE_IA64:
1232
28
      break;
1233
1234
295
    case IMAGE_FILE_MACHINE_I386:
1235
#ifdef I386MAGIC
1236
      magic = I386MAGIC;
1237
#endif
1238
295
      break;
1239
1240
239
    case IMAGE_FILE_MACHINE_AMD64:
1241
#ifdef AMD64MAGIC
1242
      magic = AMD64MAGIC;
1243
#endif
1244
239
      break;
1245
1246
4
    case IMAGE_FILE_MACHINE_R3000:
1247
10
    case IMAGE_FILE_MACHINE_R4000:
1248
19
    case IMAGE_FILE_MACHINE_R10000:
1249
1250
25
    case IMAGE_FILE_MACHINE_MIPS16:
1251
34
    case IMAGE_FILE_MACHINE_MIPSFPU:
1252
42
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1253
#ifdef MIPS_ARCH_MAGIC_WINCE
1254
      magic = MIPS_ARCH_MAGIC_WINCE;
1255
#endif
1256
42
      break;
1257
1258
1.29k
    case IMAGE_FILE_MACHINE_SH3:
1259
1.48k
    case IMAGE_FILE_MACHINE_SH4:
1260
1.48k
#ifdef SH_ARCH_MAGIC_WINCE
1261
1.48k
      magic = SH_ARCH_MAGIC_WINCE;
1262
1.48k
#endif
1263
1.48k
      break;
1264
1265
149
    case IMAGE_FILE_MACHINE_ARM:
1266
#ifdef ARMPEMAGIC
1267
      magic = ARMPEMAGIC;
1268
#endif
1269
149
      break;
1270
1271
275
    case IMAGE_FILE_MACHINE_ARM64:
1272
#ifdef AARCH64MAGIC
1273
      magic = AARCH64MAGIC;
1274
#endif
1275
275
      break;
1276
1277
246
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1278
#ifdef LOONGARCH64MAGIC
1279
      magic = LOONGARCH64MAGIC;
1280
#endif
1281
246
      break;
1282
1283
279
    case IMAGE_FILE_MACHINE_RISCV64:
1284
#ifdef RISCV64MAGIC
1285
      magic = RISCV64MAGIC;
1286
#endif
1287
279
      break;
1288
1289
192
    case IMAGE_FILE_MACHINE_THUMB:
1290
#ifdef THUMBPEMAGIC
1291
      {
1292
  extern const bfd_target TARGET_LITTLE_SYM;
1293
1294
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1295
    magic = THUMBPEMAGIC;
1296
      }
1297
#endif
1298
192
      break;
1299
1300
0
    case IMAGE_FILE_MACHINE_POWERPC:
1301
      /* We no longer support PowerPC.  */
1302
704
    default:
1303
704
      _bfd_error_handler
1304
  /* xgettext:c-format */
1305
704
  (_("%pB: unrecognised machine type (0x%x)"
1306
704
     " in Import Library Format archive"),
1307
704
   abfd, machine);
1308
704
      bfd_set_error (bfd_error_malformed_archive);
1309
1310
704
      return NULL;
1311
0
      break;
1312
3.93k
    }
1313
1314
3.23k
  if (magic == 0)
1315
1.74k
    {
1316
1.74k
      _bfd_error_handler
1317
  /* xgettext:c-format */
1318
1.74k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1319
1.74k
     " in Import Library Format archive"),
1320
1.74k
   abfd, machine);
1321
1.74k
      bfd_set_error (bfd_error_wrong_format);
1322
1323
1.74k
      return NULL;
1324
1.74k
    }
1325
1326
  /* We do not bother to check the date.
1327
     date = H_GET_32 (abfd, ptr);  */
1328
1.48k
  ptr += 4;
1329
1330
1.48k
  size = H_GET_32 (abfd, ptr);
1331
1.48k
  ptr += 4;
1332
1333
1.48k
  if (size == 0)
1334
12
    {
1335
12
      _bfd_error_handler
1336
12
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1337
12
      bfd_set_error (bfd_error_malformed_archive);
1338
1339
12
      return NULL;
1340
12
    }
1341
1342
1.47k
  ordinal = H_GET_16 (abfd, ptr);
1343
1.47k
  ptr += 2;
1344
1345
1.47k
  types = H_GET_16 (abfd, ptr);
1346
  /* ptr += 2; */
1347
1348
  /* Now read in the two strings that follow.  */
1349
1.47k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1350
1.47k
  if (ptr == NULL)
1351
323
    return NULL;
1352
1353
1.15k
  symbol_name = (char *) ptr;
1354
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1355
1.15k
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1356
1357
  /* Verify that the strings are null terminated.  */
1358
1.15k
  if (ptr[size - 1] != 0
1359
294
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1360
872
    {
1361
872
      _bfd_error_handler
1362
872
  (_("%pB: string not null terminated in ILF object file"), abfd);
1363
872
      bfd_set_error (bfd_error_malformed_archive);
1364
872
      bfd_release (abfd, ptr);
1365
872
      return NULL;
1366
872
    }
1367
1368
  /* An ILF file may contain a third string, after source_dll; this is
1369
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1370
     block of data is null terminated, ptr[size-1]==0, but we don't
1371
     know how many individual null terminated strings we have in there.
1372
1373
     First find the end of source_dll.  */
1374
282
  import_name = source_dll + strlen (source_dll) + 1;
1375
282
  if ((bfd_byte *) import_name >= ptr + size)
1376
65
    {
1377
      /* If this points at the end of the ptr+size block, we only had
1378
   two strings. */
1379
65
      import_name = NULL;
1380
65
    }
1381
1382
  /* Now construct the bfd.  */
1383
282
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1384
282
          source_dll, ordinal, types,
1385
282
          import_name))
1386
110
    {
1387
110
      bfd_release (abfd, ptr);
1388
110
      return NULL;
1389
110
    }
1390
1391
172
  return pe_ILF_cleanup;
1392
282
}
1393
1394
static void
1395
pe_bfd_read_buildid (bfd *abfd)
1396
45.6k
{
1397
45.6k
  pe_data_type *pe = pe_data (abfd);
1398
45.6k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1399
45.6k
  asection *section;
1400
45.6k
  bfd_byte *data = 0;
1401
45.6k
  bfd_size_type dataoff;
1402
45.6k
  unsigned int i;
1403
45.6k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1404
45.6k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1405
1406
45.6k
  if (size == 0)
1407
27.6k
    return;
1408
1409
17.9k
  addr += extra->ImageBase;
1410
1411
  /* Search for the section containing the DebugDirectory.  */
1412
129k
  for (section = abfd->sections; section != NULL; section = section->next)
1413
120k
    {
1414
120k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1415
8.94k
  break;
1416
120k
    }
1417
1418
17.9k
  if (section == NULL)
1419
9.00k
    return;
1420
1421
8.94k
  if (!(section->flags & SEC_HAS_CONTENTS))
1422
465
    return;
1423
1424
8.47k
  dataoff = addr - section->vma;
1425
1426
  /* PR 20605 and 22373: Make sure that the data is really there.
1427
     Note - since we are dealing with unsigned quantities we have
1428
     to be careful to check for potential overflows.  */
1429
8.47k
  if (dataoff >= section->size
1430
8.47k
      || size > section->size - dataoff)
1431
2.77k
    {
1432
2.77k
      _bfd_error_handler
1433
2.77k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1434
2.77k
   abfd);
1435
2.77k
      return;
1436
2.77k
    }
1437
1438
  /* Read the whole section. */
1439
5.69k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1440
1.54k
    {
1441
1.54k
      free (data);
1442
1.54k
      return;
1443
1.54k
    }
1444
1445
  /* Search for a CodeView entry in the DebugDirectory */
1446
300k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1447
297k
    {
1448
297k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1449
297k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1450
297k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1451
1452
297k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1453
1454
297k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1455
1.63k
  {
1456
1.63k
    char buffer[256 + 1];
1457
1.63k
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1458
1459
    /*
1460
      The debug entry doesn't have to have to be in a section, in which
1461
      case AddressOfRawData is 0, so always use PointerToRawData.
1462
    */
1463
1.63k
    if (_bfd_XXi_slurp_codeview_record (abfd,
1464
1.63k
                (file_ptr) idd.PointerToRawData,
1465
1.63k
                idd.SizeOfData, cvinfo, NULL))
1466
112
      {
1467
112
        struct bfd_build_id *build_id;
1468
112
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1469
1470
112
        build_id = bfd_alloc (abfd, bidlen);
1471
112
        if (build_id)
1472
112
    {
1473
112
      build_id->size = cvinfo->SignatureLength;
1474
112
      memcpy(build_id->data, cvinfo->Signature,
1475
112
       cvinfo->SignatureLength);
1476
112
      abfd->build_id = build_id;
1477
112
    }
1478
112
      }
1479
1.63k
    break;
1480
1.63k
  }
1481
297k
    }
1482
1483
4.15k
  free (data);
1484
4.15k
}
pei-i386.c:pe_bfd_read_buildid
Line
Count
Source
1396
8.42k
{
1397
8.42k
  pe_data_type *pe = pe_data (abfd);
1398
8.42k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1399
8.42k
  asection *section;
1400
8.42k
  bfd_byte *data = 0;
1401
8.42k
  bfd_size_type dataoff;
1402
8.42k
  unsigned int i;
1403
8.42k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1404
8.42k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1405
1406
8.42k
  if (size == 0)
1407
6.57k
    return;
1408
1409
1.85k
  addr += extra->ImageBase;
1410
1411
  /* Search for the section containing the DebugDirectory.  */
1412
14.5k
  for (section = abfd->sections; section != NULL; section = section->next)
1413
13.6k
    {
1414
13.6k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1415
893
  break;
1416
13.6k
    }
1417
1418
1.85k
  if (section == NULL)
1419
965
    return;
1420
1421
893
  if (!(section->flags & SEC_HAS_CONTENTS))
1422
73
    return;
1423
1424
820
  dataoff = addr - section->vma;
1425
1426
  /* PR 20605 and 22373: Make sure that the data is really there.
1427
     Note - since we are dealing with unsigned quantities we have
1428
     to be careful to check for potential overflows.  */
1429
820
  if (dataoff >= section->size
1430
820
      || size > section->size - dataoff)
1431
423
    {
1432
423
      _bfd_error_handler
1433
423
  (_("%pB: error: debug data ends beyond end of debug directory"),
1434
423
   abfd);
1435
423
      return;
1436
423
    }
1437
1438
  /* Read the whole section. */
1439
397
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1440
168
    {
1441
168
      free (data);
1442
168
      return;
1443
168
    }
1444
1445
  /* Search for a CodeView entry in the DebugDirectory */
1446
6.23k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1447
6.13k
    {
1448
6.13k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1449
6.13k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1450
6.13k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1451
1452
6.13k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1453
1454
6.13k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1455
130
  {
1456
130
    char buffer[256 + 1];
1457
130
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1458
1459
    /*
1460
      The debug entry doesn't have to have to be in a section, in which
1461
      case AddressOfRawData is 0, so always use PointerToRawData.
1462
    */
1463
130
    if (_bfd_XXi_slurp_codeview_record (abfd,
1464
130
                (file_ptr) idd.PointerToRawData,
1465
130
                idd.SizeOfData, cvinfo, NULL))
1466
14
      {
1467
14
        struct bfd_build_id *build_id;
1468
14
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1469
1470
14
        build_id = bfd_alloc (abfd, bidlen);
1471
14
        if (build_id)
1472
14
    {
1473
14
      build_id->size = cvinfo->SignatureLength;
1474
14
      memcpy(build_id->data, cvinfo->Signature,
1475
14
       cvinfo->SignatureLength);
1476
14
      abfd->build_id = build_id;
1477
14
    }
1478
14
      }
1479
130
    break;
1480
130
  }
1481
6.13k
    }
1482
1483
229
  free (data);
1484
229
}
pei-x86_64.c:pe_bfd_read_buildid
Line
Count
Source
1396
6.28k
{
1397
6.28k
  pe_data_type *pe = pe_data (abfd);
1398
6.28k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1399
6.28k
  asection *section;
1400
6.28k
  bfd_byte *data = 0;
1401
6.28k
  bfd_size_type dataoff;
1402
6.28k
  unsigned int i;
1403
6.28k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1404
6.28k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1405
1406
6.28k
  if (size == 0)
1407
3.96k
    return;
1408
1409
2.31k
  addr += extra->ImageBase;
1410
1411
  /* Search for the section containing the DebugDirectory.  */
1412
23.6k
  for (section = abfd->sections; section != NULL; section = section->next)
1413
22.3k
    {
1414
22.3k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1415
956
  break;
1416
22.3k
    }
1417
1418
2.31k
  if (section == NULL)
1419
1.36k
    return;
1420
1421
956
  if (!(section->flags & SEC_HAS_CONTENTS))
1422
54
    return;
1423
1424
902
  dataoff = addr - section->vma;
1425
1426
  /* PR 20605 and 22373: Make sure that the data is really there.
1427
     Note - since we are dealing with unsigned quantities we have
1428
     to be careful to check for potential overflows.  */
1429
902
  if (dataoff >= section->size
1430
902
      || size > section->size - dataoff)
1431
357
    {
1432
357
      _bfd_error_handler
1433
357
  (_("%pB: error: debug data ends beyond end of debug directory"),
1434
357
   abfd);
1435
357
      return;
1436
357
    }
1437
1438
  /* Read the whole section. */
1439
545
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1440
192
    {
1441
192
      free (data);
1442
192
      return;
1443
192
    }
1444
1445
  /* Search for a CodeView entry in the DebugDirectory */
1446
9.49k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1447
9.40k
    {
1448
9.40k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1449
9.40k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1450
9.40k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1451
1452
9.40k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1453
1454
9.40k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1455
268
  {
1456
268
    char buffer[256 + 1];
1457
268
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1458
1459
    /*
1460
      The debug entry doesn't have to have to be in a section, in which
1461
      case AddressOfRawData is 0, so always use PointerToRawData.
1462
    */
1463
268
    if (_bfd_XXi_slurp_codeview_record (abfd,
1464
268
                (file_ptr) idd.PointerToRawData,
1465
268
                idd.SizeOfData, cvinfo, NULL))
1466
40
      {
1467
40
        struct bfd_build_id *build_id;
1468
40
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1469
1470
40
        build_id = bfd_alloc (abfd, bidlen);
1471
40
        if (build_id)
1472
40
    {
1473
40
      build_id->size = cvinfo->SignatureLength;
1474
40
      memcpy(build_id->data, cvinfo->Signature,
1475
40
       cvinfo->SignatureLength);
1476
40
      abfd->build_id = build_id;
1477
40
    }
1478
40
      }
1479
268
    break;
1480
268
  }
1481
9.40k
    }
1482
1483
353
  free (data);
1484
353
}
pei-aarch64.c:pe_bfd_read_buildid
Line
Count
Source
1396
6.63k
{
1397
6.63k
  pe_data_type *pe = pe_data (abfd);
1398
6.63k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1399
6.63k
  asection *section;
1400
6.63k
  bfd_byte *data = 0;
1401
6.63k
  bfd_size_type dataoff;
1402
6.63k
  unsigned int i;
1403
6.63k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1404
6.63k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1405
1406
6.63k
  if (size == 0)
1407
2.38k
    return;
1408
1409
4.25k
  addr += extra->ImageBase;
1410
1411
  /* Search for the section containing the DebugDirectory.  */
1412
25.5k
  for (section = abfd->sections; section != NULL; section = section->next)
1413
24.2k
    {
1414
24.2k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1415
2.95k
  break;
1416
24.2k
    }
1417
1418
4.25k
  if (section == NULL)
1419
1.29k
    return;
1420
1421
2.95k
  if (!(section->flags & SEC_HAS_CONTENTS))
1422
25
    return;
1423
1424
2.92k
  dataoff = addr - section->vma;
1425
1426
  /* PR 20605 and 22373: Make sure that the data is really there.
1427
     Note - since we are dealing with unsigned quantities we have
1428
     to be careful to check for potential overflows.  */
1429
2.92k
  if (dataoff >= section->size
1430
2.92k
      || size > section->size - dataoff)
1431
376
    {
1432
376
      _bfd_error_handler
1433
376
  (_("%pB: error: debug data ends beyond end of debug directory"),
1434
376
   abfd);
1435
376
      return;
1436
376
    }
1437
1438
  /* Read the whole section. */
1439
2.55k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1440
372
    {
1441
372
      free (data);
1442
372
      return;
1443
372
    }
1444
1445
  /* Search for a CodeView entry in the DebugDirectory */
1446
256k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1447
254k
    {
1448
254k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1449
254k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1450
254k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1451
1452
254k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1453
1454
254k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1455
548
  {
1456
548
    char buffer[256 + 1];
1457
548
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1458
1459
    /*
1460
      The debug entry doesn't have to have to be in a section, in which
1461
      case AddressOfRawData is 0, so always use PointerToRawData.
1462
    */
1463
548
    if (_bfd_XXi_slurp_codeview_record (abfd,
1464
548
                (file_ptr) idd.PointerToRawData,
1465
548
                idd.SizeOfData, cvinfo, NULL))
1466
10
      {
1467
10
        struct bfd_build_id *build_id;
1468
10
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1469
1470
10
        build_id = bfd_alloc (abfd, bidlen);
1471
10
        if (build_id)
1472
10
    {
1473
10
      build_id->size = cvinfo->SignatureLength;
1474
10
      memcpy(build_id->data, cvinfo->Signature,
1475
10
       cvinfo->SignatureLength);
1476
10
      abfd->build_id = build_id;
1477
10
    }
1478
10
      }
1479
548
    break;
1480
548
  }
1481
254k
    }
1482
1483
2.18k
  free (data);
1484
2.18k
}
pei-ia64.c:pe_bfd_read_buildid
Line
Count
Source
1396
4.15k
{
1397
4.15k
  pe_data_type *pe = pe_data (abfd);
1398
4.15k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1399
4.15k
  asection *section;
1400
4.15k
  bfd_byte *data = 0;
1401
4.15k
  bfd_size_type dataoff;
1402
4.15k
  unsigned int i;
1403
4.15k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1404
4.15k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1405
1406
4.15k
  if (size == 0)
1407
3.09k
    return;
1408
1409
1.06k
  addr += extra->ImageBase;
1410
1411
  /* Search for the section containing the DebugDirectory.  */
1412
6.70k
  for (section = abfd->sections; section != NULL; section = section->next)
1413
5.93k
    {
1414
5.93k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1415
297
  break;
1416
5.93k
    }
1417
1418
1.06k
  if (section == NULL)
1419
764
    return;
1420
1421
297
  if (!(section->flags & SEC_HAS_CONTENTS))
1422
33
    return;
1423
1424
264
  dataoff = addr - section->vma;
1425
1426
  /* PR 20605 and 22373: Make sure that the data is really there.
1427
     Note - since we are dealing with unsigned quantities we have
1428
     to be careful to check for potential overflows.  */
1429
264
  if (dataoff >= section->size
1430
264
      || size > section->size - dataoff)
1431
51
    {
1432
51
      _bfd_error_handler
1433
51
  (_("%pB: error: debug data ends beyond end of debug directory"),
1434
51
   abfd);
1435
51
      return;
1436
51
    }
1437
1438
  /* Read the whole section. */
1439
213
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1440
41
    {
1441
41
      free (data);
1442
41
      return;
1443
41
    }
1444
1445
  /* Search for a CodeView entry in the DebugDirectory */
1446
1.85k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1447
1.77k
    {
1448
1.77k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1449
1.77k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1450
1.77k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1451
1452
1.77k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1453
1454
1.77k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1455
96
  {
1456
96
    char buffer[256 + 1];
1457
96
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1458
1459
    /*
1460
      The debug entry doesn't have to have to be in a section, in which
1461
      case AddressOfRawData is 0, so always use PointerToRawData.
1462
    */
1463
96
    if (_bfd_XXi_slurp_codeview_record (abfd,
1464
96
                (file_ptr) idd.PointerToRawData,
1465
96
                idd.SizeOfData, cvinfo, NULL))
1466
2
      {
1467
2
        struct bfd_build_id *build_id;
1468
2
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1469
1470
2
        build_id = bfd_alloc (abfd, bidlen);
1471
2
        if (build_id)
1472
2
    {
1473
2
      build_id->size = cvinfo->SignatureLength;
1474
2
      memcpy(build_id->data, cvinfo->Signature,
1475
2
       cvinfo->SignatureLength);
1476
2
      abfd->build_id = build_id;
1477
2
    }
1478
2
      }
1479
96
    break;
1480
96
  }
1481
1.77k
    }
1482
1483
172
  free (data);
1484
172
}
pei-loongarch64.c:pe_bfd_read_buildid
Line
Count
Source
1396
3.68k
{
1397
3.68k
  pe_data_type *pe = pe_data (abfd);
1398
3.68k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1399
3.68k
  asection *section;
1400
3.68k
  bfd_byte *data = 0;
1401
3.68k
  bfd_size_type dataoff;
1402
3.68k
  unsigned int i;
1403
3.68k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1404
3.68k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1405
1406
3.68k
  if (size == 0)
1407
2.41k
    return;
1408
1409
1.26k
  addr += extra->ImageBase;
1410
1411
  /* Search for the section containing the DebugDirectory.  */
1412
9.90k
  for (section = abfd->sections; section != NULL; section = section->next)
1413
9.14k
    {
1414
9.14k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1415
507
  break;
1416
9.14k
    }
1417
1418
1.26k
  if (section == NULL)
1419
756
    return;
1420
1421
507
  if (!(section->flags & SEC_HAS_CONTENTS))
1422
39
    return;
1423
1424
468
  dataoff = addr - section->vma;
1425
1426
  /* PR 20605 and 22373: Make sure that the data is really there.
1427
     Note - since we are dealing with unsigned quantities we have
1428
     to be careful to check for potential overflows.  */
1429
468
  if (dataoff >= section->size
1430
468
      || size > section->size - dataoff)
1431
112
    {
1432
112
      _bfd_error_handler
1433
112
  (_("%pB: error: debug data ends beyond end of debug directory"),
1434
112
   abfd);
1435
112
      return;
1436
112
    }
1437
1438
  /* Read the whole section. */
1439
356
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1440
67
    {
1441
67
      free (data);
1442
67
      return;
1443
67
    }
1444
1445
  /* Search for a CodeView entry in the DebugDirectory */
1446
7.34k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1447
7.22k
    {
1448
7.22k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1449
7.22k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1450
7.22k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1451
1452
7.22k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1453
1454
7.22k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1455
168
  {
1456
168
    char buffer[256 + 1];
1457
168
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1458
1459
    /*
1460
      The debug entry doesn't have to have to be in a section, in which
1461
      case AddressOfRawData is 0, so always use PointerToRawData.
1462
    */
1463
168
    if (_bfd_XXi_slurp_codeview_record (abfd,
1464
168
                (file_ptr) idd.PointerToRawData,
1465
168
                idd.SizeOfData, cvinfo, NULL))
1466
7
      {
1467
7
        struct bfd_build_id *build_id;
1468
7
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1469
1470
7
        build_id = bfd_alloc (abfd, bidlen);
1471
7
        if (build_id)
1472
7
    {
1473
7
      build_id->size = cvinfo->SignatureLength;
1474
7
      memcpy(build_id->data, cvinfo->Signature,
1475
7
       cvinfo->SignatureLength);
1476
7
      abfd->build_id = build_id;
1477
7
    }
1478
7
      }
1479
168
    break;
1480
168
  }
1481
7.22k
    }
1482
1483
289
  free (data);
1484
289
}
pei-riscv64.c:pe_bfd_read_buildid
Line
Count
Source
1396
3.88k
{
1397
3.88k
  pe_data_type *pe = pe_data (abfd);
1398
3.88k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1399
3.88k
  asection *section;
1400
3.88k
  bfd_byte *data = 0;
1401
3.88k
  bfd_size_type dataoff;
1402
3.88k
  unsigned int i;
1403
3.88k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1404
3.88k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1405
1406
3.88k
  if (size == 0)
1407
2.37k
    return;
1408
1409
1.51k
  addr += extra->ImageBase;
1410
1411
  /* Search for the section containing the DebugDirectory.  */
1412
15.4k
  for (section = abfd->sections; section != NULL; section = section->next)
1413
14.5k
    {
1414
14.5k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1415
575
  break;
1416
14.5k
    }
1417
1418
1.51k
  if (section == NULL)
1419
935
    return;
1420
1421
575
  if (!(section->flags & SEC_HAS_CONTENTS))
1422
37
    return;
1423
1424
538
  dataoff = addr - section->vma;
1425
1426
  /* PR 20605 and 22373: Make sure that the data is really there.
1427
     Note - since we are dealing with unsigned quantities we have
1428
     to be careful to check for potential overflows.  */
1429
538
  if (dataoff >= section->size
1430
538
      || size > section->size - dataoff)
1431
206
    {
1432
206
      _bfd_error_handler
1433
206
  (_("%pB: error: debug data ends beyond end of debug directory"),
1434
206
   abfd);
1435
206
      return;
1436
206
    }
1437
1438
  /* Read the whole section. */
1439
332
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1440
99
    {
1441
99
      free (data);
1442
99
      return;
1443
99
    }
1444
1445
  /* Search for a CodeView entry in the DebugDirectory */
1446
2.83k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1447
2.76k
    {
1448
2.76k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1449
2.76k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1450
2.76k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1451
1452
2.76k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1453
1454
2.76k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1455
163
  {
1456
163
    char buffer[256 + 1];
1457
163
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1458
1459
    /*
1460
      The debug entry doesn't have to have to be in a section, in which
1461
      case AddressOfRawData is 0, so always use PointerToRawData.
1462
    */
1463
163
    if (_bfd_XXi_slurp_codeview_record (abfd,
1464
163
                (file_ptr) idd.PointerToRawData,
1465
163
                idd.SizeOfData, cvinfo, NULL))
1466
6
      {
1467
6
        struct bfd_build_id *build_id;
1468
6
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1469
1470
6
        build_id = bfd_alloc (abfd, bidlen);
1471
6
        if (build_id)
1472
6
    {
1473
6
      build_id->size = cvinfo->SignatureLength;
1474
6
      memcpy(build_id->data, cvinfo->Signature,
1475
6
       cvinfo->SignatureLength);
1476
6
      abfd->build_id = build_id;
1477
6
    }
1478
6
      }
1479
163
    break;
1480
163
  }
1481
2.76k
    }
1482
1483
233
  free (data);
1484
233
}
pei-arm-wince.c:pe_bfd_read_buildid
Line
Count
Source
1396
2.29k
{
1397
2.29k
  pe_data_type *pe = pe_data (abfd);
1398
2.29k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1399
2.29k
  asection *section;
1400
2.29k
  bfd_byte *data = 0;
1401
2.29k
  bfd_size_type dataoff;
1402
2.29k
  unsigned int i;
1403
2.29k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1404
2.29k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1405
1406
2.29k
  if (size == 0)
1407
1.00k
    return;
1408
1409
1.29k
  addr += extra->ImageBase;
1410
1411
  /* Search for the section containing the DebugDirectory.  */
1412
5.72k
  for (section = abfd->sections; section != NULL; section = section->next)
1413
4.99k
    {
1414
4.99k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1415
560
  break;
1416
4.99k
    }
1417
1418
1.29k
  if (section == NULL)
1419
731
    return;
1420
1421
560
  if (!(section->flags & SEC_HAS_CONTENTS))
1422
58
    return;
1423
1424
502
  dataoff = addr - section->vma;
1425
1426
  /* PR 20605 and 22373: Make sure that the data is really there.
1427
     Note - since we are dealing with unsigned quantities we have
1428
     to be careful to check for potential overflows.  */
1429
502
  if (dataoff >= section->size
1430
502
      || size > section->size - dataoff)
1431
273
    {
1432
273
      _bfd_error_handler
1433
273
  (_("%pB: error: debug data ends beyond end of debug directory"),
1434
273
   abfd);
1435
273
      return;
1436
273
    }
1437
1438
  /* Read the whole section. */
1439
229
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1440
113
    {
1441
113
      free (data);
1442
113
      return;
1443
113
    }
1444
1445
  /* Search for a CodeView entry in the DebugDirectory */
1446
1.84k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1447
1.77k
    {
1448
1.77k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1449
1.77k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1450
1.77k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1451
1452
1.77k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1453
1454
1.77k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1455
49
  {
1456
49
    char buffer[256 + 1];
1457
49
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1458
1459
    /*
1460
      The debug entry doesn't have to have to be in a section, in which
1461
      case AddressOfRawData is 0, so always use PointerToRawData.
1462
    */
1463
49
    if (_bfd_XXi_slurp_codeview_record (abfd,
1464
49
                (file_ptr) idd.PointerToRawData,
1465
49
                idd.SizeOfData, cvinfo, NULL))
1466
6
      {
1467
6
        struct bfd_build_id *build_id;
1468
6
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1469
1470
6
        build_id = bfd_alloc (abfd, bidlen);
1471
6
        if (build_id)
1472
6
    {
1473
6
      build_id->size = cvinfo->SignatureLength;
1474
6
      memcpy(build_id->data, cvinfo->Signature,
1475
6
       cvinfo->SignatureLength);
1476
6
      abfd->build_id = build_id;
1477
6
    }
1478
6
      }
1479
49
    break;
1480
49
  }
1481
1.77k
    }
1482
1483
116
  free (data);
1484
116
}
pei-arm.c:pe_bfd_read_buildid
Line
Count
Source
1396
3.52k
{
1397
3.52k
  pe_data_type *pe = pe_data (abfd);
1398
3.52k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1399
3.52k
  asection *section;
1400
3.52k
  bfd_byte *data = 0;
1401
3.52k
  bfd_size_type dataoff;
1402
3.52k
  unsigned int i;
1403
3.52k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1404
3.52k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1405
1406
3.52k
  if (size == 0)
1407
1.85k
    return;
1408
1409
1.66k
  addr += extra->ImageBase;
1410
1411
  /* Search for the section containing the DebugDirectory.  */
1412
9.92k
  for (section = abfd->sections; section != NULL; section = section->next)
1413
9.10k
    {
1414
9.10k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1415
847
  break;
1416
9.10k
    }
1417
1418
1.66k
  if (section == NULL)
1419
822
    return;
1420
1421
847
  if (!(section->flags & SEC_HAS_CONTENTS))
1422
44
    return;
1423
1424
803
  dataoff = addr - section->vma;
1425
1426
  /* PR 20605 and 22373: Make sure that the data is really there.
1427
     Note - since we are dealing with unsigned quantities we have
1428
     to be careful to check for potential overflows.  */
1429
803
  if (dataoff >= section->size
1430
803
      || size > section->size - dataoff)
1431
376
    {
1432
376
      _bfd_error_handler
1433
376
  (_("%pB: error: debug data ends beyond end of debug directory"),
1434
376
   abfd);
1435
376
      return;
1436
376
    }
1437
1438
  /* Read the whole section. */
1439
427
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1440
191
    {
1441
191
      free (data);
1442
191
      return;
1443
191
    }
1444
1445
  /* Search for a CodeView entry in the DebugDirectory */
1446
3.04k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1447
2.88k
    {
1448
2.88k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1449
2.88k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1450
2.88k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1451
1452
2.88k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1453
1454
2.88k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1455
70
  {
1456
70
    char buffer[256 + 1];
1457
70
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1458
1459
    /*
1460
      The debug entry doesn't have to have to be in a section, in which
1461
      case AddressOfRawData is 0, so always use PointerToRawData.
1462
    */
1463
70
    if (_bfd_XXi_slurp_codeview_record (abfd,
1464
70
                (file_ptr) idd.PointerToRawData,
1465
70
                idd.SizeOfData, cvinfo, NULL))
1466
21
      {
1467
21
        struct bfd_build_id *build_id;
1468
21
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1469
1470
21
        build_id = bfd_alloc (abfd, bidlen);
1471
21
        if (build_id)
1472
21
    {
1473
21
      build_id->size = cvinfo->SignatureLength;
1474
21
      memcpy(build_id->data, cvinfo->Signature,
1475
21
       cvinfo->SignatureLength);
1476
21
      abfd->build_id = build_id;
1477
21
    }
1478
21
      }
1479
70
    break;
1480
70
  }
1481
2.88k
    }
1482
1483
236
  free (data);
1484
236
}
pei-mcore.c:pe_bfd_read_buildid
Line
Count
Source
1396
3.38k
{
1397
3.38k
  pe_data_type *pe = pe_data (abfd);
1398
3.38k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1399
3.38k
  asection *section;
1400
3.38k
  bfd_byte *data = 0;
1401
3.38k
  bfd_size_type dataoff;
1402
3.38k
  unsigned int i;
1403
3.38k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1404
3.38k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1405
1406
3.38k
  if (size == 0)
1407
1.96k
    return;
1408
1409
1.42k
  addr += extra->ImageBase;
1410
1411
  /* Search for the section containing the DebugDirectory.  */
1412
9.69k
  for (section = abfd->sections; section != NULL; section = section->next)
1413
8.94k
    {
1414
8.94k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1415
674
  break;
1416
8.94k
    }
1417
1418
1.42k
  if (section == NULL)
1419
747
    return;
1420
1421
674
  if (!(section->flags & SEC_HAS_CONTENTS))
1422
56
    return;
1423
1424
618
  dataoff = addr - section->vma;
1425
1426
  /* PR 20605 and 22373: Make sure that the data is really there.
1427
     Note - since we are dealing with unsigned quantities we have
1428
     to be careful to check for potential overflows.  */
1429
618
  if (dataoff >= section->size
1430
618
      || size > section->size - dataoff)
1431
308
    {
1432
308
      _bfd_error_handler
1433
308
  (_("%pB: error: debug data ends beyond end of debug directory"),
1434
308
   abfd);
1435
308
      return;
1436
308
    }
1437
1438
  /* Read the whole section. */
1439
310
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1440
159
    {
1441
159
      free (data);
1442
159
      return;
1443
159
    }
1444
1445
  /* Search for a CodeView entry in the DebugDirectory */
1446
5.02k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1447
4.93k
    {
1448
4.93k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1449
4.93k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1450
4.93k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1451
1452
4.93k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1453
1454
4.93k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1455
59
  {
1456
59
    char buffer[256 + 1];
1457
59
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1458
1459
    /*
1460
      The debug entry doesn't have to have to be in a section, in which
1461
      case AddressOfRawData is 0, so always use PointerToRawData.
1462
    */
1463
59
    if (_bfd_XXi_slurp_codeview_record (abfd,
1464
59
                (file_ptr) idd.PointerToRawData,
1465
59
                idd.SizeOfData, cvinfo, NULL))
1466
3
      {
1467
3
        struct bfd_build_id *build_id;
1468
3
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1469
1470
3
        build_id = bfd_alloc (abfd, bidlen);
1471
3
        if (build_id)
1472
3
    {
1473
3
      build_id->size = cvinfo->SignatureLength;
1474
3
      memcpy(build_id->data, cvinfo->Signature,
1475
3
       cvinfo->SignatureLength);
1476
3
      abfd->build_id = build_id;
1477
3
    }
1478
3
      }
1479
59
    break;
1480
59
  }
1481
4.93k
    }
1482
1483
151
  free (data);
1484
151
}
pei-sh.c:pe_bfd_read_buildid
Line
Count
Source
1396
3.32k
{
1397
3.32k
  pe_data_type *pe = pe_data (abfd);
1398
3.32k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1399
3.32k
  asection *section;
1400
3.32k
  bfd_byte *data = 0;
1401
3.32k
  bfd_size_type dataoff;
1402
3.32k
  unsigned int i;
1403
3.32k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1404
3.32k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1405
1406
3.32k
  if (size == 0)
1407
2.02k
    return;
1408
1409
1.30k
  addr += extra->ImageBase;
1410
1411
  /* Search for the section containing the DebugDirectory.  */
1412
8.05k
  for (section = abfd->sections; section != NULL; section = section->next)
1413
7.43k
    {
1414
7.43k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1415
680
  break;
1416
7.43k
    }
1417
1418
1.30k
  if (section == NULL)
1419
628
    return;
1420
1421
680
  if (!(section->flags & SEC_HAS_CONTENTS))
1422
46
    return;
1423
1424
634
  dataoff = addr - section->vma;
1425
1426
  /* PR 20605 and 22373: Make sure that the data is really there.
1427
     Note - since we are dealing with unsigned quantities we have
1428
     to be careful to check for potential overflows.  */
1429
634
  if (dataoff >= section->size
1430
634
      || size > section->size - dataoff)
1431
297
    {
1432
297
      _bfd_error_handler
1433
297
  (_("%pB: error: debug data ends beyond end of debug directory"),
1434
297
   abfd);
1435
297
      return;
1436
297
    }
1437
1438
  /* Read the whole section. */
1439
337
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1440
145
    {
1441
145
      free (data);
1442
145
      return;
1443
145
    }
1444
1445
  /* Search for a CodeView entry in the DebugDirectory */
1446
6.12k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1447
6.00k
    {
1448
6.00k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1449
6.00k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1450
6.00k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1451
1452
6.00k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1453
1454
6.00k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1455
79
  {
1456
79
    char buffer[256 + 1];
1457
79
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1458
1459
    /*
1460
      The debug entry doesn't have to have to be in a section, in which
1461
      case AddressOfRawData is 0, so always use PointerToRawData.
1462
    */
1463
79
    if (_bfd_XXi_slurp_codeview_record (abfd,
1464
79
                (file_ptr) idd.PointerToRawData,
1465
79
                idd.SizeOfData, cvinfo, NULL))
1466
3
      {
1467
3
        struct bfd_build_id *build_id;
1468
3
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1469
1470
3
        build_id = bfd_alloc (abfd, bidlen);
1471
3
        if (build_id)
1472
3
    {
1473
3
      build_id->size = cvinfo->SignatureLength;
1474
3
      memcpy(build_id->data, cvinfo->Signature,
1475
3
       cvinfo->SignatureLength);
1476
3
      abfd->build_id = build_id;
1477
3
    }
1478
3
      }
1479
79
    break;
1480
79
  }
1481
6.00k
    }
1482
1483
192
  free (data);
1484
192
}
1485
1486
static bfd_cleanup
1487
pe_bfd_object_p (bfd *abfd)
1488
2.37M
{
1489
2.37M
  bfd_byte buffer[6];
1490
2.37M
  struct external_DOS_hdr dos_hdr;
1491
2.37M
  struct external_PEI_IMAGE_hdr image_hdr;
1492
2.37M
  struct internal_filehdr internal_f;
1493
2.37M
  struct internal_aouthdr internal_a;
1494
2.37M
  bfd_size_type opt_hdr_size;
1495
2.37M
  file_ptr offset;
1496
2.37M
  bfd_cleanup result;
1497
1498
  /* Detect if this a Microsoft Import Library Format element.  */
1499
  /* First read the beginning of the header.  */
1500
2.37M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1501
2.37M
      || bfd_read (buffer, 6, abfd) != 6)
1502
21.5k
    {
1503
21.5k
      if (bfd_get_error () != bfd_error_system_call)
1504
19.3k
  bfd_set_error (bfd_error_wrong_format);
1505
21.5k
      return NULL;
1506
21.5k
    }
1507
1508
  /* Then check the magic and the version (only 0 is supported).  */
1509
2.35M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1510
43.2k
      && H_GET_16 (abfd, buffer + 4) == 0)
1511
35.8k
    return pe_ILF_object_p (abfd);
1512
1513
2.31M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1514
2.31M
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1515
491k
    {
1516
491k
      if (bfd_get_error () != bfd_error_system_call)
1517
491k
  bfd_set_error (bfd_error_wrong_format);
1518
491k
      return NULL;
1519
491k
    }
1520
1521
  /* There are really two magic numbers involved; the magic number
1522
     that says this is a NT executable (PEI) and the magic number that
1523
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1524
     the e_magic field.  The latter is stored in the f_magic field.
1525
     If the NT magic number isn't valid, the architecture magic number
1526
     could be mimicked by some other field (specifically, the number
1527
     of relocs in section 3).  Since this routine can only be called
1528
     correctly for a PEI file, check the e_magic number here, and, if
1529
     it doesn't match, clobber the f_magic number so that we don't get
1530
     a false match.  */
1531
1.82M
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1532
1.33M
    {
1533
1.33M
      bfd_set_error (bfd_error_wrong_format);
1534
1.33M
      return NULL;
1535
1.33M
    }
1536
1537
489k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1538
489k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1539
489k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1540
3.34k
    {
1541
3.34k
      if (bfd_get_error () != bfd_error_system_call)
1542
3.34k
  bfd_set_error (bfd_error_wrong_format);
1543
3.34k
      return NULL;
1544
3.34k
    }
1545
1546
485k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1547
6.00k
    {
1548
6.00k
      bfd_set_error (bfd_error_wrong_format);
1549
6.00k
      return NULL;
1550
6.00k
    }
1551
1552
  /* Swap file header, so that we get the location for calling
1553
     real_object_p.  */
1554
479k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1555
1556
479k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1557
71.5k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1558
408k
    {
1559
408k
      bfd_set_error (bfd_error_wrong_format);
1560
408k
      return NULL;
1561
408k
    }
1562
1563
71.3k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1564
71.3k
    sizeof (internal_f.pe.dos_message));
1565
1566
  /* Read the optional header, which has variable size.  */
1567
71.3k
  opt_hdr_size = internal_f.f_opthdr;
1568
1569
71.3k
  if (opt_hdr_size != 0)
1570
42.4k
    {
1571
42.4k
      bfd_size_type amt = opt_hdr_size;
1572
42.4k
      bfd_byte *opthdr;
1573
1574
      /* PR 17521 file: 230-131433-0.004.  */
1575
42.4k
      if (amt < sizeof (PEAOUTHDR))
1576
39.1k
  amt = sizeof (PEAOUTHDR);
1577
1578
42.4k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1579
42.4k
      if (opthdr == NULL)
1580
396
  return NULL;
1581
42.0k
      if (amt > opt_hdr_size)
1582
38.8k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1583
1584
42.0k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1585
1586
42.0k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1587
1588
#ifdef ARM
1589
      /* Use Subsystem to distinguish between pei-arm-little and
1590
   pei-arm-wince-little.  */
1591
#ifdef WINCE
1592
4.78k
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1593
#else
1594
5.08k
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1595
1.55k
#endif
1596
4.33k
  {
1597
4.33k
    bfd_set_error (bfd_error_wrong_format);
1598
4.33k
    return NULL;
1599
4.33k
  }
1600
5.53k
#endif
1601
1602
37.6k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1603
17.5k
    || a->SectionAlignment >= 0x80000000)
1604
20.4k
  {
1605
20.4k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1606
20.4k
            abfd);
1607
20.4k
    a->SectionAlignment &= -a->SectionAlignment;
1608
20.4k
    if (a->SectionAlignment >= 0x80000000)
1609
360
      a->SectionAlignment = 0x40000000;
1610
20.4k
  }
1611
1612
37.6k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1613
19.1k
    || a->FileAlignment > a->SectionAlignment)
1614
24.7k
  {
1615
24.7k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1616
24.7k
            abfd);
1617
24.7k
    a->FileAlignment &= -a->FileAlignment;
1618
24.7k
    if (a->FileAlignment > a->SectionAlignment)
1619
17.4k
      a->FileAlignment = a->SectionAlignment;
1620
24.7k
  }
1621
1622
37.6k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1623
19.7k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1624
5.53k
    }
1625
1626
66.6k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1627
66.6k
             (opt_hdr_size != 0
1628
66.6k
        ? &internal_a
1629
66.6k
        : (struct internal_aouthdr *) NULL));
1630
1631
66.6k
  if (result)
1632
45.6k
    {
1633
      /* Now the whole header has been processed, see if there is a build-id */
1634
45.6k
      pe_bfd_read_buildid(abfd);
1635
45.6k
    }
1636
1637
66.6k
  return result;
1638
71.3k
}
pei-i386.c:pe_bfd_object_p
Line
Count
Source
1488
212k
{
1489
212k
  bfd_byte buffer[6];
1490
212k
  struct external_DOS_hdr dos_hdr;
1491
212k
  struct external_PEI_IMAGE_hdr image_hdr;
1492
212k
  struct internal_filehdr internal_f;
1493
212k
  struct internal_aouthdr internal_a;
1494
212k
  bfd_size_type opt_hdr_size;
1495
212k
  file_ptr offset;
1496
212k
  bfd_cleanup result;
1497
1498
  /* Detect if this a Microsoft Import Library Format element.  */
1499
  /* First read the beginning of the header.  */
1500
212k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1501
212k
      || bfd_read (buffer, 6, abfd) != 6)
1502
1.79k
    {
1503
1.79k
      if (bfd_get_error () != bfd_error_system_call)
1504
1.60k
  bfd_set_error (bfd_error_wrong_format);
1505
1.79k
      return NULL;
1506
1.79k
    }
1507
1508
  /* Then check the magic and the version (only 0 is supported).  */
1509
210k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1510
4.82k
      && H_GET_16 (abfd, buffer + 4) == 0)
1511
3.97k
    return pe_ILF_object_p (abfd);
1512
1513
206k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1514
206k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1515
42.1k
    {
1516
42.1k
      if (bfd_get_error () != bfd_error_system_call)
1517
42.1k
  bfd_set_error (bfd_error_wrong_format);
1518
42.1k
      return NULL;
1519
42.1k
    }
1520
1521
  /* There are really two magic numbers involved; the magic number
1522
     that says this is a NT executable (PEI) and the magic number that
1523
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1524
     the e_magic field.  The latter is stored in the f_magic field.
1525
     If the NT magic number isn't valid, the architecture magic number
1526
     could be mimicked by some other field (specifically, the number
1527
     of relocs in section 3).  Since this routine can only be called
1528
     correctly for a PEI file, check the e_magic number here, and, if
1529
     it doesn't match, clobber the f_magic number so that we don't get
1530
     a false match.  */
1531
164k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1532
109k
    {
1533
109k
      bfd_set_error (bfd_error_wrong_format);
1534
109k
      return NULL;
1535
109k
    }
1536
1537
55.2k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1538
55.2k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1539
55.2k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1540
176
    {
1541
176
      if (bfd_get_error () != bfd_error_system_call)
1542
176
  bfd_set_error (bfd_error_wrong_format);
1543
176
      return NULL;
1544
176
    }
1545
1546
55.0k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1547
426
    {
1548
426
      bfd_set_error (bfd_error_wrong_format);
1549
426
      return NULL;
1550
426
    }
1551
1552
  /* Swap file header, so that we get the location for calling
1553
     real_object_p.  */
1554
54.6k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1555
1556
54.6k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1557
9.75k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1558
44.8k
    {
1559
44.8k
      bfd_set_error (bfd_error_wrong_format);
1560
44.8k
      return NULL;
1561
44.8k
    }
1562
1563
9.73k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1564
9.73k
    sizeof (internal_f.pe.dos_message));
1565
1566
  /* Read the optional header, which has variable size.  */
1567
9.73k
  opt_hdr_size = internal_f.f_opthdr;
1568
1569
9.73k
  if (opt_hdr_size != 0)
1570
4.79k
    {
1571
4.79k
      bfd_size_type amt = opt_hdr_size;
1572
4.79k
      bfd_byte *opthdr;
1573
1574
      /* PR 17521 file: 230-131433-0.004.  */
1575
4.79k
      if (amt < sizeof (PEAOUTHDR))
1576
4.07k
  amt = sizeof (PEAOUTHDR);
1577
1578
4.79k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1579
4.79k
      if (opthdr == NULL)
1580
40
  return NULL;
1581
4.75k
      if (amt > opt_hdr_size)
1582
4.04k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1583
1584
4.75k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1585
1586
4.75k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1587
1588
#ifdef ARM
1589
      /* Use Subsystem to distinguish between pei-arm-little and
1590
   pei-arm-wince-little.  */
1591
#ifdef WINCE
1592
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1593
#else
1594
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1595
#endif
1596
  {
1597
    bfd_set_error (bfd_error_wrong_format);
1598
    return NULL;
1599
  }
1600
#endif
1601
1602
4.75k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1603
2.61k
    || a->SectionAlignment >= 0x80000000)
1604
2.20k
  {
1605
2.20k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1606
2.20k
            abfd);
1607
2.20k
    a->SectionAlignment &= -a->SectionAlignment;
1608
2.20k
    if (a->SectionAlignment >= 0x80000000)
1609
67
      a->SectionAlignment = 0x40000000;
1610
2.20k
  }
1611
1612
4.75k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1613
2.58k
    || a->FileAlignment > a->SectionAlignment)
1614
2.60k
  {
1615
2.60k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1616
2.60k
            abfd);
1617
2.60k
    a->FileAlignment &= -a->FileAlignment;
1618
2.60k
    if (a->FileAlignment > a->SectionAlignment)
1619
1.68k
      a->FileAlignment = a->SectionAlignment;
1620
2.60k
  }
1621
1622
4.75k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1623
2.25k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1624
4.75k
    }
1625
1626
9.69k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1627
9.69k
             (opt_hdr_size != 0
1628
9.69k
        ? &internal_a
1629
9.69k
        : (struct internal_aouthdr *) NULL));
1630
1631
9.69k
  if (result)
1632
8.42k
    {
1633
      /* Now the whole header has been processed, see if there is a build-id */
1634
8.42k
      pe_bfd_read_buildid(abfd);
1635
8.42k
    }
1636
1637
9.69k
  return result;
1638
9.73k
}
pei-x86_64.c:pe_bfd_object_p
Line
Count
Source
1488
211k
{
1489
211k
  bfd_byte buffer[6];
1490
211k
  struct external_DOS_hdr dos_hdr;
1491
211k
  struct external_PEI_IMAGE_hdr image_hdr;
1492
211k
  struct internal_filehdr internal_f;
1493
211k
  struct internal_aouthdr internal_a;
1494
211k
  bfd_size_type opt_hdr_size;
1495
211k
  file_ptr offset;
1496
211k
  bfd_cleanup result;
1497
1498
  /* Detect if this a Microsoft Import Library Format element.  */
1499
  /* First read the beginning of the header.  */
1500
211k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1501
211k
      || bfd_read (buffer, 6, abfd) != 6)
1502
1.79k
    {
1503
1.79k
      if (bfd_get_error () != bfd_error_system_call)
1504
1.60k
  bfd_set_error (bfd_error_wrong_format);
1505
1.79k
      return NULL;
1506
1.79k
    }
1507
1508
  /* Then check the magic and the version (only 0 is supported).  */
1509
209k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1510
4.80k
      && H_GET_16 (abfd, buffer + 4) == 0)
1511
3.94k
    return pe_ILF_object_p (abfd);
1512
1513
205k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1514
205k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1515
42.1k
    {
1516
42.1k
      if (bfd_get_error () != bfd_error_system_call)
1517
42.1k
  bfd_set_error (bfd_error_wrong_format);
1518
42.1k
      return NULL;
1519
42.1k
    }
1520
1521
  /* There are really two magic numbers involved; the magic number
1522
     that says this is a NT executable (PEI) and the magic number that
1523
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1524
     the e_magic field.  The latter is stored in the f_magic field.
1525
     If the NT magic number isn't valid, the architecture magic number
1526
     could be mimicked by some other field (specifically, the number
1527
     of relocs in section 3).  Since this routine can only be called
1528
     correctly for a PEI file, check the e_magic number here, and, if
1529
     it doesn't match, clobber the f_magic number so that we don't get
1530
     a false match.  */
1531
163k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1532
109k
    {
1533
109k
      bfd_set_error (bfd_error_wrong_format);
1534
109k
      return NULL;
1535
109k
    }
1536
1537
54.2k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1538
54.2k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1539
54.2k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1540
176
    {
1541
176
      if (bfd_get_error () != bfd_error_system_call)
1542
176
  bfd_set_error (bfd_error_wrong_format);
1543
176
      return NULL;
1544
176
    }
1545
1546
54.0k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1547
426
    {
1548
426
      bfd_set_error (bfd_error_wrong_format);
1549
426
      return NULL;
1550
426
    }
1551
1552
  /* Swap file header, so that we get the location for calling
1553
     real_object_p.  */
1554
53.6k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1555
1556
53.6k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1557
8.03k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1558
45.6k
    {
1559
45.6k
      bfd_set_error (bfd_error_wrong_format);
1560
45.6k
      return NULL;
1561
45.6k
    }
1562
1563
8.00k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1564
8.00k
    sizeof (internal_f.pe.dos_message));
1565
1566
  /* Read the optional header, which has variable size.  */
1567
8.00k
  opt_hdr_size = internal_f.f_opthdr;
1568
1569
8.00k
  if (opt_hdr_size != 0)
1570
4.80k
    {
1571
4.80k
      bfd_size_type amt = opt_hdr_size;
1572
4.80k
      bfd_byte *opthdr;
1573
1574
      /* PR 17521 file: 230-131433-0.004.  */
1575
4.80k
      if (amt < sizeof (PEAOUTHDR))
1576
4.46k
  amt = sizeof (PEAOUTHDR);
1577
1578
4.80k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1579
4.80k
      if (opthdr == NULL)
1580
32
  return NULL;
1581
4.76k
      if (amt > opt_hdr_size)
1582
4.44k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1583
1584
4.76k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1585
1586
4.76k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1587
1588
#ifdef ARM
1589
      /* Use Subsystem to distinguish between pei-arm-little and
1590
   pei-arm-wince-little.  */
1591
#ifdef WINCE
1592
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1593
#else
1594
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1595
#endif
1596
  {
1597
    bfd_set_error (bfd_error_wrong_format);
1598
    return NULL;
1599
  }
1600
#endif
1601
1602
4.76k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1603
2.56k
    || a->SectionAlignment >= 0x80000000)
1604
2.24k
  {
1605
2.24k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1606
2.24k
            abfd);
1607
2.24k
    a->SectionAlignment &= -a->SectionAlignment;
1608
2.24k
    if (a->SectionAlignment >= 0x80000000)
1609
41
      a->SectionAlignment = 0x40000000;
1610
2.24k
  }
1611
1612
4.76k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1613
2.24k
    || a->FileAlignment > a->SectionAlignment)
1614
3.00k
  {
1615
3.00k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1616
3.00k
            abfd);
1617
3.00k
    a->FileAlignment &= -a->FileAlignment;
1618
3.00k
    if (a->FileAlignment > a->SectionAlignment)
1619
1.59k
      a->FileAlignment = a->SectionAlignment;
1620
3.00k
  }
1621
1622
4.76k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1623
2.54k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1624
4.76k
    }
1625
1626
7.97k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1627
7.97k
             (opt_hdr_size != 0
1628
7.97k
        ? &internal_a
1629
7.97k
        : (struct internal_aouthdr *) NULL));
1630
1631
7.97k
  if (result)
1632
6.28k
    {
1633
      /* Now the whole header has been processed, see if there is a build-id */
1634
6.28k
      pe_bfd_read_buildid(abfd);
1635
6.28k
    }
1636
1637
7.97k
  return result;
1638
8.00k
}
pei-aarch64.c:pe_bfd_object_p
Line
Count
Source
1488
209k
{
1489
209k
  bfd_byte buffer[6];
1490
209k
  struct external_DOS_hdr dos_hdr;
1491
209k
  struct external_PEI_IMAGE_hdr image_hdr;
1492
209k
  struct internal_filehdr internal_f;
1493
209k
  struct internal_aouthdr internal_a;
1494
209k
  bfd_size_type opt_hdr_size;
1495
209k
  file_ptr offset;
1496
209k
  bfd_cleanup result;
1497
1498
  /* Detect if this a Microsoft Import Library Format element.  */
1499
  /* First read the beginning of the header.  */
1500
209k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1501
209k
      || bfd_read (buffer, 6, abfd) != 6)
1502
1.79k
    {
1503
1.79k
      if (bfd_get_error () != bfd_error_system_call)
1504
1.60k
  bfd_set_error (bfd_error_wrong_format);
1505
1.79k
      return NULL;
1506
1.79k
    }
1507
1508
  /* Then check the magic and the version (only 0 is supported).  */
1509
207k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1510
4.84k
      && H_GET_16 (abfd, buffer + 4) == 0)
1511
3.98k
    return pe_ILF_object_p (abfd);
1512
1513
203k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1514
203k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1515
42.1k
    {
1516
42.1k
      if (bfd_get_error () != bfd_error_system_call)
1517
42.1k
  bfd_set_error (bfd_error_wrong_format);
1518
42.1k
      return NULL;
1519
42.1k
    }
1520
1521
  /* There are really two magic numbers involved; the magic number
1522
     that says this is a NT executable (PEI) and the magic number that
1523
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1524
     the e_magic field.  The latter is stored in the f_magic field.
1525
     If the NT magic number isn't valid, the architecture magic number
1526
     could be mimicked by some other field (specifically, the number
1527
     of relocs in section 3).  Since this routine can only be called
1528
     correctly for a PEI file, check the e_magic number here, and, if
1529
     it doesn't match, clobber the f_magic number so that we don't get
1530
     a false match.  */
1531
161k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1532
107k
    {
1533
107k
      bfd_set_error (bfd_error_wrong_format);
1534
107k
      return NULL;
1535
107k
    }
1536
1537
54.1k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1538
54.1k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1539
54.1k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1540
800
    {
1541
800
      if (bfd_get_error () != bfd_error_system_call)
1542
800
  bfd_set_error (bfd_error_wrong_format);
1543
800
      return NULL;
1544
800
    }
1545
1546
53.3k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1547
1.21k
    {
1548
1.21k
      bfd_set_error (bfd_error_wrong_format);
1549
1.21k
      return NULL;
1550
1.21k
    }
1551
1552
  /* Swap file header, so that we get the location for calling
1553
     real_object_p.  */
1554
52.1k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1555
1556
52.1k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1557
8.78k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1558
43.3k
    {
1559
43.3k
      bfd_set_error (bfd_error_wrong_format);
1560
43.3k
      return NULL;
1561
43.3k
    }
1562
1563
8.77k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1564
8.77k
    sizeof (internal_f.pe.dos_message));
1565
1566
  /* Read the optional header, which has variable size.  */
1567
8.77k
  opt_hdr_size = internal_f.f_opthdr;
1568
1569
8.77k
  if (opt_hdr_size != 0)
1570
6.51k
    {
1571
6.51k
      bfd_size_type amt = opt_hdr_size;
1572
6.51k
      bfd_byte *opthdr;
1573
1574
      /* PR 17521 file: 230-131433-0.004.  */
1575
6.51k
      if (amt < sizeof (PEAOUTHDR))
1576
6.28k
  amt = sizeof (PEAOUTHDR);
1577
1578
6.51k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1579
6.51k
      if (opthdr == NULL)
1580
35
  return NULL;
1581
6.48k
      if (amt > opt_hdr_size)
1582
6.25k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1583
1584
6.48k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1585
1586
6.48k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1587
1588
#ifdef ARM
1589
      /* Use Subsystem to distinguish between pei-arm-little and
1590
   pei-arm-wince-little.  */
1591
#ifdef WINCE
1592
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1593
#else
1594
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1595
#endif
1596
  {
1597
    bfd_set_error (bfd_error_wrong_format);
1598
    return NULL;
1599
  }
1600
#endif
1601
1602
6.48k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1603
2.17k
    || a->SectionAlignment >= 0x80000000)
1604
4.33k
  {
1605
4.33k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1606
4.33k
            abfd);
1607
4.33k
    a->SectionAlignment &= -a->SectionAlignment;
1608
4.33k
    if (a->SectionAlignment >= 0x80000000)
1609
28
      a->SectionAlignment = 0x40000000;
1610
4.33k
  }
1611
1612
6.48k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1613
4.38k
    || a->FileAlignment > a->SectionAlignment)
1614
4.93k
  {
1615
4.93k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1616
4.93k
            abfd);
1617
4.93k
    a->FileAlignment &= -a->FileAlignment;
1618
4.93k
    if (a->FileAlignment > a->SectionAlignment)
1619
4.04k
      a->FileAlignment = a->SectionAlignment;
1620
4.93k
  }
1621
1622
6.48k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1623
2.73k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1624
6.48k
    }
1625
1626
8.73k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1627
8.73k
             (opt_hdr_size != 0
1628
8.73k
        ? &internal_a
1629
8.73k
        : (struct internal_aouthdr *) NULL));
1630
1631
8.73k
  if (result)
1632
6.63k
    {
1633
      /* Now the whole header has been processed, see if there is a build-id */
1634
6.63k
      pe_bfd_read_buildid(abfd);
1635
6.63k
    }
1636
1637
8.73k
  return result;
1638
8.77k
}
pei-ia64.c:pe_bfd_object_p
Line
Count
Source
1488
16.3k
{
1489
16.3k
  bfd_byte buffer[6];
1490
16.3k
  struct external_DOS_hdr dos_hdr;
1491
16.3k
  struct external_PEI_IMAGE_hdr image_hdr;
1492
16.3k
  struct internal_filehdr internal_f;
1493
16.3k
  struct internal_aouthdr internal_a;
1494
16.3k
  bfd_size_type opt_hdr_size;
1495
16.3k
  file_ptr offset;
1496
16.3k
  bfd_cleanup result;
1497
1498
  /* Detect if this a Microsoft Import Library Format element.  */
1499
  /* First read the beginning of the header.  */
1500
16.3k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1501
16.3k
      || bfd_read (buffer, 6, abfd) != 6)
1502
0
    {
1503
0
      if (bfd_get_error () != bfd_error_system_call)
1504
0
  bfd_set_error (bfd_error_wrong_format);
1505
0
      return NULL;
1506
0
    }
1507
1508
  /* Then check the magic and the version (only 0 is supported).  */
1509
16.3k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1510
0
      && H_GET_16 (abfd, buffer + 4) == 0)
1511
0
    return pe_ILF_object_p (abfd);
1512
1513
16.3k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1514
16.3k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1515
0
    {
1516
0
      if (bfd_get_error () != bfd_error_system_call)
1517
0
  bfd_set_error (bfd_error_wrong_format);
1518
0
      return NULL;
1519
0
    }
1520
1521
  /* There are really two magic numbers involved; the magic number
1522
     that says this is a NT executable (PEI) and the magic number that
1523
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1524
     the e_magic field.  The latter is stored in the f_magic field.
1525
     If the NT magic number isn't valid, the architecture magic number
1526
     could be mimicked by some other field (specifically, the number
1527
     of relocs in section 3).  Since this routine can only be called
1528
     correctly for a PEI file, check the e_magic number here, and, if
1529
     it doesn't match, clobber the f_magic number so that we don't get
1530
     a false match.  */
1531
16.3k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1532
0
    {
1533
0
      bfd_set_error (bfd_error_wrong_format);
1534
0
      return NULL;
1535
0
    }
1536
1537
16.3k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1538
16.3k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1539
16.3k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1540
0
    {
1541
0
      if (bfd_get_error () != bfd_error_system_call)
1542
0
  bfd_set_error (bfd_error_wrong_format);
1543
0
      return NULL;
1544
0
    }
1545
1546
16.3k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1547
0
    {
1548
0
      bfd_set_error (bfd_error_wrong_format);
1549
0
      return NULL;
1550
0
    }
1551
1552
  /* Swap file header, so that we get the location for calling
1553
     real_object_p.  */
1554
16.3k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1555
1556
16.3k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1557
6.44k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1558
9.89k
    {
1559
9.89k
      bfd_set_error (bfd_error_wrong_format);
1560
9.89k
      return NULL;
1561
9.89k
    }
1562
1563
6.41k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1564
6.41k
    sizeof (internal_f.pe.dos_message));
1565
1566
  /* Read the optional header, which has variable size.  */
1567
6.41k
  opt_hdr_size = internal_f.f_opthdr;
1568
1569
6.41k
  if (opt_hdr_size != 0)
1570
2.76k
    {
1571
2.76k
      bfd_size_type amt = opt_hdr_size;
1572
2.76k
      bfd_byte *opthdr;
1573
1574
      /* PR 17521 file: 230-131433-0.004.  */
1575
2.76k
      if (amt < sizeof (PEAOUTHDR))
1576
2.62k
  amt = sizeof (PEAOUTHDR);
1577
1578
2.76k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1579
2.76k
      if (opthdr == NULL)
1580
42
  return NULL;
1581
2.72k
      if (amt > opt_hdr_size)
1582
2.59k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1583
1584
2.72k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1585
1586
2.72k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1587
1588
#ifdef ARM
1589
      /* Use Subsystem to distinguish between pei-arm-little and
1590
   pei-arm-wince-little.  */
1591
#ifdef WINCE
1592
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1593
#else
1594
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1595
#endif
1596
  {
1597
    bfd_set_error (bfd_error_wrong_format);
1598
    return NULL;
1599
  }
1600
#endif
1601
1602
2.72k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1603
1.19k
    || a->SectionAlignment >= 0x80000000)
1604
1.55k
  {
1605
1.55k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1606
1.55k
            abfd);
1607
1.55k
    a->SectionAlignment &= -a->SectionAlignment;
1608
1.55k
    if (a->SectionAlignment >= 0x80000000)
1609
35
      a->SectionAlignment = 0x40000000;
1610
1.55k
  }
1611
1612
2.72k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1613
1.21k
    || a->FileAlignment > a->SectionAlignment)
1614
1.89k
  {
1615
1.89k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1616
1.89k
            abfd);
1617
1.89k
    a->FileAlignment &= -a->FileAlignment;
1618
1.89k
    if (a->FileAlignment > a->SectionAlignment)
1619
989
      a->FileAlignment = a->SectionAlignment;
1620
1.89k
  }
1621
1622
2.72k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1623
1.65k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1624
2.72k
    }
1625
1626
6.37k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1627
6.37k
             (opt_hdr_size != 0
1628
6.37k
        ? &internal_a
1629
6.37k
        : (struct internal_aouthdr *) NULL));
1630
1631
6.37k
  if (result)
1632
4.15k
    {
1633
      /* Now the whole header has been processed, see if there is a build-id */
1634
4.15k
      pe_bfd_read_buildid(abfd);
1635
4.15k
    }
1636
1637
6.37k
  return result;
1638
6.41k
}
pei-loongarch64.c:pe_bfd_object_p
Line
Count
Source
1488
209k
{
1489
209k
  bfd_byte buffer[6];
1490
209k
  struct external_DOS_hdr dos_hdr;
1491
209k
  struct external_PEI_IMAGE_hdr image_hdr;
1492
209k
  struct internal_filehdr internal_f;
1493
209k
  struct internal_aouthdr internal_a;
1494
209k
  bfd_size_type opt_hdr_size;
1495
209k
  file_ptr offset;
1496
209k
  bfd_cleanup result;
1497
1498
  /* Detect if this a Microsoft Import Library Format element.  */
1499
  /* First read the beginning of the header.  */
1500
209k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1501
209k
      || bfd_read (buffer, 6, abfd) != 6)
1502
1.79k
    {
1503
1.79k
      if (bfd_get_error () != bfd_error_system_call)
1504
1.60k
  bfd_set_error (bfd_error_wrong_format);
1505
1.79k
      return NULL;
1506
1.79k
    }
1507
1508
  /* Then check the magic and the version (only 0 is supported).  */
1509
207k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1510
4.78k
      && H_GET_16 (abfd, buffer + 4) == 0)
1511
3.93k
    return pe_ILF_object_p (abfd);
1512
1513
203k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1514
203k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1515
42.1k
    {
1516
42.1k
      if (bfd_get_error () != bfd_error_system_call)
1517
42.1k
  bfd_set_error (bfd_error_wrong_format);
1518
42.1k
      return NULL;
1519
42.1k
    }
1520
1521
  /* There are really two magic numbers involved; the magic number
1522
     that says this is a NT executable (PEI) and the magic number that
1523
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1524
     the e_magic field.  The latter is stored in the f_magic field.
1525
     If the NT magic number isn't valid, the architecture magic number
1526
     could be mimicked by some other field (specifically, the number
1527
     of relocs in section 3).  Since this routine can only be called
1528
     correctly for a PEI file, check the e_magic number here, and, if
1529
     it doesn't match, clobber the f_magic number so that we don't get
1530
     a false match.  */
1531
161k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1532
109k
    {
1533
109k
      bfd_set_error (bfd_error_wrong_format);
1534
109k
      return NULL;
1535
109k
    }
1536
1537
52.2k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1538
52.2k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1539
52.2k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1540
176
    {
1541
176
      if (bfd_get_error () != bfd_error_system_call)
1542
176
  bfd_set_error (bfd_error_wrong_format);
1543
176
      return NULL;
1544
176
    }
1545
1546
52.0k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1547
426
    {
1548
426
      bfd_set_error (bfd_error_wrong_format);
1549
426
      return NULL;
1550
426
    }
1551
1552
  /* Swap file header, so that we get the location for calling
1553
     real_object_p.  */
1554
51.6k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1555
1556
51.6k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1557
5.87k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1558
45.7k
    {
1559
45.7k
      bfd_set_error (bfd_error_wrong_format);
1560
45.7k
      return NULL;
1561
45.7k
    }
1562
1563
5.86k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1564
5.86k
    sizeof (internal_f.pe.dos_message));
1565
1566
  /* Read the optional header, which has variable size.  */
1567
5.86k
  opt_hdr_size = internal_f.f_opthdr;
1568
1569
5.86k
  if (opt_hdr_size != 0)
1570
3.57k
    {
1571
3.57k
      bfd_size_type amt = opt_hdr_size;
1572
3.57k
      bfd_byte *opthdr;
1573
1574
      /* PR 17521 file: 230-131433-0.004.  */
1575
3.57k
      if (amt < sizeof (PEAOUTHDR))
1576
3.27k
  amt = sizeof (PEAOUTHDR);
1577
1578
3.57k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1579
3.57k
      if (opthdr == NULL)
1580
33
  return NULL;
1581
3.53k
      if (amt > opt_hdr_size)
1582
3.25k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1583
1584
3.53k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1585
1586
3.53k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1587
1588
#ifdef ARM
1589
      /* Use Subsystem to distinguish between pei-arm-little and
1590
   pei-arm-wince-little.  */
1591
#ifdef WINCE
1592
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1593
#else
1594
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1595
#endif
1596
  {
1597
    bfd_set_error (bfd_error_wrong_format);
1598
    return NULL;
1599
  }
1600
#endif
1601
1602
3.53k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1603
2.04k
    || a->SectionAlignment >= 0x80000000)
1604
1.51k
  {
1605
1.51k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1606
1.51k
            abfd);
1607
1.51k
    a->SectionAlignment &= -a->SectionAlignment;
1608
1.51k
    if (a->SectionAlignment >= 0x80000000)
1609
30
      a->SectionAlignment = 0x40000000;
1610
1.51k
  }
1611
1612
3.53k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1613
1.70k
    || a->FileAlignment > a->SectionAlignment)
1614
2.15k
  {
1615
2.15k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1616
2.15k
            abfd);
1617
2.15k
    a->FileAlignment &= -a->FileAlignment;
1618
2.15k
    if (a->FileAlignment > a->SectionAlignment)
1619
1.39k
      a->FileAlignment = a->SectionAlignment;
1620
2.15k
  }
1621
1622
3.53k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1623
1.84k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1624
3.53k
    }
1625
1626
5.83k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1627
5.83k
             (opt_hdr_size != 0
1628
5.83k
        ? &internal_a
1629
5.83k
        : (struct internal_aouthdr *) NULL));
1630
1631
5.83k
  if (result)
1632
3.68k
    {
1633
      /* Now the whole header has been processed, see if there is a build-id */
1634
3.68k
      pe_bfd_read_buildid(abfd);
1635
3.68k
    }
1636
1637
5.83k
  return result;
1638
5.86k
}
pei-riscv64.c:pe_bfd_object_p
Line
Count
Source
1488
209k
{
1489
209k
  bfd_byte buffer[6];
1490
209k
  struct external_DOS_hdr dos_hdr;
1491
209k
  struct external_PEI_IMAGE_hdr image_hdr;
1492
209k
  struct internal_filehdr internal_f;
1493
209k
  struct internal_aouthdr internal_a;
1494
209k
  bfd_size_type opt_hdr_size;
1495
209k
  file_ptr offset;
1496
209k
  bfd_cleanup result;
1497
1498
  /* Detect if this a Microsoft Import Library Format element.  */
1499
  /* First read the beginning of the header.  */
1500
209k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1501
209k
      || bfd_read (buffer, 6, abfd) != 6)
1502
1.79k
    {
1503
1.79k
      if (bfd_get_error () != bfd_error_system_call)
1504
1.60k
  bfd_set_error (bfd_error_wrong_format);
1505
1.79k
      return NULL;
1506
1.79k
    }
1507
1508
  /* Then check the magic and the version (only 0 is supported).  */
1509
207k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1510
4.83k
      && H_GET_16 (abfd, buffer + 4) == 0)
1511
3.97k
    return pe_ILF_object_p (abfd);
1512
1513
203k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1514
203k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1515
42.1k
    {
1516
42.1k
      if (bfd_get_error () != bfd_error_system_call)
1517
42.1k
  bfd_set_error (bfd_error_wrong_format);
1518
42.1k
      return NULL;
1519
42.1k
    }
1520
1521
  /* There are really two magic numbers involved; the magic number
1522
     that says this is a NT executable (PEI) and the magic number that
1523
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1524
     the e_magic field.  The latter is stored in the f_magic field.
1525
     If the NT magic number isn't valid, the architecture magic number
1526
     could be mimicked by some other field (specifically, the number
1527
     of relocs in section 3).  Since this routine can only be called
1528
     correctly for a PEI file, check the e_magic number here, and, if
1529
     it doesn't match, clobber the f_magic number so that we don't get
1530
     a false match.  */
1531
161k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1532
109k
    {
1533
109k
      bfd_set_error (bfd_error_wrong_format);
1534
109k
      return NULL;
1535
109k
    }
1536
1537
52.2k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1538
52.2k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1539
52.2k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1540
176
    {
1541
176
      if (bfd_get_error () != bfd_error_system_call)
1542
176
  bfd_set_error (bfd_error_wrong_format);
1543
176
      return NULL;
1544
176
    }
1545
1546
52.0k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1547
426
    {
1548
426
      bfd_set_error (bfd_error_wrong_format);
1549
426
      return NULL;
1550
426
    }
1551
1552
  /* Swap file header, so that we get the location for calling
1553
     real_object_p.  */
1554
51.6k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1555
1556
51.6k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1557
6.13k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1558
45.5k
    {
1559
45.5k
      bfd_set_error (bfd_error_wrong_format);
1560
45.5k
      return NULL;
1561
45.5k
    }
1562
1563
6.12k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1564
6.12k
    sizeof (internal_f.pe.dos_message));
1565
1566
  /* Read the optional header, which has variable size.  */
1567
6.12k
  opt_hdr_size = internal_f.f_opthdr;
1568
1569
6.12k
  if (opt_hdr_size != 0)
1570
4.08k
    {
1571
4.08k
      bfd_size_type amt = opt_hdr_size;
1572
4.08k
      bfd_byte *opthdr;
1573
1574
      /* PR 17521 file: 230-131433-0.004.  */
1575
4.08k
      if (amt < sizeof (PEAOUTHDR))
1576
3.67k
  amt = sizeof (PEAOUTHDR);
1577
1578
4.08k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1579
4.08k
      if (opthdr == NULL)
1580
44
  return NULL;
1581
4.04k
      if (amt > opt_hdr_size)
1582
3.64k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1583
1584
4.04k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1585
1586
4.04k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1587
1588
#ifdef ARM
1589
      /* Use Subsystem to distinguish between pei-arm-little and
1590
   pei-arm-wince-little.  */
1591
#ifdef WINCE
1592
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1593
#else
1594
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1595
#endif
1596
  {
1597
    bfd_set_error (bfd_error_wrong_format);
1598
    return NULL;
1599
  }
1600
#endif
1601
1602
4.04k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1603
2.19k
    || a->SectionAlignment >= 0x80000000)
1604
1.88k
  {
1605
1.88k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1606
1.88k
            abfd);
1607
1.88k
    a->SectionAlignment &= -a->SectionAlignment;
1608
1.88k
    if (a->SectionAlignment >= 0x80000000)
1609
39
      a->SectionAlignment = 0x40000000;
1610
1.88k
  }
1611
1612
4.04k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1613
1.75k
    || a->FileAlignment > a->SectionAlignment)
1614
2.67k
  {
1615
2.67k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1616
2.67k
            abfd);
1617
2.67k
    a->FileAlignment &= -a->FileAlignment;
1618
2.67k
    if (a->FileAlignment > a->SectionAlignment)
1619
1.89k
      a->FileAlignment = a->SectionAlignment;
1620
2.67k
  }
1621
1622
4.04k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1623
2.22k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1624
4.04k
    }
1625
1626
6.08k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1627
6.08k
             (opt_hdr_size != 0
1628
6.08k
        ? &internal_a
1629
6.08k
        : (struct internal_aouthdr *) NULL));
1630
1631
6.08k
  if (result)
1632
3.88k
    {
1633
      /* Now the whole header has been processed, see if there is a build-id */
1634
3.88k
      pe_bfd_read_buildid(abfd);
1635
3.88k
    }
1636
1637
6.08k
  return result;
1638
6.12k
}
pei-arm-wince.c:pe_bfd_object_p
Line
Count
Source
1488
371k
{
1489
371k
  bfd_byte buffer[6];
1490
371k
  struct external_DOS_hdr dos_hdr;
1491
371k
  struct external_PEI_IMAGE_hdr image_hdr;
1492
371k
  struct internal_filehdr internal_f;
1493
371k
  struct internal_aouthdr internal_a;
1494
371k
  bfd_size_type opt_hdr_size;
1495
371k
  file_ptr offset;
1496
371k
  bfd_cleanup result;
1497
1498
  /* Detect if this a Microsoft Import Library Format element.  */
1499
  /* First read the beginning of the header.  */
1500
371k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1501
371k
      || bfd_read (buffer, 6, abfd) != 6)
1502
3.58k
    {
1503
3.58k
      if (bfd_get_error () != bfd_error_system_call)
1504
3.21k
  bfd_set_error (bfd_error_wrong_format);
1505
3.58k
      return NULL;
1506
3.58k
    }
1507
1508
  /* Then check the magic and the version (only 0 is supported).  */
1509
368k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1510
4.79k
      && H_GET_16 (abfd, buffer + 4) == 0)
1511
4.00k
    return pe_ILF_object_p (abfd);
1512
1513
364k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1514
364k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1515
80.6k
    {
1516
80.6k
      if (bfd_get_error () != bfd_error_system_call)
1517
80.6k
  bfd_set_error (bfd_error_wrong_format);
1518
80.6k
      return NULL;
1519
80.6k
    }
1520
1521
  /* There are really two magic numbers involved; the magic number
1522
     that says this is a NT executable (PEI) and the magic number that
1523
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1524
     the e_magic field.  The latter is stored in the f_magic field.
1525
     If the NT magic number isn't valid, the architecture magic number
1526
     could be mimicked by some other field (specifically, the number
1527
     of relocs in section 3).  Since this routine can only be called
1528
     correctly for a PEI file, check the e_magic number here, and, if
1529
     it doesn't match, clobber the f_magic number so that we don't get
1530
     a false match.  */
1531
283k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1532
231k
    {
1533
231k
      bfd_set_error (bfd_error_wrong_format);
1534
231k
      return NULL;
1535
231k
    }
1536
1537
51.7k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1538
51.7k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1539
51.7k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1540
748
    {
1541
748
      if (bfd_get_error () != bfd_error_system_call)
1542
748
  bfd_set_error (bfd_error_wrong_format);
1543
748
      return NULL;
1544
748
    }
1545
1546
51.0k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1547
1.11k
    {
1548
1.11k
      bfd_set_error (bfd_error_wrong_format);
1549
1.11k
      return NULL;
1550
1.11k
    }
1551
1552
  /* Swap file header, so that we get the location for calling
1553
     real_object_p.  */
1554
49.9k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1555
1556
49.9k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1557
8.10k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1558
41.8k
    {
1559
41.8k
      bfd_set_error (bfd_error_wrong_format);
1560
41.8k
      return NULL;
1561
41.8k
    }
1562
1563
8.05k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1564
8.05k
    sizeof (internal_f.pe.dos_message));
1565
1566
  /* Read the optional header, which has variable size.  */
1567
8.05k
  opt_hdr_size = internal_f.f_opthdr;
1568
1569
8.05k
  if (opt_hdr_size != 0)
1570
4.83k
    {
1571
4.83k
      bfd_size_type amt = opt_hdr_size;
1572
4.83k
      bfd_byte *opthdr;
1573
1574
      /* PR 17521 file: 230-131433-0.004.  */
1575
4.83k
      if (amt < sizeof (PEAOUTHDR))
1576
4.43k
  amt = sizeof (PEAOUTHDR);
1577
1578
4.83k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1579
4.83k
      if (opthdr == NULL)
1580
52
  return NULL;
1581
4.78k
      if (amt > opt_hdr_size)
1582
4.39k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1583
1584
4.78k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1585
1586
4.78k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1587
1588
4.78k
#ifdef ARM
1589
      /* Use Subsystem to distinguish between pei-arm-little and
1590
   pei-arm-wince-little.  */
1591
4.78k
#ifdef WINCE
1592
4.78k
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1593
#else
1594
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1595
#endif
1596
2.78k
  {
1597
2.78k
    bfd_set_error (bfd_error_wrong_format);
1598
2.78k
    return NULL;
1599
2.78k
  }
1600
2.00k
#endif
1601
1602
2.00k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1603
426
    || a->SectionAlignment >= 0x80000000)
1604
1.60k
  {
1605
1.60k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1606
1.60k
            abfd);
1607
1.60k
    a->SectionAlignment &= -a->SectionAlignment;
1608
1.60k
    if (a->SectionAlignment >= 0x80000000)
1609
29
      a->SectionAlignment = 0x40000000;
1610
1.60k
  }
1611
1612
2.00k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1613
534
    || a->FileAlignment > a->SectionAlignment)
1614
1.77k
  {
1615
1.77k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1616
1.77k
            abfd);
1617
1.77k
    a->FileAlignment &= -a->FileAlignment;
1618
1.77k
    if (a->FileAlignment > a->SectionAlignment)
1619
1.35k
      a->FileAlignment = a->SectionAlignment;
1620
1.77k
  }
1621
1622
2.00k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1623
1.46k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1624
2.00k
    }
1625
1626
5.22k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1627
5.22k
             (opt_hdr_size != 0
1628
5.22k
        ? &internal_a
1629
5.22k
        : (struct internal_aouthdr *) NULL));
1630
1631
5.22k
  if (result)
1632
2.29k
    {
1633
      /* Now the whole header has been processed, see if there is a build-id */
1634
2.29k
      pe_bfd_read_buildid(abfd);
1635
2.29k
    }
1636
1637
5.22k
  return result;
1638
8.05k
}
pei-arm.c:pe_bfd_object_p
Line
Count
Source
1488
371k
{
1489
371k
  bfd_byte buffer[6];
1490
371k
  struct external_DOS_hdr dos_hdr;
1491
371k
  struct external_PEI_IMAGE_hdr image_hdr;
1492
371k
  struct internal_filehdr internal_f;
1493
371k
  struct internal_aouthdr internal_a;
1494
371k
  bfd_size_type opt_hdr_size;
1495
371k
  file_ptr offset;
1496
371k
  bfd_cleanup result;
1497
1498
  /* Detect if this a Microsoft Import Library Format element.  */
1499
  /* First read the beginning of the header.  */
1500
371k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1501
371k
      || bfd_read (buffer, 6, abfd) != 6)
1502
3.58k
    {
1503
3.58k
      if (bfd_get_error () != bfd_error_system_call)
1504
3.21k
  bfd_set_error (bfd_error_wrong_format);
1505
3.58k
      return NULL;
1506
3.58k
    }
1507
1508
  /* Then check the magic and the version (only 0 is supported).  */
1509
368k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1510
4.79k
      && H_GET_16 (abfd, buffer + 4) == 0)
1511
4.00k
    return pe_ILF_object_p (abfd);
1512
1513
364k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1514
364k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1515
80.6k
    {
1516
80.6k
      if (bfd_get_error () != bfd_error_system_call)
1517
80.6k
  bfd_set_error (bfd_error_wrong_format);
1518
80.6k
      return NULL;
1519
80.6k
    }
1520
1521
  /* There are really two magic numbers involved; the magic number
1522
     that says this is a NT executable (PEI) and the magic number that
1523
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1524
     the e_magic field.  The latter is stored in the f_magic field.
1525
     If the NT magic number isn't valid, the architecture magic number
1526
     could be mimicked by some other field (specifically, the number
1527
     of relocs in section 3).  Since this routine can only be called
1528
     correctly for a PEI file, check the e_magic number here, and, if
1529
     it doesn't match, clobber the f_magic number so that we don't get
1530
     a false match.  */
1531
283k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1532
231k
    {
1533
231k
      bfd_set_error (bfd_error_wrong_format);
1534
231k
      return NULL;
1535
231k
    }
1536
1537
52.0k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1538
52.0k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1539
52.0k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1540
748
    {
1541
748
      if (bfd_get_error () != bfd_error_system_call)
1542
748
  bfd_set_error (bfd_error_wrong_format);
1543
748
      return NULL;
1544
748
    }
1545
1546
51.3k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1547
1.11k
    {
1548
1.11k
      bfd_set_error (bfd_error_wrong_format);
1549
1.11k
      return NULL;
1550
1.11k
    }
1551
1552
  /* Swap file header, so that we get the location for calling
1553
     real_object_p.  */
1554
50.2k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1555
1556
50.2k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1557
8.39k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1558
41.8k
    {
1559
41.8k
      bfd_set_error (bfd_error_wrong_format);
1560
41.8k
      return NULL;
1561
41.8k
    }
1562
1563
8.34k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1564
8.34k
    sizeof (internal_f.pe.dos_message));
1565
1566
  /* Read the optional header, which has variable size.  */
1567
8.34k
  opt_hdr_size = internal_f.f_opthdr;
1568
1569
8.34k
  if (opt_hdr_size != 0)
1570
5.13k
    {
1571
5.13k
      bfd_size_type amt = opt_hdr_size;
1572
5.13k
      bfd_byte *opthdr;
1573
1574
      /* PR 17521 file: 230-131433-0.004.  */
1575
5.13k
      if (amt < sizeof (PEAOUTHDR))
1576
4.72k
  amt = sizeof (PEAOUTHDR);
1577
1578
5.13k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1579
5.13k
      if (opthdr == NULL)
1580
52
  return NULL;
1581
5.08k
      if (amt > opt_hdr_size)
1582
4.67k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1583
1584
5.08k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1585
1586
5.08k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1587
1588
5.08k
#ifdef ARM
1589
      /* Use Subsystem to distinguish between pei-arm-little and
1590
   pei-arm-wince-little.  */
1591
#ifdef WINCE
1592
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1593
#else
1594
5.08k
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1595
1.55k
#endif
1596
1.55k
  {
1597
1.55k
    bfd_set_error (bfd_error_wrong_format);
1598
1.55k
    return NULL;
1599
1.55k
  }
1600
3.52k
#endif
1601
1602
3.52k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1603
1.56k
    || a->SectionAlignment >= 0x80000000)
1604
1.99k
  {
1605
1.99k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1606
1.99k
            abfd);
1607
1.99k
    a->SectionAlignment &= -a->SectionAlignment;
1608
1.99k
    if (a->SectionAlignment >= 0x80000000)
1609
36
      a->SectionAlignment = 0x40000000;
1610
1.99k
  }
1611
1612
3.52k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1613
1.75k
    || a->FileAlignment > a->SectionAlignment)
1614
2.15k
  {
1615
2.15k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1616
2.15k
            abfd);
1617
2.15k
    a->FileAlignment &= -a->FileAlignment;
1618
2.15k
    if (a->FileAlignment > a->SectionAlignment)
1619
1.67k
      a->FileAlignment = a->SectionAlignment;
1620
2.15k
  }
1621
1622
3.52k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1623
1.83k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1624
3.52k
    }
1625
1626
6.74k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1627
6.74k
             (opt_hdr_size != 0
1628
6.74k
        ? &internal_a
1629
6.74k
        : (struct internal_aouthdr *) NULL));
1630
1631
6.74k
  if (result)
1632
3.52k
    {
1633
      /* Now the whole header has been processed, see if there is a build-id */
1634
3.52k
      pe_bfd_read_buildid(abfd);
1635
3.52k
    }
1636
1637
6.74k
  return result;
1638
8.34k
}
pei-mcore.c:pe_bfd_object_p
Line
Count
Source
1488
372k
{
1489
372k
  bfd_byte buffer[6];
1490
372k
  struct external_DOS_hdr dos_hdr;
1491
372k
  struct external_PEI_IMAGE_hdr image_hdr;
1492
372k
  struct internal_filehdr internal_f;
1493
372k
  struct internal_aouthdr internal_a;
1494
372k
  bfd_size_type opt_hdr_size;
1495
372k
  file_ptr offset;
1496
372k
  bfd_cleanup result;
1497
1498
  /* Detect if this a Microsoft Import Library Format element.  */
1499
  /* First read the beginning of the header.  */
1500
372k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1501
372k
      || bfd_read (buffer, 6, abfd) != 6)
1502
3.58k
    {
1503
3.58k
      if (bfd_get_error () != bfd_error_system_call)
1504
3.21k
  bfd_set_error (bfd_error_wrong_format);
1505
3.58k
      return NULL;
1506
3.58k
    }
1507
1508
  /* Then check the magic and the version (only 0 is supported).  */
1509
368k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1510
4.78k
      && H_GET_16 (abfd, buffer + 4) == 0)
1511
4.00k
    return pe_ILF_object_p (abfd);
1512
1513
364k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1514
364k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1515
80.7k
    {
1516
80.7k
      if (bfd_get_error () != bfd_error_system_call)
1517
80.7k
  bfd_set_error (bfd_error_wrong_format);
1518
80.7k
      return NULL;
1519
80.7k
    }
1520
1521
  /* There are really two magic numbers involved; the magic number
1522
     that says this is a NT executable (PEI) and the magic number that
1523
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1524
     the e_magic field.  The latter is stored in the f_magic field.
1525
     If the NT magic number isn't valid, the architecture magic number
1526
     could be mimicked by some other field (specifically, the number
1527
     of relocs in section 3).  Since this routine can only be called
1528
     correctly for a PEI file, check the e_magic number here, and, if
1529
     it doesn't match, clobber the f_magic number so that we don't get
1530
     a false match.  */
1531
283k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1532
233k
    {
1533
233k
      bfd_set_error (bfd_error_wrong_format);
1534
233k
      return NULL;
1535
233k
    }
1536
1537
50.4k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1538
50.4k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1539
50.4k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1540
174
    {
1541
174
      if (bfd_get_error () != bfd_error_system_call)
1542
174
  bfd_set_error (bfd_error_wrong_format);
1543
174
      return NULL;
1544
174
    }
1545
1546
50.3k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1547
426
    {
1548
426
      bfd_set_error (bfd_error_wrong_format);
1549
426
      return NULL;
1550
426
    }
1551
1552
  /* Swap file header, so that we get the location for calling
1553
     real_object_p.  */
1554
49.8k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1555
1556
49.8k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1557
5.16k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1558
44.7k
    {
1559
44.7k
      bfd_set_error (bfd_error_wrong_format);
1560
44.7k
      return NULL;
1561
44.7k
    }
1562
1563
5.15k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1564
5.15k
    sizeof (internal_f.pe.dos_message));
1565
1566
  /* Read the optional header, which has variable size.  */
1567
5.15k
  opt_hdr_size = internal_f.f_opthdr;
1568
1569
5.15k
  if (opt_hdr_size != 0)
1570
3.05k
    {
1571
3.05k
      bfd_size_type amt = opt_hdr_size;
1572
3.05k
      bfd_byte *opthdr;
1573
1574
      /* PR 17521 file: 230-131433-0.004.  */
1575
3.05k
      if (amt < sizeof (PEAOUTHDR))
1576
2.87k
  amt = sizeof (PEAOUTHDR);
1577
1578
3.05k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1579
3.05k
      if (opthdr == NULL)
1580
31
  return NULL;
1581
3.02k
      if (amt > opt_hdr_size)
1582
2.85k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1583
1584
3.02k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1585
1586
3.02k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1587
1588
#ifdef ARM
1589
      /* Use Subsystem to distinguish between pei-arm-little and
1590
   pei-arm-wince-little.  */
1591
#ifdef WINCE
1592
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1593
#else
1594
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1595
#endif
1596
  {
1597
    bfd_set_error (bfd_error_wrong_format);
1598
    return NULL;
1599
  }
1600
#endif
1601
1602
3.02k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1603
1.30k
    || a->SectionAlignment >= 0x80000000)
1604
1.75k
  {
1605
1.75k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1606
1.75k
            abfd);
1607
1.75k
    a->SectionAlignment &= -a->SectionAlignment;
1608
1.75k
    if (a->SectionAlignment >= 0x80000000)
1609
36
      a->SectionAlignment = 0x40000000;
1610
1.75k
  }
1611
1612
3.02k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1613
1.36k
    || a->FileAlignment > a->SectionAlignment)
1614
1.91k
  {
1615
1.91k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1616
1.91k
            abfd);
1617
1.91k
    a->FileAlignment &= -a->FileAlignment;
1618
1.91k
    if (a->FileAlignment > a->SectionAlignment)
1619
1.61k
      a->FileAlignment = a->SectionAlignment;
1620
1.91k
  }
1621
1622
3.02k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1623
1.70k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1624
3.02k
    }
1625
1626
5.12k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1627
5.12k
             (opt_hdr_size != 0
1628
5.12k
        ? &internal_a
1629
5.12k
        : (struct internal_aouthdr *) NULL));
1630
1631
5.12k
  if (result)
1632
3.38k
    {
1633
      /* Now the whole header has been processed, see if there is a build-id */
1634
3.38k
      pe_bfd_read_buildid(abfd);
1635
3.38k
    }
1636
1637
5.12k
  return result;
1638
5.15k
}
pei-sh.c:pe_bfd_object_p
Line
Count
Source
1488
187k
{
1489
187k
  bfd_byte buffer[6];
1490
187k
  struct external_DOS_hdr dos_hdr;
1491
187k
  struct external_PEI_IMAGE_hdr image_hdr;
1492
187k
  struct internal_filehdr internal_f;
1493
187k
  struct internal_aouthdr internal_a;
1494
187k
  bfd_size_type opt_hdr_size;
1495
187k
  file_ptr offset;
1496
187k
  bfd_cleanup result;
1497
1498
  /* Detect if this a Microsoft Import Library Format element.  */
1499
  /* First read the beginning of the header.  */
1500
187k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1501
187k
      || bfd_read (buffer, 6, abfd) != 6)
1502
1.78k
    {
1503
1.78k
      if (bfd_get_error () != bfd_error_system_call)
1504
1.60k
  bfd_set_error (bfd_error_wrong_format);
1505
1.78k
      return NULL;
1506
1.78k
    }
1507
1508
  /* Then check the magic and the version (only 0 is supported).  */
1509
186k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1510
4.77k
      && H_GET_16 (abfd, buffer + 4) == 0)
1511
3.99k
    return pe_ILF_object_p (abfd);
1512
1513
182k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1514
182k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1515
38.9k
    {
1516
38.9k
      if (bfd_get_error () != bfd_error_system_call)
1517
38.9k
  bfd_set_error (bfd_error_wrong_format);
1518
38.9k
      return NULL;
1519
38.9k
    }
1520
1521
  /* There are really two magic numbers involved; the magic number
1522
     that says this is a NT executable (PEI) and the magic number that
1523
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1524
     the e_magic field.  The latter is stored in the f_magic field.
1525
     If the NT magic number isn't valid, the architecture magic number
1526
     could be mimicked by some other field (specifically, the number
1527
     of relocs in section 3).  Since this routine can only be called
1528
     correctly for a PEI file, check the e_magic number here, and, if
1529
     it doesn't match, clobber the f_magic number so that we don't get
1530
     a false match.  */
1531
143k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1532
92.7k
    {
1533
92.7k
      bfd_set_error (bfd_error_wrong_format);
1534
92.7k
      return NULL;
1535
92.7k
    }
1536
1537
50.3k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1538
50.3k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1539
50.3k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1540
174
    {
1541
174
      if (bfd_get_error () != bfd_error_system_call)
1542
174
  bfd_set_error (bfd_error_wrong_format);
1543
174
      return NULL;
1544
174
    }
1545
1546
50.1k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1547
422
    {
1548
422
      bfd_set_error (bfd_error_wrong_format);
1549
422
      return NULL;
1550
422
    }
1551
1552
  /* Swap file header, so that we get the location for calling
1553
     real_object_p.  */
1554
49.7k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1555
1556
49.7k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1557
4.90k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1558
44.8k
    {
1559
44.8k
      bfd_set_error (bfd_error_wrong_format);
1560
44.8k
      return NULL;
1561
44.8k
    }
1562
1563
4.89k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1564
4.89k
    sizeof (internal_f.pe.dos_message));
1565
1566
  /* Read the optional header, which has variable size.  */
1567
4.89k
  opt_hdr_size = internal_f.f_opthdr;
1568
1569
4.89k
  if (opt_hdr_size != 0)
1570
2.86k
    {
1571
2.86k
      bfd_size_type amt = opt_hdr_size;
1572
2.86k
      bfd_byte *opthdr;
1573
1574
      /* PR 17521 file: 230-131433-0.004.  */
1575
2.86k
      if (amt < sizeof (PEAOUTHDR))
1576
2.68k
  amt = sizeof (PEAOUTHDR);
1577
1578
2.86k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1579
2.86k
      if (opthdr == NULL)
1580
35
  return NULL;
1581
2.82k
      if (amt > opt_hdr_size)
1582
2.65k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1583
1584
2.82k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1585
1586
2.82k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1587
1588
#ifdef ARM
1589
      /* Use Subsystem to distinguish between pei-arm-little and
1590
   pei-arm-wince-little.  */
1591
#ifdef WINCE
1592
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1593
#else
1594
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1595
#endif
1596
  {
1597
    bfd_set_error (bfd_error_wrong_format);
1598
    return NULL;
1599
  }
1600
#endif
1601
1602
2.82k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1603
1.47k
    || a->SectionAlignment >= 0x80000000)
1604
1.37k
  {
1605
1.37k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1606
1.37k
            abfd);
1607
1.37k
    a->SectionAlignment &= -a->SectionAlignment;
1608
1.37k
    if (a->SectionAlignment >= 0x80000000)
1609
19
      a->SectionAlignment = 0x40000000;
1610
1.37k
  }
1611
1612
2.82k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1613
1.58k
    || a->FileAlignment > a->SectionAlignment)
1614
1.60k
  {
1615
1.60k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1616
1.60k
            abfd);
1617
1.60k
    a->FileAlignment &= -a->FileAlignment;
1618
1.60k
    if (a->FileAlignment > a->SectionAlignment)
1619
1.23k
      a->FileAlignment = a->SectionAlignment;
1620
1.60k
  }
1621
1622
2.82k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1623
1.50k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1624
2.82k
    }
1625
1626
4.85k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1627
4.85k
             (opt_hdr_size != 0
1628
4.85k
        ? &internal_a
1629
4.85k
        : (struct internal_aouthdr *) NULL));
1630
1631
4.85k
  if (result)
1632
3.32k
    {
1633
      /* Now the whole header has been processed, see if there is a build-id */
1634
3.32k
      pe_bfd_read_buildid(abfd);
1635
3.32k
    }
1636
1637
4.85k
  return result;
1638
4.89k
}
1639
1640
16.3k
#define coff_object_p pe_bfd_object_p
1641
#endif /* COFF_IMAGE_WITH_PE */