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