PageRenderTime 40ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 1ms

/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
  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) since the fields's width is 20 and
  1423. there numbers with more than 32 bits can be represented. */
  1424. filestart = strtol (arch_xhdr_big (last_file)->nextoff, (char **) NULL,
  1425. 10);
  1426. /* XXX These actually have to be calls to strtoll (at least on 32-bit
  1427. machines) since the fields's width is 20 and there numbers with more
  1428. than 32 bits can be represented. */
  1429. if (filestart == 0
  1430. || filestart == strtol (xcoff_ardata_big (archive)->memoff,
  1431. (char **) NULL, 10)
  1432. || filestart == strtol (xcoff_ardata_big (archive)->symoff,
  1433. (char **) NULL, 10))
  1434. {
  1435. bfd_set_error (bfd_error_no_more_archived_files);
  1436. return NULL;
  1437. }
  1438. }
  1439. return _bfd_get_elt_at_filepos (archive, filestart);
  1440. }
  1441. /* Stat an element in an XCOFF archive. */
  1442. int
  1443. _bfd_xcoff_stat_arch_elt (bfd *abfd, struct stat *s)
  1444. {
  1445. if (abfd->arelt_data == NULL)
  1446. {
  1447. bfd_set_error (bfd_error_invalid_operation);
  1448. return -1;
  1449. }
  1450. if (! xcoff_big_format_p (abfd->my_archive))
  1451. {
  1452. struct xcoff_ar_hdr *hdrp = arch_xhdr (abfd);
  1453. s->st_mtime = strtol (hdrp->date, (char **) NULL, 10);
  1454. s->st_uid = strtol (hdrp->uid, (char **) NULL, 10);
  1455. s->st_gid = strtol (hdrp->gid, (char **) NULL, 10);
  1456. s->st_mode = strtol (hdrp->mode, (char **) NULL, 8);
  1457. s->st_size = arch_eltdata (abfd)->parsed_size;
  1458. }
  1459. else
  1460. {
  1461. struct xcoff_ar_hdr_big *hdrp = arch_xhdr_big (abfd);
  1462. s->st_mtime = strtol (hdrp->date, (char **) NULL, 10);
  1463. s->st_uid = strtol (hdrp->uid, (char **) NULL, 10);
  1464. s->st_gid = strtol (hdrp->gid, (char **) NULL, 10);
  1465. s->st_mode = strtol (hdrp->mode, (char **) NULL, 8);
  1466. s->st_size = arch_eltdata (abfd)->parsed_size;
  1467. }
  1468. return 0;
  1469. }
  1470. /* Normalize a file name for inclusion in an archive. */
  1471. static const char *
  1472. normalize_filename (bfd *abfd)
  1473. {
  1474. const char *file;
  1475. const char *filename;
  1476. file = bfd_get_filename (abfd);
  1477. filename = strrchr (file, '/');
  1478. if (filename != NULL)
  1479. filename++;
  1480. else
  1481. filename = file;
  1482. return filename;
  1483. }
  1484. /* Write out an XCOFF armap. */
  1485. static bfd_boolean
  1486. xcoff_write_armap_old (bfd *abfd, unsigned int elength ATTRIBUTE_UNUSED,
  1487. struct orl *map, unsigned int orl_count, int stridx)
  1488. {
  1489. struct archive_iterator iterator;
  1490. struct xcoff_ar_hdr hdr;
  1491. char *p;
  1492. unsigned char buf[4];
  1493. unsigned int i;
  1494. memset (&hdr, 0, sizeof hdr);
  1495. sprintf (hdr.size, "%ld", (long) (4 + orl_count * 4 + stridx));
  1496. sprintf (hdr.nextoff, "%d", 0);
  1497. memcpy (hdr.prevoff, xcoff_ardata (abfd)->memoff, XCOFFARMAG_ELEMENT_SIZE);
  1498. sprintf (hdr.date, "%d", 0);
  1499. sprintf (hdr.uid, "%d", 0);
  1500. sprintf (hdr.gid, "%d", 0);
  1501. sprintf (hdr.mode, "%d", 0);
  1502. sprintf (hdr.namlen, "%d", 0);
  1503. /* We need spaces, not null bytes, in the header. */
  1504. for (p = (char *) &hdr; p < (char *) &hdr + SIZEOF_AR_HDR; p++)
  1505. if (*p == '\0')
  1506. *p = ' ';
  1507. if (bfd_bwrite (&hdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
  1508. != SIZEOF_AR_HDR
  1509. || (bfd_bwrite (XCOFFARFMAG, (bfd_size_type) SXCOFFARFMAG, abfd)
  1510. != SXCOFFARFMAG))
  1511. return FALSE;
  1512. H_PUT_32 (abfd, orl_count, buf);
  1513. if (bfd_bwrite (buf, (bfd_size_type) 4, abfd) != 4)
  1514. return FALSE;
  1515. i = 0;
  1516. archive_iterator_begin (&iterator, abfd);
  1517. while (i < orl_count && archive_iterator_next (&iterator))
  1518. while (map[i].u.abfd == iterator.current.member)
  1519. {
  1520. H_PUT_32 (abfd, iterator.current.offset, buf);
  1521. if (bfd_bwrite (buf, (bfd_size_type) 4, abfd) != 4)
  1522. return FALSE;
  1523. ++i;
  1524. }
  1525. for (i = 0; i < orl_count; i++)
  1526. {
  1527. const char *name;
  1528. size_t namlen;
  1529. name = *map[i].name;
  1530. namlen = strlen (name);
  1531. if (bfd_bwrite (name, (bfd_size_type) (namlen + 1), abfd) != namlen + 1)
  1532. return FALSE;
  1533. }
  1534. if ((stridx & 1) != 0)
  1535. {
  1536. char b;
  1537. b = '\0';
  1538. if (bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1)
  1539. return FALSE;
  1540. }
  1541. return TRUE;
  1542. }
  1543. static char buff20[XCOFFARMAGBIG_ELEMENT_SIZE + 1];
  1544. #define FMT20 "%-20lld"
  1545. #define FMT12 "%-12d"
  1546. #define FMT12_OCTAL "%-12o"
  1547. #define FMT4 "%-4d"
  1548. #define PRINT20(d, v) \
  1549. sprintf (buff20, FMT20, (long long)(v)), \
  1550. memcpy ((void *) (d), buff20, 20)
  1551. #define PRINT12(d, v) \
  1552. sprintf (buff20, FMT12, (int)(v)), \
  1553. memcpy ((void *) (d), buff20, 12)
  1554. #define PRINT12_OCTAL(d, v) \
  1555. sprintf (buff20, FMT12_OCTAL, (unsigned int)(v)), \
  1556. memcpy ((void *) (d), buff20, 12)
  1557. #define PRINT4(d, v) \
  1558. sprintf (buff20, FMT4, (int)(v)), \
  1559. memcpy ((void *) (d), buff20, 4)
  1560. #define READ20(d, v) \
  1561. buff20[20] = 0, \
  1562. memcpy (buff20, (d), 20), \
  1563. (v) = bfd_scan_vma (buff20, (const char **) NULL, 10)
  1564. static bfd_boolean
  1565. do_pad (bfd *abfd, unsigned int number)
  1566. {
  1567. bfd_byte b = 0;
  1568. /* Limit pad to <= 4096. */
  1569. if (number > 4096)
  1570. return FALSE;
  1571. while (number--)
  1572. if (bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1)
  1573. return FALSE;
  1574. return TRUE;
  1575. }
  1576. static bfd_boolean
  1577. do_copy (bfd *out_bfd, bfd *in_bfd)
  1578. {
  1579. bfd_size_type remaining;
  1580. bfd_byte buffer[DEFAULT_BUFFERSIZE];
  1581. if (bfd_seek (in_bfd, (file_ptr) 0, SEEK_SET) != 0)
  1582. return FALSE;
  1583. remaining = arelt_size (in_bfd);
  1584. while (remaining >= DEFAULT_BUFFERSIZE)
  1585. {
  1586. if (bfd_bread (buffer, DEFAULT_BUFFERSIZE, in_bfd) != DEFAULT_BUFFERSIZE
  1587. || bfd_bwrite (buffer, DEFAULT_BUFFERSIZE, out_bfd) != DEFAULT_BUFFERSIZE)
  1588. return FALSE;
  1589. remaining -= DEFAULT_BUFFERSIZE;
  1590. }
  1591. if (remaining)
  1592. {
  1593. if (bfd_bread (buffer, remaining, in_bfd) != remaining
  1594. || bfd_bwrite (buffer, remaining, out_bfd) != remaining)
  1595. return FALSE;
  1596. }
  1597. return TRUE;
  1598. }
  1599. static bfd_boolean
  1600. xcoff_write_armap_big (bfd *abfd, unsigned int elength ATTRIBUTE_UNUSED,
  1601. struct orl *map, unsigned int orl_count, int stridx)
  1602. {
  1603. struct archive_iterator iterator;
  1604. struct xcoff_ar_file_hdr_big *fhdr;
  1605. bfd_vma i, sym_32, sym_64, str_32, str_64;
  1606. const bfd_arch_info_type *arch_info;
  1607. bfd *current_bfd;
  1608. size_t string_length;
  1609. file_ptr nextoff, prevoff;
  1610. /* First, we look through the symbols and work out which are
  1611. from 32-bit objects and which from 64-bit ones. */
  1612. sym_32 = sym_64 = str_32 = str_64 = 0;
  1613. i = 0;
  1614. for (current_bfd = abfd->archive_head;
  1615. current_bfd != NULL && i < orl_count;
  1616. current_bfd = current_bfd->archive_next)
  1617. {
  1618. arch_info = bfd_get_arch_info (current_bfd);
  1619. while (map[i].u.abfd == current_bfd)
  1620. {
  1621. string_length = strlen (*map[i].name) + 1;
  1622. if (arch_info->bits_per_address == 64)
  1623. {
  1624. sym_64++;
  1625. str_64 += string_length;
  1626. }
  1627. else
  1628. {
  1629. sym_32++;
  1630. str_32 += string_length;
  1631. }
  1632. i++;
  1633. }
  1634. }
  1635. /* A quick sanity check... */
  1636. BFD_ASSERT (sym_64 + sym_32 == orl_count);
  1637. /* Explicit cast to int for compiler. */
  1638. BFD_ASSERT ((int)(str_64 + str_32) == stridx);
  1639. fhdr = xcoff_ardata_big (abfd);
  1640. /* xcoff_write_archive_contents_big passes nextoff in symoff. */
  1641. READ20 (fhdr->memoff, prevoff);
  1642. READ20 (fhdr->symoff, nextoff);
  1643. BFD_ASSERT (nextoff == bfd_tell (abfd));
  1644. /* Write out the symbol table.
  1645. Layout :
  1646. standard big archive header
  1647. 0x0000 ar_size [0x14]
  1648. 0x0014 ar_nxtmem [0x14]
  1649. 0x0028 ar_prvmem [0x14]
  1650. 0x003C ar_date [0x0C]
  1651. 0x0048 ar_uid [0x0C]
  1652. 0x0054 ar_gid [0x0C]
  1653. 0x0060 ar_mod [0x0C]
  1654. 0x006C ar_namelen[0x04]
  1655. 0x0070 ar_fmag [SXCOFFARFMAG]
  1656. Symbol table
  1657. 0x0072 num_syms [0x08], binary
  1658. 0x0078 offsets [0x08 * num_syms], binary
  1659. 0x0086 + 0x08 * num_syms names [??]
  1660. ?? pad to even bytes.
  1661. */
  1662. if (sym_32)
  1663. {
  1664. struct xcoff_ar_hdr_big *hdr;
  1665. char *symbol_table;
  1666. char *st;
  1667. bfd_vma symbol_table_size =
  1668. SIZEOF_AR_HDR_BIG
  1669. + SXCOFFARFMAG
  1670. + 8
  1671. + 8 * sym_32
  1672. + str_32 + (str_32 & 1);
  1673. symbol_table = bfd_zmalloc (symbol_table_size);
  1674. if (symbol_table == NULL)
  1675. return FALSE;
  1676. hdr = (struct xcoff_ar_hdr_big *) symbol_table;
  1677. PRINT20 (hdr->size, 8 + 8 * sym_32 + str_32 + (str_32 & 1));
  1678. if (sym_64)
  1679. PRINT20 (hdr->nextoff, nextoff + symbol_table_size);
  1680. else
  1681. PRINT20 (hdr->nextoff, 0);
  1682. PRINT20 (hdr->prevoff, prevoff);
  1683. PRINT12 (hdr->date, 0);
  1684. PRINT12 (hdr->uid, 0);
  1685. PRINT12 (hdr->gid, 0);
  1686. PRINT12 (hdr->mode, 0);
  1687. PRINT4 (hdr->namlen, 0) ;
  1688. st = symbol_table + SIZEOF_AR_HDR_BIG;
  1689. memcpy (st, XCOFFARFMAG, SXCOFFARFMAG);
  1690. st += SXCOFFARFMAG;
  1691. bfd_h_put_64 (abfd, sym_32, st);
  1692. st += 8;
  1693. /* loop over the 32 bit offsets */
  1694. i = 0;
  1695. archive_iterator_begin (&iterator, abfd);
  1696. while (i < orl_count && archive_iterator_next (&iterator))
  1697. {
  1698. arch_info = bfd_get_arch_info (iterator.current.member);
  1699. while (map[i].u.abfd == iterator.current.member)
  1700. {
  1701. if (arch_info->bits_per_address == 32)
  1702. {
  1703. bfd_h_put_64 (abfd, iterator.current.offset, st);
  1704. st += 8;
  1705. }
  1706. i++;
  1707. }
  1708. }
  1709. /* loop over the 32 bit symbol names */
  1710. i = 0;
  1711. for (current_bfd = abfd->archive_head;
  1712. current_bfd != NULL && i < orl_count;
  1713. current_bfd = current_bfd->archive_next)
  1714. {
  1715. arch_info = bfd_get_arch_info (current_bfd);
  1716. while (map[i].u.abfd == current_bfd)
  1717. {
  1718. if (arch_info->bits_per_address == 32)
  1719. {
  1720. string_length = sprintf (st, "%s", *map[i].name);
  1721. st += string_length + 1;
  1722. }
  1723. i++;
  1724. }
  1725. }
  1726. bfd_bwrite (symbol_table, symbol_table_size, abfd);
  1727. free (symbol_table);
  1728. prevoff = nextoff;
  1729. nextoff = nextoff + symbol_table_size;
  1730. }
  1731. else
  1732. PRINT20 (fhdr->symoff, 0);
  1733. if (sym_64)
  1734. {
  1735. struct xcoff_ar_hdr_big *hdr;
  1736. char *symbol_table;
  1737. char *st;
  1738. bfd_vma symbol_table_size =
  1739. SIZEOF_AR_HDR_BIG
  1740. + SXCOFFARFMAG
  1741. + 8
  1742. + 8 * sym_64
  1743. + str_64 + (str_64 & 1);
  1744. symbol_table = bfd_zmalloc (symbol_table_size);
  1745. if (symbol_table == NULL)
  1746. return FALSE;
  1747. hdr = (struct xcoff_ar_hdr_big *) symbol_table;
  1748. PRINT20 (hdr->size, 8 + 8 * sym_64 + str_64 + (str_64 & 1));
  1749. PRINT20 (hdr->nextoff, 0);
  1750. PRINT20 (hdr->prevoff, prevoff);
  1751. PRINT12 (hdr->date, 0);
  1752. PRINT12 (hdr->uid, 0);
  1753. PRINT12 (hdr->gid, 0);
  1754. PRINT12 (hdr->mode, 0);
  1755. PRINT4 (hdr->namlen, 0);
  1756. st = symbol_table + SIZEOF_AR_HDR_BIG;
  1757. memcpy (st, XCOFFARFMAG, SXCOFFARFMAG);
  1758. st += SXCOFFARFMAG;
  1759. bfd_h_put_64 (abfd, sym_64, st);
  1760. st += 8;
  1761. /* loop over the 64 bit offsets */
  1762. i = 0;
  1763. archive_iterator_begin (&iterator, abfd);
  1764. while (i < orl_count && archive_iterator_next (&iterator))
  1765. {
  1766. arch_info = bfd_get_arch_info (iterator.current.member);
  1767. while (map[i].u.abfd == iterator.current.member)
  1768. {
  1769. if (arch_info->bits_per_address == 64)
  1770. {
  1771. bfd_h_put_64 (abfd, iterator.current.offset, st);
  1772. st += 8;
  1773. }
  1774. i++;
  1775. }
  1776. }
  1777. /* loop over the 64 bit symbol names */
  1778. i = 0;
  1779. for (current_bfd = abfd->archive_head;
  1780. current_bfd != NULL && i < orl_count;
  1781. current_bfd = current_bfd->archive_next)
  1782. {
  1783. arch_info = bfd_get_arch_info (current_bfd);
  1784. while (map[i].u.abfd == current_bfd)
  1785. {
  1786. if (arch_info->bits_per_address == 64)
  1787. {
  1788. string_length = sprintf (st, "%s", *map[i].name);
  1789. st += string_length + 1;
  1790. }
  1791. i++;
  1792. }
  1793. }
  1794. bfd_bwrite (symbol_table, symbol_table_size, abfd);
  1795. free (symbol_table);
  1796. PRINT20 (fhdr->symoff64, nextoff);
  1797. }
  1798. else
  1799. PRINT20 (fhdr->symoff64, 0);
  1800. return TRUE;
  1801. }
  1802. bfd_boolean
  1803. _bfd_xcoff_write_armap (bfd *abfd, unsigned int elength ATTRIBUTE_UNUSED,
  1804. struct orl *map, unsigned int orl_count, int stridx)
  1805. {
  1806. if (! xcoff_big_format_p (abfd))
  1807. return xcoff_write_armap_old (abfd, elength, map, orl_count, stridx);
  1808. else
  1809. return xcoff_write_armap_big (abfd, elength, map, orl_count, stridx);
  1810. }
  1811. /* Write out an XCOFF archive. We always write an entire archive,
  1812. rather than fussing with the freelist and so forth. */
  1813. static bfd_boolean
  1814. xcoff_write_archive_contents_old (bfd *abfd)
  1815. {
  1816. struct archive_iterator iterator;
  1817. struct xcoff_ar_file_hdr fhdr;
  1818. bfd_size_type count;
  1819. bfd_size_type total_namlen;
  1820. file_ptr *offsets;
  1821. bfd_boolean makemap;
  1822. bfd_boolean hasobjects;
  1823. file_ptr prevoff, nextoff;
  1824. bfd *sub;
  1825. size_t i;
  1826. struct xcoff_ar_hdr ahdr;
  1827. bfd_size_type size;
  1828. char *p;
  1829. char decbuf[XCOFFARMAG_ELEMENT_SIZE + 1];
  1830. memset (&fhdr, 0, sizeof fhdr);
  1831. (void) strncpy (fhdr.magic, XCOFFARMAG, SXCOFFARMAG);
  1832. sprintf (fhdr.firstmemoff, "%d", SIZEOF_AR_FILE_HDR);
  1833. sprintf (fhdr.freeoff, "%d", 0);
  1834. count = 0;
  1835. total_namlen = 0;
  1836. for (sub = abfd->archive_head; sub != NULL; sub = sub->archive_next)
  1837. {
  1838. ++count;
  1839. total_namlen += strlen (normalize_filename (sub)) + 1;
  1840. if (sub->arelt_data == NULL)
  1841. {
  1842. sub->arelt_data = bfd_zalloc (sub, sizeof (struct areltdata));
  1843. if (sub->arelt_data == NULL)
  1844. return FALSE;
  1845. }
  1846. if (arch_xhdr (sub) == NULL)
  1847. {
  1848. struct xcoff_ar_hdr *ahdrp;
  1849. struct stat s;
  1850. if (stat (bfd_get_filename (sub), &s) != 0)
  1851. {
  1852. bfd_set_error (bfd_error_system_call);
  1853. return FALSE;
  1854. }
  1855. ahdrp = bfd_zalloc (sub, sizeof (*ahdrp));
  1856. if (ahdrp == NULL)
  1857. return FALSE;
  1858. sprintf (ahdrp->size, "%ld", (long) s.st_size);
  1859. sprintf (ahdrp->date, "%ld", (long) s.st_mtime);
  1860. sprintf (ahdrp->uid, "%ld", (long) s.st_uid);
  1861. sprintf (ahdrp->gid, "%ld", (long) s.st_gid);
  1862. sprintf (ahdrp->mode, "%o", (unsigned int) s.st_mode);
  1863. arch_eltdata (sub)->arch_header = (char *) ahdrp;
  1864. arch_eltdata (sub)->parsed_size = s.st_size;
  1865. }
  1866. }
  1867. offsets = (file_ptr *) bfd_alloc (abfd, count * sizeof (file_ptr));
  1868. if (offsets == NULL)
  1869. return FALSE;
  1870. if (bfd_seek (abfd, (file_ptr) SIZEOF_AR_FILE_HDR, SEEK_SET) != 0)
  1871. return FALSE;
  1872. makemap = bfd_has_map (abfd);
  1873. hasobjects = FALSE;
  1874. prevoff = 0;
  1875. for (archive_iterator_begin (&iterator, abfd), i = 0;
  1876. archive_iterator_next (&iterator);
  1877. i++)
  1878. {
  1879. bfd_size_type namlen;
  1880. struct xcoff_ar_hdr *ahdrp;
  1881. if (makemap && ! hasobjects)
  1882. {
  1883. if (bfd_check_format (iterator.current.member, bfd_object))
  1884. hasobjects = TRUE;
  1885. }
  1886. ahdrp = arch_xhdr (iterator.current.member);
  1887. sprintf (ahdrp->prevoff, "%ld", (long) prevoff);
  1888. sprintf (ahdrp->namlen, "%ld", (long) iterator.current.namlen);
  1889. sprintf (ahdrp->nextoff, "%ld", (long) iterator.next.offset);
  1890. /* We need spaces, not null bytes, in the header. */
  1891. for (p = (char *) ahdrp; p < (char *) ahdrp + SIZEOF_AR_HDR; p++)
  1892. if (*p == '\0')
  1893. *p = ' ';
  1894. if (!do_pad (abfd, iterator.current.leading_padding))
  1895. return FALSE;
  1896. BFD_ASSERT (iterator.current.offset == bfd_tell (abfd));
  1897. namlen = iterator.current.padded_namlen;
  1898. if (bfd_bwrite (ahdrp, SIZEOF_AR_HDR, abfd) != SIZEOF_AR_HDR
  1899. || bfd_bwrite (iterator.current.name, namlen, abfd) != namlen
  1900. || bfd_bwrite (XCOFFARFMAG, SXCOFFARFMAG, abfd) != SXCOFFARFMAG
  1901. || bfd_seek (iterator.current.member, 0, SEEK_SET) != 0
  1902. || !do_copy (abfd, iterator.current.member)
  1903. || !do_pad (abfd, iterator.current.trailing_padding))
  1904. return FALSE;
  1905. offsets[i] = iterator.current.offset;
  1906. prevoff = iterator.current.offset;
  1907. }
  1908. sprintf (fhdr.lastmemoff, "%ld", (long) prevoff);
  1909. /* Write out the member table. */
  1910. nextoff = iterator.next.offset;
  1911. BFD_ASSERT (nextoff == bfd_tell (abfd));
  1912. sprintf (fhdr.memoff, "%ld", (long) nextoff);
  1913. memset (&ahdr, 0, sizeof ahdr);
  1914. sprintf (ahdr.size, "%ld", (long) (XCOFFARMAG_ELEMENT_SIZE
  1915. + count * XCOFFARMAG_ELEMENT_SIZE
  1916. + total_namlen));
  1917. sprintf (ahdr.prevoff, "%ld", (long) prevoff);
  1918. sprintf (ahdr.date, "%d", 0);
  1919. sprintf (ahdr.uid, "%d", 0);
  1920. sprintf (ahdr.gid, "%d", 0);
  1921. sprintf (ahdr.mode, "%d", 0);
  1922. sprintf (ahdr.namlen, "%d", 0);
  1923. size = (SIZEOF_AR_HDR
  1924. + XCOFFARMAG_ELEMENT_SIZE
  1925. + count * XCOFFARMAG_ELEMENT_SIZE
  1926. + total_namlen
  1927. + SXCOFFARFMAG);
  1928. prevoff = nextoff;
  1929. nextoff += size + (size & 1);
  1930. if (makemap && hasobjects)
  1931. sprintf (ahdr.nextoff, "%ld", (long) nextoff);
  1932. else
  1933. sprintf (ahdr.nextoff, "%d", 0);
  1934. /* We need spaces, not null bytes, in the header. */
  1935. for (p = (char *) &ahdr; p < (char *) &ahdr + SIZEOF_AR_HDR; p++)
  1936. if (*p == '\0')
  1937. *p = ' ';
  1938. if ((bfd_bwrite (&ahdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
  1939. != SIZEOF_AR_HDR)
  1940. || (bfd_bwrite (XCOFFARFMAG, (bfd_size_type) SXCOFFARFMAG, abfd)
  1941. != SXCOFFARFMAG))
  1942. return FALSE;
  1943. sprintf (decbuf, "%-12ld", (long) count);
  1944. if (bfd_bwrite (decbuf, (bfd_size_type) XCOFFARMAG_ELEMENT_SIZE, abfd)
  1945. != XCOFFARMAG_ELEMENT_SIZE)
  1946. return FALSE;
  1947. for (i = 0; i < (size_t) count; i++)
  1948. {
  1949. sprintf (decbuf, "%-12ld", (long) offsets[i]);
  1950. if (bfd_bwrite (decbuf, (bfd_size_type) XCOFFARMAG_ELEMENT_SIZE,
  1951. abfd) != XCOFFARMAG_ELEMENT_SIZE)
  1952. return FALSE;
  1953. }
  1954. for (sub = abfd->archive_head; sub != NULL; sub = sub->archive_next)
  1955. {
  1956. const char *name;
  1957. bfd_size_type namlen;
  1958. name = normalize_filename (sub);
  1959. namlen = strlen (name);
  1960. if (bfd_bwrite (name, namlen + 1, abfd) != namlen + 1)
  1961. return FALSE;
  1962. }
  1963. if (! do_pad (abfd, size & 1))
  1964. return FALSE;
  1965. /* Write out the armap, if appropriate. */
  1966. if (! makemap || ! hasobjects)
  1967. sprintf (fhdr.symoff, "%d", 0);
  1968. else
  1969. {
  1970. BFD_ASSERT (nextoff == bfd_tell (abfd));
  1971. sprintf (fhdr.symoff, "%ld", (long) nextoff);
  1972. bfd_ardata (abfd)->tdata = &fhdr;
  1973. if (! _bfd_compute_and_write_armap (abfd, 0))
  1974. return FALSE;
  1975. }
  1976. /* Write out the archive file header. */
  1977. /* We need spaces, not null bytes, in the header. */
  1978. for (p = (char *) &fhdr; p < (char *) &fhdr + SIZEOF_AR_FILE_HDR; p++)
  1979. if (*p == '\0')
  1980. *p = ' ';
  1981. if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
  1982. || (bfd_bwrite (&fhdr, (bfd_size_type) SIZEOF_AR_FILE_HDR, abfd)
  1983. != SIZEOF_AR_FILE_HDR))
  1984. return FALSE;
  1985. return TRUE;
  1986. }
  1987. static bfd_boolean
  1988. xcoff_write_archive_contents_big (bfd *abfd)
  1989. {
  1990. struct xcoff_ar_file_hdr_big fhdr;
  1991. bfd_size_type count;
  1992. bfd_size_type total_namlen;
  1993. file_ptr *offsets;
  1994. bfd_boolean makemap;
  1995. bfd_boolean hasobjects;
  1996. file_ptr prevoff, nextoff;
  1997. bfd *current_bfd;
  1998. size_t i;
  1999. struct xcoff_ar_hdr_big *hdr;
  2000. bfd_size_type size;
  2001. char *member_table, *mt;
  2002. bfd_vma member_table_size;
  2003. struct archive_iterator iterator;
  2004. memset (&fhdr, 0, SIZEOF_AR_FILE_HDR_BIG);
  2005. memcpy (fhdr.magic, XCOFFARMAGBIG, SXCOFFARMAG);
  2006. if (bfd_seek (abfd, (file_ptr) SIZEOF_AR_FILE_HDR_BIG, SEEK_SET) != 0)
  2007. return FALSE;
  2008. /* Calculate count and total_namlen. */
  2009. makemap = bfd_has_map (abfd);
  2010. hasobjects = FALSE;
  2011. for (current_bfd = abfd->archive_head, count = 0, total_namlen = 0;
  2012. current_bfd != NULL;
  2013. current_bfd = current_bfd->archive_next, count++)
  2014. {
  2015. total_namlen += strlen (normalize_filename (current_bfd)) + 1;
  2016. if (makemap
  2017. && ! hasobjects
  2018. && bfd_check_format (current_bfd, bfd_object))
  2019. hasobjects = TRUE;
  2020. if (current_bfd->arelt_data == NULL)
  2021. {
  2022. size = sizeof (struct areltdata);
  2023. current_bfd->arelt_data = bfd_zalloc (current_bfd, size);
  2024. if (current_bfd->arelt_data == NULL)
  2025. return FALSE;
  2026. }
  2027. if (arch_xhdr_big (current_bfd) == NULL)
  2028. {
  2029. struct xcoff_ar_hdr_big *ahdrp;
  2030. struct stat s;
  2031. /* XXX This should actually be a call to stat64 (at least on
  2032. 32-bit machines).
  2033. XXX This call will fail if the original object is not found. */
  2034. if (stat (bfd_get_filename (current_bfd), &s) != 0)
  2035. {
  2036. bfd_set_error (bfd_error_system_call);
  2037. return FALSE;
  2038. }
  2039. ahdrp = bfd_zalloc (current_bfd, sizeof (*ahdrp));
  2040. if (ahdrp == NULL)
  2041. return FALSE;
  2042. PRINT20 (ahdrp->size, s.st_size);
  2043. PRINT12 (ahdrp->date, s.st_mtime);
  2044. PRINT12 (ahdrp->uid, s.st_uid);
  2045. PRINT12 (ahdrp->gid, s.st_gid);
  2046. PRINT12_OCTAL (ahdrp->mode, s.st_mode);
  2047. arch_eltdata (current_bfd)->arch_header = (char *) ahdrp;
  2048. arch_eltdata (current_bfd)->parsed_size = s.st_size;
  2049. }
  2050. }
  2051. offsets = NULL;
  2052. if (count)
  2053. {
  2054. offsets = (file_ptr *) bfd_malloc (count * sizeof (file_ptr));
  2055. if (offsets == NULL)
  2056. return FALSE;
  2057. }
  2058. prevoff = 0;
  2059. for (archive_iterator_begin (&iterator, abfd), i = 0;
  2060. archive_iterator_next (&iterator);
  2061. i++)
  2062. {
  2063. bfd_size_type namlen;
  2064. struct xcoff_ar_hdr_big *ahdrp;
  2065. ahdrp = arch_xhdr_big (iterator.current.member);
  2066. PRINT20 (ahdrp->prevoff, prevoff);
  2067. PRINT4 (ahdrp->namlen, iterator.current.namlen);
  2068. PRINT20 (ahdrp->nextoff, iterator.next.offset);
  2069. if (!do_pad (abfd, iterator.current.leading_padding))
  2070. return FALSE;
  2071. BFD_ASSERT (iterator.current.offset == bfd_tell (abfd));
  2072. namlen = iterator.current.padded_namlen;
  2073. if (bfd_bwrite (ahdrp, SIZEOF_AR_HDR_BIG, abfd) != SIZEOF_AR_HDR_BIG
  2074. || bfd_bwrite (iterator.current.name, namlen, abfd) != namlen
  2075. || bfd_bwrite (XCOFFARFMAG, SXCOFFARFMAG, abfd) != SXCOFFARFMAG
  2076. || bfd_seek (iterator.current.member, 0, SEEK_SET) != 0
  2077. || !do_copy (abfd, iterator.current.member)
  2078. || !do_pad (abfd, iterator.current.trailing_padding))
  2079. return FALSE;
  2080. offsets[i] = iterator.current.offset;
  2081. prevoff = iterator.current.offset;
  2082. }
  2083. if (count)
  2084. {
  2085. PRINT20 (fhdr.firstmemoff, offsets[0]);
  2086. PRINT20 (fhdr.lastmemoff, prevoff);
  2087. }
  2088. /* Write out the member table.
  2089. Layout :
  2090. standard big archive header
  2091. 0x0000 ar_size [0x14]
  2092. 0x0014 ar_nxtmem [0x14]
  2093. 0x0028 ar_prvmem [0x14]
  2094. 0x003C ar_date [0x0C]
  2095. 0x0048 ar_uid [0x0C]
  2096. 0x0054 ar_gid [0x0C]
  2097. 0x0060 ar_mod [0x0C]
  2098. 0x006C ar_namelen[0x04]
  2099. 0x0070 ar_fmag [0x02]
  2100. Member table
  2101. 0x0072 count [0x14]
  2102. 0x0086 offsets [0x14 * counts]
  2103. 0x0086 + 0x14 * counts names [??]
  2104. ?? pad to even bytes.
  2105. */
  2106. nextoff = iterator.next.offset;
  2107. BFD_ASSERT (nextoff == bfd_tell (abfd));
  2108. member_table_size = (SIZEOF_AR_HDR_BIG
  2109. + SXCOFFARFMAG
  2110. + XCOFFARMAGBIG_ELEMENT_SIZE
  2111. + count * XCOFFARMAGBIG_ELEMENT_SIZE
  2112. + total_namlen);
  2113. member_table_size += member_table_size & 1;
  2114. member_table = bfd_zmalloc (member_table_size);
  2115. if (member_table == NULL)
  2116. return FALSE;
  2117. hdr = (struct xcoff_ar_hdr_big *) member_table;
  2118. PRINT20 (hdr->size, (XCOFFARMAGBIG_ELEMENT_SIZE
  2119. + count * XCOFFARMAGBIG_ELEMENT_SIZE
  2120. + total_namlen + (total_namlen & 1)));
  2121. if (makemap && hasobjects)
  2122. PRINT20 (hdr->nextoff, nextoff + member_table_size);
  2123. else
  2124. PRINT20 (hdr->nextoff, 0);
  2125. PRINT20 (hdr->prevoff, prevoff);
  2126. PRINT12 (hdr->date, 0);
  2127. PRINT12 (hdr->uid, 0);
  2128. PRINT12 (hdr->gid, 0);
  2129. PRINT12 (hdr->mode, 0);
  2130. PRINT4 (hdr->namlen, 0);
  2131. mt = member_table + SIZEOF_AR_HDR_BIG;
  2132. memcpy (mt, XCOFFARFMAG, SXCOFFARFMAG);
  2133. mt += SXCOFFARFMAG;
  2134. PRINT20 (mt, count);
  2135. mt += XCOFFARMAGBIG_ELEMENT_SIZE;
  2136. for (i = 0; i < (size_t) count; i++)
  2137. {
  2138. PRINT20 (mt, offsets[i]);
  2139. mt += XCOFFARMAGBIG_ELEMENT_SIZE;
  2140. }
  2141. if (count)
  2142. {
  2143. free (offsets);
  2144. offsets = NULL;
  2145. }
  2146. for (current_bfd = abfd->archive_head;
  2147. current_bfd != NULL;
  2148. current_bfd = current_bfd->archive_next)
  2149. {
  2150. const char *name;
  2151. size_t namlen;
  2152. name = normalize_filename (current_bfd);
  2153. namlen = sprintf (mt, "%s", name);
  2154. mt += namlen + 1;
  2155. }
  2156. if (bfd_bwrite (member_table, member_table_size, abfd) != member_table_size)
  2157. return FALSE;
  2158. free (member_table);
  2159. PRINT20 (fhdr.memoff, nextoff);
  2160. prevoff = nextoff;
  2161. nextoff += member_table_size;
  2162. /* Write out the armap, if appropriate. */
  2163. if (! makemap || ! hasobjects)
  2164. PRINT20 (fhdr.symoff, 0);
  2165. else
  2166. {
  2167. BFD_ASSERT (nextoff == bfd_tell (abfd));
  2168. /* Save nextoff in fhdr.symoff so the armap routine can use it. */
  2169. PRINT20 (fhdr.symoff, nextoff);
  2170. bfd_ardata (abfd)->tdata = &fhdr;
  2171. if (! _bfd_compute_and_write_armap (abfd, 0))
  2172. return FALSE;
  2173. }
  2174. /* Write out the archive file header. */
  2175. if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
  2176. || (bfd_bwrite (&fhdr, (bfd_size_type) SIZEOF_AR_FILE_HDR_BIG,
  2177. abfd) != SIZEOF_AR_FILE_HDR_BIG))
  2178. return FALSE;
  2179. return TRUE;
  2180. }
  2181. bfd_boolean
  2182. _bfd_xcoff_write_archive_contents (bfd *abfd)
  2183. {
  2184. if (! xcoff_big_format_p (abfd))
  2185. return xcoff_write_archive_contents_old (abfd);
  2186. else
  2187. return xcoff_write_archive_contents_big (abfd);
  2188. }
  2189. /* We can't use the usual coff_sizeof_headers routine, because AIX
  2190. always uses an a.out header. */
  2191. int
  2192. _bfd_xcoff_sizeof_headers (bfd *abfd,
  2193. struct bfd_link_info *info ATTRIBUTE_UNUSED)
  2194. {
  2195. int size;
  2196. size = FILHSZ;
  2197. if (xcoff_data (abfd)->full_aouthdr)
  2198. size += AOUTSZ;
  2199. else
  2200. size += SMALL_AOUTSZ;
  2201. size += abfd->section_count * SCNHSZ;
  2202. return size;
  2203. }
  2204. /* Routines to swap information in the XCOFF .loader section. If we
  2205. ever need to write an XCOFF loader, this stuff will need to be
  2206. moved to another file shared by the linker (which XCOFF calls the
  2207. ``binder'') and the loader. */
  2208. /* Swap in the ldhdr structure. */
  2209. static void
  2210. xcoff_swap_ldhdr_in (bfd *abfd, const void * s, struct internal_ldhdr *dst)
  2211. {
  2212. const struct external_ldhdr *src = (const struct external_ldhdr *) s;
  2213. dst->l_version = bfd_get_32 (abfd, src->l_version);
  2214. dst->l_nsyms = bfd_get_32 (abfd, src->l_nsyms);
  2215. dst->l_nreloc = bfd_get_32 (abfd, src->l_nreloc);
  2216. dst->l_istlen = bfd_get_32 (abfd, src->l_istlen);
  2217. dst->l_nimpid = bfd_get_32 (abfd, src->l_nimpid);
  2218. dst->l_impoff = bfd_get_32 (abfd, src->l_impoff);
  2219. dst->l_stlen = bfd_get_32 (abfd, src->l_stlen);
  2220. dst->l_stoff = bfd_get_32 (abfd, src->l_stoff);
  2221. }
  2222. /* Swap out the ldhdr structure. */
  2223. static void
  2224. xcoff_swap_ldhdr_out (bfd *abfd, const struct internal_ldhdr *src, void * d)
  2225. {
  2226. struct external_ldhdr *dst = (struct external_ldhdr *) d;
  2227. bfd_put_32 (abfd, (bfd_vma) src->l_version, dst->l_version);
  2228. bfd_put_32 (abfd, src->l_nsyms, dst->l_nsyms);
  2229. bfd_put_32 (abfd, src->l_nreloc, dst->l_nreloc);
  2230. bfd_put_32 (abfd, src->l_istlen, dst->l_istlen);
  2231. bfd_put_32 (abfd, src->l_nimpid, dst->l_nimpid);
  2232. bfd_put_32 (abfd, src->l_impoff, dst->l_impoff);
  2233. bfd_put_32 (abfd, src->l_stlen, dst->l_stlen);
  2234. bfd_put_32 (abfd, src->l_stoff, dst->l_stoff);
  2235. }
  2236. /* Swap in the ldsym structure. */
  2237. static void
  2238. xcoff_swap_ldsym_in (bfd *abfd, const void * s, struct internal_ldsym *dst)
  2239. {
  2240. const struct external_ldsym *src = (const struct external_ldsym *) s;
  2241. if (bfd_get_32 (abfd, src->_l._l_l._l_zeroes) != 0) {
  2242. memcpy (dst->_l._l_name, src->_l._l_name, SYMNMLEN);
  2243. } else {
  2244. dst->_l._l_l._l_zeroes = 0;
  2245. dst->_l._l_l._l_offset = bfd_get_32 (abfd, src->_l._l_l._l_offset);
  2246. }
  2247. dst->l_value = bfd_get_32 (abfd, src->l_value);
  2248. dst->l_scnum = bfd_get_16 (abfd, src->l_scnum);
  2249. dst->l_smtype = bfd_get_8 (abfd, src->l_smtype);
  2250. dst->l_smclas = bfd_get_8 (abfd, src->l_smclas);
  2251. dst->l_ifile = bfd_get_32 (abfd, src->l_ifile);
  2252. dst->l_parm = bfd_get_32 (abfd, src->l_parm);
  2253. }
  2254. /* Swap out the ldsym structure. */
  2255. static void
  2256. xcoff_swap_ldsym_out (bfd *abfd, const struct internal_ldsym *src, void * d)
  2257. {
  2258. struct external_ldsym *dst = (struct external_ldsym *) d;
  2259. if (src->_l._l_l._l_zeroes != 0)
  2260. memcpy (dst->_l._l_name, src->_l._l_name, SYMNMLEN);
  2261. else
  2262. {
  2263. bfd_put_32 (abfd, (bfd_vma) 0, dst->_l._l_l._l_zeroes);
  2264. bfd_put_32 (abfd, (bfd_vma) src->_l._l_l._l_offset,
  2265. dst->_l._l_l._l_offset);
  2266. }
  2267. bfd_put_32 (abfd, src->l_value, dst->l_value);
  2268. bfd_put_16 (abfd, (bfd_vma) src->l_scnum, dst->l_scnum);
  2269. bfd_put_8 (abfd, src->l_smtype, dst->l_smtype);
  2270. bfd_put_8 (abfd, src->l_smclas, dst->l_smclas);
  2271. bfd_put_32 (abfd, src->l_ifile, dst->l_ifile);
  2272. bfd_put_32 (abfd, src->l_parm, dst->l_parm);
  2273. }
  2274. static void
  2275. xcoff_swap_reloc_in (bfd *abfd, void * s, void * d)
  2276. {
  2277. struct external_reloc *src = (struct external_reloc *) s;
  2278. struct internal_reloc *dst = (struct internal_reloc *) d;
  2279. memset (dst, 0, sizeof (struct internal_reloc));
  2280. dst->r_vaddr = bfd_get_32 (abfd, src->r_vaddr);
  2281. dst->r_symndx = bfd_get_32 (abfd, src->r_symndx);
  2282. dst->r_size = bfd_get_8 (abfd, src->r_size);
  2283. dst->r_type = bfd_get_8 (abfd, src->r_type);
  2284. }
  2285. static unsigned int
  2286. xcoff_swap_reloc_out (bfd *abfd, void * s, void * d)
  2287. {
  2288. struct internal_reloc *src = (struct internal_reloc *) s;
  2289. struct external_reloc *dst = (struct external_reloc *) d;
  2290. bfd_put_32 (abfd, src->r_vaddr, dst->r_vaddr);
  2291. bfd_put_32 (abfd, src->r_symndx, dst->r_symndx);
  2292. bfd_put_8 (abfd, src->r_type, dst->r_type);
  2293. bfd_put_8 (abfd, src->r_size, dst->r_size);
  2294. return bfd_coff_relsz (abfd);
  2295. }
  2296. /* Swap in the ldrel structure. */
  2297. static void
  2298. xcoff_swap_ldrel_in (bfd *abfd, const void * s, struct internal_ldrel *dst)
  2299. {
  2300. const struct external_ldrel *src = (const struct external_ldrel *) s;
  2301. dst->l_vaddr = bfd_get_32 (abfd, src->l_vaddr);
  2302. dst->l_symndx = bfd_get_32 (abfd, src->l_symndx);
  2303. dst->l_rtype = bfd_get_16 (abfd, src->l_rtype);
  2304. dst->l_rsecnm = bfd_get_16 (abfd, src->l_rsecnm);
  2305. }
  2306. /* Swap out the ldrel structure. */
  2307. static void
  2308. xcoff_swap_ldrel_out (bfd *abfd, const struct internal_ldrel *src, void * d)
  2309. {
  2310. struct external_ldrel *dst = (struct external_ldrel *) d;
  2311. bfd_put_32 (abfd, src->l_vaddr, dst->l_vaddr);
  2312. bfd_put_32 (abfd, src->l_symndx, dst->l_symndx);
  2313. bfd_put_16 (abfd, (bfd_vma) src->l_rtype, dst->l_rtype);
  2314. bfd_put_16 (abfd, (bfd_vma) src->l_rsecnm, dst->l_rsecnm);
  2315. }
  2316. bfd_boolean
  2317. xcoff_reloc_type_noop (bfd *input_bfd ATTRIBUTE_UNUSED,
  2318. asection *input_section ATTRIBUTE_UNUSED,
  2319. bfd *output_bfd ATTRIBUTE_UNUSED,
  2320. struct internal_reloc *rel ATTRIBUTE_UNUSED,
  2321. struct internal_syment *sym ATTRIBUTE_UNUSED,
  2322. struct reloc_howto_struct *howto ATTRIBUTE_UNUSED,
  2323. bfd_vma val ATTRIBUTE_UNUSED,
  2324. bfd_vma addend ATTRIBUTE_UNUSED,
  2325. bfd_vma *relocation ATTRIBUTE_UNUSED,
  2326. bfd_byte *contents ATTRIBUTE_UNUSED)
  2327. {
  2328. return TRUE;
  2329. }
  2330. bfd_boolean
  2331. xcoff_reloc_type_fail (bfd *input_bfd,
  2332. asection *input_section ATTRIBUTE_UNUSED,
  2333. bfd *output_bfd ATTRIBUTE_UNUSED,
  2334. struct internal_reloc *rel,
  2335. struct internal_syment *sym ATTRIBUTE_UNUSED,
  2336. struct reloc_howto_struct *howto ATTRIBUTE_UNUSED,
  2337. bfd_vma val ATTRIBUTE_UNUSED,
  2338. bfd_vma addend ATTRIBUTE_UNUSED,
  2339. bfd_vma *relocation ATTRIBUTE_UNUSED,
  2340. bfd_byte *contents ATTRIBUTE_UNUSED)
  2341. {
  2342. (*_bfd_error_handler)
  2343. (_("%s: unsupported relocation type 0x%02x"),
  2344. bfd_get_filename (input_bfd), (unsigned int) rel->r_type);
  2345. bfd_set_error (bfd_error_bad_value);
  2346. return FALSE;
  2347. }
  2348. bfd_boolean
  2349. xcoff_reloc_type_pos (bfd *input_bfd ATTRIBUTE_UNUSED,
  2350. asection *input_section ATTRIBUTE_UNUSED,
  2351. bfd *output_bfd ATTRIBUTE_UNUSED,
  2352. struct internal_reloc *rel ATTRIBUTE_UNUSED,
  2353. struct internal_syment *sym ATTRIBUTE_UNUSED,
  2354. struct reloc_howto_struct *howto ATTRIBUTE_UNUSED,
  2355. bfd_vma val,
  2356. bfd_vma addend,
  2357. bfd_vma *relocation,
  2358. bfd_byte *contents ATTRIBUTE_UNUSED)
  2359. {
  2360. *relocation = val + addend;
  2361. return TRUE;
  2362. }
  2363. bfd_boolean
  2364. xcoff_reloc_type_neg (bfd *input_bfd ATTRIBUTE_UNUSED,
  2365. asection *input_section ATTRIBUTE_UNUSED,
  2366. bfd *output_bfd ATTRIBUTE_UNUSED,
  2367. struct internal_reloc *rel ATTRIBUTE_UNUSED,
  2368. struct internal_syment *sym ATTRIBUTE_UNUSED,
  2369. struct reloc_howto_struct *howto ATTRIBUTE_UNUSED,
  2370. bfd_vma val,
  2371. bfd_vma addend,
  2372. bfd_vma *relocation,
  2373. bfd_byte *contents ATTRIBUTE_UNUSED)
  2374. {
  2375. *relocation = addend - val;
  2376. return TRUE;
  2377. }
  2378. bfd_boolean
  2379. xcoff_reloc_type_rel (bfd *input_bfd ATTRIBUTE_UNUSED,
  2380. asection *input_section,
  2381. bfd *output_bfd ATTRIBUTE_UNUSED,
  2382. struct internal_reloc *rel ATTRIBUTE_UNUSED,
  2383. struct internal_syment *sym ATTRIBUTE_UNUSED,
  2384. struct reloc_howto_struct *howto,
  2385. bfd_vma val,
  2386. bfd_vma addend,
  2387. bfd_vma *relocation,
  2388. bfd_byte *contents ATTRIBUTE_UNUSED)
  2389. {
  2390. howto->pc_relative = TRUE;
  2391. /* A PC relative reloc includes the section address. */
  2392. addend += input_section->vma;
  2393. *relocation = val + addend;
  2394. *relocation -= (input_section->output_section->vma
  2395. + input_section->output_offset);
  2396. return TRUE;
  2397. }
  2398. bfd_boolean
  2399. xcoff_reloc_type_toc (bfd *input_bfd,
  2400. asection *input_section ATTRIBUTE_UNUSED,
  2401. bfd *output_bfd,
  2402. struct internal_reloc *rel,
  2403. struct internal_syment *sym,
  2404. struct reloc_howto_struct *howto ATTRIBUTE_UNUSED,
  2405. bfd_vma val,
  2406. bfd_vma addend ATTRIBUTE_UNUSED,
  2407. bfd_vma *relocation,
  2408. bfd_byte *contents ATTRIBUTE_UNUSED)
  2409. {
  2410. struct xcoff_link_hash_entry *h;
  2411. if (0 > rel->r_symndx)
  2412. return FALSE;
  2413. h = obj_xcoff_sym_hashes (input_bfd)[rel->r_symndx];
  2414. if (h != NULL && h->smclas != XMC_TD)
  2415. {
  2416. if (h->toc_section == NULL)
  2417. {
  2418. (*_bfd_error_handler)
  2419. (_("%s: TOC reloc at 0x%x to symbol `%s' with no TOC entry"),
  2420. bfd_get_filename (input_bfd), rel->r_vaddr,
  2421. h->root.root.string);
  2422. bfd_set_error (bfd_error_bad_value);
  2423. return FALSE;
  2424. }
  2425. BFD_ASSERT ((h->flags & XCOFF_SET_TOC) == 0);
  2426. val = (h->toc_section->output_section->vma
  2427. + h->toc_section->output_offset);
  2428. }
  2429. *relocation = ((val - xcoff_data (output_bfd)->toc)
  2430. - (sym->n_value - xcoff_data (input_bfd)->toc));
  2431. return TRUE;
  2432. }
  2433. bfd_boolean
  2434. xcoff_reloc_type_ba (bfd *input_bfd ATTRIBUTE_UNUSED,
  2435. asection *input_section ATTRIBUTE_UNUSED,
  2436. bfd *output_bfd ATTRIBUTE_UNUSED,
  2437. struct internal_reloc *rel ATTRIBUTE_UNUSED,
  2438. struct internal_syment *sym ATTRIBUTE_UNUSED,
  2439. struct reloc_howto_struct *howto,
  2440. bfd_vma val,
  2441. bfd_vma addend,
  2442. bfd_vma *relocation,
  2443. bfd_byte *contents ATTRIBUTE_UNUSED)
  2444. {
  2445. howto->src_mask &= ~3;
  2446. howto->dst_mask = howto->src_mask;
  2447. *relocation = val + addend;
  2448. return TRUE;
  2449. }
  2450. static bfd_boolean
  2451. xcoff_reloc_type_br (bfd *input_bfd,
  2452. asection *input_section,
  2453. bfd *output_bfd ATTRIBUTE_UNUSED,
  2454. struct internal_reloc *rel,
  2455. struct internal_syment *sym ATTRIBUTE_UNUSED,
  2456. struct reloc_howto_struct *howto,
  2457. bfd_vma val,
  2458. bfd_vma addend,
  2459. bfd_vma *relocation,
  2460. bfd_byte *contents)
  2461. {
  2462. struct xcoff_link_hash_entry *h;
  2463. bfd_vma section_offset;
  2464. if (0 > rel->r_symndx)
  2465. return FALSE;
  2466. h = obj_xcoff_sym_hashes (input_bfd)[rel->r_symndx];
  2467. section_offset = rel->r_vaddr - input_section->vma;
  2468. /* If we see an R_BR or R_RBR reloc which is jumping to global
  2469. linkage code, and it is followed by an appropriate cror nop
  2470. instruction, we replace the cror with lwz r2,20(r1). This
  2471. restores the TOC after the glink code. Contrariwise, if the
  2472. call is followed by a lwz r2,20(r1), but the call is not
  2473. going to global linkage code, we can replace the load with a
  2474. cror. */
  2475. if (NULL != h
  2476. && (bfd_link_hash_defined == h->root.type
  2477. || bfd_link_hash_defweak == h->root.type)
  2478. && section_offset + 8 <= input_section->size)
  2479. {
  2480. bfd_byte *pnext;
  2481. unsigned long next;
  2482. pnext = contents + section_offset + 4;
  2483. next = bfd_get_32 (input_bfd, pnext);
  2484. /* The _ptrgl function is magic. It is used by the AIX
  2485. compiler to call a function through a pointer. */
  2486. if (h->smclas == XMC_GL || strcmp (h->root.root.string, "._ptrgl") == 0)
  2487. {
  2488. if (next == 0x4def7b82 /* cror 15,15,15 */
  2489. || next == 0x4ffffb82 /* cror 31,31,31 */
  2490. || next == 0x60000000) /* ori r0,r0,0 */
  2491. bfd_put_32 (input_bfd, 0x80410014, pnext); /* lwz r2,20(r1) */
  2492. }
  2493. else
  2494. {
  2495. if (next == 0x80410014) /* lwz r2,20(r1) */
  2496. bfd_put_32 (input_bfd, 0x60000000, pnext); /* ori r0,r0,0 */
  2497. }
  2498. }
  2499. else if (NULL != h && bfd_link_hash_undefined == h->root.type)
  2500. {
  2501. /* Normally, this relocation is against a defined symbol. In the
  2502. case where this is a partial link and the output section offset
  2503. is greater than 2^25, the linker will return an invalid error
  2504. message that the relocation has been truncated. Yes it has been
  2505. truncated but no it not important. For this case, disable the
  2506. overflow checking. */
  2507. howto->complain_on_overflow = complain_overflow_dont;
  2508. }
  2509. /* The original PC-relative relocation is biased by -r_vaddr, so adding
  2510. the value below will give the absolute target address. */
  2511. *relocation = val + addend + rel->r_vaddr;
  2512. howto->src_mask &= ~3;
  2513. howto->dst_mask = howto->src_mask;
  2514. if (h != NULL
  2515. && (h->root.type == bfd_link_hash_defined
  2516. || h->root.type == bfd_link_hash_defweak)
  2517. && bfd_is_abs_section (h->root.u.def.section)
  2518. && section_offset + 4 <= input_section->size)
  2519. {
  2520. bfd_byte *ptr;
  2521. bfd_vma insn;
  2522. /* Turn the relative branch into an absolute one by setting the
  2523. AA bit. */
  2524. ptr = contents + section_offset;
  2525. insn = bfd_get_32 (input_bfd, ptr);
  2526. insn |= 2;
  2527. bfd_put_32 (input_bfd, insn, ptr);
  2528. /* Make the howto absolute too. */
  2529. howto->pc_relative = FALSE;
  2530. howto->complain_on_overflow = complain_overflow_bitfield;
  2531. }
  2532. else
  2533. {
  2534. /* Use a PC-relative howto and subtract the instruction's address
  2535. from the target address we calculated above. */
  2536. howto->pc_relative = TRUE;
  2537. *relocation -= (input_section->output_section->vma
  2538. + input_section->output_offset
  2539. + section_offset);
  2540. }
  2541. return TRUE;
  2542. }
  2543. bfd_boolean
  2544. xcoff_reloc_type_crel (bfd *input_bfd ATTRIBUTE_UNUSED,
  2545. asection *input_section,
  2546. bfd *output_bfd ATTRIBUTE_UNUSED,
  2547. struct internal_reloc *rel ATTRIBUTE_UNUSED,
  2548. struct internal_syment *sym ATTRIBUTE_UNUSED,
  2549. struct reloc_howto_struct *howto,
  2550. bfd_vma val ATTRIBUTE_UNUSED,
  2551. bfd_vma addend,
  2552. bfd_vma *relocation,
  2553. bfd_byte *contents ATTRIBUTE_UNUSED)
  2554. {
  2555. howto->pc_relative = TRUE;
  2556. howto->src_mask &= ~3;
  2557. howto->dst_mask = howto->src_mask;
  2558. /* A PC relative reloc includes the section address. */
  2559. addend += input_section->vma;
  2560. *relocation = val + addend;
  2561. *relocation -= (input_section->output_section->vma
  2562. + input_section->output_offset);
  2563. return TRUE;
  2564. }
  2565. static bfd_boolean
  2566. xcoff_complain_overflow_dont_func (bfd *input_bfd ATTRIBUTE_UNUSED,
  2567. bfd_vma val ATTRIBUTE_UNUSED,
  2568. bfd_vma relocation ATTRIBUTE_UNUSED,
  2569. struct reloc_howto_struct *
  2570. howto ATTRIBUTE_UNUSED)
  2571. {
  2572. return FALSE;
  2573. }
  2574. static bfd_boolean
  2575. xcoff_complain_overflow_bitfield_func (bfd *input_bfd,
  2576. bfd_vma val,
  2577. bfd_vma relocation,
  2578. struct reloc_howto_struct *howto)
  2579. {
  2580. bfd_vma fieldmask, signmask, ss;
  2581. bfd_vma a, b, sum;
  2582. /* Get the values to be added together. For signed and unsigned
  2583. relocations, we assume that all values should be truncated to
  2584. the size of an address. For bitfields, all the bits matter.
  2585. See also bfd_check_overflow. */
  2586. fieldmask = N_ONES (howto->bitsize);
  2587. a = relocation;
  2588. b = val & howto->src_mask;
  2589. /* Much like unsigned, except no trimming with addrmask. In
  2590. addition, the sum overflows if there is a carry out of
  2591. the bfd_vma, i.e., the sum is less than either input
  2592. operand. */
  2593. a >>= howto->rightshift;
  2594. b >>= howto->bitpos;
  2595. /* Bitfields are sometimes used for signed numbers; for
  2596. example, a 13-bit field sometimes represents values in
  2597. 0..8191 and sometimes represents values in -4096..4095.
  2598. If the field is signed and a is -4095 (0x1001) and b is
  2599. -1 (0x1fff), the sum is -4096 (0x1000), but (0x1001 +
  2600. 0x1fff is 0x3000). It's not clear how to handle this
  2601. everywhere, since there is not way to know how many bits
  2602. are significant in the relocation, but the original code
  2603. assumed that it was fully sign extended, and we will keep
  2604. that assumption. */
  2605. signmask = (fieldmask >> 1) + 1;
  2606. if ((a & ~ fieldmask) != 0)
  2607. {
  2608. /* Some bits out of the field are set. This might not
  2609. be a problem: if this is a signed bitfield, it is OK
  2610. iff all the high bits are set, including the sign
  2611. bit. We'll try setting all but the most significant
  2612. bit in the original relocation value: if this is all
  2613. ones, we are OK, assuming a signed bitfield. */
  2614. ss = (signmask << howto->rightshift) - 1;
  2615. if ((ss | relocation) != ~ (bfd_vma) 0)
  2616. return TRUE;
  2617. a &= fieldmask;
  2618. }
  2619. /* We just assume (b & ~ fieldmask) == 0. */
  2620. /* We explicitly permit wrap around if this relocation
  2621. covers the high bit of an address. The Linux kernel
  2622. relies on it, and it is the only way to write assembler
  2623. code which can run when loaded at a location 0x80000000
  2624. away from the location at which it is linked. */
  2625. if (howto->bitsize + howto->rightshift
  2626. == bfd_arch_bits_per_address (input_bfd))
  2627. return FALSE;
  2628. sum = a + b;
  2629. if (sum < a || (sum & ~ fieldmask) != 0)
  2630. {
  2631. /* There was a carry out, or the field overflow. Test
  2632. for signed operands again. Here is the overflow test
  2633. is as for complain_overflow_signed. */
  2634. if (((~ (a ^ b)) & (a ^ sum)) & signmask)
  2635. return TRUE;
  2636. }
  2637. return FALSE;
  2638. }
  2639. static bfd_boolean
  2640. xcoff_complain_overflow_signed_func (bfd *input_bfd,
  2641. bfd_vma val,
  2642. bfd_vma relocation,
  2643. struct reloc_howto_struct *howto)
  2644. {
  2645. bfd_vma addrmask, fieldmask, signmask, ss;
  2646. bfd_vma a, b, sum;
  2647. /* Get the values to be added together. For signed and unsigned
  2648. relocations, we assume that all values should be truncated to
  2649. the size of an address. For bitfields, all the bits matter.
  2650. See also bfd_check_overflow. */
  2651. fieldmask = N_ONES (howto->bitsize);
  2652. addrmask = N_ONES (bfd_arch_bits_per_address (input_bfd)) | fieldmask;
  2653. a = relocation;
  2654. b = val & howto->src_mask;
  2655. a = (a & addrmask) >> howto->rightshift;
  2656. /* If any sign bits are set, all sign bits must be set.
  2657. That is, A must be a valid negative address after
  2658. shifting. */
  2659. signmask = ~ (fieldmask >> 1);
  2660. ss = a & signmask;
  2661. if (ss != 0 && ss != ((addrmask >> howto->rightshift) & signmask))
  2662. return TRUE;
  2663. /* We only need this next bit of code if the sign bit of B
  2664. is below the sign bit of A. This would only happen if
  2665. SRC_MASK had fewer bits than BITSIZE. Note that if
  2666. SRC_MASK has more bits than BITSIZE, we can get into
  2667. trouble; we would need to verify that B is in range, as
  2668. we do for A above. */
  2669. signmask = ((~ howto->src_mask) >> 1) & howto->src_mask;
  2670. if ((b & signmask) != 0)
  2671. {
  2672. /* Set all the bits above the sign bit. */
  2673. b -= signmask <<= 1;
  2674. }
  2675. b = (b & addrmask) >> howto->bitpos;
  2676. /* Now we can do the addition. */
  2677. sum = a + b;
  2678. /* See if the result has the correct sign. Bits above the
  2679. sign bit are junk now; ignore them. If the sum is
  2680. positive, make sure we did not have all negative inputs;
  2681. if the sum is negative, make sure we did not have all
  2682. positive inputs. The test below looks only at the sign
  2683. bits, and it really just
  2684. SIGN (A) == SIGN (B) && SIGN (A) != SIGN (SUM)
  2685. */
  2686. signmask = (fieldmask >> 1) + 1;
  2687. if (((~ (a ^ b)) & (a ^ sum)) & signmask)
  2688. return TRUE;
  2689. return FALSE;
  2690. }
  2691. static bfd_boolean
  2692. xcoff_complain_overflow_unsigned_func (bfd *input_bfd,
  2693. bfd_vma val,
  2694. bfd_vma relocation,
  2695. struct reloc_howto_struct *howto)
  2696. {
  2697. bfd_vma addrmask, fieldmask;
  2698. bfd_vma a, b, sum;
  2699. /* Get the values to be added together. For signed and unsigned
  2700. relocations, we assume that all values should be truncated to
  2701. the size of an address. For bitfields, all the bits matter.
  2702. See also bfd_check_overflow. */
  2703. fieldmask = N_ONES (howto->bitsize);
  2704. addrmask = N_ONES (bfd_arch_bits_per_address (input_bfd)) | fieldmask;
  2705. a = relocation;
  2706. b = val & howto->src_mask;
  2707. /* Checking for an unsigned overflow is relatively easy:
  2708. trim the addresses and add, and trim the result as well.
  2709. Overflow is normally indicated when the result does not
  2710. fit in the field. However, we also need to consider the
  2711. case when, e.g., fieldmask is 0x7fffffff or smaller, an
  2712. input is 0x80000000, and bfd_vma is only 32 bits; then we
  2713. will get sum == 0, but there is an overflow, since the
  2714. inputs did not fit in the field. Instead of doing a
  2715. separate test, we can check for this by or-ing in the
  2716. operands when testing for the sum overflowing its final
  2717. field. */
  2718. a = (a & addrmask) >> howto->rightshift;
  2719. b = (b & addrmask) >> howto->bitpos;
  2720. sum = (a + b) & addrmask;
  2721. if ((a | b | sum) & ~ fieldmask)
  2722. return TRUE;
  2723. return FALSE;
  2724. }
  2725. /* This is the relocation function for the RS/6000/POWER/PowerPC.
  2726. This is currently the only processor which uses XCOFF; I hope that
  2727. will never change.
  2728. I took the relocation type definitions from two documents:
  2729. the PowerPC AIX Version 4 Application Binary Interface, First
  2730. Edition (April 1992), and the PowerOpen ABI, Big-Endian
  2731. 32-Bit Hardware Implementation (June 30, 1994). Differences
  2732. between the documents are noted below.
  2733. Unsupported r_type's
  2734. R_RTB:
  2735. R_RRTBI:
  2736. R_RRTBA:
  2737. These relocs are defined by the PowerPC ABI to be
  2738. relative branches which use half of the difference
  2739. between the symbol and the program counter. I can't
  2740. quite figure out when this is useful. These relocs are
  2741. not defined by the PowerOpen ABI.
  2742. Supported r_type's
  2743. R_POS:
  2744. Simple positive relocation.
  2745. R_NEG:
  2746. Simple negative relocation.
  2747. R_REL:
  2748. Simple PC relative relocation.
  2749. R_TOC:
  2750. TOC relative relocation. The value in the instruction in
  2751. the input file is the offset from the input file TOC to
  2752. the desired location. We want the offset from the final
  2753. TOC to the desired location. We have:
  2754. isym = iTOC + in
  2755. iinsn = in + o
  2756. osym = oTOC + on
  2757. oinsn = on + o
  2758. so we must change insn by on - in.
  2759. R_GL:
  2760. GL linkage relocation. The value of this relocation
  2761. is the address of the entry in the TOC section.
  2762. R_TCL:
  2763. Local object TOC address. I can't figure out the
  2764. difference between this and case R_GL.
  2765. R_TRL:
  2766. TOC relative relocation. A TOC relative load instruction
  2767. which may be changed to a load address instruction.
  2768. FIXME: We don't currently implement this optimization.
  2769. R_TRLA:
  2770. TOC relative relocation. This is a TOC relative load
  2771. address instruction which may be changed to a load
  2772. instruction. FIXME: I don't know if this is the correct
  2773. implementation.
  2774. R_BA:
  2775. Absolute branch. We don't want to mess with the lower
  2776. two bits of the instruction.
  2777. R_CAI:
  2778. The PowerPC ABI defines this as an absolute call which
  2779. may be modified to become a relative call. The PowerOpen
  2780. ABI does not define this relocation type.
  2781. R_RBA:
  2782. Absolute branch which may be modified to become a
  2783. relative branch.
  2784. R_RBAC:
  2785. The PowerPC ABI defines this as an absolute branch to a
  2786. fixed address which may be modified to an absolute branch
  2787. to a symbol. The PowerOpen ABI does not define this
  2788. relocation type.
  2789. R_RBRC:
  2790. The PowerPC ABI defines this as an absolute branch to a
  2791. fixed address which may be modified to a relative branch.
  2792. The PowerOpen ABI does not define this relocation type.
  2793. R_BR:
  2794. Relative branch. We don't want to mess with the lower
  2795. two bits of the instruction.
  2796. R_CREL:
  2797. The PowerPC ABI defines this as a relative call which may
  2798. be modified to become an absolute call. The PowerOpen
  2799. ABI does not define this relocation type.
  2800. R_RBR:
  2801. A relative branch which may be modified to become an
  2802. absolute branch.
  2803. R_RL:
  2804. The PowerPC AIX ABI describes this as a load which may be
  2805. changed to a load address. The PowerOpen ABI says this
  2806. is the same as case R_POS.
  2807. R_RLA:
  2808. The PowerPC AIX ABI describes this as a load address
  2809. which may be changed to a load. The PowerOpen ABI says
  2810. this is the same as R_POS.
  2811. */
  2812. bfd_boolean
  2813. xcoff_ppc_relocate_section (bfd *output_bfd,
  2814. struct bfd_link_info *info,
  2815. bfd *input_bfd,
  2816. asection *input_section,
  2817. bfd_byte *contents,
  2818. struct internal_reloc *relocs,
  2819. struct internal_syment *syms,
  2820. asection **sections)
  2821. {
  2822. struct internal_reloc *rel;
  2823. struct internal_reloc *relend;
  2824. rel = relocs;
  2825. relend = rel + input_section->reloc_count;
  2826. for (; rel < relend; rel++)
  2827. {
  2828. long symndx;
  2829. struct xcoff_link_hash_entry *h;
  2830. struct internal_syment *sym;
  2831. bfd_vma addend;
  2832. bfd_vma val;
  2833. struct reloc_howto_struct howto;
  2834. bfd_vma relocation;
  2835. bfd_vma value_to_relocate;
  2836. bfd_vma address;
  2837. bfd_byte *location;
  2838. /* Relocation type R_REF is a special relocation type which is
  2839. merely used to prevent garbage collection from occurring for
  2840. the csect including the symbol which it references. */
  2841. if (rel->r_type == R_REF)
  2842. continue;
  2843. /* howto */
  2844. howto.type = rel->r_type;
  2845. howto.rightshift = 0;
  2846. howto.bitsize = (rel->r_size & 0x1f) + 1;
  2847. howto.size = howto.bitsize > 16 ? 2 : 1;
  2848. howto.pc_relative = FALSE;
  2849. howto.bitpos = 0;
  2850. howto.complain_on_overflow = (rel->r_size & 0x80
  2851. ? complain_overflow_signed
  2852. : complain_overflow_bitfield);
  2853. howto.special_function = NULL;
  2854. howto.name = "internal";
  2855. howto.partial_inplace = TRUE;
  2856. howto.src_mask = howto.dst_mask = N_ONES (howto.bitsize);
  2857. howto.pcrel_offset = FALSE;
  2858. /* symbol */
  2859. val = 0;
  2860. addend = 0;
  2861. h = NULL;
  2862. sym = NULL;
  2863. symndx = rel->r_symndx;
  2864. if (-1 != symndx)
  2865. {
  2866. asection *sec;
  2867. h = obj_xcoff_sym_hashes (input_bfd)[symndx];
  2868. sym = syms + symndx;
  2869. addend = - sym->n_value;
  2870. if (NULL == h)
  2871. {
  2872. sec = sections[symndx];
  2873. /* Hack to make sure we use the right TOC anchor value
  2874. if this reloc is against the TOC anchor. */
  2875. if (sec->name[3] == '0'
  2876. && strcmp (sec->name, ".tc0") == 0)
  2877. val = xcoff_data (output_bfd)->toc;
  2878. else
  2879. val = (sec->output_section->vma
  2880. + sec->output_offset
  2881. + sym->n_value
  2882. - sec->vma);
  2883. }
  2884. else
  2885. {
  2886. if (info->unresolved_syms_in_objects != RM_IGNORE
  2887. && (h->flags & XCOFF_WAS_UNDEFINED) != 0)
  2888. {
  2889. if (! ((*info->callbacks->undefined_symbol)
  2890. (info, h->root.root.string,
  2891. input_bfd, input_section,
  2892. rel->r_vaddr - input_section->vma,
  2893. (info->unresolved_syms_in_objects
  2894. == RM_GENERATE_ERROR))))
  2895. return FALSE;
  2896. }
  2897. if (h->root.type == bfd_link_hash_defined
  2898. || h->root.type == bfd_link_hash_defweak)
  2899. {
  2900. sec = h->root.u.def.section;
  2901. val = (h->root.u.def.value
  2902. + sec->output_section->vma
  2903. + sec->output_offset);
  2904. }
  2905. else if (h->root.type == bfd_link_hash_common)
  2906. {
  2907. sec = h->root.u.c.p->section;
  2908. val = (sec->output_section->vma
  2909. + sec->output_offset);
  2910. }
  2911. else
  2912. {
  2913. BFD_ASSERT (info->relocatable
  2914. || (info->static_link
  2915. && (h->flags & XCOFF_WAS_UNDEFINED) != 0)
  2916. || (h->flags & XCOFF_DEF_DYNAMIC) != 0
  2917. || (h->flags & XCOFF_IMPORT) != 0);
  2918. }
  2919. }
  2920. }
  2921. if (rel->r_type >= XCOFF_MAX_CALCULATE_RELOCATION
  2922. || !((*xcoff_calculate_relocation[rel->r_type])
  2923. (input_bfd, input_section, output_bfd, rel, sym, &howto, val,
  2924. addend, &relocation, contents)))
  2925. return FALSE;
  2926. /* address */
  2927. address = rel->r_vaddr - input_section->vma;
  2928. location = contents + address;
  2929. if (address > input_section->size)
  2930. abort ();
  2931. /* Get the value we are going to relocate. */
  2932. if (1 == howto.size)
  2933. value_to_relocate = bfd_get_16 (input_bfd, location);
  2934. else
  2935. value_to_relocate = bfd_get_32 (input_bfd, location);
  2936. /* overflow.
  2937. FIXME: We may drop bits during the addition
  2938. which we don't check for. We must either check at every single
  2939. operation, which would be tedious, or we must do the computations
  2940. in a type larger than bfd_vma, which would be inefficient. */
  2941. if ((unsigned int) howto.complain_on_overflow
  2942. >= XCOFF_MAX_COMPLAIN_OVERFLOW)
  2943. abort ();
  2944. if (((*xcoff_complain_overflow[howto.complain_on_overflow])
  2945. (input_bfd, value_to_relocate, relocation, &howto)))
  2946. {
  2947. const char *name;
  2948. char buf[SYMNMLEN + 1];
  2949. char reloc_type_name[10];
  2950. if (symndx == -1)
  2951. {
  2952. name = "*ABS*";
  2953. }
  2954. else if (h != NULL)
  2955. {
  2956. name = NULL;
  2957. }
  2958. else
  2959. {
  2960. name = _bfd_coff_internal_syment_name (input_bfd, sym, buf);
  2961. if (name == NULL)
  2962. name = "UNKNOWN";
  2963. }
  2964. sprintf (reloc_type_name, "0x%02x", rel->r_type);
  2965. if (! ((*info->callbacks->reloc_overflow)
  2966. (info, (h ? &h->root : NULL), name, reloc_type_name,
  2967. (bfd_vma) 0, input_bfd, input_section,
  2968. rel->r_vaddr - input_section->vma)))
  2969. return FALSE;
  2970. }
  2971. /* Add RELOCATION to the right bits of VALUE_TO_RELOCATE. */
  2972. value_to_relocate = ((value_to_relocate & ~howto.dst_mask)
  2973. | (((value_to_relocate & howto.src_mask)
  2974. + relocation) & howto.dst_mask));
  2975. /* Put the value back in the object file. */
  2976. if (1 == howto.size)
  2977. bfd_put_16 (input_bfd, value_to_relocate, location);
  2978. else
  2979. bfd_put_32 (input_bfd, value_to_relocate, location);
  2980. }
  2981. return TRUE;
  2982. }
  2983. static bfd_boolean
  2984. _bfd_xcoff_put_ldsymbol_name (bfd *abfd ATTRIBUTE_UNUSED,
  2985. struct xcoff_loader_info *ldinfo,
  2986. struct internal_ldsym *ldsym,
  2987. const char *name)
  2988. {
  2989. size_t len;
  2990. len = strlen (name);
  2991. if (len <= SYMNMLEN)
  2992. strncpy (ldsym->_l._l_name, name, SYMNMLEN);
  2993. else
  2994. {
  2995. if (ldinfo->string_size + len + 3 > ldinfo->string_alc)
  2996. {
  2997. bfd_size_type newalc;
  2998. char *newstrings;
  2999. newalc = ldinfo->string_alc * 2;
  3000. if (newalc == 0)
  3001. newalc = 32;
  3002. while (ldinfo->string_size + len + 3 > newalc)
  3003. newalc *= 2;
  3004. newstrings = bfd_realloc (ldinfo->strings, newalc);
  3005. if (newstrings == NULL)
  3006. {
  3007. ldinfo->failed = TRUE;
  3008. return FALSE;
  3009. }
  3010. ldinfo->string_alc = newalc;
  3011. ldinfo->strings = newstrings;
  3012. }
  3013. bfd_put_16 (ldinfo->output_bfd, (bfd_vma) (len + 1),
  3014. ldinfo->strings + ldinfo->string_size);
  3015. strcpy (ldinfo->strings + ldinfo->string_size + 2, name);
  3016. ldsym->_l._l_l._l_zeroes = 0;
  3017. ldsym->_l._l_l._l_offset = ldinfo->string_size + 2;
  3018. ldinfo->string_size += len + 3;
  3019. }
  3020. return TRUE;
  3021. }
  3022. static bfd_boolean
  3023. _bfd_xcoff_put_symbol_name (bfd *abfd, struct bfd_strtab_hash *strtab,
  3024. struct internal_syment *sym,
  3025. const char *name)
  3026. {
  3027. if (strlen (name) <= SYMNMLEN)
  3028. {
  3029. strncpy (sym->_n._n_name, name, SYMNMLEN);
  3030. }
  3031. else
  3032. {
  3033. bfd_boolean hash;
  3034. bfd_size_type indx;
  3035. hash = TRUE;
  3036. if ((abfd->flags & BFD_TRADITIONAL_FORMAT) != 0)
  3037. hash = FALSE;
  3038. indx = _bfd_stringtab_add (strtab, name, hash, FALSE);
  3039. if (indx == (bfd_size_type) -1)
  3040. return FALSE;
  3041. sym->_n._n_n._n_zeroes = 0;
  3042. sym->_n._n_n._n_offset = STRING_SIZE_SIZE + indx;
  3043. }
  3044. return TRUE;
  3045. }
  3046. static asection *
  3047. xcoff_create_csect_from_smclas (bfd *abfd,
  3048. union internal_auxent *aux,
  3049. const char *symbol_name)
  3050. {
  3051. asection *return_value = NULL;
  3052. /* .sv64 = x_smclas == 17
  3053. This is an invalid csect for 32 bit apps. */
  3054. static const char *names[19] =
  3055. {
  3056. ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo",
  3057. ".sv", ".bs", ".ds", ".uc", ".ti", ".tb", NULL, ".tc0",
  3058. ".td", NULL, ".sv3264"
  3059. };
  3060. if ((19 >= aux->x_csect.x_smclas)
  3061. && (NULL != names[aux->x_csect.x_smclas]))
  3062. {
  3063. return_value = bfd_make_section_anyway
  3064. (abfd, names[aux->x_csect.x_smclas]);
  3065. }
  3066. else
  3067. {
  3068. (*_bfd_error_handler)
  3069. (_("%B: symbol `%s' has unrecognized smclas %d"),
  3070. abfd, symbol_name, aux->x_csect.x_smclas);
  3071. bfd_set_error (bfd_error_bad_value);
  3072. }
  3073. return return_value;
  3074. }
  3075. static bfd_boolean
  3076. xcoff_is_lineno_count_overflow (bfd *abfd ATTRIBUTE_UNUSED, bfd_vma value)
  3077. {
  3078. if (0xffff <= value)
  3079. return TRUE;
  3080. return FALSE;
  3081. }
  3082. static bfd_boolean
  3083. xcoff_is_reloc_count_overflow (bfd *abfd ATTRIBUTE_UNUSED, bfd_vma value)
  3084. {
  3085. if (0xffff <= value)
  3086. return TRUE;
  3087. return FALSE;
  3088. }
  3089. static bfd_vma
  3090. xcoff_loader_symbol_offset (bfd *abfd,
  3091. struct internal_ldhdr *ldhdr ATTRIBUTE_UNUSED)
  3092. {
  3093. return bfd_xcoff_ldhdrsz (abfd);
  3094. }
  3095. static bfd_vma
  3096. xcoff_loader_reloc_offset (bfd *abfd, struct internal_ldhdr *ldhdr)
  3097. {
  3098. return bfd_xcoff_ldhdrsz (abfd) + ldhdr->l_nsyms * bfd_xcoff_ldsymsz (abfd);
  3099. }
  3100. static bfd_boolean
  3101. xcoff_generate_rtinit (bfd *abfd, const char *init, const char *fini,
  3102. bfd_boolean rtld)
  3103. {
  3104. bfd_byte filehdr_ext[FILHSZ];
  3105. bfd_byte scnhdr_ext[SCNHSZ];
  3106. bfd_byte syment_ext[SYMESZ * 10];
  3107. bfd_byte reloc_ext[RELSZ * 3];
  3108. bfd_byte *data_buffer;
  3109. bfd_size_type data_buffer_size;
  3110. bfd_byte *string_table = NULL, *st_tmp = NULL;
  3111. bfd_size_type string_table_size;
  3112. bfd_vma val;
  3113. size_t initsz, finisz;
  3114. struct internal_filehdr filehdr;
  3115. struct internal_scnhdr scnhdr;
  3116. struct internal_syment syment;
  3117. union internal_auxent auxent;
  3118. struct internal_reloc reloc;
  3119. char *data_name = ".data";
  3120. char *rtinit_name = "__rtinit";
  3121. char *rtld_name = "__rtld";
  3122. if (! bfd_xcoff_rtinit_size (abfd))
  3123. return FALSE;
  3124. initsz = (init == NULL ? 0 : 1 + strlen (init));
  3125. finisz = (fini == NULL ? 0 : 1 + strlen (fini));
  3126. /* file header */
  3127. memset (filehdr_ext, 0, FILHSZ);
  3128. memset (&filehdr, 0, sizeof (struct internal_filehdr));
  3129. filehdr.f_magic = bfd_xcoff_magic_number (abfd);
  3130. filehdr.f_nscns = 1;
  3131. filehdr.f_timdat = 0;
  3132. filehdr.f_nsyms = 0; /* at least 6, no more than 10 */
  3133. filehdr.f_symptr = 0; /* set below */
  3134. filehdr.f_opthdr = 0;
  3135. filehdr.f_flags = 0;
  3136. /* section header */
  3137. memset (scnhdr_ext, 0, SCNHSZ);
  3138. memset (&scnhdr, 0, sizeof (struct internal_scnhdr));
  3139. memcpy (scnhdr.s_name, data_name, strlen (data_name));
  3140. scnhdr.s_paddr = 0;
  3141. scnhdr.s_vaddr = 0;
  3142. scnhdr.s_size = 0; /* set below */
  3143. scnhdr.s_scnptr = FILHSZ + SCNHSZ;
  3144. scnhdr.s_relptr = 0; /* set below */
  3145. scnhdr.s_lnnoptr = 0;
  3146. scnhdr.s_nreloc = 0; /* either 1 or 2 */
  3147. scnhdr.s_nlnno = 0;
  3148. scnhdr.s_flags = STYP_DATA;
  3149. /* .data
  3150. 0x0000 0x00000000 : rtl
  3151. 0x0004 0x00000010 : offset to init, or 0
  3152. 0x0008 0x00000028 : offset to fini, or 0
  3153. 0x000C 0x0000000C : size of descriptor
  3154. 0x0010 0x00000000 : init, needs a reloc
  3155. 0x0014 0x00000040 : offset to init name
  3156. 0x0018 0x00000000 : flags, padded to a word
  3157. 0x001C 0x00000000 : empty init
  3158. 0x0020 0x00000000 :
  3159. 0x0024 0x00000000 :
  3160. 0x0028 0x00000000 : fini, needs a reloc
  3161. 0x002C 0x00000??? : offset to fini name
  3162. 0x0030 0x00000000 : flags, padded to a word
  3163. 0x0034 0x00000000 : empty fini
  3164. 0x0038 0x00000000 :
  3165. 0x003C 0x00000000 :
  3166. 0x0040 init name
  3167. 0x0040 + initsz fini name */
  3168. data_buffer_size = 0x0040 + initsz + finisz;
  3169. data_buffer_size = (data_buffer_size + 7) &~ (bfd_size_type) 7;
  3170. data_buffer = NULL;
  3171. data_buffer = (bfd_byte *) bfd_zmalloc (data_buffer_size);
  3172. if (data_buffer == NULL)
  3173. return FALSE;
  3174. if (initsz)
  3175. {
  3176. val = 0x10;
  3177. bfd_h_put_32 (abfd, val, &data_buffer[0x04]);
  3178. val = 0x40;
  3179. bfd_h_put_32 (abfd, val, &data_buffer[0x14]);
  3180. memcpy (&data_buffer[val], init, initsz);
  3181. }
  3182. if (finisz)
  3183. {
  3184. val = 0x28;
  3185. bfd_h_put_32 (abfd, val, &data_buffer[0x08]);
  3186. val = 0x40 + initsz;
  3187. bfd_h_put_32 (abfd, val, &data_buffer[0x2C]);
  3188. memcpy (&data_buffer[val], fini, finisz);
  3189. }
  3190. val = 0x0C;
  3191. bfd_h_put_32 (abfd, val, &data_buffer[0x0C]);
  3192. scnhdr.s_size = data_buffer_size;
  3193. /* string table */
  3194. string_table_size = 0;
  3195. if (initsz > 9)
  3196. string_table_size += initsz;
  3197. if (finisz > 9)
  3198. string_table_size += finisz;
  3199. if (string_table_size)
  3200. {
  3201. string_table_size += 4;
  3202. string_table = (bfd_byte *) bfd_zmalloc (string_table_size);
  3203. if (string_table == NULL)
  3204. return FALSE;
  3205. val = string_table_size;
  3206. bfd_h_put_32 (abfd, val, &string_table[0]);
  3207. st_tmp = string_table + 4;
  3208. }
  3209. /* symbols
  3210. 0. .data csect
  3211. 2. __rtinit
  3212. 4. init function
  3213. 6. fini function
  3214. 8. __rtld */
  3215. memset (syment_ext, 0, 10 * SYMESZ);
  3216. memset (reloc_ext, 0, 3 * RELSZ);
  3217. /* .data csect */
  3218. memset (&syment, 0, sizeof (struct internal_syment));
  3219. memset (&auxent, 0, sizeof (union internal_auxent));
  3220. memcpy (syment._n._n_name, data_name, strlen (data_name));
  3221. syment.n_scnum = 1;
  3222. syment.n_sclass = C_HIDEXT;
  3223. syment.n_numaux = 1;
  3224. auxent.x_csect.x_scnlen.l = data_buffer_size;
  3225. auxent.x_csect.x_smtyp = 3 << 3 | XTY_SD;
  3226. auxent.x_csect.x_smclas = XMC_RW;
  3227. bfd_coff_swap_sym_out (abfd, &syment,
  3228. &syment_ext[filehdr.f_nsyms * SYMESZ]);
  3229. bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
  3230. syment.n_numaux,
  3231. &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
  3232. filehdr.f_nsyms += 2;
  3233. /* __rtinit */
  3234. memset (&syment, 0, sizeof (struct internal_syment));
  3235. memset (&auxent, 0, sizeof (union internal_auxent));
  3236. memcpy (syment._n._n_name, rtinit_name, strlen (rtinit_name));
  3237. syment.n_scnum = 1;
  3238. syment.n_sclass = C_EXT;
  3239. syment.n_numaux = 1;
  3240. auxent.x_csect.x_smtyp = XTY_LD;
  3241. auxent.x_csect.x_smclas = XMC_RW;
  3242. bfd_coff_swap_sym_out (abfd, &syment,
  3243. &syment_ext[filehdr.f_nsyms * SYMESZ]);
  3244. bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
  3245. syment.n_numaux,
  3246. &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
  3247. filehdr.f_nsyms += 2;
  3248. /* init */
  3249. if (initsz)
  3250. {
  3251. memset (&syment, 0, sizeof (struct internal_syment));
  3252. memset (&auxent, 0, sizeof (union internal_auxent));
  3253. if (initsz > 9)
  3254. {
  3255. syment._n._n_n._n_offset = st_tmp - string_table;
  3256. memcpy (st_tmp, init, initsz);
  3257. st_tmp += initsz;
  3258. }
  3259. else
  3260. memcpy (syment._n._n_name, init, initsz - 1);
  3261. syment.n_sclass = C_EXT;
  3262. syment.n_numaux = 1;
  3263. bfd_coff_swap_sym_out (abfd, &syment,
  3264. &syment_ext[filehdr.f_nsyms * SYMESZ]);
  3265. bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
  3266. syment.n_numaux,
  3267. &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
  3268. /* reloc */
  3269. memset (&reloc, 0, sizeof (struct internal_reloc));
  3270. reloc.r_vaddr = 0x0010;
  3271. reloc.r_symndx = filehdr.f_nsyms;
  3272. reloc.r_type = R_POS;
  3273. reloc.r_size = 31;
  3274. bfd_coff_swap_reloc_out (abfd, &reloc, &reloc_ext[0]);
  3275. filehdr.f_nsyms += 2;
  3276. scnhdr.s_nreloc += 1;
  3277. }
  3278. /* fini */
  3279. if (finisz)
  3280. {
  3281. memset (&syment, 0, sizeof (struct internal_syment));
  3282. memset (&auxent, 0, sizeof (union internal_auxent));
  3283. if (finisz > 9)
  3284. {
  3285. syment._n._n_n._n_offset = st_tmp - string_table;
  3286. memcpy (st_tmp, fini, finisz);
  3287. st_tmp += finisz;
  3288. }
  3289. else
  3290. memcpy (syment._n._n_name, fini, finisz - 1);
  3291. syment.n_sclass = C_EXT;
  3292. syment.n_numaux = 1;
  3293. bfd_coff_swap_sym_out (abfd, &syment,
  3294. &syment_ext[filehdr.f_nsyms * SYMESZ]);
  3295. bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
  3296. syment.n_numaux,
  3297. &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
  3298. /* reloc */
  3299. memset (&reloc, 0, sizeof (struct internal_reloc));
  3300. reloc.r_vaddr = 0x0028;
  3301. reloc.r_symndx = filehdr.f_nsyms;
  3302. reloc.r_type = R_POS;
  3303. reloc.r_size = 31;
  3304. bfd_coff_swap_reloc_out (abfd, &reloc,
  3305. &reloc_ext[scnhdr.s_nreloc * RELSZ]);
  3306. filehdr.f_nsyms += 2;
  3307. scnhdr.s_nreloc += 1;
  3308. }
  3309. if (rtld)
  3310. {
  3311. memset (&syment, 0, sizeof (struct internal_syment));
  3312. memset (&auxent, 0, sizeof (union internal_auxent));
  3313. memcpy (syment._n._n_name, rtld_name, strlen (rtld_name));
  3314. syment.n_sclass = C_EXT;
  3315. syment.n_numaux = 1;
  3316. bfd_coff_swap_sym_out (abfd, &syment,
  3317. &syment_ext[filehdr.f_nsyms * SYMESZ]);
  3318. bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
  3319. syment.n_numaux,
  3320. &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
  3321. /* reloc */
  3322. memset (&reloc, 0, sizeof (struct internal_reloc));
  3323. reloc.r_vaddr = 0x0000;
  3324. reloc.r_symndx = filehdr.f_nsyms;
  3325. reloc.r_type = R_POS;
  3326. reloc.r_size = 31;
  3327. bfd_coff_swap_reloc_out (abfd, &reloc,
  3328. &reloc_ext[scnhdr.s_nreloc * RELSZ]);
  3329. filehdr.f_nsyms += 2;
  3330. scnhdr.s_nreloc += 1;
  3331. }
  3332. scnhdr.s_relptr = scnhdr.s_scnptr + data_buffer_size;
  3333. filehdr.f_symptr = scnhdr.s_relptr + scnhdr.s_nreloc * RELSZ;
  3334. bfd_coff_swap_filehdr_out (abfd, &filehdr, filehdr_ext);
  3335. bfd_bwrite (filehdr_ext, FILHSZ, abfd);
  3336. bfd_coff_swap_scnhdr_out (abfd, &scnhdr, scnhdr_ext);
  3337. bfd_bwrite (scnhdr_ext, SCNHSZ, abfd);
  3338. bfd_bwrite (data_buffer, data_buffer_size, abfd);
  3339. bfd_bwrite (reloc_ext, scnhdr.s_nreloc * RELSZ, abfd);
  3340. bfd_bwrite (syment_ext, filehdr.f_nsyms * SYMESZ, abfd);
  3341. bfd_bwrite (string_table, string_table_size, abfd);
  3342. free (data_buffer);
  3343. data_buffer = NULL;
  3344. return TRUE;
  3345. }
  3346. static reloc_howto_type xcoff_dynamic_reloc =
  3347. HOWTO (0, /* type */
  3348. 0, /* rightshift */
  3349. 2, /* size (0 = byte, 1 = short, 2 = long) */
  3350. 32, /* bitsize */
  3351. FALSE, /* pc_relative */
  3352. 0, /* bitpos */
  3353. complain_overflow_bitfield, /* complain_on_overflow */
  3354. 0, /* special_function */
  3355. "R_POS", /* name */
  3356. TRUE, /* partial_inplace */
  3357. 0xffffffff, /* src_mask */
  3358. 0xffffffff, /* dst_mask */
  3359. FALSE); /* pcrel_offset */
  3360. /* glink
  3361. The first word of global linkage code must be modified by filling in
  3362. the correct TOC offset. */
  3363. static unsigned long xcoff_glink_code[9] =
  3364. {
  3365. 0x81820000, /* lwz r12,0(r2) */
  3366. 0x90410014, /* stw r2,20(r1) */
  3367. 0x800c0000, /* lwz r0,0(r12) */
  3368. 0x804c0004, /* lwz r2,4(r12) */
  3369. 0x7c0903a6, /* mtctr r0 */
  3370. 0x4e800420, /* bctr */
  3371. 0x00000000, /* start of traceback table */
  3372. 0x000c8000, /* traceback table */
  3373. 0x00000000, /* traceback table */
  3374. };
  3375. /* Table to convert DWARF flags to section names. */
  3376. const struct xcoff_dwsect_name xcoff_dwsect_names[] = {
  3377. { SSUBTYP_DWINFO, ".dwinfo", TRUE },
  3378. { SSUBTYP_DWLINE, ".dwline", TRUE },
  3379. { SSUBTYP_DWPBNMS, ".dwpbnms", TRUE },
  3380. { SSUBTYP_DWPBTYP, ".dwpbtyp", TRUE },
  3381. { SSUBTYP_DWARNGE, ".dwarnge", TRUE },
  3382. { SSUBTYP_DWABREV, ".dwabrev", FALSE },
  3383. { SSUBTYP_DWSTR, ".dwstr", TRUE },
  3384. { SSUBTYP_DWRNGES, ".dwrnges", TRUE }
  3385. };
  3386. static const struct xcoff_backend_data_rec bfd_xcoff_backend_data =
  3387. {
  3388. { /* COFF backend, defined in libcoff.h. */
  3389. _bfd_xcoff_swap_aux_in,
  3390. _bfd_xcoff_swap_sym_in,
  3391. coff_swap_lineno_in,
  3392. _bfd_xcoff_swap_aux_out,
  3393. _bfd_xcoff_swap_sym_out,
  3394. coff_swap_lineno_out,
  3395. xcoff_swap_reloc_out,
  3396. coff_swap_filehdr_out,
  3397. coff_swap_aouthdr_out,
  3398. coff_swap_scnhdr_out,
  3399. FILHSZ,
  3400. AOUTSZ,
  3401. SCNHSZ,
  3402. SYMESZ,
  3403. AUXESZ,
  3404. RELSZ,
  3405. LINESZ,
  3406. FILNMLEN,
  3407. TRUE, /* _bfd_coff_long_filenames */
  3408. XCOFF_NO_LONG_SECTION_NAMES, /* _bfd_coff_long_section_names */
  3409. 3, /* _bfd_coff_default_section_alignment_power */
  3410. FALSE, /* _bfd_coff_force_symnames_in_strings */
  3411. 2, /* _bfd_coff_debug_string_prefix_length */
  3412. coff_swap_filehdr_in,
  3413. coff_swap_aouthdr_in,
  3414. coff_swap_scnhdr_in,
  3415. xcoff_swap_reloc_in,
  3416. coff_bad_format_hook,
  3417. coff_set_arch_mach_hook,
  3418. coff_mkobject_hook,
  3419. styp_to_sec_flags,
  3420. coff_set_alignment_hook,
  3421. coff_slurp_symbol_table,
  3422. symname_in_debug_hook,
  3423. coff_pointerize_aux_hook,
  3424. coff_print_aux,
  3425. dummy_reloc16_extra_cases,
  3426. dummy_reloc16_estimate,
  3427. NULL, /* bfd_coff_sym_is_global */
  3428. coff_compute_section_file_positions,
  3429. NULL, /* _bfd_coff_start_final_link */
  3430. xcoff_ppc_relocate_section,
  3431. coff_rtype_to_howto,
  3432. NULL, /* _bfd_coff_adjust_symndx */
  3433. _bfd_generic_link_add_one_symbol,
  3434. coff_link_output_has_begun,
  3435. coff_final_link_postscript,
  3436. NULL /* print_pdata. */
  3437. },
  3438. 0x01DF, /* magic number */
  3439. bfd_arch_rs6000,
  3440. bfd_mach_rs6k,
  3441. /* Function pointers to xcoff specific swap routines. */
  3442. xcoff_swap_ldhdr_in,
  3443. xcoff_swap_ldhdr_out,
  3444. xcoff_swap_ldsym_in,
  3445. xcoff_swap_ldsym_out,
  3446. xcoff_swap_ldrel_in,
  3447. xcoff_swap_ldrel_out,
  3448. /* Sizes. */
  3449. LDHDRSZ,
  3450. LDSYMSZ,
  3451. LDRELSZ,
  3452. 12, /* _xcoff_function_descriptor_size */
  3453. SMALL_AOUTSZ,
  3454. /* Versions. */
  3455. 1, /* _xcoff_ldhdr_version */
  3456. _bfd_xcoff_put_symbol_name,
  3457. _bfd_xcoff_put_ldsymbol_name,
  3458. &xcoff_dynamic_reloc,
  3459. xcoff_create_csect_from_smclas,
  3460. /* Lineno and reloc count overflow. */
  3461. xcoff_is_lineno_count_overflow,
  3462. xcoff_is_reloc_count_overflow,
  3463. xcoff_loader_symbol_offset,
  3464. xcoff_loader_reloc_offset,
  3465. /* glink. */
  3466. &xcoff_glink_code[0],
  3467. 36, /* _xcoff_glink_size */
  3468. /* rtinit */
  3469. 64, /* _xcoff_rtinit_size */
  3470. xcoff_generate_rtinit,
  3471. };
  3472. /* The transfer vector that leads the outside world to all of the above. */
  3473. const bfd_target rs6000coff_vec =
  3474. {
  3475. "aixcoff-rs6000",
  3476. bfd_target_xcoff_flavour,
  3477. BFD_ENDIAN_BIG, /* data byte order is big */
  3478. BFD_ENDIAN_BIG, /* header byte order is big */
  3479. (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | DYNAMIC
  3480. | HAS_SYMS | HAS_LOCALS | WP_TEXT),
  3481. SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE | SEC_DATA,
  3482. 0, /* leading char */
  3483. '/', /* ar_pad_char */
  3484. 15, /* ar_max_namelen */
  3485. 0, /* match priority. */
  3486. /* data */
  3487. bfd_getb64,
  3488. bfd_getb_signed_64,
  3489. bfd_putb64,
  3490. bfd_getb32,
  3491. bfd_getb_signed_32,
  3492. bfd_putb32,
  3493. bfd_getb16,
  3494. bfd_getb_signed_16,
  3495. bfd_putb16,
  3496. /* hdrs */
  3497. bfd_getb64,
  3498. bfd_getb_signed_64,
  3499. bfd_putb64,
  3500. bfd_getb32,
  3501. bfd_getb_signed_32,
  3502. bfd_putb32,
  3503. bfd_getb16,
  3504. bfd_getb_signed_16,
  3505. bfd_putb16,
  3506. { /* bfd_check_format */
  3507. _bfd_dummy_target,
  3508. coff_object_p,
  3509. _bfd_xcoff_archive_p,
  3510. CORE_FILE_P
  3511. },
  3512. { /* bfd_set_format */
  3513. bfd_false,
  3514. coff_mkobject,
  3515. _bfd_generic_mkarchive,
  3516. bfd_false
  3517. },
  3518. {/* bfd_write_contents */
  3519. bfd_false,
  3520. coff_write_object_contents,
  3521. _bfd_xcoff_write_archive_contents,
  3522. bfd_false
  3523. },
  3524. /* Generic */
  3525. bfd_true,
  3526. bfd_true,
  3527. coff_new_section_hook,
  3528. _bfd_generic_get_section_contents,
  3529. _bfd_generic_get_section_contents_in_window,
  3530. /* Copy */
  3531. _bfd_xcoff_copy_private_bfd_data,
  3532. _bfd_generic_bfd_merge_private_bfd_data,
  3533. _bfd_generic_init_private_section_data,
  3534. _bfd_generic_bfd_copy_private_section_data,
  3535. _bfd_generic_bfd_copy_private_symbol_data,
  3536. _bfd_generic_bfd_copy_private_header_data,
  3537. _bfd_generic_bfd_set_private_flags,
  3538. _bfd_generic_bfd_print_private_bfd_data,
  3539. /* Core */
  3540. BFD_JUMP_TABLE_CORE (coff),
  3541. /* Archive */
  3542. _bfd_xcoff_slurp_armap,
  3543. _bfd_noarchive_slurp_extended_name_table,
  3544. _bfd_noarchive_construct_extended_name_table,
  3545. bfd_dont_truncate_arname,
  3546. _bfd_xcoff_write_armap,
  3547. _bfd_xcoff_read_ar_hdr,
  3548. _bfd_generic_write_ar_hdr,
  3549. _bfd_xcoff_openr_next_archived_file,
  3550. _bfd_generic_get_elt_at_index,
  3551. _bfd_xcoff_stat_arch_elt,
  3552. bfd_true,
  3553. /* Symbols */
  3554. coff_get_symtab_upper_bound,
  3555. coff_canonicalize_symtab,
  3556. coff_make_empty_symbol,
  3557. coff_print_symbol,
  3558. coff_get_symbol_info,
  3559. _bfd_xcoff_is_local_label_name,
  3560. coff_bfd_is_target_special_symbol,
  3561. coff_get_lineno,
  3562. xcoff_find_nearest_line,
  3563. _bfd_generic_find_line,
  3564. coff_find_inliner_info,
  3565. coff_bfd_make_debug_symbol,
  3566. _bfd_generic_read_minisymbols,
  3567. _bfd_generic_minisymbol_to_symbol,
  3568. /* Reloc */
  3569. coff_get_reloc_upper_bound,
  3570. coff_canonicalize_reloc,
  3571. _bfd_xcoff_reloc_type_lookup,
  3572. _bfd_xcoff_reloc_name_lookup,
  3573. /* Write */
  3574. coff_set_arch_mach,
  3575. coff_set_section_contents,
  3576. /* Link */
  3577. _bfd_xcoff_sizeof_headers,
  3578. bfd_generic_get_relocated_section_contents,
  3579. bfd_generic_relax_section,
  3580. _bfd_xcoff_bfd_link_hash_table_create,
  3581. _bfd_generic_link_hash_table_free,
  3582. _bfd_xcoff_bfd_link_add_symbols,
  3583. _bfd_generic_link_just_syms,
  3584. _bfd_generic_copy_link_hash_symbol_type,
  3585. _bfd_xcoff_bfd_final_link,
  3586. _bfd_generic_link_split_section,
  3587. bfd_generic_gc_sections,
  3588. bfd_generic_lookup_section_flags,
  3589. bfd_generic_merge_sections,
  3590. bfd_generic_is_group_section,
  3591. bfd_generic_discard_group,
  3592. _bfd_generic_section_already_linked,
  3593. _bfd_xcoff_define_common_symbol,
  3594. /* Dynamic */
  3595. _bfd_xcoff_get_dynamic_symtab_upper_bound,
  3596. _bfd_xcoff_canonicalize_dynamic_symtab,
  3597. _bfd_nodynamic_get_synthetic_symtab,
  3598. _bfd_xcoff_get_dynamic_reloc_upper_bound,
  3599. _bfd_xcoff_canonicalize_dynamic_reloc,
  3600. /* Opposite endian version, none exists */
  3601. NULL,
  3602. & bfd_xcoff_backend_data,
  3603. };
  3604. /* xcoff-powermac target
  3605. Old target.
  3606. Only difference between this target and the rs6000 target is the
  3607. the default architecture and machine type used in coffcode.h
  3608. PowerPC Macs use the same magic numbers as RS/6000
  3609. (because that's how they were bootstrapped originally),
  3610. but they are always PowerPC architecture. */
  3611. static const struct xcoff_backend_data_rec bfd_pmac_xcoff_backend_data =
  3612. {
  3613. { /* COFF backend, defined in libcoff.h. */
  3614. _bfd_xcoff_swap_aux_in,
  3615. _bfd_xcoff_swap_sym_in,
  3616. coff_swap_lineno_in,
  3617. _bfd_xcoff_swap_aux_out,
  3618. _bfd_xcoff_swap_sym_out,
  3619. coff_swap_lineno_out,
  3620. xcoff_swap_reloc_out,
  3621. coff_swap_filehdr_out,
  3622. coff_swap_aouthdr_out,
  3623. coff_swap_scnhdr_out,
  3624. FILHSZ,
  3625. AOUTSZ,
  3626. SCNHSZ,
  3627. SYMESZ,
  3628. AUXESZ,
  3629. RELSZ,
  3630. LINESZ,
  3631. FILNMLEN,
  3632. TRUE, /* _bfd_coff_long_filenames */
  3633. XCOFF_NO_LONG_SECTION_NAMES, /* _bfd_coff_long_section_names */
  3634. 3, /* _bfd_coff_default_section_alignment_power */
  3635. FALSE, /* _bfd_coff_force_symnames_in_strings */
  3636. 2, /* _bfd_coff_debug_string_prefix_length */
  3637. coff_swap_filehdr_in,
  3638. coff_swap_aouthdr_in,
  3639. coff_swap_scnhdr_in,
  3640. xcoff_swap_reloc_in,
  3641. coff_bad_format_hook,
  3642. coff_set_arch_mach_hook,
  3643. coff_mkobject_hook,
  3644. styp_to_sec_flags,
  3645. coff_set_alignment_hook,
  3646. coff_slurp_symbol_table,
  3647. symname_in_debug_hook,
  3648. coff_pointerize_aux_hook,
  3649. coff_print_aux,
  3650. dummy_reloc16_extra_cases,
  3651. dummy_reloc16_estimate,
  3652. NULL, /* bfd_coff_sym_is_global */
  3653. coff_compute_section_file_positions,
  3654. NULL, /* _bfd_coff_start_final_link */
  3655. xcoff_ppc_relocate_section,
  3656. coff_rtype_to_howto,
  3657. NULL, /* _bfd_coff_adjust_symndx */
  3658. _bfd_generic_link_add_one_symbol,
  3659. coff_link_output_has_begun,
  3660. coff_final_link_postscript,
  3661. NULL /* print_pdata. */
  3662. },
  3663. 0x01DF, /* magic number */
  3664. bfd_arch_powerpc,
  3665. bfd_mach_ppc,
  3666. /* Function pointers to xcoff specific swap routines. */
  3667. xcoff_swap_ldhdr_in,
  3668. xcoff_swap_ldhdr_out,
  3669. xcoff_swap_ldsym_in,
  3670. xcoff_swap_ldsym_out,
  3671. xcoff_swap_ldrel_in,
  3672. xcoff_swap_ldrel_out,
  3673. /* Sizes. */
  3674. LDHDRSZ,
  3675. LDSYMSZ,
  3676. LDRELSZ,
  3677. 12, /* _xcoff_function_descriptor_size */
  3678. SMALL_AOUTSZ,
  3679. /* Versions. */
  3680. 1, /* _xcoff_ldhdr_version */
  3681. _bfd_xcoff_put_symbol_name,
  3682. _bfd_xcoff_put_ldsymbol_name,
  3683. &xcoff_dynamic_reloc,
  3684. xcoff_create_csect_from_smclas,
  3685. /* Lineno and reloc count overflow. */
  3686. xcoff_is_lineno_count_overflow,
  3687. xcoff_is_reloc_count_overflow,
  3688. xcoff_loader_symbol_offset,
  3689. xcoff_loader_reloc_offset,
  3690. /* glink. */
  3691. &xcoff_glink_code[0],
  3692. 36, /* _xcoff_glink_size */
  3693. /* rtinit */
  3694. 0, /* _xcoff_rtinit_size */
  3695. xcoff_generate_rtinit,
  3696. };
  3697. /* The transfer vector that leads the outside world to all of the above. */
  3698. const bfd_target pmac_xcoff_vec =
  3699. {
  3700. "xcoff-powermac",
  3701. bfd_target_xcoff_flavour,
  3702. BFD_ENDIAN_BIG, /* data byte order is big */
  3703. BFD_ENDIAN_BIG, /* header byte order is big */
  3704. (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | DYNAMIC
  3705. | HAS_SYMS | HAS_LOCALS | WP_TEXT),
  3706. SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE | SEC_DATA,
  3707. 0, /* leading char */
  3708. '/', /* ar_pad_char */
  3709. 15, /* ar_max_namelen */
  3710. 0, /* match priority. */
  3711. /* data */
  3712. bfd_getb64,
  3713. bfd_getb_signed_64,
  3714. bfd_putb64,
  3715. bfd_getb32,
  3716. bfd_getb_signed_32,
  3717. bfd_putb32,
  3718. bfd_getb16,
  3719. bfd_getb_signed_16,
  3720. bfd_putb16,
  3721. /* hdrs */
  3722. bfd_getb64,
  3723. bfd_getb_signed_64,
  3724. bfd_putb64,
  3725. bfd_getb32,
  3726. bfd_getb_signed_32,
  3727. bfd_putb32,
  3728. bfd_getb16,
  3729. bfd_getb_signed_16,
  3730. bfd_putb16,
  3731. { /* bfd_check_format */
  3732. _bfd_dummy_target,
  3733. coff_object_p,
  3734. _bfd_xcoff_archive_p,
  3735. CORE_FILE_P
  3736. },
  3737. { /* bfd_set_format */
  3738. bfd_false,
  3739. coff_mkobject,
  3740. _bfd_generic_mkarchive,
  3741. bfd_false
  3742. },
  3743. {/* bfd_write_contents */
  3744. bfd_false,
  3745. coff_write_object_contents,
  3746. _bfd_xcoff_write_archive_contents,
  3747. bfd_false
  3748. },
  3749. /* Generic */
  3750. bfd_true,
  3751. bfd_true,
  3752. coff_new_section_hook,
  3753. _bfd_generic_get_section_contents,
  3754. _bfd_generic_get_section_contents_in_window,
  3755. /* Copy */
  3756. _bfd_xcoff_copy_private_bfd_data,
  3757. _bfd_generic_bfd_merge_private_bfd_data,
  3758. _bfd_generic_init_private_section_data,
  3759. _bfd_generic_bfd_copy_private_section_data,
  3760. _bfd_generic_bfd_copy_private_symbol_data,
  3761. _bfd_generic_bfd_copy_private_header_data,
  3762. _bfd_generic_bfd_set_private_flags,
  3763. _bfd_generic_bfd_print_private_bfd_data,
  3764. /* Core */
  3765. BFD_JUMP_TABLE_CORE (coff),
  3766. /* Archive */
  3767. _bfd_xcoff_slurp_armap,
  3768. _bfd_noarchive_slurp_extended_name_table,
  3769. _bfd_noarchive_construct_extended_name_table,
  3770. bfd_dont_truncate_arname,
  3771. _bfd_xcoff_write_armap,
  3772. _bfd_xcoff_read_ar_hdr,
  3773. _bfd_generic_write_ar_hdr,
  3774. _bfd_xcoff_openr_next_archived_file,
  3775. _bfd_generic_get_elt_at_index,
  3776. _bfd_xcoff_stat_arch_elt,
  3777. bfd_true,
  3778. /* Symbols */
  3779. coff_get_symtab_upper_bound,
  3780. coff_canonicalize_symtab,
  3781. coff_make_empty_symbol,
  3782. coff_print_symbol,
  3783. coff_get_symbol_info,
  3784. _bfd_xcoff_is_local_label_name,
  3785. coff_bfd_is_target_special_symbol,
  3786. coff_get_lineno,
  3787. xcoff_find_nearest_line,
  3788. _bfd_generic_find_line,
  3789. coff_find_inliner_info,
  3790. coff_bfd_make_debug_symbol,
  3791. _bfd_generic_read_minisymbols,
  3792. _bfd_generic_minisymbol_to_symbol,
  3793. /* Reloc */
  3794. coff_get_reloc_upper_bound,
  3795. coff_canonicalize_reloc,
  3796. _bfd_xcoff_reloc_type_lookup,
  3797. _bfd_xcoff_reloc_name_lookup,
  3798. /* Write */
  3799. coff_set_arch_mach,
  3800. coff_set_section_contents,
  3801. /* Link */
  3802. _bfd_xcoff_sizeof_headers,
  3803. bfd_generic_get_relocated_section_contents,
  3804. bfd_generic_relax_section,
  3805. _bfd_xcoff_bfd_link_hash_table_create,
  3806. _bfd_generic_link_hash_table_free,
  3807. _bfd_xcoff_bfd_link_add_symbols,
  3808. _bfd_generic_link_just_syms,
  3809. _bfd_generic_copy_link_hash_symbol_type,
  3810. _bfd_xcoff_bfd_final_link,
  3811. _bfd_generic_link_split_section,
  3812. bfd_generic_gc_sections,
  3813. bfd_generic_lookup_section_flags,
  3814. bfd_generic_merge_sections,
  3815. bfd_generic_is_group_section,
  3816. bfd_generic_discard_group,
  3817. _bfd_generic_section_already_linked,
  3818. _bfd_xcoff_define_common_symbol,
  3819. /* Dynamic */
  3820. _bfd_xcoff_get_dynamic_symtab_upper_bound,
  3821. _bfd_xcoff_canonicalize_dynamic_symtab,
  3822. _bfd_nodynamic_get_synthetic_symtab,
  3823. _bfd_xcoff_get_dynamic_reloc_upper_bound,
  3824. _bfd_xcoff_canonicalize_dynamic_reloc,
  3825. /* Opposite endian version, none exists */
  3826. NULL,
  3827. & bfd_pmac_xcoff_backend_data,
  3828. };