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