PageRenderTime 68ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/mingw-w64-v2.0.999/binutils/src/bfd/coff-rs6000.c

#
C | 4422 lines | 3278 code | 549 blank | 595 comment | 529 complexity | 013360a2a10ee578f0ef63b9b5b1cc41 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-1.0, LGPL-3.0, Unlicense, GPL-2.0, LGPL-2.0, BSD-3-Clause, GPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. /* BFD back-end for IBM RS/6000 "XCOFF" files.
  2. Copyright 1990-1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
  3. 2008, 2009, 2010, 2011, 2012
  4. Free Software Foundation, Inc.
  5. Written by Metin G. Ozisik, Mimi Phuong-Thao Vo, and John Gilmore.
  6. Archive support from Damon A. Permezel.
  7. Contributed by IBM Corporation and Cygnus Support.
  8. This file is part of BFD, the Binary File Descriptor library.
  9. This program is free software; you can redistribute it and/or modify
  10. it under the terms of the GNU General Public License as published by
  11. the Free Software Foundation; either version 3 of the License, or
  12. (at your option) any later version.
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. GNU General Public License for more details.
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  20. MA 02110-1301, USA. */
  21. #include "sysdep.h"
  22. #include "bfd.h"
  23. #include "bfdlink.h"
  24. #include "libbfd.h"
  25. #include "coff/internal.h"
  26. #include "coff/xcoff.h"
  27. #include "coff/rs6000.h"
  28. #include "libcoff.h"
  29. #include "libxcoff.h"
  30. extern bfd_boolean _bfd_xcoff_mkobject (bfd *);
  31. extern bfd_boolean _bfd_xcoff_copy_private_bfd_data (bfd *, bfd *);
  32. extern bfd_boolean _bfd_xcoff_is_local_label_name (bfd *, const char *);
  33. extern reloc_howto_type *_bfd_xcoff_reloc_type_lookup
  34. (bfd *, bfd_reloc_code_real_type);
  35. extern bfd_boolean _bfd_xcoff_slurp_armap (bfd *);
  36. extern const bfd_target *_bfd_xcoff_archive_p (bfd *);
  37. extern void * _bfd_xcoff_read_ar_hdr (bfd *);
  38. extern bfd *_bfd_xcoff_openr_next_archived_file (bfd *, bfd *);
  39. extern int _bfd_xcoff_stat_arch_elt (bfd *, struct stat *);
  40. extern bfd_boolean _bfd_xcoff_write_armap
  41. (bfd *, unsigned int, struct orl *, unsigned int, int);
  42. extern bfd_boolean _bfd_xcoff_write_archive_contents (bfd *);
  43. extern int _bfd_xcoff_sizeof_headers (bfd *, struct bfd_link_info *);
  44. extern void _bfd_xcoff_swap_sym_in (bfd *, void *, void *);
  45. extern unsigned int _bfd_xcoff_swap_sym_out (bfd *, void *, void *);
  46. extern void _bfd_xcoff_swap_aux_in (bfd *, void *, int, int, int, int, void *);
  47. extern unsigned int _bfd_xcoff_swap_aux_out
  48. (bfd *, void *, int, int, int, int, void *);
  49. static void xcoff_swap_reloc_in (bfd *, void *, void *);
  50. static unsigned int xcoff_swap_reloc_out (bfd *, void *, void *);
  51. /* Forward declare xcoff_rtype2howto for coffcode.h macro. */
  52. void xcoff_rtype2howto (arelent *, struct internal_reloc *);
  53. /* coffcode.h needs these to be defined. */
  54. #define RS6000COFF_C 1
  55. #define SELECT_RELOC(internal, howto) \
  56. { \
  57. internal.r_type = howto->type; \
  58. internal.r_size = \
  59. ((howto->complain_on_overflow == complain_overflow_signed \
  60. ? 0x80 \
  61. : 0) \
  62. | (howto->bitsize - 1)); \
  63. }
  64. #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
  65. #define COFF_LONG_FILENAMES
  66. #define NO_COFF_SYMBOLS
  67. #define RTYPE2HOWTO(cache_ptr, dst) xcoff_rtype2howto (cache_ptr, dst)
  68. #define coff_mkobject _bfd_xcoff_mkobject
  69. #define coff_bfd_copy_private_bfd_data _bfd_xcoff_copy_private_bfd_data
  70. #define coff_bfd_is_local_label_name _bfd_xcoff_is_local_label_name
  71. #define coff_bfd_reloc_type_lookup _bfd_xcoff_reloc_type_lookup
  72. #define coff_bfd_reloc_name_lookup _bfd_xcoff_reloc_name_lookup
  73. #ifdef AIX_CORE
  74. extern const bfd_target * rs6000coff_core_p (bfd *abfd);
  75. extern bfd_boolean rs6000coff_core_file_matches_executable_p
  76. (bfd *cbfd, bfd *ebfd);
  77. extern char *rs6000coff_core_file_failing_command (bfd *abfd);
  78. extern int rs6000coff_core_file_failing_signal (bfd *abfd);
  79. #define CORE_FILE_P rs6000coff_core_p
  80. #define coff_core_file_failing_command \
  81. rs6000coff_core_file_failing_command
  82. #define coff_core_file_failing_signal \
  83. rs6000coff_core_file_failing_signal
  84. #define coff_core_file_matches_executable_p \
  85. rs6000coff_core_file_matches_executable_p
  86. #define coff_core_file_pid \
  87. _bfd_nocore_core_file_pid
  88. #else
  89. #define CORE_FILE_P _bfd_dummy_target
  90. #define coff_core_file_failing_command \
  91. _bfd_nocore_core_file_failing_command
  92. #define coff_core_file_failing_signal \
  93. _bfd_nocore_core_file_failing_signal
  94. #define coff_core_file_matches_executable_p \
  95. _bfd_nocore_core_file_matches_executable_p
  96. #define coff_core_file_pid \
  97. _bfd_nocore_core_file_pid
  98. #endif
  99. #define coff_SWAP_sym_in _bfd_xcoff_swap_sym_in
  100. #define coff_SWAP_sym_out _bfd_xcoff_swap_sym_out
  101. #define coff_SWAP_aux_in _bfd_xcoff_swap_aux_in
  102. #define coff_SWAP_aux_out _bfd_xcoff_swap_aux_out
  103. #define coff_swap_reloc_in xcoff_swap_reloc_in
  104. #define coff_swap_reloc_out xcoff_swap_reloc_out
  105. #define NO_COFF_RELOCS
  106. #ifndef bfd_pe_print_pdata
  107. #define bfd_pe_print_pdata NULL
  108. #endif
  109. #include "coffcode.h"
  110. /* The main body of code is in coffcode.h. */
  111. static const char *normalize_filename (bfd *);
  112. static bfd_boolean xcoff_write_armap_old
  113. (bfd *, unsigned int, struct orl *, unsigned int, int);
  114. static bfd_boolean xcoff_write_armap_big
  115. (bfd *, unsigned int, struct orl *, unsigned int, int);
  116. static bfd_boolean xcoff_write_archive_contents_old (bfd *);
  117. static bfd_boolean xcoff_write_archive_contents_big (bfd *);
  118. static void xcoff_swap_ldhdr_in (bfd *, const void *, struct internal_ldhdr *);
  119. static void xcoff_swap_ldhdr_out (bfd *, const struct internal_ldhdr *, void *);
  120. static void xcoff_swap_ldsym_in (bfd *, const void *, struct internal_ldsym *);
  121. static void xcoff_swap_ldsym_out (bfd *, const struct internal_ldsym *, void *);
  122. static void xcoff_swap_ldrel_in (bfd *, const void *, struct internal_ldrel *);
  123. static void xcoff_swap_ldrel_out (bfd *, const struct internal_ldrel *, void *);
  124. static bfd_boolean xcoff_ppc_relocate_section
  125. (bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
  126. struct internal_reloc *, struct internal_syment *, asection **);
  127. static bfd_boolean _bfd_xcoff_put_ldsymbol_name
  128. (bfd *, struct xcoff_loader_info *, struct internal_ldsym *, const char *);
  129. static asection *xcoff_create_csect_from_smclas
  130. (bfd *, union internal_auxent *, const char *);
  131. static bfd_boolean xcoff_is_lineno_count_overflow (bfd *, bfd_vma);
  132. static bfd_boolean xcoff_is_reloc_count_overflow (bfd *, bfd_vma);
  133. static bfd_vma xcoff_loader_symbol_offset (bfd *, struct internal_ldhdr *);
  134. static bfd_vma xcoff_loader_reloc_offset (bfd *, struct internal_ldhdr *);
  135. static bfd_boolean xcoff_generate_rtinit
  136. (bfd *, const char *, const char *, bfd_boolean);
  137. static bfd_boolean do_pad (bfd *, unsigned int);
  138. static bfd_boolean do_copy (bfd *, bfd *);
  139. /* Relocation functions */
  140. static bfd_boolean xcoff_reloc_type_br (XCOFF_RELOC_FUNCTION_ARGS);
  141. static bfd_boolean xcoff_complain_overflow_dont_func
  142. (XCOFF_COMPLAIN_FUNCTION_ARGS);
  143. static bfd_boolean xcoff_complain_overflow_bitfield_func
  144. (XCOFF_COMPLAIN_FUNCTION_ARGS);
  145. static bfd_boolean xcoff_complain_overflow_signed_func
  146. (XCOFF_COMPLAIN_FUNCTION_ARGS);
  147. static bfd_boolean xcoff_complain_overflow_unsigned_func
  148. (XCOFF_COMPLAIN_FUNCTION_ARGS);
  149. bfd_boolean (*xcoff_calculate_relocation[XCOFF_MAX_CALCULATE_RELOCATION])
  150. (XCOFF_RELOC_FUNCTION_ARGS) =
  151. {
  152. xcoff_reloc_type_pos, /* R_POS (0x00) */
  153. xcoff_reloc_type_neg, /* R_NEG (0x01) */
  154. xcoff_reloc_type_rel, /* R_REL (0x02) */
  155. xcoff_reloc_type_toc, /* R_TOC (0x03) */
  156. xcoff_reloc_type_fail, /* R_RTB (0x04) */
  157. xcoff_reloc_type_toc, /* R_GL (0x05) */
  158. xcoff_reloc_type_toc, /* R_TCL (0x06) */
  159. xcoff_reloc_type_fail, /* (0x07) */
  160. xcoff_reloc_type_ba, /* R_BA (0x08) */
  161. xcoff_reloc_type_fail, /* (0x09) */
  162. xcoff_reloc_type_br, /* R_BR (0x0a) */
  163. xcoff_reloc_type_fail, /* (0x0b) */
  164. xcoff_reloc_type_pos, /* R_RL (0x0c) */
  165. xcoff_reloc_type_pos, /* R_RLA (0x0d) */
  166. xcoff_reloc_type_fail, /* (0x0e) */
  167. xcoff_reloc_type_noop, /* R_REF (0x0f) */
  168. xcoff_reloc_type_fail, /* (0x10) */
  169. xcoff_reloc_type_fail, /* (0x11) */
  170. xcoff_reloc_type_toc, /* R_TRL (0x12) */
  171. xcoff_reloc_type_toc, /* R_TRLA (0x13) */
  172. xcoff_reloc_type_fail, /* R_RRTBI (0x14) */
  173. xcoff_reloc_type_fail, /* R_RRTBA (0x15) */
  174. xcoff_reloc_type_ba, /* R_CAI (0x16) */
  175. xcoff_reloc_type_crel, /* R_CREL (0x17) */
  176. xcoff_reloc_type_ba, /* R_RBA (0x18) */
  177. xcoff_reloc_type_ba, /* R_RBAC (0x19) */
  178. xcoff_reloc_type_br, /* R_RBR (0x1a) */
  179. xcoff_reloc_type_ba, /* R_RBRC (0x1b) */
  180. };
  181. bfd_boolean (*xcoff_complain_overflow[XCOFF_MAX_COMPLAIN_OVERFLOW])
  182. (XCOFF_COMPLAIN_FUNCTION_ARGS) =
  183. {
  184. xcoff_complain_overflow_dont_func,
  185. xcoff_complain_overflow_bitfield_func,
  186. xcoff_complain_overflow_signed_func,
  187. xcoff_complain_overflow_unsigned_func,
  188. };
  189. /* Information about one member of an archive. */
  190. struct member_layout {
  191. /* The archive member that this structure describes. */
  192. bfd *member;
  193. /* The number of bytes of padding that must be inserted before the
  194. start of the member in order to ensure that the section contents
  195. are correctly aligned. */
  196. unsigned int leading_padding;
  197. /* The offset of MEMBER from the start of the archive (i.e. the end
  198. of the leading padding). */
  199. file_ptr offset;
  200. /* The normalized name of MEMBER. */
  201. const char *name;
  202. /* The length of NAME, without padding. */
  203. bfd_size_type namlen;
  204. /* The length of NAME, with padding. */
  205. bfd_size_type padded_namlen;
  206. /* The size of MEMBER's header, including the name and magic sequence. */
  207. bfd_size_type header_size;
  208. /* The size of the MEMBER's contents. */
  209. bfd_size_type contents_size;
  210. /* The number of bytes of padding that must be inserted after MEMBER
  211. in order to preserve even alignment. */
  212. bfd_size_type trailing_padding;
  213. };
  214. /* A structure used for iterating over the members of an archive. */
  215. struct archive_iterator {
  216. /* The archive itself. */
  217. bfd *archive;
  218. /* Information about the current archive member. */
  219. struct member_layout current;
  220. /* Information about the next archive member. MEMBER is null if there
  221. are no more archive members, in which case OFFSET is the offset of
  222. the first unused byte. */
  223. struct member_layout next;
  224. };
  225. /* Initialize INFO so that it describes member MEMBER of archive ARCHIVE.
  226. OFFSET is the even-padded offset of MEMBER, not including any leading
  227. padding needed for section alignment. */
  228. static void
  229. member_layout_init (struct member_layout *info, bfd *archive,
  230. bfd *member, file_ptr offset)
  231. {
  232. info->member = member;
  233. info->leading_padding = 0;
  234. if (member)
  235. {
  236. info->name = normalize_filename (member);
  237. info->namlen = strlen (info->name);
  238. info->padded_namlen = info->namlen + (info->namlen & 1);
  239. if (xcoff_big_format_p (archive))
  240. info->header_size = SIZEOF_AR_HDR_BIG;
  241. else
  242. info->header_size = SIZEOF_AR_HDR;
  243. info->header_size += info->padded_namlen + SXCOFFARFMAG;
  244. info->contents_size = arelt_size (member);
  245. info->trailing_padding = info->contents_size & 1;
  246. if (bfd_check_format (member, bfd_object)
  247. && bfd_get_flavour (member) == bfd_target_xcoff_flavour
  248. && (member->flags & DYNAMIC) != 0)
  249. info->leading_padding
  250. = (-(offset + info->header_size)
  251. & ((1 << bfd_xcoff_text_align_power (member)) - 1));
  252. }
  253. info->offset = offset + info->leading_padding;
  254. }
  255. /* Set up ITERATOR to iterate through archive ARCHIVE. */
  256. static void
  257. archive_iterator_begin (struct archive_iterator *iterator,
  258. bfd *archive)
  259. {
  260. iterator->archive = archive;
  261. member_layout_init (&iterator->next, archive, archive->archive_head,
  262. xcoff_big_format_p (archive)
  263. ? SIZEOF_AR_FILE_HDR_BIG
  264. : SIZEOF_AR_FILE_HDR);
  265. }
  266. /* Make ITERATOR visit the first unvisited archive member. Return true
  267. on success; return false if all members have been visited. */
  268. static bfd_boolean
  269. archive_iterator_next (struct archive_iterator *iterator)
  270. {
  271. if (!iterator->next.member)
  272. return FALSE;
  273. iterator->current = iterator->next;
  274. member_layout_init (&iterator->next, iterator->archive,
  275. iterator->current.member->archive_next,
  276. iterator->current.offset
  277. + iterator->current.header_size
  278. + iterator->current.contents_size
  279. + iterator->current.trailing_padding);
  280. return TRUE;
  281. }
  282. /* We use our own tdata type. Its first field is the COFF tdata type,
  283. so the COFF routines are compatible. */
  284. bfd_boolean
  285. _bfd_xcoff_mkobject (bfd *abfd)
  286. {
  287. coff_data_type *coff;
  288. bfd_size_type amt = sizeof (struct xcoff_tdata);
  289. abfd->tdata.xcoff_obj_data = (struct xcoff_tdata *) bfd_zalloc (abfd, amt);
  290. if (abfd->tdata.xcoff_obj_data == NULL)
  291. return FALSE;
  292. coff = coff_data (abfd);
  293. coff->symbols = (coff_symbol_type *) NULL;
  294. coff->conversion_table = (unsigned int *) NULL;
  295. coff->raw_syments = (struct coff_ptr_struct *) NULL;
  296. coff->relocbase = 0;
  297. xcoff_data (abfd)->modtype = ('1' << 8) | 'L';
  298. /* We set cputype to -1 to indicate that it has not been
  299. initialized. */
  300. xcoff_data (abfd)->cputype = -1;
  301. xcoff_data (abfd)->csects = NULL;
  302. xcoff_data (abfd)->debug_indices = NULL;
  303. /* text section alignment is different than the default */
  304. bfd_xcoff_text_align_power (abfd) = 2;
  305. return TRUE;
  306. }
  307. /* Copy XCOFF data from one BFD to another. */
  308. bfd_boolean
  309. _bfd_xcoff_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
  310. {
  311. struct xcoff_tdata *ix, *ox;
  312. asection *sec;
  313. if (ibfd->xvec != obfd->xvec)
  314. return TRUE;
  315. ix = xcoff_data (ibfd);
  316. ox = xcoff_data (obfd);
  317. ox->full_aouthdr = ix->full_aouthdr;
  318. ox->toc = ix->toc;
  319. if (ix->sntoc == 0)
  320. ox->sntoc = 0;
  321. else
  322. {
  323. sec = coff_section_from_bfd_index (ibfd, ix->sntoc);
  324. if (sec == NULL)
  325. ox->sntoc = 0;
  326. else
  327. ox->sntoc = sec->output_section->target_index;
  328. }
  329. if (ix->snentry == 0)
  330. ox->snentry = 0;
  331. else
  332. {
  333. sec = coff_section_from_bfd_index (ibfd, ix->snentry);
  334. if (sec == NULL)
  335. ox->snentry = 0;
  336. else
  337. ox->snentry = sec->output_section->target_index;
  338. }
  339. bfd_xcoff_text_align_power (obfd) = bfd_xcoff_text_align_power (ibfd);
  340. bfd_xcoff_data_align_power (obfd) = bfd_xcoff_data_align_power (ibfd);
  341. ox->modtype = ix->modtype;
  342. ox->cputype = ix->cputype;
  343. ox->maxdata = ix->maxdata;
  344. ox->maxstack = ix->maxstack;
  345. return TRUE;
  346. }
  347. /* I don't think XCOFF really has a notion of local labels based on
  348. name. This will mean that ld -X doesn't actually strip anything.
  349. The AIX native linker does not have a -X option, and it ignores the
  350. -x option. */
  351. bfd_boolean
  352. _bfd_xcoff_is_local_label_name (bfd *abfd ATTRIBUTE_UNUSED,
  353. const char *name ATTRIBUTE_UNUSED)
  354. {
  355. return FALSE;
  356. }
  357. static const struct dwarf_debug_section xcoff_debug_sections[] =
  358. {
  359. { ".dwabrev", NULL },
  360. { ".dwarnge", NULL },
  361. { NULL, NULL }, /* .debug_frame */
  362. { ".dwinfo", NULL },
  363. { ".dwline", NULL },
  364. { NULL, NULL }, /* .debug_loc */
  365. { NULL, NULL }, /* .debug_macinfo */
  366. { NULL, NULL }, /* .debug_macro */
  367. { ".dwpbnms", NULL },
  368. { ".dwpbtyp", NULL },
  369. { ".dwrnges", NULL },
  370. { NULL, NULL }, /* .debug_static_func */
  371. { NULL, NULL }, /* .debug_static_vars */
  372. { ".dwstr", NULL },
  373. { NULL, NULL }, /* .debug_types */
  374. /* GNU DWARF 1 extensions */
  375. { NULL, NULL }, /* .debug_sfnames */
  376. { NULL, NULL }, /* .debug_srcinfo */
  377. /* SGI/MIPS DWARF 2 extensions */
  378. { NULL, NULL }, /* .debug_funcnames */
  379. { NULL, NULL }, /* .debug_typenames */
  380. { NULL, NULL }, /* .debug_varnames */
  381. { NULL, NULL }, /* .debug_weaknames */
  382. { NULL, NULL },
  383. };
  384. static bfd_boolean
  385. xcoff_find_nearest_line (bfd *abfd,
  386. asection *section,
  387. asymbol **symbols,
  388. bfd_vma offset,
  389. const char **filename_ptr,
  390. const char **functionname_ptr,
  391. unsigned int *line_ptr)
  392. {
  393. return coff_find_nearest_line_with_names (abfd, xcoff_debug_sections,
  394. section, symbols, offset,
  395. filename_ptr, functionname_ptr,
  396. line_ptr);
  397. }
  398. void
  399. _bfd_xcoff_swap_sym_in (bfd *abfd, void * ext1, void * in1)
  400. {
  401. SYMENT *ext = (SYMENT *)ext1;
  402. struct internal_syment * in = (struct internal_syment *)in1;
  403. if (ext->e.e_name[0] != 0)
  404. {
  405. memcpy (in->_n._n_name, ext->e.e_name, SYMNMLEN);
  406. }
  407. else
  408. {
  409. in->_n._n_n._n_zeroes = 0;
  410. in->_n._n_n._n_offset = H_GET_32 (abfd, ext->e.e.e_offset);
  411. }
  412. in->n_value = H_GET_32 (abfd, ext->e_value);
  413. in->n_scnum = H_GET_16 (abfd, ext->e_scnum);
  414. in->n_type = H_GET_16 (abfd, ext->e_type);
  415. in->n_sclass = H_GET_8 (abfd, ext->e_sclass);
  416. in->n_numaux = H_GET_8 (abfd, ext->e_numaux);
  417. }
  418. unsigned int
  419. _bfd_xcoff_swap_sym_out (bfd *abfd, void * inp, void * extp)
  420. {
  421. struct internal_syment *in = (struct internal_syment *)inp;
  422. SYMENT *ext =(SYMENT *)extp;
  423. if (in->_n._n_name[0] != 0)
  424. {
  425. memcpy (ext->e.e_name, in->_n._n_name, SYMNMLEN);
  426. }
  427. else
  428. {
  429. H_PUT_32 (abfd, 0, ext->e.e.e_zeroes);
  430. H_PUT_32 (abfd, in->_n._n_n._n_offset, ext->e.e.e_offset);
  431. }
  432. H_PUT_32 (abfd, in->n_value, ext->e_value);
  433. H_PUT_16 (abfd, in->n_scnum, ext->e_scnum);
  434. H_PUT_16 (abfd, in->n_type, ext->e_type);
  435. H_PUT_8 (abfd, in->n_sclass, ext->e_sclass);
  436. H_PUT_8 (abfd, in->n_numaux, ext->e_numaux);
  437. return bfd_coff_symesz (abfd);
  438. }
  439. void
  440. _bfd_xcoff_swap_aux_in (bfd *abfd, void * ext1, int type, int in_class,
  441. int indx, int numaux, void * in1)
  442. {
  443. AUXENT * ext = (AUXENT *)ext1;
  444. union internal_auxent *in = (union internal_auxent *)in1;
  445. switch (in_class)
  446. {
  447. case C_FILE:
  448. if (ext->x_file.x_n.x_fname[0] == 0)
  449. {
  450. in->x_file.x_n.x_zeroes = 0;
  451. in->x_file.x_n.x_offset =
  452. H_GET_32 (abfd, ext->x_file.x_n.x_n.x_offset);
  453. }
  454. else
  455. {
  456. if (numaux > 1)
  457. {
  458. if (indx == 0)
  459. memcpy (in->x_file.x_fname, ext->x_file.x_n.x_fname,
  460. numaux * sizeof (AUXENT));
  461. }
  462. else
  463. {
  464. memcpy (in->x_file.x_fname, ext->x_file.x_n.x_fname, FILNMLEN);
  465. }
  466. }
  467. goto end;
  468. /* RS/6000 "csect" auxents */
  469. case C_EXT:
  470. case C_AIX_WEAKEXT:
  471. case C_HIDEXT:
  472. if (indx + 1 == numaux)
  473. {
  474. in->x_csect.x_scnlen.l = H_GET_32 (abfd, ext->x_csect.x_scnlen);
  475. in->x_csect.x_parmhash = H_GET_32 (abfd, ext->x_csect.x_parmhash);
  476. in->x_csect.x_snhash = H_GET_16 (abfd, ext->x_csect.x_snhash);
  477. /* We don't have to hack bitfields in x_smtyp because it's
  478. defined by shifts-and-ands, which are equivalent on all
  479. byte orders. */
  480. in->x_csect.x_smtyp = H_GET_8 (abfd, ext->x_csect.x_smtyp);
  481. in->x_csect.x_smclas = H_GET_8 (abfd, ext->x_csect.x_smclas);
  482. in->x_csect.x_stab = H_GET_32 (abfd, ext->x_csect.x_stab);
  483. in->x_csect.x_snstab = H_GET_16 (abfd, ext->x_csect.x_snstab);
  484. goto end;
  485. }
  486. break;
  487. case C_STAT:
  488. case C_LEAFSTAT:
  489. case C_HIDDEN:
  490. if (type == T_NULL)
  491. {
  492. in->x_scn.x_scnlen = H_GET_32 (abfd, ext->x_scn.x_scnlen);
  493. in->x_scn.x_nreloc = H_GET_16 (abfd, ext->x_scn.x_nreloc);
  494. in->x_scn.x_nlinno = H_GET_16 (abfd, ext->x_scn.x_nlinno);
  495. /* PE defines some extra fields; we zero them out for
  496. safety. */
  497. in->x_scn.x_checksum = 0;
  498. in->x_scn.x_associated = 0;
  499. in->x_scn.x_comdat = 0;
  500. goto end;
  501. }
  502. break;
  503. }
  504. in->x_sym.x_tagndx.l = H_GET_32 (abfd, ext->x_sym.x_tagndx);
  505. in->x_sym.x_tvndx = H_GET_16 (abfd, ext->x_sym.x_tvndx);
  506. if (in_class == C_BLOCK || in_class == C_FCN || ISFCN (type)
  507. || ISTAG (in_class))
  508. {
  509. in->x_sym.x_fcnary.x_fcn.x_lnnoptr =
  510. H_GET_32 (abfd, ext->x_sym.x_fcnary.x_fcn.x_lnnoptr);
  511. in->x_sym.x_fcnary.x_fcn.x_endndx.l =
  512. H_GET_32 (abfd, ext->x_sym.x_fcnary.x_fcn.x_endndx);
  513. }
  514. else
  515. {
  516. in->x_sym.x_fcnary.x_ary.x_dimen[0] =
  517. H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
  518. in->x_sym.x_fcnary.x_ary.x_dimen[1] =
  519. H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
  520. in->x_sym.x_fcnary.x_ary.x_dimen[2] =
  521. H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
  522. in->x_sym.x_fcnary.x_ary.x_dimen[3] =
  523. H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
  524. }
  525. if (ISFCN (type))
  526. {
  527. in->x_sym.x_misc.x_fsize = H_GET_32 (abfd, ext->x_sym.x_misc.x_fsize);
  528. }
  529. else
  530. {
  531. in->x_sym.x_misc.x_lnsz.x_lnno =
  532. H_GET_16 (abfd, ext->x_sym.x_misc.x_lnsz.x_lnno);
  533. in->x_sym.x_misc.x_lnsz.x_size =
  534. H_GET_16 (abfd, ext->x_sym.x_misc.x_lnsz.x_size);
  535. }
  536. end: ;
  537. /* The semicolon is because MSVC doesn't like labels at
  538. end of block. */
  539. }
  540. unsigned int
  541. _bfd_xcoff_swap_aux_out (bfd *abfd, void * inp, int type, int in_class,
  542. int indx ATTRIBUTE_UNUSED,
  543. int numaux ATTRIBUTE_UNUSED,
  544. void * extp)
  545. {
  546. union internal_auxent *in = (union internal_auxent *)inp;
  547. AUXENT *ext = (AUXENT *)extp;
  548. memset (ext, 0, bfd_coff_auxesz (abfd));
  549. switch (in_class)
  550. {
  551. case C_FILE:
  552. if (in->x_file.x_fname[0] == 0)
  553. {
  554. H_PUT_32 (abfd, 0, ext->x_file.x_n.x_n.x_zeroes);
  555. H_PUT_32 (abfd, in->x_file.x_n.x_offset,
  556. ext->x_file.x_n.x_n.x_offset);
  557. }
  558. else
  559. {
  560. memcpy (ext->x_file.x_n.x_fname, in->x_file.x_fname, FILNMLEN);
  561. }
  562. goto end;
  563. /* RS/6000 "csect" auxents */
  564. case C_EXT:
  565. case C_AIX_WEAKEXT:
  566. case C_HIDEXT:
  567. if (indx + 1 == numaux)
  568. {
  569. H_PUT_32 (abfd, in->x_csect.x_scnlen.l, ext->x_csect.x_scnlen);
  570. H_PUT_32 (abfd, in->x_csect.x_parmhash, ext->x_csect.x_parmhash);
  571. H_PUT_16 (abfd, in->x_csect.x_snhash, ext->x_csect.x_snhash);
  572. /* We don't have to hack bitfields in x_smtyp because it's
  573. defined by shifts-and-ands, which are equivalent on all
  574. byte orders. */
  575. H_PUT_8 (abfd, in->x_csect.x_smtyp, ext->x_csect.x_smtyp);
  576. H_PUT_8 (abfd, in->x_csect.x_smclas, ext->x_csect.x_smclas);
  577. H_PUT_32 (abfd, in->x_csect.x_stab, ext->x_csect.x_stab);
  578. H_PUT_16 (abfd, in->x_csect.x_snstab, ext->x_csect.x_snstab);
  579. goto end;
  580. }
  581. break;
  582. case C_STAT:
  583. case C_LEAFSTAT:
  584. case C_HIDDEN:
  585. if (type == T_NULL)
  586. {
  587. H_PUT_32 (abfd, in->x_scn.x_scnlen, ext->x_scn.x_scnlen);
  588. H_PUT_16 (abfd, in->x_scn.x_nreloc, ext->x_scn.x_nreloc);
  589. H_PUT_16 (abfd, in->x_scn.x_nlinno, ext->x_scn.x_nlinno);
  590. goto end;
  591. }
  592. break;
  593. }
  594. H_PUT_32 (abfd, in->x_sym.x_tagndx.l, ext->x_sym.x_tagndx);
  595. H_PUT_16 (abfd, in->x_sym.x_tvndx, ext->x_sym.x_tvndx);
  596. if (in_class == C_BLOCK || in_class == C_FCN || ISFCN (type)
  597. || ISTAG (in_class))
  598. {
  599. H_PUT_32 (abfd, in->x_sym.x_fcnary.x_fcn.x_lnnoptr,
  600. ext->x_sym.x_fcnary.x_fcn.x_lnnoptr);
  601. H_PUT_32 (abfd, in->x_sym.x_fcnary.x_fcn.x_endndx.l,
  602. ext->x_sym.x_fcnary.x_fcn.x_endndx);
  603. }
  604. else
  605. {
  606. H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[0],
  607. ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
  608. H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[1],
  609. ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
  610. H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[2],
  611. ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
  612. H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[3],
  613. ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
  614. }
  615. if (ISFCN (type))
  616. H_PUT_32 (abfd, in->x_sym.x_misc.x_fsize, ext->x_sym.x_misc.x_fsize);
  617. else
  618. {
  619. H_PUT_16 (abfd, in->x_sym.x_misc.x_lnsz.x_lnno,
  620. ext->x_sym.x_misc.x_lnsz.x_lnno);
  621. H_PUT_16 (abfd, in->x_sym.x_misc.x_lnsz.x_size,
  622. ext->x_sym.x_misc.x_lnsz.x_size);
  623. }
  624. end:
  625. return bfd_coff_auxesz (abfd);
  626. }
  627. /* The XCOFF reloc table. Actually, XCOFF relocations specify the
  628. bitsize and whether they are signed or not, along with a
  629. conventional type. This table is for the types, which are used for
  630. different algorithms for putting in the reloc. Many of these
  631. relocs need special_function entries, which I have not written. */
  632. reloc_howto_type xcoff_howto_table[] =
  633. {
  634. /* Standard 32 bit relocation. */
  635. HOWTO (R_POS, /* type */
  636. 0, /* rightshift */
  637. 2, /* size (0 = byte, 1 = short, 2 = long) */
  638. 32, /* bitsize */
  639. FALSE, /* pc_relative */
  640. 0, /* bitpos */
  641. complain_overflow_bitfield, /* complain_on_overflow */
  642. 0, /* special_function */
  643. "R_POS", /* name */
  644. TRUE, /* partial_inplace */
  645. 0xffffffff, /* src_mask */
  646. 0xffffffff, /* dst_mask */
  647. FALSE), /* pcrel_offset */
  648. /* 32 bit relocation, but store negative value. */
  649. HOWTO (R_NEG, /* type */
  650. 0, /* rightshift */
  651. -2, /* size (0 = byte, 1 = short, 2 = long) */
  652. 32, /* bitsize */
  653. FALSE, /* pc_relative */
  654. 0, /* bitpos */
  655. complain_overflow_bitfield, /* complain_on_overflow */
  656. 0, /* special_function */
  657. "R_NEG", /* name */
  658. TRUE, /* partial_inplace */
  659. 0xffffffff, /* src_mask */
  660. 0xffffffff, /* dst_mask */
  661. FALSE), /* pcrel_offset */
  662. /* 32 bit PC relative relocation. */
  663. HOWTO (R_REL, /* type */
  664. 0, /* rightshift */
  665. 2, /* size (0 = byte, 1 = short, 2 = long) */
  666. 32, /* bitsize */
  667. TRUE, /* pc_relative */
  668. 0, /* bitpos */
  669. complain_overflow_signed, /* complain_on_overflow */
  670. 0, /* special_function */
  671. "R_REL", /* name */
  672. TRUE, /* partial_inplace */
  673. 0xffffffff, /* src_mask */
  674. 0xffffffff, /* dst_mask */
  675. FALSE), /* pcrel_offset */
  676. /* 16 bit TOC relative relocation. */
  677. HOWTO (R_TOC, /* type */
  678. 0, /* rightshift */
  679. 1, /* size (0 = byte, 1 = short, 2 = long) */
  680. 16, /* bitsize */
  681. FALSE, /* pc_relative */
  682. 0, /* bitpos */
  683. complain_overflow_bitfield, /* complain_on_overflow */
  684. 0, /* special_function */
  685. "R_TOC", /* name */
  686. TRUE, /* partial_inplace */
  687. 0xffff, /* src_mask */
  688. 0xffff, /* dst_mask */
  689. FALSE), /* pcrel_offset */
  690. /* I don't really know what this is. */
  691. HOWTO (R_RTB, /* type */
  692. 1, /* rightshift */
  693. 2, /* size (0 = byte, 1 = short, 2 = long) */
  694. 32, /* bitsize */
  695. FALSE, /* pc_relative */
  696. 0, /* bitpos */
  697. complain_overflow_bitfield, /* complain_on_overflow */
  698. 0, /* special_function */
  699. "R_RTB", /* name */
  700. TRUE, /* partial_inplace */
  701. 0xffffffff, /* src_mask */
  702. 0xffffffff, /* dst_mask */
  703. FALSE), /* pcrel_offset */
  704. /* External TOC relative symbol. */
  705. HOWTO (R_GL, /* type */
  706. 0, /* rightshift */
  707. 1, /* size (0 = byte, 1 = short, 2 = long) */
  708. 16, /* bitsize */
  709. FALSE, /* pc_relative */
  710. 0, /* bitpos */
  711. complain_overflow_bitfield, /* complain_on_overflow */
  712. 0, /* special_function */
  713. "R_GL", /* name */
  714. TRUE, /* partial_inplace */
  715. 0xffff, /* src_mask */
  716. 0xffff, /* dst_mask */
  717. FALSE), /* pcrel_offset */
  718. /* Local TOC relative symbol. */
  719. HOWTO (R_TCL, /* type */
  720. 0, /* rightshift */
  721. 1, /* size (0 = byte, 1 = short, 2 = long) */
  722. 16, /* bitsize */
  723. FALSE, /* pc_relative */
  724. 0, /* bitpos */
  725. complain_overflow_bitfield, /* complain_on_overflow */
  726. 0, /* special_function */
  727. "R_TCL", /* name */
  728. TRUE, /* partial_inplace */
  729. 0xffff, /* src_mask */
  730. 0xffff, /* dst_mask */
  731. FALSE), /* pcrel_offset */
  732. EMPTY_HOWTO (7),
  733. /* Non modifiable absolute branch. */
  734. HOWTO (R_BA, /* type */
  735. 0, /* rightshift */
  736. 2, /* size (0 = byte, 1 = short, 2 = long) */
  737. 26, /* bitsize */
  738. FALSE, /* pc_relative */
  739. 0, /* bitpos */
  740. complain_overflow_bitfield, /* complain_on_overflow */
  741. 0, /* special_function */
  742. "R_BA_26", /* name */
  743. TRUE, /* partial_inplace */
  744. 0x03fffffc, /* src_mask */
  745. 0x03fffffc, /* dst_mask */
  746. FALSE), /* pcrel_offset */
  747. EMPTY_HOWTO (9),
  748. /* Non modifiable relative branch. */
  749. HOWTO (R_BR, /* type */
  750. 0, /* rightshift */
  751. 2, /* size (0 = byte, 1 = short, 2 = long) */
  752. 26, /* bitsize */
  753. TRUE, /* pc_relative */
  754. 0, /* bitpos */
  755. complain_overflow_signed, /* complain_on_overflow */
  756. 0, /* special_function */
  757. "R_BR", /* name */
  758. TRUE, /* partial_inplace */
  759. 0x03fffffc, /* src_mask */
  760. 0x03fffffc, /* dst_mask */
  761. FALSE), /* pcrel_offset */
  762. EMPTY_HOWTO (0xb),
  763. /* Indirect load. */
  764. HOWTO (R_RL, /* type */
  765. 0, /* rightshift */
  766. 1, /* size (0 = byte, 1 = short, 2 = long) */
  767. 16, /* bitsize */
  768. FALSE, /* pc_relative */
  769. 0, /* bitpos */
  770. complain_overflow_bitfield, /* complain_on_overflow */
  771. 0, /* special_function */
  772. "R_RL", /* name */
  773. TRUE, /* partial_inplace */
  774. 0xffff, /* src_mask */
  775. 0xffff, /* dst_mask */
  776. FALSE), /* pcrel_offset */
  777. /* Load address. */
  778. HOWTO (R_RLA, /* type */
  779. 0, /* rightshift */
  780. 1, /* size (0 = byte, 1 = short, 2 = long) */
  781. 16, /* bitsize */
  782. FALSE, /* pc_relative */
  783. 0, /* bitpos */
  784. complain_overflow_bitfield, /* complain_on_overflow */
  785. 0, /* special_function */
  786. "R_RLA", /* name */
  787. TRUE, /* partial_inplace */
  788. 0xffff, /* src_mask */
  789. 0xffff, /* dst_mask */
  790. FALSE), /* pcrel_offset */
  791. EMPTY_HOWTO (0xe),
  792. /* Non-relocating reference. Bitsize is 1 so that r_rsize is 0. */
  793. HOWTO (R_REF, /* type */
  794. 0, /* rightshift */
  795. 0, /* size (0 = byte, 1 = short, 2 = long) */
  796. 1, /* bitsize */
  797. FALSE, /* pc_relative */
  798. 0, /* bitpos */
  799. complain_overflow_dont, /* complain_on_overflow */
  800. 0, /* special_function */
  801. "R_REF", /* name */
  802. FALSE, /* partial_inplace */
  803. 0, /* src_mask */
  804. 0, /* dst_mask */
  805. FALSE), /* pcrel_offset */
  806. EMPTY_HOWTO (0x10),
  807. EMPTY_HOWTO (0x11),
  808. /* TOC relative indirect load. */
  809. HOWTO (R_TRL, /* type */
  810. 0, /* rightshift */
  811. 1, /* size (0 = byte, 1 = short, 2 = long) */
  812. 16, /* bitsize */
  813. FALSE, /* pc_relative */
  814. 0, /* bitpos */
  815. complain_overflow_bitfield, /* complain_on_overflow */
  816. 0, /* special_function */
  817. "R_TRL", /* name */
  818. TRUE, /* partial_inplace */
  819. 0xffff, /* src_mask */
  820. 0xffff, /* dst_mask */
  821. FALSE), /* pcrel_offset */
  822. /* TOC relative load address. */
  823. HOWTO (R_TRLA, /* type */
  824. 0, /* rightshift */
  825. 1, /* size (0 = byte, 1 = short, 2 = long) */
  826. 16, /* bitsize */
  827. FALSE, /* pc_relative */
  828. 0, /* bitpos */
  829. complain_overflow_bitfield, /* complain_on_overflow */
  830. 0, /* special_function */
  831. "R_TRLA", /* name */
  832. TRUE, /* partial_inplace */
  833. 0xffff, /* src_mask */
  834. 0xffff, /* dst_mask */
  835. FALSE), /* pcrel_offset */
  836. /* Modifiable relative branch. */
  837. HOWTO (R_RRTBI, /* type */
  838. 1, /* rightshift */
  839. 2, /* size (0 = byte, 1 = short, 2 = long) */
  840. 32, /* bitsize */
  841. FALSE, /* pc_relative */
  842. 0, /* bitpos */
  843. complain_overflow_bitfield, /* complain_on_overflow */
  844. 0, /* special_function */
  845. "R_RRTBI", /* name */
  846. TRUE, /* partial_inplace */
  847. 0xffffffff, /* src_mask */
  848. 0xffffffff, /* dst_mask */
  849. FALSE), /* pcrel_offset */
  850. /* Modifiable absolute branch. */
  851. HOWTO (R_RRTBA, /* type */
  852. 1, /* rightshift */
  853. 2, /* size (0 = byte, 1 = short, 2 = long) */
  854. 32, /* bitsize */
  855. FALSE, /* pc_relative */
  856. 0, /* bitpos */
  857. complain_overflow_bitfield, /* complain_on_overflow */
  858. 0, /* special_function */
  859. "R_RRTBA", /* name */
  860. TRUE, /* partial_inplace */
  861. 0xffffffff, /* src_mask */
  862. 0xffffffff, /* dst_mask */
  863. FALSE), /* pcrel_offset */
  864. /* Modifiable call absolute indirect. */
  865. HOWTO (R_CAI, /* type */
  866. 0, /* rightshift */
  867. 1, /* size (0 = byte, 1 = short, 2 = long) */
  868. 16, /* bitsize */
  869. FALSE, /* pc_relative */
  870. 0, /* bitpos */
  871. complain_overflow_bitfield, /* complain_on_overflow */
  872. 0, /* special_function */
  873. "R_CAI", /* name */
  874. TRUE, /* partial_inplace */
  875. 0xffff, /* src_mask */
  876. 0xffff, /* dst_mask */
  877. FALSE), /* pcrel_offset */
  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. /* Modifiable branch absolute. */
  893. HOWTO (R_RBA, /* type */
  894. 0, /* rightshift */
  895. 2, /* size (0 = byte, 1 = short, 2 = long) */
  896. 26, /* bitsize */
  897. FALSE, /* pc_relative */
  898. 0, /* bitpos */
  899. complain_overflow_bitfield, /* complain_on_overflow */
  900. 0, /* special_function */
  901. "R_RBA", /* name */
  902. TRUE, /* partial_inplace */
  903. 0x03fffffc, /* src_mask */
  904. 0x03fffffc, /* dst_mask */
  905. FALSE), /* pcrel_offset */
  906. /* Modifiable branch absolute. */
  907. HOWTO (R_RBAC, /* type */
  908. 0, /* rightshift */
  909. 2, /* size (0 = byte, 1 = short, 2 = long) */
  910. 32, /* bitsize */
  911. FALSE, /* pc_relative */
  912. 0, /* bitpos */
  913. complain_overflow_bitfield, /* complain_on_overflow */
  914. 0, /* special_function */
  915. "R_RBAC", /* name */
  916. TRUE, /* partial_inplace */
  917. 0xffffffff, /* src_mask */
  918. 0xffffffff, /* dst_mask */
  919. FALSE), /* pcrel_offset */
  920. /* Modifiable branch relative. */
  921. HOWTO (R_RBR, /* type */
  922. 0, /* rightshift */
  923. 2, /* size (0 = byte, 1 = short, 2 = long) */
  924. 26, /* bitsize */
  925. FALSE, /* pc_relative */
  926. 0, /* bitpos */
  927. complain_overflow_signed, /* complain_on_overflow */
  928. 0, /* special_function */
  929. "R_RBR_26", /* name */
  930. TRUE, /* partial_inplace */
  931. 0x03fffffc, /* src_mask */
  932. 0x03fffffc, /* dst_mask */
  933. FALSE), /* pcrel_offset */
  934. /* Modifiable branch absolute. */
  935. HOWTO (R_RBRC, /* type */
  936. 0, /* rightshift */
  937. 1, /* size (0 = byte, 1 = short, 2 = long) */
  938. 16, /* bitsize */
  939. FALSE, /* pc_relative */
  940. 0, /* bitpos */
  941. complain_overflow_bitfield, /* complain_on_overflow */
  942. 0, /* special_function */
  943. "R_RBRC", /* name */
  944. TRUE, /* partial_inplace */
  945. 0xffff, /* src_mask */
  946. 0xffff, /* dst_mask */
  947. FALSE), /* pcrel_offset */
  948. /* 16 bit Non modifiable absolute branch. */
  949. HOWTO (R_BA, /* type */
  950. 0, /* rightshift */
  951. 1, /* size (0 = byte, 1 = short, 2 = long) */
  952. 16, /* bitsize */
  953. FALSE, /* pc_relative */
  954. 0, /* bitpos */
  955. complain_overflow_bitfield, /* complain_on_overflow */
  956. 0, /* special_function */
  957. "R_BA_16", /* name */
  958. TRUE, /* partial_inplace */
  959. 0xfffc, /* src_mask */
  960. 0xfffc, /* dst_mask */
  961. FALSE), /* pcrel_offset */
  962. /* Modifiable branch relative. */
  963. HOWTO (R_RBR, /* type */
  964. 0, /* rightshift */
  965. 1, /* size (0 = byte, 1 = short, 2 = long) */
  966. 16, /* bitsize */
  967. FALSE, /* pc_relative */
  968. 0, /* bitpos */
  969. complain_overflow_signed, /* complain_on_overflow */
  970. 0, /* special_function */
  971. "R_RBR_16", /* name */
  972. TRUE, /* partial_inplace */
  973. 0xffff, /* src_mask */
  974. 0xffff, /* dst_mask */
  975. FALSE), /* pcrel_offset */
  976. /* Modifiable branch relative. */
  977. HOWTO (R_RBA, /* type */
  978. 0, /* rightshift */
  979. 1, /* size (0 = byte, 1 = short, 2 = long) */
  980. 16, /* bitsize */
  981. FALSE, /* pc_relative */
  982. 0, /* bitpos */
  983. complain_overflow_signed, /* complain_on_overflow */
  984. 0, /* special_function */
  985. "R_RBA_16", /* name */
  986. TRUE, /* partial_inplace */
  987. 0xffff, /* src_mask */
  988. 0xffff, /* dst_mask */
  989. FALSE), /* pcrel_offset */
  990. };
  991. void
  992. xcoff_rtype2howto (arelent *relent, struct internal_reloc *internal)
  993. {
  994. if (internal->r_type > R_RBRC)
  995. abort ();
  996. /* Default howto layout works most of the time */
  997. relent->howto = &xcoff_howto_table[internal->r_type];
  998. /* Special case some 16 bit reloc */
  999. if (15 == (internal->r_size & 0x1f))
  1000. {
  1001. if (R_BA == internal->r_type)
  1002. relent->howto = &xcoff_howto_table[0x1c];
  1003. else if (R_RBR == internal->r_type)
  1004. relent->howto = &xcoff_howto_table[0x1d];
  1005. else if (R_RBA == internal->r_type)
  1006. relent->howto = &xcoff_howto_table[0x1e];
  1007. }
  1008. /* The r_size field of an XCOFF reloc encodes the bitsize of the
  1009. relocation, as well as indicating whether it is signed or not.
  1010. Doublecheck that the relocation information gathered from the
  1011. type matches this information. The bitsize is not significant
  1012. for R_REF relocs. */
  1013. if (relent->howto->dst_mask != 0
  1014. && (relent->howto->bitsize
  1015. != ((unsigned int) internal->r_size & 0x1f) + 1))
  1016. abort ();
  1017. }
  1018. reloc_howto_type *
  1019. _bfd_xcoff_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  1020. bfd_reloc_code_real_type code)
  1021. {
  1022. switch (code)
  1023. {
  1024. case BFD_RELOC_PPC_B26:
  1025. return &xcoff_howto_table[0xa];
  1026. case BFD_RELOC_PPC_BA16:
  1027. return &xcoff_howto_table[0x1c];
  1028. case BFD_RELOC_PPC_BA26:
  1029. return &xcoff_howto_table[8];
  1030. case BFD_RELOC_PPC_TOC16:
  1031. return &xcoff_howto_table[3];
  1032. case BFD_RELOC_32:
  1033. case BFD_RELOC_CTOR:
  1034. return &xcoff_howto_table[0];
  1035. case BFD_RELOC_NONE:
  1036. return &xcoff_howto_table[0xf];
  1037. default:
  1038. return NULL;
  1039. }
  1040. }
  1041. static reloc_howto_type *
  1042. _bfd_xcoff_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  1043. const char *r_name)
  1044. {
  1045. unsigned int i;
  1046. for (i = 0;
  1047. i < sizeof (xcoff_howto_table) / sizeof (xcoff_howto_table[0]);
  1048. i++)
  1049. if (xcoff_howto_table[i].name != NULL
  1050. && strcasecmp (xcoff_howto_table[i].name, r_name) == 0)
  1051. return &xcoff_howto_table[i];
  1052. return NULL;
  1053. }
  1054. /* XCOFF archive support. The original version of this code was by
  1055. Damon A. Permezel. It was enhanced to permit cross support, and
  1056. writing archive files, by Ian Lance Taylor, Cygnus Support.
  1057. XCOFF uses its own archive format. Everything is hooked together
  1058. with file offset links, so it is possible to rapidly update an
  1059. archive in place. Of course, we don't do that. An XCOFF archive
  1060. has a real file header, not just an ARMAG string. The structure of
  1061. the file header and of each archive header appear below.
  1062. An XCOFF archive also has a member table, which is a list of
  1063. elements in the archive (you can get that by looking through the
  1064. linked list, but you have to read a lot more of the file). The
  1065. member table has a normal archive header with an empty name. It is
  1066. normally (and perhaps must be) the second to last entry in the
  1067. archive. The member table data is almost printable ASCII. It
  1068. starts with a 12 character decimal string which is the number of
  1069. entries in the table. For each entry it has a 12 character decimal
  1070. string which is the offset in the archive of that member. These
  1071. entries are followed by a series of null terminated strings which
  1072. are the member names for each entry.
  1073. Finally, an XCOFF archive has a global symbol table, which is what
  1074. we call the armap. The global symbol table has a normal archive
  1075. header with an empty name. It is normally (and perhaps must be)
  1076. the last entry in the archive. The contents start with a four byte
  1077. binary number which is the number of entries. This is followed by
  1078. a that many four byte binary numbers; each is the file offset of an
  1079. entry in the archive. These numbers are followed by a series of
  1080. null terminated strings, which are symbol names.
  1081. AIX 4.3 introduced a new archive format which can handle larger
  1082. files and also 32- and 64-bit objects in the same archive. The
  1083. things said above remain true except that there is now more than
  1084. one global symbol table. The one is used to index 32-bit objects,
  1085. the other for 64-bit objects.
  1086. The new archives (recognizable by the new ARMAG string) has larger
  1087. field lengths so that we cannot really share any code. Also we have
  1088. to take care that we are not generating the new form of archives
  1089. on AIX 4.2 or earlier systems. */
  1090. /* XCOFF archives use this as a magic string. Note that both strings
  1091. have the same length. */
  1092. /* Set the magic for archive. */
  1093. bfd_boolean
  1094. bfd_xcoff_ar_archive_set_magic (bfd *abfd ATTRIBUTE_UNUSED,
  1095. char *magic ATTRIBUTE_UNUSED)
  1096. {
  1097. /* Not supported yet. */
  1098. return FALSE;
  1099. /* bfd_xcoff_archive_set_magic (abfd, magic); */
  1100. }
  1101. /* Read in the armap of an XCOFF archive. */
  1102. bfd_boolean
  1103. _bfd_xcoff_slurp_armap (bfd *abfd)
  1104. {
  1105. file_ptr off;
  1106. size_t namlen;
  1107. bfd_size_type sz;
  1108. bfd_byte *contents, *cend;
  1109. bfd_vma c, i;
  1110. carsym *arsym;
  1111. bfd_byte *p;
  1112. if (xcoff_ardata (abfd) == NULL)
  1113. {
  1114. bfd_has_map (abfd) = FALSE;
  1115. return TRUE;
  1116. }
  1117. if (! xcoff_big_format_p (abfd))
  1118. {
  1119. /* This is for the old format. */
  1120. struct xcoff_ar_hdr hdr;
  1121. off = strtol (xcoff_ardata (abfd)->symoff, (char **) NULL, 10);
  1122. if (off == 0)
  1123. {
  1124. bfd_has_map (abfd) = FALSE;
  1125. return TRUE;
  1126. }
  1127. if (bfd_seek (abfd, off, SEEK_SET) != 0)
  1128. return FALSE;
  1129. /* The symbol table starts with a normal archive header. */
  1130. if (bfd_bread (&hdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
  1131. != SIZEOF_AR_HDR)
  1132. return FALSE;
  1133. /* Skip the name (normally empty). */
  1134. namlen = strtol (hdr.namlen, (char **) NULL, 10);
  1135. off = ((namlen + 1) & ~ (size_t) 1) + SXCOFFARFMAG;
  1136. if (bfd_seek (abfd, off, SEEK_CUR) != 0)
  1137. return FALSE;
  1138. sz = strtol (hdr.size, (char **) NULL, 10);
  1139. /* Read in the entire symbol table. */
  1140. contents = (bfd_byte *) bfd_alloc (abfd, sz);
  1141. if (contents == NULL)
  1142. return FALSE;
  1143. if (bfd_bread (contents, sz, abfd) != sz)
  1144. return FALSE;
  1145. /* The symbol table starts with a four byte count. */
  1146. c = H_GET_32 (abfd, contents);
  1147. if (c * 4 >= sz)
  1148. {
  1149. bfd_set_error (bfd_error_bad_value);
  1150. return FALSE;
  1151. }
  1152. bfd_ardata (abfd)->symdefs =
  1153. ((carsym *) bfd_alloc (abfd, c * sizeof (carsym)));
  1154. if (bfd_ardata (abfd)->symdefs == NULL)
  1155. return FALSE;
  1156. /* After the count comes a list of four byte file offsets. */
  1157. for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 4;
  1158. i < c;
  1159. ++i, ++arsym, p += 4)
  1160. arsym->file_offset = H_GET_32 (abfd, p);
  1161. }
  1162. else
  1163. {
  1164. /* This is for the new format. */
  1165. struct xcoff_ar_hdr_big hdr;
  1166. off = strtol (xcoff_ardata_big (abfd)->symoff, (char **) NULL, 10);
  1167. if (off == 0)
  1168. {
  1169. bfd_has_map (abfd) = FALSE;
  1170. return TRUE;
  1171. }
  1172. if (bfd_seek (abfd, off, SEEK_SET) != 0)
  1173. return FALSE;
  1174. /* The symbol table starts with a normal archive header. */
  1175. if (bfd_bread (&hdr, (bfd_size_type) SIZEOF_AR_HDR_BIG, abfd)
  1176. != SIZEOF_AR_HDR_BIG)
  1177. return FALSE;
  1178. /* Skip the name (normally empty). */
  1179. namlen = strtol (hdr.namlen, (char **) NULL, 10);
  1180. off = ((namlen + 1) & ~ (size_t) 1) + SXCOFFARFMAG;
  1181. if (bfd_seek (abfd, off, SEEK_CUR) != 0)
  1182. return FALSE;
  1183. /* XXX This actually has to be a call to strtoll (at least on 32-bit
  1184. machines) since the field width is 20 and there numbers with more
  1185. than 32 bits can be represented. */
  1186. sz = strtol (hdr.size, (char **) NULL, 10);
  1187. /* Read in the entire symbol table. */
  1188. contents = (bfd_byte *) bfd_alloc (abfd, sz);
  1189. if (contents == NULL)
  1190. return FALSE;
  1191. if (bfd_bread (contents, sz, abfd) != sz)
  1192. return FALSE;
  1193. /* The symbol table starts with an eight byte count. */
  1194. c = H_GET_64 (abfd, contents);
  1195. if (c * 8 >= sz)
  1196. {
  1197. bfd_set_error (bfd_error_bad_value);
  1198. return FALSE;
  1199. }
  1200. bfd_ardata (abfd)->symdefs =
  1201. ((carsym *) bfd_alloc (abfd, c * sizeof (carsym)));
  1202. if (bfd_ardata (abfd)->symdefs == NULL)
  1203. return FALSE;
  1204. /* After the count comes a list of eight byte file offsets. */
  1205. for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 8;
  1206. i < c;
  1207. ++i, ++arsym, p += 8)
  1208. arsym->file_offset = H_GET_64 (abfd, p);
  1209. }
  1210. /* After the file offsets come null terminated symbol names. */
  1211. cend = contents + sz;
  1212. for (i = 0, arsym = bfd_ardata (abfd)->symdefs;
  1213. i < c;
  1214. ++i, ++arsym, p += strlen ((char *) p) + 1)
  1215. {
  1216. if (p >= cend)
  1217. {
  1218. bfd_set_error (bfd_error_bad_value);
  1219. return FALSE;
  1220. }
  1221. arsym->name = (char *) p;
  1222. }
  1223. bfd_ardata (abfd)->symdef_count = c;
  1224. bfd_has_map (abfd) = TRUE;
  1225. return TRUE;
  1226. }
  1227. /* See if this is an XCOFF archive. */
  1228. const bfd_target *
  1229. _bfd_xcoff_archive_p (bfd *abfd)
  1230. {
  1231. struct artdata *tdata_hold;
  1232. char magic[SXCOFFARMAG];
  1233. bfd_size_type amt = SXCOFFARMAG;
  1234. if (bfd_bread (magic, amt, abfd) != amt)
  1235. {
  1236. if (bfd_get_error () != bfd_error_system_call)
  1237. bfd_set_error (bfd_error_wrong_format);
  1238. return NULL;
  1239. }
  1240. if (strncmp (magic, XCOFFARMAG, SXCOFFARMAG) != 0
  1241. && strncmp (magic, XCOFFARMAGBIG, SXCOFFARMAG) != 0)
  1242. {
  1243. bfd_set_error (bfd_error_wrong_format);
  1244. return NULL;
  1245. }
  1246. tdata_hold = bfd_ardata (abfd);
  1247. amt = sizeof (struct artdata);
  1248. bfd_ardata (abfd) = (struct artdata *) bfd_zalloc (abfd, amt);
  1249. if (bfd_ardata (abfd) == (struct artdata *) NULL)
  1250. goto error_ret_restore;
  1251. /* Cleared by bfd_zalloc above.
  1252. bfd_ardata (abfd)->cache = NULL;
  1253. bfd_ardata (abfd)->archive_head = NULL;
  1254. bfd_ardata (abfd)->symdefs = NULL;
  1255. bfd_ardata (abfd)->extended_names = NULL;
  1256. bfd_ardata (abfd)->extended_names_size = 0; */
  1257. /* Now handle the two formats. */
  1258. if (magic[1] != 'b')
  1259. {
  1260. /* This is the old format. */
  1261. struct xcoff_ar_file_hdr hdr;
  1262. /* Copy over the magic string. */
  1263. memcpy (hdr.magic, magic, SXCOFFARMAG);
  1264. /* Now read the rest of the file header. */
  1265. amt = SIZEOF_AR_FILE_HDR - SXCOFFARMAG;
  1266. if (bfd_bread (&hdr.memoff, amt, abfd) != amt)
  1267. {
  1268. if (bfd_get_error () != bfd_error_system_call)
  1269. bfd_set_error (bfd_error_wrong_format);
  1270. goto error_ret;
  1271. }
  1272. bfd_ardata (abfd)->first_file_filepos = strtol (hdr.firstmemoff,
  1273. (char **) NULL, 10);
  1274. amt = SIZEOF_AR_FILE_HDR;
  1275. bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, amt);
  1276. if (bfd_ardata (abfd)->tdata == NULL)
  1277. goto error_ret;
  1278. memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR);
  1279. }
  1280. else
  1281. {
  1282. /* This is the new format. */
  1283. struct xcoff_ar_file_hdr_big hdr;
  1284. /* Copy over the magic string. */
  1285. memcpy (hdr.magic, magic, SXCOFFARMAG);
  1286. /* Now read the rest of the file header. */
  1287. amt = SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG;
  1288. if (bfd_bread (&hdr.memoff, amt, abfd) != amt)
  1289. {
  1290. if (bfd_get_error () != bfd_error_system_call)
  1291. bfd_set_error (bfd_error_wrong_format);
  1292. goto error_ret;
  1293. }
  1294. bfd_ardata (abfd)->first_file_filepos = bfd_scan_vma (hdr.firstmemoff,
  1295. (const char **) 0,
  1296. 10);
  1297. amt = SIZEOF_AR_FILE_HDR_BIG;
  1298. bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, amt);
  1299. if (bfd_ardata (abfd)->tdata == NULL)
  1300. goto error_ret;
  1301. memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR_BIG);
  1302. }
  1303. if (! _bfd_xcoff_slurp_armap (abfd))
  1304. {
  1305. error_ret:
  1306. bfd_release (abfd, bfd_ardata (abfd));
  1307. error_ret_restore:
  1308. bfd_ardata (abfd) = tdata_hold;
  1309. return NULL;
  1310. }
  1311. return abfd->xvec;
  1312. }
  1313. /* Read the archive header in an XCOFF archive. */
  1314. void *
  1315. _bfd_xcoff_read_ar_hdr (bfd *abfd)
  1316. {
  1317. bfd_size_type namlen;
  1318. struct areltdata *ret;
  1319. bfd_size_type amt = sizeof (struct areltdata);
  1320. ret = (struct areltdata *) bfd_alloc (abfd, amt);
  1321. if (ret == NULL)
  1322. return NULL;
  1323. if (! xcoff_big_format_p (abfd))
  1324. {
  1325. struct xcoff_ar_hdr hdr;
  1326. struct xcoff_ar_hdr *hdrp;
  1327. if (bfd_bread (&hdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
  1328. != SIZEOF_AR_HDR)
  1329. {
  1330. free (ret);
  1331. return NULL;
  1332. }
  1333. namlen = strtol (hdr.namlen, (char **) NULL, 10);
  1334. amt = SIZEOF_AR_HDR + namlen + 1;
  1335. hdrp = (struct xcoff_ar_hdr *) bfd_alloc (abfd, amt);
  1336. if (hdrp == NULL)
  1337. {
  1338. free (ret);
  1339. return NULL;
  1340. }
  1341. memcpy (hdrp, &hdr, SIZEOF_AR_HDR);
  1342. if (bfd_bread ((char *) hdrp + SIZEOF_AR_HDR, namlen, abfd) != namlen)
  1343. {
  1344. free (ret);
  1345. return NULL;
  1346. }
  1347. ((char *) hdrp)[SIZEOF_AR_HDR + namlen] = '\0';
  1348. ret->arch_header = (char *) hdrp;
  1349. ret->parsed_size = strtol (hdr.size, (char **) NULL, 10);
  1350. ret->filename = (char *) hdrp + SIZEOF_AR_HDR;
  1351. }
  1352. else
  1353. {
  1354. struct xcoff_ar_hdr_big hdr;
  1355. struct xcoff_ar_hdr_big *hdrp;
  1356. if (bfd_bread (&hdr, (bfd_size_type) SIZEOF_AR_HDR_BIG, abfd)
  1357. != SIZEOF_AR_HDR_BIG)
  1358. {
  1359. free (ret);
  1360. return NULL;
  1361. }
  1362. namlen = strtol (hdr.namlen, (char **) NULL, 10);
  1363. amt = SIZEOF_AR_HDR_BIG + namlen + 1;
  1364. hdrp = (struct xcoff_ar_hdr_big *) bfd_alloc (abfd, amt);
  1365. if (hdrp == NULL)
  1366. {
  1367. free (ret);
  1368. return NULL;
  1369. }
  1370. memcpy (hdrp, &hdr, SIZEOF_AR_HDR_BIG);
  1371. if (bfd_bread ((char *) hdrp + SIZEOF_AR_HDR_BIG, namlen, abfd) != namlen)
  1372. {
  1373. free (ret);
  1374. return NULL;
  1375. }
  1376. ((char *) hdrp)[SIZEOF_AR_HDR_BIG + namlen] = '\0';
  1377. ret->arch_header = (char *) hdrp;
  1378. /* XXX This actually has to be a call to strtoll (at least on 32-bit
  1379. machines) since the field width is 20 and there numbers with more
  1380. than 32 bits can be represented. */
  1381. ret->parsed_size = strtol (hdr.size, (char **) NULL, 10);
  1382. ret->filename = (char *) hdrp + SIZEOF_AR_HDR_BIG;
  1383. }
  1384. /* Skip over the XCOFFARFMAG at the end of the file name. */
  1385. if (bfd_seek (abfd, (file_ptr) ((namlen & 1) + SXCOFFARFMAG), SEEK_CUR) != 0)
  1386. return NULL;
  1387. return ret;
  1388. }
  1389. /* Open the next element in an XCOFF archive. */
  1390. bfd *
  1391. _bfd_xcoff_openr_next_archived_file (bfd *archive, bfd *last_file)
  1392. {
  1393. file_ptr filestart;
  1394. if (xcoff_ardata (archive) == NULL)
  1395. {
  1396. bfd_set_error (bfd_error_invalid_operation);
  1397. return NULL;
  1398. }
  1399. if (! xcoff_big_format_p (archive))
  1400. {
  1401. if (last_file == NULL)
  1402. filestart = bfd_ardata (archive)->first_file_filepos;
  1403. else
  1404. filestart = strtol (arch_xhdr (last_file)->nextoff, (char **) NULL,
  1405. 10);
  1406. if (filestart == 0
  1407. || filestart == strtol (xcoff_ardata (archive)->memoff,
  1408. (char **) NULL, 10)
  1409. || filestart == strtol (xcoff_ardata (archive)->symoff,
  1410. (char **) NULL, 10))
  1411. {
  1412. bfd_set_error (bfd_error_no_more_archived_files);
  1413. return NULL;
  1414. }
  1415. }
  1416. else
  1417. {
  1418. if (last_file == NULL)
  1419. filestart = bfd_ardata (archive)->first_file_filepos;
  1420. else
  1421. /* XXX These actually have to be a calls to strtoll (at least
  1422. on 32-bit machines) si…

Large files files are truncated, but you can click here to view the full file