coff-ia64.c revision 1.1.1.6 1 1.1 christos /* BFD back-end for HP/Intel IA-64 COFF files.
2 1.1.1.6 christos Copyright (C) 1999-2022 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.1.1.2 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.1.1.6 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.1.1.6 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.1.1.6 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.1.1.4 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.1 christos if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
80 1.1 christos || (bfd_bread (&dos_hdr, (bfd_size_type) sizeof (dos_hdr), abfd)
81 1.1 christos != sizeof (dos_hdr)))
82 1.1 christos {
83 1.1 christos if (bfd_get_error () != bfd_error_system_call)
84 1.1 christos bfd_set_error (bfd_error_wrong_format);
85 1.1 christos return NULL;
86 1.1 christos }
87 1.1 christos
88 1.1 christos /* There are really two magic numbers involved; the magic number
89 1.1 christos that says this is a NT executable (PEI) and the magic number
90 1.1.1.4 christos that determines the architecture. The former is IMAGE_DOS_SIGNATURE,
91 1.1 christos stored in the e_magic field. The latter is stored in the
92 1.1 christos f_magic field. If the NT magic number isn't valid, the
93 1.1 christos architecture magic number could be mimicked by some other
94 1.1 christos field (specifically, the number of relocs in section 3). Since
95 1.1 christos this routine can only be called correctly for a PEI file, check
96 1.1 christos the e_magic number here, and, if it doesn't match, clobber the
97 1.1 christos f_magic number so that we don't get a false match. */
98 1.1.1.4 christos if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
99 1.1 christos {
100 1.1 christos bfd_set_error (bfd_error_wrong_format);
101 1.1 christos return NULL;
102 1.1 christos }
103 1.1 christos
104 1.1 christos offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
105 1.1 christos if (bfd_seek (abfd, offset, SEEK_SET) != 0
106 1.1 christos || (bfd_bread (&image_hdr, (bfd_size_type) sizeof (image_hdr), abfd)
107 1.1 christos != sizeof (image_hdr)))
108 1.1 christos {
109 1.1 christos if (bfd_get_error () != bfd_error_system_call)
110 1.1 christos bfd_set_error (bfd_error_wrong_format);
111 1.1 christos return NULL;
112 1.1 christos }
113 1.1 christos
114 1.1 christos if (H_GET_32 (abfd, image_hdr.nt_signature)
115 1.1 christos != 0x4550)
116 1.1 christos {
117 1.1 christos bfd_set_error (bfd_error_wrong_format);
118 1.1 christos return NULL;
119 1.1 christos }
120 1.1 christos
121 1.1 christos /* Here is the hack. coff_object_p wants to read filhsz bytes to
122 1.1 christos pick up the COFF header for PE, see "struct external_PEI_filehdr"
123 1.1 christos in include/coff/pe.h. We adjust so that that will work. */
124 1.1 christos if (bfd_seek (abfd, offset - sizeof (dos_hdr), SEEK_SET) != 0)
125 1.1 christos {
126 1.1 christos if (bfd_get_error () != bfd_error_system_call)
127 1.1 christos bfd_set_error (bfd_error_wrong_format);
128 1.1 christos return NULL;
129 1.1 christos }
130 1.1 christos }
131 1.1 christos #endif
132 1.1 christos
133 1.1 christos return coff_object_p (abfd);
134 1.1 christos }
135 1.1 christos
136 1.1 christos const bfd_target
137 1.1 christos #ifdef TARGET_SYM
138 1.1 christos TARGET_SYM =
139 1.1 christos #else
140 1.1 christos ia64coff_vec =
141 1.1 christos #endif
142 1.1 christos {
143 1.1 christos #ifdef TARGET_NAME
144 1.1 christos TARGET_NAME,
145 1.1 christos #else
146 1.1 christos "coff-ia64", /* name */
147 1.1 christos #endif
148 1.1 christos bfd_target_coff_flavour,
149 1.1 christos BFD_ENDIAN_LITTLE, /* data byte order is little */
150 1.1 christos BFD_ENDIAN_LITTLE, /* header byte order is little */
151 1.1 christos
152 1.1.1.4 christos (HAS_RELOC | EXEC_P /* object flags */
153 1.1.1.4 christos | HAS_LINENO | HAS_DEBUG
154 1.1.1.4 christos | HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
155 1.1 christos
156 1.1 christos #ifndef COFF_WITH_PE
157 1.1 christos (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC /* section flags */
158 1.1 christos | SEC_CODE | SEC_DATA),
159 1.1 christos #else
160 1.1 christos (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC /* section flags */
161 1.1 christos | SEC_CODE | SEC_DATA
162 1.1 christos | SEC_LINK_ONCE | SEC_LINK_DUPLICATES),
163 1.1 christos #endif
164 1.1 christos
165 1.1 christos #ifdef TARGET_UNDERSCORE
166 1.1 christos TARGET_UNDERSCORE, /* leading underscore */
167 1.1 christos #else
168 1.1 christos 0, /* leading underscore */
169 1.1 christos #endif
170 1.1 christos '/', /* ar_pad_char */
171 1.1 christos 15, /* ar_max_namelen */
172 1.1 christos 0, /* match priority. */
173 1.1.1.6 christos TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */
174 1.1 christos
175 1.1 christos bfd_getl64, bfd_getl_signed_64, bfd_putl64,
176 1.1 christos bfd_getl32, bfd_getl_signed_32, bfd_putl32,
177 1.1 christos bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
178 1.1 christos bfd_getl64, bfd_getl_signed_64, bfd_putl64,
179 1.1 christos bfd_getl32, bfd_getl_signed_32, bfd_putl32,
180 1.1 christos bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
181 1.1 christos
182 1.1 christos /* Note that we allow an object file to be treated as a core file as well. */
183 1.1.1.4 christos { /* bfd_check_format */
184 1.1.1.4 christos _bfd_dummy_target,
185 1.1.1.4 christos ia64coff_object_p,
186 1.1.1.4 christos bfd_generic_archive_p,
187 1.1.1.4 christos ia64coff_object_p
188 1.1.1.4 christos },
189 1.1.1.4 christos { /* bfd_set_format */
190 1.1.1.4 christos _bfd_bool_bfd_false_error,
191 1.1.1.4 christos coff_mkobject,
192 1.1.1.4 christos _bfd_generic_mkarchive,
193 1.1.1.4 christos _bfd_bool_bfd_false_error
194 1.1.1.4 christos },
195 1.1.1.4 christos { /* bfd_write_contents */
196 1.1.1.4 christos _bfd_bool_bfd_false_error,
197 1.1.1.4 christos coff_write_object_contents,
198 1.1.1.4 christos _bfd_write_archive_contents,
199 1.1.1.4 christos _bfd_bool_bfd_false_error
200 1.1.1.4 christos },
201 1.1.1.4 christos
202 1.1.1.4 christos BFD_JUMP_TABLE_GENERIC (coff),
203 1.1.1.4 christos BFD_JUMP_TABLE_COPY (coff),
204 1.1.1.4 christos BFD_JUMP_TABLE_CORE (_bfd_nocore),
205 1.1.1.4 christos BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
206 1.1.1.4 christos BFD_JUMP_TABLE_SYMBOLS (coff),
207 1.1.1.4 christos BFD_JUMP_TABLE_RELOCS (coff),
208 1.1.1.4 christos BFD_JUMP_TABLE_WRITE (coff),
209 1.1.1.4 christos BFD_JUMP_TABLE_LINK (coff),
210 1.1.1.4 christos BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
211 1.1 christos
212 1.1 christos NULL,
213 1.1 christos
214 1.1 christos COFF_SWAP_TABLE
215 1.1 christos };
216