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