Add field ``name'' to floatformat.
[binutils.git] / bfd / coff-ia64.c
blobdf867e737171ed6befff3efc275afaae312ca451
1 /* BFD back-end for HP/Intel IA-64 COFF files.
2 Copyright 1999 Free Software Foundation, Inc.
3 Contributed by David Mosberger <davidm@hpl.hp.com>
5 This file is part of BFD, the Binary File Descriptor library.
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 2 of the License, or
10 (at your option) any later version.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 #include "bfd.h"
22 #include "sysdep.h"
23 #include "libbfd.h"
25 #include "coff/ia64.h"
27 #include "coff/internal.h"
29 #include "coff/pe.h"
31 #include "libcoff.h"
33 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (2)
34 /* The page size is a guess based on ELF. */
36 #define COFF_PAGE_SIZE 0x1000
38 static reloc_howto_type howto_table[] =
40 {0},
43 #define BADMAG(x) IA64BADMAG(x)
44 #define IA64 1 /* Customize coffcode.h */
46 #ifdef COFF_WITH_PEP64
47 # undef AOUTSZ
48 # define AOUTSZ PEP64AOUTSZ
49 # define PEAOUTHDR PEP64AOUTHDR
50 #endif
52 #define RTYPE2HOWTO(cache_ptr, dst) \
53 (cache_ptr)->howto = howto_table + (dst)->r_type;
55 #ifdef COFF_WITH_PE
56 /* Return true if this relocation should
57 appear in the output .reloc section. */
59 static boolean
60 in_reloc_p(abfd, howto)
61 bfd * abfd;
62 reloc_howto_type *howto;
64 return 0; /* We don't do relocs for now... */
66 #endif
68 #include "coffcode.h"
70 static const bfd_target *
71 ia64coff_object_p (abfd)
72 bfd *abfd;
74 #ifdef COFF_IMAGE_WITH_PE
75 /* We need to hack badly to handle a PE image correctly. In PE
76 images created by the GNU linker, the offset to the COFF header
77 is always the size. However, this is not the case in images
78 generated by other PE linkers. The PE format stores a four byte
79 offset to the PE signature just before the COFF header at
80 location 0x3c of the file. We pick up that offset, verify that
81 the PE signature is there, and then set ourselves up to read in
82 the COFF header. */
84 bfd_byte ext_offset[4];
85 file_ptr offset;
86 bfd_byte ext_signature[4];
87 unsigned long signature;
89 if (bfd_seek (abfd, 0x3c, SEEK_SET) != 0
90 || bfd_read (ext_offset, 1, 4, abfd) != 4)
92 if (bfd_get_error () != bfd_error_system_call)
93 bfd_set_error (bfd_error_wrong_format);
94 return NULL;
96 offset = bfd_h_get_32 (abfd, ext_offset);
97 if (bfd_seek (abfd, offset, SEEK_SET) != 0
98 || bfd_read (ext_signature, 1, 4, abfd) != 4)
100 if (bfd_get_error () != bfd_error_system_call)
101 bfd_set_error (bfd_error_wrong_format);
102 return NULL;
104 signature = bfd_h_get_32 (abfd, ext_signature);
106 if (signature != 0x4550)
108 bfd_set_error (bfd_error_wrong_format);
109 return NULL;
112 /* Here is the hack. coff_object_p wants to read filhsz bytes to
113 pick up the COFF header. We adjust so that that will work. 20
114 is the size of the COFF filehdr. */
116 if (bfd_seek (abfd,
117 (bfd_tell (abfd)
118 - bfd_coff_filhsz (abfd)
119 + 20),
120 SEEK_SET)
121 != 0)
123 if (bfd_get_error () != bfd_error_system_call)
124 bfd_set_error (bfd_error_wrong_format);
125 return NULL;
128 #endif
130 return coff_object_p (abfd);
133 const bfd_target
134 #ifdef TARGET_SYM
135 TARGET_SYM =
136 #else
137 ia64coff_vec =
138 #endif
140 #ifdef TARGET_NAME
141 TARGET_NAME,
142 #else
143 "coff-ia64", /* name */
144 #endif
145 bfd_target_coff_flavour,
146 BFD_ENDIAN_LITTLE, /* data byte order is little */
147 BFD_ENDIAN_LITTLE, /* header byte order is little */
149 (HAS_RELOC | EXEC_P | /* object flags */
150 HAS_LINENO | HAS_DEBUG |
151 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
153 #ifndef COFF_WITH_PE
154 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC /* section flags */
155 | SEC_CODE | SEC_DATA),
156 #else
157 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC /* section flags */
158 | SEC_CODE | SEC_DATA
159 | SEC_LINK_ONCE | SEC_LINK_DUPLICATES),
160 #endif
162 #ifdef TARGET_UNDERSCORE
163 TARGET_UNDERSCORE, /* leading underscore */
164 #else
165 0, /* leading underscore */
166 #endif
167 '/', /* ar_pad_char */
168 15, /* ar_max_namelen */
170 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
171 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
172 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
173 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
174 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
175 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
177 /* Note that we allow an object file to be treated as a core file as well. */
178 {_bfd_dummy_target, ia64coff_object_p, /* bfd_check_format */
179 bfd_generic_archive_p, ia64coff_object_p},
180 {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
181 bfd_false},
182 {bfd_false, coff_write_object_contents, /* bfd_write_contents */
183 _bfd_write_archive_contents, bfd_false},
185 BFD_JUMP_TABLE_GENERIC (coff),
186 BFD_JUMP_TABLE_COPY (coff),
187 BFD_JUMP_TABLE_CORE (_bfd_nocore),
188 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
189 BFD_JUMP_TABLE_SYMBOLS (coff),
190 BFD_JUMP_TABLE_RELOCS (coff),
191 BFD_JUMP_TABLE_WRITE (coff),
192 BFD_JUMP_TABLE_LINK (coff),
193 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
195 NULL,
197 COFF_SWAP_TABLE