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
7f6d05e8
CP
23#include "bfd.h"
24#include "sysdep.h"
beb1bf64 25#include "bfdlink.h"
7f6d05e8
CP
26#include "libbfd.h"
27#include "coff/internal.h"
beb1bf64 28#include "coff/xcoff.h"
7f6d05e8 29#include "coff/rs6k64.h"
beb1bf64
TR
30#include "libcoff.h"
31#include "libxcoff.h"
7f6d05e8 32
7f6d05e8
CP
33#define GET_FILEHDR_SYMPTR bfd_h_get_64
34#define PUT_FILEHDR_SYMPTR bfd_h_put_64
35#define GET_AOUTHDR_DATA_START bfd_h_get_64
36#define PUT_AOUTHDR_DATA_START bfd_h_put_64
37#define GET_AOUTHDR_TEXT_START bfd_h_get_64
38#define PUT_AOUTHDR_TEXT_START bfd_h_put_64
39#define GET_AOUTHDR_TSIZE bfd_h_get_64
40#define PUT_AOUTHDR_TSIZE bfd_h_put_64
41#define GET_AOUTHDR_DSIZE bfd_h_get_64
42#define PUT_AOUTHDR_DSIZE bfd_h_put_64
43#define GET_AOUTHDR_BSIZE bfd_h_get_64
44#define PUT_AOUTHDR_BSIZE bfd_h_put_64
45#define GET_AOUTHDR_ENTRY bfd_h_get_64
46#define PUT_AOUTHDR_ENTRY bfd_h_put_64
47#define GET_SCNHDR_PADDR bfd_h_get_64
48#define PUT_SCNHDR_PADDR bfd_h_put_64
49#define GET_SCNHDR_VADDR bfd_h_get_64
50#define PUT_SCNHDR_VADDR bfd_h_put_64
51#define GET_SCNHDR_SIZE bfd_h_get_64
52#define PUT_SCNHDR_SIZE bfd_h_put_64
53#define GET_SCNHDR_SCNPTR bfd_h_get_64
54#define PUT_SCNHDR_SCNPTR bfd_h_put_64
55#define GET_SCNHDR_RELPTR bfd_h_get_64
56#define PUT_SCNHDR_RELPTR bfd_h_put_64
57#define GET_SCNHDR_LNNOPTR bfd_h_get_64
58#define PUT_SCNHDR_LNNOPTR bfd_h_put_64
59#define GET_SCNHDR_NRELOC bfd_h_get_32
60#define MAX_SCNHDR_NRELOC 0xffffffff
61#define PUT_SCNHDR_NRELOC bfd_h_put_32
62#define GET_SCNHDR_NLNNO bfd_h_get_32
63#define MAX_SCNHDR_NLNNO 0xffffffff
64#define PUT_SCNHDR_NLNNO bfd_h_put_32
65#define GET_RELOC_VADDR bfd_h_get_64
66#define PUT_RELOC_VADDR bfd_h_put_64
67
68#define COFF_FORCE_SYMBOLS_IN_STRINGS
69#define COFF_DEBUG_STRING_WIDE_PREFIX
70
beb1bf64 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));\
beb1bf64
TR
75} while(0)
76
77/* In case we're on a 32-bit machine, construct a 64-bit "-1" value
78 from smaller values. Start with zero, widen, *then* decrement. */
79#define MINUS_ONE (((bfd_vma)0) - 1)
80
7f6d05e8
CP
81
82#define NO_COFF_LINENOS
83
beb1bf64
TR
84#define coff_SWAP_lineno_in _bfd_xcoff64_swap_lineno_in
85#define coff_SWAP_lineno_out _bfd_xcoff64_swap_lineno_out
7f6d05e8
CP
86
87#define PUTWORD bfd_h_put_32
88#define PUTHALF bfd_h_put_16
89#define PUTBYTE bfd_h_put_8
90#define GETWORD bfd_h_get_32
91#define GETHALF bfd_h_get_16
92#define GETBYTE bfd_h_get_8
93
beb1bf64
TR
94
95/* For XCOFF64, the effective width of symndx changes depending on
7f6d05e8
CP
96 whether we are the first entry. Sigh. */
97static void
beb1bf64 98_bfd_xcoff64_swap_lineno_in (abfd, ext1, in1)
7f6d05e8
CP
99 bfd *abfd;
100 PTR ext1;
101 PTR in1;
102{
103 LINENO *ext = (LINENO *)ext1;
104 struct internal_lineno *in = (struct internal_lineno *)in1;
105
106 in->l_lnno = bfd_h_get_32(abfd, (bfd_byte *) (ext->l_lnno));
107 if (in->l_lnno == 0)
beb1bf64 108 in->l_addr.l_symndx =
7f6d05e8
CP
109 bfd_h_get_32(abfd, (bfd_byte *) ext->l_addr.l_symndx);
110 else
beb1bf64
TR
111 in->l_addr.l_paddr =
112 bfd_h_get_64(abfd, (bfd_byte *) ext->l_addr.l_paddr);
7f6d05e8
CP
113}
114
115static unsigned int
beb1bf64 116_bfd_xcoff64_swap_lineno_out (abfd, inp, outp)
7f6d05e8
CP
117 bfd *abfd;
118 PTR inp;
119 PTR outp;
120{
121 struct internal_lineno *in = (struct internal_lineno *)inp;
122 struct external_lineno *ext = (struct external_lineno *)outp;
123 PUTWORD(abfd, in->l_addr.l_symndx, (bfd_byte *)
124 ext->l_addr.l_symndx);
125
126 bfd_h_put_32 (abfd, in->l_lnno, (bfd_byte *) (ext->l_lnno));
127 if (in->l_lnno == 0)
128 bfd_h_put_32 (abfd, in->l_addr.l_symndx, (bfd_byte *)ext->l_addr.l_symndx);
129 else
beb1bf64 130 bfd_h_put_64 (abfd, in->l_addr.l_paddr, (bfd_byte *)ext->l_addr.l_paddr);
7f6d05e8
CP
131
132 return bfd_coff_linesz (abfd);
133}
134
beb1bf64
TR
135
136static void _bfd_xcoff64_swap_sym_in PARAMS ((bfd *, PTR, PTR));
137static unsigned int _bfd_xcoff64_swap_sym_out PARAMS ((bfd *, PTR, PTR));
138static void _bfd_xcoff64_swap_aux_in PARAMS ((bfd *, PTR, int, int, int, int, PTR));
139static unsigned int _bfd_xcoff64_swap_aux_out PARAMS ((bfd *, PTR, int, int, int, int, PTR));
7f6d05e8
CP
140
141static void
beb1bf64 142_bfd_xcoff64_swap_sym_in (abfd, ext1, in1)
7f6d05e8
CP
143 bfd *abfd;
144 PTR ext1;
145 PTR in1;
146{
beb1bf64 147 struct external_syment *ext = (struct external_syment *)ext1;
7f6d05e8
CP
148 struct internal_syment *in = (struct internal_syment *)in1;
149
7f6d05e8 150 in->_n._n_n._n_zeroes = 0;
beb1bf64 151 in->_n._n_n._n_offset = bfd_h_get_32(abfd, (bfd_byte *) ext->e_offset);
03d411a9 152 in->n_value = bfd_h_get_64(abfd, (bfd_byte *) ext->e_value);
7f6d05e8
CP
153 in->n_scnum = bfd_h_get_16(abfd, (bfd_byte *) ext->e_scnum);
154 in->n_type = bfd_h_get_16(abfd, (bfd_byte *) ext->e_type);
155 in->n_sclass = bfd_h_get_8(abfd, ext->e_sclass);
156 in->n_numaux = bfd_h_get_8(abfd, ext->e_numaux);
157}
158
159static unsigned int
beb1bf64 160_bfd_xcoff64_swap_sym_out (abfd, inp, extp)
7f6d05e8
CP
161 bfd *abfd;
162 PTR inp;
163 PTR extp;
164{
165 struct internal_syment *in = (struct internal_syment *)inp;
beb1bf64 166 struct external_syment *ext =(struct external_syment *)extp;
7f6d05e8 167
beb1bf64 168 bfd_h_put_32(abfd, in->_n._n_n._n_offset, (bfd_byte *) ext->e_offset);
03d411a9 169 bfd_h_put_64(abfd, in->n_value , (bfd_byte *) ext->e_value);
7f6d05e8
CP
170 bfd_h_put_16(abfd, in->n_scnum , (bfd_byte *) ext->e_scnum);
171 bfd_h_put_16(abfd, in->n_type , (bfd_byte *) ext->e_type);
172 bfd_h_put_8(abfd, in->n_sclass , ext->e_sclass);
173 bfd_h_put_8(abfd, in->n_numaux , ext->e_numaux);
174 return bfd_coff_symesz (abfd);
175}
176
177static void
beb1bf64 178_bfd_xcoff64_swap_aux_in (abfd, ext1, type, class, indx, numaux, in1)
7f6d05e8
CP
179 bfd *abfd;
180 PTR ext1;
181 int type;
182 int class;
183 int indx;
184 int numaux;
185 PTR in1;
186{
beb1bf64 187 union external_auxent *ext = (union external_auxent *)ext1;
7f6d05e8
CP
188 union internal_auxent *in = (union internal_auxent *)in1;
189
190 switch (class) {
191 case C_FILE:
beb1bf64 192 if (ext->x_file.x_n.x_zeroes == 0) {
7f6d05e8 193 in->x_file.x_n.x_zeroes = 0;
beb1bf64 194 in->x_file.x_n.x_offset =
7f6d05e8
CP
195 bfd_h_get_32(abfd, (bfd_byte *) ext->x_file.x_n.x_offset);
196 } else {
beb1bf64
TR
197 memcpy (in->x_file.x_fname, ext->x_file.x_fname, FILNMLEN);
198 }
7f6d05e8
CP
199 goto end;
200
201 /* RS/6000 "csect" auxents */
202 case C_EXT:
203 case C_HIDEXT:
204 if (indx + 1 == numaux)
205 {
beb1bf64
TR
206 bfd_signed_vma h = 0;
207 bfd_vma l = 0;
208
209 h = bfd_h_get_signed_32(abfd, ext->x_csect.x_scnlen_hi);
210 l = bfd_h_get_32 (abfd, ext->x_csect.x_scnlen_lo);
211
212 in->x_csect.x_scnlen.l = h << 32 | (l & 0xffffffff);
213
7f6d05e8
CP
214 in->x_csect.x_parmhash = bfd_h_get_32 (abfd,
215 ext->x_csect.x_parmhash);
216 in->x_csect.x_snhash = bfd_h_get_16 (abfd, ext->x_csect.x_snhash);
217 /* We don't have to hack bitfields in x_smtyp because it's
218 defined by shifts-and-ands, which are equivalent on all
219 byte orders. */
220 in->x_csect.x_smtyp = bfd_h_get_8 (abfd, ext->x_csect.x_smtyp);
221 in->x_csect.x_smclas = bfd_h_get_8 (abfd, ext->x_csect.x_smclas);
222 goto end;
223 }
224 break;
225
226 case C_STAT:
227 case C_LEAFSTAT:
228 case C_HIDDEN:
229 if (type == T_NULL) {
230 /* PE defines some extra fields; we zero them out for
231 safety. */
232 in->x_scn.x_checksum = 0;
233 in->x_scn.x_associated = 0;
234 in->x_scn.x_comdat = 0;
235
236 goto end;
237 }
238 break;
239 }
240
241 if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
242 {
243 in->x_sym.x_fcnary.x_fcn.x_lnnoptr = bfd_h_get_64(abfd, (bfd_byte *)
244 ext->x_sym.x_fcnary.x_fcn.x_lnnoptr);
245 in->x_sym.x_fcnary.x_fcn.x_endndx.l = bfd_h_get_32(abfd, (bfd_byte *)
246 ext->x_sym.x_fcnary.x_fcn.x_endndx);
247 }
248 if (ISFCN(type)) {
249 in->x_sym.x_misc.x_fsize = bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_fsize);
250 }
251 else {
252 in->x_sym.x_misc.x_lnsz.x_lnno = bfd_h_get_32(abfd, (bfd_byte *)
253 ext->x_sym.x_fcnary.x_lnsz.x_lnno);
254 in->x_sym.x_misc.x_lnsz.x_size = bfd_h_get_16(abfd, (bfd_byte *)
255 ext->x_sym.x_fcnary.x_lnsz.x_size);
256 }
257
258end: ;
259 /* the semicolon is because MSVC doesn't like labels at
beb1bf64 260 end of block. */
7f6d05e8
CP
261
262}
263
beb1bf64
TR
264
265
7f6d05e8 266static unsigned int
beb1bf64 267_bfd_xcoff64_swap_aux_out (abfd, inp, type, class, indx, numaux, extp)
7f6d05e8
CP
268 bfd *abfd;
269 PTR inp;
270 int type;
271 int class;
272 int indx ATTRIBUTE_UNUSED;
273 int numaux ATTRIBUTE_UNUSED;
274 PTR extp;
275{
276 union internal_auxent *in = (union internal_auxent *)inp;
beb1bf64 277 union external_auxent *ext = (union external_auxent *)extp;
7f6d05e8
CP
278
279 memset((PTR)ext, 0, bfd_coff_auxesz (abfd));
280 switch (class)
281 {
282 case C_FILE:
beb1bf64
TR
283 if (ext->x_file.x_n.x_zeroes == 0) {
284 bfd_h_put_32 (abfd, 0, (bfd_byte *) ext->x_file.x_n.x_zeroes);
285 bfd_h_put_32 (abfd, in->x_file.x_n.x_offset,
7f6d05e8 286 (bfd_byte *) ext->x_file.x_n.x_offset);
beb1bf64 287 } else {
7f6d05e8 288 memcpy (ext->x_file.x_fname, in->x_file.x_fname, FILNMLEN);
beb1bf64
TR
289 }
290 bfd_h_put_8 (abfd, _AUX_FILE, (bfd_byte *) ext->x_auxtype.x_auxtype);
7f6d05e8
CP
291 goto end;
292
293 /* RS/6000 "csect" auxents */
294 case C_EXT:
295 case C_HIDEXT:
296 if (indx + 1 == numaux)
297 {
beb1bf64
TR
298 bfd_vma temp;
299
300 temp = in->x_csect.x_scnlen.l & 0xffffffff;
301 bfd_h_put_32 (abfd, temp, ext->x_csect.x_scnlen_lo);
302 temp = in->x_csect.x_scnlen.l >> 32;
303 bfd_h_put_32 (abfd, temp, ext->x_csect.x_scnlen_hi);
304 bfd_h_put_32 (abfd, in->x_csect.x_parmhash, ext->x_csect.x_parmhash);
305 bfd_h_put_16 (abfd, in->x_csect.x_snhash, ext->x_csect.x_snhash);
7f6d05e8
CP
306 /* We don't have to hack bitfields in x_smtyp because it's
307 defined by shifts-and-ands, which are equivalent on all
308 byte orders. */
beb1bf64
TR
309 bfd_h_put_8 (abfd, in->x_csect.x_smtyp, ext->x_csect.x_smtyp);
310 bfd_h_put_8 (abfd, in->x_csect.x_smclas, ext->x_csect.x_smclas);
311 bfd_h_put_8 (abfd, _AUX_CSECT, (bfd_byte *) ext->x_auxtype.x_auxtype);
7f6d05e8
CP
312 goto end;
313 }
314 break;
315
316 case C_STAT:
317 case C_LEAFSTAT:
318 case C_HIDDEN:
319 if (type == T_NULL) {
320 goto end;
321 }
322 break;
323 }
324
325 if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
326 {
beb1bf64
TR
327 bfd_h_put_64(abfd, in->x_sym.x_fcnary.x_fcn.x_lnnoptr,
328 (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr);
329 bfd_h_put_8 (abfd, _AUX_FCN, (bfd_byte *) ext->x_auxtype.x_auxtype);
330 bfd_h_put_32(abfd, in->x_sym.x_fcnary.x_fcn.x_endndx.l,
331 (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_endndx);
7f6d05e8
CP
332 }
333 if (ISFCN (type))
beb1bf64
TR
334 bfd_h_put_32 (abfd, in->x_sym.x_misc.x_fsize,
335 (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_fsize);
7f6d05e8
CP
336 else
337 {
beb1bf64 338 bfd_h_put_32(abfd, in->x_sym.x_misc.x_lnsz.x_lnno,
7f6d05e8 339 (bfd_byte *)ext->x_sym.x_fcnary.x_lnsz.x_lnno);
beb1bf64 340 bfd_h_put_16(abfd, in->x_sym.x_misc.x_lnsz.x_size,
7f6d05e8
CP
341 (bfd_byte *)ext->x_sym.x_fcnary.x_lnsz.x_size);
342 }
343
344end:
beb1bf64 345
7f6d05e8
CP
346 return bfd_coff_auxesz (abfd);
347}
348
beb1bf64
TR
349static boolean
350_bfd_xcoff64_put_symbol_name (bfd *abfd, struct bfd_strtab_hash *strtab,
351 struct internal_syment *sym,
352 const char *name) {
353 boolean hash;
354 bfd_size_type indx;
355
356 hash = true;
357
358 if ((abfd->flags & BFD_TRADITIONAL_FORMAT) != 0)
359 hash = false;
360
361 indx = _bfd_stringtab_add (strtab, name, hash, false);
362
363 if (indx == (bfd_size_type) -1)
364 return false;
365
366 sym->_n._n_n._n_zeroes = 0;
367 sym->_n._n_n._n_offset = STRING_SIZE_SIZE + indx;
368
369 return true;
370}
371
372static boolean
373_bfd_xcoff64_put_ldsymbol_name (abfd, ldinfo, ldsym, name)
374 bfd *abfd ATTRIBUTE_UNUSED;
375 struct xcoff_loader_info *ldinfo;
376 struct internal_ldsym *ldsym;
377 const char *name;
378{
379
380 size_t len;
381 len = strlen (name);
382
383 if (ldinfo->string_size + len + 3 > ldinfo->string_alc){
384 size_t newalc;
385 bfd_byte *newstrings;
386
387 newalc = ldinfo->string_alc * 2;
388 if (newalc == 0)
389 newalc = 32;
390 while (ldinfo->string_size + len + 3 > newalc)
391 newalc *= 2;
392
393 newstrings = ((bfd_byte *)
394 bfd_realloc ((PTR) ldinfo->strings, newalc));
395 if (newstrings == NULL) {
396 ldinfo->failed = true;
397 return false;
398 }
399 ldinfo->string_alc = newalc;
400 ldinfo->strings = newstrings;
401 }
402
403 bfd_put_16 (ldinfo->output_bfd, len + 1,
404 ldinfo->strings + ldinfo->string_size);
405 strcpy (ldinfo->strings + ldinfo->string_size + 2, name);
406 ldsym->_l._l_l._l_zeroes = 0;
407 ldsym->_l._l_l._l_offset = ldinfo->string_size + 2;
408 ldinfo->string_size += len + 3;
409
410 return true;
411}
412
413extern const bfd_target * rs6000coff_core_p ();
414extern boolean rs6000coff_core_file_matches_executable_p ();
415extern char *rs6000coff_core_file_failing_command PARAMS ((bfd *abfd));
416extern int rs6000coff_core_file_failing_signal PARAMS ((bfd *abfd));
417extern boolean _bfd_xcoff_mkobject PARAMS ((bfd *));
418extern boolean _bfd_xcoff_copy_private_bfd_data PARAMS ((bfd *, bfd *));
419extern boolean _bfd_xcoff_is_local_label_name PARAMS ((bfd *, const char *));
420extern void xcoff64_rtype2howto
421 PARAMS ((arelent *, struct internal_reloc *));
422extern reloc_howto_type * xcoff64_reloc_type_lookup
423 PARAMS ((bfd *, bfd_reloc_code_real_type));
424extern boolean _bfd_xcoff_slurp_armap PARAMS ((bfd *));
425extern PTR _bfd_xcoff_read_ar_hdr PARAMS ((bfd *));
426extern bfd *_bfd_xcoff_openr_next_archived_file PARAMS ((bfd *, bfd *));
427extern int _bfd_xcoff_generic_stat_arch_elt PARAMS ((bfd *, struct stat *));
428extern boolean _bfd_xcoff_write_armap
429 PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int));
430extern boolean _bfd_xcoff_write_archive_contents PARAMS ((bfd *));
431extern int _bfd_xcoff_sizeof_headers PARAMS ((bfd *, boolean));
432extern void _bfd_xcoff_swap_sym_in PARAMS ((bfd *, PTR, PTR));
433extern unsigned int _bfd_xcoff_swap_sym_out PARAMS ((bfd *, PTR, PTR));
434extern void _bfd_xcoff_swap_aux_in PARAMS ((bfd *, PTR, int, int, int, int, PTR));
435extern unsigned int _bfd_xcoff_swap_aux_out PARAMS ((bfd *, PTR, int, int, int, int, PTR));
436
437/* coffcode.h needs these to be defined */
438/* Internalcoff.h and coffcode.h modify themselves based on these flags. */
439#define XCOFF64
440#define RS6000COFF_C 1
441
442#define SELECT_RELOC(internal, howto) \
443 { \
444 internal.r_type = howto->type; \
445 internal.r_size = \
446 ((howto->complain_on_overflow == complain_overflow_signed \
447 ? 0x80 \
448 : 0) \
449 | (howto->bitsize - 1)); \
450 }
451
452#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
453#define COFF_LONG_FILENAMES
454#define NO_COFF_SYMBOLS
455#define RTYPE2HOWTO(cache_ptr, dst) xcoff64_rtype2howto (cache_ptr, dst)
456#define coff_mkobject _bfd_xcoff_mkobject
457#define coff_bfd_copy_private_bfd_data _bfd_xcoff_copy_private_bfd_data
458#define coff_bfd_is_local_label_name _bfd_xcoff_is_local_label_name
459#define coff_bfd_reloc_type_lookup xcoff64_reloc_type_lookup
460#define CORE_FILE_P rs6000coff_core_p
461#define coff_SWAP_sym_in _bfd_xcoff64_swap_sym_in
462#define coff_SWAP_sym_out _bfd_xcoff64_swap_sym_out
463#define coff_SWAP_aux_in _bfd_xcoff64_swap_aux_in
464#define coff_SWAP_aux_out _bfd_xcoff64_swap_aux_out
465
466
467
468#include "coffcode.h"
469
470/* Routines to swap information in the XCOFF .loader section. If we
471 ever need to write an XCOFF loader, this stuff will need to be
472 moved to another file shared by the linker (which XCOFF calls the
473 ``binder'') and the loader. */
474
475/* Swap in the ldhdr structure. */
476
477static void
478xcoff64_swap_ldhdr_in (abfd, src, dst)
479 bfd *abfd;
480 const struct external_ldhdr *src;
481 struct internal_ldhdr *dst;
482 {
483 dst->l_version = bfd_get_32 (abfd, src->l_version);
484 dst->l_nsyms = bfd_get_32 (abfd, src->l_nsyms);
485 dst->l_nreloc = bfd_get_32 (abfd, src->l_nreloc);
486 dst->l_istlen = bfd_get_32 (abfd, src->l_istlen);
487 dst->l_nimpid = bfd_get_32 (abfd, src->l_nimpid);
488 dst->l_stlen = bfd_get_32 (abfd, src->l_stlen);
489 dst->l_impoff = bfd_get_64 (abfd, src->l_impoff);
490 dst->l_stoff = bfd_get_64 (abfd, src->l_stoff);
491 dst->l_symoff = bfd_get_64 (abfd, src->l_symoff);
492 dst->l_rldoff = bfd_get_64 (abfd, src->l_rldoff);
493}
494
495/* Swap out the ldhdr structure. */
496
497static void
498xcoff64_swap_ldhdr_out (abfd, src, dst)
499 bfd *abfd;
500 const struct internal_ldhdr *src;
501 struct external_ldhdr *dst;
502{
503 bfd_put_32 (abfd, src->l_version, dst->l_version);
504 bfd_put_32 (abfd, src->l_nsyms, dst->l_nsyms);
505 bfd_put_32 (abfd, src->l_nreloc, dst->l_nreloc);
506 bfd_put_32 (abfd, src->l_istlen, dst->l_istlen);
507 bfd_put_32 (abfd, src->l_nimpid, dst->l_nimpid);
508 bfd_put_32 (abfd, src->l_stlen, dst->l_stlen);
509 bfd_put_64 (abfd, src->l_impoff, dst->l_impoff);
510 bfd_put_64 (abfd, src->l_stoff, dst->l_stoff);
511 bfd_put_64 (abfd, src->l_symoff, dst->l_symoff);
512 bfd_put_64 (abfd, src->l_rldoff, dst->l_rldoff);
513}
514
515/* Swap in the ldsym structure. */
516
517static void
518xcoff64_swap_ldsym_in (abfd, src, dst)
519 bfd *abfd;
520 const struct external_ldsym *src;
521 struct internal_ldsym *dst;
522{
523 /*
524 * XCOFF64 does not use l_zeroes like XCOFF32
525 * Set the internal l_zeroes to 0 so the common 32/64 code uses l_value
526 * as an offset into the loader symbol table
527 */
528 dst->_l._l_l._l_zeroes = 0;
529 dst->_l._l_l._l_offset = bfd_get_32 (abfd, src->l_offset);
530 dst->l_value = bfd_get_64 (abfd, src->l_value);
531 dst->l_scnum = bfd_get_16 (abfd, src->l_scnum);
532 dst->l_smtype = bfd_get_8 (abfd, src->l_smtype);
533 dst->l_smclas = bfd_get_8 (abfd, src->l_smclas);
534 dst->l_ifile = bfd_get_32 (abfd, src->l_ifile);
535 dst->l_parm = bfd_get_32 (abfd, src->l_parm);
536}
537
538/* Swap out the ldsym structure. */
539
540static void
541xcoff64_swap_ldsym_out (abfd, src, dst)
542 bfd *abfd;
543 const struct internal_ldsym *src;
544 struct external_ldsym *dst;
545{
546 bfd_put_64 (abfd, src->l_value, dst->l_value);
547 bfd_put_32 (abfd, src->_l._l_l._l_offset, dst->l_offset);
548 bfd_put_16 (abfd, src->l_scnum, dst->l_scnum);
549 bfd_put_8 (abfd, src->l_smtype, dst->l_smtype);
550 bfd_put_8 (abfd, src->l_smclas, dst->l_smclas);
551 bfd_put_32 (abfd, src->l_ifile, dst->l_ifile);
552 bfd_put_32 (abfd, src->l_parm, dst->l_parm);
553}
554
555/* Swap in the ldrel structure. */
556
557static void
558xcoff64_swap_ldrel_in (abfd, src, dst)
559 bfd *abfd;
560 const struct external_ldrel *src;
561 struct internal_ldrel *dst;
562{
563 dst->l_vaddr = bfd_get_64 (abfd, src->l_vaddr);
564 dst->l_symndx = bfd_get_32 (abfd, src->l_symndx);
565 dst->l_rtype = bfd_get_16 (abfd, src->l_rtype);
566 dst->l_rsecnm = bfd_get_16 (abfd, src->l_rsecnm);
567}
568
569/* Swap out the ldrel structure. */
570
571static void
572xcoff64_swap_ldrel_out (abfd, src, dst)
573 bfd *abfd;
574 const struct internal_ldrel *src;
575 struct external_ldrel *dst;
576{
577 bfd_put_64 (abfd, src->l_vaddr, dst->l_vaddr);
578 bfd_put_16 (abfd, src->l_rtype, dst->l_rtype);
579 bfd_put_16 (abfd, src->l_rsecnm, dst->l_rsecnm);
580 bfd_put_32 (abfd, src->l_symndx, dst->l_symndx);
581}
582
583static boolean
584xcoff64_write_object_contents (abfd)
585 bfd * abfd;
586{
587 asection *current;
588 boolean hasrelocs = false;
589 boolean haslinno = false;
590 file_ptr scn_base;
591 file_ptr reloc_base;
592 file_ptr lineno_base;
593 file_ptr sym_base;
594 unsigned long reloc_size = 0;
595 unsigned long lnno_size = 0;
596 boolean long_section_names;
597 asection *text_sec = ((void *)0) ;
598 asection *data_sec = ((void *)0) ;
599 asection *bss_sec = ((void *)0) ;
600 struct internal_filehdr internal_f;
601 struct internal_aouthdr internal_a;
602
603 bfd_set_error (bfd_error_system_call);
604
605 if (abfd->output_has_begun == false) {
606 if (! bfd_coff_compute_section_file_positions (abfd))
607 return false;
608 }
609
610 /* Work out the size of the reloc and linno areas */
611 reloc_base = obj_relocbase (abfd);
612
613 for (current = abfd->sections; current != NULL; current = current->next) {
614 reloc_size += current->reloc_count * bfd_coff_relsz (abfd);
615 }
616
617 lineno_base = reloc_base + reloc_size;
618
619 /* Make a pass through the symbol table to count line number entries and
620 put them into the correct asections */
621 lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
622
623 sym_base = lineno_base + lnno_size;
624
625 /* Indicate in each section->line_filepos its actual file address */
626 for (current = abfd->sections; current != NULL; current = current->next) {
627 if (current->lineno_count) {
628 current->line_filepos = lineno_base;
629 current->moving_line_filepos = lineno_base;
630 lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
631 } else {
632 current->line_filepos = 0;
633 }
634
635 if (current->reloc_count) {
636 current->rel_filepos = reloc_base;
637 reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
638 } else {
639 current->rel_filepos = 0;
640 }
641 }
642
643 if ((abfd->flags & EXEC_P) != 0) {
644 scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
645 internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
646 } else {
647 scn_base = bfd_coff_filhsz (abfd);
648 internal_f.f_opthdr = 0;
649 }
650
651 internal_f.f_nscns = 0;
652
653 if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
654 return false;
655
656 long_section_names = false;
657 for (current = abfd->sections; current != NULL; current = current->next) {
658
659 struct internal_scnhdr section;
660 struct external_scnhdr buff;
661
662 internal_f.f_nscns++;
663
664 strncpy (section.s_name, current->name, SCNNMLEN);
665
666 section.s_vaddr = current->vma;
667 section.s_paddr = current->lma;
668 section.s_size = current->_raw_size;
669
670 /*
671 If this section has no size or is unloadable then the scnptr
672 will be 0 too
673 */
674 if (current->_raw_size == 0 ||
675 (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0) {
676 section.s_scnptr = 0;
677 } else {
678 section.s_scnptr = current->filepos;
679 }
680
681 section.s_relptr = current->rel_filepos;
682 section.s_lnnoptr = current->line_filepos;
683 section.s_nreloc = current->reloc_count;
684
685 section.s_nlnno = current->lineno_count;
686 if (current->reloc_count != 0)
687 hasrelocs = true;
688 if (current->lineno_count != 0)
689 haslinno = true;
690
691 section.s_flags = sec_to_styp_flags (current->name, current->flags);
692
693 if (!strcmp (current->name, _TEXT)) {
694 text_sec = current;
695 } else if (!strcmp (current->name, _DATA)) {
696 data_sec = current;
697 } else if (!strcmp (current->name, _BSS)) {
698 bss_sec = current;
699 }
700
701 if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
702 || bfd_write ((PTR) (&buff), 1, bfd_coff_scnhsz (abfd), abfd)
703 != bfd_coff_scnhsz (abfd))
704 return false;
705 }
706
707 internal_f.f_timdat = 0;
708
709 internal_f.f_flags = 0;
710
711 if (!hasrelocs)
712 internal_f.f_flags |= F_RELFLG;
713 if (!haslinno)
714 internal_f.f_flags |= F_LNNO;
715 if (abfd->flags & EXEC_P)
716 internal_f.f_flags |= F_EXEC;
717
718 /* FIXME: this is wrong for PPC_PE! */
719 if (bfd_little_endian (abfd))
720 internal_f.f_flags |= F_AR32WR;
721 else
722 internal_f.f_flags |= F_AR32W;
723
724 if ((abfd->flags & DYNAMIC) != 0)
725 internal_f.f_flags |= F_SHROBJ;
726 if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
727 internal_f.f_flags |= F_DYNLOAD;
728
729 memset (&internal_a, 0, sizeof internal_a);
730
731
732 /*
733 * This can only be called from the xcoff64 backend so the magic # must
734 * be for xcoff64
735 */
736 internal_f.f_magic = 0757;
737
738 internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
739 (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
740 RS6K_AOUTHDR_OMAGIC;
741
742 /* FIXME: Does anybody ever set this to another value? */
743 internal_a.vstamp = 0;
744
745 /* Now should write relocs, strings, syms */
746 obj_sym_filepos (abfd) = sym_base;
747
748 internal_f.f_symptr = 0;
749 internal_f.f_nsyms = 0;
750
751 /*
752 * If bfd_get_symcount (abfd) != 0, then we are not using the COFF
753 * backend linker, and obj_raw_syment_count is not valid until after
754 * coff_write_symbols is called.
755 */
756 if (bfd_get_symcount (abfd) != 0) {
757 int firstundef;
758
759 if (!coff_renumber_symbols (abfd, &firstundef))
760 return false;
761 coff_mangle_symbols (abfd);
762 if (! coff_write_symbols (abfd))
763 return false;
764 if (! coff_write_linenumbers (abfd))
765 return false;
766 if (! coff_write_relocs (abfd, firstundef))
767 return false;
768
769 internal_f.f_symptr = sym_base;
770 internal_f.f_nsyms = bfd_get_symcount (abfd);
771 } else if (obj_raw_syment_count (abfd) != 0) {
772 internal_f.f_symptr = sym_base;
773
774 /*
775 * AIX appears to require that F_RELFLG not be set if there are
776 * local symbols but no relocations.
777 */
778 internal_f.f_flags &=~ F_RELFLG;
779 } else {
780 internal_f.f_flags |= F_LSYMS;
781 }
782
783 if (text_sec) {
784 internal_a.tsize = bfd_get_section_size_before_reloc (text_sec);
785 internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
786 }
787
788 if (data_sec) {
789 internal_a.dsize = bfd_get_section_size_before_reloc (data_sec);
790 internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
791 }
792
793 if (bss_sec) {
794 internal_a.bsize = bfd_get_section_size_before_reloc (bss_sec);
795 if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
796 internal_a.data_start = bss_sec->vma;
797 }
798
799 internal_a.entry = bfd_get_start_address (abfd);
800 internal_f.f_nsyms = obj_raw_syment_count (abfd);
801
802 if (xcoff_data (abfd)->full_aouthdr) {
803
804 bfd_vma toc;
805 asection *loader_sec;
806
807 internal_a.vstamp = 1;
808
809 internal_a.o_snentry = xcoff_data (abfd)->snentry;
810 if (internal_a.o_snentry == 0)
811 internal_a.entry = (bfd_vma) -1;
812
813 if (text_sec != NULL) {
814 internal_a.o_sntext = text_sec->target_index;
815 internal_a.o_algntext = bfd_get_section_alignment (abfd, text_sec);
816 } else {
817 internal_a.o_sntext = 0;
818 internal_a.o_algntext = 0;
819 }
820
821 if (data_sec != NULL) {
822 internal_a.o_sndata = data_sec->target_index;
823 internal_a.o_algndata = bfd_get_section_alignment (abfd, data_sec);
824 } else {
825 internal_a.o_sndata = 0;
826 internal_a.o_algndata = 0;
827 }
828
829 loader_sec = bfd_get_section_by_name (abfd, ".loader");
830 if (loader_sec != NULL)
831 internal_a.o_snloader = loader_sec->target_index;
832 else
833 internal_a.o_snloader = 0;
834 if (bss_sec != NULL)
835 internal_a.o_snbss = bss_sec->target_index;
836 else
837 internal_a.o_snbss = 0;
838
839 toc = xcoff_data (abfd)->toc;
840 internal_a.o_toc = toc;
841 internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
842
843 internal_a.o_modtype = xcoff_data (abfd)->modtype;
844 if (xcoff_data (abfd)->cputype != -1)
845 internal_a.o_cputype = xcoff_data (abfd)->cputype;
846 else
847 {
848 switch (bfd_get_arch (abfd))
849 {
850 case bfd_arch_rs6000:
851 internal_a.o_cputype = 4;
852 break;
853 case bfd_arch_powerpc:
854 if (bfd_get_mach (abfd) == 0)
855 internal_a.o_cputype = 3;
856 else
857 internal_a.o_cputype = 1;
858 break;
859 default:
860 abort ();
861 }
862 }
863 internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
864 internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
865 }
866
867 if (bfd_seek (abfd, (file_ptr) 0, 0 ) != 0)
868 return false;
869
870 {
871 char * buff;
872 bfd_size_type amount;
873
874 buff = bfd_malloc (bfd_coff_filhsz (abfd));
875 if (buff == ((void *)0) )
876 return false;
877
878 bfd_coff_swap_filehdr_out (abfd, (PTR) & internal_f, (PTR) buff);
879 amount = bfd_write ((PTR) buff, 1, bfd_coff_filhsz (abfd), abfd);
880
881 free (buff);
882
883 if (amount != bfd_coff_filhsz (abfd))
884 return false;
885 }
886
887 if (abfd->flags & EXEC_P) {
888
889 char * buff;
890 bfd_size_type amount;
891
892 buff = bfd_malloc (bfd_coff_aoutsz (abfd));
893 if (buff == NULL)
894 return false;
895
896 bfd_coff_swap_aouthdr_out (abfd, (PTR) & internal_a, (PTR) buff);
897 amount = bfd_write ((PTR) buff, 1, bfd_coff_aoutsz (abfd), abfd);
898
899 free (buff);
900
901 if (amount != bfd_coff_aoutsz (abfd))
902 return false;
903 }
904
905
906 return true;
907}
908
909/* This is the relocation function for the RS/6000/POWER/PowerPC.
910 This is currently the only processor which uses XCOFF; I hope that
911 will never change. */
912
913boolean
914xcoff64_ppc_relocate_section (output_bfd, info, input_bfd,
915 input_section, contents, relocs, syms,
916 sections)
917 bfd *output_bfd;
918 struct bfd_link_info *info;
919 bfd *input_bfd;
920 asection *input_section;
921 bfd_byte *contents;
922 struct internal_reloc *relocs;
923 struct internal_syment *syms;
924 asection **sections;
925{
926 struct internal_reloc *rel;
927 struct internal_reloc *relend;
928
929 rel = relocs;
930 relend = rel + input_section->reloc_count;
931 for (; rel < relend; rel++)
932 {
933 long symndx;
934 struct xcoff_link_hash_entry *h;
935 struct internal_syment *sym;
936 bfd_vma addend;
937 bfd_vma val;
938 struct reloc_howto_struct howto;
939 bfd_reloc_status_type rstat;
940
941 /* Relocation type R_REF is a special relocation type which is
942 merely used to prevent garbage collection from occurring for
943 the csect including the symbol which it references. */
944 if (rel->r_type == R_REF)
945 continue;
946
947 symndx = rel->r_symndx;
948
949 if (symndx == -1) {
950 h = NULL;
951 sym = NULL;
952 addend = 0;
953 } else {
954 h = obj_xcoff_sym_hashes (input_bfd)[symndx];
955 sym = syms + symndx;
956 addend = - sym->n_value;
957 }
958
959 /* We build the howto information on the fly. */
960
961 howto.type = rel->r_type;
962 howto.rightshift = 0;
963 howto.size = 4;
964 howto.bitsize = (rel->r_size & 0x3f) + 1;
965 howto.pc_relative = false;
966 howto.bitpos = 0;
967 if ((rel->r_size & 0x80) != 0)
968 howto.complain_on_overflow = complain_overflow_signed;
969 else
970 howto.complain_on_overflow = complain_overflow_bitfield;
971 howto.special_function = NULL;
972 howto.name = "internal";
973 howto.partial_inplace = true;
974
975 if (howto.bitsize == 64) {
976 howto.src_mask = howto.dst_mask = MINUS_ONE;
977 } else if (howto.bitsize == 32) {
978 howto.src_mask = howto.dst_mask = 0xffffffff;
979 } else {
980 howto.src_mask = howto.dst_mask = (1 << howto.bitsize) - 1;
981 if (howto.bitsize == 16)
982 howto.size = 1;
983 }
984 howto.pcrel_offset = false;
985
986 val = 0;
987
988 if (h == NULL) {
989 asection *sec;
990
991 if (symndx == -1) {
992 sec = bfd_abs_section_ptr;
993 val = 0;
994 } else {
995 sec = sections[symndx];
996 /* Hack to make sure we use the right TOC anchor value
997 if this reloc is against the TOC anchor. */
998 if (sec->name[3] == '0'
999 && strcmp (sec->name, ".tc0") == 0)
1000 val = xcoff_data (output_bfd)->toc;
1001 else
1002 val = (sec->output_section->vma
1003 + sec->output_offset
1004 + sym->n_value
1005 - sec->vma);
1006 }
1007
1008 } else {
1009
1010 if (h->root.type == bfd_link_hash_defined
1011 || h->root.type == bfd_link_hash_defweak) {
1012 asection *sec;
1013
1014 sec = h->root.u.def.section;
1015 val = (h->root.u.def.value
1016 + sec->output_section->vma
1017 + sec->output_offset);
1018
1019 } else if (h->root.type == bfd_link_hash_common) {
1020 asection *sec;
1021
1022 sec = h->root.u.c.p->section;
1023 val = (sec->output_section->vma
1024 + sec->output_offset);
1025 } else if ((h->flags & XCOFF_DEF_DYNAMIC) != 0
1026 || (h->flags & XCOFF_IMPORT) != 0) {
1027 /* Every symbol in a shared object is defined somewhere. */
1028 val = 0;
1029 } else if (! info->relocateable) {
1030 if (! ((*info->callbacks->undefined_symbol)
1031 (info, h->root.root.string, input_bfd, input_section,
1032 rel->r_vaddr - input_section->vma, true)))
1033 return false;
1034
1035 /* Don't try to process the reloc. It can't help, and
1036 it may generate another error. */
1037 continue;
1038 }
1039 }
1040
1041 /* I took the relocation type definitions from two documents:
1042 the PowerPC AIX Version 4 Application Binary Interface, First
1043 Edition (April 1992), and the PowerOpen ABI, Big-Endian
1044 32-Bit Hardware Implementation (June 30, 1994). Differences
1045 between the documents are noted below. */
1046
1047 switch (rel->r_type) {
1048 case R_RTB:
1049 case R_RRTBI:
1050 case R_RRTBA:
1051 /* These relocs are defined by the PowerPC ABI to be
1052 relative branches which use half of the difference
1053 between the symbol and the program counter. I can't
1054 quite figure out when this is useful. These relocs are
1055 not defined by the PowerOpen ABI. */
1056 default:
1057 (*_bfd_error_handler)
1058 (_("%s: unsupported relocation type 0x%02x"),
1059 bfd_get_filename (input_bfd), (unsigned int) rel->r_type);
1060 bfd_set_error (bfd_error_bad_value);
1061 return false;
1062 case R_POS:
1063 /* Simple positive relocation. */
1064 break;
1065 case R_NEG:
1066 /* Simple negative relocation. */
1067 val = - val;
1068 break;
1069 case R_REL:
1070 /* Simple PC relative relocation. */
1071 howto.pc_relative = true;
1072 break;
1073 case R_TOC:
1074 /* TOC relative relocation. The value in the instruction in
1075 the input file is the offset from the input file TOC to
1076 the desired location. We want the offset from the final
1077 TOC to the desired location. We have:
1078 isym = iTOC + in
1079 iinsn = in + o
1080 osym = oTOC + on
1081 oinsn = on + o
1082 so we must change insn by on - in.
1083 */
1084 case R_GL:
1085 /* Global linkage relocation. The value of this relocation
1086 is the address of the entry in the TOC section. */
1087 case R_TCL:
1088 /* Local object TOC address. I can't figure out the
1089 difference between this and case R_GL. */
1090 case R_TRL:
1091 /* TOC relative relocation. A TOC relative load instruction
1092 which may be changed to a load address instruction.
1093 FIXME: We don't currently implement this optimization. */
1094 case R_TRLA:
1095 /* TOC relative relocation. This is a TOC relative load
1096 address instruction which may be changed to a load
1097 instruction. FIXME: I don't know if this is the correct
1098 implementation. */
1099 if (h != NULL && h->smclas != XMC_TD)
1100 {
1101 if (h->toc_section == NULL)
1102 {
1103 (*_bfd_error_handler)
1104 (_("%s: TOC reloc at 0x%x to symbol `%s' with no TOC entry"),
1105 bfd_get_filename (input_bfd), rel->r_vaddr,
1106 h->root.root.string);
1107 bfd_set_error (bfd_error_bad_value);
1108 return false;
1109 }
1110
1111 BFD_ASSERT ((h->flags & XCOFF_SET_TOC) == 0);
1112 val = (h->toc_section->output_section->vma
1113 + h->toc_section->output_offset);
1114
1115 }
1116
1117
1118 val = ((val - xcoff_data (output_bfd)->toc)
1119 - (sym->n_value - xcoff_data (input_bfd)->toc));
1120
1121 addend = 0;
1122 break;
1123 case R_BA:
1124 /* Absolute branch. We don't want to mess with the lower
1125 two bits of the instruction. */
1126 case R_CAI:
1127 /* The PowerPC ABI defines this as an absolute call which
1128 may be modified to become a relative call. The PowerOpen
1129 ABI does not define this relocation type. */
1130 case R_RBA:
1131 /* Absolute branch which may be modified to become a
1132 relative branch. */
1133 case R_RBAC:
1134 /* The PowerPC ABI defines this as an absolute branch to a
1135 fixed address which may be modified to an absolute branch
1136 to a symbol. The PowerOpen ABI does not define this
1137 relocation type. */
1138 case R_RBRC:
1139 /* The PowerPC ABI defines this as an absolute branch to a
1140 fixed address which may be modified to a relative branch.
1141 The PowerOpen ABI does not define this relocation type. */
1142 howto.src_mask &= ~3;
1143 howto.dst_mask = howto.src_mask;
1144 break;
1145 case R_BR:
1146 /* Relative branch. We don't want to mess with the lower
1147 two bits of the instruction. */
1148 case R_CREL:
1149 /* The PowerPC ABI defines this as a relative call which may
1150 be modified to become an absolute call. The PowerOpen
1151 ABI does not define this relocation type. */
1152 case R_RBR:
1153 /* A relative branch which may be modified to become an
1154 absolute branch. FIXME: We don't implement this,
1155 although we should for symbols of storage mapping class
1156 XMC_XO. */
1157 howto.pc_relative = true;
1158 howto.src_mask &= ~3;
1159 howto.dst_mask = howto.src_mask;
1160 howto.size = 2;
1161 howto.complain_on_overflow = complain_overflow_bitfield;
1162 break;
1163 case R_RL:
1164 /* The PowerPC AIX ABI describes this as a load which may be
1165 changed to a load address. The PowerOpen ABI says this
1166 is the same as case R_POS. */
1167 break;
1168 case R_RLA:
1169 /* The PowerPC AIX ABI describes this as a load address
1170 which may be changed to a load. The PowerOpen ABI says
1171 this is the same as R_POS. */
1172 break;
1173 }
1174
1175 /* If we see an R_BR or R_RBR reloc which is jumping to global
1176 linkage code, and it is followed by an appropriate cror nop
1177 instruction, we replace the cror with ld r2,40(r1). This
1178 restores the TOC after the glink code. Contrariwise, if the
1179 call is followed by a ld r2,40(r1), but the call is not
1180 going to global linkage code, we can replace the load with a
1181 cror. */
1182 if ((rel->r_type == R_BR || rel->r_type == R_RBR) &&
1183 h != NULL &&
1184 h->root.type == bfd_link_hash_defined &&
1185 (rel->r_vaddr - input_section->vma + 8
1186 <= input_section->_cooked_size)) {
1187
1188 bfd_byte *pnext;
1189 unsigned long next;
1190
1191 pnext = contents + (rel->r_vaddr - input_section->vma) + 4;
1192 next = bfd_get_32 (input_bfd, pnext);
1193
1194
1195 /* The _ptrgl function is magic. It is used by the AIX
1196 * compiler to call a function through a pointer.
1197 *
1198 * special case XMC_GL, global linkage
1199 */
1200 if (h->smclas == XMC_GL
1201 || strcmp (h->root.root.string, "._ptrgl") == 0)
1202 {
1203 if (next == 0x4def7b82 /* cror 15,15,15 */
1204 || next == 0x4ffffb82 /* cror 31,31,31 */
1205 || next == 0x60000000) /* ori r0,r0,0 */
1206 bfd_put_32 (input_bfd, 0xe8410028, pnext); /* ld r2,40(r1) */
1207 }
1208 else
1209 {
1210 if (next == 0xe8410028) /* ld r2,40(r1) */
1211 bfd_put_32 (input_bfd, 0x60000000, pnext); /* ori r0,r0,0 */
1212 }
1213 }
1214
1215 /* A PC relative reloc includes the section address. */
1216 if (howto.pc_relative)
1217 addend += input_section->vma;
1218
1219 rstat = _bfd_final_link_relocate (&howto, input_bfd, input_section,
1220 contents,
1221 rel->r_vaddr - input_section->vma,
1222 val, addend);
1223
1224 switch (rstat)
1225 {
1226 default:
1227 abort ();
1228 case bfd_reloc_ok:
1229 break;
1230 case bfd_reloc_overflow:
1231 {
1232 const char *name;
1233 char buf[SYMNMLEN + 1];
1234 char howto_name[10];
1235
1236 if (symndx == -1)
1237 name = "*ABS*";
1238 else if (h != NULL)
1239 name = h->root.root.string;
1240 else
1241 {
1242 name = _bfd_coff_internal_syment_name (input_bfd, sym, buf);
1243 if (name == NULL)
1244 return false;
1245 }
1246 sprintf (howto_name, "0x%02x", rel->r_type);
1247
1248 if (! ((*info->callbacks->reloc_overflow)
1249 (info, name, howto_name, (bfd_vma) 0, input_bfd,
1250 input_section, rel->r_vaddr - input_section->vma)))
1251 return false;
1252 }
1253 }
1254 }
1255
1256 return true;
1257}
1258
1259
1260\f
1261/* The XCOFF reloc table. Actually, XCOFF relocations specify the
1262 bitsize and whether they are signed or not, along with a
1263 conventional type. This table is for the types, which are used for
1264 different algorithms for putting in the reloc. Many of these
1265 relocs need special_function entries, which I have not written. */
1266
1267
1268reloc_howto_type xcoff64_howto_table[] =
1269{
1270 /* Standard 64 bit relocation. */
1271 HOWTO (0, /* type */
1272 0, /* rightshift */
1273 4, /* size (0 = byte, 1 = short, 2 = long) */
1274 64, /* bitsize */
1275 false, /* pc_relative */
1276 0, /* bitpos */
1277 complain_overflow_bitfield, /* complain_on_overflow */
1278 0, /* special_function */
1279 "R_POS", /* name */
1280 true, /* partial_inplace */
1281 MINUS_ONE, /* src_mask */
1282 MINUS_ONE, /* dst_mask */
1283 false), /* pcrel_offset */
1284
1285 /* 64 bit relocation, but store negative value. */
1286 HOWTO (1, /* type */
1287 0, /* rightshift */
1288 -4, /* size (0 = byte, 1 = short, 2 = long) */
1289 64, /* bitsize */
1290 false, /* pc_relative */
1291 0, /* bitpos */
1292 complain_overflow_bitfield, /* complain_on_overflow */
1293 0, /* special_function */
1294 "R_NEG", /* name */
1295 true, /* partial_inplace */
1296 MINUS_ONE, /* src_mask */
1297 MINUS_ONE, /* dst_mask */
1298 false), /* pcrel_offset */
1299
1300 /* 32 bit PC relative relocation. */
1301 HOWTO (2, /* type */
1302 0, /* rightshift */
1303 2, /* size (0 = byte, 1 = short, 2 = long) */
1304 32, /* bitsize */
1305 true, /* pc_relative */
1306 0, /* bitpos */
1307 complain_overflow_signed, /* complain_on_overflow */
1308 0, /* special_function */
1309 "R_REL", /* name */
1310 true, /* partial_inplace */
1311 0xffffffff, /* src_mask */
1312 0xffffffff, /* dst_mask */
1313 false), /* pcrel_offset */
1314
1315 /* 16 bit TOC relative relocation. */
1316 HOWTO (3, /* type */
1317 0, /* rightshift */
1318 1, /* size (0 = byte, 1 = short, 2 = long) */
1319 16, /* bitsize */
1320 false, /* pc_relative */
1321 0, /* bitpos */
1322 complain_overflow_bitfield, /* complain_on_overflow */
1323 0, /* special_function */
1324 "R_TOC", /* name */
1325 true, /* partial_inplace */
1326 0xffff, /* src_mask */
1327 0xffff, /* dst_mask */
1328 false), /* pcrel_offset */
1329
1330 /* I don't really know what this is. */
1331 HOWTO (4, /* type */
1332 1, /* rightshift */
1333 2, /* size (0 = byte, 1 = short, 2 = long) */
1334 32, /* bitsize */
1335 false, /* pc_relative */
1336 0, /* bitpos */
1337 complain_overflow_bitfield, /* complain_on_overflow */
1338 0, /* special_function */
1339 "R_RTB", /* name */
1340 true, /* partial_inplace */
1341 0xffffffff, /* src_mask */
1342 0xffffffff, /* dst_mask */
1343 false), /* pcrel_offset */
1344
1345 /* External TOC relative symbol. */
1346 HOWTO (5, /* type */
1347 0, /* rightshift */
1348 2, /* size (0 = byte, 1 = short, 2 = long) */
1349 16, /* bitsize */
1350 false, /* pc_relative */
1351 0, /* bitpos */
1352 complain_overflow_bitfield, /* complain_on_overflow */
1353 0, /* special_function */
1354 "R_GL", /* name */
1355 true, /* partial_inplace */
1356 0xffff, /* src_mask */
1357 0xffff, /* dst_mask */
1358 false), /* pcrel_offset */
1359
1360 /* Local TOC relative symbol. */
1361 HOWTO (6, /* type */
1362 0, /* rightshift */
1363 2, /* size (0 = byte, 1 = short, 2 = long) */
1364 16, /* bitsize */
1365 false, /* pc_relative */
1366 0, /* bitpos */
1367 complain_overflow_bitfield, /* complain_on_overflow */
1368 0, /* special_function */
1369 "R_TCL", /* name */
1370 true, /* partial_inplace */
1371 0xffff, /* src_mask */
1372 0xffff, /* dst_mask */
1373 false), /* pcrel_offset */
1374
1375 EMPTY_HOWTO (7),
1376
1377 /* Non modifiable absolute branch. */
1378 HOWTO (8, /* type */
1379 0, /* rightshift */
1380 2, /* size (0 = byte, 1 = short, 2 = long) */
1381 26, /* bitsize */
1382 false, /* pc_relative */
1383 0, /* bitpos */
1384 complain_overflow_bitfield, /* complain_on_overflow */
1385 0, /* special_function */
1386 "R_BA", /* name */
1387 true, /* partial_inplace */
1388 0x3fffffc, /* src_mask */
1389 0x3fffffc, /* dst_mask */
1390 false), /* pcrel_offset */
1391
1392 EMPTY_HOWTO (9),
1393
1394 /* Non modifiable relative branch. */
1395 HOWTO (0xa, /* type */
1396 0, /* rightshift */
1397 2, /* size (0 = byte, 1 = short, 2 = long) */
1398 26, /* bitsize */
1399 true, /* pc_relative */
1400 0, /* bitpos */
1401 complain_overflow_signed, /* complain_on_overflow */
1402 0, /* special_function */
1403 "R_BR", /* name */
1404 true, /* partial_inplace */
1405 0x3fffffc, /* src_mask */
1406 0x3fffffc, /* dst_mask */
1407 false), /* pcrel_offset */
1408
1409 EMPTY_HOWTO (0xb),
1410
1411 /* Indirect load. */
1412 HOWTO (0xc, /* type */
1413 0, /* rightshift */
1414 2, /* size (0 = byte, 1 = short, 2 = long) */
1415 16, /* bitsize */
1416 false, /* pc_relative */
1417 0, /* bitpos */
1418 complain_overflow_bitfield, /* complain_on_overflow */
1419 0, /* special_function */
1420 "R_RL", /* name */
1421 true, /* partial_inplace */
1422 0xffff, /* src_mask */
1423 0xffff, /* dst_mask */
1424 false), /* pcrel_offset */
1425
1426 /* Load address. */
1427 HOWTO (0xd, /* type */
1428 0, /* rightshift */
1429 2, /* size (0 = byte, 1 = short, 2 = long) */
1430 16, /* bitsize */
1431 false, /* pc_relative */
1432 0, /* bitpos */
1433 complain_overflow_bitfield, /* complain_on_overflow */
1434 0, /* special_function */
1435 "R_RLA", /* name */
1436 true, /* partial_inplace */
1437 0xffff, /* src_mask */
1438 0xffff, /* dst_mask */
1439 false), /* pcrel_offset */
1440
1441 EMPTY_HOWTO (0xe),
1442
1443 /* Non-relocating reference. */
1444 HOWTO (0xf, /* type */
1445 0, /* rightshift */
1446 2, /* size (0 = byte, 1 = short, 2 = long) */
1447 32, /* bitsize */
1448 false, /* pc_relative */
1449 0, /* bitpos */
1450 complain_overflow_bitfield, /* complain_on_overflow */
1451 0, /* special_function */
1452 "R_REF", /* name */
1453 false, /* partial_inplace */
1454 0, /* src_mask */
1455 0, /* dst_mask */
1456 false), /* pcrel_offset */
1457
1458 EMPTY_HOWTO (0x10),
1459 EMPTY_HOWTO (0x11),
1460
1461 /* TOC relative indirect load. */
1462 HOWTO (0x12, /* type */
1463 0, /* rightshift */
1464 2, /* size (0 = byte, 1 = short, 2 = long) */
1465 16, /* bitsize */
1466 false, /* pc_relative */
1467 0, /* bitpos */
1468 complain_overflow_bitfield, /* complain_on_overflow */
1469 0, /* special_function */
1470 "R_TRL", /* name */
1471 true, /* partial_inplace */
1472 0xffff, /* src_mask */
1473 0xffff, /* dst_mask */
1474 false), /* pcrel_offset */
1475
1476 /* TOC relative load address. */
1477 HOWTO (0x13, /* type */
1478 0, /* rightshift */
1479 2, /* size (0 = byte, 1 = short, 2 = long) */
1480 16, /* bitsize */
1481 false, /* pc_relative */
1482 0, /* bitpos */
1483 complain_overflow_bitfield, /* complain_on_overflow */
1484 0, /* special_function */
1485 "R_TRLA", /* name */
1486 true, /* partial_inplace */
1487 0xffff, /* src_mask */
1488 0xffff, /* dst_mask */
1489 false), /* pcrel_offset */
1490
1491 /* Modifiable relative branch. */
1492 HOWTO (0x14, /* type */
1493 1, /* rightshift */
1494 2, /* size (0 = byte, 1 = short, 2 = long) */
1495 32, /* bitsize */
1496 false, /* pc_relative */
1497 0, /* bitpos */
1498 complain_overflow_bitfield, /* complain_on_overflow */
1499 0, /* special_function */
1500 "R_RRTBI", /* name */
1501 true, /* partial_inplace */
1502 0xffffffff, /* src_mask */
1503 0xffffffff, /* dst_mask */
1504 false), /* pcrel_offset */
1505
1506 /* Modifiable absolute branch. */
1507 HOWTO (0x15, /* type */
1508 1, /* rightshift */
1509 2, /* size (0 = byte, 1 = short, 2 = long) */
1510 32, /* bitsize */
1511 false, /* pc_relative */
1512 0, /* bitpos */
1513 complain_overflow_bitfield, /* complain_on_overflow */
1514 0, /* special_function */
1515 "R_RRTBA", /* name */
1516 true, /* partial_inplace */
1517 0xffffffff, /* src_mask */
1518 0xffffffff, /* dst_mask */
1519 false), /* pcrel_offset */
1520
1521 /* Modifiable call absolute indirect. */
1522 HOWTO (0x16, /* type */
1523 0, /* rightshift */
1524 2, /* size (0 = byte, 1 = short, 2 = long) */
1525 16, /* bitsize */
1526 false, /* pc_relative */
1527 0, /* bitpos */
1528 complain_overflow_bitfield, /* complain_on_overflow */
1529 0, /* special_function */
1530 "R_CAI", /* name */
1531 true, /* partial_inplace */
1532 0xffff, /* src_mask */
1533 0xffff, /* dst_mask */
1534 false), /* pcrel_offset */
1535
1536 /* Modifiable call relative. */
1537 HOWTO (0x17, /* type */
1538 0, /* rightshift */
1539 2, /* size (0 = byte, 1 = short, 2 = long) */
1540 16, /* bitsize */
1541 false, /* pc_relative */
1542 0, /* bitpos */
1543 complain_overflow_bitfield, /* complain_on_overflow */
1544 0, /* special_function */
1545 "R_CREL", /* name */
1546 true, /* partial_inplace */
1547 0xffff, /* src_mask */
1548 0xffff, /* dst_mask */
1549 false), /* pcrel_offset */
1550
1551 /* Modifiable branch absolute. */
1552 HOWTO (0x18, /* type */
1553 0, /* rightshift */
1554 2, /* size (0 = byte, 1 = short, 2 = long) */
1555 26, /* bitsize */
1556 false, /* pc_relative */
1557 0, /* bitpos */
1558 complain_overflow_bitfield, /* complain_on_overflow */
1559 0, /* special_function */
1560 "R_RBA", /* name */
1561 true, /* partial_inplace */
1562 0xffff, /* src_mask */
1563 0xffff, /* dst_mask */
1564 false), /* pcrel_offset */
1565
1566 /* Modifiable branch absolute. */
1567 HOWTO (0x19, /* type */
1568 0, /* rightshift */
1569 2, /* size (0 = byte, 1 = short, 2 = long) */
1570 32, /* bitsize */
1571 false, /* pc_relative */
1572 0, /* bitpos */
1573 complain_overflow_bitfield, /* complain_on_overflow */
1574 0, /* special_function */
1575 "R_RBAC", /* name */
1576 true, /* partial_inplace */
1577 0xffff, /* src_mask */
1578 0xffff, /* dst_mask */
1579 false), /* pcrel_offset */
1580
1581 /* Modifiable branch relative. */
1582 HOWTO (0x1a, /* type */
1583 0, /* rightshift */
1584 2, /* size (0 = byte, 1 = short, 2 = long) */
1585 26, /* bitsize */
1586 false, /* pc_relative */
1587 0, /* bitpos */
1588 complain_overflow_signed, /* complain_on_overflow */
1589 0, /* special_function */
1590 "R_RBR", /* name */
1591 true, /* partial_inplace */
1592 0xffff, /* src_mask */
1593 0xffff, /* dst_mask */
1594 false), /* pcrel_offset */
1595
1596 /* Modifiable branch absolute. */
1597 HOWTO (0x1b, /* type */
1598 0, /* rightshift */
1599 2, /* size (0 = byte, 1 = short, 2 = long) */
1600 16, /* bitsize */
1601 false, /* pc_relative */
1602 0, /* bitpos */
1603 complain_overflow_bitfield, /* complain_on_overflow */
1604 0, /* special_function */
1605 "R_RBRC", /* name */
1606 true, /* partial_inplace */
1607 0xffff, /* src_mask */
1608 0xffff, /* dst_mask */
1609 false), /* pcrel_offset */
1610
1611 HOWTO (0, /* type */
1612 0, /* rightshift */
1613 4, /* size (0 = byte, 1 = short, 2 = long) */
1614 64, /* bitsize */
1615 false, /* pc_relative */
1616 0, /* bitpos */
1617 complain_overflow_bitfield, /* complain_on_overflow */
1618 0, /* special_function */
1619 "R_POS", /* name */
1620 true, /* partial_inplace */
1621 MINUS_ONE, /* src_mask */
1622 MINUS_ONE, /* dst_mask */
1623 false) /* pcrel_offset */
1624
1625};
1626
1627void
1628xcoff64_rtype2howto (relent, internal)
1629 arelent *relent;
1630 struct internal_reloc *internal;
1631{
1632 relent->howto = xcoff64_howto_table + internal->r_type;
1633
1634 /* Check for relocs we don't know of. */
1635 if (internal->r_type
1636 >= sizeof (xcoff64_howto_table) / sizeof (xcoff64_howto_table[0]))
1637 abort ();
1638 if (internal->r_type != relent->howto->type)
1639 abort ();
1640
1641 /* The r_size field of an XCOFF reloc encodes the bitsize of the
1642 relocation, as well as indicating whether it is signed or not.
1643 Doublecheck that the relocation information gathered from the
1644 type matches this information. The bitsize is not significant
1645 for R_REF relocs. */
1646 if (relent->howto->dst_mask != 0
1647 && (relent->howto->bitsize
1648 != ((unsigned int) internal->r_size & 0x3f) + 1))
1649 abort ();
1650#if 0
1651 if ((internal->r_size & 0x80) != 0
1652 ? (relent->howto->complain_on_overflow != complain_overflow_signed)
1653 : (relent->howto->complain_on_overflow != complain_overflow_bitfield))
1654 abort ();
1655#endif
1656}
1657
1658reloc_howto_type *
1659xcoff64_reloc_type_lookup (abfd, code)
1660 bfd *abfd ATTRIBUTE_UNUSED;
1661 bfd_reloc_code_real_type code;
1662{
1663 switch (code)
1664 {
1665 case BFD_RELOC_PPC_B26:
1666 return &xcoff64_howto_table[0xa];
1667 case BFD_RELOC_PPC_BA26:
1668 return &xcoff64_howto_table[8];
1669 case BFD_RELOC_PPC_TOC16:
1670 return &xcoff64_howto_table[3];
1671 case BFD_RELOC_32:
1672 case BFD_RELOC_CTOR:
1673 return &xcoff64_howto_table[0];
1674 case BFD_RELOC_64:
1675 return &xcoff64_howto_table[0x1c];
1676 default:
1677 return NULL;
1678 }
1679}
1680
1681
1682
1683/* Read in the armap of an XCOFF archive. */
1684
1685boolean
1686xcoff64_slurp_armap (abfd)
1687 bfd *abfd;
1688{
1689 file_ptr off;
1690 size_t namlen;
1691 bfd_size_type sz;
1692 bfd_byte *contents, *cend;
1693 bfd_vma c, i;
1694 carsym *arsym;
1695 bfd_byte *p;
1696
1697 /* This is for the new format. */
1698 struct xcoff_ar_hdr_big hdr;
1699
1700 if (xcoff_ardata (abfd) == NULL) {
1701 bfd_has_map (abfd) = false;
1702 return true;
1703 }
1704
1705 off = strtol (xcoff_ardata_big (abfd)->symoff64, (char **) NULL, 10);
1706 if (off == 0) {
1707 bfd_has_map (abfd) = false;
1708 return true;
1709 }
1710
1711 if (bfd_seek (abfd, off, SEEK_SET) != 0)
1712 return false;
1713
1714 /* The symbol table starts with a normal archive header. */
1715 if (bfd_read ((PTR) &hdr, SIZEOF_AR_HDR_BIG, 1, abfd) != SIZEOF_AR_HDR_BIG)
1716 return false;
1717
1718 /* Skip the name (normally empty). */
1719 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1720 if (bfd_seek (abfd, ((namlen + 1) & ~1) + SXCOFFARFMAG, SEEK_CUR) != 0)
1721 return false;
1722
1723 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1724 machines) since the field width is 20 and there numbers with more
1725 than 32 bits can be represented. */
1726 sz = strtol (hdr.size, (char **) NULL, 10);
1727
1728 /* Read in the entire symbol table. */
1729 contents = (bfd_byte *) bfd_alloc (abfd, sz);
1730 if (contents == NULL)
1731 return false;
1732 if (bfd_read ((PTR) contents, 1, sz, abfd) != sz)
1733 return false;
1734
1735 /* The symbol table starts with an eight byte count. */
1736 c = bfd_h_get_64 (abfd, contents);
1737
1738 if (c * 8 >= sz) {
1739 bfd_set_error (bfd_error_bad_value);
1740 return false;
1741 }
1742
1743 bfd_ardata (abfd)->symdefs = ((carsym *)
1744 bfd_alloc (abfd, c * sizeof (carsym)));
1745 if (bfd_ardata (abfd)->symdefs == NULL)
1746 return false;
1747
1748 /* After the count comes a list of eight byte file offsets. */
1749 for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 8;
1750 i < c;
1751 ++i, ++arsym, p += 8)
1752 arsym->file_offset = bfd_h_get_64 (abfd, p);
1753
1754 /* After the file offsets come null terminated symbol names. */
1755 cend = contents + sz;
1756 for (i = 0, arsym = bfd_ardata (abfd)->symdefs;
1757 i < c;
1758 ++i, ++arsym, p += strlen ((char *) p) + 1)
1759 {
1760 if (p >= cend)
1761 {
1762 bfd_set_error (bfd_error_bad_value);
1763 return false;
1764 }
1765 arsym->name = (char *) p;
1766 }
1767
1768 bfd_ardata (abfd)->symdef_count = c;
1769 bfd_has_map (abfd) = true;
1770
1771 return true;
1772}
1773
1774
1775
1776/* See if this is an NEW XCOFF archive. */
1777
1778const bfd_target *
1779xcoff64_archive_p (abfd)
1780 bfd *abfd;
1781{
1782 char magic[SXCOFFARMAG];
1783 /* This is the new format. */
1784 struct xcoff_ar_file_hdr_big hdr;
1785
1786 if (bfd_read ((PTR) magic, SXCOFFARMAG, 1, abfd) != SXCOFFARMAG) {
1787 if (bfd_get_error () != bfd_error_system_call)
1788 bfd_set_error (bfd_error_wrong_format);
1789 return NULL;
1790 }
1791
1792 if (strncmp (magic, XCOFFARMAGBIG, SXCOFFARMAG) != 0) {
1793 bfd_set_error (bfd_error_wrong_format);
1794 return NULL;
1795 }
1796
1797 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
1798 involves a cast, we can't do it as the left operand of
1799 assignment. */
1800 abfd->tdata.aout_ar_data =
1801 (struct artdata *) bfd_zalloc (abfd, sizeof (struct artdata));
1802
1803 if (bfd_ardata (abfd) == (struct artdata *) NULL)
1804 return NULL;
1805
1806 bfd_ardata (abfd)->cache = NULL;
1807 bfd_ardata (abfd)->archive_head = NULL;
1808 bfd_ardata (abfd)->symdefs = NULL;
1809 bfd_ardata (abfd)->extended_names = NULL;
1810
1811 /* Copy over the magic string. */
1812 memcpy (hdr.magic, magic, SXCOFFARMAG);
1813
1814 /* Now read the rest of the file header. */
1815 if (bfd_read ((PTR) &hdr.memoff, SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG, 1,
1816 abfd) != SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG) {
1817 if (bfd_get_error () != bfd_error_system_call)
1818 bfd_set_error (bfd_error_wrong_format);
1819 return NULL;
1820 }
1821
1822 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1823 machines) since the field width is 20 and there numbers with more
1824 than 32 bits can be represented. */
1825 bfd_ardata (abfd)->first_file_filepos = strtol (hdr.firstmemoff,
1826 (char **) NULL, 10);
1827
1828 bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, SIZEOF_AR_FILE_HDR_BIG);
1829 if (bfd_ardata (abfd)->tdata == NULL)
1830 return NULL;
1831
1832 memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR_BIG);
1833
1834 if (! xcoff64_slurp_armap (abfd)) {
1835
1836 bfd_release (abfd, bfd_ardata (abfd));
1837 abfd->tdata.aout_ar_data = (struct artdata *) NULL;
1838 return NULL;
1839 }
1840
1841 return abfd->xvec;
1842}
1843
1844
1845/* Open the next element in an XCOFF archive. */
1846
1847bfd *
1848xcoff64_openr_next_archived_file (archive, last_file)
1849 bfd *archive;
1850 bfd *last_file;
1851{
1852 file_ptr filestart;
1853
1854 if ((xcoff_ardata (archive) == NULL) ||
1855 (! xcoff_big_format_p (archive))) {
1856 bfd_set_error (bfd_error_invalid_operation);
1857 return NULL;
1858 }
1859
1860 if (last_file == NULL) {
1861 filestart = bfd_ardata (archive)->first_file_filepos;
1862 } else {
1863 /* XXX These actually have to be a calls to strtoll (at least
1864 on 32-bit machines) since the fields's width is 20 and
1865 there numbers with more than 32 bits can be represented. */
1866 filestart = strtol (arch_xhdr_big (last_file)->nextoff, (char **) NULL,
1867 10);
1868 }
1869 /* XXX These actually have to be calls to strtoll (at least on 32-bit
1870 machines) since the fields's width is 20 and there numbers with more
1871 than 32 bits can be represented. */
1872 if (filestart == 0
1873 || filestart == strtol (xcoff_ardata_big (archive)->memoff,
1874 (char **) NULL, 10)
1875 || filestart == strtol (xcoff_ardata_big (archive)->symoff,
1876 (char **) NULL, 10)) {
1877 bfd_set_error (bfd_error_no_more_archived_files);
1878 return NULL;
1879 }
1880
1881 return _bfd_get_elt_at_filepos (archive, filestart);
1882}
1883
1884/* We can't use the usual coff_sizeof_headers routine, because AIX
1885 always uses an a.out header. */
1886
1887/*ARGSUSED*/
1888int
1889xcoff64_sizeof_headers (abfd, reloc)
1890 bfd *abfd;
1891 boolean reloc ATTRIBUTE_UNUSED;
1892{
1893 int size;
1894
1895 size = bfd_coff_filhsz(abfd);
1896
1897 /*
1898 * Don't think the small aout header can be used since some of the the
1899 * old elements have been reordered past the end of the old coff
1900 * small aout size
1901 */
1902
1903 if (xcoff_data (abfd)->full_aouthdr)
1904 size += bfd_coff_aoutsz(abfd);
1905
1906 size += abfd->section_count * bfd_coff_scnhsz(abfd);
1907 return size;
1908}
1909
1910
1911
1912static asection *
1913xcoff64_create_csect_from_smclas (abfd, aux, symbol_name)
1914 bfd *abfd;
1915 union internal_auxent *aux;
1916 const char *symbol_name;
1917{
1918 asection *return_value = NULL;
1919
1920 /*
1921 * Changes from 32 :
1922 * .sv == 8, is only for 32 bit programs
1923 * .ti == 12 and .tb == 13 are now reserved
1924 */
1925 static const char *names[19] = {
1926 ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo",
1927 NULL, ".bs", ".ds", ".uc", NULL, NULL, NULL, ".tc0",
1928 ".td", ".sv64", ".sv3264"
1929 };
1930
1931 if ((19 >= aux->x_csect.x_smclas) &&
1932 (NULL != names[aux->x_csect.x_smclas])) {
1933
1934 return_value = bfd_make_section_anyway
1935 (abfd, names[aux->x_csect.x_smclas]);
1936
1937 } else {
1938 (*_bfd_error_handler)
1939 (_("%s: symbol `%s' has unrecognized smclas %d"),
1940 bfd_get_filename (abfd), symbol_name, aux->x_csect.x_smclas);
1941 bfd_set_error (bfd_error_bad_value);
1942 }
1943
1944 return return_value;
1945}
1946
1947boolean
1948xcoff64_is_lineno_count_overflow (abfd, value)
1949 bfd *abfd ATTRIBUTE_UNUSED;
1950 bfd_vma value ATTRIBUTE_UNUSED;
1951{
1952 return false;
1953}
1954
1955boolean
1956xcoff64_is_reloc_count_overflow (abfd, value)
1957 bfd *abfd ATTRIBUTE_UNUSED;
1958 bfd_vma value ATTRIBUTE_UNUSED;
1959{
1960 return false;
1961}
1962
1963bfd_vma
1964xcoff64_loader_symbol_offset (abfd, ldhdr)
1965 bfd *abfd ATTRIBUTE_UNUSED;
1966 struct internal_ldhdr *ldhdr;
1967{
1968 return (ldhdr->l_symoff);
1969}
1970
1971bfd_vma
1972xcoff64_loader_reloc_offset (abfd, ldhdr)
1973 bfd *abfd ATTRIBUTE_UNUSED;
1974 struct internal_ldhdr *ldhdr;
1975{
1976 return (ldhdr->l_rldoff);
1977}
1978
1979/* The typical dynamic reloc. */
1980
1981static reloc_howto_type xcoff64_dynamic_reloc =
1982 HOWTO (0, /* type */
1983 0, /* rightshift */
1984 4, /* size (0 = byte, 1 = short, 2 = long) */
1985 64, /* bitsize */
1986 false, /* pc_relative */
1987 0, /* bitpos */
1988 complain_overflow_bitfield, /* complain_on_overflow */
1989 0, /* special_function */
1990 "R_POS", /* name */
1991 true, /* partial_inplace */
1992 MINUS_ONE, /* src_mask */
1993 MINUS_ONE, /* dst_mask */
1994 false); /* pcrel_offset */
1995
1996static unsigned long xcoff64_glink_code[10] =
1997{
1998 0xe9820000, /* ld r12,0(r2) */
1999 0xf8410028, /* std r2,40(r1) */
2000 0xe80c0000, /* ld r0,0(r12) */
2001 0xe84c0008, /* ld r0,8(r12) */
2002 0x7c0903a6, /* mtctr r0 */
2003 0x4e800420, /* bctr */
2004 0x00000000, /* start of traceback table */
2005 0x000ca000, /* traceback table */
2006 0x00000000, /* traceback table */
2007 0x00000018, /* ??? */
2008};
2009
2010static const struct xcoff_backend_data_rec bfd_xcoff_backend_data =
2011{
2012 { /* COFF backend, defined in libcoff.h */
2013 _bfd_xcoff64_swap_aux_in, /* _bfd_coff_swap_aux_in */
2014 _bfd_xcoff64_swap_sym_in, /* _bfd_coff_swap_sym_in */
2015 _bfd_xcoff64_swap_lineno_in, /* _bfd_coff_swap_lineno_in */
2016 _bfd_xcoff64_swap_aux_out, /* _bfd_swap_aux_out */
2017 _bfd_xcoff64_swap_sym_out, /* _bfd_swap_sym_out */
2018 _bfd_xcoff64_swap_lineno_out, /* _bfd_swap_lineno_out */
2019 coff_swap_reloc_out, /* _bfd_swap_reloc_out */
2020 coff_swap_filehdr_out, /* _bfd_swap_filehdr_out */
2021 coff_swap_aouthdr_out, /* _bfd_swap_aouthdr_out */
2022 coff_swap_scnhdr_out, /* _bfd_swap_scnhdr_out */
2023 FILHSZ, /* _bfd_filhsz */
2024 AOUTSZ, /* _bfd_aoutsz */
2025 SCNHSZ, /* _bfd_scnhsz */
2026 SYMESZ, /* _bfd_symesz */
2027 AUXESZ, /* _bfd_auxesz */
2028 RELSZ, /* _bfd_relsz */
2029 LINESZ, /* _bfd_linesz */
2030 FILNMLEN, /* _bfd_filnmlen */
2031 true, /* _bfd_coff_long_filenames */
2032 false, /* _bfd_coff_long_section_names */
2033 (3), /* _bfd_coff_default_section_alignment_power */
2034 true, /* _bfd_coff_force_symnames_in_strings */
2035 4, /* _bfd_coff_debug_string_prefix_length */
2036 coff_swap_filehdr_in, /* _bfd_coff_swap_filehdr_in */
2037 coff_swap_aouthdr_in, /* _bfd_swap_aouthdr_in */
2038 coff_swap_scnhdr_in, /* _bfd_swap_scnhdr_in */
2039 coff_swap_reloc_in, /* _bfd_reloc_in */
2040 coff_bad_format_hook, /* _bfd_bad_format_hook */
2041 coff_set_arch_mach_hook, /* _bfd_set_arch_mach_hook */
2042 coff_mkobject_hook, /* _bfd_mkobject_hook */
2043 styp_to_sec_flags, /* _bfd_syp_to_sec_flags */
2044 coff_set_alignment_hook, /* _bfd_set_alignment_hook */
2045 coff_slurp_symbol_table, /* _bfd_coff_slurp_symbol_table */
2046 symname_in_debug_hook, /* _coff_symname_in_debug_hook */
2047 coff_pointerize_aux_hook, /* _bfd_coff_pointerize_aux_hook */
2048 coff_print_aux, /* bfd_coff_print_aux */
2049 dummy_reloc16_extra_cases, /* _bfd_coff_reloc16_extra_cases */
2050 dummy_reloc16_estimate, /* _bfd_coff_reloc16_estimate */
2051 NULL, /* bfd_coff_sym_is_global */
2052 /* _bfd_coff_compute_section_file_positions */
2053 coff_compute_section_file_positions,
2054 NULL , /* _bfd_coff_start_final_link */
2055 xcoff64_ppc_relocate_section, /* _bfd_coff_relocate_section */
2056 coff_rtype_to_howto, /* _bfd_coff_rtype_to_howto */
2057 NULL , /* _bfd_coff_addust_symndx */
2058 _bfd_generic_link_add_one_symbol, /* _bfd_coff_add_one_symbol */
2059 coff_link_output_has_begun, /* _bfd_coff_link_output_has_begun */
2060 coff_final_link_postscript /* _bfd_coff_final_link_postscript */
2061 },
2062
2063 0x01EF, /* magic number */
2064 bfd_arch_powerpc, /* architecture */
2065 bfd_mach_ppc_620, /* machine */
2066
2067 /* function pointers to xcoff specific swap routines */
2068 xcoff64_swap_ldhdr_in, /* _xcoff_swap_ldhdr_in */
2069 xcoff64_swap_ldhdr_out, /* _xcoff_swap_ldhdr_out */
2070 xcoff64_swap_ldsym_in, /* _xcoff_swap_ldsym_in */
2071 xcoff64_swap_ldsym_out, /* _xcoff_swap_ldsym_out */
2072 xcoff64_swap_ldrel_in, /* _xcoff_swap_ldrel_in */
2073 xcoff64_swap_ldrel_out, /* _xcoff_swap_ldrel_out */
2074
2075 /* sizes */
2076 LDHDRSZ, /* _xcoff_ldhdrsz */
2077 LDSYMSZ, /* _xcoff_ldsymsz */
2078 LDRELSZ, /* _xcoff_ldrelsz */
2079 24, /* _xcoff_function_descriptor_size */
2080 0, /* _xcoff_small_aout_header_size */
2081 /* versions */
2082 2, /* _xcoff_ldhdr_version */
2083
2084 /* xcoff vs xcoff64 putting symbol names */
2085 _bfd_xcoff64_put_symbol_name, /* _xcoff_put_symbol_name */
2086 _bfd_xcoff64_put_ldsymbol_name, /* _xcoff_put_ldsymbol_name */
2087
2088 /* dynamic reloc howto */
2089 &xcoff64_dynamic_reloc,
2090
2091 xcoff64_create_csect_from_smclas,
2092
2093 /* lineno and reloc count overflow */
2094 xcoff64_is_lineno_count_overflow,
2095 xcoff64_is_reloc_count_overflow,
2096
2097 xcoff64_loader_symbol_offset,
2098 xcoff64_loader_reloc_offset,
2099
2100 /* glink */
2101 &xcoff64_glink_code[0],
2102 40, /* _xcoff_glink_size */
2103
2104};
2105
2106/* The transfer vector that leads the outside world to all of the above. */
2107const bfd_target rs6000coff64_vec =
2108{
2109 "aixcoff64-rs6000",
2110 bfd_target_xcoff_flavour,
2111 BFD_ENDIAN_BIG, /* data byte order is big */
2112 BFD_ENDIAN_BIG, /* header byte order is big */
2113
2114 (HAS_RELOC | EXEC_P | /* object flags */
2115 HAS_LINENO | HAS_DEBUG | DYNAMIC |
2116 HAS_SYMS | HAS_LOCALS | WP_TEXT),
2117
2118 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
2119 0, /* leading char */
2120 '/', /* ar_pad_char */
2121 15, /* ar_max_namelen??? FIXMEmgo */
2122
2123 /* data */
2124 bfd_getb64, /* bfd_getx64 */
2125 bfd_getb_signed_64, /* bfd_getx_signed_64 */
2126 bfd_putb64, /* bfd_putx64 */
2127 bfd_getb32, /* bfd_getx32 */
2128 bfd_getb_signed_32, /* bfd_getx_signed_32 */
2129 bfd_putb32, /* bfd_putx32 */
2130 bfd_getb16, /* bfd_getx16 */
2131 bfd_getb_signed_16, /* bfd_getx_signed_16 */
2132 bfd_putb16, /* bfd_putx16 */
2133
2134 /* hdrs */
2135 bfd_getb64, /* bfd_h_getx64 */
2136 bfd_getb_signed_64, /* bfd_h_getx_signed_64 */
2137 bfd_putb64, /* bfd_h_putx64 */
2138 bfd_getb32, /* bfd_h_getx32 */
2139 bfd_getb_signed_32, /* bfd_h_getx_signed_32 */
2140 bfd_putb32, /* bfd_h_putx32 */
2141 bfd_getb16, /* bfd_h_getx16 */
2142 bfd_getb_signed_16, /* bfd_h_getx_signed_16 */
2143 bfd_putb16, /* bfd_h_putx16 */
2144
2145 { /* bfd_check_format */
2146 _bfd_dummy_target,
2147 coff_object_p,
2148 xcoff64_archive_p,
2149 rs6000coff_core_p
2150 },
2151
2152 { /* bfd_set_format */
2153 bfd_false,
2154 coff_mkobject,
2155 _bfd_generic_mkarchive,
2156 bfd_false
2157 },
2158
2159 {/* bfd_write_contents */
2160 bfd_false,
2161 xcoff64_write_object_contents,
2162 _bfd_xcoff_write_archive_contents,
2163 bfd_false
2164 },
2165
2166 /* Generic */
2167 bfd_true, /* _close_and_cleanup */
2168 bfd_true, /* _bfd_free_cached_info */
2169 coff_new_section_hook, /* _new_section_hook */
2170 _bfd_generic_get_section_contents, /* _bfd_get_section_contents */
2171 /* _bfd_get_section_contents_in_window */
2172 _bfd_generic_get_section_contents_in_window,
2173
2174 /* Copy */
2175 _bfd_xcoff_copy_private_bfd_data, /* _bfd_copy_private_bfd */
2176 /* _bfd_merge_private_bfd_data */
2177 ((boolean (*) (bfd *, bfd *)) bfd_true),
2178 /* _bfd_copy_pivate_section_data */
2179 ((boolean (*) (bfd *, asection *, bfd *, asection *)) bfd_true),
2180 /* _bfd_copy_private_symbol_data */
2181 ((boolean (*) (bfd *, asymbol *, bfd *, asymbol *)) bfd_true),
2182 ((boolean (*) (bfd *, flagword)) bfd_true), /* _bfd_set_private_flags */
2183 ((boolean (*) (bfd *, void * )) bfd_true), /* _bfd_print_private_bfd_data */
2184
2185 /* Core */
2186 rs6000coff_core_file_failing_command, /* _core_file_failing_command */
2187 rs6000coff_core_file_failing_signal, /* _core_file_failing_signal */
2188 /* _core_file_matches_executable_p */
2189 rs6000coff_core_file_matches_executable_p,
2190
2191 /* Archive */
2192 xcoff64_slurp_armap, /* _slurp_armap */
2193 /* XCOFF archives do not have
2194 anything which corresponds to
2195 an extended name table. */
2196 bfd_false, /* _slurp_extended_name_table */
2197 /* _construct_extended_name_table */
2198 ((boolean (*) (bfd *, char **, bfd_size_type *, const char **)) bfd_false),
2199 bfd_dont_truncate_arname, /* _truncate_arname */
2200 _bfd_xcoff_write_armap, /* _write_armap */
2201 _bfd_xcoff_read_ar_hdr, /* _read_ar_hdr */
2202 xcoff64_openr_next_archived_file, /* _openr_next_archived_file */
2203 _bfd_generic_get_elt_at_index, /* _get_elt_at_index */
2204 _bfd_xcoff_generic_stat_arch_elt, /* _generic_dtat_arch_elt */
2205 /* XCOFF archives do not have
2206 a timestamp. */
2207 bfd_true, /* _update_armap_timestamp */
2208
2209 /* Symbols */
2210 coff_get_symtab_upper_bound, /* _get_symtab_upper_bound */
2211 coff_get_symtab, /* _get_symtab */
2212 coff_make_empty_symbol, /* _make_empty_symbol */
2213 coff_print_symbol, /* _print_symbol */
2214 coff_get_symbol_info, /* _get_symbol_info */
2215 _bfd_xcoff_is_local_label_name, /* _bfd_is_local_label_name */
2216 coff_get_lineno, /* _get_lineno */
2217 coff_find_nearest_line, /* _find_nearest_line */
2218 coff_bfd_make_debug_symbol, /* _bfd_make_debug_symbol */
2219 _bfd_generic_read_minisymbols, /* _read_minisymbols */
2220 _bfd_generic_minisymbol_to_symbol, /* _minsymbol_to_symbol */
2221
2222 /* Reloc */
2223 coff_get_reloc_upper_bound, /* _get_reloc_upper_bound */
2224 coff_canonicalize_reloc, /* _cononicalize_reloc */
2225 xcoff64_reloc_type_lookup, /* _bfd_reloc_type_lookup */
2226
2227 /* Write */
2228 coff_set_arch_mach, /* _set_arch_mach */
2229 coff_set_section_contents, /* _set_section_contents */
2230
2231 /* Link */
2232 xcoff64_sizeof_headers, /* _sizeof_headers */
2233 /* _bfd_get_relocated_section_contents */
2234 bfd_generic_get_relocated_section_contents,
2235 bfd_generic_relax_section, /* _bfd_relax_section */
2236 _bfd_xcoff_bfd_link_hash_table_create, /* _bfd_link_hash_table_create */
2237 _bfd_xcoff_bfd_link_add_symbols, /* _bfd_link_add_symbols */
2238 _bfd_xcoff_bfd_final_link, /* _bfd_filnal_link */
2239 _bfd_generic_link_split_section, /* _bfd_link_split_section */
2240 bfd_generic_gc_sections, /* _bfd_gc_sections */
2241 bfd_generic_merge_sections, /* _bfd_merge_sections */
2242
2243 /* Dynamic */
2244 /* _get_dynamic_symtab_upper_bound */
2245 _bfd_xcoff_get_dynamic_symtab_upper_bound,
2246 _bfd_xcoff_canonicalize_dynamic_symtab, /* _cononicalize_dynamic_symtab */
2247 _bfd_xcoff_get_dynamic_reloc_upper_bound,/* _get_dynamic_reloc_upper_bound */
2248 _bfd_xcoff_canonicalize_dynamic_reloc, /* _cononicalize_dynamic_reloc */
2249
2250 /* Opposite endian version, none exists */
2251 NULL,
2252
2253 /* back end data */
2254 (void *) &bfd_xcoff_backend_data,
2255};
14958a43 2256
14958a43 2257
This page took 0.139196 seconds and 4 git commands to generate.