OSDN Git Service

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