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