1*86d7f5d3SJohn Marino /* `a.out' object-file definitions, including extensions to 64-bit fields 2*86d7f5d3SJohn Marino 3*86d7f5d3SJohn Marino Copyright 1999, 2000, 2001, 2003, 2009, 2010 Free Software Foundation, Inc. 4*86d7f5d3SJohn Marino 5*86d7f5d3SJohn Marino This program is free software; you can redistribute it and/or modify 6*86d7f5d3SJohn Marino it under the terms of the GNU General Public License as published by 7*86d7f5d3SJohn Marino the Free Software Foundation; either version 3 of the License, or 8*86d7f5d3SJohn Marino (at your option) any later version. 9*86d7f5d3SJohn Marino 10*86d7f5d3SJohn Marino This program is distributed in the hope that it will be useful, 11*86d7f5d3SJohn Marino but WITHOUT ANY WARRANTY; without even the implied warranty of 12*86d7f5d3SJohn Marino MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13*86d7f5d3SJohn Marino GNU General Public License for more details. 14*86d7f5d3SJohn Marino 15*86d7f5d3SJohn Marino You should have received a copy of the GNU General Public License 16*86d7f5d3SJohn Marino along with this program; if not, write to the Free Software 17*86d7f5d3SJohn Marino Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, 18*86d7f5d3SJohn Marino MA 02110-1301, USA. */ 19*86d7f5d3SJohn Marino 20*86d7f5d3SJohn Marino #ifndef __A_OUT_64_H__ 21*86d7f5d3SJohn Marino #define __A_OUT_64_H__ 22*86d7f5d3SJohn Marino 23*86d7f5d3SJohn Marino #ifndef BYTES_IN_WORD 24*86d7f5d3SJohn Marino #define BYTES_IN_WORD 4 25*86d7f5d3SJohn Marino #endif 26*86d7f5d3SJohn Marino 27*86d7f5d3SJohn Marino /* This is the layout on disk of the 32-bit or 64-bit exec header. */ 28*86d7f5d3SJohn Marino 29*86d7f5d3SJohn Marino #ifndef external_exec 30*86d7f5d3SJohn Marino struct external_exec 31*86d7f5d3SJohn Marino { 32*86d7f5d3SJohn Marino bfd_byte e_info[4]; /* Magic number and stuff. */ 33*86d7f5d3SJohn Marino bfd_byte e_text[BYTES_IN_WORD]; /* Length of text section in bytes. */ 34*86d7f5d3SJohn Marino bfd_byte e_data[BYTES_IN_WORD]; /* Length of data section in bytes. */ 35*86d7f5d3SJohn Marino bfd_byte e_bss[BYTES_IN_WORD]; /* Length of bss area in bytes. */ 36*86d7f5d3SJohn Marino bfd_byte e_syms[BYTES_IN_WORD]; /* Length of symbol table in bytes. */ 37*86d7f5d3SJohn Marino bfd_byte e_entry[BYTES_IN_WORD]; /* Start address. */ 38*86d7f5d3SJohn Marino bfd_byte e_trsize[BYTES_IN_WORD]; /* Length of text relocation info. */ 39*86d7f5d3SJohn Marino bfd_byte e_drsize[BYTES_IN_WORD]; /* Length of data relocation info. */ 40*86d7f5d3SJohn Marino }; 41*86d7f5d3SJohn Marino 42*86d7f5d3SJohn Marino #define EXEC_BYTES_SIZE (4 + BYTES_IN_WORD * 7) 43*86d7f5d3SJohn Marino 44*86d7f5d3SJohn Marino /* Magic numbers for a.out files. */ 45*86d7f5d3SJohn Marino 46*86d7f5d3SJohn Marino #if ARCH_SIZE==64 47*86d7f5d3SJohn Marino #define OMAGIC 0x1001 /* Code indicating object file. */ 48*86d7f5d3SJohn Marino #define ZMAGIC 0x1002 /* Code indicating demand-paged executable. */ 49*86d7f5d3SJohn Marino #define NMAGIC 0x1003 /* Code indicating pure executable. */ 50*86d7f5d3SJohn Marino 51*86d7f5d3SJohn Marino /* There is no 64-bit QMAGIC as far as I know. */ 52*86d7f5d3SJohn Marino 53*86d7f5d3SJohn Marino #define N_BADMAG(x) (N_MAGIC(x) != OMAGIC \ 54*86d7f5d3SJohn Marino && N_MAGIC(x) != NMAGIC \ 55*86d7f5d3SJohn Marino && N_MAGIC(x) != ZMAGIC) 56*86d7f5d3SJohn Marino #else 57*86d7f5d3SJohn Marino #define OMAGIC 0407 /* Object file or impure executable. */ 58*86d7f5d3SJohn Marino #define NMAGIC 0410 /* Code indicating pure executable. */ 59*86d7f5d3SJohn Marino #define ZMAGIC 0413 /* Code indicating demand-paged executable. */ 60*86d7f5d3SJohn Marino #define BMAGIC 0415 /* Used by a b.out object. */ 61*86d7f5d3SJohn Marino 62*86d7f5d3SJohn Marino /* This indicates a demand-paged executable with the header in the text. 63*86d7f5d3SJohn Marino It is used by 386BSD (and variants) and Linux, at least. */ 64*86d7f5d3SJohn Marino #ifndef QMAGIC 65*86d7f5d3SJohn Marino #define QMAGIC 0314 66*86d7f5d3SJohn Marino #endif 67*86d7f5d3SJohn Marino # ifndef N_BADMAG 68*86d7f5d3SJohn Marino # define N_BADMAG(x) (N_MAGIC(x) != OMAGIC \ 69*86d7f5d3SJohn Marino && N_MAGIC(x) != NMAGIC \ 70*86d7f5d3SJohn Marino && N_MAGIC(x) != ZMAGIC \ 71*86d7f5d3SJohn Marino && N_MAGIC(x) != QMAGIC) 72*86d7f5d3SJohn Marino # endif /* N_BADMAG */ 73*86d7f5d3SJohn Marino #endif 74*86d7f5d3SJohn Marino 75*86d7f5d3SJohn Marino #endif 76*86d7f5d3SJohn Marino 77*86d7f5d3SJohn Marino #ifdef QMAGIC 78*86d7f5d3SJohn Marino #define N_IS_QMAGIC(x) (N_MAGIC (x) == QMAGIC) 79*86d7f5d3SJohn Marino #else 80*86d7f5d3SJohn Marino #define N_IS_QMAGIC(x) (0) 81*86d7f5d3SJohn Marino #endif 82*86d7f5d3SJohn Marino 83*86d7f5d3SJohn Marino /* The difference between TARGET_PAGE_SIZE and N_SEGSIZE is that TARGET_PAGE_SIZE is 84*86d7f5d3SJohn Marino the finest granularity at which you can page something, thus it 85*86d7f5d3SJohn Marino controls the padding (if any) before the text segment of a ZMAGIC 86*86d7f5d3SJohn Marino file. N_SEGSIZE is the resolution at which things can be marked as 87*86d7f5d3SJohn Marino read-only versus read/write, so it controls the padding between the 88*86d7f5d3SJohn Marino text segment and the data segment (in memory; on disk the padding 89*86d7f5d3SJohn Marino between them is TARGET_PAGE_SIZE). TARGET_PAGE_SIZE and N_SEGSIZE are the same 90*86d7f5d3SJohn Marino for most machines, but different for sun3. */ 91*86d7f5d3SJohn Marino 92*86d7f5d3SJohn Marino /* By default, segment size is constant. But some machines override this 93*86d7f5d3SJohn Marino to be a function of the a.out header (e.g. machine type). */ 94*86d7f5d3SJohn Marino 95*86d7f5d3SJohn Marino #ifndef N_SEGSIZE 96*86d7f5d3SJohn Marino #define N_SEGSIZE(x) SEGMENT_SIZE 97*86d7f5d3SJohn Marino #endif 98*86d7f5d3SJohn Marino 99*86d7f5d3SJohn Marino /* Virtual memory address of the text section. 100*86d7f5d3SJohn Marino This is getting very complicated. A good reason to discard a.out format 101*86d7f5d3SJohn Marino for something that specifies these fields explicitly. But til then... 102*86d7f5d3SJohn Marino 103*86d7f5d3SJohn Marino * OMAGIC and NMAGIC files: 104*86d7f5d3SJohn Marino (object files: text for "relocatable addr 0" right after the header) 105*86d7f5d3SJohn Marino start at 0, offset is EXEC_BYTES_SIZE, size as stated. 106*86d7f5d3SJohn Marino * The text address, offset, and size of ZMAGIC files depend 107*86d7f5d3SJohn Marino on the entry point of the file: 108*86d7f5d3SJohn Marino * entry point below TEXT_START_ADDR: 109*86d7f5d3SJohn Marino (hack for SunOS shared libraries) 110*86d7f5d3SJohn Marino start at 0, offset is 0, size as stated. 111*86d7f5d3SJohn Marino * If N_HEADER_IN_TEXT(x) is true (which defaults to being the 112*86d7f5d3SJohn Marino case when the entry point is EXEC_BYTES_SIZE or further into a page): 113*86d7f5d3SJohn Marino no padding is needed; text can start after exec header. Sun 114*86d7f5d3SJohn Marino considers the text segment of such files to include the exec header; 115*86d7f5d3SJohn Marino for BFD's purposes, we don't, which makes more work for us. 116*86d7f5d3SJohn Marino start at TEXT_START_ADDR + EXEC_BYTES_SIZE, offset is EXEC_BYTES_SIZE, 117*86d7f5d3SJohn Marino size as stated minus EXEC_BYTES_SIZE. 118*86d7f5d3SJohn Marino * If N_HEADER_IN_TEXT(x) is false (which defaults to being the case when 119*86d7f5d3SJohn Marino the entry point is less than EXEC_BYTES_SIZE into a page (e.g. page 120*86d7f5d3SJohn Marino aligned)): (padding is needed so that text can start at a page boundary) 121*86d7f5d3SJohn Marino start at TEXT_START_ADDR, offset TARGET_PAGE_SIZE, size as stated. 122*86d7f5d3SJohn Marino 123*86d7f5d3SJohn Marino Specific configurations may want to hardwire N_HEADER_IN_TEXT, 124*86d7f5d3SJohn Marino for efficiency or to allow people to play games with the entry point. 125*86d7f5d3SJohn Marino In that case, you would #define N_HEADER_IN_TEXT(x) as 1 for sunos, 126*86d7f5d3SJohn Marino and as 0 for most other hosts (Sony News, Vax Ultrix, etc). 127*86d7f5d3SJohn Marino (Do this in the appropriate bfd target file.) 128*86d7f5d3SJohn Marino (The default is a heuristic that will break if people try changing 129*86d7f5d3SJohn Marino the entry point, perhaps with the ld -e flag.) 130*86d7f5d3SJohn Marino 131*86d7f5d3SJohn Marino * QMAGIC is always like a ZMAGIC for which N_HEADER_IN_TEXT is true, 132*86d7f5d3SJohn Marino and for which the starting address is TARGET_PAGE_SIZE (or should this be 133*86d7f5d3SJohn Marino SEGMENT_SIZE?) (TEXT_START_ADDR only applies to ZMAGIC, not to QMAGIC). */ 134*86d7f5d3SJohn Marino 135*86d7f5d3SJohn Marino /* This macro is only relevant for ZMAGIC files; QMAGIC always has the header 136*86d7f5d3SJohn Marino in the text. */ 137*86d7f5d3SJohn Marino #ifndef N_HEADER_IN_TEXT 138*86d7f5d3SJohn Marino #define N_HEADER_IN_TEXT(x) \ 139*86d7f5d3SJohn Marino (((x).a_entry & (TARGET_PAGE_SIZE-1)) >= EXEC_BYTES_SIZE) 140*86d7f5d3SJohn Marino #endif 141*86d7f5d3SJohn Marino 142*86d7f5d3SJohn Marino /* Sun shared libraries, not linux. This macro is only relevant for ZMAGIC 143*86d7f5d3SJohn Marino files. */ 144*86d7f5d3SJohn Marino #ifndef N_SHARED_LIB 145*86d7f5d3SJohn Marino #define N_SHARED_LIB(x) (0) 146*86d7f5d3SJohn Marino #endif 147*86d7f5d3SJohn Marino 148*86d7f5d3SJohn Marino /* Returning 0 not TEXT_START_ADDR for OMAGIC and NMAGIC is based on 149*86d7f5d3SJohn Marino the assumption that we are dealing with a .o file, not an 150*86d7f5d3SJohn Marino executable. This is necessary for OMAGIC (but means we don't work 151*86d7f5d3SJohn Marino right on the output from ld -N); more questionable for NMAGIC. */ 152*86d7f5d3SJohn Marino 153*86d7f5d3SJohn Marino #ifndef N_TXTADDR 154*86d7f5d3SJohn Marino #define N_TXTADDR(x) \ 155*86d7f5d3SJohn Marino (/* The address of a QMAGIC file is always one page in, \ 156*86d7f5d3SJohn Marino with the header in the text. */ \ 157*86d7f5d3SJohn Marino N_IS_QMAGIC (x) \ 158*86d7f5d3SJohn Marino ? (bfd_vma) TARGET_PAGE_SIZE + EXEC_BYTES_SIZE \ 159*86d7f5d3SJohn Marino : (N_MAGIC (x) != ZMAGIC \ 160*86d7f5d3SJohn Marino ? (bfd_vma) 0 /* Object file or NMAGIC. */ \ 161*86d7f5d3SJohn Marino : (N_SHARED_LIB (x) \ 162*86d7f5d3SJohn Marino ? (bfd_vma) 0 \ 163*86d7f5d3SJohn Marino : (N_HEADER_IN_TEXT (x) \ 164*86d7f5d3SJohn Marino ? (bfd_vma) TEXT_START_ADDR + EXEC_BYTES_SIZE \ 165*86d7f5d3SJohn Marino : (bfd_vma) TEXT_START_ADDR)))) 166*86d7f5d3SJohn Marino #endif 167*86d7f5d3SJohn Marino 168*86d7f5d3SJohn Marino /* If N_HEADER_IN_TEXT is not true for ZMAGIC, there is some padding 169*86d7f5d3SJohn Marino to make the text segment start at a certain boundary. For most 170*86d7f5d3SJohn Marino systems, this boundary is TARGET_PAGE_SIZE. But for Linux, in the 171*86d7f5d3SJohn Marino time-honored tradition of crazy ZMAGIC hacks, it is 1024 which is 172*86d7f5d3SJohn Marino not what TARGET_PAGE_SIZE needs to be for QMAGIC. */ 173*86d7f5d3SJohn Marino 174*86d7f5d3SJohn Marino #ifndef ZMAGIC_DISK_BLOCK_SIZE 175*86d7f5d3SJohn Marino #define ZMAGIC_DISK_BLOCK_SIZE TARGET_PAGE_SIZE 176*86d7f5d3SJohn Marino #endif 177*86d7f5d3SJohn Marino 178*86d7f5d3SJohn Marino #define N_DISK_BLOCK_SIZE(x) \ 179*86d7f5d3SJohn Marino (N_MAGIC(x) == ZMAGIC ? ZMAGIC_DISK_BLOCK_SIZE : TARGET_PAGE_SIZE) 180*86d7f5d3SJohn Marino 181*86d7f5d3SJohn Marino /* Offset in an a.out of the start of the text section. */ 182*86d7f5d3SJohn Marino #ifndef N_TXTOFF 183*86d7f5d3SJohn Marino #define N_TXTOFF(x) \ 184*86d7f5d3SJohn Marino (/* For {O,N,Q}MAGIC, no padding. */ \ 185*86d7f5d3SJohn Marino N_MAGIC (x) != ZMAGIC \ 186*86d7f5d3SJohn Marino ? EXEC_BYTES_SIZE \ 187*86d7f5d3SJohn Marino : (N_SHARED_LIB (x) \ 188*86d7f5d3SJohn Marino ? 0 \ 189*86d7f5d3SJohn Marino : (N_HEADER_IN_TEXT (x) \ 190*86d7f5d3SJohn Marino ? EXEC_BYTES_SIZE /* No padding. */ \ 191*86d7f5d3SJohn Marino : ZMAGIC_DISK_BLOCK_SIZE /* A page of padding. */))) 192*86d7f5d3SJohn Marino #endif 193*86d7f5d3SJohn Marino /* Size of the text section. It's always as stated, except that we 194*86d7f5d3SJohn Marino offset it to `undo' the adjustment to N_TXTADDR and N_TXTOFF 195*86d7f5d3SJohn Marino for ZMAGIC files that nominally include the exec header 196*86d7f5d3SJohn Marino as part of the first page of text. (BFD doesn't consider the 197*86d7f5d3SJohn Marino exec header to be part of the text segment.) */ 198*86d7f5d3SJohn Marino #ifndef N_TXTSIZE 199*86d7f5d3SJohn Marino #define N_TXTSIZE(x) \ 200*86d7f5d3SJohn Marino (/* For QMAGIC, we don't consider the header part of the text section. */\ 201*86d7f5d3SJohn Marino N_IS_QMAGIC (x) \ 202*86d7f5d3SJohn Marino ? (x).a_text - EXEC_BYTES_SIZE \ 203*86d7f5d3SJohn Marino : ((N_MAGIC (x) != ZMAGIC || N_SHARED_LIB (x)) \ 204*86d7f5d3SJohn Marino ? (x).a_text \ 205*86d7f5d3SJohn Marino : (N_HEADER_IN_TEXT (x) \ 206*86d7f5d3SJohn Marino ? (x).a_text - EXEC_BYTES_SIZE /* No padding. */ \ 207*86d7f5d3SJohn Marino : (x).a_text /* A page of padding. */ ))) 208*86d7f5d3SJohn Marino #endif 209*86d7f5d3SJohn Marino /* The address of the data segment in virtual memory. 210*86d7f5d3SJohn Marino It is the text segment address, plus text segment size, rounded 211*86d7f5d3SJohn Marino up to a N_SEGSIZE boundary for pure or pageable files. */ 212*86d7f5d3SJohn Marino #ifndef N_DATADDR 213*86d7f5d3SJohn Marino #define N_DATADDR(x) \ 214*86d7f5d3SJohn Marino (N_MAGIC (x) == OMAGIC \ 215*86d7f5d3SJohn Marino ? (N_TXTADDR (x) + N_TXTSIZE (x)) \ 216*86d7f5d3SJohn Marino : (N_SEGSIZE (x) + ((N_TXTADDR (x) + N_TXTSIZE (x) - 1) \ 217*86d7f5d3SJohn Marino & ~ (bfd_vma) (N_SEGSIZE (x) - 1)))) 218*86d7f5d3SJohn Marino #endif 219*86d7f5d3SJohn Marino /* The address of the BSS segment -- immediately after the data segment. */ 220*86d7f5d3SJohn Marino 221*86d7f5d3SJohn Marino #define N_BSSADDR(x) (N_DATADDR (x) + (x).a_data) 222*86d7f5d3SJohn Marino 223*86d7f5d3SJohn Marino /* Offsets of the various portions of the file after the text segment. */ 224*86d7f5d3SJohn Marino 225*86d7f5d3SJohn Marino /* For {Q,Z}MAGIC, there is padding to make the data segment start on 226*86d7f5d3SJohn Marino a page boundary. Most of the time the a_text field (and thus 227*86d7f5d3SJohn Marino N_TXTSIZE) already contains this padding. It is possible that for 228*86d7f5d3SJohn Marino BSDI and/or 386BSD it sometimes doesn't contain the padding, and 229*86d7f5d3SJohn Marino perhaps we should be adding it here. But this seems kind of 230*86d7f5d3SJohn Marino questionable and probably should be BSDI/386BSD-specific if we do 231*86d7f5d3SJohn Marino do it. 232*86d7f5d3SJohn Marino 233*86d7f5d3SJohn Marino For NMAGIC (at least for hp300 BSD, probably others), there is 234*86d7f5d3SJohn Marino padding in memory only, not on disk, so we must *not* ever pad here 235*86d7f5d3SJohn Marino for NMAGIC. */ 236*86d7f5d3SJohn Marino 237*86d7f5d3SJohn Marino #ifndef N_DATOFF 238*86d7f5d3SJohn Marino #define N_DATOFF(x) (N_TXTOFF (x) + N_TXTSIZE (x)) 239*86d7f5d3SJohn Marino #endif 240*86d7f5d3SJohn Marino #ifndef N_TRELOFF 241*86d7f5d3SJohn Marino #define N_TRELOFF(x) (N_DATOFF (x) + (x).a_data) 242*86d7f5d3SJohn Marino #endif 243*86d7f5d3SJohn Marino #ifndef N_DRELOFF 244*86d7f5d3SJohn Marino #define N_DRELOFF(x) (N_TRELOFF (x) + (x).a_trsize) 245*86d7f5d3SJohn Marino #endif 246*86d7f5d3SJohn Marino #ifndef N_SYMOFF 247*86d7f5d3SJohn Marino #define N_SYMOFF(x) (N_DRELOFF (x) + (x).a_drsize) 248*86d7f5d3SJohn Marino #endif 249*86d7f5d3SJohn Marino #ifndef N_STROFF 250*86d7f5d3SJohn Marino #define N_STROFF(x) (N_SYMOFF (x) + (x).a_syms) 251*86d7f5d3SJohn Marino #endif 252*86d7f5d3SJohn Marino 253*86d7f5d3SJohn Marino /* Symbols */ 254*86d7f5d3SJohn Marino #ifndef external_nlist 255*86d7f5d3SJohn Marino struct external_nlist 256*86d7f5d3SJohn Marino { 257*86d7f5d3SJohn Marino bfd_byte e_strx[BYTES_IN_WORD]; /* Index into string table of name. */ 258*86d7f5d3SJohn Marino bfd_byte e_type[1]; /* Type of symbol. */ 259*86d7f5d3SJohn Marino bfd_byte e_other[1]; /* Misc info (usually empty). */ 260*86d7f5d3SJohn Marino bfd_byte e_desc[2]; /* Description field. */ 261*86d7f5d3SJohn Marino bfd_byte e_value[BYTES_IN_WORD]; /* Value of symbol. */ 262*86d7f5d3SJohn Marino }; 263*86d7f5d3SJohn Marino #define EXTERNAL_NLIST_SIZE (BYTES_IN_WORD+4+BYTES_IN_WORD) 264*86d7f5d3SJohn Marino #endif 265*86d7f5d3SJohn Marino 266*86d7f5d3SJohn Marino struct internal_nlist 267*86d7f5d3SJohn Marino { 268*86d7f5d3SJohn Marino unsigned long n_strx; /* Index into string table of name. */ 269*86d7f5d3SJohn Marino unsigned char n_type; /* Type of symbol. */ 270*86d7f5d3SJohn Marino unsigned char n_other; /* Misc info (usually empty). */ 271*86d7f5d3SJohn Marino unsigned short n_desc; /* Description field. */ 272*86d7f5d3SJohn Marino bfd_vma n_value; /* Value of symbol. */ 273*86d7f5d3SJohn Marino }; 274*86d7f5d3SJohn Marino 275*86d7f5d3SJohn Marino /* The n_type field is the symbol type, containing: */ 276*86d7f5d3SJohn Marino 277*86d7f5d3SJohn Marino #define N_UNDF 0 /* Undefined symbol. */ 278*86d7f5d3SJohn Marino #define N_ABS 2 /* Absolute symbol -- defined at particular addr. */ 279*86d7f5d3SJohn Marino #define N_TEXT 4 /* Text sym -- defined at offset in text seg. */ 280*86d7f5d3SJohn Marino #define N_DATA 6 /* Data sym -- defined at offset in data seg. */ 281*86d7f5d3SJohn Marino #define N_BSS 8 /* BSS sym -- defined at offset in zero'd seg. */ 282*86d7f5d3SJohn Marino #define N_COMM 0x12 /* Common symbol (visible after shared lib dynlink). */ 283*86d7f5d3SJohn Marino #define N_FN 0x1f /* File name of .o file. */ 284*86d7f5d3SJohn Marino #define N_FN_SEQ 0x0C /* N_FN from Sequent compilers (sigh). */ 285*86d7f5d3SJohn Marino /* Note: N_EXT can only be usefully OR-ed with N_UNDF, N_ABS, N_TEXT, 286*86d7f5d3SJohn Marino N_DATA, or N_BSS. When the low-order bit of other types is set, 287*86d7f5d3SJohn Marino (e.g. N_WARNING versus N_FN), they are two different types. */ 288*86d7f5d3SJohn Marino #define N_EXT 1 /* External symbol (as opposed to local-to-this-file). */ 289*86d7f5d3SJohn Marino #define N_TYPE 0x1e 290*86d7f5d3SJohn Marino #define N_STAB 0xe0 /* If any of these bits are on, it's a debug symbol. */ 291*86d7f5d3SJohn Marino 292*86d7f5d3SJohn Marino #define N_INDR 0x0a 293*86d7f5d3SJohn Marino 294*86d7f5d3SJohn Marino /* The following symbols refer to set elements. 295*86d7f5d3SJohn Marino All the N_SET[ATDB] symbols with the same name form one set. 296*86d7f5d3SJohn Marino Space is allocated for the set in the text section, and each set 297*86d7f5d3SJohn Marino elements value is stored into one word of the space. 298*86d7f5d3SJohn Marino The first word of the space is the length of the set (number of elements). 299*86d7f5d3SJohn Marino 300*86d7f5d3SJohn Marino The address of the set is made into an N_SETV symbol 301*86d7f5d3SJohn Marino whose name is the same as the name of the set. 302*86d7f5d3SJohn Marino This symbol acts like a N_DATA global symbol 303*86d7f5d3SJohn Marino in that it can satisfy undefined external references. */ 304*86d7f5d3SJohn Marino 305*86d7f5d3SJohn Marino /* These appear as input to LD, in a .o file. */ 306*86d7f5d3SJohn Marino #define N_SETA 0x14 /* Absolute set element symbol. */ 307*86d7f5d3SJohn Marino #define N_SETT 0x16 /* Text set element symbol. */ 308*86d7f5d3SJohn Marino #define N_SETD 0x18 /* Data set element symbol. */ 309*86d7f5d3SJohn Marino #define N_SETB 0x1A /* Bss set element symbol. */ 310*86d7f5d3SJohn Marino 311*86d7f5d3SJohn Marino /* This is output from LD. */ 312*86d7f5d3SJohn Marino #define N_SETV 0x1C /* Pointer to set vector in data area. */ 313*86d7f5d3SJohn Marino 314*86d7f5d3SJohn Marino /* Warning symbol. The text gives a warning message, the next symbol 315*86d7f5d3SJohn Marino in the table will be undefined. When the symbol is referenced, the 316*86d7f5d3SJohn Marino message is printed. */ 317*86d7f5d3SJohn Marino 318*86d7f5d3SJohn Marino #define N_WARNING 0x1e 319*86d7f5d3SJohn Marino 320*86d7f5d3SJohn Marino /* Weak symbols. These are a GNU extension to the a.out format. The 321*86d7f5d3SJohn Marino semantics are those of ELF weak symbols. Weak symbols are always 322*86d7f5d3SJohn Marino externally visible. The N_WEAK? values are squeezed into the 323*86d7f5d3SJohn Marino available slots. The value of a N_WEAKU symbol is 0. The values 324*86d7f5d3SJohn Marino of the other types are the definitions. */ 325*86d7f5d3SJohn Marino #define N_WEAKU 0x0d /* Weak undefined symbol. */ 326*86d7f5d3SJohn Marino #define N_WEAKA 0x0e /* Weak absolute symbol. */ 327*86d7f5d3SJohn Marino #define N_WEAKT 0x0f /* Weak text symbol. */ 328*86d7f5d3SJohn Marino #define N_WEAKD 0x10 /* Weak data symbol. */ 329*86d7f5d3SJohn Marino #define N_WEAKB 0x11 /* Weak bss symbol. */ 330*86d7f5d3SJohn Marino 331*86d7f5d3SJohn Marino /* Relocations 332*86d7f5d3SJohn Marino 333*86d7f5d3SJohn Marino There are two types of relocation flavours for a.out systems, 334*86d7f5d3SJohn Marino standard and extended. The standard form is used on systems where the 335*86d7f5d3SJohn Marino instruction has room for all the bits of an offset to the operand, whilst 336*86d7f5d3SJohn Marino the extended form is used when an address operand has to be split over n 337*86d7f5d3SJohn Marino instructions. Eg, on the 68k, each move instruction can reference 338*86d7f5d3SJohn Marino the target with a displacement of 16 or 32 bits. On the sparc, move 339*86d7f5d3SJohn Marino instructions use an offset of 14 bits, so the offset is stored in 340*86d7f5d3SJohn Marino the reloc field, and the data in the section is ignored. */ 341*86d7f5d3SJohn Marino 342*86d7f5d3SJohn Marino /* This structure describes a single relocation to be performed. 343*86d7f5d3SJohn Marino The text-relocation section of the file is a vector of these structures, 344*86d7f5d3SJohn Marino all of which apply to the text section. 345*86d7f5d3SJohn Marino Likewise, the data-relocation section applies to the data section. */ 346*86d7f5d3SJohn Marino 347*86d7f5d3SJohn Marino struct reloc_std_external 348*86d7f5d3SJohn Marino { 349*86d7f5d3SJohn Marino bfd_byte r_address[BYTES_IN_WORD]; /* Offset of of data to relocate. */ 350*86d7f5d3SJohn Marino bfd_byte r_index[3]; /* Symbol table index of symbol. */ 351*86d7f5d3SJohn Marino bfd_byte r_type[1]; /* Relocation type. */ 352*86d7f5d3SJohn Marino }; 353*86d7f5d3SJohn Marino 354*86d7f5d3SJohn Marino #define RELOC_STD_BITS_PCREL_BIG ((unsigned int) 0x80) 355*86d7f5d3SJohn Marino #define RELOC_STD_BITS_PCREL_LITTLE ((unsigned int) 0x01) 356*86d7f5d3SJohn Marino 357*86d7f5d3SJohn Marino #define RELOC_STD_BITS_LENGTH_BIG ((unsigned int) 0x60) 358*86d7f5d3SJohn Marino #define RELOC_STD_BITS_LENGTH_SH_BIG 5 359*86d7f5d3SJohn Marino #define RELOC_STD_BITS_LENGTH_LITTLE ((unsigned int) 0x06) 360*86d7f5d3SJohn Marino #define RELOC_STD_BITS_LENGTH_SH_LITTLE 1 361*86d7f5d3SJohn Marino 362*86d7f5d3SJohn Marino #define RELOC_STD_BITS_EXTERN_BIG ((unsigned int) 0x10) 363*86d7f5d3SJohn Marino #define RELOC_STD_BITS_EXTERN_LITTLE ((unsigned int) 0x08) 364*86d7f5d3SJohn Marino 365*86d7f5d3SJohn Marino #define RELOC_STD_BITS_BASEREL_BIG ((unsigned int) 0x08) 366*86d7f5d3SJohn Marino #define RELOC_STD_BITS_BASEREL_LITTLE ((unsigned int) 0x10) 367*86d7f5d3SJohn Marino 368*86d7f5d3SJohn Marino #define RELOC_STD_BITS_JMPTABLE_BIG ((unsigned int) 0x04) 369*86d7f5d3SJohn Marino #define RELOC_STD_BITS_JMPTABLE_LITTLE ((unsigned int) 0x20) 370*86d7f5d3SJohn Marino 371*86d7f5d3SJohn Marino #define RELOC_STD_BITS_RELATIVE_BIG ((unsigned int) 0x02) 372*86d7f5d3SJohn Marino #define RELOC_STD_BITS_RELATIVE_LITTLE ((unsigned int) 0x40) 373*86d7f5d3SJohn Marino 374*86d7f5d3SJohn Marino #define RELOC_STD_SIZE (BYTES_IN_WORD + 3 + 1) /* Bytes per relocation entry. */ 375*86d7f5d3SJohn Marino 376*86d7f5d3SJohn Marino struct reloc_std_internal 377*86d7f5d3SJohn Marino { 378*86d7f5d3SJohn Marino bfd_vma r_address; /* Address (within segment) to be relocated. */ 379*86d7f5d3SJohn Marino /* The meaning of r_symbolnum depends on r_extern. */ 380*86d7f5d3SJohn Marino unsigned int r_symbolnum:24; 381*86d7f5d3SJohn Marino /* Nonzero means value is a pc-relative offset 382*86d7f5d3SJohn Marino and it should be relocated for changes in its own address 383*86d7f5d3SJohn Marino as well as for changes in the symbol or section specified. */ 384*86d7f5d3SJohn Marino unsigned int r_pcrel:1; 385*86d7f5d3SJohn Marino /* Length (as exponent of 2) of the field to be relocated. 386*86d7f5d3SJohn Marino Thus, a value of 2 indicates 1<<2 bytes. */ 387*86d7f5d3SJohn Marino unsigned int r_length:2; 388*86d7f5d3SJohn Marino /* 1 => relocate with value of symbol. 389*86d7f5d3SJohn Marino r_symbolnum is the index of the symbol 390*86d7f5d3SJohn Marino in files the symbol table. 391*86d7f5d3SJohn Marino 0 => relocate with the address of a segment. 392*86d7f5d3SJohn Marino r_symbolnum is N_TEXT, N_DATA, N_BSS or N_ABS 393*86d7f5d3SJohn Marino (the N_EXT bit may be set also, but signifies nothing). */ 394*86d7f5d3SJohn Marino unsigned int r_extern:1; 395*86d7f5d3SJohn Marino /* The next three bits are for SunOS shared libraries, and seem to 396*86d7f5d3SJohn Marino be undocumented. */ 397*86d7f5d3SJohn Marino unsigned int r_baserel:1; /* Linkage table relative. */ 398*86d7f5d3SJohn Marino unsigned int r_jmptable:1; /* pc-relative to jump table. */ 399*86d7f5d3SJohn Marino unsigned int r_relative:1; /* "relative relocation". */ 400*86d7f5d3SJohn Marino /* unused */ 401*86d7f5d3SJohn Marino unsigned int r_pad:1; /* Padding -- set to zero. */ 402*86d7f5d3SJohn Marino }; 403*86d7f5d3SJohn Marino 404*86d7f5d3SJohn Marino 405*86d7f5d3SJohn Marino /* EXTENDED RELOCS. */ 406*86d7f5d3SJohn Marino 407*86d7f5d3SJohn Marino struct reloc_ext_external 408*86d7f5d3SJohn Marino { 409*86d7f5d3SJohn Marino bfd_byte r_address[BYTES_IN_WORD]; /* Offset of of data to relocate. */ 410*86d7f5d3SJohn Marino bfd_byte r_index[3]; /* Symbol table index of symbol. */ 411*86d7f5d3SJohn Marino bfd_byte r_type[1]; /* Relocation type. */ 412*86d7f5d3SJohn Marino bfd_byte r_addend[BYTES_IN_WORD]; /* Datum addend. */ 413*86d7f5d3SJohn Marino }; 414*86d7f5d3SJohn Marino 415*86d7f5d3SJohn Marino #ifndef RELOC_EXT_BITS_EXTERN_BIG 416*86d7f5d3SJohn Marino #define RELOC_EXT_BITS_EXTERN_BIG ((unsigned int) 0x80) 417*86d7f5d3SJohn Marino #endif 418*86d7f5d3SJohn Marino 419*86d7f5d3SJohn Marino #ifndef RELOC_EXT_BITS_EXTERN_LITTLE 420*86d7f5d3SJohn Marino #define RELOC_EXT_BITS_EXTERN_LITTLE ((unsigned int) 0x01) 421*86d7f5d3SJohn Marino #endif 422*86d7f5d3SJohn Marino 423*86d7f5d3SJohn Marino #ifndef RELOC_EXT_BITS_TYPE_BIG 424*86d7f5d3SJohn Marino #define RELOC_EXT_BITS_TYPE_BIG ((unsigned int) 0x1F) 425*86d7f5d3SJohn Marino #endif 426*86d7f5d3SJohn Marino 427*86d7f5d3SJohn Marino #ifndef RELOC_EXT_BITS_TYPE_SH_BIG 428*86d7f5d3SJohn Marino #define RELOC_EXT_BITS_TYPE_SH_BIG 0 429*86d7f5d3SJohn Marino #endif 430*86d7f5d3SJohn Marino 431*86d7f5d3SJohn Marino #ifndef RELOC_EXT_BITS_TYPE_LITTLE 432*86d7f5d3SJohn Marino #define RELOC_EXT_BITS_TYPE_LITTLE ((unsigned int) 0xF8) 433*86d7f5d3SJohn Marino #endif 434*86d7f5d3SJohn Marino 435*86d7f5d3SJohn Marino #ifndef RELOC_EXT_BITS_TYPE_SH_LITTLE 436*86d7f5d3SJohn Marino #define RELOC_EXT_BITS_TYPE_SH_LITTLE 3 437*86d7f5d3SJohn Marino #endif 438*86d7f5d3SJohn Marino 439*86d7f5d3SJohn Marino /* Bytes per relocation entry. */ 440*86d7f5d3SJohn Marino #define RELOC_EXT_SIZE (BYTES_IN_WORD + 3 + 1 + BYTES_IN_WORD) 441*86d7f5d3SJohn Marino 442*86d7f5d3SJohn Marino enum reloc_type 443*86d7f5d3SJohn Marino { 444*86d7f5d3SJohn Marino /* Simple relocations. */ 445*86d7f5d3SJohn Marino RELOC_8, /* data[0:7] = addend + sv */ 446*86d7f5d3SJohn Marino RELOC_16, /* data[0:15] = addend + sv */ 447*86d7f5d3SJohn Marino RELOC_32, /* data[0:31] = addend + sv */ 448*86d7f5d3SJohn Marino /* PC-rel displacement. */ 449*86d7f5d3SJohn Marino RELOC_DISP8, /* data[0:7] = addend - pc + sv */ 450*86d7f5d3SJohn Marino RELOC_DISP16, /* data[0:15] = addend - pc + sv */ 451*86d7f5d3SJohn Marino RELOC_DISP32, /* data[0:31] = addend - pc + sv */ 452*86d7f5d3SJohn Marino /* Special. */ 453*86d7f5d3SJohn Marino RELOC_WDISP30, /* data[0:29] = (addend + sv - pc)>>2 */ 454*86d7f5d3SJohn Marino RELOC_WDISP22, /* data[0:21] = (addend + sv - pc)>>2 */ 455*86d7f5d3SJohn Marino RELOC_HI22, /* data[0:21] = (addend + sv)>>10 */ 456*86d7f5d3SJohn Marino RELOC_22, /* data[0:21] = (addend + sv) */ 457*86d7f5d3SJohn Marino RELOC_13, /* data[0:12] = (addend + sv) */ 458*86d7f5d3SJohn Marino RELOC_LO10, /* data[0:9] = (addend + sv) */ 459*86d7f5d3SJohn Marino RELOC_SFA_BASE, 460*86d7f5d3SJohn Marino RELOC_SFA_OFF13, 461*86d7f5d3SJohn Marino /* P.I.C. (base-relative). */ 462*86d7f5d3SJohn Marino RELOC_BASE10, /* Not sure - maybe we can do this the */ 463*86d7f5d3SJohn Marino RELOC_BASE13, /* right way now */ 464*86d7f5d3SJohn Marino RELOC_BASE22, 465*86d7f5d3SJohn Marino /* For some sort of pc-rel P.I.C. (?) */ 466*86d7f5d3SJohn Marino RELOC_PC10, 467*86d7f5d3SJohn Marino RELOC_PC22, 468*86d7f5d3SJohn Marino /* P.I.C. jump table. */ 469*86d7f5d3SJohn Marino RELOC_JMP_TBL, 470*86d7f5d3SJohn Marino /* Reputedly for shared libraries somehow. */ 471*86d7f5d3SJohn Marino RELOC_SEGOFF16, 472*86d7f5d3SJohn Marino RELOC_GLOB_DAT, 473*86d7f5d3SJohn Marino RELOC_JMP_SLOT, 474*86d7f5d3SJohn Marino RELOC_RELATIVE, 475*86d7f5d3SJohn Marino 476*86d7f5d3SJohn Marino RELOC_11, 477*86d7f5d3SJohn Marino RELOC_WDISP2_14, 478*86d7f5d3SJohn Marino RELOC_WDISP19, 479*86d7f5d3SJohn Marino RELOC_HHI22, /* data[0:21] = (addend + sv) >> 42 */ 480*86d7f5d3SJohn Marino RELOC_HLO10, /* data[0:9] = (addend + sv) >> 32 */ 481*86d7f5d3SJohn Marino 482*86d7f5d3SJohn Marino /* 29K relocation types. */ 483*86d7f5d3SJohn Marino RELOC_JUMPTARG, 484*86d7f5d3SJohn Marino RELOC_CONST, 485*86d7f5d3SJohn Marino RELOC_CONSTH, 486*86d7f5d3SJohn Marino 487*86d7f5d3SJohn Marino /* All the new ones I can think of, for sparc v9. */ 488*86d7f5d3SJohn Marino RELOC_64, /* data[0:63] = addend + sv */ 489*86d7f5d3SJohn Marino RELOC_DISP64, /* data[0:63] = addend - pc + sv */ 490*86d7f5d3SJohn Marino RELOC_WDISP21, /* data[0:20] = (addend + sv - pc)>>2 */ 491*86d7f5d3SJohn Marino RELOC_DISP21, /* data[0:20] = addend - pc + sv */ 492*86d7f5d3SJohn Marino RELOC_DISP14, /* data[0:13] = addend - pc + sv */ 493*86d7f5d3SJohn Marino /* Q . 494*86d7f5d3SJohn Marino What are the other ones, 495*86d7f5d3SJohn Marino Since this is a clean slate, can we throw away the ones we dont 496*86d7f5d3SJohn Marino understand ? Should we sort the values ? What about using a 497*86d7f5d3SJohn Marino microcode format like the 68k ? */ 498*86d7f5d3SJohn Marino NO_RELOC 499*86d7f5d3SJohn Marino }; 500*86d7f5d3SJohn Marino 501*86d7f5d3SJohn Marino 502*86d7f5d3SJohn Marino struct reloc_internal 503*86d7f5d3SJohn Marino { 504*86d7f5d3SJohn Marino bfd_vma r_address; /* Offset of of data to relocate. */ 505*86d7f5d3SJohn Marino long r_index; /* Symbol table index of symbol. */ 506*86d7f5d3SJohn Marino enum reloc_type r_type; /* Relocation type. */ 507*86d7f5d3SJohn Marino bfd_vma r_addend; /* Datum addend. */ 508*86d7f5d3SJohn Marino }; 509*86d7f5d3SJohn Marino 510*86d7f5d3SJohn Marino /* Q. 511*86d7f5d3SJohn Marino Should the length of the string table be 4 bytes or 8 bytes ? 512*86d7f5d3SJohn Marino 513*86d7f5d3SJohn Marino Q. 514*86d7f5d3SJohn Marino What about archive indexes ? */ 515*86d7f5d3SJohn Marino 516*86d7f5d3SJohn Marino #endif /* __A_OUT_64_H__ */ 517