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