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