Coverage Report

Created: 2026-03-10 08:46

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
51.8k
{
137
51.8k
  RELOC *reloc_src = (RELOC *) src;
138
51.8k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
51.8k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
51.8k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
51.8k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
#ifdef SWAP_IN_RELOC_OFFSET
144
23.7k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
#endif
146
51.8k
}
pei-i386.c:coff_swap_reloc_in
Line
Count
Source
136
3.56k
{
137
3.56k
  RELOC *reloc_src = (RELOC *) src;
138
3.56k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
3.56k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
3.56k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
3.56k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
#ifdef SWAP_IN_RELOC_OFFSET
144
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
#endif
146
3.56k
}
pe-x86_64.c:coff_swap_reloc_in
Line
Count
Source
136
2.23k
{
137
2.23k
  RELOC *reloc_src = (RELOC *) src;
138
2.23k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
2.23k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
2.23k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
2.23k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
#ifdef SWAP_IN_RELOC_OFFSET
144
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
#endif
146
2.23k
}
pei-x86_64.c:coff_swap_reloc_in
Line
Count
Source
136
3.87k
{
137
3.87k
  RELOC *reloc_src = (RELOC *) src;
138
3.87k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
3.87k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
3.87k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
3.87k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
#ifdef SWAP_IN_RELOC_OFFSET
144
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
#endif
146
3.87k
}
pe-aarch64.c:coff_swap_reloc_in
Line
Count
Source
136
2.33k
{
137
2.33k
  RELOC *reloc_src = (RELOC *) src;
138
2.33k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
2.33k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
2.33k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
2.33k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
#ifdef SWAP_IN_RELOC_OFFSET
144
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
#endif
146
2.33k
}
pei-aarch64.c:coff_swap_reloc_in
Line
Count
Source
136
3.92k
{
137
3.92k
  RELOC *reloc_src = (RELOC *) src;
138
3.92k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
3.92k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
3.92k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
3.92k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
#ifdef SWAP_IN_RELOC_OFFSET
144
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
#endif
146
3.92k
}
pei-ia64.c:coff_swap_reloc_in
Line
Count
Source
136
2.39k
{
137
2.39k
  RELOC *reloc_src = (RELOC *) src;
138
2.39k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
2.39k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
2.39k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
2.39k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
#ifdef SWAP_IN_RELOC_OFFSET
144
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
#endif
146
2.39k
}
pei-loongarch64.c:coff_swap_reloc_in
Line
Count
Source
136
2.40k
{
137
2.40k
  RELOC *reloc_src = (RELOC *) src;
138
2.40k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
2.40k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
2.40k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
2.40k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
2.40k
#ifdef SWAP_IN_RELOC_OFFSET
144
2.40k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
2.40k
#endif
146
2.40k
}
pei-riscv64.c:coff_swap_reloc_in
Line
Count
Source
136
3.59k
{
137
3.59k
  RELOC *reloc_src = (RELOC *) src;
138
3.59k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
3.59k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
3.59k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
3.59k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
3.59k
#ifdef SWAP_IN_RELOC_OFFSET
144
3.59k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
3.59k
#endif
146
3.59k
}
pe-arm-wince.c:coff_swap_reloc_in
Line
Count
Source
136
1.60k
{
137
1.60k
  RELOC *reloc_src = (RELOC *) src;
138
1.60k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
1.60k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
1.60k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
1.60k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
1.60k
#ifdef SWAP_IN_RELOC_OFFSET
144
1.60k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
1.60k
#endif
146
1.60k
}
pe-arm.c:coff_swap_reloc_in
Line
Count
Source
136
1.60k
{
137
1.60k
  RELOC *reloc_src = (RELOC *) src;
138
1.60k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
1.60k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
1.60k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
1.60k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
1.60k
#ifdef SWAP_IN_RELOC_OFFSET
144
1.60k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
1.60k
#endif
146
1.60k
}
pe-i386.c:coff_swap_reloc_in
Line
Count
Source
136
4.81k
{
137
4.81k
  RELOC *reloc_src = (RELOC *) src;
138
4.81k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
4.81k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
4.81k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
4.81k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
#ifdef SWAP_IN_RELOC_OFFSET
144
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
#endif
146
4.81k
}
pe-mcore.c:coff_swap_reloc_in
Line
Count
Source
136
2.38k
{
137
2.38k
  RELOC *reloc_src = (RELOC *) src;
138
2.38k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
2.38k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
2.38k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
2.38k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
2.38k
#ifdef SWAP_IN_RELOC_OFFSET
144
2.38k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
2.38k
#endif
146
2.38k
}
pe-sh.c:coff_swap_reloc_in
Line
Count
Source
136
2.64k
{
137
2.64k
  RELOC *reloc_src = (RELOC *) src;
138
2.64k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
2.64k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
2.64k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
2.64k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
#ifdef SWAP_IN_RELOC_OFFSET
144
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
#endif
146
2.64k
}
pei-arm-wince.c:coff_swap_reloc_in
Line
Count
Source
136
4.56k
{
137
4.56k
  RELOC *reloc_src = (RELOC *) src;
138
4.56k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
4.56k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
4.56k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
4.56k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
4.56k
#ifdef SWAP_IN_RELOC_OFFSET
144
4.56k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
4.56k
#endif
146
4.56k
}
pei-arm.c:coff_swap_reloc_in
Line
Count
Source
136
4.73k
{
137
4.73k
  RELOC *reloc_src = (RELOC *) src;
138
4.73k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
4.73k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
4.73k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
4.73k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
4.73k
#ifdef SWAP_IN_RELOC_OFFSET
144
4.73k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
4.73k
#endif
146
4.73k
}
pei-mcore.c:coff_swap_reloc_in
Line
Count
Source
136
2.86k
{
137
2.86k
  RELOC *reloc_src = (RELOC *) src;
138
2.86k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
2.86k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
2.86k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
2.86k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
2.86k
#ifdef SWAP_IN_RELOC_OFFSET
144
2.86k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
2.86k
#endif
146
2.86k
}
pei-sh.c:coff_swap_reloc_in
Line
Count
Source
136
2.34k
{
137
2.34k
  RELOC *reloc_src = (RELOC *) src;
138
2.34k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
2.34k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
2.34k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
2.34k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
#ifdef SWAP_IN_RELOC_OFFSET
144
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
#endif
146
2.34k
}
147
148
static unsigned int
149
coff_swap_reloc_out (bfd *abfd, void *src, void *dst)
150
108
{
151
108
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
152
108
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
153
154
108
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
155
108
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
156
108
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
157
158
#ifdef SWAP_OUT_RELOC_OFFSET
159
42
  SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
160
#endif
161
#ifdef SWAP_OUT_RELOC_EXTRA
162
  SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
163
#endif
164
108
  return RELSZ;
165
108
}
pei-i386.c:coff_swap_reloc_out
Line
Count
Source
150
13
{
151
13
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
152
13
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
153
154
13
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
155
13
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
156
13
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
157
158
#ifdef SWAP_OUT_RELOC_OFFSET
159
  SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
160
#endif
161
#ifdef SWAP_OUT_RELOC_EXTRA
162
  SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
163
#endif
164
13
  return RELSZ;
165
13
}
Unexecuted instantiation: pe-x86_64.c:coff_swap_reloc_out
pei-x86_64.c:coff_swap_reloc_out
Line
Count
Source
150
15
{
151
15
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
152
15
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
153
154
15
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
155
15
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
156
15
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
157
158
#ifdef SWAP_OUT_RELOC_OFFSET
159
  SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
160
#endif
161
#ifdef SWAP_OUT_RELOC_EXTRA
162
  SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
163
#endif
164
15
  return RELSZ;
165
15
}
Unexecuted instantiation: pe-aarch64.c:coff_swap_reloc_out
pei-aarch64.c:coff_swap_reloc_out
Line
Count
Source
150
29
{
151
29
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
152
29
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
153
154
29
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
155
29
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
156
29
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
157
158
#ifdef SWAP_OUT_RELOC_OFFSET
159
  SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
160
#endif
161
#ifdef SWAP_OUT_RELOC_EXTRA
162
  SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
163
#endif
164
29
  return RELSZ;
165
29
}
Unexecuted instantiation: pei-ia64.c:coff_swap_reloc_out
pei-loongarch64.c:coff_swap_reloc_out
Line
Count
Source
150
17
{
151
17
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
152
17
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
153
154
17
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
155
17
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
156
17
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
157
158
17
#ifdef SWAP_OUT_RELOC_OFFSET
159
17
  SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
160
17
#endif
161
#ifdef SWAP_OUT_RELOC_EXTRA
162
  SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
163
#endif
164
17
  return RELSZ;
165
17
}
pei-riscv64.c:coff_swap_reloc_out
Line
Count
Source
150
23
{
151
23
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
152
23
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
153
154
23
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
155
23
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
156
23
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
157
158
23
#ifdef SWAP_OUT_RELOC_OFFSET
159
23
  SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
160
23
#endif
161
#ifdef SWAP_OUT_RELOC_EXTRA
162
  SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
163
#endif
164
23
  return RELSZ;
165
23
}
Unexecuted instantiation: pe-arm-wince.c:coff_swap_reloc_out
Unexecuted instantiation: pe-arm.c:coff_swap_reloc_out
Unexecuted instantiation: pe-i386.c:coff_swap_reloc_out
pe-mcore.c:coff_swap_reloc_out
Line
Count
Source
150
1
{
151
1
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
152
1
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
153
154
1
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
155
1
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
156
1
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
157
158
1
#ifdef SWAP_OUT_RELOC_OFFSET
159
1
  SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
160
1
#endif
161
#ifdef SWAP_OUT_RELOC_EXTRA
162
  SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
163
#endif
164
1
  return RELSZ;
165
1
}
Unexecuted instantiation: pe-sh.c:coff_swap_reloc_out
Unexecuted instantiation: pei-arm-wince.c:coff_swap_reloc_out
pei-arm.c:coff_swap_reloc_out
Line
Count
Source
150
1
{
151
1
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
152
1
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
153
154
1
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
155
1
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
156
1
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
157
158
1
#ifdef SWAP_OUT_RELOC_OFFSET
159
1
  SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
160
1
#endif
161
#ifdef SWAP_OUT_RELOC_EXTRA
162
  SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
163
#endif
164
1
  return RELSZ;
165
1
}
Unexecuted instantiation: pei-mcore.c:coff_swap_reloc_out
pei-sh.c:coff_swap_reloc_out
Line
Count
Source
150
9
{
151
9
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
152
9
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
153
154
9
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
155
9
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
156
9
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
157
158
#ifdef SWAP_OUT_RELOC_OFFSET
159
  SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
160
#endif
161
#ifdef SWAP_OUT_RELOC_EXTRA
162
  SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
163
#endif
164
9
  return RELSZ;
165
9
}
166
#endif /* not NO_COFF_RELOCS */
167
168
#ifdef COFF_IMAGE_WITH_PE
169
#undef FILHDR
170
421k
#define FILHDR struct external_PEI_IMAGE_hdr
171
#endif
172
173
static void
174
coff_swap_filehdr_in (bfd *abfd, void *src, void *dst)
175
1.82M
{
176
1.82M
  FILHDR *filehdr_src = (FILHDR *) src;
177
1.82M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
1.82M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
1.82M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
1.82M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
1.82M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
1.82M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
1.82M
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
1.82M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
172k
    {
190
172k
      filehdr_dst->f_nsyms = 0;
191
172k
      filehdr_dst->f_flags |= F_LSYMS;
192
172k
    }
193
194
1.82M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
1.82M
}
pei-i386.c:coff_swap_filehdr_in
Line
Count
Source
175
47.2k
{
176
47.2k
  FILHDR *filehdr_src = (FILHDR *) src;
177
47.2k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
47.2k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
47.2k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
47.2k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
47.2k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
47.2k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
47.2k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
47.2k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
4.12k
    {
190
4.12k
      filehdr_dst->f_nsyms = 0;
191
4.12k
      filehdr_dst->f_flags |= F_LSYMS;
192
4.12k
    }
193
194
47.2k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
47.2k
}
pe-x86_64.c:coff_swap_filehdr_in
Line
Count
Source
175
156k
{
176
156k
  FILHDR *filehdr_src = (FILHDR *) src;
177
156k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
156k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
156k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
156k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
156k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
156k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
156k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
156k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
15.5k
    {
190
15.5k
      filehdr_dst->f_nsyms = 0;
191
15.5k
      filehdr_dst->f_flags |= F_LSYMS;
192
15.5k
    }
193
194
156k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
156k
}
pei-x86_64.c:coff_swap_filehdr_in
Line
Count
Source
175
46.4k
{
176
46.4k
  FILHDR *filehdr_src = (FILHDR *) src;
177
46.4k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
46.4k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
46.4k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
46.4k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
46.4k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
46.4k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
46.4k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
46.4k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
4.08k
    {
190
4.08k
      filehdr_dst->f_nsyms = 0;
191
4.08k
      filehdr_dst->f_flags |= F_LSYMS;
192
4.08k
    }
193
194
46.4k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
46.4k
}
pe-aarch64.c:coff_swap_filehdr_in
Line
Count
Source
175
155k
{
176
155k
  FILHDR *filehdr_src = (FILHDR *) src;
177
155k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
155k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
155k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
155k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
155k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
155k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
155k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
155k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
15.3k
    {
190
15.3k
      filehdr_dst->f_nsyms = 0;
191
15.3k
      filehdr_dst->f_flags |= F_LSYMS;
192
15.3k
    }
193
194
155k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
155k
}
pei-aarch64.c:coff_swap_filehdr_in
Line
Count
Source
175
45.1k
{
176
45.1k
  FILHDR *filehdr_src = (FILHDR *) src;
177
45.1k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
45.1k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
45.1k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
45.1k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
45.1k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
45.1k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
45.1k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
45.1k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
3.95k
    {
190
3.95k
      filehdr_dst->f_nsyms = 0;
191
3.95k
      filehdr_dst->f_flags |= F_LSYMS;
192
3.95k
    }
193
194
45.1k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
45.1k
}
pei-ia64.c:coff_swap_filehdr_in
Line
Count
Source
175
20.2k
{
176
20.2k
  FILHDR *filehdr_src = (FILHDR *) src;
177
20.2k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
20.2k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
20.2k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
20.2k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
20.2k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
20.2k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
20.2k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
20.2k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
919
    {
190
919
      filehdr_dst->f_nsyms = 0;
191
919
      filehdr_dst->f_flags |= F_LSYMS;
192
919
    }
193
194
20.2k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
20.2k
}
pei-loongarch64.c:coff_swap_filehdr_in
Line
Count
Source
175
44.5k
{
176
44.5k
  FILHDR *filehdr_src = (FILHDR *) src;
177
44.5k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
44.5k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
44.5k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
44.5k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
44.5k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
44.5k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
44.5k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
44.5k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
3.89k
    {
190
3.89k
      filehdr_dst->f_nsyms = 0;
191
3.89k
      filehdr_dst->f_flags |= F_LSYMS;
192
3.89k
    }
193
194
44.5k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
44.5k
}
pei-riscv64.c:coff_swap_filehdr_in
Line
Count
Source
175
44.7k
{
176
44.7k
  FILHDR *filehdr_src = (FILHDR *) src;
177
44.7k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
44.7k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
44.7k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
44.7k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
44.7k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
44.7k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
44.7k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
44.7k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
3.83k
    {
190
3.83k
      filehdr_dst->f_nsyms = 0;
191
3.83k
      filehdr_dst->f_flags |= F_LSYMS;
192
3.83k
    }
193
194
44.7k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
44.7k
}
pe-arm-wince.c:coff_swap_filehdr_in
Line
Count
Source
175
265k
{
176
265k
  FILHDR *filehdr_src = (FILHDR *) src;
177
265k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
265k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
265k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
265k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
265k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
265k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
265k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
265k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
25.7k
    {
190
25.7k
      filehdr_dst->f_nsyms = 0;
191
25.7k
      filehdr_dst->f_flags |= F_LSYMS;
192
25.7k
    }
193
194
265k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
265k
}
pe-arm.c:coff_swap_filehdr_in
Line
Count
Source
175
265k
{
176
265k
  FILHDR *filehdr_src = (FILHDR *) src;
177
265k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
265k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
265k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
265k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
265k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
265k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
265k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
265k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
25.7k
    {
190
25.7k
      filehdr_dst->f_nsyms = 0;
191
25.7k
      filehdr_dst->f_flags |= F_LSYMS;
192
25.7k
    }
193
194
265k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
265k
}
pe-i386.c:coff_swap_filehdr_in
Line
Count
Source
175
155k
{
176
155k
  FILHDR *filehdr_src = (FILHDR *) src;
177
155k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
155k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
155k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
155k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
155k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
155k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
155k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
155k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
15.4k
    {
190
15.4k
      filehdr_dst->f_nsyms = 0;
191
15.4k
      filehdr_dst->f_flags |= F_LSYMS;
192
15.4k
    }
193
194
155k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
155k
}
pe-mcore.c:coff_swap_filehdr_in
Line
Count
Source
175
265k
{
176
265k
  FILHDR *filehdr_src = (FILHDR *) src;
177
265k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
265k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
265k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
265k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
265k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
265k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
265k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
265k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
25.9k
    {
190
25.9k
      filehdr_dst->f_nsyms = 0;
191
25.9k
      filehdr_dst->f_flags |= F_LSYMS;
192
25.9k
    }
193
194
265k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
265k
}
pe-sh.c:coff_swap_filehdr_in
Line
Count
Source
175
135k
{
176
135k
  FILHDR *filehdr_src = (FILHDR *) src;
177
135k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
135k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
135k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
135k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
135k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
135k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
135k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
135k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
13.1k
    {
190
13.1k
      filehdr_dst->f_nsyms = 0;
191
13.1k
      filehdr_dst->f_flags |= F_LSYMS;
192
13.1k
    }
193
194
135k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
135k
}
pei-arm-wince.c:coff_swap_filehdr_in
Line
Count
Source
175
43.3k
{
176
43.3k
  FILHDR *filehdr_src = (FILHDR *) src;
177
43.3k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
43.3k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
43.3k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
43.3k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
43.3k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
43.3k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
43.3k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
43.3k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
3.83k
    {
190
3.83k
      filehdr_dst->f_nsyms = 0;
191
3.83k
      filehdr_dst->f_flags |= F_LSYMS;
192
3.83k
    }
193
194
43.3k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
43.3k
}
pei-arm.c:coff_swap_filehdr_in
Line
Count
Source
175
43.6k
{
176
43.6k
  FILHDR *filehdr_src = (FILHDR *) src;
177
43.6k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
43.6k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
43.6k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
43.6k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
43.6k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
43.6k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
43.6k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
43.6k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
3.83k
    {
190
3.83k
      filehdr_dst->f_nsyms = 0;
191
3.83k
      filehdr_dst->f_flags |= F_LSYMS;
192
3.83k
    }
193
194
43.6k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
43.6k
}
pei-mcore.c:coff_swap_filehdr_in
Line
Count
Source
175
43.0k
{
176
43.0k
  FILHDR *filehdr_src = (FILHDR *) src;
177
43.0k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
43.0k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
43.0k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
43.0k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
43.0k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
43.0k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
43.0k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
43.0k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
3.75k
    {
190
3.75k
      filehdr_dst->f_nsyms = 0;
191
3.75k
      filehdr_dst->f_flags |= F_LSYMS;
192
3.75k
    }
193
194
43.0k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
43.0k
}
pei-sh.c:coff_swap_filehdr_in
Line
Count
Source
175
43.1k
{
176
43.1k
  FILHDR *filehdr_src = (FILHDR *) src;
177
43.1k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
43.1k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
43.1k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
43.1k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
43.1k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
43.1k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
43.1k
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
43.1k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
3.79k
    {
190
3.79k
      filehdr_dst->f_nsyms = 0;
191
3.79k
      filehdr_dst->f_flags |= F_LSYMS;
192
3.79k
    }
193
194
43.1k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
43.1k
}
196
197
#ifdef COFF_IMAGE_WITH_PE
198
# define coff_swap_filehdr_out _bfd_XXi_only_swap_filehdr_out
199
#elif defined COFF_WITH_peAArch64
200
# define coff_swap_filehdr_out _bfd_XX_only_swap_filehdr_out
201
#elif defined COFF_WITH_pex64
202
# define coff_swap_filehdr_out _bfd_pex64_only_swap_filehdr_out
203
#elif defined COFF_WITH_pep
204
# define coff_swap_filehdr_out _bfd_pep_only_swap_filehdr_out
205
#else
206
# define coff_swap_filehdr_out _bfd_pe_only_swap_filehdr_out
207
#endif
208
209
static void
210
coff_swap_scnhdr_in (bfd *abfd, void *ext, void *in)
211
766k
{
212
766k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
766k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
766k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
766k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
766k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
766k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
766k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
766k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
766k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
766k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
#ifdef COFF_IMAGE_WITH_PE
229
511k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
511k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
  scnhdr_int->s_nreloc = 0;
232
#else
233
254k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
254k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
#endif
236
237
766k
  if (scnhdr_int->s_vaddr != 0)
238
486k
    {
239
486k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
      scnhdr_int->s_vaddr &= 0xffffffff;
244
#endif
245
486k
    }
246
247
766k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
766k
  if (scnhdr_int->s_paddr > 0
253
540k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
124k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
490k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
151k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
766k
#endif
262
766k
}
pei-i386.c:coff_swap_scnhdr_in
Line
Count
Source
211
53.9k
{
212
53.9k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
53.9k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
53.9k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
53.9k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
53.9k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
53.9k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
53.9k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
53.9k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
53.9k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
53.9k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
53.9k
#ifdef COFF_IMAGE_WITH_PE
229
53.9k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
53.9k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
53.9k
  scnhdr_int->s_nreloc = 0;
232
#else
233
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
#endif
236
237
53.9k
  if (scnhdr_int->s_vaddr != 0)
238
34.1k
    {
239
34.1k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
34.1k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
34.1k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
34.1k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
34.1k
#endif
245
34.1k
    }
246
247
53.9k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
53.9k
  if (scnhdr_int->s_paddr > 0
253
38.1k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
8.13k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
36.9k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
13.7k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
53.9k
#endif
262
53.9k
}
pe-x86_64.c:coff_swap_scnhdr_in
Line
Count
Source
211
58.0k
{
212
58.0k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
58.0k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
58.0k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
58.0k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
58.0k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
58.0k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
58.0k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
58.0k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
58.0k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
58.0k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
#ifdef COFF_IMAGE_WITH_PE
229
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
  scnhdr_int->s_nreloc = 0;
232
#else
233
58.0k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
58.0k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
58.0k
#endif
236
237
58.0k
  if (scnhdr_int->s_vaddr != 0)
238
32.8k
    {
239
32.8k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
      scnhdr_int->s_vaddr &= 0xffffffff;
244
#endif
245
32.8k
    }
246
247
58.0k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
58.0k
  if (scnhdr_int->s_paddr > 0
253
34.8k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
5.99k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
28.8k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
5.99k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
58.0k
#endif
262
58.0k
}
pei-x86_64.c:coff_swap_scnhdr_in
Line
Count
Source
211
58.1k
{
212
58.1k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
58.1k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
58.1k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
58.1k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
58.1k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
58.1k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
58.1k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
58.1k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
58.1k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
58.1k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
58.1k
#ifdef COFF_IMAGE_WITH_PE
229
58.1k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
58.1k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
58.1k
  scnhdr_int->s_nreloc = 0;
232
#else
233
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
#endif
236
237
58.1k
  if (scnhdr_int->s_vaddr != 0)
238
36.6k
    {
239
36.6k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
      scnhdr_int->s_vaddr &= 0xffffffff;
244
#endif
245
36.6k
    }
246
247
58.1k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
58.1k
  if (scnhdr_int->s_paddr > 0
253
40.3k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
8.97k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
38.9k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
14.0k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
58.1k
#endif
262
58.1k
}
pe-aarch64.c:coff_swap_scnhdr_in
Line
Count
Source
211
34.0k
{
212
34.0k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
34.0k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
34.0k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
34.0k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
34.0k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
34.0k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
34.0k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
34.0k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
34.0k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
34.0k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
#ifdef COFF_IMAGE_WITH_PE
229
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
  scnhdr_int->s_nreloc = 0;
232
#else
233
34.0k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
34.0k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
34.0k
#endif
236
237
34.0k
  if (scnhdr_int->s_vaddr != 0)
238
20.0k
    {
239
20.0k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
      scnhdr_int->s_vaddr &= 0xffffffff;
244
#endif
245
20.0k
    }
246
247
34.0k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
34.0k
  if (scnhdr_int->s_paddr > 0
253
21.6k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
4.56k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
17.0k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
4.56k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
34.0k
#endif
262
34.0k
}
pei-aarch64.c:coff_swap_scnhdr_in
Line
Count
Source
211
62.5k
{
212
62.5k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
62.5k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
62.5k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
62.5k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
62.5k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
62.5k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
62.5k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
62.5k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
62.5k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
62.5k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
62.5k
#ifdef COFF_IMAGE_WITH_PE
229
62.5k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
62.5k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
62.5k
  scnhdr_int->s_nreloc = 0;
232
#else
233
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
#endif
236
237
62.5k
  if (scnhdr_int->s_vaddr != 0)
238
42.9k
    {
239
42.9k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
      scnhdr_int->s_vaddr &= 0xffffffff;
244
#endif
245
42.9k
    }
246
247
62.5k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
62.5k
  if (scnhdr_int->s_paddr > 0
253
43.6k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
8.85k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
42.3k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
15.3k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
62.5k
#endif
262
62.5k
}
pei-ia64.c:coff_swap_scnhdr_in
Line
Count
Source
211
44.7k
{
212
44.7k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
44.7k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
44.7k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
44.7k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
44.7k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
44.7k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
44.7k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
44.7k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
44.7k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
44.7k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
44.7k
#ifdef COFF_IMAGE_WITH_PE
229
44.7k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
44.7k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
44.7k
  scnhdr_int->s_nreloc = 0;
232
#else
233
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
#endif
236
237
44.7k
  if (scnhdr_int->s_vaddr != 0)
238
28.8k
    {
239
28.8k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
28.8k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
28.8k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
28.8k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
28.8k
#endif
245
28.8k
    }
246
247
44.7k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
44.7k
  if (scnhdr_int->s_paddr > 0
253
31.7k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
7.73k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
29.9k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
10.7k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
44.7k
#endif
262
44.7k
}
pei-loongarch64.c:coff_swap_scnhdr_in
Line
Count
Source
211
45.3k
{
212
45.3k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
45.3k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
45.3k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
45.3k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
45.3k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
45.3k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
45.3k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
45.3k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
45.3k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
45.3k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
45.3k
#ifdef COFF_IMAGE_WITH_PE
229
45.3k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
45.3k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
45.3k
  scnhdr_int->s_nreloc = 0;
232
#else
233
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
#endif
236
237
45.3k
  if (scnhdr_int->s_vaddr != 0)
238
30.7k
    {
239
30.7k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
      scnhdr_int->s_vaddr &= 0xffffffff;
244
#endif
245
30.7k
    }
246
247
45.3k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
45.3k
  if (scnhdr_int->s_paddr > 0
253
33.3k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
6.77k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
32.0k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
9.76k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
45.3k
#endif
262
45.3k
}
pei-riscv64.c:coff_swap_scnhdr_in
Line
Count
Source
211
52.0k
{
212
52.0k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
52.0k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
52.0k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
52.0k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
52.0k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
52.0k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
52.0k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
52.0k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
52.0k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
52.0k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
52.0k
#ifdef COFF_IMAGE_WITH_PE
229
52.0k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
52.0k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
52.0k
  scnhdr_int->s_nreloc = 0;
232
#else
233
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
#endif
236
237
52.0k
  if (scnhdr_int->s_vaddr != 0)
238
31.6k
    {
239
31.6k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
      scnhdr_int->s_vaddr &= 0xffffffff;
244
#endif
245
31.6k
    }
246
247
52.0k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
52.0k
  if (scnhdr_int->s_paddr > 0
253
37.0k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
9.62k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
36.0k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
10.2k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
52.0k
#endif
262
52.0k
}
pe-arm-wince.c:coff_swap_scnhdr_in
Line
Count
Source
211
21.9k
{
212
21.9k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
21.9k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
21.9k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
21.9k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
21.9k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
21.9k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
21.9k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
21.9k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
21.9k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
21.9k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
#ifdef COFF_IMAGE_WITH_PE
229
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
  scnhdr_int->s_nreloc = 0;
232
#else
233
21.9k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
21.9k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
21.9k
#endif
236
237
21.9k
  if (scnhdr_int->s_vaddr != 0)
238
13.4k
    {
239
13.4k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
13.4k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
13.4k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
13.4k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
13.4k
#endif
245
13.4k
    }
246
247
21.9k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
21.9k
  if (scnhdr_int->s_paddr > 0
253
14.7k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
3.19k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
11.5k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
3.19k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
21.9k
#endif
262
21.9k
}
pe-arm.c:coff_swap_scnhdr_in
Line
Count
Source
211
21.9k
{
212
21.9k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
21.9k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
21.9k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
21.9k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
21.9k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
21.9k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
21.9k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
21.9k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
21.9k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
21.9k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
#ifdef COFF_IMAGE_WITH_PE
229
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
  scnhdr_int->s_nreloc = 0;
232
#else
233
21.9k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
21.9k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
21.9k
#endif
236
237
21.9k
  if (scnhdr_int->s_vaddr != 0)
238
13.4k
    {
239
13.4k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
13.4k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
13.4k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
13.4k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
13.4k
#endif
245
13.4k
    }
246
247
21.9k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
21.9k
  if (scnhdr_int->s_paddr > 0
253
14.7k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
3.19k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
11.5k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
3.19k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
21.9k
#endif
262
21.9k
}
pe-i386.c:coff_swap_scnhdr_in
Line
Count
Source
211
55.4k
{
212
55.4k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
55.4k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
55.4k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
55.4k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
55.4k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
55.4k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
55.4k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
55.4k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
55.4k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
55.4k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
#ifdef COFF_IMAGE_WITH_PE
229
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
  scnhdr_int->s_nreloc = 0;
232
#else
233
55.4k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
55.4k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
55.4k
#endif
236
237
55.4k
  if (scnhdr_int->s_vaddr != 0)
238
35.6k
    {
239
35.6k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
35.6k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
35.6k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
35.6k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
35.6k
#endif
245
35.6k
    }
246
247
55.4k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
55.4k
  if (scnhdr_int->s_paddr > 0
253
40.6k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
8.96k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
31.6k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
8.96k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
55.4k
#endif
262
55.4k
}
pe-mcore.c:coff_swap_scnhdr_in
Line
Count
Source
211
23.0k
{
212
23.0k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
23.0k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
23.0k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
23.0k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
23.0k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
23.0k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
23.0k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
23.0k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
23.0k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
23.0k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
#ifdef COFF_IMAGE_WITH_PE
229
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
  scnhdr_int->s_nreloc = 0;
232
#else
233
23.0k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
23.0k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
23.0k
#endif
236
237
23.0k
  if (scnhdr_int->s_vaddr != 0)
238
15.0k
    {
239
15.0k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
15.0k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
15.0k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
15.0k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
15.0k
#endif
245
15.0k
    }
246
247
23.0k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
23.0k
  if (scnhdr_int->s_paddr > 0
253
16.8k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
3.97k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
12.8k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
3.97k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
23.0k
#endif
262
23.0k
}
pe-sh.c:coff_swap_scnhdr_in
Line
Count
Source
211
39.7k
{
212
39.7k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
39.7k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
39.7k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
39.7k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
39.7k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
39.7k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
39.7k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
39.7k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
39.7k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
39.7k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
#ifdef COFF_IMAGE_WITH_PE
229
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
  scnhdr_int->s_nreloc = 0;
232
#else
233
39.7k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
39.7k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
39.7k
#endif
236
237
39.7k
  if (scnhdr_int->s_vaddr != 0)
238
24.6k
    {
239
24.6k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
24.6k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
24.6k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
24.6k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
24.6k
#endif
245
24.6k
    }
246
247
39.7k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
39.7k
  if (scnhdr_int->s_paddr > 0
253
27.3k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
6.07k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
21.2k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
6.07k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
39.7k
#endif
262
39.7k
}
pei-arm-wince.c:coff_swap_scnhdr_in
Line
Count
Source
211
45.2k
{
212
45.2k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
45.2k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
45.2k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
45.2k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
45.2k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
45.2k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
45.2k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
45.2k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
45.2k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
45.2k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
45.2k
#ifdef COFF_IMAGE_WITH_PE
229
45.2k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
45.2k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
45.2k
  scnhdr_int->s_nreloc = 0;
232
#else
233
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
#endif
236
237
45.2k
  if (scnhdr_int->s_vaddr != 0)
238
29.2k
    {
239
29.2k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
29.2k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
29.2k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
29.2k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
29.2k
#endif
245
29.2k
    }
246
247
45.2k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
45.2k
  if (scnhdr_int->s_paddr > 0
253
34.3k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
10.2k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
32.7k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
9.89k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
45.2k
#endif
262
45.2k
}
pei-arm.c:coff_swap_scnhdr_in
Line
Count
Source
211
59.2k
{
212
59.2k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
59.2k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
59.2k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
59.2k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
59.2k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
59.2k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
59.2k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
59.2k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
59.2k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
59.2k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
59.2k
#ifdef COFF_IMAGE_WITH_PE
229
59.2k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
59.2k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
59.2k
  scnhdr_int->s_nreloc = 0;
232
#else
233
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
#endif
236
237
59.2k
  if (scnhdr_int->s_vaddr != 0)
238
38.3k
    {
239
38.3k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
38.3k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
38.3k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
38.3k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
38.3k
#endif
245
38.3k
    }
246
247
59.2k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
59.2k
  if (scnhdr_int->s_paddr > 0
253
43.4k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
12.4k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
41.7k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
11.8k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
59.2k
#endif
262
59.2k
}
pei-mcore.c:coff_swap_scnhdr_in
Line
Count
Source
211
46.9k
{
212
46.9k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
46.9k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
46.9k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
46.9k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
46.9k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
46.9k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
46.9k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
46.9k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
46.9k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
46.9k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
46.9k
#ifdef COFF_IMAGE_WITH_PE
229
46.9k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
46.9k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
46.9k
  scnhdr_int->s_nreloc = 0;
232
#else
233
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
#endif
236
237
46.9k
  if (scnhdr_int->s_vaddr != 0)
238
29.6k
    {
239
29.6k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
29.6k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
29.6k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
29.6k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
29.6k
#endif
245
29.6k
    }
246
247
46.9k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
46.9k
  if (scnhdr_int->s_paddr > 0
253
34.6k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
7.57k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
33.4k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
9.41k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
46.9k
#endif
262
46.9k
}
pei-sh.c:coff_swap_scnhdr_in
Line
Count
Source
211
43.6k
{
212
43.6k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
43.6k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
43.6k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
43.6k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
43.6k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
43.6k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
43.6k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
43.6k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
43.6k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
43.6k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
43.6k
#ifdef COFF_IMAGE_WITH_PE
229
43.6k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
43.6k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
43.6k
  scnhdr_int->s_nreloc = 0;
232
#else
233
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
#endif
236
237
43.6k
  if (scnhdr_int->s_vaddr != 0)
238
28.9k
    {
239
28.9k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
28.9k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
28.9k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
28.9k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
28.9k
#endif
245
28.9k
    }
246
247
43.6k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
43.6k
  if (scnhdr_int->s_paddr > 0
253
32.8k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
8.46k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
31.6k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
10.8k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
43.6k
#endif
262
43.6k
}
263
264
static bool
265
pe_mkobject (bfd *abfd)
266
92.4k
{
267
  /* Some x86 code followed by an ascii string.  */
268
92.4k
  static const char default_dos_message[64] = {
269
92.4k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
92.4k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
92.4k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
92.4k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
92.4k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
92.4k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
92.4k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
92.4k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
92.4k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
92.4k
  abfd->tdata.pe_obj_data = pe;
280
92.4k
  if (pe == NULL)
281
0
    return false;
282
283
92.4k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
92.4k
  pe->in_reloc_p = in_reloc_p;
287
288
92.4k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
92.4k
  bfd_coff_long_section_names (abfd)
291
92.4k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
92.4k
  return true;
294
92.4k
}
pei-i386.c:pe_mkobject
Line
Count
Source
266
8.94k
{
267
  /* Some x86 code followed by an ascii string.  */
268
8.94k
  static const char default_dos_message[64] = {
269
8.94k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
8.94k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
8.94k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
8.94k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
8.94k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
8.94k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
8.94k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
8.94k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
8.94k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
8.94k
  abfd->tdata.pe_obj_data = pe;
280
8.94k
  if (pe == NULL)
281
0
    return false;
282
283
8.94k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
8.94k
  pe->in_reloc_p = in_reloc_p;
287
288
8.94k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
8.94k
  bfd_coff_long_section_names (abfd)
291
8.94k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
8.94k
}
pe-x86_64.c:pe_mkobject
Line
Count
Source
266
7.64k
{
267
  /* Some x86 code followed by an ascii string.  */
268
7.64k
  static const char default_dos_message[64] = {
269
7.64k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
7.64k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
7.64k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
7.64k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
7.64k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
7.64k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
7.64k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
7.64k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
7.64k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
7.64k
  abfd->tdata.pe_obj_data = pe;
280
7.64k
  if (pe == NULL)
281
0
    return false;
282
283
7.64k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
7.64k
  pe->in_reloc_p = in_reloc_p;
287
288
7.64k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
7.64k
  bfd_coff_long_section_names (abfd)
291
7.64k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
7.64k
}
pei-x86_64.c:pe_mkobject
Line
Count
Source
266
7.63k
{
267
  /* Some x86 code followed by an ascii string.  */
268
7.63k
  static const char default_dos_message[64] = {
269
7.63k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
7.63k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
7.63k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
7.63k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
7.63k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
7.63k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
7.63k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
7.63k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
7.63k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
7.63k
  abfd->tdata.pe_obj_data = pe;
280
7.63k
  if (pe == NULL)
281
0
    return false;
282
283
7.63k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
7.63k
  pe->in_reloc_p = in_reloc_p;
287
288
7.63k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
7.63k
  bfd_coff_long_section_names (abfd)
291
7.63k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
7.63k
}
pe-aarch64.c:pe_mkobject
Line
Count
Source
266
3.90k
{
267
  /* Some x86 code followed by an ascii string.  */
268
3.90k
  static const char default_dos_message[64] = {
269
3.90k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
3.90k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
3.90k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
3.90k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
3.90k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
3.90k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
3.90k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
3.90k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
3.90k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
3.90k
  abfd->tdata.pe_obj_data = pe;
280
3.90k
  if (pe == NULL)
281
0
    return false;
282
283
3.90k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
3.90k
  pe->in_reloc_p = in_reloc_p;
287
288
3.90k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
3.90k
  bfd_coff_long_section_names (abfd)
291
3.90k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
3.90k
}
pei-aarch64.c:pe_mkobject
Line
Count
Source
266
6.67k
{
267
  /* Some x86 code followed by an ascii string.  */
268
6.67k
  static const char default_dos_message[64] = {
269
6.67k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
6.67k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
6.67k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
6.67k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
6.67k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
6.67k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
6.67k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
6.67k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
6.67k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
6.67k
  abfd->tdata.pe_obj_data = pe;
280
6.67k
  if (pe == NULL)
281
0
    return false;
282
283
6.67k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
6.67k
  pe->in_reloc_p = in_reloc_p;
287
288
6.67k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
6.67k
  bfd_coff_long_section_names (abfd)
291
6.67k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
6.67k
}
pei-ia64.c:pe_mkobject
Line
Count
Source
266
5.75k
{
267
  /* Some x86 code followed by an ascii string.  */
268
5.75k
  static const char default_dos_message[64] = {
269
5.75k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
5.75k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
5.75k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
5.75k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
5.75k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
5.75k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
5.75k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
5.75k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
5.75k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
5.75k
  abfd->tdata.pe_obj_data = pe;
280
5.75k
  if (pe == NULL)
281
0
    return false;
282
283
5.75k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
5.75k
  pe->in_reloc_p = in_reloc_p;
287
288
5.75k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
5.75k
  bfd_coff_long_section_names (abfd)
291
5.75k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
5.75k
}
pei-loongarch64.c:pe_mkobject
Line
Count
Source
266
5.53k
{
267
  /* Some x86 code followed by an ascii string.  */
268
5.53k
  static const char default_dos_message[64] = {
269
5.53k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
5.53k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
5.53k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
5.53k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
5.53k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
5.53k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
5.53k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
5.53k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
5.53k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
5.53k
  abfd->tdata.pe_obj_data = pe;
280
5.53k
  if (pe == NULL)
281
0
    return false;
282
283
5.53k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
5.53k
  pe->in_reloc_p = in_reloc_p;
287
288
5.53k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
5.53k
  bfd_coff_long_section_names (abfd)
291
5.53k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
5.53k
}
pei-riscv64.c:pe_mkobject
Line
Count
Source
266
6.16k
{
267
  /* Some x86 code followed by an ascii string.  */
268
6.16k
  static const char default_dos_message[64] = {
269
6.16k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
6.16k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
6.16k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
6.16k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
6.16k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
6.16k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
6.16k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
6.16k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
6.16k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
6.16k
  abfd->tdata.pe_obj_data = pe;
280
6.16k
  if (pe == NULL)
281
0
    return false;
282
283
6.16k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
6.16k
  pe->in_reloc_p = in_reloc_p;
287
288
6.16k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
6.16k
  bfd_coff_long_section_names (abfd)
291
6.16k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
6.16k
}
pe-arm-wince.c:pe_mkobject
Line
Count
Source
266
1.95k
{
267
  /* Some x86 code followed by an ascii string.  */
268
1.95k
  static const char default_dos_message[64] = {
269
1.95k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
1.95k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
1.95k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
1.95k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
1.95k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
1.95k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
1.95k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
1.95k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
1.95k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
1.95k
  abfd->tdata.pe_obj_data = pe;
280
1.95k
  if (pe == NULL)
281
0
    return false;
282
283
1.95k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
1.95k
  pe->in_reloc_p = in_reloc_p;
287
288
1.95k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
1.95k
  bfd_coff_long_section_names (abfd)
291
1.95k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
1.95k
}
pe-arm.c:pe_mkobject
Line
Count
Source
266
1.95k
{
267
  /* Some x86 code followed by an ascii string.  */
268
1.95k
  static const char default_dos_message[64] = {
269
1.95k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
1.95k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
1.95k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
1.95k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
1.95k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
1.95k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
1.95k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
1.95k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
1.95k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
1.95k
  abfd->tdata.pe_obj_data = pe;
280
1.95k
  if (pe == NULL)
281
0
    return false;
282
283
1.95k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
1.95k
  pe->in_reloc_p = in_reloc_p;
287
288
1.95k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
1.95k
  bfd_coff_long_section_names (abfd)
291
1.95k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
1.95k
}
pe-i386.c:pe_mkobject
Line
Count
Source
266
8.16k
{
267
  /* Some x86 code followed by an ascii string.  */
268
8.16k
  static const char default_dos_message[64] = {
269
8.16k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
8.16k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
8.16k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
8.16k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
8.16k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
8.16k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
8.16k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
8.16k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
8.16k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
8.16k
  abfd->tdata.pe_obj_data = pe;
280
8.16k
  if (pe == NULL)
281
0
    return false;
282
283
8.16k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
8.16k
  pe->in_reloc_p = in_reloc_p;
287
288
8.16k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
8.16k
  bfd_coff_long_section_names (abfd)
291
8.16k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
8.16k
}
pe-mcore.c:pe_mkobject
Line
Count
Source
266
3.01k
{
267
  /* Some x86 code followed by an ascii string.  */
268
3.01k
  static const char default_dos_message[64] = {
269
3.01k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
3.01k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
3.01k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
3.01k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
3.01k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
3.01k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
3.01k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
3.01k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
3.01k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
3.01k
  abfd->tdata.pe_obj_data = pe;
280
3.01k
  if (pe == NULL)
281
0
    return false;
282
283
3.01k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
3.01k
  pe->in_reloc_p = in_reloc_p;
287
288
3.01k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
3.01k
  bfd_coff_long_section_names (abfd)
291
3.01k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
3.01k
}
pe-sh.c:pe_mkobject
Line
Count
Source
266
4.30k
{
267
  /* Some x86 code followed by an ascii string.  */
268
4.30k
  static const char default_dos_message[64] = {
269
4.30k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
4.30k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
4.30k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
4.30k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
4.30k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
4.30k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
4.30k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
4.30k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
4.30k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
4.30k
  abfd->tdata.pe_obj_data = pe;
280
4.30k
  if (pe == NULL)
281
0
    return false;
282
283
4.30k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
4.30k
  pe->in_reloc_p = in_reloc_p;
287
288
4.30k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
4.30k
  bfd_coff_long_section_names (abfd)
291
4.30k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
4.30k
}
pei-arm-wince.c:pe_mkobject
Line
Count
Source
266
5.07k
{
267
  /* Some x86 code followed by an ascii string.  */
268
5.07k
  static const char default_dos_message[64] = {
269
5.07k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
5.07k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
5.07k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
5.07k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
5.07k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
5.07k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
5.07k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
5.07k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
5.07k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
5.07k
  abfd->tdata.pe_obj_data = pe;
280
5.07k
  if (pe == NULL)
281
0
    return false;
282
283
5.07k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
5.07k
  pe->in_reloc_p = in_reloc_p;
287
288
5.07k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
5.07k
  bfd_coff_long_section_names (abfd)
291
5.07k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
5.07k
}
pei-arm.c:pe_mkobject
Line
Count
Source
266
6.44k
{
267
  /* Some x86 code followed by an ascii string.  */
268
6.44k
  static const char default_dos_message[64] = {
269
6.44k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
6.44k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
6.44k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
6.44k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
6.44k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
6.44k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
6.44k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
6.44k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
6.44k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
6.44k
  abfd->tdata.pe_obj_data = pe;
280
6.44k
  if (pe == NULL)
281
0
    return false;
282
283
6.44k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
6.44k
  pe->in_reloc_p = in_reloc_p;
287
288
6.44k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
6.44k
  bfd_coff_long_section_names (abfd)
291
6.44k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
6.44k
}
pei-mcore.c:pe_mkobject
Line
Count
Source
266
4.40k
{
267
  /* Some x86 code followed by an ascii string.  */
268
4.40k
  static const char default_dos_message[64] = {
269
4.40k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
4.40k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
4.40k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
4.40k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
4.40k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
4.40k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
4.40k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
4.40k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
4.40k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
4.40k
  abfd->tdata.pe_obj_data = pe;
280
4.40k
  if (pe == NULL)
281
0
    return false;
282
283
4.40k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
4.40k
  pe->in_reloc_p = in_reloc_p;
287
288
4.40k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
4.40k
  bfd_coff_long_section_names (abfd)
291
4.40k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
4.40k
}
pei-sh.c:pe_mkobject
Line
Count
Source
266
4.90k
{
267
  /* Some x86 code followed by an ascii string.  */
268
4.90k
  static const char default_dos_message[64] = {
269
4.90k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
4.90k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
4.90k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
4.90k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
4.90k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
4.90k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
4.90k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
4.90k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
4.90k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
4.90k
  abfd->tdata.pe_obj_data = pe;
280
4.90k
  if (pe == NULL)
281
0
    return false;
282
283
4.90k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
4.90k
  pe->in_reloc_p = in_reloc_p;
287
288
4.90k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
4.90k
  bfd_coff_long_section_names (abfd)
291
4.90k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
4.90k
}
295
296
/* Create the COFF backend specific information.  */
297
298
static void *
299
pe_mkobject_hook (bfd *abfd,
300
      void *filehdr,
301
      void *aouthdr ATTRIBUTE_UNUSED)
302
87.3k
{
303
87.3k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
87.3k
  pe_data_type *pe;
305
306
87.3k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
87.3k
  pe = pe_data (abfd);
310
87.3k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
87.3k
  pe->coff.local_n_btmask = N_BTMASK;
315
87.3k
  pe->coff.local_n_btshft = N_BTSHFT;
316
87.3k
  pe->coff.local_n_tmask = N_TMASK;
317
87.3k
  pe->coff.local_n_tshift = N_TSHIFT;
318
87.3k
  pe->coff.local_symesz = SYMESZ;
319
87.3k
  pe->coff.local_auxesz = AUXESZ;
320
87.3k
  pe->coff.local_linesz = LINESZ;
321
322
87.3k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
87.3k
  obj_raw_syment_count (abfd) =
325
87.3k
    obj_conv_table_size (abfd) =
326
87.3k
      internal_f->f_nsyms;
327
328
87.3k
  pe->real_flags = internal_f->f_flags;
329
330
87.3k
  if ((internal_f->f_flags & F_DLL) != 0)
331
26.2k
    pe->dll = 1;
332
333
87.3k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
62.2k
    abfd->flags |= HAS_DEBUG;
335
336
#ifdef COFF_IMAGE_WITH_PE
337
58.2k
  if (aouthdr)
338
34.3k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
#endif
340
341
#ifdef ARM
342
14.9k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
0
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
87.3k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
87.3k
    sizeof (pe->dos_message));
348
349
87.3k
  return (void *) pe;
350
87.3k
}
pei-i386.c:pe_mkobject_hook
Line
Count
Source
302
8.59k
{
303
8.59k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
8.59k
  pe_data_type *pe;
305
306
8.59k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
8.59k
  pe = pe_data (abfd);
310
8.59k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
8.59k
  pe->coff.local_n_btmask = N_BTMASK;
315
8.59k
  pe->coff.local_n_btshft = N_BTSHFT;
316
8.59k
  pe->coff.local_n_tmask = N_TMASK;
317
8.59k
  pe->coff.local_n_tshift = N_TSHIFT;
318
8.59k
  pe->coff.local_symesz = SYMESZ;
319
8.59k
  pe->coff.local_auxesz = AUXESZ;
320
8.59k
  pe->coff.local_linesz = LINESZ;
321
322
8.59k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
8.59k
  obj_raw_syment_count (abfd) =
325
8.59k
    obj_conv_table_size (abfd) =
326
8.59k
      internal_f->f_nsyms;
327
328
8.59k
  pe->real_flags = internal_f->f_flags;
329
330
8.59k
  if ((internal_f->f_flags & F_DLL) != 0)
331
2.07k
    pe->dll = 1;
332
333
8.59k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
6.96k
    abfd->flags |= HAS_DEBUG;
335
336
8.59k
#ifdef COFF_IMAGE_WITH_PE
337
8.59k
  if (aouthdr)
338
4.06k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
8.59k
#endif
340
341
#ifdef ARM
342
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
8.59k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
8.59k
    sizeof (pe->dos_message));
348
349
8.59k
  return (void *) pe;
350
8.59k
}
pe-x86_64.c:pe_mkobject_hook
Line
Count
Source
302
6.97k
{
303
6.97k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
6.97k
  pe_data_type *pe;
305
306
6.97k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
6.97k
  pe = pe_data (abfd);
310
6.97k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
6.97k
  pe->coff.local_n_btmask = N_BTMASK;
315
6.97k
  pe->coff.local_n_btshft = N_BTSHFT;
316
6.97k
  pe->coff.local_n_tmask = N_TMASK;
317
6.97k
  pe->coff.local_n_tshift = N_TSHIFT;
318
6.97k
  pe->coff.local_symesz = SYMESZ;
319
6.97k
  pe->coff.local_auxesz = AUXESZ;
320
6.97k
  pe->coff.local_linesz = LINESZ;
321
322
6.97k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
6.97k
  obj_raw_syment_count (abfd) =
325
6.97k
    obj_conv_table_size (abfd) =
326
6.97k
      internal_f->f_nsyms;
327
328
6.97k
  pe->real_flags = internal_f->f_flags;
329
330
6.97k
  if ((internal_f->f_flags & F_DLL) != 0)
331
1.64k
    pe->dll = 1;
332
333
6.97k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
5.26k
    abfd->flags |= HAS_DEBUG;
335
336
#ifdef COFF_IMAGE_WITH_PE
337
  if (aouthdr)
338
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
#endif
340
341
#ifdef ARM
342
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
6.97k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
6.97k
    sizeof (pe->dos_message));
348
349
6.97k
  return (void *) pe;
350
6.97k
}
pei-x86_64.c:pe_mkobject_hook
Line
Count
Source
302
7.23k
{
303
7.23k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
7.23k
  pe_data_type *pe;
305
306
7.23k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
7.23k
  pe = pe_data (abfd);
310
7.23k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
7.23k
  pe->coff.local_n_btmask = N_BTMASK;
315
7.23k
  pe->coff.local_n_btshft = N_BTSHFT;
316
7.23k
  pe->coff.local_n_tmask = N_TMASK;
317
7.23k
  pe->coff.local_n_tshift = N_TSHIFT;
318
7.23k
  pe->coff.local_symesz = SYMESZ;
319
7.23k
  pe->coff.local_auxesz = AUXESZ;
320
7.23k
  pe->coff.local_linesz = LINESZ;
321
322
7.23k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
7.23k
  obj_raw_syment_count (abfd) =
325
7.23k
    obj_conv_table_size (abfd) =
326
7.23k
      internal_f->f_nsyms;
327
328
7.23k
  pe->real_flags = internal_f->f_flags;
329
330
7.23k
  if ((internal_f->f_flags & F_DLL) != 0)
331
2.81k
    pe->dll = 1;
332
333
7.23k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
4.89k
    abfd->flags |= HAS_DEBUG;
335
336
7.23k
#ifdef COFF_IMAGE_WITH_PE
337
7.23k
  if (aouthdr)
338
4.58k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
7.23k
#endif
340
341
#ifdef ARM
342
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
7.23k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
7.23k
    sizeof (pe->dos_message));
348
349
7.23k
  return (void *) pe;
350
7.23k
}
pe-aarch64.c:pe_mkobject_hook
Line
Count
Source
302
3.49k
{
303
3.49k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
3.49k
  pe_data_type *pe;
305
306
3.49k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
3.49k
  pe = pe_data (abfd);
310
3.49k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
3.49k
  pe->coff.local_n_btmask = N_BTMASK;
315
3.49k
  pe->coff.local_n_btshft = N_BTSHFT;
316
3.49k
  pe->coff.local_n_tmask = N_TMASK;
317
3.49k
  pe->coff.local_n_tshift = N_TSHIFT;
318
3.49k
  pe->coff.local_symesz = SYMESZ;
319
3.49k
  pe->coff.local_auxesz = AUXESZ;
320
3.49k
  pe->coff.local_linesz = LINESZ;
321
322
3.49k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
3.49k
  obj_raw_syment_count (abfd) =
325
3.49k
    obj_conv_table_size (abfd) =
326
3.49k
      internal_f->f_nsyms;
327
328
3.49k
  pe->real_flags = internal_f->f_flags;
329
330
3.49k
  if ((internal_f->f_flags & F_DLL) != 0)
331
885
    pe->dll = 1;
332
333
3.49k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
2.77k
    abfd->flags |= HAS_DEBUG;
335
336
#ifdef COFF_IMAGE_WITH_PE
337
  if (aouthdr)
338
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
#endif
340
341
#ifdef ARM
342
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
3.49k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
3.49k
    sizeof (pe->dos_message));
348
349
3.49k
  return (void *) pe;
350
3.49k
}
pei-aarch64.c:pe_mkobject_hook
Line
Count
Source
302
6.38k
{
303
6.38k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
6.38k
  pe_data_type *pe;
305
306
6.38k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
6.38k
  pe = pe_data (abfd);
310
6.38k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
6.38k
  pe->coff.local_n_btmask = N_BTMASK;
315
6.38k
  pe->coff.local_n_btshft = N_BTSHFT;
316
6.38k
  pe->coff.local_n_tmask = N_TMASK;
317
6.38k
  pe->coff.local_n_tshift = N_TSHIFT;
318
6.38k
  pe->coff.local_symesz = SYMESZ;
319
6.38k
  pe->coff.local_auxesz = AUXESZ;
320
6.38k
  pe->coff.local_linesz = LINESZ;
321
322
6.38k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
6.38k
  obj_raw_syment_count (abfd) =
325
6.38k
    obj_conv_table_size (abfd) =
326
6.38k
      internal_f->f_nsyms;
327
328
6.38k
  pe->real_flags = internal_f->f_flags;
329
330
6.38k
  if ((internal_f->f_flags & F_DLL) != 0)
331
1.47k
    pe->dll = 1;
332
333
6.38k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
5.15k
    abfd->flags |= HAS_DEBUG;
335
336
6.38k
#ifdef COFF_IMAGE_WITH_PE
337
6.38k
  if (aouthdr)
338
4.97k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
6.38k
#endif
340
341
#ifdef ARM
342
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
6.38k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
6.38k
    sizeof (pe->dos_message));
348
349
6.38k
  return (void *) pe;
350
6.38k
}
pei-ia64.c:pe_mkobject_hook
Line
Count
Source
302
5.35k
{
303
5.35k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
5.35k
  pe_data_type *pe;
305
306
5.35k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
5.35k
  pe = pe_data (abfd);
310
5.35k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
5.35k
  pe->coff.local_n_btmask = N_BTMASK;
315
5.35k
  pe->coff.local_n_btshft = N_BTSHFT;
316
5.35k
  pe->coff.local_n_tmask = N_TMASK;
317
5.35k
  pe->coff.local_n_tshift = N_TSHIFT;
318
5.35k
  pe->coff.local_symesz = SYMESZ;
319
5.35k
  pe->coff.local_auxesz = AUXESZ;
320
5.35k
  pe->coff.local_linesz = LINESZ;
321
322
5.35k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
5.35k
  obj_raw_syment_count (abfd) =
325
5.35k
    obj_conv_table_size (abfd) =
326
5.35k
      internal_f->f_nsyms;
327
328
5.35k
  pe->real_flags = internal_f->f_flags;
329
330
5.35k
  if ((internal_f->f_flags & F_DLL) != 0)
331
1.84k
    pe->dll = 1;
332
333
5.35k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
3.53k
    abfd->flags |= HAS_DEBUG;
335
336
5.35k
#ifdef COFF_IMAGE_WITH_PE
337
5.35k
  if (aouthdr)
338
2.78k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
5.35k
#endif
340
341
#ifdef ARM
342
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
5.35k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
5.35k
    sizeof (pe->dos_message));
348
349
5.35k
  return (void *) pe;
350
5.35k
}
pei-loongarch64.c:pe_mkobject_hook
Line
Count
Source
302
5.13k
{
303
5.13k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
5.13k
  pe_data_type *pe;
305
306
5.13k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
5.13k
  pe = pe_data (abfd);
310
5.13k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
5.13k
  pe->coff.local_n_btmask = N_BTMASK;
315
5.13k
  pe->coff.local_n_btshft = N_BTSHFT;
316
5.13k
  pe->coff.local_n_tmask = N_TMASK;
317
5.13k
  pe->coff.local_n_tshift = N_TSHIFT;
318
5.13k
  pe->coff.local_symesz = SYMESZ;
319
5.13k
  pe->coff.local_auxesz = AUXESZ;
320
5.13k
  pe->coff.local_linesz = LINESZ;
321
322
5.13k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
5.13k
  obj_raw_syment_count (abfd) =
325
5.13k
    obj_conv_table_size (abfd) =
326
5.13k
      internal_f->f_nsyms;
327
328
5.13k
  pe->real_flags = internal_f->f_flags;
329
330
5.13k
  if ((internal_f->f_flags & F_DLL) != 0)
331
1.40k
    pe->dll = 1;
332
333
5.13k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
3.72k
    abfd->flags |= HAS_DEBUG;
335
336
5.13k
#ifdef COFF_IMAGE_WITH_PE
337
5.13k
  if (aouthdr)
338
3.18k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
5.13k
#endif
340
341
#ifdef ARM
342
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
5.13k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
5.13k
    sizeof (pe->dos_message));
348
349
5.13k
  return (void *) pe;
350
5.13k
}
pei-riscv64.c:pe_mkobject_hook
Line
Count
Source
302
5.72k
{
303
5.72k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
5.72k
  pe_data_type *pe;
305
306
5.72k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
5.72k
  pe = pe_data (abfd);
310
5.72k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
5.72k
  pe->coff.local_n_btmask = N_BTMASK;
315
5.72k
  pe->coff.local_n_btshft = N_BTSHFT;
316
5.72k
  pe->coff.local_n_tmask = N_TMASK;
317
5.72k
  pe->coff.local_n_tshift = N_TSHIFT;
318
5.72k
  pe->coff.local_symesz = SYMESZ;
319
5.72k
  pe->coff.local_auxesz = AUXESZ;
320
5.72k
  pe->coff.local_linesz = LINESZ;
321
322
5.72k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
5.72k
  obj_raw_syment_count (abfd) =
325
5.72k
    obj_conv_table_size (abfd) =
326
5.72k
      internal_f->f_nsyms;
327
328
5.72k
  pe->real_flags = internal_f->f_flags;
329
330
5.72k
  if ((internal_f->f_flags & F_DLL) != 0)
331
1.60k
    pe->dll = 1;
332
333
5.72k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
4.19k
    abfd->flags |= HAS_DEBUG;
335
336
5.72k
#ifdef COFF_IMAGE_WITH_PE
337
5.72k
  if (aouthdr)
338
4.14k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
5.72k
#endif
340
341
#ifdef ARM
342
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
5.72k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
5.72k
    sizeof (pe->dos_message));
348
349
5.72k
  return (void *) pe;
350
5.72k
}
pe-arm-wince.c:pe_mkobject_hook
Line
Count
Source
302
1.95k
{
303
1.95k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
1.95k
  pe_data_type *pe;
305
306
1.95k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
1.95k
  pe = pe_data (abfd);
310
1.95k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
1.95k
  pe->coff.local_n_btmask = N_BTMASK;
315
1.95k
  pe->coff.local_n_btshft = N_BTSHFT;
316
1.95k
  pe->coff.local_n_tmask = N_TMASK;
317
1.95k
  pe->coff.local_n_tshift = N_TSHIFT;
318
1.95k
  pe->coff.local_symesz = SYMESZ;
319
1.95k
  pe->coff.local_auxesz = AUXESZ;
320
1.95k
  pe->coff.local_linesz = LINESZ;
321
322
1.95k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
1.95k
  obj_raw_syment_count (abfd) =
325
1.95k
    obj_conv_table_size (abfd) =
326
1.95k
      internal_f->f_nsyms;
327
328
1.95k
  pe->real_flags = internal_f->f_flags;
329
330
1.95k
  if ((internal_f->f_flags & F_DLL) != 0)
331
562
    pe->dll = 1;
332
333
1.95k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
1.46k
    abfd->flags |= HAS_DEBUG;
335
336
#ifdef COFF_IMAGE_WITH_PE
337
  if (aouthdr)
338
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
#endif
340
341
1.95k
#ifdef ARM
342
1.95k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
0
    coff_data (abfd) ->flags = 0;
344
1.95k
#endif
345
346
1.95k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
1.95k
    sizeof (pe->dos_message));
348
349
1.95k
  return (void *) pe;
350
1.95k
}
pe-arm.c:pe_mkobject_hook
Line
Count
Source
302
1.95k
{
303
1.95k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
1.95k
  pe_data_type *pe;
305
306
1.95k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
1.95k
  pe = pe_data (abfd);
310
1.95k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
1.95k
  pe->coff.local_n_btmask = N_BTMASK;
315
1.95k
  pe->coff.local_n_btshft = N_BTSHFT;
316
1.95k
  pe->coff.local_n_tmask = N_TMASK;
317
1.95k
  pe->coff.local_n_tshift = N_TSHIFT;
318
1.95k
  pe->coff.local_symesz = SYMESZ;
319
1.95k
  pe->coff.local_auxesz = AUXESZ;
320
1.95k
  pe->coff.local_linesz = LINESZ;
321
322
1.95k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
1.95k
  obj_raw_syment_count (abfd) =
325
1.95k
    obj_conv_table_size (abfd) =
326
1.95k
      internal_f->f_nsyms;
327
328
1.95k
  pe->real_flags = internal_f->f_flags;
329
330
1.95k
  if ((internal_f->f_flags & F_DLL) != 0)
331
562
    pe->dll = 1;
332
333
1.95k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
1.46k
    abfd->flags |= HAS_DEBUG;
335
336
#ifdef COFF_IMAGE_WITH_PE
337
  if (aouthdr)
338
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
#endif
340
341
1.95k
#ifdef ARM
342
1.95k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
0
    coff_data (abfd) ->flags = 0;
344
1.95k
#endif
345
346
1.95k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
1.95k
    sizeof (pe->dos_message));
348
349
1.95k
  return (void *) pe;
350
1.95k
}
pe-i386.c:pe_mkobject_hook
Line
Count
Source
302
7.92k
{
303
7.92k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
7.92k
  pe_data_type *pe;
305
306
7.92k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
7.92k
  pe = pe_data (abfd);
310
7.92k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
7.92k
  pe->coff.local_n_btmask = N_BTMASK;
315
7.92k
  pe->coff.local_n_btshft = N_BTSHFT;
316
7.92k
  pe->coff.local_n_tmask = N_TMASK;
317
7.92k
  pe->coff.local_n_tshift = N_TSHIFT;
318
7.92k
  pe->coff.local_symesz = SYMESZ;
319
7.92k
  pe->coff.local_auxesz = AUXESZ;
320
7.92k
  pe->coff.local_linesz = LINESZ;
321
322
7.92k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
7.92k
  obj_raw_syment_count (abfd) =
325
7.92k
    obj_conv_table_size (abfd) =
326
7.92k
      internal_f->f_nsyms;
327
328
7.92k
  pe->real_flags = internal_f->f_flags;
329
330
7.92k
  if ((internal_f->f_flags & F_DLL) != 0)
331
2.00k
    pe->dll = 1;
332
333
7.92k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
5.11k
    abfd->flags |= HAS_DEBUG;
335
336
#ifdef COFF_IMAGE_WITH_PE
337
  if (aouthdr)
338
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
#endif
340
341
#ifdef ARM
342
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
7.92k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
7.92k
    sizeof (pe->dos_message));
348
349
7.92k
  return (void *) pe;
350
7.92k
}
pe-mcore.c:pe_mkobject_hook
Line
Count
Source
302
2.68k
{
303
2.68k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
2.68k
  pe_data_type *pe;
305
306
2.68k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
2.68k
  pe = pe_data (abfd);
310
2.68k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
2.68k
  pe->coff.local_n_btmask = N_BTMASK;
315
2.68k
  pe->coff.local_n_btshft = N_BTSHFT;
316
2.68k
  pe->coff.local_n_tmask = N_TMASK;
317
2.68k
  pe->coff.local_n_tshift = N_TSHIFT;
318
2.68k
  pe->coff.local_symesz = SYMESZ;
319
2.68k
  pe->coff.local_auxesz = AUXESZ;
320
2.68k
  pe->coff.local_linesz = LINESZ;
321
322
2.68k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
2.68k
  obj_raw_syment_count (abfd) =
325
2.68k
    obj_conv_table_size (abfd) =
326
2.68k
      internal_f->f_nsyms;
327
328
2.68k
  pe->real_flags = internal_f->f_flags;
329
330
2.68k
  if ((internal_f->f_flags & F_DLL) != 0)
331
816
    pe->dll = 1;
332
333
2.68k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
2.18k
    abfd->flags |= HAS_DEBUG;
335
336
#ifdef COFF_IMAGE_WITH_PE
337
  if (aouthdr)
338
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
#endif
340
341
#ifdef ARM
342
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
2.68k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
2.68k
    sizeof (pe->dos_message));
348
349
2.68k
  return (void *) pe;
350
2.68k
}
pe-sh.c:pe_mkobject_hook
Line
Count
Source
302
4.08k
{
303
4.08k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
4.08k
  pe_data_type *pe;
305
306
4.08k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
4.08k
  pe = pe_data (abfd);
310
4.08k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
4.08k
  pe->coff.local_n_btmask = N_BTMASK;
315
4.08k
  pe->coff.local_n_btshft = N_BTSHFT;
316
4.08k
  pe->coff.local_n_tmask = N_TMASK;
317
4.08k
  pe->coff.local_n_tshift = N_TSHIFT;
318
4.08k
  pe->coff.local_symesz = SYMESZ;
319
4.08k
  pe->coff.local_auxesz = AUXESZ;
320
4.08k
  pe->coff.local_linesz = LINESZ;
321
322
4.08k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
4.08k
  obj_raw_syment_count (abfd) =
325
4.08k
    obj_conv_table_size (abfd) =
326
4.08k
      internal_f->f_nsyms;
327
328
4.08k
  pe->real_flags = internal_f->f_flags;
329
330
4.08k
  if ((internal_f->f_flags & F_DLL) != 0)
331
1.04k
    pe->dll = 1;
332
333
4.08k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
3.28k
    abfd->flags |= HAS_DEBUG;
335
336
#ifdef COFF_IMAGE_WITH_PE
337
  if (aouthdr)
338
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
#endif
340
341
#ifdef ARM
342
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
4.08k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
4.08k
    sizeof (pe->dos_message));
348
349
4.08k
  return (void *) pe;
350
4.08k
}
pei-arm-wince.c:pe_mkobject_hook
Line
Count
Source
302
4.87k
{
303
4.87k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
4.87k
  pe_data_type *pe;
305
306
4.87k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
4.87k
  pe = pe_data (abfd);
310
4.87k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
4.87k
  pe->coff.local_n_btmask = N_BTMASK;
315
4.87k
  pe->coff.local_n_btshft = N_BTSHFT;
316
4.87k
  pe->coff.local_n_tmask = N_TMASK;
317
4.87k
  pe->coff.local_n_tshift = N_TSHIFT;
318
4.87k
  pe->coff.local_symesz = SYMESZ;
319
4.87k
  pe->coff.local_auxesz = AUXESZ;
320
4.87k
  pe->coff.local_linesz = LINESZ;
321
322
4.87k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
4.87k
  obj_raw_syment_count (abfd) =
325
4.87k
    obj_conv_table_size (abfd) =
326
4.87k
      internal_f->f_nsyms;
327
328
4.87k
  pe->real_flags = internal_f->f_flags;
329
330
4.87k
  if ((internal_f->f_flags & F_DLL) != 0)
331
1.88k
    pe->dll = 1;
332
333
4.87k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
2.97k
    abfd->flags |= HAS_DEBUG;
335
336
4.87k
#ifdef COFF_IMAGE_WITH_PE
337
4.87k
  if (aouthdr)
338
2.02k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
4.87k
#endif
340
341
4.87k
#ifdef ARM
342
4.87k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
0
    coff_data (abfd) ->flags = 0;
344
4.87k
#endif
345
346
4.87k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
4.87k
    sizeof (pe->dos_message));
348
349
4.87k
  return (void *) pe;
350
4.87k
}
pei-arm.c:pe_mkobject_hook
Line
Count
Source
302
6.14k
{
303
6.14k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
6.14k
  pe_data_type *pe;
305
306
6.14k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
6.14k
  pe = pe_data (abfd);
310
6.14k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
6.14k
  pe->coff.local_n_btmask = N_BTMASK;
315
6.14k
  pe->coff.local_n_btshft = N_BTSHFT;
316
6.14k
  pe->coff.local_n_tmask = N_TMASK;
317
6.14k
  pe->coff.local_n_tshift = N_TSHIFT;
318
6.14k
  pe->coff.local_symesz = SYMESZ;
319
6.14k
  pe->coff.local_auxesz = AUXESZ;
320
6.14k
  pe->coff.local_linesz = LINESZ;
321
322
6.14k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
6.14k
  obj_raw_syment_count (abfd) =
325
6.14k
    obj_conv_table_size (abfd) =
326
6.14k
      internal_f->f_nsyms;
327
328
6.14k
  pe->real_flags = internal_f->f_flags;
329
330
6.14k
  if ((internal_f->f_flags & F_DLL) != 0)
331
2.26k
    pe->dll = 1;
332
333
6.14k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
3.97k
    abfd->flags |= HAS_DEBUG;
335
336
6.14k
#ifdef COFF_IMAGE_WITH_PE
337
6.14k
  if (aouthdr)
338
3.29k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
6.14k
#endif
340
341
6.14k
#ifdef ARM
342
6.14k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
0
    coff_data (abfd) ->flags = 0;
344
6.14k
#endif
345
346
6.14k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
6.14k
    sizeof (pe->dos_message));
348
349
6.14k
  return (void *) pe;
350
6.14k
}
pei-mcore.c:pe_mkobject_hook
Line
Count
Source
302
4.16k
{
303
4.16k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
4.16k
  pe_data_type *pe;
305
306
4.16k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
4.16k
  pe = pe_data (abfd);
310
4.16k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
4.16k
  pe->coff.local_n_btmask = N_BTMASK;
315
4.16k
  pe->coff.local_n_btshft = N_BTSHFT;
316
4.16k
  pe->coff.local_n_tmask = N_TMASK;
317
4.16k
  pe->coff.local_n_tshift = N_TSHIFT;
318
4.16k
  pe->coff.local_symesz = SYMESZ;
319
4.16k
  pe->coff.local_auxesz = AUXESZ;
320
4.16k
  pe->coff.local_linesz = LINESZ;
321
322
4.16k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
4.16k
  obj_raw_syment_count (abfd) =
325
4.16k
    obj_conv_table_size (abfd) =
326
4.16k
      internal_f->f_nsyms;
327
328
4.16k
  pe->real_flags = internal_f->f_flags;
329
330
4.16k
  if ((internal_f->f_flags & F_DLL) != 0)
331
1.59k
    pe->dll = 1;
332
333
4.16k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
2.58k
    abfd->flags |= HAS_DEBUG;
335
336
4.16k
#ifdef COFF_IMAGE_WITH_PE
337
4.16k
  if (aouthdr)
338
2.42k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
4.16k
#endif
340
341
#ifdef ARM
342
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
4.16k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
4.16k
    sizeof (pe->dos_message));
348
349
4.16k
  return (void *) pe;
350
4.16k
}
pei-sh.c:pe_mkobject_hook
Line
Count
Source
302
4.62k
{
303
4.62k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
4.62k
  pe_data_type *pe;
305
306
4.62k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
4.62k
  pe = pe_data (abfd);
310
4.62k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
4.62k
  pe->coff.local_n_btmask = N_BTMASK;
315
4.62k
  pe->coff.local_n_btshft = N_BTSHFT;
316
4.62k
  pe->coff.local_n_tmask = N_TMASK;
317
4.62k
  pe->coff.local_n_tshift = N_TSHIFT;
318
4.62k
  pe->coff.local_symesz = SYMESZ;
319
4.62k
  pe->coff.local_auxesz = AUXESZ;
320
4.62k
  pe->coff.local_linesz = LINESZ;
321
322
4.62k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
4.62k
  obj_raw_syment_count (abfd) =
325
4.62k
    obj_conv_table_size (abfd) =
326
4.62k
      internal_f->f_nsyms;
327
328
4.62k
  pe->real_flags = internal_f->f_flags;
329
330
4.62k
  if ((internal_f->f_flags & F_DLL) != 0)
331
1.75k
    pe->dll = 1;
332
333
4.62k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
2.67k
    abfd->flags |= HAS_DEBUG;
335
336
4.62k
#ifdef COFF_IMAGE_WITH_PE
337
4.62k
  if (aouthdr)
338
2.86k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
4.62k
#endif
340
341
#ifdef ARM
342
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
4.62k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
4.62k
    sizeof (pe->dos_message));
348
349
4.62k
  return (void *) pe;
350
4.62k
}
351
352
static bool
353
pe_print_private_bfd_data (bfd *abfd, void *vfile)
354
4.03k
{
355
4.03k
  FILE *file = (FILE *) vfile;
356
357
4.03k
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
4.03k
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
3.85k
    return true;
362
363
188
  fputc ('\n', file);
364
365
188
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
4.03k
}
pei-i386.c:pe_print_private_bfd_data
Line
Count
Source
354
141
{
355
141
  FILE *file = (FILE *) vfile;
356
357
141
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
141
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
141
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
141
}
pe-x86_64.c:pe_print_private_bfd_data
Line
Count
Source
354
139
{
355
139
  FILE *file = (FILE *) vfile;
356
357
139
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
139
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
139
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
139
}
pei-x86_64.c:pe_print_private_bfd_data
Line
Count
Source
354
98
{
355
98
  FILE *file = (FILE *) vfile;
356
357
98
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
98
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
98
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
98
}
pe-aarch64.c:pe_print_private_bfd_data
Line
Count
Source
354
481
{
355
481
  FILE *file = (FILE *) vfile;
356
357
481
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
481
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
481
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
481
}
pei-aarch64.c:pe_print_private_bfd_data
Line
Count
Source
354
2.24k
{
355
2.24k
  FILE *file = (FILE *) vfile;
356
357
2.24k
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
2.24k
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
2.24k
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
2.24k
}
pei-ia64.c:pe_print_private_bfd_data
Line
Count
Source
354
235
{
355
235
  FILE *file = (FILE *) vfile;
356
357
235
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
235
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
235
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
235
}
pei-loongarch64.c:pe_print_private_bfd_data
Line
Count
Source
354
93
{
355
93
  FILE *file = (FILE *) vfile;
356
357
93
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
93
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
93
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
93
}
pei-riscv64.c:pe_print_private_bfd_data
Line
Count
Source
354
204
{
355
204
  FILE *file = (FILE *) vfile;
356
357
204
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
204
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
204
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
204
}
Unexecuted instantiation: pe-arm-wince.c:pe_print_private_bfd_data
Unexecuted instantiation: pe-arm.c:pe_print_private_bfd_data
pe-i386.c:pe_print_private_bfd_data
Line
Count
Source
354
41
{
355
41
  FILE *file = (FILE *) vfile;
356
357
41
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
41
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
41
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
41
}
pe-mcore.c:pe_print_private_bfd_data
Line
Count
Source
354
27
{
355
27
  FILE *file = (FILE *) vfile;
356
357
27
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
27
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
27
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
27
}
pe-sh.c:pe_print_private_bfd_data
Line
Count
Source
354
46
{
355
46
  FILE *file = (FILE *) vfile;
356
357
46
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
46
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
46
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
46
}
pei-arm-wince.c:pe_print_private_bfd_data
Line
Count
Source
354
10
{
355
10
  FILE *file = (FILE *) vfile;
356
357
10
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
10
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
0
    return true;
362
363
10
  fputc ('\n', file);
364
365
10
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
10
}
pei-arm.c:pe_print_private_bfd_data
Line
Count
Source
354
178
{
355
178
  FILE *file = (FILE *) vfile;
356
357
178
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
178
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
0
    return true;
362
363
178
  fputc ('\n', file);
364
365
178
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
178
}
pei-mcore.c:pe_print_private_bfd_data
Line
Count
Source
354
57
{
355
57
  FILE *file = (FILE *) vfile;
356
357
57
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
57
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
57
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
57
}
pei-sh.c:pe_print_private_bfd_data
Line
Count
Source
354
48
{
355
48
  FILE *file = (FILE *) vfile;
356
357
48
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
48
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
48
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
48
}
367
368
/* Copy any private info we understand from the input bfd
369
   to the output bfd.  */
370
371
static bool
372
pe_bfd_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
373
976
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
976
  if (pe_data (obfd) != NULL
378
976
      && pe_data (ibfd) != NULL
379
976
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
306
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
976
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
10
    return false;
384
385
966
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
79
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
887
  return true;
389
966
}
pei-i386.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
82
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
82
  if (pe_data (obfd) != NULL
378
82
      && pe_data (ibfd) != NULL
379
82
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
14
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
82
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
0
    return false;
384
385
82
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
82
  return true;
389
82
}
pe-x86_64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
128
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
128
  if (pe_data (obfd) != NULL
378
128
      && pe_data (ibfd) != NULL
379
128
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
19
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
128
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
0
    return false;
384
385
128
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
128
  return true;
389
128
}
pei-x86_64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
61
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
61
  if (pe_data (obfd) != NULL
378
61
      && pe_data (ibfd) != NULL
379
61
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
27
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
61
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
1
    return false;
384
385
60
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
60
  return true;
389
60
}
pe-aarch64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
74
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
74
  if (pe_data (obfd) != NULL
378
74
      && pe_data (ibfd) != NULL
379
74
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
19
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
74
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
0
    return false;
384
385
74
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
74
  return true;
389
74
}
pei-aarch64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
66
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
66
  if (pe_data (obfd) != NULL
378
66
      && pe_data (ibfd) != NULL
379
66
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
33
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
66
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
0
    return false;
384
385
66
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
66
  return true;
389
66
}
pei-ia64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
84
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
84
  if (pe_data (obfd) != NULL
378
84
      && pe_data (ibfd) != NULL
379
84
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
29
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
84
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
2
    return false;
384
385
82
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
82
  return true;
389
82
}
pei-loongarch64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
88
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
88
  if (pe_data (obfd) != NULL
378
88
      && pe_data (ibfd) != NULL
379
88
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
14
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
88
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
2
    return false;
384
385
86
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
86
  return true;
389
86
}
pei-riscv64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
80
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
80
  if (pe_data (obfd) != NULL
378
80
      && pe_data (ibfd) != NULL
379
80
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
51
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
80
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
1
    return false;
384
385
79
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
79
  return true;
389
79
}
Unexecuted instantiation: pe-arm-wince.c:pe_bfd_copy_private_bfd_data
Unexecuted instantiation: pe-arm.c:pe_bfd_copy_private_bfd_data
pe-i386.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
36
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
36
  if (pe_data (obfd) != NULL
378
36
      && pe_data (ibfd) != NULL
379
36
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
13
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
36
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
0
    return false;
384
385
36
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
36
  return true;
389
36
}
pe-mcore.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
61
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
61
  if (pe_data (obfd) != NULL
378
61
      && pe_data (ibfd) != NULL
379
61
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
10
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
61
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
0
    return false;
384
385
61
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
61
  return true;
389
61
}
pe-sh.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
47
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
47
  if (pe_data (obfd) != NULL
378
47
      && pe_data (ibfd) != NULL
379
47
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
11
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
47
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
0
    return false;
384
385
47
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
47
  return true;
389
47
}
pei-arm-wince.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
28
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
28
  if (pe_data (obfd) != NULL
378
28
      && pe_data (ibfd) != NULL
379
28
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
8
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
28
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
1
    return false;
384
385
27
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
27
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
0
  return true;
389
27
}
pei-arm.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
53
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
53
  if (pe_data (obfd) != NULL
378
53
      && pe_data (ibfd) != NULL
379
53
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
25
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
53
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
1
    return false;
384
385
52
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
52
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
0
  return true;
389
52
}
pei-mcore.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
30
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
30
  if (pe_data (obfd) != NULL
378
30
      && pe_data (ibfd) != NULL
379
30
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
17
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
30
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
1
    return false;
384
385
29
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
29
  return true;
389
29
}
pei-sh.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
58
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
58
  if (pe_data (obfd) != NULL
378
58
      && pe_data (ibfd) != NULL
379
58
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
16
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
58
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
1
    return false;
384
385
57
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
57
  return true;
389
57
}
390
391
#define coff_bfd_copy_private_section_data \
392
  _bfd_XX_bfd_copy_private_section_data
393
394
#define coff_get_symbol_info _bfd_XX_get_symbol_info
395
396
#ifdef COFF_IMAGE_WITH_PE
397

398
/* Code to handle Microsoft's Import Library Format.
399
   Also known as LINK6 format.
400
   Documentation about this format can be found at:
401
402
   https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#import-library-format  */
403
404
/* The following constants specify the sizes of the various data
405
   structures that we have to create in order to build a bfd describing
406
   an ILF object file.  The final "+ 1" in the definitions of SIZEOF_IDATA6
407
   and SIZEOF_IDATA7 below is to allow for the possibility that we might
408
   need a padding byte in order to ensure 16 bit alignment for the section's
409
   contents.
410
411
   The value for SIZEOF_ILF_STRINGS is computed as follows:
412
413
      There will be NUM_ILF_SECTIONS section symbols.  Allow 9 characters
414
      per symbol for their names (longest section name is .idata$x).
415
416
      There will be two symbols for the imported value, one the symbol name
417
      and one with _imp__ prefixed.  Allowing for the terminating nul's this
418
      is strlen (symbol_name) * 2 + 8 + 21 + strlen (source_dll).
419
420
      The strings in the string table must start STRING__SIZE_SIZE bytes into
421
      the table in order to for the string lookup code in coffgen/coffcode to
422
      work.  */
423
3.96k
#define NUM_ILF_RELOCS    8
424
13.2k
#define NUM_ILF_SECTIONS  6
425
9.90k
#define NUM_ILF_SYMS    (2 + NUM_ILF_SECTIONS)
426
427
1.98k
#define SIZEOF_ILF_SYMS    (NUM_ILF_SYMS * sizeof (*vars.sym_cache))
428
1.98k
#define SIZEOF_ILF_SYM_TABLE   (NUM_ILF_SYMS * sizeof (*vars.sym_table))
429
1.98k
#define SIZEOF_ILF_NATIVE_SYMS   (NUM_ILF_SYMS * sizeof (*vars.native_syms))
430
1.98k
#define SIZEOF_ILF_SYM_PTR_TABLE (NUM_ILF_SYMS * sizeof (*vars.sym_ptr_table))
431
1.98k
#define SIZEOF_ILF_EXT_SYMS  (NUM_ILF_SYMS * sizeof (*vars.esym_table))
432
1.98k
#define SIZEOF_ILF_RELOCS  (NUM_ILF_RELOCS * sizeof (*vars.reltab))
433
1.98k
#define SIZEOF_ILF_INT_RELOCS  (NUM_ILF_RELOCS * sizeof (*vars.int_reltab))
434
1.98k
#define SIZEOF_ILF_STRINGS   (strlen (symbol_name) * 2 + 8 \
435
1.98k
          + 21 + strlen (source_dll)   \
436
1.98k
          + NUM_ILF_SECTIONS * 9       \
437
1.98k
          + STRING_SIZE_SIZE)
438
1.32k
#define SIZEOF_IDATA2   (5 * 4)
439
440
/* For PEx64 idata4 & 5 have thumb size of 8 bytes.  */
441
#if defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64)
442
540
#define SIZEOF_IDATA4   (2 * 4)
443
540
#define SIZEOF_IDATA5   (2 * 4)
444
#else
445
1.44k
#define SIZEOF_IDATA4   (1 * 4)
446
1.44k
#define SIZEOF_IDATA5   (1 * 4)
447
#endif
448
449
1.79k
#define SIZEOF_IDATA6   (2 + strlen (import_name) + 1 + 1)
450
1.32k
#define SIZEOF_IDATA7   (strlen (source_dll) + 1 + 1)
451
1.32k
#define SIZEOF_ILF_SECTIONS (NUM_ILF_SECTIONS \
452
1.32k
         * sizeof (struct coff_section_tdata))
453
454
#define ILF_DATA_SIZE       \
455
1.32k
    + SIZEOF_ILF_SYMS        \
456
1.32k
    + SIZEOF_ILF_SYM_TABLE      \
457
1.32k
    + SIZEOF_ILF_NATIVE_SYMS      \
458
1.32k
    + SIZEOF_ILF_SYM_PTR_TABLE      \
459
1.32k
    + SIZEOF_ILF_EXT_SYMS      \
460
1.32k
    + SIZEOF_ILF_RELOCS        \
461
1.32k
    + SIZEOF_ILF_INT_RELOCS      \
462
1.32k
    + SIZEOF_ILF_STRINGS      \
463
1.32k
    + SIZEOF_IDATA2        \
464
1.32k
    + SIZEOF_IDATA4        \
465
1.32k
    + SIZEOF_IDATA5        \
466
1.32k
    + SIZEOF_IDATA6        \
467
1.32k
    + SIZEOF_IDATA7        \
468
1.32k
    + SIZEOF_ILF_SECTIONS      \
469
1.32k
    + MAX_TEXT_SECTION_SIZE
470
471
/* Create an empty relocation against the given symbol.  */
472
473
static void
474
pe_ILF_make_a_symbol_reloc (pe_ILF_vars *   vars,
475
          bfd_vma     address,
476
          bfd_reloc_code_real_type  reloc,
477
          struct bfd_symbol **  sym,
478
          unsigned int    sym_index)
479
1.22k
{
480
1.22k
  arelent *entry;
481
1.22k
  struct internal_reloc *internal;
482
483
1.22k
  entry = vars->reltab + vars->relcount;
484
1.22k
  internal = vars->int_reltab + vars->relcount;
485
486
1.22k
  entry->address     = address;
487
1.22k
  entry->addend      = 0;
488
1.22k
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
489
1.22k
  entry->sym_ptr_ptr = sym;
490
491
1.22k
  internal->r_vaddr  = address;
492
1.22k
  internal->r_symndx = sym_index;
493
1.22k
  internal->r_type   = entry->howto ? entry->howto->type : 0;
494
495
1.22k
  vars->relcount ++;
496
497
1.22k
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
498
1.22k
}
pei-i386.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
479
196
{
480
196
  arelent *entry;
481
196
  struct internal_reloc *internal;
482
483
196
  entry = vars->reltab + vars->relcount;
484
196
  internal = vars->int_reltab + vars->relcount;
485
486
196
  entry->address     = address;
487
196
  entry->addend      = 0;
488
196
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
489
196
  entry->sym_ptr_ptr = sym;
490
491
196
  internal->r_vaddr  = address;
492
196
  internal->r_symndx = sym_index;
493
196
  internal->r_type   = entry->howto ? entry->howto->type : 0;
494
495
196
  vars->relcount ++;
496
497
196
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
498
196
}
pei-x86_64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
479
168
{
480
168
  arelent *entry;
481
168
  struct internal_reloc *internal;
482
483
168
  entry = vars->reltab + vars->relcount;
484
168
  internal = vars->int_reltab + vars->relcount;
485
486
168
  entry->address     = address;
487
168
  entry->addend      = 0;
488
168
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
489
168
  entry->sym_ptr_ptr = sym;
490
491
168
  internal->r_vaddr  = address;
492
168
  internal->r_symndx = sym_index;
493
168
  internal->r_type   = entry->howto ? entry->howto->type : 0;
494
495
168
  vars->relcount ++;
496
497
168
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
498
168
}
pei-aarch64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
479
187
{
480
187
  arelent *entry;
481
187
  struct internal_reloc *internal;
482
483
187
  entry = vars->reltab + vars->relcount;
484
187
  internal = vars->int_reltab + vars->relcount;
485
486
187
  entry->address     = address;
487
187
  entry->addend      = 0;
488
187
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
489
187
  entry->sym_ptr_ptr = sym;
490
491
187
  internal->r_vaddr  = address;
492
187
  internal->r_symndx = sym_index;
493
187
  internal->r_type   = entry->howto ? entry->howto->type : 0;
494
495
187
  vars->relcount ++;
496
497
187
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
498
187
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_symbol_reloc
pei-loongarch64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
479
156
{
480
156
  arelent *entry;
481
156
  struct internal_reloc *internal;
482
483
156
  entry = vars->reltab + vars->relcount;
484
156
  internal = vars->int_reltab + vars->relcount;
485
486
156
  entry->address     = address;
487
156
  entry->addend      = 0;
488
156
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
489
156
  entry->sym_ptr_ptr = sym;
490
491
156
  internal->r_vaddr  = address;
492
156
  internal->r_symndx = sym_index;
493
156
  internal->r_type   = entry->howto ? entry->howto->type : 0;
494
495
156
  vars->relcount ++;
496
497
156
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
498
156
}
pei-riscv64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
479
165
{
480
165
  arelent *entry;
481
165
  struct internal_reloc *internal;
482
483
165
  entry = vars->reltab + vars->relcount;
484
165
  internal = vars->int_reltab + vars->relcount;
485
486
165
  entry->address     = address;
487
165
  entry->addend      = 0;
488
165
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
489
165
  entry->sym_ptr_ptr = sym;
490
491
165
  internal->r_vaddr  = address;
492
165
  internal->r_symndx = sym_index;
493
165
  internal->r_type   = entry->howto ? entry->howto->type : 0;
494
495
165
  vars->relcount ++;
496
497
165
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
498
165
}
pei-arm-wince.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
479
96
{
480
96
  arelent *entry;
481
96
  struct internal_reloc *internal;
482
483
96
  entry = vars->reltab + vars->relcount;
484
96
  internal = vars->int_reltab + vars->relcount;
485
486
96
  entry->address     = address;
487
96
  entry->addend      = 0;
488
96
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
489
96
  entry->sym_ptr_ptr = sym;
490
491
96
  internal->r_vaddr  = address;
492
96
  internal->r_symndx = sym_index;
493
96
  internal->r_type   = entry->howto ? entry->howto->type : 0;
494
495
96
  vars->relcount ++;
496
497
96
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
498
96
}
pei-arm.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
479
99
{
480
99
  arelent *entry;
481
99
  struct internal_reloc *internal;
482
483
99
  entry = vars->reltab + vars->relcount;
484
99
  internal = vars->int_reltab + vars->relcount;
485
486
99
  entry->address     = address;
487
99
  entry->addend      = 0;
488
99
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
489
99
  entry->sym_ptr_ptr = sym;
490
491
99
  internal->r_vaddr  = address;
492
99
  internal->r_symndx = sym_index;
493
99
  internal->r_type   = entry->howto ? entry->howto->type : 0;
494
495
99
  vars->relcount ++;
496
497
99
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
498
99
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_symbol_reloc
pei-sh.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
479
154
{
480
154
  arelent *entry;
481
154
  struct internal_reloc *internal;
482
483
154
  entry = vars->reltab + vars->relcount;
484
154
  internal = vars->int_reltab + vars->relcount;
485
486
154
  entry->address     = address;
487
154
  entry->addend      = 0;
488
154
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
489
154
  entry->sym_ptr_ptr = sym;
490
491
154
  internal->r_vaddr  = address;
492
154
  internal->r_symndx = sym_index;
493
154
  internal->r_type   = entry->howto ? entry->howto->type : 0;
494
495
154
  vars->relcount ++;
496
497
154
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
498
154
}
499
500
/* Create an empty relocation against the given section.  */
501
502
static void
503
pe_ILF_make_a_reloc (pe_ILF_vars *         vars,
504
         bfd_vma           address,
505
         bfd_reloc_code_real_type  reloc,
506
         asection_ptr        sec)
507
956
{
508
956
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
509
956
            coff_section_data (vars->abfd, sec)->i);
510
956
}
pei-i386.c:pe_ILF_make_a_reloc
Line
Count
Source
507
152
{
508
152
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
509
152
            coff_section_data (vars->abfd, sec)->i);
510
152
}
pei-x86_64.c:pe_ILF_make_a_reloc
Line
Count
Source
507
130
{
508
130
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
509
130
            coff_section_data (vars->abfd, sec)->i);
510
130
}
pei-aarch64.c:pe_ILF_make_a_reloc
Line
Count
Source
507
136
{
508
136
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
509
136
            coff_section_data (vars->abfd, sec)->i);
510
136
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_reloc
pei-loongarch64.c:pe_ILF_make_a_reloc
Line
Count
Source
507
124
{
508
124
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
509
124
            coff_section_data (vars->abfd, sec)->i);
510
124
}
pei-riscv64.c:pe_ILF_make_a_reloc
Line
Count
Source
507
138
{
508
138
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
509
138
            coff_section_data (vars->abfd, sec)->i);
510
138
}
pei-arm-wince.c:pe_ILF_make_a_reloc
Line
Count
Source
507
74
{
508
74
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
509
74
            coff_section_data (vars->abfd, sec)->i);
510
74
}
pei-arm.c:pe_ILF_make_a_reloc
Line
Count
Source
507
76
{
508
76
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
509
76
            coff_section_data (vars->abfd, sec)->i);
510
76
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_reloc
pei-sh.c:pe_ILF_make_a_reloc
Line
Count
Source
507
126
{
508
126
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
509
126
            coff_section_data (vars->abfd, sec)->i);
510
126
}
511
512
/* Move the queued relocs into the given section.  */
513
514
static void
515
pe_ILF_save_relocs (pe_ILF_vars *vars,
516
        asection_ptr sec)
517
1.22k
{
518
  /* Make sure that there is somewhere to store the internal relocs.  */
519
1.22k
  if (coff_section_data (vars->abfd, sec) == NULL)
520
    /* We should probably return an error indication here.  */
521
0
    abort ();
522
523
1.22k
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
524
525
1.22k
  sec->relocation  = vars->reltab;
526
1.22k
  sec->reloc_count = vars->relcount;
527
1.22k
  sec->flags      |= SEC_RELOC;
528
529
1.22k
  vars->reltab     += vars->relcount;
530
1.22k
  vars->int_reltab += vars->relcount;
531
1.22k
  vars->relcount   = 0;
532
533
1.22k
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
534
1.22k
}
pei-i386.c:pe_ILF_save_relocs
Line
Count
Source
517
196
{
518
  /* Make sure that there is somewhere to store the internal relocs.  */
519
196
  if (coff_section_data (vars->abfd, sec) == NULL)
520
    /* We should probably return an error indication here.  */
521
0
    abort ();
522
523
196
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
524
525
196
  sec->relocation  = vars->reltab;
526
196
  sec->reloc_count = vars->relcount;
527
196
  sec->flags      |= SEC_RELOC;
528
529
196
  vars->reltab     += vars->relcount;
530
196
  vars->int_reltab += vars->relcount;
531
196
  vars->relcount   = 0;
532
533
196
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
534
196
}
pei-x86_64.c:pe_ILF_save_relocs
Line
Count
Source
517
168
{
518
  /* Make sure that there is somewhere to store the internal relocs.  */
519
168
  if (coff_section_data (vars->abfd, sec) == NULL)
520
    /* We should probably return an error indication here.  */
521
0
    abort ();
522
523
168
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
524
525
168
  sec->relocation  = vars->reltab;
526
168
  sec->reloc_count = vars->relcount;
527
168
  sec->flags      |= SEC_RELOC;
528
529
168
  vars->reltab     += vars->relcount;
530
168
  vars->int_reltab += vars->relcount;
531
168
  vars->relcount   = 0;
532
533
168
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
534
168
}
pei-aarch64.c:pe_ILF_save_relocs
Line
Count
Source
517
187
{
518
  /* Make sure that there is somewhere to store the internal relocs.  */
519
187
  if (coff_section_data (vars->abfd, sec) == NULL)
520
    /* We should probably return an error indication here.  */
521
0
    abort ();
522
523
187
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
524
525
187
  sec->relocation  = vars->reltab;
526
187
  sec->reloc_count = vars->relcount;
527
187
  sec->flags      |= SEC_RELOC;
528
529
187
  vars->reltab     += vars->relcount;
530
187
  vars->int_reltab += vars->relcount;
531
187
  vars->relcount   = 0;
532
533
187
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
534
187
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_save_relocs
pei-loongarch64.c:pe_ILF_save_relocs
Line
Count
Source
517
156
{
518
  /* Make sure that there is somewhere to store the internal relocs.  */
519
156
  if (coff_section_data (vars->abfd, sec) == NULL)
520
    /* We should probably return an error indication here.  */
521
0
    abort ();
522
523
156
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
524
525
156
  sec->relocation  = vars->reltab;
526
156
  sec->reloc_count = vars->relcount;
527
156
  sec->flags      |= SEC_RELOC;
528
529
156
  vars->reltab     += vars->relcount;
530
156
  vars->int_reltab += vars->relcount;
531
156
  vars->relcount   = 0;
532
533
156
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
534
156
}
pei-riscv64.c:pe_ILF_save_relocs
Line
Count
Source
517
165
{
518
  /* Make sure that there is somewhere to store the internal relocs.  */
519
165
  if (coff_section_data (vars->abfd, sec) == NULL)
520
    /* We should probably return an error indication here.  */
521
0
    abort ();
522
523
165
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
524
525
165
  sec->relocation  = vars->reltab;
526
165
  sec->reloc_count = vars->relcount;
527
165
  sec->flags      |= SEC_RELOC;
528
529
165
  vars->reltab     += vars->relcount;
530
165
  vars->int_reltab += vars->relcount;
531
165
  vars->relcount   = 0;
532
533
165
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
534
165
}
pei-arm-wince.c:pe_ILF_save_relocs
Line
Count
Source
517
96
{
518
  /* Make sure that there is somewhere to store the internal relocs.  */
519
96
  if (coff_section_data (vars->abfd, sec) == NULL)
520
    /* We should probably return an error indication here.  */
521
0
    abort ();
522
523
96
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
524
525
96
  sec->relocation  = vars->reltab;
526
96
  sec->reloc_count = vars->relcount;
527
96
  sec->flags      |= SEC_RELOC;
528
529
96
  vars->reltab     += vars->relcount;
530
96
  vars->int_reltab += vars->relcount;
531
96
  vars->relcount   = 0;
532
533
96
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
534
96
}
pei-arm.c:pe_ILF_save_relocs
Line
Count
Source
517
99
{
518
  /* Make sure that there is somewhere to store the internal relocs.  */
519
99
  if (coff_section_data (vars->abfd, sec) == NULL)
520
    /* We should probably return an error indication here.  */
521
0
    abort ();
522
523
99
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
524
525
99
  sec->relocation  = vars->reltab;
526
99
  sec->reloc_count = vars->relcount;
527
99
  sec->flags      |= SEC_RELOC;
528
529
99
  vars->reltab     += vars->relcount;
530
99
  vars->int_reltab += vars->relcount;
531
99
  vars->relcount   = 0;
532
533
99
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
534
99
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_save_relocs
pei-sh.c:pe_ILF_save_relocs
Line
Count
Source
517
154
{
518
  /* Make sure that there is somewhere to store the internal relocs.  */
519
154
  if (coff_section_data (vars->abfd, sec) == NULL)
520
    /* We should probably return an error indication here.  */
521
0
    abort ();
522
523
154
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
524
525
154
  sec->relocation  = vars->reltab;
526
154
  sec->reloc_count = vars->relcount;
527
154
  sec->flags      |= SEC_RELOC;
528
529
154
  vars->reltab     += vars->relcount;
530
154
  vars->int_reltab += vars->relcount;
531
154
  vars->relcount   = 0;
532
533
154
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
534
154
}
535
536
/* Create a global symbol and add it to the relevant tables.  */
537
538
static void
539
pe_ILF_make_a_symbol (pe_ILF_vars *  vars,
540
          const char *   prefix,
541
          const char *   symbol_name,
542
          asection_ptr   section,
543
          flagword       extra_flags)
544
3.73k
{
545
3.73k
  coff_symbol_type *sym;
546
3.73k
  combined_entry_type *ent;
547
3.73k
  SYMENT *esym;
548
3.73k
  unsigned short sclass;
549
550
3.73k
  if (extra_flags & BSF_LOCAL)
551
2.06k
    sclass = C_STAT;
552
1.67k
  else
553
1.67k
    sclass = C_EXT;
554
555
#ifdef THUMBPEMAGIC
556
648
  if (vars->magic == THUMBPEMAGIC)
557
278
    {
558
278
      if (extra_flags & BSF_FUNCTION)
559
22
  sclass = C_THUMBEXTFUNC;
560
256
      else if (extra_flags & BSF_LOCAL)
561
154
  sclass = C_THUMBSTAT;
562
102
      else
563
102
  sclass = C_THUMBEXT;
564
278
    }
565
#endif
566
567
3.73k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
568
569
3.73k
  sym = vars->sym_ptr;
570
3.73k
  ent = vars->native_ptr;
571
3.73k
  esym = vars->esym_ptr;
572
573
  /* Copy the symbol's name into the string table.  */
574
3.73k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
575
576
3.73k
  if (section == NULL)
577
617
    section = bfd_und_section_ptr;
578
579
  /* Initialise the external symbol.  */
580
3.73k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
581
3.73k
      esym->e.e.e_offset);
582
3.73k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
583
3.73k
  esym->e_sclass[0] = sclass;
584
585
  /* The following initialisations are unnecessary - the memory is
586
     zero initialised.  They are just kept here as reminders.  */
587
588
  /* Initialise the internal symbol structure.  */
589
3.73k
  ent->u.syment.n_sclass    = sclass;
590
3.73k
  ent->u.syment.n_scnum     = section->target_index;
591
3.73k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
592
3.73k
  ent->is_sym = true;
593
594
3.73k
  sym->symbol.the_bfd = vars->abfd;
595
3.73k
  sym->symbol.name    = vars->string_ptr;
596
3.73k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
597
3.73k
  sym->symbol.section = section;
598
3.73k
  sym->native       = ent;
599
600
3.73k
  *vars->table_ptr = vars->sym_index;
601
3.73k
  *vars->sym_ptr_ptr = sym;
602
603
  /* Adjust pointers for the next symbol.  */
604
3.73k
  vars->sym_index ++;
605
3.73k
  vars->sym_ptr ++;
606
3.73k
  vars->sym_ptr_ptr ++;
607
3.73k
  vars->table_ptr ++;
608
3.73k
  vars->native_ptr ++;
609
3.73k
  vars->esym_ptr ++;
610
3.73k
  vars->string_ptr += len + 1;
611
612
3.73k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
613
3.73k
}
pei-i386.c:pe_ILF_make_a_symbol
Line
Count
Source
544
557
{
545
557
  coff_symbol_type *sym;
546
557
  combined_entry_type *ent;
547
557
  SYMENT *esym;
548
557
  unsigned short sclass;
549
550
557
  if (extra_flags & BSF_LOCAL)
551
312
    sclass = C_STAT;
552
245
  else
553
245
    sclass = C_EXT;
554
555
#ifdef THUMBPEMAGIC
556
  if (vars->magic == THUMBPEMAGIC)
557
    {
558
      if (extra_flags & BSF_FUNCTION)
559
  sclass = C_THUMBEXTFUNC;
560
      else if (extra_flags & BSF_LOCAL)
561
  sclass = C_THUMBSTAT;
562
      else
563
  sclass = C_THUMBEXT;
564
    }
565
#endif
566
567
557
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
568
569
557
  sym = vars->sym_ptr;
570
557
  ent = vars->native_ptr;
571
557
  esym = vars->esym_ptr;
572
573
  /* Copy the symbol's name into the string table.  */
574
557
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
575
576
557
  if (section == NULL)
577
92
    section = bfd_und_section_ptr;
578
579
  /* Initialise the external symbol.  */
580
557
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
581
557
      esym->e.e.e_offset);
582
557
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
583
557
  esym->e_sclass[0] = sclass;
584
585
  /* The following initialisations are unnecessary - the memory is
586
     zero initialised.  They are just kept here as reminders.  */
587
588
  /* Initialise the internal symbol structure.  */
589
557
  ent->u.syment.n_sclass    = sclass;
590
557
  ent->u.syment.n_scnum     = section->target_index;
591
557
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
592
557
  ent->is_sym = true;
593
594
557
  sym->symbol.the_bfd = vars->abfd;
595
557
  sym->symbol.name    = vars->string_ptr;
596
557
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
597
557
  sym->symbol.section = section;
598
557
  sym->native       = ent;
599
600
557
  *vars->table_ptr = vars->sym_index;
601
557
  *vars->sym_ptr_ptr = sym;
602
603
  /* Adjust pointers for the next symbol.  */
604
557
  vars->sym_index ++;
605
557
  vars->sym_ptr ++;
606
557
  vars->sym_ptr_ptr ++;
607
557
  vars->table_ptr ++;
608
557
  vars->native_ptr ++;
609
557
  vars->esym_ptr ++;
610
557
  vars->string_ptr += len + 1;
611
612
557
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
613
557
}
pei-x86_64.c:pe_ILF_make_a_symbol
Line
Count
Source
544
505
{
545
505
  coff_symbol_type *sym;
546
505
  combined_entry_type *ent;
547
505
  SYMENT *esym;
548
505
  unsigned short sclass;
549
550
505
  if (extra_flags & BSF_LOCAL)
551
277
    sclass = C_STAT;
552
228
  else
553
228
    sclass = C_EXT;
554
555
#ifdef THUMBPEMAGIC
556
  if (vars->magic == THUMBPEMAGIC)
557
    {
558
      if (extra_flags & BSF_FUNCTION)
559
  sclass = C_THUMBEXTFUNC;
560
      else if (extra_flags & BSF_LOCAL)
561
  sclass = C_THUMBSTAT;
562
      else
563
  sclass = C_THUMBEXT;
564
    }
565
#endif
566
567
505
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
568
569
505
  sym = vars->sym_ptr;
570
505
  ent = vars->native_ptr;
571
505
  esym = vars->esym_ptr;
572
573
  /* Copy the symbol's name into the string table.  */
574
505
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
575
576
505
  if (section == NULL)
577
82
    section = bfd_und_section_ptr;
578
579
  /* Initialise the external symbol.  */
580
505
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
581
505
      esym->e.e.e_offset);
582
505
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
583
505
  esym->e_sclass[0] = sclass;
584
585
  /* The following initialisations are unnecessary - the memory is
586
     zero initialised.  They are just kept here as reminders.  */
587
588
  /* Initialise the internal symbol structure.  */
589
505
  ent->u.syment.n_sclass    = sclass;
590
505
  ent->u.syment.n_scnum     = section->target_index;
591
505
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
592
505
  ent->is_sym = true;
593
594
505
  sym->symbol.the_bfd = vars->abfd;
595
505
  sym->symbol.name    = vars->string_ptr;
596
505
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
597
505
  sym->symbol.section = section;
598
505
  sym->native       = ent;
599
600
505
  *vars->table_ptr = vars->sym_index;
601
505
  *vars->sym_ptr_ptr = sym;
602
603
  /* Adjust pointers for the next symbol.  */
604
505
  vars->sym_index ++;
605
505
  vars->sym_ptr ++;
606
505
  vars->sym_ptr_ptr ++;
607
505
  vars->table_ptr ++;
608
505
  vars->native_ptr ++;
609
505
  vars->esym_ptr ++;
610
505
  vars->string_ptr += len + 1;
611
612
505
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
613
505
}
pei-aarch64.c:pe_ILF_make_a_symbol
Line
Count
Source
544
550
{
545
550
  coff_symbol_type *sym;
546
550
  combined_entry_type *ent;
547
550
  SYMENT *esym;
548
550
  unsigned short sclass;
549
550
550
  if (extra_flags & BSF_LOCAL)
551
305
    sclass = C_STAT;
552
245
  else
553
245
    sclass = C_EXT;
554
555
#ifdef THUMBPEMAGIC
556
  if (vars->magic == THUMBPEMAGIC)
557
    {
558
      if (extra_flags & BSF_FUNCTION)
559
  sclass = C_THUMBEXTFUNC;
560
      else if (extra_flags & BSF_LOCAL)
561
  sclass = C_THUMBSTAT;
562
      else
563
  sclass = C_THUMBEXT;
564
    }
565
#endif
566
567
550
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
568
569
550
  sym = vars->sym_ptr;
570
550
  ent = vars->native_ptr;
571
550
  esym = vars->esym_ptr;
572
573
  /* Copy the symbol's name into the string table.  */
574
550
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
575
576
550
  if (section == NULL)
577
89
    section = bfd_und_section_ptr;
578
579
  /* Initialise the external symbol.  */
580
550
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
581
550
      esym->e.e.e_offset);
582
550
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
583
550
  esym->e_sclass[0] = sclass;
584
585
  /* The following initialisations are unnecessary - the memory is
586
     zero initialised.  They are just kept here as reminders.  */
587
588
  /* Initialise the internal symbol structure.  */
589
550
  ent->u.syment.n_sclass    = sclass;
590
550
  ent->u.syment.n_scnum     = section->target_index;
591
550
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
592
550
  ent->is_sym = true;
593
594
550
  sym->symbol.the_bfd = vars->abfd;
595
550
  sym->symbol.name    = vars->string_ptr;
596
550
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
597
550
  sym->symbol.section = section;
598
550
  sym->native       = ent;
599
600
550
  *vars->table_ptr = vars->sym_index;
601
550
  *vars->sym_ptr_ptr = sym;
602
603
  /* Adjust pointers for the next symbol.  */
604
550
  vars->sym_index ++;
605
550
  vars->sym_ptr ++;
606
550
  vars->sym_ptr_ptr ++;
607
550
  vars->table_ptr ++;
608
550
  vars->native_ptr ++;
609
550
  vars->esym_ptr ++;
610
550
  vars->string_ptr += len + 1;
611
612
550
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
613
550
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_symbol
pei-loongarch64.c:pe_ILF_make_a_symbol
Line
Count
Source
544
469
{
545
469
  coff_symbol_type *sym;
546
469
  combined_entry_type *ent;
547
469
  SYMENT *esym;
548
469
  unsigned short sclass;
549
550
469
  if (extra_flags & BSF_LOCAL)
551
260
    sclass = C_STAT;
552
209
  else
553
209
    sclass = C_EXT;
554
555
#ifdef THUMBPEMAGIC
556
  if (vars->magic == THUMBPEMAGIC)
557
    {
558
      if (extra_flags & BSF_FUNCTION)
559
  sclass = C_THUMBEXTFUNC;
560
      else if (extra_flags & BSF_LOCAL)
561
  sclass = C_THUMBSTAT;
562
      else
563
  sclass = C_THUMBEXT;
564
    }
565
#endif
566
567
469
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
568
569
469
  sym = vars->sym_ptr;
570
469
  ent = vars->native_ptr;
571
469
  esym = vars->esym_ptr;
572
573
  /* Copy the symbol's name into the string table.  */
574
469
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
575
576
469
  if (section == NULL)
577
78
    section = bfd_und_section_ptr;
578
579
  /* Initialise the external symbol.  */
580
469
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
581
469
      esym->e.e.e_offset);
582
469
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
583
469
  esym->e_sclass[0] = sclass;
584
585
  /* The following initialisations are unnecessary - the memory is
586
     zero initialised.  They are just kept here as reminders.  */
587
588
  /* Initialise the internal symbol structure.  */
589
469
  ent->u.syment.n_sclass    = sclass;
590
469
  ent->u.syment.n_scnum     = section->target_index;
591
469
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
592
469
  ent->is_sym = true;
593
594
469
  sym->symbol.the_bfd = vars->abfd;
595
469
  sym->symbol.name    = vars->string_ptr;
596
469
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
597
469
  sym->symbol.section = section;
598
469
  sym->native       = ent;
599
600
469
  *vars->table_ptr = vars->sym_index;
601
469
  *vars->sym_ptr_ptr = sym;
602
603
  /* Adjust pointers for the next symbol.  */
604
469
  vars->sym_index ++;
605
469
  vars->sym_ptr ++;
606
469
  vars->sym_ptr_ptr ++;
607
469
  vars->table_ptr ++;
608
469
  vars->native_ptr ++;
609
469
  vars->esym_ptr ++;
610
469
  vars->string_ptr += len + 1;
611
612
469
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
613
469
}
pei-riscv64.c:pe_ILF_make_a_symbol
Line
Count
Source
544
509
{
545
509
  coff_symbol_type *sym;
546
509
  combined_entry_type *ent;
547
509
  SYMENT *esym;
548
509
  unsigned short sclass;
549
550
509
  if (extra_flags & BSF_LOCAL)
551
274
    sclass = C_STAT;
552
235
  else
553
235
    sclass = C_EXT;
554
555
#ifdef THUMBPEMAGIC
556
  if (vars->magic == THUMBPEMAGIC)
557
    {
558
      if (extra_flags & BSF_FUNCTION)
559
  sclass = C_THUMBEXTFUNC;
560
      else if (extra_flags & BSF_LOCAL)
561
  sclass = C_THUMBSTAT;
562
      else
563
  sclass = C_THUMBEXT;
564
    }
565
#endif
566
567
509
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
568
569
509
  sym = vars->sym_ptr;
570
509
  ent = vars->native_ptr;
571
509
  esym = vars->esym_ptr;
572
573
  /* Copy the symbol's name into the string table.  */
574
509
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
575
576
509
  if (section == NULL)
577
85
    section = bfd_und_section_ptr;
578
579
  /* Initialise the external symbol.  */
580
509
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
581
509
      esym->e.e.e_offset);
582
509
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
583
509
  esym->e_sclass[0] = sclass;
584
585
  /* The following initialisations are unnecessary - the memory is
586
     zero initialised.  They are just kept here as reminders.  */
587
588
  /* Initialise the internal symbol structure.  */
589
509
  ent->u.syment.n_sclass    = sclass;
590
509
  ent->u.syment.n_scnum     = section->target_index;
591
509
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
592
509
  ent->is_sym = true;
593
594
509
  sym->symbol.the_bfd = vars->abfd;
595
509
  sym->symbol.name    = vars->string_ptr;
596
509
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
597
509
  sym->symbol.section = section;
598
509
  sym->native       = ent;
599
600
509
  *vars->table_ptr = vars->sym_index;
601
509
  *vars->sym_ptr_ptr = sym;
602
603
  /* Adjust pointers for the next symbol.  */
604
509
  vars->sym_index ++;
605
509
  vars->sym_ptr ++;
606
509
  vars->sym_ptr_ptr ++;
607
509
  vars->table_ptr ++;
608
509
  vars->native_ptr ++;
609
509
  vars->esym_ptr ++;
610
509
  vars->string_ptr += len + 1;
611
612
509
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
613
509
}
pei-arm-wince.c:pe_ILF_make_a_symbol
Line
Count
Source
544
318
{
545
318
  coff_symbol_type *sym;
546
318
  combined_entry_type *ent;
547
318
  SYMENT *esym;
548
318
  unsigned short sclass;
549
550
318
  if (extra_flags & BSF_LOCAL)
551
179
    sclass = C_STAT;
552
139
  else
553
139
    sclass = C_EXT;
554
555
318
#ifdef THUMBPEMAGIC
556
318
  if (vars->magic == THUMBPEMAGIC)
557
139
    {
558
139
      if (extra_flags & BSF_FUNCTION)
559
11
  sclass = C_THUMBEXTFUNC;
560
128
      else if (extra_flags & BSF_LOCAL)
561
77
  sclass = C_THUMBSTAT;
562
51
      else
563
51
  sclass = C_THUMBEXT;
564
139
    }
565
318
#endif
566
567
318
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
568
569
318
  sym = vars->sym_ptr;
570
318
  ent = vars->native_ptr;
571
318
  esym = vars->esym_ptr;
572
573
  /* Copy the symbol's name into the string table.  */
574
318
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
575
576
318
  if (section == NULL)
577
52
    section = bfd_und_section_ptr;
578
579
  /* Initialise the external symbol.  */
580
318
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
581
318
      esym->e.e.e_offset);
582
318
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
583
318
  esym->e_sclass[0] = sclass;
584
585
  /* The following initialisations are unnecessary - the memory is
586
     zero initialised.  They are just kept here as reminders.  */
587
588
  /* Initialise the internal symbol structure.  */
589
318
  ent->u.syment.n_sclass    = sclass;
590
318
  ent->u.syment.n_scnum     = section->target_index;
591
318
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
592
318
  ent->is_sym = true;
593
594
318
  sym->symbol.the_bfd = vars->abfd;
595
318
  sym->symbol.name    = vars->string_ptr;
596
318
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
597
318
  sym->symbol.section = section;
598
318
  sym->native       = ent;
599
600
318
  *vars->table_ptr = vars->sym_index;
601
318
  *vars->sym_ptr_ptr = sym;
602
603
  /* Adjust pointers for the next symbol.  */
604
318
  vars->sym_index ++;
605
318
  vars->sym_ptr ++;
606
318
  vars->sym_ptr_ptr ++;
607
318
  vars->table_ptr ++;
608
318
  vars->native_ptr ++;
609
318
  vars->esym_ptr ++;
610
318
  vars->string_ptr += len + 1;
611
612
318
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
613
318
}
pei-arm.c:pe_ILF_make_a_symbol
Line
Count
Source
544
330
{
545
330
  coff_symbol_type *sym;
546
330
  combined_entry_type *ent;
547
330
  SYMENT *esym;
548
330
  unsigned short sclass;
549
550
330
  if (extra_flags & BSF_LOCAL)
551
185
    sclass = C_STAT;
552
145
  else
553
145
    sclass = C_EXT;
554
555
330
#ifdef THUMBPEMAGIC
556
330
  if (vars->magic == THUMBPEMAGIC)
557
139
    {
558
139
      if (extra_flags & BSF_FUNCTION)
559
11
  sclass = C_THUMBEXTFUNC;
560
128
      else if (extra_flags & BSF_LOCAL)
561
77
  sclass = C_THUMBSTAT;
562
51
      else
563
51
  sclass = C_THUMBEXT;
564
139
    }
565
330
#endif
566
567
330
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
568
569
330
  sym = vars->sym_ptr;
570
330
  ent = vars->native_ptr;
571
330
  esym = vars->esym_ptr;
572
573
  /* Copy the symbol's name into the string table.  */
574
330
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
575
576
330
  if (section == NULL)
577
54
    section = bfd_und_section_ptr;
578
579
  /* Initialise the external symbol.  */
580
330
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
581
330
      esym->e.e.e_offset);
582
330
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
583
330
  esym->e_sclass[0] = sclass;
584
585
  /* The following initialisations are unnecessary - the memory is
586
     zero initialised.  They are just kept here as reminders.  */
587
588
  /* Initialise the internal symbol structure.  */
589
330
  ent->u.syment.n_sclass    = sclass;
590
330
  ent->u.syment.n_scnum     = section->target_index;
591
330
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
592
330
  ent->is_sym = true;
593
594
330
  sym->symbol.the_bfd = vars->abfd;
595
330
  sym->symbol.name    = vars->string_ptr;
596
330
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
597
330
  sym->symbol.section = section;
598
330
  sym->native       = ent;
599
600
330
  *vars->table_ptr = vars->sym_index;
601
330
  *vars->sym_ptr_ptr = sym;
602
603
  /* Adjust pointers for the next symbol.  */
604
330
  vars->sym_index ++;
605
330
  vars->sym_ptr ++;
606
330
  vars->sym_ptr_ptr ++;
607
330
  vars->table_ptr ++;
608
330
  vars->native_ptr ++;
609
330
  vars->esym_ptr ++;
610
330
  vars->string_ptr += len + 1;
611
612
330
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
613
330
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_symbol
pei-sh.c:pe_ILF_make_a_symbol
Line
Count
Source
544
498
{
545
498
  coff_symbol_type *sym;
546
498
  combined_entry_type *ent;
547
498
  SYMENT *esym;
548
498
  unsigned short sclass;
549
550
498
  if (extra_flags & BSF_LOCAL)
551
271
    sclass = C_STAT;
552
227
  else
553
227
    sclass = C_EXT;
554
555
#ifdef THUMBPEMAGIC
556
  if (vars->magic == THUMBPEMAGIC)
557
    {
558
      if (extra_flags & BSF_FUNCTION)
559
  sclass = C_THUMBEXTFUNC;
560
      else if (extra_flags & BSF_LOCAL)
561
  sclass = C_THUMBSTAT;
562
      else
563
  sclass = C_THUMBEXT;
564
    }
565
#endif
566
567
498
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
568
569
498
  sym = vars->sym_ptr;
570
498
  ent = vars->native_ptr;
571
498
  esym = vars->esym_ptr;
572
573
  /* Copy the symbol's name into the string table.  */
574
498
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
575
576
498
  if (section == NULL)
577
85
    section = bfd_und_section_ptr;
578
579
  /* Initialise the external symbol.  */
580
498
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
581
498
      esym->e.e.e_offset);
582
498
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
583
498
  esym->e_sclass[0] = sclass;
584
585
  /* The following initialisations are unnecessary - the memory is
586
     zero initialised.  They are just kept here as reminders.  */
587
588
  /* Initialise the internal symbol structure.  */
589
498
  ent->u.syment.n_sclass    = sclass;
590
498
  ent->u.syment.n_scnum     = section->target_index;
591
498
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
592
498
  ent->is_sym = true;
593
594
498
  sym->symbol.the_bfd = vars->abfd;
595
498
  sym->symbol.name    = vars->string_ptr;
596
498
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
597
498
  sym->symbol.section = section;
598
498
  sym->native       = ent;
599
600
498
  *vars->table_ptr = vars->sym_index;
601
498
  *vars->sym_ptr_ptr = sym;
602
603
  /* Adjust pointers for the next symbol.  */
604
498
  vars->sym_index ++;
605
498
  vars->sym_ptr ++;
606
498
  vars->sym_ptr_ptr ++;
607
498
  vars->table_ptr ++;
608
498
  vars->native_ptr ++;
609
498
  vars->esym_ptr ++;
610
498
  vars->string_ptr += len + 1;
611
612
498
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
613
498
}
614
615
/* Create a section.  */
616
617
static asection_ptr
618
pe_ILF_make_a_section (pe_ILF_vars * vars,
619
           const char *  name,
620
           unsigned int  size,
621
           flagword      extra_flags)
622
2.06k
{
623
2.06k
  asection_ptr sec;
624
2.06k
  flagword     flags;
625
2.06k
  intptr_t alignment;
626
627
2.06k
  sec = bfd_make_section_old_way (vars->abfd, name);
628
2.06k
  if (sec == NULL)
629
0
    return NULL;
630
631
2.06k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
632
633
2.06k
  bfd_set_section_flags (sec, flags | extra_flags);
634
635
2.06k
  bfd_set_section_alignment (sec, 2);
636
637
  /* Check that we will not run out of space.  */
638
2.06k
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
639
640
  /* Set the section size and contents.  The actual
641
     contents are filled in by our parent.  */
642
2.06k
  bfd_set_section_size (sec, (bfd_size_type) size);
643
2.06k
  sec->contents = vars->data;
644
2.06k
  sec->target_index = vars->sec_index ++;
645
646
  /* Advance data pointer in the vars structure.  */
647
2.06k
  vars->data += size;
648
649
  /* Skip the padding byte if it was not needed.
650
     The logic here is that if the string length is odd,
651
     then the entire string length, including the null byte,
652
     is even and so the extra, padding byte, is not needed.  */
653
2.06k
  if (size & 1)
654
232
    vars->data --;
655
656
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
657
     preserve host alignment requirements.  The BFD_ASSERTs in this
658
     functions will warn us if we run out of room, but we should
659
     already have enough padding built in to ILF_DATA_SIZE.  */
660
2.06k
#if GCC_VERSION >= 3000
661
2.06k
  alignment = __alignof__ (struct coff_section_tdata);
662
#else
663
  alignment = 8;
664
#endif
665
2.06k
  vars->data
666
2.06k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
667
668
  /* Create a coff_section_tdata structure for our use.  */
669
2.06k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
670
2.06k
  vars->data += sizeof (struct coff_section_tdata);
671
672
2.06k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
673
674
  /* Create a symbol to refer to this section.  */
675
2.06k
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
676
677
  /* Cache the index to the symbol in the coff_section_data structure.  */
678
2.06k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
679
680
2.06k
  return sec;
681
2.06k
}
pei-i386.c:pe_ILF_make_a_section
Line
Count
Source
622
312
{
623
312
  asection_ptr sec;
624
312
  flagword     flags;
625
312
  intptr_t alignment;
626
627
312
  sec = bfd_make_section_old_way (vars->abfd, name);
628
312
  if (sec == NULL)
629
0
    return NULL;
630
631
312
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
632
633
312
  bfd_set_section_flags (sec, flags | extra_flags);
634
635
312
  bfd_set_section_alignment (sec, 2);
636
637
  /* Check that we will not run out of space.  */
638
312
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
639
640
  /* Set the section size and contents.  The actual
641
     contents are filled in by our parent.  */
642
312
  bfd_set_section_size (sec, (bfd_size_type) size);
643
312
  sec->contents = vars->data;
644
312
  sec->target_index = vars->sec_index ++;
645
646
  /* Advance data pointer in the vars structure.  */
647
312
  vars->data += size;
648
649
  /* Skip the padding byte if it was not needed.
650
     The logic here is that if the string length is odd,
651
     then the entire string length, including the null byte,
652
     is even and so the extra, padding byte, is not needed.  */
653
312
  if (size & 1)
654
29
    vars->data --;
655
656
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
657
     preserve host alignment requirements.  The BFD_ASSERTs in this
658
     functions will warn us if we run out of room, but we should
659
     already have enough padding built in to ILF_DATA_SIZE.  */
660
312
#if GCC_VERSION >= 3000
661
312
  alignment = __alignof__ (struct coff_section_tdata);
662
#else
663
  alignment = 8;
664
#endif
665
312
  vars->data
666
312
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
667
668
  /* Create a coff_section_tdata structure for our use.  */
669
312
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
670
312
  vars->data += sizeof (struct coff_section_tdata);
671
672
312
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
673
674
  /* Create a symbol to refer to this section.  */
675
312
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
676
677
  /* Cache the index to the symbol in the coff_section_data structure.  */
678
312
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
679
680
312
  return sec;
681
312
}
pei-x86_64.c:pe_ILF_make_a_section
Line
Count
Source
622
277
{
623
277
  asection_ptr sec;
624
277
  flagword     flags;
625
277
  intptr_t alignment;
626
627
277
  sec = bfd_make_section_old_way (vars->abfd, name);
628
277
  if (sec == NULL)
629
0
    return NULL;
630
631
277
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
632
633
277
  bfd_set_section_flags (sec, flags | extra_flags);
634
635
277
  bfd_set_section_alignment (sec, 2);
636
637
  /* Check that we will not run out of space.  */
638
277
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
639
640
  /* Set the section size and contents.  The actual
641
     contents are filled in by our parent.  */
642
277
  bfd_set_section_size (sec, (bfd_size_type) size);
643
277
  sec->contents = vars->data;
644
277
  sec->target_index = vars->sec_index ++;
645
646
  /* Advance data pointer in the vars structure.  */
647
277
  vars->data += size;
648
649
  /* Skip the padding byte if it was not needed.
650
     The logic here is that if the string length is odd,
651
     then the entire string length, including the null byte,
652
     is even and so the extra, padding byte, is not needed.  */
653
277
  if (size & 1)
654
28
    vars->data --;
655
656
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
657
     preserve host alignment requirements.  The BFD_ASSERTs in this
658
     functions will warn us if we run out of room, but we should
659
     already have enough padding built in to ILF_DATA_SIZE.  */
660
277
#if GCC_VERSION >= 3000
661
277
  alignment = __alignof__ (struct coff_section_tdata);
662
#else
663
  alignment = 8;
664
#endif
665
277
  vars->data
666
277
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
667
668
  /* Create a coff_section_tdata structure for our use.  */
669
277
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
670
277
  vars->data += sizeof (struct coff_section_tdata);
671
672
277
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
673
674
  /* Create a symbol to refer to this section.  */
675
277
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
676
677
  /* Cache the index to the symbol in the coff_section_data structure.  */
678
277
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
679
680
277
  return sec;
681
277
}
pei-aarch64.c:pe_ILF_make_a_section
Line
Count
Source
622
305
{
623
305
  asection_ptr sec;
624
305
  flagword     flags;
625
305
  intptr_t alignment;
626
627
305
  sec = bfd_make_section_old_way (vars->abfd, name);
628
305
  if (sec == NULL)
629
0
    return NULL;
630
631
305
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
632
633
305
  bfd_set_section_flags (sec, flags | extra_flags);
634
635
305
  bfd_set_section_alignment (sec, 2);
636
637
  /* Check that we will not run out of space.  */
638
305
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
639
640
  /* Set the section size and contents.  The actual
641
     contents are filled in by our parent.  */
642
305
  bfd_set_section_size (sec, (bfd_size_type) size);
643
305
  sec->contents = vars->data;
644
305
  sec->target_index = vars->sec_index ++;
645
646
  /* Advance data pointer in the vars structure.  */
647
305
  vars->data += size;
648
649
  /* Skip the padding byte if it was not needed.
650
     The logic here is that if the string length is odd,
651
     then the entire string length, including the null byte,
652
     is even and so the extra, padding byte, is not needed.  */
653
305
  if (size & 1)
654
39
    vars->data --;
655
656
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
657
     preserve host alignment requirements.  The BFD_ASSERTs in this
658
     functions will warn us if we run out of room, but we should
659
     already have enough padding built in to ILF_DATA_SIZE.  */
660
305
#if GCC_VERSION >= 3000
661
305
  alignment = __alignof__ (struct coff_section_tdata);
662
#else
663
  alignment = 8;
664
#endif
665
305
  vars->data
666
305
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
667
668
  /* Create a coff_section_tdata structure for our use.  */
669
305
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
670
305
  vars->data += sizeof (struct coff_section_tdata);
671
672
305
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
673
674
  /* Create a symbol to refer to this section.  */
675
305
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
676
677
  /* Cache the index to the symbol in the coff_section_data structure.  */
678
305
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
679
680
305
  return sec;
681
305
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_section
pei-loongarch64.c:pe_ILF_make_a_section
Line
Count
Source
622
260
{
623
260
  asection_ptr sec;
624
260
  flagword     flags;
625
260
  intptr_t alignment;
626
627
260
  sec = bfd_make_section_old_way (vars->abfd, name);
628
260
  if (sec == NULL)
629
0
    return NULL;
630
631
260
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
632
633
260
  bfd_set_section_flags (sec, flags | extra_flags);
634
635
260
  bfd_set_section_alignment (sec, 2);
636
637
  /* Check that we will not run out of space.  */
638
260
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
639
640
  /* Set the section size and contents.  The actual
641
     contents are filled in by our parent.  */
642
260
  bfd_set_section_size (sec, (bfd_size_type) size);
643
260
  sec->contents = vars->data;
644
260
  sec->target_index = vars->sec_index ++;
645
646
  /* Advance data pointer in the vars structure.  */
647
260
  vars->data += size;
648
649
  /* Skip the padding byte if it was not needed.
650
     The logic here is that if the string length is odd,
651
     then the entire string length, including the null byte,
652
     is even and so the extra, padding byte, is not needed.  */
653
260
  if (size & 1)
654
35
    vars->data --;
655
656
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
657
     preserve host alignment requirements.  The BFD_ASSERTs in this
658
     functions will warn us if we run out of room, but we should
659
     already have enough padding built in to ILF_DATA_SIZE.  */
660
260
#if GCC_VERSION >= 3000
661
260
  alignment = __alignof__ (struct coff_section_tdata);
662
#else
663
  alignment = 8;
664
#endif
665
260
  vars->data
666
260
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
667
668
  /* Create a coff_section_tdata structure for our use.  */
669
260
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
670
260
  vars->data += sizeof (struct coff_section_tdata);
671
672
260
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
673
674
  /* Create a symbol to refer to this section.  */
675
260
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
676
677
  /* Cache the index to the symbol in the coff_section_data structure.  */
678
260
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
679
680
260
  return sec;
681
260
}
pei-riscv64.c:pe_ILF_make_a_section
Line
Count
Source
622
274
{
623
274
  asection_ptr sec;
624
274
  flagword     flags;
625
274
  intptr_t alignment;
626
627
274
  sec = bfd_make_section_old_way (vars->abfd, name);
628
274
  if (sec == NULL)
629
0
    return NULL;
630
631
274
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
632
633
274
  bfd_set_section_flags (sec, flags | extra_flags);
634
635
274
  bfd_set_section_alignment (sec, 2);
636
637
  /* Check that we will not run out of space.  */
638
274
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
639
640
  /* Set the section size and contents.  The actual
641
     contents are filled in by our parent.  */
642
274
  bfd_set_section_size (sec, (bfd_size_type) size);
643
274
  sec->contents = vars->data;
644
274
  sec->target_index = vars->sec_index ++;
645
646
  /* Advance data pointer in the vars structure.  */
647
274
  vars->data += size;
648
649
  /* Skip the padding byte if it was not needed.
650
     The logic here is that if the string length is odd,
651
     then the entire string length, including the null byte,
652
     is even and so the extra, padding byte, is not needed.  */
653
274
  if (size & 1)
654
36
    vars->data --;
655
656
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
657
     preserve host alignment requirements.  The BFD_ASSERTs in this
658
     functions will warn us if we run out of room, but we should
659
     already have enough padding built in to ILF_DATA_SIZE.  */
660
274
#if GCC_VERSION >= 3000
661
274
  alignment = __alignof__ (struct coff_section_tdata);
662
#else
663
  alignment = 8;
664
#endif
665
274
  vars->data
666
274
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
667
668
  /* Create a coff_section_tdata structure for our use.  */
669
274
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
670
274
  vars->data += sizeof (struct coff_section_tdata);
671
672
274
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
673
674
  /* Create a symbol to refer to this section.  */
675
274
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
676
677
  /* Cache the index to the symbol in the coff_section_data structure.  */
678
274
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
679
680
274
  return sec;
681
274
}
pei-arm-wince.c:pe_ILF_make_a_section
Line
Count
Source
622
179
{
623
179
  asection_ptr sec;
624
179
  flagword     flags;
625
179
  intptr_t alignment;
626
627
179
  sec = bfd_make_section_old_way (vars->abfd, name);
628
179
  if (sec == NULL)
629
0
    return NULL;
630
631
179
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
632
633
179
  bfd_set_section_flags (sec, flags | extra_flags);
634
635
179
  bfd_set_section_alignment (sec, 2);
636
637
  /* Check that we will not run out of space.  */
638
179
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
639
640
  /* Set the section size and contents.  The actual
641
     contents are filled in by our parent.  */
642
179
  bfd_set_section_size (sec, (bfd_size_type) size);
643
179
  sec->contents = vars->data;
644
179
  sec->target_index = vars->sec_index ++;
645
646
  /* Advance data pointer in the vars structure.  */
647
179
  vars->data += size;
648
649
  /* Skip the padding byte if it was not needed.
650
     The logic here is that if the string length is odd,
651
     then the entire string length, including the null byte,
652
     is even and so the extra, padding byte, is not needed.  */
653
179
  if (size & 1)
654
19
    vars->data --;
655
656
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
657
     preserve host alignment requirements.  The BFD_ASSERTs in this
658
     functions will warn us if we run out of room, but we should
659
     already have enough padding built in to ILF_DATA_SIZE.  */
660
179
#if GCC_VERSION >= 3000
661
179
  alignment = __alignof__ (struct coff_section_tdata);
662
#else
663
  alignment = 8;
664
#endif
665
179
  vars->data
666
179
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
667
668
  /* Create a coff_section_tdata structure for our use.  */
669
179
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
670
179
  vars->data += sizeof (struct coff_section_tdata);
671
672
179
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
673
674
  /* Create a symbol to refer to this section.  */
675
179
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
676
677
  /* Cache the index to the symbol in the coff_section_data structure.  */
678
179
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
679
680
179
  return sec;
681
179
}
pei-arm.c:pe_ILF_make_a_section
Line
Count
Source
622
185
{
623
185
  asection_ptr sec;
624
185
  flagword     flags;
625
185
  intptr_t alignment;
626
627
185
  sec = bfd_make_section_old_way (vars->abfd, name);
628
185
  if (sec == NULL)
629
0
    return NULL;
630
631
185
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
632
633
185
  bfd_set_section_flags (sec, flags | extra_flags);
634
635
185
  bfd_set_section_alignment (sec, 2);
636
637
  /* Check that we will not run out of space.  */
638
185
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
639
640
  /* Set the section size and contents.  The actual
641
     contents are filled in by our parent.  */
642
185
  bfd_set_section_size (sec, (bfd_size_type) size);
643
185
  sec->contents = vars->data;
644
185
  sec->target_index = vars->sec_index ++;
645
646
  /* Advance data pointer in the vars structure.  */
647
185
  vars->data += size;
648
649
  /* Skip the padding byte if it was not needed.
650
     The logic here is that if the string length is odd,
651
     then the entire string length, including the null byte,
652
     is even and so the extra, padding byte, is not needed.  */
653
185
  if (size & 1)
654
19
    vars->data --;
655
656
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
657
     preserve host alignment requirements.  The BFD_ASSERTs in this
658
     functions will warn us if we run out of room, but we should
659
     already have enough padding built in to ILF_DATA_SIZE.  */
660
185
#if GCC_VERSION >= 3000
661
185
  alignment = __alignof__ (struct coff_section_tdata);
662
#else
663
  alignment = 8;
664
#endif
665
185
  vars->data
666
185
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
667
668
  /* Create a coff_section_tdata structure for our use.  */
669
185
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
670
185
  vars->data += sizeof (struct coff_section_tdata);
671
672
185
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
673
674
  /* Create a symbol to refer to this section.  */
675
185
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
676
677
  /* Cache the index to the symbol in the coff_section_data structure.  */
678
185
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
679
680
185
  return sec;
681
185
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_section
pei-sh.c:pe_ILF_make_a_section
Line
Count
Source
622
271
{
623
271
  asection_ptr sec;
624
271
  flagword     flags;
625
271
  intptr_t alignment;
626
627
271
  sec = bfd_make_section_old_way (vars->abfd, name);
628
271
  if (sec == NULL)
629
0
    return NULL;
630
631
271
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
632
633
271
  bfd_set_section_flags (sec, flags | extra_flags);
634
635
271
  bfd_set_section_alignment (sec, 2);
636
637
  /* Check that we will not run out of space.  */
638
271
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
639
640
  /* Set the section size and contents.  The actual
641
     contents are filled in by our parent.  */
642
271
  bfd_set_section_size (sec, (bfd_size_type) size);
643
271
  sec->contents = vars->data;
644
271
  sec->target_index = vars->sec_index ++;
645
646
  /* Advance data pointer in the vars structure.  */
647
271
  vars->data += size;
648
649
  /* Skip the padding byte if it was not needed.
650
     The logic here is that if the string length is odd,
651
     then the entire string length, including the null byte,
652
     is even and so the extra, padding byte, is not needed.  */
653
271
  if (size & 1)
654
27
    vars->data --;
655
656
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
657
     preserve host alignment requirements.  The BFD_ASSERTs in this
658
     functions will warn us if we run out of room, but we should
659
     already have enough padding built in to ILF_DATA_SIZE.  */
660
271
#if GCC_VERSION >= 3000
661
271
  alignment = __alignof__ (struct coff_section_tdata);
662
#else
663
  alignment = 8;
664
#endif
665
271
  vars->data
666
271
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
667
668
  /* Create a coff_section_tdata structure for our use.  */
669
271
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
670
271
  vars->data += sizeof (struct coff_section_tdata);
671
672
271
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
673
674
  /* Create a symbol to refer to this section.  */
675
271
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
676
677
  /* Cache the index to the symbol in the coff_section_data structure.  */
678
271
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
679
680
271
  return sec;
681
271
}
682
683
/* This structure contains the code that goes into the .text section
684
   in order to perform a jump into the DLL lookup table.  The entries
685
   in the table are index by the magic number used to represent the
686
   machine type in the PE file.  The contents of the data[] arrays in
687
   these entries are stolen from the jtab[] arrays in ld/pe-dll.c.
688
   The SIZE field says how many bytes in the DATA array are actually
689
   used.  The OFFSET field says where in the data array the address
690
   of the .idata$5 section should be placed.  */
691
1.32k
#define MAX_TEXT_SECTION_SIZE 32
692
693
typedef struct
694
{
695
  unsigned short magic;
696
  unsigned char  data[MAX_TEXT_SECTION_SIZE];
697
  unsigned int   size;
698
  unsigned int   offset;
699
}
700
jump_table;
701
702
static const jump_table jtab[] =
703
{
704
#ifdef I386MAGIC
705
  { I386MAGIC,
706
    { 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, 0x90, 0x90 },
707
    8, 2
708
  },
709
#endif
710
711
#ifdef AMD64MAGIC
712
  { AMD64MAGIC,
713
    { 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, 0x90, 0x90 },
714
    8, 2
715
  },
716
#endif
717
718
#ifdef  MC68MAGIC
719
  { MC68MAGIC,
720
    { /* XXX fill me in */ },
721
    0, 0
722
  },
723
#endif
724
725
#ifdef  MIPS_ARCH_MAGIC_WINCE
726
  { MIPS_ARCH_MAGIC_WINCE,
727
    { 0x00, 0x00, 0x08, 0x3c, 0x00, 0x00, 0x08, 0x8d,
728
      0x08, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00 },
729
    16, 0
730
  },
731
#endif
732
733
#ifdef  SH_ARCH_MAGIC_WINCE
734
  { SH_ARCH_MAGIC_WINCE,
735
    { 0x01, 0xd0, 0x02, 0x60, 0x2b, 0x40,
736
      0x09, 0x00, 0x00, 0x00, 0x00, 0x00 },
737
    12, 8
738
  },
739
#endif
740
741
#ifdef AARCH64MAGIC
742
/* We don't currently support jumping to DLLs, so if
743
   someone does try emit a runtime trap.  Through UDF #0.  */
744
  { AARCH64MAGIC,
745
    { 0x00, 0x00, 0x00, 0x00 },
746
    4, 0
747
  },
748
749
#endif
750
751
#ifdef  ARMPEMAGIC
752
  { ARMPEMAGIC,
753
    { 0x00, 0xc0, 0x9f, 0xe5, 0x00, 0xf0,
754
      0x9c, 0xe5, 0x00, 0x00, 0x00, 0x00},
755
    12, 8
756
  },
757
#endif
758
759
#ifdef  THUMBPEMAGIC
760
  { THUMBPEMAGIC,
761
    { 0x40, 0xb4, 0x02, 0x4e, 0x36, 0x68, 0xb4, 0x46,
762
      0x40, 0xbc, 0x60, 0x47, 0x00, 0x00, 0x00, 0x00 },
763
    16, 12
764
  },
765
#endif
766
767
#ifdef LOONGARCH64MAGIC
768
/* We don't currently support jumping to DLLs, so if
769
   someone does try emit a runtime trap.  Through BREAK 0.  */
770
  { LOONGARCH64MAGIC,
771
    { 0x00, 0x00, 0x2a, 0x00 },
772
    4, 0
773
  },
774
775
#endif
776
777
#ifdef RISCV64MAGIC
778
  /* We don't currently support jumping to DLLs, so if
779
     someone does try emit a runtime trap.  Through EBREAK.  */
780
  { RISCV64MAGIC,
781
    { 0x73, 0x00, 0x10, 0x00 },
782
    4, 0
783
  },
784
785
#endif
786
787
  { 0, { 0 }, 0, 0 }
788
};
789
790
#ifndef NUM_ENTRIES
791
265
#define NUM_ENTRIES(a) (sizeof (a) / sizeof (a)[0])
792
#endif
793
794
/* Build a full BFD from the information supplied in a ILF object.  */
795
796
static bool
797
pe_ILF_build_a_bfd (bfd *     abfd,
798
        unsigned int    magic,
799
        char *      symbol_name,
800
        char *      source_dll,
801
        unsigned int    ordinal,
802
        unsigned int    types,
803
        char *      import_name)
804
829
{
805
829
  bfd_byte *       ptr;
806
829
  pe_ILF_vars      vars;
807
829
  struct internal_filehdr  internal_f;
808
829
  unsigned int       import_type;
809
829
  unsigned int       import_name_type;
810
829
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
811
829
  coff_symbol_type **    imp_sym;
812
829
  unsigned int       imp_index;
813
829
  intptr_t alignment;
814
815
  /* Decode and verify the types field of the ILF structure.  */
816
829
  import_type = types & 0x3;
817
829
  import_name_type = (types & 0x1c) >> 2;
818
819
829
  switch (import_type)
820
829
    {
821
354
    case IMPORT_CODE:
822
566
    case IMPORT_DATA:
823
778
    case IMPORT_CONST:
824
778
      break;
825
826
51
    default:
827
      /* xgettext:c-format */
828
51
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
51
        abfd, import_type);
830
51
      return false;
831
829
    }
832
833
778
  switch (import_name_type)
834
778
    {
835
182
    case IMPORT_ORDINAL:
836
255
    case IMPORT_NAME:
837
395
    case IMPORT_NAME_NOPREFIX:
838
592
    case IMPORT_NAME_UNDECORATE:
839
592
      import_name = symbol_name;
840
592
      break;
841
842
144
    case IMPORT_NAME_EXPORTAS:
843
144
      if (!import_name || !import_name[0])
844
76
  {
845
76
    _bfd_error_handler (_("%pB: missing import name for "
846
76
        "IMPORT_NAME_EXPORTAS for %s"),
847
76
            abfd, symbol_name);
848
76
    return false;
849
76
  }
850
68
      break;
851
852
68
    default:
853
      /* xgettext:c-format */
854
42
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
855
42
        abfd, import_name_type);
856
42
      return false;
857
778
    }
858
859
  /* Initialise local variables.
860
861
     Note these are kept in a structure rather than being
862
     declared as statics since bfd frowns on global variables.
863
864
     We are going to construct the contents of the BFD in memory,
865
     so allocate all the space that we will need right now.  */
866
660
  vars.bim
867
660
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
868
660
  if (vars.bim == NULL)
869
0
    return false;
870
871
660
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
872
660
  vars.bim->buffer = ptr;
873
660
  vars.bim->size   = ILF_DATA_SIZE;
874
660
  if (ptr == NULL)
875
0
    goto error_return;
876
877
  /* Initialise the pointers to regions of the memory and the
878
     other contents of the pe_ILF_vars structure as well.  */
879
660
  vars.sym_cache = (coff_symbol_type *) ptr;
880
660
  vars.sym_ptr   = (coff_symbol_type *) ptr;
881
660
  vars.sym_index = 0;
882
660
  ptr += SIZEOF_ILF_SYMS;
883
884
660
  vars.sym_table = (unsigned int *) ptr;
885
660
  vars.table_ptr = (unsigned int *) ptr;
886
660
  ptr += SIZEOF_ILF_SYM_TABLE;
887
888
660
  vars.native_syms = (combined_entry_type *) ptr;
889
660
  vars.native_ptr  = (combined_entry_type *) ptr;
890
660
  ptr += SIZEOF_ILF_NATIVE_SYMS;
891
892
660
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
893
660
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
894
660
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
895
896
660
  vars.esym_table = (SYMENT *) ptr;
897
660
  vars.esym_ptr   = (SYMENT *) ptr;
898
660
  ptr += SIZEOF_ILF_EXT_SYMS;
899
900
660
  vars.reltab   = (arelent *) ptr;
901
660
  vars.relcount = 0;
902
660
  ptr += SIZEOF_ILF_RELOCS;
903
904
660
  vars.int_reltab  = (struct internal_reloc *) ptr;
905
660
  ptr += SIZEOF_ILF_INT_RELOCS;
906
907
660
  vars.string_table = (char *) ptr;
908
660
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
909
660
  ptr += SIZEOF_ILF_STRINGS;
910
660
  vars.end_string_ptr = (char *) ptr;
911
912
  /* The remaining space in bim->buffer is used
913
     by the pe_ILF_make_a_section() function.  */
914
915
  /* PR 18758: Make sure that the data area is sufficiently aligned for
916
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
917
     the test of GCC_VERSION.  For other compilers we assume 8 byte
918
     alignment.  */
919
660
#if GCC_VERSION >= 3000
920
660
  alignment = __alignof__ (struct coff_section_tdata);
921
#else
922
  alignment = 8;
923
#endif
924
660
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
925
926
660
  vars.data = ptr;
927
660
  vars.abfd = abfd;
928
660
  vars.sec_index = 0;
929
660
  vars.magic = magic;
930
931
  /* Create the initial .idata$<n> sections:
932
     [.idata$2:  Import Directory Table -- not needed]
933
     .idata$4:  Import Lookup Table
934
     .idata$5:  Import Address Table
935
936
     Note we do not create a .idata$3 section as this is
937
     created for us by the linker script.  */
938
660
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
939
660
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
940
660
  if (id4 == NULL || id5 == NULL)
941
0
    goto error_return;
942
943
  /* Fill in the contents of these sections.  */
944
660
  if (import_name_type == IMPORT_ORDINAL)
945
182
    {
946
182
      if (ordinal == 0)
947
  /* See PR 20907 for a reproducer.  */
948
43
  goto error_return;
949
950
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
951
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
952
70
      ((unsigned int *) id4->contents)[0] = ordinal;
953
70
      ((unsigned int *) id4->contents)[1] = 0x80000000;
954
70
      ((unsigned int *) id5->contents)[0] = ordinal;
955
70
      ((unsigned int *) id5->contents)[1] = 0x80000000;
956
#else
957
69
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
958
69
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
959
69
#endif
960
69
    }
961
478
  else
962
478
    {
963
478
      char *symbol;
964
478
      unsigned int len;
965
966
      /* Create .idata$6 - the Hint Name Table.  */
967
478
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
968
478
      if (id6 == NULL)
969
0
  goto error_return;
970
971
      /* If necessary, trim the import symbol name.  */
972
478
      symbol = import_name;
973
974
      /* As used by MS compiler, '_', '@', and '?' are alternative
975
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
976
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
977
   of these is used for a symbol.  We strip this leading char for
978
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
979
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
980
981
478
      if (import_name_type != IMPORT_NAME
982
405
    && import_name_type != IMPORT_NAME_EXPORTAS)
983
337
  {
984
337
    char c = symbol[0];
985
986
    /* Check that we don't remove for targets with empty
987
       USER_LABEL_PREFIX the leading underscore.  */
988
337
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
989
316
        || c == '@' || c == '?')
990
124
      symbol++;
991
337
  }
992
993
478
      len = strlen (symbol);
994
478
      if (import_name_type == IMPORT_NAME_UNDECORATE)
995
197
  {
996
    /* Truncate at the first '@'.  */
997
197
    char *at = strchr (symbol, '@');
998
999
197
    if (at != NULL)
1000
63
      len = at - symbol;
1001
197
  }
1002
1003
478
      id6->contents[0] = ordinal & 0xff;
1004
478
      id6->contents[1] = ordinal >> 8;
1005
1006
478
      memcpy ((char *) id6->contents + 2, symbol, len);
1007
478
      id6->contents[len + 2] = '\0';
1008
478
    }
1009
1010
617
  if (import_name_type != IMPORT_ORDINAL)
1011
478
    {
1012
478
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1013
478
      pe_ILF_save_relocs (&vars, id4);
1014
1015
478
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1016
478
      pe_ILF_save_relocs (&vars, id5);
1017
478
    }
1018
1019
  /* Create an import symbol.  */
1020
617
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1021
617
  imp_sym   = vars.sym_ptr_ptr - 1;
1022
617
  imp_index = vars.sym_index - 1;
1023
1024
  /* Create extra sections depending upon the type of import we are
1025
     dealing with.  */
1026
617
  switch (import_type)
1027
617
    {
1028
0
      int i;
1029
1030
265
    case IMPORT_CODE:
1031
      /* CODE functions are special, in that they get a trampoline that
1032
   jumps to the main import symbol.  Create a .text section to hold it.
1033
   First we need to look up its contents in the jump table.  */
1034
553
      for (i = NUM_ENTRIES (jtab); i--;)
1035
553
  {
1036
553
    if (jtab[i].size == 0)
1037
265
      continue;
1038
288
    if (jtab[i].magic == magic)
1039
265
      break;
1040
288
  }
1041
      /* If we did not find a matching entry something is wrong.  */
1042
265
      if (i < 0)
1043
0
  abort ();
1044
1045
      /* Create the .text section.  */
1046
265
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1047
265
      if (text == NULL)
1048
0
  goto error_return;
1049
1050
      /* Copy in the jump code.  */
1051
265
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1052
1053
      /* Create a reloc for the data in the text section.  */
1054
#ifdef MIPS_ARCH_MAGIC_WINCE
1055
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1056
  {
1057
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1058
              (struct bfd_symbol **) imp_sym,
1059
              imp_index);
1060
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1061
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1062
              (struct bfd_symbol **) imp_sym,
1063
              imp_index);
1064
  }
1065
      else
1066
#endif
1067
#ifdef AMD64MAGIC
1068
38
      if (magic == AMD64MAGIC)
1069
38
  {
1070
38
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1071
38
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1072
38
              imp_index);
1073
38
  }
1074
0
      else
1075
0
#endif
1076
0
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1077
0
            BFD_RELOC_32, (asymbol **) imp_sym,
1078
0
            imp_index);
1079
1080
265
      pe_ILF_save_relocs (&vars, text);
1081
265
      break;
1082
1083
178
    case IMPORT_DATA:
1084
352
    case IMPORT_CONST:
1085
352
      break;
1086
1087
0
    default:
1088
      /* XXX code not yet written.  */
1089
0
      abort ();
1090
617
    }
1091
1092
  /* Now create a symbol describing the imported value.  */
1093
617
  switch (import_type)
1094
617
    {
1095
265
    case IMPORT_CODE:
1096
265
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1097
265
          BSF_NOT_AT_END | BSF_FUNCTION);
1098
1099
265
      break;
1100
1101
178
    case IMPORT_DATA:
1102
      /* Nothing to do here.  */
1103
178
      break;
1104
1105
174
    case IMPORT_CONST:
1106
174
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1107
174
      break;
1108
1109
0
    default:
1110
      /* XXX code not yet written.  */
1111
0
      abort ();
1112
617
    }
1113
1114
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1115
617
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1116
617
  if (ptr)
1117
94
    *ptr = 0;
1118
617
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1119
617
  if (ptr)
1120
94
    *ptr = '.';
1121
1122
  /* Initialise the bfd.  */
1123
617
  memset (&internal_f, 0, sizeof (internal_f));
1124
1125
617
  internal_f.f_magic  = magic;
1126
617
  internal_f.f_symptr = 0;
1127
617
  internal_f.f_nsyms  = 0;
1128
617
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1129
1130
617
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1131
617
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1132
0
    goto error_return;
1133
1134
617
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1135
0
    goto error_return;
1136
1137
617
  obj_pe (abfd) = true;
1138
#ifdef THUMBPEMAGIC
1139
106
  if (vars.magic == THUMBPEMAGIC)
1140
    /* Stop some linker warnings about thumb code not supporting
1141
       interworking.  */
1142
46
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1143
#endif
1144
1145
  /* Switch from file contents to memory contents.  */
1146
617
  bfd_cache_close (abfd);
1147
1148
617
  abfd->iostream = (void *) vars.bim;
1149
617
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1150
617
  abfd->iovec = &_bfd_memory_iovec;
1151
617
  abfd->where = 0;
1152
617
  abfd->origin = 0;
1153
617
  abfd->size = 0;
1154
617
  obj_sym_filepos (abfd) = 0;
1155
1156
  /* Point the bfd at the symbol table.  */
1157
617
  obj_symbols (abfd) = vars.sym_cache;
1158
617
  abfd->symcount = vars.sym_index;
1159
1160
617
  obj_raw_syments (abfd) = vars.native_syms;
1161
617
  obj_raw_syment_count (abfd) = vars.sym_index;
1162
617
  obj_coff_keep_raw_syms (abfd) = true;
1163
1164
617
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1165
617
  obj_coff_keep_syms (abfd) = true;
1166
1167
617
  obj_convert (abfd) = vars.sym_table;
1168
617
  obj_conv_table_size (abfd) = vars.sym_index;
1169
1170
617
  obj_coff_strings (abfd) = vars.string_table;
1171
617
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1172
617
  obj_coff_keep_strings (abfd) = true;
1173
1174
617
  return true;
1175
1176
43
 error_return:
1177
43
  free (vars.bim->buffer);
1178
43
  free (vars.bim);
1179
43
  return false;
1180
617
}
pei-i386.c:pe_ILF_build_a_bfd
Line
Count
Source
804
116
{
805
116
  bfd_byte *       ptr;
806
116
  pe_ILF_vars      vars;
807
116
  struct internal_filehdr  internal_f;
808
116
  unsigned int       import_type;
809
116
  unsigned int       import_name_type;
810
116
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
811
116
  coff_symbol_type **    imp_sym;
812
116
  unsigned int       imp_index;
813
116
  intptr_t alignment;
814
815
  /* Decode and verify the types field of the ILF structure.  */
816
116
  import_type = types & 0x3;
817
116
  import_name_type = (types & 0x1c) >> 2;
818
819
116
  switch (import_type)
820
116
    {
821
53
    case IMPORT_CODE:
822
87
    case IMPORT_DATA:
823
110
    case IMPORT_CONST:
824
110
      break;
825
826
6
    default:
827
      /* xgettext:c-format */
828
6
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
6
        abfd, import_type);
830
6
      return false;
831
116
    }
832
833
110
  switch (import_name_type)
834
110
    {
835
20
    case IMPORT_ORDINAL:
836
34
    case IMPORT_NAME:
837
65
    case IMPORT_NAME_NOPREFIX:
838
86
    case IMPORT_NAME_UNDECORATE:
839
86
      import_name = symbol_name;
840
86
      break;
841
842
19
    case IMPORT_NAME_EXPORTAS:
843
19
      if (!import_name || !import_name[0])
844
9
  {
845
9
    _bfd_error_handler (_("%pB: missing import name for "
846
9
        "IMPORT_NAME_EXPORTAS for %s"),
847
9
            abfd, symbol_name);
848
9
    return false;
849
9
  }
850
10
      break;
851
852
10
    default:
853
      /* xgettext:c-format */
854
5
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
855
5
        abfd, import_name_type);
856
5
      return false;
857
110
    }
858
859
  /* Initialise local variables.
860
861
     Note these are kept in a structure rather than being
862
     declared as statics since bfd frowns on global variables.
863
864
     We are going to construct the contents of the BFD in memory,
865
     so allocate all the space that we will need right now.  */
866
96
  vars.bim
867
96
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
868
96
  if (vars.bim == NULL)
869
0
    return false;
870
871
96
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
872
96
  vars.bim->buffer = ptr;
873
96
  vars.bim->size   = ILF_DATA_SIZE;
874
96
  if (ptr == NULL)
875
0
    goto error_return;
876
877
  /* Initialise the pointers to regions of the memory and the
878
     other contents of the pe_ILF_vars structure as well.  */
879
96
  vars.sym_cache = (coff_symbol_type *) ptr;
880
96
  vars.sym_ptr   = (coff_symbol_type *) ptr;
881
96
  vars.sym_index = 0;
882
96
  ptr += SIZEOF_ILF_SYMS;
883
884
96
  vars.sym_table = (unsigned int *) ptr;
885
96
  vars.table_ptr = (unsigned int *) ptr;
886
96
  ptr += SIZEOF_ILF_SYM_TABLE;
887
888
96
  vars.native_syms = (combined_entry_type *) ptr;
889
96
  vars.native_ptr  = (combined_entry_type *) ptr;
890
96
  ptr += SIZEOF_ILF_NATIVE_SYMS;
891
892
96
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
893
96
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
894
96
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
895
896
96
  vars.esym_table = (SYMENT *) ptr;
897
96
  vars.esym_ptr   = (SYMENT *) ptr;
898
96
  ptr += SIZEOF_ILF_EXT_SYMS;
899
900
96
  vars.reltab   = (arelent *) ptr;
901
96
  vars.relcount = 0;
902
96
  ptr += SIZEOF_ILF_RELOCS;
903
904
96
  vars.int_reltab  = (struct internal_reloc *) ptr;
905
96
  ptr += SIZEOF_ILF_INT_RELOCS;
906
907
96
  vars.string_table = (char *) ptr;
908
96
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
909
96
  ptr += SIZEOF_ILF_STRINGS;
910
96
  vars.end_string_ptr = (char *) ptr;
911
912
  /* The remaining space in bim->buffer is used
913
     by the pe_ILF_make_a_section() function.  */
914
915
  /* PR 18758: Make sure that the data area is sufficiently aligned for
916
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
917
     the test of GCC_VERSION.  For other compilers we assume 8 byte
918
     alignment.  */
919
96
#if GCC_VERSION >= 3000
920
96
  alignment = __alignof__ (struct coff_section_tdata);
921
#else
922
  alignment = 8;
923
#endif
924
96
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
925
926
96
  vars.data = ptr;
927
96
  vars.abfd = abfd;
928
96
  vars.sec_index = 0;
929
96
  vars.magic = magic;
930
931
  /* Create the initial .idata$<n> sections:
932
     [.idata$2:  Import Directory Table -- not needed]
933
     .idata$4:  Import Lookup Table
934
     .idata$5:  Import Address Table
935
936
     Note we do not create a .idata$3 section as this is
937
     created for us by the linker script.  */
938
96
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
939
96
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
940
96
  if (id4 == NULL || id5 == NULL)
941
0
    goto error_return;
942
943
  /* Fill in the contents of these sections.  */
944
96
  if (import_name_type == IMPORT_ORDINAL)
945
20
    {
946
20
      if (ordinal == 0)
947
  /* See PR 20907 for a reproducer.  */
948
4
  goto error_return;
949
950
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
951
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
952
      ((unsigned int *) id4->contents)[0] = ordinal;
953
      ((unsigned int *) id4->contents)[1] = 0x80000000;
954
      ((unsigned int *) id5->contents)[0] = ordinal;
955
      ((unsigned int *) id5->contents)[1] = 0x80000000;
956
#else
957
16
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
958
16
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
959
16
#endif
960
16
    }
961
76
  else
962
76
    {
963
76
      char *symbol;
964
76
      unsigned int len;
965
966
      /* Create .idata$6 - the Hint Name Table.  */
967
76
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
968
76
      if (id6 == NULL)
969
0
  goto error_return;
970
971
      /* If necessary, trim the import symbol name.  */
972
76
      symbol = import_name;
973
974
      /* As used by MS compiler, '_', '@', and '?' are alternative
975
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
976
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
977
   of these is used for a symbol.  We strip this leading char for
978
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
979
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
980
981
76
      if (import_name_type != IMPORT_NAME
982
62
    && import_name_type != IMPORT_NAME_EXPORTAS)
983
52
  {
984
52
    char c = symbol[0];
985
986
    /* Check that we don't remove for targets with empty
987
       USER_LABEL_PREFIX the leading underscore.  */
988
52
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
989
44
        || c == '@' || c == '?')
990
21
      symbol++;
991
52
  }
992
993
76
      len = strlen (symbol);
994
76
      if (import_name_type == IMPORT_NAME_UNDECORATE)
995
21
  {
996
    /* Truncate at the first '@'.  */
997
21
    char *at = strchr (symbol, '@');
998
999
21
    if (at != NULL)
1000
8
      len = at - symbol;
1001
21
  }
1002
1003
76
      id6->contents[0] = ordinal & 0xff;
1004
76
      id6->contents[1] = ordinal >> 8;
1005
1006
76
      memcpy ((char *) id6->contents + 2, symbol, len);
1007
76
      id6->contents[len + 2] = '\0';
1008
76
    }
1009
1010
92
  if (import_name_type != IMPORT_ORDINAL)
1011
76
    {
1012
76
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1013
76
      pe_ILF_save_relocs (&vars, id4);
1014
1015
76
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1016
76
      pe_ILF_save_relocs (&vars, id5);
1017
76
    }
1018
1019
  /* Create an import symbol.  */
1020
92
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1021
92
  imp_sym   = vars.sym_ptr_ptr - 1;
1022
92
  imp_index = vars.sym_index - 1;
1023
1024
  /* Create extra sections depending upon the type of import we are
1025
     dealing with.  */
1026
92
  switch (import_type)
1027
92
    {
1028
0
      int i;
1029
1030
44
    case IMPORT_CODE:
1031
      /* CODE functions are special, in that they get a trampoline that
1032
   jumps to the main import symbol.  Create a .text section to hold it.
1033
   First we need to look up its contents in the jump table.  */
1034
88
      for (i = NUM_ENTRIES (jtab); i--;)
1035
88
  {
1036
88
    if (jtab[i].size == 0)
1037
44
      continue;
1038
44
    if (jtab[i].magic == magic)
1039
44
      break;
1040
44
  }
1041
      /* If we did not find a matching entry something is wrong.  */
1042
44
      if (i < 0)
1043
0
  abort ();
1044
1045
      /* Create the .text section.  */
1046
44
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1047
44
      if (text == NULL)
1048
0
  goto error_return;
1049
1050
      /* Copy in the jump code.  */
1051
44
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1052
1053
      /* Create a reloc for the data in the text section.  */
1054
#ifdef MIPS_ARCH_MAGIC_WINCE
1055
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1056
  {
1057
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1058
              (struct bfd_symbol **) imp_sym,
1059
              imp_index);
1060
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1061
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1062
              (struct bfd_symbol **) imp_sym,
1063
              imp_index);
1064
  }
1065
      else
1066
#endif
1067
#ifdef AMD64MAGIC
1068
      if (magic == AMD64MAGIC)
1069
  {
1070
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1071
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1072
              imp_index);
1073
  }
1074
      else
1075
#endif
1076
44
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1077
44
            BFD_RELOC_32, (asymbol **) imp_sym,
1078
44
            imp_index);
1079
1080
44
      pe_ILF_save_relocs (&vars, text);
1081
44
      break;
1082
1083
31
    case IMPORT_DATA:
1084
48
    case IMPORT_CONST:
1085
48
      break;
1086
1087
0
    default:
1088
      /* XXX code not yet written.  */
1089
0
      abort ();
1090
92
    }
1091
1092
  /* Now create a symbol describing the imported value.  */
1093
92
  switch (import_type)
1094
92
    {
1095
44
    case IMPORT_CODE:
1096
44
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1097
44
          BSF_NOT_AT_END | BSF_FUNCTION);
1098
1099
44
      break;
1100
1101
31
    case IMPORT_DATA:
1102
      /* Nothing to do here.  */
1103
31
      break;
1104
1105
17
    case IMPORT_CONST:
1106
17
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1107
17
      break;
1108
1109
0
    default:
1110
      /* XXX code not yet written.  */
1111
0
      abort ();
1112
92
    }
1113
1114
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1115
92
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1116
92
  if (ptr)
1117
15
    *ptr = 0;
1118
92
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1119
92
  if (ptr)
1120
15
    *ptr = '.';
1121
1122
  /* Initialise the bfd.  */
1123
92
  memset (&internal_f, 0, sizeof (internal_f));
1124
1125
92
  internal_f.f_magic  = magic;
1126
92
  internal_f.f_symptr = 0;
1127
92
  internal_f.f_nsyms  = 0;
1128
92
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1129
1130
92
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1131
92
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1132
0
    goto error_return;
1133
1134
92
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1135
0
    goto error_return;
1136
1137
92
  obj_pe (abfd) = true;
1138
#ifdef THUMBPEMAGIC
1139
  if (vars.magic == THUMBPEMAGIC)
1140
    /* Stop some linker warnings about thumb code not supporting
1141
       interworking.  */
1142
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1143
#endif
1144
1145
  /* Switch from file contents to memory contents.  */
1146
92
  bfd_cache_close (abfd);
1147
1148
92
  abfd->iostream = (void *) vars.bim;
1149
92
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1150
92
  abfd->iovec = &_bfd_memory_iovec;
1151
92
  abfd->where = 0;
1152
92
  abfd->origin = 0;
1153
92
  abfd->size = 0;
1154
92
  obj_sym_filepos (abfd) = 0;
1155
1156
  /* Point the bfd at the symbol table.  */
1157
92
  obj_symbols (abfd) = vars.sym_cache;
1158
92
  abfd->symcount = vars.sym_index;
1159
1160
92
  obj_raw_syments (abfd) = vars.native_syms;
1161
92
  obj_raw_syment_count (abfd) = vars.sym_index;
1162
92
  obj_coff_keep_raw_syms (abfd) = true;
1163
1164
92
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1165
92
  obj_coff_keep_syms (abfd) = true;
1166
1167
92
  obj_convert (abfd) = vars.sym_table;
1168
92
  obj_conv_table_size (abfd) = vars.sym_index;
1169
1170
92
  obj_coff_strings (abfd) = vars.string_table;
1171
92
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1172
92
  obj_coff_keep_strings (abfd) = true;
1173
1174
92
  return true;
1175
1176
4
 error_return:
1177
4
  free (vars.bim->buffer);
1178
4
  free (vars.bim);
1179
  return false;
1180
92
}
pei-x86_64.c:pe_ILF_build_a_bfd
Line
Count
Source
804
107
{
805
107
  bfd_byte *       ptr;
806
107
  pe_ILF_vars      vars;
807
107
  struct internal_filehdr  internal_f;
808
107
  unsigned int       import_type;
809
107
  unsigned int       import_name_type;
810
107
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
811
107
  coff_symbol_type **    imp_sym;
812
107
  unsigned int       imp_index;
813
107
  intptr_t alignment;
814
815
  /* Decode and verify the types field of the ILF structure.  */
816
107
  import_type = types & 0x3;
817
107
  import_name_type = (types & 0x1c) >> 2;
818
819
107
  switch (import_type)
820
107
    {
821
47
    case IMPORT_CODE:
822
68
    case IMPORT_DATA:
823
101
    case IMPORT_CONST:
824
101
      break;
825
826
6
    default:
827
      /* xgettext:c-format */
828
6
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
6
        abfd, import_type);
830
6
      return false;
831
107
    }
832
833
101
  switch (import_name_type)
834
101
    {
835
22
    case IMPORT_ORDINAL:
836
32
    case IMPORT_NAME:
837
49
    case IMPORT_NAME_NOPREFIX:
838
79
    case IMPORT_NAME_UNDECORATE:
839
79
      import_name = symbol_name;
840
79
      break;
841
842
17
    case IMPORT_NAME_EXPORTAS:
843
17
      if (!import_name || !import_name[0])
844
9
  {
845
9
    _bfd_error_handler (_("%pB: missing import name for "
846
9
        "IMPORT_NAME_EXPORTAS for %s"),
847
9
            abfd, symbol_name);
848
9
    return false;
849
9
  }
850
8
      break;
851
852
8
    default:
853
      /* xgettext:c-format */
854
5
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
855
5
        abfd, import_name_type);
856
5
      return false;
857
101
    }
858
859
  /* Initialise local variables.
860
861
     Note these are kept in a structure rather than being
862
     declared as statics since bfd frowns on global variables.
863
864
     We are going to construct the contents of the BFD in memory,
865
     so allocate all the space that we will need right now.  */
866
87
  vars.bim
867
87
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
868
87
  if (vars.bim == NULL)
869
0
    return false;
870
871
87
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
872
87
  vars.bim->buffer = ptr;
873
87
  vars.bim->size   = ILF_DATA_SIZE;
874
87
  if (ptr == NULL)
875
0
    goto error_return;
876
877
  /* Initialise the pointers to regions of the memory and the
878
     other contents of the pe_ILF_vars structure as well.  */
879
87
  vars.sym_cache = (coff_symbol_type *) ptr;
880
87
  vars.sym_ptr   = (coff_symbol_type *) ptr;
881
87
  vars.sym_index = 0;
882
87
  ptr += SIZEOF_ILF_SYMS;
883
884
87
  vars.sym_table = (unsigned int *) ptr;
885
87
  vars.table_ptr = (unsigned int *) ptr;
886
87
  ptr += SIZEOF_ILF_SYM_TABLE;
887
888
87
  vars.native_syms = (combined_entry_type *) ptr;
889
87
  vars.native_ptr  = (combined_entry_type *) ptr;
890
87
  ptr += SIZEOF_ILF_NATIVE_SYMS;
891
892
87
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
893
87
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
894
87
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
895
896
87
  vars.esym_table = (SYMENT *) ptr;
897
87
  vars.esym_ptr   = (SYMENT *) ptr;
898
87
  ptr += SIZEOF_ILF_EXT_SYMS;
899
900
87
  vars.reltab   = (arelent *) ptr;
901
87
  vars.relcount = 0;
902
87
  ptr += SIZEOF_ILF_RELOCS;
903
904
87
  vars.int_reltab  = (struct internal_reloc *) ptr;
905
87
  ptr += SIZEOF_ILF_INT_RELOCS;
906
907
87
  vars.string_table = (char *) ptr;
908
87
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
909
87
  ptr += SIZEOF_ILF_STRINGS;
910
87
  vars.end_string_ptr = (char *) ptr;
911
912
  /* The remaining space in bim->buffer is used
913
     by the pe_ILF_make_a_section() function.  */
914
915
  /* PR 18758: Make sure that the data area is sufficiently aligned for
916
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
917
     the test of GCC_VERSION.  For other compilers we assume 8 byte
918
     alignment.  */
919
87
#if GCC_VERSION >= 3000
920
87
  alignment = __alignof__ (struct coff_section_tdata);
921
#else
922
  alignment = 8;
923
#endif
924
87
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
925
926
87
  vars.data = ptr;
927
87
  vars.abfd = abfd;
928
87
  vars.sec_index = 0;
929
87
  vars.magic = magic;
930
931
  /* Create the initial .idata$<n> sections:
932
     [.idata$2:  Import Directory Table -- not needed]
933
     .idata$4:  Import Lookup Table
934
     .idata$5:  Import Address Table
935
936
     Note we do not create a .idata$3 section as this is
937
     created for us by the linker script.  */
938
87
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
939
87
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
940
87
  if (id4 == NULL || id5 == NULL)
941
0
    goto error_return;
942
943
  /* Fill in the contents of these sections.  */
944
87
  if (import_name_type == IMPORT_ORDINAL)
945
22
    {
946
22
      if (ordinal == 0)
947
  /* See PR 20907 for a reproducer.  */
948
5
  goto error_return;
949
950
17
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
951
17
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
952
17
      ((unsigned int *) id4->contents)[0] = ordinal;
953
17
      ((unsigned int *) id4->contents)[1] = 0x80000000;
954
17
      ((unsigned int *) id5->contents)[0] = ordinal;
955
17
      ((unsigned int *) id5->contents)[1] = 0x80000000;
956
#else
957
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
958
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
959
#endif
960
17
    }
961
65
  else
962
65
    {
963
65
      char *symbol;
964
65
      unsigned int len;
965
966
      /* Create .idata$6 - the Hint Name Table.  */
967
65
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
968
65
      if (id6 == NULL)
969
0
  goto error_return;
970
971
      /* If necessary, trim the import symbol name.  */
972
65
      symbol = import_name;
973
974
      /* As used by MS compiler, '_', '@', and '?' are alternative
975
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
976
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
977
   of these is used for a symbol.  We strip this leading char for
978
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
979
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
980
981
65
      if (import_name_type != IMPORT_NAME
982
55
    && import_name_type != IMPORT_NAME_EXPORTAS)
983
47
  {
984
47
    char c = symbol[0];
985
986
    /* Check that we don't remove for targets with empty
987
       USER_LABEL_PREFIX the leading underscore.  */
988
47
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
989
47
        || c == '@' || c == '?')
990
18
      symbol++;
991
47
  }
992
993
65
      len = strlen (symbol);
994
65
      if (import_name_type == IMPORT_NAME_UNDECORATE)
995
30
  {
996
    /* Truncate at the first '@'.  */
997
30
    char *at = strchr (symbol, '@');
998
999
30
    if (at != NULL)
1000
18
      len = at - symbol;
1001
30
  }
1002
1003
65
      id6->contents[0] = ordinal & 0xff;
1004
65
      id6->contents[1] = ordinal >> 8;
1005
1006
65
      memcpy ((char *) id6->contents + 2, symbol, len);
1007
65
      id6->contents[len + 2] = '\0';
1008
65
    }
1009
1010
82
  if (import_name_type != IMPORT_ORDINAL)
1011
65
    {
1012
65
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1013
65
      pe_ILF_save_relocs (&vars, id4);
1014
1015
65
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1016
65
      pe_ILF_save_relocs (&vars, id5);
1017
65
    }
1018
1019
  /* Create an import symbol.  */
1020
82
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1021
82
  imp_sym   = vars.sym_ptr_ptr - 1;
1022
82
  imp_index = vars.sym_index - 1;
1023
1024
  /* Create extra sections depending upon the type of import we are
1025
     dealing with.  */
1026
82
  switch (import_type)
1027
82
    {
1028
0
      int i;
1029
1030
38
    case IMPORT_CODE:
1031
      /* CODE functions are special, in that they get a trampoline that
1032
   jumps to the main import symbol.  Create a .text section to hold it.
1033
   First we need to look up its contents in the jump table.  */
1034
76
      for (i = NUM_ENTRIES (jtab); i--;)
1035
76
  {
1036
76
    if (jtab[i].size == 0)
1037
38
      continue;
1038
38
    if (jtab[i].magic == magic)
1039
38
      break;
1040
38
  }
1041
      /* If we did not find a matching entry something is wrong.  */
1042
38
      if (i < 0)
1043
0
  abort ();
1044
1045
      /* Create the .text section.  */
1046
38
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1047
38
      if (text == NULL)
1048
0
  goto error_return;
1049
1050
      /* Copy in the jump code.  */
1051
38
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1052
1053
      /* Create a reloc for the data in the text section.  */
1054
#ifdef MIPS_ARCH_MAGIC_WINCE
1055
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1056
  {
1057
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1058
              (struct bfd_symbol **) imp_sym,
1059
              imp_index);
1060
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1061
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1062
              (struct bfd_symbol **) imp_sym,
1063
              imp_index);
1064
  }
1065
      else
1066
#endif
1067
38
#ifdef AMD64MAGIC
1068
38
      if (magic == AMD64MAGIC)
1069
38
  {
1070
38
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1071
38
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1072
38
              imp_index);
1073
38
  }
1074
0
      else
1075
0
#endif
1076
0
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1077
0
            BFD_RELOC_32, (asymbol **) imp_sym,
1078
0
            imp_index);
1079
1080
38
      pe_ILF_save_relocs (&vars, text);
1081
38
      break;
1082
1083
18
    case IMPORT_DATA:
1084
44
    case IMPORT_CONST:
1085
44
      break;
1086
1087
0
    default:
1088
      /* XXX code not yet written.  */
1089
0
      abort ();
1090
82
    }
1091
1092
  /* Now create a symbol describing the imported value.  */
1093
82
  switch (import_type)
1094
82
    {
1095
38
    case IMPORT_CODE:
1096
38
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1097
38
          BSF_NOT_AT_END | BSF_FUNCTION);
1098
1099
38
      break;
1100
1101
18
    case IMPORT_DATA:
1102
      /* Nothing to do here.  */
1103
18
      break;
1104
1105
26
    case IMPORT_CONST:
1106
26
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1107
26
      break;
1108
1109
0
    default:
1110
      /* XXX code not yet written.  */
1111
0
      abort ();
1112
82
    }
1113
1114
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1115
82
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1116
82
  if (ptr)
1117
8
    *ptr = 0;
1118
82
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1119
82
  if (ptr)
1120
8
    *ptr = '.';
1121
1122
  /* Initialise the bfd.  */
1123
82
  memset (&internal_f, 0, sizeof (internal_f));
1124
1125
82
  internal_f.f_magic  = magic;
1126
82
  internal_f.f_symptr = 0;
1127
82
  internal_f.f_nsyms  = 0;
1128
82
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1129
1130
82
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1131
82
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1132
0
    goto error_return;
1133
1134
82
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1135
0
    goto error_return;
1136
1137
82
  obj_pe (abfd) = true;
1138
#ifdef THUMBPEMAGIC
1139
  if (vars.magic == THUMBPEMAGIC)
1140
    /* Stop some linker warnings about thumb code not supporting
1141
       interworking.  */
1142
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1143
#endif
1144
1145
  /* Switch from file contents to memory contents.  */
1146
82
  bfd_cache_close (abfd);
1147
1148
82
  abfd->iostream = (void *) vars.bim;
1149
82
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1150
82
  abfd->iovec = &_bfd_memory_iovec;
1151
82
  abfd->where = 0;
1152
82
  abfd->origin = 0;
1153
82
  abfd->size = 0;
1154
82
  obj_sym_filepos (abfd) = 0;
1155
1156
  /* Point the bfd at the symbol table.  */
1157
82
  obj_symbols (abfd) = vars.sym_cache;
1158
82
  abfd->symcount = vars.sym_index;
1159
1160
82
  obj_raw_syments (abfd) = vars.native_syms;
1161
82
  obj_raw_syment_count (abfd) = vars.sym_index;
1162
82
  obj_coff_keep_raw_syms (abfd) = true;
1163
1164
82
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1165
82
  obj_coff_keep_syms (abfd) = true;
1166
1167
82
  obj_convert (abfd) = vars.sym_table;
1168
82
  obj_conv_table_size (abfd) = vars.sym_index;
1169
1170
82
  obj_coff_strings (abfd) = vars.string_table;
1171
82
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1172
82
  obj_coff_keep_strings (abfd) = true;
1173
1174
82
  return true;
1175
1176
5
 error_return:
1177
5
  free (vars.bim->buffer);
1178
5
  free (vars.bim);
1179
  return false;
1180
82
}
pei-aarch64.c:pe_ILF_build_a_bfd
Line
Count
Source
804
114
{
805
114
  bfd_byte *       ptr;
806
114
  pe_ILF_vars      vars;
807
114
  struct internal_filehdr  internal_f;
808
114
  unsigned int       import_type;
809
114
  unsigned int       import_name_type;
810
114
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
811
114
  coff_symbol_type **    imp_sym;
812
114
  unsigned int       imp_index;
813
114
  intptr_t alignment;
814
815
  /* Decode and verify the types field of the ILF structure.  */
816
114
  import_type = types & 0x3;
817
114
  import_name_type = (types & 0x1c) >> 2;
818
819
114
  switch (import_type)
820
114
    {
821
57
    case IMPORT_CODE:
822
86
    case IMPORT_DATA:
823
108
    case IMPORT_CONST:
824
108
      break;
825
826
6
    default:
827
      /* xgettext:c-format */
828
6
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
6
        abfd, import_type);
830
6
      return false;
831
114
    }
832
833
108
  switch (import_name_type)
834
108
    {
835
25
    case IMPORT_ORDINAL:
836
36
    case IMPORT_NAME:
837
51
    case IMPORT_NAME_NOPREFIX:
838
81
    case IMPORT_NAME_UNDECORATE:
839
81
      import_name = symbol_name;
840
81
      break;
841
842
22
    case IMPORT_NAME_EXPORTAS:
843
22
      if (!import_name || !import_name[0])
844
10
  {
845
10
    _bfd_error_handler (_("%pB: missing import name for "
846
10
        "IMPORT_NAME_EXPORTAS for %s"),
847
10
            abfd, symbol_name);
848
10
    return false;
849
10
  }
850
12
      break;
851
852
12
    default:
853
      /* xgettext:c-format */
854
5
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
855
5
        abfd, import_name_type);
856
5
      return false;
857
108
    }
858
859
  /* Initialise local variables.
860
861
     Note these are kept in a structure rather than being
862
     declared as statics since bfd frowns on global variables.
863
864
     We are going to construct the contents of the BFD in memory,
865
     so allocate all the space that we will need right now.  */
866
93
  vars.bim
867
93
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
868
93
  if (vars.bim == NULL)
869
0
    return false;
870
871
93
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
872
93
  vars.bim->buffer = ptr;
873
93
  vars.bim->size   = ILF_DATA_SIZE;
874
93
  if (ptr == NULL)
875
0
    goto error_return;
876
877
  /* Initialise the pointers to regions of the memory and the
878
     other contents of the pe_ILF_vars structure as well.  */
879
93
  vars.sym_cache = (coff_symbol_type *) ptr;
880
93
  vars.sym_ptr   = (coff_symbol_type *) ptr;
881
93
  vars.sym_index = 0;
882
93
  ptr += SIZEOF_ILF_SYMS;
883
884
93
  vars.sym_table = (unsigned int *) ptr;
885
93
  vars.table_ptr = (unsigned int *) ptr;
886
93
  ptr += SIZEOF_ILF_SYM_TABLE;
887
888
93
  vars.native_syms = (combined_entry_type *) ptr;
889
93
  vars.native_ptr  = (combined_entry_type *) ptr;
890
93
  ptr += SIZEOF_ILF_NATIVE_SYMS;
891
892
93
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
893
93
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
894
93
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
895
896
93
  vars.esym_table = (SYMENT *) ptr;
897
93
  vars.esym_ptr   = (SYMENT *) ptr;
898
93
  ptr += SIZEOF_ILF_EXT_SYMS;
899
900
93
  vars.reltab   = (arelent *) ptr;
901
93
  vars.relcount = 0;
902
93
  ptr += SIZEOF_ILF_RELOCS;
903
904
93
  vars.int_reltab  = (struct internal_reloc *) ptr;
905
93
  ptr += SIZEOF_ILF_INT_RELOCS;
906
907
93
  vars.string_table = (char *) ptr;
908
93
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
909
93
  ptr += SIZEOF_ILF_STRINGS;
910
93
  vars.end_string_ptr = (char *) ptr;
911
912
  /* The remaining space in bim->buffer is used
913
     by the pe_ILF_make_a_section() function.  */
914
915
  /* PR 18758: Make sure that the data area is sufficiently aligned for
916
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
917
     the test of GCC_VERSION.  For other compilers we assume 8 byte
918
     alignment.  */
919
93
#if GCC_VERSION >= 3000
920
93
  alignment = __alignof__ (struct coff_section_tdata);
921
#else
922
  alignment = 8;
923
#endif
924
93
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
925
926
93
  vars.data = ptr;
927
93
  vars.abfd = abfd;
928
93
  vars.sec_index = 0;
929
93
  vars.magic = magic;
930
931
  /* Create the initial .idata$<n> sections:
932
     [.idata$2:  Import Directory Table -- not needed]
933
     .idata$4:  Import Lookup Table
934
     .idata$5:  Import Address Table
935
936
     Note we do not create a .idata$3 section as this is
937
     created for us by the linker script.  */
938
93
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
939
93
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
940
93
  if (id4 == NULL || id5 == NULL)
941
0
    goto error_return;
942
943
  /* Fill in the contents of these sections.  */
944
93
  if (import_name_type == IMPORT_ORDINAL)
945
25
    {
946
25
      if (ordinal == 0)
947
  /* See PR 20907 for a reproducer.  */
948
4
  goto error_return;
949
950
21
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
951
21
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
952
21
      ((unsigned int *) id4->contents)[0] = ordinal;
953
21
      ((unsigned int *) id4->contents)[1] = 0x80000000;
954
21
      ((unsigned int *) id5->contents)[0] = ordinal;
955
21
      ((unsigned int *) id5->contents)[1] = 0x80000000;
956
#else
957
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
958
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
959
#endif
960
21
    }
961
68
  else
962
68
    {
963
68
      char *symbol;
964
68
      unsigned int len;
965
966
      /* Create .idata$6 - the Hint Name Table.  */
967
68
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
968
68
      if (id6 == NULL)
969
0
  goto error_return;
970
971
      /* If necessary, trim the import symbol name.  */
972
68
      symbol = import_name;
973
974
      /* As used by MS compiler, '_', '@', and '?' are alternative
975
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
976
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
977
   of these is used for a symbol.  We strip this leading char for
978
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
979
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
980
981
68
      if (import_name_type != IMPORT_NAME
982
57
    && import_name_type != IMPORT_NAME_EXPORTAS)
983
45
  {
984
45
    char c = symbol[0];
985
986
    /* Check that we don't remove for targets with empty
987
       USER_LABEL_PREFIX the leading underscore.  */
988
45
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
989
45
        || c == '@' || c == '?')
990
14
      symbol++;
991
45
  }
992
993
68
      len = strlen (symbol);
994
68
      if (import_name_type == IMPORT_NAME_UNDECORATE)
995
30
  {
996
    /* Truncate at the first '@'.  */
997
30
    char *at = strchr (symbol, '@');
998
999
30
    if (at != NULL)
1000
9
      len = at - symbol;
1001
30
  }
1002
1003
68
      id6->contents[0] = ordinal & 0xff;
1004
68
      id6->contents[1] = ordinal >> 8;
1005
1006
68
      memcpy ((char *) id6->contents + 2, symbol, len);
1007
68
      id6->contents[len + 2] = '\0';
1008
68
    }
1009
1010
89
  if (import_name_type != IMPORT_ORDINAL)
1011
68
    {
1012
68
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1013
68
      pe_ILF_save_relocs (&vars, id4);
1014
1015
68
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1016
68
      pe_ILF_save_relocs (&vars, id5);
1017
68
    }
1018
1019
  /* Create an import symbol.  */
1020
89
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1021
89
  imp_sym   = vars.sym_ptr_ptr - 1;
1022
89
  imp_index = vars.sym_index - 1;
1023
1024
  /* Create extra sections depending upon the type of import we are
1025
     dealing with.  */
1026
89
  switch (import_type)
1027
89
    {
1028
0
      int i;
1029
1030
51
    case IMPORT_CODE:
1031
      /* CODE functions are special, in that they get a trampoline that
1032
   jumps to the main import symbol.  Create a .text section to hold it.
1033
   First we need to look up its contents in the jump table.  */
1034
102
      for (i = NUM_ENTRIES (jtab); i--;)
1035
102
  {
1036
102
    if (jtab[i].size == 0)
1037
51
      continue;
1038
51
    if (jtab[i].magic == magic)
1039
51
      break;
1040
51
  }
1041
      /* If we did not find a matching entry something is wrong.  */
1042
51
      if (i < 0)
1043
0
  abort ();
1044
1045
      /* Create the .text section.  */
1046
51
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1047
51
      if (text == NULL)
1048
0
  goto error_return;
1049
1050
      /* Copy in the jump code.  */
1051
51
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1052
1053
      /* Create a reloc for the data in the text section.  */
1054
#ifdef MIPS_ARCH_MAGIC_WINCE
1055
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1056
  {
1057
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1058
              (struct bfd_symbol **) imp_sym,
1059
              imp_index);
1060
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1061
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1062
              (struct bfd_symbol **) imp_sym,
1063
              imp_index);
1064
  }
1065
      else
1066
#endif
1067
#ifdef AMD64MAGIC
1068
      if (magic == AMD64MAGIC)
1069
  {
1070
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1071
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1072
              imp_index);
1073
  }
1074
      else
1075
#endif
1076
51
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1077
51
            BFD_RELOC_32, (asymbol **) imp_sym,
1078
51
            imp_index);
1079
1080
51
      pe_ILF_save_relocs (&vars, text);
1081
51
      break;
1082
1083
22
    case IMPORT_DATA:
1084
38
    case IMPORT_CONST:
1085
38
      break;
1086
1087
0
    default:
1088
      /* XXX code not yet written.  */
1089
0
      abort ();
1090
89
    }
1091
1092
  /* Now create a symbol describing the imported value.  */
1093
89
  switch (import_type)
1094
89
    {
1095
51
    case IMPORT_CODE:
1096
51
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1097
51
          BSF_NOT_AT_END | BSF_FUNCTION);
1098
1099
51
      break;
1100
1101
22
    case IMPORT_DATA:
1102
      /* Nothing to do here.  */
1103
22
      break;
1104
1105
16
    case IMPORT_CONST:
1106
16
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1107
16
      break;
1108
1109
0
    default:
1110
      /* XXX code not yet written.  */
1111
0
      abort ();
1112
89
    }
1113
1114
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1115
89
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1116
89
  if (ptr)
1117
22
    *ptr = 0;
1118
89
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1119
89
  if (ptr)
1120
22
    *ptr = '.';
1121
1122
  /* Initialise the bfd.  */
1123
89
  memset (&internal_f, 0, sizeof (internal_f));
1124
1125
89
  internal_f.f_magic  = magic;
1126
89
  internal_f.f_symptr = 0;
1127
89
  internal_f.f_nsyms  = 0;
1128
89
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1129
1130
89
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1131
89
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1132
0
    goto error_return;
1133
1134
89
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1135
0
    goto error_return;
1136
1137
89
  obj_pe (abfd) = true;
1138
#ifdef THUMBPEMAGIC
1139
  if (vars.magic == THUMBPEMAGIC)
1140
    /* Stop some linker warnings about thumb code not supporting
1141
       interworking.  */
1142
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1143
#endif
1144
1145
  /* Switch from file contents to memory contents.  */
1146
89
  bfd_cache_close (abfd);
1147
1148
89
  abfd->iostream = (void *) vars.bim;
1149
89
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1150
89
  abfd->iovec = &_bfd_memory_iovec;
1151
89
  abfd->where = 0;
1152
89
  abfd->origin = 0;
1153
89
  abfd->size = 0;
1154
89
  obj_sym_filepos (abfd) = 0;
1155
1156
  /* Point the bfd at the symbol table.  */
1157
89
  obj_symbols (abfd) = vars.sym_cache;
1158
89
  abfd->symcount = vars.sym_index;
1159
1160
89
  obj_raw_syments (abfd) = vars.native_syms;
1161
89
  obj_raw_syment_count (abfd) = vars.sym_index;
1162
89
  obj_coff_keep_raw_syms (abfd) = true;
1163
1164
89
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1165
89
  obj_coff_keep_syms (abfd) = true;
1166
1167
89
  obj_convert (abfd) = vars.sym_table;
1168
89
  obj_conv_table_size (abfd) = vars.sym_index;
1169
1170
89
  obj_coff_strings (abfd) = vars.string_table;
1171
89
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1172
89
  obj_coff_keep_strings (abfd) = true;
1173
1174
89
  return true;
1175
1176
4
 error_return:
1177
4
  free (vars.bim->buffer);
1178
4
  free (vars.bim);
1179
  return false;
1180
89
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_build_a_bfd
pei-loongarch64.c:pe_ILF_build_a_bfd
Line
Count
Source
804
102
{
805
102
  bfd_byte *       ptr;
806
102
  pe_ILF_vars      vars;
807
102
  struct internal_filehdr  internal_f;
808
102
  unsigned int       import_type;
809
102
  unsigned int       import_name_type;
810
102
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
811
102
  coff_symbol_type **    imp_sym;
812
102
  unsigned int       imp_index;
813
102
  intptr_t alignment;
814
815
  /* Decode and verify the types field of the ILF structure.  */
816
102
  import_type = types & 0x3;
817
102
  import_name_type = (types & 0x1c) >> 2;
818
819
102
  switch (import_type)
820
102
    {
821
41
    case IMPORT_CODE:
822
70
    case IMPORT_DATA:
823
95
    case IMPORT_CONST:
824
95
      break;
825
826
7
    default:
827
      /* xgettext:c-format */
828
7
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
7
        abfd, import_type);
830
7
      return false;
831
102
    }
832
833
95
  switch (import_name_type)
834
95
    {
835
21
    case IMPORT_ORDINAL:
836
31
    case IMPORT_NAME:
837
41
    case IMPORT_NAME_NOPREFIX:
838
73
    case IMPORT_NAME_UNDECORATE:
839
73
      import_name = symbol_name;
840
73
      break;
841
842
18
    case IMPORT_NAME_EXPORTAS:
843
18
      if (!import_name || !import_name[0])
844
8
  {
845
8
    _bfd_error_handler (_("%pB: missing import name for "
846
8
        "IMPORT_NAME_EXPORTAS for %s"),
847
8
            abfd, symbol_name);
848
8
    return false;
849
8
  }
850
10
      break;
851
852
10
    default:
853
      /* xgettext:c-format */
854
4
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
855
4
        abfd, import_name_type);
856
4
      return false;
857
95
    }
858
859
  /* Initialise local variables.
860
861
     Note these are kept in a structure rather than being
862
     declared as statics since bfd frowns on global variables.
863
864
     We are going to construct the contents of the BFD in memory,
865
     so allocate all the space that we will need right now.  */
866
83
  vars.bim
867
83
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
868
83
  if (vars.bim == NULL)
869
0
    return false;
870
871
83
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
872
83
  vars.bim->buffer = ptr;
873
83
  vars.bim->size   = ILF_DATA_SIZE;
874
83
  if (ptr == NULL)
875
0
    goto error_return;
876
877
  /* Initialise the pointers to regions of the memory and the
878
     other contents of the pe_ILF_vars structure as well.  */
879
83
  vars.sym_cache = (coff_symbol_type *) ptr;
880
83
  vars.sym_ptr   = (coff_symbol_type *) ptr;
881
83
  vars.sym_index = 0;
882
83
  ptr += SIZEOF_ILF_SYMS;
883
884
83
  vars.sym_table = (unsigned int *) ptr;
885
83
  vars.table_ptr = (unsigned int *) ptr;
886
83
  ptr += SIZEOF_ILF_SYM_TABLE;
887
888
83
  vars.native_syms = (combined_entry_type *) ptr;
889
83
  vars.native_ptr  = (combined_entry_type *) ptr;
890
83
  ptr += SIZEOF_ILF_NATIVE_SYMS;
891
892
83
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
893
83
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
894
83
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
895
896
83
  vars.esym_table = (SYMENT *) ptr;
897
83
  vars.esym_ptr   = (SYMENT *) ptr;
898
83
  ptr += SIZEOF_ILF_EXT_SYMS;
899
900
83
  vars.reltab   = (arelent *) ptr;
901
83
  vars.relcount = 0;
902
83
  ptr += SIZEOF_ILF_RELOCS;
903
904
83
  vars.int_reltab  = (struct internal_reloc *) ptr;
905
83
  ptr += SIZEOF_ILF_INT_RELOCS;
906
907
83
  vars.string_table = (char *) ptr;
908
83
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
909
83
  ptr += SIZEOF_ILF_STRINGS;
910
83
  vars.end_string_ptr = (char *) ptr;
911
912
  /* The remaining space in bim->buffer is used
913
     by the pe_ILF_make_a_section() function.  */
914
915
  /* PR 18758: Make sure that the data area is sufficiently aligned for
916
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
917
     the test of GCC_VERSION.  For other compilers we assume 8 byte
918
     alignment.  */
919
83
#if GCC_VERSION >= 3000
920
83
  alignment = __alignof__ (struct coff_section_tdata);
921
#else
922
  alignment = 8;
923
#endif
924
83
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
925
926
83
  vars.data = ptr;
927
83
  vars.abfd = abfd;
928
83
  vars.sec_index = 0;
929
83
  vars.magic = magic;
930
931
  /* Create the initial .idata$<n> sections:
932
     [.idata$2:  Import Directory Table -- not needed]
933
     .idata$4:  Import Lookup Table
934
     .idata$5:  Import Address Table
935
936
     Note we do not create a .idata$3 section as this is
937
     created for us by the linker script.  */
938
83
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
939
83
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
940
83
  if (id4 == NULL || id5 == NULL)
941
0
    goto error_return;
942
943
  /* Fill in the contents of these sections.  */
944
83
  if (import_name_type == IMPORT_ORDINAL)
945
21
    {
946
21
      if (ordinal == 0)
947
  /* See PR 20907 for a reproducer.  */
948
5
  goto error_return;
949
950
16
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
951
16
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
952
16
      ((unsigned int *) id4->contents)[0] = ordinal;
953
16
      ((unsigned int *) id4->contents)[1] = 0x80000000;
954
16
      ((unsigned int *) id5->contents)[0] = ordinal;
955
16
      ((unsigned int *) id5->contents)[1] = 0x80000000;
956
#else
957
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
958
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
959
#endif
960
16
    }
961
62
  else
962
62
    {
963
62
      char *symbol;
964
62
      unsigned int len;
965
966
      /* Create .idata$6 - the Hint Name Table.  */
967
62
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
968
62
      if (id6 == NULL)
969
0
  goto error_return;
970
971
      /* If necessary, trim the import symbol name.  */
972
62
      symbol = import_name;
973
974
      /* As used by MS compiler, '_', '@', and '?' are alternative
975
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
976
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
977
   of these is used for a symbol.  We strip this leading char for
978
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
979
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
980
981
62
      if (import_name_type != IMPORT_NAME
982
52
    && import_name_type != IMPORT_NAME_EXPORTAS)
983
42
  {
984
42
    char c = symbol[0];
985
986
    /* Check that we don't remove for targets with empty
987
       USER_LABEL_PREFIX the leading underscore.  */
988
42
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
989
42
        || c == '@' || c == '?')
990
13
      symbol++;
991
42
  }
992
993
62
      len = strlen (symbol);
994
62
      if (import_name_type == IMPORT_NAME_UNDECORATE)
995
32
  {
996
    /* Truncate at the first '@'.  */
997
32
    char *at = strchr (symbol, '@');
998
999
32
    if (at != NULL)
1000
8
      len = at - symbol;
1001
32
  }
1002
1003
62
      id6->contents[0] = ordinal & 0xff;
1004
62
      id6->contents[1] = ordinal >> 8;
1005
1006
62
      memcpy ((char *) id6->contents + 2, symbol, len);
1007
62
      id6->contents[len + 2] = '\0';
1008
62
    }
1009
1010
78
  if (import_name_type != IMPORT_ORDINAL)
1011
62
    {
1012
62
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1013
62
      pe_ILF_save_relocs (&vars, id4);
1014
1015
62
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1016
62
      pe_ILF_save_relocs (&vars, id5);
1017
62
    }
1018
1019
  /* Create an import symbol.  */
1020
78
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1021
78
  imp_sym   = vars.sym_ptr_ptr - 1;
1022
78
  imp_index = vars.sym_index - 1;
1023
1024
  /* Create extra sections depending upon the type of import we are
1025
     dealing with.  */
1026
78
  switch (import_type)
1027
78
    {
1028
0
      int i;
1029
1030
32
    case IMPORT_CODE:
1031
      /* CODE functions are special, in that they get a trampoline that
1032
   jumps to the main import symbol.  Create a .text section to hold it.
1033
   First we need to look up its contents in the jump table.  */
1034
64
      for (i = NUM_ENTRIES (jtab); i--;)
1035
64
  {
1036
64
    if (jtab[i].size == 0)
1037
32
      continue;
1038
32
    if (jtab[i].magic == magic)
1039
32
      break;
1040
32
  }
1041
      /* If we did not find a matching entry something is wrong.  */
1042
32
      if (i < 0)
1043
0
  abort ();
1044
1045
      /* Create the .text section.  */
1046
32
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1047
32
      if (text == NULL)
1048
0
  goto error_return;
1049
1050
      /* Copy in the jump code.  */
1051
32
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1052
1053
      /* Create a reloc for the data in the text section.  */
1054
#ifdef MIPS_ARCH_MAGIC_WINCE
1055
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1056
  {
1057
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1058
              (struct bfd_symbol **) imp_sym,
1059
              imp_index);
1060
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1061
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1062
              (struct bfd_symbol **) imp_sym,
1063
              imp_index);
1064
  }
1065
      else
1066
#endif
1067
#ifdef AMD64MAGIC
1068
      if (magic == AMD64MAGIC)
1069
  {
1070
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1071
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1072
              imp_index);
1073
  }
1074
      else
1075
#endif
1076
32
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1077
32
            BFD_RELOC_32, (asymbol **) imp_sym,
1078
32
            imp_index);
1079
1080
32
      pe_ILF_save_relocs (&vars, text);
1081
32
      break;
1082
1083
25
    case IMPORT_DATA:
1084
46
    case IMPORT_CONST:
1085
46
      break;
1086
1087
0
    default:
1088
      /* XXX code not yet written.  */
1089
0
      abort ();
1090
78
    }
1091
1092
  /* Now create a symbol describing the imported value.  */
1093
78
  switch (import_type)
1094
78
    {
1095
32
    case IMPORT_CODE:
1096
32
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1097
32
          BSF_NOT_AT_END | BSF_FUNCTION);
1098
1099
32
      break;
1100
1101
25
    case IMPORT_DATA:
1102
      /* Nothing to do here.  */
1103
25
      break;
1104
1105
21
    case IMPORT_CONST:
1106
21
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1107
21
      break;
1108
1109
0
    default:
1110
      /* XXX code not yet written.  */
1111
0
      abort ();
1112
78
    }
1113
1114
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1115
78
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1116
78
  if (ptr)
1117
16
    *ptr = 0;
1118
78
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1119
78
  if (ptr)
1120
16
    *ptr = '.';
1121
1122
  /* Initialise the bfd.  */
1123
78
  memset (&internal_f, 0, sizeof (internal_f));
1124
1125
78
  internal_f.f_magic  = magic;
1126
78
  internal_f.f_symptr = 0;
1127
78
  internal_f.f_nsyms  = 0;
1128
78
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1129
1130
78
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1131
78
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1132
0
    goto error_return;
1133
1134
78
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1135
0
    goto error_return;
1136
1137
78
  obj_pe (abfd) = true;
1138
#ifdef THUMBPEMAGIC
1139
  if (vars.magic == THUMBPEMAGIC)
1140
    /* Stop some linker warnings about thumb code not supporting
1141
       interworking.  */
1142
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1143
#endif
1144
1145
  /* Switch from file contents to memory contents.  */
1146
78
  bfd_cache_close (abfd);
1147
1148
78
  abfd->iostream = (void *) vars.bim;
1149
78
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1150
78
  abfd->iovec = &_bfd_memory_iovec;
1151
78
  abfd->where = 0;
1152
78
  abfd->origin = 0;
1153
78
  abfd->size = 0;
1154
78
  obj_sym_filepos (abfd) = 0;
1155
1156
  /* Point the bfd at the symbol table.  */
1157
78
  obj_symbols (abfd) = vars.sym_cache;
1158
78
  abfd->symcount = vars.sym_index;
1159
1160
78
  obj_raw_syments (abfd) = vars.native_syms;
1161
78
  obj_raw_syment_count (abfd) = vars.sym_index;
1162
78
  obj_coff_keep_raw_syms (abfd) = true;
1163
1164
78
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1165
78
  obj_coff_keep_syms (abfd) = true;
1166
1167
78
  obj_convert (abfd) = vars.sym_table;
1168
78
  obj_conv_table_size (abfd) = vars.sym_index;
1169
1170
78
  obj_coff_strings (abfd) = vars.string_table;
1171
78
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1172
78
  obj_coff_keep_strings (abfd) = true;
1173
1174
78
  return true;
1175
1176
5
 error_return:
1177
5
  free (vars.bim->buffer);
1178
5
  free (vars.bim);
1179
  return false;
1180
78
}
pei-riscv64.c:pe_ILF_build_a_bfd
Line
Count
Source
804
110
{
805
110
  bfd_byte *       ptr;
806
110
  pe_ILF_vars      vars;
807
110
  struct internal_filehdr  internal_f;
808
110
  unsigned int       import_type;
809
110
  unsigned int       import_name_type;
810
110
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
811
110
  coff_symbol_type **    imp_sym;
812
110
  unsigned int       imp_index;
813
110
  intptr_t alignment;
814
815
  /* Decode and verify the types field of the ILF structure.  */
816
110
  import_type = types & 0x3;
817
110
  import_name_type = (types & 0x1c) >> 2;
818
819
110
  switch (import_type)
820
110
    {
821
38
    case IMPORT_CODE:
822
63
    case IMPORT_DATA:
823
105
    case IMPORT_CONST:
824
105
      break;
825
826
5
    default:
827
      /* xgettext:c-format */
828
5
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
5
        abfd, import_type);
830
5
      return false;
831
110
    }
832
833
105
  switch (import_name_type)
834
105
    {
835
20
    case IMPORT_ORDINAL:
836
30
    case IMPORT_NAME:
837
53
    case IMPORT_NAME_NOPREFIX:
838
77
    case IMPORT_NAME_UNDECORATE:
839
77
      import_name = symbol_name;
840
77
      break;
841
842
22
    case IMPORT_NAME_EXPORTAS:
843
22
      if (!import_name || !import_name[0])
844
10
  {
845
10
    _bfd_error_handler (_("%pB: missing import name for "
846
10
        "IMPORT_NAME_EXPORTAS for %s"),
847
10
            abfd, symbol_name);
848
10
    return false;
849
10
  }
850
12
      break;
851
852
12
    default:
853
      /* xgettext:c-format */
854
6
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
855
6
        abfd, import_name_type);
856
6
      return false;
857
105
    }
858
859
  /* Initialise local variables.
860
861
     Note these are kept in a structure rather than being
862
     declared as statics since bfd frowns on global variables.
863
864
     We are going to construct the contents of the BFD in memory,
865
     so allocate all the space that we will need right now.  */
866
89
  vars.bim
867
89
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
868
89
  if (vars.bim == NULL)
869
0
    return false;
870
871
89
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
872
89
  vars.bim->buffer = ptr;
873
89
  vars.bim->size   = ILF_DATA_SIZE;
874
89
  if (ptr == NULL)
875
0
    goto error_return;
876
877
  /* Initialise the pointers to regions of the memory and the
878
     other contents of the pe_ILF_vars structure as well.  */
879
89
  vars.sym_cache = (coff_symbol_type *) ptr;
880
89
  vars.sym_ptr   = (coff_symbol_type *) ptr;
881
89
  vars.sym_index = 0;
882
89
  ptr += SIZEOF_ILF_SYMS;
883
884
89
  vars.sym_table = (unsigned int *) ptr;
885
89
  vars.table_ptr = (unsigned int *) ptr;
886
89
  ptr += SIZEOF_ILF_SYM_TABLE;
887
888
89
  vars.native_syms = (combined_entry_type *) ptr;
889
89
  vars.native_ptr  = (combined_entry_type *) ptr;
890
89
  ptr += SIZEOF_ILF_NATIVE_SYMS;
891
892
89
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
893
89
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
894
89
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
895
896
89
  vars.esym_table = (SYMENT *) ptr;
897
89
  vars.esym_ptr   = (SYMENT *) ptr;
898
89
  ptr += SIZEOF_ILF_EXT_SYMS;
899
900
89
  vars.reltab   = (arelent *) ptr;
901
89
  vars.relcount = 0;
902
89
  ptr += SIZEOF_ILF_RELOCS;
903
904
89
  vars.int_reltab  = (struct internal_reloc *) ptr;
905
89
  ptr += SIZEOF_ILF_INT_RELOCS;
906
907
89
  vars.string_table = (char *) ptr;
908
89
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
909
89
  ptr += SIZEOF_ILF_STRINGS;
910
89
  vars.end_string_ptr = (char *) ptr;
911
912
  /* The remaining space in bim->buffer is used
913
     by the pe_ILF_make_a_section() function.  */
914
915
  /* PR 18758: Make sure that the data area is sufficiently aligned for
916
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
917
     the test of GCC_VERSION.  For other compilers we assume 8 byte
918
     alignment.  */
919
89
#if GCC_VERSION >= 3000
920
89
  alignment = __alignof__ (struct coff_section_tdata);
921
#else
922
  alignment = 8;
923
#endif
924
89
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
925
926
89
  vars.data = ptr;
927
89
  vars.abfd = abfd;
928
89
  vars.sec_index = 0;
929
89
  vars.magic = magic;
930
931
  /* Create the initial .idata$<n> sections:
932
     [.idata$2:  Import Directory Table -- not needed]
933
     .idata$4:  Import Lookup Table
934
     .idata$5:  Import Address Table
935
936
     Note we do not create a .idata$3 section as this is
937
     created for us by the linker script.  */
938
89
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
939
89
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
940
89
  if (id4 == NULL || id5 == NULL)
941
0
    goto error_return;
942
943
  /* Fill in the contents of these sections.  */
944
89
  if (import_name_type == IMPORT_ORDINAL)
945
20
    {
946
20
      if (ordinal == 0)
947
  /* See PR 20907 for a reproducer.  */
948
4
  goto error_return;
949
950
16
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
951
16
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
952
16
      ((unsigned int *) id4->contents)[0] = ordinal;
953
16
      ((unsigned int *) id4->contents)[1] = 0x80000000;
954
16
      ((unsigned int *) id5->contents)[0] = ordinal;
955
16
      ((unsigned int *) id5->contents)[1] = 0x80000000;
956
#else
957
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
958
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
959
#endif
960
16
    }
961
69
  else
962
69
    {
963
69
      char *symbol;
964
69
      unsigned int len;
965
966
      /* Create .idata$6 - the Hint Name Table.  */
967
69
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
968
69
      if (id6 == NULL)
969
0
  goto error_return;
970
971
      /* If necessary, trim the import symbol name.  */
972
69
      symbol = import_name;
973
974
      /* As used by MS compiler, '_', '@', and '?' are alternative
975
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
976
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
977
   of these is used for a symbol.  We strip this leading char for
978
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
979
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
980
981
69
      if (import_name_type != IMPORT_NAME
982
59
    && import_name_type != IMPORT_NAME_EXPORTAS)
983
47
  {
984
47
    char c = symbol[0];
985
986
    /* Check that we don't remove for targets with empty
987
       USER_LABEL_PREFIX the leading underscore.  */
988
47
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
989
47
        || c == '@' || c == '?')
990
15
      symbol++;
991
47
  }
992
993
69
      len = strlen (symbol);
994
69
      if (import_name_type == IMPORT_NAME_UNDECORATE)
995
24
  {
996
    /* Truncate at the first '@'.  */
997
24
    char *at = strchr (symbol, '@');
998
999
24
    if (at != NULL)
1000
6
      len = at - symbol;
1001
24
  }
1002
1003
69
      id6->contents[0] = ordinal & 0xff;
1004
69
      id6->contents[1] = ordinal >> 8;
1005
1006
69
      memcpy ((char *) id6->contents + 2, symbol, len);
1007
69
      id6->contents[len + 2] = '\0';
1008
69
    }
1009
1010
85
  if (import_name_type != IMPORT_ORDINAL)
1011
69
    {
1012
69
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1013
69
      pe_ILF_save_relocs (&vars, id4);
1014
1015
69
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1016
69
      pe_ILF_save_relocs (&vars, id5);
1017
69
    }
1018
1019
  /* Create an import symbol.  */
1020
85
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1021
85
  imp_sym   = vars.sym_ptr_ptr - 1;
1022
85
  imp_index = vars.sym_index - 1;
1023
1024
  /* Create extra sections depending upon the type of import we are
1025
     dealing with.  */
1026
85
  switch (import_type)
1027
85
    {
1028
0
      int i;
1029
1030
27
    case IMPORT_CODE:
1031
      /* CODE functions are special, in that they get a trampoline that
1032
   jumps to the main import symbol.  Create a .text section to hold it.
1033
   First we need to look up its contents in the jump table.  */
1034
54
      for (i = NUM_ENTRIES (jtab); i--;)
1035
54
  {
1036
54
    if (jtab[i].size == 0)
1037
27
      continue;
1038
27
    if (jtab[i].magic == magic)
1039
27
      break;
1040
27
  }
1041
      /* If we did not find a matching entry something is wrong.  */
1042
27
      if (i < 0)
1043
0
  abort ();
1044
1045
      /* Create the .text section.  */
1046
27
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1047
27
      if (text == NULL)
1048
0
  goto error_return;
1049
1050
      /* Copy in the jump code.  */
1051
27
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1052
1053
      /* Create a reloc for the data in the text section.  */
1054
#ifdef MIPS_ARCH_MAGIC_WINCE
1055
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1056
  {
1057
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1058
              (struct bfd_symbol **) imp_sym,
1059
              imp_index);
1060
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1061
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1062
              (struct bfd_symbol **) imp_sym,
1063
              imp_index);
1064
  }
1065
      else
1066
#endif
1067
#ifdef AMD64MAGIC
1068
      if (magic == AMD64MAGIC)
1069
  {
1070
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1071
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1072
              imp_index);
1073
  }
1074
      else
1075
#endif
1076
27
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1077
27
            BFD_RELOC_32, (asymbol **) imp_sym,
1078
27
            imp_index);
1079
1080
27
      pe_ILF_save_relocs (&vars, text);
1081
27
      break;
1082
1083
20
    case IMPORT_DATA:
1084
58
    case IMPORT_CONST:
1085
58
      break;
1086
1087
0
    default:
1088
      /* XXX code not yet written.  */
1089
0
      abort ();
1090
85
    }
1091
1092
  /* Now create a symbol describing the imported value.  */
1093
85
  switch (import_type)
1094
85
    {
1095
27
    case IMPORT_CODE:
1096
27
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1097
27
          BSF_NOT_AT_END | BSF_FUNCTION);
1098
1099
27
      break;
1100
1101
20
    case IMPORT_DATA:
1102
      /* Nothing to do here.  */
1103
20
      break;
1104
1105
38
    case IMPORT_CONST:
1106
38
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1107
38
      break;
1108
1109
0
    default:
1110
      /* XXX code not yet written.  */
1111
0
      abort ();
1112
85
    }
1113
1114
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1115
85
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1116
85
  if (ptr)
1117
12
    *ptr = 0;
1118
85
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1119
85
  if (ptr)
1120
12
    *ptr = '.';
1121
1122
  /* Initialise the bfd.  */
1123
85
  memset (&internal_f, 0, sizeof (internal_f));
1124
1125
85
  internal_f.f_magic  = magic;
1126
85
  internal_f.f_symptr = 0;
1127
85
  internal_f.f_nsyms  = 0;
1128
85
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1129
1130
85
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1131
85
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1132
0
    goto error_return;
1133
1134
85
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1135
0
    goto error_return;
1136
1137
85
  obj_pe (abfd) = true;
1138
#ifdef THUMBPEMAGIC
1139
  if (vars.magic == THUMBPEMAGIC)
1140
    /* Stop some linker warnings about thumb code not supporting
1141
       interworking.  */
1142
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1143
#endif
1144
1145
  /* Switch from file contents to memory contents.  */
1146
85
  bfd_cache_close (abfd);
1147
1148
85
  abfd->iostream = (void *) vars.bim;
1149
85
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1150
85
  abfd->iovec = &_bfd_memory_iovec;
1151
85
  abfd->where = 0;
1152
85
  abfd->origin = 0;
1153
85
  abfd->size = 0;
1154
85
  obj_sym_filepos (abfd) = 0;
1155
1156
  /* Point the bfd at the symbol table.  */
1157
85
  obj_symbols (abfd) = vars.sym_cache;
1158
85
  abfd->symcount = vars.sym_index;
1159
1160
85
  obj_raw_syments (abfd) = vars.native_syms;
1161
85
  obj_raw_syment_count (abfd) = vars.sym_index;
1162
85
  obj_coff_keep_raw_syms (abfd) = true;
1163
1164
85
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1165
85
  obj_coff_keep_syms (abfd) = true;
1166
1167
85
  obj_convert (abfd) = vars.sym_table;
1168
85
  obj_conv_table_size (abfd) = vars.sym_index;
1169
1170
85
  obj_coff_strings (abfd) = vars.string_table;
1171
85
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1172
85
  obj_coff_keep_strings (abfd) = true;
1173
1174
85
  return true;
1175
1176
4
 error_return:
1177
4
  free (vars.bim->buffer);
1178
4
  free (vars.bim);
1179
  return false;
1180
85
}
pei-arm-wince.c:pe_ILF_build_a_bfd
Line
Count
Source
804
82
{
805
82
  bfd_byte *       ptr;
806
82
  pe_ILF_vars      vars;
807
82
  struct internal_filehdr  internal_f;
808
82
  unsigned int       import_type;
809
82
  unsigned int       import_name_type;
810
82
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
811
82
  coff_symbol_type **    imp_sym;
812
82
  unsigned int       imp_index;
813
82
  intptr_t alignment;
814
815
  /* Decode and verify the types field of the ILF structure.  */
816
82
  import_type = types & 0x3;
817
82
  import_name_type = (types & 0x1c) >> 2;
818
819
82
  switch (import_type)
820
82
    {
821
37
    case IMPORT_CODE:
822
59
    case IMPORT_DATA:
823
76
    case IMPORT_CONST:
824
76
      break;
825
826
6
    default:
827
      /* xgettext:c-format */
828
6
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
6
        abfd, import_type);
830
6
      return false;
831
82
    }
832
833
76
  switch (import_name_type)
834
76
    {
835
23
    case IMPORT_ORDINAL:
836
28
    case IMPORT_NAME:
837
38
    case IMPORT_NAME_NOPREFIX:
838
56
    case IMPORT_NAME_UNDECORATE:
839
56
      import_name = symbol_name;
840
56
      break;
841
842
14
    case IMPORT_NAME_EXPORTAS:
843
14
      if (!import_name || !import_name[0])
844
10
  {
845
10
    _bfd_error_handler (_("%pB: missing import name for "
846
10
        "IMPORT_NAME_EXPORTAS for %s"),
847
10
            abfd, symbol_name);
848
10
    return false;
849
10
  }
850
4
      break;
851
852
6
    default:
853
      /* xgettext:c-format */
854
6
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
855
6
        abfd, import_name_type);
856
6
      return false;
857
76
    }
858
859
  /* Initialise local variables.
860
861
     Note these are kept in a structure rather than being
862
     declared as statics since bfd frowns on global variables.
863
864
     We are going to construct the contents of the BFD in memory,
865
     so allocate all the space that we will need right now.  */
866
60
  vars.bim
867
60
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
868
60
  if (vars.bim == NULL)
869
0
    return false;
870
871
60
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
872
60
  vars.bim->buffer = ptr;
873
60
  vars.bim->size   = ILF_DATA_SIZE;
874
60
  if (ptr == NULL)
875
0
    goto error_return;
876
877
  /* Initialise the pointers to regions of the memory and the
878
     other contents of the pe_ILF_vars structure as well.  */
879
60
  vars.sym_cache = (coff_symbol_type *) ptr;
880
60
  vars.sym_ptr   = (coff_symbol_type *) ptr;
881
60
  vars.sym_index = 0;
882
60
  ptr += SIZEOF_ILF_SYMS;
883
884
60
  vars.sym_table = (unsigned int *) ptr;
885
60
  vars.table_ptr = (unsigned int *) ptr;
886
60
  ptr += SIZEOF_ILF_SYM_TABLE;
887
888
60
  vars.native_syms = (combined_entry_type *) ptr;
889
60
  vars.native_ptr  = (combined_entry_type *) ptr;
890
60
  ptr += SIZEOF_ILF_NATIVE_SYMS;
891
892
60
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
893
60
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
894
60
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
895
896
60
  vars.esym_table = (SYMENT *) ptr;
897
60
  vars.esym_ptr   = (SYMENT *) ptr;
898
60
  ptr += SIZEOF_ILF_EXT_SYMS;
899
900
60
  vars.reltab   = (arelent *) ptr;
901
60
  vars.relcount = 0;
902
60
  ptr += SIZEOF_ILF_RELOCS;
903
904
60
  vars.int_reltab  = (struct internal_reloc *) ptr;
905
60
  ptr += SIZEOF_ILF_INT_RELOCS;
906
907
60
  vars.string_table = (char *) ptr;
908
60
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
909
60
  ptr += SIZEOF_ILF_STRINGS;
910
60
  vars.end_string_ptr = (char *) ptr;
911
912
  /* The remaining space in bim->buffer is used
913
     by the pe_ILF_make_a_section() function.  */
914
915
  /* PR 18758: Make sure that the data area is sufficiently aligned for
916
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
917
     the test of GCC_VERSION.  For other compilers we assume 8 byte
918
     alignment.  */
919
60
#if GCC_VERSION >= 3000
920
60
  alignment = __alignof__ (struct coff_section_tdata);
921
#else
922
  alignment = 8;
923
#endif
924
60
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
925
926
60
  vars.data = ptr;
927
60
  vars.abfd = abfd;
928
60
  vars.sec_index = 0;
929
60
  vars.magic = magic;
930
931
  /* Create the initial .idata$<n> sections:
932
     [.idata$2:  Import Directory Table -- not needed]
933
     .idata$4:  Import Lookup Table
934
     .idata$5:  Import Address Table
935
936
     Note we do not create a .idata$3 section as this is
937
     created for us by the linker script.  */
938
60
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
939
60
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
940
60
  if (id4 == NULL || id5 == NULL)
941
0
    goto error_return;
942
943
  /* Fill in the contents of these sections.  */
944
60
  if (import_name_type == IMPORT_ORDINAL)
945
23
    {
946
23
      if (ordinal == 0)
947
  /* See PR 20907 for a reproducer.  */
948
8
  goto error_return;
949
950
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
951
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
952
      ((unsigned int *) id4->contents)[0] = ordinal;
953
      ((unsigned int *) id4->contents)[1] = 0x80000000;
954
      ((unsigned int *) id5->contents)[0] = ordinal;
955
      ((unsigned int *) id5->contents)[1] = 0x80000000;
956
#else
957
15
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
958
15
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
959
15
#endif
960
15
    }
961
37
  else
962
37
    {
963
37
      char *symbol;
964
37
      unsigned int len;
965
966
      /* Create .idata$6 - the Hint Name Table.  */
967
37
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
968
37
      if (id6 == NULL)
969
0
  goto error_return;
970
971
      /* If necessary, trim the import symbol name.  */
972
37
      symbol = import_name;
973
974
      /* As used by MS compiler, '_', '@', and '?' are alternative
975
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
976
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
977
   of these is used for a symbol.  We strip this leading char for
978
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
979
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
980
981
37
      if (import_name_type != IMPORT_NAME
982
32
    && import_name_type != IMPORT_NAME_EXPORTAS)
983
28
  {
984
28
    char c = symbol[0];
985
986
    /* Check that we don't remove for targets with empty
987
       USER_LABEL_PREFIX the leading underscore.  */
988
28
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
989
28
        || c == '@' || c == '?')
990
7
      symbol++;
991
28
  }
992
993
37
      len = strlen (symbol);
994
37
      if (import_name_type == IMPORT_NAME_UNDECORATE)
995
18
  {
996
    /* Truncate at the first '@'.  */
997
18
    char *at = strchr (symbol, '@');
998
999
18
    if (at != NULL)
1000
4
      len = at - symbol;
1001
18
  }
1002
1003
37
      id6->contents[0] = ordinal & 0xff;
1004
37
      id6->contents[1] = ordinal >> 8;
1005
1006
37
      memcpy ((char *) id6->contents + 2, symbol, len);
1007
37
      id6->contents[len + 2] = '\0';
1008
37
    }
1009
1010
52
  if (import_name_type != IMPORT_ORDINAL)
1011
37
    {
1012
37
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1013
37
      pe_ILF_save_relocs (&vars, id4);
1014
1015
37
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1016
37
      pe_ILF_save_relocs (&vars, id5);
1017
37
    }
1018
1019
  /* Create an import symbol.  */
1020
52
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1021
52
  imp_sym   = vars.sym_ptr_ptr - 1;
1022
52
  imp_index = vars.sym_index - 1;
1023
1024
  /* Create extra sections depending upon the type of import we are
1025
     dealing with.  */
1026
52
  switch (import_type)
1027
52
    {
1028
0
      int i;
1029
1030
22
    case IMPORT_CODE:
1031
      /* CODE functions are special, in that they get a trampoline that
1032
   jumps to the main import symbol.  Create a .text section to hold it.
1033
   First we need to look up its contents in the jump table.  */
1034
55
      for (i = NUM_ENTRIES (jtab); i--;)
1035
55
  {
1036
55
    if (jtab[i].size == 0)
1037
22
      continue;
1038
33
    if (jtab[i].magic == magic)
1039
22
      break;
1040
33
  }
1041
      /* If we did not find a matching entry something is wrong.  */
1042
22
      if (i < 0)
1043
0
  abort ();
1044
1045
      /* Create the .text section.  */
1046
22
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1047
22
      if (text == NULL)
1048
0
  goto error_return;
1049
1050
      /* Copy in the jump code.  */
1051
22
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1052
1053
      /* Create a reloc for the data in the text section.  */
1054
#ifdef MIPS_ARCH_MAGIC_WINCE
1055
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1056
  {
1057
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1058
              (struct bfd_symbol **) imp_sym,
1059
              imp_index);
1060
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1061
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1062
              (struct bfd_symbol **) imp_sym,
1063
              imp_index);
1064
  }
1065
      else
1066
#endif
1067
#ifdef AMD64MAGIC
1068
      if (magic == AMD64MAGIC)
1069
  {
1070
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1071
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1072
              imp_index);
1073
  }
1074
      else
1075
#endif
1076
22
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1077
22
            BFD_RELOC_32, (asymbol **) imp_sym,
1078
22
            imp_index);
1079
1080
22
      pe_ILF_save_relocs (&vars, text);
1081
22
      break;
1082
1083
17
    case IMPORT_DATA:
1084
30
    case IMPORT_CONST:
1085
30
      break;
1086
1087
0
    default:
1088
      /* XXX code not yet written.  */
1089
0
      abort ();
1090
52
    }
1091
1092
  /* Now create a symbol describing the imported value.  */
1093
52
  switch (import_type)
1094
52
    {
1095
22
    case IMPORT_CODE:
1096
22
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1097
22
          BSF_NOT_AT_END | BSF_FUNCTION);
1098
1099
22
      break;
1100
1101
17
    case IMPORT_DATA:
1102
      /* Nothing to do here.  */
1103
17
      break;
1104
1105
13
    case IMPORT_CONST:
1106
13
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1107
13
      break;
1108
1109
0
    default:
1110
      /* XXX code not yet written.  */
1111
0
      abort ();
1112
52
    }
1113
1114
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1115
52
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1116
52
  if (ptr)
1117
5
    *ptr = 0;
1118
52
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1119
52
  if (ptr)
1120
5
    *ptr = '.';
1121
1122
  /* Initialise the bfd.  */
1123
52
  memset (&internal_f, 0, sizeof (internal_f));
1124
1125
52
  internal_f.f_magic  = magic;
1126
52
  internal_f.f_symptr = 0;
1127
52
  internal_f.f_nsyms  = 0;
1128
52
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1129
1130
52
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1131
52
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1132
0
    goto error_return;
1133
1134
52
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1135
0
    goto error_return;
1136
1137
52
  obj_pe (abfd) = true;
1138
52
#ifdef THUMBPEMAGIC
1139
52
  if (vars.magic == THUMBPEMAGIC)
1140
    /* Stop some linker warnings about thumb code not supporting
1141
       interworking.  */
1142
23
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1143
52
#endif
1144
1145
  /* Switch from file contents to memory contents.  */
1146
52
  bfd_cache_close (abfd);
1147
1148
52
  abfd->iostream = (void *) vars.bim;
1149
52
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1150
52
  abfd->iovec = &_bfd_memory_iovec;
1151
52
  abfd->where = 0;
1152
52
  abfd->origin = 0;
1153
52
  abfd->size = 0;
1154
52
  obj_sym_filepos (abfd) = 0;
1155
1156
  /* Point the bfd at the symbol table.  */
1157
52
  obj_symbols (abfd) = vars.sym_cache;
1158
52
  abfd->symcount = vars.sym_index;
1159
1160
52
  obj_raw_syments (abfd) = vars.native_syms;
1161
52
  obj_raw_syment_count (abfd) = vars.sym_index;
1162
52
  obj_coff_keep_raw_syms (abfd) = true;
1163
1164
52
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1165
52
  obj_coff_keep_syms (abfd) = true;
1166
1167
52
  obj_convert (abfd) = vars.sym_table;
1168
52
  obj_conv_table_size (abfd) = vars.sym_index;
1169
1170
52
  obj_coff_strings (abfd) = vars.string_table;
1171
52
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1172
52
  obj_coff_keep_strings (abfd) = true;
1173
1174
52
  return true;
1175
1176
8
 error_return:
1177
8
  free (vars.bim->buffer);
1178
8
  free (vars.bim);
1179
  return false;
1180
52
}
pei-arm.c:pe_ILF_build_a_bfd
Line
Count
Source
804
84
{
805
84
  bfd_byte *       ptr;
806
84
  pe_ILF_vars      vars;
807
84
  struct internal_filehdr  internal_f;
808
84
  unsigned int       import_type;
809
84
  unsigned int       import_name_type;
810
84
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
811
84
  coff_symbol_type **    imp_sym;
812
84
  unsigned int       imp_index;
813
84
  intptr_t alignment;
814
815
  /* Decode and verify the types field of the ILF structure.  */
816
84
  import_type = types & 0x3;
817
84
  import_name_type = (types & 0x1c) >> 2;
818
819
84
  switch (import_type)
820
84
    {
821
38
    case IMPORT_CODE:
822
60
    case IMPORT_DATA:
823
78
    case IMPORT_CONST:
824
78
      break;
825
826
6
    default:
827
      /* xgettext:c-format */
828
6
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
6
        abfd, import_type);
830
6
      return false;
831
84
    }
832
833
78
  switch (import_name_type)
834
78
    {
835
24
    case IMPORT_ORDINAL:
836
29
    case IMPORT_NAME:
837
40
    case IMPORT_NAME_NOPREFIX:
838
58
    case IMPORT_NAME_UNDECORATE:
839
58
      import_name = symbol_name;
840
58
      break;
841
842
14
    case IMPORT_NAME_EXPORTAS:
843
14
      if (!import_name || !import_name[0])
844
10
  {
845
10
    _bfd_error_handler (_("%pB: missing import name for "
846
10
        "IMPORT_NAME_EXPORTAS for %s"),
847
10
            abfd, symbol_name);
848
10
    return false;
849
10
  }
850
4
      break;
851
852
6
    default:
853
      /* xgettext:c-format */
854
6
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
855
6
        abfd, import_name_type);
856
6
      return false;
857
78
    }
858
859
  /* Initialise local variables.
860
861
     Note these are kept in a structure rather than being
862
     declared as statics since bfd frowns on global variables.
863
864
     We are going to construct the contents of the BFD in memory,
865
     so allocate all the space that we will need right now.  */
866
62
  vars.bim
867
62
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
868
62
  if (vars.bim == NULL)
869
0
    return false;
870
871
62
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
872
62
  vars.bim->buffer = ptr;
873
62
  vars.bim->size   = ILF_DATA_SIZE;
874
62
  if (ptr == NULL)
875
0
    goto error_return;
876
877
  /* Initialise the pointers to regions of the memory and the
878
     other contents of the pe_ILF_vars structure as well.  */
879
62
  vars.sym_cache = (coff_symbol_type *) ptr;
880
62
  vars.sym_ptr   = (coff_symbol_type *) ptr;
881
62
  vars.sym_index = 0;
882
62
  ptr += SIZEOF_ILF_SYMS;
883
884
62
  vars.sym_table = (unsigned int *) ptr;
885
62
  vars.table_ptr = (unsigned int *) ptr;
886
62
  ptr += SIZEOF_ILF_SYM_TABLE;
887
888
62
  vars.native_syms = (combined_entry_type *) ptr;
889
62
  vars.native_ptr  = (combined_entry_type *) ptr;
890
62
  ptr += SIZEOF_ILF_NATIVE_SYMS;
891
892
62
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
893
62
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
894
62
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
895
896
62
  vars.esym_table = (SYMENT *) ptr;
897
62
  vars.esym_ptr   = (SYMENT *) ptr;
898
62
  ptr += SIZEOF_ILF_EXT_SYMS;
899
900
62
  vars.reltab   = (arelent *) ptr;
901
62
  vars.relcount = 0;
902
62
  ptr += SIZEOF_ILF_RELOCS;
903
904
62
  vars.int_reltab  = (struct internal_reloc *) ptr;
905
62
  ptr += SIZEOF_ILF_INT_RELOCS;
906
907
62
  vars.string_table = (char *) ptr;
908
62
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
909
62
  ptr += SIZEOF_ILF_STRINGS;
910
62
  vars.end_string_ptr = (char *) ptr;
911
912
  /* The remaining space in bim->buffer is used
913
     by the pe_ILF_make_a_section() function.  */
914
915
  /* PR 18758: Make sure that the data area is sufficiently aligned for
916
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
917
     the test of GCC_VERSION.  For other compilers we assume 8 byte
918
     alignment.  */
919
62
#if GCC_VERSION >= 3000
920
62
  alignment = __alignof__ (struct coff_section_tdata);
921
#else
922
  alignment = 8;
923
#endif
924
62
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
925
926
62
  vars.data = ptr;
927
62
  vars.abfd = abfd;
928
62
  vars.sec_index = 0;
929
62
  vars.magic = magic;
930
931
  /* Create the initial .idata$<n> sections:
932
     [.idata$2:  Import Directory Table -- not needed]
933
     .idata$4:  Import Lookup Table
934
     .idata$5:  Import Address Table
935
936
     Note we do not create a .idata$3 section as this is
937
     created for us by the linker script.  */
938
62
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
939
62
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
940
62
  if (id4 == NULL || id5 == NULL)
941
0
    goto error_return;
942
943
  /* Fill in the contents of these sections.  */
944
62
  if (import_name_type == IMPORT_ORDINAL)
945
24
    {
946
24
      if (ordinal == 0)
947
  /* See PR 20907 for a reproducer.  */
948
8
  goto error_return;
949
950
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
951
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
952
      ((unsigned int *) id4->contents)[0] = ordinal;
953
      ((unsigned int *) id4->contents)[1] = 0x80000000;
954
      ((unsigned int *) id5->contents)[0] = ordinal;
955
      ((unsigned int *) id5->contents)[1] = 0x80000000;
956
#else
957
16
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
958
16
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
959
16
#endif
960
16
    }
961
38
  else
962
38
    {
963
38
      char *symbol;
964
38
      unsigned int len;
965
966
      /* Create .idata$6 - the Hint Name Table.  */
967
38
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
968
38
      if (id6 == NULL)
969
0
  goto error_return;
970
971
      /* If necessary, trim the import symbol name.  */
972
38
      symbol = import_name;
973
974
      /* As used by MS compiler, '_', '@', and '?' are alternative
975
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
976
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
977
   of these is used for a symbol.  We strip this leading char for
978
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
979
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
980
981
38
      if (import_name_type != IMPORT_NAME
982
33
    && import_name_type != IMPORT_NAME_EXPORTAS)
983
29
  {
984
29
    char c = symbol[0];
985
986
    /* Check that we don't remove for targets with empty
987
       USER_LABEL_PREFIX the leading underscore.  */
988
29
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
989
24
        || c == '@' || c == '?')
990
12
      symbol++;
991
29
  }
992
993
38
      len = strlen (symbol);
994
38
      if (import_name_type == IMPORT_NAME_UNDECORATE)
995
18
  {
996
    /* Truncate at the first '@'.  */
997
18
    char *at = strchr (symbol, '@');
998
999
18
    if (at != NULL)
1000
4
      len = at - symbol;
1001
18
  }
1002
1003
38
      id6->contents[0] = ordinal & 0xff;
1004
38
      id6->contents[1] = ordinal >> 8;
1005
1006
38
      memcpy ((char *) id6->contents + 2, symbol, len);
1007
38
      id6->contents[len + 2] = '\0';
1008
38
    }
1009
1010
54
  if (import_name_type != IMPORT_ORDINAL)
1011
38
    {
1012
38
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1013
38
      pe_ILF_save_relocs (&vars, id4);
1014
1015
38
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1016
38
      pe_ILF_save_relocs (&vars, id5);
1017
38
    }
1018
1019
  /* Create an import symbol.  */
1020
54
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1021
54
  imp_sym   = vars.sym_ptr_ptr - 1;
1022
54
  imp_index = vars.sym_index - 1;
1023
1024
  /* Create extra sections depending upon the type of import we are
1025
     dealing with.  */
1026
54
  switch (import_type)
1027
54
    {
1028
0
      int i;
1029
1030
23
    case IMPORT_CODE:
1031
      /* CODE functions are special, in that they get a trampoline that
1032
   jumps to the main import symbol.  Create a .text section to hold it.
1033
   First we need to look up its contents in the jump table.  */
1034
58
      for (i = NUM_ENTRIES (jtab); i--;)
1035
58
  {
1036
58
    if (jtab[i].size == 0)
1037
23
      continue;
1038
35
    if (jtab[i].magic == magic)
1039
23
      break;
1040
35
  }
1041
      /* If we did not find a matching entry something is wrong.  */
1042
23
      if (i < 0)
1043
0
  abort ();
1044
1045
      /* Create the .text section.  */
1046
23
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1047
23
      if (text == NULL)
1048
0
  goto error_return;
1049
1050
      /* Copy in the jump code.  */
1051
23
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1052
1053
      /* Create a reloc for the data in the text section.  */
1054
#ifdef MIPS_ARCH_MAGIC_WINCE
1055
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1056
  {
1057
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1058
              (struct bfd_symbol **) imp_sym,
1059
              imp_index);
1060
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1061
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1062
              (struct bfd_symbol **) imp_sym,
1063
              imp_index);
1064
  }
1065
      else
1066
#endif
1067
#ifdef AMD64MAGIC
1068
      if (magic == AMD64MAGIC)
1069
  {
1070
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1071
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1072
              imp_index);
1073
  }
1074
      else
1075
#endif
1076
23
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1077
23
            BFD_RELOC_32, (asymbol **) imp_sym,
1078
23
            imp_index);
1079
1080
23
      pe_ILF_save_relocs (&vars, text);
1081
23
      break;
1082
1083
17
    case IMPORT_DATA:
1084
31
    case IMPORT_CONST:
1085
31
      break;
1086
1087
0
    default:
1088
      /* XXX code not yet written.  */
1089
0
      abort ();
1090
54
    }
1091
1092
  /* Now create a symbol describing the imported value.  */
1093
54
  switch (import_type)
1094
54
    {
1095
23
    case IMPORT_CODE:
1096
23
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1097
23
          BSF_NOT_AT_END | BSF_FUNCTION);
1098
1099
23
      break;
1100
1101
17
    case IMPORT_DATA:
1102
      /* Nothing to do here.  */
1103
17
      break;
1104
1105
14
    case IMPORT_CONST:
1106
14
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1107
14
      break;
1108
1109
0
    default:
1110
      /* XXX code not yet written.  */
1111
0
      abort ();
1112
54
    }
1113
1114
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1115
54
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1116
54
  if (ptr)
1117
5
    *ptr = 0;
1118
54
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1119
54
  if (ptr)
1120
5
    *ptr = '.';
1121
1122
  /* Initialise the bfd.  */
1123
54
  memset (&internal_f, 0, sizeof (internal_f));
1124
1125
54
  internal_f.f_magic  = magic;
1126
54
  internal_f.f_symptr = 0;
1127
54
  internal_f.f_nsyms  = 0;
1128
54
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1129
1130
54
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1131
54
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1132
0
    goto error_return;
1133
1134
54
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1135
0
    goto error_return;
1136
1137
54
  obj_pe (abfd) = true;
1138
54
#ifdef THUMBPEMAGIC
1139
54
  if (vars.magic == THUMBPEMAGIC)
1140
    /* Stop some linker warnings about thumb code not supporting
1141
       interworking.  */
1142
23
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1143
54
#endif
1144
1145
  /* Switch from file contents to memory contents.  */
1146
54
  bfd_cache_close (abfd);
1147
1148
54
  abfd->iostream = (void *) vars.bim;
1149
54
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1150
54
  abfd->iovec = &_bfd_memory_iovec;
1151
54
  abfd->where = 0;
1152
54
  abfd->origin = 0;
1153
54
  abfd->size = 0;
1154
54
  obj_sym_filepos (abfd) = 0;
1155
1156
  /* Point the bfd at the symbol table.  */
1157
54
  obj_symbols (abfd) = vars.sym_cache;
1158
54
  abfd->symcount = vars.sym_index;
1159
1160
54
  obj_raw_syments (abfd) = vars.native_syms;
1161
54
  obj_raw_syment_count (abfd) = vars.sym_index;
1162
54
  obj_coff_keep_raw_syms (abfd) = true;
1163
1164
54
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1165
54
  obj_coff_keep_syms (abfd) = true;
1166
1167
54
  obj_convert (abfd) = vars.sym_table;
1168
54
  obj_conv_table_size (abfd) = vars.sym_index;
1169
1170
54
  obj_coff_strings (abfd) = vars.string_table;
1171
54
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1172
54
  obj_coff_keep_strings (abfd) = true;
1173
1174
54
  return true;
1175
1176
8
 error_return:
1177
8
  free (vars.bim->buffer);
1178
8
  free (vars.bim);
1179
  return false;
1180
54
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_build_a_bfd
pei-sh.c:pe_ILF_build_a_bfd
Line
Count
Source
804
114
{
805
114
  bfd_byte *       ptr;
806
114
  pe_ILF_vars      vars;
807
114
  struct internal_filehdr  internal_f;
808
114
  unsigned int       import_type;
809
114
  unsigned int       import_name_type;
810
114
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
811
114
  coff_symbol_type **    imp_sym;
812
114
  unsigned int       imp_index;
813
114
  intptr_t alignment;
814
815
  /* Decode and verify the types field of the ILF structure.  */
816
114
  import_type = types & 0x3;
817
114
  import_name_type = (types & 0x1c) >> 2;
818
819
114
  switch (import_type)
820
114
    {
821
43
    case IMPORT_CODE:
822
73
    case IMPORT_DATA:
823
105
    case IMPORT_CONST:
824
105
      break;
825
826
9
    default:
827
      /* xgettext:c-format */
828
9
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
9
        abfd, import_type);
830
9
      return false;
831
114
    }
832
833
105
  switch (import_name_type)
834
105
    {
835
27
    case IMPORT_ORDINAL:
836
35
    case IMPORT_NAME:
837
58
    case IMPORT_NAME_NOPREFIX:
838
82
    case IMPORT_NAME_UNDECORATE:
839
82
      import_name = symbol_name;
840
82
      break;
841
842
18
    case IMPORT_NAME_EXPORTAS:
843
18
      if (!import_name || !import_name[0])
844
10
  {
845
10
    _bfd_error_handler (_("%pB: missing import name for "
846
10
        "IMPORT_NAME_EXPORTAS for %s"),
847
10
            abfd, symbol_name);
848
10
    return false;
849
10
  }
850
8
      break;
851
852
8
    default:
853
      /* xgettext:c-format */
854
5
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
855
5
        abfd, import_name_type);
856
5
      return false;
857
105
    }
858
859
  /* Initialise local variables.
860
861
     Note these are kept in a structure rather than being
862
     declared as statics since bfd frowns on global variables.
863
864
     We are going to construct the contents of the BFD in memory,
865
     so allocate all the space that we will need right now.  */
866
90
  vars.bim
867
90
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
868
90
  if (vars.bim == NULL)
869
0
    return false;
870
871
90
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
872
90
  vars.bim->buffer = ptr;
873
90
  vars.bim->size   = ILF_DATA_SIZE;
874
90
  if (ptr == NULL)
875
0
    goto error_return;
876
877
  /* Initialise the pointers to regions of the memory and the
878
     other contents of the pe_ILF_vars structure as well.  */
879
90
  vars.sym_cache = (coff_symbol_type *) ptr;
880
90
  vars.sym_ptr   = (coff_symbol_type *) ptr;
881
90
  vars.sym_index = 0;
882
90
  ptr += SIZEOF_ILF_SYMS;
883
884
90
  vars.sym_table = (unsigned int *) ptr;
885
90
  vars.table_ptr = (unsigned int *) ptr;
886
90
  ptr += SIZEOF_ILF_SYM_TABLE;
887
888
90
  vars.native_syms = (combined_entry_type *) ptr;
889
90
  vars.native_ptr  = (combined_entry_type *) ptr;
890
90
  ptr += SIZEOF_ILF_NATIVE_SYMS;
891
892
90
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
893
90
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
894
90
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
895
896
90
  vars.esym_table = (SYMENT *) ptr;
897
90
  vars.esym_ptr   = (SYMENT *) ptr;
898
90
  ptr += SIZEOF_ILF_EXT_SYMS;
899
900
90
  vars.reltab   = (arelent *) ptr;
901
90
  vars.relcount = 0;
902
90
  ptr += SIZEOF_ILF_RELOCS;
903
904
90
  vars.int_reltab  = (struct internal_reloc *) ptr;
905
90
  ptr += SIZEOF_ILF_INT_RELOCS;
906
907
90
  vars.string_table = (char *) ptr;
908
90
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
909
90
  ptr += SIZEOF_ILF_STRINGS;
910
90
  vars.end_string_ptr = (char *) ptr;
911
912
  /* The remaining space in bim->buffer is used
913
     by the pe_ILF_make_a_section() function.  */
914
915
  /* PR 18758: Make sure that the data area is sufficiently aligned for
916
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
917
     the test of GCC_VERSION.  For other compilers we assume 8 byte
918
     alignment.  */
919
90
#if GCC_VERSION >= 3000
920
90
  alignment = __alignof__ (struct coff_section_tdata);
921
#else
922
  alignment = 8;
923
#endif
924
90
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
925
926
90
  vars.data = ptr;
927
90
  vars.abfd = abfd;
928
90
  vars.sec_index = 0;
929
90
  vars.magic = magic;
930
931
  /* Create the initial .idata$<n> sections:
932
     [.idata$2:  Import Directory Table -- not needed]
933
     .idata$4:  Import Lookup Table
934
     .idata$5:  Import Address Table
935
936
     Note we do not create a .idata$3 section as this is
937
     created for us by the linker script.  */
938
90
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
939
90
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
940
90
  if (id4 == NULL || id5 == NULL)
941
0
    goto error_return;
942
943
  /* Fill in the contents of these sections.  */
944
90
  if (import_name_type == IMPORT_ORDINAL)
945
27
    {
946
27
      if (ordinal == 0)
947
  /* See PR 20907 for a reproducer.  */
948
5
  goto error_return;
949
950
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
951
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
952
      ((unsigned int *) id4->contents)[0] = ordinal;
953
      ((unsigned int *) id4->contents)[1] = 0x80000000;
954
      ((unsigned int *) id5->contents)[0] = ordinal;
955
      ((unsigned int *) id5->contents)[1] = 0x80000000;
956
#else
957
22
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
958
22
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
959
22
#endif
960
22
    }
961
63
  else
962
63
    {
963
63
      char *symbol;
964
63
      unsigned int len;
965
966
      /* Create .idata$6 - the Hint Name Table.  */
967
63
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
968
63
      if (id6 == NULL)
969
0
  goto error_return;
970
971
      /* If necessary, trim the import symbol name.  */
972
63
      symbol = import_name;
973
974
      /* As used by MS compiler, '_', '@', and '?' are alternative
975
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
976
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
977
   of these is used for a symbol.  We strip this leading char for
978
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
979
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
980
981
63
      if (import_name_type != IMPORT_NAME
982
55
    && import_name_type != IMPORT_NAME_EXPORTAS)
983
47
  {
984
47
    char c = symbol[0];
985
986
    /* Check that we don't remove for targets with empty
987
       USER_LABEL_PREFIX the leading underscore.  */
988
47
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
989
39
        || c == '@' || c == '?')
990
24
      symbol++;
991
47
  }
992
993
63
      len = strlen (symbol);
994
63
      if (import_name_type == IMPORT_NAME_UNDECORATE)
995
24
  {
996
    /* Truncate at the first '@'.  */
997
24
    char *at = strchr (symbol, '@');
998
999
24
    if (at != NULL)
1000
6
      len = at - symbol;
1001
24
  }
1002
1003
63
      id6->contents[0] = ordinal & 0xff;
1004
63
      id6->contents[1] = ordinal >> 8;
1005
1006
63
      memcpy ((char *) id6->contents + 2, symbol, len);
1007
63
      id6->contents[len + 2] = '\0';
1008
63
    }
1009
1010
85
  if (import_name_type != IMPORT_ORDINAL)
1011
63
    {
1012
63
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1013
63
      pe_ILF_save_relocs (&vars, id4);
1014
1015
63
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1016
63
      pe_ILF_save_relocs (&vars, id5);
1017
63
    }
1018
1019
  /* Create an import symbol.  */
1020
85
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1021
85
  imp_sym   = vars.sym_ptr_ptr - 1;
1022
85
  imp_index = vars.sym_index - 1;
1023
1024
  /* Create extra sections depending upon the type of import we are
1025
     dealing with.  */
1026
85
  switch (import_type)
1027
85
    {
1028
0
      int i;
1029
1030
28
    case IMPORT_CODE:
1031
      /* CODE functions are special, in that they get a trampoline that
1032
   jumps to the main import symbol.  Create a .text section to hold it.
1033
   First we need to look up its contents in the jump table.  */
1034
56
      for (i = NUM_ENTRIES (jtab); i--;)
1035
56
  {
1036
56
    if (jtab[i].size == 0)
1037
28
      continue;
1038
28
    if (jtab[i].magic == magic)
1039
28
      break;
1040
28
  }
1041
      /* If we did not find a matching entry something is wrong.  */
1042
28
      if (i < 0)
1043
0
  abort ();
1044
1045
      /* Create the .text section.  */
1046
28
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1047
28
      if (text == NULL)
1048
0
  goto error_return;
1049
1050
      /* Copy in the jump code.  */
1051
28
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1052
1053
      /* Create a reloc for the data in the text section.  */
1054
#ifdef MIPS_ARCH_MAGIC_WINCE
1055
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1056
  {
1057
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1058
              (struct bfd_symbol **) imp_sym,
1059
              imp_index);
1060
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1061
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1062
              (struct bfd_symbol **) imp_sym,
1063
              imp_index);
1064
  }
1065
      else
1066
#endif
1067
#ifdef AMD64MAGIC
1068
      if (magic == AMD64MAGIC)
1069
  {
1070
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1071
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1072
              imp_index);
1073
  }
1074
      else
1075
#endif
1076
28
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1077
28
            BFD_RELOC_32, (asymbol **) imp_sym,
1078
28
            imp_index);
1079
1080
28
      pe_ILF_save_relocs (&vars, text);
1081
28
      break;
1082
1083
28
    case IMPORT_DATA:
1084
57
    case IMPORT_CONST:
1085
57
      break;
1086
1087
0
    default:
1088
      /* XXX code not yet written.  */
1089
0
      abort ();
1090
85
    }
1091
1092
  /* Now create a symbol describing the imported value.  */
1093
85
  switch (import_type)
1094
85
    {
1095
28
    case IMPORT_CODE:
1096
28
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1097
28
          BSF_NOT_AT_END | BSF_FUNCTION);
1098
1099
28
      break;
1100
1101
28
    case IMPORT_DATA:
1102
      /* Nothing to do here.  */
1103
28
      break;
1104
1105
29
    case IMPORT_CONST:
1106
29
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1107
29
      break;
1108
1109
0
    default:
1110
      /* XXX code not yet written.  */
1111
0
      abort ();
1112
85
    }
1113
1114
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1115
85
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1116
85
  if (ptr)
1117
11
    *ptr = 0;
1118
85
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1119
85
  if (ptr)
1120
11
    *ptr = '.';
1121
1122
  /* Initialise the bfd.  */
1123
85
  memset (&internal_f, 0, sizeof (internal_f));
1124
1125
85
  internal_f.f_magic  = magic;
1126
85
  internal_f.f_symptr = 0;
1127
85
  internal_f.f_nsyms  = 0;
1128
85
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1129
1130
85
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1131
85
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1132
0
    goto error_return;
1133
1134
85
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1135
0
    goto error_return;
1136
1137
85
  obj_pe (abfd) = true;
1138
#ifdef THUMBPEMAGIC
1139
  if (vars.magic == THUMBPEMAGIC)
1140
    /* Stop some linker warnings about thumb code not supporting
1141
       interworking.  */
1142
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1143
#endif
1144
1145
  /* Switch from file contents to memory contents.  */
1146
85
  bfd_cache_close (abfd);
1147
1148
85
  abfd->iostream = (void *) vars.bim;
1149
85
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1150
85
  abfd->iovec = &_bfd_memory_iovec;
1151
85
  abfd->where = 0;
1152
85
  abfd->origin = 0;
1153
85
  abfd->size = 0;
1154
85
  obj_sym_filepos (abfd) = 0;
1155
1156
  /* Point the bfd at the symbol table.  */
1157
85
  obj_symbols (abfd) = vars.sym_cache;
1158
85
  abfd->symcount = vars.sym_index;
1159
1160
85
  obj_raw_syments (abfd) = vars.native_syms;
1161
85
  obj_raw_syment_count (abfd) = vars.sym_index;
1162
85
  obj_coff_keep_raw_syms (abfd) = true;
1163
1164
85
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1165
85
  obj_coff_keep_syms (abfd) = true;
1166
1167
85
  obj_convert (abfd) = vars.sym_table;
1168
85
  obj_conv_table_size (abfd) = vars.sym_index;
1169
1170
85
  obj_coff_strings (abfd) = vars.string_table;
1171
85
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1172
85
  obj_coff_keep_strings (abfd) = true;
1173
1174
85
  return true;
1175
1176
5
 error_return:
1177
5
  free (vars.bim->buffer);
1178
5
  free (vars.bim);
1179
  return false;
1180
85
}
1181
1182
/* Cleanup function, returned from check_format hook.  */
1183
1184
static void
1185
pe_ILF_cleanup (bfd *abfd)
1186
20
{
1187
20
  coff_object_cleanup (abfd);
1188
1189
20
  struct bfd_in_memory *bim = abfd->iostream;
1190
20
  free (bim->buffer);
1191
20
  free (bim);
1192
20
  abfd->iostream = NULL;
1193
20
}
Unexecuted instantiation: pei-i386.c:pe_ILF_cleanup
Unexecuted instantiation: pei-x86_64.c:pe_ILF_cleanup
Unexecuted instantiation: pei-aarch64.c:pe_ILF_cleanup
Unexecuted instantiation: pei-ia64.c:pe_ILF_cleanup
Unexecuted instantiation: pei-loongarch64.c:pe_ILF_cleanup
Unexecuted instantiation: pei-riscv64.c:pe_ILF_cleanup
pei-arm-wince.c:pe_ILF_cleanup
Line
Count
Source
1186
10
{
1187
10
  coff_object_cleanup (abfd);
1188
1189
10
  struct bfd_in_memory *bim = abfd->iostream;
1190
10
  free (bim->buffer);
1191
10
  free (bim);
1192
  abfd->iostream = NULL;
1193
10
}
pei-arm.c:pe_ILF_cleanup
Line
Count
Source
1186
10
{
1187
10
  coff_object_cleanup (abfd);
1188
1189
10
  struct bfd_in_memory *bim = abfd->iostream;
1190
10
  free (bim->buffer);
1191
10
  free (bim);
1192
  abfd->iostream = NULL;
1193
10
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_cleanup
Unexecuted instantiation: pei-sh.c:pe_ILF_cleanup
1194
1195
/* We have detected an Import Library Format archive element.
1196
   Decode the element and return the appropriate target.  */
1197
1198
static bfd_cleanup
1199
pe_ILF_object_p (bfd *abfd)
1200
18.2k
{
1201
18.2k
  bfd_byte    buffer[14];
1202
18.2k
  bfd_byte *    ptr;
1203
18.2k
  char *    symbol_name;
1204
18.2k
  char *    source_dll;
1205
18.2k
  char *    import_name;
1206
18.2k
  unsigned int    machine;
1207
18.2k
  bfd_size_type   size;
1208
18.2k
  unsigned int    ordinal;
1209
18.2k
  unsigned int    types;
1210
18.2k
  unsigned int    magic;
1211
1212
  /* Upon entry the first six bytes of the ILF header have
1213
     already been read.  Now read the rest of the header.  */
1214
18.2k
  if (bfd_read (buffer, 14, abfd) != 14)
1215
260
    return NULL;
1216
1217
17.9k
  ptr = buffer;
1218
1219
17.9k
  machine = H_GET_16 (abfd, ptr);
1220
17.9k
  ptr += 2;
1221
1222
  /* Check that the machine type is recognised.  */
1223
17.9k
  magic = 0;
1224
1225
17.9k
  switch (machine)
1226
17.9k
    {
1227
71
    case IMAGE_FILE_MACHINE_UNKNOWN:
1228
130
    case IMAGE_FILE_MACHINE_ALPHA:
1229
180
    case IMAGE_FILE_MACHINE_ALPHA64:
1230
230
    case IMAGE_FILE_MACHINE_IA64:
1231
230
      break;
1232
1233
1.93k
    case IMAGE_FILE_MACHINE_I386:
1234
#ifdef I386MAGIC
1235
269
      magic = I386MAGIC;
1236
#endif
1237
1.93k
      break;
1238
1239
1.83k
    case IMAGE_FILE_MACHINE_AMD64:
1240
#ifdef AMD64MAGIC
1241
252
      magic = AMD64MAGIC;
1242
#endif
1243
1.83k
      break;
1244
1245
36
    case IMAGE_FILE_MACHINE_R3000:
1246
86
    case IMAGE_FILE_MACHINE_R4000:
1247
127
    case IMAGE_FILE_MACHINE_R10000:
1248
1249
168
    case IMAGE_FILE_MACHINE_MIPS16:
1250
227
    case IMAGE_FILE_MACHINE_MIPSFPU:
1251
277
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1252
#ifdef MIPS_ARCH_MAGIC_WINCE
1253
      magic = MIPS_ARCH_MAGIC_WINCE;
1254
#endif
1255
277
      break;
1256
1257
734
    case IMAGE_FILE_MACHINE_SH3:
1258
1.79k
    case IMAGE_FILE_MACHINE_SH4:
1259
#ifdef SH_ARCH_MAGIC_WINCE
1260
217
      magic = SH_ARCH_MAGIC_WINCE;
1261
#endif
1262
1.79k
      break;
1263
1264
1.32k
    case IMAGE_FILE_MACHINE_ARM:
1265
#ifdef ARMPEMAGIC
1266
294
      magic = ARMPEMAGIC;
1267
#endif
1268
1.32k
      break;
1269
1270
1.65k
    case IMAGE_FILE_MACHINE_ARM64:
1271
#ifdef AARCH64MAGIC
1272
238
      magic = AARCH64MAGIC;
1273
#endif
1274
1.65k
      break;
1275
1276
1.69k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1277
#ifdef LOONGARCH64MAGIC
1278
230
      magic = LOONGARCH64MAGIC;
1279
#endif
1280
1.69k
      break;
1281
1282
1.84k
    case IMAGE_FILE_MACHINE_RISCV64:
1283
#ifdef RISCV64MAGIC
1284
257
      magic = RISCV64MAGIC;
1285
#endif
1286
1.84k
      break;
1287
1288
948
    case IMAGE_FILE_MACHINE_THUMB:
1289
#ifdef THUMBPEMAGIC
1290
      {
1291
  extern const bfd_target TARGET_LITTLE_SYM;
1292
1293
182
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1294
180
    magic = THUMBPEMAGIC;
1295
      }
1296
#endif
1297
948
      break;
1298
1299
0
    case IMAGE_FILE_MACHINE_POWERPC:
1300
      /* We no longer support PowerPC.  */
1301
4.47k
    default:
1302
4.47k
      _bfd_error_handler
1303
  /* xgettext:c-format */
1304
4.47k
  (_("%pB: unrecognised machine type (0x%x)"
1305
4.47k
     " in Import Library Format archive"),
1306
4.47k
   abfd, machine);
1307
4.47k
      bfd_set_error (bfd_error_malformed_archive);
1308
1309
4.47k
      return NULL;
1310
0
      break;
1311
17.9k
    }
1312
1313
13.5k
  if (magic == 0)
1314
11.5k
    {
1315
11.5k
      _bfd_error_handler
1316
  /* xgettext:c-format */
1317
11.5k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1318
11.5k
     " in Import Library Format archive"),
1319
11.5k
   abfd, machine);
1320
11.5k
      bfd_set_error (bfd_error_wrong_format);
1321
1322
11.5k
      return NULL;
1323
11.5k
    }
1324
1325
  /* We do not bother to check the date.
1326
     date = H_GET_32 (abfd, ptr);  */
1327
1.93k
  ptr += 4;
1328
1329
1.93k
  size = H_GET_32 (abfd, ptr);
1330
1.93k
  ptr += 4;
1331
1332
1.93k
  if (size == 0)
1333
44
    {
1334
44
      _bfd_error_handler
1335
44
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1336
44
      bfd_set_error (bfd_error_malformed_archive);
1337
1338
44
      return NULL;
1339
44
    }
1340
1341
1.89k
  ordinal = H_GET_16 (abfd, ptr);
1342
1.89k
  ptr += 2;
1343
1344
1.89k
  types = H_GET_16 (abfd, ptr);
1345
  /* ptr += 2; */
1346
1347
  /* Now read in the two strings that follow.  */
1348
1.89k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1349
1.89k
  if (ptr == NULL)
1350
955
    return NULL;
1351
1352
938
  symbol_name = (char *) ptr;
1353
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1354
938
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1355
1356
  /* Verify that the strings are null terminated.  */
1357
938
  if (ptr[size - 1] != 0
1358
869
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1359
109
    {
1360
109
      _bfd_error_handler
1361
109
  (_("%pB: string not null terminated in ILF object file"), abfd);
1362
109
      bfd_set_error (bfd_error_malformed_archive);
1363
109
      bfd_release (abfd, ptr);
1364
109
      return NULL;
1365
109
    }
1366
1367
  /* An ILF file may contain a third string, after source_dll; this is
1368
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1369
     block of data is null terminated, ptr[size-1]==0, but we don't
1370
     know how many individual null terminated strings we have in there.
1371
1372
     First find the end of source_dll.  */
1373
829
  import_name = source_dll + strlen (source_dll) + 1;
1374
829
  if ((bfd_byte *) import_name >= ptr + size)
1375
234
    {
1376
      /* If this points at the end of the ptr+size block, we only had
1377
   two strings. */
1378
234
      import_name = NULL;
1379
234
    }
1380
1381
  /* Now construct the bfd.  */
1382
829
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1383
829
          source_dll, ordinal, types,
1384
829
          import_name))
1385
212
    {
1386
212
      bfd_release (abfd, ptr);
1387
212
      return NULL;
1388
212
    }
1389
1390
617
  return pe_ILF_cleanup;
1391
829
}
pei-i386.c:pe_ILF_object_p
Line
Count
Source
1200
2.20k
{
1201
2.20k
  bfd_byte    buffer[14];
1202
2.20k
  bfd_byte *    ptr;
1203
2.20k
  char *    symbol_name;
1204
2.20k
  char *    source_dll;
1205
2.20k
  char *    import_name;
1206
2.20k
  unsigned int    machine;
1207
2.20k
  bfd_size_type   size;
1208
2.20k
  unsigned int    ordinal;
1209
2.20k
  unsigned int    types;
1210
2.20k
  unsigned int    magic;
1211
1212
  /* Upon entry the first six bytes of the ILF header have
1213
     already been read.  Now read the rest of the header.  */
1214
2.20k
  if (bfd_read (buffer, 14, abfd) != 14)
1215
30
    return NULL;
1216
1217
2.17k
  ptr = buffer;
1218
1219
2.17k
  machine = H_GET_16 (abfd, ptr);
1220
2.17k
  ptr += 2;
1221
1222
  /* Check that the machine type is recognised.  */
1223
2.17k
  magic = 0;
1224
1225
2.17k
  switch (machine)
1226
2.17k
    {
1227
7
    case IMAGE_FILE_MACHINE_UNKNOWN:
1228
14
    case IMAGE_FILE_MACHINE_ALPHA:
1229
20
    case IMAGE_FILE_MACHINE_ALPHA64:
1230
26
    case IMAGE_FILE_MACHINE_IA64:
1231
26
      break;
1232
1233
269
    case IMAGE_FILE_MACHINE_I386:
1234
269
#ifdef I386MAGIC
1235
269
      magic = I386MAGIC;
1236
269
#endif
1237
269
      break;
1238
1239
213
    case IMAGE_FILE_MACHINE_AMD64:
1240
#ifdef AMD64MAGIC
1241
      magic = AMD64MAGIC;
1242
#endif
1243
213
      break;
1244
1245
4
    case IMAGE_FILE_MACHINE_R3000:
1246
10
    case IMAGE_FILE_MACHINE_R4000:
1247
15
    case IMAGE_FILE_MACHINE_R10000:
1248
1249
20
    case IMAGE_FILE_MACHINE_MIPS16:
1250
27
    case IMAGE_FILE_MACHINE_MIPSFPU:
1251
33
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1252
#ifdef MIPS_ARCH_MAGIC_WINCE
1253
      magic = MIPS_ARCH_MAGIC_WINCE;
1254
#endif
1255
33
      break;
1256
1257
83
    case IMAGE_FILE_MACHINE_SH3:
1258
210
    case IMAGE_FILE_MACHINE_SH4:
1259
#ifdef SH_ARCH_MAGIC_WINCE
1260
      magic = SH_ARCH_MAGIC_WINCE;
1261
#endif
1262
210
      break;
1263
1264
150
    case IMAGE_FILE_MACHINE_ARM:
1265
#ifdef ARMPEMAGIC
1266
      magic = ARMPEMAGIC;
1267
#endif
1268
150
      break;
1269
1270
197
    case IMAGE_FILE_MACHINE_ARM64:
1271
#ifdef AARCH64MAGIC
1272
      magic = AARCH64MAGIC;
1273
#endif
1274
197
      break;
1275
1276
194
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1277
#ifdef LOONGARCH64MAGIC
1278
      magic = LOONGARCH64MAGIC;
1279
#endif
1280
194
      break;
1281
1282
219
    case IMAGE_FILE_MACHINE_RISCV64:
1283
#ifdef RISCV64MAGIC
1284
      magic = RISCV64MAGIC;
1285
#endif
1286
219
      break;
1287
1288
117
    case IMAGE_FILE_MACHINE_THUMB:
1289
#ifdef THUMBPEMAGIC
1290
      {
1291
  extern const bfd_target TARGET_LITTLE_SYM;
1292
1293
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1294
    magic = THUMBPEMAGIC;
1295
      }
1296
#endif
1297
117
      break;
1298
1299
0
    case IMAGE_FILE_MACHINE_POWERPC:
1300
      /* We no longer support PowerPC.  */
1301
545
    default:
1302
545
      _bfd_error_handler
1303
  /* xgettext:c-format */
1304
545
  (_("%pB: unrecognised machine type (0x%x)"
1305
545
     " in Import Library Format archive"),
1306
545
   abfd, machine);
1307
545
      bfd_set_error (bfd_error_malformed_archive);
1308
1309
545
      return NULL;
1310
0
      break;
1311
2.17k
    }
1312
1313
1.62k
  if (magic == 0)
1314
1.35k
    {
1315
1.35k
      _bfd_error_handler
1316
  /* xgettext:c-format */
1317
1.35k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1318
1.35k
     " in Import Library Format archive"),
1319
1.35k
   abfd, machine);
1320
1.35k
      bfd_set_error (bfd_error_wrong_format);
1321
1322
1.35k
      return NULL;
1323
1.35k
    }
1324
1325
  /* We do not bother to check the date.
1326
     date = H_GET_32 (abfd, ptr);  */
1327
269
  ptr += 4;
1328
1329
269
  size = H_GET_32 (abfd, ptr);
1330
269
  ptr += 4;
1331
1332
269
  if (size == 0)
1333
5
    {
1334
5
      _bfd_error_handler
1335
5
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1336
5
      bfd_set_error (bfd_error_malformed_archive);
1337
1338
5
      return NULL;
1339
5
    }
1340
1341
264
  ordinal = H_GET_16 (abfd, ptr);
1342
264
  ptr += 2;
1343
1344
264
  types = H_GET_16 (abfd, ptr);
1345
  /* ptr += 2; */
1346
1347
  /* Now read in the two strings that follow.  */
1348
264
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1349
264
  if (ptr == NULL)
1350
135
    return NULL;
1351
1352
129
  symbol_name = (char *) ptr;
1353
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1354
129
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1355
1356
  /* Verify that the strings are null terminated.  */
1357
129
  if (ptr[size - 1] != 0
1358
121
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1359
13
    {
1360
13
      _bfd_error_handler
1361
13
  (_("%pB: string not null terminated in ILF object file"), abfd);
1362
13
      bfd_set_error (bfd_error_malformed_archive);
1363
13
      bfd_release (abfd, ptr);
1364
13
      return NULL;
1365
13
    }
1366
1367
  /* An ILF file may contain a third string, after source_dll; this is
1368
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1369
     block of data is null terminated, ptr[size-1]==0, but we don't
1370
     know how many individual null terminated strings we have in there.
1371
1372
     First find the end of source_dll.  */
1373
116
  import_name = source_dll + strlen (source_dll) + 1;
1374
116
  if ((bfd_byte *) import_name >= ptr + size)
1375
31
    {
1376
      /* If this points at the end of the ptr+size block, we only had
1377
   two strings. */
1378
31
      import_name = NULL;
1379
31
    }
1380
1381
  /* Now construct the bfd.  */
1382
116
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1383
116
          source_dll, ordinal, types,
1384
116
          import_name))
1385
24
    {
1386
24
      bfd_release (abfd, ptr);
1387
24
      return NULL;
1388
24
    }
1389
1390
92
  return pe_ILF_cleanup;
1391
116
}
pei-x86_64.c:pe_ILF_object_p
Line
Count
Source
1200
2.19k
{
1201
2.19k
  bfd_byte    buffer[14];
1202
2.19k
  bfd_byte *    ptr;
1203
2.19k
  char *    symbol_name;
1204
2.19k
  char *    source_dll;
1205
2.19k
  char *    import_name;
1206
2.19k
  unsigned int    machine;
1207
2.19k
  bfd_size_type   size;
1208
2.19k
  unsigned int    ordinal;
1209
2.19k
  unsigned int    types;
1210
2.19k
  unsigned int    magic;
1211
1212
  /* Upon entry the first six bytes of the ILF header have
1213
     already been read.  Now read the rest of the header.  */
1214
2.19k
  if (bfd_read (buffer, 14, abfd) != 14)
1215
30
    return NULL;
1216
1217
2.16k
  ptr = buffer;
1218
1219
2.16k
  machine = H_GET_16 (abfd, ptr);
1220
2.16k
  ptr += 2;
1221
1222
  /* Check that the machine type is recognised.  */
1223
2.16k
  magic = 0;
1224
1225
2.16k
  switch (machine)
1226
2.16k
    {
1227
7
    case IMAGE_FILE_MACHINE_UNKNOWN:
1228
14
    case IMAGE_FILE_MACHINE_ALPHA:
1229
20
    case IMAGE_FILE_MACHINE_ALPHA64:
1230
26
    case IMAGE_FILE_MACHINE_IA64:
1231
26
      break;
1232
1233
222
    case IMAGE_FILE_MACHINE_I386:
1234
#ifdef I386MAGIC
1235
      magic = I386MAGIC;
1236
#endif
1237
222
      break;
1238
1239
252
    case IMAGE_FILE_MACHINE_AMD64:
1240
252
#ifdef AMD64MAGIC
1241
252
      magic = AMD64MAGIC;
1242
252
#endif
1243
252
      break;
1244
1245
4
    case IMAGE_FILE_MACHINE_R3000:
1246
10
    case IMAGE_FILE_MACHINE_R4000:
1247
15
    case IMAGE_FILE_MACHINE_R10000:
1248
1249
20
    case IMAGE_FILE_MACHINE_MIPS16:
1250
27
    case IMAGE_FILE_MACHINE_MIPSFPU:
1251
33
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1252
#ifdef MIPS_ARCH_MAGIC_WINCE
1253
      magic = MIPS_ARCH_MAGIC_WINCE;
1254
#endif
1255
33
      break;
1256
1257
83
    case IMAGE_FILE_MACHINE_SH3:
1258
208
    case IMAGE_FILE_MACHINE_SH4:
1259
#ifdef SH_ARCH_MAGIC_WINCE
1260
      magic = SH_ARCH_MAGIC_WINCE;
1261
#endif
1262
208
      break;
1263
1264
150
    case IMAGE_FILE_MACHINE_ARM:
1265
#ifdef ARMPEMAGIC
1266
      magic = ARMPEMAGIC;
1267
#endif
1268
150
      break;
1269
1270
197
    case IMAGE_FILE_MACHINE_ARM64:
1271
#ifdef AARCH64MAGIC
1272
      magic = AARCH64MAGIC;
1273
#endif
1274
197
      break;
1275
1276
194
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1277
#ifdef LOONGARCH64MAGIC
1278
      magic = LOONGARCH64MAGIC;
1279
#endif
1280
194
      break;
1281
1282
217
    case IMAGE_FILE_MACHINE_RISCV64:
1283
#ifdef RISCV64MAGIC
1284
      magic = RISCV64MAGIC;
1285
#endif
1286
217
      break;
1287
1288
117
    case IMAGE_FILE_MACHINE_THUMB:
1289
#ifdef THUMBPEMAGIC
1290
      {
1291
  extern const bfd_target TARGET_LITTLE_SYM;
1292
1293
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1294
    magic = THUMBPEMAGIC;
1295
      }
1296
#endif
1297
117
      break;
1298
1299
0
    case IMAGE_FILE_MACHINE_POWERPC:
1300
      /* We no longer support PowerPC.  */
1301
545
    default:
1302
545
      _bfd_error_handler
1303
  /* xgettext:c-format */
1304
545
  (_("%pB: unrecognised machine type (0x%x)"
1305
545
     " in Import Library Format archive"),
1306
545
   abfd, machine);
1307
545
      bfd_set_error (bfd_error_malformed_archive);
1308
1309
545
      return NULL;
1310
0
      break;
1311
2.16k
    }
1312
1313
1.61k
  if (magic == 0)
1314
1.36k
    {
1315
1.36k
      _bfd_error_handler
1316
  /* xgettext:c-format */
1317
1.36k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1318
1.36k
     " in Import Library Format archive"),
1319
1.36k
   abfd, machine);
1320
1.36k
      bfd_set_error (bfd_error_wrong_format);
1321
1322
1.36k
      return NULL;
1323
1.36k
    }
1324
1325
  /* We do not bother to check the date.
1326
     date = H_GET_32 (abfd, ptr);  */
1327
252
  ptr += 4;
1328
1329
252
  size = H_GET_32 (abfd, ptr);
1330
252
  ptr += 4;
1331
1332
252
  if (size == 0)
1333
7
    {
1334
7
      _bfd_error_handler
1335
7
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1336
7
      bfd_set_error (bfd_error_malformed_archive);
1337
1338
7
      return NULL;
1339
7
    }
1340
1341
245
  ordinal = H_GET_16 (abfd, ptr);
1342
245
  ptr += 2;
1343
1344
245
  types = H_GET_16 (abfd, ptr);
1345
  /* ptr += 2; */
1346
1347
  /* Now read in the two strings that follow.  */
1348
245
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1349
245
  if (ptr == NULL)
1350
127
    return NULL;
1351
1352
118
  symbol_name = (char *) ptr;
1353
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1354
118
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1355
1356
  /* Verify that the strings are null terminated.  */
1357
118
  if (ptr[size - 1] != 0
1358
112
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1359
11
    {
1360
11
      _bfd_error_handler
1361
11
  (_("%pB: string not null terminated in ILF object file"), abfd);
1362
11
      bfd_set_error (bfd_error_malformed_archive);
1363
11
      bfd_release (abfd, ptr);
1364
11
      return NULL;
1365
11
    }
1366
1367
  /* An ILF file may contain a third string, after source_dll; this is
1368
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1369
     block of data is null terminated, ptr[size-1]==0, but we don't
1370
     know how many individual null terminated strings we have in there.
1371
1372
     First find the end of source_dll.  */
1373
107
  import_name = source_dll + strlen (source_dll) + 1;
1374
107
  if ((bfd_byte *) import_name >= ptr + size)
1375
28
    {
1376
      /* If this points at the end of the ptr+size block, we only had
1377
   two strings. */
1378
28
      import_name = NULL;
1379
28
    }
1380
1381
  /* Now construct the bfd.  */
1382
107
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1383
107
          source_dll, ordinal, types,
1384
107
          import_name))
1385
25
    {
1386
25
      bfd_release (abfd, ptr);
1387
25
      return NULL;
1388
25
    }
1389
1390
82
  return pe_ILF_cleanup;
1391
107
}
pei-aarch64.c:pe_ILF_object_p
Line
Count
Source
1200
2.20k
{
1201
2.20k
  bfd_byte    buffer[14];
1202
2.20k
  bfd_byte *    ptr;
1203
2.20k
  char *    symbol_name;
1204
2.20k
  char *    source_dll;
1205
2.20k
  char *    import_name;
1206
2.20k
  unsigned int    machine;
1207
2.20k
  bfd_size_type   size;
1208
2.20k
  unsigned int    ordinal;
1209
2.20k
  unsigned int    types;
1210
2.20k
  unsigned int    magic;
1211
1212
  /* Upon entry the first six bytes of the ILF header have
1213
     already been read.  Now read the rest of the header.  */
1214
2.20k
  if (bfd_read (buffer, 14, abfd) != 14)
1215
30
    return NULL;
1216
1217
2.17k
  ptr = buffer;
1218
1219
2.17k
  machine = H_GET_16 (abfd, ptr);
1220
2.17k
  ptr += 2;
1221
1222
  /* Check that the machine type is recognised.  */
1223
2.17k
  magic = 0;
1224
1225
2.17k
  switch (machine)
1226
2.17k
    {
1227
7
    case IMAGE_FILE_MACHINE_UNKNOWN:
1228
14
    case IMAGE_FILE_MACHINE_ALPHA:
1229
20
    case IMAGE_FILE_MACHINE_ALPHA64:
1230
26
    case IMAGE_FILE_MACHINE_IA64:
1231
26
      break;
1232
1233
225
    case IMAGE_FILE_MACHINE_I386:
1234
#ifdef I386MAGIC
1235
      magic = I386MAGIC;
1236
#endif
1237
225
      break;
1238
1239
213
    case IMAGE_FILE_MACHINE_AMD64:
1240
#ifdef AMD64MAGIC
1241
      magic = AMD64MAGIC;
1242
#endif
1243
213
      break;
1244
1245
4
    case IMAGE_FILE_MACHINE_R3000:
1246
10
    case IMAGE_FILE_MACHINE_R4000:
1247
15
    case IMAGE_FILE_MACHINE_R10000:
1248
1249
20
    case IMAGE_FILE_MACHINE_MIPS16:
1250
27
    case IMAGE_FILE_MACHINE_MIPSFPU:
1251
33
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1252
#ifdef MIPS_ARCH_MAGIC_WINCE
1253
      magic = MIPS_ARCH_MAGIC_WINCE;
1254
#endif
1255
33
      break;
1256
1257
83
    case IMAGE_FILE_MACHINE_SH3:
1258
210
    case IMAGE_FILE_MACHINE_SH4:
1259
#ifdef SH_ARCH_MAGIC_WINCE
1260
      magic = SH_ARCH_MAGIC_WINCE;
1261
#endif
1262
210
      break;
1263
1264
152
    case IMAGE_FILE_MACHINE_ARM:
1265
#ifdef ARMPEMAGIC
1266
      magic = ARMPEMAGIC;
1267
#endif
1268
152
      break;
1269
1270
238
    case IMAGE_FILE_MACHINE_ARM64:
1271
238
#ifdef AARCH64MAGIC
1272
238
      magic = AARCH64MAGIC;
1273
238
#endif
1274
238
      break;
1275
1276
194
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1277
#ifdef LOONGARCH64MAGIC
1278
      magic = LOONGARCH64MAGIC;
1279
#endif
1280
194
      break;
1281
1282
219
    case IMAGE_FILE_MACHINE_RISCV64:
1283
#ifdef RISCV64MAGIC
1284
      magic = RISCV64MAGIC;
1285
#endif
1286
219
      break;
1287
1288
117
    case IMAGE_FILE_MACHINE_THUMB:
1289
#ifdef THUMBPEMAGIC
1290
      {
1291
  extern const bfd_target TARGET_LITTLE_SYM;
1292
1293
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1294
    magic = THUMBPEMAGIC;
1295
      }
1296
#endif
1297
117
      break;
1298
1299
0
    case IMAGE_FILE_MACHINE_POWERPC:
1300
      /* We no longer support PowerPC.  */
1301
545
    default:
1302
545
      _bfd_error_handler
1303
  /* xgettext:c-format */
1304
545
  (_("%pB: unrecognised machine type (0x%x)"
1305
545
     " in Import Library Format archive"),
1306
545
   abfd, machine);
1307
545
      bfd_set_error (bfd_error_malformed_archive);
1308
1309
545
      return NULL;
1310
0
      break;
1311
2.17k
    }
1312
1313
1.62k
  if (magic == 0)
1314
1.38k
    {
1315
1.38k
      _bfd_error_handler
1316
  /* xgettext:c-format */
1317
1.38k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1318
1.38k
     " in Import Library Format archive"),
1319
1.38k
   abfd, machine);
1320
1.38k
      bfd_set_error (bfd_error_wrong_format);
1321
1322
1.38k
      return NULL;
1323
1.38k
    }
1324
1325
  /* We do not bother to check the date.
1326
     date = H_GET_32 (abfd, ptr);  */
1327
238
  ptr += 4;
1328
1329
238
  size = H_GET_32 (abfd, ptr);
1330
238
  ptr += 4;
1331
1332
238
  if (size == 0)
1333
5
    {
1334
5
      _bfd_error_handler
1335
5
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1336
5
      bfd_set_error (bfd_error_malformed_archive);
1337
1338
5
      return NULL;
1339
5
    }
1340
1341
233
  ordinal = H_GET_16 (abfd, ptr);
1342
233
  ptr += 2;
1343
1344
233
  types = H_GET_16 (abfd, ptr);
1345
  /* ptr += 2; */
1346
1347
  /* Now read in the two strings that follow.  */
1348
233
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1349
233
  if (ptr == NULL)
1350
109
    return NULL;
1351
1352
124
  symbol_name = (char *) ptr;
1353
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1354
124
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1355
1356
  /* Verify that the strings are null terminated.  */
1357
124
  if (ptr[size - 1] != 0
1358
119
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1359
10
    {
1360
10
      _bfd_error_handler
1361
10
  (_("%pB: string not null terminated in ILF object file"), abfd);
1362
10
      bfd_set_error (bfd_error_malformed_archive);
1363
10
      bfd_release (abfd, ptr);
1364
10
      return NULL;
1365
10
    }
1366
1367
  /* An ILF file may contain a third string, after source_dll; this is
1368
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1369
     block of data is null terminated, ptr[size-1]==0, but we don't
1370
     know how many individual null terminated strings we have in there.
1371
1372
     First find the end of source_dll.  */
1373
114
  import_name = source_dll + strlen (source_dll) + 1;
1374
114
  if ((bfd_byte *) import_name >= ptr + size)
1375
35
    {
1376
      /* If this points at the end of the ptr+size block, we only had
1377
   two strings. */
1378
35
      import_name = NULL;
1379
35
    }
1380
1381
  /* Now construct the bfd.  */
1382
114
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1383
114
          source_dll, ordinal, types,
1384
114
          import_name))
1385
25
    {
1386
25
      bfd_release (abfd, ptr);
1387
25
      return NULL;
1388
25
    }
1389
1390
89
  return pe_ILF_cleanup;
1391
114
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_object_p
pei-loongarch64.c:pe_ILF_object_p
Line
Count
Source
1200
2.18k
{
1201
2.18k
  bfd_byte    buffer[14];
1202
2.18k
  bfd_byte *    ptr;
1203
2.18k
  char *    symbol_name;
1204
2.18k
  char *    source_dll;
1205
2.18k
  char *    import_name;
1206
2.18k
  unsigned int    machine;
1207
2.18k
  bfd_size_type   size;
1208
2.18k
  unsigned int    ordinal;
1209
2.18k
  unsigned int    types;
1210
2.18k
  unsigned int    magic;
1211
1212
  /* Upon entry the first six bytes of the ILF header have
1213
     already been read.  Now read the rest of the header.  */
1214
2.18k
  if (bfd_read (buffer, 14, abfd) != 14)
1215
30
    return NULL;
1216
1217
2.15k
  ptr = buffer;
1218
1219
2.15k
  machine = H_GET_16 (abfd, ptr);
1220
2.15k
  ptr += 2;
1221
1222
  /* Check that the machine type is recognised.  */
1223
2.15k
  magic = 0;
1224
1225
2.15k
  switch (machine)
1226
2.15k
    {
1227
7
    case IMAGE_FILE_MACHINE_UNKNOWN:
1228
14
    case IMAGE_FILE_MACHINE_ALPHA:
1229
20
    case IMAGE_FILE_MACHINE_ALPHA64:
1230
26
    case IMAGE_FILE_MACHINE_IA64:
1231
26
      break;
1232
1233
222
    case IMAGE_FILE_MACHINE_I386:
1234
#ifdef I386MAGIC
1235
      magic = I386MAGIC;
1236
#endif
1237
222
      break;
1238
1239
210
    case IMAGE_FILE_MACHINE_AMD64:
1240
#ifdef AMD64MAGIC
1241
      magic = AMD64MAGIC;
1242
#endif
1243
210
      break;
1244
1245
4
    case IMAGE_FILE_MACHINE_R3000:
1246
10
    case IMAGE_FILE_MACHINE_R4000:
1247
15
    case IMAGE_FILE_MACHINE_R10000:
1248
1249
20
    case IMAGE_FILE_MACHINE_MIPS16:
1250
27
    case IMAGE_FILE_MACHINE_MIPSFPU:
1251
33
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1252
#ifdef MIPS_ARCH_MAGIC_WINCE
1253
      magic = MIPS_ARCH_MAGIC_WINCE;
1254
#endif
1255
33
      break;
1256
1257
83
    case IMAGE_FILE_MACHINE_SH3:
1258
208
    case IMAGE_FILE_MACHINE_SH4:
1259
#ifdef SH_ARCH_MAGIC_WINCE
1260
      magic = SH_ARCH_MAGIC_WINCE;
1261
#endif
1262
208
      break;
1263
1264
150
    case IMAGE_FILE_MACHINE_ARM:
1265
#ifdef ARMPEMAGIC
1266
      magic = ARMPEMAGIC;
1267
#endif
1268
150
      break;
1269
1270
197
    case IMAGE_FILE_MACHINE_ARM64:
1271
#ifdef AARCH64MAGIC
1272
      magic = AARCH64MAGIC;
1273
#endif
1274
197
      break;
1275
1276
230
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1277
230
#ifdef LOONGARCH64MAGIC
1278
230
      magic = LOONGARCH64MAGIC;
1279
230
#endif
1280
230
      break;
1281
1282
217
    case IMAGE_FILE_MACHINE_RISCV64:
1283
#ifdef RISCV64MAGIC
1284
      magic = RISCV64MAGIC;
1285
#endif
1286
217
      break;
1287
1288
117
    case IMAGE_FILE_MACHINE_THUMB:
1289
#ifdef THUMBPEMAGIC
1290
      {
1291
  extern const bfd_target TARGET_LITTLE_SYM;
1292
1293
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1294
    magic = THUMBPEMAGIC;
1295
      }
1296
#endif
1297
117
      break;
1298
1299
0
    case IMAGE_FILE_MACHINE_POWERPC:
1300
      /* We no longer support PowerPC.  */
1301
545
    default:
1302
545
      _bfd_error_handler
1303
  /* xgettext:c-format */
1304
545
  (_("%pB: unrecognised machine type (0x%x)"
1305
545
     " in Import Library Format archive"),
1306
545
   abfd, machine);
1307
545
      bfd_set_error (bfd_error_malformed_archive);
1308
1309
545
      return NULL;
1310
0
      break;
1311
2.15k
    }
1312
1313
1.61k
  if (magic == 0)
1314
1.38k
    {
1315
1.38k
      _bfd_error_handler
1316
  /* xgettext:c-format */
1317
1.38k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1318
1.38k
     " in Import Library Format archive"),
1319
1.38k
   abfd, machine);
1320
1.38k
      bfd_set_error (bfd_error_wrong_format);
1321
1322
1.38k
      return NULL;
1323
1.38k
    }
1324
1325
  /* We do not bother to check the date.
1326
     date = H_GET_32 (abfd, ptr);  */
1327
230
  ptr += 4;
1328
1329
230
  size = H_GET_32 (abfd, ptr);
1330
230
  ptr += 4;
1331
1332
230
  if (size == 0)
1333
7
    {
1334
7
      _bfd_error_handler
1335
7
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1336
7
      bfd_set_error (bfd_error_malformed_archive);
1337
1338
7
      return NULL;
1339
7
    }
1340
1341
223
  ordinal = H_GET_16 (abfd, ptr);
1342
223
  ptr += 2;
1343
1344
223
  types = H_GET_16 (abfd, ptr);
1345
  /* ptr += 2; */
1346
1347
  /* Now read in the two strings that follow.  */
1348
223
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1349
223
  if (ptr == NULL)
1350
110
    return NULL;
1351
1352
113
  symbol_name = (char *) ptr;
1353
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1354
113
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1355
1356
  /* Verify that the strings are null terminated.  */
1357
113
  if (ptr[size - 1] != 0
1358
107
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1359
11
    {
1360
11
      _bfd_error_handler
1361
11
  (_("%pB: string not null terminated in ILF object file"), abfd);
1362
11
      bfd_set_error (bfd_error_malformed_archive);
1363
11
      bfd_release (abfd, ptr);
1364
11
      return NULL;
1365
11
    }
1366
1367
  /* An ILF file may contain a third string, after source_dll; this is
1368
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1369
     block of data is null terminated, ptr[size-1]==0, but we don't
1370
     know how many individual null terminated strings we have in there.
1371
1372
     First find the end of source_dll.  */
1373
102
  import_name = source_dll + strlen (source_dll) + 1;
1374
102
  if ((bfd_byte *) import_name >= ptr + size)
1375
24
    {
1376
      /* If this points at the end of the ptr+size block, we only had
1377
   two strings. */
1378
24
      import_name = NULL;
1379
24
    }
1380
1381
  /* Now construct the bfd.  */
1382
102
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1383
102
          source_dll, ordinal, types,
1384
102
          import_name))
1385
24
    {
1386
24
      bfd_release (abfd, ptr);
1387
24
      return NULL;
1388
24
    }
1389
1390
78
  return pe_ILF_cleanup;
1391
102
}
pei-riscv64.c:pe_ILF_object_p
Line
Count
Source
1200
2.19k
{
1201
2.19k
  bfd_byte    buffer[14];
1202
2.19k
  bfd_byte *    ptr;
1203
2.19k
  char *    symbol_name;
1204
2.19k
  char *    source_dll;
1205
2.19k
  char *    import_name;
1206
2.19k
  unsigned int    machine;
1207
2.19k
  bfd_size_type   size;
1208
2.19k
  unsigned int    ordinal;
1209
2.19k
  unsigned int    types;
1210
2.19k
  unsigned int    magic;
1211
1212
  /* Upon entry the first six bytes of the ILF header have
1213
     already been read.  Now read the rest of the header.  */
1214
2.19k
  if (bfd_read (buffer, 14, abfd) != 14)
1215
30
    return NULL;
1216
1217
2.16k
  ptr = buffer;
1218
1219
2.16k
  machine = H_GET_16 (abfd, ptr);
1220
2.16k
  ptr += 2;
1221
1222
  /* Check that the machine type is recognised.  */
1223
2.16k
  magic = 0;
1224
1225
2.16k
  switch (machine)
1226
2.16k
    {
1227
7
    case IMAGE_FILE_MACHINE_UNKNOWN:
1228
14
    case IMAGE_FILE_MACHINE_ALPHA:
1229
20
    case IMAGE_FILE_MACHINE_ALPHA64:
1230
26
    case IMAGE_FILE_MACHINE_IA64:
1231
26
      break;
1232
1233
222
    case IMAGE_FILE_MACHINE_I386:
1234
#ifdef I386MAGIC
1235
      magic = I386MAGIC;
1236
#endif
1237
222
      break;
1238
1239
213
    case IMAGE_FILE_MACHINE_AMD64:
1240
#ifdef AMD64MAGIC
1241
      magic = AMD64MAGIC;
1242
#endif
1243
213
      break;
1244
1245
4
    case IMAGE_FILE_MACHINE_R3000:
1246
10
    case IMAGE_FILE_MACHINE_R4000:
1247
15
    case IMAGE_FILE_MACHINE_R10000:
1248
1249
20
    case IMAGE_FILE_MACHINE_MIPS16:
1250
27
    case IMAGE_FILE_MACHINE_MIPSFPU:
1251
33
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1252
#ifdef MIPS_ARCH_MAGIC_WINCE
1253
      magic = MIPS_ARCH_MAGIC_WINCE;
1254
#endif
1255
33
      break;
1256
1257
83
    case IMAGE_FILE_MACHINE_SH3:
1258
210
    case IMAGE_FILE_MACHINE_SH4:
1259
#ifdef SH_ARCH_MAGIC_WINCE
1260
      magic = SH_ARCH_MAGIC_WINCE;
1261
#endif
1262
210
      break;
1263
1264
150
    case IMAGE_FILE_MACHINE_ARM:
1265
#ifdef ARMPEMAGIC
1266
      magic = ARMPEMAGIC;
1267
#endif
1268
150
      break;
1269
1270
197
    case IMAGE_FILE_MACHINE_ARM64:
1271
#ifdef AARCH64MAGIC
1272
      magic = AARCH64MAGIC;
1273
#endif
1274
197
      break;
1275
1276
194
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1277
#ifdef LOONGARCH64MAGIC
1278
      magic = LOONGARCH64MAGIC;
1279
#endif
1280
194
      break;
1281
1282
257
    case IMAGE_FILE_MACHINE_RISCV64:
1283
257
#ifdef RISCV64MAGIC
1284
257
      magic = RISCV64MAGIC;
1285
257
#endif
1286
257
      break;
1287
1288
117
    case IMAGE_FILE_MACHINE_THUMB:
1289
#ifdef THUMBPEMAGIC
1290
      {
1291
  extern const bfd_target TARGET_LITTLE_SYM;
1292
1293
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1294
    magic = THUMBPEMAGIC;
1295
      }
1296
#endif
1297
117
      break;
1298
1299
0
    case IMAGE_FILE_MACHINE_POWERPC:
1300
      /* We no longer support PowerPC.  */
1301
545
    default:
1302
545
      _bfd_error_handler
1303
  /* xgettext:c-format */
1304
545
  (_("%pB: unrecognised machine type (0x%x)"
1305
545
     " in Import Library Format archive"),
1306
545
   abfd, machine);
1307
545
      bfd_set_error (bfd_error_malformed_archive);
1308
1309
545
      return NULL;
1310
0
      break;
1311
2.16k
    }
1312
1313
1.61k
  if (magic == 0)
1314
1.36k
    {
1315
1.36k
      _bfd_error_handler
1316
  /* xgettext:c-format */
1317
1.36k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1318
1.36k
     " in Import Library Format archive"),
1319
1.36k
   abfd, machine);
1320
1.36k
      bfd_set_error (bfd_error_wrong_format);
1321
1322
1.36k
      return NULL;
1323
1.36k
    }
1324
1325
  /* We do not bother to check the date.
1326
     date = H_GET_32 (abfd, ptr);  */
1327
257
  ptr += 4;
1328
1329
257
  size = H_GET_32 (abfd, ptr);
1330
257
  ptr += 4;
1331
1332
257
  if (size == 0)
1333
5
    {
1334
5
      _bfd_error_handler
1335
5
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1336
5
      bfd_set_error (bfd_error_malformed_archive);
1337
1338
5
      return NULL;
1339
5
    }
1340
1341
252
  ordinal = H_GET_16 (abfd, ptr);
1342
252
  ptr += 2;
1343
1344
252
  types = H_GET_16 (abfd, ptr);
1345
  /* ptr += 2; */
1346
1347
  /* Now read in the two strings that follow.  */
1348
252
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1349
252
  if (ptr == NULL)
1350
132
    return NULL;
1351
1352
120
  symbol_name = (char *) ptr;
1353
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1354
120
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1355
1356
  /* Verify that the strings are null terminated.  */
1357
120
  if (ptr[size - 1] != 0
1358
115
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1359
10
    {
1360
10
      _bfd_error_handler
1361
10
  (_("%pB: string not null terminated in ILF object file"), abfd);
1362
10
      bfd_set_error (bfd_error_malformed_archive);
1363
10
      bfd_release (abfd, ptr);
1364
10
      return NULL;
1365
10
    }
1366
1367
  /* An ILF file may contain a third string, after source_dll; this is
1368
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1369
     block of data is null terminated, ptr[size-1]==0, but we don't
1370
     know how many individual null terminated strings we have in there.
1371
1372
     First find the end of source_dll.  */
1373
110
  import_name = source_dll + strlen (source_dll) + 1;
1374
110
  if ((bfd_byte *) import_name >= ptr + size)
1375
27
    {
1376
      /* If this points at the end of the ptr+size block, we only had
1377
   two strings. */
1378
27
      import_name = NULL;
1379
27
    }
1380
1381
  /* Now construct the bfd.  */
1382
110
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1383
110
          source_dll, ordinal, types,
1384
110
          import_name))
1385
25
    {
1386
25
      bfd_release (abfd, ptr);
1387
25
      return NULL;
1388
25
    }
1389
1390
85
  return pe_ILF_cleanup;
1391
110
}
pei-arm-wince.c:pe_ILF_object_p
Line
Count
Source
1200
1.82k
{
1201
1.82k
  bfd_byte    buffer[14];
1202
1.82k
  bfd_byte *    ptr;
1203
1.82k
  char *    symbol_name;
1204
1.82k
  char *    source_dll;
1205
1.82k
  char *    import_name;
1206
1.82k
  unsigned int    machine;
1207
1.82k
  bfd_size_type   size;
1208
1.82k
  unsigned int    ordinal;
1209
1.82k
  unsigned int    types;
1210
1.82k
  unsigned int    magic;
1211
1212
  /* Upon entry the first six bytes of the ILF header have
1213
     already been read.  Now read the rest of the header.  */
1214
1.82k
  if (bfd_read (buffer, 14, abfd) != 14)
1215
29
    return NULL;
1216
1217
1.79k
  ptr = buffer;
1218
1219
1.79k
  machine = H_GET_16 (abfd, ptr);
1220
1.79k
  ptr += 2;
1221
1222
  /* Check that the machine type is recognised.  */
1223
1.79k
  magic = 0;
1224
1225
1.79k
  switch (machine)
1226
1.79k
    {
1227
10
    case IMAGE_FILE_MACHINE_UNKNOWN:
1228
16
    case IMAGE_FILE_MACHINE_ALPHA:
1229
21
    case IMAGE_FILE_MACHINE_ALPHA64:
1230
26
    case IMAGE_FILE_MACHINE_IA64:
1231
26
      break;
1232
1233
194
    case IMAGE_FILE_MACHINE_I386:
1234
#ifdef I386MAGIC
1235
      magic = I386MAGIC;
1236
#endif
1237
194
      break;
1238
1239
183
    case IMAGE_FILE_MACHINE_AMD64:
1240
#ifdef AMD64MAGIC
1241
      magic = AMD64MAGIC;
1242
#endif
1243
183
      break;
1244
1245
4
    case IMAGE_FILE_MACHINE_R3000:
1246
9
    case IMAGE_FILE_MACHINE_R4000:
1247
13
    case IMAGE_FILE_MACHINE_R10000:
1248
1249
17
    case IMAGE_FILE_MACHINE_MIPS16:
1250
23
    case IMAGE_FILE_MACHINE_MIPSFPU:
1251
28
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1252
#ifdef MIPS_ARCH_MAGIC_WINCE
1253
      magic = MIPS_ARCH_MAGIC_WINCE;
1254
#endif
1255
28
      break;
1256
1257
75
    case IMAGE_FILE_MACHINE_SH3:
1258
176
    case IMAGE_FILE_MACHINE_SH4:
1259
#ifdef SH_ARCH_MAGIC_WINCE
1260
      magic = SH_ARCH_MAGIC_WINCE;
1261
#endif
1262
176
      break;
1263
1264
146
    case IMAGE_FILE_MACHINE_ARM:
1265
146
#ifdef ARMPEMAGIC
1266
146
      magic = ARMPEMAGIC;
1267
146
#endif
1268
146
      break;
1269
1270
156
    case IMAGE_FILE_MACHINE_ARM64:
1271
#ifdef AARCH64MAGIC
1272
      magic = AARCH64MAGIC;
1273
#endif
1274
156
      break;
1275
1276
171
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1277
#ifdef LOONGARCH64MAGIC
1278
      magic = LOONGARCH64MAGIC;
1279
#endif
1280
171
      break;
1281
1282
179
    case IMAGE_FILE_MACHINE_RISCV64:
1283
#ifdef RISCV64MAGIC
1284
      magic = RISCV64MAGIC;
1285
#endif
1286
179
      break;
1287
1288
91
    case IMAGE_FILE_MACHINE_THUMB:
1289
91
#ifdef THUMBPEMAGIC
1290
91
      {
1291
91
  extern const bfd_target TARGET_LITTLE_SYM;
1292
1293
91
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1294
90
    magic = THUMBPEMAGIC;
1295
91
      }
1296
91
#endif
1297
91
      break;
1298
1299
0
    case IMAGE_FILE_MACHINE_POWERPC:
1300
      /* We no longer support PowerPC.  */
1301
441
    default:
1302
441
      _bfd_error_handler
1303
  /* xgettext:c-format */
1304
441
  (_("%pB: unrecognised machine type (0x%x)"
1305
441
     " in Import Library Format archive"),
1306
441
   abfd, machine);
1307
441
      bfd_set_error (bfd_error_malformed_archive);
1308
1309
441
      return NULL;
1310
0
      break;
1311
1.79k
    }
1312
1313
1.35k
  if (magic == 0)
1314
1.11k
    {
1315
1.11k
      _bfd_error_handler
1316
  /* xgettext:c-format */
1317
1.11k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1318
1.11k
     " in Import Library Format archive"),
1319
1.11k
   abfd, machine);
1320
1.11k
      bfd_set_error (bfd_error_wrong_format);
1321
1322
1.11k
      return NULL;
1323
1.11k
    }
1324
1325
  /* We do not bother to check the date.
1326
     date = H_GET_32 (abfd, ptr);  */
1327
236
  ptr += 4;
1328
1329
236
  size = H_GET_32 (abfd, ptr);
1330
236
  ptr += 4;
1331
1332
236
  if (size == 0)
1333
5
    {
1334
5
      _bfd_error_handler
1335
5
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1336
5
      bfd_set_error (bfd_error_malformed_archive);
1337
1338
5
      return NULL;
1339
5
    }
1340
1341
231
  ordinal = H_GET_16 (abfd, ptr);
1342
231
  ptr += 2;
1343
1344
231
  types = H_GET_16 (abfd, ptr);
1345
  /* ptr += 2; */
1346
1347
  /* Now read in the two strings that follow.  */
1348
231
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1349
231
  if (ptr == NULL)
1350
130
    return NULL;
1351
1352
101
  symbol_name = (char *) ptr;
1353
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1354
101
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1355
1356
  /* Verify that the strings are null terminated.  */
1357
101
  if (ptr[size - 1] != 0
1358
87
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1359
19
    {
1360
19
      _bfd_error_handler
1361
19
  (_("%pB: string not null terminated in ILF object file"), abfd);
1362
19
      bfd_set_error (bfd_error_malformed_archive);
1363
19
      bfd_release (abfd, ptr);
1364
19
      return NULL;
1365
19
    }
1366
1367
  /* An ILF file may contain a third string, after source_dll; this is
1368
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1369
     block of data is null terminated, ptr[size-1]==0, but we don't
1370
     know how many individual null terminated strings we have in there.
1371
1372
     First find the end of source_dll.  */
1373
82
  import_name = source_dll + strlen (source_dll) + 1;
1374
82
  if ((bfd_byte *) import_name >= ptr + size)
1375
24
    {
1376
      /* If this points at the end of the ptr+size block, we only had
1377
   two strings. */
1378
24
      import_name = NULL;
1379
24
    }
1380
1381
  /* Now construct the bfd.  */
1382
82
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1383
82
          source_dll, ordinal, types,
1384
82
          import_name))
1385
30
    {
1386
30
      bfd_release (abfd, ptr);
1387
30
      return NULL;
1388
30
    }
1389
1390
52
  return pe_ILF_cleanup;
1391
82
}
pei-arm.c:pe_ILF_object_p
Line
Count
Source
1200
1.82k
{
1201
1.82k
  bfd_byte    buffer[14];
1202
1.82k
  bfd_byte *    ptr;
1203
1.82k
  char *    symbol_name;
1204
1.82k
  char *    source_dll;
1205
1.82k
  char *    import_name;
1206
1.82k
  unsigned int    machine;
1207
1.82k
  bfd_size_type   size;
1208
1.82k
  unsigned int    ordinal;
1209
1.82k
  unsigned int    types;
1210
1.82k
  unsigned int    magic;
1211
1212
  /* Upon entry the first six bytes of the ILF header have
1213
     already been read.  Now read the rest of the header.  */
1214
1.82k
  if (bfd_read (buffer, 14, abfd) != 14)
1215
29
    return NULL;
1216
1217
1.79k
  ptr = buffer;
1218
1219
1.79k
  machine = H_GET_16 (abfd, ptr);
1220
1.79k
  ptr += 2;
1221
1222
  /* Check that the machine type is recognised.  */
1223
1.79k
  magic = 0;
1224
1225
1.79k
  switch (machine)
1226
1.79k
    {
1227
10
    case IMAGE_FILE_MACHINE_UNKNOWN:
1228
16
    case IMAGE_FILE_MACHINE_ALPHA:
1229
21
    case IMAGE_FILE_MACHINE_ALPHA64:
1230
26
    case IMAGE_FILE_MACHINE_IA64:
1231
26
      break;
1232
1233
194
    case IMAGE_FILE_MACHINE_I386:
1234
#ifdef I386MAGIC
1235
      magic = I386MAGIC;
1236
#endif
1237
194
      break;
1238
1239
183
    case IMAGE_FILE_MACHINE_AMD64:
1240
#ifdef AMD64MAGIC
1241
      magic = AMD64MAGIC;
1242
#endif
1243
183
      break;
1244
1245
4
    case IMAGE_FILE_MACHINE_R3000:
1246
9
    case IMAGE_FILE_MACHINE_R4000:
1247
13
    case IMAGE_FILE_MACHINE_R10000:
1248
1249
17
    case IMAGE_FILE_MACHINE_MIPS16:
1250
23
    case IMAGE_FILE_MACHINE_MIPSFPU:
1251
28
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1252
#ifdef MIPS_ARCH_MAGIC_WINCE
1253
      magic = MIPS_ARCH_MAGIC_WINCE;
1254
#endif
1255
28
      break;
1256
1257
75
    case IMAGE_FILE_MACHINE_SH3:
1258
176
    case IMAGE_FILE_MACHINE_SH4:
1259
#ifdef SH_ARCH_MAGIC_WINCE
1260
      magic = SH_ARCH_MAGIC_WINCE;
1261
#endif
1262
176
      break;
1263
1264
148
    case IMAGE_FILE_MACHINE_ARM:
1265
148
#ifdef ARMPEMAGIC
1266
148
      magic = ARMPEMAGIC;
1267
148
#endif
1268
148
      break;
1269
1270
156
    case IMAGE_FILE_MACHINE_ARM64:
1271
#ifdef AARCH64MAGIC
1272
      magic = AARCH64MAGIC;
1273
#endif
1274
156
      break;
1275
1276
171
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1277
#ifdef LOONGARCH64MAGIC
1278
      magic = LOONGARCH64MAGIC;
1279
#endif
1280
171
      break;
1281
1282
179
    case IMAGE_FILE_MACHINE_RISCV64:
1283
#ifdef RISCV64MAGIC
1284
      magic = RISCV64MAGIC;
1285
#endif
1286
179
      break;
1287
1288
91
    case IMAGE_FILE_MACHINE_THUMB:
1289
91
#ifdef THUMBPEMAGIC
1290
91
      {
1291
91
  extern const bfd_target TARGET_LITTLE_SYM;
1292
1293
91
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1294
90
    magic = THUMBPEMAGIC;
1295
91
      }
1296
91
#endif
1297
91
      break;
1298
1299
0
    case IMAGE_FILE_MACHINE_POWERPC:
1300
      /* We no longer support PowerPC.  */
1301
441
    default:
1302
441
      _bfd_error_handler
1303
  /* xgettext:c-format */
1304
441
  (_("%pB: unrecognised machine type (0x%x)"
1305
441
     " in Import Library Format archive"),
1306
441
   abfd, machine);
1307
441
      bfd_set_error (bfd_error_malformed_archive);
1308
1309
441
      return NULL;
1310
0
      break;
1311
1.79k
    }
1312
1313
1.35k
  if (magic == 0)
1314
1.11k
    {
1315
1.11k
      _bfd_error_handler
1316
  /* xgettext:c-format */
1317
1.11k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1318
1.11k
     " in Import Library Format archive"),
1319
1.11k
   abfd, machine);
1320
1.11k
      bfd_set_error (bfd_error_wrong_format);
1321
1322
1.11k
      return NULL;
1323
1.11k
    }
1324
1325
  /* We do not bother to check the date.
1326
     date = H_GET_32 (abfd, ptr);  */
1327
238
  ptr += 4;
1328
1329
238
  size = H_GET_32 (abfd, ptr);
1330
238
  ptr += 4;
1331
1332
238
  if (size == 0)
1333
5
    {
1334
5
      _bfd_error_handler
1335
5
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1336
5
      bfd_set_error (bfd_error_malformed_archive);
1337
1338
5
      return NULL;
1339
5
    }
1340
1341
233
  ordinal = H_GET_16 (abfd, ptr);
1342
233
  ptr += 2;
1343
1344
233
  types = H_GET_16 (abfd, ptr);
1345
  /* ptr += 2; */
1346
1347
  /* Now read in the two strings that follow.  */
1348
233
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1349
233
  if (ptr == NULL)
1350
130
    return NULL;
1351
1352
103
  symbol_name = (char *) ptr;
1353
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1354
103
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1355
1356
  /* Verify that the strings are null terminated.  */
1357
103
  if (ptr[size - 1] != 0
1358
89
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1359
19
    {
1360
19
      _bfd_error_handler
1361
19
  (_("%pB: string not null terminated in ILF object file"), abfd);
1362
19
      bfd_set_error (bfd_error_malformed_archive);
1363
19
      bfd_release (abfd, ptr);
1364
19
      return NULL;
1365
19
    }
1366
1367
  /* An ILF file may contain a third string, after source_dll; this is
1368
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1369
     block of data is null terminated, ptr[size-1]==0, but we don't
1370
     know how many individual null terminated strings we have in there.
1371
1372
     First find the end of source_dll.  */
1373
84
  import_name = source_dll + strlen (source_dll) + 1;
1374
84
  if ((bfd_byte *) import_name >= ptr + size)
1375
25
    {
1376
      /* If this points at the end of the ptr+size block, we only had
1377
   two strings. */
1378
25
      import_name = NULL;
1379
25
    }
1380
1381
  /* Now construct the bfd.  */
1382
84
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1383
84
          source_dll, ordinal, types,
1384
84
          import_name))
1385
30
    {
1386
30
      bfd_release (abfd, ptr);
1387
30
      return NULL;
1388
30
    }
1389
1390
54
  return pe_ILF_cleanup;
1391
84
}
pei-mcore.c:pe_ILF_object_p
Line
Count
Source
1200
1.81k
{
1201
1.81k
  bfd_byte    buffer[14];
1202
1.81k
  bfd_byte *    ptr;
1203
1.81k
  char *    symbol_name;
1204
1.81k
  char *    source_dll;
1205
1.81k
  char *    import_name;
1206
1.81k
  unsigned int    machine;
1207
1.81k
  bfd_size_type   size;
1208
1.81k
  unsigned int    ordinal;
1209
1.81k
  unsigned int    types;
1210
1.81k
  unsigned int    magic;
1211
1212
  /* Upon entry the first six bytes of the ILF header have
1213
     already been read.  Now read the rest of the header.  */
1214
1.81k
  if (bfd_read (buffer, 14, abfd) != 14)
1215
29
    return NULL;
1216
1217
1.78k
  ptr = buffer;
1218
1219
1.78k
  machine = H_GET_16 (abfd, ptr);
1220
1.78k
  ptr += 2;
1221
1222
  /* Check that the machine type is recognised.  */
1223
1.78k
  magic = 0;
1224
1225
1.78k
  switch (machine)
1226
1.78k
    {
1227
10
    case IMAGE_FILE_MACHINE_UNKNOWN:
1228
16
    case IMAGE_FILE_MACHINE_ALPHA:
1229
21
    case IMAGE_FILE_MACHINE_ALPHA64:
1230
26
    case IMAGE_FILE_MACHINE_IA64:
1231
26
      break;
1232
1233
191
    case IMAGE_FILE_MACHINE_I386:
1234
#ifdef I386MAGIC
1235
      magic = I386MAGIC;
1236
#endif
1237
191
      break;
1238
1239
183
    case IMAGE_FILE_MACHINE_AMD64:
1240
#ifdef AMD64MAGIC
1241
      magic = AMD64MAGIC;
1242
#endif
1243
183
      break;
1244
1245
4
    case IMAGE_FILE_MACHINE_R3000:
1246
9
    case IMAGE_FILE_MACHINE_R4000:
1247
13
    case IMAGE_FILE_MACHINE_R10000:
1248
1249
17
    case IMAGE_FILE_MACHINE_MIPS16:
1250
23
    case IMAGE_FILE_MACHINE_MIPSFPU:
1251
28
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1252
#ifdef MIPS_ARCH_MAGIC_WINCE
1253
      magic = MIPS_ARCH_MAGIC_WINCE;
1254
#endif
1255
28
      break;
1256
1257
75
    case IMAGE_FILE_MACHINE_SH3:
1258
176
    case IMAGE_FILE_MACHINE_SH4:
1259
#ifdef SH_ARCH_MAGIC_WINCE
1260
      magic = SH_ARCH_MAGIC_WINCE;
1261
#endif
1262
176
      break;
1263
1264
146
    case IMAGE_FILE_MACHINE_ARM:
1265
#ifdef ARMPEMAGIC
1266
      magic = ARMPEMAGIC;
1267
#endif
1268
146
      break;
1269
1270
156
    case IMAGE_FILE_MACHINE_ARM64:
1271
#ifdef AARCH64MAGIC
1272
      magic = AARCH64MAGIC;
1273
#endif
1274
156
      break;
1275
1276
171
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1277
#ifdef LOONGARCH64MAGIC
1278
      magic = LOONGARCH64MAGIC;
1279
#endif
1280
171
      break;
1281
1282
179
    case IMAGE_FILE_MACHINE_RISCV64:
1283
#ifdef RISCV64MAGIC
1284
      magic = RISCV64MAGIC;
1285
#endif
1286
179
      break;
1287
1288
91
    case IMAGE_FILE_MACHINE_THUMB:
1289
#ifdef THUMBPEMAGIC
1290
      {
1291
  extern const bfd_target TARGET_LITTLE_SYM;
1292
1293
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1294
    magic = THUMBPEMAGIC;
1295
      }
1296
#endif
1297
91
      break;
1298
1299
0
    case IMAGE_FILE_MACHINE_POWERPC:
1300
      /* We no longer support PowerPC.  */
1301
441
    default:
1302
441
      _bfd_error_handler
1303
  /* xgettext:c-format */
1304
441
  (_("%pB: unrecognised machine type (0x%x)"
1305
441
     " in Import Library Format archive"),
1306
441
   abfd, machine);
1307
441
      bfd_set_error (bfd_error_malformed_archive);
1308
1309
441
      return NULL;
1310
0
      break;
1311
1.78k
    }
1312
1313
1.34k
  if (magic == 0)
1314
1.34k
    {
1315
1.34k
      _bfd_error_handler
1316
  /* xgettext:c-format */
1317
1.34k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1318
1.34k
     " in Import Library Format archive"),
1319
1.34k
   abfd, machine);
1320
1.34k
      bfd_set_error (bfd_error_wrong_format);
1321
1322
1.34k
      return NULL;
1323
1.34k
    }
1324
1325
  /* We do not bother to check the date.
1326
     date = H_GET_32 (abfd, ptr);  */
1327
0
  ptr += 4;
1328
1329
0
  size = H_GET_32 (abfd, ptr);
1330
0
  ptr += 4;
1331
1332
0
  if (size == 0)
1333
0
    {
1334
0
      _bfd_error_handler
1335
0
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1336
0
      bfd_set_error (bfd_error_malformed_archive);
1337
1338
0
      return NULL;
1339
0
    }
1340
1341
0
  ordinal = H_GET_16 (abfd, ptr);
1342
0
  ptr += 2;
1343
1344
0
  types = H_GET_16 (abfd, ptr);
1345
  /* ptr += 2; */
1346
1347
  /* Now read in the two strings that follow.  */
1348
0
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1349
0
  if (ptr == NULL)
1350
0
    return NULL;
1351
1352
0
  symbol_name = (char *) ptr;
1353
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1354
0
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1355
1356
  /* Verify that the strings are null terminated.  */
1357
0
  if (ptr[size - 1] != 0
1358
0
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1359
0
    {
1360
0
      _bfd_error_handler
1361
0
  (_("%pB: string not null terminated in ILF object file"), abfd);
1362
0
      bfd_set_error (bfd_error_malformed_archive);
1363
0
      bfd_release (abfd, ptr);
1364
0
      return NULL;
1365
0
    }
1366
1367
  /* An ILF file may contain a third string, after source_dll; this is
1368
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1369
     block of data is null terminated, ptr[size-1]==0, but we don't
1370
     know how many individual null terminated strings we have in there.
1371
1372
     First find the end of source_dll.  */
1373
0
  import_name = source_dll + strlen (source_dll) + 1;
1374
0
  if ((bfd_byte *) import_name >= ptr + size)
1375
0
    {
1376
      /* If this points at the end of the ptr+size block, we only had
1377
   two strings. */
1378
0
      import_name = NULL;
1379
0
    }
1380
1381
  /* Now construct the bfd.  */
1382
0
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1383
0
          source_dll, ordinal, types,
1384
0
          import_name))
1385
0
    {
1386
0
      bfd_release (abfd, ptr);
1387
0
      return NULL;
1388
0
    }
1389
1390
0
  return pe_ILF_cleanup;
1391
0
}
pei-sh.c:pe_ILF_object_p
Line
Count
Source
1200
1.82k
{
1201
1.82k
  bfd_byte    buffer[14];
1202
1.82k
  bfd_byte *    ptr;
1203
1.82k
  char *    symbol_name;
1204
1.82k
  char *    source_dll;
1205
1.82k
  char *    import_name;
1206
1.82k
  unsigned int    machine;
1207
1.82k
  bfd_size_type   size;
1208
1.82k
  unsigned int    ordinal;
1209
1.82k
  unsigned int    types;
1210
1.82k
  unsigned int    magic;
1211
1212
  /* Upon entry the first six bytes of the ILF header have
1213
     already been read.  Now read the rest of the header.  */
1214
1.82k
  if (bfd_read (buffer, 14, abfd) != 14)
1215
23
    return NULL;
1216
1217
1.79k
  ptr = buffer;
1218
1219
1.79k
  machine = H_GET_16 (abfd, ptr);
1220
1.79k
  ptr += 2;
1221
1222
  /* Check that the machine type is recognised.  */
1223
1.79k
  magic = 0;
1224
1225
1.79k
  switch (machine)
1226
1.79k
    {
1227
6
    case IMAGE_FILE_MACHINE_UNKNOWN:
1228
12
    case IMAGE_FILE_MACHINE_ALPHA:
1229
17
    case IMAGE_FILE_MACHINE_ALPHA64:
1230
22
    case IMAGE_FILE_MACHINE_IA64:
1231
22
      break;
1232
1233
191
    case IMAGE_FILE_MACHINE_I386:
1234
#ifdef I386MAGIC
1235
      magic = I386MAGIC;
1236
#endif
1237
191
      break;
1238
1239
183
    case IMAGE_FILE_MACHINE_AMD64:
1240
#ifdef AMD64MAGIC
1241
      magic = AMD64MAGIC;
1242
#endif
1243
183
      break;
1244
1245
4
    case IMAGE_FILE_MACHINE_R3000:
1246
9
    case IMAGE_FILE_MACHINE_R4000:
1247
13
    case IMAGE_FILE_MACHINE_R10000:
1248
1249
17
    case IMAGE_FILE_MACHINE_MIPS16:
1250
23
    case IMAGE_FILE_MACHINE_MIPSFPU:
1251
28
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1252
#ifdef MIPS_ARCH_MAGIC_WINCE
1253
      magic = MIPS_ARCH_MAGIC_WINCE;
1254
#endif
1255
28
      break;
1256
1257
94
    case IMAGE_FILE_MACHINE_SH3:
1258
217
    case IMAGE_FILE_MACHINE_SH4:
1259
217
#ifdef SH_ARCH_MAGIC_WINCE
1260
217
      magic = SH_ARCH_MAGIC_WINCE;
1261
217
#endif
1262
217
      break;
1263
1264
134
    case IMAGE_FILE_MACHINE_ARM:
1265
#ifdef ARMPEMAGIC
1266
      magic = ARMPEMAGIC;
1267
#endif
1268
134
      break;
1269
1270
156
    case IMAGE_FILE_MACHINE_ARM64:
1271
#ifdef AARCH64MAGIC
1272
      magic = AARCH64MAGIC;
1273
#endif
1274
156
      break;
1275
1276
171
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1277
#ifdef LOONGARCH64MAGIC
1278
      magic = LOONGARCH64MAGIC;
1279
#endif
1280
171
      break;
1281
1282
177
    case IMAGE_FILE_MACHINE_RISCV64:
1283
#ifdef RISCV64MAGIC
1284
      magic = RISCV64MAGIC;
1285
#endif
1286
177
      break;
1287
1288
90
    case IMAGE_FILE_MACHINE_THUMB:
1289
#ifdef THUMBPEMAGIC
1290
      {
1291
  extern const bfd_target TARGET_LITTLE_SYM;
1292
1293
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1294
    magic = THUMBPEMAGIC;
1295
      }
1296
#endif
1297
90
      break;
1298
1299
0
    case IMAGE_FILE_MACHINE_POWERPC:
1300
      /* We no longer support PowerPC.  */
1301
428
    default:
1302
428
      _bfd_error_handler
1303
  /* xgettext:c-format */
1304
428
  (_("%pB: unrecognised machine type (0x%x)"
1305
428
     " in Import Library Format archive"),
1306
428
   abfd, machine);
1307
428
      bfd_set_error (bfd_error_malformed_archive);
1308
1309
428
      return NULL;
1310
0
      break;
1311
1.79k
    }
1312
1313
1.36k
  if (magic == 0)
1314
1.15k
    {
1315
1.15k
      _bfd_error_handler
1316
  /* xgettext:c-format */
1317
1.15k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1318
1.15k
     " in Import Library Format archive"),
1319
1.15k
   abfd, machine);
1320
1.15k
      bfd_set_error (bfd_error_wrong_format);
1321
1322
1.15k
      return NULL;
1323
1.15k
    }
1324
1325
  /* We do not bother to check the date.
1326
     date = H_GET_32 (abfd, ptr);  */
1327
217
  ptr += 4;
1328
1329
217
  size = H_GET_32 (abfd, ptr);
1330
217
  ptr += 4;
1331
1332
217
  if (size == 0)
1333
5
    {
1334
5
      _bfd_error_handler
1335
5
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1336
5
      bfd_set_error (bfd_error_malformed_archive);
1337
1338
5
      return NULL;
1339
5
    }
1340
1341
212
  ordinal = H_GET_16 (abfd, ptr);
1342
212
  ptr += 2;
1343
1344
212
  types = H_GET_16 (abfd, ptr);
1345
  /* ptr += 2; */
1346
1347
  /* Now read in the two strings that follow.  */
1348
212
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1349
212
  if (ptr == NULL)
1350
82
    return NULL;
1351
1352
130
  symbol_name = (char *) ptr;
1353
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1354
130
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1355
1356
  /* Verify that the strings are null terminated.  */
1357
130
  if (ptr[size - 1] != 0
1358
119
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1359
16
    {
1360
16
      _bfd_error_handler
1361
16
  (_("%pB: string not null terminated in ILF object file"), abfd);
1362
16
      bfd_set_error (bfd_error_malformed_archive);
1363
16
      bfd_release (abfd, ptr);
1364
16
      return NULL;
1365
16
    }
1366
1367
  /* An ILF file may contain a third string, after source_dll; this is
1368
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1369
     block of data is null terminated, ptr[size-1]==0, but we don't
1370
     know how many individual null terminated strings we have in there.
1371
1372
     First find the end of source_dll.  */
1373
114
  import_name = source_dll + strlen (source_dll) + 1;
1374
114
  if ((bfd_byte *) import_name >= ptr + size)
1375
40
    {
1376
      /* If this points at the end of the ptr+size block, we only had
1377
   two strings. */
1378
40
      import_name = NULL;
1379
40
    }
1380
1381
  /* Now construct the bfd.  */
1382
114
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1383
114
          source_dll, ordinal, types,
1384
114
          import_name))
1385
29
    {
1386
29
      bfd_release (abfd, ptr);
1387
29
      return NULL;
1388
29
    }
1389
1390
85
  return pe_ILF_cleanup;
1391
114
}
1392
1393
static void
1394
pe_bfd_read_buildid (bfd *abfd)
1395
38.4k
{
1396
38.4k
  pe_data_type *pe = pe_data (abfd);
1397
38.4k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
38.4k
  asection *section;
1399
38.4k
  bfd_byte *data = 0;
1400
38.4k
  bfd_size_type dataoff;
1401
38.4k
  unsigned int i;
1402
38.4k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
38.4k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
38.4k
  if (size == 0)
1406
21.2k
    return;
1407
1408
17.2k
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
112k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
103k
    {
1413
103k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
8.33k
  break;
1415
103k
    }
1416
1417
17.2k
  if (section == NULL)
1418
8.88k
    return;
1419
1420
8.33k
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
361
    return;
1422
1423
7.97k
  dataoff = addr - section->vma;
1424
1425
  /* PR 20605 and 22373: Make sure that the data is really there.
1426
     Note - since we are dealing with unsigned quantities we have
1427
     to be careful to check for potential overflows.  */
1428
7.97k
  if (dataoff >= section->size
1429
7.97k
      || size > section->size - dataoff)
1430
2.95k
    {
1431
2.95k
      _bfd_error_handler
1432
2.95k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
2.95k
   abfd);
1434
2.95k
      return;
1435
2.95k
    }
1436
1437
  /* Read the whole section. */
1438
5.01k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
1.49k
    {
1440
1.49k
      free (data);
1441
1.49k
      return;
1442
1.49k
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
241k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
239k
    {
1447
239k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
239k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
239k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
239k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
239k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
1.47k
  {
1455
1.47k
    char buffer[256 + 1];
1456
1.47k
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1457
1458
    /*
1459
      The debug entry doesn't have to have to be in a section, in which
1460
      case AddressOfRawData is 0, so always use PointerToRawData.
1461
    */
1462
1.47k
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
1.47k
                (file_ptr) idd.PointerToRawData,
1464
1.47k
                idd.SizeOfData, cvinfo, NULL))
1465
112
      {
1466
112
        struct bfd_build_id *build_id;
1467
112
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1468
1469
112
        build_id = bfd_alloc (abfd, bidlen);
1470
112
        if (build_id)
1471
112
    {
1472
112
      build_id->size = cvinfo->SignatureLength;
1473
112
      memcpy(build_id->data, cvinfo->Signature,
1474
112
       cvinfo->SignatureLength);
1475
112
      abfd->build_id = build_id;
1476
112
    }
1477
112
      }
1478
1.47k
    break;
1479
1.47k
  }
1480
239k
    }
1481
1482
3.52k
  free (data);
1483
3.52k
}
pei-i386.c:pe_bfd_read_buildid
Line
Count
Source
1395
7.28k
{
1396
7.28k
  pe_data_type *pe = pe_data (abfd);
1397
7.28k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
7.28k
  asection *section;
1399
7.28k
  bfd_byte *data = 0;
1400
7.28k
  bfd_size_type dataoff;
1401
7.28k
  unsigned int i;
1402
7.28k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
7.28k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
7.28k
  if (size == 0)
1406
5.58k
    return;
1407
1408
1.70k
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
12.1k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
11.3k
    {
1413
11.3k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
822
  break;
1415
11.3k
    }
1416
1417
1.70k
  if (section == NULL)
1418
879
    return;
1419
1420
822
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
66
    return;
1422
1423
756
  dataoff = addr - section->vma;
1424
1425
  /* PR 20605 and 22373: Make sure that the data is really there.
1426
     Note - since we are dealing with unsigned quantities we have
1427
     to be careful to check for potential overflows.  */
1428
756
  if (dataoff >= section->size
1429
756
      || size > section->size - dataoff)
1430
353
    {
1431
353
      _bfd_error_handler
1432
353
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
353
   abfd);
1434
353
      return;
1435
353
    }
1436
1437
  /* Read the whole section. */
1438
403
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
157
    {
1440
157
      free (data);
1441
157
      return;
1442
157
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
5.51k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
5.42k
    {
1447
5.42k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
5.42k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
5.42k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
5.42k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
5.42k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
153
  {
1455
153
    char buffer[256 + 1];
1456
153
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1457
1458
    /*
1459
      The debug entry doesn't have to have to be in a section, in which
1460
      case AddressOfRawData is 0, so always use PointerToRawData.
1461
    */
1462
153
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
153
                (file_ptr) idd.PointerToRawData,
1464
153
                idd.SizeOfData, cvinfo, NULL))
1465
15
      {
1466
15
        struct bfd_build_id *build_id;
1467
15
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1468
1469
15
        build_id = bfd_alloc (abfd, bidlen);
1470
15
        if (build_id)
1471
15
    {
1472
15
      build_id->size = cvinfo->SignatureLength;
1473
15
      memcpy(build_id->data, cvinfo->Signature,
1474
15
       cvinfo->SignatureLength);
1475
15
      abfd->build_id = build_id;
1476
15
    }
1477
15
      }
1478
153
    break;
1479
153
  }
1480
5.42k
    }
1481
1482
246
  free (data);
1483
246
}
pei-x86_64.c:pe_bfd_read_buildid
Line
Count
Source
1395
5.63k
{
1396
5.63k
  pe_data_type *pe = pe_data (abfd);
1397
5.63k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
5.63k
  asection *section;
1399
5.63k
  bfd_byte *data = 0;
1400
5.63k
  bfd_size_type dataoff;
1401
5.63k
  unsigned int i;
1402
5.63k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
5.63k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
5.63k
  if (size == 0)
1406
3.14k
    return;
1407
1408
2.48k
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
22.8k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
21.3k
    {
1413
21.3k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
1.02k
  break;
1415
21.3k
    }
1416
1417
2.48k
  if (section == NULL)
1418
1.46k
    return;
1419
1420
1.02k
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
34
    return;
1422
1423
986
  dataoff = addr - section->vma;
1424
1425
  /* PR 20605 and 22373: Make sure that the data is really there.
1426
     Note - since we are dealing with unsigned quantities we have
1427
     to be careful to check for potential overflows.  */
1428
986
  if (dataoff >= section->size
1429
986
      || size > section->size - dataoff)
1430
394
    {
1431
394
      _bfd_error_handler
1432
394
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
394
   abfd);
1434
394
      return;
1435
394
    }
1436
1437
  /* Read the whole section. */
1438
592
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
245
    {
1440
245
      free (data);
1441
245
      return;
1442
245
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
13.2k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
13.1k
    {
1447
13.1k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
13.1k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
13.1k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
13.1k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
13.1k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
232
  {
1455
232
    char buffer[256 + 1];
1456
232
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1457
1458
    /*
1459
      The debug entry doesn't have to have to be in a section, in which
1460
      case AddressOfRawData is 0, so always use PointerToRawData.
1461
    */
1462
232
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
232
                (file_ptr) idd.PointerToRawData,
1464
232
                idd.SizeOfData, cvinfo, NULL))
1465
29
      {
1466
29
        struct bfd_build_id *build_id;
1467
29
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1468
1469
29
        build_id = bfd_alloc (abfd, bidlen);
1470
29
        if (build_id)
1471
29
    {
1472
29
      build_id->size = cvinfo->SignatureLength;
1473
29
      memcpy(build_id->data, cvinfo->Signature,
1474
29
       cvinfo->SignatureLength);
1475
29
      abfd->build_id = build_id;
1476
29
    }
1477
29
      }
1478
232
    break;
1479
232
  }
1480
13.1k
    }
1481
1482
347
  free (data);
1483
347
}
pei-aarch64.c:pe_bfd_read_buildid
Line
Count
Source
1395
4.77k
{
1396
4.77k
  pe_data_type *pe = pe_data (abfd);
1397
4.77k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
4.77k
  asection *section;
1399
4.77k
  bfd_byte *data = 0;
1400
4.77k
  bfd_size_type dataoff;
1401
4.77k
  unsigned int i;
1402
4.77k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
4.77k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
4.77k
  if (size == 0)
1406
1.57k
    return;
1407
1408
3.20k
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
19.6k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
18.6k
    {
1413
18.6k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
2.14k
  break;
1415
18.6k
    }
1416
1417
3.20k
  if (section == NULL)
1418
1.05k
    return;
1419
1420
2.14k
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
26
    return;
1422
1423
2.12k
  dataoff = addr - section->vma;
1424
1425
  /* PR 20605 and 22373: Make sure that the data is really there.
1426
     Note - since we are dealing with unsigned quantities we have
1427
     to be careful to check for potential overflows.  */
1428
2.12k
  if (dataoff >= section->size
1429
2.12k
      || size > section->size - dataoff)
1430
209
    {
1431
209
      _bfd_error_handler
1432
209
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
209
   abfd);
1434
209
      return;
1435
209
    }
1436
1437
  /* Read the whole section. */
1438
1.91k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
270
    {
1440
270
      free (data);
1441
270
      return;
1442
270
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
189k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
188k
    {
1447
188k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
188k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
188k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
188k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
188k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
454
  {
1455
454
    char buffer[256 + 1];
1456
454
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1457
1458
    /*
1459
      The debug entry doesn't have to have to be in a section, in which
1460
      case AddressOfRawData is 0, so always use PointerToRawData.
1461
    */
1462
454
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
454
                (file_ptr) idd.PointerToRawData,
1464
454
                idd.SizeOfData, cvinfo, NULL))
1465
7
      {
1466
7
        struct bfd_build_id *build_id;
1467
7
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1468
1469
7
        build_id = bfd_alloc (abfd, bidlen);
1470
7
        if (build_id)
1471
7
    {
1472
7
      build_id->size = cvinfo->SignatureLength;
1473
7
      memcpy(build_id->data, cvinfo->Signature,
1474
7
       cvinfo->SignatureLength);
1475
7
      abfd->build_id = build_id;
1476
7
    }
1477
7
      }
1478
454
    break;
1479
454
  }
1480
188k
    }
1481
1482
1.64k
  free (data);
1483
1.64k
}
pei-ia64.c:pe_bfd_read_buildid
Line
Count
Source
1395
3.30k
{
1396
3.30k
  pe_data_type *pe = pe_data (abfd);
1397
3.30k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
3.30k
  asection *section;
1399
3.30k
  bfd_byte *data = 0;
1400
3.30k
  bfd_size_type dataoff;
1401
3.30k
  unsigned int i;
1402
3.30k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
3.30k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
3.30k
  if (size == 0)
1406
2.21k
    return;
1407
1408
1.09k
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
4.95k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
4.28k
    {
1413
4.28k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
426
  break;
1415
4.28k
    }
1416
1417
1.09k
  if (section == NULL)
1418
668
    return;
1419
1420
426
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
24
    return;
1422
1423
402
  dataoff = addr - section->vma;
1424
1425
  /* PR 20605 and 22373: Make sure that the data is really there.
1426
     Note - since we are dealing with unsigned quantities we have
1427
     to be careful to check for potential overflows.  */
1428
402
  if (dataoff >= section->size
1429
402
      || size > section->size - dataoff)
1430
164
    {
1431
164
      _bfd_error_handler
1432
164
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
164
   abfd);
1434
164
      return;
1435
164
    }
1436
1437
  /* Read the whole section. */
1438
238
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
77
    {
1440
77
      free (data);
1441
77
      return;
1442
77
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
3.01k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
2.96k
    {
1447
2.96k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
2.96k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
2.96k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
2.96k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
2.96k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
109
  {
1455
109
    char buffer[256 + 1];
1456
109
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1457
1458
    /*
1459
      The debug entry doesn't have to have to be in a section, in which
1460
      case AddressOfRawData is 0, so always use PointerToRawData.
1461
    */
1462
109
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
109
                (file_ptr) idd.PointerToRawData,
1464
109
                idd.SizeOfData, cvinfo, NULL))
1465
1
      {
1466
1
        struct bfd_build_id *build_id;
1467
1
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1468
1469
1
        build_id = bfd_alloc (abfd, bidlen);
1470
1
        if (build_id)
1471
1
    {
1472
1
      build_id->size = cvinfo->SignatureLength;
1473
1
      memcpy(build_id->data, cvinfo->Signature,
1474
1
       cvinfo->SignatureLength);
1475
1
      abfd->build_id = build_id;
1476
1
    }
1477
1
      }
1478
109
    break;
1479
109
  }
1480
2.96k
    }
1481
1482
161
  free (data);
1483
161
}
pei-loongarch64.c:pe_bfd_read_buildid
Line
Count
Source
1395
3.06k
{
1396
3.06k
  pe_data_type *pe = pe_data (abfd);
1397
3.06k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
3.06k
  asection *section;
1399
3.06k
  bfd_byte *data = 0;
1400
3.06k
  bfd_size_type dataoff;
1401
3.06k
  unsigned int i;
1402
3.06k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
3.06k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
3.06k
  if (size == 0)
1406
1.85k
    return;
1407
1408
1.20k
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
8.48k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
7.78k
    {
1413
7.78k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
501
  break;
1415
7.78k
    }
1416
1417
1.20k
  if (section == NULL)
1418
703
    return;
1419
1420
501
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
23
    return;
1422
1423
478
  dataoff = addr - section->vma;
1424
1425
  /* PR 20605 and 22373: Make sure that the data is really there.
1426
     Note - since we are dealing with unsigned quantities we have
1427
     to be careful to check for potential overflows.  */
1428
478
  if (dataoff >= section->size
1429
478
      || size > section->size - dataoff)
1430
212
    {
1431
212
      _bfd_error_handler
1432
212
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
212
   abfd);
1434
212
      return;
1435
212
    }
1436
1437
  /* Read the whole section. */
1438
266
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
49
    {
1440
49
      free (data);
1441
49
      return;
1442
49
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
8.73k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
8.64k
    {
1447
8.64k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
8.64k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
8.64k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
8.64k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
8.64k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
128
  {
1455
128
    char buffer[256 + 1];
1456
128
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1457
1458
    /*
1459
      The debug entry doesn't have to have to be in a section, in which
1460
      case AddressOfRawData is 0, so always use PointerToRawData.
1461
    */
1462
128
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
128
                (file_ptr) idd.PointerToRawData,
1464
128
                idd.SizeOfData, cvinfo, NULL))
1465
6
      {
1466
6
        struct bfd_build_id *build_id;
1467
6
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1468
1469
6
        build_id = bfd_alloc (abfd, bidlen);
1470
6
        if (build_id)
1471
6
    {
1472
6
      build_id->size = cvinfo->SignatureLength;
1473
6
      memcpy(build_id->data, cvinfo->Signature,
1474
6
       cvinfo->SignatureLength);
1475
6
      abfd->build_id = build_id;
1476
6
    }
1477
6
      }
1478
128
    break;
1479
128
  }
1480
8.64k
    }
1481
1482
217
  free (data);
1483
217
}
pei-riscv64.c:pe_bfd_read_buildid
Line
Count
Source
1395
3.62k
{
1396
3.62k
  pe_data_type *pe = pe_data (abfd);
1397
3.62k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
3.62k
  asection *section;
1399
3.62k
  bfd_byte *data = 0;
1400
3.62k
  bfd_size_type dataoff;
1401
3.62k
  unsigned int i;
1402
3.62k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
3.62k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
3.62k
  if (size == 0)
1406
1.72k
    return;
1407
1408
1.90k
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
15.6k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
14.3k
    {
1413
14.3k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
641
  break;
1415
14.3k
    }
1416
1417
1.90k
  if (section == NULL)
1418
1.26k
    return;
1419
1420
641
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
30
    return;
1422
1423
611
  dataoff = addr - section->vma;
1424
1425
  /* PR 20605 and 22373: Make sure that the data is really there.
1426
     Note - since we are dealing with unsigned quantities we have
1427
     to be careful to check for potential overflows.  */
1428
611
  if (dataoff >= section->size
1429
611
      || size > section->size - dataoff)
1430
350
    {
1431
350
      _bfd_error_handler
1432
350
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
350
   abfd);
1434
350
      return;
1435
350
    }
1436
1437
  /* Read the whole section. */
1438
261
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
109
    {
1440
109
      free (data);
1441
109
      return;
1442
109
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
2.06k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
2.01k
    {
1447
2.01k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
2.01k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
2.01k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
2.01k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
2.01k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
109
  {
1455
109
    char buffer[256 + 1];
1456
109
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1457
1458
    /*
1459
      The debug entry doesn't have to have to be in a section, in which
1460
      case AddressOfRawData is 0, so always use PointerToRawData.
1461
    */
1462
109
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
109
                (file_ptr) idd.PointerToRawData,
1464
109
                idd.SizeOfData, cvinfo, NULL))
1465
5
      {
1466
5
        struct bfd_build_id *build_id;
1467
5
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1468
1469
5
        build_id = bfd_alloc (abfd, bidlen);
1470
5
        if (build_id)
1471
5
    {
1472
5
      build_id->size = cvinfo->SignatureLength;
1473
5
      memcpy(build_id->data, cvinfo->Signature,
1474
5
       cvinfo->SignatureLength);
1475
5
      abfd->build_id = build_id;
1476
5
    }
1477
5
      }
1478
109
    break;
1479
109
  }
1480
2.01k
    }
1481
1482
152
  free (data);
1483
152
}
pei-arm-wince.c:pe_bfd_read_buildid
Line
Count
Source
1395
2.26k
{
1396
2.26k
  pe_data_type *pe = pe_data (abfd);
1397
2.26k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
2.26k
  asection *section;
1399
2.26k
  bfd_byte *data = 0;
1400
2.26k
  bfd_size_type dataoff;
1401
2.26k
  unsigned int i;
1402
2.26k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
2.26k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
2.26k
  if (size == 0)
1406
835
    return;
1407
1408
1.42k
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
5.74k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
5.00k
    {
1413
5.00k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
681
  break;
1415
5.00k
    }
1416
1417
1.42k
  if (section == NULL)
1418
746
    return;
1419
1420
681
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
37
    return;
1422
1423
644
  dataoff = addr - section->vma;
1424
1425
  /* PR 20605 and 22373: Make sure that the data is really there.
1426
     Note - since we are dealing with unsigned quantities we have
1427
     to be careful to check for potential overflows.  */
1428
644
  if (dataoff >= section->size
1429
644
      || size > section->size - dataoff)
1430
355
    {
1431
355
      _bfd_error_handler
1432
355
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
355
   abfd);
1434
355
      return;
1435
355
    }
1436
1437
  /* Read the whole section. */
1438
289
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
141
    {
1440
141
      free (data);
1441
141
      return;
1442
141
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
3.02k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
2.93k
    {
1447
2.93k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
2.93k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
2.93k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
2.93k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
2.93k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
56
  {
1455
56
    char buffer[256 + 1];
1456
56
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1457
1458
    /*
1459
      The debug entry doesn't have to have to be in a section, in which
1460
      case AddressOfRawData is 0, so always use PointerToRawData.
1461
    */
1462
56
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
56
                (file_ptr) idd.PointerToRawData,
1464
56
                idd.SizeOfData, cvinfo, NULL))
1465
4
      {
1466
4
        struct bfd_build_id *build_id;
1467
4
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1468
1469
4
        build_id = bfd_alloc (abfd, bidlen);
1470
4
        if (build_id)
1471
4
    {
1472
4
      build_id->size = cvinfo->SignatureLength;
1473
4
      memcpy(build_id->data, cvinfo->Signature,
1474
4
       cvinfo->SignatureLength);
1475
4
      abfd->build_id = build_id;
1476
4
    }
1477
4
      }
1478
56
    break;
1479
56
  }
1480
2.93k
    }
1481
1482
148
  free (data);
1483
148
}
pei-arm.c:pe_bfd_read_buildid
Line
Count
Source
1395
3.14k
{
1396
3.14k
  pe_data_type *pe = pe_data (abfd);
1397
3.14k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
3.14k
  asection *section;
1399
3.14k
  bfd_byte *data = 0;
1400
3.14k
  bfd_size_type dataoff;
1401
3.14k
  unsigned int i;
1402
3.14k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
3.14k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
3.14k
  if (size == 0)
1406
1.37k
    return;
1407
1408
1.77k
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
9.24k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
8.39k
    {
1413
8.39k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
926
  break;
1415
8.39k
    }
1416
1417
1.77k
  if (section == NULL)
1418
851
    return;
1419
1420
926
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
44
    return;
1422
1423
882
  dataoff = addr - section->vma;
1424
1425
  /* PR 20605 and 22373: Make sure that the data is really there.
1426
     Note - since we are dealing with unsigned quantities we have
1427
     to be careful to check for potential overflows.  */
1428
882
  if (dataoff >= section->size
1429
882
      || size > section->size - dataoff)
1430
412
    {
1431
412
      _bfd_error_handler
1432
412
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
412
   abfd);
1434
412
      return;
1435
412
    }
1436
1437
  /* Read the whole section. */
1438
470
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
180
    {
1440
180
      free (data);
1441
180
      return;
1442
180
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
5.11k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
4.92k
    {
1447
4.92k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
4.92k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
4.92k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
4.92k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
4.92k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
95
  {
1455
95
    char buffer[256 + 1];
1456
95
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1457
1458
    /*
1459
      The debug entry doesn't have to have to be in a section, in which
1460
      case AddressOfRawData is 0, so always use PointerToRawData.
1461
    */
1462
95
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
95
                (file_ptr) idd.PointerToRawData,
1464
95
                idd.SizeOfData, cvinfo, NULL))
1465
38
      {
1466
38
        struct bfd_build_id *build_id;
1467
38
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1468
1469
38
        build_id = bfd_alloc (abfd, bidlen);
1470
38
        if (build_id)
1471
38
    {
1472
38
      build_id->size = cvinfo->SignatureLength;
1473
38
      memcpy(build_id->data, cvinfo->Signature,
1474
38
       cvinfo->SignatureLength);
1475
38
      abfd->build_id = build_id;
1476
38
    }
1477
38
      }
1478
95
    break;
1479
95
  }
1480
4.92k
    }
1481
1482
290
  free (data);
1483
290
}
pei-mcore.c:pe_bfd_read_buildid
Line
Count
Source
1395
2.48k
{
1396
2.48k
  pe_data_type *pe = pe_data (abfd);
1397
2.48k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
2.48k
  asection *section;
1399
2.48k
  bfd_byte *data = 0;
1400
2.48k
  bfd_size_type dataoff;
1401
2.48k
  unsigned int i;
1402
2.48k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
2.48k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
2.48k
  if (size == 0)
1406
1.50k
    return;
1407
1408
980
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
6.53k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
6.01k
    {
1413
6.01k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
458
  break;
1415
6.01k
    }
1416
1417
980
  if (section == NULL)
1418
522
    return;
1419
1420
458
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
39
    return;
1422
1423
419
  dataoff = addr - section->vma;
1424
1425
  /* PR 20605 and 22373: Make sure that the data is really there.
1426
     Note - since we are dealing with unsigned quantities we have
1427
     to be careful to check for potential overflows.  */
1428
419
  if (dataoff >= section->size
1429
419
      || size > section->size - dataoff)
1430
184
    {
1431
184
      _bfd_error_handler
1432
184
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
184
   abfd);
1434
184
      return;
1435
184
    }
1436
1437
  /* Read the whole section. */
1438
235
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
83
    {
1440
83
      free (data);
1441
83
      return;
1442
83
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
5.63k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
5.54k
    {
1447
5.54k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
5.54k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
5.54k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
5.54k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
5.54k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
59
  {
1455
59
    char buffer[256 + 1];
1456
59
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1457
1458
    /*
1459
      The debug entry doesn't have to have to be in a section, in which
1460
      case AddressOfRawData is 0, so always use PointerToRawData.
1461
    */
1462
59
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
59
                (file_ptr) idd.PointerToRawData,
1464
59
                idd.SizeOfData, cvinfo, NULL))
1465
3
      {
1466
3
        struct bfd_build_id *build_id;
1467
3
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1468
1469
3
        build_id = bfd_alloc (abfd, bidlen);
1470
3
        if (build_id)
1471
3
    {
1472
3
      build_id->size = cvinfo->SignatureLength;
1473
3
      memcpy(build_id->data, cvinfo->Signature,
1474
3
       cvinfo->SignatureLength);
1475
3
      abfd->build_id = build_id;
1476
3
    }
1477
3
      }
1478
59
    break;
1479
59
  }
1480
5.54k
    }
1481
1482
152
  free (data);
1483
152
}
pei-sh.c:pe_bfd_read_buildid
Line
Count
Source
1395
2.91k
{
1396
2.91k
  pe_data_type *pe = pe_data (abfd);
1397
2.91k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
2.91k
  asection *section;
1399
2.91k
  bfd_byte *data = 0;
1400
2.91k
  bfd_size_type dataoff;
1401
2.91k
  unsigned int i;
1402
2.91k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
2.91k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
2.91k
  if (size == 0)
1406
1.47k
    return;
1407
1408
1.44k
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
7.59k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
6.86k
    {
1413
6.86k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
712
  break;
1415
6.86k
    }
1416
1417
1.44k
  if (section == NULL)
1418
733
    return;
1419
1420
712
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
38
    return;
1422
1423
674
  dataoff = addr - section->vma;
1424
1425
  /* PR 20605 and 22373: Make sure that the data is really there.
1426
     Note - since we are dealing with unsigned quantities we have
1427
     to be careful to check for potential overflows.  */
1428
674
  if (dataoff >= section->size
1429
674
      || size > section->size - dataoff)
1430
325
    {
1431
325
      _bfd_error_handler
1432
325
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
325
   abfd);
1434
325
      return;
1435
325
    }
1436
1437
  /* Read the whole section. */
1438
349
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
181
    {
1440
181
      free (data);
1441
181
      return;
1442
181
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
5.25k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
5.17k
    {
1447
5.17k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
5.17k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
5.17k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
5.17k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
5.17k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
84
  {
1455
84
    char buffer[256 + 1];
1456
84
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1457
1458
    /*
1459
      The debug entry doesn't have to have to be in a section, in which
1460
      case AddressOfRawData is 0, so always use PointerToRawData.
1461
    */
1462
84
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
84
                (file_ptr) idd.PointerToRawData,
1464
84
                idd.SizeOfData, cvinfo, NULL))
1465
4
      {
1466
4
        struct bfd_build_id *build_id;
1467
4
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1468
1469
4
        build_id = bfd_alloc (abfd, bidlen);
1470
4
        if (build_id)
1471
4
    {
1472
4
      build_id->size = cvinfo->SignatureLength;
1473
4
      memcpy(build_id->data, cvinfo->Signature,
1474
4
       cvinfo->SignatureLength);
1475
4
      abfd->build_id = build_id;
1476
4
    }
1477
4
      }
1478
84
    break;
1479
84
  }
1480
5.17k
    }
1481
1482
168
  free (data);
1483
168
}
1484
1485
static bfd_cleanup
1486
pe_bfd_object_p (bfd *abfd)
1487
1.77M
{
1488
1.77M
  bfd_byte buffer[6];
1489
1.77M
  struct external_DOS_hdr dos_hdr;
1490
1.77M
  struct external_PEI_IMAGE_hdr image_hdr;
1491
1.77M
  struct internal_filehdr internal_f;
1492
1.77M
  struct internal_aouthdr internal_a;
1493
1.77M
  bfd_size_type opt_hdr_size;
1494
1.77M
  file_ptr offset;
1495
1.77M
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
1.77M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
1.77M
      || bfd_read (buffer, 6, abfd) != 6)
1501
11.9k
    {
1502
11.9k
      if (bfd_get_error () != bfd_error_system_call)
1503
11.9k
  bfd_set_error (bfd_error_wrong_format);
1504
11.9k
      return NULL;
1505
11.9k
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
1.75M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
20.8k
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
18.2k
    return pe_ILF_object_p (abfd);
1511
1512
1.74M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
1.74M
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
370k
    {
1515
370k
      if (bfd_get_error () != bfd_error_system_call)
1516
370k
  bfd_set_error (bfd_error_wrong_format);
1517
370k
      return NULL;
1518
370k
    }
1519
1520
  /* There are really two magic numbers involved; the magic number
1521
     that says this is a NT executable (PEI) and the magic number that
1522
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1523
     the e_magic field.  The latter is stored in the f_magic field.
1524
     If the NT magic number isn't valid, the architecture magic number
1525
     could be mimicked by some other field (specifically, the number
1526
     of relocs in section 3).  Since this routine can only be called
1527
     correctly for a PEI file, check the e_magic number here, and, if
1528
     it doesn't match, clobber the f_magic number so that we don't get
1529
     a false match.  */
1530
1.37M
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
942k
    {
1532
942k
      bfd_set_error (bfd_error_wrong_format);
1533
942k
      return NULL;
1534
942k
    }
1535
1536
428k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
428k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
428k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
2.57k
    {
1540
2.57k
      if (bfd_get_error () != bfd_error_system_call)
1541
2.57k
  bfd_set_error (bfd_error_wrong_format);
1542
2.57k
      return NULL;
1543
2.57k
    }
1544
1545
425k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
4.57k
    {
1547
4.57k
      bfd_set_error (bfd_error_wrong_format);
1548
4.57k
      return NULL;
1549
4.57k
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
421k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
421k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
62.3k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
359k
    {
1558
359k
      bfd_set_error (bfd_error_wrong_format);
1559
359k
      return NULL;
1560
359k
    }
1561
1562
62.0k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
62.0k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
62.0k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
62.0k
  if (opt_hdr_size != 0)
1569
38.7k
    {
1570
38.7k
      bfd_size_type amt = opt_hdr_size;
1571
38.7k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
38.7k
      if (amt < sizeof (PEAOUTHDR))
1575
34.6k
  amt = sizeof (PEAOUTHDR);
1576
1577
38.7k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
38.7k
      if (opthdr == NULL)
1579
323
  return NULL;
1580
38.4k
      if (amt > opt_hdr_size)
1581
34.3k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
38.4k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
38.4k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1586
1587
#ifdef ARM
1588
      /* Use Subsystem to distinguish between pei-arm-little and
1589
   pei-arm-wince-little.  */
1590
#ifdef WINCE
1591
4.60k
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1592
#else
1593
4.83k
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1594
1.53k
#endif
1595
4.11k
  {
1596
4.11k
    bfd_set_error (bfd_error_wrong_format);
1597
4.11k
    return NULL;
1598
4.11k
  }
1599
5.32k
#endif
1600
1601
34.3k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
15.3k
    || a->SectionAlignment >= 0x80000000)
1603
19.3k
  {
1604
19.3k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
19.3k
            abfd);
1606
19.3k
    a->SectionAlignment &= -a->SectionAlignment;
1607
19.3k
    if (a->SectionAlignment >= 0x80000000)
1608
336
      a->SectionAlignment = 0x40000000;
1609
19.3k
  }
1610
1611
34.3k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
16.3k
    || a->FileAlignment > a->SectionAlignment)
1613
23.4k
  {
1614
23.4k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
23.4k
            abfd);
1616
23.4k
    a->FileAlignment &= -a->FileAlignment;
1617
23.4k
    if (a->FileAlignment > a->SectionAlignment)
1618
15.9k
      a->FileAlignment = a->SectionAlignment;
1619
23.4k
  }
1620
1621
34.3k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
19.6k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
5.32k
    }
1624
1625
57.6k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
57.6k
             (opt_hdr_size != 0
1627
57.6k
        ? &internal_a
1628
57.6k
        : (struct internal_aouthdr *) NULL));
1629
1630
57.6k
  if (result)
1631
38.4k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
38.4k
      pe_bfd_read_buildid(abfd);
1634
38.4k
    }
1635
1636
57.6k
  return result;
1637
62.0k
}
pei-i386.c:pe_bfd_object_p
Line
Count
Source
1487
161k
{
1488
161k
  bfd_byte buffer[6];
1489
161k
  struct external_DOS_hdr dos_hdr;
1490
161k
  struct external_PEI_IMAGE_hdr image_hdr;
1491
161k
  struct internal_filehdr internal_f;
1492
161k
  struct internal_aouthdr internal_a;
1493
161k
  bfd_size_type opt_hdr_size;
1494
161k
  file_ptr offset;
1495
161k
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
161k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
161k
      || bfd_read (buffer, 6, abfd) != 6)
1501
1.09k
    {
1502
1.09k
      if (bfd_get_error () != bfd_error_system_call)
1503
1.09k
  bfd_set_error (bfd_error_wrong_format);
1504
1.09k
      return NULL;
1505
1.09k
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
160k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
2.52k
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
2.20k
    return pe_ILF_object_p (abfd);
1511
1512
158k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
158k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
34.9k
    {
1515
34.9k
      if (bfd_get_error () != bfd_error_system_call)
1516
34.9k
  bfd_set_error (bfd_error_wrong_format);
1517
34.9k
      return NULL;
1518
34.9k
    }
1519
1520
  /* There are really two magic numbers involved; the magic number
1521
     that says this is a NT executable (PEI) and the magic number that
1522
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1523
     the e_magic field.  The latter is stored in the f_magic field.
1524
     If the NT magic number isn't valid, the architecture magic number
1525
     could be mimicked by some other field (specifically, the number
1526
     of relocs in section 3).  Since this routine can only be called
1527
     correctly for a PEI file, check the e_magic number here, and, if
1528
     it doesn't match, clobber the f_magic number so that we don't get
1529
     a false match.  */
1530
123k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
75.9k
    {
1532
75.9k
      bfd_set_error (bfd_error_wrong_format);
1533
75.9k
      return NULL;
1534
75.9k
    }
1535
1536
47.6k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
47.6k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
47.6k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
111
    {
1540
111
      if (bfd_get_error () != bfd_error_system_call)
1541
111
  bfd_set_error (bfd_error_wrong_format);
1542
111
      return NULL;
1543
111
    }
1544
1545
47.4k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
287
    {
1547
287
      bfd_set_error (bfd_error_wrong_format);
1548
287
      return NULL;
1549
287
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
47.2k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
47.2k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
8.54k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
38.6k
    {
1558
38.6k
      bfd_set_error (bfd_error_wrong_format);
1559
38.6k
      return NULL;
1560
38.6k
    }
1561
1562
8.53k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
8.53k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
8.53k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
8.53k
  if (opt_hdr_size != 0)
1569
4.08k
    {
1570
4.08k
      bfd_size_type amt = opt_hdr_size;
1571
4.08k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
4.08k
      if (amt < sizeof (PEAOUTHDR))
1575
3.26k
  amt = sizeof (PEAOUTHDR);
1576
1577
4.08k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
4.08k
      if (opthdr == NULL)
1579
25
  return NULL;
1580
4.06k
      if (amt > opt_hdr_size)
1581
3.24k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
4.06k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
4.06k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1586
1587
#ifdef ARM
1588
      /* Use Subsystem to distinguish between pei-arm-little and
1589
   pei-arm-wince-little.  */
1590
#ifdef WINCE
1591
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1592
#else
1593
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1594
#endif
1595
  {
1596
    bfd_set_error (bfd_error_wrong_format);
1597
    return NULL;
1598
  }
1599
#endif
1600
1601
4.06k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
1.79k
    || a->SectionAlignment >= 0x80000000)
1603
2.33k
  {
1604
2.33k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
2.33k
            abfd);
1606
2.33k
    a->SectionAlignment &= -a->SectionAlignment;
1607
2.33k
    if (a->SectionAlignment >= 0x80000000)
1608
69
      a->SectionAlignment = 0x40000000;
1609
2.33k
  }
1610
1611
4.06k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
1.84k
    || a->FileAlignment > a->SectionAlignment)
1613
2.74k
  {
1614
2.74k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
2.74k
            abfd);
1616
2.74k
    a->FileAlignment &= -a->FileAlignment;
1617
2.74k
    if (a->FileAlignment > a->SectionAlignment)
1618
1.67k
      a->FileAlignment = a->SectionAlignment;
1619
2.74k
  }
1620
1621
4.06k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
2.16k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
4.06k
    }
1624
1625
8.50k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
8.50k
             (opt_hdr_size != 0
1627
8.50k
        ? &internal_a
1628
8.50k
        : (struct internal_aouthdr *) NULL));
1629
1630
8.50k
  if (result)
1631
7.28k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
7.28k
      pe_bfd_read_buildid(abfd);
1634
7.28k
    }
1635
1636
8.50k
  return result;
1637
8.53k
}
pei-x86_64.c:pe_bfd_object_p
Line
Count
Source
1487
161k
{
1488
161k
  bfd_byte buffer[6];
1489
161k
  struct external_DOS_hdr dos_hdr;
1490
161k
  struct external_PEI_IMAGE_hdr image_hdr;
1491
161k
  struct internal_filehdr internal_f;
1492
161k
  struct internal_aouthdr internal_a;
1493
161k
  bfd_size_type opt_hdr_size;
1494
161k
  file_ptr offset;
1495
161k
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
161k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
161k
      || bfd_read (buffer, 6, abfd) != 6)
1501
1.09k
    {
1502
1.09k
      if (bfd_get_error () != bfd_error_system_call)
1503
1.09k
  bfd_set_error (bfd_error_wrong_format);
1504
1.09k
      return NULL;
1505
1.09k
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
159k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
2.51k
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
2.19k
    return pe_ILF_object_p (abfd);
1511
1512
157k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
157k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
34.9k
    {
1515
34.9k
      if (bfd_get_error () != bfd_error_system_call)
1516
34.9k
  bfd_set_error (bfd_error_wrong_format);
1517
34.9k
      return NULL;
1518
34.9k
    }
1519
1520
  /* There are really two magic numbers involved; the magic number
1521
     that says this is a NT executable (PEI) and the magic number that
1522
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1523
     the e_magic field.  The latter is stored in the f_magic field.
1524
     If the NT magic number isn't valid, the architecture magic number
1525
     could be mimicked by some other field (specifically, the number
1526
     of relocs in section 3).  Since this routine can only be called
1527
     correctly for a PEI file, check the e_magic number here, and, if
1528
     it doesn't match, clobber the f_magic number so that we don't get
1529
     a false match.  */
1530
122k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
75.9k
    {
1532
75.9k
      bfd_set_error (bfd_error_wrong_format);
1533
75.9k
      return NULL;
1534
75.9k
    }
1535
1536
46.8k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
46.8k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
46.8k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
111
    {
1540
111
      if (bfd_get_error () != bfd_error_system_call)
1541
111
  bfd_set_error (bfd_error_wrong_format);
1542
111
      return NULL;
1543
111
    }
1544
1545
46.7k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
287
    {
1547
287
      bfd_set_error (bfd_error_wrong_format);
1548
287
      return NULL;
1549
287
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
46.4k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
46.4k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
7.20k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
39.2k
    {
1558
39.2k
      bfd_set_error (bfd_error_wrong_format);
1559
39.2k
      return NULL;
1560
39.2k
    }
1561
1562
7.18k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
7.18k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
7.18k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
7.18k
  if (opt_hdr_size != 0)
1569
4.61k
    {
1570
4.61k
      bfd_size_type amt = opt_hdr_size;
1571
4.61k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
4.61k
      if (amt < sizeof (PEAOUTHDR))
1575
4.19k
  amt = sizeof (PEAOUTHDR);
1576
1577
4.61k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
4.61k
      if (opthdr == NULL)
1579
31
  return NULL;
1580
4.58k
      if (amt > opt_hdr_size)
1581
4.17k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
4.58k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
4.58k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1586
1587
#ifdef ARM
1588
      /* Use Subsystem to distinguish between pei-arm-little and
1589
   pei-arm-wince-little.  */
1590
#ifdef WINCE
1591
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1592
#else
1593
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1594
#endif
1595
  {
1596
    bfd_set_error (bfd_error_wrong_format);
1597
    return NULL;
1598
  }
1599
#endif
1600
1601
4.58k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
2.65k
    || a->SectionAlignment >= 0x80000000)
1603
1.95k
  {
1604
1.95k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
1.95k
            abfd);
1606
1.95k
    a->SectionAlignment &= -a->SectionAlignment;
1607
1.95k
    if (a->SectionAlignment >= 0x80000000)
1608
26
      a->SectionAlignment = 0x40000000;
1609
1.95k
  }
1610
1611
4.58k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
2.00k
    || a->FileAlignment > a->SectionAlignment)
1613
3.11k
  {
1614
3.11k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
3.11k
            abfd);
1616
3.11k
    a->FileAlignment &= -a->FileAlignment;
1617
3.11k
    if (a->FileAlignment > a->SectionAlignment)
1618
1.56k
      a->FileAlignment = a->SectionAlignment;
1619
3.11k
  }
1620
1621
4.58k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
2.63k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
4.58k
    }
1624
1625
7.15k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
7.15k
             (opt_hdr_size != 0
1627
7.15k
        ? &internal_a
1628
7.15k
        : (struct internal_aouthdr *) NULL));
1629
1630
7.15k
  if (result)
1631
5.63k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
5.63k
      pe_bfd_read_buildid(abfd);
1634
5.63k
    }
1635
1636
7.15k
  return result;
1637
7.18k
}
pei-aarch64.c:pe_bfd_object_p
Line
Count
Source
1487
159k
{
1488
159k
  bfd_byte buffer[6];
1489
159k
  struct external_DOS_hdr dos_hdr;
1490
159k
  struct external_PEI_IMAGE_hdr image_hdr;
1491
159k
  struct internal_filehdr internal_f;
1492
159k
  struct internal_aouthdr internal_a;
1493
159k
  bfd_size_type opt_hdr_size;
1494
159k
  file_ptr offset;
1495
159k
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
159k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
159k
      || bfd_read (buffer, 6, abfd) != 6)
1501
1.09k
    {
1502
1.09k
      if (bfd_get_error () != bfd_error_system_call)
1503
1.09k
  bfd_set_error (bfd_error_wrong_format);
1504
1.09k
      return NULL;
1505
1.09k
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
158k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
2.52k
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
2.20k
    return pe_ILF_object_p (abfd);
1511
1512
155k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
155k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
34.9k
    {
1515
34.9k
      if (bfd_get_error () != bfd_error_system_call)
1516
34.9k
  bfd_set_error (bfd_error_wrong_format);
1517
34.9k
      return NULL;
1518
34.9k
    }
1519
1520
  /* There are really two magic numbers involved; the magic number
1521
     that says this is a NT executable (PEI) and the magic number that
1522
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1523
     the e_magic field.  The latter is stored in the f_magic field.
1524
     If the NT magic number isn't valid, the architecture magic number
1525
     could be mimicked by some other field (specifically, the number
1526
     of relocs in section 3).  Since this routine can only be called
1527
     correctly for a PEI file, check the e_magic number here, and, if
1528
     it doesn't match, clobber the f_magic number so that we don't get
1529
     a false match.  */
1530
120k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
74.1k
    {
1532
74.1k
      bfd_set_error (bfd_error_wrong_format);
1533
74.1k
      return NULL;
1534
74.1k
    }
1535
1536
46.7k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
46.7k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
46.7k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
672
    {
1540
672
      if (bfd_get_error () != bfd_error_system_call)
1541
672
  bfd_set_error (bfd_error_wrong_format);
1542
672
      return NULL;
1543
672
    }
1544
1545
46.1k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
999
    {
1547
999
      bfd_set_error (bfd_error_wrong_format);
1548
999
      return NULL;
1549
999
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
45.1k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
45.1k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
6.34k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
38.7k
    {
1558
38.7k
      bfd_set_error (bfd_error_wrong_format);
1559
38.7k
      return NULL;
1560
38.7k
    }
1561
1562
6.32k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
6.32k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
6.32k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
6.32k
  if (opt_hdr_size != 0)
1569
5.00k
    {
1570
5.00k
      bfd_size_type amt = opt_hdr_size;
1571
5.00k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
5.00k
      if (amt < sizeof (PEAOUTHDR))
1575
4.55k
  amt = sizeof (PEAOUTHDR);
1576
1577
5.00k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
5.00k
      if (opthdr == NULL)
1579
29
  return NULL;
1580
4.97k
      if (amt > opt_hdr_size)
1581
4.52k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
4.97k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
4.97k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1586
1587
#ifdef ARM
1588
      /* Use Subsystem to distinguish between pei-arm-little and
1589
   pei-arm-wince-little.  */
1590
#ifdef WINCE
1591
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1592
#else
1593
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1594
#endif
1595
  {
1596
    bfd_set_error (bfd_error_wrong_format);
1597
    return NULL;
1598
  }
1599
#endif
1600
1601
4.97k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
1.57k
    || a->SectionAlignment >= 0x80000000)
1603
3.42k
  {
1604
3.42k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
3.42k
            abfd);
1606
3.42k
    a->SectionAlignment &= -a->SectionAlignment;
1607
3.42k
    if (a->SectionAlignment >= 0x80000000)
1608
17
      a->SectionAlignment = 0x40000000;
1609
3.42k
  }
1610
1611
4.97k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
3.29k
    || a->FileAlignment > a->SectionAlignment)
1613
3.83k
  {
1614
3.83k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
3.83k
            abfd);
1616
3.83k
    a->FileAlignment &= -a->FileAlignment;
1617
3.83k
    if (a->FileAlignment > a->SectionAlignment)
1618
2.95k
      a->FileAlignment = a->SectionAlignment;
1619
3.83k
  }
1620
1621
4.97k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
2.40k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
4.97k
    }
1624
1625
6.29k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
6.29k
             (opt_hdr_size != 0
1627
6.29k
        ? &internal_a
1628
6.29k
        : (struct internal_aouthdr *) NULL));
1629
1630
6.29k
  if (result)
1631
4.77k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
4.77k
      pe_bfd_read_buildid(abfd);
1634
4.77k
    }
1635
1636
6.29k
  return result;
1637
6.32k
}
pei-ia64.c:pe_bfd_object_p
Line
Count
Source
1487
20.2k
{
1488
20.2k
  bfd_byte buffer[6];
1489
20.2k
  struct external_DOS_hdr dos_hdr;
1490
20.2k
  struct external_PEI_IMAGE_hdr image_hdr;
1491
20.2k
  struct internal_filehdr internal_f;
1492
20.2k
  struct internal_aouthdr internal_a;
1493
20.2k
  bfd_size_type opt_hdr_size;
1494
20.2k
  file_ptr offset;
1495
20.2k
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
20.2k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
20.2k
      || bfd_read (buffer, 6, abfd) != 6)
1501
0
    {
1502
0
      if (bfd_get_error () != bfd_error_system_call)
1503
0
  bfd_set_error (bfd_error_wrong_format);
1504
0
      return NULL;
1505
0
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
20.2k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
0
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
0
    return pe_ILF_object_p (abfd);
1511
1512
20.2k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
20.2k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
0
    {
1515
0
      if (bfd_get_error () != bfd_error_system_call)
1516
0
  bfd_set_error (bfd_error_wrong_format);
1517
0
      return NULL;
1518
0
    }
1519
1520
  /* There are really two magic numbers involved; the magic number
1521
     that says this is a NT executable (PEI) and the magic number that
1522
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1523
     the e_magic field.  The latter is stored in the f_magic field.
1524
     If the NT magic number isn't valid, the architecture magic number
1525
     could be mimicked by some other field (specifically, the number
1526
     of relocs in section 3).  Since this routine can only be called
1527
     correctly for a PEI file, check the e_magic number here, and, if
1528
     it doesn't match, clobber the f_magic number so that we don't get
1529
     a false match.  */
1530
20.2k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
0
    {
1532
0
      bfd_set_error (bfd_error_wrong_format);
1533
0
      return NULL;
1534
0
    }
1535
1536
20.2k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
20.2k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
20.2k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
0
    {
1540
0
      if (bfd_get_error () != bfd_error_system_call)
1541
0
  bfd_set_error (bfd_error_wrong_format);
1542
0
      return NULL;
1543
0
    }
1544
1545
20.2k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
0
    {
1547
0
      bfd_set_error (bfd_error_wrong_format);
1548
0
      return NULL;
1549
0
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
20.2k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
20.2k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
5.40k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
14.8k
    {
1558
14.8k
      bfd_set_error (bfd_error_wrong_format);
1559
14.8k
      return NULL;
1560
14.8k
    }
1561
1562
5.39k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
5.39k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
5.39k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
5.39k
  if (opt_hdr_size != 0)
1569
2.81k
    {
1570
2.81k
      bfd_size_type amt = opt_hdr_size;
1571
2.81k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
2.81k
      if (amt < sizeof (PEAOUTHDR))
1575
2.72k
  amt = sizeof (PEAOUTHDR);
1576
1577
2.81k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
2.81k
      if (opthdr == NULL)
1579
32
  return NULL;
1580
2.78k
      if (amt > opt_hdr_size)
1581
2.69k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
2.78k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
2.78k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1586
1587
#ifdef ARM
1588
      /* Use Subsystem to distinguish between pei-arm-little and
1589
   pei-arm-wince-little.  */
1590
#ifdef WINCE
1591
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1592
#else
1593
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1594
#endif
1595
  {
1596
    bfd_set_error (bfd_error_wrong_format);
1597
    return NULL;
1598
  }
1599
#endif
1600
1601
2.78k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
1.25k
    || a->SectionAlignment >= 0x80000000)
1603
1.56k
  {
1604
1.56k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
1.56k
            abfd);
1606
1.56k
    a->SectionAlignment &= -a->SectionAlignment;
1607
1.56k
    if (a->SectionAlignment >= 0x80000000)
1608
31
      a->SectionAlignment = 0x40000000;
1609
1.56k
  }
1610
1611
2.78k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
1.22k
    || a->FileAlignment > a->SectionAlignment)
1613
2.00k
  {
1614
2.00k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
2.00k
            abfd);
1616
2.00k
    a->FileAlignment &= -a->FileAlignment;
1617
2.00k
    if (a->FileAlignment > a->SectionAlignment)
1618
1.22k
      a->FileAlignment = a->SectionAlignment;
1619
2.00k
  }
1620
1621
2.78k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
1.75k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
2.78k
    }
1624
1625
5.35k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
5.35k
             (opt_hdr_size != 0
1627
5.35k
        ? &internal_a
1628
5.35k
        : (struct internal_aouthdr *) NULL));
1629
1630
5.35k
  if (result)
1631
3.30k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
3.30k
      pe_bfd_read_buildid(abfd);
1634
3.30k
    }
1635
1636
5.35k
  return result;
1637
5.39k
}
pei-loongarch64.c:pe_bfd_object_p
Line
Count
Source
1487
159k
{
1488
159k
  bfd_byte buffer[6];
1489
159k
  struct external_DOS_hdr dos_hdr;
1490
159k
  struct external_PEI_IMAGE_hdr image_hdr;
1491
159k
  struct internal_filehdr internal_f;
1492
159k
  struct internal_aouthdr internal_a;
1493
159k
  bfd_size_type opt_hdr_size;
1494
159k
  file_ptr offset;
1495
159k
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
159k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
159k
      || bfd_read (buffer, 6, abfd) != 6)
1501
1.09k
    {
1502
1.09k
      if (bfd_get_error () != bfd_error_system_call)
1503
1.09k
  bfd_set_error (bfd_error_wrong_format);
1504
1.09k
      return NULL;
1505
1.09k
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
158k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
2.50k
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
2.18k
    return pe_ILF_object_p (abfd);
1511
1512
155k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
155k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
34.9k
    {
1515
34.9k
      if (bfd_get_error () != bfd_error_system_call)
1516
34.9k
  bfd_set_error (bfd_error_wrong_format);
1517
34.9k
      return NULL;
1518
34.9k
    }
1519
1520
  /* There are really two magic numbers involved; the magic number
1521
     that says this is a NT executable (PEI) and the magic number that
1522
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1523
     the e_magic field.  The latter is stored in the f_magic field.
1524
     If the NT magic number isn't valid, the architecture magic number
1525
     could be mimicked by some other field (specifically, the number
1526
     of relocs in section 3).  Since this routine can only be called
1527
     correctly for a PEI file, check the e_magic number here, and, if
1528
     it doesn't match, clobber the f_magic number so that we don't get
1529
     a false match.  */
1530
120k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
75.9k
    {
1532
75.9k
      bfd_set_error (bfd_error_wrong_format);
1533
75.9k
      return NULL;
1534
75.9k
    }
1535
1536
44.9k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
44.9k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
44.9k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
111
    {
1540
111
      if (bfd_get_error () != bfd_error_system_call)
1541
111
  bfd_set_error (bfd_error_wrong_format);
1542
111
      return NULL;
1543
111
    }
1544
1545
44.7k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
287
    {
1547
287
      bfd_set_error (bfd_error_wrong_format);
1548
287
      return NULL;
1549
287
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
44.5k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
44.5k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
5.09k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
39.4k
    {
1558
39.4k
      bfd_set_error (bfd_error_wrong_format);
1559
39.4k
      return NULL;
1560
39.4k
    }
1561
1562
5.08k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
5.08k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
5.08k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
5.08k
  if (opt_hdr_size != 0)
1569
3.21k
    {
1570
3.21k
      bfd_size_type amt = opt_hdr_size;
1571
3.21k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
3.21k
      if (amt < sizeof (PEAOUTHDR))
1575
2.94k
  amt = sizeof (PEAOUTHDR);
1576
1577
3.21k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
3.21k
      if (opthdr == NULL)
1579
30
  return NULL;
1580
3.18k
      if (amt > opt_hdr_size)
1581
2.92k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
3.18k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
3.18k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1586
1587
#ifdef ARM
1588
      /* Use Subsystem to distinguish between pei-arm-little and
1589
   pei-arm-wince-little.  */
1590
#ifdef WINCE
1591
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1592
#else
1593
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1594
#endif
1595
  {
1596
    bfd_set_error (bfd_error_wrong_format);
1597
    return NULL;
1598
  }
1599
#endif
1600
1601
3.18k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
1.82k
    || a->SectionAlignment >= 0x80000000)
1603
1.38k
  {
1604
1.38k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
1.38k
            abfd);
1606
1.38k
    a->SectionAlignment &= -a->SectionAlignment;
1607
1.38k
    if (a->SectionAlignment >= 0x80000000)
1608
20
      a->SectionAlignment = 0x40000000;
1609
1.38k
  }
1610
1611
3.18k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
1.64k
    || a->FileAlignment > a->SectionAlignment)
1613
1.79k
  {
1614
1.79k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
1.79k
            abfd);
1616
1.79k
    a->FileAlignment &= -a->FileAlignment;
1617
1.79k
    if (a->FileAlignment > a->SectionAlignment)
1618
1.08k
      a->FileAlignment = a->SectionAlignment;
1619
1.79k
  }
1620
1621
3.18k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
1.69k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
3.18k
    }
1624
1625
5.05k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
5.05k
             (opt_hdr_size != 0
1627
5.05k
        ? &internal_a
1628
5.05k
        : (struct internal_aouthdr *) NULL));
1629
1630
5.05k
  if (result)
1631
3.06k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
3.06k
      pe_bfd_read_buildid(abfd);
1634
3.06k
    }
1635
1636
5.05k
  return result;
1637
5.08k
}
pei-riscv64.c:pe_bfd_object_p
Line
Count
Source
1487
159k
{
1488
159k
  bfd_byte buffer[6];
1489
159k
  struct external_DOS_hdr dos_hdr;
1490
159k
  struct external_PEI_IMAGE_hdr image_hdr;
1491
159k
  struct internal_filehdr internal_f;
1492
159k
  struct internal_aouthdr internal_a;
1493
159k
  bfd_size_type opt_hdr_size;
1494
159k
  file_ptr offset;
1495
159k
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
159k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
159k
      || bfd_read (buffer, 6, abfd) != 6)
1501
1.09k
    {
1502
1.09k
      if (bfd_get_error () != bfd_error_system_call)
1503
1.09k
  bfd_set_error (bfd_error_wrong_format);
1504
1.09k
      return NULL;
1505
1.09k
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
158k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
2.51k
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
2.19k
    return pe_ILF_object_p (abfd);
1511
1512
156k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
156k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
34.9k
    {
1515
34.9k
      if (bfd_get_error () != bfd_error_system_call)
1516
34.9k
  bfd_set_error (bfd_error_wrong_format);
1517
34.9k
      return NULL;
1518
34.9k
    }
1519
1520
  /* There are really two magic numbers involved; the magic number
1521
     that says this is a NT executable (PEI) and the magic number that
1522
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1523
     the e_magic field.  The latter is stored in the f_magic field.
1524
     If the NT magic number isn't valid, the architecture magic number
1525
     could be mimicked by some other field (specifically, the number
1526
     of relocs in section 3).  Since this routine can only be called
1527
     correctly for a PEI file, check the e_magic number here, and, if
1528
     it doesn't match, clobber the f_magic number so that we don't get
1529
     a false match.  */
1530
121k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
75.9k
    {
1532
75.9k
      bfd_set_error (bfd_error_wrong_format);
1533
75.9k
      return NULL;
1534
75.9k
    }
1535
1536
45.1k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
45.1k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
45.1k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
111
    {
1540
111
      if (bfd_get_error () != bfd_error_system_call)
1541
111
  bfd_set_error (bfd_error_wrong_format);
1542
111
      return NULL;
1543
111
    }
1544
1545
45.0k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
287
    {
1547
287
      bfd_set_error (bfd_error_wrong_format);
1548
287
      return NULL;
1549
287
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
44.7k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
44.7k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
5.69k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
39.0k
    {
1558
39.0k
      bfd_set_error (bfd_error_wrong_format);
1559
39.0k
      return NULL;
1560
39.0k
    }
1561
1562
5.67k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
5.67k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
5.67k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
5.67k
  if (opt_hdr_size != 0)
1569
4.17k
    {
1570
4.17k
      bfd_size_type amt = opt_hdr_size;
1571
4.17k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
4.17k
      if (amt < sizeof (PEAOUTHDR))
1575
3.41k
  amt = sizeof (PEAOUTHDR);
1576
1577
4.17k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
4.17k
      if (opthdr == NULL)
1579
31
  return NULL;
1580
4.14k
      if (amt > opt_hdr_size)
1581
3.38k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
4.14k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
4.14k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1586
1587
#ifdef ARM
1588
      /* Use Subsystem to distinguish between pei-arm-little and
1589
   pei-arm-wince-little.  */
1590
#ifdef WINCE
1591
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1592
#else
1593
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1594
#endif
1595
  {
1596
    bfd_set_error (bfd_error_wrong_format);
1597
    return NULL;
1598
  }
1599
#endif
1600
1601
4.14k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
2.05k
    || a->SectionAlignment >= 0x80000000)
1603
2.13k
  {
1604
2.13k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
2.13k
            abfd);
1606
2.13k
    a->SectionAlignment &= -a->SectionAlignment;
1607
2.13k
    if (a->SectionAlignment >= 0x80000000)
1608
44
      a->SectionAlignment = 0x40000000;
1609
2.13k
  }
1610
1611
4.14k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
1.66k
    || a->FileAlignment > a->SectionAlignment)
1613
2.79k
  {
1614
2.79k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
2.79k
            abfd);
1616
2.79k
    a->FileAlignment &= -a->FileAlignment;
1617
2.79k
    if (a->FileAlignment > a->SectionAlignment)
1618
1.80k
      a->FileAlignment = a->SectionAlignment;
1619
2.79k
  }
1620
1621
4.14k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
2.61k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
4.14k
    }
1624
1625
5.64k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
5.64k
             (opt_hdr_size != 0
1627
5.64k
        ? &internal_a
1628
5.64k
        : (struct internal_aouthdr *) NULL));
1629
1630
5.64k
  if (result)
1631
3.62k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
3.62k
      pe_bfd_read_buildid(abfd);
1634
3.62k
    }
1635
1636
5.64k
  return result;
1637
5.67k
}
pei-arm-wince.c:pe_bfd_object_p
Line
Count
Source
1487
270k
{
1488
270k
  bfd_byte buffer[6];
1489
270k
  struct external_DOS_hdr dos_hdr;
1490
270k
  struct external_PEI_IMAGE_hdr image_hdr;
1491
270k
  struct internal_filehdr internal_f;
1492
270k
  struct internal_aouthdr internal_a;
1493
270k
  bfd_size_type opt_hdr_size;
1494
270k
  file_ptr offset;
1495
270k
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
270k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
270k
      || bfd_read (buffer, 6, abfd) != 6)
1501
1.86k
    {
1502
1.86k
      if (bfd_get_error () != bfd_error_system_call)
1503
1.85k
  bfd_set_error (bfd_error_wrong_format);
1504
1.86k
      return NULL;
1505
1.86k
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
268k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
2.07k
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
1.82k
    return pe_ILF_object_p (abfd);
1511
1512
266k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
266k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
56.0k
    {
1515
56.0k
      if (bfd_get_error () != bfd_error_system_call)
1516
56.0k
  bfd_set_error (bfd_error_wrong_format);
1517
56.0k
      return NULL;
1518
56.0k
    }
1519
1520
  /* There are really two magic numbers involved; the magic number
1521
     that says this is a NT executable (PEI) and the magic number that
1522
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1523
     the e_magic field.  The latter is stored in the f_magic field.
1524
     If the NT magic number isn't valid, the architecture magic number
1525
     could be mimicked by some other field (specifically, the number
1526
     of relocs in section 3).  Since this routine can only be called
1527
     correctly for a PEI file, check the e_magic number here, and, if
1528
     it doesn't match, clobber the f_magic number so that we don't get
1529
     a false match.  */
1530
210k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
165k
    {
1532
165k
      bfd_set_error (bfd_error_wrong_format);
1533
165k
      return NULL;
1534
165k
    }
1535
1536
44.9k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
44.9k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
44.9k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
620
    {
1540
620
      if (bfd_get_error () != bfd_error_system_call)
1541
620
  bfd_set_error (bfd_error_wrong_format);
1542
620
      return NULL;
1543
620
    }
1544
1545
44.3k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
930
    {
1547
930
      bfd_set_error (bfd_error_wrong_format);
1548
930
      return NULL;
1549
930
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
43.3k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
43.3k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
7.49k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
35.9k
    {
1558
35.9k
      bfd_set_error (bfd_error_wrong_format);
1559
35.9k
      return NULL;
1560
35.9k
    }
1561
1562
7.44k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
7.44k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
7.44k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
7.44k
  if (opt_hdr_size != 0)
1569
4.64k
    {
1570
4.64k
      bfd_size_type amt = opt_hdr_size;
1571
4.64k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
4.64k
      if (amt < sizeof (PEAOUTHDR))
1575
4.15k
  amt = sizeof (PEAOUTHDR);
1576
1577
4.64k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
4.64k
      if (opthdr == NULL)
1579
43
  return NULL;
1580
4.60k
      if (amt > opt_hdr_size)
1581
4.11k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
4.60k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
4.60k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1586
1587
4.60k
#ifdef ARM
1588
      /* Use Subsystem to distinguish between pei-arm-little and
1589
   pei-arm-wince-little.  */
1590
4.60k
#ifdef WINCE
1591
4.60k
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1592
#else
1593
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1594
#endif
1595
2.57k
  {
1596
2.57k
    bfd_set_error (bfd_error_wrong_format);
1597
2.57k
    return NULL;
1598
2.57k
  }
1599
2.02k
#endif
1600
1601
2.02k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
365
    || a->SectionAlignment >= 0x80000000)
1603
1.70k
  {
1604
1.70k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
1.70k
            abfd);
1606
1.70k
    a->SectionAlignment &= -a->SectionAlignment;
1607
1.70k
    if (a->SectionAlignment >= 0x80000000)
1608
38
      a->SectionAlignment = 0x40000000;
1609
1.70k
  }
1610
1611
2.02k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
535
    || a->FileAlignment > a->SectionAlignment)
1613
1.80k
  {
1614
1.80k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
1.80k
            abfd);
1616
1.80k
    a->FileAlignment &= -a->FileAlignment;
1617
1.80k
    if (a->FileAlignment > a->SectionAlignment)
1618
1.44k
      a->FileAlignment = a->SectionAlignment;
1619
1.80k
  }
1620
1621
2.02k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
1.54k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
2.02k
    }
1624
1625
4.82k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
4.82k
             (opt_hdr_size != 0
1627
4.82k
        ? &internal_a
1628
4.82k
        : (struct internal_aouthdr *) NULL));
1629
1630
4.82k
  if (result)
1631
2.26k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
2.26k
      pe_bfd_read_buildid(abfd);
1634
2.26k
    }
1635
1636
4.82k
  return result;
1637
7.44k
}
pei-arm.c:pe_bfd_object_p
Line
Count
Source
1487
270k
{
1488
270k
  bfd_byte buffer[6];
1489
270k
  struct external_DOS_hdr dos_hdr;
1490
270k
  struct external_PEI_IMAGE_hdr image_hdr;
1491
270k
  struct internal_filehdr internal_f;
1492
270k
  struct internal_aouthdr internal_a;
1493
270k
  bfd_size_type opt_hdr_size;
1494
270k
  file_ptr offset;
1495
270k
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
270k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
270k
      || bfd_read (buffer, 6, abfd) != 6)
1501
1.86k
    {
1502
1.86k
      if (bfd_get_error () != bfd_error_system_call)
1503
1.85k
  bfd_set_error (bfd_error_wrong_format);
1504
1.86k
      return NULL;
1505
1.86k
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
268k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
2.08k
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
1.82k
    return pe_ILF_object_p (abfd);
1511
1512
267k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
267k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
56.0k
    {
1515
56.0k
      if (bfd_get_error () != bfd_error_system_call)
1516
56.0k
  bfd_set_error (bfd_error_wrong_format);
1517
56.0k
      return NULL;
1518
56.0k
    }
1519
1520
  /* There are really two magic numbers involved; the magic number
1521
     that says this is a NT executable (PEI) and the magic number that
1522
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1523
     the e_magic field.  The latter is stored in the f_magic field.
1524
     If the NT magic number isn't valid, the architecture magic number
1525
     could be mimicked by some other field (specifically, the number
1526
     of relocs in section 3).  Since this routine can only be called
1527
     correctly for a PEI file, check the e_magic number here, and, if
1528
     it doesn't match, clobber the f_magic number so that we don't get
1529
     a false match.  */
1530
210k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
165k
    {
1532
165k
      bfd_set_error (bfd_error_wrong_format);
1533
165k
      return NULL;
1534
165k
    }
1535
1536
45.1k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
45.1k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
45.1k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
620
    {
1540
620
      if (bfd_get_error () != bfd_error_system_call)
1541
620
  bfd_set_error (bfd_error_wrong_format);
1542
620
      return NULL;
1543
620
    }
1544
1545
44.5k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
930
    {
1547
930
      bfd_set_error (bfd_error_wrong_format);
1548
930
      return NULL;
1549
930
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
43.6k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
43.6k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
7.72k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
35.9k
    {
1558
35.9k
      bfd_set_error (bfd_error_wrong_format);
1559
35.9k
      return NULL;
1560
35.9k
    }
1561
1562
7.66k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
7.66k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
7.66k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
7.66k
  if (opt_hdr_size != 0)
1569
4.87k
    {
1570
4.87k
      bfd_size_type amt = opt_hdr_size;
1571
4.87k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
4.87k
      if (amt < sizeof (PEAOUTHDR))
1575
4.38k
  amt = sizeof (PEAOUTHDR);
1576
1577
4.87k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
4.87k
      if (opthdr == NULL)
1579
43
  return NULL;
1580
4.83k
      if (amt > opt_hdr_size)
1581
4.35k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
4.83k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
4.83k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1586
1587
4.83k
#ifdef ARM
1588
      /* Use Subsystem to distinguish between pei-arm-little and
1589
   pei-arm-wince-little.  */
1590
#ifdef WINCE
1591
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1592
#else
1593
4.83k
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1594
1.53k
#endif
1595
1.53k
  {
1596
1.53k
    bfd_set_error (bfd_error_wrong_format);
1597
1.53k
    return NULL;
1598
1.53k
  }
1599
3.29k
#endif
1600
1601
3.29k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
1.26k
    || a->SectionAlignment >= 0x80000000)
1603
2.07k
  {
1604
2.07k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
2.07k
            abfd);
1606
2.07k
    a->SectionAlignment &= -a->SectionAlignment;
1607
2.07k
    if (a->SectionAlignment >= 0x80000000)
1608
40
      a->SectionAlignment = 0x40000000;
1609
2.07k
  }
1610
1611
3.29k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
1.61k
    || a->FileAlignment > a->SectionAlignment)
1613
2.01k
  {
1614
2.01k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
2.01k
            abfd);
1616
2.01k
    a->FileAlignment &= -a->FileAlignment;
1617
2.01k
    if (a->FileAlignment > a->SectionAlignment)
1618
1.58k
      a->FileAlignment = a->SectionAlignment;
1619
2.01k
  }
1620
1621
3.29k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
1.84k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
3.29k
    }
1624
1625
6.09k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
6.09k
             (opt_hdr_size != 0
1627
6.09k
        ? &internal_a
1628
6.09k
        : (struct internal_aouthdr *) NULL));
1629
1630
6.09k
  if (result)
1631
3.14k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
3.14k
      pe_bfd_read_buildid(abfd);
1634
3.14k
    }
1635
1636
6.09k
  return result;
1637
7.66k
}
pei-mcore.c:pe_bfd_object_p
Line
Count
Source
1487
270k
{
1488
270k
  bfd_byte buffer[6];
1489
270k
  struct external_DOS_hdr dos_hdr;
1490
270k
  struct external_PEI_IMAGE_hdr image_hdr;
1491
270k
  struct internal_filehdr internal_f;
1492
270k
  struct internal_aouthdr internal_a;
1493
270k
  bfd_size_type opt_hdr_size;
1494
270k
  file_ptr offset;
1495
270k
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
270k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
270k
      || bfd_read (buffer, 6, abfd) != 6)
1501
1.86k
    {
1502
1.86k
      if (bfd_get_error () != bfd_error_system_call)
1503
1.85k
  bfd_set_error (bfd_error_wrong_format);
1504
1.86k
      return NULL;
1505
1.86k
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
268k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
2.07k
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
1.81k
    return pe_ILF_object_p (abfd);
1511
1512
266k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
266k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
56.0k
    {
1515
56.0k
      if (bfd_get_error () != bfd_error_system_call)
1516
56.0k
  bfd_set_error (bfd_error_wrong_format);
1517
56.0k
      return NULL;
1518
56.0k
    }
1519
1520
  /* There are really two magic numbers involved; the magic number
1521
     that says this is a NT executable (PEI) and the magic number that
1522
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1523
     the e_magic field.  The latter is stored in the f_magic field.
1524
     If the NT magic number isn't valid, the architecture magic number
1525
     could be mimicked by some other field (specifically, the number
1526
     of relocs in section 3).  Since this routine can only be called
1527
     correctly for a PEI file, check the e_magic number here, and, if
1528
     it doesn't match, clobber the f_magic number so that we don't get
1529
     a false match.  */
1530
210k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
167k
    {
1532
167k
      bfd_set_error (bfd_error_wrong_format);
1533
167k
      return NULL;
1534
167k
    }
1535
1536
43.4k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
43.4k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
43.4k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
111
    {
1540
111
      if (bfd_get_error () != bfd_error_system_call)
1541
111
  bfd_set_error (bfd_error_wrong_format);
1542
111
      return NULL;
1543
111
    }
1544
1545
43.3k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
284
    {
1547
284
      bfd_set_error (bfd_error_wrong_format);
1548
284
      return NULL;
1549
284
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
43.0k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
43.0k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
4.22k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
38.8k
    {
1558
38.8k
      bfd_set_error (bfd_error_wrong_format);
1559
38.8k
      return NULL;
1560
38.8k
    }
1561
1562
4.19k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
4.19k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
4.19k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
4.19k
  if (opt_hdr_size != 0)
1569
2.44k
    {
1570
2.44k
      bfd_size_type amt = opt_hdr_size;
1571
2.44k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
2.44k
      if (amt < sizeof (PEAOUTHDR))
1575
2.26k
  amt = sizeof (PEAOUTHDR);
1576
1577
2.44k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
2.44k
      if (opthdr == NULL)
1579
24
  return NULL;
1580
2.42k
      if (amt > opt_hdr_size)
1581
2.24k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
2.42k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
2.42k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1586
1587
#ifdef ARM
1588
      /* Use Subsystem to distinguish between pei-arm-little and
1589
   pei-arm-wince-little.  */
1590
#ifdef WINCE
1591
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1592
#else
1593
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1594
#endif
1595
  {
1596
    bfd_set_error (bfd_error_wrong_format);
1597
    return NULL;
1598
  }
1599
#endif
1600
1601
2.42k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
1.16k
    || a->SectionAlignment >= 0x80000000)
1603
1.29k
  {
1604
1.29k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
1.29k
            abfd);
1606
1.29k
    a->SectionAlignment &= -a->SectionAlignment;
1607
1.29k
    if (a->SectionAlignment >= 0x80000000)
1608
38
      a->SectionAlignment = 0x40000000;
1609
1.29k
  }
1610
1611
2.42k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
1.18k
    || a->FileAlignment > a->SectionAlignment)
1613
1.45k
  {
1614
1.45k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
1.45k
            abfd);
1616
1.45k
    a->FileAlignment &= -a->FileAlignment;
1617
1.45k
    if (a->FileAlignment > a->SectionAlignment)
1618
1.14k
      a->FileAlignment = a->SectionAlignment;
1619
1.45k
  }
1620
1621
2.42k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
1.25k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
2.42k
    }
1624
1625
4.16k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
4.16k
             (opt_hdr_size != 0
1627
4.16k
        ? &internal_a
1628
4.16k
        : (struct internal_aouthdr *) NULL));
1629
1630
4.16k
  if (result)
1631
2.48k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
2.48k
      pe_bfd_read_buildid(abfd);
1634
2.48k
    }
1635
1636
4.16k
  return result;
1637
4.19k
}
pei-sh.c:pe_bfd_object_p
Line
Count
Source
1487
138k
{
1488
138k
  bfd_byte buffer[6];
1489
138k
  struct external_DOS_hdr dos_hdr;
1490
138k
  struct external_PEI_IMAGE_hdr image_hdr;
1491
138k
  struct internal_filehdr internal_f;
1492
138k
  struct internal_aouthdr internal_a;
1493
138k
  bfd_size_type opt_hdr_size;
1494
138k
  file_ptr offset;
1495
138k
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
138k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
138k
      || bfd_read (buffer, 6, abfd) != 6)
1501
925
    {
1502
925
      if (bfd_get_error () != bfd_error_system_call)
1503
922
  bfd_set_error (bfd_error_wrong_format);
1504
925
      return NULL;
1505
925
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
137k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
2.06k
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
1.82k
    return pe_ILF_object_p (abfd);
1511
1512
135k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
135k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
27.2k
    {
1515
27.2k
      if (bfd_get_error () != bfd_error_system_call)
1516
27.2k
  bfd_set_error (bfd_error_wrong_format);
1517
27.2k
      return NULL;
1518
27.2k
    }
1519
1520
  /* There are really two magic numbers involved; the magic number
1521
     that says this is a NT executable (PEI) and the magic number that
1522
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1523
     the e_magic field.  The latter is stored in the f_magic field.
1524
     If the NT magic number isn't valid, the architecture magic number
1525
     could be mimicked by some other field (specifically, the number
1526
     of relocs in section 3).  Since this routine can only be called
1527
     correctly for a PEI file, check the e_magic number here, and, if
1528
     it doesn't match, clobber the f_magic number so that we don't get
1529
     a false match.  */
1530
108k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
64.8k
    {
1532
64.8k
      bfd_set_error (bfd_error_wrong_format);
1533
64.8k
      return NULL;
1534
64.8k
    }
1535
1536
43.5k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
43.5k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
43.5k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
110
    {
1540
110
      if (bfd_get_error () != bfd_error_system_call)
1541
110
  bfd_set_error (bfd_error_wrong_format);
1542
110
      return NULL;
1543
110
    }
1544
1545
43.3k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
282
    {
1547
282
      bfd_set_error (bfd_error_wrong_format);
1548
282
      return NULL;
1549
282
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
43.1k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
43.1k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
4.61k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
38.5k
    {
1558
38.5k
      bfd_set_error (bfd_error_wrong_format);
1559
38.5k
      return NULL;
1560
38.5k
    }
1561
1562
4.57k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
4.57k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
4.57k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
4.57k
  if (opt_hdr_size != 0)
1569
2.90k
    {
1570
2.90k
      bfd_size_type amt = opt_hdr_size;
1571
2.90k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
2.90k
      if (amt < sizeof (PEAOUTHDR))
1575
2.69k
  amt = sizeof (PEAOUTHDR);
1576
1577
2.90k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
2.90k
      if (opthdr == NULL)
1579
35
  return NULL;
1580
2.86k
      if (amt > opt_hdr_size)
1581
2.66k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
2.86k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
2.86k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1586
1587
#ifdef ARM
1588
      /* Use Subsystem to distinguish between pei-arm-little and
1589
   pei-arm-wince-little.  */
1590
#ifdef WINCE
1591
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1592
#else
1593
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1594
#endif
1595
  {
1596
    bfd_set_error (bfd_error_wrong_format);
1597
    return NULL;
1598
  }
1599
#endif
1600
1601
2.86k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
1.39k
    || a->SectionAlignment >= 0x80000000)
1603
1.48k
  {
1604
1.48k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
1.48k
            abfd);
1606
1.48k
    a->SectionAlignment &= -a->SectionAlignment;
1607
1.48k
    if (a->SectionAlignment >= 0x80000000)
1608
13
      a->SectionAlignment = 0x40000000;
1609
1.48k
  }
1610
1611
2.86k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
1.30k
    || a->FileAlignment > a->SectionAlignment)
1613
1.90k
  {
1614
1.90k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
1.90k
            abfd);
1616
1.90k
    a->FileAlignment &= -a->FileAlignment;
1617
1.90k
    if (a->FileAlignment > a->SectionAlignment)
1618
1.45k
      a->FileAlignment = a->SectionAlignment;
1619
1.90k
  }
1620
1621
2.86k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
1.71k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
2.86k
    }
1624
1625
4.54k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
4.54k
             (opt_hdr_size != 0
1627
4.54k
        ? &internal_a
1628
4.54k
        : (struct internal_aouthdr *) NULL));
1629
1630
4.54k
  if (result)
1631
2.91k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
2.91k
      pe_bfd_read_buildid(abfd);
1634
2.91k
    }
1635
1636
4.54k
  return result;
1637
4.57k
}
1638
1639
20.2k
#define coff_object_p pe_bfd_object_p
1640
#endif /* COFF_IMAGE_WITH_PE */