| 1 | /* BFD back-end for IBM RS/6000 "XCOFF" files. | 
|---|
| 2 | Copyright 1990-1999, 2000, 2001, 2002 | 
|---|
| 3 | Free Software Foundation, Inc. | 
|---|
| 4 | FIXME: Can someone provide a transliteration of this name into ASCII? | 
|---|
| 5 | Using the following chars caused a compiler warning on HIUX (so I replaced | 
|---|
| 6 | them with octal escapes), and isn't useful without an understanding of what | 
|---|
| 7 | character set it is. | 
|---|
| 8 | Written by Metin G. Ozisik, Mimi Ph\373\364ng-Th\345o V\365, | 
|---|
| 9 | and John Gilmore. | 
|---|
| 10 | Archive support from Damon A. Permezel. | 
|---|
| 11 | Contributed by IBM Corporation and Cygnus Support. | 
|---|
| 12 |  | 
|---|
| 13 | This file is part of BFD, the Binary File Descriptor library. | 
|---|
| 14 |  | 
|---|
| 15 | This program is free software; you can redistribute it and/or modify | 
|---|
| 16 | it under the terms of the GNU General Public License as published by | 
|---|
| 17 | the Free Software Foundation; either version 2 of the License, or | 
|---|
| 18 | (at your option) any later version. | 
|---|
| 19 |  | 
|---|
| 20 | This program is distributed in the hope that it will be useful, | 
|---|
| 21 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 23 | GNU General Public License for more details. | 
|---|
| 24 |  | 
|---|
| 25 | You should have received a copy of the GNU General Public License | 
|---|
| 26 | along with this program; if not, write to the Free Software | 
|---|
| 27 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */ | 
|---|
| 28 |  | 
|---|
| 29 | #include "bfd.h" | 
|---|
| 30 | #include "sysdep.h" | 
|---|
| 31 | #include "bfdlink.h" | 
|---|
| 32 | #include "libbfd.h" | 
|---|
| 33 | #include "coff/internal.h" | 
|---|
| 34 | #include "coff/xcoff.h" | 
|---|
| 35 | #include "coff/rs6000.h" | 
|---|
| 36 | #include "libcoff.h" | 
|---|
| 37 | #include "libxcoff.h" | 
|---|
| 38 |  | 
|---|
| 39 | extern bfd_boolean _bfd_xcoff_mkobject | 
|---|
| 40 | PARAMS ((bfd *)); | 
|---|
| 41 | extern bfd_boolean _bfd_xcoff_copy_private_bfd_data | 
|---|
| 42 | PARAMS ((bfd *, bfd *)); | 
|---|
| 43 | extern bfd_boolean _bfd_xcoff_is_local_label_name | 
|---|
| 44 | PARAMS ((bfd *, const char *)); | 
|---|
| 45 | extern reloc_howto_type *_bfd_xcoff_reloc_type_lookup | 
|---|
| 46 | PARAMS ((bfd *, bfd_reloc_code_real_type)); | 
|---|
| 47 | extern bfd_boolean _bfd_xcoff_slurp_armap | 
|---|
| 48 | PARAMS ((bfd *)); | 
|---|
| 49 | extern const bfd_target *_bfd_xcoff_archive_p | 
|---|
| 50 | PARAMS ((bfd *)); | 
|---|
| 51 | extern PTR _bfd_xcoff_read_ar_hdr | 
|---|
| 52 | PARAMS ((bfd *)); | 
|---|
| 53 | extern bfd *_bfd_xcoff_openr_next_archived_file | 
|---|
| 54 | PARAMS ((bfd *, bfd *)); | 
|---|
| 55 | extern int _bfd_xcoff_stat_arch_elt | 
|---|
| 56 | PARAMS ((bfd *, struct stat *)); | 
|---|
| 57 | extern bfd_boolean _bfd_xcoff_write_armap | 
|---|
| 58 | PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int)); | 
|---|
| 59 | extern bfd_boolean _bfd_xcoff_write_archive_contents | 
|---|
| 60 | PARAMS ((bfd *)); | 
|---|
| 61 | extern int _bfd_xcoff_sizeof_headers | 
|---|
| 62 | PARAMS ((bfd *, bfd_boolean)); | 
|---|
| 63 | extern void _bfd_xcoff_swap_sym_in | 
|---|
| 64 | PARAMS ((bfd *, PTR, PTR)); | 
|---|
| 65 | extern unsigned int _bfd_xcoff_swap_sym_out | 
|---|
| 66 | PARAMS ((bfd *, PTR, PTR)); | 
|---|
| 67 | extern void _bfd_xcoff_swap_aux_in | 
|---|
| 68 | PARAMS ((bfd *, PTR, int, int, int, int, PTR)); | 
|---|
| 69 | extern unsigned int _bfd_xcoff_swap_aux_out | 
|---|
| 70 | PARAMS ((bfd *, PTR, int, int, int, int, PTR)); | 
|---|
| 71 | static void xcoff_swap_reloc_in | 
|---|
| 72 | PARAMS ((bfd *, PTR, PTR)); | 
|---|
| 73 | static unsigned int xcoff_swap_reloc_out | 
|---|
| 74 | PARAMS ((bfd *, PTR, PTR)); | 
|---|
| 75 |  | 
|---|
| 76 | /* Forward declare xcoff_rtype2howto for coffcode.h macro.  */ | 
|---|
| 77 | void xcoff_rtype2howto | 
|---|
| 78 | PARAMS ((arelent *, struct internal_reloc *)); | 
|---|
| 79 |  | 
|---|
| 80 | /* coffcode.h needs these to be defined.  */ | 
|---|
| 81 | #define RS6000COFF_C 1 | 
|---|
| 82 |  | 
|---|
| 83 | #define SELECT_RELOC(internal, howto)                                   \ | 
|---|
| 84 | {                                                                     \ | 
|---|
| 85 | internal.r_type = howto->type;                                      \ | 
|---|
| 86 | internal.r_size =                                                   \ | 
|---|
| 87 | ((howto->complain_on_overflow == complain_overflow_signed         \ | 
|---|
| 88 | ? 0x80                                                          \ | 
|---|
| 89 | : 0)                                                            \ | 
|---|
| 90 | | (howto->bitsize - 1));                                         \ | 
|---|
| 91 | } | 
|---|
| 92 |  | 
|---|
| 93 | #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3) | 
|---|
| 94 | #define COFF_LONG_FILENAMES | 
|---|
| 95 | #define NO_COFF_SYMBOLS | 
|---|
| 96 | #define RTYPE2HOWTO(cache_ptr, dst) xcoff_rtype2howto (cache_ptr, dst) | 
|---|
| 97 | #define coff_mkobject _bfd_xcoff_mkobject | 
|---|
| 98 | #define coff_bfd_copy_private_bfd_data _bfd_xcoff_copy_private_bfd_data | 
|---|
| 99 | #define coff_bfd_is_local_label_name _bfd_xcoff_is_local_label_name | 
|---|
| 100 | #define coff_bfd_reloc_type_lookup _bfd_xcoff_reloc_type_lookup | 
|---|
| 101 | #ifdef AIX_CORE | 
|---|
| 102 | extern const bfd_target * rs6000coff_core_p | 
|---|
| 103 | PARAMS ((bfd *abfd)); | 
|---|
| 104 | extern bfd_boolean rs6000coff_core_file_matches_executable_p | 
|---|
| 105 | PARAMS ((bfd *cbfd, bfd *ebfd)); | 
|---|
| 106 | extern char *rs6000coff_core_file_failing_command | 
|---|
| 107 | PARAMS ((bfd *abfd)); | 
|---|
| 108 | extern int rs6000coff_core_file_failing_signal | 
|---|
| 109 | PARAMS ((bfd *abfd)); | 
|---|
| 110 | #define CORE_FILE_P rs6000coff_core_p | 
|---|
| 111 | #define coff_core_file_failing_command \ | 
|---|
| 112 | rs6000coff_core_file_failing_command | 
|---|
| 113 | #define coff_core_file_failing_signal \ | 
|---|
| 114 | rs6000coff_core_file_failing_signal | 
|---|
| 115 | #define coff_core_file_matches_executable_p \ | 
|---|
| 116 | rs6000coff_core_file_matches_executable_p | 
|---|
| 117 | #else | 
|---|
| 118 | #define CORE_FILE_P _bfd_dummy_target | 
|---|
| 119 | #define coff_core_file_failing_command \ | 
|---|
| 120 | _bfd_nocore_core_file_failing_command | 
|---|
| 121 | #define coff_core_file_failing_signal \ | 
|---|
| 122 | _bfd_nocore_core_file_failing_signal | 
|---|
| 123 | #define coff_core_file_matches_executable_p \ | 
|---|
| 124 | _bfd_nocore_core_file_matches_executable_p | 
|---|
| 125 | #endif | 
|---|
| 126 | #define coff_SWAP_sym_in _bfd_xcoff_swap_sym_in | 
|---|
| 127 | #define coff_SWAP_sym_out _bfd_xcoff_swap_sym_out | 
|---|
| 128 | #define coff_SWAP_aux_in _bfd_xcoff_swap_aux_in | 
|---|
| 129 | #define coff_SWAP_aux_out _bfd_xcoff_swap_aux_out | 
|---|
| 130 | #define coff_swap_reloc_in xcoff_swap_reloc_in | 
|---|
| 131 | #define coff_swap_reloc_out xcoff_swap_reloc_out | 
|---|
| 132 | #define NO_COFF_RELOCS | 
|---|
| 133 |  | 
|---|
| 134 | #include "coffcode.h" | 
|---|
| 135 |  | 
|---|
| 136 | /* The main body of code is in coffcode.h.  */ | 
|---|
| 137 |  | 
|---|
| 138 | static const char *normalize_filename | 
|---|
| 139 | PARAMS ((bfd *)); | 
|---|
| 140 | static bfd_boolean xcoff_write_armap_old | 
|---|
| 141 | PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int)); | 
|---|
| 142 | static bfd_boolean xcoff_write_armap_big | 
|---|
| 143 | PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int)); | 
|---|
| 144 | static bfd_boolean xcoff_write_archive_contents_old | 
|---|
| 145 | PARAMS ((bfd *)); | 
|---|
| 146 | static bfd_boolean xcoff_write_archive_contents_big | 
|---|
| 147 | PARAMS ((bfd *)); | 
|---|
| 148 | static void xcoff_swap_ldhdr_in | 
|---|
| 149 | PARAMS ((bfd *, const PTR, struct internal_ldhdr *)); | 
|---|
| 150 | static void xcoff_swap_ldhdr_out | 
|---|
| 151 | PARAMS ((bfd *, const struct internal_ldhdr *, PTR)); | 
|---|
| 152 | static void xcoff_swap_ldsym_in | 
|---|
| 153 | PARAMS ((bfd *, const PTR, struct internal_ldsym *)); | 
|---|
| 154 | static void xcoff_swap_ldsym_out | 
|---|
| 155 | PARAMS ((bfd *, const struct internal_ldsym *, PTR)); | 
|---|
| 156 | static void xcoff_swap_ldrel_in | 
|---|
| 157 | PARAMS ((bfd *, const PTR, struct internal_ldrel *)); | 
|---|
| 158 | static void xcoff_swap_ldrel_out | 
|---|
| 159 | PARAMS ((bfd *, const struct internal_ldrel *, PTR)); | 
|---|
| 160 | static bfd_boolean xcoff_ppc_relocate_section | 
|---|
| 161 | PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, | 
|---|
| 162 | struct internal_reloc *, struct internal_syment *, asection **)); | 
|---|
| 163 | static bfd_boolean _bfd_xcoff_put_ldsymbol_name | 
|---|
| 164 | PARAMS ((bfd *, struct xcoff_loader_info *, struct internal_ldsym *, | 
|---|
| 165 | const char *)); | 
|---|
| 166 | static asection *xcoff_create_csect_from_smclas | 
|---|
| 167 | PARAMS ((bfd *, union internal_auxent *, const char *)); | 
|---|
| 168 | static bfd_boolean xcoff_is_lineno_count_overflow | 
|---|
| 169 | PARAMS ((bfd *, bfd_vma)); | 
|---|
| 170 | static bfd_boolean xcoff_is_reloc_count_overflow | 
|---|
| 171 | PARAMS ((bfd *, bfd_vma)); | 
|---|
| 172 | static bfd_vma xcoff_loader_symbol_offset | 
|---|
| 173 | PARAMS ((bfd *, struct internal_ldhdr *)); | 
|---|
| 174 | static bfd_vma xcoff_loader_reloc_offset | 
|---|
| 175 | PARAMS ((bfd *, struct internal_ldhdr *)); | 
|---|
| 176 | static bfd_boolean xcoff_generate_rtinit | 
|---|
| 177 | PARAMS ((bfd *, const char *, const char *, bfd_boolean)); | 
|---|
| 178 | static bfd_boolean do_pad | 
|---|
| 179 | PARAMS ((bfd *, unsigned int)); | 
|---|
| 180 | static bfd_boolean do_copy | 
|---|
| 181 | PARAMS ((bfd *, bfd *)); | 
|---|
| 182 | static bfd_boolean do_shared_object_padding | 
|---|
| 183 | PARAMS ((bfd *, bfd *, ufile_ptr *, int)); | 
|---|
| 184 |  | 
|---|
| 185 | /* Relocation functions */ | 
|---|
| 186 | static bfd_boolean xcoff_reloc_type_br | 
|---|
| 187 | PARAMS ((XCOFF_RELOC_FUNCTION_ARGS)); | 
|---|
| 188 |  | 
|---|
| 189 | static bfd_boolean xcoff_complain_overflow_dont_func | 
|---|
| 190 | PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS)); | 
|---|
| 191 | static bfd_boolean xcoff_complain_overflow_bitfield_func | 
|---|
| 192 | PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS)); | 
|---|
| 193 | static bfd_boolean xcoff_complain_overflow_signed_func | 
|---|
| 194 | PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS)); | 
|---|
| 195 | static bfd_boolean xcoff_complain_overflow_unsigned_func | 
|---|
| 196 | PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS)); | 
|---|
| 197 |  | 
|---|
| 198 | bfd_boolean (*xcoff_calculate_relocation[XCOFF_MAX_CALCULATE_RELOCATION]) | 
|---|
| 199 | PARAMS ((XCOFF_RELOC_FUNCTION_ARGS)) = | 
|---|
| 200 | { | 
|---|
| 201 | xcoff_reloc_type_pos,  /* R_POS   (0x00) */ | 
|---|
| 202 | xcoff_reloc_type_neg,  /* R_NEG   (0x01) */ | 
|---|
| 203 | xcoff_reloc_type_rel,  /* R_REL   (0x02) */ | 
|---|
| 204 | xcoff_reloc_type_toc,  /* R_TOC   (0x03) */ | 
|---|
| 205 | xcoff_reloc_type_fail, /* R_RTB   (0x04) */ | 
|---|
| 206 | xcoff_reloc_type_toc,  /* R_GL    (0x05) */ | 
|---|
| 207 | xcoff_reloc_type_toc,  /* R_TCL   (0x06) */ | 
|---|
| 208 | xcoff_reloc_type_fail, /*         (0x07) */ | 
|---|
| 209 | xcoff_reloc_type_ba,   /* R_BA    (0x08) */ | 
|---|
| 210 | xcoff_reloc_type_fail, /*         (0x09) */ | 
|---|
| 211 | xcoff_reloc_type_br,   /* R_BR    (0x0a) */ | 
|---|
| 212 | xcoff_reloc_type_fail, /*         (0x0b) */ | 
|---|
| 213 | xcoff_reloc_type_pos,  /* R_RL    (0x0c) */ | 
|---|
| 214 | xcoff_reloc_type_pos,  /* R_RLA   (0x0d) */ | 
|---|
| 215 | xcoff_reloc_type_fail, /*         (0x0e) */ | 
|---|
| 216 | xcoff_reloc_type_noop, /* R_REF   (0x0f) */ | 
|---|
| 217 | xcoff_reloc_type_fail, /*         (0x10) */ | 
|---|
| 218 | xcoff_reloc_type_fail, /*         (0x11) */ | 
|---|
| 219 | xcoff_reloc_type_toc,  /* R_TRL   (0x12) */ | 
|---|
| 220 | xcoff_reloc_type_toc,  /* R_TRLA  (0x13) */ | 
|---|
| 221 | xcoff_reloc_type_fail, /* R_RRTBI (0x14) */ | 
|---|
| 222 | xcoff_reloc_type_fail, /* R_RRTBA (0x15) */ | 
|---|
| 223 | xcoff_reloc_type_ba,   /* R_CAI   (0x16) */ | 
|---|
| 224 | xcoff_reloc_type_crel, /* R_CREL  (0x17) */ | 
|---|
| 225 | xcoff_reloc_type_ba,   /* R_RBA   (0x18) */ | 
|---|
| 226 | xcoff_reloc_type_ba,   /* R_RBAC  (0x19) */ | 
|---|
| 227 | xcoff_reloc_type_br,   /* R_RBR   (0x1a) */ | 
|---|
| 228 | xcoff_reloc_type_ba,   /* R_RBRC  (0x1b) */ | 
|---|
| 229 | }; | 
|---|
| 230 |  | 
|---|
| 231 | bfd_boolean (*xcoff_complain_overflow[XCOFF_MAX_COMPLAIN_OVERFLOW]) | 
|---|
| 232 | PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS)) = | 
|---|
| 233 | { | 
|---|
| 234 | xcoff_complain_overflow_dont_func, | 
|---|
| 235 | xcoff_complain_overflow_bitfield_func, | 
|---|
| 236 | xcoff_complain_overflow_signed_func, | 
|---|
| 237 | xcoff_complain_overflow_unsigned_func, | 
|---|
| 238 | }; | 
|---|
| 239 |  | 
|---|
| 240 | /* We use our own tdata type.  Its first field is the COFF tdata type, | 
|---|
| 241 | so the COFF routines are compatible.  */ | 
|---|
| 242 |  | 
|---|
| 243 | bfd_boolean | 
|---|
| 244 | _bfd_xcoff_mkobject (abfd) | 
|---|
| 245 | bfd *abfd; | 
|---|
| 246 | { | 
|---|
| 247 | coff_data_type *coff; | 
|---|
| 248 | bfd_size_type amt = sizeof (struct xcoff_tdata); | 
|---|
| 249 |  | 
|---|
| 250 | abfd->tdata.xcoff_obj_data = (struct xcoff_tdata *) bfd_zalloc (abfd, amt); | 
|---|
| 251 | if (abfd->tdata.xcoff_obj_data == NULL) | 
|---|
| 252 | return FALSE; | 
|---|
| 253 | coff = coff_data (abfd); | 
|---|
| 254 | coff->symbols = (coff_symbol_type *) NULL; | 
|---|
| 255 | coff->conversion_table = (unsigned int *) NULL; | 
|---|
| 256 | coff->raw_syments = (struct coff_ptr_struct *) NULL; | 
|---|
| 257 | coff->relocbase = 0; | 
|---|
| 258 |  | 
|---|
| 259 | xcoff_data (abfd)->modtype = ('1' << 8) | 'L'; | 
|---|
| 260 |  | 
|---|
| 261 | /* We set cputype to -1 to indicate that it has not been | 
|---|
| 262 | initialized.  */ | 
|---|
| 263 | xcoff_data (abfd)->cputype = -1; | 
|---|
| 264 |  | 
|---|
| 265 | xcoff_data (abfd)->csects = NULL; | 
|---|
| 266 | xcoff_data (abfd)->debug_indices = NULL; | 
|---|
| 267 |  | 
|---|
| 268 | /* text section alignment is different than the default */ | 
|---|
| 269 | bfd_xcoff_text_align_power (abfd) = 2; | 
|---|
| 270 |  | 
|---|
| 271 | return TRUE; | 
|---|
| 272 | } | 
|---|
| 273 |  | 
|---|
| 274 | /* Copy XCOFF data from one BFD to another.  */ | 
|---|
| 275 |  | 
|---|
| 276 | bfd_boolean | 
|---|
| 277 | _bfd_xcoff_copy_private_bfd_data (ibfd, obfd) | 
|---|
| 278 | bfd *ibfd; | 
|---|
| 279 | bfd *obfd; | 
|---|
| 280 | { | 
|---|
| 281 | struct xcoff_tdata *ix, *ox; | 
|---|
| 282 | asection *sec; | 
|---|
| 283 |  | 
|---|
| 284 | if (ibfd->xvec != obfd->xvec) | 
|---|
| 285 | return TRUE; | 
|---|
| 286 | ix = xcoff_data (ibfd); | 
|---|
| 287 | ox = xcoff_data (obfd); | 
|---|
| 288 | ox->full_aouthdr = ix->full_aouthdr; | 
|---|
| 289 | ox->toc = ix->toc; | 
|---|
| 290 | if (ix->sntoc == 0) | 
|---|
| 291 | ox->sntoc = 0; | 
|---|
| 292 | else | 
|---|
| 293 | { | 
|---|
| 294 | sec = coff_section_from_bfd_index (ibfd, ix->sntoc); | 
|---|
| 295 | if (sec == NULL) | 
|---|
| 296 | ox->sntoc = 0; | 
|---|
| 297 | else | 
|---|
| 298 | ox->sntoc = sec->output_section->target_index; | 
|---|
| 299 | } | 
|---|
| 300 | if (ix->snentry == 0) | 
|---|
| 301 | ox->snentry = 0; | 
|---|
| 302 | else | 
|---|
| 303 | { | 
|---|
| 304 | sec = coff_section_from_bfd_index (ibfd, ix->snentry); | 
|---|
| 305 | if (sec == NULL) | 
|---|
| 306 | ox->snentry = 0; | 
|---|
| 307 | else | 
|---|
| 308 | ox->snentry = sec->output_section->target_index; | 
|---|
| 309 | } | 
|---|
| 310 | bfd_xcoff_text_align_power (obfd) = bfd_xcoff_text_align_power (ibfd); | 
|---|
| 311 | bfd_xcoff_data_align_power (obfd) = bfd_xcoff_data_align_power (ibfd); | 
|---|
| 312 | ox->modtype = ix->modtype; | 
|---|
| 313 | ox->cputype = ix->cputype; | 
|---|
| 314 | ox->maxdata = ix->maxdata; | 
|---|
| 315 | ox->maxstack = ix->maxstack; | 
|---|
| 316 | return TRUE; | 
|---|
| 317 | } | 
|---|
| 318 |  | 
|---|
| 319 | /* I don't think XCOFF really has a notion of local labels based on | 
|---|
| 320 | name.  This will mean that ld -X doesn't actually strip anything. | 
|---|
| 321 | The AIX native linker does not have a -X option, and it ignores the | 
|---|
| 322 | -x option.  */ | 
|---|
| 323 |  | 
|---|
| 324 | bfd_boolean | 
|---|
| 325 | _bfd_xcoff_is_local_label_name (abfd, name) | 
|---|
| 326 | bfd *abfd ATTRIBUTE_UNUSED; | 
|---|
| 327 | const char *name ATTRIBUTE_UNUSED; | 
|---|
| 328 | { | 
|---|
| 329 | return FALSE; | 
|---|
| 330 | } | 
|---|
| 331 |  | 
|---|
| 332 |  | 
|---|
| 333 | void | 
|---|
| 334 | _bfd_xcoff_swap_sym_in (abfd, ext1, in1) | 
|---|
| 335 | bfd *abfd; | 
|---|
| 336 | PTR ext1; | 
|---|
| 337 | PTR in1; | 
|---|
| 338 | { | 
|---|
| 339 | SYMENT *ext = (SYMENT *)ext1; | 
|---|
| 340 | struct internal_syment * in = (struct internal_syment *)in1; | 
|---|
| 341 |  | 
|---|
| 342 | if (ext->e.e_name[0] != 0) | 
|---|
| 343 | { | 
|---|
| 344 | memcpy (in->_n._n_name, ext->e.e_name, SYMNMLEN); | 
|---|
| 345 | } | 
|---|
| 346 | else | 
|---|
| 347 | { | 
|---|
| 348 | in->_n._n_n._n_zeroes = 0; | 
|---|
| 349 | in->_n._n_n._n_offset = H_GET_32 (abfd, ext->e.e.e_offset); | 
|---|
| 350 | } | 
|---|
| 351 |  | 
|---|
| 352 | in->n_value = H_GET_32 (abfd, ext->e_value); | 
|---|
| 353 | in->n_scnum = H_GET_16 (abfd, ext->e_scnum); | 
|---|
| 354 | in->n_type = H_GET_16 (abfd, ext->e_type); | 
|---|
| 355 | in->n_sclass = H_GET_8 (abfd, ext->e_sclass); | 
|---|
| 356 | in->n_numaux = H_GET_8 (abfd, ext->e_numaux); | 
|---|
| 357 | } | 
|---|
| 358 |  | 
|---|
| 359 | unsigned int | 
|---|
| 360 | _bfd_xcoff_swap_sym_out (abfd, inp, extp) | 
|---|
| 361 | bfd *abfd; | 
|---|
| 362 | PTR inp; | 
|---|
| 363 | PTR extp; | 
|---|
| 364 | { | 
|---|
| 365 | struct internal_syment *in = (struct internal_syment *)inp; | 
|---|
| 366 | SYMENT *ext =(SYMENT *)extp; | 
|---|
| 367 |  | 
|---|
| 368 | if (in->_n._n_name[0] != 0) | 
|---|
| 369 | { | 
|---|
| 370 | memcpy (ext->e.e_name, in->_n._n_name, SYMNMLEN); | 
|---|
| 371 | } | 
|---|
| 372 | else | 
|---|
| 373 | { | 
|---|
| 374 | H_PUT_32 (abfd, 0, ext->e.e.e_zeroes); | 
|---|
| 375 | H_PUT_32 (abfd, in->_n._n_n._n_offset, ext->e.e.e_offset); | 
|---|
| 376 | } | 
|---|
| 377 |  | 
|---|
| 378 | H_PUT_32 (abfd, in->n_value, ext->e_value); | 
|---|
| 379 | H_PUT_16 (abfd, in->n_scnum, ext->e_scnum); | 
|---|
| 380 | H_PUT_16 (abfd, in->n_type, ext->e_type); | 
|---|
| 381 | H_PUT_8 (abfd, in->n_sclass, ext->e_sclass); | 
|---|
| 382 | H_PUT_8 (abfd, in->n_numaux, ext->e_numaux); | 
|---|
| 383 | return bfd_coff_symesz (abfd); | 
|---|
| 384 | } | 
|---|
| 385 |  | 
|---|
| 386 | void | 
|---|
| 387 | _bfd_xcoff_swap_aux_in (abfd, ext1, type, class, indx, numaux, in1) | 
|---|
| 388 | bfd *abfd; | 
|---|
| 389 | PTR ext1; | 
|---|
| 390 | int type; | 
|---|
| 391 | int class; | 
|---|
| 392 | int indx; | 
|---|
| 393 | int numaux; | 
|---|
| 394 | PTR in1; | 
|---|
| 395 | { | 
|---|
| 396 | AUXENT * ext = (AUXENT *)ext1; | 
|---|
| 397 | union internal_auxent *in = (union internal_auxent *)in1; | 
|---|
| 398 |  | 
|---|
| 399 | switch (class) | 
|---|
| 400 | { | 
|---|
| 401 | case C_FILE: | 
|---|
| 402 | if (ext->x_file.x_fname[0] == 0) | 
|---|
| 403 | { | 
|---|
| 404 | in->x_file.x_n.x_zeroes = 0; | 
|---|
| 405 | in->x_file.x_n.x_offset = | 
|---|
| 406 | H_GET_32 (abfd, ext->x_file.x_n.x_offset); | 
|---|
| 407 | } | 
|---|
| 408 | else | 
|---|
| 409 | { | 
|---|
| 410 | if (numaux > 1) | 
|---|
| 411 | { | 
|---|
| 412 | if (indx == 0) | 
|---|
| 413 | memcpy (in->x_file.x_fname, ext->x_file.x_fname, | 
|---|
| 414 | numaux * sizeof (AUXENT)); | 
|---|
| 415 | } | 
|---|
| 416 | else | 
|---|
| 417 | { | 
|---|
| 418 | memcpy (in->x_file.x_fname, ext->x_file.x_fname, FILNMLEN); | 
|---|
| 419 | } | 
|---|
| 420 | } | 
|---|
| 421 | goto end; | 
|---|
| 422 |  | 
|---|
| 423 | /* RS/6000 "csect" auxents */ | 
|---|
| 424 | case C_EXT: | 
|---|
| 425 | case C_HIDEXT: | 
|---|
| 426 | if (indx + 1 == numaux) | 
|---|
| 427 | { | 
|---|
| 428 | in->x_csect.x_scnlen.l = H_GET_32 (abfd, ext->x_csect.x_scnlen); | 
|---|
| 429 | in->x_csect.x_parmhash = H_GET_32 (abfd, ext->x_csect.x_parmhash); | 
|---|
| 430 | in->x_csect.x_snhash   = H_GET_16 (abfd, ext->x_csect.x_snhash); | 
|---|
| 431 | /* We don't have to hack bitfields in x_smtyp because it's | 
|---|
| 432 | defined by shifts-and-ands, which are equivalent on all | 
|---|
| 433 | byte orders.  */ | 
|---|
| 434 | in->x_csect.x_smtyp    = H_GET_8 (abfd, ext->x_csect.x_smtyp); | 
|---|
| 435 | in->x_csect.x_smclas   = H_GET_8 (abfd, ext->x_csect.x_smclas); | 
|---|
| 436 | in->x_csect.x_stab     = H_GET_32 (abfd, ext->x_csect.x_stab); | 
|---|
| 437 | in->x_csect.x_snstab   = H_GET_16 (abfd, ext->x_csect.x_snstab); | 
|---|
| 438 | goto end; | 
|---|
| 439 | } | 
|---|
| 440 | break; | 
|---|
| 441 |  | 
|---|
| 442 | case C_STAT: | 
|---|
| 443 | case C_LEAFSTAT: | 
|---|
| 444 | case C_HIDDEN: | 
|---|
| 445 | if (type == T_NULL) | 
|---|
| 446 | { | 
|---|
| 447 | in->x_scn.x_scnlen = H_GET_32 (abfd, ext->x_scn.x_scnlen); | 
|---|
| 448 | in->x_scn.x_nreloc = H_GET_16 (abfd, ext->x_scn.x_nreloc); | 
|---|
| 449 | in->x_scn.x_nlinno = H_GET_16 (abfd, ext->x_scn.x_nlinno); | 
|---|
| 450 | /* PE defines some extra fields; we zero them out for | 
|---|
| 451 | safety.  */ | 
|---|
| 452 | in->x_scn.x_checksum = 0; | 
|---|
| 453 | in->x_scn.x_associated = 0; | 
|---|
| 454 | in->x_scn.x_comdat = 0; | 
|---|
| 455 |  | 
|---|
| 456 | goto end; | 
|---|
| 457 | } | 
|---|
| 458 | break; | 
|---|
| 459 | } | 
|---|
| 460 |  | 
|---|
| 461 | in->x_sym.x_tagndx.l = H_GET_32 (abfd, ext->x_sym.x_tagndx); | 
|---|
| 462 | in->x_sym.x_tvndx = H_GET_16 (abfd, ext->x_sym.x_tvndx); | 
|---|
| 463 |  | 
|---|
| 464 | if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class)) | 
|---|
| 465 | { | 
|---|
| 466 | in->x_sym.x_fcnary.x_fcn.x_lnnoptr = | 
|---|
| 467 | H_GET_32 (abfd, ext->x_sym.x_fcnary.x_fcn.x_lnnoptr); | 
|---|
| 468 | in->x_sym.x_fcnary.x_fcn.x_endndx.l = | 
|---|
| 469 | H_GET_32 (abfd, ext->x_sym.x_fcnary.x_fcn.x_endndx); | 
|---|
| 470 | } | 
|---|
| 471 | else | 
|---|
| 472 | { | 
|---|
| 473 | in->x_sym.x_fcnary.x_ary.x_dimen[0] = | 
|---|
| 474 | H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[0]); | 
|---|
| 475 | in->x_sym.x_fcnary.x_ary.x_dimen[1] = | 
|---|
| 476 | H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[1]); | 
|---|
| 477 | in->x_sym.x_fcnary.x_ary.x_dimen[2] = | 
|---|
| 478 | H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[2]); | 
|---|
| 479 | in->x_sym.x_fcnary.x_ary.x_dimen[3] = | 
|---|
| 480 | H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[3]); | 
|---|
| 481 | } | 
|---|
| 482 |  | 
|---|
| 483 | if (ISFCN (type)) | 
|---|
| 484 | { | 
|---|
| 485 | in->x_sym.x_misc.x_fsize = H_GET_32 (abfd, ext->x_sym.x_misc.x_fsize); | 
|---|
| 486 | } | 
|---|
| 487 | else | 
|---|
| 488 | { | 
|---|
| 489 | in->x_sym.x_misc.x_lnsz.x_lnno = | 
|---|
| 490 | H_GET_16 (abfd, ext->x_sym.x_misc.x_lnsz.x_lnno); | 
|---|
| 491 | in->x_sym.x_misc.x_lnsz.x_size = | 
|---|
| 492 | H_GET_16 (abfd, ext->x_sym.x_misc.x_lnsz.x_size); | 
|---|
| 493 | } | 
|---|
| 494 |  | 
|---|
| 495 | end: ; | 
|---|
| 496 | /* The semicolon is because MSVC doesn't like labels at | 
|---|
| 497 | end of block.  */ | 
|---|
| 498 | } | 
|---|
| 499 |  | 
|---|
| 500 |  | 
|---|
| 501 | unsigned int _bfd_xcoff_swap_aux_out | 
|---|
| 502 | PARAMS ((bfd *, PTR, int, int, int, int, PTR)); | 
|---|
| 503 |  | 
|---|
| 504 | unsigned int | 
|---|
| 505 | _bfd_xcoff_swap_aux_out (abfd, inp, type, class, indx, numaux, extp) | 
|---|
| 506 | bfd * abfd; | 
|---|
| 507 | PTR   inp; | 
|---|
| 508 | int   type; | 
|---|
| 509 | int   class; | 
|---|
| 510 | int   indx ATTRIBUTE_UNUSED; | 
|---|
| 511 | int   numaux ATTRIBUTE_UNUSED; | 
|---|
| 512 | PTR   extp; | 
|---|
| 513 | { | 
|---|
| 514 | union internal_auxent *in = (union internal_auxent *)inp; | 
|---|
| 515 | AUXENT *ext = (AUXENT *)extp; | 
|---|
| 516 |  | 
|---|
| 517 | memset ((PTR)ext, 0, bfd_coff_auxesz (abfd)); | 
|---|
| 518 | switch (class) | 
|---|
| 519 | { | 
|---|
| 520 | case C_FILE: | 
|---|
| 521 | if (in->x_file.x_fname[0] == 0) | 
|---|
| 522 | { | 
|---|
| 523 | H_PUT_32 (abfd, 0, ext->x_file.x_n.x_zeroes); | 
|---|
| 524 | H_PUT_32 (abfd, in->x_file.x_n.x_offset, ext->x_file.x_n.x_offset); | 
|---|
| 525 | } | 
|---|
| 526 | else | 
|---|
| 527 | { | 
|---|
| 528 | memcpy (ext->x_file.x_fname, in->x_file.x_fname, FILNMLEN); | 
|---|
| 529 | } | 
|---|
| 530 | goto end; | 
|---|
| 531 |  | 
|---|
| 532 | /* RS/6000 "csect" auxents */ | 
|---|
| 533 | case C_EXT: | 
|---|
| 534 | case C_HIDEXT: | 
|---|
| 535 | if (indx + 1 == numaux) | 
|---|
| 536 | { | 
|---|
| 537 | H_PUT_32 (abfd, in->x_csect.x_scnlen.l, ext->x_csect.x_scnlen); | 
|---|
| 538 | H_PUT_32 (abfd, in->x_csect.x_parmhash, ext->x_csect.x_parmhash); | 
|---|
| 539 | H_PUT_16 (abfd, in->x_csect.x_snhash, ext->x_csect.x_snhash); | 
|---|
| 540 | /* We don't have to hack bitfields in x_smtyp because it's | 
|---|
| 541 | defined by shifts-and-ands, which are equivalent on all | 
|---|
| 542 | byte orders.  */ | 
|---|
| 543 | H_PUT_8 (abfd, in->x_csect.x_smtyp, ext->x_csect.x_smtyp); | 
|---|
| 544 | H_PUT_8 (abfd, in->x_csect.x_smclas, ext->x_csect.x_smclas); | 
|---|
| 545 | H_PUT_32 (abfd, in->x_csect.x_stab, ext->x_csect.x_stab); | 
|---|
| 546 | H_PUT_16 (abfd, in->x_csect.x_snstab, ext->x_csect.x_snstab); | 
|---|
| 547 | goto end; | 
|---|
| 548 | } | 
|---|
| 549 | break; | 
|---|
| 550 |  | 
|---|
| 551 | case C_STAT: | 
|---|
| 552 | case C_LEAFSTAT: | 
|---|
| 553 | case C_HIDDEN: | 
|---|
| 554 | if (type == T_NULL) | 
|---|
| 555 | { | 
|---|
| 556 | H_PUT_32 (abfd, in->x_scn.x_scnlen, ext->x_scn.x_scnlen); | 
|---|
| 557 | H_PUT_16 (abfd, in->x_scn.x_nreloc, ext->x_scn.x_nreloc); | 
|---|
| 558 | H_PUT_16 (abfd, in->x_scn.x_nlinno, ext->x_scn.x_nlinno); | 
|---|
| 559 | goto end; | 
|---|
| 560 | } | 
|---|
| 561 | break; | 
|---|
| 562 | } | 
|---|
| 563 |  | 
|---|
| 564 | H_PUT_32 (abfd, in->x_sym.x_tagndx.l, ext->x_sym.x_tagndx); | 
|---|
| 565 | H_PUT_16 (abfd, in->x_sym.x_tvndx, ext->x_sym.x_tvndx); | 
|---|
| 566 |  | 
|---|
| 567 | if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class)) | 
|---|
| 568 | { | 
|---|
| 569 | H_PUT_32 (abfd, in->x_sym.x_fcnary.x_fcn.x_lnnoptr, | 
|---|
| 570 | ext->x_sym.x_fcnary.x_fcn.x_lnnoptr); | 
|---|
| 571 | H_PUT_32 (abfd, in->x_sym.x_fcnary.x_fcn.x_endndx.l, | 
|---|
| 572 | ext->x_sym.x_fcnary.x_fcn.x_endndx); | 
|---|
| 573 | } | 
|---|
| 574 | else | 
|---|
| 575 | { | 
|---|
| 576 | H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[0], | 
|---|
| 577 | ext->x_sym.x_fcnary.x_ary.x_dimen[0]); | 
|---|
| 578 | H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[1], | 
|---|
| 579 | ext->x_sym.x_fcnary.x_ary.x_dimen[1]); | 
|---|
| 580 | H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[2], | 
|---|
| 581 | ext->x_sym.x_fcnary.x_ary.x_dimen[2]); | 
|---|
| 582 | H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[3], | 
|---|
| 583 | ext->x_sym.x_fcnary.x_ary.x_dimen[3]); | 
|---|
| 584 | } | 
|---|
| 585 |  | 
|---|
| 586 | if (ISFCN (type)) | 
|---|
| 587 | H_PUT_32 (abfd, in->x_sym.x_misc.x_fsize, ext->x_sym.x_misc.x_fsize); | 
|---|
| 588 | else | 
|---|
| 589 | { | 
|---|
| 590 | H_PUT_16 (abfd, in->x_sym.x_misc.x_lnsz.x_lnno, | 
|---|
| 591 | ext->x_sym.x_misc.x_lnsz.x_lnno); | 
|---|
| 592 | H_PUT_16 (abfd, in->x_sym.x_misc.x_lnsz.x_size, | 
|---|
| 593 | ext->x_sym.x_misc.x_lnsz.x_size); | 
|---|
| 594 | } | 
|---|
| 595 |  | 
|---|
| 596 | end: | 
|---|
| 597 | return bfd_coff_auxesz (abfd); | 
|---|
| 598 | } | 
|---|
| 599 |  | 
|---|
| 600 |  | 
|---|
| 601 |  | 
|---|
| 602 |  | 
|---|
| 603 | /* The XCOFF reloc table.  Actually, XCOFF relocations specify the | 
|---|
| 604 | bitsize and whether they are signed or not, along with a | 
|---|
| 605 | conventional type.  This table is for the types, which are used for | 
|---|
| 606 | different algorithms for putting in the reloc.  Many of these | 
|---|
| 607 | relocs need special_function entries, which I have not written.  */ | 
|---|
| 608 |  | 
|---|
| 609 |  | 
|---|
| 610 | reloc_howto_type xcoff_howto_table[] = | 
|---|
| 611 | { | 
|---|
| 612 | /* Standard 32 bit relocation.  */ | 
|---|
| 613 | HOWTO (R_POS,                 /* type */ | 
|---|
| 614 | 0,                     /* rightshift */ | 
|---|
| 615 | 2,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 616 | 32,                    /* bitsize */ | 
|---|
| 617 | FALSE,                 /* pc_relative */ | 
|---|
| 618 | 0,                     /* bitpos */ | 
|---|
| 619 | complain_overflow_bitfield, /* complain_on_overflow */ | 
|---|
| 620 | 0,                     /* special_function */ | 
|---|
| 621 | "R_POS",               /* name */ | 
|---|
| 622 | TRUE,                  /* partial_inplace */ | 
|---|
| 623 | 0xffffffff,            /* src_mask */ | 
|---|
| 624 | 0xffffffff,            /* dst_mask */ | 
|---|
| 625 | FALSE),                /* pcrel_offset */ | 
|---|
| 626 |  | 
|---|
| 627 | /* 32 bit relocation, but store negative value.  */ | 
|---|
| 628 | HOWTO (R_NEG,                 /* type */ | 
|---|
| 629 | 0,                     /* rightshift */ | 
|---|
| 630 | -2,                    /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 631 | 32,                    /* bitsize */ | 
|---|
| 632 | FALSE,                 /* pc_relative */ | 
|---|
| 633 | 0,                     /* bitpos */ | 
|---|
| 634 | complain_overflow_bitfield, /* complain_on_overflow */ | 
|---|
| 635 | 0,                     /* special_function */ | 
|---|
| 636 | "R_NEG",               /* name */ | 
|---|
| 637 | TRUE,                  /* partial_inplace */ | 
|---|
| 638 | 0xffffffff,            /* src_mask */ | 
|---|
| 639 | 0xffffffff,            /* dst_mask */ | 
|---|
| 640 | FALSE),                /* pcrel_offset */ | 
|---|
| 641 |  | 
|---|
| 642 | /* 32 bit PC relative relocation.  */ | 
|---|
| 643 | HOWTO (R_REL,                 /* type */ | 
|---|
| 644 | 0,                     /* rightshift */ | 
|---|
| 645 | 2,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 646 | 32,                    /* bitsize */ | 
|---|
| 647 | TRUE,                  /* pc_relative */ | 
|---|
| 648 | 0,                     /* bitpos */ | 
|---|
| 649 | complain_overflow_signed, /* complain_on_overflow */ | 
|---|
| 650 | 0,                     /* special_function */ | 
|---|
| 651 | "R_REL",               /* name */ | 
|---|
| 652 | TRUE,                  /* partial_inplace */ | 
|---|
| 653 | 0xffffffff,            /* src_mask */ | 
|---|
| 654 | 0xffffffff,            /* dst_mask */ | 
|---|
| 655 | FALSE),                /* pcrel_offset */ | 
|---|
| 656 |  | 
|---|
| 657 | /* 16 bit TOC relative relocation.  */ | 
|---|
| 658 | HOWTO (R_TOC,                 /* type */ | 
|---|
| 659 | 0,                     /* rightshift */ | 
|---|
| 660 | 1,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 661 | 16,                    /* bitsize */ | 
|---|
| 662 | FALSE,                 /* pc_relative */ | 
|---|
| 663 | 0,                     /* bitpos */ | 
|---|
| 664 | complain_overflow_bitfield, /* complain_on_overflow */ | 
|---|
| 665 | 0,                     /* special_function */ | 
|---|
| 666 | "R_TOC",               /* name */ | 
|---|
| 667 | TRUE,                  /* partial_inplace */ | 
|---|
| 668 | 0xffff,                /* src_mask */ | 
|---|
| 669 | 0xffff,                /* dst_mask */ | 
|---|
| 670 | FALSE),                /* pcrel_offset */ | 
|---|
| 671 |  | 
|---|
| 672 | /* I don't really know what this is.  */ | 
|---|
| 673 | HOWTO (R_RTB,                 /* type */ | 
|---|
| 674 | 1,                     /* rightshift */ | 
|---|
| 675 | 2,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 676 | 32,                    /* bitsize */ | 
|---|
| 677 | FALSE,                 /* pc_relative */ | 
|---|
| 678 | 0,                     /* bitpos */ | 
|---|
| 679 | complain_overflow_bitfield, /* complain_on_overflow */ | 
|---|
| 680 | 0,                     /* special_function */ | 
|---|
| 681 | "R_RTB",               /* name */ | 
|---|
| 682 | TRUE,                  /* partial_inplace */ | 
|---|
| 683 | 0xffffffff,            /* src_mask */ | 
|---|
| 684 | 0xffffffff,            /* dst_mask */ | 
|---|
| 685 | FALSE),                /* pcrel_offset */ | 
|---|
| 686 |  | 
|---|
| 687 | /* External TOC relative symbol.  */ | 
|---|
| 688 | HOWTO (R_GL,                  /* type */ | 
|---|
| 689 | 0,                     /* rightshift */ | 
|---|
| 690 | 1,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 691 | 16,                    /* bitsize */ | 
|---|
| 692 | FALSE,                 /* pc_relative */ | 
|---|
| 693 | 0,                     /* bitpos */ | 
|---|
| 694 | complain_overflow_bitfield, /* complain_on_overflow */ | 
|---|
| 695 | 0,                     /* special_function */ | 
|---|
| 696 | "R_GL",                /* name */ | 
|---|
| 697 | TRUE,                  /* partial_inplace */ | 
|---|
| 698 | 0xffff,                /* src_mask */ | 
|---|
| 699 | 0xffff,                /* dst_mask */ | 
|---|
| 700 | FALSE),                /* pcrel_offset */ | 
|---|
| 701 |  | 
|---|
| 702 | /* Local TOC relative symbol.  */ | 
|---|
| 703 | HOWTO (R_TCL,                 /* type */ | 
|---|
| 704 | 0,                     /* rightshift */ | 
|---|
| 705 | 1,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 706 | 16,                    /* bitsize */ | 
|---|
| 707 | FALSE,                 /* pc_relative */ | 
|---|
| 708 | 0,                     /* bitpos */ | 
|---|
| 709 | complain_overflow_bitfield, /* complain_on_overflow */ | 
|---|
| 710 | 0,                     /* special_function */ | 
|---|
| 711 | "R_TCL",               /* name */ | 
|---|
| 712 | TRUE,                  /* partial_inplace */ | 
|---|
| 713 | 0xffff,                /* src_mask */ | 
|---|
| 714 | 0xffff,                /* dst_mask */ | 
|---|
| 715 | FALSE),                /* pcrel_offset */ | 
|---|
| 716 |  | 
|---|
| 717 | EMPTY_HOWTO (7), | 
|---|
| 718 |  | 
|---|
| 719 | /* Non modifiable absolute branch.  */ | 
|---|
| 720 | HOWTO (R_BA,                  /* type */ | 
|---|
| 721 | 0,                     /* rightshift */ | 
|---|
| 722 | 2,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 723 | 26,                    /* bitsize */ | 
|---|
| 724 | FALSE,                 /* pc_relative */ | 
|---|
| 725 | 0,                     /* bitpos */ | 
|---|
| 726 | complain_overflow_bitfield, /* complain_on_overflow */ | 
|---|
| 727 | 0,                     /* special_function */ | 
|---|
| 728 | "R_BA_26",             /* name */ | 
|---|
| 729 | TRUE,                  /* partial_inplace */ | 
|---|
| 730 | 0x03fffffc,            /* src_mask */ | 
|---|
| 731 | 0x03fffffc,            /* dst_mask */ | 
|---|
| 732 | FALSE),                /* pcrel_offset */ | 
|---|
| 733 |  | 
|---|
| 734 | EMPTY_HOWTO (9), | 
|---|
| 735 |  | 
|---|
| 736 | /* Non modifiable relative branch.  */ | 
|---|
| 737 | HOWTO (R_BR,                  /* type */ | 
|---|
| 738 | 0,                     /* rightshift */ | 
|---|
| 739 | 2,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 740 | 26,                    /* bitsize */ | 
|---|
| 741 | TRUE,                  /* pc_relative */ | 
|---|
| 742 | 0,                     /* bitpos */ | 
|---|
| 743 | complain_overflow_signed, /* complain_on_overflow */ | 
|---|
| 744 | 0,                     /* special_function */ | 
|---|
| 745 | "R_BR",                /* name */ | 
|---|
| 746 | TRUE,                  /* partial_inplace */ | 
|---|
| 747 | 0x03fffffc,            /* src_mask */ | 
|---|
| 748 | 0x03fffffc,            /* dst_mask */ | 
|---|
| 749 | FALSE),                /* pcrel_offset */ | 
|---|
| 750 |  | 
|---|
| 751 | EMPTY_HOWTO (0xb), | 
|---|
| 752 |  | 
|---|
| 753 | /* Indirect load.  */ | 
|---|
| 754 | HOWTO (R_RL,                  /* type */ | 
|---|
| 755 | 0,                     /* rightshift */ | 
|---|
| 756 | 1,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 757 | 16,                    /* bitsize */ | 
|---|
| 758 | FALSE,                 /* pc_relative */ | 
|---|
| 759 | 0,                     /* bitpos */ | 
|---|
| 760 | complain_overflow_bitfield, /* complain_on_overflow */ | 
|---|
| 761 | 0,                     /* special_function */ | 
|---|
| 762 | "R_RL",                /* name */ | 
|---|
| 763 | TRUE,                  /* partial_inplace */ | 
|---|
| 764 | 0xffff,                /* src_mask */ | 
|---|
| 765 | 0xffff,                /* dst_mask */ | 
|---|
| 766 | FALSE),                /* pcrel_offset */ | 
|---|
| 767 |  | 
|---|
| 768 | /* Load address.  */ | 
|---|
| 769 | HOWTO (R_RLA,                 /* type */ | 
|---|
| 770 | 0,                     /* rightshift */ | 
|---|
| 771 | 1,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 772 | 16,                    /* bitsize */ | 
|---|
| 773 | FALSE,                 /* pc_relative */ | 
|---|
| 774 | 0,                     /* bitpos */ | 
|---|
| 775 | complain_overflow_bitfield, /* complain_on_overflow */ | 
|---|
| 776 | 0,                     /* special_function */ | 
|---|
| 777 | "R_RLA",               /* name */ | 
|---|
| 778 | TRUE,                  /* partial_inplace */ | 
|---|
| 779 | 0xffff,                /* src_mask */ | 
|---|
| 780 | 0xffff,                /* dst_mask */ | 
|---|
| 781 | FALSE),                /* pcrel_offset */ | 
|---|
| 782 |  | 
|---|
| 783 | EMPTY_HOWTO (0xe), | 
|---|
| 784 |  | 
|---|
| 785 | /* Non-relocating reference.  */ | 
|---|
| 786 | HOWTO (R_REF,                 /* type */ | 
|---|
| 787 | 0,                     /* rightshift */ | 
|---|
| 788 | 2,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 789 | 32,                    /* bitsize */ | 
|---|
| 790 | FALSE,                 /* pc_relative */ | 
|---|
| 791 | 0,                     /* bitpos */ | 
|---|
| 792 | complain_overflow_dont, /* complain_on_overflow */ | 
|---|
| 793 | 0,                     /* special_function */ | 
|---|
| 794 | "R_REF",               /* name */ | 
|---|
| 795 | FALSE,                 /* partial_inplace */ | 
|---|
| 796 | 0,                     /* src_mask */ | 
|---|
| 797 | 0,                     /* dst_mask */ | 
|---|
| 798 | FALSE),                /* pcrel_offset */ | 
|---|
| 799 |  | 
|---|
| 800 | EMPTY_HOWTO (0x10), | 
|---|
| 801 | EMPTY_HOWTO (0x11), | 
|---|
| 802 |  | 
|---|
| 803 | /* TOC relative indirect load.  */ | 
|---|
| 804 | HOWTO (R_TRL,                 /* type */ | 
|---|
| 805 | 0,                     /* rightshift */ | 
|---|
| 806 | 1,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 807 | 16,                    /* bitsize */ | 
|---|
| 808 | FALSE,                 /* pc_relative */ | 
|---|
| 809 | 0,                     /* bitpos */ | 
|---|
| 810 | complain_overflow_bitfield, /* complain_on_overflow */ | 
|---|
| 811 | 0,                     /* special_function */ | 
|---|
| 812 | "R_TRL",               /* name */ | 
|---|
| 813 | TRUE,                  /* partial_inplace */ | 
|---|
| 814 | 0xffff,                /* src_mask */ | 
|---|
| 815 | 0xffff,                /* dst_mask */ | 
|---|
| 816 | FALSE),                /* pcrel_offset */ | 
|---|
| 817 |  | 
|---|
| 818 | /* TOC relative load address.  */ | 
|---|
| 819 | HOWTO (R_TRLA,                /* type */ | 
|---|
| 820 | 0,                     /* rightshift */ | 
|---|
| 821 | 1,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 822 | 16,                    /* bitsize */ | 
|---|
| 823 | FALSE,                 /* pc_relative */ | 
|---|
| 824 | 0,                     /* bitpos */ | 
|---|
| 825 | complain_overflow_bitfield, /* complain_on_overflow */ | 
|---|
| 826 | 0,                     /* special_function */ | 
|---|
| 827 | "R_TRLA",              /* name */ | 
|---|
| 828 | TRUE,                  /* partial_inplace */ | 
|---|
| 829 | 0xffff,                /* src_mask */ | 
|---|
| 830 | 0xffff,                /* dst_mask */ | 
|---|
| 831 | FALSE),                /* pcrel_offset */ | 
|---|
| 832 |  | 
|---|
| 833 | /* Modifiable relative branch.  */ | 
|---|
| 834 | HOWTO (R_RRTBI,                /* type */ | 
|---|
| 835 | 1,                     /* rightshift */ | 
|---|
| 836 | 2,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 837 | 32,                    /* bitsize */ | 
|---|
| 838 | FALSE,                 /* pc_relative */ | 
|---|
| 839 | 0,                     /* bitpos */ | 
|---|
| 840 | complain_overflow_bitfield, /* complain_on_overflow */ | 
|---|
| 841 | 0,                     /* special_function */ | 
|---|
| 842 | "R_RRTBI",             /* name */ | 
|---|
| 843 | TRUE,                  /* partial_inplace */ | 
|---|
| 844 | 0xffffffff,            /* src_mask */ | 
|---|
| 845 | 0xffffffff,            /* dst_mask */ | 
|---|
| 846 | FALSE),                /* pcrel_offset */ | 
|---|
| 847 |  | 
|---|
| 848 | /* Modifiable absolute branch.  */ | 
|---|
| 849 | HOWTO (R_RRTBA,                /* type */ | 
|---|
| 850 | 1,                     /* rightshift */ | 
|---|
| 851 | 2,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 852 | 32,                    /* bitsize */ | 
|---|
| 853 | FALSE,                 /* pc_relative */ | 
|---|
| 854 | 0,                     /* bitpos */ | 
|---|
| 855 | complain_overflow_bitfield, /* complain_on_overflow */ | 
|---|
| 856 | 0,                     /* special_function */ | 
|---|
| 857 | "R_RRTBA",             /* name */ | 
|---|
| 858 | TRUE,                  /* partial_inplace */ | 
|---|
| 859 | 0xffffffff,            /* src_mask */ | 
|---|
| 860 | 0xffffffff,            /* dst_mask */ | 
|---|
| 861 | FALSE),                /* pcrel_offset */ | 
|---|
| 862 |  | 
|---|
| 863 | /* Modifiable call absolute indirect.  */ | 
|---|
| 864 | HOWTO (R_CAI,                 /* type */ | 
|---|
| 865 | 0,                     /* rightshift */ | 
|---|
| 866 | 1,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 867 | 16,                    /* bitsize */ | 
|---|
| 868 | FALSE,                 /* pc_relative */ | 
|---|
| 869 | 0,                     /* bitpos */ | 
|---|
| 870 | complain_overflow_bitfield, /* complain_on_overflow */ | 
|---|
| 871 | 0,                     /* special_function */ | 
|---|
| 872 | "R_CAI",               /* name */ | 
|---|
| 873 | TRUE,                  /* partial_inplace */ | 
|---|
| 874 | 0xffff,                /* src_mask */ | 
|---|
| 875 | 0xffff,                /* dst_mask */ | 
|---|
| 876 | FALSE),                /* pcrel_offset */ | 
|---|
| 877 |  | 
|---|
| 878 | /* Modifiable call relative.  */ | 
|---|
| 879 | HOWTO (R_CREL,                /* type */ | 
|---|
| 880 | 0,                     /* rightshift */ | 
|---|
| 881 | 1,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 882 | 16,                    /* bitsize */ | 
|---|
| 883 | FALSE,                 /* pc_relative */ | 
|---|
| 884 | 0,                     /* bitpos */ | 
|---|
| 885 | complain_overflow_bitfield, /* complain_on_overflow */ | 
|---|
| 886 | 0,                     /* special_function */ | 
|---|
| 887 | "R_CREL",              /* name */ | 
|---|
| 888 | TRUE,                  /* partial_inplace */ | 
|---|
| 889 | 0xffff,                /* src_mask */ | 
|---|
| 890 | 0xffff,                /* dst_mask */ | 
|---|
| 891 | FALSE),                /* pcrel_offset */ | 
|---|
| 892 |  | 
|---|
| 893 | /* Modifiable branch absolute.  */ | 
|---|
| 894 | HOWTO (R_RBA,                 /* type */ | 
|---|
| 895 | 0,                     /* rightshift */ | 
|---|
| 896 | 2,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 897 | 26,                    /* bitsize */ | 
|---|
| 898 | FALSE,                 /* pc_relative */ | 
|---|
| 899 | 0,                     /* bitpos */ | 
|---|
| 900 | complain_overflow_bitfield, /* complain_on_overflow */ | 
|---|
| 901 | 0,                     /* special_function */ | 
|---|
| 902 | "R_RBA",               /* name */ | 
|---|
| 903 | TRUE,                  /* partial_inplace */ | 
|---|
| 904 | 0x03fffffc,            /* src_mask */ | 
|---|
| 905 | 0x03fffffc,            /* dst_mask */ | 
|---|
| 906 | FALSE),                /* pcrel_offset */ | 
|---|
| 907 |  | 
|---|
| 908 | /* Modifiable branch absolute.  */ | 
|---|
| 909 | HOWTO (R_RBAC,                /* type */ | 
|---|
| 910 | 0,                     /* rightshift */ | 
|---|
| 911 | 2,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 912 | 32,                    /* bitsize */ | 
|---|
| 913 | FALSE,                 /* pc_relative */ | 
|---|
| 914 | 0,                     /* bitpos */ | 
|---|
| 915 | complain_overflow_bitfield, /* complain_on_overflow */ | 
|---|
| 916 | 0,                     /* special_function */ | 
|---|
| 917 | "R_RBAC",              /* name */ | 
|---|
| 918 | TRUE,                  /* partial_inplace */ | 
|---|
| 919 | 0xffffffff,            /* src_mask */ | 
|---|
| 920 | 0xffffffff,            /* dst_mask */ | 
|---|
| 921 | FALSE),                /* pcrel_offset */ | 
|---|
| 922 |  | 
|---|
| 923 | /* Modifiable branch relative.  */ | 
|---|
| 924 | HOWTO (R_RBR,                 /* type */ | 
|---|
| 925 | 0,                     /* rightshift */ | 
|---|
| 926 | 2,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 927 | 26,                    /* bitsize */ | 
|---|
| 928 | FALSE,                 /* pc_relative */ | 
|---|
| 929 | 0,                     /* bitpos */ | 
|---|
| 930 | complain_overflow_signed, /* complain_on_overflow */ | 
|---|
| 931 | 0,                     /* special_function */ | 
|---|
| 932 | "R_RBR_26",            /* name */ | 
|---|
| 933 | TRUE,                  /* partial_inplace */ | 
|---|
| 934 | 0x03fffffc,            /* src_mask */ | 
|---|
| 935 | 0x03fffffc,            /* dst_mask */ | 
|---|
| 936 | FALSE),                /* pcrel_offset */ | 
|---|
| 937 |  | 
|---|
| 938 | /* Modifiable branch absolute.  */ | 
|---|
| 939 | HOWTO (R_RBRC,                /* type */ | 
|---|
| 940 | 0,                     /* rightshift */ | 
|---|
| 941 | 1,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 942 | 16,                    /* bitsize */ | 
|---|
| 943 | FALSE,                 /* pc_relative */ | 
|---|
| 944 | 0,                     /* bitpos */ | 
|---|
| 945 | complain_overflow_bitfield, /* complain_on_overflow */ | 
|---|
| 946 | 0,                     /* special_function */ | 
|---|
| 947 | "R_RBRC",              /* name */ | 
|---|
| 948 | TRUE,                  /* partial_inplace */ | 
|---|
| 949 | 0xffff,                /* src_mask */ | 
|---|
| 950 | 0xffff,                /* dst_mask */ | 
|---|
| 951 | FALSE),                /* pcrel_offset */ | 
|---|
| 952 |  | 
|---|
| 953 | /* 16 bit Non modifiable absolute branch.  */ | 
|---|
| 954 | HOWTO (R_BA,                  /* type */ | 
|---|
| 955 | 0,                     /* rightshift */ | 
|---|
| 956 | 1,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 957 | 16,                    /* bitsize */ | 
|---|
| 958 | FALSE,                 /* pc_relative */ | 
|---|
| 959 | 0,                     /* bitpos */ | 
|---|
| 960 | complain_overflow_bitfield, /* complain_on_overflow */ | 
|---|
| 961 | 0,                     /* special_function */ | 
|---|
| 962 | "R_BA_16",             /* name */ | 
|---|
| 963 | TRUE,                  /* partial_inplace */ | 
|---|
| 964 | 0xfffc,                /* src_mask */ | 
|---|
| 965 | 0xfffc,                /* dst_mask */ | 
|---|
| 966 | FALSE),                /* pcrel_offset */ | 
|---|
| 967 |  | 
|---|
| 968 | /* Modifiable branch relative.  */ | 
|---|
| 969 | HOWTO (R_RBR,                 /* type */ | 
|---|
| 970 | 0,                     /* rightshift */ | 
|---|
| 971 | 1,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 972 | 16,                    /* bitsize */ | 
|---|
| 973 | FALSE,                 /* pc_relative */ | 
|---|
| 974 | 0,                     /* bitpos */ | 
|---|
| 975 | complain_overflow_signed, /* complain_on_overflow */ | 
|---|
| 976 | 0,                     /* special_function */ | 
|---|
| 977 | "R_RBR_16",            /* name */ | 
|---|
| 978 | TRUE,                  /* partial_inplace */ | 
|---|
| 979 | 0xffff,                /* src_mask */ | 
|---|
| 980 | 0xffff,                /* dst_mask */ | 
|---|
| 981 | FALSE),                /* pcrel_offset */ | 
|---|
| 982 |  | 
|---|
| 983 | /* Modifiable branch relative.  */ | 
|---|
| 984 | HOWTO (R_RBA,                 /* type */ | 
|---|
| 985 | 0,                     /* rightshift */ | 
|---|
| 986 | 1,                     /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 987 | 16,                    /* bitsize */ | 
|---|
| 988 | FALSE,                 /* pc_relative */ | 
|---|
| 989 | 0,                     /* bitpos */ | 
|---|
| 990 | complain_overflow_signed, /* complain_on_overflow */ | 
|---|
| 991 | 0,                     /* special_function */ | 
|---|
| 992 | "R_RBA_16",            /* name */ | 
|---|
| 993 | TRUE,                  /* partial_inplace */ | 
|---|
| 994 | 0xffff,                /* src_mask */ | 
|---|
| 995 | 0xffff,                /* dst_mask */ | 
|---|
| 996 | FALSE),                /* pcrel_offset */ | 
|---|
| 997 |  | 
|---|
| 998 | }; | 
|---|
| 999 |  | 
|---|
| 1000 | void | 
|---|
| 1001 | xcoff_rtype2howto (relent, internal) | 
|---|
| 1002 | arelent *relent; | 
|---|
| 1003 | struct internal_reloc *internal; | 
|---|
| 1004 | { | 
|---|
| 1005 | if (internal->r_type > R_RBRC) | 
|---|
| 1006 | abort (); | 
|---|
| 1007 |  | 
|---|
| 1008 | /* Default howto layout works most of the time */ | 
|---|
| 1009 | relent->howto = &xcoff_howto_table[internal->r_type]; | 
|---|
| 1010 |  | 
|---|
| 1011 | /* Special case some 16 bit reoloc */ | 
|---|
| 1012 | if (15 == (internal->r_size & 0x1f)) | 
|---|
| 1013 | { | 
|---|
| 1014 | if (R_BA == internal->r_type) | 
|---|
| 1015 | relent->howto = &xcoff_howto_table[0x1c]; | 
|---|
| 1016 | else if (R_RBR == internal->r_type) | 
|---|
| 1017 | relent->howto = &xcoff_howto_table[0x1d]; | 
|---|
| 1018 | else if (R_RBA == internal->r_type) | 
|---|
| 1019 | relent->howto = &xcoff_howto_table[0x1e]; | 
|---|
| 1020 | } | 
|---|
| 1021 |  | 
|---|
| 1022 | /* The r_size field of an XCOFF reloc encodes the bitsize of the | 
|---|
| 1023 | relocation, as well as indicating whether it is signed or not. | 
|---|
| 1024 | Doublecheck that the relocation information gathered from the | 
|---|
| 1025 | type matches this information.  The bitsize is not significant | 
|---|
| 1026 | for R_REF relocs.  */ | 
|---|
| 1027 | if (relent->howto->dst_mask != 0 | 
|---|
| 1028 | && (relent->howto->bitsize | 
|---|
| 1029 | != ((unsigned int) internal->r_size & 0x1f) + 1)) | 
|---|
| 1030 | abort (); | 
|---|
| 1031 | } | 
|---|
| 1032 |  | 
|---|
| 1033 | reloc_howto_type * | 
|---|
| 1034 | _bfd_xcoff_reloc_type_lookup (abfd, code) | 
|---|
| 1035 | bfd *abfd ATTRIBUTE_UNUSED; | 
|---|
| 1036 | bfd_reloc_code_real_type code; | 
|---|
| 1037 | { | 
|---|
| 1038 | switch (code) | 
|---|
| 1039 | { | 
|---|
| 1040 | case BFD_RELOC_PPC_B26: | 
|---|
| 1041 | return &xcoff_howto_table[0xa]; | 
|---|
| 1042 | case BFD_RELOC_PPC_BA16: | 
|---|
| 1043 | return &xcoff_howto_table[0x1c]; | 
|---|
| 1044 | case BFD_RELOC_PPC_BA26: | 
|---|
| 1045 | return &xcoff_howto_table[8]; | 
|---|
| 1046 | case BFD_RELOC_PPC_TOC16: | 
|---|
| 1047 | return &xcoff_howto_table[3]; | 
|---|
| 1048 | case BFD_RELOC_32: | 
|---|
| 1049 | case BFD_RELOC_CTOR: | 
|---|
| 1050 | return &xcoff_howto_table[0]; | 
|---|
| 1051 | default: | 
|---|
| 1052 | return NULL; | 
|---|
| 1053 | } | 
|---|
| 1054 | } | 
|---|
| 1055 |  | 
|---|
| 1056 |  | 
|---|
| 1057 |  | 
|---|
| 1058 | /* XCOFF archive support.  The original version of this code was by | 
|---|
| 1059 | Damon A. Permezel.  It was enhanced to permit cross support, and | 
|---|
| 1060 | writing archive files, by Ian Lance Taylor, Cygnus Support. | 
|---|
| 1061 |  | 
|---|
| 1062 | XCOFF uses its own archive format.  Everything is hooked together | 
|---|
| 1063 | with file offset links, so it is possible to rapidly update an | 
|---|
| 1064 | archive in place.  Of course, we don't do that.  An XCOFF archive | 
|---|
| 1065 | has a real file header, not just an ARMAG string.  The structure of | 
|---|
| 1066 | the file header and of each archive header appear below. | 
|---|
| 1067 |  | 
|---|
| 1068 | An XCOFF archive also has a member table, which is a list of | 
|---|
| 1069 | elements in the archive (you can get that by looking through the | 
|---|
| 1070 | linked list, but you have to read a lot more of the file).  The | 
|---|
| 1071 | member table has a normal archive header with an empty name.  It is | 
|---|
| 1072 | normally (and perhaps must be) the second to last entry in the | 
|---|
| 1073 | archive.  The member table data is almost printable ASCII.  It | 
|---|
| 1074 | starts with a 12 character decimal string which is the number of | 
|---|
| 1075 | entries in the table.  For each entry it has a 12 character decimal | 
|---|
| 1076 | string which is the offset in the archive of that member.  These | 
|---|
| 1077 | entries are followed by a series of null terminated strings which | 
|---|
| 1078 | are the member names for each entry. | 
|---|
| 1079 |  | 
|---|
| 1080 | Finally, an XCOFF archive has a global symbol table, which is what | 
|---|
| 1081 | we call the armap.  The global symbol table has a normal archive | 
|---|
| 1082 | header with an empty name.  It is normally (and perhaps must be) | 
|---|
| 1083 | the last entry in the archive.  The contents start with a four byte | 
|---|
| 1084 | binary number which is the number of entries.  This is followed by | 
|---|
| 1085 | a that many four byte binary numbers; each is the file offset of an | 
|---|
| 1086 | entry in the archive.  These numbers are followed by a series of | 
|---|
| 1087 | null terminated strings, which are symbol names. | 
|---|
| 1088 |  | 
|---|
| 1089 | AIX 4.3 introduced a new archive format which can handle larger | 
|---|
| 1090 | files and also 32- and 64-bit objects in the same archive.  The | 
|---|
| 1091 | things said above remain true except that there is now more than | 
|---|
| 1092 | one global symbol table.  The one is used to index 32-bit objects, | 
|---|
| 1093 | the other for 64-bit objects. | 
|---|
| 1094 |  | 
|---|
| 1095 | The new archives (recognizable by the new ARMAG string) has larger | 
|---|
| 1096 | field lengths so that we cannot really share any code.  Also we have | 
|---|
| 1097 | to take care that we are not generating the new form of archives | 
|---|
| 1098 | on AIX 4.2 or earlier systems.  */ | 
|---|
| 1099 |  | 
|---|
| 1100 | /* XCOFF archives use this as a magic string.  Note that both strings | 
|---|
| 1101 | have the same length.  */ | 
|---|
| 1102 |  | 
|---|
| 1103 | /* Set the magic for archive.  */ | 
|---|
| 1104 |  | 
|---|
| 1105 | bfd_boolean | 
|---|
| 1106 | bfd_xcoff_ar_archive_set_magic (abfd, magic) | 
|---|
| 1107 | bfd *abfd ATTRIBUTE_UNUSED; | 
|---|
| 1108 | char *magic ATTRIBUTE_UNUSED; | 
|---|
| 1109 | { | 
|---|
| 1110 | /* Not supported yet.  */ | 
|---|
| 1111 | return FALSE; | 
|---|
| 1112 | /* bfd_xcoff_archive_set_magic (abfd, magic); */ | 
|---|
| 1113 | } | 
|---|
| 1114 |  | 
|---|
| 1115 | /* Read in the armap of an XCOFF archive.  */ | 
|---|
| 1116 |  | 
|---|
| 1117 | bfd_boolean | 
|---|
| 1118 | _bfd_xcoff_slurp_armap (abfd) | 
|---|
| 1119 | bfd *abfd; | 
|---|
| 1120 | { | 
|---|
| 1121 | file_ptr off; | 
|---|
| 1122 | size_t namlen; | 
|---|
| 1123 | bfd_size_type sz; | 
|---|
| 1124 | bfd_byte *contents, *cend; | 
|---|
| 1125 | bfd_vma c, i; | 
|---|
| 1126 | carsym *arsym; | 
|---|
| 1127 | bfd_byte *p; | 
|---|
| 1128 |  | 
|---|
| 1129 | if (xcoff_ardata (abfd) == NULL) | 
|---|
| 1130 | { | 
|---|
| 1131 | bfd_has_map (abfd) = FALSE; | 
|---|
| 1132 | return TRUE; | 
|---|
| 1133 | } | 
|---|
| 1134 |  | 
|---|
| 1135 | if (! xcoff_big_format_p (abfd)) | 
|---|
| 1136 | { | 
|---|
| 1137 | /* This is for the old format.  */ | 
|---|
| 1138 | struct xcoff_ar_hdr hdr; | 
|---|
| 1139 |  | 
|---|
| 1140 | off = strtol (xcoff_ardata (abfd)->symoff, (char **) NULL, 10); | 
|---|
| 1141 | if (off == 0) | 
|---|
| 1142 | { | 
|---|
| 1143 | bfd_has_map (abfd) = FALSE; | 
|---|
| 1144 | return TRUE; | 
|---|
| 1145 | } | 
|---|
| 1146 |  | 
|---|
| 1147 | if (bfd_seek (abfd, off, SEEK_SET) != 0) | 
|---|
| 1148 | return FALSE; | 
|---|
| 1149 |  | 
|---|
| 1150 | /* The symbol table starts with a normal archive header.  */ | 
|---|
| 1151 | if (bfd_bread ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR, abfd) | 
|---|
| 1152 | != SIZEOF_AR_HDR) | 
|---|
| 1153 | return FALSE; | 
|---|
| 1154 |  | 
|---|
| 1155 | /* Skip the name (normally empty).  */ | 
|---|
| 1156 | namlen = strtol (hdr.namlen, (char **) NULL, 10); | 
|---|
| 1157 | off = ((namlen + 1) & ~ (size_t) 1) + SXCOFFARFMAG; | 
|---|
| 1158 | if (bfd_seek (abfd, off, SEEK_CUR) != 0) | 
|---|
| 1159 | return FALSE; | 
|---|
| 1160 |  | 
|---|
| 1161 | sz = strtol (hdr.size, (char **) NULL, 10); | 
|---|
| 1162 |  | 
|---|
| 1163 | /* Read in the entire symbol table.  */ | 
|---|
| 1164 | contents = (bfd_byte *) bfd_alloc (abfd, sz); | 
|---|
| 1165 | if (contents == NULL) | 
|---|
| 1166 | return FALSE; | 
|---|
| 1167 | if (bfd_bread ((PTR) contents, sz, abfd) != sz) | 
|---|
| 1168 | return FALSE; | 
|---|
| 1169 |  | 
|---|
| 1170 | /* The symbol table starts with a four byte count.  */ | 
|---|
| 1171 | c = H_GET_32 (abfd, contents); | 
|---|
| 1172 |  | 
|---|
| 1173 | if (c * 4 >= sz) | 
|---|
| 1174 | { | 
|---|
| 1175 | bfd_set_error (bfd_error_bad_value); | 
|---|
| 1176 | return FALSE; | 
|---|
| 1177 | } | 
|---|
| 1178 |  | 
|---|
| 1179 | bfd_ardata (abfd)->symdefs = | 
|---|
| 1180 | ((carsym *) bfd_alloc (abfd, c * sizeof (carsym))); | 
|---|
| 1181 | if (bfd_ardata (abfd)->symdefs == NULL) | 
|---|
| 1182 | return FALSE; | 
|---|
| 1183 |  | 
|---|
| 1184 | /* After the count comes a list of four byte file offsets.  */ | 
|---|
| 1185 | for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 4; | 
|---|
| 1186 | i < c; | 
|---|
| 1187 | ++i, ++arsym, p += 4) | 
|---|
| 1188 | arsym->file_offset = H_GET_32 (abfd, p); | 
|---|
| 1189 | } | 
|---|
| 1190 | else | 
|---|
| 1191 | { | 
|---|
| 1192 | /* This is for the new format.  */ | 
|---|
| 1193 | struct xcoff_ar_hdr_big hdr; | 
|---|
| 1194 |  | 
|---|
| 1195 | off = strtol (xcoff_ardata_big (abfd)->symoff, (char **) NULL, 10); | 
|---|
| 1196 | if (off == 0) | 
|---|
| 1197 | { | 
|---|
| 1198 | bfd_has_map (abfd) = FALSE; | 
|---|
| 1199 | return TRUE; | 
|---|
| 1200 | } | 
|---|
| 1201 |  | 
|---|
| 1202 | if (bfd_seek (abfd, off, SEEK_SET) != 0) | 
|---|
| 1203 | return FALSE; | 
|---|
| 1204 |  | 
|---|
| 1205 | /* The symbol table starts with a normal archive header.  */ | 
|---|
| 1206 | if (bfd_bread ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR_BIG, abfd) | 
|---|
| 1207 | != SIZEOF_AR_HDR_BIG) | 
|---|
| 1208 | return FALSE; | 
|---|
| 1209 |  | 
|---|
| 1210 | /* Skip the name (normally empty).  */ | 
|---|
| 1211 | namlen = strtol (hdr.namlen, (char **) NULL, 10); | 
|---|
| 1212 | off = ((namlen + 1) & ~ (size_t) 1) + SXCOFFARFMAG; | 
|---|
| 1213 | if (bfd_seek (abfd, off, SEEK_CUR) != 0) | 
|---|
| 1214 | return FALSE; | 
|---|
| 1215 |  | 
|---|
| 1216 | /* XXX This actually has to be a call to strtoll (at least on 32-bit | 
|---|
| 1217 | machines) since the field width is 20 and there numbers with more | 
|---|
| 1218 | than 32 bits can be represented.  */ | 
|---|
| 1219 | sz = strtol (hdr.size, (char **) NULL, 10); | 
|---|
| 1220 |  | 
|---|
| 1221 | /* Read in the entire symbol table.  */ | 
|---|
| 1222 | contents = (bfd_byte *) bfd_alloc (abfd, sz); | 
|---|
| 1223 | if (contents == NULL) | 
|---|
| 1224 | return FALSE; | 
|---|
| 1225 | if (bfd_bread ((PTR) contents, sz, abfd) != sz) | 
|---|
| 1226 | return FALSE; | 
|---|
| 1227 |  | 
|---|
| 1228 | /* The symbol table starts with an eight byte count.  */ | 
|---|
| 1229 | c = H_GET_64 (abfd, contents); | 
|---|
| 1230 |  | 
|---|
| 1231 | if (c * 8 >= sz) | 
|---|
| 1232 | { | 
|---|
| 1233 | bfd_set_error (bfd_error_bad_value); | 
|---|
| 1234 | return FALSE; | 
|---|
| 1235 | } | 
|---|
| 1236 |  | 
|---|
| 1237 | bfd_ardata (abfd)->symdefs = | 
|---|
| 1238 | ((carsym *) bfd_alloc (abfd, c * sizeof (carsym))); | 
|---|
| 1239 | if (bfd_ardata (abfd)->symdefs == NULL) | 
|---|
| 1240 | return FALSE; | 
|---|
| 1241 |  | 
|---|
| 1242 | /* After the count comes a list of eight byte file offsets.  */ | 
|---|
| 1243 | for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 8; | 
|---|
| 1244 | i < c; | 
|---|
| 1245 | ++i, ++arsym, p += 8) | 
|---|
| 1246 | arsym->file_offset = H_GET_64 (abfd, p); | 
|---|
| 1247 | } | 
|---|
| 1248 |  | 
|---|
| 1249 | /* After the file offsets come null terminated symbol names.  */ | 
|---|
| 1250 | cend = contents + sz; | 
|---|
| 1251 | for (i = 0, arsym = bfd_ardata (abfd)->symdefs; | 
|---|
| 1252 | i < c; | 
|---|
| 1253 | ++i, ++arsym, p += strlen ((char *) p) + 1) | 
|---|
| 1254 | { | 
|---|
| 1255 | if (p >= cend) | 
|---|
| 1256 | { | 
|---|
| 1257 | bfd_set_error (bfd_error_bad_value); | 
|---|
| 1258 | return FALSE; | 
|---|
| 1259 | } | 
|---|
| 1260 | arsym->name = (char *) p; | 
|---|
| 1261 | } | 
|---|
| 1262 |  | 
|---|
| 1263 | bfd_ardata (abfd)->symdef_count = c; | 
|---|
| 1264 | bfd_has_map (abfd) = TRUE; | 
|---|
| 1265 |  | 
|---|
| 1266 | return TRUE; | 
|---|
| 1267 | } | 
|---|
| 1268 |  | 
|---|
| 1269 | /* See if this is an XCOFF archive.  */ | 
|---|
| 1270 |  | 
|---|
| 1271 | const bfd_target * | 
|---|
| 1272 | _bfd_xcoff_archive_p (abfd) | 
|---|
| 1273 | bfd *abfd; | 
|---|
| 1274 | { | 
|---|
| 1275 | struct artdata *tdata_hold; | 
|---|
| 1276 | char magic[SXCOFFARMAG]; | 
|---|
| 1277 | bfd_size_type amt = SXCOFFARMAG; | 
|---|
| 1278 |  | 
|---|
| 1279 | if (bfd_bread ((PTR) magic, amt, abfd) != amt) | 
|---|
| 1280 | { | 
|---|
| 1281 | if (bfd_get_error () != bfd_error_system_call) | 
|---|
| 1282 | bfd_set_error (bfd_error_wrong_format); | 
|---|
| 1283 | return NULL; | 
|---|
| 1284 | } | 
|---|
| 1285 |  | 
|---|
| 1286 | if (strncmp (magic, XCOFFARMAG, SXCOFFARMAG) != 0 | 
|---|
| 1287 | && strncmp (magic, XCOFFARMAGBIG, SXCOFFARMAG) != 0) | 
|---|
| 1288 | { | 
|---|
| 1289 | bfd_set_error (bfd_error_wrong_format); | 
|---|
| 1290 | return NULL; | 
|---|
| 1291 | } | 
|---|
| 1292 |  | 
|---|
| 1293 | tdata_hold = bfd_ardata (abfd); | 
|---|
| 1294 |  | 
|---|
| 1295 | amt = sizeof (struct artdata); | 
|---|
| 1296 | bfd_ardata (abfd) = (struct artdata *) bfd_zalloc (abfd, amt); | 
|---|
| 1297 | if (bfd_ardata (abfd) == (struct artdata *) NULL) | 
|---|
| 1298 | goto error_ret_restore; | 
|---|
| 1299 |  | 
|---|
| 1300 | bfd_ardata (abfd)->cache = NULL; | 
|---|
| 1301 | bfd_ardata (abfd)->archive_head = NULL; | 
|---|
| 1302 | bfd_ardata (abfd)->symdefs = NULL; | 
|---|
| 1303 | bfd_ardata (abfd)->extended_names = NULL; | 
|---|
| 1304 |  | 
|---|
| 1305 | /* Now handle the two formats.  */ | 
|---|
| 1306 | if (magic[1] != 'b') | 
|---|
| 1307 | { | 
|---|
| 1308 | /* This is the old format.  */ | 
|---|
| 1309 | struct xcoff_ar_file_hdr hdr; | 
|---|
| 1310 |  | 
|---|
| 1311 | /* Copy over the magic string.  */ | 
|---|
| 1312 | memcpy (hdr.magic, magic, SXCOFFARMAG); | 
|---|
| 1313 |  | 
|---|
| 1314 | /* Now read the rest of the file header.  */ | 
|---|
| 1315 | amt = SIZEOF_AR_FILE_HDR - SXCOFFARMAG; | 
|---|
| 1316 | if (bfd_bread ((PTR) &hdr.memoff, amt, abfd) != amt) | 
|---|
| 1317 | { | 
|---|
| 1318 | if (bfd_get_error () != bfd_error_system_call) | 
|---|
| 1319 | bfd_set_error (bfd_error_wrong_format); | 
|---|
| 1320 | goto error_ret; | 
|---|
| 1321 | } | 
|---|
| 1322 |  | 
|---|
| 1323 | bfd_ardata (abfd)->first_file_filepos = strtol (hdr.firstmemoff, | 
|---|
| 1324 | (char **) NULL, 10); | 
|---|
| 1325 |  | 
|---|
| 1326 | amt = SIZEOF_AR_FILE_HDR; | 
|---|
| 1327 | bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, amt); | 
|---|
| 1328 | if (bfd_ardata (abfd)->tdata == NULL) | 
|---|
| 1329 | goto error_ret; | 
|---|
| 1330 |  | 
|---|
| 1331 | memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR); | 
|---|
| 1332 | } | 
|---|
| 1333 | else | 
|---|
| 1334 | { | 
|---|
| 1335 | /* This is the new format.  */ | 
|---|
| 1336 | struct xcoff_ar_file_hdr_big hdr; | 
|---|
| 1337 |  | 
|---|
| 1338 | /* Copy over the magic string.  */ | 
|---|
| 1339 | memcpy (hdr.magic, magic, SXCOFFARMAG); | 
|---|
| 1340 |  | 
|---|
| 1341 | /* Now read the rest of the file header.  */ | 
|---|
| 1342 | amt = SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG; | 
|---|
| 1343 | if (bfd_bread ((PTR) &hdr.memoff, amt, abfd) != amt) | 
|---|
| 1344 | { | 
|---|
| 1345 | if (bfd_get_error () != bfd_error_system_call) | 
|---|
| 1346 | bfd_set_error (bfd_error_wrong_format); | 
|---|
| 1347 | goto error_ret; | 
|---|
| 1348 | } | 
|---|
| 1349 |  | 
|---|
| 1350 | bfd_ardata (abfd)->first_file_filepos = bfd_scan_vma (hdr.firstmemoff, | 
|---|
| 1351 | (const char **) 0, | 
|---|
| 1352 | 10); | 
|---|
| 1353 |  | 
|---|
| 1354 | amt = SIZEOF_AR_FILE_HDR_BIG; | 
|---|
| 1355 | bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, amt); | 
|---|
| 1356 | if (bfd_ardata (abfd)->tdata == NULL) | 
|---|
| 1357 | goto error_ret; | 
|---|
| 1358 |  | 
|---|
| 1359 | memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR_BIG); | 
|---|
| 1360 | } | 
|---|
| 1361 |  | 
|---|
| 1362 | if (! _bfd_xcoff_slurp_armap (abfd)) | 
|---|
| 1363 | { | 
|---|
| 1364 | error_ret: | 
|---|
| 1365 | bfd_release (abfd, bfd_ardata (abfd)); | 
|---|
| 1366 | error_ret_restore: | 
|---|
| 1367 | bfd_ardata (abfd) = tdata_hold; | 
|---|
| 1368 | return NULL; | 
|---|
| 1369 | } | 
|---|
| 1370 |  | 
|---|
| 1371 | return abfd->xvec; | 
|---|
| 1372 | } | 
|---|
| 1373 |  | 
|---|
| 1374 | /* Read the archive header in an XCOFF archive.  */ | 
|---|
| 1375 |  | 
|---|
| 1376 | PTR | 
|---|
| 1377 | _bfd_xcoff_read_ar_hdr (abfd) | 
|---|
| 1378 | bfd *abfd; | 
|---|
| 1379 | { | 
|---|
| 1380 | bfd_size_type namlen; | 
|---|
| 1381 | struct areltdata *ret; | 
|---|
| 1382 | bfd_size_type amt = sizeof (struct areltdata); | 
|---|
| 1383 |  | 
|---|
| 1384 | ret = (struct areltdata *) bfd_alloc (abfd, amt); | 
|---|
| 1385 | if (ret == NULL) | 
|---|
| 1386 | return NULL; | 
|---|
| 1387 |  | 
|---|
| 1388 | if (! xcoff_big_format_p (abfd)) | 
|---|
| 1389 | { | 
|---|
| 1390 | struct xcoff_ar_hdr hdr; | 
|---|
| 1391 | struct xcoff_ar_hdr *hdrp; | 
|---|
| 1392 |  | 
|---|
| 1393 | if (bfd_bread ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR, abfd) | 
|---|
| 1394 | != SIZEOF_AR_HDR) | 
|---|
| 1395 | { | 
|---|
| 1396 | free (ret); | 
|---|
| 1397 | return NULL; | 
|---|
| 1398 | } | 
|---|
| 1399 |  | 
|---|
| 1400 | namlen = strtol (hdr.namlen, (char **) NULL, 10); | 
|---|
| 1401 | amt = SIZEOF_AR_HDR + namlen + 1; | 
|---|
| 1402 | hdrp = (struct xcoff_ar_hdr *) bfd_alloc (abfd, amt); | 
|---|
| 1403 | if (hdrp == NULL) | 
|---|
| 1404 | { | 
|---|
| 1405 | free (ret); | 
|---|
| 1406 | return NULL; | 
|---|
| 1407 | } | 
|---|
| 1408 | memcpy (hdrp, &hdr, SIZEOF_AR_HDR); | 
|---|
| 1409 | if (bfd_bread ((char *) hdrp + SIZEOF_AR_HDR, namlen, abfd) != namlen) | 
|---|
| 1410 | { | 
|---|
| 1411 | free (ret); | 
|---|
| 1412 | return NULL; | 
|---|
| 1413 | } | 
|---|
| 1414 | ((char *) hdrp)[SIZEOF_AR_HDR + namlen] = '\0'; | 
|---|
| 1415 |  | 
|---|
| 1416 | ret->arch_header = (char *) hdrp; | 
|---|
| 1417 | ret->parsed_size = strtol (hdr.size, (char **) NULL, 10); | 
|---|
| 1418 | ret->filename = (char *) hdrp + SIZEOF_AR_HDR; | 
|---|
| 1419 | } | 
|---|
| 1420 | else | 
|---|
| 1421 | { | 
|---|
| 1422 | struct xcoff_ar_hdr_big hdr; | 
|---|
| 1423 | struct xcoff_ar_hdr_big *hdrp; | 
|---|
| 1424 |  | 
|---|
| 1425 | if (bfd_bread ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR_BIG, abfd) | 
|---|
| 1426 | != SIZEOF_AR_HDR_BIG) | 
|---|
| 1427 | { | 
|---|
| 1428 | free (ret); | 
|---|
| 1429 | return NULL; | 
|---|
| 1430 | } | 
|---|
| 1431 |  | 
|---|
| 1432 | namlen = strtol (hdr.namlen, (char **) NULL, 10); | 
|---|
| 1433 | amt = SIZEOF_AR_HDR_BIG + namlen + 1; | 
|---|
| 1434 | hdrp = (struct xcoff_ar_hdr_big *) bfd_alloc (abfd, amt); | 
|---|
| 1435 | if (hdrp == NULL) | 
|---|
| 1436 | { | 
|---|
| 1437 | free (ret); | 
|---|
| 1438 | return NULL; | 
|---|
| 1439 | } | 
|---|
| 1440 | memcpy (hdrp, &hdr, SIZEOF_AR_HDR_BIG); | 
|---|
| 1441 | if (bfd_bread ((char *) hdrp + SIZEOF_AR_HDR_BIG, namlen, abfd) != namlen) | 
|---|
| 1442 | { | 
|---|
| 1443 | free (ret); | 
|---|
| 1444 | return NULL; | 
|---|
| 1445 | } | 
|---|
| 1446 | ((char *) hdrp)[SIZEOF_AR_HDR_BIG + namlen] = '\0'; | 
|---|
| 1447 |  | 
|---|
| 1448 | ret->arch_header = (char *) hdrp; | 
|---|
| 1449 | /* XXX This actually has to be a call to strtoll (at least on 32-bit | 
|---|
| 1450 | machines) since the field width is 20 and there numbers with more | 
|---|
| 1451 | than 32 bits can be represented.  */ | 
|---|
| 1452 | ret->parsed_size = strtol (hdr.size, (char **) NULL, 10); | 
|---|
| 1453 | ret->filename = (char *) hdrp + SIZEOF_AR_HDR_BIG; | 
|---|
| 1454 | } | 
|---|
| 1455 |  | 
|---|
| 1456 | /* Skip over the XCOFFARFMAG at the end of the file name.  */ | 
|---|
| 1457 | if (bfd_seek (abfd, (file_ptr) ((namlen & 1) + SXCOFFARFMAG), SEEK_CUR) != 0) | 
|---|
| 1458 | return NULL; | 
|---|
| 1459 |  | 
|---|
| 1460 | return (PTR) ret; | 
|---|
| 1461 | } | 
|---|
| 1462 |  | 
|---|
| 1463 | /* Open the next element in an XCOFF archive.  */ | 
|---|
| 1464 |  | 
|---|
| 1465 | bfd * | 
|---|
| 1466 | _bfd_xcoff_openr_next_archived_file (archive, last_file) | 
|---|
| 1467 | bfd *archive; | 
|---|
| 1468 | bfd *last_file; | 
|---|
| 1469 | { | 
|---|
| 1470 | file_ptr filestart; | 
|---|
| 1471 |  | 
|---|
| 1472 | if (xcoff_ardata (archive) == NULL) | 
|---|
| 1473 | { | 
|---|
| 1474 | bfd_set_error (bfd_error_invalid_operation); | 
|---|
| 1475 | return NULL; | 
|---|
| 1476 | } | 
|---|
| 1477 |  | 
|---|
| 1478 | if (! xcoff_big_format_p (archive)) | 
|---|
| 1479 | { | 
|---|
| 1480 | if (last_file == NULL) | 
|---|
| 1481 | filestart = bfd_ardata (archive)->first_file_filepos; | 
|---|
| 1482 | else | 
|---|
| 1483 | filestart = strtol (arch_xhdr (last_file)->nextoff, (char **) NULL, | 
|---|
| 1484 | 10); | 
|---|
| 1485 |  | 
|---|
| 1486 | if (filestart == 0 | 
|---|
| 1487 | || filestart == strtol (xcoff_ardata (archive)->memoff, | 
|---|
| 1488 | (char **) NULL, 10) | 
|---|
| 1489 | || filestart == strtol (xcoff_ardata (archive)->symoff, | 
|---|
| 1490 | (char **) NULL, 10)) | 
|---|
| 1491 | { | 
|---|
| 1492 | bfd_set_error (bfd_error_no_more_archived_files); | 
|---|
| 1493 | return NULL; | 
|---|
| 1494 | } | 
|---|
| 1495 | } | 
|---|
| 1496 | else | 
|---|
| 1497 | { | 
|---|
| 1498 | if (last_file == NULL) | 
|---|
| 1499 | filestart = bfd_ardata (archive)->first_file_filepos; | 
|---|
| 1500 | else | 
|---|
| 1501 | /* XXX These actually have to be a calls to strtoll (at least | 
|---|
| 1502 | on 32-bit machines) since the fields's width is 20 and | 
|---|
| 1503 | there numbers with more than 32 bits can be represented.  */ | 
|---|
| 1504 | filestart = strtol (arch_xhdr_big (last_file)->nextoff, (char **) NULL, | 
|---|
| 1505 | 10); | 
|---|
| 1506 |  | 
|---|
| 1507 | /* XXX These actually have to be calls to strtoll (at least on 32-bit | 
|---|
| 1508 | machines) since the fields's width is 20 and there numbers with more | 
|---|
| 1509 | than 32 bits can be represented.  */ | 
|---|
| 1510 | if (filestart == 0 | 
|---|
| 1511 | || filestart == strtol (xcoff_ardata_big (archive)->memoff, | 
|---|
| 1512 | (char **) NULL, 10) | 
|---|
| 1513 | || filestart == strtol (xcoff_ardata_big (archive)->symoff, | 
|---|
| 1514 | (char **) NULL, 10)) | 
|---|
| 1515 | { | 
|---|
| 1516 | bfd_set_error (bfd_error_no_more_archived_files); | 
|---|
| 1517 | return NULL; | 
|---|
| 1518 | } | 
|---|
| 1519 | } | 
|---|
| 1520 |  | 
|---|
| 1521 | return _bfd_get_elt_at_filepos (archive, filestart); | 
|---|
| 1522 | } | 
|---|
| 1523 |  | 
|---|
| 1524 | /* Stat an element in an XCOFF archive.  */ | 
|---|
| 1525 |  | 
|---|
| 1526 | int | 
|---|
| 1527 | _bfd_xcoff_stat_arch_elt (abfd, s) | 
|---|
| 1528 | bfd *abfd; | 
|---|
| 1529 | struct stat *s; | 
|---|
| 1530 | { | 
|---|
| 1531 | if (abfd->arelt_data == NULL) | 
|---|
| 1532 | { | 
|---|
| 1533 | bfd_set_error (bfd_error_invalid_operation); | 
|---|
| 1534 | return -1; | 
|---|
| 1535 | } | 
|---|
| 1536 |  | 
|---|
| 1537 | if (! xcoff_big_format_p (abfd->my_archive)) | 
|---|
| 1538 | { | 
|---|
| 1539 | struct xcoff_ar_hdr *hdrp = arch_xhdr (abfd); | 
|---|
| 1540 |  | 
|---|
| 1541 | s->st_mtime = strtol (hdrp->date, (char **) NULL, 10); | 
|---|
| 1542 | s->st_uid = strtol (hdrp->uid, (char **) NULL, 10); | 
|---|
| 1543 | s->st_gid = strtol (hdrp->gid, (char **) NULL, 10); | 
|---|
| 1544 | s->st_mode = strtol (hdrp->mode, (char **) NULL, 8); | 
|---|
| 1545 | s->st_size = arch_eltdata (abfd)->parsed_size; | 
|---|
| 1546 | } | 
|---|
| 1547 | else | 
|---|
| 1548 | { | 
|---|
| 1549 | struct xcoff_ar_hdr_big *hdrp = arch_xhdr_big (abfd); | 
|---|
| 1550 |  | 
|---|
| 1551 | s->st_mtime = strtol (hdrp->date, (char **) NULL, 10); | 
|---|
| 1552 | s->st_uid = strtol (hdrp->uid, (char **) NULL, 10); | 
|---|
| 1553 | s->st_gid = strtol (hdrp->gid, (char **) NULL, 10); | 
|---|
| 1554 | s->st_mode = strtol (hdrp->mode, (char **) NULL, 8); | 
|---|
| 1555 | s->st_size = arch_eltdata (abfd)->parsed_size; | 
|---|
| 1556 | } | 
|---|
| 1557 |  | 
|---|
| 1558 | return 0; | 
|---|
| 1559 | } | 
|---|
| 1560 |  | 
|---|
| 1561 | /* Normalize a file name for inclusion in an archive.  */ | 
|---|
| 1562 |  | 
|---|
| 1563 | static const char * | 
|---|
| 1564 | normalize_filename (abfd) | 
|---|
| 1565 | bfd *abfd; | 
|---|
| 1566 | { | 
|---|
| 1567 | const char *file; | 
|---|
| 1568 | const char *filename; | 
|---|
| 1569 |  | 
|---|
| 1570 | file = bfd_get_filename (abfd); | 
|---|
| 1571 | filename = strrchr (file, '/'); | 
|---|
| 1572 | if (filename != NULL) | 
|---|
| 1573 | filename++; | 
|---|
| 1574 | else | 
|---|
| 1575 | filename = file; | 
|---|
| 1576 | return filename; | 
|---|
| 1577 | } | 
|---|
| 1578 |  | 
|---|
| 1579 | /* Write out an XCOFF armap.  */ | 
|---|
| 1580 |  | 
|---|
| 1581 | /*ARGSUSED*/ | 
|---|
| 1582 | static bfd_boolean | 
|---|
| 1583 | xcoff_write_armap_old (abfd, elength, map, orl_count, stridx) | 
|---|
| 1584 | bfd *abfd; | 
|---|
| 1585 | unsigned int elength ATTRIBUTE_UNUSED; | 
|---|
| 1586 | struct orl *map; | 
|---|
| 1587 | unsigned int orl_count; | 
|---|
| 1588 | int stridx; | 
|---|
| 1589 | { | 
|---|
| 1590 | struct xcoff_ar_hdr hdr; | 
|---|
| 1591 | char *p; | 
|---|
| 1592 | unsigned char buf[4]; | 
|---|
| 1593 | bfd *sub; | 
|---|
| 1594 | file_ptr fileoff; | 
|---|
| 1595 | unsigned int i; | 
|---|
| 1596 |  | 
|---|
| 1597 | memset (&hdr, 0, sizeof hdr); | 
|---|
| 1598 | sprintf (hdr.size, "%ld", (long) (4 + orl_count * 4 + stridx)); | 
|---|
| 1599 | sprintf (hdr.nextoff, "%d", 0); | 
|---|
| 1600 | memcpy (hdr.prevoff, xcoff_ardata (abfd)->memoff, XCOFFARMAG_ELEMENT_SIZE); | 
|---|
| 1601 | sprintf (hdr.date, "%d", 0); | 
|---|
| 1602 | sprintf (hdr.uid, "%d", 0); | 
|---|
| 1603 | sprintf (hdr.gid, "%d", 0); | 
|---|
| 1604 | sprintf (hdr.mode, "%d", 0); | 
|---|
| 1605 | sprintf (hdr.namlen, "%d", 0); | 
|---|
| 1606 |  | 
|---|
| 1607 | /* We need spaces, not null bytes, in the header.  */ | 
|---|
| 1608 | for (p = (char *) &hdr; p < (char *) &hdr + SIZEOF_AR_HDR; p++) | 
|---|
| 1609 | if (*p == '\0') | 
|---|
| 1610 | *p = ' '; | 
|---|
| 1611 |  | 
|---|
| 1612 | if (bfd_bwrite ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR, abfd) | 
|---|
| 1613 | != SIZEOF_AR_HDR | 
|---|
| 1614 | || (bfd_bwrite (XCOFFARFMAG, (bfd_size_type) SXCOFFARFMAG, abfd) | 
|---|
| 1615 | != SXCOFFARFMAG)) | 
|---|
| 1616 | return FALSE; | 
|---|
| 1617 |  | 
|---|
| 1618 | H_PUT_32 (abfd, orl_count, buf); | 
|---|
| 1619 | if (bfd_bwrite (buf, (bfd_size_type) 4, abfd) != 4) | 
|---|
| 1620 | return FALSE; | 
|---|
| 1621 |  | 
|---|
| 1622 | sub = abfd->archive_head; | 
|---|
| 1623 | fileoff = SIZEOF_AR_FILE_HDR; | 
|---|
| 1624 | i = 0; | 
|---|
| 1625 | while (sub != NULL && i < orl_count) | 
|---|
| 1626 | { | 
|---|
| 1627 | size_t namlen; | 
|---|
| 1628 |  | 
|---|
| 1629 | while (map[i].u.abfd == sub) | 
|---|
| 1630 | { | 
|---|
| 1631 | H_PUT_32 (abfd, fileoff, buf); | 
|---|
| 1632 | if (bfd_bwrite (buf, (bfd_size_type) 4, abfd) != 4) | 
|---|
| 1633 | return FALSE; | 
|---|
| 1634 | ++i; | 
|---|
| 1635 | } | 
|---|
| 1636 | namlen = strlen (normalize_filename (sub)); | 
|---|
| 1637 | namlen = (namlen + 1) &~ (size_t) 1; | 
|---|
| 1638 | fileoff += (SIZEOF_AR_HDR | 
|---|
| 1639 | + namlen | 
|---|
| 1640 | + SXCOFFARFMAG | 
|---|
| 1641 | + arelt_size (sub)); | 
|---|
| 1642 | fileoff = (fileoff + 1) &~ 1; | 
|---|
| 1643 | sub = sub->next; | 
|---|
| 1644 | } | 
|---|
| 1645 |  | 
|---|
| 1646 | for (i = 0; i < orl_count; i++) | 
|---|
| 1647 | { | 
|---|
| 1648 | const char *name; | 
|---|
| 1649 | size_t namlen; | 
|---|
| 1650 |  | 
|---|
| 1651 | name = *map[i].name; | 
|---|
| 1652 | namlen = strlen (name); | 
|---|
| 1653 | if (bfd_bwrite (name, (bfd_size_type) (namlen + 1), abfd) != namlen + 1) | 
|---|
| 1654 | return FALSE; | 
|---|
| 1655 | } | 
|---|
| 1656 |  | 
|---|
| 1657 | if ((stridx & 1) != 0) | 
|---|
| 1658 | { | 
|---|
| 1659 | char b; | 
|---|
| 1660 |  | 
|---|
| 1661 | b = '\0'; | 
|---|
| 1662 | if (bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1) | 
|---|
| 1663 | return FALSE; | 
|---|
| 1664 | } | 
|---|
| 1665 |  | 
|---|
| 1666 | return TRUE; | 
|---|
| 1667 | } | 
|---|
| 1668 |  | 
|---|
| 1669 | static char buff20[XCOFFARMAGBIG_ELEMENT_SIZE + 1]; | 
|---|
| 1670 | #define FMT20  "%-20lld" | 
|---|
| 1671 | #define FMT12  "%-12d" | 
|---|
| 1672 | #define FMT12_OCTAL  "%-12o" | 
|---|
| 1673 | #define FMT4  "%-4d" | 
|---|
| 1674 | #define PRINT20(d, v) \ | 
|---|
| 1675 | sprintf (buff20, FMT20, (long long)(v)), \ | 
|---|
| 1676 | memcpy ((void *) (d), buff20, 20) | 
|---|
| 1677 |  | 
|---|
| 1678 | #define PRINT12(d, v) \ | 
|---|
| 1679 | sprintf (buff20, FMT12, (int)(v)), \ | 
|---|
| 1680 | memcpy ((void *) (d), buff20, 12) | 
|---|
| 1681 |  | 
|---|
| 1682 | #define PRINT12_OCTAL(d, v) \ | 
|---|
| 1683 | sprintf (buff20, FMT12_OCTAL, (unsigned int)(v)), \ | 
|---|
| 1684 | memcpy ((void *) (d), buff20, 12) | 
|---|
| 1685 |  | 
|---|
| 1686 | #define PRINT4(d, v) \ | 
|---|
| 1687 | sprintf (buff20, FMT4, (int)(v)), \ | 
|---|
| 1688 | memcpy ((void *) (d), buff20, 4) | 
|---|
| 1689 |  | 
|---|
| 1690 | #define READ20(d, v) \ | 
|---|
| 1691 | buff20[20] = 0, \ | 
|---|
| 1692 | memcpy (buff20, (d), 20), \ | 
|---|
| 1693 | (v) = bfd_scan_vma (buff20, (const char **) NULL, 10) | 
|---|
| 1694 |  | 
|---|
| 1695 | static bfd_boolean | 
|---|
| 1696 | do_pad (abfd, number) | 
|---|
| 1697 | bfd *abfd; | 
|---|
| 1698 | unsigned int number; | 
|---|
| 1699 | { | 
|---|
| 1700 | bfd_byte b = 0; | 
|---|
| 1701 |  | 
|---|
| 1702 | /* Limit pad to <= 4096.  */ | 
|---|
| 1703 | if (number > 4096) | 
|---|
| 1704 | return FALSE; | 
|---|
| 1705 |  | 
|---|
| 1706 | while (number--) | 
|---|
| 1707 | if (bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1) | 
|---|
| 1708 | return FALSE; | 
|---|
| 1709 |  | 
|---|
| 1710 | return TRUE; | 
|---|
| 1711 | } | 
|---|
| 1712 |  | 
|---|
| 1713 | static bfd_boolean | 
|---|
| 1714 | do_copy (out_bfd, in_bfd) | 
|---|
| 1715 | bfd *out_bfd; | 
|---|
| 1716 | bfd *in_bfd; | 
|---|
| 1717 | { | 
|---|
| 1718 | bfd_size_type remaining; | 
|---|
| 1719 | bfd_byte buffer[DEFAULT_BUFFERSIZE]; | 
|---|
| 1720 |  | 
|---|
| 1721 | if (bfd_seek (in_bfd, (file_ptr) 0, SEEK_SET) != 0) | 
|---|
| 1722 | return FALSE; | 
|---|
| 1723 |  | 
|---|
| 1724 | remaining = arelt_size (in_bfd); | 
|---|
| 1725 |  | 
|---|
| 1726 | while (remaining >= DEFAULT_BUFFERSIZE) | 
|---|
| 1727 | { | 
|---|
| 1728 | if (bfd_bread (buffer, DEFAULT_BUFFERSIZE, in_bfd) != DEFAULT_BUFFERSIZE | 
|---|
| 1729 | || bfd_bwrite (buffer, DEFAULT_BUFFERSIZE, out_bfd) != DEFAULT_BUFFERSIZE) | 
|---|
| 1730 | return FALSE; | 
|---|
| 1731 |  | 
|---|
| 1732 | remaining -= DEFAULT_BUFFERSIZE; | 
|---|
| 1733 | } | 
|---|
| 1734 |  | 
|---|
| 1735 | if (remaining) | 
|---|
| 1736 | { | 
|---|
| 1737 | if (bfd_bread (buffer, remaining, in_bfd) != remaining | 
|---|
| 1738 | || bfd_bwrite (buffer, remaining, out_bfd) != remaining) | 
|---|
| 1739 | return FALSE; | 
|---|
| 1740 | } | 
|---|
| 1741 |  | 
|---|
| 1742 | return TRUE; | 
|---|
| 1743 | } | 
|---|
| 1744 |  | 
|---|
| 1745 | static bfd_boolean | 
|---|
| 1746 | do_shared_object_padding (out_bfd, in_bfd, offset, ar_header_size) | 
|---|
| 1747 | bfd *out_bfd; | 
|---|
| 1748 | bfd *in_bfd; | 
|---|
| 1749 | ufile_ptr *offset; | 
|---|
| 1750 | int ar_header_size; | 
|---|
| 1751 | { | 
|---|
| 1752 | if (bfd_check_format (in_bfd, bfd_object) | 
|---|
| 1753 | && bfd_get_flavour (in_bfd) == bfd_target_xcoff_flavour | 
|---|
| 1754 | && (in_bfd->flags & DYNAMIC) != 0) | 
|---|
| 1755 | { | 
|---|
| 1756 | bfd_size_type pad = 0; | 
|---|
| 1757 | int text_align_power; | 
|---|
| 1758 |  | 
|---|
| 1759 | text_align_power = bfd_xcoff_text_align_power (in_bfd); | 
|---|
| 1760 |  | 
|---|
| 1761 | pad = 1 << text_align_power; | 
|---|
| 1762 | pad -= (*offset + ar_header_size) & (pad - 1); | 
|---|
| 1763 |  | 
|---|
| 1764 | if (! do_pad (out_bfd, pad)) | 
|---|
| 1765 | return FALSE; | 
|---|
| 1766 |  | 
|---|
| 1767 | *offset += pad; | 
|---|
| 1768 | } | 
|---|
| 1769 |  | 
|---|
| 1770 | return TRUE; | 
|---|
| 1771 | } | 
|---|
| 1772 |  | 
|---|
| 1773 | static bfd_boolean | 
|---|
| 1774 | xcoff_write_armap_big (abfd, elength, map, orl_count, stridx) | 
|---|
| 1775 | bfd *abfd; | 
|---|
| 1776 | unsigned int elength ATTRIBUTE_UNUSED; | 
|---|
| 1777 | struct orl *map; | 
|---|
| 1778 | unsigned int orl_count; | 
|---|
| 1779 | int stridx; | 
|---|
| 1780 | { | 
|---|
| 1781 | struct xcoff_ar_file_hdr_big *fhdr; | 
|---|
| 1782 | bfd_vma i, sym_32, sym_64, str_32, str_64; | 
|---|
| 1783 | const bfd_arch_info_type *arch_info = NULL; | 
|---|
| 1784 | bfd *current_bfd; | 
|---|
| 1785 | size_t string_length; | 
|---|
| 1786 | ufile_ptr nextoff, prevoff; | 
|---|
| 1787 |  | 
|---|
| 1788 | /* First, we look through the symbols and work out which are | 
|---|
| 1789 | from 32-bit objects and which from 64-bit ones.  */ | 
|---|
| 1790 | sym_32 = sym_64 = str_32 = str_64 = 0; | 
|---|
| 1791 |  | 
|---|
| 1792 | current_bfd = abfd->archive_head; | 
|---|
| 1793 | if (current_bfd != NULL) | 
|---|
| 1794 | arch_info = bfd_get_arch_info (current_bfd); | 
|---|
| 1795 | i = 0; | 
|---|
| 1796 | while (current_bfd != NULL && i < orl_count) | 
|---|
| 1797 | { | 
|---|
| 1798 | while (map[i].u.abfd == current_bfd) | 
|---|
| 1799 | { | 
|---|
| 1800 | string_length = strlen (*map[i].name) + 1; | 
|---|
| 1801 |  | 
|---|
| 1802 | if (arch_info->bits_per_address == 64) | 
|---|
| 1803 | { | 
|---|
| 1804 | sym_64++; | 
|---|
| 1805 | str_64 += string_length; | 
|---|
| 1806 | } | 
|---|
| 1807 | else | 
|---|
| 1808 | { | 
|---|
| 1809 | sym_32++; | 
|---|
| 1810 | str_32 += string_length; | 
|---|
| 1811 | } | 
|---|
| 1812 | i++; | 
|---|
| 1813 | } | 
|---|
| 1814 | current_bfd = current_bfd->next; | 
|---|
| 1815 | if (current_bfd != NULL) | 
|---|
| 1816 | arch_info = bfd_get_arch_info (current_bfd); | 
|---|
| 1817 | } | 
|---|
| 1818 |  | 
|---|
| 1819 | /* A quick sanity check... */ | 
|---|
| 1820 | BFD_ASSERT (sym_64 + sym_32 == orl_count); | 
|---|
| 1821 | /* Explicit cast to int for compiler.  */ | 
|---|
| 1822 | BFD_ASSERT ((int)(str_64 + str_32) == stridx); | 
|---|
| 1823 |  | 
|---|
| 1824 | fhdr = xcoff_ardata_big (abfd); | 
|---|
| 1825 |  | 
|---|
| 1826 | /* xcoff_write_archive_contents_big passes nextoff in symoff. */ | 
|---|
| 1827 | READ20 (fhdr->memoff, prevoff); | 
|---|
| 1828 | READ20 (fhdr->symoff, nextoff); | 
|---|
| 1829 |  | 
|---|
| 1830 | BFD_ASSERT (nextoff == bfd_tell (abfd)); | 
|---|
| 1831 |  | 
|---|
| 1832 | /* Write out the symbol table. | 
|---|
| 1833 | Layout : | 
|---|
| 1834 |  | 
|---|
| 1835 | standard big archive header | 
|---|
| 1836 | 0x0000                   ar_size   [0x14] | 
|---|
| 1837 | 0x0014                   ar_nxtmem [0x14] | 
|---|
| 1838 | 0x0028                   ar_prvmem [0x14] | 
|---|
| 1839 | 0x003C                   ar_date   [0x0C] | 
|---|
| 1840 | 0x0048                   ar_uid    [0x0C] | 
|---|
| 1841 | 0x0054                   ar_gid    [0x0C] | 
|---|
| 1842 | 0x0060                   ar_mod    [0x0C] | 
|---|
| 1843 | 0x006C                   ar_namelen[0x04] | 
|---|
| 1844 | 0x0070                   ar_fmag   [SXCOFFARFMAG] | 
|---|
| 1845 |  | 
|---|
| 1846 | Symbol table | 
|---|
| 1847 | 0x0072                   num_syms  [0x08], binary | 
|---|
| 1848 | 0x0078                   offsets   [0x08 * num_syms], binary | 
|---|
| 1849 | 0x0086 + 0x08 * num_syms names     [??] | 
|---|
| 1850 | ??                       pad to even bytes. | 
|---|
| 1851 | */ | 
|---|
| 1852 |  | 
|---|
| 1853 | if (sym_32) | 
|---|
| 1854 | { | 
|---|
| 1855 | struct xcoff_ar_hdr_big *hdr; | 
|---|
| 1856 | bfd_byte *symbol_table; | 
|---|
| 1857 | bfd_byte *st; | 
|---|
| 1858 | file_ptr fileoff; | 
|---|
| 1859 |  | 
|---|
| 1860 | bfd_vma symbol_table_size = | 
|---|
| 1861 | SIZEOF_AR_HDR_BIG | 
|---|
| 1862 | + SXCOFFARFMAG | 
|---|
| 1863 | + 8 | 
|---|
| 1864 | + 8 * sym_32 | 
|---|
| 1865 | + str_32 + (str_32 & 1); | 
|---|
| 1866 |  | 
|---|
| 1867 | symbol_table = NULL; | 
|---|
| 1868 | symbol_table = (bfd_byte *) bfd_zmalloc (symbol_table_size); | 
|---|
| 1869 | if (symbol_table == NULL) | 
|---|
| 1870 | return FALSE; | 
|---|
| 1871 |  | 
|---|
| 1872 | hdr = (struct xcoff_ar_hdr_big *) symbol_table; | 
|---|
| 1873 |  | 
|---|
| 1874 | PRINT20 (hdr->size, 8 + 8 * sym_32 + str_32 + (str_32 & 1)); | 
|---|
| 1875 |  | 
|---|
| 1876 | if (sym_64) | 
|---|
| 1877 | PRINT20 (hdr->nextoff, nextoff + symbol_table_size); | 
|---|
| 1878 | else | 
|---|
| 1879 | PRINT20 (hdr->nextoff, 0); | 
|---|
| 1880 |  | 
|---|
| 1881 | PRINT20 (hdr->prevoff, prevoff); | 
|---|
| 1882 | PRINT12 (hdr->date, 0); | 
|---|
| 1883 | PRINT12 (hdr->uid, 0); | 
|---|
| 1884 | PRINT12 (hdr->gid, 0); | 
|---|
| 1885 | PRINT12 (hdr->mode, 0); | 
|---|
| 1886 | PRINT4 (hdr->namlen, 0) ; | 
|---|
| 1887 |  | 
|---|
| 1888 | st = symbol_table + SIZEOF_AR_HDR_BIG; | 
|---|
| 1889 | memcpy (st, XCOFFARFMAG, SXCOFFARFMAG); | 
|---|
| 1890 | st += SXCOFFARFMAG; | 
|---|
| 1891 |  | 
|---|
| 1892 | bfd_h_put_64 (abfd, sym_32, st); | 
|---|
| 1893 | st += 8; | 
|---|
| 1894 |  | 
|---|
| 1895 | /* loop over the 32 bit offsets */ | 
|---|
| 1896 | current_bfd = abfd->archive_head; | 
|---|
| 1897 | if (current_bfd != NULL) | 
|---|
| 1898 | arch_info = bfd_get_arch_info (current_bfd); | 
|---|
| 1899 | fileoff = SIZEOF_AR_FILE_HDR_BIG; | 
|---|
| 1900 | i = 0; | 
|---|
| 1901 | while (current_bfd != NULL && i < orl_count) | 
|---|
| 1902 | { | 
|---|
| 1903 | while (map[i].u.abfd == current_bfd) | 
|---|
| 1904 | { | 
|---|
| 1905 | if (arch_info->bits_per_address == 32) | 
|---|
| 1906 | { | 
|---|
| 1907 | bfd_h_put_64 (abfd, fileoff, st); | 
|---|
| 1908 | st += 8; | 
|---|
| 1909 | } | 
|---|
| 1910 | i++; | 
|---|
| 1911 | } | 
|---|
| 1912 | string_length = strlen (normalize_filename (current_bfd)); | 
|---|
| 1913 | string_length += string_length & 1; | 
|---|
| 1914 | fileoff += (SIZEOF_AR_HDR_BIG | 
|---|
| 1915 | + string_length | 
|---|
| 1916 | + SXCOFFARFMAG | 
|---|
| 1917 | + arelt_size (current_bfd)); | 
|---|
| 1918 | fileoff += fileoff & 1; | 
|---|
| 1919 | current_bfd = current_bfd->next; | 
|---|
| 1920 | if (current_bfd != NULL) | 
|---|
| 1921 | arch_info = bfd_get_arch_info (current_bfd); | 
|---|
| 1922 | } | 
|---|
| 1923 |  | 
|---|
| 1924 | /* loop over the 32 bit symbol names */ | 
|---|
| 1925 | current_bfd = abfd->archive_head; | 
|---|
| 1926 | if (current_bfd != NULL) | 
|---|
| 1927 | arch_info = bfd_get_arch_info (current_bfd); | 
|---|
| 1928 | i = 0; | 
|---|
| 1929 | while (current_bfd != NULL && i < orl_count) | 
|---|
| 1930 | { | 
|---|
| 1931 | while (map[i].u.abfd == current_bfd) | 
|---|
| 1932 | { | 
|---|
| 1933 | if (arch_info->bits_per_address == 32) | 
|---|
| 1934 | { | 
|---|
| 1935 | string_length = sprintf (st, "%s", *map[i].name); | 
|---|
| 1936 | st += string_length + 1; | 
|---|
| 1937 | } | 
|---|
| 1938 | i++; | 
|---|
| 1939 | } | 
|---|
| 1940 | current_bfd = current_bfd->next; | 
|---|
| 1941 | if (current_bfd != NULL) | 
|---|
| 1942 | arch_info = bfd_get_arch_info (current_bfd); | 
|---|
| 1943 | } | 
|---|
| 1944 |  | 
|---|
| 1945 | bfd_bwrite (symbol_table, symbol_table_size, abfd); | 
|---|
| 1946 |  | 
|---|
| 1947 | free (symbol_table); | 
|---|
| 1948 | symbol_table = NULL; | 
|---|
| 1949 |  | 
|---|
| 1950 | prevoff = nextoff; | 
|---|
| 1951 | nextoff = nextoff + symbol_table_size; | 
|---|
| 1952 | } | 
|---|
| 1953 | else | 
|---|
| 1954 | PRINT20 (fhdr->symoff, 0); | 
|---|
| 1955 |  | 
|---|
| 1956 | if (sym_64) | 
|---|
| 1957 | { | 
|---|
| 1958 | struct xcoff_ar_hdr_big *hdr; | 
|---|
| 1959 | bfd_byte *symbol_table; | 
|---|
| 1960 | bfd_byte *st; | 
|---|
| 1961 | file_ptr fileoff; | 
|---|
| 1962 |  | 
|---|
| 1963 | bfd_vma symbol_table_size = | 
|---|
| 1964 | SIZEOF_AR_HDR_BIG | 
|---|
| 1965 | + SXCOFFARFMAG | 
|---|
| 1966 | + 8 | 
|---|
| 1967 | + 8 * sym_64 | 
|---|
| 1968 | + str_64 + (str_64 & 1); | 
|---|
| 1969 |  | 
|---|
| 1970 | symbol_table = NULL; | 
|---|
| 1971 | symbol_table = (bfd_byte *) bfd_zmalloc (symbol_table_size); | 
|---|
| 1972 | if (symbol_table == NULL) | 
|---|
| 1973 | return FALSE; | 
|---|
| 1974 |  | 
|---|
| 1975 | hdr = (struct xcoff_ar_hdr_big *) symbol_table; | 
|---|
| 1976 |  | 
|---|
| 1977 | PRINT20 (hdr->size, 8 + 8 * sym_64 + str_64 + (str_64 & 1)); | 
|---|
| 1978 | PRINT20 (hdr->nextoff, 0); | 
|---|
| 1979 | PRINT20 (hdr->prevoff, prevoff); | 
|---|
| 1980 | PRINT12 (hdr->date, 0); | 
|---|
| 1981 | PRINT12 (hdr->uid, 0); | 
|---|
| 1982 | PRINT12 (hdr->gid, 0); | 
|---|
| 1983 | PRINT12 (hdr->mode, 0); | 
|---|
| 1984 | PRINT4 (hdr->namlen, 0); | 
|---|
| 1985 |  | 
|---|
| 1986 | st = symbol_table + SIZEOF_AR_HDR_BIG; | 
|---|
| 1987 | memcpy (st, XCOFFARFMAG, SXCOFFARFMAG); | 
|---|
| 1988 | st += SXCOFFARFMAG; | 
|---|
| 1989 |  | 
|---|
| 1990 | bfd_h_put_64 (abfd, sym_64, st); | 
|---|
| 1991 | st += 8; | 
|---|
| 1992 |  | 
|---|
| 1993 | /* loop over the 64 bit offsets */ | 
|---|
| 1994 | current_bfd = abfd->archive_head; | 
|---|
| 1995 | if (current_bfd != NULL) | 
|---|
| 1996 | arch_info = bfd_get_arch_info (current_bfd); | 
|---|
| 1997 | fileoff = SIZEOF_AR_FILE_HDR_BIG; | 
|---|
| 1998 | i = 0; | 
|---|
| 1999 | while (current_bfd != NULL && i < orl_count) | 
|---|
| 2000 | { | 
|---|
| 2001 | while (map[i].u.abfd == current_bfd) | 
|---|
| 2002 | { | 
|---|
| 2003 | if (arch_info->bits_per_address == 64) | 
|---|
| 2004 | { | 
|---|
| 2005 | bfd_h_put_64 (abfd, fileoff, st); | 
|---|
| 2006 | st += 8; | 
|---|
| 2007 | } | 
|---|
| 2008 | i++; | 
|---|
| 2009 | } | 
|---|
| 2010 | string_length = strlen (normalize_filename (current_bfd)); | 
|---|
| 2011 | string_length += string_length & 1; | 
|---|
| 2012 | fileoff += (SIZEOF_AR_HDR_BIG | 
|---|
| 2013 | + string_length | 
|---|
| 2014 | + SXCOFFARFMAG | 
|---|
| 2015 | + arelt_size (current_bfd)); | 
|---|
| 2016 | fileoff += fileoff & 1; | 
|---|
| 2017 | current_bfd = current_bfd->next; | 
|---|
| 2018 | if (current_bfd != NULL) | 
|---|
| 2019 | arch_info = bfd_get_arch_info (current_bfd); | 
|---|
| 2020 | } | 
|---|
| 2021 |  | 
|---|
| 2022 | /* loop over the 64 bit symbol names */ | 
|---|
| 2023 | current_bfd = abfd->archive_head; | 
|---|
| 2024 | if (current_bfd != NULL) | 
|---|
| 2025 | arch_info = bfd_get_arch_info (current_bfd); | 
|---|
| 2026 | i = 0; | 
|---|
| 2027 | while (current_bfd != NULL && i < orl_count) | 
|---|
| 2028 | { | 
|---|
| 2029 | while (map[i].u.abfd == current_bfd) | 
|---|
| 2030 | { | 
|---|
| 2031 | if (arch_info->bits_per_address == 64) | 
|---|
| 2032 | { | 
|---|
| 2033 | string_length = sprintf (st, "%s", *map[i].name); | 
|---|
| 2034 | st += string_length + 1; | 
|---|
| 2035 | } | 
|---|
| 2036 | i++; | 
|---|
| 2037 | } | 
|---|
| 2038 | current_bfd = current_bfd->next; | 
|---|
| 2039 | if (current_bfd != NULL) | 
|---|
| 2040 | arch_info = bfd_get_arch_info (current_bfd); | 
|---|
| 2041 | } | 
|---|
| 2042 |  | 
|---|
| 2043 | bfd_bwrite (symbol_table, symbol_table_size, abfd); | 
|---|
| 2044 |  | 
|---|
| 2045 | free (symbol_table); | 
|---|
| 2046 | symbol_table = NULL; | 
|---|
| 2047 |  | 
|---|
| 2048 | PRINT20 (fhdr->symoff64, nextoff); | 
|---|
| 2049 | } | 
|---|
| 2050 | else | 
|---|
| 2051 | PRINT20 (fhdr->symoff64, 0); | 
|---|
| 2052 |  | 
|---|
| 2053 | return TRUE; | 
|---|
| 2054 | } | 
|---|
| 2055 |  | 
|---|
| 2056 | bfd_boolean | 
|---|
| 2057 | _bfd_xcoff_write_armap (abfd, elength, map, orl_count, stridx) | 
|---|
| 2058 | bfd *abfd; | 
|---|
| 2059 | unsigned int elength ATTRIBUTE_UNUSED; | 
|---|
| 2060 | struct orl *map; | 
|---|
| 2061 | unsigned int orl_count; | 
|---|
| 2062 | int stridx; | 
|---|
| 2063 | { | 
|---|
| 2064 | if (! xcoff_big_format_p (abfd)) | 
|---|
| 2065 | return xcoff_write_armap_old (abfd, elength, map, orl_count, stridx); | 
|---|
| 2066 | else | 
|---|
| 2067 | return xcoff_write_armap_big (abfd, elength, map, orl_count, stridx); | 
|---|
| 2068 | } | 
|---|
| 2069 |  | 
|---|
| 2070 | /* Write out an XCOFF archive.  We always write an entire archive, | 
|---|
| 2071 | rather than fussing with the freelist and so forth.  */ | 
|---|
| 2072 |  | 
|---|
| 2073 | static bfd_boolean | 
|---|
| 2074 | xcoff_write_archive_contents_old (abfd) | 
|---|
| 2075 | bfd *abfd; | 
|---|
| 2076 | { | 
|---|
| 2077 | struct xcoff_ar_file_hdr fhdr; | 
|---|
| 2078 | bfd_size_type count; | 
|---|
| 2079 | bfd_size_type total_namlen; | 
|---|
| 2080 | file_ptr *offsets; | 
|---|
| 2081 | bfd_boolean makemap; | 
|---|
| 2082 | bfd_boolean hasobjects; | 
|---|
| 2083 | ufile_ptr prevoff, nextoff; | 
|---|
| 2084 | bfd *sub; | 
|---|
| 2085 | size_t i; | 
|---|
| 2086 | struct xcoff_ar_hdr ahdr; | 
|---|
| 2087 | bfd_size_type size; | 
|---|
| 2088 | char *p; | 
|---|
| 2089 | char decbuf[XCOFFARMAG_ELEMENT_SIZE + 1]; | 
|---|
| 2090 |  | 
|---|
| 2091 | memset (&fhdr, 0, sizeof fhdr); | 
|---|
| 2092 | strncpy (fhdr.magic, XCOFFARMAG, SXCOFFARMAG); | 
|---|
| 2093 | sprintf (fhdr.firstmemoff, "%d", SIZEOF_AR_FILE_HDR); | 
|---|
| 2094 | sprintf (fhdr.freeoff, "%d", 0); | 
|---|
| 2095 |  | 
|---|
| 2096 | count = 0; | 
|---|
| 2097 | total_namlen = 0; | 
|---|
| 2098 | for (sub = abfd->archive_head; sub != NULL; sub = sub->next) | 
|---|
| 2099 | { | 
|---|
| 2100 | ++count; | 
|---|
| 2101 | total_namlen += strlen (normalize_filename (sub)) + 1; | 
|---|
| 2102 | } | 
|---|
| 2103 | offsets = (file_ptr *) bfd_alloc (abfd, count * sizeof (file_ptr)); | 
|---|
| 2104 | if (offsets == NULL) | 
|---|
| 2105 | return FALSE; | 
|---|
| 2106 |  | 
|---|
| 2107 | if (bfd_seek (abfd, (file_ptr) SIZEOF_AR_FILE_HDR, SEEK_SET) != 0) | 
|---|
| 2108 | return FALSE; | 
|---|
| 2109 |  | 
|---|
| 2110 | makemap = bfd_has_map (abfd); | 
|---|
| 2111 | hasobjects = FALSE; | 
|---|
| 2112 | prevoff = 0; | 
|---|
| 2113 | nextoff = SIZEOF_AR_FILE_HDR; | 
|---|
| 2114 | for (sub = abfd->archive_head, i = 0; sub != NULL; sub = sub->next, i++) | 
|---|
| 2115 | { | 
|---|
| 2116 | const char *name; | 
|---|
| 2117 | bfd_size_type namlen; | 
|---|
| 2118 | struct xcoff_ar_hdr *ahdrp; | 
|---|
| 2119 | bfd_size_type remaining; | 
|---|
| 2120 |  | 
|---|
| 2121 | if (makemap && ! hasobjects) | 
|---|
| 2122 | { | 
|---|
| 2123 | if (bfd_check_format (sub, bfd_object)) | 
|---|
| 2124 | hasobjects = TRUE; | 
|---|
| 2125 | } | 
|---|
| 2126 |  | 
|---|
| 2127 | name = normalize_filename (sub); | 
|---|
| 2128 | namlen = strlen (name); | 
|---|
| 2129 |  | 
|---|
| 2130 | if (sub->arelt_data != NULL) | 
|---|
| 2131 | ahdrp = arch_xhdr (sub); | 
|---|
| 2132 | else | 
|---|
| 2133 | ahdrp = NULL; | 
|---|
| 2134 |  | 
|---|
| 2135 | if (ahdrp == NULL) | 
|---|
| 2136 | { | 
|---|
| 2137 | struct stat s; | 
|---|
| 2138 |  | 
|---|
| 2139 | memset (&ahdr, 0, sizeof ahdr); | 
|---|
| 2140 | ahdrp = &ahdr; | 
|---|
| 2141 | if (stat (bfd_get_filename (sub), &s) != 0) | 
|---|
| 2142 | { | 
|---|
| 2143 | bfd_set_error (bfd_error_system_call); | 
|---|
| 2144 | return FALSE; | 
|---|
| 2145 | } | 
|---|
| 2146 |  | 
|---|
| 2147 | sprintf (ahdrp->size, "%ld", (long) s.st_size); | 
|---|
| 2148 | sprintf (ahdrp->date, "%ld", (long) s.st_mtime); | 
|---|
| 2149 | sprintf (ahdrp->uid, "%ld", (long) s.st_uid); | 
|---|
| 2150 | sprintf (ahdrp->gid, "%ld", (long) s.st_gid); | 
|---|
| 2151 | sprintf (ahdrp->mode, "%o", (unsigned int) s.st_mode); | 
|---|
| 2152 |  | 
|---|
| 2153 | if (sub->arelt_data == NULL) | 
|---|
| 2154 | { | 
|---|
| 2155 | size = sizeof (struct areltdata); | 
|---|
| 2156 | sub->arelt_data = bfd_alloc (sub, size); | 
|---|
| 2157 | if (sub->arelt_data == NULL) | 
|---|
| 2158 | return FALSE; | 
|---|
| 2159 | } | 
|---|
| 2160 |  | 
|---|
| 2161 | arch_eltdata (sub)->parsed_size = s.st_size; | 
|---|
| 2162 | } | 
|---|
| 2163 |  | 
|---|
| 2164 | sprintf (ahdrp->prevoff, "%ld", (long) prevoff); | 
|---|
| 2165 | sprintf (ahdrp->namlen, "%ld", (long) namlen); | 
|---|
| 2166 |  | 
|---|
| 2167 | /* If the length of the name is odd, we write out the null byte | 
|---|
| 2168 | after the name as well.  */ | 
|---|
| 2169 | namlen = (namlen + 1) &~ (bfd_size_type) 1; | 
|---|
| 2170 |  | 
|---|
| 2171 | remaining = arelt_size (sub); | 
|---|
| 2172 | size = (SIZEOF_AR_HDR | 
|---|
| 2173 | + namlen | 
|---|
| 2174 | + SXCOFFARFMAG | 
|---|
| 2175 | + remaining); | 
|---|
| 2176 |  | 
|---|
| 2177 | BFD_ASSERT (nextoff == bfd_tell (abfd)); | 
|---|
| 2178 |  | 
|---|
| 2179 | offsets[i] = nextoff; | 
|---|
| 2180 |  | 
|---|
| 2181 | prevoff = nextoff; | 
|---|
| 2182 | nextoff += size + (size & 1); | 
|---|
| 2183 |  | 
|---|
| 2184 | sprintf (ahdrp->nextoff, "%ld", (long) nextoff); | 
|---|
| 2185 |  | 
|---|
| 2186 | /* We need spaces, not null bytes, in the header.  */ | 
|---|
| 2187 | for (p = (char *) ahdrp; p < (char *) ahdrp + SIZEOF_AR_HDR; p++) | 
|---|
| 2188 | if (*p == '\0') | 
|---|
| 2189 | *p = ' '; | 
|---|
| 2190 |  | 
|---|
| 2191 | if ((bfd_bwrite ((PTR) ahdrp, (bfd_size_type) SIZEOF_AR_HDR, abfd) | 
|---|
| 2192 | != SIZEOF_AR_HDR) | 
|---|
| 2193 | || bfd_bwrite ((PTR) name, namlen, abfd) != namlen | 
|---|
| 2194 | || bfd_bwrite ((PTR) XCOFFARFMAG, (bfd_size_type) SXCOFFARFMAG, | 
|---|
| 2195 | abfd) != SXCOFFARFMAG) | 
|---|
| 2196 | return FALSE; | 
|---|
| 2197 |  | 
|---|
| 2198 | if (bfd_seek (sub, (file_ptr) 0, SEEK_SET) != 0) | 
|---|
| 2199 | return FALSE; | 
|---|
| 2200 |  | 
|---|
| 2201 | if (! do_copy (abfd, sub)) | 
|---|
| 2202 | return FALSE; | 
|---|
| 2203 |  | 
|---|
| 2204 | if (! do_pad (abfd, size & 1)) | 
|---|
| 2205 | return FALSE; | 
|---|
| 2206 | } | 
|---|
| 2207 |  | 
|---|
| 2208 | sprintf (fhdr.lastmemoff, "%ld", (long) prevoff); | 
|---|
| 2209 |  | 
|---|
| 2210 | /* Write out the member table.  */ | 
|---|
| 2211 |  | 
|---|
| 2212 | BFD_ASSERT (nextoff == bfd_tell (abfd)); | 
|---|
| 2213 | sprintf (fhdr.memoff, "%ld", (long) nextoff); | 
|---|
| 2214 |  | 
|---|
| 2215 | memset (&ahdr, 0, sizeof ahdr); | 
|---|
| 2216 | sprintf (ahdr.size, "%ld", (long) (XCOFFARMAG_ELEMENT_SIZE | 
|---|
| 2217 | + count * XCOFFARMAG_ELEMENT_SIZE | 
|---|
| 2218 | + total_namlen)); | 
|---|
| 2219 | sprintf (ahdr.prevoff, "%ld", (long) prevoff); | 
|---|
| 2220 | sprintf (ahdr.date, "%d", 0); | 
|---|
| 2221 | sprintf (ahdr.uid, "%d", 0); | 
|---|
| 2222 | sprintf (ahdr.gid, "%d", 0); | 
|---|
| 2223 | sprintf (ahdr.mode, "%d", 0); | 
|---|
| 2224 | sprintf (ahdr.namlen, "%d", 0); | 
|---|
| 2225 |  | 
|---|
| 2226 | size = (SIZEOF_AR_HDR | 
|---|
| 2227 | + XCOFFARMAG_ELEMENT_SIZE | 
|---|
| 2228 | + count * XCOFFARMAG_ELEMENT_SIZE | 
|---|
| 2229 | + total_namlen | 
|---|
| 2230 | + SXCOFFARFMAG); | 
|---|
| 2231 |  | 
|---|
| 2232 | prevoff = nextoff; | 
|---|
| 2233 | nextoff += size + (size & 1); | 
|---|
| 2234 |  | 
|---|
| 2235 | if (makemap && hasobjects) | 
|---|
| 2236 | sprintf (ahdr.nextoff, "%ld", (long) nextoff); | 
|---|
| 2237 | else | 
|---|
| 2238 | sprintf (ahdr.nextoff, "%d", 0); | 
|---|
| 2239 |  | 
|---|
| 2240 | /* We need spaces, not null bytes, in the header.  */ | 
|---|
| 2241 | for (p = (char *) &ahdr; p < (char *) &ahdr + SIZEOF_AR_HDR; p++) | 
|---|
| 2242 | if (*p == '\0') | 
|---|
| 2243 | *p = ' '; | 
|---|
| 2244 |  | 
|---|
| 2245 | if ((bfd_bwrite ((PTR) &ahdr, (bfd_size_type) SIZEOF_AR_HDR, abfd) | 
|---|
| 2246 | != SIZEOF_AR_HDR) | 
|---|
| 2247 | || (bfd_bwrite ((PTR) XCOFFARFMAG, (bfd_size_type) SXCOFFARFMAG, abfd) | 
|---|
| 2248 | != SXCOFFARFMAG)) | 
|---|
| 2249 | return FALSE; | 
|---|
| 2250 |  | 
|---|
| 2251 | sprintf (decbuf, "%-12ld", (long) count); | 
|---|
| 2252 | if (bfd_bwrite ((PTR) decbuf, (bfd_size_type) XCOFFARMAG_ELEMENT_SIZE, abfd) | 
|---|
| 2253 | != XCOFFARMAG_ELEMENT_SIZE) | 
|---|
| 2254 | return FALSE; | 
|---|
| 2255 | for (i = 0; i < (size_t) count; i++) | 
|---|
| 2256 | { | 
|---|
| 2257 | sprintf (decbuf, "%-12ld", (long) offsets[i]); | 
|---|
| 2258 | if (bfd_bwrite ((PTR) decbuf, (bfd_size_type) XCOFFARMAG_ELEMENT_SIZE, | 
|---|
| 2259 | abfd) != XCOFFARMAG_ELEMENT_SIZE) | 
|---|
| 2260 | return FALSE; | 
|---|
| 2261 | } | 
|---|
| 2262 | for (sub = abfd->archive_head; sub != NULL; sub = sub->next) | 
|---|
| 2263 | { | 
|---|
| 2264 | const char *name; | 
|---|
| 2265 | bfd_size_type namlen; | 
|---|
| 2266 |  | 
|---|
| 2267 | name = normalize_filename (sub); | 
|---|
| 2268 | namlen = strlen (name); | 
|---|
| 2269 | if (bfd_bwrite ((PTR) name, namlen + 1, abfd) != namlen + 1) | 
|---|
| 2270 | return FALSE; | 
|---|
| 2271 | } | 
|---|
| 2272 |  | 
|---|
| 2273 | if (! do_pad (abfd, size & 1)) | 
|---|
| 2274 | return FALSE; | 
|---|
| 2275 |  | 
|---|
| 2276 | /* Write out the armap, if appropriate.  */ | 
|---|
| 2277 | if (! makemap || ! hasobjects) | 
|---|
| 2278 | sprintf (fhdr.symoff, "%d", 0); | 
|---|
| 2279 | else | 
|---|
| 2280 | { | 
|---|
| 2281 | BFD_ASSERT (nextoff == bfd_tell (abfd)); | 
|---|
| 2282 | sprintf (fhdr.symoff, "%ld", (long) nextoff); | 
|---|
| 2283 | bfd_ardata (abfd)->tdata = (PTR) &fhdr; | 
|---|
| 2284 | if (! _bfd_compute_and_write_armap (abfd, 0)) | 
|---|
| 2285 | return FALSE; | 
|---|
| 2286 | } | 
|---|
| 2287 |  | 
|---|
| 2288 | /* Write out the archive file header.  */ | 
|---|
| 2289 |  | 
|---|
| 2290 | /* We need spaces, not null bytes, in the header.  */ | 
|---|
| 2291 | for (p = (char *) &fhdr; p < (char *) &fhdr + SIZEOF_AR_FILE_HDR; p++) | 
|---|
| 2292 | if (*p == '\0') | 
|---|
| 2293 | *p = ' '; | 
|---|
| 2294 |  | 
|---|
| 2295 | if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0 | 
|---|
| 2296 | || (bfd_bwrite ((PTR) &fhdr, (bfd_size_type) SIZEOF_AR_FILE_HDR, abfd) | 
|---|
| 2297 | != SIZEOF_AR_FILE_HDR)) | 
|---|
| 2298 | return FALSE; | 
|---|
| 2299 |  | 
|---|
| 2300 | return TRUE; | 
|---|
| 2301 | } | 
|---|
| 2302 |  | 
|---|
| 2303 | static bfd_boolean | 
|---|
| 2304 | xcoff_write_archive_contents_big (abfd) | 
|---|
| 2305 | bfd *abfd; | 
|---|
| 2306 | { | 
|---|
| 2307 | struct xcoff_ar_file_hdr_big fhdr; | 
|---|
| 2308 | bfd_size_type count; | 
|---|
| 2309 | bfd_size_type total_namlen; | 
|---|
| 2310 | file_ptr *offsets; | 
|---|
| 2311 | bfd_boolean makemap; | 
|---|
| 2312 | bfd_boolean hasobjects; | 
|---|
| 2313 | ufile_ptr prevoff, nextoff; | 
|---|
| 2314 | bfd *current_bfd; | 
|---|
| 2315 | size_t i; | 
|---|
| 2316 | struct xcoff_ar_hdr_big *hdr, ahdr; | 
|---|
| 2317 | bfd_size_type size; | 
|---|
| 2318 | bfd_byte *member_table, *mt; | 
|---|
| 2319 | bfd_vma member_table_size; | 
|---|
| 2320 |  | 
|---|
| 2321 | memset (&fhdr, 0, SIZEOF_AR_FILE_HDR_BIG); | 
|---|
| 2322 | memcpy (fhdr.magic, XCOFFARMAGBIG, SXCOFFARMAG); | 
|---|
| 2323 |  | 
|---|
| 2324 | if (bfd_seek (abfd, (file_ptr) SIZEOF_AR_FILE_HDR_BIG, SEEK_SET) != 0) | 
|---|
| 2325 | return FALSE; | 
|---|
| 2326 |  | 
|---|
| 2327 | /* Calculate count and total_namlen.  */ | 
|---|
| 2328 | makemap = bfd_has_map (abfd); | 
|---|
| 2329 | hasobjects = FALSE; | 
|---|
| 2330 | for (current_bfd = abfd->archive_head, count = 0, total_namlen = 0; | 
|---|
| 2331 | current_bfd != NULL; | 
|---|
| 2332 | current_bfd = current_bfd->next, count++) | 
|---|
| 2333 | { | 
|---|
| 2334 | total_namlen += strlen (normalize_filename (current_bfd)) + 1; | 
|---|
| 2335 |  | 
|---|
| 2336 | if (makemap | 
|---|
| 2337 | && ! hasobjects | 
|---|
| 2338 | && bfd_check_format (current_bfd, bfd_object)) | 
|---|
| 2339 | hasobjects = TRUE; | 
|---|
| 2340 | } | 
|---|
| 2341 |  | 
|---|
| 2342 | offsets = NULL; | 
|---|
| 2343 | if (count) | 
|---|
| 2344 | { | 
|---|
| 2345 | offsets = (file_ptr *) bfd_malloc (count * sizeof (file_ptr)); | 
|---|
| 2346 | if (offsets == NULL) | 
|---|
| 2347 | return FALSE; | 
|---|
| 2348 | } | 
|---|
| 2349 |  | 
|---|
| 2350 | prevoff = 0; | 
|---|
| 2351 | nextoff = SIZEOF_AR_FILE_HDR_BIG; | 
|---|
| 2352 | for (current_bfd = abfd->archive_head, i = 0; | 
|---|
| 2353 | current_bfd != NULL; | 
|---|
| 2354 | current_bfd = current_bfd->next, i++) | 
|---|
| 2355 | { | 
|---|
| 2356 | const char *name; | 
|---|
| 2357 | bfd_size_type namlen; | 
|---|
| 2358 | struct xcoff_ar_hdr_big *ahdrp; | 
|---|
| 2359 | bfd_size_type remaining; | 
|---|
| 2360 |  | 
|---|
| 2361 | name = normalize_filename (current_bfd); | 
|---|
| 2362 | namlen = strlen (name); | 
|---|
| 2363 |  | 
|---|
| 2364 | if (current_bfd->arelt_data != NULL) | 
|---|
| 2365 | ahdrp = arch_xhdr_big (current_bfd); | 
|---|
| 2366 | else | 
|---|
| 2367 | ahdrp = NULL; | 
|---|
| 2368 |  | 
|---|
| 2369 | if (ahdrp == NULL) | 
|---|
| 2370 | { | 
|---|
| 2371 | struct stat s; | 
|---|
| 2372 |  | 
|---|
| 2373 | ahdrp = &ahdr; | 
|---|
| 2374 | /* XXX This should actually be a call to stat64 (at least on | 
|---|
| 2375 | 32-bit machines). | 
|---|
| 2376 | XXX This call will fail if the original object is not found.  */ | 
|---|
| 2377 | if (stat (bfd_get_filename (current_bfd), &s) != 0) | 
|---|
| 2378 | { | 
|---|
| 2379 | bfd_set_error (bfd_error_system_call); | 
|---|
| 2380 | return FALSE; | 
|---|
| 2381 | } | 
|---|
| 2382 |  | 
|---|
| 2383 | PRINT20 (ahdrp->size, s.st_size); | 
|---|
| 2384 | PRINT12 (ahdrp->date, s.st_mtime); | 
|---|
| 2385 | PRINT12 (ahdrp->uid,  s.st_uid); | 
|---|
| 2386 | PRINT12 (ahdrp->gid,  s.st_gid); | 
|---|
| 2387 | PRINT12_OCTAL (ahdrp->mode, s.st_mode); | 
|---|
| 2388 |  | 
|---|
| 2389 | if (current_bfd->arelt_data == NULL) | 
|---|
| 2390 | { | 
|---|
| 2391 | size = sizeof (struct areltdata); | 
|---|
| 2392 | current_bfd->arelt_data = bfd_alloc (current_bfd, size); | 
|---|
| 2393 | if (current_bfd->arelt_data == NULL) | 
|---|
| 2394 | return FALSE; | 
|---|
| 2395 | } | 
|---|
| 2396 |  | 
|---|
| 2397 | arch_eltdata (current_bfd)->parsed_size = s.st_size; | 
|---|
| 2398 | } | 
|---|
| 2399 |  | 
|---|
| 2400 | PRINT20 (ahdrp->prevoff, prevoff); | 
|---|
| 2401 | PRINT4 (ahdrp->namlen, namlen); | 
|---|
| 2402 |  | 
|---|
| 2403 | /* If the length of the name is odd, we write out the null byte | 
|---|
| 2404 | after the name as well.  */ | 
|---|
| 2405 | namlen = (namlen + 1) &~ (bfd_size_type) 1; | 
|---|
| 2406 |  | 
|---|
| 2407 | remaining = arelt_size (current_bfd); | 
|---|
| 2408 | size = (SIZEOF_AR_HDR_BIG | 
|---|
| 2409 | + namlen | 
|---|
| 2410 | + SXCOFFARFMAG | 
|---|
| 2411 | + remaining); | 
|---|
| 2412 |  | 
|---|
| 2413 | BFD_ASSERT (nextoff == bfd_tell (abfd)); | 
|---|
| 2414 |  | 
|---|
| 2415 | /* Check for xcoff shared objects. | 
|---|
| 2416 | Their text section needs to be aligned wrt the archive file position. | 
|---|
| 2417 | This requires extra padding before the archive header.  */ | 
|---|
| 2418 | if (! do_shared_object_padding (abfd, current_bfd, & nextoff, | 
|---|
| 2419 | SIZEOF_AR_HDR_BIG + namlen | 
|---|
| 2420 | + SXCOFFARFMAG)) | 
|---|
| 2421 | return FALSE; | 
|---|
| 2422 |  | 
|---|
| 2423 | offsets[i] = nextoff; | 
|---|
| 2424 |  | 
|---|
| 2425 | prevoff = nextoff; | 
|---|
| 2426 | nextoff += size + (size & 1); | 
|---|
| 2427 |  | 
|---|
| 2428 | PRINT20 (ahdrp->nextoff, nextoff); | 
|---|
| 2429 |  | 
|---|
| 2430 | if ((bfd_bwrite ((PTR) ahdrp, (bfd_size_type) SIZEOF_AR_HDR_BIG, abfd) | 
|---|
| 2431 | != SIZEOF_AR_HDR_BIG) | 
|---|
| 2432 | || bfd_bwrite ((PTR) name, (bfd_size_type) namlen, abfd) != namlen | 
|---|
| 2433 | || (bfd_bwrite ((PTR) XCOFFARFMAG, (bfd_size_type) SXCOFFARFMAG, | 
|---|
| 2434 | abfd) != SXCOFFARFMAG)) | 
|---|
| 2435 | return FALSE; | 
|---|
| 2436 |  | 
|---|
| 2437 | if (bfd_seek (current_bfd, (file_ptr) 0, SEEK_SET) != 0) | 
|---|
| 2438 | return FALSE; | 
|---|
| 2439 |  | 
|---|
| 2440 | if (! do_copy (abfd, current_bfd)) | 
|---|
| 2441 | return FALSE; | 
|---|
| 2442 |  | 
|---|
| 2443 | if (! do_pad (abfd, size & 1)) | 
|---|
| 2444 | return FALSE; | 
|---|
| 2445 | } | 
|---|
| 2446 |  | 
|---|
| 2447 | if (count) | 
|---|
| 2448 | { | 
|---|
| 2449 | PRINT20 (fhdr.firstmemoff, offsets[0]); | 
|---|
| 2450 | PRINT20 (fhdr.lastmemoff, prevoff); | 
|---|
| 2451 | } | 
|---|
| 2452 |  | 
|---|
| 2453 | /* Write out the member table. | 
|---|
| 2454 | Layout : | 
|---|
| 2455 |  | 
|---|
| 2456 | standard big archive header | 
|---|
| 2457 | 0x0000                   ar_size   [0x14] | 
|---|
| 2458 | 0x0014                   ar_nxtmem [0x14] | 
|---|
| 2459 | 0x0028                   ar_prvmem [0x14] | 
|---|
| 2460 | 0x003C                   ar_date   [0x0C] | 
|---|
| 2461 | 0x0048                   ar_uid    [0x0C] | 
|---|
| 2462 | 0x0054                   ar_gid    [0x0C] | 
|---|
| 2463 | 0x0060                   ar_mod    [0x0C] | 
|---|
| 2464 | 0x006C                   ar_namelen[0x04] | 
|---|
| 2465 | 0x0070                   ar_fmag   [0x02] | 
|---|
| 2466 |  | 
|---|
| 2467 | Member table | 
|---|
| 2468 | 0x0072                   count     [0x14] | 
|---|
| 2469 | 0x0086                   offsets   [0x14 * counts] | 
|---|
| 2470 | 0x0086 + 0x14 * counts   names     [??] | 
|---|
| 2471 | ??                       pad to even bytes. | 
|---|
| 2472 | */ | 
|---|
| 2473 |  | 
|---|
| 2474 | BFD_ASSERT (nextoff == bfd_tell (abfd)); | 
|---|
| 2475 |  | 
|---|
| 2476 | member_table_size = (SIZEOF_AR_HDR_BIG | 
|---|
| 2477 | + SXCOFFARFMAG | 
|---|
| 2478 | + XCOFFARMAGBIG_ELEMENT_SIZE | 
|---|
| 2479 | + count * XCOFFARMAGBIG_ELEMENT_SIZE | 
|---|
| 2480 | + total_namlen); | 
|---|
| 2481 |  | 
|---|
| 2482 | member_table_size += member_table_size & 1; | 
|---|
| 2483 | member_table = NULL; | 
|---|
| 2484 | member_table = (bfd_byte *) bfd_zmalloc (member_table_size); | 
|---|
| 2485 | if (member_table == NULL) | 
|---|
| 2486 | return FALSE; | 
|---|
| 2487 |  | 
|---|
| 2488 | hdr = (struct xcoff_ar_hdr_big *) member_table; | 
|---|
| 2489 |  | 
|---|
| 2490 | PRINT20 (hdr->size, (XCOFFARMAGBIG_ELEMENT_SIZE | 
|---|
| 2491 | + count * XCOFFARMAGBIG_ELEMENT_SIZE | 
|---|
| 2492 | + total_namlen + (total_namlen & 1))); | 
|---|
| 2493 | if (makemap && hasobjects) | 
|---|
| 2494 | PRINT20 (hdr->nextoff, nextoff + member_table_size); | 
|---|
| 2495 | else | 
|---|
| 2496 | PRINT20 (hdr->nextoff, 0); | 
|---|
| 2497 | PRINT20 (hdr->prevoff, prevoff); | 
|---|
| 2498 | PRINT12 (hdr->date, 0); | 
|---|
| 2499 | PRINT12 (hdr->uid, 0); | 
|---|
| 2500 | PRINT12 (hdr->gid, 0); | 
|---|
| 2501 | PRINT12 (hdr->mode, 0); | 
|---|
| 2502 | PRINT4 (hdr->namlen, 0); | 
|---|
| 2503 |  | 
|---|
| 2504 | mt = member_table + SIZEOF_AR_HDR_BIG; | 
|---|
| 2505 | memcpy (mt, XCOFFARFMAG, SXCOFFARFMAG); | 
|---|
| 2506 | mt += SXCOFFARFMAG; | 
|---|
| 2507 |  | 
|---|
| 2508 | PRINT20 (mt, count); | 
|---|
| 2509 | mt += XCOFFARMAGBIG_ELEMENT_SIZE; | 
|---|
| 2510 | for (i = 0; i < (size_t) count; i++) | 
|---|
| 2511 | { | 
|---|
| 2512 | PRINT20 (mt, offsets[i]); | 
|---|
| 2513 | mt += XCOFFARMAGBIG_ELEMENT_SIZE; | 
|---|
| 2514 | } | 
|---|
| 2515 |  | 
|---|
| 2516 | if (count) | 
|---|
| 2517 | { | 
|---|
| 2518 | free (offsets); | 
|---|
| 2519 | offsets = NULL; | 
|---|
| 2520 | } | 
|---|
| 2521 |  | 
|---|
| 2522 | for (current_bfd = abfd->archive_head; current_bfd != NULL; | 
|---|
| 2523 | current_bfd = current_bfd->next) | 
|---|
| 2524 | { | 
|---|
| 2525 | const char *name; | 
|---|
| 2526 | size_t namlen; | 
|---|
| 2527 |  | 
|---|
| 2528 | name = normalize_filename (current_bfd); | 
|---|
| 2529 | namlen = sprintf (mt, "%s", name); | 
|---|
| 2530 | mt += namlen + 1; | 
|---|
| 2531 | } | 
|---|
| 2532 |  | 
|---|
| 2533 | if (bfd_bwrite (member_table, member_table_size, abfd) != member_table_size) | 
|---|
| 2534 | return FALSE; | 
|---|
| 2535 |  | 
|---|
| 2536 | free (member_table); | 
|---|
| 2537 | member_table = NULL; | 
|---|
| 2538 |  | 
|---|
| 2539 | PRINT20 (fhdr.memoff, nextoff); | 
|---|
| 2540 |  | 
|---|
| 2541 | prevoff = nextoff; | 
|---|
| 2542 | nextoff += member_table_size; | 
|---|
| 2543 |  | 
|---|
| 2544 | /* Write out the armap, if appropriate.  */ | 
|---|
| 2545 |  | 
|---|
| 2546 | if (! makemap || ! hasobjects) | 
|---|
| 2547 | PRINT20 (fhdr.symoff, 0); | 
|---|
| 2548 | else | 
|---|
| 2549 | { | 
|---|
| 2550 | BFD_ASSERT (nextoff == bfd_tell (abfd)); | 
|---|
| 2551 |  | 
|---|
| 2552 | /* Save nextoff in fhdr.symoff so the armap routine can use it.  */ | 
|---|
| 2553 | PRINT20 (fhdr.symoff, nextoff); | 
|---|
| 2554 |  | 
|---|
| 2555 | bfd_ardata (abfd)->tdata = (PTR) &fhdr; | 
|---|
| 2556 | if (! _bfd_compute_and_write_armap (abfd, 0)) | 
|---|
| 2557 | return FALSE; | 
|---|
| 2558 | } | 
|---|
| 2559 |  | 
|---|
| 2560 | /* Write out the archive file header.  */ | 
|---|
| 2561 |  | 
|---|
| 2562 | if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0 | 
|---|
| 2563 | || (bfd_bwrite ((PTR) &fhdr, (bfd_size_type) SIZEOF_AR_FILE_HDR_BIG, | 
|---|
| 2564 | abfd) != SIZEOF_AR_FILE_HDR_BIG)) | 
|---|
| 2565 | return FALSE; | 
|---|
| 2566 |  | 
|---|
| 2567 | return TRUE; | 
|---|
| 2568 | } | 
|---|
| 2569 |  | 
|---|
| 2570 | bfd_boolean | 
|---|
| 2571 | _bfd_xcoff_write_archive_contents (abfd) | 
|---|
| 2572 | bfd *abfd; | 
|---|
| 2573 | { | 
|---|
| 2574 | if (! xcoff_big_format_p (abfd)) | 
|---|
| 2575 | return xcoff_write_archive_contents_old (abfd); | 
|---|
| 2576 | else | 
|---|
| 2577 | return xcoff_write_archive_contents_big (abfd); | 
|---|
| 2578 | } | 
|---|
| 2579 |  | 
|---|
| 2580 |  | 
|---|
| 2581 | /* We can't use the usual coff_sizeof_headers routine, because AIX | 
|---|
| 2582 | always uses an a.out header.  */ | 
|---|
| 2583 |  | 
|---|
| 2584 | int | 
|---|
| 2585 | _bfd_xcoff_sizeof_headers (abfd, reloc) | 
|---|
| 2586 | bfd *abfd; | 
|---|
| 2587 | bfd_boolean reloc ATTRIBUTE_UNUSED; | 
|---|
| 2588 | { | 
|---|
| 2589 | int size; | 
|---|
| 2590 |  | 
|---|
| 2591 | size = FILHSZ; | 
|---|
| 2592 | if (xcoff_data (abfd)->full_aouthdr) | 
|---|
| 2593 | size += AOUTSZ; | 
|---|
| 2594 | else | 
|---|
| 2595 | size += SMALL_AOUTSZ; | 
|---|
| 2596 | size += abfd->section_count * SCNHSZ; | 
|---|
| 2597 | return size; | 
|---|
| 2598 | } | 
|---|
| 2599 |  | 
|---|
| 2600 |  | 
|---|
| 2601 | /* Routines to swap information in the XCOFF .loader section.  If we | 
|---|
| 2602 | ever need to write an XCOFF loader, this stuff will need to be | 
|---|
| 2603 | moved to another file shared by the linker (which XCOFF calls the | 
|---|
| 2604 | ``binder'') and the loader.  */ | 
|---|
| 2605 |  | 
|---|
| 2606 | /* Swap in the ldhdr structure.  */ | 
|---|
| 2607 |  | 
|---|
| 2608 | static void | 
|---|
| 2609 | xcoff_swap_ldhdr_in (abfd, s, dst) | 
|---|
| 2610 | bfd *abfd; | 
|---|
| 2611 | const PTR s; | 
|---|
| 2612 | struct internal_ldhdr *dst; | 
|---|
| 2613 | { | 
|---|
| 2614 | const struct external_ldhdr *src = (const struct external_ldhdr *) s; | 
|---|
| 2615 |  | 
|---|
| 2616 | dst->l_version = bfd_get_32 (abfd, src->l_version); | 
|---|
| 2617 | dst->l_nsyms = bfd_get_32 (abfd, src->l_nsyms); | 
|---|
| 2618 | dst->l_nreloc = bfd_get_32 (abfd, src->l_nreloc); | 
|---|
| 2619 | dst->l_istlen = bfd_get_32 (abfd, src->l_istlen); | 
|---|
| 2620 | dst->l_nimpid = bfd_get_32 (abfd, src->l_nimpid); | 
|---|
| 2621 | dst->l_impoff = bfd_get_32 (abfd, src->l_impoff); | 
|---|
| 2622 | dst->l_stlen = bfd_get_32 (abfd, src->l_stlen); | 
|---|
| 2623 | dst->l_stoff = bfd_get_32 (abfd, src->l_stoff); | 
|---|
| 2624 | } | 
|---|
| 2625 |  | 
|---|
| 2626 | /* Swap out the ldhdr structure.  */ | 
|---|
| 2627 |  | 
|---|
| 2628 | static void | 
|---|
| 2629 | xcoff_swap_ldhdr_out (abfd, src, d) | 
|---|
| 2630 | bfd *abfd; | 
|---|
| 2631 | const struct internal_ldhdr *src; | 
|---|
| 2632 | PTR d; | 
|---|
| 2633 | { | 
|---|
| 2634 | struct external_ldhdr *dst = (struct external_ldhdr *) d; | 
|---|
| 2635 |  | 
|---|
| 2636 | bfd_put_32 (abfd, (bfd_vma) src->l_version, dst->l_version); | 
|---|
| 2637 | bfd_put_32 (abfd, src->l_nsyms, dst->l_nsyms); | 
|---|
| 2638 | bfd_put_32 (abfd, src->l_nreloc, dst->l_nreloc); | 
|---|
| 2639 | bfd_put_32 (abfd, src->l_istlen, dst->l_istlen); | 
|---|
| 2640 | bfd_put_32 (abfd, src->l_nimpid, dst->l_nimpid); | 
|---|
| 2641 | bfd_put_32 (abfd, src->l_impoff, dst->l_impoff); | 
|---|
| 2642 | bfd_put_32 (abfd, src->l_stlen, dst->l_stlen); | 
|---|
| 2643 | bfd_put_32 (abfd, src->l_stoff, dst->l_stoff); | 
|---|
| 2644 | } | 
|---|
| 2645 |  | 
|---|
| 2646 | /* Swap in the ldsym structure.  */ | 
|---|
| 2647 |  | 
|---|
| 2648 | static void | 
|---|
| 2649 | xcoff_swap_ldsym_in (abfd, s, dst) | 
|---|
| 2650 | bfd *abfd; | 
|---|
| 2651 | const PTR s; | 
|---|
| 2652 | struct internal_ldsym *dst; | 
|---|
| 2653 | { | 
|---|
| 2654 | const struct external_ldsym *src = (const struct external_ldsym *) s; | 
|---|
| 2655 |  | 
|---|
| 2656 | if (bfd_get_32 (abfd, src->_l._l_l._l_zeroes) != 0) { | 
|---|
| 2657 | memcpy (dst->_l._l_name, src->_l._l_name, SYMNMLEN); | 
|---|
| 2658 | } else { | 
|---|
| 2659 | dst->_l._l_l._l_zeroes = 0; | 
|---|
| 2660 | dst->_l._l_l._l_offset = bfd_get_32 (abfd, src->_l._l_l._l_offset); | 
|---|
| 2661 | } | 
|---|
| 2662 | dst->l_value = bfd_get_32 (abfd, src->l_value); | 
|---|
| 2663 | dst->l_scnum = bfd_get_16 (abfd, src->l_scnum); | 
|---|
| 2664 | dst->l_smtype = bfd_get_8 (abfd, src->l_smtype); | 
|---|
| 2665 | dst->l_smclas = bfd_get_8 (abfd, src->l_smclas); | 
|---|
| 2666 | dst->l_ifile = bfd_get_32 (abfd, src->l_ifile); | 
|---|
| 2667 | dst->l_parm = bfd_get_32 (abfd, src->l_parm); | 
|---|
| 2668 | } | 
|---|
| 2669 |  | 
|---|
| 2670 | /* Swap out the ldsym structure.  */ | 
|---|
| 2671 |  | 
|---|
| 2672 | static void | 
|---|
| 2673 | xcoff_swap_ldsym_out (abfd, src, d) | 
|---|
| 2674 | bfd *abfd; | 
|---|
| 2675 | const struct internal_ldsym *src; | 
|---|
| 2676 | PTR d; | 
|---|
| 2677 | { | 
|---|
| 2678 | struct external_ldsym *dst = (struct external_ldsym *) d; | 
|---|
| 2679 |  | 
|---|
| 2680 | if (src->_l._l_l._l_zeroes != 0) | 
|---|
| 2681 | memcpy (dst->_l._l_name, src->_l._l_name, SYMNMLEN); | 
|---|
| 2682 | else | 
|---|
| 2683 | { | 
|---|
| 2684 | bfd_put_32 (abfd, (bfd_vma) 0, dst->_l._l_l._l_zeroes); | 
|---|
| 2685 | bfd_put_32 (abfd, (bfd_vma) src->_l._l_l._l_offset, | 
|---|
| 2686 | dst->_l._l_l._l_offset); | 
|---|
| 2687 | } | 
|---|
| 2688 | bfd_put_32 (abfd, src->l_value, dst->l_value); | 
|---|
| 2689 | bfd_put_16 (abfd, (bfd_vma) src->l_scnum, dst->l_scnum); | 
|---|
| 2690 | bfd_put_8 (abfd, src->l_smtype, dst->l_smtype); | 
|---|
| 2691 | bfd_put_8 (abfd, src->l_smclas, dst->l_smclas); | 
|---|
| 2692 | bfd_put_32 (abfd, src->l_ifile, dst->l_ifile); | 
|---|
| 2693 | bfd_put_32 (abfd, src->l_parm, dst->l_parm); | 
|---|
| 2694 | } | 
|---|
| 2695 |  | 
|---|
| 2696 | static void | 
|---|
| 2697 | xcoff_swap_reloc_in (abfd, s, d) | 
|---|
| 2698 | bfd *abfd; | 
|---|
| 2699 | PTR s; | 
|---|
| 2700 | PTR d; | 
|---|
| 2701 | { | 
|---|
| 2702 | struct external_reloc *src = (struct external_reloc *) s; | 
|---|
| 2703 | struct internal_reloc *dst = (struct internal_reloc *) d; | 
|---|
| 2704 |  | 
|---|
| 2705 | memset (dst, 0, sizeof (struct internal_reloc)); | 
|---|
| 2706 |  | 
|---|
| 2707 | dst->r_vaddr = bfd_get_32 (abfd, src->r_vaddr); | 
|---|
| 2708 | dst->r_symndx = bfd_get_32 (abfd, src->r_symndx); | 
|---|
| 2709 | dst->r_size = bfd_get_8 (abfd, src->r_size); | 
|---|
| 2710 | dst->r_type = bfd_get_8 (abfd, src->r_type); | 
|---|
| 2711 | } | 
|---|
| 2712 |  | 
|---|
| 2713 | static unsigned int | 
|---|
| 2714 | xcoff_swap_reloc_out (abfd, s, d) | 
|---|
| 2715 | bfd *abfd; | 
|---|
| 2716 | PTR s; | 
|---|
| 2717 | PTR d; | 
|---|
| 2718 | { | 
|---|
| 2719 | struct internal_reloc *src = (struct internal_reloc *) s; | 
|---|
| 2720 | struct external_reloc *dst = (struct external_reloc *) d; | 
|---|
| 2721 |  | 
|---|
| 2722 | bfd_put_32 (abfd, src->r_vaddr, dst->r_vaddr); | 
|---|
| 2723 | bfd_put_32 (abfd, src->r_symndx, dst->r_symndx); | 
|---|
| 2724 | bfd_put_8 (abfd, src->r_type, dst->r_type); | 
|---|
| 2725 | bfd_put_8 (abfd, src->r_size, dst->r_size); | 
|---|
| 2726 |  | 
|---|
| 2727 | return bfd_coff_relsz (abfd); | 
|---|
| 2728 | } | 
|---|
| 2729 |  | 
|---|
| 2730 | /* Swap in the ldrel structure.  */ | 
|---|
| 2731 |  | 
|---|
| 2732 | static void | 
|---|
| 2733 | xcoff_swap_ldrel_in (abfd, s, dst) | 
|---|
| 2734 | bfd *abfd; | 
|---|
| 2735 | const PTR s; | 
|---|
| 2736 | struct internal_ldrel *dst; | 
|---|
| 2737 | { | 
|---|
| 2738 | const struct external_ldrel *src = (const struct external_ldrel *) s; | 
|---|
| 2739 |  | 
|---|
| 2740 | dst->l_vaddr = bfd_get_32 (abfd, src->l_vaddr); | 
|---|
| 2741 | dst->l_symndx = bfd_get_32 (abfd, src->l_symndx); | 
|---|
| 2742 | dst->l_rtype = bfd_get_16 (abfd, src->l_rtype); | 
|---|
| 2743 | dst->l_rsecnm = bfd_get_16 (abfd, src->l_rsecnm); | 
|---|
| 2744 | } | 
|---|
| 2745 |  | 
|---|
| 2746 | /* Swap out the ldrel structure.  */ | 
|---|
| 2747 |  | 
|---|
| 2748 | static void | 
|---|
| 2749 | xcoff_swap_ldrel_out (abfd, src, d) | 
|---|
| 2750 | bfd *abfd; | 
|---|
| 2751 | const struct internal_ldrel *src; | 
|---|
| 2752 | PTR d; | 
|---|
| 2753 | { | 
|---|
| 2754 | struct external_ldrel *dst = (struct external_ldrel *) d; | 
|---|
| 2755 |  | 
|---|
| 2756 | bfd_put_32 (abfd, src->l_vaddr, dst->l_vaddr); | 
|---|
| 2757 | bfd_put_32 (abfd, src->l_symndx, dst->l_symndx); | 
|---|
| 2758 | bfd_put_16 (abfd, (bfd_vma) src->l_rtype, dst->l_rtype); | 
|---|
| 2759 | bfd_put_16 (abfd, (bfd_vma) src->l_rsecnm, dst->l_rsecnm); | 
|---|
| 2760 | } | 
|---|
| 2761 |  | 
|---|
| 2762 |  | 
|---|
| 2763 |  | 
|---|
| 2764 | bfd_boolean | 
|---|
| 2765 | xcoff_reloc_type_noop (input_bfd, input_section, output_bfd, rel, sym, howto, | 
|---|
| 2766 | val, addend, relocation, contents) | 
|---|
| 2767 | bfd *input_bfd ATTRIBUTE_UNUSED; | 
|---|
| 2768 | asection *input_section ATTRIBUTE_UNUSED; | 
|---|
| 2769 | bfd *output_bfd ATTRIBUTE_UNUSED; | 
|---|
| 2770 | struct internal_reloc *rel ATTRIBUTE_UNUSED; | 
|---|
| 2771 | struct internal_syment *sym ATTRIBUTE_UNUSED; | 
|---|
| 2772 | struct reloc_howto_struct *howto ATTRIBUTE_UNUSED; | 
|---|
| 2773 | bfd_vma val ATTRIBUTE_UNUSED; | 
|---|
| 2774 | bfd_vma addend ATTRIBUTE_UNUSED; | 
|---|
| 2775 | bfd_vma *relocation ATTRIBUTE_UNUSED; | 
|---|
| 2776 | bfd_byte *contents ATTRIBUTE_UNUSED; | 
|---|
| 2777 | { | 
|---|
| 2778 | return TRUE; | 
|---|
| 2779 | } | 
|---|
| 2780 |  | 
|---|
| 2781 | bfd_boolean | 
|---|
| 2782 | xcoff_reloc_type_fail (input_bfd, input_section, output_bfd, rel, sym, howto, | 
|---|
| 2783 | val, addend, relocation, contents) | 
|---|
| 2784 | bfd *input_bfd; | 
|---|
| 2785 | asection *input_section ATTRIBUTE_UNUSED; | 
|---|
| 2786 | bfd *output_bfd ATTRIBUTE_UNUSED; | 
|---|
| 2787 | struct internal_reloc *rel; | 
|---|
| 2788 | struct internal_syment *sym ATTRIBUTE_UNUSED; | 
|---|
| 2789 | struct reloc_howto_struct *howto ATTRIBUTE_UNUSED; | 
|---|
| 2790 | bfd_vma val ATTRIBUTE_UNUSED; | 
|---|
| 2791 | bfd_vma addend ATTRIBUTE_UNUSED; | 
|---|
| 2792 | bfd_vma *relocation ATTRIBUTE_UNUSED; | 
|---|
| 2793 | bfd_byte *contents ATTRIBUTE_UNUSED; | 
|---|
| 2794 | { | 
|---|
| 2795 | (*_bfd_error_handler) | 
|---|
| 2796 | (_("%s: unsupported relocation type 0x%02x"), | 
|---|
| 2797 | bfd_get_filename (input_bfd), (unsigned int) rel->r_type); | 
|---|
| 2798 | bfd_set_error (bfd_error_bad_value); | 
|---|
| 2799 | return FALSE; | 
|---|
| 2800 | } | 
|---|
| 2801 |  | 
|---|
| 2802 | bfd_boolean | 
|---|
| 2803 | xcoff_reloc_type_pos (input_bfd, input_section, output_bfd, rel, sym, howto, | 
|---|
| 2804 | val, addend, relocation, contents) | 
|---|
| 2805 | bfd *input_bfd ATTRIBUTE_UNUSED; | 
|---|
| 2806 | asection *input_section ATTRIBUTE_UNUSED; | 
|---|
| 2807 | bfd *output_bfd ATTRIBUTE_UNUSED; | 
|---|
| 2808 | struct internal_reloc *rel ATTRIBUTE_UNUSED; | 
|---|
| 2809 | struct internal_syment *sym ATTRIBUTE_UNUSED; | 
|---|
| 2810 | struct reloc_howto_struct *howto ATTRIBUTE_UNUSED; | 
|---|
| 2811 | bfd_vma val; | 
|---|
| 2812 | bfd_vma addend; | 
|---|
| 2813 | bfd_vma *relocation; | 
|---|
| 2814 | bfd_byte *contents ATTRIBUTE_UNUSED; | 
|---|
| 2815 | { | 
|---|
| 2816 | *relocation = val + addend; | 
|---|
| 2817 | return TRUE; | 
|---|
| 2818 | } | 
|---|
| 2819 |  | 
|---|
| 2820 | bfd_boolean | 
|---|
| 2821 | xcoff_reloc_type_neg (input_bfd, input_section, output_bfd, rel, sym, howto, | 
|---|
| 2822 | val, addend, relocation, contents) | 
|---|
| 2823 | bfd *input_bfd ATTRIBUTE_UNUSED; | 
|---|
| 2824 | asection *input_section ATTRIBUTE_UNUSED; | 
|---|
| 2825 | bfd *output_bfd ATTRIBUTE_UNUSED; | 
|---|
| 2826 | struct internal_reloc *rel ATTRIBUTE_UNUSED; | 
|---|
| 2827 | struct internal_syment *sym ATTRIBUTE_UNUSED; | 
|---|
| 2828 | struct reloc_howto_struct *howto ATTRIBUTE_UNUSED; | 
|---|
| 2829 | bfd_vma val; | 
|---|
| 2830 | bfd_vma addend; | 
|---|
| 2831 | bfd_vma *relocation; | 
|---|
| 2832 | bfd_byte *contents ATTRIBUTE_UNUSED; | 
|---|
| 2833 | { | 
|---|
| 2834 | *relocation = addend - val; | 
|---|
| 2835 | return TRUE; | 
|---|
| 2836 | } | 
|---|
| 2837 |  | 
|---|
| 2838 | bfd_boolean | 
|---|
| 2839 | xcoff_reloc_type_rel (input_bfd, input_section, output_bfd, rel, sym, howto, | 
|---|
| 2840 | val, addend, relocation, contents) | 
|---|
| 2841 | bfd *input_bfd ATTRIBUTE_UNUSED; | 
|---|
| 2842 | asection *input_section; | 
|---|
| 2843 | bfd *output_bfd ATTRIBUTE_UNUSED; | 
|---|
| 2844 | struct internal_reloc *rel ATTRIBUTE_UNUSED; | 
|---|
| 2845 | struct internal_syment *sym ATTRIBUTE_UNUSED; | 
|---|
| 2846 | struct reloc_howto_struct *howto; | 
|---|
| 2847 | bfd_vma val; | 
|---|
| 2848 | bfd_vma addend; | 
|---|
| 2849 | bfd_vma *relocation; | 
|---|
| 2850 | bfd_byte *contents ATTRIBUTE_UNUSED; | 
|---|
| 2851 | { | 
|---|
| 2852 | howto->pc_relative = TRUE; | 
|---|
| 2853 |  | 
|---|
| 2854 | /* A PC relative reloc includes the section address.  */ | 
|---|
| 2855 | addend += input_section->vma; | 
|---|
| 2856 |  | 
|---|
| 2857 | *relocation = val + addend; | 
|---|
| 2858 | *relocation -= (input_section->output_section->vma | 
|---|
| 2859 | + input_section->output_offset); | 
|---|
| 2860 | return TRUE; | 
|---|
| 2861 | } | 
|---|
| 2862 |  | 
|---|
| 2863 | bfd_boolean | 
|---|
| 2864 | xcoff_reloc_type_toc (input_bfd, input_section, output_bfd, rel, sym, howto, | 
|---|
| 2865 | val, addend, relocation, contents) | 
|---|
| 2866 | bfd *input_bfd; | 
|---|
| 2867 | asection *input_section ATTRIBUTE_UNUSED; | 
|---|
| 2868 | bfd *output_bfd; | 
|---|
| 2869 | struct internal_reloc *rel; | 
|---|
| 2870 | struct internal_syment *sym; | 
|---|
| 2871 | struct reloc_howto_struct *howto ATTRIBUTE_UNUSED; | 
|---|
| 2872 | bfd_vma val; | 
|---|
| 2873 | bfd_vma addend ATTRIBUTE_UNUSED; | 
|---|
| 2874 | bfd_vma *relocation; | 
|---|
| 2875 | bfd_byte *contents ATTRIBUTE_UNUSED; | 
|---|
| 2876 | { | 
|---|
| 2877 | struct xcoff_link_hash_entry *h; | 
|---|
| 2878 |  | 
|---|
| 2879 | if (0 > rel->r_symndx) | 
|---|
| 2880 | return FALSE; | 
|---|
| 2881 |  | 
|---|
| 2882 | h = obj_xcoff_sym_hashes (input_bfd)[rel->r_symndx]; | 
|---|
| 2883 |  | 
|---|
| 2884 | if (h != NULL && h->smclas != XMC_TD) | 
|---|
| 2885 | { | 
|---|
| 2886 | if (h->toc_section == NULL) | 
|---|
| 2887 | { | 
|---|
| 2888 | (*_bfd_error_handler) | 
|---|
| 2889 | (_("%s: TOC reloc at 0x%x to symbol `%s' with no TOC entry"), | 
|---|
| 2890 | bfd_get_filename (input_bfd), rel->r_vaddr, | 
|---|
| 2891 | h->root.root.string); | 
|---|
| 2892 | bfd_set_error (bfd_error_bad_value); | 
|---|
| 2893 | return FALSE; | 
|---|
| 2894 | } | 
|---|
| 2895 |  | 
|---|
| 2896 | BFD_ASSERT ((h->flags & XCOFF_SET_TOC) == 0); | 
|---|
| 2897 | val = (h->toc_section->output_section->vma | 
|---|
| 2898 | + h->toc_section->output_offset); | 
|---|
| 2899 | } | 
|---|
| 2900 |  | 
|---|
| 2901 | *relocation = ((val - xcoff_data (output_bfd)->toc) | 
|---|
| 2902 | - (sym->n_value - xcoff_data (input_bfd)->toc)); | 
|---|
| 2903 | return TRUE; | 
|---|
| 2904 | } | 
|---|
| 2905 |  | 
|---|
| 2906 | bfd_boolean | 
|---|
| 2907 | xcoff_reloc_type_ba (input_bfd, input_section, output_bfd, rel, sym, howto, | 
|---|
| 2908 | val, addend, relocation, contents) | 
|---|
| 2909 | bfd *input_bfd ATTRIBUTE_UNUSED; | 
|---|
| 2910 | asection *input_section ATTRIBUTE_UNUSED; | 
|---|
| 2911 | bfd *output_bfd ATTRIBUTE_UNUSED; | 
|---|
| 2912 | struct internal_reloc *rel ATTRIBUTE_UNUSED; | 
|---|
| 2913 | struct internal_syment *sym ATTRIBUTE_UNUSED; | 
|---|
| 2914 | struct reloc_howto_struct *howto; | 
|---|
| 2915 | bfd_vma val; | 
|---|
| 2916 | bfd_vma addend; | 
|---|
| 2917 | bfd_vma *relocation; | 
|---|
| 2918 | bfd_byte *contents ATTRIBUTE_UNUSED; | 
|---|
| 2919 | { | 
|---|
| 2920 | howto->src_mask &= ~3; | 
|---|
| 2921 | howto->dst_mask = howto->src_mask; | 
|---|
| 2922 |  | 
|---|
| 2923 | *relocation = val + addend; | 
|---|
| 2924 |  | 
|---|
| 2925 | return TRUE; | 
|---|
| 2926 | } | 
|---|
| 2927 |  | 
|---|
| 2928 | static bfd_boolean | 
|---|
| 2929 | xcoff_reloc_type_br (input_bfd, input_section, output_bfd, rel, sym, howto, | 
|---|
| 2930 | val, addend, relocation, contents) | 
|---|
| 2931 | bfd *input_bfd; | 
|---|
| 2932 | asection *input_section; | 
|---|
| 2933 | bfd *output_bfd ATTRIBUTE_UNUSED; | 
|---|
| 2934 | struct internal_reloc *rel; | 
|---|
| 2935 | struct internal_syment *sym ATTRIBUTE_UNUSED; | 
|---|
| 2936 | struct reloc_howto_struct *howto; | 
|---|
| 2937 | bfd_vma val; | 
|---|
| 2938 | bfd_vma addend; | 
|---|
| 2939 | bfd_vma *relocation; | 
|---|
| 2940 | bfd_byte *contents; | 
|---|
| 2941 | { | 
|---|
| 2942 | struct xcoff_link_hash_entry *h; | 
|---|
| 2943 |  | 
|---|
| 2944 | if (0 > rel->r_symndx) | 
|---|
| 2945 | return FALSE; | 
|---|
| 2946 |  | 
|---|
| 2947 | h = obj_xcoff_sym_hashes (input_bfd)[rel->r_symndx]; | 
|---|
| 2948 |  | 
|---|
| 2949 | /* If we see an R_BR or R_RBR reloc which is jumping to global | 
|---|
| 2950 | linkage code, and it is followed by an appropriate cror nop | 
|---|
| 2951 | instruction, we replace the cror with lwz r2,20(r1).  This | 
|---|
| 2952 | restores the TOC after the glink code.  Contrariwise, if the | 
|---|
| 2953 | call is followed by a lwz r2,20(r1), but the call is not | 
|---|
| 2954 | going to global linkage code, we can replace the load with a | 
|---|
| 2955 | cror.  */ | 
|---|
| 2956 | if (NULL != h | 
|---|
| 2957 | && bfd_link_hash_defined == h->root.type | 
|---|
| 2958 | && (rel->r_vaddr - input_section->vma + 8 | 
|---|
| 2959 | <= input_section->_cooked_size)) | 
|---|
| 2960 | { | 
|---|
| 2961 | bfd_byte *pnext; | 
|---|
| 2962 | unsigned long next; | 
|---|
| 2963 |  | 
|---|
| 2964 | pnext = contents + (rel->r_vaddr - input_section->vma) + 4; | 
|---|
| 2965 | next = bfd_get_32 (input_bfd, pnext); | 
|---|
| 2966 |  | 
|---|
| 2967 | /* The _ptrgl function is magic.  It is used by the AIX | 
|---|
| 2968 | compiler to call a function through a pointer.  */ | 
|---|
| 2969 | if (h->smclas == XMC_GL || strcmp (h->root.root.string, "._ptrgl") == 0) | 
|---|
| 2970 | { | 
|---|
| 2971 | if (next == 0x4def7b82                        /* cror 15,15,15 */ | 
|---|
| 2972 | || next == 0x4ffffb82                     /* cror 31,31,31 */ | 
|---|
| 2973 | || next == 0x60000000)                    /* ori r0,r0,0 */ | 
|---|
| 2974 | bfd_put_32 (input_bfd, 0x80410014, pnext);  /* lwz r1,20(r1) */ | 
|---|
| 2975 |  | 
|---|
| 2976 | } | 
|---|
| 2977 | else | 
|---|
| 2978 | { | 
|---|
| 2979 | if (next == 0x80410014)                       /* lwz r1,20(r1) */ | 
|---|
| 2980 | bfd_put_32 (input_bfd, 0x60000000, pnext);  /* ori r0,r0,0 */ | 
|---|
| 2981 | } | 
|---|
| 2982 | } | 
|---|
| 2983 | else if (NULL != h && bfd_link_hash_undefined == h->root.type) | 
|---|
| 2984 | { | 
|---|
| 2985 | /* Normally, this relocation is against a defined symbol.  In the | 
|---|
| 2986 | case where this is a partial link and the output section offset | 
|---|
| 2987 | is greater than 2^25, the linker will return an invalid error | 
|---|
| 2988 | message that the relocation has been truncated.  Yes it has been | 
|---|
| 2989 | truncated but no it not important.  For this case, disable the | 
|---|
| 2990 | overflow checking. */ | 
|---|
| 2991 |  | 
|---|
| 2992 | howto->complain_on_overflow = complain_overflow_dont; | 
|---|
| 2993 | } | 
|---|
| 2994 |  | 
|---|
| 2995 | howto->pc_relative = TRUE; | 
|---|
| 2996 | howto->src_mask &= ~3; | 
|---|
| 2997 | howto->dst_mask = howto->src_mask; | 
|---|
| 2998 |  | 
|---|
| 2999 | /* A PC relative reloc includes the section address.  */ | 
|---|
| 3000 | addend += input_section->vma; | 
|---|
| 3001 |  | 
|---|
| 3002 | *relocation = val + addend; | 
|---|
| 3003 | *relocation -= (input_section->output_section->vma | 
|---|
| 3004 | + input_section->output_offset); | 
|---|
| 3005 | return TRUE; | 
|---|
| 3006 | } | 
|---|
| 3007 |  | 
|---|
| 3008 | bfd_boolean | 
|---|
| 3009 | xcoff_reloc_type_crel (input_bfd, input_section, output_bfd, rel, sym, howto, | 
|---|
| 3010 | val, addend, relocation, contents) | 
|---|
| 3011 | bfd *input_bfd ATTRIBUTE_UNUSED; | 
|---|
| 3012 | asection *input_section; | 
|---|
| 3013 | bfd *output_bfd ATTRIBUTE_UNUSED; | 
|---|
| 3014 | struct internal_reloc *rel ATTRIBUTE_UNUSED; | 
|---|
| 3015 | struct internal_syment *sym ATTRIBUTE_UNUSED; | 
|---|
| 3016 | struct reloc_howto_struct *howto; | 
|---|
| 3017 | bfd_vma val ATTRIBUTE_UNUSED; | 
|---|
| 3018 | bfd_vma addend; | 
|---|
| 3019 | bfd_vma *relocation; | 
|---|
| 3020 | bfd_byte *contents ATTRIBUTE_UNUSED; | 
|---|
| 3021 | { | 
|---|
| 3022 | howto->pc_relative = TRUE; | 
|---|
| 3023 | howto->src_mask &= ~3; | 
|---|
| 3024 | howto->dst_mask = howto->src_mask; | 
|---|
| 3025 |  | 
|---|
| 3026 | /* A PC relative reloc includes the section address.  */ | 
|---|
| 3027 | addend += input_section->vma; | 
|---|
| 3028 |  | 
|---|
| 3029 | *relocation = val + addend; | 
|---|
| 3030 | *relocation -= (input_section->output_section->vma | 
|---|
| 3031 | + input_section->output_offset); | 
|---|
| 3032 | return TRUE; | 
|---|
| 3033 | } | 
|---|
| 3034 |  | 
|---|
| 3035 | static bfd_boolean | 
|---|
| 3036 | xcoff_complain_overflow_dont_func (input_bfd, val, relocation, howto) | 
|---|
| 3037 | bfd *input_bfd ATTRIBUTE_UNUSED; | 
|---|
| 3038 | bfd_vma val ATTRIBUTE_UNUSED; | 
|---|
| 3039 | bfd_vma relocation ATTRIBUTE_UNUSED; | 
|---|
| 3040 | struct reloc_howto_struct *howto ATTRIBUTE_UNUSED; | 
|---|
| 3041 | { | 
|---|
| 3042 | return FALSE; | 
|---|
| 3043 | } | 
|---|
| 3044 |  | 
|---|
| 3045 | static bfd_boolean | 
|---|
| 3046 | xcoff_complain_overflow_bitfield_func (input_bfd, val, relocation, howto) | 
|---|
| 3047 | bfd *input_bfd; | 
|---|
| 3048 | bfd_vma val; | 
|---|
| 3049 | bfd_vma relocation; | 
|---|
| 3050 | struct reloc_howto_struct *howto; | 
|---|
| 3051 | { | 
|---|
| 3052 | bfd_vma addrmask, fieldmask, signmask, ss; | 
|---|
| 3053 | bfd_vma a, b, sum; | 
|---|
| 3054 |  | 
|---|
| 3055 | /* Get the values to be added together.  For signed and unsigned | 
|---|
| 3056 | relocations, we assume that all values should be truncated to | 
|---|
| 3057 | the size of an address.  For bitfields, all the bits matter. | 
|---|
| 3058 | See also bfd_check_overflow.  */ | 
|---|
| 3059 | fieldmask = N_ONES (howto->bitsize); | 
|---|
| 3060 | addrmask = N_ONES (bfd_arch_bits_per_address (input_bfd)) | fieldmask; | 
|---|
| 3061 | a = relocation; | 
|---|
| 3062 | b = val & howto->src_mask; | 
|---|
| 3063 |  | 
|---|
| 3064 | /* Much like unsigned, except no trimming with addrmask.  In | 
|---|
| 3065 | addition, the sum overflows if there is a carry out of | 
|---|
| 3066 | the bfd_vma, i.e., the sum is less than either input | 
|---|
| 3067 | operand.  */ | 
|---|
| 3068 | a >>= howto->rightshift; | 
|---|
| 3069 | b >>= howto->bitpos; | 
|---|
| 3070 |  | 
|---|
| 3071 | /* Bitfields are sometimes used for signed numbers; for | 
|---|
| 3072 | example, a 13-bit field sometimes represents values in | 
|---|
| 3073 | 0..8191 and sometimes represents values in -4096..4095. | 
|---|
| 3074 | If the field is signed and a is -4095 (0x1001) and b is | 
|---|
| 3075 | -1 (0x1fff), the sum is -4096 (0x1000), but (0x1001 + | 
|---|
| 3076 | 0x1fff is 0x3000).  It's not clear how to handle this | 
|---|
| 3077 | everywhere, since there is not way to know how many bits | 
|---|
| 3078 | are significant in the relocation, but the original code | 
|---|
| 3079 | assumed that it was fully sign extended, and we will keep | 
|---|
| 3080 | that assumption.  */ | 
|---|
| 3081 | signmask = (fieldmask >> 1) + 1; | 
|---|
| 3082 |  | 
|---|
| 3083 | if ((a & ~ fieldmask) != 0) | 
|---|
| 3084 | { | 
|---|
| 3085 | /* Some bits out of the field are set.  This might not | 
|---|
| 3086 | be a problem: if this is a signed bitfield, it is OK | 
|---|
| 3087 | iff all the high bits are set, including the sign | 
|---|
| 3088 | bit.  We'll try setting all but the most significant | 
|---|
| 3089 | bit in the original relocation value: if this is all | 
|---|
| 3090 | ones, we are OK, assuming a signed bitfield.  */ | 
|---|
| 3091 | ss = (signmask << howto->rightshift) - 1; | 
|---|
| 3092 | if ((ss | relocation) != ~ (bfd_vma) 0) | 
|---|
| 3093 | return TRUE; | 
|---|
| 3094 | a &= fieldmask; | 
|---|
| 3095 | } | 
|---|
| 3096 |  | 
|---|
| 3097 | /* We just assume (b & ~ fieldmask) == 0.  */ | 
|---|
| 3098 |  | 
|---|
| 3099 | /* We explicitly permit wrap around if this relocation | 
|---|
| 3100 | covers the high bit of an address.  The Linux kernel | 
|---|
| 3101 | relies on it, and it is the only way to write assembler | 
|---|
| 3102 | code which can run when loaded at a location 0x80000000 | 
|---|
| 3103 | away from the location at which it is linked.  */ | 
|---|
| 3104 | if (howto->bitsize + howto->rightshift | 
|---|
| 3105 | == bfd_arch_bits_per_address (input_bfd)) | 
|---|
| 3106 | return FALSE; | 
|---|
| 3107 |  | 
|---|
| 3108 | sum = a + b; | 
|---|
| 3109 | if (sum < a || (sum & ~ fieldmask) != 0) | 
|---|
| 3110 | { | 
|---|
| 3111 | /* There was a carry out, or the field overflow.  Test | 
|---|
| 3112 | for signed operands again.  Here is the overflow test | 
|---|
| 3113 | is as for complain_overflow_signed.  */ | 
|---|
| 3114 | if (((~ (a ^ b)) & (a ^ sum)) & signmask) | 
|---|
| 3115 | return TRUE; | 
|---|
| 3116 | } | 
|---|
| 3117 |  | 
|---|
| 3118 | return FALSE; | 
|---|
| 3119 | } | 
|---|
| 3120 |  | 
|---|
| 3121 | static bfd_boolean | 
|---|
| 3122 | xcoff_complain_overflow_signed_func (input_bfd, val, relocation, howto) | 
|---|
| 3123 | bfd *input_bfd; | 
|---|
| 3124 | bfd_vma val; | 
|---|
| 3125 | bfd_vma relocation; | 
|---|
| 3126 | struct reloc_howto_struct *howto; | 
|---|
| 3127 | { | 
|---|
| 3128 | bfd_vma addrmask, fieldmask, signmask, ss; | 
|---|
| 3129 | bfd_vma a, b, sum; | 
|---|
| 3130 |  | 
|---|
| 3131 | /* Get the values to be added together.  For signed and unsigned | 
|---|
| 3132 | relocations, we assume that all values should be truncated to | 
|---|
| 3133 | the size of an address.  For bitfields, all the bits matter. | 
|---|
| 3134 | See also bfd_check_overflow.  */ | 
|---|
| 3135 | fieldmask = N_ONES (howto->bitsize); | 
|---|
| 3136 | addrmask = N_ONES (bfd_arch_bits_per_address (input_bfd)) | fieldmask; | 
|---|
| 3137 | a = relocation; | 
|---|
| 3138 | b = val & howto->src_mask; | 
|---|
| 3139 |  | 
|---|
| 3140 | a = (a & addrmask) >> howto->rightshift; | 
|---|
| 3141 |  | 
|---|
| 3142 | /* If any sign bits are set, all sign bits must be set. | 
|---|
| 3143 | That is, A must be a valid negative address after | 
|---|
| 3144 | shifting.  */ | 
|---|
| 3145 | signmask = ~ (fieldmask >> 1); | 
|---|
| 3146 | ss = a & signmask; | 
|---|
| 3147 | if (ss != 0 && ss != ((addrmask >> howto->rightshift) & signmask)) | 
|---|
| 3148 | return TRUE; | 
|---|
| 3149 |  | 
|---|
| 3150 | /* We only need this next bit of code if the sign bit of B | 
|---|
| 3151 | is below the sign bit of A.  This would only happen if | 
|---|
| 3152 | SRC_MASK had fewer bits than BITSIZE.  Note that if | 
|---|
| 3153 | SRC_MASK has more bits than BITSIZE, we can get into | 
|---|
| 3154 | trouble; we would need to verify that B is in range, as | 
|---|
| 3155 | we do for A above.  */ | 
|---|
| 3156 | signmask = ((~ howto->src_mask) >> 1) & howto->src_mask; | 
|---|
| 3157 | if ((b & signmask) != 0) | 
|---|
| 3158 | { | 
|---|
| 3159 | /* Set all the bits above the sign bit.  */ | 
|---|
| 3160 | b -= signmask <<= 1; | 
|---|
| 3161 | } | 
|---|
| 3162 |  | 
|---|
| 3163 | b = (b & addrmask) >> howto->bitpos; | 
|---|
| 3164 |  | 
|---|
| 3165 | /* Now we can do the addition.  */ | 
|---|
| 3166 | sum = a + b; | 
|---|
| 3167 |  | 
|---|
| 3168 | /* See if the result has the correct sign.  Bits above the | 
|---|
| 3169 | sign bit are junk now; ignore them.  If the sum is | 
|---|
| 3170 | positive, make sure we did not have all negative inputs; | 
|---|
| 3171 | if the sum is negative, make sure we did not have all | 
|---|
| 3172 | positive inputs.  The test below looks only at the sign | 
|---|
| 3173 | bits, and it really just | 
|---|
| 3174 | SIGN (A) == SIGN (B) && SIGN (A) != SIGN (SUM) | 
|---|
| 3175 | */ | 
|---|
| 3176 | signmask = (fieldmask >> 1) + 1; | 
|---|
| 3177 | if (((~ (a ^ b)) & (a ^ sum)) & signmask) | 
|---|
| 3178 | return TRUE; | 
|---|
| 3179 |  | 
|---|
| 3180 | return FALSE; | 
|---|
| 3181 | } | 
|---|
| 3182 |  | 
|---|
| 3183 | static bfd_boolean | 
|---|
| 3184 | xcoff_complain_overflow_unsigned_func (input_bfd, val, relocation, howto) | 
|---|
| 3185 | bfd *input_bfd; | 
|---|
| 3186 | bfd_vma val; | 
|---|
| 3187 | bfd_vma relocation; | 
|---|
| 3188 | struct reloc_howto_struct *howto; | 
|---|
| 3189 | { | 
|---|
| 3190 | bfd_vma addrmask, fieldmask; | 
|---|
| 3191 | bfd_vma a, b, sum; | 
|---|
| 3192 |  | 
|---|
| 3193 | /* Get the values to be added together.  For signed and unsigned | 
|---|
| 3194 | relocations, we assume that all values should be truncated to | 
|---|
| 3195 | the size of an address.  For bitfields, all the bits matter. | 
|---|
| 3196 | See also bfd_check_overflow.  */ | 
|---|
| 3197 | fieldmask = N_ONES (howto->bitsize); | 
|---|
| 3198 | addrmask = N_ONES (bfd_arch_bits_per_address (input_bfd)) | fieldmask; | 
|---|
| 3199 | a = relocation; | 
|---|
| 3200 | b = val & howto->src_mask; | 
|---|
| 3201 |  | 
|---|
| 3202 | /* Checking for an unsigned overflow is relatively easy: | 
|---|
| 3203 | trim the addresses and add, and trim the result as well. | 
|---|
| 3204 | Overflow is normally indicated when the result does not | 
|---|
| 3205 | fit in the field.  However, we also need to consider the | 
|---|
| 3206 | case when, e.g., fieldmask is 0x7fffffff or smaller, an | 
|---|
| 3207 | input is 0x80000000, and bfd_vma is only 32 bits; then we | 
|---|
| 3208 | will get sum == 0, but there is an overflow, since the | 
|---|
| 3209 | inputs did not fit in the field.  Instead of doing a | 
|---|
| 3210 | separate test, we can check for this by or-ing in the | 
|---|
| 3211 | operands when testing for the sum overflowing its final | 
|---|
| 3212 | field.  */ | 
|---|
| 3213 | a = (a & addrmask) >> howto->rightshift; | 
|---|
| 3214 | b = (b & addrmask) >> howto->bitpos; | 
|---|
| 3215 | sum = (a + b) & addrmask; | 
|---|
| 3216 | if ((a | b | sum) & ~ fieldmask) | 
|---|
| 3217 | return TRUE; | 
|---|
| 3218 |  | 
|---|
| 3219 | return FALSE; | 
|---|
| 3220 | } | 
|---|
| 3221 |  | 
|---|
| 3222 | /* This is the relocation function for the RS/6000/POWER/PowerPC. | 
|---|
| 3223 | This is currently the only processor which uses XCOFF; I hope that | 
|---|
| 3224 | will never change. | 
|---|
| 3225 |  | 
|---|
| 3226 | I took the relocation type definitions from two documents: | 
|---|
| 3227 | the PowerPC AIX Version 4 Application Binary Interface, First | 
|---|
| 3228 | Edition (April 1992), and the PowerOpen ABI, Big-Endian | 
|---|
| 3229 | 32-Bit Hardware Implementation (June 30, 1994).  Differences | 
|---|
| 3230 | between the documents are noted below. | 
|---|
| 3231 |  | 
|---|
| 3232 | Unsupported r_type's | 
|---|
| 3233 |  | 
|---|
| 3234 | R_RTB: | 
|---|
| 3235 | R_RRTBI: | 
|---|
| 3236 | R_RRTBA: | 
|---|
| 3237 |  | 
|---|
| 3238 | These relocs are defined by the PowerPC ABI to be | 
|---|
| 3239 | relative branches which use half of the difference | 
|---|
| 3240 | between the symbol and the program counter.  I can't | 
|---|
| 3241 | quite figure out when this is useful.  These relocs are | 
|---|
| 3242 | not defined by the PowerOpen ABI. | 
|---|
| 3243 |  | 
|---|
| 3244 | Supported r_type's | 
|---|
| 3245 |  | 
|---|
| 3246 | R_POS: | 
|---|
| 3247 | Simple positive relocation. | 
|---|
| 3248 |  | 
|---|
| 3249 | R_NEG: | 
|---|
| 3250 | Simple negative relocation. | 
|---|
| 3251 |  | 
|---|
| 3252 | R_REL: | 
|---|
| 3253 | Simple PC relative relocation. | 
|---|
| 3254 |  | 
|---|
| 3255 | R_TOC: | 
|---|
| 3256 | TOC relative relocation.  The value in the instruction in | 
|---|
| 3257 | the input file is the offset from the input file TOC to | 
|---|
| 3258 | the desired location.  We want the offset from the final | 
|---|
| 3259 | TOC to the desired location.  We have: | 
|---|
| 3260 | isym = iTOC + in | 
|---|
| 3261 | iinsn = in + o | 
|---|
| 3262 | osym = oTOC + on | 
|---|
| 3263 | oinsn = on + o | 
|---|
| 3264 | so we must change insn by on - in. | 
|---|
| 3265 |  | 
|---|
| 3266 | R_GL: | 
|---|
| 3267 | GL linkage relocation.  The value of this relocation | 
|---|
| 3268 | is the address of the entry in the TOC section. | 
|---|
| 3269 |  | 
|---|
| 3270 | R_TCL: | 
|---|
| 3271 | Local object TOC address.  I can't figure out the | 
|---|
| 3272 | difference between this and case R_GL. | 
|---|
| 3273 |  | 
|---|
| 3274 | R_TRL: | 
|---|
| 3275 | TOC relative relocation.  A TOC relative load instruction | 
|---|
| 3276 | which may be changed to a load address instruction. | 
|---|
| 3277 | FIXME: We don't currently implement this optimization. | 
|---|
| 3278 |  | 
|---|
| 3279 | R_TRLA: | 
|---|
| 3280 | TOC relative relocation.  This is a TOC relative load | 
|---|
| 3281 | address instruction which may be changed to a load | 
|---|
| 3282 | instruction.  FIXME: I don't know if this is the correct | 
|---|
| 3283 | implementation. | 
|---|
| 3284 |  | 
|---|
| 3285 | R_BA: | 
|---|
| 3286 | Absolute branch.  We don't want to mess with the lower | 
|---|
| 3287 | two bits of the instruction. | 
|---|
| 3288 |  | 
|---|
| 3289 | R_CAI: | 
|---|
| 3290 | The PowerPC ABI defines this as an absolute call which | 
|---|
| 3291 | may be modified to become a relative call.  The PowerOpen | 
|---|
| 3292 | ABI does not define this relocation type. | 
|---|
| 3293 |  | 
|---|
| 3294 | R_RBA: | 
|---|
| 3295 | Absolute branch which may be modified to become a | 
|---|
| 3296 | relative branch. | 
|---|
| 3297 |  | 
|---|
| 3298 | R_RBAC: | 
|---|
| 3299 | The PowerPC ABI defines this as an absolute branch to a | 
|---|
| 3300 | fixed address which may be modified to an absolute branch | 
|---|
| 3301 | to a symbol.  The PowerOpen ABI does not define this | 
|---|
| 3302 | relocation type. | 
|---|
| 3303 |  | 
|---|
| 3304 | R_RBRC: | 
|---|
| 3305 | The PowerPC ABI defines this as an absolute branch to a | 
|---|
| 3306 | fixed address which may be modified to a relative branch. | 
|---|
| 3307 | The PowerOpen ABI does not define this relocation type. | 
|---|
| 3308 |  | 
|---|
| 3309 | R_BR: | 
|---|
| 3310 | Relative branch.  We don't want to mess with the lower | 
|---|
| 3311 | two bits of the instruction. | 
|---|
| 3312 |  | 
|---|
| 3313 | R_CREL: | 
|---|
| 3314 | The PowerPC ABI defines this as a relative call which may | 
|---|
| 3315 | be modified to become an absolute call.  The PowerOpen | 
|---|
| 3316 | ABI does not define this relocation type. | 
|---|
| 3317 |  | 
|---|
| 3318 | R_RBR: | 
|---|
| 3319 | A relative branch which may be modified to become an | 
|---|
| 3320 | absolute branch.  FIXME: We don't implement this, | 
|---|
| 3321 | although we should for symbols of storage mapping class | 
|---|
| 3322 | XMC_XO. | 
|---|
| 3323 |  | 
|---|
| 3324 | R_RL: | 
|---|
| 3325 | The PowerPC AIX ABI describes this as a load which may be | 
|---|
| 3326 | changed to a load address.  The PowerOpen ABI says this | 
|---|
| 3327 | is the same as case R_POS. | 
|---|
| 3328 |  | 
|---|
| 3329 | R_RLA: | 
|---|
| 3330 | The PowerPC AIX ABI describes this as a load address | 
|---|
| 3331 | which may be changed to a load.  The PowerOpen ABI says | 
|---|
| 3332 | this is the same as R_POS. | 
|---|
| 3333 | */ | 
|---|
| 3334 |  | 
|---|
| 3335 | bfd_boolean | 
|---|
| 3336 | xcoff_ppc_relocate_section (output_bfd, info, input_bfd, | 
|---|
| 3337 | input_section, contents, relocs, syms, | 
|---|
| 3338 | sections) | 
|---|
| 3339 | bfd *output_bfd; | 
|---|
| 3340 | struct bfd_link_info *info; | 
|---|
| 3341 | bfd *input_bfd; | 
|---|
| 3342 | asection *input_section; | 
|---|
| 3343 | bfd_byte *contents; | 
|---|
| 3344 | struct internal_reloc *relocs; | 
|---|
| 3345 | struct internal_syment *syms; | 
|---|
| 3346 | asection **sections; | 
|---|
| 3347 | { | 
|---|
| 3348 | struct internal_reloc *rel; | 
|---|
| 3349 | struct internal_reloc *relend; | 
|---|
| 3350 |  | 
|---|
| 3351 | rel = relocs; | 
|---|
| 3352 | relend = rel + input_section->reloc_count; | 
|---|
| 3353 | for (; rel < relend; rel++) | 
|---|
| 3354 | { | 
|---|
| 3355 | long symndx; | 
|---|
| 3356 | struct xcoff_link_hash_entry *h; | 
|---|
| 3357 | struct internal_syment *sym; | 
|---|
| 3358 | bfd_vma addend; | 
|---|
| 3359 | bfd_vma val; | 
|---|
| 3360 | struct reloc_howto_struct howto; | 
|---|
| 3361 | bfd_vma relocation; | 
|---|
| 3362 | bfd_vma value_to_relocate; | 
|---|
| 3363 | bfd_vma address; | 
|---|
| 3364 | bfd_byte *location; | 
|---|
| 3365 |  | 
|---|
| 3366 | /* Relocation type R_REF is a special relocation type which is | 
|---|
| 3367 | merely used to prevent garbage collection from occurring for | 
|---|
| 3368 | the csect including the symbol which it references.  */ | 
|---|
| 3369 | if (rel->r_type == R_REF) | 
|---|
| 3370 | continue; | 
|---|
| 3371 |  | 
|---|
| 3372 | /* howto */ | 
|---|
| 3373 | howto.type = rel->r_type; | 
|---|
| 3374 | howto.rightshift = 0; | 
|---|
| 3375 | howto.bitsize = (rel->r_size & 0x1f) + 1; | 
|---|
| 3376 | howto.size = howto.bitsize > 16 ? 2 : 1; | 
|---|
| 3377 | howto.pc_relative = FALSE; | 
|---|
| 3378 | howto.bitpos = 0; | 
|---|
| 3379 | howto.complain_on_overflow = (rel->r_size & 0x80 | 
|---|
| 3380 | ? complain_overflow_signed | 
|---|
| 3381 | : complain_overflow_bitfield); | 
|---|
| 3382 | howto.special_function = NULL; | 
|---|
| 3383 | howto.name = "internal"; | 
|---|
| 3384 | howto.partial_inplace = TRUE; | 
|---|
| 3385 | howto.src_mask = howto.dst_mask = N_ONES (howto.bitsize); | 
|---|
| 3386 | howto.pcrel_offset = FALSE; | 
|---|
| 3387 |  | 
|---|
| 3388 | /* symbol */ | 
|---|
| 3389 | val = 0; | 
|---|
| 3390 | addend = 0; | 
|---|
| 3391 | h = NULL; | 
|---|
| 3392 | sym = NULL; | 
|---|
| 3393 | symndx = rel->r_symndx; | 
|---|
| 3394 |  | 
|---|
| 3395 | if (-1 != symndx) | 
|---|
| 3396 | { | 
|---|
| 3397 | asection *sec; | 
|---|
| 3398 |  | 
|---|
| 3399 | h = obj_xcoff_sym_hashes (input_bfd)[symndx]; | 
|---|
| 3400 | sym = syms + symndx; | 
|---|
| 3401 | addend = - sym->n_value; | 
|---|
| 3402 |  | 
|---|
| 3403 | if (NULL == h) | 
|---|
| 3404 | { | 
|---|
| 3405 | sec = sections[symndx]; | 
|---|
| 3406 | /* Hack to make sure we use the right TOC anchor value | 
|---|
| 3407 | if this reloc is against the TOC anchor.  */ | 
|---|
| 3408 | if (sec->name[3] == '0' | 
|---|
| 3409 | && strcmp (sec->name, ".tc0") == 0) | 
|---|
| 3410 | val = xcoff_data (output_bfd)->toc; | 
|---|
| 3411 | else | 
|---|
| 3412 | val = (sec->output_section->vma | 
|---|
| 3413 | + sec->output_offset | 
|---|
| 3414 | + sym->n_value | 
|---|
| 3415 | - sec->vma); | 
|---|
| 3416 | } | 
|---|
| 3417 | else | 
|---|
| 3418 | { | 
|---|
| 3419 | if (h->root.type == bfd_link_hash_defined | 
|---|
| 3420 | || h->root.type == bfd_link_hash_defweak) | 
|---|
| 3421 | { | 
|---|
| 3422 | sec = h->root.u.def.section; | 
|---|
| 3423 | val = (h->root.u.def.value | 
|---|
| 3424 | + sec->output_section->vma | 
|---|
| 3425 | + sec->output_offset); | 
|---|
| 3426 | } | 
|---|
| 3427 | else if (h->root.type == bfd_link_hash_common) | 
|---|
| 3428 | { | 
|---|
| 3429 | sec = h->root.u.c.p->section; | 
|---|
| 3430 | val = (sec->output_section->vma | 
|---|
| 3431 | + sec->output_offset); | 
|---|
| 3432 |  | 
|---|
| 3433 | } | 
|---|
| 3434 | else if ((0 == (h->flags & (XCOFF_DEF_DYNAMIC | XCOFF_IMPORT))) | 
|---|
| 3435 | && ! info->relocateable) | 
|---|
| 3436 | { | 
|---|
| 3437 | if (! ((*info->callbacks->undefined_symbol) | 
|---|
| 3438 | (info, h->root.root.string, input_bfd, input_section, | 
|---|
| 3439 | rel->r_vaddr - input_section->vma, TRUE))) | 
|---|
| 3440 | return FALSE; | 
|---|
| 3441 |  | 
|---|
| 3442 | /* Don't try to process the reloc.  It can't help, and | 
|---|
| 3443 | it may generate another error.  */ | 
|---|
| 3444 | continue; | 
|---|
| 3445 | } | 
|---|
| 3446 | } | 
|---|
| 3447 | } | 
|---|
| 3448 |  | 
|---|
| 3449 | if (rel->r_type >= XCOFF_MAX_CALCULATE_RELOCATION | 
|---|
| 3450 | || !((*xcoff_calculate_relocation[rel->r_type]) | 
|---|
| 3451 | (input_bfd, input_section, output_bfd, rel, sym, &howto, val, | 
|---|
| 3452 | addend, &relocation, contents))) | 
|---|
| 3453 | return FALSE; | 
|---|
| 3454 |  | 
|---|
| 3455 | /* address */ | 
|---|
| 3456 | address = rel->r_vaddr - input_section->vma; | 
|---|
| 3457 | location = contents + address; | 
|---|
| 3458 |  | 
|---|
| 3459 | if (address > input_section->_raw_size) | 
|---|
| 3460 | abort (); | 
|---|
| 3461 |  | 
|---|
| 3462 | /* Get the value we are going to relocate.  */ | 
|---|
| 3463 | if (1 == howto.size) | 
|---|
| 3464 | value_to_relocate = bfd_get_16 (input_bfd, location); | 
|---|
| 3465 | else | 
|---|
| 3466 | value_to_relocate = bfd_get_32 (input_bfd, location); | 
|---|
| 3467 |  | 
|---|
| 3468 | /* overflow. | 
|---|
| 3469 |  | 
|---|
| 3470 | FIXME: We may drop bits during the addition | 
|---|
| 3471 | which we don't check for.  We must either check at every single | 
|---|
| 3472 | operation, which would be tedious, or we must do the computations | 
|---|
| 3473 | in a type larger than bfd_vma, which would be inefficient.  */ | 
|---|
| 3474 |  | 
|---|
| 3475 | if ((unsigned int) howto.complain_on_overflow | 
|---|
| 3476 | >= XCOFF_MAX_COMPLAIN_OVERFLOW) | 
|---|
| 3477 | abort (); | 
|---|
| 3478 |  | 
|---|
| 3479 | if (((*xcoff_complain_overflow[howto.complain_on_overflow]) | 
|---|
| 3480 | (input_bfd, value_to_relocate, relocation, &howto))) | 
|---|
| 3481 | { | 
|---|
| 3482 | const char *name; | 
|---|
| 3483 | char buf[SYMNMLEN + 1]; | 
|---|
| 3484 | char reloc_type_name[10]; | 
|---|
| 3485 |  | 
|---|
| 3486 | if (symndx == -1) | 
|---|
| 3487 | { | 
|---|
| 3488 | name = "*ABS*"; | 
|---|
| 3489 | } | 
|---|
| 3490 | else if (h != NULL) | 
|---|
| 3491 | { | 
|---|
| 3492 | name = h->root.root.string; | 
|---|
| 3493 | } | 
|---|
| 3494 | else | 
|---|
| 3495 | { | 
|---|
| 3496 | name = _bfd_coff_internal_syment_name (input_bfd, sym, buf); | 
|---|
| 3497 | if (name == NULL) | 
|---|
| 3498 | name = "UNKNOWN"; | 
|---|
| 3499 | } | 
|---|
| 3500 | sprintf (reloc_type_name, "0x%02x", rel->r_type); | 
|---|
| 3501 |  | 
|---|
| 3502 | if (! ((*info->callbacks->reloc_overflow) | 
|---|
| 3503 | (info, name, reloc_type_name, (bfd_vma) 0, input_bfd, | 
|---|
| 3504 | input_section, rel->r_vaddr - input_section->vma))) | 
|---|
| 3505 | return FALSE; | 
|---|
| 3506 | } | 
|---|
| 3507 |  | 
|---|
| 3508 | /* Add RELOCATION to the right bits of VALUE_TO_RELOCATE.  */ | 
|---|
| 3509 | value_to_relocate = ((value_to_relocate & ~howto.dst_mask) | 
|---|
| 3510 | | (((value_to_relocate & howto.src_mask) | 
|---|
| 3511 | + relocation) & howto.dst_mask)); | 
|---|
| 3512 |  | 
|---|
| 3513 | /* Put the value back in the object file.  */ | 
|---|
| 3514 | if (1 == howto.size) | 
|---|
| 3515 | bfd_put_16 (input_bfd, value_to_relocate, location); | 
|---|
| 3516 | else | 
|---|
| 3517 | bfd_put_32 (input_bfd, value_to_relocate, location); | 
|---|
| 3518 | } | 
|---|
| 3519 |  | 
|---|
| 3520 | return TRUE; | 
|---|
| 3521 | } | 
|---|
| 3522 |  | 
|---|
| 3523 | static bfd_boolean | 
|---|
| 3524 | _bfd_xcoff_put_ldsymbol_name (abfd, ldinfo, ldsym, name) | 
|---|
| 3525 | bfd *abfd ATTRIBUTE_UNUSED; | 
|---|
| 3526 | struct xcoff_loader_info *ldinfo; | 
|---|
| 3527 | struct internal_ldsym *ldsym; | 
|---|
| 3528 | const char *name; | 
|---|
| 3529 | { | 
|---|
| 3530 | size_t len; | 
|---|
| 3531 | len = strlen (name); | 
|---|
| 3532 |  | 
|---|
| 3533 | if (len <= SYMNMLEN) | 
|---|
| 3534 | strncpy (ldsym->_l._l_name, name, SYMNMLEN); | 
|---|
| 3535 | else | 
|---|
| 3536 | { | 
|---|
| 3537 | if (ldinfo->string_size + len + 3 > ldinfo->string_alc) | 
|---|
| 3538 | { | 
|---|
| 3539 | bfd_size_type newalc; | 
|---|
| 3540 | bfd_byte *newstrings; | 
|---|
| 3541 |  | 
|---|
| 3542 | newalc = ldinfo->string_alc * 2; | 
|---|
| 3543 | if (newalc == 0) | 
|---|
| 3544 | newalc = 32; | 
|---|
| 3545 | while (ldinfo->string_size + len + 3 > newalc) | 
|---|
| 3546 | newalc *= 2; | 
|---|
| 3547 |  | 
|---|
| 3548 | newstrings = ((bfd_byte *) | 
|---|
| 3549 | bfd_realloc ((PTR) ldinfo->strings, newalc)); | 
|---|
| 3550 | if (newstrings == NULL) | 
|---|
| 3551 | { | 
|---|
| 3552 | ldinfo->failed = TRUE; | 
|---|
| 3553 | return FALSE; | 
|---|
| 3554 | } | 
|---|
| 3555 | ldinfo->string_alc = newalc; | 
|---|
| 3556 | ldinfo->strings = newstrings; | 
|---|
| 3557 | } | 
|---|
| 3558 |  | 
|---|
| 3559 | bfd_put_16 (ldinfo->output_bfd, (bfd_vma) (len + 1), | 
|---|
| 3560 | ldinfo->strings + ldinfo->string_size); | 
|---|
| 3561 | strcpy (ldinfo->strings + ldinfo->string_size + 2, name); | 
|---|
| 3562 | ldsym->_l._l_l._l_zeroes = 0; | 
|---|
| 3563 | ldsym->_l._l_l._l_offset = ldinfo->string_size + 2; | 
|---|
| 3564 | ldinfo->string_size += len + 3; | 
|---|
| 3565 | } | 
|---|
| 3566 |  | 
|---|
| 3567 | return TRUE; | 
|---|
| 3568 | } | 
|---|
| 3569 |  | 
|---|
| 3570 | static bfd_boolean | 
|---|
| 3571 | _bfd_xcoff_put_symbol_name (bfd *abfd, struct bfd_strtab_hash *strtab, | 
|---|
| 3572 | struct internal_syment *sym, | 
|---|
| 3573 | const char *name) | 
|---|
| 3574 | { | 
|---|
| 3575 | if (strlen (name) <= SYMNMLEN) | 
|---|
| 3576 | { | 
|---|
| 3577 | strncpy (sym->_n._n_name, name, SYMNMLEN); | 
|---|
| 3578 | } | 
|---|
| 3579 | else | 
|---|
| 3580 | { | 
|---|
| 3581 | bfd_boolean hash; | 
|---|
| 3582 | bfd_size_type indx; | 
|---|
| 3583 |  | 
|---|
| 3584 | hash = TRUE; | 
|---|
| 3585 | if ((abfd->flags & BFD_TRADITIONAL_FORMAT) != 0) | 
|---|
| 3586 | hash = FALSE; | 
|---|
| 3587 | indx = _bfd_stringtab_add (strtab, name, hash, FALSE); | 
|---|
| 3588 | if (indx == (bfd_size_type) -1) | 
|---|
| 3589 | return FALSE; | 
|---|
| 3590 | sym->_n._n_n._n_zeroes = 0; | 
|---|
| 3591 | sym->_n._n_n._n_offset = STRING_SIZE_SIZE + indx; | 
|---|
| 3592 | } | 
|---|
| 3593 | return TRUE; | 
|---|
| 3594 | } | 
|---|
| 3595 |  | 
|---|
| 3596 | static asection * | 
|---|
| 3597 | xcoff_create_csect_from_smclas (abfd, aux, symbol_name) | 
|---|
| 3598 | bfd *abfd; | 
|---|
| 3599 | union internal_auxent *aux; | 
|---|
| 3600 | const char *symbol_name; | 
|---|
| 3601 | { | 
|---|
| 3602 | asection *return_value = NULL; | 
|---|
| 3603 |  | 
|---|
| 3604 | /* .sv64 = x_smclas == 17 | 
|---|
| 3605 | This is an invalid csect for 32 bit apps.  */ | 
|---|
| 3606 | static const char *names[19] = | 
|---|
| 3607 | { | 
|---|
| 3608 | ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo", | 
|---|
| 3609 | ".sv", ".bs", ".ds", ".uc", ".ti", ".tb", NULL, ".tc0", | 
|---|
| 3610 | ".td", NULL, ".sv3264" | 
|---|
| 3611 | }; | 
|---|
| 3612 |  | 
|---|
| 3613 | if ((19 >= aux->x_csect.x_smclas) | 
|---|
| 3614 | && (NULL != names[aux->x_csect.x_smclas])) | 
|---|
| 3615 | { | 
|---|
| 3616 | return_value = bfd_make_section_anyway | 
|---|
| 3617 | (abfd, names[aux->x_csect.x_smclas]); | 
|---|
| 3618 | } | 
|---|
| 3619 | else | 
|---|
| 3620 | { | 
|---|
| 3621 | (*_bfd_error_handler) | 
|---|
| 3622 | (_("%s: symbol `%s' has unrecognized smclas %d"), | 
|---|
| 3623 | bfd_archive_filename (abfd), symbol_name, aux->x_csect.x_smclas); | 
|---|
| 3624 | bfd_set_error (bfd_error_bad_value); | 
|---|
| 3625 | } | 
|---|
| 3626 |  | 
|---|
| 3627 | return return_value; | 
|---|
| 3628 | } | 
|---|
| 3629 |  | 
|---|
| 3630 | static bfd_boolean | 
|---|
| 3631 | xcoff_is_lineno_count_overflow (abfd, value) | 
|---|
| 3632 | bfd *abfd ATTRIBUTE_UNUSED; | 
|---|
| 3633 | bfd_vma value; | 
|---|
| 3634 | { | 
|---|
| 3635 | if (0xffff <= value) | 
|---|
| 3636 | return TRUE; | 
|---|
| 3637 |  | 
|---|
| 3638 | return FALSE; | 
|---|
| 3639 | } | 
|---|
| 3640 |  | 
|---|
| 3641 | static bfd_boolean | 
|---|
| 3642 | xcoff_is_reloc_count_overflow (abfd, value) | 
|---|
| 3643 | bfd *abfd ATTRIBUTE_UNUSED; | 
|---|
| 3644 | bfd_vma value; | 
|---|
| 3645 | { | 
|---|
| 3646 | if (0xffff <= value) | 
|---|
| 3647 | return TRUE; | 
|---|
| 3648 |  | 
|---|
| 3649 | return FALSE; | 
|---|
| 3650 | } | 
|---|
| 3651 |  | 
|---|
| 3652 | static bfd_vma | 
|---|
| 3653 | xcoff_loader_symbol_offset (abfd, ldhdr) | 
|---|
| 3654 | bfd *abfd; | 
|---|
| 3655 | struct internal_ldhdr *ldhdr ATTRIBUTE_UNUSED; | 
|---|
| 3656 | { | 
|---|
| 3657 | return bfd_xcoff_ldhdrsz (abfd); | 
|---|
| 3658 | } | 
|---|
| 3659 |  | 
|---|
| 3660 | static bfd_vma | 
|---|
| 3661 | xcoff_loader_reloc_offset (abfd, ldhdr) | 
|---|
| 3662 | bfd *abfd; | 
|---|
| 3663 | struct internal_ldhdr *ldhdr; | 
|---|
| 3664 | { | 
|---|
| 3665 | return bfd_xcoff_ldhdrsz (abfd) + ldhdr->l_nsyms * bfd_xcoff_ldsymsz (abfd); | 
|---|
| 3666 | } | 
|---|
| 3667 |  | 
|---|
| 3668 | static bfd_boolean | 
|---|
| 3669 | xcoff_generate_rtinit  (abfd, init, fini, rtld) | 
|---|
| 3670 | bfd *abfd; | 
|---|
| 3671 | const char *init; | 
|---|
| 3672 | const char *fini; | 
|---|
| 3673 | bfd_boolean rtld; | 
|---|
| 3674 | { | 
|---|
| 3675 | bfd_byte filehdr_ext[FILHSZ]; | 
|---|
| 3676 | bfd_byte scnhdr_ext[SCNHSZ]; | 
|---|
| 3677 | bfd_byte syment_ext[SYMESZ * 10]; | 
|---|
| 3678 | bfd_byte reloc_ext[RELSZ * 3]; | 
|---|
| 3679 | bfd_byte *data_buffer; | 
|---|
| 3680 | bfd_size_type data_buffer_size; | 
|---|
| 3681 | bfd_byte *string_table = NULL, *st_tmp = NULL; | 
|---|
| 3682 | bfd_size_type string_table_size; | 
|---|
| 3683 | bfd_vma val; | 
|---|
| 3684 | size_t initsz, finisz; | 
|---|
| 3685 | struct internal_filehdr filehdr; | 
|---|
| 3686 | struct internal_scnhdr scnhdr; | 
|---|
| 3687 | struct internal_syment syment; | 
|---|
| 3688 | union internal_auxent auxent; | 
|---|
| 3689 | struct internal_reloc reloc; | 
|---|
| 3690 |  | 
|---|
| 3691 | char *data_name = ".data"; | 
|---|
| 3692 | char *rtinit_name = "__rtinit"; | 
|---|
| 3693 | char *rtld_name = "__rtld"; | 
|---|
| 3694 |  | 
|---|
| 3695 | if (! bfd_xcoff_rtinit_size (abfd)) | 
|---|
| 3696 | return FALSE; | 
|---|
| 3697 |  | 
|---|
| 3698 | initsz = (init == NULL ? 0 : 1 + strlen (init)); | 
|---|
| 3699 | finisz = (fini == NULL ? 0 : 1 + strlen (fini)); | 
|---|
| 3700 |  | 
|---|
| 3701 | /* file header */ | 
|---|
| 3702 | memset (filehdr_ext, 0, FILHSZ); | 
|---|
| 3703 | memset (&filehdr, 0, sizeof (struct internal_filehdr)); | 
|---|
| 3704 | filehdr.f_magic = bfd_xcoff_magic_number (abfd); | 
|---|
| 3705 | filehdr.f_nscns = 1; | 
|---|
| 3706 | filehdr.f_timdat = 0; | 
|---|
| 3707 | filehdr.f_nsyms = 0;  /* at least 6, no more than 10 */ | 
|---|
| 3708 | filehdr.f_symptr = 0; /* set below */ | 
|---|
| 3709 | filehdr.f_opthdr = 0; | 
|---|
| 3710 | filehdr.f_flags = 0; | 
|---|
| 3711 |  | 
|---|
| 3712 | /* section header */ | 
|---|
| 3713 | memset (scnhdr_ext, 0, SCNHSZ); | 
|---|
| 3714 | memset (&scnhdr, 0, sizeof (struct internal_scnhdr)); | 
|---|
| 3715 | memcpy (scnhdr.s_name, data_name, strlen (data_name)); | 
|---|
| 3716 | scnhdr.s_paddr = 0; | 
|---|
| 3717 | scnhdr.s_vaddr = 0; | 
|---|
| 3718 | scnhdr.s_size = 0;    /* set below */ | 
|---|
| 3719 | scnhdr.s_scnptr = FILHSZ + SCNHSZ; | 
|---|
| 3720 | scnhdr.s_relptr = 0;  /* set below */ | 
|---|
| 3721 | scnhdr.s_lnnoptr = 0; | 
|---|
| 3722 | scnhdr.s_nreloc = 0;  /* either 1 or 2 */ | 
|---|
| 3723 | scnhdr.s_nlnno = 0; | 
|---|
| 3724 | scnhdr.s_flags = STYP_DATA; | 
|---|
| 3725 |  | 
|---|
| 3726 | /* .data | 
|---|
| 3727 | 0x0000           0x00000000 : rtl | 
|---|
| 3728 | 0x0004           0x00000010 : offset to init, or 0 | 
|---|
| 3729 | 0x0008           0x00000028 : offset to fini, or 0 | 
|---|
| 3730 | 0x000C           0x0000000C : size of descriptor | 
|---|
| 3731 | 0x0010           0x00000000 : init, needs a reloc | 
|---|
| 3732 | 0x0014           0x00000040 : offset to init name | 
|---|
| 3733 | 0x0018           0x00000000 : flags, padded to a word | 
|---|
| 3734 | 0x001C           0x00000000 : empty init | 
|---|
| 3735 | 0x0020           0x00000000 : | 
|---|
| 3736 | 0x0024           0x00000000 : | 
|---|
| 3737 | 0x0028           0x00000000 : fini, needs a reloc | 
|---|
| 3738 | 0x002C           0x00000??? : offset to fini name | 
|---|
| 3739 | 0x0030           0x00000000 : flags, padded to a word | 
|---|
| 3740 | 0x0034           0x00000000 : empty fini | 
|---|
| 3741 | 0x0038           0x00000000 : | 
|---|
| 3742 | 0x003C           0x00000000 : | 
|---|
| 3743 | 0x0040           init name | 
|---|
| 3744 | 0x0040 + initsz  fini name */ | 
|---|
| 3745 |  | 
|---|
| 3746 | data_buffer_size = 0x0040 + initsz + finisz; | 
|---|
| 3747 | data_buffer_size = (data_buffer_size + 7) &~ (bfd_size_type) 7; | 
|---|
| 3748 | data_buffer = NULL; | 
|---|
| 3749 | data_buffer = (bfd_byte *) bfd_zmalloc (data_buffer_size); | 
|---|
| 3750 | if (data_buffer == NULL) | 
|---|
| 3751 | return FALSE; | 
|---|
| 3752 |  | 
|---|
| 3753 | if (initsz) | 
|---|
| 3754 | { | 
|---|
| 3755 | val = 0x10; | 
|---|
| 3756 | bfd_h_put_32 (abfd, val, &data_buffer[0x04]); | 
|---|
| 3757 | val = 0x40; | 
|---|
| 3758 | bfd_h_put_32 (abfd, val, &data_buffer[0x14]); | 
|---|
| 3759 | memcpy (&data_buffer[val], init, initsz); | 
|---|
| 3760 | } | 
|---|
| 3761 |  | 
|---|
| 3762 | if (finisz) | 
|---|
| 3763 | { | 
|---|
| 3764 | val = 0x28; | 
|---|
| 3765 | bfd_h_put_32 (abfd, val, &data_buffer[0x08]); | 
|---|
| 3766 | val = 0x40 + initsz; | 
|---|
| 3767 | bfd_h_put_32 (abfd, val, &data_buffer[0x2C]); | 
|---|
| 3768 | memcpy (&data_buffer[val], fini, finisz); | 
|---|
| 3769 | } | 
|---|
| 3770 |  | 
|---|
| 3771 | val = 0x0C; | 
|---|
| 3772 | bfd_h_put_32 (abfd, val, &data_buffer[0x0C]); | 
|---|
| 3773 |  | 
|---|
| 3774 | scnhdr.s_size = data_buffer_size; | 
|---|
| 3775 |  | 
|---|
| 3776 | /* string table */ | 
|---|
| 3777 | string_table_size = 0; | 
|---|
| 3778 | if (initsz > 9) | 
|---|
| 3779 | string_table_size += initsz; | 
|---|
| 3780 | if (finisz > 9) | 
|---|
| 3781 | string_table_size += finisz; | 
|---|
| 3782 | if (string_table_size) | 
|---|
| 3783 | { | 
|---|
| 3784 | string_table_size += 4; | 
|---|
| 3785 | string_table = (bfd_byte *) bfd_zmalloc (string_table_size); | 
|---|
| 3786 | if (string_table == NULL) | 
|---|
| 3787 | return FALSE; | 
|---|
| 3788 |  | 
|---|
| 3789 | val = string_table_size; | 
|---|
| 3790 | bfd_h_put_32 (abfd, val, &string_table[0]); | 
|---|
| 3791 | st_tmp = string_table + 4; | 
|---|
| 3792 | } | 
|---|
| 3793 |  | 
|---|
| 3794 | /* symbols | 
|---|
| 3795 | 0. .data csect | 
|---|
| 3796 | 2. __rtinit | 
|---|
| 3797 | 4. init function | 
|---|
| 3798 | 6. fini function | 
|---|
| 3799 | 8. __rtld  */ | 
|---|
| 3800 | memset (syment_ext, 0, 10 * SYMESZ); | 
|---|
| 3801 | memset (reloc_ext, 0, 3 * RELSZ); | 
|---|
| 3802 |  | 
|---|
| 3803 | /* .data csect */ | 
|---|
| 3804 | memset (&syment, 0, sizeof (struct internal_syment)); | 
|---|
| 3805 | memset (&auxent, 0, sizeof (union internal_auxent)); | 
|---|
| 3806 | memcpy (syment._n._n_name, data_name, strlen (data_name)); | 
|---|
| 3807 | syment.n_scnum = 1; | 
|---|
| 3808 | syment.n_sclass = C_HIDEXT; | 
|---|
| 3809 | syment.n_numaux = 1; | 
|---|
| 3810 | auxent.x_csect.x_scnlen.l = data_buffer_size; | 
|---|
| 3811 | auxent.x_csect.x_smtyp = 3 << 3 | XTY_SD; | 
|---|
| 3812 | auxent.x_csect.x_smclas = XMC_RW; | 
|---|
| 3813 | bfd_coff_swap_sym_out (abfd, &syment, | 
|---|
| 3814 | &syment_ext[filehdr.f_nsyms * SYMESZ]); | 
|---|
| 3815 | bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0, | 
|---|
| 3816 | syment.n_numaux, | 
|---|
| 3817 | &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]); | 
|---|
| 3818 | filehdr.f_nsyms += 2; | 
|---|
| 3819 |  | 
|---|
| 3820 | /* __rtinit */ | 
|---|
| 3821 | memset (&syment, 0, sizeof (struct internal_syment)); | 
|---|
| 3822 | memset (&auxent, 0, sizeof (union internal_auxent)); | 
|---|
| 3823 | memcpy (syment._n._n_name, rtinit_name, strlen (rtinit_name)); | 
|---|
| 3824 | syment.n_scnum = 1; | 
|---|
| 3825 | syment.n_sclass = C_EXT; | 
|---|
| 3826 | syment.n_numaux = 1; | 
|---|
| 3827 | auxent.x_csect.x_smtyp = XTY_LD; | 
|---|
| 3828 | auxent.x_csect.x_smclas = XMC_RW; | 
|---|
| 3829 | bfd_coff_swap_sym_out (abfd, &syment, | 
|---|
| 3830 | &syment_ext[filehdr.f_nsyms * SYMESZ]); | 
|---|
| 3831 | bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0, | 
|---|
| 3832 | syment.n_numaux, | 
|---|
| 3833 | &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]); | 
|---|
| 3834 | filehdr.f_nsyms += 2; | 
|---|
| 3835 |  | 
|---|
| 3836 | /* init */ | 
|---|
| 3837 | if (initsz) | 
|---|
| 3838 | { | 
|---|
| 3839 | memset (&syment, 0, sizeof (struct internal_syment)); | 
|---|
| 3840 | memset (&auxent, 0, sizeof (union internal_auxent)); | 
|---|
| 3841 |  | 
|---|
| 3842 | if (initsz > 9) | 
|---|
| 3843 | { | 
|---|
| 3844 | syment._n._n_n._n_offset = st_tmp - string_table; | 
|---|
| 3845 | memcpy (st_tmp, init, initsz); | 
|---|
| 3846 | st_tmp += initsz; | 
|---|
| 3847 | } | 
|---|
| 3848 | else | 
|---|
| 3849 | memcpy (syment._n._n_name, init, initsz - 1); | 
|---|
| 3850 |  | 
|---|
| 3851 | syment.n_sclass = C_EXT; | 
|---|
| 3852 | syment.n_numaux = 1; | 
|---|
| 3853 | bfd_coff_swap_sym_out (abfd, &syment, | 
|---|
| 3854 | &syment_ext[filehdr.f_nsyms * SYMESZ]); | 
|---|
| 3855 | bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0, | 
|---|
| 3856 | syment.n_numaux, | 
|---|
| 3857 | &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]); | 
|---|
| 3858 |  | 
|---|
| 3859 | /* reloc */ | 
|---|
| 3860 | memset (&reloc, 0, sizeof (struct internal_reloc)); | 
|---|
| 3861 | reloc.r_vaddr = 0x0010; | 
|---|
| 3862 | reloc.r_symndx = filehdr.f_nsyms; | 
|---|
| 3863 | reloc.r_type = R_POS; | 
|---|
| 3864 | reloc.r_size = 31; | 
|---|
| 3865 | bfd_coff_swap_reloc_out (abfd, &reloc, &reloc_ext[0]); | 
|---|
| 3866 |  | 
|---|
| 3867 | filehdr.f_nsyms += 2; | 
|---|
| 3868 | scnhdr.s_nreloc += 1; | 
|---|
| 3869 | } | 
|---|
| 3870 |  | 
|---|
| 3871 | /* fini */ | 
|---|
| 3872 | if (finisz) | 
|---|
| 3873 | { | 
|---|
| 3874 | memset (&syment, 0, sizeof (struct internal_syment)); | 
|---|
| 3875 | memset (&auxent, 0, sizeof (union internal_auxent)); | 
|---|
| 3876 |  | 
|---|
| 3877 | if (finisz > 9) | 
|---|
| 3878 | { | 
|---|
| 3879 | syment._n._n_n._n_offset = st_tmp - string_table; | 
|---|
| 3880 | memcpy (st_tmp, fini, finisz); | 
|---|
| 3881 | st_tmp += finisz; | 
|---|
| 3882 | } | 
|---|
| 3883 | else | 
|---|
| 3884 | memcpy (syment._n._n_name, fini, finisz - 1); | 
|---|
| 3885 |  | 
|---|
| 3886 | syment.n_sclass = C_EXT; | 
|---|
| 3887 | syment.n_numaux = 1; | 
|---|
| 3888 | bfd_coff_swap_sym_out (abfd, &syment, | 
|---|
| 3889 | &syment_ext[filehdr.f_nsyms * SYMESZ]); | 
|---|
| 3890 | bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0, | 
|---|
| 3891 | syment.n_numaux, | 
|---|
| 3892 | &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]); | 
|---|
| 3893 |  | 
|---|
| 3894 | /* reloc */ | 
|---|
| 3895 | memset (&reloc, 0, sizeof (struct internal_reloc)); | 
|---|
| 3896 | reloc.r_vaddr = 0x0028; | 
|---|
| 3897 | reloc.r_symndx = filehdr.f_nsyms; | 
|---|
| 3898 | reloc.r_type = R_POS; | 
|---|
| 3899 | reloc.r_size = 31; | 
|---|
| 3900 | bfd_coff_swap_reloc_out (abfd, &reloc, | 
|---|
| 3901 | &reloc_ext[scnhdr.s_nreloc * RELSZ]); | 
|---|
| 3902 |  | 
|---|
| 3903 | filehdr.f_nsyms += 2; | 
|---|
| 3904 | scnhdr.s_nreloc += 1; | 
|---|
| 3905 | } | 
|---|
| 3906 |  | 
|---|
| 3907 | if (rtld) | 
|---|
| 3908 | { | 
|---|
| 3909 | memset (&syment, 0, sizeof (struct internal_syment)); | 
|---|
| 3910 | memset (&auxent, 0, sizeof (union internal_auxent)); | 
|---|
| 3911 | memcpy (syment._n._n_name, rtld_name, strlen (rtld_name)); | 
|---|
| 3912 | syment.n_sclass = C_EXT; | 
|---|
| 3913 | syment.n_numaux = 1; | 
|---|
| 3914 | bfd_coff_swap_sym_out (abfd, &syment, | 
|---|
| 3915 | &syment_ext[filehdr.f_nsyms * SYMESZ]); | 
|---|
| 3916 | bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0, | 
|---|
| 3917 | syment.n_numaux, | 
|---|
| 3918 | &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]); | 
|---|
| 3919 |  | 
|---|
| 3920 | /* reloc */ | 
|---|
| 3921 | memset (&reloc, 0, sizeof (struct internal_reloc)); | 
|---|
| 3922 | reloc.r_vaddr = 0x0000; | 
|---|
| 3923 | reloc.r_symndx = filehdr.f_nsyms; | 
|---|
| 3924 | reloc.r_type = R_POS; | 
|---|
| 3925 | reloc.r_size = 31; | 
|---|
| 3926 | bfd_coff_swap_reloc_out (abfd, &reloc, | 
|---|
| 3927 | &reloc_ext[scnhdr.s_nreloc * RELSZ]); | 
|---|
| 3928 |  | 
|---|
| 3929 | filehdr.f_nsyms += 2; | 
|---|
| 3930 | scnhdr.s_nreloc += 1; | 
|---|
| 3931 | } | 
|---|
| 3932 |  | 
|---|
| 3933 | scnhdr.s_relptr = scnhdr.s_scnptr + data_buffer_size; | 
|---|
| 3934 | filehdr.f_symptr = scnhdr.s_relptr + scnhdr.s_nreloc * RELSZ; | 
|---|
| 3935 |  | 
|---|
| 3936 | bfd_coff_swap_filehdr_out (abfd, &filehdr, filehdr_ext); | 
|---|
| 3937 | bfd_bwrite (filehdr_ext, FILHSZ, abfd); | 
|---|
| 3938 | bfd_coff_swap_scnhdr_out (abfd, &scnhdr, scnhdr_ext); | 
|---|
| 3939 | bfd_bwrite (scnhdr_ext, SCNHSZ, abfd); | 
|---|
| 3940 | bfd_bwrite (data_buffer, data_buffer_size, abfd); | 
|---|
| 3941 | bfd_bwrite (reloc_ext, scnhdr.s_nreloc * RELSZ, abfd); | 
|---|
| 3942 | bfd_bwrite (syment_ext, filehdr.f_nsyms * SYMESZ, abfd); | 
|---|
| 3943 | bfd_bwrite (string_table, string_table_size, abfd); | 
|---|
| 3944 |  | 
|---|
| 3945 | free (data_buffer); | 
|---|
| 3946 | data_buffer = NULL; | 
|---|
| 3947 |  | 
|---|
| 3948 | return TRUE; | 
|---|
| 3949 | } | 
|---|
| 3950 |  | 
|---|
| 3951 |  | 
|---|
| 3952 | static reloc_howto_type xcoff_dynamic_reloc = | 
|---|
| 3953 | HOWTO (0,                       /* type */ | 
|---|
| 3954 | 0,                       /* rightshift */ | 
|---|
| 3955 | 2,                       /* size (0 = byte, 1 = short, 2 = long) */ | 
|---|
| 3956 | 32,                      /* bitsize */ | 
|---|
| 3957 | FALSE,                   /* pc_relative */ | 
|---|
| 3958 | 0,                       /* bitpos */ | 
|---|
| 3959 | complain_overflow_bitfield, /* complain_on_overflow */ | 
|---|
| 3960 | 0,                       /* special_function */ | 
|---|
| 3961 | "R_POS",                 /* name */ | 
|---|
| 3962 | TRUE,                    /* partial_inplace */ | 
|---|
| 3963 | 0xffffffff,              /* src_mask */ | 
|---|
| 3964 | 0xffffffff,              /* dst_mask */ | 
|---|
| 3965 | FALSE);                  /* pcrel_offset */ | 
|---|
| 3966 |  | 
|---|
| 3967 | /*  glink | 
|---|
| 3968 |  | 
|---|
| 3969 | The first word of global linkage code must be modified by filling in | 
|---|
| 3970 | the correct TOC offset.  */ | 
|---|
| 3971 |  | 
|---|
| 3972 | static unsigned long xcoff_glink_code[9] = | 
|---|
| 3973 | { | 
|---|
| 3974 | 0x81820000, /* lwz r12,0(r2) */ | 
|---|
| 3975 | 0x90410014, /* stw r2,20(r1) */ | 
|---|
| 3976 | 0x800c0000, /* lwz r0,0(r12) */ | 
|---|
| 3977 | 0x804c0004, /* lwz r2,4(r12) */ | 
|---|
| 3978 | 0x7c0903a6, /* mtctr r0 */ | 
|---|
| 3979 | 0x4e800420, /* bctr */ | 
|---|
| 3980 | 0x00000000, /* start of traceback table */ | 
|---|
| 3981 | 0x000c8000, /* traceback table */ | 
|---|
| 3982 | 0x00000000, /* traceback table */ | 
|---|
| 3983 | }; | 
|---|
| 3984 |  | 
|---|
| 3985 |  | 
|---|
| 3986 | static const struct xcoff_backend_data_rec bfd_xcoff_backend_data = | 
|---|
| 3987 | { | 
|---|
| 3988 | { /* COFF backend, defined in libcoff.h.  */ | 
|---|
| 3989 | _bfd_xcoff_swap_aux_in, | 
|---|
| 3990 | _bfd_xcoff_swap_sym_in, | 
|---|
| 3991 | coff_swap_lineno_in, | 
|---|
| 3992 | _bfd_xcoff_swap_aux_out, | 
|---|
| 3993 | _bfd_xcoff_swap_sym_out, | 
|---|
| 3994 | coff_swap_lineno_out, | 
|---|
| 3995 | xcoff_swap_reloc_out, | 
|---|
| 3996 | coff_swap_filehdr_out, | 
|---|
| 3997 | coff_swap_aouthdr_out, | 
|---|
| 3998 | coff_swap_scnhdr_out, | 
|---|
| 3999 | FILHSZ, | 
|---|
| 4000 | AOUTSZ, | 
|---|
| 4001 | SCNHSZ, | 
|---|
| 4002 | SYMESZ, | 
|---|
| 4003 | AUXESZ, | 
|---|
| 4004 | RELSZ, | 
|---|
| 4005 | LINESZ, | 
|---|
| 4006 | FILNMLEN, | 
|---|
| 4007 | TRUE,                     /* _bfd_coff_long_filenames */ | 
|---|
| 4008 | FALSE,                    /* _bfd_coff_long_section_names */ | 
|---|
| 4009 | 3,                        /* _bfd_coff_default_section_alignment_power */ | 
|---|
| 4010 | FALSE,                    /* _bfd_coff_force_symnames_in_strings */ | 
|---|
| 4011 | 2,                        /* _bfd_coff_debug_string_prefix_length */ | 
|---|
| 4012 | coff_swap_filehdr_in, | 
|---|
| 4013 | coff_swap_aouthdr_in, | 
|---|
| 4014 | coff_swap_scnhdr_in, | 
|---|
| 4015 | xcoff_swap_reloc_in, | 
|---|
| 4016 | coff_bad_format_hook, | 
|---|
| 4017 | coff_set_arch_mach_hook, | 
|---|
| 4018 | coff_mkobject_hook, | 
|---|
| 4019 | styp_to_sec_flags, | 
|---|
| 4020 | coff_set_alignment_hook, | 
|---|
| 4021 | coff_slurp_symbol_table, | 
|---|
| 4022 | symname_in_debug_hook, | 
|---|
| 4023 | coff_pointerize_aux_hook, | 
|---|
| 4024 | coff_print_aux, | 
|---|
| 4025 | dummy_reloc16_extra_cases, | 
|---|
| 4026 | dummy_reloc16_estimate, | 
|---|
| 4027 | NULL,                     /* bfd_coff_sym_is_global */ | 
|---|
| 4028 | coff_compute_section_file_positions, | 
|---|
| 4029 | NULL,                     /* _bfd_coff_start_final_link */ | 
|---|
| 4030 | xcoff_ppc_relocate_section, | 
|---|
| 4031 | coff_rtype_to_howto, | 
|---|
| 4032 | NULL,                     /* _bfd_coff_adjust_symndx */ | 
|---|
| 4033 | _bfd_generic_link_add_one_symbol, | 
|---|
| 4034 | coff_link_output_has_begun, | 
|---|
| 4035 | coff_final_link_postscript | 
|---|
| 4036 | }, | 
|---|
| 4037 |  | 
|---|
| 4038 | 0x01DF,                     /* magic number */ | 
|---|
| 4039 | bfd_arch_rs6000, | 
|---|
| 4040 | bfd_mach_rs6k, | 
|---|
| 4041 |  | 
|---|
| 4042 | /* Function pointers to xcoff specific swap routines.  */ | 
|---|
| 4043 | xcoff_swap_ldhdr_in, | 
|---|
| 4044 | xcoff_swap_ldhdr_out, | 
|---|
| 4045 | xcoff_swap_ldsym_in, | 
|---|
| 4046 | xcoff_swap_ldsym_out, | 
|---|
| 4047 | xcoff_swap_ldrel_in, | 
|---|
| 4048 | xcoff_swap_ldrel_out, | 
|---|
| 4049 |  | 
|---|
| 4050 | /* Sizes.  */ | 
|---|
| 4051 | LDHDRSZ, | 
|---|
| 4052 | LDSYMSZ, | 
|---|
| 4053 | LDRELSZ, | 
|---|
| 4054 | 12,                         /* _xcoff_function_descriptor_size */ | 
|---|
| 4055 | SMALL_AOUTSZ, | 
|---|
| 4056 |  | 
|---|
| 4057 | /* Versions.  */ | 
|---|
| 4058 | 1,                          /* _xcoff_ldhdr_version */ | 
|---|
| 4059 |  | 
|---|
| 4060 | _bfd_xcoff_put_symbol_name, | 
|---|
| 4061 | _bfd_xcoff_put_ldsymbol_name, | 
|---|
| 4062 | &xcoff_dynamic_reloc, | 
|---|
| 4063 | xcoff_create_csect_from_smclas, | 
|---|
| 4064 |  | 
|---|
| 4065 | /* Lineno and reloc count overflow.  */ | 
|---|
| 4066 | xcoff_is_lineno_count_overflow, | 
|---|
| 4067 | xcoff_is_reloc_count_overflow, | 
|---|
| 4068 |  | 
|---|
| 4069 | xcoff_loader_symbol_offset, | 
|---|
| 4070 | xcoff_loader_reloc_offset, | 
|---|
| 4071 |  | 
|---|
| 4072 | /* glink.  */ | 
|---|
| 4073 | &xcoff_glink_code[0], | 
|---|
| 4074 | 36,                         /* _xcoff_glink_size */ | 
|---|
| 4075 |  | 
|---|
| 4076 | /* rtinit */ | 
|---|
| 4077 | 64,                         /* _xcoff_rtinit_size */ | 
|---|
| 4078 | xcoff_generate_rtinit, | 
|---|
| 4079 | }; | 
|---|
| 4080 |  | 
|---|
| 4081 | /* The transfer vector that leads the outside world to all of the above.  */ | 
|---|
| 4082 | const bfd_target rs6000coff_vec = | 
|---|
| 4083 | { | 
|---|
| 4084 | "aixcoff-rs6000", | 
|---|
| 4085 | bfd_target_xcoff_flavour, | 
|---|
| 4086 | BFD_ENDIAN_BIG,             /* data byte order is big */ | 
|---|
| 4087 | BFD_ENDIAN_BIG,             /* header byte order is big */ | 
|---|
| 4088 |  | 
|---|
| 4089 | (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | DYNAMIC | 
|---|
| 4090 | | HAS_SYMS | HAS_LOCALS | WP_TEXT), | 
|---|
| 4091 |  | 
|---|
| 4092 | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE | SEC_DATA, | 
|---|
| 4093 | 0,                          /* leading char */ | 
|---|
| 4094 | '/',                        /* ar_pad_char */ | 
|---|
| 4095 | 15,                         /* ar_max_namelen */ | 
|---|
| 4096 |  | 
|---|
| 4097 | /* data */ | 
|---|
| 4098 | bfd_getb64, | 
|---|
| 4099 | bfd_getb_signed_64, | 
|---|
| 4100 | bfd_putb64, | 
|---|
| 4101 | bfd_getb32, | 
|---|
| 4102 | bfd_getb_signed_32, | 
|---|
| 4103 | bfd_putb32, | 
|---|
| 4104 | bfd_getb16, | 
|---|
| 4105 | bfd_getb_signed_16, | 
|---|
| 4106 | bfd_putb16, | 
|---|
| 4107 |  | 
|---|
| 4108 | /* hdrs */ | 
|---|
| 4109 | bfd_getb64, | 
|---|
| 4110 | bfd_getb_signed_64, | 
|---|
| 4111 | bfd_putb64, | 
|---|
| 4112 | bfd_getb32, | 
|---|
| 4113 | bfd_getb_signed_32, | 
|---|
| 4114 | bfd_putb32, | 
|---|
| 4115 | bfd_getb16, | 
|---|
| 4116 | bfd_getb_signed_16, | 
|---|
| 4117 | bfd_putb16, | 
|---|
| 4118 |  | 
|---|
| 4119 | { /* bfd_check_format */ | 
|---|
| 4120 | _bfd_dummy_target, | 
|---|
| 4121 | coff_object_p, | 
|---|
| 4122 | _bfd_xcoff_archive_p, | 
|---|
| 4123 | CORE_FILE_P | 
|---|
| 4124 | }, | 
|---|
| 4125 |  | 
|---|
| 4126 | { /* bfd_set_format */ | 
|---|
| 4127 | bfd_false, | 
|---|
| 4128 | coff_mkobject, | 
|---|
| 4129 | _bfd_generic_mkarchive, | 
|---|
| 4130 | bfd_false | 
|---|
| 4131 | }, | 
|---|
| 4132 |  | 
|---|
| 4133 | {/* bfd_write_contents */ | 
|---|
| 4134 | bfd_false, | 
|---|
| 4135 | coff_write_object_contents, | 
|---|
| 4136 | _bfd_xcoff_write_archive_contents, | 
|---|
| 4137 | bfd_false | 
|---|
| 4138 | }, | 
|---|
| 4139 |  | 
|---|
| 4140 | /* Generic */ | 
|---|
| 4141 | bfd_true, | 
|---|
| 4142 | bfd_true, | 
|---|
| 4143 | coff_new_section_hook, | 
|---|
| 4144 | _bfd_generic_get_section_contents, | 
|---|
| 4145 | _bfd_generic_get_section_contents_in_window, | 
|---|
| 4146 |  | 
|---|
| 4147 | /* Copy */ | 
|---|
| 4148 | _bfd_xcoff_copy_private_bfd_data, | 
|---|
| 4149 | ((bfd_boolean (*) (bfd *, bfd *)) bfd_true), | 
|---|
| 4150 | ((bfd_boolean (*) (bfd *, asection *, bfd *, asection *)) bfd_true), | 
|---|
| 4151 | ((bfd_boolean (*) (bfd *, asymbol *, bfd *, asymbol *)) bfd_true), | 
|---|
| 4152 | ((bfd_boolean (*) (bfd *, flagword)) bfd_true), | 
|---|
| 4153 | ((bfd_boolean (*) (bfd *, void * )) bfd_true), | 
|---|
| 4154 |  | 
|---|
| 4155 | /* Core */ | 
|---|
| 4156 | coff_core_file_failing_command, | 
|---|
| 4157 | coff_core_file_failing_signal, | 
|---|
| 4158 | coff_core_file_matches_executable_p, | 
|---|
| 4159 |  | 
|---|
| 4160 | /* Archive */ | 
|---|
| 4161 | _bfd_xcoff_slurp_armap, | 
|---|
| 4162 | bfd_false, | 
|---|
| 4163 | ((bfd_boolean (*) (bfd *, char **, bfd_size_type *, const char **)) bfd_false), | 
|---|
| 4164 | bfd_dont_truncate_arname, | 
|---|
| 4165 | _bfd_xcoff_write_armap, | 
|---|
| 4166 | _bfd_xcoff_read_ar_hdr, | 
|---|
| 4167 | _bfd_xcoff_openr_next_archived_file, | 
|---|
| 4168 | _bfd_generic_get_elt_at_index, | 
|---|
| 4169 | _bfd_xcoff_stat_arch_elt, | 
|---|
| 4170 | bfd_true, | 
|---|
| 4171 |  | 
|---|
| 4172 | /* Symbols */ | 
|---|
| 4173 | coff_get_symtab_upper_bound, | 
|---|
| 4174 | coff_get_symtab, | 
|---|
| 4175 | coff_make_empty_symbol, | 
|---|
| 4176 | coff_print_symbol, | 
|---|
| 4177 | coff_get_symbol_info, | 
|---|
| 4178 | _bfd_xcoff_is_local_label_name, | 
|---|
| 4179 | coff_get_lineno, | 
|---|
| 4180 | coff_find_nearest_line, | 
|---|
| 4181 | coff_bfd_make_debug_symbol, | 
|---|
| 4182 | _bfd_generic_read_minisymbols, | 
|---|
| 4183 | _bfd_generic_minisymbol_to_symbol, | 
|---|
| 4184 |  | 
|---|
| 4185 | /* Reloc */ | 
|---|
| 4186 | coff_get_reloc_upper_bound, | 
|---|
| 4187 | coff_canonicalize_reloc, | 
|---|
| 4188 | _bfd_xcoff_reloc_type_lookup, | 
|---|
| 4189 |  | 
|---|
| 4190 | /* Write */ | 
|---|
| 4191 | coff_set_arch_mach, | 
|---|
| 4192 | coff_set_section_contents, | 
|---|
| 4193 |  | 
|---|
| 4194 | /* Link */ | 
|---|
| 4195 | _bfd_xcoff_sizeof_headers, | 
|---|
| 4196 | bfd_generic_get_relocated_section_contents, | 
|---|
| 4197 | bfd_generic_relax_section, | 
|---|
| 4198 | _bfd_xcoff_bfd_link_hash_table_create, | 
|---|
| 4199 | _bfd_generic_link_hash_table_free, | 
|---|
| 4200 | _bfd_xcoff_bfd_link_add_symbols, | 
|---|
| 4201 | _bfd_generic_link_just_syms, | 
|---|
| 4202 | _bfd_xcoff_bfd_final_link, | 
|---|
| 4203 | _bfd_generic_link_split_section, | 
|---|
| 4204 | bfd_generic_gc_sections, | 
|---|
| 4205 | bfd_generic_merge_sections, | 
|---|
| 4206 | bfd_generic_discard_group, | 
|---|
| 4207 |  | 
|---|
| 4208 | /* Dynamic */ | 
|---|
| 4209 | _bfd_xcoff_get_dynamic_symtab_upper_bound, | 
|---|
| 4210 | _bfd_xcoff_canonicalize_dynamic_symtab, | 
|---|
| 4211 | _bfd_xcoff_get_dynamic_reloc_upper_bound, | 
|---|
| 4212 | _bfd_xcoff_canonicalize_dynamic_reloc, | 
|---|
| 4213 |  | 
|---|
| 4214 | /* Opposite endian version, none exists */ | 
|---|
| 4215 | NULL, | 
|---|
| 4216 |  | 
|---|
| 4217 | (void *) &bfd_xcoff_backend_data, | 
|---|
| 4218 | }; | 
|---|
| 4219 |  | 
|---|
| 4220 | /* xcoff-powermac target | 
|---|
| 4221 | Old target. | 
|---|
| 4222 | Only difference between this target and the rs6000 target is the | 
|---|
| 4223 | the default architecture and machine type used in coffcode.h | 
|---|
| 4224 |  | 
|---|
| 4225 | PowerPC Macs use the same magic numbers as RS/6000 | 
|---|
| 4226 | (because that's how they were bootstrapped originally), | 
|---|
| 4227 | but they are always PowerPC architecture.  */ | 
|---|
| 4228 | static const struct xcoff_backend_data_rec bfd_pmac_xcoff_backend_data = | 
|---|
| 4229 | { | 
|---|
| 4230 | { /* COFF backend, defined in libcoff.h.  */ | 
|---|
| 4231 | _bfd_xcoff_swap_aux_in, | 
|---|
| 4232 | _bfd_xcoff_swap_sym_in, | 
|---|
| 4233 | coff_swap_lineno_in, | 
|---|
| 4234 | _bfd_xcoff_swap_aux_out, | 
|---|
| 4235 | _bfd_xcoff_swap_sym_out, | 
|---|
| 4236 | coff_swap_lineno_out, | 
|---|
| 4237 | xcoff_swap_reloc_out, | 
|---|
| 4238 | coff_swap_filehdr_out, | 
|---|
| 4239 | coff_swap_aouthdr_out, | 
|---|
| 4240 | coff_swap_scnhdr_out, | 
|---|
| 4241 | FILHSZ, | 
|---|
| 4242 | AOUTSZ, | 
|---|
| 4243 | SCNHSZ, | 
|---|
| 4244 | SYMESZ, | 
|---|
| 4245 | AUXESZ, | 
|---|
| 4246 | RELSZ, | 
|---|
| 4247 | LINESZ, | 
|---|
| 4248 | FILNMLEN, | 
|---|
| 4249 | TRUE,                     /* _bfd_coff_long_filenames */ | 
|---|
| 4250 | FALSE,                    /* _bfd_coff_long_section_names */ | 
|---|
| 4251 | 3,                        /* _bfd_coff_default_section_alignment_power */ | 
|---|
| 4252 | FALSE,                    /* _bfd_coff_force_symnames_in_strings */ | 
|---|
| 4253 | 2,                        /* _bfd_coff_debug_string_prefix_length */ | 
|---|
| 4254 | coff_swap_filehdr_in, | 
|---|
| 4255 | coff_swap_aouthdr_in, | 
|---|
| 4256 | coff_swap_scnhdr_in, | 
|---|
| 4257 | xcoff_swap_reloc_in, | 
|---|
| 4258 | coff_bad_format_hook, | 
|---|
| 4259 | coff_set_arch_mach_hook, | 
|---|
| 4260 | coff_mkobject_hook, | 
|---|
| 4261 | styp_to_sec_flags, | 
|---|
| 4262 | coff_set_alignment_hook, | 
|---|
| 4263 | coff_slurp_symbol_table, | 
|---|
| 4264 | symname_in_debug_hook, | 
|---|
| 4265 | coff_pointerize_aux_hook, | 
|---|
| 4266 | coff_print_aux, | 
|---|
| 4267 | dummy_reloc16_extra_cases, | 
|---|
| 4268 | dummy_reloc16_estimate, | 
|---|
| 4269 | NULL,                     /* bfd_coff_sym_is_global */ | 
|---|
| 4270 | coff_compute_section_file_positions, | 
|---|
| 4271 | NULL,                     /* _bfd_coff_start_final_link */ | 
|---|
| 4272 | xcoff_ppc_relocate_section, | 
|---|
| 4273 | coff_rtype_to_howto, | 
|---|
| 4274 | NULL,                     /* _bfd_coff_adjust_symndx */ | 
|---|
| 4275 | _bfd_generic_link_add_one_symbol, | 
|---|
| 4276 | coff_link_output_has_begun, | 
|---|
| 4277 | coff_final_link_postscript | 
|---|
| 4278 | }, | 
|---|
| 4279 |  | 
|---|
| 4280 | 0x01DF,                     /* magic number */ | 
|---|
| 4281 | bfd_arch_powerpc, | 
|---|
| 4282 | bfd_mach_ppc, | 
|---|
| 4283 |  | 
|---|
| 4284 | /* Function pointers to xcoff specific swap routines.  */ | 
|---|
| 4285 | xcoff_swap_ldhdr_in, | 
|---|
| 4286 | xcoff_swap_ldhdr_out, | 
|---|
| 4287 | xcoff_swap_ldsym_in, | 
|---|
| 4288 | xcoff_swap_ldsym_out, | 
|---|
| 4289 | xcoff_swap_ldrel_in, | 
|---|
| 4290 | xcoff_swap_ldrel_out, | 
|---|
| 4291 |  | 
|---|
| 4292 | /* Sizes.  */ | 
|---|
| 4293 | LDHDRSZ, | 
|---|
| 4294 | LDSYMSZ, | 
|---|
| 4295 | LDRELSZ, | 
|---|
| 4296 | 12,                         /* _xcoff_function_descriptor_size */ | 
|---|
| 4297 | SMALL_AOUTSZ, | 
|---|
| 4298 |  | 
|---|
| 4299 | /* Versions.  */ | 
|---|
| 4300 | 1,                          /* _xcoff_ldhdr_version */ | 
|---|
| 4301 |  | 
|---|
| 4302 | _bfd_xcoff_put_symbol_name, | 
|---|
| 4303 | _bfd_xcoff_put_ldsymbol_name, | 
|---|
| 4304 | &xcoff_dynamic_reloc, | 
|---|
| 4305 | xcoff_create_csect_from_smclas, | 
|---|
| 4306 |  | 
|---|
| 4307 | /* Lineno and reloc count overflow.  */ | 
|---|
| 4308 | xcoff_is_lineno_count_overflow, | 
|---|
| 4309 | xcoff_is_reloc_count_overflow, | 
|---|
| 4310 |  | 
|---|
| 4311 | xcoff_loader_symbol_offset, | 
|---|
| 4312 | xcoff_loader_reloc_offset, | 
|---|
| 4313 |  | 
|---|
| 4314 | /* glink.  */ | 
|---|
| 4315 | &xcoff_glink_code[0], | 
|---|
| 4316 | 36,                         /* _xcoff_glink_size */ | 
|---|
| 4317 |  | 
|---|
| 4318 | /* rtinit */ | 
|---|
| 4319 | 0,                          /* _xcoff_rtinit_size */ | 
|---|
| 4320 | xcoff_generate_rtinit, | 
|---|
| 4321 | }; | 
|---|
| 4322 |  | 
|---|
| 4323 | /* The transfer vector that leads the outside world to all of the above.  */ | 
|---|
| 4324 | const bfd_target pmac_xcoff_vec = | 
|---|
| 4325 | { | 
|---|
| 4326 | "xcoff-powermac", | 
|---|
| 4327 | bfd_target_xcoff_flavour, | 
|---|
| 4328 | BFD_ENDIAN_BIG,             /* data byte order is big */ | 
|---|
| 4329 | BFD_ENDIAN_BIG,             /* header byte order is big */ | 
|---|
| 4330 |  | 
|---|
| 4331 | (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | DYNAMIC | 
|---|
| 4332 | | HAS_SYMS | HAS_LOCALS | WP_TEXT), | 
|---|
| 4333 |  | 
|---|
| 4334 | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE | SEC_DATA, | 
|---|
| 4335 | 0,                          /* leading char */ | 
|---|
| 4336 | '/',                        /* ar_pad_char */ | 
|---|
| 4337 | 15,                         /* ar_max_namelen */ | 
|---|
| 4338 |  | 
|---|
| 4339 | /* data */ | 
|---|
| 4340 | bfd_getb64, | 
|---|
| 4341 | bfd_getb_signed_64, | 
|---|
| 4342 | bfd_putb64, | 
|---|
| 4343 | bfd_getb32, | 
|---|
| 4344 | bfd_getb_signed_32, | 
|---|
| 4345 | bfd_putb32, | 
|---|
| 4346 | bfd_getb16, | 
|---|
| 4347 | bfd_getb_signed_16, | 
|---|
| 4348 | bfd_putb16, | 
|---|
| 4349 |  | 
|---|
| 4350 | /* hdrs */ | 
|---|
| 4351 | bfd_getb64, | 
|---|
| 4352 | bfd_getb_signed_64, | 
|---|
| 4353 | bfd_putb64, | 
|---|
| 4354 | bfd_getb32, | 
|---|
| 4355 | bfd_getb_signed_32, | 
|---|
| 4356 | bfd_putb32, | 
|---|
| 4357 | bfd_getb16, | 
|---|
| 4358 | bfd_getb_signed_16, | 
|---|
| 4359 | bfd_putb16, | 
|---|
| 4360 |  | 
|---|
| 4361 | { /* bfd_check_format */ | 
|---|
| 4362 | _bfd_dummy_target, | 
|---|
| 4363 | coff_object_p, | 
|---|
| 4364 | _bfd_xcoff_archive_p, | 
|---|
| 4365 | CORE_FILE_P | 
|---|
| 4366 | }, | 
|---|
| 4367 |  | 
|---|
| 4368 | { /* bfd_set_format */ | 
|---|
| 4369 | bfd_false, | 
|---|
| 4370 | coff_mkobject, | 
|---|
| 4371 | _bfd_generic_mkarchive, | 
|---|
| 4372 | bfd_false | 
|---|
| 4373 | }, | 
|---|
| 4374 |  | 
|---|
| 4375 | {/* bfd_write_contents */ | 
|---|
| 4376 | bfd_false, | 
|---|
| 4377 | coff_write_object_contents, | 
|---|
| 4378 | _bfd_xcoff_write_archive_contents, | 
|---|
| 4379 | bfd_false | 
|---|
| 4380 | }, | 
|---|
| 4381 |  | 
|---|
| 4382 | /* Generic */ | 
|---|
| 4383 | bfd_true, | 
|---|
| 4384 | bfd_true, | 
|---|
| 4385 | coff_new_section_hook, | 
|---|
| 4386 | _bfd_generic_get_section_contents, | 
|---|
| 4387 | _bfd_generic_get_section_contents_in_window, | 
|---|
| 4388 |  | 
|---|
| 4389 | /* Copy */ | 
|---|
| 4390 | _bfd_xcoff_copy_private_bfd_data, | 
|---|
| 4391 | ((bfd_boolean (*) (bfd *, bfd *)) bfd_true), | 
|---|
| 4392 | ((bfd_boolean (*) (bfd *, asection *, bfd *, asection *)) bfd_true), | 
|---|
| 4393 | ((bfd_boolean (*) (bfd *, asymbol *, bfd *, asymbol *)) bfd_true), | 
|---|
| 4394 | ((bfd_boolean (*) (bfd *, flagword)) bfd_true), | 
|---|
| 4395 | ((bfd_boolean (*) (bfd *, void * )) bfd_true), | 
|---|
| 4396 |  | 
|---|
| 4397 | /* Core */ | 
|---|
| 4398 | coff_core_file_failing_command, | 
|---|
| 4399 | coff_core_file_failing_signal, | 
|---|
| 4400 | coff_core_file_matches_executable_p, | 
|---|
| 4401 |  | 
|---|
| 4402 | /* Archive */ | 
|---|
| 4403 | _bfd_xcoff_slurp_armap, | 
|---|
| 4404 | bfd_false, | 
|---|
| 4405 | ((bfd_boolean (*) (bfd *, char **, bfd_size_type *, const char **)) bfd_false), | 
|---|
| 4406 | bfd_dont_truncate_arname, | 
|---|
| 4407 | _bfd_xcoff_write_armap, | 
|---|
| 4408 | _bfd_xcoff_read_ar_hdr, | 
|---|
| 4409 | _bfd_xcoff_openr_next_archived_file, | 
|---|
| 4410 | _bfd_generic_get_elt_at_index, | 
|---|
| 4411 | _bfd_xcoff_stat_arch_elt, | 
|---|
| 4412 | bfd_true, | 
|---|
| 4413 |  | 
|---|
| 4414 | /* Symbols */ | 
|---|
| 4415 | coff_get_symtab_upper_bound, | 
|---|
| 4416 | coff_get_symtab, | 
|---|
| 4417 | coff_make_empty_symbol, | 
|---|
| 4418 | coff_print_symbol, | 
|---|
| 4419 | coff_get_symbol_info, | 
|---|
| 4420 | _bfd_xcoff_is_local_label_name, | 
|---|
| 4421 | coff_get_lineno, | 
|---|
| 4422 | coff_find_nearest_line, | 
|---|
| 4423 | coff_bfd_make_debug_symbol, | 
|---|
| 4424 | _bfd_generic_read_minisymbols, | 
|---|
| 4425 | _bfd_generic_minisymbol_to_symbol, | 
|---|
| 4426 |  | 
|---|
| 4427 | /* Reloc */ | 
|---|
| 4428 | coff_get_reloc_upper_bound, | 
|---|
| 4429 | coff_canonicalize_reloc, | 
|---|
| 4430 | _bfd_xcoff_reloc_type_lookup, | 
|---|
| 4431 |  | 
|---|
| 4432 | /* Write */ | 
|---|
| 4433 | coff_set_arch_mach, | 
|---|
| 4434 | coff_set_section_contents, | 
|---|
| 4435 |  | 
|---|
| 4436 | /* Link */ | 
|---|
| 4437 | _bfd_xcoff_sizeof_headers, | 
|---|
| 4438 | bfd_generic_get_relocated_section_contents, | 
|---|
| 4439 | bfd_generic_relax_section, | 
|---|
| 4440 | _bfd_xcoff_bfd_link_hash_table_create, | 
|---|
| 4441 | _bfd_generic_link_hash_table_free, | 
|---|
| 4442 | _bfd_xcoff_bfd_link_add_symbols, | 
|---|
| 4443 | _bfd_generic_link_just_syms, | 
|---|
| 4444 | _bfd_xcoff_bfd_final_link, | 
|---|
| 4445 | _bfd_generic_link_split_section, | 
|---|
| 4446 | bfd_generic_gc_sections, | 
|---|
| 4447 | bfd_generic_merge_sections, | 
|---|
| 4448 | bfd_generic_discard_group, | 
|---|
| 4449 |  | 
|---|
| 4450 | /* Dynamic */ | 
|---|
| 4451 | _bfd_xcoff_get_dynamic_symtab_upper_bound, | 
|---|
| 4452 | _bfd_xcoff_canonicalize_dynamic_symtab, | 
|---|
| 4453 | _bfd_xcoff_get_dynamic_reloc_upper_bound, | 
|---|
| 4454 | _bfd_xcoff_canonicalize_dynamic_reloc, | 
|---|
| 4455 |  | 
|---|
| 4456 | /* Opposite endian version, none exists */ | 
|---|
| 4457 | NULL, | 
|---|
| 4458 |  | 
|---|
| 4459 | (void *) &bfd_pmac_xcoff_backend_data, | 
|---|
| 4460 | }; | 
|---|