Coverage Report

Created: 2026-07-12 09:22

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
68.2k
{
137
68.2k
  RELOC *reloc_src = (RELOC *) src;
138
68.2k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
68.2k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
68.2k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
68.2k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
#ifdef SWAP_IN_RELOC_OFFSET
144
26.6k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
#endif
146
68.2k
}
pei-i386.c:coff_swap_reloc_in
Line
Count
Source
136
3.76k
{
137
3.76k
  RELOC *reloc_src = (RELOC *) src;
138
3.76k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
3.76k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
3.76k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
3.76k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
#ifdef SWAP_IN_RELOC_OFFSET
144
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
#endif
146
3.76k
}
pe-x86_64.c:coff_swap_reloc_in
Line
Count
Source
136
3.42k
{
137
3.42k
  RELOC *reloc_src = (RELOC *) src;
138
3.42k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
3.42k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
3.42k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
3.42k
  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.42k
}
pei-x86_64.c:coff_swap_reloc_in
Line
Count
Source
136
4.92k
{
137
4.92k
  RELOC *reloc_src = (RELOC *) src;
138
4.92k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
4.92k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
4.92k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
4.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
4.92k
}
pe-aarch64.c:coff_swap_reloc_in
Line
Count
Source
136
11.4k
{
137
11.4k
  RELOC *reloc_src = (RELOC *) src;
138
11.4k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
11.4k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
11.4k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
11.4k
  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
11.4k
}
pei-aarch64.c:coff_swap_reloc_in
Line
Count
Source
136
4.30k
{
137
4.30k
  RELOC *reloc_src = (RELOC *) src;
138
4.30k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
4.30k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
4.30k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
4.30k
  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.30k
}
pei-ia64.c:coff_swap_reloc_in
Line
Count
Source
136
3.36k
{
137
3.36k
  RELOC *reloc_src = (RELOC *) src;
138
3.36k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
3.36k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
3.36k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
3.36k
  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.36k
}
pei-loongarch64.c:coff_swap_reloc_in
Line
Count
Source
136
3.32k
{
137
3.32k
  RELOC *reloc_src = (RELOC *) src;
138
3.32k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
3.32k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
3.32k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
3.32k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
3.32k
#ifdef SWAP_IN_RELOC_OFFSET
144
3.32k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
3.32k
#endif
146
3.32k
}
pei-riscv64.c:coff_swap_reloc_in
Line
Count
Source
136
3.66k
{
137
3.66k
  RELOC *reloc_src = (RELOC *) src;
138
3.66k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
3.66k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
3.66k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
3.66k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
3.66k
#ifdef SWAP_IN_RELOC_OFFSET
144
3.66k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
3.66k
#endif
146
3.66k
}
pe-arm-wince.c:coff_swap_reloc_in
Line
Count
Source
136
1.69k
{
137
1.69k
  RELOC *reloc_src = (RELOC *) src;
138
1.69k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
1.69k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
1.69k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
1.69k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
1.69k
#ifdef SWAP_IN_RELOC_OFFSET
144
1.69k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
1.69k
#endif
146
1.69k
}
pe-arm.c:coff_swap_reloc_in
Line
Count
Source
136
1.69k
{
137
1.69k
  RELOC *reloc_src = (RELOC *) src;
138
1.69k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
1.69k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
1.69k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
1.69k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
1.69k
#ifdef SWAP_IN_RELOC_OFFSET
144
1.69k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
1.69k
#endif
146
1.69k
}
pe-i386.c:coff_swap_reloc_in
Line
Count
Source
136
4.64k
{
137
4.64k
  RELOC *reloc_src = (RELOC *) src;
138
4.64k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
4.64k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
4.64k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
4.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
4.64k
}
pe-mcore.c:coff_swap_reloc_in
Line
Count
Source
136
3.49k
{
137
3.49k
  RELOC *reloc_src = (RELOC *) src;
138
3.49k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
3.49k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
3.49k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
3.49k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
3.49k
#ifdef SWAP_IN_RELOC_OFFSET
144
3.49k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
3.49k
#endif
146
3.49k
}
pe-sh.c:coff_swap_reloc_in
Line
Count
Source
136
3.28k
{
137
3.28k
  RELOC *reloc_src = (RELOC *) src;
138
3.28k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
3.28k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
3.28k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
3.28k
  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.28k
}
pei-arm-wince.c:coff_swap_reloc_in
Line
Count
Source
136
4.71k
{
137
4.71k
  RELOC *reloc_src = (RELOC *) src;
138
4.71k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
4.71k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
4.71k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
4.71k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
4.71k
#ifdef SWAP_IN_RELOC_OFFSET
144
4.71k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
4.71k
#endif
146
4.71k
}
pei-arm.c:coff_swap_reloc_in
Line
Count
Source
136
4.84k
{
137
4.84k
  RELOC *reloc_src = (RELOC *) src;
138
4.84k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
4.84k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
4.84k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
4.84k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
4.84k
#ifdef SWAP_IN_RELOC_OFFSET
144
4.84k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
4.84k
#endif
146
4.84k
}
pei-mcore.c:coff_swap_reloc_in
Line
Count
Source
136
3.26k
{
137
3.26k
  RELOC *reloc_src = (RELOC *) src;
138
3.26k
  struct internal_reloc *reloc_dst = (struct internal_reloc *) dst;
139
140
3.26k
  reloc_dst->r_vaddr  = H_GET_32 (abfd, reloc_src->r_vaddr);
141
3.26k
  reloc_dst->r_symndx = H_GET_S32 (abfd, reloc_src->r_symndx);
142
3.26k
  reloc_dst->r_type   = H_GET_16 (abfd, reloc_src->r_type);
143
3.26k
#ifdef SWAP_IN_RELOC_OFFSET
144
3.26k
  reloc_dst->r_offset = SWAP_IN_RELOC_OFFSET (abfd, reloc_src->r_offset);
145
3.26k
#endif
146
3.26k
}
pei-sh.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
}
147
148
static unsigned int
149
coff_swap_reloc_out (bfd *abfd, void *src, void *dst)
150
206
{
151
206
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
152
206
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
153
154
206
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
155
206
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
156
206
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
157
158
#ifdef SWAP_OUT_RELOC_OFFSET
159
123
  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
206
  return RELSZ;
165
206
}
pei-i386.c:coff_swap_reloc_out
Line
Count
Source
150
19
{
151
19
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
152
19
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
153
154
19
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
155
19
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
156
19
  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
19
  return RELSZ;
165
19
}
pe-x86_64.c:coff_swap_reloc_out
Line
Count
Source
150
2
{
151
2
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
152
2
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
153
154
2
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
155
2
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
156
2
  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
2
  return RELSZ;
165
2
}
pei-x86_64.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
}
pe-aarch64.c:coff_swap_reloc_out
Line
Count
Source
150
8
{
151
8
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
152
8
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
153
154
8
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
155
8
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
156
8
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
157
158
#ifdef SWAP_OUT_RELOC_OFFSET
159
  SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
160
#endif
161
#ifdef SWAP_OUT_RELOC_EXTRA
162
  SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
163
#endif
164
8
  return RELSZ;
165
8
}
pei-aarch64.c:coff_swap_reloc_out
Line
Count
Source
150
24
{
151
24
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
152
24
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
153
154
24
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
155
24
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
156
24
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
157
158
#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
24
  return RELSZ;
165
24
}
Unexecuted instantiation: pei-ia64.c:coff_swap_reloc_out
pei-loongarch64.c:coff_swap_reloc_out
Line
Count
Source
150
27
{
151
27
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
152
27
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
153
154
27
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
155
27
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
156
27
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
157
158
27
#ifdef SWAP_OUT_RELOC_OFFSET
159
27
  SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
160
27
#endif
161
#ifdef SWAP_OUT_RELOC_EXTRA
162
  SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
163
#endif
164
27
  return RELSZ;
165
27
}
pei-riscv64.c:coff_swap_reloc_out
Line
Count
Source
150
12
{
151
12
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
152
12
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
153
154
12
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
155
12
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
156
12
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
157
158
12
#ifdef SWAP_OUT_RELOC_OFFSET
159
12
  SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
160
12
#endif
161
#ifdef SWAP_OUT_RELOC_EXTRA
162
  SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
163
#endif
164
12
  return RELSZ;
165
12
}
Unexecuted instantiation: pe-arm-wince.c:coff_swap_reloc_out
Unexecuted instantiation: pe-arm.c:coff_swap_reloc_out
Unexecuted instantiation: pe-i386.c:coff_swap_reloc_out
pe-mcore.c:coff_swap_reloc_out
Line
Count
Source
150
81
{
151
81
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
152
81
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
153
154
81
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
155
81
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
156
81
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
157
158
81
#ifdef SWAP_OUT_RELOC_OFFSET
159
81
  SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
160
81
#endif
161
#ifdef SWAP_OUT_RELOC_EXTRA
162
  SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
163
#endif
164
81
  return RELSZ;
165
81
}
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
3
{
151
3
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
152
3
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
153
154
3
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
155
3
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
156
3
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
157
158
3
#ifdef SWAP_OUT_RELOC_OFFSET
159
3
  SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
160
3
#endif
161
#ifdef SWAP_OUT_RELOC_EXTRA
162
  SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
163
#endif
164
3
  return RELSZ;
165
3
}
Unexecuted instantiation: pei-mcore.c:coff_swap_reloc_out
pei-sh.c:coff_swap_reloc_out
Line
Count
Source
150
21
{
151
21
  struct internal_reloc *reloc_src = (struct internal_reloc *) src;
152
21
  struct external_reloc *reloc_dst = (struct external_reloc *) dst;
153
154
21
  H_PUT_32 (abfd, reloc_src->r_vaddr, reloc_dst->r_vaddr);
155
21
  H_PUT_32 (abfd, reloc_src->r_symndx, reloc_dst->r_symndx);
156
21
  H_PUT_16 (abfd, reloc_src->r_type, reloc_dst->r_type);
157
158
#ifdef SWAP_OUT_RELOC_OFFSET
159
  SWAP_OUT_RELOC_OFFSET (abfd, reloc_src->r_offset, reloc_dst->r_offset);
160
#endif
161
#ifdef SWAP_OUT_RELOC_EXTRA
162
  SWAP_OUT_RELOC_EXTRA (abfd, reloc_src, reloc_dst);
163
#endif
164
21
  return RELSZ;
165
21
}
166
#endif /* not NO_COFF_RELOCS */
167
168
#ifdef COFF_IMAGE_WITH_PE
169
#undef FILHDR
170
455k
#define FILHDR struct external_PEI_IMAGE_hdr
171
#endif
172
173
static void
174
coff_swap_filehdr_in (bfd *abfd, void *src, void *dst)
175
2.19M
{
176
2.19M
  FILHDR *filehdr_src = (FILHDR *) src;
177
2.19M
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
2.19M
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
2.19M
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
2.19M
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
2.19M
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
2.19M
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
2.19M
  filehdr_dst->f_symptr = H_GET_32 (abfd, filehdr_src->f_symptr);
185
186
  /* Other people's tools sometimes generate headers with an nsyms but
187
     a zero symptr.  */
188
2.19M
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
211k
    {
190
211k
      filehdr_dst->f_nsyms = 0;
191
211k
      filehdr_dst->f_flags |= F_LSYMS;
192
211k
    }
193
194
2.19M
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
2.19M
}
pei-i386.c:coff_swap_filehdr_in
Line
Count
Source
175
52.0k
{
176
52.0k
  FILHDR *filehdr_src = (FILHDR *) src;
177
52.0k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
52.0k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
52.0k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
52.0k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
52.0k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
52.0k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
52.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
52.0k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
5.11k
    {
190
5.11k
      filehdr_dst->f_nsyms = 0;
191
5.11k
      filehdr_dst->f_flags |= F_LSYMS;
192
5.11k
    }
193
194
52.0k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
52.0k
}
pe-x86_64.c:coff_swap_filehdr_in
Line
Count
Source
175
191k
{
176
191k
  FILHDR *filehdr_src = (FILHDR *) src;
177
191k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
191k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
191k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
191k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
191k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
191k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
191k
  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
191k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
18.7k
    {
190
18.7k
      filehdr_dst->f_nsyms = 0;
191
18.7k
      filehdr_dst->f_flags |= F_LSYMS;
192
18.7k
    }
193
194
191k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
191k
}
pei-x86_64.c:coff_swap_filehdr_in
Line
Count
Source
175
50.6k
{
176
50.6k
  FILHDR *filehdr_src = (FILHDR *) src;
177
50.6k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
50.6k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
50.6k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
50.6k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
50.6k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
50.6k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
50.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
50.6k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
4.86k
    {
190
4.86k
      filehdr_dst->f_nsyms = 0;
191
4.86k
      filehdr_dst->f_flags |= F_LSYMS;
192
4.86k
    }
193
194
50.6k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
50.6k
}
pe-aarch64.c:coff_swap_filehdr_in
Line
Count
Source
175
189k
{
176
189k
  FILHDR *filehdr_src = (FILHDR *) src;
177
189k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
189k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
189k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
189k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
189k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
189k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
189k
  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
189k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
18.5k
    {
190
18.5k
      filehdr_dst->f_nsyms = 0;
191
18.5k
      filehdr_dst->f_flags |= F_LSYMS;
192
18.5k
    }
193
194
189k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
189k
}
pei-aarch64.c:coff_swap_filehdr_in
Line
Count
Source
175
49.4k
{
176
49.4k
  FILHDR *filehdr_src = (FILHDR *) src;
177
49.4k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
49.4k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
49.4k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
49.4k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
49.4k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
49.4k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
49.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
49.4k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
4.83k
    {
190
4.83k
      filehdr_dst->f_nsyms = 0;
191
4.83k
      filehdr_dst->f_flags |= F_LSYMS;
192
4.83k
    }
193
194
49.4k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
49.4k
}
pei-ia64.c:coff_swap_filehdr_in
Line
Count
Source
175
15.2k
{
176
15.2k
  FILHDR *filehdr_src = (FILHDR *) src;
177
15.2k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
15.2k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
15.2k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
15.2k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
15.2k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
15.2k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
15.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
15.2k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
536
    {
190
536
      filehdr_dst->f_nsyms = 0;
191
536
      filehdr_dst->f_flags |= F_LSYMS;
192
536
    }
193
194
15.2k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
15.2k
}
pei-loongarch64.c:coff_swap_filehdr_in
Line
Count
Source
175
48.8k
{
176
48.8k
  FILHDR *filehdr_src = (FILHDR *) src;
177
48.8k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
48.8k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
48.8k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
48.8k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
48.8k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
48.8k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
48.8k
  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
48.8k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
4.77k
    {
190
4.77k
      filehdr_dst->f_nsyms = 0;
191
4.77k
      filehdr_dst->f_flags |= F_LSYMS;
192
4.77k
    }
193
194
48.8k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
48.8k
}
pei-riscv64.c:coff_swap_filehdr_in
Line
Count
Source
175
48.8k
{
176
48.8k
  FILHDR *filehdr_src = (FILHDR *) src;
177
48.8k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
48.8k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
48.8k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
48.8k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
48.8k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
48.8k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
48.8k
  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
48.8k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
4.68k
    {
190
4.68k
      filehdr_dst->f_nsyms = 0;
191
4.68k
      filehdr_dst->f_flags |= F_LSYMS;
192
4.68k
    }
193
194
48.8k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
48.8k
}
pe-arm-wince.c:coff_swap_filehdr_in
Line
Count
Source
175
334k
{
176
334k
  FILHDR *filehdr_src = (FILHDR *) src;
177
334k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
334k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
334k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
334k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
334k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
334k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
334k
  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
334k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
31.7k
    {
190
31.7k
      filehdr_dst->f_nsyms = 0;
191
31.7k
      filehdr_dst->f_flags |= F_LSYMS;
192
31.7k
    }
193
194
334k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
334k
}
pe-arm.c:coff_swap_filehdr_in
Line
Count
Source
175
334k
{
176
334k
  FILHDR *filehdr_src = (FILHDR *) src;
177
334k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
334k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
334k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
334k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
334k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
334k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
334k
  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
334k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
31.7k
    {
190
31.7k
      filehdr_dst->f_nsyms = 0;
191
31.7k
      filehdr_dst->f_flags |= F_LSYMS;
192
31.7k
    }
193
194
334k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
334k
}
pe-i386.c:coff_swap_filehdr_in
Line
Count
Source
175
189k
{
176
189k
  FILHDR *filehdr_src = (FILHDR *) src;
177
189k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
189k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
189k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
189k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
189k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
189k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
189k
  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
189k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
18.6k
    {
190
18.6k
      filehdr_dst->f_nsyms = 0;
191
18.6k
      filehdr_dst->f_flags |= F_LSYMS;
192
18.6k
    }
193
194
189k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
189k
}
pe-mcore.c:coff_swap_filehdr_in
Line
Count
Source
175
334k
{
176
334k
  FILHDR *filehdr_src = (FILHDR *) src;
177
334k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
334k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
334k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
334k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
334k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
334k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
334k
  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
334k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
31.9k
    {
190
31.9k
      filehdr_dst->f_nsyms = 0;
191
31.9k
      filehdr_dst->f_flags |= F_LSYMS;
192
31.9k
    }
193
194
334k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
334k
}
pe-sh.c:coff_swap_filehdr_in
Line
Count
Source
175
168k
{
176
168k
  FILHDR *filehdr_src = (FILHDR *) src;
177
168k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
168k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
168k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
168k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
168k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
168k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
168k
  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
168k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
16.1k
    {
190
16.1k
      filehdr_dst->f_nsyms = 0;
191
16.1k
      filehdr_dst->f_flags |= F_LSYMS;
192
16.1k
    }
193
194
168k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
168k
}
pei-arm-wince.c:coff_swap_filehdr_in
Line
Count
Source
175
47.6k
{
176
47.6k
  FILHDR *filehdr_src = (FILHDR *) src;
177
47.6k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
47.6k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
47.6k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
47.6k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
47.6k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
47.6k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
47.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
47.6k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
4.71k
    {
190
4.71k
      filehdr_dst->f_nsyms = 0;
191
4.71k
      filehdr_dst->f_flags |= F_LSYMS;
192
4.71k
    }
193
194
47.6k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
47.6k
}
pei-arm.c:coff_swap_filehdr_in
Line
Count
Source
175
47.8k
{
176
47.8k
  FILHDR *filehdr_src = (FILHDR *) src;
177
47.8k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
47.8k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
47.8k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
47.8k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
47.8k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
47.8k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
47.8k
  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.8k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
4.74k
    {
190
4.74k
      filehdr_dst->f_nsyms = 0;
191
4.74k
      filehdr_dst->f_flags |= F_LSYMS;
192
4.74k
    }
193
194
47.8k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
47.8k
}
pei-mcore.c:coff_swap_filehdr_in
Line
Count
Source
175
47.4k
{
176
47.4k
  FILHDR *filehdr_src = (FILHDR *) src;
177
47.4k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
47.4k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
47.4k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
47.4k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
47.4k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
47.4k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
47.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
47.4k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
4.63k
    {
190
4.63k
      filehdr_dst->f_nsyms = 0;
191
4.63k
      filehdr_dst->f_flags |= F_LSYMS;
192
4.63k
    }
193
194
47.4k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
47.4k
}
pei-sh.c:coff_swap_filehdr_in
Line
Count
Source
175
47.4k
{
176
47.4k
  FILHDR *filehdr_src = (FILHDR *) src;
177
47.4k
  struct internal_filehdr *filehdr_dst = (struct internal_filehdr *) dst;
178
179
47.4k
  filehdr_dst->f_magic  = H_GET_16 (abfd, filehdr_src->f_magic);
180
47.4k
  filehdr_dst->f_nscns  = H_GET_16 (abfd, filehdr_src->f_nscns);
181
47.4k
  filehdr_dst->f_timdat = H_GET_32 (abfd, filehdr_src->f_timdat);
182
47.4k
  filehdr_dst->f_nsyms  = H_GET_32 (abfd, filehdr_src->f_nsyms);
183
47.4k
  filehdr_dst->f_flags  = H_GET_16 (abfd, filehdr_src->f_flags);
184
47.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
47.4k
  if (filehdr_dst->f_nsyms != 0 && filehdr_dst->f_symptr == 0)
189
4.65k
    {
190
4.65k
      filehdr_dst->f_nsyms = 0;
191
4.65k
      filehdr_dst->f_flags |= F_LSYMS;
192
4.65k
    }
193
194
47.4k
  filehdr_dst->f_opthdr = H_GET_16 (abfd, filehdr_src-> f_opthdr);
195
47.4k
}
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
828k
{
212
828k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
828k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
828k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
828k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
828k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
828k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
828k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
828k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
828k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
828k
  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
553k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
553k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
  scnhdr_int->s_nreloc = 0;
232
#else
233
275k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
275k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
#endif
236
237
828k
  if (scnhdr_int->s_vaddr != 0)
238
534k
    {
239
534k
      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
534k
    }
246
247
828k
#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
828k
  if (scnhdr_int->s_paddr > 0
253
595k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
136k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
542k
    || (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
164k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
828k
#endif
262
828k
}
pei-i386.c:coff_swap_scnhdr_in
Line
Count
Source
211
58.8k
{
212
58.8k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
58.8k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
58.8k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
58.8k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
58.8k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
58.8k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
58.8k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
58.8k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
58.8k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
58.8k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
58.8k
#ifdef COFF_IMAGE_WITH_PE
229
58.8k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
58.8k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
58.8k
  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.8k
  if (scnhdr_int->s_vaddr != 0)
238
38.7k
    {
239
38.7k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
38.7k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
38.7k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
38.7k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
38.7k
#endif
245
38.7k
    }
246
247
58.8k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
58.8k
  if (scnhdr_int->s_paddr > 0
253
43.1k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
10.7k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
41.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
14.8k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
58.8k
#endif
262
58.8k
}
pe-x86_64.c:coff_swap_scnhdr_in
Line
Count
Source
211
61.4k
{
212
61.4k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
61.4k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
61.4k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
61.4k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
61.4k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
61.4k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
61.4k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
61.4k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
61.4k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
61.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
61.4k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
61.4k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
61.4k
#endif
236
237
61.4k
  if (scnhdr_int->s_vaddr != 0)
238
34.0k
    {
239
34.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
34.0k
    }
246
247
61.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
61.4k
  if (scnhdr_int->s_paddr > 0
253
36.5k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
6.37k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
30.1k
    || (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.37k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
61.4k
#endif
262
61.4k
}
pei-x86_64.c:coff_swap_scnhdr_in
Line
Count
Source
211
65.0k
{
212
65.0k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
65.0k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
65.0k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
65.0k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
65.0k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
65.0k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
65.0k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
65.0k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
65.0k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
65.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
65.0k
#ifdef COFF_IMAGE_WITH_PE
229
65.0k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
65.0k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
65.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
65.0k
  if (scnhdr_int->s_vaddr != 0)
238
40.4k
    {
239
40.4k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
      scnhdr_int->s_vaddr &= 0xffffffff;
244
#endif
245
40.4k
    }
246
247
65.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
65.0k
  if (scnhdr_int->s_paddr > 0
253
44.1k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
10.2k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
42.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
14.1k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
65.0k
#endif
262
65.0k
}
pe-aarch64.c:coff_swap_scnhdr_in
Line
Count
Source
211
38.0k
{
212
38.0k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
38.0k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
38.0k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
38.0k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
38.0k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
38.0k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
38.0k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
38.0k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
38.0k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
38.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
38.0k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
38.0k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
38.0k
#endif
236
237
38.0k
  if (scnhdr_int->s_vaddr != 0)
238
23.1k
    {
239
23.1k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
      scnhdr_int->s_vaddr &= 0xffffffff;
244
#endif
245
23.1k
    }
246
247
38.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
38.0k
  if (scnhdr_int->s_paddr > 0
253
26.6k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
4.56k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
22.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
38.0k
#endif
262
38.0k
}
pei-aarch64.c:coff_swap_scnhdr_in
Line
Count
Source
211
70.4k
{
212
70.4k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
70.4k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
70.4k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
70.4k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
70.4k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
70.4k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
70.4k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
70.4k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
70.4k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
70.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
70.4k
#ifdef COFF_IMAGE_WITH_PE
229
70.4k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
70.4k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
70.4k
  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
70.4k
  if (scnhdr_int->s_vaddr != 0)
238
49.2k
    {
239
49.2k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
      scnhdr_int->s_vaddr &= 0xffffffff;
244
#endif
245
49.2k
    }
246
247
70.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
70.4k
  if (scnhdr_int->s_paddr > 0
253
52.1k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
11.4k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
50.1k
    || (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
18.6k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
70.4k
#endif
262
70.4k
}
pei-ia64.c:coff_swap_scnhdr_in
Line
Count
Source
211
51.1k
{
212
51.1k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
51.1k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
51.1k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
51.1k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
51.1k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
51.1k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
51.1k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
51.1k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
51.1k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
51.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
51.1k
#ifdef COFF_IMAGE_WITH_PE
229
51.1k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
51.1k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
51.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
51.1k
  if (scnhdr_int->s_vaddr != 0)
238
32.3k
    {
239
32.3k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
32.3k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
32.3k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
32.3k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
32.3k
#endif
245
32.3k
    }
246
247
51.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
51.1k
  if (scnhdr_int->s_paddr > 0
253
36.2k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
8.42k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
34.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
11.4k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
51.1k
#endif
262
51.1k
}
pei-loongarch64.c:coff_swap_scnhdr_in
Line
Count
Source
211
47.6k
{
212
47.6k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
47.6k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
47.6k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
47.6k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
47.6k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
47.6k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
47.6k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
47.6k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
47.6k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
47.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
47.6k
#ifdef COFF_IMAGE_WITH_PE
229
47.6k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
47.6k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
47.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
47.6k
  if (scnhdr_int->s_vaddr != 0)
238
31.5k
    {
239
31.5k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
      scnhdr_int->s_vaddr &= 0xffffffff;
244
#endif
245
31.5k
    }
246
247
47.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
47.6k
  if (scnhdr_int->s_paddr > 0
253
34.9k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
7.33k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
33.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
11.5k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
47.6k
#endif
262
47.6k
}
pei-riscv64.c:coff_swap_scnhdr_in
Line
Count
Source
211
55.3k
{
212
55.3k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
55.3k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
55.3k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
55.3k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
55.3k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
55.3k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
55.3k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
55.3k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
55.3k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
55.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
55.3k
#ifdef COFF_IMAGE_WITH_PE
229
55.3k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
55.3k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
55.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
55.3k
  if (scnhdr_int->s_vaddr != 0)
238
35.1k
    {
239
35.1k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
      scnhdr_int->s_vaddr &= 0xffffffff;
244
#endif
245
35.1k
    }
246
247
55.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
55.3k
  if (scnhdr_int->s_paddr > 0
253
40.6k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
11.0k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
39.1k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
11.2k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
55.3k
#endif
262
55.3k
}
pe-arm-wince.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.3k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
3.73k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
12.6k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
3.73k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
23.0k
#endif
262
23.0k
}
pe-arm.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.3k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
3.73k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
12.6k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
3.73k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
23.0k
#endif
262
23.0k
}
pe-i386.c:coff_swap_scnhdr_in
Line
Count
Source
211
56.6k
{
212
56.6k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
56.6k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
56.6k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
56.6k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
56.6k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
56.6k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
56.6k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
56.6k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
56.6k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
56.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
#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
56.6k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
56.6k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
56.6k
#endif
236
237
56.6k
  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
36.6k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
36.6k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
36.6k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
36.6k
#endif
245
36.6k
    }
246
247
56.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
56.6k
  if (scnhdr_int->s_paddr > 0
253
41.0k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
8.68k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
32.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
8.68k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
56.6k
#endif
262
56.6k
}
pe-mcore.c:coff_swap_scnhdr_in
Line
Count
Source
211
28.6k
{
212
28.6k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
28.6k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
28.6k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
28.6k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
28.6k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
28.6k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
28.6k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
28.6k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
28.6k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
28.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
#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
28.6k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
28.6k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
28.6k
#endif
236
237
28.6k
  if (scnhdr_int->s_vaddr != 0)
238
17.5k
    {
239
17.5k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
17.5k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
17.5k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
17.5k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
17.5k
#endif
245
17.5k
    }
246
247
28.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
28.6k
  if (scnhdr_int->s_paddr > 0
253
19.7k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
3.55k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
16.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
3.55k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
28.6k
#endif
262
28.6k
}
pe-sh.c:coff_swap_scnhdr_in
Line
Count
Source
211
44.2k
{
212
44.2k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
44.2k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
44.2k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
44.2k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
44.2k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
44.2k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
44.2k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
44.2k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
44.2k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
44.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
#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
44.2k
  scnhdr_int->s_nreloc = H_GET_16 (abfd, scnhdr_ext->s_nreloc);
234
44.2k
  scnhdr_int->s_nlnno = H_GET_16 (abfd, scnhdr_ext->s_nlnno);
235
44.2k
#endif
236
237
44.2k
  if (scnhdr_int->s_vaddr != 0)
238
28.3k
    {
239
28.3k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
28.3k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
28.3k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
28.3k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
28.3k
#endif
245
28.3k
    }
246
247
44.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
44.2k
  if (scnhdr_int->s_paddr > 0
253
31.5k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
6.76k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
24.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
6.76k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
44.2k
#endif
262
44.2k
}
pei-arm-wince.c:coff_swap_scnhdr_in
Line
Count
Source
211
45.1k
{
212
45.1k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
45.1k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
45.1k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
45.1k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
45.1k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
45.1k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
45.1k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
45.1k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
45.1k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
45.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
45.1k
#ifdef COFF_IMAGE_WITH_PE
229
45.1k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
45.1k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
45.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
45.1k
  if (scnhdr_int->s_vaddr != 0)
238
29.1k
    {
239
29.1k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
29.1k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
29.1k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
29.1k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
29.1k
#endif
245
29.1k
    }
246
247
45.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
45.1k
  if (scnhdr_int->s_paddr > 0
253
34.4k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
8.91k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
33.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.5k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
45.1k
#endif
262
45.1k
}
pei-arm.c:coff_swap_scnhdr_in
Line
Count
Source
211
60.3k
{
212
60.3k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
60.3k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
60.3k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
60.3k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
60.3k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
60.3k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
60.3k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
60.3k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
60.3k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
60.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
60.3k
#ifdef COFF_IMAGE_WITH_PE
229
60.3k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
60.3k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
60.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
60.3k
  if (scnhdr_int->s_vaddr != 0)
238
40.1k
    {
239
40.1k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
40.1k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
40.1k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
40.1k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
40.1k
#endif
245
40.1k
    }
246
247
60.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
60.3k
  if (scnhdr_int->s_paddr > 0
253
46.0k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
11.6k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
44.1k
    || (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.1k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
60.3k
#endif
262
60.3k
}
pei-mcore.c:coff_swap_scnhdr_in
Line
Count
Source
211
53.3k
{
212
53.3k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
53.3k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
53.3k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
53.3k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
53.3k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
53.3k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
53.3k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
53.3k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
53.3k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
53.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
53.3k
#ifdef COFF_IMAGE_WITH_PE
229
53.3k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
53.3k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
53.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
53.3k
  if (scnhdr_int->s_vaddr != 0)
238
35.9k
    {
239
35.9k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
35.9k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
35.9k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
35.9k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
35.9k
#endif
245
35.9k
    }
246
247
53.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
53.3k
  if (scnhdr_int->s_paddr > 0
253
40.3k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
8.58k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
39.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.9k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
53.3k
#endif
262
53.3k
}
pei-sh.c:coff_swap_scnhdr_in
Line
Count
Source
211
45.8k
{
212
45.8k
  SCNHDR *scnhdr_ext = (SCNHDR *) ext;
213
45.8k
  struct internal_scnhdr *scnhdr_int = (struct internal_scnhdr *) in;
214
215
45.8k
  memcpy (scnhdr_int->s_name, scnhdr_ext->s_name, sizeof (scnhdr_int->s_name));
216
217
45.8k
  scnhdr_int->s_vaddr   = GET_SCNHDR_VADDR (abfd, scnhdr_ext->s_vaddr);
218
45.8k
  scnhdr_int->s_paddr   = GET_SCNHDR_PADDR (abfd, scnhdr_ext->s_paddr);
219
45.8k
  scnhdr_int->s_size    = GET_SCNHDR_SIZE (abfd, scnhdr_ext->s_size);
220
45.8k
  scnhdr_int->s_scnptr  = GET_SCNHDR_SCNPTR (abfd, scnhdr_ext->s_scnptr);
221
45.8k
  scnhdr_int->s_relptr  = GET_SCNHDR_RELPTR (abfd, scnhdr_ext->s_relptr);
222
45.8k
  scnhdr_int->s_lnnoptr = GET_SCNHDR_LNNOPTR (abfd, scnhdr_ext->s_lnnoptr);
223
45.8k
  scnhdr_int->s_flags   = H_GET_32 (abfd, scnhdr_ext->s_flags);
224
225
  /* MS handles overflow of line numbers by carrying into the reloc
226
     field (it appears).  Since it's supposed to be zero for PE
227
     *IMAGE* format, that's safe.  This is still a bit iffy.  */
228
45.8k
#ifdef COFF_IMAGE_WITH_PE
229
45.8k
  scnhdr_int->s_nlnno = (H_GET_16 (abfd, scnhdr_ext->s_nlnno)
230
45.8k
       + (H_GET_16 (abfd, scnhdr_ext->s_nreloc) << 16));
231
45.8k
  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.8k
  if (scnhdr_int->s_vaddr != 0)
238
31.5k
    {
239
31.5k
      scnhdr_int->s_vaddr += pe_data (abfd)->pe_opthdr.ImageBase;
240
      /* Do not cut upper 32-bits for 64-bit vma.  */
241
31.5k
#if (!defined(COFF_WITH_pex64) && !defined(COFF_WITH_peAArch64) \
242
31.5k
     && !defined(COFF_WITH_peLoongArch64) && !defined(COFF_WITH_peRiscV64))
243
31.5k
      scnhdr_int->s_vaddr &= 0xffffffff;
244
31.5k
#endif
245
31.5k
    }
246
247
45.8k
#ifndef COFF_NO_HACK_SCNHDR_SIZE
248
  /* If this section holds uninitialized data and is from an object file
249
     or from an executable image that has not initialized the field,
250
     or if the image is an executable file and the physical size is padded,
251
     use the virtual size (stored in s_paddr) instead.  */
252
45.8k
  if (scnhdr_int->s_paddr > 0
253
35.1k
      && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
254
10.2k
     && (! bfd_pei_p (abfd) || scnhdr_int->s_size == 0))
255
33.7k
    || (bfd_pei_p (abfd) && (scnhdr_int->s_size > scnhdr_int->s_paddr))))
256
  /* This code used to set scnhdr_int->s_paddr to 0.  However,
257
     coff_set_alignment_hook stores s_paddr in virt_size, which
258
     only works if it correctly holds the virtual size of the
259
     section.  */
260
10.9k
    scnhdr_int->s_size = scnhdr_int->s_paddr;
261
45.8k
#endif
262
45.8k
}
263
264
static bool
265
pe_mkobject (bfd *abfd)
266
106k
{
267
  /* Some x86 code followed by an ascii string.  */
268
106k
  static const char default_dos_message[64] = {
269
106k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
106k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
106k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
106k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
106k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
106k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
106k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
106k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
106k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
106k
  abfd->tdata.pe_obj_data = pe;
280
106k
  if (pe == NULL)
281
0
    return false;
282
283
106k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
106k
  pe->in_reloc_p = in_reloc_p;
287
288
106k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
106k
  bfd_coff_long_section_names (abfd)
291
106k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
106k
  return true;
294
106k
}
pei-i386.c:pe_mkobject
Line
Count
Source
266
10.3k
{
267
  /* Some x86 code followed by an ascii string.  */
268
10.3k
  static const char default_dos_message[64] = {
269
10.3k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
10.3k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
10.3k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
10.3k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
10.3k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
10.3k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
10.3k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
10.3k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
10.3k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
10.3k
  abfd->tdata.pe_obj_data = pe;
280
10.3k
  if (pe == NULL)
281
0
    return false;
282
283
10.3k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
10.3k
  pe->in_reloc_p = in_reloc_p;
287
288
10.3k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
10.3k
  bfd_coff_long_section_names (abfd)
291
10.3k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
10.3k
}
pe-x86_64.c:pe_mkobject
Line
Count
Source
266
9.73k
{
267
  /* Some x86 code followed by an ascii string.  */
268
9.73k
  static const char default_dos_message[64] = {
269
9.73k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
9.73k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
9.73k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
9.73k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
9.73k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
9.73k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
9.73k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
9.73k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
9.73k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
9.73k
  abfd->tdata.pe_obj_data = pe;
280
9.73k
  if (pe == NULL)
281
0
    return false;
282
283
9.73k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
9.73k
  pe->in_reloc_p = in_reloc_p;
287
288
9.73k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
9.73k
  bfd_coff_long_section_names (abfd)
291
9.73k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
9.73k
}
pei-x86_64.c:pe_mkobject
Line
Count
Source
266
7.49k
{
267
  /* Some x86 code followed by an ascii string.  */
268
7.49k
  static const char default_dos_message[64] = {
269
7.49k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
7.49k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
7.49k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
7.49k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
7.49k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
7.49k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
7.49k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
7.49k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
7.49k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
7.49k
  abfd->tdata.pe_obj_data = pe;
280
7.49k
  if (pe == NULL)
281
0
    return false;
282
283
7.49k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
7.49k
  pe->in_reloc_p = in_reloc_p;
287
288
7.49k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
7.49k
  bfd_coff_long_section_names (abfd)
291
7.49k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
7.49k
}
pe-aarch64.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
}
pei-aarch64.c:pe_mkobject
Line
Count
Source
266
8.66k
{
267
  /* Some x86 code followed by an ascii string.  */
268
8.66k
  static const char default_dos_message[64] = {
269
8.66k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
8.66k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
8.66k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
8.66k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
8.66k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
8.66k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
8.66k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
8.66k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
8.66k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
8.66k
  abfd->tdata.pe_obj_data = pe;
280
8.66k
  if (pe == NULL)
281
0
    return false;
282
283
8.66k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
8.66k
  pe->in_reloc_p = in_reloc_p;
287
288
8.66k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
8.66k
  bfd_coff_long_section_names (abfd)
291
8.66k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
8.66k
}
pei-ia64.c:pe_mkobject
Line
Count
Source
266
5.91k
{
267
  /* Some x86 code followed by an ascii string.  */
268
5.91k
  static const char default_dos_message[64] = {
269
5.91k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
5.91k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
5.91k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
5.91k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
5.91k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
5.91k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
5.91k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
5.91k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
5.91k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
5.91k
  abfd->tdata.pe_obj_data = pe;
280
5.91k
  if (pe == NULL)
281
0
    return false;
282
283
5.91k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
5.91k
  pe->in_reloc_p = in_reloc_p;
287
288
5.91k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
5.91k
  bfd_coff_long_section_names (abfd)
291
5.91k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
5.91k
}
pei-loongarch64.c:pe_mkobject
Line
Count
Source
266
6.02k
{
267
  /* Some x86 code followed by an ascii string.  */
268
6.02k
  static const char default_dos_message[64] = {
269
6.02k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
6.02k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
6.02k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
6.02k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
6.02k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
6.02k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
6.02k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
6.02k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
6.02k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
6.02k
  abfd->tdata.pe_obj_data = pe;
280
6.02k
  if (pe == NULL)
281
0
    return false;
282
283
6.02k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
6.02k
  pe->in_reloc_p = in_reloc_p;
287
288
6.02k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
6.02k
  bfd_coff_long_section_names (abfd)
291
6.02k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
6.02k
}
pei-riscv64.c:pe_mkobject
Line
Count
Source
266
6.19k
{
267
  /* Some x86 code followed by an ascii string.  */
268
6.19k
  static const char default_dos_message[64] = {
269
6.19k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
6.19k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
6.19k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
6.19k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
6.19k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
6.19k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
6.19k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
6.19k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
6.19k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
6.19k
  abfd->tdata.pe_obj_data = pe;
280
6.19k
  if (pe == NULL)
281
0
    return false;
282
283
6.19k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
6.19k
  pe->in_reloc_p = in_reloc_p;
287
288
6.19k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
6.19k
  bfd_coff_long_section_names (abfd)
291
6.19k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
6.19k
}
pe-arm-wince.c:pe_mkobject
Line
Count
Source
266
2.66k
{
267
  /* Some x86 code followed by an ascii string.  */
268
2.66k
  static const char default_dos_message[64] = {
269
2.66k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
2.66k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
2.66k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
2.66k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
2.66k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
2.66k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
2.66k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
2.66k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
2.66k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
2.66k
  abfd->tdata.pe_obj_data = pe;
280
2.66k
  if (pe == NULL)
281
0
    return false;
282
283
2.66k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
2.66k
  pe->in_reloc_p = in_reloc_p;
287
288
2.66k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
2.66k
  bfd_coff_long_section_names (abfd)
291
2.66k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
2.66k
}
pe-arm.c:pe_mkobject
Line
Count
Source
266
2.66k
{
267
  /* Some x86 code followed by an ascii string.  */
268
2.66k
  static const char default_dos_message[64] = {
269
2.66k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
2.66k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
2.66k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
2.66k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
2.66k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
2.66k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
2.66k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
2.66k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
2.66k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
2.66k
  abfd->tdata.pe_obj_data = pe;
280
2.66k
  if (pe == NULL)
281
0
    return false;
282
283
2.66k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
2.66k
  pe->in_reloc_p = in_reloc_p;
287
288
2.66k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
2.66k
  bfd_coff_long_section_names (abfd)
291
2.66k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
2.66k
}
pe-i386.c:pe_mkobject
Line
Count
Source
266
9.49k
{
267
  /* Some x86 code followed by an ascii string.  */
268
9.49k
  static const char default_dos_message[64] = {
269
9.49k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
9.49k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
9.49k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
9.49k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
9.49k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
9.49k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
9.49k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
9.49k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
9.49k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
9.49k
  abfd->tdata.pe_obj_data = pe;
280
9.49k
  if (pe == NULL)
281
0
    return false;
282
283
9.49k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
9.49k
  pe->in_reloc_p = in_reloc_p;
287
288
9.49k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
9.49k
  bfd_coff_long_section_names (abfd)
291
9.49k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
9.49k
}
pe-mcore.c:pe_mkobject
Line
Count
Source
266
3.81k
{
267
  /* Some x86 code followed by an ascii string.  */
268
3.81k
  static const char default_dos_message[64] = {
269
3.81k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
3.81k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
3.81k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
3.81k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
3.81k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
3.81k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
3.81k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
3.81k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
3.81k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
3.81k
  abfd->tdata.pe_obj_data = pe;
280
3.81k
  if (pe == NULL)
281
0
    return false;
282
283
3.81k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
3.81k
  pe->in_reloc_p = in_reloc_p;
287
288
3.81k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
3.81k
  bfd_coff_long_section_names (abfd)
291
3.81k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
3.81k
}
pe-sh.c:pe_mkobject
Line
Count
Source
266
5.23k
{
267
  /* Some x86 code followed by an ascii string.  */
268
5.23k
  static const char default_dos_message[64] = {
269
5.23k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
5.23k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
5.23k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
5.23k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
5.23k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
5.23k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
5.23k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
5.23k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
5.23k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
5.23k
  abfd->tdata.pe_obj_data = pe;
280
5.23k
  if (pe == NULL)
281
0
    return false;
282
283
5.23k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
5.23k
  pe->in_reloc_p = in_reloc_p;
287
288
5.23k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
5.23k
  bfd_coff_long_section_names (abfd)
291
5.23k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
5.23k
}
pei-arm-wince.c:pe_mkobject
Line
Count
Source
266
5.54k
{
267
  /* Some x86 code followed by an ascii string.  */
268
5.54k
  static const char default_dos_message[64] = {
269
5.54k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
5.54k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
5.54k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
5.54k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
5.54k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
5.54k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
5.54k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
5.54k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
5.54k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
5.54k
  abfd->tdata.pe_obj_data = pe;
280
5.54k
  if (pe == NULL)
281
0
    return false;
282
283
5.54k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
5.54k
  pe->in_reloc_p = in_reloc_p;
287
288
5.54k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
5.54k
  bfd_coff_long_section_names (abfd)
291
5.54k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
5.54k
}
pei-arm.c:pe_mkobject
Line
Count
Source
266
7.10k
{
267
  /* Some x86 code followed by an ascii string.  */
268
7.10k
  static const char default_dos_message[64] = {
269
7.10k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
7.10k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
7.10k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
7.10k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
7.10k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
7.10k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
7.10k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
7.10k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
7.10k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
7.10k
  abfd->tdata.pe_obj_data = pe;
280
7.10k
  if (pe == NULL)
281
0
    return false;
282
283
7.10k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
7.10k
  pe->in_reloc_p = in_reloc_p;
287
288
7.10k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
7.10k
  bfd_coff_long_section_names (abfd)
291
7.10k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
7.10k
}
pei-mcore.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-sh.c:pe_mkobject
Line
Count
Source
266
5.23k
{
267
  /* Some x86 code followed by an ascii string.  */
268
5.23k
  static const char default_dos_message[64] = {
269
5.23k
    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
270
5.23k
    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
271
5.23k
    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
272
5.23k
    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
273
5.23k
    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
274
5.23k
    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
275
5.23k
    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
276
5.23k
    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
277
278
5.23k
  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
279
5.23k
  abfd->tdata.pe_obj_data = pe;
280
5.23k
  if (pe == NULL)
281
0
    return false;
282
283
5.23k
  pe->coff.pe = 1;
284
285
  /* in_reloc_p is architecture dependent.  */
286
5.23k
  pe->in_reloc_p = in_reloc_p;
287
288
5.23k
  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
289
290
5.23k
  bfd_coff_long_section_names (abfd)
291
5.23k
    = coff_backend_info (abfd)->_bfd_coff_long_section_names;
292
293
  return true;
294
5.23k
}
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
100k
{
303
100k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
100k
  pe_data_type *pe;
305
306
100k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
100k
  pe = pe_data (abfd);
310
100k
  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
100k
  pe->coff.local_n_btmask = N_BTMASK;
315
100k
  pe->coff.local_n_btshft = N_BTSHFT;
316
100k
  pe->coff.local_n_tmask = N_TMASK;
317
100k
  pe->coff.local_n_tshift = N_TSHIFT;
318
100k
  pe->coff.local_symesz = SYMESZ;
319
100k
  pe->coff.local_auxesz = AUXESZ;
320
100k
  pe->coff.local_linesz = LINESZ;
321
322
100k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
100k
  obj_raw_syment_count (abfd) =
325
100k
    obj_conv_table_size (abfd) =
326
100k
      internal_f->f_nsyms;
327
328
100k
  pe->real_flags = internal_f->f_flags;
329
330
100k
  if ((internal_f->f_flags & F_DLL) != 0)
331
30.6k
    pe->dll = 1;
332
333
100k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
72.0k
    abfd->flags |= HAS_DEBUG;
335
336
#ifdef COFF_IMAGE_WITH_PE
337
64.0k
  if (aouthdr)
338
35.5k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
#endif
340
341
#ifdef ARM
342
17.4k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
0
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
100k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
100k
    sizeof (pe->dos_message));
348
349
100k
  return (void *) pe;
350
100k
}
pei-i386.c:pe_mkobject_hook
Line
Count
Source
302
9.95k
{
303
9.95k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
9.95k
  pe_data_type *pe;
305
306
9.95k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
9.95k
  pe = pe_data (abfd);
310
9.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
9.95k
  pe->coff.local_n_btmask = N_BTMASK;
315
9.95k
  pe->coff.local_n_btshft = N_BTSHFT;
316
9.95k
  pe->coff.local_n_tmask = N_TMASK;
317
9.95k
  pe->coff.local_n_tshift = N_TSHIFT;
318
9.95k
  pe->coff.local_symesz = SYMESZ;
319
9.95k
  pe->coff.local_auxesz = AUXESZ;
320
9.95k
  pe->coff.local_linesz = LINESZ;
321
322
9.95k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
9.95k
  obj_raw_syment_count (abfd) =
325
9.95k
    obj_conv_table_size (abfd) =
326
9.95k
      internal_f->f_nsyms;
327
328
9.95k
  pe->real_flags = internal_f->f_flags;
329
330
9.95k
  if ((internal_f->f_flags & F_DLL) != 0)
331
2.64k
    pe->dll = 1;
332
333
9.95k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
7.76k
    abfd->flags |= HAS_DEBUG;
335
336
9.95k
#ifdef COFF_IMAGE_WITH_PE
337
9.95k
  if (aouthdr)
338
4.63k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
9.95k
#endif
340
341
#ifdef ARM
342
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
    coff_data (abfd) ->flags = 0;
344
#endif
345
346
9.95k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
9.95k
    sizeof (pe->dos_message));
348
349
9.95k
  return (void *) pe;
350
9.95k
}
pe-x86_64.c:pe_mkobject_hook
Line
Count
Source
302
9.08k
{
303
9.08k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
9.08k
  pe_data_type *pe;
305
306
9.08k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
9.08k
  pe = pe_data (abfd);
310
9.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
9.08k
  pe->coff.local_n_btmask = N_BTMASK;
315
9.08k
  pe->coff.local_n_btshft = N_BTSHFT;
316
9.08k
  pe->coff.local_n_tmask = N_TMASK;
317
9.08k
  pe->coff.local_n_tshift = N_TSHIFT;
318
9.08k
  pe->coff.local_symesz = SYMESZ;
319
9.08k
  pe->coff.local_auxesz = AUXESZ;
320
9.08k
  pe->coff.local_linesz = LINESZ;
321
322
9.08k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
9.08k
  obj_raw_syment_count (abfd) =
325
9.08k
    obj_conv_table_size (abfd) =
326
9.08k
      internal_f->f_nsyms;
327
328
9.08k
  pe->real_flags = internal_f->f_flags;
329
330
9.08k
  if ((internal_f->f_flags & F_DLL) != 0)
331
2.36k
    pe->dll = 1;
332
333
9.08k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
6.76k
    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
9.08k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
9.08k
    sizeof (pe->dos_message));
348
349
9.08k
  return (void *) pe;
350
9.08k
}
pei-x86_64.c:pe_mkobject_hook
Line
Count
Source
302
7.13k
{
303
7.13k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
7.13k
  pe_data_type *pe;
305
306
7.13k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
7.13k
  pe = pe_data (abfd);
310
7.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
7.13k
  pe->coff.local_n_btmask = N_BTMASK;
315
7.13k
  pe->coff.local_n_btshft = N_BTSHFT;
316
7.13k
  pe->coff.local_n_tmask = N_TMASK;
317
7.13k
  pe->coff.local_n_tshift = N_TSHIFT;
318
7.13k
  pe->coff.local_symesz = SYMESZ;
319
7.13k
  pe->coff.local_auxesz = AUXESZ;
320
7.13k
  pe->coff.local_linesz = LINESZ;
321
322
7.13k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
7.13k
  obj_raw_syment_count (abfd) =
325
7.13k
    obj_conv_table_size (abfd) =
326
7.13k
      internal_f->f_nsyms;
327
328
7.13k
  pe->real_flags = internal_f->f_flags;
329
330
7.13k
  if ((internal_f->f_flags & F_DLL) != 0)
331
2.70k
    pe->dll = 1;
332
333
7.13k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
4.65k
    abfd->flags |= HAS_DEBUG;
335
336
7.13k
#ifdef COFF_IMAGE_WITH_PE
337
7.13k
  if (aouthdr)
338
4.19k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
7.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
7.13k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
7.13k
    sizeof (pe->dos_message));
348
349
7.13k
  return (void *) pe;
350
7.13k
}
pe-aarch64.c:pe_mkobject_hook
Line
Count
Source
302
4.45k
{
303
4.45k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
4.45k
  pe_data_type *pe;
305
306
4.45k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
4.45k
  pe = pe_data (abfd);
310
4.45k
  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.45k
  pe->coff.local_n_btmask = N_BTMASK;
315
4.45k
  pe->coff.local_n_btshft = N_BTSHFT;
316
4.45k
  pe->coff.local_n_tmask = N_TMASK;
317
4.45k
  pe->coff.local_n_tshift = N_TSHIFT;
318
4.45k
  pe->coff.local_symesz = SYMESZ;
319
4.45k
  pe->coff.local_auxesz = AUXESZ;
320
4.45k
  pe->coff.local_linesz = LINESZ;
321
322
4.45k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
4.45k
  obj_raw_syment_count (abfd) =
325
4.45k
    obj_conv_table_size (abfd) =
326
4.45k
      internal_f->f_nsyms;
327
328
4.45k
  pe->real_flags = internal_f->f_flags;
329
330
4.45k
  if ((internal_f->f_flags & F_DLL) != 0)
331
1.25k
    pe->dll = 1;
332
333
4.45k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
3.43k
    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.45k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
4.45k
    sizeof (pe->dos_message));
348
349
4.45k
  return (void *) pe;
350
4.45k
}
pei-aarch64.c:pe_mkobject_hook
Line
Count
Source
302
8.30k
{
303
8.30k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
8.30k
  pe_data_type *pe;
305
306
8.30k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
8.30k
  pe = pe_data (abfd);
310
8.30k
  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.30k
  pe->coff.local_n_btmask = N_BTMASK;
315
8.30k
  pe->coff.local_n_btshft = N_BTSHFT;
316
8.30k
  pe->coff.local_n_tmask = N_TMASK;
317
8.30k
  pe->coff.local_n_tshift = N_TSHIFT;
318
8.30k
  pe->coff.local_symesz = SYMESZ;
319
8.30k
  pe->coff.local_auxesz = AUXESZ;
320
8.30k
  pe->coff.local_linesz = LINESZ;
321
322
8.30k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
8.30k
  obj_raw_syment_count (abfd) =
325
8.30k
    obj_conv_table_size (abfd) =
326
8.30k
      internal_f->f_nsyms;
327
328
8.30k
  pe->real_flags = internal_f->f_flags;
329
330
8.30k
  if ((internal_f->f_flags & F_DLL) != 0)
331
2.13k
    pe->dll = 1;
332
333
8.30k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
6.45k
    abfd->flags |= HAS_DEBUG;
335
336
8.30k
#ifdef COFF_IMAGE_WITH_PE
337
8.30k
  if (aouthdr)
338
6.22k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
8.30k
#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.30k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
8.30k
    sizeof (pe->dos_message));
348
349
8.30k
  return (void *) pe;
350
8.30k
}
pei-ia64.c:pe_mkobject_hook
Line
Count
Source
302
5.53k
{
303
5.53k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
5.53k
  pe_data_type *pe;
305
306
5.53k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
5.53k
  pe = pe_data (abfd);
310
5.53k
  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.53k
  pe->coff.local_n_btmask = N_BTMASK;
315
5.53k
  pe->coff.local_n_btshft = N_BTSHFT;
316
5.53k
  pe->coff.local_n_tmask = N_TMASK;
317
5.53k
  pe->coff.local_n_tshift = N_TSHIFT;
318
5.53k
  pe->coff.local_symesz = SYMESZ;
319
5.53k
  pe->coff.local_auxesz = AUXESZ;
320
5.53k
  pe->coff.local_linesz = LINESZ;
321
322
5.53k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
5.53k
  obj_raw_syment_count (abfd) =
325
5.53k
    obj_conv_table_size (abfd) =
326
5.53k
      internal_f->f_nsyms;
327
328
5.53k
  pe->real_flags = internal_f->f_flags;
329
330
5.53k
  if ((internal_f->f_flags & F_DLL) != 0)
331
1.69k
    pe->dll = 1;
332
333
5.53k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
3.74k
    abfd->flags |= HAS_DEBUG;
335
336
5.53k
#ifdef COFF_IMAGE_WITH_PE
337
5.53k
  if (aouthdr)
338
2.28k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
5.53k
#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.53k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
5.53k
    sizeof (pe->dos_message));
348
349
5.53k
  return (void *) pe;
350
5.53k
}
pei-loongarch64.c:pe_mkobject_hook
Line
Count
Source
302
5.57k
{
303
5.57k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
5.57k
  pe_data_type *pe;
305
306
5.57k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
5.57k
  pe = pe_data (abfd);
310
5.57k
  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.57k
  pe->coff.local_n_btmask = N_BTMASK;
315
5.57k
  pe->coff.local_n_btshft = N_BTSHFT;
316
5.57k
  pe->coff.local_n_tmask = N_TMASK;
317
5.57k
  pe->coff.local_n_tshift = N_TSHIFT;
318
5.57k
  pe->coff.local_symesz = SYMESZ;
319
5.57k
  pe->coff.local_auxesz = AUXESZ;
320
5.57k
  pe->coff.local_linesz = LINESZ;
321
322
5.57k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
5.57k
  obj_raw_syment_count (abfd) =
325
5.57k
    obj_conv_table_size (abfd) =
326
5.57k
      internal_f->f_nsyms;
327
328
5.57k
  pe->real_flags = internal_f->f_flags;
329
330
5.57k
  if ((internal_f->f_flags & F_DLL) != 0)
331
1.55k
    pe->dll = 1;
332
333
5.57k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
4.20k
    abfd->flags |= HAS_DEBUG;
335
336
5.57k
#ifdef COFF_IMAGE_WITH_PE
337
5.57k
  if (aouthdr)
338
3.41k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
5.57k
#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.57k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
5.57k
    sizeof (pe->dos_message));
348
349
5.57k
  return (void *) pe;
350
5.57k
}
pei-riscv64.c:pe_mkobject_hook
Line
Count
Source
302
5.76k
{
303
5.76k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
5.76k
  pe_data_type *pe;
305
306
5.76k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
5.76k
  pe = pe_data (abfd);
310
5.76k
  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.76k
  pe->coff.local_n_btmask = N_BTMASK;
315
5.76k
  pe->coff.local_n_btshft = N_BTSHFT;
316
5.76k
  pe->coff.local_n_tmask = N_TMASK;
317
5.76k
  pe->coff.local_n_tshift = N_TSHIFT;
318
5.76k
  pe->coff.local_symesz = SYMESZ;
319
5.76k
  pe->coff.local_auxesz = AUXESZ;
320
5.76k
  pe->coff.local_linesz = LINESZ;
321
322
5.76k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
5.76k
  obj_raw_syment_count (abfd) =
325
5.76k
    obj_conv_table_size (abfd) =
326
5.76k
      internal_f->f_nsyms;
327
328
5.76k
  pe->real_flags = internal_f->f_flags;
329
330
5.76k
  if ((internal_f->f_flags & F_DLL) != 0)
331
1.63k
    pe->dll = 1;
332
333
5.76k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
4.07k
    abfd->flags |= HAS_DEBUG;
335
336
5.76k
#ifdef COFF_IMAGE_WITH_PE
337
5.76k
  if (aouthdr)
338
3.79k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
5.76k
#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.76k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
5.76k
    sizeof (pe->dos_message));
348
349
5.76k
  return (void *) pe;
350
5.76k
}
pe-arm-wince.c:pe_mkobject_hook
Line
Count
Source
302
2.66k
{
303
2.66k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
2.66k
  pe_data_type *pe;
305
306
2.66k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
2.66k
  pe = pe_data (abfd);
310
2.66k
  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.66k
  pe->coff.local_n_btmask = N_BTMASK;
315
2.66k
  pe->coff.local_n_btshft = N_BTSHFT;
316
2.66k
  pe->coff.local_n_tmask = N_TMASK;
317
2.66k
  pe->coff.local_n_tshift = N_TSHIFT;
318
2.66k
  pe->coff.local_symesz = SYMESZ;
319
2.66k
  pe->coff.local_auxesz = AUXESZ;
320
2.66k
  pe->coff.local_linesz = LINESZ;
321
322
2.66k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
2.66k
  obj_raw_syment_count (abfd) =
325
2.66k
    obj_conv_table_size (abfd) =
326
2.66k
      internal_f->f_nsyms;
327
328
2.66k
  pe->real_flags = internal_f->f_flags;
329
330
2.66k
  if ((internal_f->f_flags & F_DLL) != 0)
331
719
    pe->dll = 1;
332
333
2.66k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
2.01k
    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
2.66k
#ifdef ARM
342
2.66k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
0
    coff_data (abfd) ->flags = 0;
344
2.66k
#endif
345
346
2.66k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
2.66k
    sizeof (pe->dos_message));
348
349
2.66k
  return (void *) pe;
350
2.66k
}
pe-arm.c:pe_mkobject_hook
Line
Count
Source
302
2.66k
{
303
2.66k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
2.66k
  pe_data_type *pe;
305
306
2.66k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
2.66k
  pe = pe_data (abfd);
310
2.66k
  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.66k
  pe->coff.local_n_btmask = N_BTMASK;
315
2.66k
  pe->coff.local_n_btshft = N_BTSHFT;
316
2.66k
  pe->coff.local_n_tmask = N_TMASK;
317
2.66k
  pe->coff.local_n_tshift = N_TSHIFT;
318
2.66k
  pe->coff.local_symesz = SYMESZ;
319
2.66k
  pe->coff.local_auxesz = AUXESZ;
320
2.66k
  pe->coff.local_linesz = LINESZ;
321
322
2.66k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
2.66k
  obj_raw_syment_count (abfd) =
325
2.66k
    obj_conv_table_size (abfd) =
326
2.66k
      internal_f->f_nsyms;
327
328
2.66k
  pe->real_flags = internal_f->f_flags;
329
330
2.66k
  if ((internal_f->f_flags & F_DLL) != 0)
331
719
    pe->dll = 1;
332
333
2.66k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
2.01k
    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
2.66k
#ifdef ARM
342
2.66k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
0
    coff_data (abfd) ->flags = 0;
344
2.66k
#endif
345
346
2.66k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
2.66k
    sizeof (pe->dos_message));
348
349
2.66k
  return (void *) pe;
350
2.66k
}
pe-i386.c:pe_mkobject_hook
Line
Count
Source
302
9.20k
{
303
9.20k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
9.20k
  pe_data_type *pe;
305
306
9.20k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
9.20k
  pe = pe_data (abfd);
310
9.20k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
9.20k
  pe->coff.local_n_btmask = N_BTMASK;
315
9.20k
  pe->coff.local_n_btshft = N_BTSHFT;
316
9.20k
  pe->coff.local_n_tmask = N_TMASK;
317
9.20k
  pe->coff.local_n_tshift = N_TSHIFT;
318
9.20k
  pe->coff.local_symesz = SYMESZ;
319
9.20k
  pe->coff.local_auxesz = AUXESZ;
320
9.20k
  pe->coff.local_linesz = LINESZ;
321
322
9.20k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
9.20k
  obj_raw_syment_count (abfd) =
325
9.20k
    obj_conv_table_size (abfd) =
326
9.20k
      internal_f->f_nsyms;
327
328
9.20k
  pe->real_flags = internal_f->f_flags;
329
330
9.20k
  if ((internal_f->f_flags & F_DLL) != 0)
331
2.48k
    pe->dll = 1;
332
333
9.20k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
6.17k
    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
9.20k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
9.20k
    sizeof (pe->dos_message));
348
349
9.20k
  return (void *) pe;
350
9.20k
}
pe-mcore.c:pe_mkobject_hook
Line
Count
Source
302
3.50k
{
303
3.50k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
3.50k
  pe_data_type *pe;
305
306
3.50k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
3.50k
  pe = pe_data (abfd);
310
3.50k
  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.50k
  pe->coff.local_n_btmask = N_BTMASK;
315
3.50k
  pe->coff.local_n_btshft = N_BTSHFT;
316
3.50k
  pe->coff.local_n_tmask = N_TMASK;
317
3.50k
  pe->coff.local_n_tshift = N_TSHIFT;
318
3.50k
  pe->coff.local_symesz = SYMESZ;
319
3.50k
  pe->coff.local_auxesz = AUXESZ;
320
3.50k
  pe->coff.local_linesz = LINESZ;
321
322
3.50k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
3.50k
  obj_raw_syment_count (abfd) =
325
3.50k
    obj_conv_table_size (abfd) =
326
3.50k
      internal_f->f_nsyms;
327
328
3.50k
  pe->real_flags = internal_f->f_flags;
329
330
3.50k
  if ((internal_f->f_flags & F_DLL) != 0)
331
1.04k
    pe->dll = 1;
332
333
3.50k
  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.50k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
3.50k
    sizeof (pe->dos_message));
348
349
3.50k
  return (void *) pe;
350
3.50k
}
pe-sh.c:pe_mkobject_hook
Line
Count
Source
302
4.96k
{
303
4.96k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
4.96k
  pe_data_type *pe;
305
306
4.96k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
4.96k
  pe = pe_data (abfd);
310
4.96k
  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.96k
  pe->coff.local_n_btmask = N_BTMASK;
315
4.96k
  pe->coff.local_n_btshft = N_BTSHFT;
316
4.96k
  pe->coff.local_n_tmask = N_TMASK;
317
4.96k
  pe->coff.local_n_tshift = N_TSHIFT;
318
4.96k
  pe->coff.local_symesz = SYMESZ;
319
4.96k
  pe->coff.local_auxesz = AUXESZ;
320
4.96k
  pe->coff.local_linesz = LINESZ;
321
322
4.96k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
4.96k
  obj_raw_syment_count (abfd) =
325
4.96k
    obj_conv_table_size (abfd) =
326
4.96k
      internal_f->f_nsyms;
327
328
4.96k
  pe->real_flags = internal_f->f_flags;
329
330
4.96k
  if ((internal_f->f_flags & F_DLL) != 0)
331
1.43k
    pe->dll = 1;
332
333
4.96k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
3.71k
    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.96k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
4.96k
    sizeof (pe->dos_message));
348
349
4.96k
  return (void *) pe;
350
4.96k
}
pei-arm-wince.c:pe_mkobject_hook
Line
Count
Source
302
5.33k
{
303
5.33k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
5.33k
  pe_data_type *pe;
305
306
5.33k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
5.33k
  pe = pe_data (abfd);
310
5.33k
  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.33k
  pe->coff.local_n_btmask = N_BTMASK;
315
5.33k
  pe->coff.local_n_btshft = N_BTSHFT;
316
5.33k
  pe->coff.local_n_tmask = N_TMASK;
317
5.33k
  pe->coff.local_n_tshift = N_TSHIFT;
318
5.33k
  pe->coff.local_symesz = SYMESZ;
319
5.33k
  pe->coff.local_auxesz = AUXESZ;
320
5.33k
  pe->coff.local_linesz = LINESZ;
321
322
5.33k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
5.33k
  obj_raw_syment_count (abfd) =
325
5.33k
    obj_conv_table_size (abfd) =
326
5.33k
      internal_f->f_nsyms;
327
328
5.33k
  pe->real_flags = internal_f->f_flags;
329
330
5.33k
  if ((internal_f->f_flags & F_DLL) != 0)
331
1.90k
    pe->dll = 1;
332
333
5.33k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
3.47k
    abfd->flags |= HAS_DEBUG;
335
336
5.33k
#ifdef COFF_IMAGE_WITH_PE
337
5.33k
  if (aouthdr)
338
1.95k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
5.33k
#endif
340
341
5.33k
#ifdef ARM
342
5.33k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
0
    coff_data (abfd) ->flags = 0;
344
5.33k
#endif
345
346
5.33k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
5.33k
    sizeof (pe->dos_message));
348
349
5.33k
  return (void *) pe;
350
5.33k
}
pei-arm.c:pe_mkobject_hook
Line
Count
Source
302
6.77k
{
303
6.77k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
6.77k
  pe_data_type *pe;
305
306
6.77k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
6.77k
  pe = pe_data (abfd);
310
6.77k
  pe->coff.sym_filepos = internal_f->f_symptr;
311
  /* These members communicate important constants about the symbol
312
     table to GDB's symbol-reading code.  These `constants'
313
     unfortunately vary among coff implementations...  */
314
6.77k
  pe->coff.local_n_btmask = N_BTMASK;
315
6.77k
  pe->coff.local_n_btshft = N_BTSHFT;
316
6.77k
  pe->coff.local_n_tmask = N_TMASK;
317
6.77k
  pe->coff.local_n_tshift = N_TSHIFT;
318
6.77k
  pe->coff.local_symesz = SYMESZ;
319
6.77k
  pe->coff.local_auxesz = AUXESZ;
320
6.77k
  pe->coff.local_linesz = LINESZ;
321
322
6.77k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
6.77k
  obj_raw_syment_count (abfd) =
325
6.77k
    obj_conv_table_size (abfd) =
326
6.77k
      internal_f->f_nsyms;
327
328
6.77k
  pe->real_flags = internal_f->f_flags;
329
330
6.77k
  if ((internal_f->f_flags & F_DLL) != 0)
331
2.47k
    pe->dll = 1;
332
333
6.77k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
4.58k
    abfd->flags |= HAS_DEBUG;
335
336
6.77k
#ifdef COFF_IMAGE_WITH_PE
337
6.77k
  if (aouthdr)
338
3.38k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
6.77k
#endif
340
341
6.77k
#ifdef ARM
342
6.77k
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
343
0
    coff_data (abfd) ->flags = 0;
344
6.77k
#endif
345
346
6.77k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
6.77k
    sizeof (pe->dos_message));
348
349
6.77k
  return (void *) pe;
350
6.77k
}
pei-mcore.c:pe_mkobject_hook
Line
Count
Source
302
4.79k
{
303
4.79k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
4.79k
  pe_data_type *pe;
305
306
4.79k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
4.79k
  pe = pe_data (abfd);
310
4.79k
  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.79k
  pe->coff.local_n_btmask = N_BTMASK;
315
4.79k
  pe->coff.local_n_btshft = N_BTSHFT;
316
4.79k
  pe->coff.local_n_tmask = N_TMASK;
317
4.79k
  pe->coff.local_n_tshift = N_TSHIFT;
318
4.79k
  pe->coff.local_symesz = SYMESZ;
319
4.79k
  pe->coff.local_auxesz = AUXESZ;
320
4.79k
  pe->coff.local_linesz = LINESZ;
321
322
4.79k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
4.79k
  obj_raw_syment_count (abfd) =
325
4.79k
    obj_conv_table_size (abfd) =
326
4.79k
      internal_f->f_nsyms;
327
328
4.79k
  pe->real_flags = internal_f->f_flags;
329
330
4.79k
  if ((internal_f->f_flags & F_DLL) != 0)
331
1.94k
    pe->dll = 1;
332
333
4.79k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
3.01k
    abfd->flags |= HAS_DEBUG;
335
336
4.79k
#ifdef COFF_IMAGE_WITH_PE
337
4.79k
  if (aouthdr)
338
2.77k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
4.79k
#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.79k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
4.79k
    sizeof (pe->dos_message));
348
349
4.79k
  return (void *) pe;
350
4.79k
}
pei-sh.c:pe_mkobject_hook
Line
Count
Source
302
4.92k
{
303
4.92k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
304
4.92k
  pe_data_type *pe;
305
306
4.92k
  if (! pe_mkobject (abfd))
307
0
    return NULL;
308
309
4.92k
  pe = pe_data (abfd);
310
4.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
4.92k
  pe->coff.local_n_btmask = N_BTMASK;
315
4.92k
  pe->coff.local_n_btshft = N_BTSHFT;
316
4.92k
  pe->coff.local_n_tmask = N_TMASK;
317
4.92k
  pe->coff.local_n_tshift = N_TSHIFT;
318
4.92k
  pe->coff.local_symesz = SYMESZ;
319
4.92k
  pe->coff.local_auxesz = AUXESZ;
320
4.92k
  pe->coff.local_linesz = LINESZ;
321
322
4.92k
  pe->coff.timestamp = internal_f->f_timdat;
323
324
4.92k
  obj_raw_syment_count (abfd) =
325
4.92k
    obj_conv_table_size (abfd) =
326
4.92k
      internal_f->f_nsyms;
327
328
4.92k
  pe->real_flags = internal_f->f_flags;
329
330
4.92k
  if ((internal_f->f_flags & F_DLL) != 0)
331
1.90k
    pe->dll = 1;
332
333
4.92k
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
334
3.14k
    abfd->flags |= HAS_DEBUG;
335
336
4.92k
#ifdef COFF_IMAGE_WITH_PE
337
4.92k
  if (aouthdr)
338
2.87k
    pe->pe_opthdr = ((struct internal_aouthdr *) aouthdr)->pe;
339
4.92k
#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.92k
  memcpy (pe->dos_message, internal_f->pe.dos_message,
347
4.92k
    sizeof (pe->dos_message));
348
349
4.92k
  return (void *) pe;
350
4.92k
}
351
352
static bool
353
pe_print_private_bfd_data (bfd *abfd, void *vfile)
354
4.63k
{
355
4.63k
  FILE *file = (FILE *) vfile;
356
357
4.63k
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
4.63k
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
4.48k
    return true;
362
363
148
  fputc ('\n', file);
364
365
148
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
4.63k
}
pei-i386.c:pe_print_private_bfd_data
Line
Count
Source
354
110
{
355
110
  FILE *file = (FILE *) vfile;
356
357
110
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
110
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
110
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
110
}
pe-x86_64.c:pe_print_private_bfd_data
Line
Count
Source
354
152
{
355
152
  FILE *file = (FILE *) vfile;
356
357
152
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
152
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
152
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
152
}
pei-x86_64.c:pe_print_private_bfd_data
Line
Count
Source
354
116
{
355
116
  FILE *file = (FILE *) vfile;
356
357
116
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
116
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
116
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
116
}
pe-aarch64.c:pe_print_private_bfd_data
Line
Count
Source
354
574
{
355
574
  FILE *file = (FILE *) vfile;
356
357
574
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
574
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
574
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
574
}
pei-aarch64.c:pe_print_private_bfd_data
Line
Count
Source
354
2.60k
{
355
2.60k
  FILE *file = (FILE *) vfile;
356
357
2.60k
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
2.60k
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
2.60k
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
2.60k
}
pei-ia64.c:pe_print_private_bfd_data
Line
Count
Source
354
263
{
355
263
  FILE *file = (FILE *) vfile;
356
357
263
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
263
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
263
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
263
}
pei-loongarch64.c:pe_print_private_bfd_data
Line
Count
Source
354
137
{
355
137
  FILE *file = (FILE *) vfile;
356
357
137
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
137
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
137
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
137
}
pei-riscv64.c:pe_print_private_bfd_data
Line
Count
Source
354
225
{
355
225
  FILE *file = (FILE *) vfile;
356
357
225
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
225
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
225
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
225
}
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
53
{
355
53
  FILE *file = (FILE *) vfile;
356
357
53
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
53
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
53
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
53
}
pe-mcore.c:pe_print_private_bfd_data
Line
Count
Source
354
51
{
355
51
  FILE *file = (FILE *) vfile;
356
357
51
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
51
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
51
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
51
}
pe-sh.c:pe_print_private_bfd_data
Line
Count
Source
354
50
{
355
50
  FILE *file = (FILE *) vfile;
356
357
50
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
50
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
50
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
50
}
pei-arm-wince.c:pe_print_private_bfd_data
Line
Count
Source
354
13
{
355
13
  FILE *file = (FILE *) vfile;
356
357
13
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
13
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
0
    return true;
362
363
13
  fputc ('\n', file);
364
365
13
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
13
}
pei-arm.c:pe_print_private_bfd_data
Line
Count
Source
354
135
{
355
135
  FILE *file = (FILE *) vfile;
356
357
135
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
135
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
0
    return true;
362
363
135
  fputc ('\n', file);
364
365
135
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
135
}
pei-mcore.c:pe_print_private_bfd_data
Line
Count
Source
354
85
{
355
85
  FILE *file = (FILE *) vfile;
356
357
85
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
85
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
85
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
85
}
pei-sh.c:pe_print_private_bfd_data
Line
Count
Source
354
70
{
355
70
  FILE *file = (FILE *) vfile;
356
357
70
  if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
358
0
    return false;
359
360
70
  if (pe_saved_coff_bfd_print_private_bfd_data == NULL)
361
70
    return true;
362
363
0
  fputc ('\n', file);
364
365
0
  return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
366
70
}
367
368
/* Copy any private info we understand from the input bfd
369
   to the output bfd.  */
370
371
static bool
372
pe_bfd_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
373
1.22k
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
1.22k
  if (pe_data (obfd) != NULL
378
1.22k
      && pe_data (ibfd) != NULL
379
1.22k
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
424
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
1.22k
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
20
    return false;
384
385
1.20k
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
113
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
1.09k
  return true;
389
1.20k
}
pei-i386.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
89
{
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
89
  if (pe_data (obfd) != NULL
378
89
      && pe_data (ibfd) != NULL
379
89
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
17
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
89
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
2
    return false;
384
385
87
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
87
  return true;
389
87
}
pe-x86_64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
134
{
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
134
  if (pe_data (obfd) != NULL
378
134
      && pe_data (ibfd) != NULL
379
134
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
19
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
134
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
0
    return false;
384
385
134
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
134
  return true;
389
134
}
pei-x86_64.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
40
    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
0
    return false;
384
385
88
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
88
  return true;
389
88
}
pe-aarch64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
77
{
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
77
  if (pe_data (obfd) != NULL
378
77
      && pe_data (ibfd) != NULL
379
77
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
29
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
77
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
0
    return false;
384
385
77
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
77
  return true;
389
77
}
pei-aarch64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
95
{
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
95
  if (pe_data (obfd) != NULL
378
95
      && pe_data (ibfd) != NULL
379
95
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
35
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
95
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
3
    return false;
384
385
92
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
92
  return true;
389
92
}
pei-ia64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
83
{
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
83
  if (pe_data (obfd) != NULL
378
83
      && pe_data (ibfd) != NULL
379
83
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
29
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
83
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
2
    return false;
384
385
81
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
81
  return true;
389
81
}
pei-loongarch64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
130
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
130
  if (pe_data (obfd) != NULL
378
130
      && pe_data (ibfd) != NULL
379
130
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
43
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
130
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
4
    return false;
384
385
126
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
126
  return true;
389
126
}
pei-riscv64.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
99
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
99
  if (pe_data (obfd) != NULL
378
99
      && pe_data (ibfd) != NULL
379
99
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
66
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
99
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
3
    return false;
384
385
96
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
96
  return true;
389
96
}
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
43
{
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
43
  if (pe_data (obfd) != NULL
378
43
      && pe_data (ibfd) != NULL
379
43
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
13
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
43
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
0
    return false;
384
385
43
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
43
  return true;
389
43
}
pe-mcore.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
62
{
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
62
  if (pe_data (obfd) != NULL
378
62
      && pe_data (ibfd) != NULL
379
62
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
11
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
62
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
0
    return false;
384
385
62
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
62
  return true;
389
62
}
pe-sh.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
73
{
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
73
  if (pe_data (obfd) != NULL
378
73
      && pe_data (ibfd) != NULL
379
73
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
24
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
73
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
0
    return false;
384
385
73
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
73
  return true;
389
73
}
pei-arm-wince.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
16
    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
1
    return false;
384
385
35
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
35
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
0
  return true;
389
35
}
pei-arm.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
79
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
79
  if (pe_data (obfd) != NULL
378
79
      && pe_data (ibfd) != NULL
379
79
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
41
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
79
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
1
    return false;
384
385
78
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
78
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
0
  return true;
389
78
}
pei-mcore.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
56
{
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
56
  if (pe_data (obfd) != NULL
378
56
      && pe_data (ibfd) != NULL
379
56
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
28
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
56
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
1
    return false;
384
385
55
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
55
  return true;
389
55
}
pei-sh.c:pe_bfd_copy_private_bfd_data
Line
Count
Source
373
79
{
374
  /* PR binutils/716: Copy the large address aware flag.
375
     XXX: Should we be copying other flags or other fields in the pe_data()
376
     structure ?  */
377
79
  if (pe_data (obfd) != NULL
378
79
      && pe_data (ibfd) != NULL
379
79
      && pe_data (ibfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
380
13
    pe_data (obfd)->real_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
381
382
79
  if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
383
3
    return false;
384
385
76
  if (pe_saved_coff_bfd_copy_private_bfd_data)
386
0
    return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
387
388
76
  return true;
389
76
}
390
391
#define coff_bfd_copy_private_section_data \
392
  _bfd_XX_bfd_copy_private_section_data
393
394
#define coff_get_symbol_info _bfd_XX_get_symbol_info
395
396
#ifdef COFF_IMAGE_WITH_PE
397

398
/* Code to handle Microsoft's Import Library Format.
399
   Also known as LINK6 format.
400
   Documentation about this format can be found at:
401
402
   https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#import-library-format  */
403
404
/* The following constants specify the sizes of the various data
405
   structures that we have to create in order to build a bfd describing
406
   an ILF object file.  The final "+ 1" in the definitions of SIZEOF_IDATA6
407
   and SIZEOF_IDATA7 below is to allow for the possibility that we might
408
   need a padding byte in order to ensure 16 bit alignment for the section's
409
   contents.
410
411
   The value for SIZEOF_ILF_STRINGS is computed as follows:
412
413
      There will be NUM_ILF_SECTIONS section symbols.  Allow 9 characters
414
      per symbol for their names (longest section name is .idata$x).
415
416
      There will be two symbols for the imported value, one the symbol name
417
      and one with _imp__ prefixed.  Allowing for the terminating nul's this
418
      is strlen (symbol_name) * 2 + 8 + 21 + strlen (source_dll).
419
420
      The strings in the string table must start STRING__SIZE_SIZE bytes into
421
      the table in order to for the string lookup code in coffgen/coffcode to
422
      work.  */
423
6.27k
#define NUM_ILF_RELOCS    8
424
20.9k
#define NUM_ILF_SECTIONS  6
425
15.6k
#define NUM_ILF_SYMS    (2 + NUM_ILF_SECTIONS)
426
427
3.13k
#define SIZEOF_ILF_SYMS    (NUM_ILF_SYMS * sizeof (*vars.sym_cache))
428
3.13k
#define SIZEOF_ILF_SYM_TABLE   (NUM_ILF_SYMS * sizeof (*vars.sym_table))
429
3.13k
#define SIZEOF_ILF_NATIVE_SYMS   (NUM_ILF_SYMS * sizeof (*vars.native_syms))
430
3.13k
#define SIZEOF_ILF_SYM_PTR_TABLE (NUM_ILF_SYMS * sizeof (*vars.sym_ptr_table))
431
3.13k
#define SIZEOF_ILF_EXT_SYMS  (NUM_ILF_SYMS * sizeof (*vars.esym_table))
432
3.13k
#define SIZEOF_ILF_RELOCS  (NUM_ILF_RELOCS * sizeof (*vars.reltab))
433
3.13k
#define SIZEOF_ILF_INT_RELOCS  (NUM_ILF_RELOCS * sizeof (*vars.int_reltab))
434
3.13k
#define SIZEOF_ILF_STRINGS   (strlen (symbol_name) * 2 + 8 \
435
3.13k
          + 21 + strlen (source_dll)   \
436
3.13k
          + NUM_ILF_SECTIONS * 9       \
437
3.13k
          + STRING_SIZE_SIZE)
438
2.09k
#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
807
#define SIZEOF_IDATA4   (2 * 4)
443
807
#define SIZEOF_IDATA5   (2 * 4)
444
#else
445
2.32k
#define SIZEOF_IDATA4   (1 * 4)
446
2.32k
#define SIZEOF_IDATA5   (1 * 4)
447
#endif
448
449
2.82k
#define SIZEOF_IDATA6   (2 + strlen (import_name) + 1 + 1)
450
2.09k
#define SIZEOF_IDATA7   (strlen (source_dll) + 1 + 1)
451
2.09k
#define SIZEOF_ILF_SECTIONS (NUM_ILF_SECTIONS \
452
2.09k
         * sizeof (struct coff_section_tdata))
453
454
#define ILF_DATA_SIZE       \
455
2.09k
    + SIZEOF_ILF_SYMS        \
456
2.09k
    + SIZEOF_ILF_SYM_TABLE      \
457
2.09k
    + SIZEOF_ILF_NATIVE_SYMS      \
458
2.09k
    + SIZEOF_ILF_SYM_PTR_TABLE      \
459
2.09k
    + SIZEOF_ILF_EXT_SYMS      \
460
2.09k
    + SIZEOF_ILF_RELOCS        \
461
2.09k
    + SIZEOF_ILF_INT_RELOCS      \
462
2.09k
    + SIZEOF_ILF_STRINGS      \
463
2.09k
    + SIZEOF_IDATA2        \
464
2.09k
    + SIZEOF_IDATA4        \
465
2.09k
    + SIZEOF_IDATA5        \
466
2.09k
    + SIZEOF_IDATA6        \
467
2.09k
    + SIZEOF_IDATA7        \
468
2.09k
    + SIZEOF_ILF_SECTIONS      \
469
2.09k
    + 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.90k
{
480
1.90k
  arelent *entry;
481
1.90k
  struct internal_reloc *internal;
482
483
1.90k
  entry = vars->reltab + vars->relcount;
484
1.90k
  internal = vars->int_reltab + vars->relcount;
485
486
1.90k
  entry->address     = address;
487
1.90k
  entry->addend      = 0;
488
1.90k
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
489
1.90k
  entry->sym_ptr_ptr = sym;
490
491
1.90k
  internal->r_vaddr  = address;
492
1.90k
  internal->r_symndx = sym_index;
493
1.90k
  internal->r_type   = entry->howto ? entry->howto->type : 0;
494
495
1.90k
  vars->relcount ++;
496
497
1.90k
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
498
1.90k
}
pei-i386.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
479
245
{
480
245
  arelent *entry;
481
245
  struct internal_reloc *internal;
482
483
245
  entry = vars->reltab + vars->relcount;
484
245
  internal = vars->int_reltab + vars->relcount;
485
486
245
  entry->address     = address;
487
245
  entry->addend      = 0;
488
245
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
489
245
  entry->sym_ptr_ptr = sym;
490
491
245
  internal->r_vaddr  = address;
492
245
  internal->r_symndx = sym_index;
493
245
  internal->r_type   = entry->howto ? entry->howto->type : 0;
494
495
245
  vars->relcount ++;
496
497
245
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
498
245
}
pei-x86_64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
479
254
{
480
254
  arelent *entry;
481
254
  struct internal_reloc *internal;
482
483
254
  entry = vars->reltab + vars->relcount;
484
254
  internal = vars->int_reltab + vars->relcount;
485
486
254
  entry->address     = address;
487
254
  entry->addend      = 0;
488
254
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
489
254
  entry->sym_ptr_ptr = sym;
490
491
254
  internal->r_vaddr  = address;
492
254
  internal->r_symndx = sym_index;
493
254
  internal->r_type   = entry->howto ? entry->howto->type : 0;
494
495
254
  vars->relcount ++;
496
497
254
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
498
254
}
pei-aarch64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
479
234
{
480
234
  arelent *entry;
481
234
  struct internal_reloc *internal;
482
483
234
  entry = vars->reltab + vars->relcount;
484
234
  internal = vars->int_reltab + vars->relcount;
485
486
234
  entry->address     = address;
487
234
  entry->addend      = 0;
488
234
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
489
234
  entry->sym_ptr_ptr = sym;
490
491
234
  internal->r_vaddr  = address;
492
234
  internal->r_symndx = sym_index;
493
234
  internal->r_type   = entry->howto ? entry->howto->type : 0;
494
495
234
  vars->relcount ++;
496
497
234
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
498
234
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_symbol_reloc
pei-loongarch64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
479
260
{
480
260
  arelent *entry;
481
260
  struct internal_reloc *internal;
482
483
260
  entry = vars->reltab + vars->relcount;
484
260
  internal = vars->int_reltab + vars->relcount;
485
486
260
  entry->address     = address;
487
260
  entry->addend      = 0;
488
260
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
489
260
  entry->sym_ptr_ptr = sym;
490
491
260
  internal->r_vaddr  = address;
492
260
  internal->r_symndx = sym_index;
493
260
  internal->r_type   = entry->howto ? entry->howto->type : 0;
494
495
260
  vars->relcount ++;
496
497
260
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
498
260
}
pei-riscv64.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
479
228
{
480
228
  arelent *entry;
481
228
  struct internal_reloc *internal;
482
483
228
  entry = vars->reltab + vars->relcount;
484
228
  internal = vars->int_reltab + vars->relcount;
485
486
228
  entry->address     = address;
487
228
  entry->addend      = 0;
488
228
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
489
228
  entry->sym_ptr_ptr = sym;
490
491
228
  internal->r_vaddr  = address;
492
228
  internal->r_symndx = sym_index;
493
228
  internal->r_type   = entry->howto ? entry->howto->type : 0;
494
495
228
  vars->relcount ++;
496
497
228
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
498
228
}
pei-arm-wince.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
479
190
{
480
190
  arelent *entry;
481
190
  struct internal_reloc *internal;
482
483
190
  entry = vars->reltab + vars->relcount;
484
190
  internal = vars->int_reltab + vars->relcount;
485
486
190
  entry->address     = address;
487
190
  entry->addend      = 0;
488
190
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
489
190
  entry->sym_ptr_ptr = sym;
490
491
190
  internal->r_vaddr  = address;
492
190
  internal->r_symndx = sym_index;
493
190
  internal->r_type   = entry->howto ? entry->howto->type : 0;
494
495
190
  vars->relcount ++;
496
497
190
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
498
190
}
pei-arm.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
479
193
{
480
193
  arelent *entry;
481
193
  struct internal_reloc *internal;
482
483
193
  entry = vars->reltab + vars->relcount;
484
193
  internal = vars->int_reltab + vars->relcount;
485
486
193
  entry->address     = address;
487
193
  entry->addend      = 0;
488
193
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
489
193
  entry->sym_ptr_ptr = sym;
490
491
193
  internal->r_vaddr  = address;
492
193
  internal->r_symndx = sym_index;
493
193
  internal->r_type   = entry->howto ? entry->howto->type : 0;
494
495
193
  vars->relcount ++;
496
497
193
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
498
193
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_symbol_reloc
pei-sh.c:pe_ILF_make_a_symbol_reloc
Line
Count
Source
479
298
{
480
298
  arelent *entry;
481
298
  struct internal_reloc *internal;
482
483
298
  entry = vars->reltab + vars->relcount;
484
298
  internal = vars->int_reltab + vars->relcount;
485
486
298
  entry->address     = address;
487
298
  entry->addend      = 0;
488
298
  entry->howto       = bfd_reloc_type_lookup (vars->abfd, reloc);
489
298
  entry->sym_ptr_ptr = sym;
490
491
298
  internal->r_vaddr  = address;
492
298
  internal->r_symndx = sym_index;
493
298
  internal->r_type   = entry->howto ? entry->howto->type : 0;
494
495
298
  vars->relcount ++;
496
497
298
  BFD_ASSERT (vars->relcount <= NUM_ILF_RELOCS);
498
298
}
499
500
/* Create an empty relocation against the given section.  */
501
502
static void
503
pe_ILF_make_a_reloc (pe_ILF_vars *         vars,
504
         bfd_vma           address,
505
         bfd_reloc_code_real_type  reloc,
506
         asection_ptr        sec)
507
1.46k
{
508
1.46k
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
509
1.46k
            coff_section_data (vars->abfd, sec)->i);
510
1.46k
}
pei-i386.c:pe_ILF_make_a_reloc
Line
Count
Source
507
184
{
508
184
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
509
184
            coff_section_data (vars->abfd, sec)->i);
510
184
}
pei-x86_64.c:pe_ILF_make_a_reloc
Line
Count
Source
507
198
{
508
198
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
509
198
            coff_section_data (vars->abfd, sec)->i);
510
198
}
pei-aarch64.c:pe_ILF_make_a_reloc
Line
Count
Source
507
178
{
508
178
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
509
178
            coff_section_data (vars->abfd, sec)->i);
510
178
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_reloc
pei-loongarch64.c:pe_ILF_make_a_reloc
Line
Count
Source
507
196
{
508
196
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
509
196
            coff_section_data (vars->abfd, sec)->i);
510
196
}
pei-riscv64.c:pe_ILF_make_a_reloc
Line
Count
Source
507
190
{
508
190
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
509
190
            coff_section_data (vars->abfd, sec)->i);
510
190
}
pei-arm-wince.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.c:pe_ILF_make_a_reloc
Line
Count
Source
507
140
{
508
140
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
509
140
            coff_section_data (vars->abfd, sec)->i);
510
140
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_reloc
pei-sh.c:pe_ILF_make_a_reloc
Line
Count
Source
507
242
{
508
242
  pe_ILF_make_a_symbol_reloc (vars, address, reloc, &sec->symbol,
509
242
            coff_section_data (vars->abfd, sec)->i);
510
242
}
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.90k
{
518
  /* Make sure that there is somewhere to store the internal relocs.  */
519
1.90k
  if (coff_section_data (vars->abfd, sec) == NULL)
520
    /* We should probably return an error indication here.  */
521
0
    abort ();
522
523
1.90k
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
524
525
1.90k
  sec->relocation  = vars->reltab;
526
1.90k
  sec->reloc_count = vars->relcount;
527
1.90k
  sec->flags      |= SEC_RELOC;
528
529
1.90k
  vars->reltab     += vars->relcount;
530
1.90k
  vars->int_reltab += vars->relcount;
531
1.90k
  vars->relcount   = 0;
532
533
1.90k
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
534
1.90k
}
pei-i386.c:pe_ILF_save_relocs
Line
Count
Source
517
245
{
518
  /* Make sure that there is somewhere to store the internal relocs.  */
519
245
  if (coff_section_data (vars->abfd, sec) == NULL)
520
    /* We should probably return an error indication here.  */
521
0
    abort ();
522
523
245
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
524
525
245
  sec->relocation  = vars->reltab;
526
245
  sec->reloc_count = vars->relcount;
527
245
  sec->flags      |= SEC_RELOC;
528
529
245
  vars->reltab     += vars->relcount;
530
245
  vars->int_reltab += vars->relcount;
531
245
  vars->relcount   = 0;
532
533
245
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
534
245
}
pei-x86_64.c:pe_ILF_save_relocs
Line
Count
Source
517
254
{
518
  /* Make sure that there is somewhere to store the internal relocs.  */
519
254
  if (coff_section_data (vars->abfd, sec) == NULL)
520
    /* We should probably return an error indication here.  */
521
0
    abort ();
522
523
254
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
524
525
254
  sec->relocation  = vars->reltab;
526
254
  sec->reloc_count = vars->relcount;
527
254
  sec->flags      |= SEC_RELOC;
528
529
254
  vars->reltab     += vars->relcount;
530
254
  vars->int_reltab += vars->relcount;
531
254
  vars->relcount   = 0;
532
533
254
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
534
254
}
pei-aarch64.c:pe_ILF_save_relocs
Line
Count
Source
517
234
{
518
  /* Make sure that there is somewhere to store the internal relocs.  */
519
234
  if (coff_section_data (vars->abfd, sec) == NULL)
520
    /* We should probably return an error indication here.  */
521
0
    abort ();
522
523
234
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
524
525
234
  sec->relocation  = vars->reltab;
526
234
  sec->reloc_count = vars->relcount;
527
234
  sec->flags      |= SEC_RELOC;
528
529
234
  vars->reltab     += vars->relcount;
530
234
  vars->int_reltab += vars->relcount;
531
234
  vars->relcount   = 0;
532
533
234
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
534
234
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_save_relocs
pei-loongarch64.c:pe_ILF_save_relocs
Line
Count
Source
517
260
{
518
  /* Make sure that there is somewhere to store the internal relocs.  */
519
260
  if (coff_section_data (vars->abfd, sec) == NULL)
520
    /* We should probably return an error indication here.  */
521
0
    abort ();
522
523
260
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
524
525
260
  sec->relocation  = vars->reltab;
526
260
  sec->reloc_count = vars->relcount;
527
260
  sec->flags      |= SEC_RELOC;
528
529
260
  vars->reltab     += vars->relcount;
530
260
  vars->int_reltab += vars->relcount;
531
260
  vars->relcount   = 0;
532
533
260
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
534
260
}
pei-riscv64.c:pe_ILF_save_relocs
Line
Count
Source
517
228
{
518
  /* Make sure that there is somewhere to store the internal relocs.  */
519
228
  if (coff_section_data (vars->abfd, sec) == NULL)
520
    /* We should probably return an error indication here.  */
521
0
    abort ();
522
523
228
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
524
525
228
  sec->relocation  = vars->reltab;
526
228
  sec->reloc_count = vars->relcount;
527
228
  sec->flags      |= SEC_RELOC;
528
529
228
  vars->reltab     += vars->relcount;
530
228
  vars->int_reltab += vars->relcount;
531
228
  vars->relcount   = 0;
532
533
228
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
534
228
}
pei-arm-wince.c:pe_ILF_save_relocs
Line
Count
Source
517
190
{
518
  /* Make sure that there is somewhere to store the internal relocs.  */
519
190
  if (coff_section_data (vars->abfd, sec) == NULL)
520
    /* We should probably return an error indication here.  */
521
0
    abort ();
522
523
190
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
524
525
190
  sec->relocation  = vars->reltab;
526
190
  sec->reloc_count = vars->relcount;
527
190
  sec->flags      |= SEC_RELOC;
528
529
190
  vars->reltab     += vars->relcount;
530
190
  vars->int_reltab += vars->relcount;
531
190
  vars->relcount   = 0;
532
533
190
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
534
190
}
pei-arm.c:pe_ILF_save_relocs
Line
Count
Source
517
193
{
518
  /* Make sure that there is somewhere to store the internal relocs.  */
519
193
  if (coff_section_data (vars->abfd, sec) == NULL)
520
    /* We should probably return an error indication here.  */
521
0
    abort ();
522
523
193
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
524
525
193
  sec->relocation  = vars->reltab;
526
193
  sec->reloc_count = vars->relcount;
527
193
  sec->flags      |= SEC_RELOC;
528
529
193
  vars->reltab     += vars->relcount;
530
193
  vars->int_reltab += vars->relcount;
531
193
  vars->relcount   = 0;
532
533
193
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
534
193
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_save_relocs
pei-sh.c:pe_ILF_save_relocs
Line
Count
Source
517
298
{
518
  /* Make sure that there is somewhere to store the internal relocs.  */
519
298
  if (coff_section_data (vars->abfd, sec) == NULL)
520
    /* We should probably return an error indication here.  */
521
0
    abort ();
522
523
298
  coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
524
525
298
  sec->relocation  = vars->reltab;
526
298
  sec->reloc_count = vars->relcount;
527
298
  sec->flags      |= SEC_RELOC;
528
529
298
  vars->reltab     += vars->relcount;
530
298
  vars->int_reltab += vars->relcount;
531
298
  vars->relcount   = 0;
532
533
298
  BFD_ASSERT ((bfd_byte *) vars->int_reltab < (bfd_byte *) vars->string_table);
534
298
}
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
5.86k
{
545
5.86k
  coff_symbol_type *sym;
546
5.86k
  combined_entry_type *ent;
547
5.86k
  SYMENT *esym;
548
5.86k
  unsigned short sclass;
549
550
5.86k
  if (extra_flags & BSF_LOCAL)
551
3.25k
    sclass = C_STAT;
552
2.60k
  else
553
2.60k
    sclass = C_EXT;
554
555
#ifdef THUMBPEMAGIC
556
1.20k
  if (vars->magic == THUMBPEMAGIC)
557
596
    {
558
596
      if (extra_flags & BSF_FUNCTION)
559
50
  sclass = C_THUMBEXTFUNC;
560
546
      else if (extra_flags & BSF_LOCAL)
561
330
  sclass = C_THUMBSTAT;
562
216
      else
563
216
  sclass = C_THUMBEXT;
564
596
    }
565
#endif
566
567
5.86k
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
568
569
5.86k
  sym = vars->sym_ptr;
570
5.86k
  ent = vars->native_ptr;
571
5.86k
  esym = vars->esym_ptr;
572
573
  /* Copy the symbol's name into the string table.  */
574
5.86k
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
575
576
5.86k
  if (section == NULL)
577
967
    section = bfd_und_section_ptr;
578
579
  /* Initialise the external symbol.  */
580
5.86k
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
581
5.86k
      esym->e.e.e_offset);
582
5.86k
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
583
5.86k
  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
5.86k
  ent->u.syment.n_sclass    = sclass;
590
5.86k
  ent->u.syment.n_scnum     = section->target_index;
591
5.86k
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
592
5.86k
  ent->is_sym = true;
593
594
5.86k
  sym->symbol.the_bfd = vars->abfd;
595
5.86k
  sym->symbol.name    = vars->string_ptr;
596
5.86k
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
597
5.86k
  sym->symbol.section = section;
598
5.86k
  sym->native       = ent;
599
600
5.86k
  *vars->table_ptr = vars->sym_index;
601
5.86k
  *vars->sym_ptr_ptr = sym;
602
603
  /* Adjust pointers for the next symbol.  */
604
5.86k
  vars->sym_index ++;
605
5.86k
  vars->sym_ptr ++;
606
5.86k
  vars->sym_ptr_ptr ++;
607
5.86k
  vars->table_ptr ++;
608
5.86k
  vars->native_ptr ++;
609
5.86k
  vars->esym_ptr ++;
610
5.86k
  vars->string_ptr += len + 1;
611
612
5.86k
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
613
5.86k
}
pei-i386.c:pe_ILF_make_a_symbol
Line
Count
Source
544
731
{
545
731
  coff_symbol_type *sym;
546
731
  combined_entry_type *ent;
547
731
  SYMENT *esym;
548
731
  unsigned short sclass;
549
550
731
  if (extra_flags & BSF_LOCAL)
551
405
    sclass = C_STAT;
552
326
  else
553
326
    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
731
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
568
569
731
  sym = vars->sym_ptr;
570
731
  ent = vars->native_ptr;
571
731
  esym = vars->esym_ptr;
572
573
  /* Copy the symbol's name into the string table.  */
574
731
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
575
576
731
  if (section == NULL)
577
116
    section = bfd_und_section_ptr;
578
579
  /* Initialise the external symbol.  */
580
731
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
581
731
      esym->e.e.e_offset);
582
731
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
583
731
  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
731
  ent->u.syment.n_sclass    = sclass;
590
731
  ent->u.syment.n_scnum     = section->target_index;
591
731
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
592
731
  ent->is_sym = true;
593
594
731
  sym->symbol.the_bfd = vars->abfd;
595
731
  sym->symbol.name    = vars->string_ptr;
596
731
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
597
731
  sym->symbol.section = section;
598
731
  sym->native       = ent;
599
600
731
  *vars->table_ptr = vars->sym_index;
601
731
  *vars->sym_ptr_ptr = sym;
602
603
  /* Adjust pointers for the next symbol.  */
604
731
  vars->sym_index ++;
605
731
  vars->sym_ptr ++;
606
731
  vars->sym_ptr_ptr ++;
607
731
  vars->table_ptr ++;
608
731
  vars->native_ptr ++;
609
731
  vars->esym_ptr ++;
610
731
  vars->string_ptr += len + 1;
611
612
731
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
613
731
}
pei-x86_64.c:pe_ILF_make_a_symbol
Line
Count
Source
544
798
{
545
798
  coff_symbol_type *sym;
546
798
  combined_entry_type *ent;
547
798
  SYMENT *esym;
548
798
  unsigned short sclass;
549
550
798
  if (extra_flags & BSF_LOCAL)
551
437
    sclass = C_STAT;
552
361
  else
553
361
    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
798
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
568
569
798
  sym = vars->sym_ptr;
570
798
  ent = vars->native_ptr;
571
798
  esym = vars->esym_ptr;
572
573
  /* Copy the symbol's name into the string table.  */
574
798
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
575
576
798
  if (section == NULL)
577
133
    section = bfd_und_section_ptr;
578
579
  /* Initialise the external symbol.  */
580
798
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
581
798
      esym->e.e.e_offset);
582
798
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
583
798
  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
798
  ent->u.syment.n_sclass    = sclass;
590
798
  ent->u.syment.n_scnum     = section->target_index;
591
798
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
592
798
  ent->is_sym = true;
593
594
798
  sym->symbol.the_bfd = vars->abfd;
595
798
  sym->symbol.name    = vars->string_ptr;
596
798
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
597
798
  sym->symbol.section = section;
598
798
  sym->native       = ent;
599
600
798
  *vars->table_ptr = vars->sym_index;
601
798
  *vars->sym_ptr_ptr = sym;
602
603
  /* Adjust pointers for the next symbol.  */
604
798
  vars->sym_index ++;
605
798
  vars->sym_ptr ++;
606
798
  vars->sym_ptr_ptr ++;
607
798
  vars->table_ptr ++;
608
798
  vars->native_ptr ++;
609
798
  vars->esym_ptr ++;
610
798
  vars->string_ptr += len + 1;
611
612
798
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
613
798
}
pei-aarch64.c:pe_ILF_make_a_symbol
Line
Count
Source
544
716
{
545
716
  coff_symbol_type *sym;
546
716
  combined_entry_type *ent;
547
716
  SYMENT *esym;
548
716
  unsigned short sclass;
549
550
716
  if (extra_flags & BSF_LOCAL)
551
401
    sclass = C_STAT;
552
315
  else
553
315
    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
716
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
568
569
716
  sym = vars->sym_ptr;
570
716
  ent = vars->native_ptr;
571
716
  esym = vars->esym_ptr;
572
573
  /* Copy the symbol's name into the string table.  */
574
716
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
575
576
716
  if (section == NULL)
577
119
    section = bfd_und_section_ptr;
578
579
  /* Initialise the external symbol.  */
580
716
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
581
716
      esym->e.e.e_offset);
582
716
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
583
716
  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
716
  ent->u.syment.n_sclass    = sclass;
590
716
  ent->u.syment.n_scnum     = section->target_index;
591
716
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
592
716
  ent->is_sym = true;
593
594
716
  sym->symbol.the_bfd = vars->abfd;
595
716
  sym->symbol.name    = vars->string_ptr;
596
716
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
597
716
  sym->symbol.section = section;
598
716
  sym->native       = ent;
599
600
716
  *vars->table_ptr = vars->sym_index;
601
716
  *vars->sym_ptr_ptr = sym;
602
603
  /* Adjust pointers for the next symbol.  */
604
716
  vars->sym_index ++;
605
716
  vars->sym_ptr ++;
606
716
  vars->sym_ptr_ptr ++;
607
716
  vars->table_ptr ++;
608
716
  vars->native_ptr ++;
609
716
  vars->esym_ptr ++;
610
716
  vars->string_ptr += len + 1;
611
612
716
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
613
716
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_symbol
pei-loongarch64.c:pe_ILF_make_a_symbol
Line
Count
Source
544
812
{
545
812
  coff_symbol_type *sym;
546
812
  combined_entry_type *ent;
547
812
  SYMENT *esym;
548
812
  unsigned short sclass;
549
550
812
  if (extra_flags & BSF_LOCAL)
551
454
    sclass = C_STAT;
552
358
  else
553
358
    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
812
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
568
569
812
  sym = vars->sym_ptr;
570
812
  ent = vars->native_ptr;
571
812
  esym = vars->esym_ptr;
572
573
  /* Copy the symbol's name into the string table.  */
574
812
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
575
576
812
  if (section == NULL)
577
137
    section = bfd_und_section_ptr;
578
579
  /* Initialise the external symbol.  */
580
812
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
581
812
      esym->e.e.e_offset);
582
812
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
583
812
  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
812
  ent->u.syment.n_sclass    = sclass;
590
812
  ent->u.syment.n_scnum     = section->target_index;
591
812
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
592
812
  ent->is_sym = true;
593
594
812
  sym->symbol.the_bfd = vars->abfd;
595
812
  sym->symbol.name    = vars->string_ptr;
596
812
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
597
812
  sym->symbol.section = section;
598
812
  sym->native       = ent;
599
600
812
  *vars->table_ptr = vars->sym_index;
601
812
  *vars->sym_ptr_ptr = sym;
602
603
  /* Adjust pointers for the next symbol.  */
604
812
  vars->sym_index ++;
605
812
  vars->sym_ptr ++;
606
812
  vars->sym_ptr_ptr ++;
607
812
  vars->table_ptr ++;
608
812
  vars->native_ptr ++;
609
812
  vars->esym_ptr ++;
610
812
  vars->string_ptr += len + 1;
611
612
812
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
613
812
}
pei-riscv64.c:pe_ILF_make_a_symbol
Line
Count
Source
544
708
{
545
708
  coff_symbol_type *sym;
546
708
  combined_entry_type *ent;
547
708
  SYMENT *esym;
548
708
  unsigned short sclass;
549
550
708
  if (extra_flags & BSF_LOCAL)
551
389
    sclass = C_STAT;
552
319
  else
553
319
    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
708
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
568
569
708
  sym = vars->sym_ptr;
570
708
  ent = vars->native_ptr;
571
708
  esym = vars->esym_ptr;
572
573
  /* Copy the symbol's name into the string table.  */
574
708
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
575
576
708
  if (section == NULL)
577
120
    section = bfd_und_section_ptr;
578
579
  /* Initialise the external symbol.  */
580
708
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
581
708
      esym->e.e.e_offset);
582
708
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
583
708
  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
708
  ent->u.syment.n_sclass    = sclass;
590
708
  ent->u.syment.n_scnum     = section->target_index;
591
708
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
592
708
  ent->is_sym = true;
593
594
708
  sym->symbol.the_bfd = vars->abfd;
595
708
  sym->symbol.name    = vars->string_ptr;
596
708
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
597
708
  sym->symbol.section = section;
598
708
  sym->native       = ent;
599
600
708
  *vars->table_ptr = vars->sym_index;
601
708
  *vars->sym_ptr_ptr = sym;
602
603
  /* Adjust pointers for the next symbol.  */
604
708
  vars->sym_index ++;
605
708
  vars->sym_ptr ++;
606
708
  vars->sym_ptr_ptr ++;
607
708
  vars->table_ptr ++;
608
708
  vars->native_ptr ++;
609
708
  vars->esym_ptr ++;
610
708
  vars->string_ptr += len + 1;
611
612
708
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
613
708
}
pei-arm-wince.c:pe_ILF_make_a_symbol
Line
Count
Source
544
598
{
545
598
  coff_symbol_type *sym;
546
598
  combined_entry_type *ent;
547
598
  SYMENT *esym;
548
598
  unsigned short sclass;
549
550
598
  if (extra_flags & BSF_LOCAL)
551
335
    sclass = C_STAT;
552
263
  else
553
263
    sclass = C_EXT;
554
555
598
#ifdef THUMBPEMAGIC
556
598
  if (vars->magic == THUMBPEMAGIC)
557
298
    {
558
298
      if (extra_flags & BSF_FUNCTION)
559
25
  sclass = C_THUMBEXTFUNC;
560
273
      else if (extra_flags & BSF_LOCAL)
561
165
  sclass = C_THUMBSTAT;
562
108
      else
563
108
  sclass = C_THUMBEXT;
564
298
    }
565
598
#endif
566
567
598
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
568
569
598
  sym = vars->sym_ptr;
570
598
  ent = vars->native_ptr;
571
598
  esym = vars->esym_ptr;
572
573
  /* Copy the symbol's name into the string table.  */
574
598
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
575
576
598
  if (section == NULL)
577
96
    section = bfd_und_section_ptr;
578
579
  /* Initialise the external symbol.  */
580
598
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
581
598
      esym->e.e.e_offset);
582
598
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
583
598
  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
598
  ent->u.syment.n_sclass    = sclass;
590
598
  ent->u.syment.n_scnum     = section->target_index;
591
598
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
592
598
  ent->is_sym = true;
593
594
598
  sym->symbol.the_bfd = vars->abfd;
595
598
  sym->symbol.name    = vars->string_ptr;
596
598
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
597
598
  sym->symbol.section = section;
598
598
  sym->native       = ent;
599
600
598
  *vars->table_ptr = vars->sym_index;
601
598
  *vars->sym_ptr_ptr = sym;
602
603
  /* Adjust pointers for the next symbol.  */
604
598
  vars->sym_index ++;
605
598
  vars->sym_ptr ++;
606
598
  vars->sym_ptr_ptr ++;
607
598
  vars->table_ptr ++;
608
598
  vars->native_ptr ++;
609
598
  vars->esym_ptr ++;
610
598
  vars->string_ptr += len + 1;
611
612
598
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
613
598
}
pei-arm.c:pe_ILF_make_a_symbol
Line
Count
Source
544
610
{
545
610
  coff_symbol_type *sym;
546
610
  combined_entry_type *ent;
547
610
  SYMENT *esym;
548
610
  unsigned short sclass;
549
550
610
  if (extra_flags & BSF_LOCAL)
551
341
    sclass = C_STAT;
552
269
  else
553
269
    sclass = C_EXT;
554
555
610
#ifdef THUMBPEMAGIC
556
610
  if (vars->magic == THUMBPEMAGIC)
557
298
    {
558
298
      if (extra_flags & BSF_FUNCTION)
559
25
  sclass = C_THUMBEXTFUNC;
560
273
      else if (extra_flags & BSF_LOCAL)
561
165
  sclass = C_THUMBSTAT;
562
108
      else
563
108
  sclass = C_THUMBEXT;
564
298
    }
565
610
#endif
566
567
610
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
568
569
610
  sym = vars->sym_ptr;
570
610
  ent = vars->native_ptr;
571
610
  esym = vars->esym_ptr;
572
573
  /* Copy the symbol's name into the string table.  */
574
610
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
575
576
610
  if (section == NULL)
577
98
    section = bfd_und_section_ptr;
578
579
  /* Initialise the external symbol.  */
580
610
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
581
610
      esym->e.e.e_offset);
582
610
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
583
610
  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
610
  ent->u.syment.n_sclass    = sclass;
590
610
  ent->u.syment.n_scnum     = section->target_index;
591
610
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
592
610
  ent->is_sym = true;
593
594
610
  sym->symbol.the_bfd = vars->abfd;
595
610
  sym->symbol.name    = vars->string_ptr;
596
610
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
597
610
  sym->symbol.section = section;
598
610
  sym->native       = ent;
599
600
610
  *vars->table_ptr = vars->sym_index;
601
610
  *vars->sym_ptr_ptr = sym;
602
603
  /* Adjust pointers for the next symbol.  */
604
610
  vars->sym_index ++;
605
610
  vars->sym_ptr ++;
606
610
  vars->sym_ptr_ptr ++;
607
610
  vars->table_ptr ++;
608
610
  vars->native_ptr ++;
609
610
  vars->esym_ptr ++;
610
610
  vars->string_ptr += len + 1;
611
612
610
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
613
610
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_symbol
pei-sh.c:pe_ILF_make_a_symbol
Line
Count
Source
544
888
{
545
888
  coff_symbol_type *sym;
546
888
  combined_entry_type *ent;
547
888
  SYMENT *esym;
548
888
  unsigned short sclass;
549
550
888
  if (extra_flags & BSF_LOCAL)
551
497
    sclass = C_STAT;
552
391
  else
553
391
    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
888
  BFD_ASSERT (vars->sym_index < NUM_ILF_SYMS);
568
569
888
  sym = vars->sym_ptr;
570
888
  ent = vars->native_ptr;
571
888
  esym = vars->esym_ptr;
572
573
  /* Copy the symbol's name into the string table.  */
574
888
  int len = sprintf (vars->string_ptr, "%s%s", prefix, symbol_name);
575
576
888
  if (section == NULL)
577
148
    section = bfd_und_section_ptr;
578
579
  /* Initialise the external symbol.  */
580
888
  H_PUT_32 (vars->abfd, vars->string_ptr - vars->string_table,
581
888
      esym->e.e.e_offset);
582
888
  H_PUT_16 (vars->abfd, section->target_index, esym->e_scnum);
583
888
  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
888
  ent->u.syment.n_sclass    = sclass;
590
888
  ent->u.syment.n_scnum     = section->target_index;
591
888
  ent->u.syment._n._n_n._n_offset = (uintptr_t) sym;
592
888
  ent->is_sym = true;
593
594
888
  sym->symbol.the_bfd = vars->abfd;
595
888
  sym->symbol.name    = vars->string_ptr;
596
888
  sym->symbol.flags   = BSF_EXPORT | BSF_GLOBAL | extra_flags;
597
888
  sym->symbol.section = section;
598
888
  sym->native       = ent;
599
600
888
  *vars->table_ptr = vars->sym_index;
601
888
  *vars->sym_ptr_ptr = sym;
602
603
  /* Adjust pointers for the next symbol.  */
604
888
  vars->sym_index ++;
605
888
  vars->sym_ptr ++;
606
888
  vars->sym_ptr_ptr ++;
607
888
  vars->table_ptr ++;
608
888
  vars->native_ptr ++;
609
888
  vars->esym_ptr ++;
610
888
  vars->string_ptr += len + 1;
611
612
888
  BFD_ASSERT (vars->string_ptr < vars->end_string_ptr);
613
888
}
614
615
/* Create a section.  */
616
617
static asection_ptr
618
pe_ILF_make_a_section (pe_ILF_vars * vars,
619
           const char *  name,
620
           unsigned int  size,
621
           flagword      extra_flags)
622
3.25k
{
623
3.25k
  asection_ptr sec;
624
3.25k
  flagword     flags;
625
3.25k
  intptr_t alignment;
626
627
3.25k
  sec = bfd_make_section_old_way (vars->abfd, name);
628
3.25k
  if (sec == NULL)
629
0
    return NULL;
630
631
3.25k
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
632
633
3.25k
  bfd_set_section_flags (sec, flags | extra_flags);
634
635
3.25k
  bfd_set_section_alignment (sec, 2);
636
637
  /* Check that we will not run out of space.  */
638
3.25k
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
639
640
  /* Set the section size and contents.  The actual
641
     contents are filled in by our parent.  */
642
3.25k
  bfd_set_section_size (sec, (bfd_size_type) size);
643
3.25k
  sec->contents = vars->data;
644
3.25k
  sec->target_index = vars->sec_index ++;
645
646
  /* Advance data pointer in the vars structure.  */
647
3.25k
  vars->data += size;
648
649
  /* Skip the padding byte if it was not needed.
650
     The logic here is that if the string length is odd,
651
     then the entire string length, including the null byte,
652
     is even and so the extra, padding byte, is not needed.  */
653
3.25k
  if (size & 1)
654
367
    vars->data --;
655
656
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
657
     preserve host alignment requirements.  The BFD_ASSERTs in this
658
     functions will warn us if we run out of room, but we should
659
     already have enough padding built in to ILF_DATA_SIZE.  */
660
3.25k
#if GCC_VERSION >= 3000
661
3.25k
  alignment = __alignof__ (struct coff_section_tdata);
662
#else
663
  alignment = 8;
664
#endif
665
3.25k
  vars->data
666
3.25k
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
667
668
  /* Create a coff_section_tdata structure for our use.  */
669
3.25k
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
670
3.25k
  vars->data += sizeof (struct coff_section_tdata);
671
672
3.25k
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
673
674
  /* Create a symbol to refer to this section.  */
675
3.25k
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
676
677
  /* Cache the index to the symbol in the coff_section_data structure.  */
678
3.25k
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
679
680
3.25k
  return sec;
681
3.25k
}
pei-i386.c:pe_ILF_make_a_section
Line
Count
Source
622
405
{
623
405
  asection_ptr sec;
624
405
  flagword     flags;
625
405
  intptr_t alignment;
626
627
405
  sec = bfd_make_section_old_way (vars->abfd, name);
628
405
  if (sec == NULL)
629
0
    return NULL;
630
631
405
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
632
633
405
  bfd_set_section_flags (sec, flags | extra_flags);
634
635
405
  bfd_set_section_alignment (sec, 2);
636
637
  /* Check that we will not run out of space.  */
638
405
  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
405
  bfd_set_section_size (sec, (bfd_size_type) size);
643
405
  sec->contents = vars->data;
644
405
  sec->target_index = vars->sec_index ++;
645
646
  /* Advance data pointer in the vars structure.  */
647
405
  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
405
  if (size & 1)
654
38
    vars->data --;
655
656
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
657
     preserve host alignment requirements.  The BFD_ASSERTs in this
658
     functions will warn us if we run out of room, but we should
659
     already have enough padding built in to ILF_DATA_SIZE.  */
660
405
#if GCC_VERSION >= 3000
661
405
  alignment = __alignof__ (struct coff_section_tdata);
662
#else
663
  alignment = 8;
664
#endif
665
405
  vars->data
666
405
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
667
668
  /* Create a coff_section_tdata structure for our use.  */
669
405
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
670
405
  vars->data += sizeof (struct coff_section_tdata);
671
672
405
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
673
674
  /* Create a symbol to refer to this section.  */
675
405
  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
405
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
679
680
405
  return sec;
681
405
}
pei-x86_64.c:pe_ILF_make_a_section
Line
Count
Source
622
437
{
623
437
  asection_ptr sec;
624
437
  flagword     flags;
625
437
  intptr_t alignment;
626
627
437
  sec = bfd_make_section_old_way (vars->abfd, name);
628
437
  if (sec == NULL)
629
0
    return NULL;
630
631
437
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
632
633
437
  bfd_set_section_flags (sec, flags | extra_flags);
634
635
437
  bfd_set_section_alignment (sec, 2);
636
637
  /* Check that we will not run out of space.  */
638
437
  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
437
  bfd_set_section_size (sec, (bfd_size_type) size);
643
437
  sec->contents = vars->data;
644
437
  sec->target_index = vars->sec_index ++;
645
646
  /* Advance data pointer in the vars structure.  */
647
437
  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
437
  if (size & 1)
654
49
    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
437
#if GCC_VERSION >= 3000
661
437
  alignment = __alignof__ (struct coff_section_tdata);
662
#else
663
  alignment = 8;
664
#endif
665
437
  vars->data
666
437
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
667
668
  /* Create a coff_section_tdata structure for our use.  */
669
437
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
670
437
  vars->data += sizeof (struct coff_section_tdata);
671
672
437
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
673
674
  /* Create a symbol to refer to this section.  */
675
437
  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
437
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
679
680
437
  return sec;
681
437
}
pei-aarch64.c:pe_ILF_make_a_section
Line
Count
Source
622
401
{
623
401
  asection_ptr sec;
624
401
  flagword     flags;
625
401
  intptr_t alignment;
626
627
401
  sec = bfd_make_section_old_way (vars->abfd, name);
628
401
  if (sec == NULL)
629
0
    return NULL;
630
631
401
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
632
633
401
  bfd_set_section_flags (sec, flags | extra_flags);
634
635
401
  bfd_set_section_alignment (sec, 2);
636
637
  /* Check that we will not run out of space.  */
638
401
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
639
640
  /* Set the section size and contents.  The actual
641
     contents are filled in by our parent.  */
642
401
  bfd_set_section_size (sec, (bfd_size_type) size);
643
401
  sec->contents = vars->data;
644
401
  sec->target_index = vars->sec_index ++;
645
646
  /* Advance data pointer in the vars structure.  */
647
401
  vars->data += size;
648
649
  /* Skip the padding byte if it was not needed.
650
     The logic here is that if the string length is odd,
651
     then the entire string length, including the null byte,
652
     is even and so the extra, padding byte, is not needed.  */
653
401
  if (size & 1)
654
46
    vars->data --;
655
656
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
657
     preserve host alignment requirements.  The BFD_ASSERTs in this
658
     functions will warn us if we run out of room, but we should
659
     already have enough padding built in to ILF_DATA_SIZE.  */
660
401
#if GCC_VERSION >= 3000
661
401
  alignment = __alignof__ (struct coff_section_tdata);
662
#else
663
  alignment = 8;
664
#endif
665
401
  vars->data
666
401
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
667
668
  /* Create a coff_section_tdata structure for our use.  */
669
401
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
670
401
  vars->data += sizeof (struct coff_section_tdata);
671
672
401
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
673
674
  /* Create a symbol to refer to this section.  */
675
401
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
676
677
  /* Cache the index to the symbol in the coff_section_data structure.  */
678
401
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
679
680
401
  return sec;
681
401
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_make_a_section
pei-loongarch64.c:pe_ILF_make_a_section
Line
Count
Source
622
454
{
623
454
  asection_ptr sec;
624
454
  flagword     flags;
625
454
  intptr_t alignment;
626
627
454
  sec = bfd_make_section_old_way (vars->abfd, name);
628
454
  if (sec == NULL)
629
0
    return NULL;
630
631
454
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
632
633
454
  bfd_set_section_flags (sec, flags | extra_flags);
634
635
454
  bfd_set_section_alignment (sec, 2);
636
637
  /* Check that we will not run out of space.  */
638
454
  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
454
  bfd_set_section_size (sec, (bfd_size_type) size);
643
454
  sec->contents = vars->data;
644
454
  sec->target_index = vars->sec_index ++;
645
646
  /* Advance data pointer in the vars structure.  */
647
454
  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
454
  if (size & 1)
654
59
    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
454
#if GCC_VERSION >= 3000
661
454
  alignment = __alignof__ (struct coff_section_tdata);
662
#else
663
  alignment = 8;
664
#endif
665
454
  vars->data
666
454
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
667
668
  /* Create a coff_section_tdata structure for our use.  */
669
454
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
670
454
  vars->data += sizeof (struct coff_section_tdata);
671
672
454
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
673
674
  /* Create a symbol to refer to this section.  */
675
454
  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
454
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
679
680
454
  return sec;
681
454
}
pei-riscv64.c:pe_ILF_make_a_section
Line
Count
Source
622
389
{
623
389
  asection_ptr sec;
624
389
  flagword     flags;
625
389
  intptr_t alignment;
626
627
389
  sec = bfd_make_section_old_way (vars->abfd, name);
628
389
  if (sec == NULL)
629
0
    return NULL;
630
631
389
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
632
633
389
  bfd_set_section_flags (sec, flags | extra_flags);
634
635
389
  bfd_set_section_alignment (sec, 2);
636
637
  /* Check that we will not run out of space.  */
638
389
  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
389
  bfd_set_section_size (sec, (bfd_size_type) size);
643
389
  sec->contents = vars->data;
644
389
  sec->target_index = vars->sec_index ++;
645
646
  /* Advance data pointer in the vars structure.  */
647
389
  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
389
  if (size & 1)
654
49
    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
389
#if GCC_VERSION >= 3000
661
389
  alignment = __alignof__ (struct coff_section_tdata);
662
#else
663
  alignment = 8;
664
#endif
665
389
  vars->data
666
389
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
667
668
  /* Create a coff_section_tdata structure for our use.  */
669
389
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
670
389
  vars->data += sizeof (struct coff_section_tdata);
671
672
389
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
673
674
  /* Create a symbol to refer to this section.  */
675
389
  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
389
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
679
680
389
  return sec;
681
389
}
pei-arm-wince.c:pe_ILF_make_a_section
Line
Count
Source
622
335
{
623
335
  asection_ptr sec;
624
335
  flagword     flags;
625
335
  intptr_t alignment;
626
627
335
  sec = bfd_make_section_old_way (vars->abfd, name);
628
335
  if (sec == NULL)
629
0
    return NULL;
630
631
335
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
632
633
335
  bfd_set_section_flags (sec, flags | extra_flags);
634
635
335
  bfd_set_section_alignment (sec, 2);
636
637
  /* Check that we will not run out of space.  */
638
335
  BFD_ASSERT (vars->data + size < vars->bim->buffer + vars->bim->size);
639
640
  /* Set the section size and contents.  The actual
641
     contents are filled in by our parent.  */
642
335
  bfd_set_section_size (sec, (bfd_size_type) size);
643
335
  sec->contents = vars->data;
644
335
  sec->target_index = vars->sec_index ++;
645
646
  /* Advance data pointer in the vars structure.  */
647
335
  vars->data += size;
648
649
  /* Skip the padding byte if it was not needed.
650
     The logic here is that if the string length is odd,
651
     then the entire string length, including the null byte,
652
     is even and so the extra, padding byte, is not needed.  */
653
335
  if (size & 1)
654
38
    vars->data --;
655
656
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
657
     preserve host alignment requirements.  The BFD_ASSERTs in this
658
     functions will warn us if we run out of room, but we should
659
     already have enough padding built in to ILF_DATA_SIZE.  */
660
335
#if GCC_VERSION >= 3000
661
335
  alignment = __alignof__ (struct coff_section_tdata);
662
#else
663
  alignment = 8;
664
#endif
665
335
  vars->data
666
335
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
667
668
  /* Create a coff_section_tdata structure for our use.  */
669
335
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
670
335
  vars->data += sizeof (struct coff_section_tdata);
671
672
335
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
673
674
  /* Create a symbol to refer to this section.  */
675
335
  pe_ILF_make_a_symbol (vars, "", name, sec, BSF_LOCAL);
676
677
  /* Cache the index to the symbol in the coff_section_data structure.  */
678
335
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
679
680
335
  return sec;
681
335
}
pei-arm.c:pe_ILF_make_a_section
Line
Count
Source
622
341
{
623
341
  asection_ptr sec;
624
341
  flagword     flags;
625
341
  intptr_t alignment;
626
627
341
  sec = bfd_make_section_old_way (vars->abfd, name);
628
341
  if (sec == NULL)
629
0
    return NULL;
630
631
341
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
632
633
341
  bfd_set_section_flags (sec, flags | extra_flags);
634
635
341
  bfd_set_section_alignment (sec, 2);
636
637
  /* Check that we will not run out of space.  */
638
341
  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
341
  bfd_set_section_size (sec, (bfd_size_type) size);
643
341
  sec->contents = vars->data;
644
341
  sec->target_index = vars->sec_index ++;
645
646
  /* Advance data pointer in the vars structure.  */
647
341
  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
341
  if (size & 1)
654
38
    vars->data --;
655
656
  /* PR 18758: See note in pe_ILF_buid_a_bfd.  We must make sure that we
657
     preserve host alignment requirements.  The BFD_ASSERTs in this
658
     functions will warn us if we run out of room, but we should
659
     already have enough padding built in to ILF_DATA_SIZE.  */
660
341
#if GCC_VERSION >= 3000
661
341
  alignment = __alignof__ (struct coff_section_tdata);
662
#else
663
  alignment = 8;
664
#endif
665
341
  vars->data
666
341
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
667
668
  /* Create a coff_section_tdata structure for our use.  */
669
341
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
670
341
  vars->data += sizeof (struct coff_section_tdata);
671
672
341
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
673
674
  /* Create a symbol to refer to this section.  */
675
341
  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
341
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
679
680
341
  return sec;
681
341
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_make_a_section
pei-sh.c:pe_ILF_make_a_section
Line
Count
Source
622
497
{
623
497
  asection_ptr sec;
624
497
  flagword     flags;
625
497
  intptr_t alignment;
626
627
497
  sec = bfd_make_section_old_way (vars->abfd, name);
628
497
  if (sec == NULL)
629
0
    return NULL;
630
631
497
  flags = SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_KEEP | SEC_IN_MEMORY;
632
633
497
  bfd_set_section_flags (sec, flags | extra_flags);
634
635
497
  bfd_set_section_alignment (sec, 2);
636
637
  /* Check that we will not run out of space.  */
638
497
  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
497
  bfd_set_section_size (sec, (bfd_size_type) size);
643
497
  sec->contents = vars->data;
644
497
  sec->target_index = vars->sec_index ++;
645
646
  /* Advance data pointer in the vars structure.  */
647
497
  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
497
  if (size & 1)
654
50
    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
497
#if GCC_VERSION >= 3000
661
497
  alignment = __alignof__ (struct coff_section_tdata);
662
#else
663
  alignment = 8;
664
#endif
665
497
  vars->data
666
497
    = (bfd_byte *) (((intptr_t) vars->data + alignment - 1) & -alignment);
667
668
  /* Create a coff_section_tdata structure for our use.  */
669
497
  sec->used_by_bfd = (struct coff_section_tdata *) vars->data;
670
497
  vars->data += sizeof (struct coff_section_tdata);
671
672
497
  BFD_ASSERT (vars->data <= vars->bim->buffer + vars->bim->size);
673
674
  /* Create a symbol to refer to this section.  */
675
497
  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
497
  coff_section_data (vars->abfd, sec)->i = vars->sym_index - 1;
679
680
497
  return sec;
681
497
}
682
683
/* This structure contains the code that goes into the .text section
684
   in order to perform a jump into the DLL lookup table.  The entries
685
   in the table are index by the magic number used to represent the
686
   machine type in the PE file.  The contents of the data[] arrays in
687
   these entries are stolen from the jtab[] arrays in ld/pe-dll.c.
688
   The SIZE field says how many bytes in the DATA array are actually
689
   used.  The OFFSET field says where in the data array the address
690
   of the .idata$5 section should be placed.  */
691
2.09k
#define MAX_TEXT_SECTION_SIZE 32
692
693
typedef struct
694
{
695
  unsigned short magic;
696
  unsigned char  data[MAX_TEXT_SECTION_SIZE];
697
  unsigned int   size;
698
  unsigned int   offset;
699
}
700
jump_table;
701
702
static const jump_table jtab[] =
703
{
704
#ifdef I386MAGIC
705
  { I386MAGIC,
706
    { 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, 0x90, 0x90 },
707
    8, 2
708
  },
709
#endif
710
711
#ifdef AMD64MAGIC
712
  { AMD64MAGIC,
713
    { 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, 0x90, 0x90 },
714
    8, 2
715
  },
716
#endif
717
718
#ifdef  MC68MAGIC
719
  { MC68MAGIC,
720
    { /* XXX fill me in */ },
721
    0, 0
722
  },
723
#endif
724
725
#ifdef  MIPS_ARCH_MAGIC_WINCE
726
  { MIPS_ARCH_MAGIC_WINCE,
727
    { 0x00, 0x00, 0x08, 0x3c, 0x00, 0x00, 0x08, 0x8d,
728
      0x08, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00 },
729
    16, 0
730
  },
731
#endif
732
733
#ifdef  SH_ARCH_MAGIC_WINCE
734
  { SH_ARCH_MAGIC_WINCE,
735
    { 0x01, 0xd0, 0x02, 0x60, 0x2b, 0x40,
736
      0x09, 0x00, 0x00, 0x00, 0x00, 0x00 },
737
    12, 8
738
  },
739
#endif
740
741
#ifdef AARCH64MAGIC
742
/* We don't currently support jumping to DLLs, so if
743
   someone does try emit a runtime trap.  Through UDF #0.  */
744
  { AARCH64MAGIC,
745
    { 0x00, 0x00, 0x00, 0x00 },
746
    4, 0
747
  },
748
749
#endif
750
751
#ifdef  ARMPEMAGIC
752
  { ARMPEMAGIC,
753
    { 0x00, 0xc0, 0x9f, 0xe5, 0x00, 0xf0,
754
      0x9c, 0xe5, 0x00, 0x00, 0x00, 0x00},
755
    12, 8
756
  },
757
#endif
758
759
#ifdef  THUMBPEMAGIC
760
  { THUMBPEMAGIC,
761
    { 0x40, 0xb4, 0x02, 0x4e, 0x36, 0x68, 0xb4, 0x46,
762
      0x40, 0xbc, 0x60, 0x47, 0x00, 0x00, 0x00, 0x00 },
763
    16, 12
764
  },
765
#endif
766
767
#ifdef LOONGARCH64MAGIC
768
/* We don't currently support jumping to DLLs, so if
769
   someone does try emit a runtime trap.  Through BREAK 0.  */
770
  { LOONGARCH64MAGIC,
771
    { 0x00, 0x00, 0x2a, 0x00 },
772
    4, 0
773
  },
774
775
#endif
776
777
#ifdef RISCV64MAGIC
778
  /* We don't currently support jumping to DLLs, so if
779
     someone does try emit a runtime trap.  Through EBREAK.  */
780
  { RISCV64MAGIC,
781
    { 0x73, 0x00, 0x10, 0x00 },
782
    4, 0
783
  },
784
785
#endif
786
787
  { 0, { 0 }, 0, 0 }
788
};
789
790
#ifndef NUM_ENTRIES
791
436
#define NUM_ENTRIES(a) (sizeof (a) / sizeof (a)[0])
792
#endif
793
794
/* Build a full BFD from the information supplied in a ILF object.  */
795
796
static bool
797
pe_ILF_build_a_bfd (bfd *     abfd,
798
        unsigned int    magic,
799
        char *      symbol_name,
800
        char *      source_dll,
801
        unsigned int    ordinal,
802
        unsigned int    types,
803
        char *      import_name)
804
1.35k
{
805
1.35k
  bfd_byte *       ptr;
806
1.35k
  pe_ILF_vars      vars;
807
1.35k
  struct internal_filehdr  internal_f;
808
1.35k
  unsigned int       import_type;
809
1.35k
  unsigned int       import_name_type;
810
1.35k
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
811
1.35k
  coff_symbol_type **    imp_sym;
812
1.35k
  unsigned int       imp_index;
813
1.35k
  intptr_t alignment;
814
815
  /* Decode and verify the types field of the ILF structure.  */
816
1.35k
  import_type = types & 0x3;
817
1.35k
  import_name_type = (types & 0x1c) >> 2;
818
819
1.35k
  switch (import_type)
820
1.35k
    {
821
583
    case IMPORT_CODE:
822
966
    case IMPORT_DATA:
823
1.25k
    case IMPORT_CONST:
824
1.25k
      break;
825
826
102
    default:
827
      /* xgettext:c-format */
828
102
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
102
        abfd, import_type);
830
102
      return false;
831
1.35k
    }
832
833
1.25k
  switch (import_name_type)
834
1.25k
    {
835
312
    case IMPORT_ORDINAL:
836
427
    case IMPORT_NAME:
837
624
    case IMPORT_NAME_NOPREFIX:
838
947
    case IMPORT_NAME_UNDECORATE:
839
947
      import_name = symbol_name;
840
947
      break;
841
842
236
    case IMPORT_NAME_EXPORTAS:
843
236
      if (!import_name || !import_name[0])
844
138
  {
845
138
    _bfd_error_handler (_("%pB: missing import name for "
846
138
        "IMPORT_NAME_EXPORTAS for %s"),
847
138
            abfd, symbol_name);
848
138
    return false;
849
138
  }
850
98
      break;
851
852
98
    default:
853
      /* xgettext:c-format */
854
70
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
855
70
        abfd, import_name_type);
856
70
      return false;
857
1.25k
    }
858
859
  /* Initialise local variables.
860
861
     Note these are kept in a structure rather than being
862
     declared as statics since bfd frowns on global variables.
863
864
     We are going to construct the contents of the BFD in memory,
865
     so allocate all the space that we will need right now.  */
866
1.04k
  vars.bim
867
1.04k
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
868
1.04k
  if (vars.bim == NULL)
869
0
    return false;
870
871
1.04k
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
872
1.04k
  vars.bim->buffer = ptr;
873
1.04k
  vars.bim->size   = ILF_DATA_SIZE;
874
1.04k
  if (ptr == NULL)
875
0
    goto error_return;
876
877
  /* Initialise the pointers to regions of the memory and the
878
     other contents of the pe_ILF_vars structure as well.  */
879
1.04k
  vars.sym_cache = (coff_symbol_type *) ptr;
880
1.04k
  vars.sym_ptr   = (coff_symbol_type *) ptr;
881
1.04k
  vars.sym_index = 0;
882
1.04k
  ptr += SIZEOF_ILF_SYMS;
883
884
1.04k
  vars.sym_table = (unsigned int *) ptr;
885
1.04k
  vars.table_ptr = (unsigned int *) ptr;
886
1.04k
  ptr += SIZEOF_ILF_SYM_TABLE;
887
888
1.04k
  vars.native_syms = (combined_entry_type *) ptr;
889
1.04k
  vars.native_ptr  = (combined_entry_type *) ptr;
890
1.04k
  ptr += SIZEOF_ILF_NATIVE_SYMS;
891
892
1.04k
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
893
1.04k
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
894
1.04k
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
895
896
1.04k
  vars.esym_table = (SYMENT *) ptr;
897
1.04k
  vars.esym_ptr   = (SYMENT *) ptr;
898
1.04k
  ptr += SIZEOF_ILF_EXT_SYMS;
899
900
1.04k
  vars.reltab   = (arelent *) ptr;
901
1.04k
  vars.relcount = 0;
902
1.04k
  ptr += SIZEOF_ILF_RELOCS;
903
904
1.04k
  vars.int_reltab  = (struct internal_reloc *) ptr;
905
1.04k
  ptr += SIZEOF_ILF_INT_RELOCS;
906
907
1.04k
  vars.string_table = (char *) ptr;
908
1.04k
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
909
1.04k
  ptr += SIZEOF_ILF_STRINGS;
910
1.04k
  vars.end_string_ptr = (char *) ptr;
911
912
  /* The remaining space in bim->buffer is used
913
     by the pe_ILF_make_a_section() function.  */
914
915
  /* PR 18758: Make sure that the data area is sufficiently aligned for
916
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
917
     the test of GCC_VERSION.  For other compilers we assume 8 byte
918
     alignment.  */
919
1.04k
#if GCC_VERSION >= 3000
920
1.04k
  alignment = __alignof__ (struct coff_section_tdata);
921
#else
922
  alignment = 8;
923
#endif
924
1.04k
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
925
926
1.04k
  vars.data = ptr;
927
1.04k
  vars.abfd = abfd;
928
1.04k
  vars.sec_index = 0;
929
1.04k
  vars.magic = magic;
930
931
  /* Create the initial .idata$<n> sections:
932
     [.idata$2:  Import Directory Table -- not needed]
933
     .idata$4:  Import Lookup Table
934
     .idata$5:  Import Address Table
935
936
     Note we do not create a .idata$3 section as this is
937
     created for us by the linker script.  */
938
1.04k
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
939
1.04k
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
940
1.04k
  if (id4 == NULL || id5 == NULL)
941
0
    goto error_return;
942
943
  /* Fill in the contents of these sections.  */
944
1.04k
  if (import_name_type == IMPORT_ORDINAL)
945
312
    {
946
312
      if (ordinal == 0)
947
  /* See PR 20907 for a reproducer.  */
948
78
  goto error_return;
949
950
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
951
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
952
128
      ((unsigned int *) id4->contents)[0] = ordinal;
953
128
      ((unsigned int *) id4->contents)[1] = 0x80000000;
954
128
      ((unsigned int *) id5->contents)[0] = ordinal;
955
128
      ((unsigned int *) id5->contents)[1] = 0x80000000;
956
#else
957
106
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
958
106
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
959
106
#endif
960
106
    }
961
733
  else
962
733
    {
963
733
      char *symbol;
964
733
      unsigned int len;
965
966
      /* Create .idata$6 - the Hint Name Table.  */
967
733
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
968
733
      if (id6 == NULL)
969
0
  goto error_return;
970
971
      /* If necessary, trim the import symbol name.  */
972
733
      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
733
      if (import_name_type != IMPORT_NAME
982
618
    && import_name_type != IMPORT_NAME_EXPORTAS)
983
520
  {
984
520
    char c = symbol[0];
985
986
    /* Check that we don't remove for targets with empty
987
       USER_LABEL_PREFIX the leading underscore.  */
988
520
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
989
487
        || c == '@' || c == '?')
990
159
      symbol++;
991
520
  }
992
993
733
      len = strlen (symbol);
994
733
      if (import_name_type == IMPORT_NAME_UNDECORATE)
995
323
  {
996
    /* Truncate at the first '@'.  */
997
323
    char *at = strchr (symbol, '@');
998
999
323
    if (at != NULL)
1000
70
      len = at - symbol;
1001
323
  }
1002
1003
733
      id6->contents[0] = ordinal & 0xff;
1004
733
      id6->contents[1] = ordinal >> 8;
1005
1006
733
      memcpy ((char *) id6->contents + 2, symbol, len);
1007
733
      id6->contents[len + 2] = '\0';
1008
733
    }
1009
1010
967
  if (import_name_type != IMPORT_ORDINAL)
1011
733
    {
1012
733
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1013
733
      pe_ILF_save_relocs (&vars, id4);
1014
1015
733
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1016
733
      pe_ILF_save_relocs (&vars, id5);
1017
733
    }
1018
1019
  /* Create an import symbol.  */
1020
967
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1021
967
  imp_sym   = vars.sym_ptr_ptr - 1;
1022
967
  imp_index = vars.sym_index - 1;
1023
1024
  /* Create extra sections depending upon the type of import we are
1025
     dealing with.  */
1026
967
  switch (import_type)
1027
967
    {
1028
0
      int i;
1029
1030
436
    case IMPORT_CODE:
1031
      /* CODE functions are special, in that they get a trampoline that
1032
   jumps to the main import symbol.  Create a .text section to hold it.
1033
   First we need to look up its contents in the jump table.  */
1034
927
      for (i = NUM_ENTRIES (jtab); i--;)
1035
927
  {
1036
927
    if (jtab[i].size == 0)
1037
436
      continue;
1038
491
    if (jtab[i].magic == magic)
1039
436
      break;
1040
491
  }
1041
      /* If we did not find a matching entry something is wrong.  */
1042
436
      if (i < 0)
1043
0
  abort ();
1044
1045
      /* Create the .text section.  */
1046
436
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1047
436
      if (text == NULL)
1048
0
  goto error_return;
1049
1050
      /* Copy in the jump code.  */
1051
436
      memcpy (text->contents, jtab[i].data, jtab[i].size);
1052
1053
      /* Create a reloc for the data in the text section.  */
1054
#ifdef MIPS_ARCH_MAGIC_WINCE
1055
      if (magic == MIPS_ARCH_MAGIC_WINCE)
1056
  {
1057
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
1058
              (struct bfd_symbol **) imp_sym,
1059
              imp_index);
1060
    pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
1061
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
1062
              (struct bfd_symbol **) imp_sym,
1063
              imp_index);
1064
  }
1065
      else
1066
#endif
1067
#ifdef AMD64MAGIC
1068
56
      if (magic == AMD64MAGIC)
1069
56
  {
1070
56
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1071
56
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1072
56
              imp_index);
1073
56
  }
1074
0
      else
1075
0
#endif
1076
0
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1077
0
            BFD_RELOC_32, (asymbol **) imp_sym,
1078
0
            imp_index);
1079
1080
436
      pe_ILF_save_relocs (&vars, text);
1081
436
      break;
1082
1083
299
    case IMPORT_DATA:
1084
531
    case IMPORT_CONST:
1085
531
      break;
1086
1087
0
    default:
1088
      /* XXX code not yet written.  */
1089
0
      abort ();
1090
967
    }
1091
1092
  /* Now create a symbol describing the imported value.  */
1093
967
  switch (import_type)
1094
967
    {
1095
436
    case IMPORT_CODE:
1096
436
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1097
436
          BSF_NOT_AT_END | BSF_FUNCTION);
1098
1099
436
      break;
1100
1101
299
    case IMPORT_DATA:
1102
      /* Nothing to do here.  */
1103
299
      break;
1104
1105
232
    case IMPORT_CONST:
1106
232
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1107
232
      break;
1108
1109
0
    default:
1110
      /* XXX code not yet written.  */
1111
0
      abort ();
1112
967
    }
1113
1114
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1115
967
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1116
967
  if (ptr)
1117
119
    *ptr = 0;
1118
967
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1119
967
  if (ptr)
1120
119
    *ptr = '.';
1121
1122
  /* Initialise the bfd.  */
1123
967
  memset (&internal_f, 0, sizeof (internal_f));
1124
1125
967
  internal_f.f_magic  = magic;
1126
967
  internal_f.f_symptr = 0;
1127
967
  internal_f.f_nsyms  = 0;
1128
967
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1129
1130
967
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1131
967
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1132
0
    goto error_return;
1133
1134
967
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1135
0
    goto error_return;
1136
1137
967
  obj_pe (abfd) = true;
1138
#ifdef THUMBPEMAGIC
1139
194
  if (vars.magic == THUMBPEMAGIC)
1140
    /* Stop some linker warnings about thumb code not supporting
1141
       interworking.  */
1142
98
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1143
#endif
1144
1145
  /* Switch from file contents to memory contents.  */
1146
967
  bfd_cache_close (abfd);
1147
1148
967
  abfd->iostream = (void *) vars.bim;
1149
967
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1150
967
  abfd->iovec = &_bfd_memory_iovec;
1151
967
  abfd->where = 0;
1152
967
  abfd->origin = 0;
1153
967
  abfd->size = 0;
1154
967
  obj_sym_filepos (abfd) = 0;
1155
1156
  /* Point the bfd at the symbol table.  */
1157
967
  obj_symbols (abfd) = vars.sym_cache;
1158
967
  abfd->symcount = vars.sym_index;
1159
1160
967
  obj_raw_syments (abfd) = vars.native_syms;
1161
967
  obj_raw_syment_count (abfd) = vars.sym_index;
1162
967
  obj_coff_keep_raw_syms (abfd) = true;
1163
1164
967
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1165
967
  obj_coff_keep_syms (abfd) = true;
1166
1167
967
  obj_convert (abfd) = vars.sym_table;
1168
967
  obj_conv_table_size (abfd) = vars.sym_index;
1169
1170
967
  obj_coff_strings (abfd) = vars.string_table;
1171
967
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1172
967
  obj_coff_keep_strings (abfd) = true;
1173
1174
967
  return true;
1175
1176
78
 error_return:
1177
78
  free (vars.bim->buffer);
1178
78
  free (vars.bim);
1179
78
  return false;
1180
967
}
pei-i386.c:pe_ILF_build_a_bfd
Line
Count
Source
804
155
{
805
155
  bfd_byte *       ptr;
806
155
  pe_ILF_vars      vars;
807
155
  struct internal_filehdr  internal_f;
808
155
  unsigned int       import_type;
809
155
  unsigned int       import_name_type;
810
155
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
811
155
  coff_symbol_type **    imp_sym;
812
155
  unsigned int       imp_index;
813
155
  intptr_t alignment;
814
815
  /* Decode and verify the types field of the ILF structure.  */
816
155
  import_type = types & 0x3;
817
155
  import_name_type = (types & 0x1c) >> 2;
818
819
155
  switch (import_type)
820
155
    {
821
82
    case IMPORT_CODE:
822
109
    case IMPORT_DATA:
823
149
    case IMPORT_CONST:
824
149
      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
155
    }
832
833
149
  switch (import_name_type)
834
149
    {
835
34
    case IMPORT_ORDINAL:
836
49
    case IMPORT_NAME:
837
78
    case IMPORT_NAME_NOPREFIX:
838
116
    case IMPORT_NAME_UNDECORATE:
839
116
      import_name = symbol_name;
840
116
      break;
841
842
25
    case IMPORT_NAME_EXPORTAS:
843
25
      if (!import_name || !import_name[0])
844
15
  {
845
15
    _bfd_error_handler (_("%pB: missing import name for "
846
15
        "IMPORT_NAME_EXPORTAS for %s"),
847
15
            abfd, symbol_name);
848
15
    return false;
849
15
  }
850
10
      break;
851
852
10
    default:
853
      /* xgettext:c-format */
854
8
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
855
8
        abfd, import_name_type);
856
8
      return false;
857
149
    }
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
126
  vars.bim
867
126
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
868
126
  if (vars.bim == NULL)
869
0
    return false;
870
871
126
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
872
126
  vars.bim->buffer = ptr;
873
126
  vars.bim->size   = ILF_DATA_SIZE;
874
126
  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
126
  vars.sym_cache = (coff_symbol_type *) ptr;
880
126
  vars.sym_ptr   = (coff_symbol_type *) ptr;
881
126
  vars.sym_index = 0;
882
126
  ptr += SIZEOF_ILF_SYMS;
883
884
126
  vars.sym_table = (unsigned int *) ptr;
885
126
  vars.table_ptr = (unsigned int *) ptr;
886
126
  ptr += SIZEOF_ILF_SYM_TABLE;
887
888
126
  vars.native_syms = (combined_entry_type *) ptr;
889
126
  vars.native_ptr  = (combined_entry_type *) ptr;
890
126
  ptr += SIZEOF_ILF_NATIVE_SYMS;
891
892
126
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
893
126
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
894
126
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
895
896
126
  vars.esym_table = (SYMENT *) ptr;
897
126
  vars.esym_ptr   = (SYMENT *) ptr;
898
126
  ptr += SIZEOF_ILF_EXT_SYMS;
899
900
126
  vars.reltab   = (arelent *) ptr;
901
126
  vars.relcount = 0;
902
126
  ptr += SIZEOF_ILF_RELOCS;
903
904
126
  vars.int_reltab  = (struct internal_reloc *) ptr;
905
126
  ptr += SIZEOF_ILF_INT_RELOCS;
906
907
126
  vars.string_table = (char *) ptr;
908
126
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
909
126
  ptr += SIZEOF_ILF_STRINGS;
910
126
  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
126
#if GCC_VERSION >= 3000
920
126
  alignment = __alignof__ (struct coff_section_tdata);
921
#else
922
  alignment = 8;
923
#endif
924
126
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
925
926
126
  vars.data = ptr;
927
126
  vars.abfd = abfd;
928
126
  vars.sec_index = 0;
929
126
  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
126
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
939
126
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
940
126
  if (id4 == NULL || id5 == NULL)
941
0
    goto error_return;
942
943
  /* Fill in the contents of these sections.  */
944
126
  if (import_name_type == IMPORT_ORDINAL)
945
34
    {
946
34
      if (ordinal == 0)
947
  /* See PR 20907 for a reproducer.  */
948
10
  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
24
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
958
24
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
959
24
#endif
960
24
    }
961
92
  else
962
92
    {
963
92
      char *symbol;
964
92
      unsigned int len;
965
966
      /* Create .idata$6 - the Hint Name Table.  */
967
92
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
968
92
      if (id6 == NULL)
969
0
  goto error_return;
970
971
      /* If necessary, trim the import symbol name.  */
972
92
      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
92
      if (import_name_type != IMPORT_NAME
982
77
    && import_name_type != IMPORT_NAME_EXPORTAS)
983
67
  {
984
67
    char c = symbol[0];
985
986
    /* Check that we don't remove for targets with empty
987
       USER_LABEL_PREFIX the leading underscore.  */
988
67
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
989
55
        || c == '@' || c == '?')
990
29
      symbol++;
991
67
  }
992
993
92
      len = strlen (symbol);
994
92
      if (import_name_type == IMPORT_NAME_UNDECORATE)
995
38
  {
996
    /* Truncate at the first '@'.  */
997
38
    char *at = strchr (symbol, '@');
998
999
38
    if (at != NULL)
1000
8
      len = at - symbol;
1001
38
  }
1002
1003
92
      id6->contents[0] = ordinal & 0xff;
1004
92
      id6->contents[1] = ordinal >> 8;
1005
1006
92
      memcpy ((char *) id6->contents + 2, symbol, len);
1007
92
      id6->contents[len + 2] = '\0';
1008
92
    }
1009
1010
116
  if (import_name_type != IMPORT_ORDINAL)
1011
92
    {
1012
92
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1013
92
      pe_ILF_save_relocs (&vars, id4);
1014
1015
92
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1016
92
      pe_ILF_save_relocs (&vars, id5);
1017
92
    }
1018
1019
  /* Create an import symbol.  */
1020
116
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1021
116
  imp_sym   = vars.sym_ptr_ptr - 1;
1022
116
  imp_index = vars.sym_index - 1;
1023
1024
  /* Create extra sections depending upon the type of import we are
1025
     dealing with.  */
1026
116
  switch (import_type)
1027
116
    {
1028
0
      int i;
1029
1030
61
    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
122
      for (i = NUM_ENTRIES (jtab); i--;)
1035
122
  {
1036
122
    if (jtab[i].size == 0)
1037
61
      continue;
1038
61
    if (jtab[i].magic == magic)
1039
61
      break;
1040
61
  }
1041
      /* If we did not find a matching entry something is wrong.  */
1042
61
      if (i < 0)
1043
0
  abort ();
1044
1045
      /* Create the .text section.  */
1046
61
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1047
61
      if (text == NULL)
1048
0
  goto error_return;
1049
1050
      /* Copy in the jump code.  */
1051
61
      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
61
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1077
61
            BFD_RELOC_32, (asymbol **) imp_sym,
1078
61
            imp_index);
1079
1080
61
      pe_ILF_save_relocs (&vars, text);
1081
61
      break;
1082
1083
22
    case IMPORT_DATA:
1084
55
    case IMPORT_CONST:
1085
55
      break;
1086
1087
0
    default:
1088
      /* XXX code not yet written.  */
1089
0
      abort ();
1090
116
    }
1091
1092
  /* Now create a symbol describing the imported value.  */
1093
116
  switch (import_type)
1094
116
    {
1095
61
    case IMPORT_CODE:
1096
61
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1097
61
          BSF_NOT_AT_END | BSF_FUNCTION);
1098
1099
61
      break;
1100
1101
22
    case IMPORT_DATA:
1102
      /* Nothing to do here.  */
1103
22
      break;
1104
1105
33
    case IMPORT_CONST:
1106
33
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1107
33
      break;
1108
1109
0
    default:
1110
      /* XXX code not yet written.  */
1111
0
      abort ();
1112
116
    }
1113
1114
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1115
116
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1116
116
  if (ptr)
1117
13
    *ptr = 0;
1118
116
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1119
116
  if (ptr)
1120
13
    *ptr = '.';
1121
1122
  /* Initialise the bfd.  */
1123
116
  memset (&internal_f, 0, sizeof (internal_f));
1124
1125
116
  internal_f.f_magic  = magic;
1126
116
  internal_f.f_symptr = 0;
1127
116
  internal_f.f_nsyms  = 0;
1128
116
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1129
1130
116
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1131
116
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1132
0
    goto error_return;
1133
1134
116
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1135
0
    goto error_return;
1136
1137
116
  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
116
  bfd_cache_close (abfd);
1147
1148
116
  abfd->iostream = (void *) vars.bim;
1149
116
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1150
116
  abfd->iovec = &_bfd_memory_iovec;
1151
116
  abfd->where = 0;
1152
116
  abfd->origin = 0;
1153
116
  abfd->size = 0;
1154
116
  obj_sym_filepos (abfd) = 0;
1155
1156
  /* Point the bfd at the symbol table.  */
1157
116
  obj_symbols (abfd) = vars.sym_cache;
1158
116
  abfd->symcount = vars.sym_index;
1159
1160
116
  obj_raw_syments (abfd) = vars.native_syms;
1161
116
  obj_raw_syment_count (abfd) = vars.sym_index;
1162
116
  obj_coff_keep_raw_syms (abfd) = true;
1163
1164
116
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1165
116
  obj_coff_keep_syms (abfd) = true;
1166
1167
116
  obj_convert (abfd) = vars.sym_table;
1168
116
  obj_conv_table_size (abfd) = vars.sym_index;
1169
1170
116
  obj_coff_strings (abfd) = vars.string_table;
1171
116
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1172
116
  obj_coff_keep_strings (abfd) = true;
1173
1174
116
  return true;
1175
1176
10
 error_return:
1177
10
  free (vars.bim->buffer);
1178
10
  free (vars.bim);
1179
  return false;
1180
116
}
pei-x86_64.c:pe_ILF_build_a_bfd
Line
Count
Source
804
178
{
805
178
  bfd_byte *       ptr;
806
178
  pe_ILF_vars      vars;
807
178
  struct internal_filehdr  internal_f;
808
178
  unsigned int       import_type;
809
178
  unsigned int       import_name_type;
810
178
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
811
178
  coff_symbol_type **    imp_sym;
812
178
  unsigned int       imp_index;
813
178
  intptr_t alignment;
814
815
  /* Decode and verify the types field of the ILF structure.  */
816
178
  import_type = types & 0x3;
817
178
  import_name_type = (types & 0x1c) >> 2;
818
819
178
  switch (import_type)
820
178
    {
821
68
    case IMPORT_CODE:
822
115
    case IMPORT_DATA:
823
169
    case IMPORT_CONST:
824
169
      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
178
    }
832
833
169
  switch (import_name_type)
834
169
    {
835
42
    case IMPORT_ORDINAL:
836
63
    case IMPORT_NAME:
837
87
    case IMPORT_NAME_NOPREFIX:
838
128
    case IMPORT_NAME_UNDECORATE:
839
128
      import_name = symbol_name;
840
128
      break;
841
842
30
    case IMPORT_NAME_EXPORTAS:
843
30
      if (!import_name || !import_name[0])
844
17
  {
845
17
    _bfd_error_handler (_("%pB: missing import name for "
846
17
        "IMPORT_NAME_EXPORTAS for %s"),
847
17
            abfd, symbol_name);
848
17
    return false;
849
17
  }
850
13
      break;
851
852
13
    default:
853
      /* xgettext:c-format */
854
11
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
855
11
        abfd, import_name_type);
856
11
      return false;
857
169
    }
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
141
  vars.bim
867
141
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
868
141
  if (vars.bim == NULL)
869
0
    return false;
870
871
141
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
872
141
  vars.bim->buffer = ptr;
873
141
  vars.bim->size   = ILF_DATA_SIZE;
874
141
  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
141
  vars.sym_cache = (coff_symbol_type *) ptr;
880
141
  vars.sym_ptr   = (coff_symbol_type *) ptr;
881
141
  vars.sym_index = 0;
882
141
  ptr += SIZEOF_ILF_SYMS;
883
884
141
  vars.sym_table = (unsigned int *) ptr;
885
141
  vars.table_ptr = (unsigned int *) ptr;
886
141
  ptr += SIZEOF_ILF_SYM_TABLE;
887
888
141
  vars.native_syms = (combined_entry_type *) ptr;
889
141
  vars.native_ptr  = (combined_entry_type *) ptr;
890
141
  ptr += SIZEOF_ILF_NATIVE_SYMS;
891
892
141
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
893
141
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
894
141
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
895
896
141
  vars.esym_table = (SYMENT *) ptr;
897
141
  vars.esym_ptr   = (SYMENT *) ptr;
898
141
  ptr += SIZEOF_ILF_EXT_SYMS;
899
900
141
  vars.reltab   = (arelent *) ptr;
901
141
  vars.relcount = 0;
902
141
  ptr += SIZEOF_ILF_RELOCS;
903
904
141
  vars.int_reltab  = (struct internal_reloc *) ptr;
905
141
  ptr += SIZEOF_ILF_INT_RELOCS;
906
907
141
  vars.string_table = (char *) ptr;
908
141
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
909
141
  ptr += SIZEOF_ILF_STRINGS;
910
141
  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
141
#if GCC_VERSION >= 3000
920
141
  alignment = __alignof__ (struct coff_section_tdata);
921
#else
922
  alignment = 8;
923
#endif
924
141
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
925
926
141
  vars.data = ptr;
927
141
  vars.abfd = abfd;
928
141
  vars.sec_index = 0;
929
141
  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
141
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
939
141
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
940
141
  if (id4 == NULL || id5 == NULL)
941
0
    goto error_return;
942
943
  /* Fill in the contents of these sections.  */
944
141
  if (import_name_type == IMPORT_ORDINAL)
945
42
    {
946
42
      if (ordinal == 0)
947
  /* See PR 20907 for a reproducer.  */
948
8
  goto error_return;
949
950
34
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
951
34
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
952
34
      ((unsigned int *) id4->contents)[0] = ordinal;
953
34
      ((unsigned int *) id4->contents)[1] = 0x80000000;
954
34
      ((unsigned int *) id5->contents)[0] = ordinal;
955
34
      ((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
34
    }
961
99
  else
962
99
    {
963
99
      char *symbol;
964
99
      unsigned int len;
965
966
      /* Create .idata$6 - the Hint Name Table.  */
967
99
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
968
99
      if (id6 == NULL)
969
0
  goto error_return;
970
971
      /* If necessary, trim the import symbol name.  */
972
99
      symbol = import_name;
973
974
      /* As used by MS compiler, '_', '@', and '?' are alternative
975
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
976
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
977
   of these is used for a symbol.  We strip this leading char for
978
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
979
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
980
981
99
      if (import_name_type != IMPORT_NAME
982
78
    && import_name_type != IMPORT_NAME_EXPORTAS)
983
65
  {
984
65
    char c = symbol[0];
985
986
    /* Check that we don't remove for targets with empty
987
       USER_LABEL_PREFIX the leading underscore.  */
988
65
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
989
65
        || c == '@' || c == '?')
990
18
      symbol++;
991
65
  }
992
993
99
      len = strlen (symbol);
994
99
      if (import_name_type == IMPORT_NAME_UNDECORATE)
995
41
  {
996
    /* Truncate at the first '@'.  */
997
41
    char *at = strchr (symbol, '@');
998
999
41
    if (at != NULL)
1000
15
      len = at - symbol;
1001
41
  }
1002
1003
99
      id6->contents[0] = ordinal & 0xff;
1004
99
      id6->contents[1] = ordinal >> 8;
1005
1006
99
      memcpy ((char *) id6->contents + 2, symbol, len);
1007
99
      id6->contents[len + 2] = '\0';
1008
99
    }
1009
1010
133
  if (import_name_type != IMPORT_ORDINAL)
1011
99
    {
1012
99
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1013
99
      pe_ILF_save_relocs (&vars, id4);
1014
1015
99
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1016
99
      pe_ILF_save_relocs (&vars, id5);
1017
99
    }
1018
1019
  /* Create an import symbol.  */
1020
133
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1021
133
  imp_sym   = vars.sym_ptr_ptr - 1;
1022
133
  imp_index = vars.sym_index - 1;
1023
1024
  /* Create extra sections depending upon the type of import we are
1025
     dealing with.  */
1026
133
  switch (import_type)
1027
133
    {
1028
0
      int i;
1029
1030
56
    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
112
      for (i = NUM_ENTRIES (jtab); i--;)
1035
112
  {
1036
112
    if (jtab[i].size == 0)
1037
56
      continue;
1038
56
    if (jtab[i].magic == magic)
1039
56
      break;
1040
56
  }
1041
      /* If we did not find a matching entry something is wrong.  */
1042
56
      if (i < 0)
1043
0
  abort ();
1044
1045
      /* Create the .text section.  */
1046
56
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1047
56
      if (text == NULL)
1048
0
  goto error_return;
1049
1050
      /* Copy in the jump code.  */
1051
56
      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
56
#ifdef AMD64MAGIC
1068
56
      if (magic == AMD64MAGIC)
1069
56
  {
1070
56
    pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1071
56
              BFD_RELOC_32_PCREL, (asymbol **) imp_sym,
1072
56
              imp_index);
1073
56
  }
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
56
      pe_ILF_save_relocs (&vars, text);
1081
56
      break;
1082
1083
38
    case IMPORT_DATA:
1084
77
    case IMPORT_CONST:
1085
77
      break;
1086
1087
0
    default:
1088
      /* XXX code not yet written.  */
1089
0
      abort ();
1090
133
    }
1091
1092
  /* Now create a symbol describing the imported value.  */
1093
133
  switch (import_type)
1094
133
    {
1095
56
    case IMPORT_CODE:
1096
56
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1097
56
          BSF_NOT_AT_END | BSF_FUNCTION);
1098
1099
56
      break;
1100
1101
38
    case IMPORT_DATA:
1102
      /* Nothing to do here.  */
1103
38
      break;
1104
1105
39
    case IMPORT_CONST:
1106
39
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1107
39
      break;
1108
1109
0
    default:
1110
      /* XXX code not yet written.  */
1111
0
      abort ();
1112
133
    }
1113
1114
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1115
133
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1116
133
  if (ptr)
1117
13
    *ptr = 0;
1118
133
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1119
133
  if (ptr)
1120
13
    *ptr = '.';
1121
1122
  /* Initialise the bfd.  */
1123
133
  memset (&internal_f, 0, sizeof (internal_f));
1124
1125
133
  internal_f.f_magic  = magic;
1126
133
  internal_f.f_symptr = 0;
1127
133
  internal_f.f_nsyms  = 0;
1128
133
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1129
1130
133
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1131
133
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1132
0
    goto error_return;
1133
1134
133
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1135
0
    goto error_return;
1136
1137
133
  obj_pe (abfd) = true;
1138
#ifdef THUMBPEMAGIC
1139
  if (vars.magic == THUMBPEMAGIC)
1140
    /* Stop some linker warnings about thumb code not supporting
1141
       interworking.  */
1142
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1143
#endif
1144
1145
  /* Switch from file contents to memory contents.  */
1146
133
  bfd_cache_close (abfd);
1147
1148
133
  abfd->iostream = (void *) vars.bim;
1149
133
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1150
133
  abfd->iovec = &_bfd_memory_iovec;
1151
133
  abfd->where = 0;
1152
133
  abfd->origin = 0;
1153
133
  abfd->size = 0;
1154
133
  obj_sym_filepos (abfd) = 0;
1155
1156
  /* Point the bfd at the symbol table.  */
1157
133
  obj_symbols (abfd) = vars.sym_cache;
1158
133
  abfd->symcount = vars.sym_index;
1159
1160
133
  obj_raw_syments (abfd) = vars.native_syms;
1161
133
  obj_raw_syment_count (abfd) = vars.sym_index;
1162
133
  obj_coff_keep_raw_syms (abfd) = true;
1163
1164
133
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1165
133
  obj_coff_keep_syms (abfd) = true;
1166
1167
133
  obj_convert (abfd) = vars.sym_table;
1168
133
  obj_conv_table_size (abfd) = vars.sym_index;
1169
1170
133
  obj_coff_strings (abfd) = vars.string_table;
1171
133
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1172
133
  obj_coff_keep_strings (abfd) = true;
1173
1174
133
  return true;
1175
1176
8
 error_return:
1177
8
  free (vars.bim->buffer);
1178
8
  free (vars.bim);
1179
  return false;
1180
133
}
pei-aarch64.c:pe_ILF_build_a_bfd
Line
Count
Source
804
160
{
805
160
  bfd_byte *       ptr;
806
160
  pe_ILF_vars      vars;
807
160
  struct internal_filehdr  internal_f;
808
160
  unsigned int       import_type;
809
160
  unsigned int       import_name_type;
810
160
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
811
160
  coff_symbol_type **    imp_sym;
812
160
  unsigned int       imp_index;
813
160
  intptr_t alignment;
814
815
  /* Decode and verify the types field of the ILF structure.  */
816
160
  import_type = types & 0x3;
817
160
  import_name_type = (types & 0x1c) >> 2;
818
819
160
  switch (import_type)
820
160
    {
821
68
    case IMPORT_CODE:
822
122
    case IMPORT_DATA:
823
151
    case IMPORT_CONST:
824
151
      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
160
    }
832
833
151
  switch (import_name_type)
834
151
    {
835
39
    case IMPORT_ORDINAL:
836
58
    case IMPORT_NAME:
837
78
    case IMPORT_NAME_NOPREFIX:
838
113
    case IMPORT_NAME_UNDECORATE:
839
113
      import_name = symbol_name;
840
113
      break;
841
842
31
    case IMPORT_NAME_EXPORTAS:
843
31
      if (!import_name || !import_name[0])
844
16
  {
845
16
    _bfd_error_handler (_("%pB: missing import name for "
846
16
        "IMPORT_NAME_EXPORTAS for %s"),
847
16
            abfd, symbol_name);
848
16
    return false;
849
16
  }
850
15
      break;
851
852
15
    default:
853
      /* xgettext:c-format */
854
7
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
855
7
        abfd, import_name_type);
856
7
      return false;
857
151
    }
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
128
  vars.bim
867
128
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
868
128
  if (vars.bim == NULL)
869
0
    return false;
870
871
128
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
872
128
  vars.bim->buffer = ptr;
873
128
  vars.bim->size   = ILF_DATA_SIZE;
874
128
  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
128
  vars.sym_cache = (coff_symbol_type *) ptr;
880
128
  vars.sym_ptr   = (coff_symbol_type *) ptr;
881
128
  vars.sym_index = 0;
882
128
  ptr += SIZEOF_ILF_SYMS;
883
884
128
  vars.sym_table = (unsigned int *) ptr;
885
128
  vars.table_ptr = (unsigned int *) ptr;
886
128
  ptr += SIZEOF_ILF_SYM_TABLE;
887
888
128
  vars.native_syms = (combined_entry_type *) ptr;
889
128
  vars.native_ptr  = (combined_entry_type *) ptr;
890
128
  ptr += SIZEOF_ILF_NATIVE_SYMS;
891
892
128
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
893
128
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
894
128
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
895
896
128
  vars.esym_table = (SYMENT *) ptr;
897
128
  vars.esym_ptr   = (SYMENT *) ptr;
898
128
  ptr += SIZEOF_ILF_EXT_SYMS;
899
900
128
  vars.reltab   = (arelent *) ptr;
901
128
  vars.relcount = 0;
902
128
  ptr += SIZEOF_ILF_RELOCS;
903
904
128
  vars.int_reltab  = (struct internal_reloc *) ptr;
905
128
  ptr += SIZEOF_ILF_INT_RELOCS;
906
907
128
  vars.string_table = (char *) ptr;
908
128
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
909
128
  ptr += SIZEOF_ILF_STRINGS;
910
128
  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
128
#if GCC_VERSION >= 3000
920
128
  alignment = __alignof__ (struct coff_section_tdata);
921
#else
922
  alignment = 8;
923
#endif
924
128
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
925
926
128
  vars.data = ptr;
927
128
  vars.abfd = abfd;
928
128
  vars.sec_index = 0;
929
128
  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
128
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
939
128
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
940
128
  if (id4 == NULL || id5 == NULL)
941
0
    goto error_return;
942
943
  /* Fill in the contents of these sections.  */
944
128
  if (import_name_type == IMPORT_ORDINAL)
945
39
    {
946
39
      if (ordinal == 0)
947
  /* See PR 20907 for a reproducer.  */
948
9
  goto error_return;
949
950
30
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
951
30
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
952
30
      ((unsigned int *) id4->contents)[0] = ordinal;
953
30
      ((unsigned int *) id4->contents)[1] = 0x80000000;
954
30
      ((unsigned int *) id5->contents)[0] = ordinal;
955
30
      ((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
30
    }
961
89
  else
962
89
    {
963
89
      char *symbol;
964
89
      unsigned int len;
965
966
      /* Create .idata$6 - the Hint Name Table.  */
967
89
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
968
89
      if (id6 == NULL)
969
0
  goto error_return;
970
971
      /* If necessary, trim the import symbol name.  */
972
89
      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
89
      if (import_name_type != IMPORT_NAME
982
70
    && import_name_type != IMPORT_NAME_EXPORTAS)
983
55
  {
984
55
    char c = symbol[0];
985
986
    /* Check that we don't remove for targets with empty
987
       USER_LABEL_PREFIX the leading underscore.  */
988
55
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
989
55
        || c == '@' || c == '?')
990
15
      symbol++;
991
55
  }
992
993
89
      len = strlen (symbol);
994
89
      if (import_name_type == IMPORT_NAME_UNDECORATE)
995
35
  {
996
    /* Truncate at the first '@'.  */
997
35
    char *at = strchr (symbol, '@');
998
999
35
    if (at != NULL)
1000
5
      len = at - symbol;
1001
35
  }
1002
1003
89
      id6->contents[0] = ordinal & 0xff;
1004
89
      id6->contents[1] = ordinal >> 8;
1005
1006
89
      memcpy ((char *) id6->contents + 2, symbol, len);
1007
89
      id6->contents[len + 2] = '\0';
1008
89
    }
1009
1010
119
  if (import_name_type != IMPORT_ORDINAL)
1011
89
    {
1012
89
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1013
89
      pe_ILF_save_relocs (&vars, id4);
1014
1015
89
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1016
89
      pe_ILF_save_relocs (&vars, id5);
1017
89
    }
1018
1019
  /* Create an import symbol.  */
1020
119
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1021
119
  imp_sym   = vars.sym_ptr_ptr - 1;
1022
119
  imp_index = vars.sym_index - 1;
1023
1024
  /* Create extra sections depending upon the type of import we are
1025
     dealing with.  */
1026
119
  switch (import_type)
1027
119
    {
1028
0
      int i;
1029
1030
56
    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
112
      for (i = NUM_ENTRIES (jtab); i--;)
1035
112
  {
1036
112
    if (jtab[i].size == 0)
1037
56
      continue;
1038
56
    if (jtab[i].magic == magic)
1039
56
      break;
1040
56
  }
1041
      /* If we did not find a matching entry something is wrong.  */
1042
56
      if (i < 0)
1043
0
  abort ();
1044
1045
      /* Create the .text section.  */
1046
56
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1047
56
      if (text == NULL)
1048
0
  goto error_return;
1049
1050
      /* Copy in the jump code.  */
1051
56
      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
56
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1077
56
            BFD_RELOC_32, (asymbol **) imp_sym,
1078
56
            imp_index);
1079
1080
56
      pe_ILF_save_relocs (&vars, text);
1081
56
      break;
1082
1083
42
    case IMPORT_DATA:
1084
63
    case IMPORT_CONST:
1085
63
      break;
1086
1087
0
    default:
1088
      /* XXX code not yet written.  */
1089
0
      abort ();
1090
119
    }
1091
1092
  /* Now create a symbol describing the imported value.  */
1093
119
  switch (import_type)
1094
119
    {
1095
56
    case IMPORT_CODE:
1096
56
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1097
56
          BSF_NOT_AT_END | BSF_FUNCTION);
1098
1099
56
      break;
1100
1101
42
    case IMPORT_DATA:
1102
      /* Nothing to do here.  */
1103
42
      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
119
    }
1113
1114
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1115
119
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1116
119
  if (ptr)
1117
17
    *ptr = 0;
1118
119
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1119
119
  if (ptr)
1120
17
    *ptr = '.';
1121
1122
  /* Initialise the bfd.  */
1123
119
  memset (&internal_f, 0, sizeof (internal_f));
1124
1125
119
  internal_f.f_magic  = magic;
1126
119
  internal_f.f_symptr = 0;
1127
119
  internal_f.f_nsyms  = 0;
1128
119
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1129
1130
119
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1131
119
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1132
0
    goto error_return;
1133
1134
119
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1135
0
    goto error_return;
1136
1137
119
  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
119
  bfd_cache_close (abfd);
1147
1148
119
  abfd->iostream = (void *) vars.bim;
1149
119
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1150
119
  abfd->iovec = &_bfd_memory_iovec;
1151
119
  abfd->where = 0;
1152
119
  abfd->origin = 0;
1153
119
  abfd->size = 0;
1154
119
  obj_sym_filepos (abfd) = 0;
1155
1156
  /* Point the bfd at the symbol table.  */
1157
119
  obj_symbols (abfd) = vars.sym_cache;
1158
119
  abfd->symcount = vars.sym_index;
1159
1160
119
  obj_raw_syments (abfd) = vars.native_syms;
1161
119
  obj_raw_syment_count (abfd) = vars.sym_index;
1162
119
  obj_coff_keep_raw_syms (abfd) = true;
1163
1164
119
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1165
119
  obj_coff_keep_syms (abfd) = true;
1166
1167
119
  obj_convert (abfd) = vars.sym_table;
1168
119
  obj_conv_table_size (abfd) = vars.sym_index;
1169
1170
119
  obj_coff_strings (abfd) = vars.string_table;
1171
119
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1172
119
  obj_coff_keep_strings (abfd) = true;
1173
1174
119
  return true;
1175
1176
9
 error_return:
1177
9
  free (vars.bim->buffer);
1178
9
  free (vars.bim);
1179
  return false;
1180
119
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_build_a_bfd
pei-loongarch64.c:pe_ILF_build_a_bfd
Line
Count
Source
804
181
{
805
181
  bfd_byte *       ptr;
806
181
  pe_ILF_vars      vars;
807
181
  struct internal_filehdr  internal_f;
808
181
  unsigned int       import_type;
809
181
  unsigned int       import_name_type;
810
181
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
811
181
  coff_symbol_type **    imp_sym;
812
181
  unsigned int       imp_index;
813
181
  intptr_t alignment;
814
815
  /* Decode and verify the types field of the ILF structure.  */
816
181
  import_type = types & 0x3;
817
181
  import_name_type = (types & 0x1c) >> 2;
818
819
181
  switch (import_type)
820
181
    {
821
81
    case IMPORT_CODE:
822
146
    case IMPORT_DATA:
823
172
    case IMPORT_CONST:
824
172
      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
181
    }
832
833
172
  switch (import_name_type)
834
172
    {
835
48
    case IMPORT_ORDINAL:
836
63
    case IMPORT_NAME:
837
84
    case IMPORT_NAME_NOPREFIX:
838
131
    case IMPORT_NAME_UNDECORATE:
839
131
      import_name = symbol_name;
840
131
      break;
841
842
32
    case IMPORT_NAME_EXPORTAS:
843
32
      if (!import_name || !import_name[0])
844
17
  {
845
17
    _bfd_error_handler (_("%pB: missing import name for "
846
17
        "IMPORT_NAME_EXPORTAS for %s"),
847
17
            abfd, symbol_name);
848
17
    return false;
849
17
  }
850
15
      break;
851
852
15
    default:
853
      /* xgettext:c-format */
854
9
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
855
9
        abfd, import_name_type);
856
9
      return false;
857
172
    }
858
859
  /* Initialise local variables.
860
861
     Note these are kept in a structure rather than being
862
     declared as statics since bfd frowns on global variables.
863
864
     We are going to construct the contents of the BFD in memory,
865
     so allocate all the space that we will need right now.  */
866
146
  vars.bim
867
146
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
868
146
  if (vars.bim == NULL)
869
0
    return false;
870
871
146
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
872
146
  vars.bim->buffer = ptr;
873
146
  vars.bim->size   = ILF_DATA_SIZE;
874
146
  if (ptr == NULL)
875
0
    goto error_return;
876
877
  /* Initialise the pointers to regions of the memory and the
878
     other contents of the pe_ILF_vars structure as well.  */
879
146
  vars.sym_cache = (coff_symbol_type *) ptr;
880
146
  vars.sym_ptr   = (coff_symbol_type *) ptr;
881
146
  vars.sym_index = 0;
882
146
  ptr += SIZEOF_ILF_SYMS;
883
884
146
  vars.sym_table = (unsigned int *) ptr;
885
146
  vars.table_ptr = (unsigned int *) ptr;
886
146
  ptr += SIZEOF_ILF_SYM_TABLE;
887
888
146
  vars.native_syms = (combined_entry_type *) ptr;
889
146
  vars.native_ptr  = (combined_entry_type *) ptr;
890
146
  ptr += SIZEOF_ILF_NATIVE_SYMS;
891
892
146
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
893
146
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
894
146
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
895
896
146
  vars.esym_table = (SYMENT *) ptr;
897
146
  vars.esym_ptr   = (SYMENT *) ptr;
898
146
  ptr += SIZEOF_ILF_EXT_SYMS;
899
900
146
  vars.reltab   = (arelent *) ptr;
901
146
  vars.relcount = 0;
902
146
  ptr += SIZEOF_ILF_RELOCS;
903
904
146
  vars.int_reltab  = (struct internal_reloc *) ptr;
905
146
  ptr += SIZEOF_ILF_INT_RELOCS;
906
907
146
  vars.string_table = (char *) ptr;
908
146
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
909
146
  ptr += SIZEOF_ILF_STRINGS;
910
146
  vars.end_string_ptr = (char *) ptr;
911
912
  /* The remaining space in bim->buffer is used
913
     by the pe_ILF_make_a_section() function.  */
914
915
  /* PR 18758: Make sure that the data area is sufficiently aligned for
916
     struct coff_section_tdata.  __alignof__ is a gcc extension, hence
917
     the test of GCC_VERSION.  For other compilers we assume 8 byte
918
     alignment.  */
919
146
#if GCC_VERSION >= 3000
920
146
  alignment = __alignof__ (struct coff_section_tdata);
921
#else
922
  alignment = 8;
923
#endif
924
146
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
925
926
146
  vars.data = ptr;
927
146
  vars.abfd = abfd;
928
146
  vars.sec_index = 0;
929
146
  vars.magic = magic;
930
931
  /* Create the initial .idata$<n> sections:
932
     [.idata$2:  Import Directory Table -- not needed]
933
     .idata$4:  Import Lookup Table
934
     .idata$5:  Import Address Table
935
936
     Note we do not create a .idata$3 section as this is
937
     created for us by the linker script.  */
938
146
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
939
146
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
940
146
  if (id4 == NULL || id5 == NULL)
941
0
    goto error_return;
942
943
  /* Fill in the contents of these sections.  */
944
146
  if (import_name_type == IMPORT_ORDINAL)
945
48
    {
946
48
      if (ordinal == 0)
947
  /* See PR 20907 for a reproducer.  */
948
9
  goto error_return;
949
950
39
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
951
39
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
952
39
      ((unsigned int *) id4->contents)[0] = ordinal;
953
39
      ((unsigned int *) id4->contents)[1] = 0x80000000;
954
39
      ((unsigned int *) id5->contents)[0] = ordinal;
955
39
      ((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
39
    }
961
98
  else
962
98
    {
963
98
      char *symbol;
964
98
      unsigned int len;
965
966
      /* Create .idata$6 - the Hint Name Table.  */
967
98
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
968
98
      if (id6 == NULL)
969
0
  goto error_return;
970
971
      /* If necessary, trim the import symbol name.  */
972
98
      symbol = import_name;
973
974
      /* As used by MS compiler, '_', '@', and '?' are alternative
975
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
976
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
977
   of these is used for a symbol.  We strip this leading char for
978
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
979
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
980
981
98
      if (import_name_type != IMPORT_NAME
982
83
    && import_name_type != IMPORT_NAME_EXPORTAS)
983
68
  {
984
68
    char c = symbol[0];
985
986
    /* Check that we don't remove for targets with empty
987
       USER_LABEL_PREFIX the leading underscore.  */
988
68
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
989
68
        || c == '@' || c == '?')
990
17
      symbol++;
991
68
  }
992
993
98
      len = strlen (symbol);
994
98
      if (import_name_type == IMPORT_NAME_UNDECORATE)
995
47
  {
996
    /* Truncate at the first '@'.  */
997
47
    char *at = strchr (symbol, '@');
998
999
47
    if (at != NULL)
1000
9
      len = at - symbol;
1001
47
  }
1002
1003
98
      id6->contents[0] = ordinal & 0xff;
1004
98
      id6->contents[1] = ordinal >> 8;
1005
1006
98
      memcpy ((char *) id6->contents + 2, symbol, len);
1007
98
      id6->contents[len + 2] = '\0';
1008
98
    }
1009
1010
137
  if (import_name_type != IMPORT_ORDINAL)
1011
98
    {
1012
98
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1013
98
      pe_ILF_save_relocs (&vars, id4);
1014
1015
98
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1016
98
      pe_ILF_save_relocs (&vars, id5);
1017
98
    }
1018
1019
  /* Create an import symbol.  */
1020
137
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1021
137
  imp_sym   = vars.sym_ptr_ptr - 1;
1022
137
  imp_index = vars.sym_index - 1;
1023
1024
  /* Create extra sections depending upon the type of import we are
1025
     dealing with.  */
1026
137
  switch (import_type)
1027
137
    {
1028
0
      int i;
1029
1030
64
    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
128
      for (i = NUM_ENTRIES (jtab); i--;)
1035
128
  {
1036
128
    if (jtab[i].size == 0)
1037
64
      continue;
1038
64
    if (jtab[i].magic == magic)
1039
64
      break;
1040
64
  }
1041
      /* If we did not find a matching entry something is wrong.  */
1042
64
      if (i < 0)
1043
0
  abort ();
1044
1045
      /* Create the .text section.  */
1046
64
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1047
64
      if (text == NULL)
1048
0
  goto error_return;
1049
1050
      /* Copy in the jump code.  */
1051
64
      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
64
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1077
64
            BFD_RELOC_32, (asymbol **) imp_sym,
1078
64
            imp_index);
1079
1080
64
      pe_ILF_save_relocs (&vars, text);
1081
64
      break;
1082
1083
53
    case IMPORT_DATA:
1084
73
    case IMPORT_CONST:
1085
73
      break;
1086
1087
0
    default:
1088
      /* XXX code not yet written.  */
1089
0
      abort ();
1090
137
    }
1091
1092
  /* Now create a symbol describing the imported value.  */
1093
137
  switch (import_type)
1094
137
    {
1095
64
    case IMPORT_CODE:
1096
64
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1097
64
          BSF_NOT_AT_END | BSF_FUNCTION);
1098
1099
64
      break;
1100
1101
53
    case IMPORT_DATA:
1102
      /* Nothing to do here.  */
1103
53
      break;
1104
1105
20
    case IMPORT_CONST:
1106
20
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1107
20
      break;
1108
1109
0
    default:
1110
      /* XXX code not yet written.  */
1111
0
      abort ();
1112
137
    }
1113
1114
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1115
137
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1116
137
  if (ptr)
1117
22
    *ptr = 0;
1118
137
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1119
137
  if (ptr)
1120
22
    *ptr = '.';
1121
1122
  /* Initialise the bfd.  */
1123
137
  memset (&internal_f, 0, sizeof (internal_f));
1124
1125
137
  internal_f.f_magic  = magic;
1126
137
  internal_f.f_symptr = 0;
1127
137
  internal_f.f_nsyms  = 0;
1128
137
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1129
1130
137
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1131
137
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1132
0
    goto error_return;
1133
1134
137
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1135
0
    goto error_return;
1136
1137
137
  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
137
  bfd_cache_close (abfd);
1147
1148
137
  abfd->iostream = (void *) vars.bim;
1149
137
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1150
137
  abfd->iovec = &_bfd_memory_iovec;
1151
137
  abfd->where = 0;
1152
137
  abfd->origin = 0;
1153
137
  abfd->size = 0;
1154
137
  obj_sym_filepos (abfd) = 0;
1155
1156
  /* Point the bfd at the symbol table.  */
1157
137
  obj_symbols (abfd) = vars.sym_cache;
1158
137
  abfd->symcount = vars.sym_index;
1159
1160
137
  obj_raw_syments (abfd) = vars.native_syms;
1161
137
  obj_raw_syment_count (abfd) = vars.sym_index;
1162
137
  obj_coff_keep_raw_syms (abfd) = true;
1163
1164
137
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1165
137
  obj_coff_keep_syms (abfd) = true;
1166
1167
137
  obj_convert (abfd) = vars.sym_table;
1168
137
  obj_conv_table_size (abfd) = vars.sym_index;
1169
1170
137
  obj_coff_strings (abfd) = vars.string_table;
1171
137
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1172
137
  obj_coff_keep_strings (abfd) = true;
1173
1174
137
  return true;
1175
1176
9
 error_return:
1177
9
  free (vars.bim->buffer);
1178
9
  free (vars.bim);
1179
  return false;
1180
137
}
pei-riscv64.c:pe_ILF_build_a_bfd
Line
Count
Source
804
160
{
805
160
  bfd_byte *       ptr;
806
160
  pe_ILF_vars      vars;
807
160
  struct internal_filehdr  internal_f;
808
160
  unsigned int       import_type;
809
160
  unsigned int       import_name_type;
810
160
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
811
160
  coff_symbol_type **    imp_sym;
812
160
  unsigned int       imp_index;
813
160
  intptr_t alignment;
814
815
  /* Decode and verify the types field of the ILF structure.  */
816
160
  import_type = types & 0x3;
817
160
  import_name_type = (types & 0x1c) >> 2;
818
819
160
  switch (import_type)
820
160
    {
821
60
    case IMPORT_CODE:
822
107
    case IMPORT_DATA:
823
151
    case IMPORT_CONST:
824
151
      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
160
    }
832
833
151
  switch (import_name_type)
834
151
    {
835
33
    case IMPORT_ORDINAL:
836
47
    case IMPORT_NAME:
837
66
    case IMPORT_NAME_NOPREFIX:
838
113
    case IMPORT_NAME_UNDECORATE:
839
113
      import_name = symbol_name;
840
113
      break;
841
842
29
    case IMPORT_NAME_EXPORTAS:
843
29
      if (!import_name || !import_name[0])
844
14
  {
845
14
    _bfd_error_handler (_("%pB: missing import name for "
846
14
        "IMPORT_NAME_EXPORTAS for %s"),
847
14
            abfd, symbol_name);
848
14
    return false;
849
14
  }
850
15
      break;
851
852
15
    default:
853
      /* xgettext:c-format */
854
9
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
855
9
        abfd, import_name_type);
856
9
      return false;
857
151
    }
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
128
  vars.bim
867
128
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
868
128
  if (vars.bim == NULL)
869
0
    return false;
870
871
128
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
872
128
  vars.bim->buffer = ptr;
873
128
  vars.bim->size   = ILF_DATA_SIZE;
874
128
  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
128
  vars.sym_cache = (coff_symbol_type *) ptr;
880
128
  vars.sym_ptr   = (coff_symbol_type *) ptr;
881
128
  vars.sym_index = 0;
882
128
  ptr += SIZEOF_ILF_SYMS;
883
884
128
  vars.sym_table = (unsigned int *) ptr;
885
128
  vars.table_ptr = (unsigned int *) ptr;
886
128
  ptr += SIZEOF_ILF_SYM_TABLE;
887
888
128
  vars.native_syms = (combined_entry_type *) ptr;
889
128
  vars.native_ptr  = (combined_entry_type *) ptr;
890
128
  ptr += SIZEOF_ILF_NATIVE_SYMS;
891
892
128
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
893
128
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
894
128
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
895
896
128
  vars.esym_table = (SYMENT *) ptr;
897
128
  vars.esym_ptr   = (SYMENT *) ptr;
898
128
  ptr += SIZEOF_ILF_EXT_SYMS;
899
900
128
  vars.reltab   = (arelent *) ptr;
901
128
  vars.relcount = 0;
902
128
  ptr += SIZEOF_ILF_RELOCS;
903
904
128
  vars.int_reltab  = (struct internal_reloc *) ptr;
905
128
  ptr += SIZEOF_ILF_INT_RELOCS;
906
907
128
  vars.string_table = (char *) ptr;
908
128
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
909
128
  ptr += SIZEOF_ILF_STRINGS;
910
128
  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
128
#if GCC_VERSION >= 3000
920
128
  alignment = __alignof__ (struct coff_section_tdata);
921
#else
922
  alignment = 8;
923
#endif
924
128
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
925
926
128
  vars.data = ptr;
927
128
  vars.abfd = abfd;
928
128
  vars.sec_index = 0;
929
128
  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
128
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
939
128
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
940
128
  if (id4 == NULL || id5 == NULL)
941
0
    goto error_return;
942
943
  /* Fill in the contents of these sections.  */
944
128
  if (import_name_type == IMPORT_ORDINAL)
945
33
    {
946
33
      if (ordinal == 0)
947
  /* See PR 20907 for a reproducer.  */
948
8
  goto error_return;
949
950
25
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
951
25
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
952
25
      ((unsigned int *) id4->contents)[0] = ordinal;
953
25
      ((unsigned int *) id4->contents)[1] = 0x80000000;
954
25
      ((unsigned int *) id5->contents)[0] = ordinal;
955
25
      ((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
25
    }
961
95
  else
962
95
    {
963
95
      char *symbol;
964
95
      unsigned int len;
965
966
      /* Create .idata$6 - the Hint Name Table.  */
967
95
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
968
95
      if (id6 == NULL)
969
0
  goto error_return;
970
971
      /* If necessary, trim the import symbol name.  */
972
95
      symbol = import_name;
973
974
      /* As used by MS compiler, '_', '@', and '?' are alternative
975
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
976
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
977
   of these is used for a symbol.  We strip this leading char for
978
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
979
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
980
981
95
      if (import_name_type != IMPORT_NAME
982
81
    && import_name_type != IMPORT_NAME_EXPORTAS)
983
66
  {
984
66
    char c = symbol[0];
985
986
    /* Check that we don't remove for targets with empty
987
       USER_LABEL_PREFIX the leading underscore.  */
988
66
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
989
66
        || c == '@' || c == '?')
990
21
      symbol++;
991
66
  }
992
993
95
      len = strlen (symbol);
994
95
      if (import_name_type == IMPORT_NAME_UNDECORATE)
995
47
  {
996
    /* Truncate at the first '@'.  */
997
47
    char *at = strchr (symbol, '@');
998
999
47
    if (at != NULL)
1000
9
      len = at - symbol;
1001
47
  }
1002
1003
95
      id6->contents[0] = ordinal & 0xff;
1004
95
      id6->contents[1] = ordinal >> 8;
1005
1006
95
      memcpy ((char *) id6->contents + 2, symbol, len);
1007
95
      id6->contents[len + 2] = '\0';
1008
95
    }
1009
1010
120
  if (import_name_type != IMPORT_ORDINAL)
1011
95
    {
1012
95
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1013
95
      pe_ILF_save_relocs (&vars, id4);
1014
1015
95
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1016
95
      pe_ILF_save_relocs (&vars, id5);
1017
95
    }
1018
1019
  /* Create an import symbol.  */
1020
120
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1021
120
  imp_sym   = vars.sym_ptr_ptr - 1;
1022
120
  imp_index = vars.sym_index - 1;
1023
1024
  /* Create extra sections depending upon the type of import we are
1025
     dealing with.  */
1026
120
  switch (import_type)
1027
120
    {
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
#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
38
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1077
38
            BFD_RELOC_32, (asymbol **) imp_sym,
1078
38
            imp_index);
1079
1080
38
      pe_ILF_save_relocs (&vars, text);
1081
38
      break;
1082
1083
41
    case IMPORT_DATA:
1084
82
    case IMPORT_CONST:
1085
82
      break;
1086
1087
0
    default:
1088
      /* XXX code not yet written.  */
1089
0
      abort ();
1090
120
    }
1091
1092
  /* Now create a symbol describing the imported value.  */
1093
120
  switch (import_type)
1094
120
    {
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
41
    case IMPORT_DATA:
1102
      /* Nothing to do here.  */
1103
41
      break;
1104
1105
41
    case IMPORT_CONST:
1106
41
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1107
41
      break;
1108
1109
0
    default:
1110
      /* XXX code not yet written.  */
1111
0
      abort ();
1112
120
    }
1113
1114
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1115
120
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1116
120
  if (ptr)
1117
17
    *ptr = 0;
1118
120
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1119
120
  if (ptr)
1120
17
    *ptr = '.';
1121
1122
  /* Initialise the bfd.  */
1123
120
  memset (&internal_f, 0, sizeof (internal_f));
1124
1125
120
  internal_f.f_magic  = magic;
1126
120
  internal_f.f_symptr = 0;
1127
120
  internal_f.f_nsyms  = 0;
1128
120
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1129
1130
120
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1131
120
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1132
0
    goto error_return;
1133
1134
120
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1135
0
    goto error_return;
1136
1137
120
  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
120
  bfd_cache_close (abfd);
1147
1148
120
  abfd->iostream = (void *) vars.bim;
1149
120
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1150
120
  abfd->iovec = &_bfd_memory_iovec;
1151
120
  abfd->where = 0;
1152
120
  abfd->origin = 0;
1153
120
  abfd->size = 0;
1154
120
  obj_sym_filepos (abfd) = 0;
1155
1156
  /* Point the bfd at the symbol table.  */
1157
120
  obj_symbols (abfd) = vars.sym_cache;
1158
120
  abfd->symcount = vars.sym_index;
1159
1160
120
  obj_raw_syments (abfd) = vars.native_syms;
1161
120
  obj_raw_syment_count (abfd) = vars.sym_index;
1162
120
  obj_coff_keep_raw_syms (abfd) = true;
1163
1164
120
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1165
120
  obj_coff_keep_syms (abfd) = true;
1166
1167
120
  obj_convert (abfd) = vars.sym_table;
1168
120
  obj_conv_table_size (abfd) = vars.sym_index;
1169
1170
120
  obj_coff_strings (abfd) = vars.string_table;
1171
120
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1172
120
  obj_coff_keep_strings (abfd) = true;
1173
1174
120
  return true;
1175
1176
8
 error_return:
1177
8
  free (vars.bim->buffer);
1178
8
  free (vars.bim);
1179
  return false;
1180
120
}
pei-arm-wince.c:pe_ILF_build_a_bfd
Line
Count
Source
804
144
{
805
144
  bfd_byte *       ptr;
806
144
  pe_ILF_vars      vars;
807
144
  struct internal_filehdr  internal_f;
808
144
  unsigned int       import_type;
809
144
  unsigned int       import_name_type;
810
144
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
811
144
  coff_symbol_type **    imp_sym;
812
144
  unsigned int       imp_index;
813
144
  intptr_t alignment;
814
815
  /* Decode and verify the types field of the ILF structure.  */
816
144
  import_type = types & 0x3;
817
144
  import_name_type = (types & 0x1c) >> 2;
818
819
144
  switch (import_type)
820
144
    {
821
68
    case IMPORT_CODE:
822
110
    case IMPORT_DATA:
823
134
    case IMPORT_CONST:
824
134
      break;
825
826
10
    default:
827
      /* xgettext:c-format */
828
10
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
10
        abfd, import_type);
830
10
      return false;
831
144
    }
832
833
134
  switch (import_name_type)
834
134
    {
835
38
    case IMPORT_ORDINAL:
836
46
    case IMPORT_NAME:
837
72
    case IMPORT_NAME_NOPREFIX:
838
101
    case IMPORT_NAME_UNDECORATE:
839
101
      import_name = symbol_name;
840
101
      break;
841
842
24
    case IMPORT_NAME_EXPORTAS:
843
24
      if (!import_name || !import_name[0])
844
18
  {
845
18
    _bfd_error_handler (_("%pB: missing import name for "
846
18
        "IMPORT_NAME_EXPORTAS for %s"),
847
18
            abfd, symbol_name);
848
18
    return false;
849
18
  }
850
6
      break;
851
852
9
    default:
853
      /* xgettext:c-format */
854
9
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
855
9
        abfd, import_name_type);
856
9
      return false;
857
134
    }
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
107
  vars.bim
867
107
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
868
107
  if (vars.bim == NULL)
869
0
    return false;
870
871
107
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
872
107
  vars.bim->buffer = ptr;
873
107
  vars.bim->size   = ILF_DATA_SIZE;
874
107
  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
107
  vars.sym_cache = (coff_symbol_type *) ptr;
880
107
  vars.sym_ptr   = (coff_symbol_type *) ptr;
881
107
  vars.sym_index = 0;
882
107
  ptr += SIZEOF_ILF_SYMS;
883
884
107
  vars.sym_table = (unsigned int *) ptr;
885
107
  vars.table_ptr = (unsigned int *) ptr;
886
107
  ptr += SIZEOF_ILF_SYM_TABLE;
887
888
107
  vars.native_syms = (combined_entry_type *) ptr;
889
107
  vars.native_ptr  = (combined_entry_type *) ptr;
890
107
  ptr += SIZEOF_ILF_NATIVE_SYMS;
891
892
107
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
893
107
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
894
107
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
895
896
107
  vars.esym_table = (SYMENT *) ptr;
897
107
  vars.esym_ptr   = (SYMENT *) ptr;
898
107
  ptr += SIZEOF_ILF_EXT_SYMS;
899
900
107
  vars.reltab   = (arelent *) ptr;
901
107
  vars.relcount = 0;
902
107
  ptr += SIZEOF_ILF_RELOCS;
903
904
107
  vars.int_reltab  = (struct internal_reloc *) ptr;
905
107
  ptr += SIZEOF_ILF_INT_RELOCS;
906
907
107
  vars.string_table = (char *) ptr;
908
107
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
909
107
  ptr += SIZEOF_ILF_STRINGS;
910
107
  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
107
#if GCC_VERSION >= 3000
920
107
  alignment = __alignof__ (struct coff_section_tdata);
921
#else
922
  alignment = 8;
923
#endif
924
107
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
925
926
107
  vars.data = ptr;
927
107
  vars.abfd = abfd;
928
107
  vars.sec_index = 0;
929
107
  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
107
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
939
107
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
940
107
  if (id4 == NULL || id5 == NULL)
941
0
    goto error_return;
942
943
  /* Fill in the contents of these sections.  */
944
107
  if (import_name_type == IMPORT_ORDINAL)
945
38
    {
946
38
      if (ordinal == 0)
947
  /* See PR 20907 for a reproducer.  */
948
11
  goto error_return;
949
950
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
951
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
952
      ((unsigned int *) id4->contents)[0] = ordinal;
953
      ((unsigned int *) id4->contents)[1] = 0x80000000;
954
      ((unsigned int *) id5->contents)[0] = ordinal;
955
      ((unsigned int *) id5->contents)[1] = 0x80000000;
956
#else
957
27
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
958
27
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
959
27
#endif
960
27
    }
961
69
  else
962
69
    {
963
69
      char *symbol;
964
69
      unsigned int len;
965
966
      /* Create .idata$6 - the Hint Name Table.  */
967
69
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
968
69
      if (id6 == NULL)
969
0
  goto error_return;
970
971
      /* If necessary, trim the import symbol name.  */
972
69
      symbol = import_name;
973
974
      /* As used by MS compiler, '_', '@', and '?' are alternative
975
   forms of USER_LABEL_PREFIX, with '?' for c++ mangled names,
976
   '@' used for fastcall (in C),  '_' everywhere else.  Only one
977
   of these is used for a symbol.  We strip this leading char for
978
   IMPORT_NAME_NOPREFIX and IMPORT_NAME_UNDECORATE as per the
979
   PE COFF 6.0 spec (section 8.3, Import Name Type).  */
980
981
69
      if (import_name_type != IMPORT_NAME
982
61
    && import_name_type != IMPORT_NAME_EXPORTAS)
983
55
  {
984
55
    char c = symbol[0];
985
986
    /* Check that we don't remove for targets with empty
987
       USER_LABEL_PREFIX the leading underscore.  */
988
55
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
989
55
        || c == '@' || c == '?')
990
10
      symbol++;
991
55
  }
992
993
69
      len = strlen (symbol);
994
69
      if (import_name_type == IMPORT_NAME_UNDECORATE)
995
29
  {
996
    /* Truncate at the first '@'.  */
997
29
    char *at = strchr (symbol, '@');
998
999
29
    if (at != NULL)
1000
5
      len = at - symbol;
1001
29
  }
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
96
  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
96
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1021
96
  imp_sym   = vars.sym_ptr_ptr - 1;
1022
96
  imp_index = vars.sym_index - 1;
1023
1024
  /* Create extra sections depending upon the type of import we are
1025
     dealing with.  */
1026
96
  switch (import_type)
1027
96
    {
1028
0
      int i;
1029
1030
52
    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
131
      for (i = NUM_ENTRIES (jtab); i--;)
1035
131
  {
1036
131
    if (jtab[i].size == 0)
1037
52
      continue;
1038
79
    if (jtab[i].magic == magic)
1039
52
      break;
1040
79
  }
1041
      /* If we did not find a matching entry something is wrong.  */
1042
52
      if (i < 0)
1043
0
  abort ();
1044
1045
      /* Create the .text section.  */
1046
52
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1047
52
      if (text == NULL)
1048
0
  goto error_return;
1049
1050
      /* Copy in the jump code.  */
1051
52
      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
52
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1077
52
            BFD_RELOC_32, (asymbol **) imp_sym,
1078
52
            imp_index);
1079
1080
52
      pe_ILF_save_relocs (&vars, text);
1081
52
      break;
1082
1083
25
    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
96
    }
1091
1092
  /* Now create a symbol describing the imported value.  */
1093
96
  switch (import_type)
1094
96
    {
1095
52
    case IMPORT_CODE:
1096
52
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1097
52
          BSF_NOT_AT_END | BSF_FUNCTION);
1098
1099
52
      break;
1100
1101
25
    case IMPORT_DATA:
1102
      /* Nothing to do here.  */
1103
25
      break;
1104
1105
19
    case IMPORT_CONST:
1106
19
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1107
19
      break;
1108
1109
0
    default:
1110
      /* XXX code not yet written.  */
1111
0
      abort ();
1112
96
    }
1113
1114
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1115
96
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1116
96
  if (ptr)
1117
8
    *ptr = 0;
1118
96
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1119
96
  if (ptr)
1120
8
    *ptr = '.';
1121
1122
  /* Initialise the bfd.  */
1123
96
  memset (&internal_f, 0, sizeof (internal_f));
1124
1125
96
  internal_f.f_magic  = magic;
1126
96
  internal_f.f_symptr = 0;
1127
96
  internal_f.f_nsyms  = 0;
1128
96
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1129
1130
96
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1131
96
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1132
0
    goto error_return;
1133
1134
96
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1135
0
    goto error_return;
1136
1137
96
  obj_pe (abfd) = true;
1138
96
#ifdef THUMBPEMAGIC
1139
96
  if (vars.magic == THUMBPEMAGIC)
1140
    /* Stop some linker warnings about thumb code not supporting
1141
       interworking.  */
1142
49
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1143
96
#endif
1144
1145
  /* Switch from file contents to memory contents.  */
1146
96
  bfd_cache_close (abfd);
1147
1148
96
  abfd->iostream = (void *) vars.bim;
1149
96
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1150
96
  abfd->iovec = &_bfd_memory_iovec;
1151
96
  abfd->where = 0;
1152
96
  abfd->origin = 0;
1153
96
  abfd->size = 0;
1154
96
  obj_sym_filepos (abfd) = 0;
1155
1156
  /* Point the bfd at the symbol table.  */
1157
96
  obj_symbols (abfd) = vars.sym_cache;
1158
96
  abfd->symcount = vars.sym_index;
1159
1160
96
  obj_raw_syments (abfd) = vars.native_syms;
1161
96
  obj_raw_syment_count (abfd) = vars.sym_index;
1162
96
  obj_coff_keep_raw_syms (abfd) = true;
1163
1164
96
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1165
96
  obj_coff_keep_syms (abfd) = true;
1166
1167
96
  obj_convert (abfd) = vars.sym_table;
1168
96
  obj_conv_table_size (abfd) = vars.sym_index;
1169
1170
96
  obj_coff_strings (abfd) = vars.string_table;
1171
96
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1172
96
  obj_coff_keep_strings (abfd) = true;
1173
1174
96
  return true;
1175
1176
11
 error_return:
1177
11
  free (vars.bim->buffer);
1178
11
  free (vars.bim);
1179
  return false;
1180
96
}
pei-arm.c:pe_ILF_build_a_bfd
Line
Count
Source
804
146
{
805
146
  bfd_byte *       ptr;
806
146
  pe_ILF_vars      vars;
807
146
  struct internal_filehdr  internal_f;
808
146
  unsigned int       import_type;
809
146
  unsigned int       import_name_type;
810
146
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
811
146
  coff_symbol_type **    imp_sym;
812
146
  unsigned int       imp_index;
813
146
  intptr_t alignment;
814
815
  /* Decode and verify the types field of the ILF structure.  */
816
146
  import_type = types & 0x3;
817
146
  import_name_type = (types & 0x1c) >> 2;
818
819
146
  switch (import_type)
820
146
    {
821
69
    case IMPORT_CODE:
822
111
    case IMPORT_DATA:
823
136
    case IMPORT_CONST:
824
136
      break;
825
826
10
    default:
827
      /* xgettext:c-format */
828
10
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
10
        abfd, import_type);
830
10
      return false;
831
146
    }
832
833
136
  switch (import_name_type)
834
136
    {
835
39
    case IMPORT_ORDINAL:
836
47
    case IMPORT_NAME:
837
74
    case IMPORT_NAME_NOPREFIX:
838
103
    case IMPORT_NAME_UNDECORATE:
839
103
      import_name = symbol_name;
840
103
      break;
841
842
24
    case IMPORT_NAME_EXPORTAS:
843
24
      if (!import_name || !import_name[0])
844
18
  {
845
18
    _bfd_error_handler (_("%pB: missing import name for "
846
18
        "IMPORT_NAME_EXPORTAS for %s"),
847
18
            abfd, symbol_name);
848
18
    return false;
849
18
  }
850
6
      break;
851
852
9
    default:
853
      /* xgettext:c-format */
854
9
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
855
9
        abfd, import_name_type);
856
9
      return false;
857
136
    }
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
109
  vars.bim
867
109
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
868
109
  if (vars.bim == NULL)
869
0
    return false;
870
871
109
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
872
109
  vars.bim->buffer = ptr;
873
109
  vars.bim->size   = ILF_DATA_SIZE;
874
109
  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
109
  vars.sym_cache = (coff_symbol_type *) ptr;
880
109
  vars.sym_ptr   = (coff_symbol_type *) ptr;
881
109
  vars.sym_index = 0;
882
109
  ptr += SIZEOF_ILF_SYMS;
883
884
109
  vars.sym_table = (unsigned int *) ptr;
885
109
  vars.table_ptr = (unsigned int *) ptr;
886
109
  ptr += SIZEOF_ILF_SYM_TABLE;
887
888
109
  vars.native_syms = (combined_entry_type *) ptr;
889
109
  vars.native_ptr  = (combined_entry_type *) ptr;
890
109
  ptr += SIZEOF_ILF_NATIVE_SYMS;
891
892
109
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
893
109
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
894
109
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
895
896
109
  vars.esym_table = (SYMENT *) ptr;
897
109
  vars.esym_ptr   = (SYMENT *) ptr;
898
109
  ptr += SIZEOF_ILF_EXT_SYMS;
899
900
109
  vars.reltab   = (arelent *) ptr;
901
109
  vars.relcount = 0;
902
109
  ptr += SIZEOF_ILF_RELOCS;
903
904
109
  vars.int_reltab  = (struct internal_reloc *) ptr;
905
109
  ptr += SIZEOF_ILF_INT_RELOCS;
906
907
109
  vars.string_table = (char *) ptr;
908
109
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
909
109
  ptr += SIZEOF_ILF_STRINGS;
910
109
  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
109
#if GCC_VERSION >= 3000
920
109
  alignment = __alignof__ (struct coff_section_tdata);
921
#else
922
  alignment = 8;
923
#endif
924
109
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
925
926
109
  vars.data = ptr;
927
109
  vars.abfd = abfd;
928
109
  vars.sec_index = 0;
929
109
  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
109
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
939
109
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
940
109
  if (id4 == NULL || id5 == NULL)
941
0
    goto error_return;
942
943
  /* Fill in the contents of these sections.  */
944
109
  if (import_name_type == IMPORT_ORDINAL)
945
39
    {
946
39
      if (ordinal == 0)
947
  /* See PR 20907 for a reproducer.  */
948
11
  goto error_return;
949
950
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
951
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
952
      ((unsigned int *) id4->contents)[0] = ordinal;
953
      ((unsigned int *) id4->contents)[1] = 0x80000000;
954
      ((unsigned int *) id5->contents)[0] = ordinal;
955
      ((unsigned int *) id5->contents)[1] = 0x80000000;
956
#else
957
28
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
958
28
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
959
28
#endif
960
28
    }
961
70
  else
962
70
    {
963
70
      char *symbol;
964
70
      unsigned int len;
965
966
      /* Create .idata$6 - the Hint Name Table.  */
967
70
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
968
70
      if (id6 == NULL)
969
0
  goto error_return;
970
971
      /* If necessary, trim the import symbol name.  */
972
70
      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
70
      if (import_name_type != IMPORT_NAME
982
62
    && import_name_type != IMPORT_NAME_EXPORTAS)
983
56
  {
984
56
    char c = symbol[0];
985
986
    /* Check that we don't remove for targets with empty
987
       USER_LABEL_PREFIX the leading underscore.  */
988
56
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
989
50
        || c == '@' || c == '?')
990
16
      symbol++;
991
56
  }
992
993
70
      len = strlen (symbol);
994
70
      if (import_name_type == IMPORT_NAME_UNDECORATE)
995
29
  {
996
    /* Truncate at the first '@'.  */
997
29
    char *at = strchr (symbol, '@');
998
999
29
    if (at != NULL)
1000
5
      len = at - symbol;
1001
29
  }
1002
1003
70
      id6->contents[0] = ordinal & 0xff;
1004
70
      id6->contents[1] = ordinal >> 8;
1005
1006
70
      memcpy ((char *) id6->contents + 2, symbol, len);
1007
70
      id6->contents[len + 2] = '\0';
1008
70
    }
1009
1010
98
  if (import_name_type != IMPORT_ORDINAL)
1011
70
    {
1012
70
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1013
70
      pe_ILF_save_relocs (&vars, id4);
1014
1015
70
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1016
70
      pe_ILF_save_relocs (&vars, id5);
1017
70
    }
1018
1019
  /* Create an import symbol.  */
1020
98
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1021
98
  imp_sym   = vars.sym_ptr_ptr - 1;
1022
98
  imp_index = vars.sym_index - 1;
1023
1024
  /* Create extra sections depending upon the type of import we are
1025
     dealing with.  */
1026
98
  switch (import_type)
1027
98
    {
1028
0
      int i;
1029
1030
53
    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
134
      for (i = NUM_ENTRIES (jtab); i--;)
1035
134
  {
1036
134
    if (jtab[i].size == 0)
1037
53
      continue;
1038
81
    if (jtab[i].magic == magic)
1039
53
      break;
1040
81
  }
1041
      /* If we did not find a matching entry something is wrong.  */
1042
53
      if (i < 0)
1043
0
  abort ();
1044
1045
      /* Create the .text section.  */
1046
53
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1047
53
      if (text == NULL)
1048
0
  goto error_return;
1049
1050
      /* Copy in the jump code.  */
1051
53
      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
53
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1077
53
            BFD_RELOC_32, (asymbol **) imp_sym,
1078
53
            imp_index);
1079
1080
53
      pe_ILF_save_relocs (&vars, text);
1081
53
      break;
1082
1083
25
    case IMPORT_DATA:
1084
45
    case IMPORT_CONST:
1085
45
      break;
1086
1087
0
    default:
1088
      /* XXX code not yet written.  */
1089
0
      abort ();
1090
98
    }
1091
1092
  /* Now create a symbol describing the imported value.  */
1093
98
  switch (import_type)
1094
98
    {
1095
53
    case IMPORT_CODE:
1096
53
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1097
53
          BSF_NOT_AT_END | BSF_FUNCTION);
1098
1099
53
      break;
1100
1101
25
    case IMPORT_DATA:
1102
      /* Nothing to do here.  */
1103
25
      break;
1104
1105
20
    case IMPORT_CONST:
1106
20
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1107
20
      break;
1108
1109
0
    default:
1110
      /* XXX code not yet written.  */
1111
0
      abort ();
1112
98
    }
1113
1114
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1115
98
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1116
98
  if (ptr)
1117
8
    *ptr = 0;
1118
98
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1119
98
  if (ptr)
1120
8
    *ptr = '.';
1121
1122
  /* Initialise the bfd.  */
1123
98
  memset (&internal_f, 0, sizeof (internal_f));
1124
1125
98
  internal_f.f_magic  = magic;
1126
98
  internal_f.f_symptr = 0;
1127
98
  internal_f.f_nsyms  = 0;
1128
98
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1129
1130
98
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1131
98
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1132
0
    goto error_return;
1133
1134
98
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1135
0
    goto error_return;
1136
1137
98
  obj_pe (abfd) = true;
1138
98
#ifdef THUMBPEMAGIC
1139
98
  if (vars.magic == THUMBPEMAGIC)
1140
    /* Stop some linker warnings about thumb code not supporting
1141
       interworking.  */
1142
49
    coff_data (abfd)->flags |= F_INTERWORK | F_INTERWORK_SET;
1143
98
#endif
1144
1145
  /* Switch from file contents to memory contents.  */
1146
98
  bfd_cache_close (abfd);
1147
1148
98
  abfd->iostream = (void *) vars.bim;
1149
98
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1150
98
  abfd->iovec = &_bfd_memory_iovec;
1151
98
  abfd->where = 0;
1152
98
  abfd->origin = 0;
1153
98
  abfd->size = 0;
1154
98
  obj_sym_filepos (abfd) = 0;
1155
1156
  /* Point the bfd at the symbol table.  */
1157
98
  obj_symbols (abfd) = vars.sym_cache;
1158
98
  abfd->symcount = vars.sym_index;
1159
1160
98
  obj_raw_syments (abfd) = vars.native_syms;
1161
98
  obj_raw_syment_count (abfd) = vars.sym_index;
1162
98
  obj_coff_keep_raw_syms (abfd) = true;
1163
1164
98
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1165
98
  obj_coff_keep_syms (abfd) = true;
1166
1167
98
  obj_convert (abfd) = vars.sym_table;
1168
98
  obj_conv_table_size (abfd) = vars.sym_index;
1169
1170
98
  obj_coff_strings (abfd) = vars.string_table;
1171
98
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1172
98
  obj_coff_keep_strings (abfd) = true;
1173
1174
98
  return true;
1175
1176
11
 error_return:
1177
11
  free (vars.bim->buffer);
1178
11
  free (vars.bim);
1179
  return false;
1180
98
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_build_a_bfd
pei-sh.c:pe_ILF_build_a_bfd
Line
Count
Source
804
231
{
805
231
  bfd_byte *       ptr;
806
231
  pe_ILF_vars      vars;
807
231
  struct internal_filehdr  internal_f;
808
231
  unsigned int       import_type;
809
231
  unsigned int       import_name_type;
810
231
  asection_ptr       id4, id5, id6 = NULL, text = NULL;
811
231
  coff_symbol_type **    imp_sym;
812
231
  unsigned int       imp_index;
813
231
  intptr_t alignment;
814
815
  /* Decode and verify the types field of the ILF structure.  */
816
231
  import_type = types & 0x3;
817
231
  import_name_type = (types & 0x1c) >> 2;
818
819
231
  switch (import_type)
820
231
    {
821
87
    case IMPORT_CODE:
822
146
    case IMPORT_DATA:
823
191
    case IMPORT_CONST:
824
191
      break;
825
826
40
    default:
827
      /* xgettext:c-format */
828
40
      _bfd_error_handler (_("%pB: unrecognized import type; %x"),
829
40
        abfd, import_type);
830
40
      return false;
831
231
    }
832
833
191
  switch (import_name_type)
834
191
    {
835
39
    case IMPORT_ORDINAL:
836
54
    case IMPORT_NAME:
837
85
    case IMPORT_NAME_NOPREFIX:
838
142
    case IMPORT_NAME_UNDECORATE:
839
142
      import_name = symbol_name;
840
142
      break;
841
842
41
    case IMPORT_NAME_EXPORTAS:
843
41
      if (!import_name || !import_name[0])
844
23
  {
845
23
    _bfd_error_handler (_("%pB: missing import name for "
846
23
        "IMPORT_NAME_EXPORTAS for %s"),
847
23
            abfd, symbol_name);
848
23
    return false;
849
23
  }
850
18
      break;
851
852
18
    default:
853
      /* xgettext:c-format */
854
8
      _bfd_error_handler (_("%pB: unrecognized import name type; %x"),
855
8
        abfd, import_name_type);
856
8
      return false;
857
191
    }
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
160
  vars.bim
867
160
    = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim));
868
160
  if (vars.bim == NULL)
869
0
    return false;
870
871
160
  ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE);
872
160
  vars.bim->buffer = ptr;
873
160
  vars.bim->size   = ILF_DATA_SIZE;
874
160
  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
160
  vars.sym_cache = (coff_symbol_type *) ptr;
880
160
  vars.sym_ptr   = (coff_symbol_type *) ptr;
881
160
  vars.sym_index = 0;
882
160
  ptr += SIZEOF_ILF_SYMS;
883
884
160
  vars.sym_table = (unsigned int *) ptr;
885
160
  vars.table_ptr = (unsigned int *) ptr;
886
160
  ptr += SIZEOF_ILF_SYM_TABLE;
887
888
160
  vars.native_syms = (combined_entry_type *) ptr;
889
160
  vars.native_ptr  = (combined_entry_type *) ptr;
890
160
  ptr += SIZEOF_ILF_NATIVE_SYMS;
891
892
160
  vars.sym_ptr_table = (coff_symbol_type **) ptr;
893
160
  vars.sym_ptr_ptr   = (coff_symbol_type **) ptr;
894
160
  ptr += SIZEOF_ILF_SYM_PTR_TABLE;
895
896
160
  vars.esym_table = (SYMENT *) ptr;
897
160
  vars.esym_ptr   = (SYMENT *) ptr;
898
160
  ptr += SIZEOF_ILF_EXT_SYMS;
899
900
160
  vars.reltab   = (arelent *) ptr;
901
160
  vars.relcount = 0;
902
160
  ptr += SIZEOF_ILF_RELOCS;
903
904
160
  vars.int_reltab  = (struct internal_reloc *) ptr;
905
160
  ptr += SIZEOF_ILF_INT_RELOCS;
906
907
160
  vars.string_table = (char *) ptr;
908
160
  vars.string_ptr   = (char *) ptr + STRING_SIZE_SIZE;
909
160
  ptr += SIZEOF_ILF_STRINGS;
910
160
  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
160
#if GCC_VERSION >= 3000
920
160
  alignment = __alignof__ (struct coff_section_tdata);
921
#else
922
  alignment = 8;
923
#endif
924
160
  ptr = (bfd_byte *) (((intptr_t) ptr + alignment - 1) & -alignment);
925
926
160
  vars.data = ptr;
927
160
  vars.abfd = abfd;
928
160
  vars.sec_index = 0;
929
160
  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
160
  id4 = pe_ILF_make_a_section (&vars, ".idata$4", SIZEOF_IDATA4, 0);
939
160
  id5 = pe_ILF_make_a_section (&vars, ".idata$5", SIZEOF_IDATA5, 0);
940
160
  if (id4 == NULL || id5 == NULL)
941
0
    goto error_return;
942
943
  /* Fill in the contents of these sections.  */
944
160
  if (import_name_type == IMPORT_ORDINAL)
945
39
    {
946
39
      if (ordinal == 0)
947
  /* See PR 20907 for a reproducer.  */
948
12
  goto error_return;
949
950
#if (defined(COFF_WITH_pex64) || defined(COFF_WITH_peAArch64) \
951
     || defined(COFF_WITH_peLoongArch64) || defined (COFF_WITH_peRiscV64))
952
      ((unsigned int *) id4->contents)[0] = ordinal;
953
      ((unsigned int *) id4->contents)[1] = 0x80000000;
954
      ((unsigned int *) id5->contents)[0] = ordinal;
955
      ((unsigned int *) id5->contents)[1] = 0x80000000;
956
#else
957
27
      ((unsigned int *) id4->contents)[0] = ordinal | 0x80000000;
958
27
      ((unsigned int *) id5->contents)[0] = ordinal | 0x80000000;
959
27
#endif
960
27
    }
961
121
  else
962
121
    {
963
121
      char *symbol;
964
121
      unsigned int len;
965
966
      /* Create .idata$6 - the Hint Name Table.  */
967
121
      id6 = pe_ILF_make_a_section (&vars, ".idata$6", SIZEOF_IDATA6, 0);
968
121
      if (id6 == NULL)
969
0
  goto error_return;
970
971
      /* If necessary, trim the import symbol name.  */
972
121
      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
121
      if (import_name_type != IMPORT_NAME
982
106
    && import_name_type != IMPORT_NAME_EXPORTAS)
983
88
  {
984
88
    char c = symbol[0];
985
986
    /* Check that we don't remove for targets with empty
987
       USER_LABEL_PREFIX the leading underscore.  */
988
88
    if ((c == '_' && abfd->xvec->symbol_leading_char != 0)
989
73
        || c == '@' || c == '?')
990
33
      symbol++;
991
88
  }
992
993
121
      len = strlen (symbol);
994
121
      if (import_name_type == IMPORT_NAME_UNDECORATE)
995
57
  {
996
    /* Truncate at the first '@'.  */
997
57
    char *at = strchr (symbol, '@');
998
999
57
    if (at != NULL)
1000
14
      len = at - symbol;
1001
57
  }
1002
1003
121
      id6->contents[0] = ordinal & 0xff;
1004
121
      id6->contents[1] = ordinal >> 8;
1005
1006
121
      memcpy ((char *) id6->contents + 2, symbol, len);
1007
121
      id6->contents[len + 2] = '\0';
1008
121
    }
1009
1010
148
  if (import_name_type != IMPORT_ORDINAL)
1011
121
    {
1012
121
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1013
121
      pe_ILF_save_relocs (&vars, id4);
1014
1015
121
      pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_RVA, id6);
1016
121
      pe_ILF_save_relocs (&vars, id5);
1017
121
    }
1018
1019
  /* Create an import symbol.  */
1020
148
  pe_ILF_make_a_symbol (&vars, "__imp_", symbol_name, id5, 0);
1021
148
  imp_sym   = vars.sym_ptr_ptr - 1;
1022
148
  imp_index = vars.sym_index - 1;
1023
1024
  /* Create extra sections depending upon the type of import we are
1025
     dealing with.  */
1026
148
  switch (import_type)
1027
148
    {
1028
0
      int i;
1029
1030
56
    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
112
      for (i = NUM_ENTRIES (jtab); i--;)
1035
112
  {
1036
112
    if (jtab[i].size == 0)
1037
56
      continue;
1038
56
    if (jtab[i].magic == magic)
1039
56
      break;
1040
56
  }
1041
      /* If we did not find a matching entry something is wrong.  */
1042
56
      if (i < 0)
1043
0
  abort ();
1044
1045
      /* Create the .text section.  */
1046
56
      text = pe_ILF_make_a_section (&vars, ".text", jtab[i].size, SEC_CODE);
1047
56
      if (text == NULL)
1048
0
  goto error_return;
1049
1050
      /* Copy in the jump code.  */
1051
56
      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
56
  pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) jtab[i].offset,
1077
56
            BFD_RELOC_32, (asymbol **) imp_sym,
1078
56
            imp_index);
1079
1080
56
      pe_ILF_save_relocs (&vars, text);
1081
56
      break;
1082
1083
53
    case IMPORT_DATA:
1084
92
    case IMPORT_CONST:
1085
92
      break;
1086
1087
0
    default:
1088
      /* XXX code not yet written.  */
1089
0
      abort ();
1090
148
    }
1091
1092
  /* Now create a symbol describing the imported value.  */
1093
148
  switch (import_type)
1094
148
    {
1095
56
    case IMPORT_CODE:
1096
56
      pe_ILF_make_a_symbol (&vars, "", symbol_name, text,
1097
56
          BSF_NOT_AT_END | BSF_FUNCTION);
1098
1099
56
      break;
1100
1101
53
    case IMPORT_DATA:
1102
      /* Nothing to do here.  */
1103
53
      break;
1104
1105
39
    case IMPORT_CONST:
1106
39
      pe_ILF_make_a_symbol (&vars, "", symbol_name, id5, 0);
1107
39
      break;
1108
1109
0
    default:
1110
      /* XXX code not yet written.  */
1111
0
      abort ();
1112
148
    }
1113
1114
  /* Create an import symbol for the DLL, without the .dll suffix.  */
1115
148
  ptr = (bfd_byte *) strrchr (source_dll, '.');
1116
148
  if (ptr)
1117
21
    *ptr = 0;
1118
148
  pe_ILF_make_a_symbol (&vars, "__IMPORT_DESCRIPTOR_", source_dll, NULL, 0);
1119
148
  if (ptr)
1120
21
    *ptr = '.';
1121
1122
  /* Initialise the bfd.  */
1123
148
  memset (&internal_f, 0, sizeof (internal_f));
1124
1125
148
  internal_f.f_magic  = magic;
1126
148
  internal_f.f_symptr = 0;
1127
148
  internal_f.f_nsyms  = 0;
1128
148
  internal_f.f_flags  = F_AR32WR | F_LNNO; /* XXX is this correct ?  */
1129
1130
148
  if (!bfd_set_start_address (abfd, (bfd_vma) 0)
1131
148
      || !bfd_coff_set_arch_mach_hook (abfd, &internal_f))
1132
0
    goto error_return;
1133
1134
148
  if (bfd_coff_mkobject_hook (abfd, (void *) &internal_f, NULL) == NULL)
1135
0
    goto error_return;
1136
1137
148
  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
148
  bfd_cache_close (abfd);
1147
1148
148
  abfd->iostream = (void *) vars.bim;
1149
148
  abfd->flags |= BFD_IN_MEMORY | HAS_SYMS;
1150
148
  abfd->iovec = &_bfd_memory_iovec;
1151
148
  abfd->where = 0;
1152
148
  abfd->origin = 0;
1153
148
  abfd->size = 0;
1154
148
  obj_sym_filepos (abfd) = 0;
1155
1156
  /* Point the bfd at the symbol table.  */
1157
148
  obj_symbols (abfd) = vars.sym_cache;
1158
148
  abfd->symcount = vars.sym_index;
1159
1160
148
  obj_raw_syments (abfd) = vars.native_syms;
1161
148
  obj_raw_syment_count (abfd) = vars.sym_index;
1162
148
  obj_coff_keep_raw_syms (abfd) = true;
1163
1164
148
  obj_coff_external_syms (abfd) = (void *) vars.esym_table;
1165
148
  obj_coff_keep_syms (abfd) = true;
1166
1167
148
  obj_convert (abfd) = vars.sym_table;
1168
148
  obj_conv_table_size (abfd) = vars.sym_index;
1169
1170
148
  obj_coff_strings (abfd) = vars.string_table;
1171
148
  obj_coff_strings_len (abfd) = vars.string_ptr - vars.string_table;
1172
148
  obj_coff_keep_strings (abfd) = true;
1173
1174
148
  return true;
1175
1176
12
 error_return:
1177
12
  free (vars.bim->buffer);
1178
12
  free (vars.bim);
1179
  return false;
1180
148
}
1181
1182
/* Cleanup function, returned from check_format hook.  */
1183
1184
static void
1185
pe_ILF_cleanup (bfd *abfd)
1186
98
{
1187
98
  coff_object_cleanup (abfd);
1188
1189
98
  struct bfd_in_memory *bim = abfd->iostream;
1190
98
  free (bim->buffer);
1191
98
  free (bim);
1192
98
  abfd->iostream = NULL;
1193
98
}
Unexecuted instantiation: pei-i386.c:pe_ILF_cleanup
Unexecuted instantiation: pei-x86_64.c:pe_ILF_cleanup
Unexecuted instantiation: pei-aarch64.c:pe_ILF_cleanup
Unexecuted instantiation: pei-ia64.c:pe_ILF_cleanup
Unexecuted instantiation: pei-loongarch64.c:pe_ILF_cleanup
Unexecuted instantiation: pei-riscv64.c:pe_ILF_cleanup
pei-arm-wince.c:pe_ILF_cleanup
Line
Count
Source
1186
49
{
1187
49
  coff_object_cleanup (abfd);
1188
1189
49
  struct bfd_in_memory *bim = abfd->iostream;
1190
49
  free (bim->buffer);
1191
49
  free (bim);
1192
  abfd->iostream = NULL;
1193
49
}
pei-arm.c:pe_ILF_cleanup
Line
Count
Source
1186
49
{
1187
49
  coff_object_cleanup (abfd);
1188
1189
49
  struct bfd_in_memory *bim = abfd->iostream;
1190
49
  free (bim->buffer);
1191
49
  free (bim);
1192
  abfd->iostream = NULL;
1193
49
}
Unexecuted instantiation: pei-mcore.c:pe_ILF_cleanup
Unexecuted instantiation: pei-sh.c:pe_ILF_cleanup
1194
1195
/* We have detected an Import Library Format archive element.
1196
   Decode the element and return the appropriate target.  */
1197
1198
static bfd_cleanup
1199
pe_ILF_object_p (bfd *abfd)
1200
33.5k
{
1201
33.5k
  bfd_byte    buffer[14];
1202
33.5k
  bfd_byte *    ptr;
1203
33.5k
  char *    symbol_name;
1204
33.5k
  char *    source_dll;
1205
33.5k
  char *    import_name;
1206
33.5k
  unsigned int    machine;
1207
33.5k
  bfd_size_type   size;
1208
33.5k
  unsigned int    ordinal;
1209
33.5k
  unsigned int    types;
1210
33.5k
  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
33.5k
  if (bfd_read (buffer, 14, abfd) != 14)
1215
580
    return NULL;
1216
1217
32.9k
  ptr = buffer;
1218
1219
32.9k
  machine = H_GET_16 (abfd, ptr);
1220
32.9k
  ptr += 2;
1221
1222
  /* Check that the machine type is recognised.  */
1223
32.9k
  magic = 0;
1224
1225
32.9k
  switch (machine)
1226
32.9k
    {
1227
134
    case IMAGE_FILE_MACHINE_UNKNOWN:
1228
179
    case IMAGE_FILE_MACHINE_ALPHA:
1229
233
    case IMAGE_FILE_MACHINE_ALPHA64:
1230
319
    case IMAGE_FILE_MACHINE_IA64:
1231
319
      break;
1232
1233
2.71k
    case IMAGE_FILE_MACHINE_I386:
1234
#ifdef I386MAGIC
1235
352
      magic = I386MAGIC;
1236
#endif
1237
2.71k
      break;
1238
1239
2.46k
    case IMAGE_FILE_MACHINE_AMD64:
1240
#ifdef AMD64MAGIC
1241
335
      magic = AMD64MAGIC;
1242
#endif
1243
2.46k
      break;
1244
1245
53
    case IMAGE_FILE_MACHINE_R3000:
1246
139
    case IMAGE_FILE_MACHINE_R4000:
1247
216
    case IMAGE_FILE_MACHINE_R10000:
1248
1249
261
    case IMAGE_FILE_MACHINE_MIPS16:
1250
342
    case IMAGE_FILE_MACHINE_MIPSFPU:
1251
428
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1252
#ifdef MIPS_ARCH_MAGIC_WINCE
1253
      magic = MIPS_ARCH_MAGIC_WINCE;
1254
#endif
1255
428
      break;
1256
1257
5.40k
    case IMAGE_FILE_MACHINE_SH3:
1258
7.34k
    case IMAGE_FILE_MACHINE_SH4:
1259
#ifdef SH_ARCH_MAGIC_WINCE
1260
852
      magic = SH_ARCH_MAGIC_WINCE;
1261
#endif
1262
7.34k
      break;
1263
1264
1.80k
    case IMAGE_FILE_MACHINE_ARM:
1265
#ifdef ARMPEMAGIC
1266
428
      magic = ARMPEMAGIC;
1267
#endif
1268
1.80k
      break;
1269
1270
2.78k
    case IMAGE_FILE_MACHINE_ARM64:
1271
#ifdef AARCH64MAGIC
1272
369
      magic = AARCH64MAGIC;
1273
#endif
1274
2.78k
      break;
1275
1276
2.77k
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1277
#ifdef LOONGARCH64MAGIC
1278
371
      magic = LOONGARCH64MAGIC;
1279
#endif
1280
2.77k
      break;
1281
1282
2.84k
    case IMAGE_FILE_MACHINE_RISCV64:
1283
#ifdef RISCV64MAGIC
1284
371
      magic = RISCV64MAGIC;
1285
#endif
1286
2.84k
      break;
1287
1288
1.96k
    case IMAGE_FILE_MACHINE_THUMB:
1289
#ifdef THUMBPEMAGIC
1290
      {
1291
  extern const bfd_target TARGET_LITTLE_SYM;
1292
1293
414
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1294
408
    magic = THUMBPEMAGIC;
1295
      }
1296
#endif
1297
1.96k
      break;
1298
1299
0
    case IMAGE_FILE_MACHINE_POWERPC:
1300
      /* We no longer support PowerPC.  */
1301
7.48k
    default:
1302
7.48k
      _bfd_error_handler
1303
  /* xgettext:c-format */
1304
7.48k
  (_("%pB: unrecognised machine type (0x%x)"
1305
7.48k
     " in Import Library Format archive"),
1306
7.48k
   abfd, machine);
1307
7.48k
      bfd_set_error (bfd_error_malformed_archive);
1308
1309
7.48k
      return NULL;
1310
0
      break;
1311
32.9k
    }
1312
1313
25.4k
  if (magic == 0)
1314
21.9k
    {
1315
21.9k
      _bfd_error_handler
1316
  /* xgettext:c-format */
1317
21.9k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1318
21.9k
     " in Import Library Format archive"),
1319
21.9k
   abfd, machine);
1320
21.9k
      bfd_set_error (bfd_error_wrong_format);
1321
1322
21.9k
      return NULL;
1323
21.9k
    }
1324
1325
  /* We do not bother to check the date.
1326
     date = H_GET_32 (abfd, ptr);  */
1327
3.48k
  ptr += 4;
1328
1329
3.48k
  size = H_GET_32 (abfd, ptr);
1330
3.48k
  ptr += 4;
1331
1332
3.48k
  if (size == 0)
1333
79
    {
1334
79
      _bfd_error_handler
1335
79
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1336
79
      bfd_set_error (bfd_error_malformed_archive);
1337
1338
79
      return NULL;
1339
79
    }
1340
1341
3.40k
  ordinal = H_GET_16 (abfd, ptr);
1342
3.40k
  ptr += 2;
1343
1344
3.40k
  types = H_GET_16 (abfd, ptr);
1345
  /* ptr += 2; */
1346
1347
  /* Now read in the two strings that follow.  */
1348
3.40k
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1349
3.40k
  if (ptr == NULL)
1350
1.50k
    return NULL;
1351
1352
1.89k
  symbol_name = (char *) ptr;
1353
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1354
1.89k
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1355
1356
  /* Verify that the strings are null terminated.  */
1357
1.89k
  if (ptr[size - 1] != 0
1358
1.42k
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1359
544
    {
1360
544
      _bfd_error_handler
1361
544
  (_("%pB: string not null terminated in ILF object file"), abfd);
1362
544
      bfd_set_error (bfd_error_malformed_archive);
1363
544
      bfd_release (abfd, ptr);
1364
544
      return NULL;
1365
544
    }
1366
1367
  /* An ILF file may contain a third string, after source_dll; this is
1368
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1369
     block of data is null terminated, ptr[size-1]==0, but we don't
1370
     know how many individual null terminated strings we have in there.
1371
1372
     First find the end of source_dll.  */
1373
1.35k
  import_name = source_dll + strlen (source_dll) + 1;
1374
1.35k
  if ((bfd_byte *) import_name >= ptr + size)
1375
434
    {
1376
      /* If this points at the end of the ptr+size block, we only had
1377
   two strings. */
1378
434
      import_name = NULL;
1379
434
    }
1380
1381
  /* Now construct the bfd.  */
1382
1.35k
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1383
1.35k
          source_dll, ordinal, types,
1384
1.35k
          import_name))
1385
388
    {
1386
388
      bfd_release (abfd, ptr);
1387
388
      return NULL;
1388
388
    }
1389
1390
967
  return pe_ILF_cleanup;
1391
1.35k
}
pei-i386.c:pe_ILF_object_p
Line
Count
Source
1200
3.85k
{
1201
3.85k
  bfd_byte    buffer[14];
1202
3.85k
  bfd_byte *    ptr;
1203
3.85k
  char *    symbol_name;
1204
3.85k
  char *    source_dll;
1205
3.85k
  char *    import_name;
1206
3.85k
  unsigned int    machine;
1207
3.85k
  bfd_size_type   size;
1208
3.85k
  unsigned int    ordinal;
1209
3.85k
  unsigned int    types;
1210
3.85k
  unsigned int    magic;
1211
1212
  /* Upon entry the first six bytes of the ILF header have
1213
     already been read.  Now read the rest of the header.  */
1214
3.85k
  if (bfd_read (buffer, 14, abfd) != 14)
1215
64
    return NULL;
1216
1217
3.79k
  ptr = buffer;
1218
1219
3.79k
  machine = H_GET_16 (abfd, ptr);
1220
3.79k
  ptr += 2;
1221
1222
  /* Check that the machine type is recognised.  */
1223
3.79k
  magic = 0;
1224
1225
3.79k
  switch (machine)
1226
3.79k
    {
1227
14
    case IMAGE_FILE_MACHINE_UNKNOWN:
1228
19
    case IMAGE_FILE_MACHINE_ALPHA:
1229
25
    case IMAGE_FILE_MACHINE_ALPHA64:
1230
35
    case IMAGE_FILE_MACHINE_IA64:
1231
35
      break;
1232
1233
352
    case IMAGE_FILE_MACHINE_I386:
1234
352
#ifdef I386MAGIC
1235
352
      magic = I386MAGIC;
1236
352
#endif
1237
352
      break;
1238
1239
277
    case IMAGE_FILE_MACHINE_AMD64:
1240
#ifdef AMD64MAGIC
1241
      magic = AMD64MAGIC;
1242
#endif
1243
277
      break;
1244
1245
6
    case IMAGE_FILE_MACHINE_R3000:
1246
16
    case IMAGE_FILE_MACHINE_R4000:
1247
25
    case IMAGE_FILE_MACHINE_R10000:
1248
1249
30
    case IMAGE_FILE_MACHINE_MIPS16:
1250
39
    case IMAGE_FILE_MACHINE_MIPSFPU:
1251
49
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1252
#ifdef MIPS_ARCH_MAGIC_WINCE
1253
      magic = MIPS_ARCH_MAGIC_WINCE;
1254
#endif
1255
49
      break;
1256
1257
602
    case IMAGE_FILE_MACHINE_SH3:
1258
830
    case IMAGE_FILE_MACHINE_SH4:
1259
#ifdef SH_ARCH_MAGIC_WINCE
1260
      magic = SH_ARCH_MAGIC_WINCE;
1261
#endif
1262
830
      break;
1263
1264
197
    case IMAGE_FILE_MACHINE_ARM:
1265
#ifdef ARMPEMAGIC
1266
      magic = ARMPEMAGIC;
1267
#endif
1268
197
      break;
1269
1270
318
    case IMAGE_FILE_MACHINE_ARM64:
1271
#ifdef AARCH64MAGIC
1272
      magic = AARCH64MAGIC;
1273
#endif
1274
318
      break;
1275
1276
318
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1277
#ifdef LOONGARCH64MAGIC
1278
      magic = LOONGARCH64MAGIC;
1279
#endif
1280
318
      break;
1281
1282
323
    case IMAGE_FILE_MACHINE_RISCV64:
1283
#ifdef RISCV64MAGIC
1284
      magic = RISCV64MAGIC;
1285
#endif
1286
323
      break;
1287
1288
227
    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
227
      break;
1298
1299
0
    case IMAGE_FILE_MACHINE_POWERPC:
1300
      /* We no longer support PowerPC.  */
1301
868
    default:
1302
868
      _bfd_error_handler
1303
  /* xgettext:c-format */
1304
868
  (_("%pB: unrecognised machine type (0x%x)"
1305
868
     " in Import Library Format archive"),
1306
868
   abfd, machine);
1307
868
      bfd_set_error (bfd_error_malformed_archive);
1308
1309
868
      return NULL;
1310
0
      break;
1311
3.79k
    }
1312
1313
2.92k
  if (magic == 0)
1314
2.57k
    {
1315
2.57k
      _bfd_error_handler
1316
  /* xgettext:c-format */
1317
2.57k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1318
2.57k
     " in Import Library Format archive"),
1319
2.57k
   abfd, machine);
1320
2.57k
      bfd_set_error (bfd_error_wrong_format);
1321
1322
2.57k
      return NULL;
1323
2.57k
    }
1324
1325
  /* We do not bother to check the date.
1326
     date = H_GET_32 (abfd, ptr);  */
1327
352
  ptr += 4;
1328
1329
352
  size = H_GET_32 (abfd, ptr);
1330
352
  ptr += 4;
1331
1332
352
  if (size == 0)
1333
11
    {
1334
11
      _bfd_error_handler
1335
11
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1336
11
      bfd_set_error (bfd_error_malformed_archive);
1337
1338
11
      return NULL;
1339
11
    }
1340
1341
341
  ordinal = H_GET_16 (abfd, ptr);
1342
341
  ptr += 2;
1343
1344
341
  types = H_GET_16 (abfd, ptr);
1345
  /* ptr += 2; */
1346
1347
  /* Now read in the two strings that follow.  */
1348
341
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1349
341
  if (ptr == NULL)
1350
168
    return NULL;
1351
1352
173
  symbol_name = (char *) ptr;
1353
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1354
173
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1355
1356
  /* Verify that the strings are null terminated.  */
1357
173
  if (ptr[size - 1] != 0
1358
164
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1359
18
    {
1360
18
      _bfd_error_handler
1361
18
  (_("%pB: string not null terminated in ILF object file"), abfd);
1362
18
      bfd_set_error (bfd_error_malformed_archive);
1363
18
      bfd_release (abfd, ptr);
1364
18
      return NULL;
1365
18
    }
1366
1367
  /* An ILF file may contain a third string, after source_dll; this is
1368
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1369
     block of data is null terminated, ptr[size-1]==0, but we don't
1370
     know how many individual null terminated strings we have in there.
1371
1372
     First find the end of source_dll.  */
1373
155
  import_name = source_dll + strlen (source_dll) + 1;
1374
155
  if ((bfd_byte *) import_name >= ptr + size)
1375
41
    {
1376
      /* If this points at the end of the ptr+size block, we only had
1377
   two strings. */
1378
41
      import_name = NULL;
1379
41
    }
1380
1381
  /* Now construct the bfd.  */
1382
155
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1383
155
          source_dll, ordinal, types,
1384
155
          import_name))
1385
39
    {
1386
39
      bfd_release (abfd, ptr);
1387
39
      return NULL;
1388
39
    }
1389
1390
116
  return pe_ILF_cleanup;
1391
155
}
pei-x86_64.c:pe_ILF_object_p
Line
Count
Source
1200
3.85k
{
1201
3.85k
  bfd_byte    buffer[14];
1202
3.85k
  bfd_byte *    ptr;
1203
3.85k
  char *    symbol_name;
1204
3.85k
  char *    source_dll;
1205
3.85k
  char *    import_name;
1206
3.85k
  unsigned int    machine;
1207
3.85k
  bfd_size_type   size;
1208
3.85k
  unsigned int    ordinal;
1209
3.85k
  unsigned int    types;
1210
3.85k
  unsigned int    magic;
1211
1212
  /* Upon entry the first six bytes of the ILF header have
1213
     already been read.  Now read the rest of the header.  */
1214
3.85k
  if (bfd_read (buffer, 14, abfd) != 14)
1215
64
    return NULL;
1216
1217
3.79k
  ptr = buffer;
1218
1219
3.79k
  machine = H_GET_16 (abfd, ptr);
1220
3.79k
  ptr += 2;
1221
1222
  /* Check that the machine type is recognised.  */
1223
3.79k
  magic = 0;
1224
1225
3.79k
  switch (machine)
1226
3.79k
    {
1227
14
    case IMAGE_FILE_MACHINE_UNKNOWN:
1228
19
    case IMAGE_FILE_MACHINE_ALPHA:
1229
25
    case IMAGE_FILE_MACHINE_ALPHA64:
1230
35
    case IMAGE_FILE_MACHINE_IA64:
1231
35
      break;
1232
1233
305
    case IMAGE_FILE_MACHINE_I386:
1234
#ifdef I386MAGIC
1235
      magic = I386MAGIC;
1236
#endif
1237
305
      break;
1238
1239
335
    case IMAGE_FILE_MACHINE_AMD64:
1240
335
#ifdef AMD64MAGIC
1241
335
      magic = AMD64MAGIC;
1242
335
#endif
1243
335
      break;
1244
1245
6
    case IMAGE_FILE_MACHINE_R3000:
1246
16
    case IMAGE_FILE_MACHINE_R4000:
1247
25
    case IMAGE_FILE_MACHINE_R10000:
1248
1249
30
    case IMAGE_FILE_MACHINE_MIPS16:
1250
39
    case IMAGE_FILE_MACHINE_MIPSFPU:
1251
49
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1252
#ifdef MIPS_ARCH_MAGIC_WINCE
1253
      magic = MIPS_ARCH_MAGIC_WINCE;
1254
#endif
1255
49
      break;
1256
1257
593
    case IMAGE_FILE_MACHINE_SH3:
1258
818
    case IMAGE_FILE_MACHINE_SH4:
1259
#ifdef SH_ARCH_MAGIC_WINCE
1260
      magic = SH_ARCH_MAGIC_WINCE;
1261
#endif
1262
818
      break;
1263
1264
197
    case IMAGE_FILE_MACHINE_ARM:
1265
#ifdef ARMPEMAGIC
1266
      magic = ARMPEMAGIC;
1267
#endif
1268
197
      break;
1269
1270
318
    case IMAGE_FILE_MACHINE_ARM64:
1271
#ifdef AARCH64MAGIC
1272
      magic = AARCH64MAGIC;
1273
#endif
1274
318
      break;
1275
1276
318
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1277
#ifdef LOONGARCH64MAGIC
1278
      magic = LOONGARCH64MAGIC;
1279
#endif
1280
318
      break;
1281
1282
321
    case IMAGE_FILE_MACHINE_RISCV64:
1283
#ifdef RISCV64MAGIC
1284
      magic = RISCV64MAGIC;
1285
#endif
1286
321
      break;
1287
1288
227
    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
227
      break;
1298
1299
0
    case IMAGE_FILE_MACHINE_POWERPC:
1300
      /* We no longer support PowerPC.  */
1301
868
    default:
1302
868
      _bfd_error_handler
1303
  /* xgettext:c-format */
1304
868
  (_("%pB: unrecognised machine type (0x%x)"
1305
868
     " in Import Library Format archive"),
1306
868
   abfd, machine);
1307
868
      bfd_set_error (bfd_error_malformed_archive);
1308
1309
868
      return NULL;
1310
0
      break;
1311
3.79k
    }
1312
1313
2.92k
  if (magic == 0)
1314
2.58k
    {
1315
2.58k
      _bfd_error_handler
1316
  /* xgettext:c-format */
1317
2.58k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1318
2.58k
     " in Import Library Format archive"),
1319
2.58k
   abfd, machine);
1320
2.58k
      bfd_set_error (bfd_error_wrong_format);
1321
1322
2.58k
      return NULL;
1323
2.58k
    }
1324
1325
  /* We do not bother to check the date.
1326
     date = H_GET_32 (abfd, ptr);  */
1327
335
  ptr += 4;
1328
1329
335
  size = H_GET_32 (abfd, ptr);
1330
335
  ptr += 4;
1331
1332
335
  if (size == 0)
1333
9
    {
1334
9
      _bfd_error_handler
1335
9
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1336
9
      bfd_set_error (bfd_error_malformed_archive);
1337
1338
9
      return NULL;
1339
9
    }
1340
1341
326
  ordinal = H_GET_16 (abfd, ptr);
1342
326
  ptr += 2;
1343
1344
326
  types = H_GET_16 (abfd, ptr);
1345
  /* ptr += 2; */
1346
1347
  /* Now read in the two strings that follow.  */
1348
326
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1349
326
  if (ptr == NULL)
1350
129
    return NULL;
1351
1352
197
  symbol_name = (char *) ptr;
1353
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1354
197
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1355
1356
  /* Verify that the strings are null terminated.  */
1357
197
  if (ptr[size - 1] != 0
1358
186
      || (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
178
  import_name = source_dll + strlen (source_dll) + 1;
1374
178
  if ((bfd_byte *) import_name >= ptr + size)
1375
57
    {
1376
      /* If this points at the end of the ptr+size block, we only had
1377
   two strings. */
1378
57
      import_name = NULL;
1379
57
    }
1380
1381
  /* Now construct the bfd.  */
1382
178
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1383
178
          source_dll, ordinal, types,
1384
178
          import_name))
1385
45
    {
1386
45
      bfd_release (abfd, ptr);
1387
45
      return NULL;
1388
45
    }
1389
1390
133
  return pe_ILF_cleanup;
1391
178
}
pei-aarch64.c:pe_ILF_object_p
Line
Count
Source
1200
3.86k
{
1201
3.86k
  bfd_byte    buffer[14];
1202
3.86k
  bfd_byte *    ptr;
1203
3.86k
  char *    symbol_name;
1204
3.86k
  char *    source_dll;
1205
3.86k
  char *    import_name;
1206
3.86k
  unsigned int    machine;
1207
3.86k
  bfd_size_type   size;
1208
3.86k
  unsigned int    ordinal;
1209
3.86k
  unsigned int    types;
1210
3.86k
  unsigned int    magic;
1211
1212
  /* Upon entry the first six bytes of the ILF header have
1213
     already been read.  Now read the rest of the header.  */
1214
3.86k
  if (bfd_read (buffer, 14, abfd) != 14)
1215
64
    return NULL;
1216
1217
3.80k
  ptr = buffer;
1218
1219
3.80k
  machine = H_GET_16 (abfd, ptr);
1220
3.80k
  ptr += 2;
1221
1222
  /* Check that the machine type is recognised.  */
1223
3.80k
  magic = 0;
1224
1225
3.80k
  switch (machine)
1226
3.80k
    {
1227
14
    case IMAGE_FILE_MACHINE_UNKNOWN:
1228
19
    case IMAGE_FILE_MACHINE_ALPHA:
1229
25
    case IMAGE_FILE_MACHINE_ALPHA64:
1230
35
    case IMAGE_FILE_MACHINE_IA64:
1231
35
      break;
1232
1233
308
    case IMAGE_FILE_MACHINE_I386:
1234
#ifdef I386MAGIC
1235
      magic = I386MAGIC;
1236
#endif
1237
308
      break;
1238
1239
277
    case IMAGE_FILE_MACHINE_AMD64:
1240
#ifdef AMD64MAGIC
1241
      magic = AMD64MAGIC;
1242
#endif
1243
277
      break;
1244
1245
6
    case IMAGE_FILE_MACHINE_R3000:
1246
16
    case IMAGE_FILE_MACHINE_R4000:
1247
25
    case IMAGE_FILE_MACHINE_R10000:
1248
1249
30
    case IMAGE_FILE_MACHINE_MIPS16:
1250
39
    case IMAGE_FILE_MACHINE_MIPSFPU:
1251
49
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1252
#ifdef MIPS_ARCH_MAGIC_WINCE
1253
      magic = MIPS_ARCH_MAGIC_WINCE;
1254
#endif
1255
49
      break;
1256
1257
602
    case IMAGE_FILE_MACHINE_SH3:
1258
830
    case IMAGE_FILE_MACHINE_SH4:
1259
#ifdef SH_ARCH_MAGIC_WINCE
1260
      magic = SH_ARCH_MAGIC_WINCE;
1261
#endif
1262
830
      break;
1263
1264
199
    case IMAGE_FILE_MACHINE_ARM:
1265
#ifdef ARMPEMAGIC
1266
      magic = ARMPEMAGIC;
1267
#endif
1268
199
      break;
1269
1270
369
    case IMAGE_FILE_MACHINE_ARM64:
1271
369
#ifdef AARCH64MAGIC
1272
369
      magic = AARCH64MAGIC;
1273
369
#endif
1274
369
      break;
1275
1276
318
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1277
#ifdef LOONGARCH64MAGIC
1278
      magic = LOONGARCH64MAGIC;
1279
#endif
1280
318
      break;
1281
1282
323
    case IMAGE_FILE_MACHINE_RISCV64:
1283
#ifdef RISCV64MAGIC
1284
      magic = RISCV64MAGIC;
1285
#endif
1286
323
      break;
1287
1288
227
    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
227
      break;
1298
1299
0
    case IMAGE_FILE_MACHINE_POWERPC:
1300
      /* We no longer support PowerPC.  */
1301
868
    default:
1302
868
      _bfd_error_handler
1303
  /* xgettext:c-format */
1304
868
  (_("%pB: unrecognised machine type (0x%x)"
1305
868
     " in Import Library Format archive"),
1306
868
   abfd, machine);
1307
868
      bfd_set_error (bfd_error_malformed_archive);
1308
1309
868
      return NULL;
1310
0
      break;
1311
3.80k
    }
1312
1313
2.93k
  if (magic == 0)
1314
2.56k
    {
1315
2.56k
      _bfd_error_handler
1316
  /* xgettext:c-format */
1317
2.56k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1318
2.56k
     " in Import Library Format archive"),
1319
2.56k
   abfd, machine);
1320
2.56k
      bfd_set_error (bfd_error_wrong_format);
1321
1322
2.56k
      return NULL;
1323
2.56k
    }
1324
1325
  /* We do not bother to check the date.
1326
     date = H_GET_32 (abfd, ptr);  */
1327
369
  ptr += 4;
1328
1329
369
  size = H_GET_32 (abfd, ptr);
1330
369
  ptr += 4;
1331
1332
369
  if (size == 0)
1333
9
    {
1334
9
      _bfd_error_handler
1335
9
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1336
9
      bfd_set_error (bfd_error_malformed_archive);
1337
1338
9
      return NULL;
1339
9
    }
1340
1341
360
  ordinal = H_GET_16 (abfd, ptr);
1342
360
  ptr += 2;
1343
1344
360
  types = H_GET_16 (abfd, ptr);
1345
  /* ptr += 2; */
1346
1347
  /* Now read in the two strings that follow.  */
1348
360
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1349
360
  if (ptr == NULL)
1350
184
    return NULL;
1351
1352
176
  symbol_name = (char *) ptr;
1353
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1354
176
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1355
1356
  /* Verify that the strings are null terminated.  */
1357
176
  if (ptr[size - 1] != 0
1358
167
      || (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
160
  import_name = source_dll + strlen (source_dll) + 1;
1374
160
  if ((bfd_byte *) import_name >= ptr + size)
1375
38
    {
1376
      /* If this points at the end of the ptr+size block, we only had
1377
   two strings. */
1378
38
      import_name = NULL;
1379
38
    }
1380
1381
  /* Now construct the bfd.  */
1382
160
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1383
160
          source_dll, ordinal, types,
1384
160
          import_name))
1385
41
    {
1386
41
      bfd_release (abfd, ptr);
1387
41
      return NULL;
1388
41
    }
1389
1390
119
  return pe_ILF_cleanup;
1391
160
}
Unexecuted instantiation: pei-ia64.c:pe_ILF_object_p
pei-loongarch64.c:pe_ILF_object_p
Line
Count
Source
1200
3.84k
{
1201
3.84k
  bfd_byte    buffer[14];
1202
3.84k
  bfd_byte *    ptr;
1203
3.84k
  char *    symbol_name;
1204
3.84k
  char *    source_dll;
1205
3.84k
  char *    import_name;
1206
3.84k
  unsigned int    machine;
1207
3.84k
  bfd_size_type   size;
1208
3.84k
  unsigned int    ordinal;
1209
3.84k
  unsigned int    types;
1210
3.84k
  unsigned int    magic;
1211
1212
  /* Upon entry the first six bytes of the ILF header have
1213
     already been read.  Now read the rest of the header.  */
1214
3.84k
  if (bfd_read (buffer, 14, abfd) != 14)
1215
64
    return NULL;
1216
1217
3.78k
  ptr = buffer;
1218
1219
3.78k
  machine = H_GET_16 (abfd, ptr);
1220
3.78k
  ptr += 2;
1221
1222
  /* Check that the machine type is recognised.  */
1223
3.78k
  magic = 0;
1224
1225
3.78k
  switch (machine)
1226
3.78k
    {
1227
14
    case IMAGE_FILE_MACHINE_UNKNOWN:
1228
19
    case IMAGE_FILE_MACHINE_ALPHA:
1229
25
    case IMAGE_FILE_MACHINE_ALPHA64:
1230
35
    case IMAGE_FILE_MACHINE_IA64:
1231
35
      break;
1232
1233
305
    case IMAGE_FILE_MACHINE_I386:
1234
#ifdef I386MAGIC
1235
      magic = I386MAGIC;
1236
#endif
1237
305
      break;
1238
1239
271
    case IMAGE_FILE_MACHINE_AMD64:
1240
#ifdef AMD64MAGIC
1241
      magic = AMD64MAGIC;
1242
#endif
1243
271
      break;
1244
1245
6
    case IMAGE_FILE_MACHINE_R3000:
1246
16
    case IMAGE_FILE_MACHINE_R4000:
1247
25
    case IMAGE_FILE_MACHINE_R10000:
1248
1249
30
    case IMAGE_FILE_MACHINE_MIPS16:
1250
39
    case IMAGE_FILE_MACHINE_MIPSFPU:
1251
49
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1252
#ifdef MIPS_ARCH_MAGIC_WINCE
1253
      magic = MIPS_ARCH_MAGIC_WINCE;
1254
#endif
1255
49
      break;
1256
1257
593
    case IMAGE_FILE_MACHINE_SH3:
1258
818
    case IMAGE_FILE_MACHINE_SH4:
1259
#ifdef SH_ARCH_MAGIC_WINCE
1260
      magic = SH_ARCH_MAGIC_WINCE;
1261
#endif
1262
818
      break;
1263
1264
197
    case IMAGE_FILE_MACHINE_ARM:
1265
#ifdef ARMPEMAGIC
1266
      magic = ARMPEMAGIC;
1267
#endif
1268
197
      break;
1269
1270
318
    case IMAGE_FILE_MACHINE_ARM64:
1271
#ifdef AARCH64MAGIC
1272
      magic = AARCH64MAGIC;
1273
#endif
1274
318
      break;
1275
1276
371
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1277
371
#ifdef LOONGARCH64MAGIC
1278
371
      magic = LOONGARCH64MAGIC;
1279
371
#endif
1280
371
      break;
1281
1282
321
    case IMAGE_FILE_MACHINE_RISCV64:
1283
#ifdef RISCV64MAGIC
1284
      magic = RISCV64MAGIC;
1285
#endif
1286
321
      break;
1287
1288
227
    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
227
      break;
1298
1299
0
    case IMAGE_FILE_MACHINE_POWERPC:
1300
      /* We no longer support PowerPC.  */
1301
868
    default:
1302
868
      _bfd_error_handler
1303
  /* xgettext:c-format */
1304
868
  (_("%pB: unrecognised machine type (0x%x)"
1305
868
     " in Import Library Format archive"),
1306
868
   abfd, machine);
1307
868
      bfd_set_error (bfd_error_malformed_archive);
1308
1309
868
      return NULL;
1310
0
      break;
1311
3.78k
    }
1312
1313
2.91k
  if (magic == 0)
1314
2.54k
    {
1315
2.54k
      _bfd_error_handler
1316
  /* xgettext:c-format */
1317
2.54k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1318
2.54k
     " in Import Library Format archive"),
1319
2.54k
   abfd, machine);
1320
2.54k
      bfd_set_error (bfd_error_wrong_format);
1321
1322
2.54k
      return NULL;
1323
2.54k
    }
1324
1325
  /* We do not bother to check the date.
1326
     date = H_GET_32 (abfd, ptr);  */
1327
371
  ptr += 4;
1328
1329
371
  size = H_GET_32 (abfd, ptr);
1330
371
  ptr += 4;
1331
1332
371
  if (size == 0)
1333
9
    {
1334
9
      _bfd_error_handler
1335
9
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1336
9
      bfd_set_error (bfd_error_malformed_archive);
1337
1338
9
      return NULL;
1339
9
    }
1340
1341
362
  ordinal = H_GET_16 (abfd, ptr);
1342
362
  ptr += 2;
1343
1344
362
  types = H_GET_16 (abfd, ptr);
1345
  /* ptr += 2; */
1346
1347
  /* Now read in the two strings that follow.  */
1348
362
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1349
362
  if (ptr == NULL)
1350
165
    return NULL;
1351
1352
197
  symbol_name = (char *) ptr;
1353
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1354
197
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1355
1356
  /* Verify that the strings are null terminated.  */
1357
197
  if (ptr[size - 1] != 0
1358
188
      || (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
181
  import_name = source_dll + strlen (source_dll) + 1;
1374
181
  if ((bfd_byte *) import_name >= ptr + size)
1375
66
    {
1376
      /* If this points at the end of the ptr+size block, we only had
1377
   two strings. */
1378
66
      import_name = NULL;
1379
66
    }
1380
1381
  /* Now construct the bfd.  */
1382
181
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1383
181
          source_dll, ordinal, types,
1384
181
          import_name))
1385
44
    {
1386
44
      bfd_release (abfd, ptr);
1387
44
      return NULL;
1388
44
    }
1389
1390
137
  return pe_ILF_cleanup;
1391
181
}
pei-riscv64.c:pe_ILF_object_p
Line
Count
Source
1200
3.85k
{
1201
3.85k
  bfd_byte    buffer[14];
1202
3.85k
  bfd_byte *    ptr;
1203
3.85k
  char *    symbol_name;
1204
3.85k
  char *    source_dll;
1205
3.85k
  char *    import_name;
1206
3.85k
  unsigned int    machine;
1207
3.85k
  bfd_size_type   size;
1208
3.85k
  unsigned int    ordinal;
1209
3.85k
  unsigned int    types;
1210
3.85k
  unsigned int    magic;
1211
1212
  /* Upon entry the first six bytes of the ILF header have
1213
     already been read.  Now read the rest of the header.  */
1214
3.85k
  if (bfd_read (buffer, 14, abfd) != 14)
1215
64
    return NULL;
1216
1217
3.79k
  ptr = buffer;
1218
1219
3.79k
  machine = H_GET_16 (abfd, ptr);
1220
3.79k
  ptr += 2;
1221
1222
  /* Check that the machine type is recognised.  */
1223
3.79k
  magic = 0;
1224
1225
3.79k
  switch (machine)
1226
3.79k
    {
1227
14
    case IMAGE_FILE_MACHINE_UNKNOWN:
1228
19
    case IMAGE_FILE_MACHINE_ALPHA:
1229
25
    case IMAGE_FILE_MACHINE_ALPHA64:
1230
35
    case IMAGE_FILE_MACHINE_IA64:
1231
35
      break;
1232
1233
305
    case IMAGE_FILE_MACHINE_I386:
1234
#ifdef I386MAGIC
1235
      magic = I386MAGIC;
1236
#endif
1237
305
      break;
1238
1239
277
    case IMAGE_FILE_MACHINE_AMD64:
1240
#ifdef AMD64MAGIC
1241
      magic = AMD64MAGIC;
1242
#endif
1243
277
      break;
1244
1245
6
    case IMAGE_FILE_MACHINE_R3000:
1246
16
    case IMAGE_FILE_MACHINE_R4000:
1247
25
    case IMAGE_FILE_MACHINE_R10000:
1248
1249
30
    case IMAGE_FILE_MACHINE_MIPS16:
1250
39
    case IMAGE_FILE_MACHINE_MIPSFPU:
1251
49
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1252
#ifdef MIPS_ARCH_MAGIC_WINCE
1253
      magic = MIPS_ARCH_MAGIC_WINCE;
1254
#endif
1255
49
      break;
1256
1257
602
    case IMAGE_FILE_MACHINE_SH3:
1258
830
    case IMAGE_FILE_MACHINE_SH4:
1259
#ifdef SH_ARCH_MAGIC_WINCE
1260
      magic = SH_ARCH_MAGIC_WINCE;
1261
#endif
1262
830
      break;
1263
1264
197
    case IMAGE_FILE_MACHINE_ARM:
1265
#ifdef ARMPEMAGIC
1266
      magic = ARMPEMAGIC;
1267
#endif
1268
197
      break;
1269
1270
318
    case IMAGE_FILE_MACHINE_ARM64:
1271
#ifdef AARCH64MAGIC
1272
      magic = AARCH64MAGIC;
1273
#endif
1274
318
      break;
1275
1276
318
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1277
#ifdef LOONGARCH64MAGIC
1278
      magic = LOONGARCH64MAGIC;
1279
#endif
1280
318
      break;
1281
1282
371
    case IMAGE_FILE_MACHINE_RISCV64:
1283
371
#ifdef RISCV64MAGIC
1284
371
      magic = RISCV64MAGIC;
1285
371
#endif
1286
371
      break;
1287
1288
227
    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
227
      break;
1298
1299
0
    case IMAGE_FILE_MACHINE_POWERPC:
1300
      /* We no longer support PowerPC.  */
1301
868
    default:
1302
868
      _bfd_error_handler
1303
  /* xgettext:c-format */
1304
868
  (_("%pB: unrecognised machine type (0x%x)"
1305
868
     " in Import Library Format archive"),
1306
868
   abfd, machine);
1307
868
      bfd_set_error (bfd_error_malformed_archive);
1308
1309
868
      return NULL;
1310
0
      break;
1311
3.79k
    }
1312
1313
2.92k
  if (magic == 0)
1314
2.55k
    {
1315
2.55k
      _bfd_error_handler
1316
  /* xgettext:c-format */
1317
2.55k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1318
2.55k
     " in Import Library Format archive"),
1319
2.55k
   abfd, machine);
1320
2.55k
      bfd_set_error (bfd_error_wrong_format);
1321
1322
2.55k
      return NULL;
1323
2.55k
    }
1324
1325
  /* We do not bother to check the date.
1326
     date = H_GET_32 (abfd, ptr);  */
1327
371
  ptr += 4;
1328
1329
371
  size = H_GET_32 (abfd, ptr);
1330
371
  ptr += 4;
1331
1332
371
  if (size == 0)
1333
9
    {
1334
9
      _bfd_error_handler
1335
9
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1336
9
      bfd_set_error (bfd_error_malformed_archive);
1337
1338
9
      return NULL;
1339
9
    }
1340
1341
362
  ordinal = H_GET_16 (abfd, ptr);
1342
362
  ptr += 2;
1343
1344
362
  types = H_GET_16 (abfd, ptr);
1345
  /* ptr += 2; */
1346
1347
  /* Now read in the two strings that follow.  */
1348
362
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1349
362
  if (ptr == NULL)
1350
184
    return NULL;
1351
1352
178
  symbol_name = (char *) ptr;
1353
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1354
178
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1355
1356
  /* Verify that the strings are null terminated.  */
1357
178
  if (ptr[size - 1] != 0
1358
169
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1359
18
    {
1360
18
      _bfd_error_handler
1361
18
  (_("%pB: string not null terminated in ILF object file"), abfd);
1362
18
      bfd_set_error (bfd_error_malformed_archive);
1363
18
      bfd_release (abfd, ptr);
1364
18
      return NULL;
1365
18
    }
1366
1367
  /* An ILF file may contain a third string, after source_dll; this is
1368
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1369
     block of data is null terminated, ptr[size-1]==0, but we don't
1370
     know how many individual null terminated strings we have in there.
1371
1372
     First find the end of source_dll.  */
1373
160
  import_name = source_dll + strlen (source_dll) + 1;
1374
160
  if ((bfd_byte *) import_name >= ptr + size)
1375
30
    {
1376
      /* If this points at the end of the ptr+size block, we only had
1377
   two strings. */
1378
30
      import_name = NULL;
1379
30
    }
1380
1381
  /* Now construct the bfd.  */
1382
160
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1383
160
          source_dll, ordinal, types,
1384
160
          import_name))
1385
40
    {
1386
40
      bfd_release (abfd, ptr);
1387
40
      return NULL;
1388
40
    }
1389
1390
120
  return pe_ILF_cleanup;
1391
160
}
pei-arm-wince.c:pe_ILF_object_p
Line
Count
Source
1200
3.56k
{
1201
3.56k
  bfd_byte    buffer[14];
1202
3.56k
  bfd_byte *    ptr;
1203
3.56k
  char *    symbol_name;
1204
3.56k
  char *    source_dll;
1205
3.56k
  char *    import_name;
1206
3.56k
  unsigned int    machine;
1207
3.56k
  bfd_size_type   size;
1208
3.56k
  unsigned int    ordinal;
1209
3.56k
  unsigned int    types;
1210
3.56k
  unsigned int    magic;
1211
1212
  /* Upon entry the first six bytes of the ILF header have
1213
     already been read.  Now read the rest of the header.  */
1214
3.56k
  if (bfd_read (buffer, 14, abfd) != 14)
1215
67
    return NULL;
1216
1217
3.49k
  ptr = buffer;
1218
1219
3.49k
  machine = H_GET_16 (abfd, ptr);
1220
3.49k
  ptr += 2;
1221
1222
  /* Check that the machine type is recognised.  */
1223
3.49k
  magic = 0;
1224
1225
3.49k
  switch (machine)
1226
3.49k
    {
1227
17
    case IMAGE_FILE_MACHINE_UNKNOWN:
1228
22
    case IMAGE_FILE_MACHINE_ALPHA:
1229
28
    case IMAGE_FILE_MACHINE_ALPHA64:
1230
37
    case IMAGE_FILE_MACHINE_IA64:
1231
37
      break;
1232
1233
287
    case IMAGE_FILE_MACHINE_I386:
1234
#ifdef I386MAGIC
1235
      magic = I386MAGIC;
1236
#endif
1237
287
      break;
1238
1239
256
    case IMAGE_FILE_MACHINE_AMD64:
1240
#ifdef AMD64MAGIC
1241
      magic = AMD64MAGIC;
1242
#endif
1243
256
      break;
1244
1245
6
    case IMAGE_FILE_MACHINE_R3000:
1246
15
    case IMAGE_FILE_MACHINE_R4000:
1247
23
    case IMAGE_FILE_MACHINE_R10000:
1248
1249
28
    case IMAGE_FILE_MACHINE_MIPS16:
1250
37
    case IMAGE_FILE_MACHINE_MIPSFPU:
1251
46
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1252
#ifdef MIPS_ARCH_MAGIC_WINCE
1253
      magic = MIPS_ARCH_MAGIC_WINCE;
1254
#endif
1255
46
      break;
1256
1257
596
    case IMAGE_FILE_MACHINE_SH3:
1258
790
    case IMAGE_FILE_MACHINE_SH4:
1259
#ifdef SH_ARCH_MAGIC_WINCE
1260
      magic = SH_ARCH_MAGIC_WINCE;
1261
#endif
1262
790
      break;
1263
1264
213
    case IMAGE_FILE_MACHINE_ARM:
1265
213
#ifdef ARMPEMAGIC
1266
213
      magic = ARMPEMAGIC;
1267
213
#endif
1268
213
      break;
1269
1270
286
    case IMAGE_FILE_MACHINE_ARM64:
1271
#ifdef AARCH64MAGIC
1272
      magic = AARCH64MAGIC;
1273
#endif
1274
286
      break;
1275
1276
282
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1277
#ifdef LOONGARCH64MAGIC
1278
      magic = LOONGARCH64MAGIC;
1279
#endif
1280
282
      break;
1281
1282
297
    case IMAGE_FILE_MACHINE_RISCV64:
1283
#ifdef RISCV64MAGIC
1284
      magic = RISCV64MAGIC;
1285
#endif
1286
297
      break;
1287
1288
207
    case IMAGE_FILE_MACHINE_THUMB:
1289
207
#ifdef THUMBPEMAGIC
1290
207
      {
1291
207
  extern const bfd_target TARGET_LITTLE_SYM;
1292
1293
207
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1294
204
    magic = THUMBPEMAGIC;
1295
207
      }
1296
207
#endif
1297
207
      break;
1298
1299
0
    case IMAGE_FILE_MACHINE_POWERPC:
1300
      /* We no longer support PowerPC.  */
1301
796
    default:
1302
796
      _bfd_error_handler
1303
  /* xgettext:c-format */
1304
796
  (_("%pB: unrecognised machine type (0x%x)"
1305
796
     " in Import Library Format archive"),
1306
796
   abfd, machine);
1307
796
      bfd_set_error (bfd_error_malformed_archive);
1308
1309
796
      return NULL;
1310
0
      break;
1311
3.49k
    }
1312
1313
2.70k
  if (magic == 0)
1314
2.28k
    {
1315
2.28k
      _bfd_error_handler
1316
  /* xgettext:c-format */
1317
2.28k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1318
2.28k
     " in Import Library Format archive"),
1319
2.28k
   abfd, machine);
1320
2.28k
      bfd_set_error (bfd_error_wrong_format);
1321
1322
2.28k
      return NULL;
1323
2.28k
    }
1324
1325
  /* We do not bother to check the date.
1326
     date = H_GET_32 (abfd, ptr);  */
1327
417
  ptr += 4;
1328
1329
417
  size = H_GET_32 (abfd, ptr);
1330
417
  ptr += 4;
1331
1332
417
  if (size == 0)
1333
10
    {
1334
10
      _bfd_error_handler
1335
10
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1336
10
      bfd_set_error (bfd_error_malformed_archive);
1337
1338
10
      return NULL;
1339
10
    }
1340
1341
407
  ordinal = H_GET_16 (abfd, ptr);
1342
407
  ptr += 2;
1343
1344
407
  types = H_GET_16 (abfd, ptr);
1345
  /* ptr += 2; */
1346
1347
  /* Now read in the two strings that follow.  */
1348
407
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1349
407
  if (ptr == NULL)
1350
241
    return NULL;
1351
1352
166
  symbol_name = (char *) ptr;
1353
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1354
166
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1355
1356
  /* Verify that the strings are null terminated.  */
1357
166
  if (ptr[size - 1] != 0
1358
153
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1359
22
    {
1360
22
      _bfd_error_handler
1361
22
  (_("%pB: string not null terminated in ILF object file"), abfd);
1362
22
      bfd_set_error (bfd_error_malformed_archive);
1363
22
      bfd_release (abfd, ptr);
1364
22
      return NULL;
1365
22
    }
1366
1367
  /* An ILF file may contain a third string, after source_dll; this is
1368
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1369
     block of data is null terminated, ptr[size-1]==0, but we don't
1370
     know how many individual null terminated strings we have in there.
1371
1372
     First find the end of source_dll.  */
1373
144
  import_name = source_dll + strlen (source_dll) + 1;
1374
144
  if ((bfd_byte *) import_name >= ptr + size)
1375
66
    {
1376
      /* If this points at the end of the ptr+size block, we only had
1377
   two strings. */
1378
66
      import_name = NULL;
1379
66
    }
1380
1381
  /* Now construct the bfd.  */
1382
144
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1383
144
          source_dll, ordinal, types,
1384
144
          import_name))
1385
48
    {
1386
48
      bfd_release (abfd, ptr);
1387
48
      return NULL;
1388
48
    }
1389
1390
96
  return pe_ILF_cleanup;
1391
144
}
pei-arm.c:pe_ILF_object_p
Line
Count
Source
1200
3.56k
{
1201
3.56k
  bfd_byte    buffer[14];
1202
3.56k
  bfd_byte *    ptr;
1203
3.56k
  char *    symbol_name;
1204
3.56k
  char *    source_dll;
1205
3.56k
  char *    import_name;
1206
3.56k
  unsigned int    machine;
1207
3.56k
  bfd_size_type   size;
1208
3.56k
  unsigned int    ordinal;
1209
3.56k
  unsigned int    types;
1210
3.56k
  unsigned int    magic;
1211
1212
  /* Upon entry the first six bytes of the ILF header have
1213
     already been read.  Now read the rest of the header.  */
1214
3.56k
  if (bfd_read (buffer, 14, abfd) != 14)
1215
67
    return NULL;
1216
1217
3.49k
  ptr = buffer;
1218
1219
3.49k
  machine = H_GET_16 (abfd, ptr);
1220
3.49k
  ptr += 2;
1221
1222
  /* Check that the machine type is recognised.  */
1223
3.49k
  magic = 0;
1224
1225
3.49k
  switch (machine)
1226
3.49k
    {
1227
17
    case IMAGE_FILE_MACHINE_UNKNOWN:
1228
22
    case IMAGE_FILE_MACHINE_ALPHA:
1229
28
    case IMAGE_FILE_MACHINE_ALPHA64:
1230
37
    case IMAGE_FILE_MACHINE_IA64:
1231
37
      break;
1232
1233
287
    case IMAGE_FILE_MACHINE_I386:
1234
#ifdef I386MAGIC
1235
      magic = I386MAGIC;
1236
#endif
1237
287
      break;
1238
1239
256
    case IMAGE_FILE_MACHINE_AMD64:
1240
#ifdef AMD64MAGIC
1241
      magic = AMD64MAGIC;
1242
#endif
1243
256
      break;
1244
1245
6
    case IMAGE_FILE_MACHINE_R3000:
1246
15
    case IMAGE_FILE_MACHINE_R4000:
1247
23
    case IMAGE_FILE_MACHINE_R10000:
1248
1249
28
    case IMAGE_FILE_MACHINE_MIPS16:
1250
37
    case IMAGE_FILE_MACHINE_MIPSFPU:
1251
46
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1252
#ifdef MIPS_ARCH_MAGIC_WINCE
1253
      magic = MIPS_ARCH_MAGIC_WINCE;
1254
#endif
1255
46
      break;
1256
1257
596
    case IMAGE_FILE_MACHINE_SH3:
1258
790
    case IMAGE_FILE_MACHINE_SH4:
1259
#ifdef SH_ARCH_MAGIC_WINCE
1260
      magic = SH_ARCH_MAGIC_WINCE;
1261
#endif
1262
790
      break;
1263
1264
215
    case IMAGE_FILE_MACHINE_ARM:
1265
215
#ifdef ARMPEMAGIC
1266
215
      magic = ARMPEMAGIC;
1267
215
#endif
1268
215
      break;
1269
1270
286
    case IMAGE_FILE_MACHINE_ARM64:
1271
#ifdef AARCH64MAGIC
1272
      magic = AARCH64MAGIC;
1273
#endif
1274
286
      break;
1275
1276
282
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1277
#ifdef LOONGARCH64MAGIC
1278
      magic = LOONGARCH64MAGIC;
1279
#endif
1280
282
      break;
1281
1282
297
    case IMAGE_FILE_MACHINE_RISCV64:
1283
#ifdef RISCV64MAGIC
1284
      magic = RISCV64MAGIC;
1285
#endif
1286
297
      break;
1287
1288
207
    case IMAGE_FILE_MACHINE_THUMB:
1289
207
#ifdef THUMBPEMAGIC
1290
207
      {
1291
207
  extern const bfd_target TARGET_LITTLE_SYM;
1292
1293
207
  if (abfd->xvec == &TARGET_LITTLE_SYM)
1294
204
    magic = THUMBPEMAGIC;
1295
207
      }
1296
207
#endif
1297
207
      break;
1298
1299
0
    case IMAGE_FILE_MACHINE_POWERPC:
1300
      /* We no longer support PowerPC.  */
1301
796
    default:
1302
796
      _bfd_error_handler
1303
  /* xgettext:c-format */
1304
796
  (_("%pB: unrecognised machine type (0x%x)"
1305
796
     " in Import Library Format archive"),
1306
796
   abfd, machine);
1307
796
      bfd_set_error (bfd_error_malformed_archive);
1308
1309
796
      return NULL;
1310
0
      break;
1311
3.49k
    }
1312
1313
2.70k
  if (magic == 0)
1314
2.28k
    {
1315
2.28k
      _bfd_error_handler
1316
  /* xgettext:c-format */
1317
2.28k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1318
2.28k
     " in Import Library Format archive"),
1319
2.28k
   abfd, machine);
1320
2.28k
      bfd_set_error (bfd_error_wrong_format);
1321
1322
2.28k
      return NULL;
1323
2.28k
    }
1324
1325
  /* We do not bother to check the date.
1326
     date = H_GET_32 (abfd, ptr);  */
1327
419
  ptr += 4;
1328
1329
419
  size = H_GET_32 (abfd, ptr);
1330
419
  ptr += 4;
1331
1332
419
  if (size == 0)
1333
10
    {
1334
10
      _bfd_error_handler
1335
10
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1336
10
      bfd_set_error (bfd_error_malformed_archive);
1337
1338
10
      return NULL;
1339
10
    }
1340
1341
409
  ordinal = H_GET_16 (abfd, ptr);
1342
409
  ptr += 2;
1343
1344
409
  types = H_GET_16 (abfd, ptr);
1345
  /* ptr += 2; */
1346
1347
  /* Now read in the two strings that follow.  */
1348
409
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1349
409
  if (ptr == NULL)
1350
241
    return NULL;
1351
1352
168
  symbol_name = (char *) ptr;
1353
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1354
168
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1355
1356
  /* Verify that the strings are null terminated.  */
1357
168
  if (ptr[size - 1] != 0
1358
155
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1359
22
    {
1360
22
      _bfd_error_handler
1361
22
  (_("%pB: string not null terminated in ILF object file"), abfd);
1362
22
      bfd_set_error (bfd_error_malformed_archive);
1363
22
      bfd_release (abfd, ptr);
1364
22
      return NULL;
1365
22
    }
1366
1367
  /* An ILF file may contain a third string, after source_dll; this is
1368
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1369
     block of data is null terminated, ptr[size-1]==0, but we don't
1370
     know how many individual null terminated strings we have in there.
1371
1372
     First find the end of source_dll.  */
1373
146
  import_name = source_dll + strlen (source_dll) + 1;
1374
146
  if ((bfd_byte *) import_name >= ptr + size)
1375
67
    {
1376
      /* If this points at the end of the ptr+size block, we only had
1377
   two strings. */
1378
67
      import_name = NULL;
1379
67
    }
1380
1381
  /* Now construct the bfd.  */
1382
146
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1383
146
          source_dll, ordinal, types,
1384
146
          import_name))
1385
48
    {
1386
48
      bfd_release (abfd, ptr);
1387
48
      return NULL;
1388
48
    }
1389
1390
98
  return pe_ILF_cleanup;
1391
146
}
pei-mcore.c:pe_ILF_object_p
Line
Count
Source
1200
3.56k
{
1201
3.56k
  bfd_byte    buffer[14];
1202
3.56k
  bfd_byte *    ptr;
1203
3.56k
  char *    symbol_name;
1204
3.56k
  char *    source_dll;
1205
3.56k
  char *    import_name;
1206
3.56k
  unsigned int    machine;
1207
3.56k
  bfd_size_type   size;
1208
3.56k
  unsigned int    ordinal;
1209
3.56k
  unsigned int    types;
1210
3.56k
  unsigned int    magic;
1211
1212
  /* Upon entry the first six bytes of the ILF header have
1213
     already been read.  Now read the rest of the header.  */
1214
3.56k
  if (bfd_read (buffer, 14, abfd) != 14)
1215
67
    return NULL;
1216
1217
3.49k
  ptr = buffer;
1218
1219
3.49k
  machine = H_GET_16 (abfd, ptr);
1220
3.49k
  ptr += 2;
1221
1222
  /* Check that the machine type is recognised.  */
1223
3.49k
  magic = 0;
1224
1225
3.49k
  switch (machine)
1226
3.49k
    {
1227
17
    case IMAGE_FILE_MACHINE_UNKNOWN:
1228
22
    case IMAGE_FILE_MACHINE_ALPHA:
1229
28
    case IMAGE_FILE_MACHINE_ALPHA64:
1230
37
    case IMAGE_FILE_MACHINE_IA64:
1231
37
      break;
1232
1233
284
    case IMAGE_FILE_MACHINE_I386:
1234
#ifdef I386MAGIC
1235
      magic = I386MAGIC;
1236
#endif
1237
284
      break;
1238
1239
256
    case IMAGE_FILE_MACHINE_AMD64:
1240
#ifdef AMD64MAGIC
1241
      magic = AMD64MAGIC;
1242
#endif
1243
256
      break;
1244
1245
6
    case IMAGE_FILE_MACHINE_R3000:
1246
15
    case IMAGE_FILE_MACHINE_R4000:
1247
23
    case IMAGE_FILE_MACHINE_R10000:
1248
1249
28
    case IMAGE_FILE_MACHINE_MIPS16:
1250
37
    case IMAGE_FILE_MACHINE_MIPSFPU:
1251
46
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1252
#ifdef MIPS_ARCH_MAGIC_WINCE
1253
      magic = MIPS_ARCH_MAGIC_WINCE;
1254
#endif
1255
46
      break;
1256
1257
596
    case IMAGE_FILE_MACHINE_SH3:
1258
790
    case IMAGE_FILE_MACHINE_SH4:
1259
#ifdef SH_ARCH_MAGIC_WINCE
1260
      magic = SH_ARCH_MAGIC_WINCE;
1261
#endif
1262
790
      break;
1263
1264
213
    case IMAGE_FILE_MACHINE_ARM:
1265
#ifdef ARMPEMAGIC
1266
      magic = ARMPEMAGIC;
1267
#endif
1268
213
      break;
1269
1270
286
    case IMAGE_FILE_MACHINE_ARM64:
1271
#ifdef AARCH64MAGIC
1272
      magic = AARCH64MAGIC;
1273
#endif
1274
286
      break;
1275
1276
282
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1277
#ifdef LOONGARCH64MAGIC
1278
      magic = LOONGARCH64MAGIC;
1279
#endif
1280
282
      break;
1281
1282
297
    case IMAGE_FILE_MACHINE_RISCV64:
1283
#ifdef RISCV64MAGIC
1284
      magic = RISCV64MAGIC;
1285
#endif
1286
297
      break;
1287
1288
207
    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
207
      break;
1298
1299
0
    case IMAGE_FILE_MACHINE_POWERPC:
1300
      /* We no longer support PowerPC.  */
1301
796
    default:
1302
796
      _bfd_error_handler
1303
  /* xgettext:c-format */
1304
796
  (_("%pB: unrecognised machine type (0x%x)"
1305
796
     " in Import Library Format archive"),
1306
796
   abfd, machine);
1307
796
      bfd_set_error (bfd_error_malformed_archive);
1308
1309
796
      return NULL;
1310
0
      break;
1311
3.49k
    }
1312
1313
2.69k
  if (magic == 0)
1314
2.69k
    {
1315
2.69k
      _bfd_error_handler
1316
  /* xgettext:c-format */
1317
2.69k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1318
2.69k
     " in Import Library Format archive"),
1319
2.69k
   abfd, machine);
1320
2.69k
      bfd_set_error (bfd_error_wrong_format);
1321
1322
2.69k
      return NULL;
1323
2.69k
    }
1324
1325
  /* We do not bother to check the date.
1326
     date = H_GET_32 (abfd, ptr);  */
1327
0
  ptr += 4;
1328
1329
0
  size = H_GET_32 (abfd, ptr);
1330
0
  ptr += 4;
1331
1332
0
  if (size == 0)
1333
0
    {
1334
0
      _bfd_error_handler
1335
0
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1336
0
      bfd_set_error (bfd_error_malformed_archive);
1337
1338
0
      return NULL;
1339
0
    }
1340
1341
0
  ordinal = H_GET_16 (abfd, ptr);
1342
0
  ptr += 2;
1343
1344
0
  types = H_GET_16 (abfd, ptr);
1345
  /* ptr += 2; */
1346
1347
  /* Now read in the two strings that follow.  */
1348
0
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1349
0
  if (ptr == NULL)
1350
0
    return NULL;
1351
1352
0
  symbol_name = (char *) ptr;
1353
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1354
0
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1355
1356
  /* Verify that the strings are null terminated.  */
1357
0
  if (ptr[size - 1] != 0
1358
0
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1359
0
    {
1360
0
      _bfd_error_handler
1361
0
  (_("%pB: string not null terminated in ILF object file"), abfd);
1362
0
      bfd_set_error (bfd_error_malformed_archive);
1363
0
      bfd_release (abfd, ptr);
1364
0
      return NULL;
1365
0
    }
1366
1367
  /* An ILF file may contain a third string, after source_dll; this is
1368
     used for IMPORT_NAME_EXPORTAS. We know from above that the whole
1369
     block of data is null terminated, ptr[size-1]==0, but we don't
1370
     know how many individual null terminated strings we have in there.
1371
1372
     First find the end of source_dll.  */
1373
0
  import_name = source_dll + strlen (source_dll) + 1;
1374
0
  if ((bfd_byte *) import_name >= ptr + size)
1375
0
    {
1376
      /* If this points at the end of the ptr+size block, we only had
1377
   two strings. */
1378
0
      import_name = NULL;
1379
0
    }
1380
1381
  /* Now construct the bfd.  */
1382
0
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1383
0
          source_dll, ordinal, types,
1384
0
          import_name))
1385
0
    {
1386
0
      bfd_release (abfd, ptr);
1387
0
      return NULL;
1388
0
    }
1389
1390
0
  return pe_ILF_cleanup;
1391
0
}
pei-sh.c:pe_ILF_object_p
Line
Count
Source
1200
3.52k
{
1201
3.52k
  bfd_byte    buffer[14];
1202
3.52k
  bfd_byte *    ptr;
1203
3.52k
  char *    symbol_name;
1204
3.52k
  char *    source_dll;
1205
3.52k
  char *    import_name;
1206
3.52k
  unsigned int    machine;
1207
3.52k
  bfd_size_type   size;
1208
3.52k
  unsigned int    ordinal;
1209
3.52k
  unsigned int    types;
1210
3.52k
  unsigned int    magic;
1211
1212
  /* Upon entry the first six bytes of the ILF header have
1213
     already been read.  Now read the rest of the header.  */
1214
3.52k
  if (bfd_read (buffer, 14, abfd) != 14)
1215
59
    return NULL;
1216
1217
3.46k
  ptr = buffer;
1218
1219
3.46k
  machine = H_GET_16 (abfd, ptr);
1220
3.46k
  ptr += 2;
1221
1222
  /* Check that the machine type is recognised.  */
1223
3.46k
  magic = 0;
1224
1225
3.46k
  switch (machine)
1226
3.46k
    {
1227
13
    case IMAGE_FILE_MACHINE_UNKNOWN:
1228
18
    case IMAGE_FILE_MACHINE_ALPHA:
1229
24
    case IMAGE_FILE_MACHINE_ALPHA64:
1230
33
    case IMAGE_FILE_MACHINE_IA64:
1231
33
      break;
1232
1233
284
    case IMAGE_FILE_MACHINE_I386:
1234
#ifdef I386MAGIC
1235
      magic = I386MAGIC;
1236
#endif
1237
284
      break;
1238
1239
256
    case IMAGE_FILE_MACHINE_AMD64:
1240
#ifdef AMD64MAGIC
1241
      magic = AMD64MAGIC;
1242
#endif
1243
256
      break;
1244
1245
5
    case IMAGE_FILE_MACHINE_R3000:
1246
14
    case IMAGE_FILE_MACHINE_R4000:
1247
22
    case IMAGE_FILE_MACHINE_R10000:
1248
1249
27
    case IMAGE_FILE_MACHINE_MIPS16:
1250
36
    case IMAGE_FILE_MACHINE_MIPSFPU:
1251
45
    case IMAGE_FILE_MACHINE_MIPSFPU16:
1252
#ifdef MIPS_ARCH_MAGIC_WINCE
1253
      magic = MIPS_ARCH_MAGIC_WINCE;
1254
#endif
1255
45
      break;
1256
1257
629
    case IMAGE_FILE_MACHINE_SH3:
1258
852
    case IMAGE_FILE_MACHINE_SH4:
1259
852
#ifdef SH_ARCH_MAGIC_WINCE
1260
852
      magic = SH_ARCH_MAGIC_WINCE;
1261
852
#endif
1262
852
      break;
1263
1264
175
    case IMAGE_FILE_MACHINE_ARM:
1265
#ifdef ARMPEMAGIC
1266
      magic = ARMPEMAGIC;
1267
#endif
1268
175
      break;
1269
1270
286
    case IMAGE_FILE_MACHINE_ARM64:
1271
#ifdef AARCH64MAGIC
1272
      magic = AARCH64MAGIC;
1273
#endif
1274
286
      break;
1275
1276
282
    case IMAGE_FILE_MACHINE_LOONGARCH64:
1277
#ifdef LOONGARCH64MAGIC
1278
      magic = LOONGARCH64MAGIC;
1279
#endif
1280
282
      break;
1281
1282
295
    case IMAGE_FILE_MACHINE_RISCV64:
1283
#ifdef RISCV64MAGIC
1284
      magic = RISCV64MAGIC;
1285
#endif
1286
295
      break;
1287
1288
204
    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
204
      break;
1298
1299
0
    case IMAGE_FILE_MACHINE_POWERPC:
1300
      /* We no longer support PowerPC.  */
1301
755
    default:
1302
755
      _bfd_error_handler
1303
  /* xgettext:c-format */
1304
755
  (_("%pB: unrecognised machine type (0x%x)"
1305
755
     " in Import Library Format archive"),
1306
755
   abfd, machine);
1307
755
      bfd_set_error (bfd_error_malformed_archive);
1308
1309
755
      return NULL;
1310
0
      break;
1311
3.46k
    }
1312
1313
2.71k
  if (magic == 0)
1314
1.86k
    {
1315
1.86k
      _bfd_error_handler
1316
  /* xgettext:c-format */
1317
1.86k
  (_("%pB: recognised but unhandled machine type (0x%x)"
1318
1.86k
     " in Import Library Format archive"),
1319
1.86k
   abfd, machine);
1320
1.86k
      bfd_set_error (bfd_error_wrong_format);
1321
1322
1.86k
      return NULL;
1323
1.86k
    }
1324
1325
  /* We do not bother to check the date.
1326
     date = H_GET_32 (abfd, ptr);  */
1327
852
  ptr += 4;
1328
1329
852
  size = H_GET_32 (abfd, ptr);
1330
852
  ptr += 4;
1331
1332
852
  if (size == 0)
1333
12
    {
1334
12
      _bfd_error_handler
1335
12
  (_("%pB: size field is zero in Import Library Format header"), abfd);
1336
12
      bfd_set_error (bfd_error_malformed_archive);
1337
1338
12
      return NULL;
1339
12
    }
1340
1341
840
  ordinal = H_GET_16 (abfd, ptr);
1342
840
  ptr += 2;
1343
1344
840
  types = H_GET_16 (abfd, ptr);
1345
  /* ptr += 2; */
1346
1347
  /* Now read in the two strings that follow.  */
1348
840
  ptr = (bfd_byte *) _bfd_alloc_and_read (abfd, size, size);
1349
840
  if (ptr == NULL)
1350
196
    return NULL;
1351
1352
644
  symbol_name = (char *) ptr;
1353
  /* See PR 20905 for an example of where the strnlen is necessary.  */
1354
644
  source_dll  = symbol_name + strnlen (symbol_name, size - 1) + 1;
1355
1356
  /* Verify that the strings are null terminated.  */
1357
644
  if (ptr[size - 1] != 0
1358
238
      || (bfd_size_type) ((bfd_byte *) source_dll - ptr) >= size)
1359
413
    {
1360
413
      _bfd_error_handler
1361
413
  (_("%pB: string not null terminated in ILF object file"), abfd);
1362
413
      bfd_set_error (bfd_error_malformed_archive);
1363
413
      bfd_release (abfd, ptr);
1364
413
      return NULL;
1365
413
    }
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
231
  import_name = source_dll + strlen (source_dll) + 1;
1374
231
  if ((bfd_byte *) import_name >= ptr + size)
1375
69
    {
1376
      /* If this points at the end of the ptr+size block, we only had
1377
   two strings. */
1378
69
      import_name = NULL;
1379
69
    }
1380
1381
  /* Now construct the bfd.  */
1382
231
  if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
1383
231
          source_dll, ordinal, types,
1384
231
          import_name))
1385
83
    {
1386
83
      bfd_release (abfd, ptr);
1387
83
      return NULL;
1388
83
    }
1389
1390
148
  return pe_ILF_cleanup;
1391
231
}
1392
1393
static void
1394
pe_bfd_read_buildid (bfd *abfd)
1395
42.4k
{
1396
42.4k
  pe_data_type *pe = pe_data (abfd);
1397
42.4k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
42.4k
  asection *section;
1399
42.4k
  bfd_byte *data = 0;
1400
42.4k
  bfd_size_type dataoff;
1401
42.4k
  unsigned int i;
1402
42.4k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
42.4k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
42.4k
  if (size == 0)
1406
25.9k
    return;
1407
1408
16.4k
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
118k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
109k
    {
1413
109k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
8.20k
  break;
1415
109k
    }
1416
1417
16.4k
  if (section == NULL)
1418
8.29k
    return;
1419
1420
8.20k
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
442
    return;
1422
1423
7.76k
  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.76k
  if (dataoff >= section->size
1429
7.76k
      || size > section->size - dataoff)
1430
2.49k
    {
1431
2.49k
      _bfd_error_handler
1432
2.49k
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
2.49k
   abfd);
1434
2.49k
      return;
1435
2.49k
    }
1436
1437
  /* Read the whole section. */
1438
5.27k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
1.50k
    {
1440
1.50k
      free (data);
1441
1.50k
      return;
1442
1.50k
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
260k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
257k
    {
1447
257k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
257k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
257k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
257k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
257k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
1.53k
  {
1455
1.53k
    char buffer[256 + 1];
1456
1.53k
    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.53k
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
1.53k
                (file_ptr) idd.PointerToRawData,
1464
1.53k
                idd.SizeOfData, cvinfo, NULL))
1465
104
      {
1466
104
        struct bfd_build_id *build_id;
1467
104
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1468
1469
104
        build_id = bfd_alloc (abfd, bidlen);
1470
104
        if (build_id)
1471
104
    {
1472
104
      build_id->size = cvinfo->SignatureLength;
1473
104
      memcpy(build_id->data, cvinfo->Signature,
1474
104
       cvinfo->SignatureLength);
1475
104
      abfd->build_id = build_id;
1476
104
    }
1477
104
      }
1478
1.53k
    break;
1479
1.53k
  }
1480
257k
    }
1481
1482
3.77k
  free (data);
1483
3.77k
}
pei-i386.c:pe_bfd_read_buildid
Line
Count
Source
1395
8.52k
{
1396
8.52k
  pe_data_type *pe = pe_data (abfd);
1397
8.52k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
8.52k
  asection *section;
1399
8.52k
  bfd_byte *data = 0;
1400
8.52k
  bfd_size_type dataoff;
1401
8.52k
  unsigned int i;
1402
8.52k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
8.52k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
8.52k
  if (size == 0)
1406
6.59k
    return;
1407
1408
1.93k
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
12.5k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
11.5k
    {
1413
11.5k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
888
  break;
1415
11.5k
    }
1416
1417
1.93k
  if (section == NULL)
1418
1.04k
    return;
1419
1420
888
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
75
    return;
1422
1423
813
  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
813
  if (dataoff >= section->size
1429
813
      || size > section->size - dataoff)
1430
363
    {
1431
363
      _bfd_error_handler
1432
363
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
363
   abfd);
1434
363
      return;
1435
363
    }
1436
1437
  /* Read the whole section. */
1438
450
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
189
    {
1440
189
      free (data);
1441
189
      return;
1442
189
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
5.30k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
5.18k
    {
1447
5.18k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
5.18k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
5.18k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
5.18k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
5.18k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
146
  {
1455
146
    char buffer[256 + 1];
1456
146
    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
146
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
146
                (file_ptr) idd.PointerToRawData,
1464
146
                idd.SizeOfData, cvinfo, NULL))
1465
14
      {
1466
14
        struct bfd_build_id *build_id;
1467
14
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1468
1469
14
        build_id = bfd_alloc (abfd, bidlen);
1470
14
        if (build_id)
1471
14
    {
1472
14
      build_id->size = cvinfo->SignatureLength;
1473
14
      memcpy(build_id->data, cvinfo->Signature,
1474
14
       cvinfo->SignatureLength);
1475
14
      abfd->build_id = build_id;
1476
14
    }
1477
14
      }
1478
146
    break;
1479
146
  }
1480
5.18k
    }
1481
1482
261
  free (data);
1483
261
}
pei-x86_64.c:pe_bfd_read_buildid
Line
Count
Source
1395
5.44k
{
1396
5.44k
  pe_data_type *pe = pe_data (abfd);
1397
5.44k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
5.44k
  asection *section;
1399
5.44k
  bfd_byte *data = 0;
1400
5.44k
  bfd_size_type dataoff;
1401
5.44k
  unsigned int i;
1402
5.44k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
5.44k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
5.44k
  if (size == 0)
1406
3.76k
    return;
1407
1408
1.68k
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
23.3k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
22.4k
    {
1413
22.4k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
729
  break;
1415
22.4k
    }
1416
1417
1.68k
  if (section == NULL)
1418
956
    return;
1419
1420
729
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
33
    return;
1422
1423
696
  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
696
  if (dataoff >= section->size
1429
696
      || size > section->size - dataoff)
1430
186
    {
1431
186
      _bfd_error_handler
1432
186
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
186
   abfd);
1434
186
      return;
1435
186
    }
1436
1437
  /* Read the whole section. */
1438
510
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
170
    {
1440
170
      free (data);
1441
170
      return;
1442
170
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
9.52k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
9.41k
    {
1447
9.41k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
9.41k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
9.41k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
9.41k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
9.41k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
233
  {
1455
233
    char buffer[256 + 1];
1456
233
    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
233
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
233
                (file_ptr) idd.PointerToRawData,
1464
233
                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
233
    break;
1479
233
  }
1480
9.41k
    }
1481
1482
340
  free (data);
1483
340
}
pei-aarch64.c:pe_bfd_read_buildid
Line
Count
Source
1395
6.16k
{
1396
6.16k
  pe_data_type *pe = pe_data (abfd);
1397
6.16k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
6.16k
  asection *section;
1399
6.16k
  bfd_byte *data = 0;
1400
6.16k
  bfd_size_type dataoff;
1401
6.16k
  unsigned int i;
1402
6.16k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
6.16k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
6.16k
  if (size == 0)
1406
2.15k
    return;
1407
1408
4.01k
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
23.2k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
22.0k
    {
1413
22.0k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
2.73k
  break;
1415
22.0k
    }
1416
1417
4.01k
  if (section == NULL)
1418
1.28k
    return;
1419
1420
2.73k
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
38
    return;
1422
1423
2.69k
  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.69k
  if (dataoff >= section->size
1429
2.69k
      || size > section->size - dataoff)
1430
449
    {
1431
449
      _bfd_error_handler
1432
449
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
449
   abfd);
1434
449
      return;
1435
449
    }
1436
1437
  /* Read the whole section. */
1438
2.24k
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
355
    {
1440
355
      free (data);
1441
355
      return;
1442
355
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
217k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
215k
    {
1447
215k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
215k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
215k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
215k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
215k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
475
  {
1455
475
    char buffer[256 + 1];
1456
475
    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
475
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
475
                (file_ptr) idd.PointerToRawData,
1464
475
                idd.SizeOfData, cvinfo, NULL))
1465
9
      {
1466
9
        struct bfd_build_id *build_id;
1467
9
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1468
1469
9
        build_id = bfd_alloc (abfd, bidlen);
1470
9
        if (build_id)
1471
9
    {
1472
9
      build_id->size = cvinfo->SignatureLength;
1473
9
      memcpy(build_id->data, cvinfo->Signature,
1474
9
       cvinfo->SignatureLength);
1475
9
      abfd->build_id = build_id;
1476
9
    }
1477
9
      }
1478
475
    break;
1479
475
  }
1480
215k
    }
1481
1482
1.88k
  free (data);
1483
1.88k
}
pei-ia64.c:pe_bfd_read_buildid
Line
Count
Source
1395
3.48k
{
1396
3.48k
  pe_data_type *pe = pe_data (abfd);
1397
3.48k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
3.48k
  asection *section;
1399
3.48k
  bfd_byte *data = 0;
1400
3.48k
  bfd_size_type dataoff;
1401
3.48k
  unsigned int i;
1402
3.48k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
3.48k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
3.48k
  if (size == 0)
1406
2.69k
    return;
1407
1408
796
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
4.71k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
4.22k
    {
1413
4.22k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
300
  break;
1415
4.22k
    }
1416
1417
796
  if (section == NULL)
1418
496
    return;
1419
1420
300
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
31
    return;
1422
1423
269
  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
269
  if (dataoff >= section->size
1429
269
      || size > section->size - dataoff)
1430
43
    {
1431
43
      _bfd_error_handler
1432
43
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
43
   abfd);
1434
43
      return;
1435
43
    }
1436
1437
  /* Read the whole section. */
1438
226
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
35
    {
1440
35
      free (data);
1441
35
      return;
1442
35
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
2.60k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
2.53k
    {
1447
2.53k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
2.53k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
2.53k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
2.53k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
2.53k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
119
  {
1455
119
    char buffer[256 + 1];
1456
119
    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
119
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
119
                (file_ptr) idd.PointerToRawData,
1464
119
                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
119
    break;
1479
119
  }
1480
2.53k
    }
1481
1482
191
  free (data);
1483
191
}
pei-loongarch64.c:pe_bfd_read_buildid
Line
Count
Source
1395
3.48k
{
1396
3.48k
  pe_data_type *pe = pe_data (abfd);
1397
3.48k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
3.48k
  asection *section;
1399
3.48k
  bfd_byte *data = 0;
1400
3.48k
  bfd_size_type dataoff;
1401
3.48k
  unsigned int i;
1402
3.48k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
3.48k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
3.48k
  if (size == 0)
1406
2.18k
    return;
1407
1408
1.30k
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
8.86k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
8.01k
    {
1413
8.01k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
450
  break;
1415
8.01k
    }
1416
1417
1.30k
  if (section == NULL)
1418
850
    return;
1419
1420
450
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
27
    return;
1422
1423
423
  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
423
  if (dataoff >= section->size
1429
423
      || size > section->size - dataoff)
1430
102
    {
1431
102
      _bfd_error_handler
1432
102
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
102
   abfd);
1434
102
      return;
1435
102
    }
1436
1437
  /* Read the whole section. */
1438
321
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
64
    {
1440
64
      free (data);
1441
64
      return;
1442
64
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
6.78k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
6.70k
    {
1447
6.70k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
6.70k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
6.70k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
6.70k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
6.70k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
177
  {
1455
177
    char buffer[256 + 1];
1456
177
    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
177
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
177
                (file_ptr) idd.PointerToRawData,
1464
177
                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
177
    break;
1479
177
  }
1480
6.70k
    }
1481
1482
257
  free (data);
1483
257
}
pei-riscv64.c:pe_bfd_read_buildid
Line
Count
Source
1395
3.50k
{
1396
3.50k
  pe_data_type *pe = pe_data (abfd);
1397
3.50k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
3.50k
  asection *section;
1399
3.50k
  bfd_byte *data = 0;
1400
3.50k
  bfd_size_type dataoff;
1401
3.50k
  unsigned int i;
1402
3.50k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
3.50k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
3.50k
  if (size == 0)
1406
2.09k
    return;
1407
1408
1.41k
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
15.8k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
14.9k
    {
1413
14.9k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
457
  break;
1415
14.9k
    }
1416
1417
1.41k
  if (section == NULL)
1418
954
    return;
1419
1420
457
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
35
    return;
1422
1423
422
  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
422
  if (dataoff >= section->size
1429
422
      || size > section->size - dataoff)
1430
160
    {
1431
160
      _bfd_error_handler
1432
160
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
160
   abfd);
1434
160
      return;
1435
160
    }
1436
1437
  /* Read the whole section. */
1438
262
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
99
    {
1440
99
      free (data);
1441
99
      return;
1442
99
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
2.13k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
2.08k
    {
1447
2.08k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
2.08k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
2.08k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
2.08k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
2.08k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
114
  {
1455
114
    char buffer[256 + 1];
1456
114
    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
114
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
114
                (file_ptr) idd.PointerToRawData,
1464
114
                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
114
    break;
1479
114
  }
1480
2.08k
    }
1481
1482
163
  free (data);
1483
163
}
pei-arm-wince.c:pe_bfd_read_buildid
Line
Count
Source
1395
2.28k
{
1396
2.28k
  pe_data_type *pe = pe_data (abfd);
1397
2.28k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
2.28k
  asection *section;
1399
2.28k
  bfd_byte *data = 0;
1400
2.28k
  bfd_size_type dataoff;
1401
2.28k
  unsigned int i;
1402
2.28k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
2.28k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
2.28k
  if (size == 0)
1406
981
    return;
1407
1408
1.30k
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
5.14k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
4.40k
    {
1413
4.40k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
565
  break;
1415
4.40k
    }
1416
1417
1.30k
  if (section == NULL)
1418
740
    return;
1419
1420
565
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
50
    return;
1422
1423
515
  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
515
  if (dataoff >= section->size
1429
515
      || size > section->size - dataoff)
1430
250
    {
1431
250
      _bfd_error_handler
1432
250
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
250
   abfd);
1434
250
      return;
1435
250
    }
1436
1437
  /* Read the whole section. */
1438
265
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
139
    {
1440
139
      free (data);
1441
139
      return;
1442
139
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
2.36k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
2.29k
    {
1447
2.29k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
2.29k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
2.29k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
2.29k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
2.29k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
58
  {
1455
58
    char buffer[256 + 1];
1456
58
    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
58
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
58
                (file_ptr) idd.PointerToRawData,
1464
58
                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
58
    break;
1479
58
  }
1480
2.29k
    }
1481
1482
126
  free (data);
1483
126
}
pei-arm.c:pe_bfd_read_buildid
Line
Count
Source
1395
3.31k
{
1396
3.31k
  pe_data_type *pe = pe_data (abfd);
1397
3.31k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
3.31k
  asection *section;
1399
3.31k
  bfd_byte *data = 0;
1400
3.31k
  bfd_size_type dataoff;
1401
3.31k
  unsigned int i;
1402
3.31k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
3.31k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
3.31k
  if (size == 0)
1406
1.69k
    return;
1407
1408
1.62k
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
8.06k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
7.27k
    {
1413
7.27k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
825
  break;
1415
7.27k
    }
1416
1417
1.62k
  if (section == NULL)
1418
796
    return;
1419
1420
825
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
35
    return;
1422
1423
790
  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
790
  if (dataoff >= section->size
1429
790
      || size > section->size - dataoff)
1430
389
    {
1431
389
      _bfd_error_handler
1432
389
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
389
   abfd);
1434
389
      return;
1435
389
    }
1436
1437
  /* Read the whole section. */
1438
401
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
184
    {
1440
184
      free (data);
1441
184
      return;
1442
184
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
3.38k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
3.23k
    {
1447
3.23k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
3.23k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
3.23k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
3.23k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
3.23k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
70
  {
1455
70
    char buffer[256 + 1];
1456
70
    CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer;
1457
1458
    /*
1459
      The debug entry doesn't have to have to be in a section, in which
1460
      case AddressOfRawData is 0, so always use PointerToRawData.
1461
    */
1462
70
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
70
                (file_ptr) idd.PointerToRawData,
1464
70
                idd.SizeOfData, cvinfo, NULL))
1465
20
      {
1466
20
        struct bfd_build_id *build_id;
1467
20
        size_t bidlen = sizeof (*build_id) + cvinfo->SignatureLength;
1468
1469
20
        build_id = bfd_alloc (abfd, bidlen);
1470
20
        if (build_id)
1471
20
    {
1472
20
      build_id->size = cvinfo->SignatureLength;
1473
20
      memcpy(build_id->data, cvinfo->Signature,
1474
20
       cvinfo->SignatureLength);
1475
20
      abfd->build_id = build_id;
1476
20
    }
1477
20
      }
1478
70
    break;
1479
70
  }
1480
3.23k
    }
1481
1482
217
  free (data);
1483
217
}
pei-mcore.c:pe_bfd_read_buildid
Line
Count
Source
1395
3.02k
{
1396
3.02k
  pe_data_type *pe = pe_data (abfd);
1397
3.02k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
3.02k
  asection *section;
1399
3.02k
  bfd_byte *data = 0;
1400
3.02k
  bfd_size_type dataoff;
1401
3.02k
  unsigned int i;
1402
3.02k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
3.02k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
3.02k
  if (size == 0)
1406
1.87k
    return;
1407
1408
1.14k
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
8.06k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
7.55k
    {
1413
7.55k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
627
  break;
1415
7.55k
    }
1416
1417
1.14k
  if (section == NULL)
1418
516
    return;
1419
1420
627
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
57
    return;
1422
1423
570
  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
570
  if (dataoff >= section->size
1429
570
      || size > section->size - dataoff)
1430
296
    {
1431
296
      _bfd_error_handler
1432
296
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
296
   abfd);
1434
296
      return;
1435
296
    }
1436
1437
  /* Read the whole section. */
1438
274
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
124
    {
1440
124
      free (data);
1441
124
      return;
1442
124
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
5.41k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
5.31k
    {
1447
5.31k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
5.31k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
5.31k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
5.31k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
5.31k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
52
  {
1455
52
    char buffer[256 + 1];
1456
52
    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
52
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
52
                (file_ptr) idd.PointerToRawData,
1464
52
                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
52
    break;
1479
52
  }
1480
5.31k
    }
1481
1482
150
  free (data);
1483
150
}
pei-sh.c:pe_bfd_read_buildid
Line
Count
Source
1395
3.15k
{
1396
3.15k
  pe_data_type *pe = pe_data (abfd);
1397
3.15k
  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
1398
3.15k
  asection *section;
1399
3.15k
  bfd_byte *data = 0;
1400
3.15k
  bfd_size_type dataoff;
1401
3.15k
  unsigned int i;
1402
3.15k
  bfd_vma addr = extra->DataDirectory[PE_DEBUG_DATA].VirtualAddress;
1403
3.15k
  bfd_size_type size = extra->DataDirectory[PE_DEBUG_DATA].Size;
1404
1405
3.15k
  if (size == 0)
1406
1.86k
    return;
1407
1408
1.29k
  addr += extra->ImageBase;
1409
1410
  /* Search for the section containing the DebugDirectory.  */
1411
8.16k
  for (section = abfd->sections; section != NULL; section = section->next)
1412
7.50k
    {
1413
7.50k
      if ((addr >= section->vma) && (addr < (section->vma + section->size)))
1414
635
  break;
1415
7.50k
    }
1416
1417
1.29k
  if (section == NULL)
1418
658
    return;
1419
1420
635
  if (!(section->flags & SEC_HAS_CONTENTS))
1421
61
    return;
1422
1423
574
  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
574
  if (dataoff >= section->size
1429
574
      || size > section->size - dataoff)
1430
253
    {
1431
253
      _bfd_error_handler
1432
253
  (_("%pB: error: debug data ends beyond end of debug directory"),
1433
253
   abfd);
1434
253
      return;
1435
253
    }
1436
1437
  /* Read the whole section. */
1438
321
  if (!bfd_malloc_and_get_section (abfd, section, &data))
1439
145
    {
1440
145
      free (data);
1441
145
      return;
1442
145
    }
1443
1444
  /* Search for a CodeView entry in the DebugDirectory */
1445
5.56k
  for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
1446
5.47k
    {
1447
5.47k
      struct external_IMAGE_DEBUG_DIRECTORY *ext
1448
5.47k
  = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
1449
5.47k
      struct internal_IMAGE_DEBUG_DIRECTORY idd;
1450
1451
5.47k
      _bfd_XXi_swap_debugdir_in (abfd, ext, &idd);
1452
1453
5.47k
      if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW)
1454
89
  {
1455
89
    char buffer[256 + 1];
1456
89
    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
89
    if (_bfd_XXi_slurp_codeview_record (abfd,
1463
89
                (file_ptr) idd.PointerToRawData,
1464
89
                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
89
    break;
1479
89
  }
1480
5.47k
    }
1481
1482
176
  free (data);
1483
176
}
1484
1485
static bfd_cleanup
1486
pe_bfd_object_p (bfd *abfd)
1487
2.21M
{
1488
2.21M
  bfd_byte buffer[6];
1489
2.21M
  struct external_DOS_hdr dos_hdr;
1490
2.21M
  struct external_PEI_IMAGE_hdr image_hdr;
1491
2.21M
  struct internal_filehdr internal_f;
1492
2.21M
  struct internal_aouthdr internal_a;
1493
2.21M
  bfd_size_type opt_hdr_size;
1494
2.21M
  file_ptr offset;
1495
2.21M
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
2.21M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
2.21M
      || bfd_read (buffer, 6, abfd) != 6)
1501
20.5k
    {
1502
20.5k
      if (bfd_get_error () != bfd_error_system_call)
1503
20.1k
  bfd_set_error (bfd_error_wrong_format);
1504
20.5k
      return NULL;
1505
20.5k
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
2.19M
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
39.5k
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
33.5k
    return pe_ILF_object_p (abfd);
1511
1512
2.16M
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
2.16M
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
564k
    {
1515
564k
      if (bfd_get_error () != bfd_error_system_call)
1516
564k
  bfd_set_error (bfd_error_wrong_format);
1517
564k
      return NULL;
1518
564k
    }
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.59M
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
1.13M
    {
1532
1.13M
      bfd_set_error (bfd_error_wrong_format);
1533
1.13M
      return NULL;
1534
1.13M
    }
1535
1536
464k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
464k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
464k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
3.23k
    {
1540
3.23k
      if (bfd_get_error () != bfd_error_system_call)
1541
3.23k
  bfd_set_error (bfd_error_wrong_format);
1542
3.23k
      return NULL;
1543
3.23k
    }
1544
1545
460k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
5.43k
    {
1547
5.43k
      bfd_set_error (bfd_error_wrong_format);
1548
5.43k
      return NULL;
1549
5.43k
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
455k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
455k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
67.9k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
387k
    {
1558
387k
      bfd_set_error (bfd_error_wrong_format);
1559
387k
      return NULL;
1560
387k
    }
1561
1562
67.6k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
67.6k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
67.6k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
67.6k
  if (opt_hdr_size != 0)
1569
40.0k
    {
1570
40.0k
      bfd_size_type amt = opt_hdr_size;
1571
40.0k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
40.0k
      if (amt < sizeof (PEAOUTHDR))
1575
36.7k
  amt = sizeof (PEAOUTHDR);
1576
1577
40.0k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
40.0k
      if (opthdr == NULL)
1579
393
  return NULL;
1580
39.6k
      if (amt > opt_hdr_size)
1581
36.4k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
39.6k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
39.6k
      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.62k
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1592
#else
1593
4.87k
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1594
1.48k
#endif
1595
4.15k
  {
1596
4.15k
    bfd_set_error (bfd_error_wrong_format);
1597
4.15k
    return NULL;
1598
4.15k
  }
1599
5.34k
#endif
1600
1601
35.5k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
16.6k
    || a->SectionAlignment >= 0x80000000)
1603
19.2k
  {
1604
19.2k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
19.2k
            abfd);
1606
19.2k
    a->SectionAlignment &= -a->SectionAlignment;
1607
19.2k
    if (a->SectionAlignment >= 0x80000000)
1608
333
      a->SectionAlignment = 0x40000000;
1609
19.2k
  }
1610
1611
35.5k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
17.8k
    || a->FileAlignment > a->SectionAlignment)
1613
23.0k
  {
1614
23.0k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
23.0k
            abfd);
1616
23.0k
    a->FileAlignment &= -a->FileAlignment;
1617
23.0k
    if (a->FileAlignment > a->SectionAlignment)
1618
16.0k
      a->FileAlignment = a->SectionAlignment;
1619
23.0k
  }
1620
1621
35.5k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
18.6k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
5.34k
    }
1624
1625
63.1k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
63.1k
             (opt_hdr_size != 0
1627
63.1k
        ? &internal_a
1628
63.1k
        : (struct internal_aouthdr *) NULL));
1629
1630
63.1k
  if (result)
1631
42.4k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
42.4k
      pe_bfd_read_buildid(abfd);
1634
42.4k
    }
1635
1636
63.1k
  return result;
1637
67.6k
}
pei-i386.c:pe_bfd_object_p
Line
Count
Source
1487
199k
{
1488
199k
  bfd_byte buffer[6];
1489
199k
  struct external_DOS_hdr dos_hdr;
1490
199k
  struct external_PEI_IMAGE_hdr image_hdr;
1491
199k
  struct internal_filehdr internal_f;
1492
199k
  struct internal_aouthdr internal_a;
1493
199k
  bfd_size_type opt_hdr_size;
1494
199k
  file_ptr offset;
1495
199k
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
199k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
199k
      || bfd_read (buffer, 6, abfd) != 6)
1501
1.80k
    {
1502
1.80k
      if (bfd_get_error () != bfd_error_system_call)
1503
1.76k
  bfd_set_error (bfd_error_wrong_format);
1504
1.80k
      return NULL;
1505
1.80k
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
197k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
4.57k
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
3.85k
    return pe_ILF_object_p (abfd);
1511
1512
193k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
193k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
50.7k
    {
1515
50.7k
      if (bfd_get_error () != bfd_error_system_call)
1516
50.7k
  bfd_set_error (bfd_error_wrong_format);
1517
50.7k
      return NULL;
1518
50.7k
    }
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
143k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
90.6k
    {
1532
90.6k
      bfd_set_error (bfd_error_wrong_format);
1533
90.6k
      return NULL;
1534
90.6k
    }
1535
1536
52.6k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
52.6k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
52.6k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
138
    {
1540
138
      if (bfd_get_error () != bfd_error_system_call)
1541
138
  bfd_set_error (bfd_error_wrong_format);
1542
138
      return NULL;
1543
138
    }
1544
1545
52.4k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
388
    {
1547
388
      bfd_set_error (bfd_error_wrong_format);
1548
388
      return NULL;
1549
388
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
52.0k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
52.0k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
9.90k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
42.2k
    {
1558
42.2k
      bfd_set_error (bfd_error_wrong_format);
1559
42.2k
      return NULL;
1560
42.2k
    }
1561
1562
9.87k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
9.87k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
9.87k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
9.87k
  if (opt_hdr_size != 0)
1569
4.66k
    {
1570
4.66k
      bfd_size_type amt = opt_hdr_size;
1571
4.66k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
4.66k
      if (amt < sizeof (PEAOUTHDR))
1575
3.94k
  amt = sizeof (PEAOUTHDR);
1576
1577
4.66k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
4.66k
      if (opthdr == NULL)
1579
33
  return NULL;
1580
4.63k
      if (amt > opt_hdr_size)
1581
3.91k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
4.63k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
4.63k
      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.63k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
2.35k
    || a->SectionAlignment >= 0x80000000)
1603
2.31k
  {
1604
2.31k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
2.31k
            abfd);
1606
2.31k
    a->SectionAlignment &= -a->SectionAlignment;
1607
2.31k
    if (a->SectionAlignment >= 0x80000000)
1608
47
      a->SectionAlignment = 0x40000000;
1609
2.31k
  }
1610
1611
4.63k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
2.46k
    || a->FileAlignment > a->SectionAlignment)
1613
2.63k
  {
1614
2.63k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
2.63k
            abfd);
1616
2.63k
    a->FileAlignment &= -a->FileAlignment;
1617
2.63k
    if (a->FileAlignment > a->SectionAlignment)
1618
1.74k
      a->FileAlignment = a->SectionAlignment;
1619
2.63k
  }
1620
1621
4.63k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
2.34k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
4.63k
    }
1624
1625
9.84k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
9.84k
             (opt_hdr_size != 0
1627
9.84k
        ? &internal_a
1628
9.84k
        : (struct internal_aouthdr *) NULL));
1629
1630
9.84k
  if (result)
1631
8.52k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
8.52k
      pe_bfd_read_buildid(abfd);
1634
8.52k
    }
1635
1636
9.84k
  return result;
1637
9.87k
}
pei-x86_64.c:pe_bfd_object_p
Line
Count
Source
1487
198k
{
1488
198k
  bfd_byte buffer[6];
1489
198k
  struct external_DOS_hdr dos_hdr;
1490
198k
  struct external_PEI_IMAGE_hdr image_hdr;
1491
198k
  struct internal_filehdr internal_f;
1492
198k
  struct internal_aouthdr internal_a;
1493
198k
  bfd_size_type opt_hdr_size;
1494
198k
  file_ptr offset;
1495
198k
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
198k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
198k
      || bfd_read (buffer, 6, abfd) != 6)
1501
1.80k
    {
1502
1.80k
      if (bfd_get_error () != bfd_error_system_call)
1503
1.76k
  bfd_set_error (bfd_error_wrong_format);
1504
1.80k
      return NULL;
1505
1.80k
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
196k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
4.56k
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
3.85k
    return pe_ILF_object_p (abfd);
1511
1512
192k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
192k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
50.7k
    {
1515
50.7k
      if (bfd_get_error () != bfd_error_system_call)
1516
50.7k
  bfd_set_error (bfd_error_wrong_format);
1517
50.7k
      return NULL;
1518
50.7k
    }
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
141k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
90.6k
    {
1532
90.6k
      bfd_set_error (bfd_error_wrong_format);
1533
90.6k
      return NULL;
1534
90.6k
    }
1535
1536
51.1k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
51.1k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
51.1k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
138
    {
1540
138
      if (bfd_get_error () != bfd_error_system_call)
1541
138
  bfd_set_error (bfd_error_wrong_format);
1542
138
      return NULL;
1543
138
    }
1544
1545
51.0k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
388
    {
1547
388
      bfd_set_error (bfd_error_wrong_format);
1548
388
      return NULL;
1549
388
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
50.6k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
50.6k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
7.04k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
43.5k
    {
1558
43.5k
      bfd_set_error (bfd_error_wrong_format);
1559
43.5k
      return NULL;
1560
43.5k
    }
1561
1562
7.03k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
7.03k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
7.03k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
7.03k
  if (opt_hdr_size != 0)
1569
4.22k
    {
1570
4.22k
      bfd_size_type amt = opt_hdr_size;
1571
4.22k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
4.22k
      if (amt < sizeof (PEAOUTHDR))
1575
3.90k
  amt = sizeof (PEAOUTHDR);
1576
1577
4.22k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
4.22k
      if (opthdr == NULL)
1579
29
  return NULL;
1580
4.19k
      if (amt > opt_hdr_size)
1581
3.88k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
4.19k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
4.19k
      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.19k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
2.40k
    || a->SectionAlignment >= 0x80000000)
1603
1.82k
  {
1604
1.82k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
1.82k
            abfd);
1606
1.82k
    a->SectionAlignment &= -a->SectionAlignment;
1607
1.82k
    if (a->SectionAlignment >= 0x80000000)
1608
34
      a->SectionAlignment = 0x40000000;
1609
1.82k
  }
1610
1611
4.19k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
2.14k
    || a->FileAlignment > a->SectionAlignment)
1613
2.44k
  {
1614
2.44k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
2.44k
            abfd);
1616
2.44k
    a->FileAlignment &= -a->FileAlignment;
1617
2.44k
    if (a->FileAlignment > a->SectionAlignment)
1618
1.26k
      a->FileAlignment = a->SectionAlignment;
1619
2.44k
  }
1620
1621
4.19k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
1.96k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
4.19k
    }
1624
1625
7.00k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
7.00k
             (opt_hdr_size != 0
1627
7.00k
        ? &internal_a
1628
7.00k
        : (struct internal_aouthdr *) NULL));
1629
1630
7.00k
  if (result)
1631
5.44k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
5.44k
      pe_bfd_read_buildid(abfd);
1634
5.44k
    }
1635
1636
7.00k
  return result;
1637
7.03k
}
pei-aarch64.c:pe_bfd_object_p
Line
Count
Source
1487
196k
{
1488
196k
  bfd_byte buffer[6];
1489
196k
  struct external_DOS_hdr dos_hdr;
1490
196k
  struct external_PEI_IMAGE_hdr image_hdr;
1491
196k
  struct internal_filehdr internal_f;
1492
196k
  struct internal_aouthdr internal_a;
1493
196k
  bfd_size_type opt_hdr_size;
1494
196k
  file_ptr offset;
1495
196k
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
196k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
196k
      || bfd_read (buffer, 6, abfd) != 6)
1501
1.80k
    {
1502
1.80k
      if (bfd_get_error () != bfd_error_system_call)
1503
1.76k
  bfd_set_error (bfd_error_wrong_format);
1504
1.80k
      return NULL;
1505
1.80k
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
194k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
4.57k
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
3.86k
    return pe_ILF_object_p (abfd);
1511
1512
190k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
190k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
50.6k
    {
1515
50.6k
      if (bfd_get_error () != bfd_error_system_call)
1516
50.6k
  bfd_set_error (bfd_error_wrong_format);
1517
50.6k
      return NULL;
1518
50.6k
    }
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
140k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
88.7k
    {
1532
88.7k
      bfd_set_error (bfd_error_wrong_format);
1533
88.7k
      return NULL;
1534
88.7k
    }
1535
1536
51.3k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
51.3k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
51.3k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
837
    {
1540
837
      if (bfd_get_error () != bfd_error_system_call)
1541
837
  bfd_set_error (bfd_error_wrong_format);
1542
837
      return NULL;
1543
837
    }
1544
1545
50.5k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
1.10k
    {
1547
1.10k
      bfd_set_error (bfd_error_wrong_format);
1548
1.10k
      return NULL;
1549
1.10k
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
49.4k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
49.4k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
8.26k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
41.2k
    {
1558
41.2k
      bfd_set_error (bfd_error_wrong_format);
1559
41.2k
      return NULL;
1560
41.2k
    }
1561
1562
8.23k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
8.23k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
8.23k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
8.23k
  if (opt_hdr_size != 0)
1569
6.27k
    {
1570
6.27k
      bfd_size_type amt = opt_hdr_size;
1571
6.27k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
6.27k
      if (amt < sizeof (PEAOUTHDR))
1575
5.96k
  amt = sizeof (PEAOUTHDR);
1576
1577
6.27k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
6.27k
      if (opthdr == NULL)
1579
51
  return NULL;
1580
6.22k
      if (amt > opt_hdr_size)
1581
5.92k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
6.22k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
6.22k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1586
1587
#ifdef ARM
1588
      /* Use Subsystem to distinguish between pei-arm-little and
1589
   pei-arm-wince-little.  */
1590
#ifdef WINCE
1591
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1592
#else
1593
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1594
#endif
1595
  {
1596
    bfd_set_error (bfd_error_wrong_format);
1597
    return NULL;
1598
  }
1599
#endif
1600
1601
6.22k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
2.17k
    || a->SectionAlignment >= 0x80000000)
1603
4.08k
  {
1604
4.08k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
4.08k
            abfd);
1606
4.08k
    a->SectionAlignment &= -a->SectionAlignment;
1607
4.08k
    if (a->SectionAlignment >= 0x80000000)
1608
28
      a->SectionAlignment = 0x40000000;
1609
4.08k
  }
1610
1611
6.22k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
4.00k
    || a->FileAlignment > a->SectionAlignment)
1613
4.71k
  {
1614
4.71k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
4.71k
            abfd);
1616
4.71k
    a->FileAlignment &= -a->FileAlignment;
1617
4.71k
    if (a->FileAlignment > a->SectionAlignment)
1618
3.67k
      a->FileAlignment = a->SectionAlignment;
1619
4.71k
  }
1620
1621
6.22k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
2.72k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
6.22k
    }
1624
1625
8.18k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
8.18k
             (opt_hdr_size != 0
1627
8.18k
        ? &internal_a
1628
8.18k
        : (struct internal_aouthdr *) NULL));
1629
1630
8.18k
  if (result)
1631
6.16k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
6.16k
      pe_bfd_read_buildid(abfd);
1634
6.16k
    }
1635
1636
8.18k
  return result;
1637
8.23k
}
pei-ia64.c:pe_bfd_object_p
Line
Count
Source
1487
15.2k
{
1488
15.2k
  bfd_byte buffer[6];
1489
15.2k
  struct external_DOS_hdr dos_hdr;
1490
15.2k
  struct external_PEI_IMAGE_hdr image_hdr;
1491
15.2k
  struct internal_filehdr internal_f;
1492
15.2k
  struct internal_aouthdr internal_a;
1493
15.2k
  bfd_size_type opt_hdr_size;
1494
15.2k
  file_ptr offset;
1495
15.2k
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
15.2k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
15.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
15.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
15.2k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
15.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
15.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
15.2k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
15.2k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
15.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
15.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
15.2k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
15.2k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
5.60k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
9.67k
    {
1558
9.67k
      bfd_set_error (bfd_error_wrong_format);
1559
9.67k
      return NULL;
1560
9.67k
    }
1561
1562
5.58k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
5.58k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
5.58k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
5.58k
  if (opt_hdr_size != 0)
1569
2.32k
    {
1570
2.32k
      bfd_size_type amt = opt_hdr_size;
1571
2.32k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
2.32k
      if (amt < sizeof (PEAOUTHDR))
1575
2.19k
  amt = sizeof (PEAOUTHDR);
1576
1577
2.32k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
2.32k
      if (opthdr == NULL)
1579
41
  return NULL;
1580
2.28k
      if (amt > opt_hdr_size)
1581
2.16k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
2.28k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
2.28k
      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.28k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
1.05k
    || a->SectionAlignment >= 0x80000000)
1603
1.25k
  {
1604
1.25k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
1.25k
            abfd);
1606
1.25k
    a->SectionAlignment &= -a->SectionAlignment;
1607
1.25k
    if (a->SectionAlignment >= 0x80000000)
1608
23
      a->SectionAlignment = 0x40000000;
1609
1.25k
  }
1610
1611
2.28k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
991
    || a->FileAlignment > a->SectionAlignment)
1613
1.60k
  {
1614
1.60k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
1.60k
            abfd);
1616
1.60k
    a->FileAlignment &= -a->FileAlignment;
1617
1.60k
    if (a->FileAlignment > a->SectionAlignment)
1618
855
      a->FileAlignment = a->SectionAlignment;
1619
1.60k
  }
1620
1621
2.28k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
1.31k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
2.28k
    }
1624
1625
5.53k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
5.53k
             (opt_hdr_size != 0
1627
5.53k
        ? &internal_a
1628
5.53k
        : (struct internal_aouthdr *) NULL));
1629
1630
5.53k
  if (result)
1631
3.48k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
3.48k
      pe_bfd_read_buildid(abfd);
1634
3.48k
    }
1635
1636
5.53k
  return result;
1637
5.58k
}
pei-loongarch64.c:pe_bfd_object_p
Line
Count
Source
1487
196k
{
1488
196k
  bfd_byte buffer[6];
1489
196k
  struct external_DOS_hdr dos_hdr;
1490
196k
  struct external_PEI_IMAGE_hdr image_hdr;
1491
196k
  struct internal_filehdr internal_f;
1492
196k
  struct internal_aouthdr internal_a;
1493
196k
  bfd_size_type opt_hdr_size;
1494
196k
  file_ptr offset;
1495
196k
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
196k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
196k
      || bfd_read (buffer, 6, abfd) != 6)
1501
1.80k
    {
1502
1.80k
      if (bfd_get_error () != bfd_error_system_call)
1503
1.76k
  bfd_set_error (bfd_error_wrong_format);
1504
1.80k
      return NULL;
1505
1.80k
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
194k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
4.55k
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
3.84k
    return pe_ILF_object_p (abfd);
1511
1512
190k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
190k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
50.7k
    {
1515
50.7k
      if (bfd_get_error () != bfd_error_system_call)
1516
50.7k
  bfd_set_error (bfd_error_wrong_format);
1517
50.7k
      return NULL;
1518
50.7k
    }
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
140k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
90.6k
    {
1532
90.6k
      bfd_set_error (bfd_error_wrong_format);
1533
90.6k
      return NULL;
1534
90.6k
    }
1535
1536
49.4k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
49.4k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
49.4k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
138
    {
1540
138
      if (bfd_get_error () != bfd_error_system_call)
1541
138
  bfd_set_error (bfd_error_wrong_format);
1542
138
      return NULL;
1543
138
    }
1544
1545
49.2k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
388
    {
1547
388
      bfd_set_error (bfd_error_wrong_format);
1548
388
      return NULL;
1549
388
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
48.8k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
48.8k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
5.51k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
43.4k
    {
1558
43.4k
      bfd_set_error (bfd_error_wrong_format);
1559
43.4k
      return NULL;
1560
43.4k
    }
1561
1562
5.48k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
5.48k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
5.48k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
5.48k
  if (opt_hdr_size != 0)
1569
3.45k
    {
1570
3.45k
      bfd_size_type amt = opt_hdr_size;
1571
3.45k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
3.45k
      if (amt < sizeof (PEAOUTHDR))
1575
3.14k
  amt = sizeof (PEAOUTHDR);
1576
1577
3.45k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
3.45k
      if (opthdr == NULL)
1579
42
  return NULL;
1580
3.41k
      if (amt > opt_hdr_size)
1581
3.10k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
3.41k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
3.41k
      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.41k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
1.90k
    || a->SectionAlignment >= 0x80000000)
1603
1.52k
  {
1604
1.52k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
1.52k
            abfd);
1606
1.52k
    a->SectionAlignment &= -a->SectionAlignment;
1607
1.52k
    if (a->SectionAlignment >= 0x80000000)
1608
26
      a->SectionAlignment = 0x40000000;
1609
1.52k
  }
1610
1611
3.41k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
1.59k
    || a->FileAlignment > a->SectionAlignment)
1613
2.13k
  {
1614
2.13k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
2.13k
            abfd);
1616
2.13k
    a->FileAlignment &= -a->FileAlignment;
1617
2.13k
    if (a->FileAlignment > a->SectionAlignment)
1618
1.34k
      a->FileAlignment = a->SectionAlignment;
1619
2.13k
  }
1620
1621
3.41k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
1.89k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
3.41k
    }
1624
1625
5.43k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
5.43k
             (opt_hdr_size != 0
1627
5.43k
        ? &internal_a
1628
5.43k
        : (struct internal_aouthdr *) NULL));
1629
1630
5.43k
  if (result)
1631
3.48k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
3.48k
      pe_bfd_read_buildid(abfd);
1634
3.48k
    }
1635
1636
5.43k
  return result;
1637
5.48k
}
pei-riscv64.c:pe_bfd_object_p
Line
Count
Source
1487
196k
{
1488
196k
  bfd_byte buffer[6];
1489
196k
  struct external_DOS_hdr dos_hdr;
1490
196k
  struct external_PEI_IMAGE_hdr image_hdr;
1491
196k
  struct internal_filehdr internal_f;
1492
196k
  struct internal_aouthdr internal_a;
1493
196k
  bfd_size_type opt_hdr_size;
1494
196k
  file_ptr offset;
1495
196k
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
196k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
196k
      || bfd_read (buffer, 6, abfd) != 6)
1501
1.80k
    {
1502
1.80k
      if (bfd_get_error () != bfd_error_system_call)
1503
1.76k
  bfd_set_error (bfd_error_wrong_format);
1504
1.80k
      return NULL;
1505
1.80k
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
194k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
4.57k
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
3.85k
    return pe_ILF_object_p (abfd);
1511
1512
190k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
190k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
50.7k
    {
1515
50.7k
      if (bfd_get_error () != bfd_error_system_call)
1516
50.7k
  bfd_set_error (bfd_error_wrong_format);
1517
50.7k
      return NULL;
1518
50.7k
    }
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
140k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
90.6k
    {
1532
90.6k
      bfd_set_error (bfd_error_wrong_format);
1533
90.6k
      return NULL;
1534
90.6k
    }
1535
1536
49.3k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
49.3k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
49.3k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
138
    {
1540
138
      if (bfd_get_error () != bfd_error_system_call)
1541
138
  bfd_set_error (bfd_error_wrong_format);
1542
138
      return NULL;
1543
138
    }
1544
1545
49.1k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
388
    {
1547
388
      bfd_set_error (bfd_error_wrong_format);
1548
388
      return NULL;
1549
388
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
48.8k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
48.8k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
5.69k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
43.1k
    {
1558
43.1k
      bfd_set_error (bfd_error_wrong_format);
1559
43.1k
      return NULL;
1560
43.1k
    }
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
3.82k
    {
1570
3.82k
      bfd_size_type amt = opt_hdr_size;
1571
3.82k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
3.82k
      if (amt < sizeof (PEAOUTHDR))
1575
3.43k
  amt = sizeof (PEAOUTHDR);
1576
1577
3.82k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
3.82k
      if (opthdr == NULL)
1579
35
  return NULL;
1580
3.79k
      if (amt > opt_hdr_size)
1581
3.40k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
3.79k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
3.79k
      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.79k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
2.04k
    || a->SectionAlignment >= 0x80000000)
1603
1.79k
  {
1604
1.79k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
1.79k
            abfd);
1606
1.79k
    a->SectionAlignment &= -a->SectionAlignment;
1607
1.79k
    if (a->SectionAlignment >= 0x80000000)
1608
42
      a->SectionAlignment = 0x40000000;
1609
1.79k
  }
1610
1611
3.79k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
1.67k
    || a->FileAlignment > a->SectionAlignment)
1613
2.41k
  {
1614
2.41k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
2.41k
            abfd);
1616
2.41k
    a->FileAlignment &= -a->FileAlignment;
1617
2.41k
    if (a->FileAlignment > a->SectionAlignment)
1618
1.63k
      a->FileAlignment = a->SectionAlignment;
1619
2.41k
  }
1620
1621
3.79k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
2.13k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
3.79k
    }
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.50k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
3.50k
      pe_bfd_read_buildid(abfd);
1634
3.50k
    }
1635
1636
5.64k
  return result;
1637
5.67k
}
pei-arm-wince.c:pe_bfd_object_p
Line
Count
Source
1487
345k
{
1488
345k
  bfd_byte buffer[6];
1489
345k
  struct external_DOS_hdr dos_hdr;
1490
345k
  struct external_PEI_IMAGE_hdr image_hdr;
1491
345k
  struct internal_filehdr internal_f;
1492
345k
  struct internal_aouthdr internal_a;
1493
345k
  bfd_size_type opt_hdr_size;
1494
345k
  file_ptr offset;
1495
345k
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
345k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
345k
      || bfd_read (buffer, 6, abfd) != 6)
1501
3.29k
    {
1502
3.29k
      if (bfd_get_error () != bfd_error_system_call)
1503
3.23k
  bfd_set_error (bfd_error_wrong_format);
1504
3.29k
      return NULL;
1505
3.29k
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
342k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
4.20k
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
3.56k
    return pe_ILF_object_p (abfd);
1511
1512
338k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
338k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
89.1k
    {
1515
89.1k
      if (bfd_get_error () != bfd_error_system_call)
1516
89.1k
  bfd_set_error (bfd_error_wrong_format);
1517
89.1k
      return NULL;
1518
89.1k
    }
1519
1520
  /* There are really two magic numbers involved; the magic number
1521
     that says this is a NT executable (PEI) and the magic number that
1522
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1523
     the e_magic field.  The latter is stored in the f_magic field.
1524
     If the NT magic number isn't valid, the architecture magic number
1525
     could be mimicked by some other field (specifically, the number
1526
     of relocs in section 3).  Since this routine can only be called
1527
     correctly for a PEI file, check the e_magic number here, and, if
1528
     it doesn't match, clobber the f_magic number so that we don't get
1529
     a false match.  */
1530
249k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
200k
    {
1532
200k
      bfd_set_error (bfd_error_wrong_format);
1533
200k
      return NULL;
1534
200k
    }
1535
1536
49.3k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
49.3k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
49.3k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
789
    {
1540
789
      if (bfd_get_error () != bfd_error_system_call)
1541
789
  bfd_set_error (bfd_error_wrong_format);
1542
789
      return NULL;
1543
789
    }
1544
1545
48.6k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
1.00k
    {
1547
1.00k
      bfd_set_error (bfd_error_wrong_format);
1548
1.00k
      return NULL;
1549
1.00k
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
47.6k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
47.6k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
8.00k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
39.6k
    {
1558
39.6k
      bfd_set_error (bfd_error_wrong_format);
1559
39.6k
      return NULL;
1560
39.6k
    }
1561
1562
7.94k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
7.94k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
7.94k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
7.94k
  if (opt_hdr_size != 0)
1569
4.66k
    {
1570
4.66k
      bfd_size_type amt = opt_hdr_size;
1571
4.66k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
4.66k
      if (amt < sizeof (PEAOUTHDR))
1575
4.32k
  amt = sizeof (PEAOUTHDR);
1576
1577
4.66k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
4.66k
      if (opthdr == NULL)
1579
43
  return NULL;
1580
4.62k
      if (amt > opt_hdr_size)
1581
4.28k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
4.62k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
4.62k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1586
1587
4.62k
#ifdef ARM
1588
      /* Use Subsystem to distinguish between pei-arm-little and
1589
   pei-arm-wince-little.  */
1590
4.62k
#ifdef WINCE
1591
4.62k
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1592
#else
1593
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1594
#endif
1595
2.66k
  {
1596
2.66k
    bfd_set_error (bfd_error_wrong_format);
1597
2.66k
    return NULL;
1598
2.66k
  }
1599
1.95k
#endif
1600
1601
1.95k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
399
    || a->SectionAlignment >= 0x80000000)
1603
1.58k
  {
1604
1.58k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
1.58k
            abfd);
1606
1.58k
    a->SectionAlignment &= -a->SectionAlignment;
1607
1.58k
    if (a->SectionAlignment >= 0x80000000)
1608
29
      a->SectionAlignment = 0x40000000;
1609
1.58k
  }
1610
1611
1.95k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
501
    || a->FileAlignment > a->SectionAlignment)
1613
1.70k
  {
1614
1.70k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
1.70k
            abfd);
1616
1.70k
    a->FileAlignment &= -a->FileAlignment;
1617
1.70k
    if (a->FileAlignment > a->SectionAlignment)
1618
1.28k
      a->FileAlignment = a->SectionAlignment;
1619
1.70k
  }
1620
1621
1.95k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
1.45k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
1.95k
    }
1624
1625
5.23k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
5.23k
             (opt_hdr_size != 0
1627
5.23k
        ? &internal_a
1628
5.23k
        : (struct internal_aouthdr *) NULL));
1629
1630
5.23k
  if (result)
1631
2.28k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
2.28k
      pe_bfd_read_buildid(abfd);
1634
2.28k
    }
1635
1636
5.23k
  return result;
1637
7.94k
}
pei-arm.c:pe_bfd_object_p
Line
Count
Source
1487
345k
{
1488
345k
  bfd_byte buffer[6];
1489
345k
  struct external_DOS_hdr dos_hdr;
1490
345k
  struct external_PEI_IMAGE_hdr image_hdr;
1491
345k
  struct internal_filehdr internal_f;
1492
345k
  struct internal_aouthdr internal_a;
1493
345k
  bfd_size_type opt_hdr_size;
1494
345k
  file_ptr offset;
1495
345k
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
345k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
345k
      || bfd_read (buffer, 6, abfd) != 6)
1501
3.29k
    {
1502
3.29k
      if (bfd_get_error () != bfd_error_system_call)
1503
3.23k
  bfd_set_error (bfd_error_wrong_format);
1504
3.29k
      return NULL;
1505
3.29k
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
342k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
4.20k
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
3.56k
    return pe_ILF_object_p (abfd);
1511
1512
338k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
338k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
89.1k
    {
1515
89.1k
      if (bfd_get_error () != bfd_error_system_call)
1516
89.1k
  bfd_set_error (bfd_error_wrong_format);
1517
89.1k
      return NULL;
1518
89.1k
    }
1519
1520
  /* There are really two magic numbers involved; the magic number
1521
     that says this is a NT executable (PEI) and the magic number that
1522
     determines the architecture.  The former is IMAGE_DOS_SIGNATURE, stored in
1523
     the e_magic field.  The latter is stored in the f_magic field.
1524
     If the NT magic number isn't valid, the architecture magic number
1525
     could be mimicked by some other field (specifically, the number
1526
     of relocs in section 3).  Since this routine can only be called
1527
     correctly for a PEI file, check the e_magic number here, and, if
1528
     it doesn't match, clobber the f_magic number so that we don't get
1529
     a false match.  */
1530
249k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
200k
    {
1532
200k
      bfd_set_error (bfd_error_wrong_format);
1533
200k
      return NULL;
1534
200k
    }
1535
1536
49.6k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
49.6k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
49.6k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
789
    {
1540
789
      if (bfd_get_error () != bfd_error_system_call)
1541
789
  bfd_set_error (bfd_error_wrong_format);
1542
789
      return NULL;
1543
789
    }
1544
1545
48.8k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
1.00k
    {
1547
1.00k
      bfd_set_error (bfd_error_wrong_format);
1548
1.00k
      return NULL;
1549
1.00k
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
47.8k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
47.8k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
8.25k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
39.6k
    {
1558
39.6k
      bfd_set_error (bfd_error_wrong_format);
1559
39.6k
      return NULL;
1560
39.6k
    }
1561
1562
8.20k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
8.20k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
8.20k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
8.20k
  if (opt_hdr_size != 0)
1569
4.92k
    {
1570
4.92k
      bfd_size_type amt = opt_hdr_size;
1571
4.92k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
4.92k
      if (amt < sizeof (PEAOUTHDR))
1575
4.58k
  amt = sizeof (PEAOUTHDR);
1576
1577
4.92k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
4.92k
      if (opthdr == NULL)
1579
43
  return NULL;
1580
4.87k
      if (amt > opt_hdr_size)
1581
4.55k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
4.87k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
4.87k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1586
1587
4.87k
#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.87k
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1594
1.48k
#endif
1595
1.48k
  {
1596
1.48k
    bfd_set_error (bfd_error_wrong_format);
1597
1.48k
    return NULL;
1598
1.48k
  }
1599
3.38k
#endif
1600
1601
3.38k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
1.42k
    || a->SectionAlignment >= 0x80000000)
1603
2.01k
  {
1604
2.01k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
2.01k
            abfd);
1606
2.01k
    a->SectionAlignment &= -a->SectionAlignment;
1607
2.01k
    if (a->SectionAlignment >= 0x80000000)
1608
49
      a->SectionAlignment = 0x40000000;
1609
2.01k
  }
1610
1611
3.38k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
1.56k
    || a->FileAlignment > a->SectionAlignment)
1613
2.21k
  {
1614
2.21k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
2.21k
            abfd);
1616
2.21k
    a->FileAlignment &= -a->FileAlignment;
1617
2.21k
    if (a->FileAlignment > a->SectionAlignment)
1618
1.75k
      a->FileAlignment = a->SectionAlignment;
1619
2.21k
  }
1620
1621
3.38k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
1.87k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
3.38k
    }
1624
1625
6.67k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
6.67k
             (opt_hdr_size != 0
1627
6.67k
        ? &internal_a
1628
6.67k
        : (struct internal_aouthdr *) NULL));
1629
1630
6.67k
  if (result)
1631
3.31k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
3.31k
      pe_bfd_read_buildid(abfd);
1634
3.31k
    }
1635
1636
6.67k
  return result;
1637
8.20k
}
pei-mcore.c:pe_bfd_object_p
Line
Count
Source
1487
345k
{
1488
345k
  bfd_byte buffer[6];
1489
345k
  struct external_DOS_hdr dos_hdr;
1490
345k
  struct external_PEI_IMAGE_hdr image_hdr;
1491
345k
  struct internal_filehdr internal_f;
1492
345k
  struct internal_aouthdr internal_a;
1493
345k
  bfd_size_type opt_hdr_size;
1494
345k
  file_ptr offset;
1495
345k
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
345k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
345k
      || bfd_read (buffer, 6, abfd) != 6)
1501
3.29k
    {
1502
3.29k
      if (bfd_get_error () != bfd_error_system_call)
1503
3.23k
  bfd_set_error (bfd_error_wrong_format);
1504
3.29k
      return NULL;
1505
3.29k
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
342k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
4.19k
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
3.56k
    return pe_ILF_object_p (abfd);
1511
1512
339k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
339k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
89.2k
    {
1515
89.2k
      if (bfd_get_error () != bfd_error_system_call)
1516
89.2k
  bfd_set_error (bfd_error_wrong_format);
1517
89.2k
      return NULL;
1518
89.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
249k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
201k
    {
1532
201k
      bfd_set_error (bfd_error_wrong_format);
1533
201k
      return NULL;
1534
201k
    }
1535
1536
47.9k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
47.9k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
47.9k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
133
    {
1540
133
      if (bfd_get_error () != bfd_error_system_call)
1541
133
  bfd_set_error (bfd_error_wrong_format);
1542
133
      return NULL;
1543
133
    }
1544
1545
47.8k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
385
    {
1547
385
      bfd_set_error (bfd_error_wrong_format);
1548
385
      return NULL;
1549
385
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
47.4k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
47.4k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
4.85k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
42.6k
    {
1558
42.6k
      bfd_set_error (bfd_error_wrong_format);
1559
42.6k
      return NULL;
1560
42.6k
    }
1561
1562
4.82k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
4.82k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
4.82k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
4.82k
  if (opt_hdr_size != 0)
1569
2.80k
    {
1570
2.80k
      bfd_size_type amt = opt_hdr_size;
1571
2.80k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
2.80k
      if (amt < sizeof (PEAOUTHDR))
1575
2.59k
  amt = sizeof (PEAOUTHDR);
1576
1577
2.80k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
2.80k
      if (opthdr == NULL)
1579
32
  return NULL;
1580
2.77k
      if (amt > opt_hdr_size)
1581
2.57k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
2.77k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
2.77k
      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.77k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
1.26k
    || a->SectionAlignment >= 0x80000000)
1603
1.54k
  {
1604
1.54k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
1.54k
            abfd);
1606
1.54k
    a->SectionAlignment &= -a->SectionAlignment;
1607
1.54k
    if (a->SectionAlignment >= 0x80000000)
1608
37
      a->SectionAlignment = 0x40000000;
1609
1.54k
  }
1610
1611
2.77k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
1.42k
    || a->FileAlignment > a->SectionAlignment)
1613
1.65k
  {
1614
1.65k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
1.65k
            abfd);
1616
1.65k
    a->FileAlignment &= -a->FileAlignment;
1617
1.65k
    if (a->FileAlignment > a->SectionAlignment)
1618
1.33k
      a->FileAlignment = a->SectionAlignment;
1619
1.65k
  }
1620
1621
2.77k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
1.41k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
2.77k
    }
1624
1625
4.79k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
4.79k
             (opt_hdr_size != 0
1627
4.79k
        ? &internal_a
1628
4.79k
        : (struct internal_aouthdr *) NULL));
1629
1630
4.79k
  if (result)
1631
3.02k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
3.02k
      pe_bfd_read_buildid(abfd);
1634
3.02k
    }
1635
1636
4.79k
  return result;
1637
4.82k
}
pei-sh.c:pe_bfd_object_p
Line
Count
Source
1487
174k
{
1488
174k
  bfd_byte buffer[6];
1489
174k
  struct external_DOS_hdr dos_hdr;
1490
174k
  struct external_PEI_IMAGE_hdr image_hdr;
1491
174k
  struct internal_filehdr internal_f;
1492
174k
  struct internal_aouthdr internal_a;
1493
174k
  bfd_size_type opt_hdr_size;
1494
174k
  file_ptr offset;
1495
174k
  bfd_cleanup result;
1496
1497
  /* Detect if this a Microsoft Import Library Format element.  */
1498
  /* First read the beginning of the header.  */
1499
174k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1500
174k
      || bfd_read (buffer, 6, abfd) != 6)
1501
1.64k
    {
1502
1.64k
      if (bfd_get_error () != bfd_error_system_call)
1503
1.60k
  bfd_set_error (bfd_error_wrong_format);
1504
1.64k
      return NULL;
1505
1.64k
    }
1506
1507
  /* Then check the magic and the version (only 0 is supported).  */
1508
173k
  if (H_GET_32 (abfd, buffer) == 0xffff0000
1509
4.14k
      && H_GET_16 (abfd, buffer + 4) == 0)
1510
3.52k
    return pe_ILF_object_p (abfd);
1511
1512
169k
  if (bfd_seek (abfd, 0, SEEK_SET) != 0
1513
169k
      || bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr))
1514
43.2k
    {
1515
43.2k
      if (bfd_get_error () != bfd_error_system_call)
1516
43.2k
  bfd_set_error (bfd_error_wrong_format);
1517
43.2k
      return NULL;
1518
43.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
126k
  if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
1531
78.5k
    {
1532
78.5k
      bfd_set_error (bfd_error_wrong_format);
1533
78.5k
      return NULL;
1534
78.5k
    }
1535
1536
47.9k
  offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
1537
47.9k
  if (bfd_seek (abfd, offset, SEEK_SET) != 0
1538
47.9k
      || bfd_read (&image_hdr, sizeof (image_hdr), abfd) != sizeof (image_hdr))
1539
133
    {
1540
133
      if (bfd_get_error () != bfd_error_system_call)
1541
133
  bfd_set_error (bfd_error_wrong_format);
1542
133
      return NULL;
1543
133
    }
1544
1545
47.7k
  if (H_GET_32 (abfd, image_hdr.nt_signature) != 0x4550)
1546
382
    {
1547
382
      bfd_set_error (bfd_error_wrong_format);
1548
382
      return NULL;
1549
382
    }
1550
1551
  /* Swap file header, so that we get the location for calling
1552
     real_object_p.  */
1553
47.4k
  bfd_coff_swap_filehdr_in (abfd, &image_hdr, &internal_f);
1554
1555
47.4k
  if (! bfd_coff_bad_format_hook (abfd, &internal_f)
1556
4.83k
      || internal_f.f_opthdr > bfd_coff_aoutsz (abfd))
1557
42.5k
    {
1558
42.5k
      bfd_set_error (bfd_error_wrong_format);
1559
42.5k
      return NULL;
1560
42.5k
    }
1561
1562
4.81k
  memcpy (internal_f.pe.dos_message, dos_hdr.dos_message,
1563
4.81k
    sizeof (internal_f.pe.dos_message));
1564
1565
  /* Read the optional header, which has variable size.  */
1566
4.81k
  opt_hdr_size = internal_f.f_opthdr;
1567
1568
4.81k
  if (opt_hdr_size != 0)
1569
2.91k
    {
1570
2.91k
      bfd_size_type amt = opt_hdr_size;
1571
2.91k
      bfd_byte *opthdr;
1572
1573
      /* PR 17521 file: 230-131433-0.004.  */
1574
2.91k
      if (amt < sizeof (PEAOUTHDR))
1575
2.71k
  amt = sizeof (PEAOUTHDR);
1576
1577
2.91k
      opthdr = _bfd_alloc_and_read (abfd, amt, opt_hdr_size);
1578
2.91k
      if (opthdr == NULL)
1579
44
  return NULL;
1580
2.87k
      if (amt > opt_hdr_size)
1581
2.67k
  memset (opthdr + opt_hdr_size, 0, amt - opt_hdr_size);
1582
1583
2.87k
      bfd_coff_swap_aouthdr_in (abfd, opthdr, &internal_a);
1584
1585
2.87k
      struct internal_extra_pe_aouthdr *a = &internal_a.pe;
1586
1587
#ifdef ARM
1588
      /* Use Subsystem to distinguish between pei-arm-little and
1589
   pei-arm-wince-little.  */
1590
#ifdef WINCE
1591
      if (a->Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1592
#else
1593
      if (a->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)
1594
#endif
1595
  {
1596
    bfd_set_error (bfd_error_wrong_format);
1597
    return NULL;
1598
  }
1599
#endif
1600
1601
2.87k
      if ((a->SectionAlignment & -a->SectionAlignment) != a->SectionAlignment
1602
1.57k
    || a->SectionAlignment >= 0x80000000)
1603
1.31k
  {
1604
1.31k
    _bfd_error_handler (_("%pB: adjusting invalid SectionAlignment"),
1605
1.31k
            abfd);
1606
1.31k
    a->SectionAlignment &= -a->SectionAlignment;
1607
1.31k
    if (a->SectionAlignment >= 0x80000000)
1608
18
      a->SectionAlignment = 0x40000000;
1609
1.31k
  }
1610
1611
2.87k
      if ((a->FileAlignment & -a->FileAlignment) != a->FileAlignment
1612
1.54k
    || a->FileAlignment > a->SectionAlignment)
1613
1.56k
  {
1614
1.56k
    _bfd_error_handler (_("%pB: adjusting invalid FileAlignment"),
1615
1.56k
            abfd);
1616
1.56k
    a->FileAlignment &= -a->FileAlignment;
1617
1.56k
    if (a->FileAlignment > a->SectionAlignment)
1618
1.15k
      a->FileAlignment = a->SectionAlignment;
1619
1.56k
  }
1620
1621
2.87k
      if (a->NumberOfRvaAndSizes > IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
1622
1.49k
  _bfd_error_handler (_("%pB: invalid NumberOfRvaAndSizes"), abfd);
1623
2.87k
    }
1624
1625
4.77k
  result = coff_real_object_p (abfd, internal_f.f_nscns, &internal_f,
1626
4.77k
             (opt_hdr_size != 0
1627
4.77k
        ? &internal_a
1628
4.77k
        : (struct internal_aouthdr *) NULL));
1629
1630
4.77k
  if (result)
1631
3.15k
    {
1632
      /* Now the whole header has been processed, see if there is a build-id */
1633
3.15k
      pe_bfd_read_buildid(abfd);
1634
3.15k
    }
1635
1636
4.77k
  return result;
1637
4.81k
}
1638
1639
15.2k
#define coff_object_p pe_bfd_object_p
1640
#endif /* COFF_IMAGE_WITH_PE */