Coverage Report

Created: 2026-03-10 08:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/binutils-gdb/bfd/coff-ia64.c
Line
Count
Source
1
/* BFD back-end for HP/Intel IA-64 COFF files.
2
   Copyright (C) 1999-2026 Free Software Foundation, Inc.
3
   Contributed by David Mosberger <davidm@hpl.hp.com>
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
#ifndef COFF_WITH_PE
23
#error non-PE COFF unsupported
24
#endif
25
26
#include "sysdep.h"
27
#include "bfd.h"
28
#include "libbfd.h"
29
#include "coff/ia64.h"
30
#include "coff/internal.h"
31
#include "coff/pe.h"
32
#include "libcoff.h"
33
34
91.5k
#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (2)
35
36
/* Windows ia64 uses 8K page size.  */
37
179
#define COFF_PAGE_SIZE 0x2000
38
39
static reloc_howto_type howto_table[] =
40
{
41
  EMPTY_HOWTO (0),
42
};
43
44
20.2k
#define BADMAG(x) IA64BADMAG(x)
45
#define IA64 1      /* Customize coffcode.h */
46
47
#ifdef COFF_WITH_pep
48
# undef AOUTSZ
49
# define AOUTSZ   PEPAOUTSZ
50
# define PEAOUTHDR  PEPAOUTHDR
51
#endif
52
53
#define RTYPE2HOWTO(cache_ptr, dst) \
54
0
  (cache_ptr)->howto = howto_table;
55
56
#ifdef COFF_WITH_PE
57
/* Return TRUE if this relocation should
58
   appear in the output .reloc section.  */
59
60
static bool
61
in_reloc_p (bfd * abfd ATTRIBUTE_UNUSED,
62
      reloc_howto_type *howto ATTRIBUTE_UNUSED)
63
0
{
64
0
  return false;      /* We don't do relocs for now...  */
65
0
}
66
#endif
67
68
#ifndef bfd_pe_print_pdata
69
#define bfd_pe_print_pdata  NULL
70
#endif
71
72
#include "coffcode.h"
73
74
static bfd_cleanup
75
ia64coff_object_p (bfd *abfd)
76
159k
{
77
159k
#ifdef COFF_IMAGE_WITH_PE
78
159k
  {
79
159k
    struct external_DOS_hdr dos_hdr;
80
159k
    struct external_PEI_IMAGE_hdr image_hdr;
81
159k
    file_ptr offset;
82
83
159k
    if (bfd_seek (abfd, 0, SEEK_SET) != 0
84
159k
  || (bfd_read (&dos_hdr, sizeof (dos_hdr), abfd) != sizeof (dos_hdr)))
85
38.1k
      {
86
38.1k
  if (bfd_get_error () != bfd_error_system_call)
87
38.1k
    bfd_set_error (bfd_error_wrong_format);
88
38.1k
  return NULL;
89
38.1k
      }
90
91
    /* There are really two magic numbers involved; the magic number
92
       that says this is a NT executable (PEI) and the magic number
93
       that determines the architecture.  The former is IMAGE_DOS_SIGNATURE,
94
       stored in the e_magic field.  The latter is stored in the
95
       f_magic field.  If the NT magic number isn't valid, the
96
       architecture magic number could be mimicked by some other
97
       field (specifically, the number of relocs in section 3).  Since
98
       this routine can only be called correctly for a PEI file, check
99
       the e_magic number here, and, if it doesn't match, clobber the
100
       f_magic number so that we don't get a false match.  */
101
121k
    if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
102
76.0k
      {
103
76.0k
  bfd_set_error (bfd_error_wrong_format);
104
76.0k
  return NULL;
105
76.0k
      }
106
107
45.1k
    offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
108
45.1k
    if (bfd_seek (abfd, offset, SEEK_SET) != 0
109
45.1k
  || (bfd_read (&image_hdr, sizeof (image_hdr), abfd)
110
45.1k
      != sizeof (image_hdr)))
111
111
      {
112
111
  if (bfd_get_error () != bfd_error_system_call)
113
111
    bfd_set_error (bfd_error_wrong_format);
114
111
  return NULL;
115
111
      }
116
117
45.0k
    if (H_GET_32 (abfd, image_hdr.nt_signature)
118
45.0k
  != 0x4550)
119
287
      {
120
287
  bfd_set_error (bfd_error_wrong_format);
121
287
  return NULL;
122
287
      }
123
124
    /* Here is the hack.  coff_object_p wants to read filhsz bytes to
125
       pick up the COFF header for PE, see "struct external_PEI_filehdr"
126
       in include/coff/pe.h.  We adjust so that that will work. */
127
44.7k
    if (bfd_seek (abfd, offset - sizeof (dos_hdr), SEEK_SET) != 0)
128
24.5k
      {
129
24.5k
  if (bfd_get_error () != bfd_error_system_call)
130
24.5k
    bfd_set_error (bfd_error_wrong_format);
131
24.5k
  return NULL;
132
24.5k
      }
133
44.7k
  }
134
20.2k
#endif
135
136
20.2k
  return coff_object_p (abfd);
137
44.7k
}
138
139
const bfd_target
140
#ifdef TARGET_SYM
141
  TARGET_SYM =
142
#else
143
  ia64coff_vec =
144
#endif
145
{
146
#ifdef TARGET_NAME
147
  TARGET_NAME,
148
#else
149
  "coff-ia64",      /* name */
150
#endif
151
  bfd_target_coff_flavour,
152
  BFD_ENDIAN_LITTLE,    /* data byte order is little */
153
  BFD_ENDIAN_LITTLE,    /* header byte order is little */
154
155
  (HAS_RELOC | EXEC_P   /* object flags */
156
   | HAS_LINENO | HAS_DEBUG
157
   | HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
158
159
#ifndef COFF_WITH_PE
160
  (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC /* section flags */
161
   | SEC_CODE | SEC_DATA),
162
#else
163
  (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC /* section flags */
164
   | SEC_CODE | SEC_DATA
165
   | SEC_LINK_ONCE | SEC_LINK_DUPLICATES),
166
#endif
167
168
#ifdef TARGET_UNDERSCORE
169
  TARGET_UNDERSCORE,    /* leading underscore */
170
#else
171
  0,        /* leading underscore */
172
#endif
173
  '/',        /* ar_pad_char */
174
  15,       /* ar_max_namelen */
175
  0,        /* match priority.  */
176
  TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols.  */
177
  TARGET_MERGE_SECTIONS,
178
179
  bfd_getl64, bfd_getl_signed_64, bfd_putl64,
180
     bfd_getl32, bfd_getl_signed_32, bfd_putl32,
181
     bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
182
  bfd_getl64, bfd_getl_signed_64, bfd_putl64,
183
     bfd_getl32, bfd_getl_signed_32, bfd_putl32,
184
     bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
185
186
/* Note that we allow an object file to be treated as a core file as well.  */
187
  {       /* bfd_check_format */
188
    _bfd_dummy_target,
189
    ia64coff_object_p,
190
    bfd_generic_archive_p,
191
    ia64coff_object_p
192
  },
193
  {       /* bfd_set_format */
194
    _bfd_bool_bfd_false_error,
195
    coff_mkobject,
196
    _bfd_generic_mkarchive,
197
    _bfd_bool_bfd_false_error
198
  },
199
  {       /* bfd_write_contents */
200
    _bfd_bool_bfd_false_error,
201
    coff_write_object_contents,
202
    _bfd_write_archive_contents,
203
    _bfd_bool_bfd_false_error
204
  },
205
206
  BFD_JUMP_TABLE_GENERIC (coff),
207
  BFD_JUMP_TABLE_COPY (coff),
208
  BFD_JUMP_TABLE_CORE (_bfd_nocore),
209
  BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
210
  BFD_JUMP_TABLE_SYMBOLS (coff),
211
  BFD_JUMP_TABLE_RELOCS (coff),
212
  BFD_JUMP_TABLE_WRITE (coff),
213
  BFD_JUMP_TABLE_LINK (coff),
214
  BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
215
216
  NULL,
217
218
  COFF_SWAP_TABLE
219
};