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