Support for xcoff64
[deliverable/binutils-gdb.git] / bfd / coff64-rs6000.c
CommitLineData
7f6d05e8 1/* BFD back-end for IBM RS/6000 "XCOFF64" files.
7898deda 2 Copyright 2000, 2001
7f6d05e8
CP
3 Free Software Foundation, Inc.
4 Written Clinton Popetz.
5 Contributed by Cygnus Support.
6
7This file is part of BFD, the Binary File Descriptor library.
8
9This program is free software; you can redistribute it and/or modify
10it under the terms of the GNU General Public License as published by
11the Free Software Foundation; either version 2 of the License, or
12(at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22
23/* Internalcoff.h and coffcode.h modify themselves based on these flags. */
244148ad 24#define XCOFF64
7f6d05e8
CP
25#define RS6000COFF_C 1
26
27#include "bfd.h"
28#include "sysdep.h"
29#include "libbfd.h"
30#include "coff/internal.h"
31#include "coff/rs6k64.h"
32#include "libcoff.h"
33
7f6d05e8
CP
34#define GET_FILEHDR_SYMPTR bfd_h_get_64
35#define PUT_FILEHDR_SYMPTR bfd_h_put_64
36#define GET_AOUTHDR_DATA_START bfd_h_get_64
37#define PUT_AOUTHDR_DATA_START bfd_h_put_64
38#define GET_AOUTHDR_TEXT_START bfd_h_get_64
39#define PUT_AOUTHDR_TEXT_START bfd_h_put_64
40#define GET_AOUTHDR_TSIZE bfd_h_get_64
41#define PUT_AOUTHDR_TSIZE bfd_h_put_64
42#define GET_AOUTHDR_DSIZE bfd_h_get_64
43#define PUT_AOUTHDR_DSIZE bfd_h_put_64
44#define GET_AOUTHDR_BSIZE bfd_h_get_64
45#define PUT_AOUTHDR_BSIZE bfd_h_put_64
46#define GET_AOUTHDR_ENTRY bfd_h_get_64
47#define PUT_AOUTHDR_ENTRY bfd_h_put_64
48#define GET_SCNHDR_PADDR bfd_h_get_64
49#define PUT_SCNHDR_PADDR bfd_h_put_64
50#define GET_SCNHDR_VADDR bfd_h_get_64
51#define PUT_SCNHDR_VADDR bfd_h_put_64
52#define GET_SCNHDR_SIZE bfd_h_get_64
53#define PUT_SCNHDR_SIZE bfd_h_put_64
54#define GET_SCNHDR_SCNPTR bfd_h_get_64
55#define PUT_SCNHDR_SCNPTR bfd_h_put_64
56#define GET_SCNHDR_RELPTR bfd_h_get_64
57#define PUT_SCNHDR_RELPTR bfd_h_put_64
58#define GET_SCNHDR_LNNOPTR bfd_h_get_64
59#define PUT_SCNHDR_LNNOPTR bfd_h_put_64
60#define GET_SCNHDR_NRELOC bfd_h_get_32
61#define MAX_SCNHDR_NRELOC 0xffffffff
62#define PUT_SCNHDR_NRELOC bfd_h_put_32
63#define GET_SCNHDR_NLNNO bfd_h_get_32
64#define MAX_SCNHDR_NLNNO 0xffffffff
65#define PUT_SCNHDR_NLNNO bfd_h_put_32
66#define GET_RELOC_VADDR bfd_h_get_64
67#define PUT_RELOC_VADDR bfd_h_put_64
68
69#define COFF_FORCE_SYMBOLS_IN_STRINGS
70#define COFF_DEBUG_STRING_WIDE_PREFIX
71
7f6d05e8
CP
72#define COFF_ADJUST_SCNHDR_OUT_POST(ABFD,INT,EXT) \
73do { \
74 memset (((SCNHDR *)EXT)->s_pad, 0, sizeof (((SCNHDR *)EXT)->s_pad));\
e60b52c6 75} while (0)
7f6d05e8
CP
76
77#define NO_COFF_LINENOS
78
79#define coff_SWAP_lineno_in xcoff64_swap_lineno_in
80#define coff_SWAP_lineno_out xcoff64_swap_lineno_out
81
82#define PUTWORD bfd_h_put_32
83#define PUTHALF bfd_h_put_16
84#define PUTBYTE bfd_h_put_8
85#define GETWORD bfd_h_get_32
86#define GETHALF bfd_h_get_16
87#define GETBYTE bfd_h_get_8
88
244148ad 89/* For XCOFF64, the effective width of symndx changes depending on
7f6d05e8
CP
90 whether we are the first entry. Sigh. */
91static void
92xcoff64_swap_lineno_in (abfd, ext1, in1)
93 bfd *abfd;
94 PTR ext1;
95 PTR in1;
96{
97 LINENO *ext = (LINENO *)ext1;
98 struct internal_lineno *in = (struct internal_lineno *)in1;
99
100 in->l_lnno = bfd_h_get_32(abfd, (bfd_byte *) (ext->l_lnno));
101 if (in->l_lnno == 0)
244148ad 102 in->l_addr.l_symndx =
7f6d05e8
CP
103 bfd_h_get_32(abfd, (bfd_byte *) ext->l_addr.l_symndx);
104 else
244148ad 105 in->l_addr.l_symndx =
7f6d05e8
CP
106 bfd_h_get_64(abfd, (bfd_byte *) ext->l_addr.l_symndx);
107}
108
109static unsigned int
110xcoff64_swap_lineno_out (abfd, inp, outp)
111 bfd *abfd;
112 PTR inp;
113 PTR outp;
114{
115 struct internal_lineno *in = (struct internal_lineno *)inp;
116 struct external_lineno *ext = (struct external_lineno *)outp;
117 PUTWORD(abfd, in->l_addr.l_symndx, (bfd_byte *)
118 ext->l_addr.l_symndx);
119
120 bfd_h_put_32 (abfd, in->l_lnno, (bfd_byte *) (ext->l_lnno));
121 if (in->l_lnno == 0)
122 bfd_h_put_32 (abfd, in->l_addr.l_symndx, (bfd_byte *)ext->l_addr.l_symndx);
123 else
124 bfd_h_put_64 (abfd, in->l_addr.l_symndx, (bfd_byte *)ext->l_addr.l_symndx);
125
126 return bfd_coff_linesz (abfd);
127}
128
7f6d05e8
CP
129static void xcoff64_swap_sym_in PARAMS ((bfd *, PTR, PTR));
130static unsigned int xcoff64_swap_sym_out PARAMS ((bfd *, PTR, PTR));
131static void xcoff64_swap_aux_in PARAMS ((bfd *, PTR, int, int, int, int, PTR));
132static unsigned int xcoff64_swap_aux_out PARAMS ((bfd *, PTR, int, int, int, int, PTR));
133
134static void
135xcoff64_swap_sym_in (abfd, ext1, in1)
136 bfd *abfd;
137 PTR ext1;
138 PTR in1;
139{
140 SYMENT *ext = (SYMENT *)ext1;
141 struct internal_syment *in = (struct internal_syment *)in1;
142
7f6d05e8 143 in->_n._n_n._n_zeroes = 0;
03d411a9
NC
144 in->_n._n_n._n_offset = bfd_h_get_32(abfd, (bfd_byte *) ext->e.e.e_offset);
145 in->n_value = bfd_h_get_64(abfd, (bfd_byte *) ext->e_value);
7f6d05e8
CP
146 in->n_scnum = bfd_h_get_16(abfd, (bfd_byte *) ext->e_scnum);
147 in->n_type = bfd_h_get_16(abfd, (bfd_byte *) ext->e_type);
148 in->n_sclass = bfd_h_get_8(abfd, ext->e_sclass);
149 in->n_numaux = bfd_h_get_8(abfd, ext->e_numaux);
150}
151
152static unsigned int
153xcoff64_swap_sym_out (abfd, inp, extp)
154 bfd *abfd;
155 PTR inp;
156 PTR extp;
157{
158 struct internal_syment *in = (struct internal_syment *)inp;
159 SYMENT *ext =(SYMENT *)extp;
160
03d411a9
NC
161 bfd_h_put_32(abfd, in->_n._n_n._n_offset, (bfd_byte *) ext->e.e.e_offset);
162 bfd_h_put_64(abfd, in->n_value , (bfd_byte *) ext->e_value);
7f6d05e8
CP
163 bfd_h_put_16(abfd, in->n_scnum , (bfd_byte *) ext->e_scnum);
164 bfd_h_put_16(abfd, in->n_type , (bfd_byte *) ext->e_type);
165 bfd_h_put_8(abfd, in->n_sclass , ext->e_sclass);
166 bfd_h_put_8(abfd, in->n_numaux , ext->e_numaux);
167 return bfd_coff_symesz (abfd);
168}
169
170static void
171xcoff64_swap_aux_in (abfd, ext1, type, class, indx, numaux, in1)
172 bfd *abfd;
173 PTR ext1;
174 int type;
175 int class;
176 int indx;
177 int numaux;
178 PTR in1;
179{
180 AUXENT *ext = (AUXENT *)ext1;
181 union internal_auxent *in = (union internal_auxent *)in1;
182
183 switch (class) {
184 case C_FILE:
185 if (ext->x_file.x_fname[0] == 0) {
186 in->x_file.x_n.x_zeroes = 0;
244148ad 187 in->x_file.x_n.x_offset =
7f6d05e8
CP
188 bfd_h_get_32(abfd, (bfd_byte *) ext->x_file.x_n.x_offset);
189 } else {
190 if (numaux > 1)
191 {
192 if (indx == 0)
193 memcpy (in->x_file.x_fname, ext->x_file.x_fname,
194 numaux * sizeof (AUXENT));
195 }
196 else
197 {
198 memcpy (in->x_file.x_fname, ext->x_file.x_fname, FILNMLEN);
199 }
200 }
201 goto end;
202
203 /* RS/6000 "csect" auxents */
204 case C_EXT:
205 case C_HIDEXT:
206 if (indx + 1 == numaux)
207 {
244148ad 208 in->x_csect.x_scnlen.l =
7f6d05e8 209 bfd_h_get_32(abfd, ext->x_csect.x_scnlen_lo);
244148ad 210 /* FIXME: If we want section lengths larger than 32 bits, we need
7f6d05e8
CP
211 to modify the internal coff structures to support it. */
212 in->x_csect.x_parmhash = bfd_h_get_32 (abfd,
213 ext->x_csect.x_parmhash);
214 in->x_csect.x_snhash = bfd_h_get_16 (abfd, ext->x_csect.x_snhash);
215 /* We don't have to hack bitfields in x_smtyp because it's
216 defined by shifts-and-ands, which are equivalent on all
217 byte orders. */
218 in->x_csect.x_smtyp = bfd_h_get_8 (abfd, ext->x_csect.x_smtyp);
219 in->x_csect.x_smclas = bfd_h_get_8 (abfd, ext->x_csect.x_smclas);
220 goto end;
221 }
222 break;
223
224 case C_STAT:
225 case C_LEAFSTAT:
226 case C_HIDDEN:
227 if (type == T_NULL) {
228 /* PE defines some extra fields; we zero them out for
229 safety. */
230 in->x_scn.x_checksum = 0;
231 in->x_scn.x_associated = 0;
232 in->x_scn.x_comdat = 0;
233
234 goto end;
235 }
236 break;
237 }
238
239 if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
240 {
241 in->x_sym.x_fcnary.x_fcn.x_lnnoptr = bfd_h_get_64(abfd, (bfd_byte *)
242 ext->x_sym.x_fcnary.x_fcn.x_lnnoptr);
243 in->x_sym.x_fcnary.x_fcn.x_endndx.l = bfd_h_get_32(abfd, (bfd_byte *)
244 ext->x_sym.x_fcnary.x_fcn.x_endndx);
245 }
246 if (ISFCN(type)) {
247 in->x_sym.x_misc.x_fsize = bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_fsize);
248 }
249 else {
250 in->x_sym.x_misc.x_lnsz.x_lnno = bfd_h_get_32(abfd, (bfd_byte *)
251 ext->x_sym.x_fcnary.x_lnsz.x_lnno);
252 in->x_sym.x_misc.x_lnsz.x_size = bfd_h_get_16(abfd, (bfd_byte *)
253 ext->x_sym.x_fcnary.x_lnsz.x_size);
254 }
255
256end: ;
257 /* the semicolon is because MSVC doesn't like labels at
244148ad 258 end of block. */
7f6d05e8
CP
259
260}
261
7f6d05e8
CP
262static unsigned int
263xcoff64_swap_aux_out (abfd, inp, type, class, indx, numaux, extp)
264 bfd *abfd;
265 PTR inp;
266 int type;
267 int class;
268 int indx ATTRIBUTE_UNUSED;
269 int numaux ATTRIBUTE_UNUSED;
270 PTR extp;
271{
272 union internal_auxent *in = (union internal_auxent *)inp;
273 AUXENT *ext = (AUXENT *)extp;
274
275 memset((PTR)ext, 0, bfd_coff_auxesz (abfd));
276 switch (class)
277 {
278 case C_FILE:
279 if (in->x_file.x_fname[0] == 0)
280 {
281 PUTWORD(abfd, 0, (bfd_byte *) ext->x_file.x_n.x_zeroes);
282 PUTWORD(abfd,
283 in->x_file.x_n.x_offset,
284 (bfd_byte *) ext->x_file.x_n.x_offset);
285 }
286 else
287 {
288 memcpy (ext->x_file.x_fname, in->x_file.x_fname, FILNMLEN);
289 }
290 PUTBYTE (abfd, _AUX_FILE, (bfd_byte *) ext->x_auxtype.x_auxtype);
291 goto end;
292
293 /* RS/6000 "csect" auxents */
294 case C_EXT:
295 case C_HIDEXT:
296 if (indx + 1 == numaux)
297 {
298 PUTWORD (abfd, in->x_csect.x_scnlen.l, ext->x_csect.x_scnlen_lo);
299 PUTWORD (abfd, in->x_csect.x_parmhash, ext->x_csect.x_parmhash);
300 PUTHALF (abfd, in->x_csect.x_snhash, ext->x_csect.x_snhash);
301 /* We don't have to hack bitfields in x_smtyp because it's
302 defined by shifts-and-ands, which are equivalent on all
303 byte orders. */
304 PUTBYTE (abfd, in->x_csect.x_smtyp, ext->x_csect.x_smtyp);
305 PUTBYTE (abfd, in->x_csect.x_smclas, ext->x_csect.x_smclas);
306 PUTBYTE (abfd, _AUX_CSECT, (bfd_byte *) ext->x_auxtype.x_auxtype);
307 goto end;
308 }
309 break;
310
311 case C_STAT:
312 case C_LEAFSTAT:
313 case C_HIDDEN:
314 if (type == T_NULL) {
315 goto end;
316 }
317 break;
318 }
319
320 if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
321 {
244148ad 322 bfd_h_put_64(abfd, in->x_sym.x_fcnary.x_fcn.x_lnnoptr,
7f6d05e8
CP
323 (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr);
324 PUTBYTE (abfd, _AUX_FCN, (bfd_byte *) ext->x_auxtype.x_auxtype);
244148ad 325 PUTWORD(abfd, in->x_sym.x_fcnary.x_fcn.x_endndx.l,
7f6d05e8
CP
326 (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_endndx);
327 }
328 if (ISFCN (type))
329 PUTWORD (abfd, in->x_sym.x_misc.x_fsize,
330 (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_fsize);
331 else
332 {
244148ad 333 bfd_h_put_32(abfd, in->x_sym.x_misc.x_lnsz.x_lnno,
7f6d05e8 334 (bfd_byte *)ext->x_sym.x_fcnary.x_lnsz.x_lnno);
244148ad 335 bfd_h_put_16(abfd, in->x_sym.x_misc.x_lnsz.x_size,
7f6d05e8
CP
336 (bfd_byte *)ext->x_sym.x_fcnary.x_lnsz.x_size);
337 }
338
339end:
340 return bfd_coff_auxesz (abfd);
341}
342
7f6d05e8
CP
343#define coff_SWAP_sym_in xcoff64_swap_sym_in
344#define coff_SWAP_sym_out xcoff64_swap_sym_out
345#define coff_SWAP_aux_in xcoff64_swap_aux_in
346#define coff_SWAP_aux_out xcoff64_swap_aux_out
14958a43
CP
347
348#define TARGET_NAME "aixcoff64-rs6000"
349#define TARGET_SYM rs6000coff64_vec
350
2c38bc20 351#include "xcoff-target.h"
This page took 0.071537 seconds and 4 git commands to generate.