From Craig Silverstein: Only sort for suffixes with -O2.
[deliverable/binutils-gdb.git] / bfd / coff-ia64.c
CommitLineData
fac41780 1/* BFD back-end for HP/Intel IA-64 COFF files.
3db64b00 2 Copyright 1999, 2000, 2001, 2002, 2007 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)
31/* The page size is a guess based on ELF. */
32
33#define COFF_PAGE_SIZE 0x1000
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) \
50 (cache_ptr)->howto = howto_table + (dst)->r_type;
51
52#ifdef COFF_WITH_PE
b34976b6 53/* Return TRUE if this relocation should
5fcfd273 54 appear in the output .reloc section. */
fac41780 55
b34976b6 56static bfd_boolean in_reloc_p PARAMS ((bfd *, reloc_howto_type *));
cea4409c 57
b34976b6 58static bfd_boolean
fac41780 59in_reloc_p(abfd, howto)
64bf6ae6
JW
60 bfd * abfd ATTRIBUTE_UNUSED;
61 reloc_howto_type *howto ATTRIBUTE_UNUSED;
fac41780 62{
b34976b6 63 return FALSE; /* We don't do relocs for now... */
5fcfd273 64}
fac41780
JW
65#endif
66
67#include "coffcode.h"
68
cea4409c
AM
69static const bfd_target *ia64coff_object_p PARAMS ((bfd *));
70
fac41780
JW
71static const bfd_target *
72ia64coff_object_p (abfd)
73 bfd *abfd;
74{
75#ifdef COFF_IMAGE_WITH_PE
fac41780 76 {
27e53099
L
77 struct external_PEI_DOS_hdr dos_hdr;
78 struct external_PEI_IMAGE_hdr image_hdr;
fac41780 79 file_ptr offset;
fac41780 80
dc810e39
AM
81 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
82 || (bfd_bread (&dos_hdr, (bfd_size_type) sizeof (dos_hdr), abfd)
83 != sizeof (dos_hdr)))
fac41780
JW
84 {
85 if (bfd_get_error () != bfd_error_system_call)
86 bfd_set_error (bfd_error_wrong_format);
87 return NULL;
88 }
27e53099
L
89
90 /* There are really two magic numbers involved; the magic number
91 that says this is a NT executable (PEI) and the magic number
92 that determines the architecture. The former is DOSMAGIC,
93 stored in the e_magic field. The latter is stored in the
94 f_magic field. If the NT magic number isn't valid, the
95 architecture magic number could be mimicked by some other
96 field (specifically, the number of relocs in section 3). Since
97 this routine can only be called correctly for a PEI file, check
98 the e_magic number here, and, if it doesn't match, clobber the
99 f_magic number so that we don't get a false match. */
dc810e39 100 if (H_GET_16 (abfd, dos_hdr.e_magic) != DOSMAGIC)
27e53099
L
101 {
102 bfd_set_error (bfd_error_wrong_format);
103 return NULL;
104 }
105
dc810e39
AM
106 offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
107 if (bfd_seek (abfd, offset, SEEK_SET) != 0
108 || (bfd_bread (&image_hdr, (bfd_size_type) sizeof (image_hdr), abfd)
109 != sizeof (image_hdr)))
fac41780
JW
110 {
111 if (bfd_get_error () != bfd_error_system_call)
112 bfd_set_error (bfd_error_wrong_format);
113 return NULL;
114 }
fac41780 115
dc810e39 116 if (H_GET_32 (abfd, image_hdr.nt_signature)
27e53099 117 != 0x4550)
fac41780
JW
118 {
119 bfd_set_error (bfd_error_wrong_format);
120 return NULL;
121 }
122
123 /* Here is the hack. coff_object_p wants to read filhsz bytes to
27e53099
L
124 pick up the COFF header for PE, see "struct external_PEI_filehdr"
125 in include/coff/pe.h. We adjust so that that will work. */
dc810e39 126 if (bfd_seek (abfd, offset - sizeof (dos_hdr), SEEK_SET) != 0)
fac41780
JW
127 {
128 if (bfd_get_error () != bfd_error_system_call)
129 bfd_set_error (bfd_error_wrong_format);
130 return NULL;
131 }
132 }
133#endif
134
135 return coff_object_p (abfd);
136}
137
138const bfd_target
139#ifdef TARGET_SYM
140 TARGET_SYM =
141#else
142 ia64coff_vec =
143#endif
144{
145#ifdef TARGET_NAME
146 TARGET_NAME,
147#else
148 "coff-ia64", /* name */
149#endif
150 bfd_target_coff_flavour,
151 BFD_ENDIAN_LITTLE, /* data byte order is little */
152 BFD_ENDIAN_LITTLE, /* header byte order is little */
153
154 (HAS_RELOC | EXEC_P | /* object flags */
155 HAS_LINENO | HAS_DEBUG |
156 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
157
158#ifndef COFF_WITH_PE
159 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC /* section flags */
160 | SEC_CODE | SEC_DATA),
161#else
162 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC /* section flags */
163 | SEC_CODE | SEC_DATA
164 | SEC_LINK_ONCE | SEC_LINK_DUPLICATES),
165#endif
166
167#ifdef TARGET_UNDERSCORE
168 TARGET_UNDERSCORE, /* leading underscore */
169#else
170 0, /* leading underscore */
171#endif
172 '/', /* ar_pad_char */
173 15, /* ar_max_namelen */
174
175 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
176 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
177 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
178 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
179 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
180 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
181
5fcfd273 182/* Note that we allow an object file to be treated as a core file as well. */
fac41780
JW
183 {_bfd_dummy_target, ia64coff_object_p, /* bfd_check_format */
184 bfd_generic_archive_p, ia64coff_object_p},
185 {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
186 bfd_false},
187 {bfd_false, coff_write_object_contents, /* bfd_write_contents */
188 _bfd_write_archive_contents, bfd_false},
189
190 BFD_JUMP_TABLE_GENERIC (coff),
191 BFD_JUMP_TABLE_COPY (coff),
192 BFD_JUMP_TABLE_CORE (_bfd_nocore),
193 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
194 BFD_JUMP_TABLE_SYMBOLS (coff),
195 BFD_JUMP_TABLE_RELOCS (coff),
196 BFD_JUMP_TABLE_WRITE (coff),
197 BFD_JUMP_TABLE_LINK (coff),
198 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
199
200 NULL,
201
202 COFF_SWAP_TABLE
203};
This page took 0.324755 seconds and 4 git commands to generate.