collect2-aix.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /* AIX cross support for collect2.
  2. Copyright (C) 2009-2019 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU General Public License as published by the Free
  6. Software Foundation; either version 3, or (at your option) any later
  7. version.
  8. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GCC; see the file COPYING3. If not see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef GCC_COLLECT2_AIX_H
  16. #define GCC_COLLECT2_AIX_H
  17. /* collect2-aix.c requires mmap support. It should otherwise be
  18. fairly portable. */
  19. #if defined(CROSS_DIRECTORY_STRUCTURE) \
  20. && defined(TARGET_AIX_VERSION) \
  21. && HAVE_MMAP
  22. #define CROSS_AIX_SUPPORT 1
  23. /* -------------------------------------------------------------------------
  24. Definitions adapted from bfd. (Fairly heavily adapted in some cases.)
  25. ------------------------------------------------------------------------- */
  26. /* Compatibility types for bfd. */
  27. typedef unsigned HOST_WIDE_INT bfd_vma;
  28. /* The size of an archive's fl_magic field. */
  29. #define FL_MAGIC_SIZE 8
  30. /* The expected contents of fl_magic for big archives. */
  31. #define FL_MAGIC_BIG_AR "<bigaf>\012"
  32. /* The size of each offset string in the header of a big archive. */
  33. #define AR_BIG_OFFSET_SIZE 20
  34. /* The format of the file header in a "big" XCOFF archive. */
  35. struct external_big_ar_filehdr
  36. {
  37. /* Magic string. */
  38. char fl_magic[FL_MAGIC_SIZE];
  39. /* Offset of the member table (decimal ASCII string). */
  40. char fl_memoff[AR_BIG_OFFSET_SIZE];
  41. /* Offset of the global symbol table for 32-bit objects (decimal ASCII
  42. string). */
  43. char fl_symoff[AR_BIG_OFFSET_SIZE];
  44. /* Offset of the global symbol table for 64-bit objects (decimal ASCII
  45. string). */
  46. char fl_symoff64[AR_BIG_OFFSET_SIZE];
  47. /* Offset of the first member in the archive (decimal ASCII string). */
  48. char fl_firstmemoff[AR_BIG_OFFSET_SIZE];
  49. /* Offset of the last member in the archive (decimal ASCII string). */
  50. char fl_lastmemoff[AR_BIG_OFFSET_SIZE];
  51. /* Offset of the first member on the free list (decimal ASCII
  52. string). */
  53. char fl_freeoff[AR_BIG_OFFSET_SIZE];
  54. };
  55. /* Each archive name is followed by this many bytes of magic string. */
  56. #define SXCOFFARFMAG 2
  57. /* The format of a member header in a "big" XCOFF archive. */
  58. struct external_big_ar_member
  59. {
  60. /* File size not including the header (decimal ASCII string). */
  61. char ar_size[AR_BIG_OFFSET_SIZE];
  62. /* File offset of next archive member (decimal ASCII string). */
  63. char ar_nextoff[AR_BIG_OFFSET_SIZE];
  64. /* File offset of previous archive member (decimal ASCII string). */
  65. char ar_prevoff[AR_BIG_OFFSET_SIZE];
  66. /* File mtime (decimal ASCII string). */
  67. char ar_date[12];
  68. /* File UID (decimal ASCII string). */
  69. char ar_uid[12];
  70. /* File GID (decimal ASCII string). */
  71. char ar_gid[12];
  72. /* File mode (octal ASCII string). */
  73. char ar_mode[12];
  74. /* Length of file name (decimal ASCII string). */
  75. char ar_namlen[4];
  76. /* This structure is followed by the file name. The length of the
  77. name is given in the namlen field. If the length of the name is
  78. odd, the name is followed by a null byte. The name and optional
  79. null byte are followed by XCOFFARFMAG, which is not included in
  80. namlen. The contents of the archive member follow; the number of
  81. bytes is given in the size field. */
  82. };
  83. /* The known values of f_magic in an XCOFF file header. */
  84. #define U802WRMAGIC 0730 /* Writeable text segments. */
  85. #define U802ROMAGIC 0735 /* Readonly sharable text segments. */
  86. #define U802TOCMAGIC 0737 /* Readonly text segments and TOC. */
  87. #define U803XTOCMAGIC 0757 /* Aix 4.3 64-bit XCOFF. */
  88. #define U64_TOCMAGIC 0767 /* AIX 5+ 64-bit XCOFF. */
  89. /* The number of bytes in an XCOFF file's f_magic field. */
  90. #define F_MAGIC_SIZE 2
  91. /* The format of a 32-bit XCOFF file header. */
  92. struct external_filehdr_32
  93. {
  94. /* The magic number. */
  95. char f_magic[F_MAGIC_SIZE];
  96. /* The number of sections. */
  97. char f_nscns[2];
  98. /* Time & date stamp. */
  99. char f_timdat[4];
  100. /* The offset of the symbol table from the start of the file. */
  101. char f_symptr[4];
  102. /* The number of entries in the symbol table. */
  103. char f_nsyms[4];
  104. /* The size of the auxiliary header. */
  105. char f_opthdr[2];
  106. /* Flags. */
  107. char f_flags[2];
  108. };
  109. /* The format of a 64-bit XCOFF file header. */
  110. struct external_filehdr_64
  111. {
  112. /* The magic number. */
  113. char f_magic[F_MAGIC_SIZE];
  114. /* The number of sections. */
  115. char f_nscns[2];
  116. /* Time & date stamp. */
  117. char f_timdat[4];
  118. /* The offset of the symbol table from the start of the file. */
  119. char f_symptr[8];
  120. /* The size of the auxiliary header. */
  121. char f_opthdr[2];
  122. /* Flags. */
  123. char f_flags[2];
  124. /* The number of entries in the symbol table. */
  125. char f_nsyms[4];
  126. };
  127. /* An internal representation of the XCOFF file header. */
  128. struct internal_filehdr
  129. {
  130. unsigned short f_magic;
  131. unsigned short f_nscns;
  132. long f_timdat;
  133. bfd_vma f_symptr;
  134. long f_nsyms;
  135. unsigned short f_opthdr;
  136. unsigned short f_flags;
  137. };
  138. /* Symbol classes have their names in the debug section if this flag
  139. is set. */
  140. #define DBXMASK 0x80
  141. /* The format of an XCOFF symbol-table entry. */
  142. struct external_syment
  143. {
  144. union {
  145. struct {
  146. union {
  147. /* The name of the symbol. There is an implicit null character
  148. after the end of the array. */
  149. char n_name[8];
  150. struct {
  151. /* If n_zeroes is zero, n_offset is the offset the name from
  152. the start of the string table. */
  153. char n_zeroes[4];
  154. char n_offset[4];
  155. } u;
  156. } u;
  157. /* The symbol's value. */
  158. char n_value[4];
  159. } xcoff32;
  160. struct {
  161. /* The symbol's value. */
  162. char n_value[8];
  163. /* The offset of the symbol from the start of the string table. */
  164. char n_offset[4];
  165. } xcoff64;
  166. } u;
  167. /* The number of the section to which this symbol belongs. */
  168. char n_scnum[2];
  169. /* The type of symbol. (It can be interpreted as an n_lang
  170. and an n_cpu byte, but we don't care about that here.) */
  171. char n_type[2];
  172. /* The class of symbol (a C_* value). */
  173. char n_sclass[1];
  174. /* The number of auxiliary symbols attached to this entry. */
  175. char n_numaux[1];
  176. };
  177. /* Definitions required by collect2. */
  178. #define C_EXT 2
  179. #define F_SHROBJ 0x2000
  180. #define F_LOADONLY 0x4000
  181. #define N_UNDEF ((short) 0)
  182. #define N_TMASK 060
  183. #define N_BTSHFT 4
  184. #define DT_NON 0
  185. #define DT_FCN 2
  186. /* -------------------------------------------------------------------------
  187. Local code.
  188. ------------------------------------------------------------------------- */
  189. /* An internal representation of an XCOFF symbol-table entry,
  190. which is associated with the API-defined SYMENT type. */
  191. struct internal_syment
  192. {
  193. char n_name[9];
  194. unsigned int n_zeroes;
  195. bfd_vma n_offset;
  196. bfd_vma n_value;
  197. short n_scnum;
  198. unsigned short n_flags;
  199. unsigned short n_type;
  200. unsigned char n_sclass;
  201. unsigned char n_numaux;
  202. };
  203. typedef struct internal_syment SYMENT;
  204. /* The internal representation of the API-defined LDFILE type. */
  205. struct internal_ldfile
  206. {
  207. /* The file handle for the associated file, or -1 if it hasn't been
  208. opened yet. */
  209. int fd;
  210. /* The start of the current XCOFF object, if one has been mapped
  211. into memory. Null otherwise. */
  212. char *object;
  213. /* The offset of OBJECT from the start of the containing page. */
  214. size_t page_offset;
  215. /* The size of the file pointed to by OBJECT. Valid iff OFFSET
  216. is nonnull. */
  217. size_t object_size;
  218. /* The offset of the next member in an archive after OBJECT,
  219. or -1 if this isn't an archive. Valid iff OFFSET is nonnull. */
  220. off_t next_member;
  221. /* The parsed version of the XCOFF file header. */
  222. struct internal_filehdr filehdr;
  223. };
  224. typedef struct internal_ldfile LDFILE;
  225. /* The API allows the file header to be directly accessed via this macro. */
  226. #define HEADER(FILE) ((FILE)->filehdr)
  227. /* API-defined return codes. SUCCESS must be > 0 and FAILURE must be <= 0. */
  228. #define SUCCESS 1
  229. #define FAILURE 0
  230. /* API-defined functions. */
  231. extern LDFILE *ldopen (char *, LDFILE *);
  232. extern char *ldgetname (LDFILE *, SYMENT *);
  233. extern int ldtbread (LDFILE *, long, SYMENT *);
  234. extern int ldclose (LDFILE *);
  235. #endif
  236. #endif /* GCC_COLLECT2_AIX_H */