12159047fSniklas /* coff object file format 2b55d4692Sfgsch Copyright 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 3c074d1c9Sdrahn 1999, 2000, 2002, 2003 4b305b0f1Sespie Free Software Foundation, Inc. 52159047fSniklas 62159047fSniklas This file is part of GAS. 72159047fSniklas 82159047fSniklas GAS is free software; you can redistribute it and/or modify 92159047fSniklas it under the terms of the GNU General Public License as published by 102159047fSniklas the Free Software Foundation; either version 2, or (at your option) 112159047fSniklas any later version. 122159047fSniklas 132159047fSniklas GAS is distributed in the hope that it will be useful, 142159047fSniklas but WITHOUT ANY WARRANTY; without even the implied warranty of 152159047fSniklas MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 162159047fSniklas GNU General Public License for more details. 172159047fSniklas 182159047fSniklas You should have received a copy of the GNU General Public License 19191aa565Sniklas along with GAS; see the file COPYING. If not, write to the Free 20191aa565Sniklas Software Foundation, 59 Temple Place - Suite 330, Boston, MA 21191aa565Sniklas 02111-1307, USA. */ 222159047fSniklas 232159047fSniklas #ifndef OBJ_FORMAT_H 242159047fSniklas #define OBJ_FORMAT_H 252159047fSniklas 262159047fSniklas #define OBJ_COFF 1 272159047fSniklas 282159047fSniklas #ifndef BFD_ASSEMBLER 292159047fSniklas 302159047fSniklas #define WORKING_DOT_WORD 312159047fSniklas #define WARN_SIGNED_OVERFLOW_WORD 322159047fSniklas #define OBJ_COFF_OMIT_OPTIONAL_HEADER 332159047fSniklas #define BFD_HEADERS 342159047fSniklas #define BFD 352159047fSniklas 362159047fSniklas #endif 372159047fSniklas 382159047fSniklas #include "targ-cpu.h" 392159047fSniklas 402159047fSniklas #include "bfd.h" 412159047fSniklas 422159047fSniklas /* This internal_lineno crap is to stop namespace pollution from the 432159047fSniklas bfd internal coff headerfile. */ 442159047fSniklas #define internal_lineno bfd_internal_lineno 452159047fSniklas #include "coff/internal.h" 462159047fSniklas #undef internal_lineno 472159047fSniklas 482159047fSniklas /* CPU-specific setup: */ 492159047fSniklas 502159047fSniklas #ifdef TC_ARM 512159047fSniklas #include "coff/arm.h" 522159047fSniklas #ifndef TARGET_FORMAT 532159047fSniklas #define TARGET_FORMAT "coff-arm" 542159047fSniklas #endif 552159047fSniklas #endif 562159047fSniklas 572159047fSniklas #ifdef TC_PPC 582159047fSniklas #ifdef TE_PE 592159047fSniklas #include "coff/powerpc.h" 602159047fSniklas #else 612159047fSniklas #include "coff/rs6000.h" 622159047fSniklas #endif 632159047fSniklas #endif 642159047fSniklas 652159047fSniklas #ifdef TC_SPARC 662159047fSniklas #include "coff/sparc.h" 672159047fSniklas #endif 682159047fSniklas 692159047fSniklas #ifdef TC_I386 702159047fSniklas #include "coff/i386.h" 712159047fSniklas 722159047fSniklas #ifdef TE_PE 732159047fSniklas #define TARGET_FORMAT "pe-i386" 742159047fSniklas #endif 752159047fSniklas 762159047fSniklas #ifndef TARGET_FORMAT 772159047fSniklas #define TARGET_FORMAT "coff-i386" 782159047fSniklas #endif 792159047fSniklas #endif 802159047fSniklas 812159047fSniklas #ifdef TC_M68K 822159047fSniklas #include "coff/m68k.h" 832159047fSniklas #ifndef TARGET_FORMAT 842159047fSniklas #define TARGET_FORMAT "coff-m68k" 852159047fSniklas #endif 862159047fSniklas #endif 872159047fSniklas 882159047fSniklas #ifdef TC_A29K 892159047fSniklas #include "coff/a29k.h" 902159047fSniklas #define TARGET_FORMAT "coff-a29k-big" 912159047fSniklas #endif 922159047fSniklas 93c074d1c9Sdrahn #ifdef TC_OR32 94c074d1c9Sdrahn #include "coff/or32.h" 95c074d1c9Sdrahn #define TARGET_FORMAT "coff-or32-big" 96c074d1c9Sdrahn #endif 97c074d1c9Sdrahn 982159047fSniklas #ifdef TC_I960 992159047fSniklas #include "coff/i960.h" 1002159047fSniklas #define TARGET_FORMAT "coff-Intel-little" 1012159047fSniklas #endif 1022159047fSniklas 1032159047fSniklas #ifdef TC_Z8K 1042159047fSniklas #include "coff/z8k.h" 1052159047fSniklas #define TARGET_FORMAT "coff-z8k" 1062159047fSniklas #endif 1072159047fSniklas 1082159047fSniklas #ifdef TC_H8300 1092159047fSniklas #include "coff/h8300.h" 1102159047fSniklas #define TARGET_FORMAT "coff-h8300" 1112159047fSniklas #endif 1122159047fSniklas 1132159047fSniklas #ifdef TC_H8500 1142159047fSniklas #include "coff/h8500.h" 1152159047fSniklas #define TARGET_FORMAT "coff-h8500" 1162159047fSniklas #endif 1172159047fSniklas 1182159047fSniklas #ifdef TC_SH 119b305b0f1Sespie 120b305b0f1Sespie #ifdef TE_PE 121b305b0f1Sespie #define COFF_WITH_PE 122b305b0f1Sespie #endif 123b305b0f1Sespie 1242159047fSniklas #include "coff/sh.h" 125b305b0f1Sespie 126b305b0f1Sespie #ifdef TE_PE 127b305b0f1Sespie #define TARGET_FORMAT "pe-shl" 128b305b0f1Sespie #else 129c074d1c9Sdrahn 130b305b0f1Sespie #define TARGET_FORMAT \ 131c074d1c9Sdrahn (!target_big_endian \ 132b305b0f1Sespie ? (sh_small ? "coff-shl-small" : "coff-shl") \ 133b305b0f1Sespie : (sh_small ? "coff-sh-small" : "coff-sh")) 134c074d1c9Sdrahn 135b305b0f1Sespie #endif 136b305b0f1Sespie #endif 137b305b0f1Sespie 138b305b0f1Sespie #ifdef TC_MIPS 139b305b0f1Sespie #define COFF_WITH_PE 140b305b0f1Sespie #include "coff/mipspe.h" 141b305b0f1Sespie #undef TARGET_FORMAT 142b305b0f1Sespie #define TARGET_FORMAT "pe-mips" 1432159047fSniklas #endif 1442159047fSniklas 1452159047fSniklas #ifdef TC_M88K 1462159047fSniklas #include "coff/m88k.h" 1472159047fSniklas #define TARGET_FORMAT "coff-m88kbcs" 1482159047fSniklas #endif 1492159047fSniklas 1502159047fSniklas #ifdef TC_W65 1512159047fSniklas #include "coff/w65.h" 1522159047fSniklas #define TARGET_FORMAT "coff-w65" 1532159047fSniklas #endif 1542159047fSniklas 155b305b0f1Sespie #ifdef TC_TIC30 156b305b0f1Sespie #include "coff/tic30.h" 157b305b0f1Sespie #define TARGET_FORMAT "coff-tic30" 158b305b0f1Sespie #endif 159b305b0f1Sespie 160c074d1c9Sdrahn #ifdef TC_TIC4X 161c074d1c9Sdrahn #include "coff/tic4x.h" 162c074d1c9Sdrahn #define TARGET_FORMAT "coff2-tic4x" 163c074d1c9Sdrahn #endif 164c074d1c9Sdrahn 165b55d4692Sfgsch #ifdef TC_TIC54X 166b55d4692Sfgsch #include "coff/tic54x.h" 167b55d4692Sfgsch #define TARGET_FORMAT "coff1-c54x" 168b55d4692Sfgsch #endif 169b55d4692Sfgsch 170b305b0f1Sespie #ifdef TC_TIC80 171b305b0f1Sespie #include "coff/tic80.h" 172b305b0f1Sespie #define TARGET_FORMAT "coff-tic80" 173b305b0f1Sespie #define ALIGNMENT_IN_S_FLAGS 1 174b305b0f1Sespie #endif 175b305b0f1Sespie 176b305b0f1Sespie #ifdef TC_MCORE 177b305b0f1Sespie #include "coff/mcore.h" 178b305b0f1Sespie #ifndef TARGET_FORMAT 179b305b0f1Sespie #define TARGET_FORMAT "pe-mcore" 180b305b0f1Sespie #endif 181b305b0f1Sespie #endif 182b305b0f1Sespie 1832159047fSniklas /* Targets may also set this. Also, if BFD_ASSEMBLER is defined, this 1842159047fSniklas will already have been defined. */ 1852159047fSniklas #undef SYMBOLS_NEED_BACKPOINTERS 1862159047fSniklas #define SYMBOLS_NEED_BACKPOINTERS 1 1872159047fSniklas 1882159047fSniklas #ifndef OBJ_COFF_MAX_AUXENTRIES 1892159047fSniklas #define OBJ_COFF_MAX_AUXENTRIES 1 1902159047fSniklas #endif /* OBJ_COFF_MAX_AUXENTRIES */ 1912159047fSniklas 192b305b0f1Sespie extern void coff_obj_symbol_new_hook PARAMS ((symbolS *)); 193b305b0f1Sespie #define obj_symbol_new_hook coff_obj_symbol_new_hook 194b305b0f1Sespie 195b305b0f1Sespie extern void coff_obj_read_begin_hook PARAMS ((void)); 196b305b0f1Sespie #define obj_read_begin_hook coff_obj_read_begin_hook 197b305b0f1Sespie 198c074d1c9Sdrahn /* This file really contains two implementations of the COFF back end. 1992159047fSniklas They are in the process of being merged, but this is only a 2002159047fSniklas preliminary, mechanical merging. Many definitions that are 2012159047fSniklas identical between the two are still found in both versions. 2022159047fSniklas 2032159047fSniklas The first version, with BFD_ASSEMBLER defined, uses high-level BFD 2042159047fSniklas interfaces and data structures. The second version, with 2052159047fSniklas BFD_ASSEMBLER not defined, also uses BFD, but mostly for swapping 2062159047fSniklas data structures and for doing the actual I/O. The latter defines 2072159047fSniklas the preprocessor symbols BFD and BFD_HEADERS. Try not to let this 2082159047fSniklas confuse you. 2092159047fSniklas 2102159047fSniklas These two are in the process of being merged, and eventually the 2112159047fSniklas BFD_ASSEMBLER version should take over completely. Release timing 2122159047fSniklas issues and namespace problems convinced me to merge the two 2132159047fSniklas together in this fashion, a little sooner than I would have liked. 2142159047fSniklas The real merge should be much better done by the time the next 2152159047fSniklas release comes out. 2162159047fSniklas 2172159047fSniklas For now, the structure of this file is: 2182159047fSniklas <common> 2192159047fSniklas #ifdef BFD_ASSEMBLER 2202159047fSniklas <one version> 2212159047fSniklas #else 2222159047fSniklas <other version> 2232159047fSniklas #endif 2242159047fSniklas <common> 2252159047fSniklas Unfortunately, the common portions are very small at the moment, 2262159047fSniklas and many declarations or definitions are duplicated. The structure 2272159047fSniklas of obj-coff.c is similar. 2282159047fSniklas 2292159047fSniklas See doc/internals.texi for a brief discussion of the history, if 2302159047fSniklas you care. 2312159047fSniklas 232c074d1c9Sdrahn Ken Raeburn, 5 May 1994. */ 2332159047fSniklas 2342159047fSniklas #ifdef BFD_ASSEMBLER 2352159047fSniklas 2362159047fSniklas #include "bfd/libcoff.h" 2372159047fSniklas 2382159047fSniklas #define OUTPUT_FLAVOR bfd_target_coff_flavour 2392159047fSniklas 2402159047fSniklas /* SYMBOL TABLE */ 2412159047fSniklas 2422159047fSniklas /* Alter the field names, for now, until we've fixed up the other 2432159047fSniklas references to use the new name. */ 2442159047fSniklas #ifdef TC_I960 245b305b0f1Sespie #define TC_SYMFIELD_TYPE symbolS * 2462159047fSniklas #define sy_tc bal 2472159047fSniklas #endif 2482159047fSniklas 2492159047fSniklas #define OBJ_SYMFIELD_TYPE unsigned long 2502159047fSniklas #define sy_obj sy_flags 2512159047fSniklas 252c074d1c9Sdrahn /* We can't use the predefined section symbols in bfd/section.c, as 253c074d1c9Sdrahn COFF symbols have extra fields. See bfd/libcoff.h:coff_symbol_type. */ 254c074d1c9Sdrahn #ifndef obj_sec_sym_ok_for_reloc 255c074d1c9Sdrahn #define obj_sec_sym_ok_for_reloc(SEC) ((SEC)->owner != 0) 256c074d1c9Sdrahn #endif 257c074d1c9Sdrahn 258b305b0f1Sespie #define SYM_AUXENT(S) \ 259b305b0f1Sespie (&coffsymbol (symbol_get_bfdsym (S))->native[1].u.auxent) 260b305b0f1Sespie #define SYM_AUXINFO(S) \ 261b305b0f1Sespie (&coffsymbol (symbol_get_bfdsym (S))->native[1]) 2622159047fSniklas 2632159047fSniklas #define DO_NOT_STRIP 0 2642159047fSniklas 2652159047fSniklas extern void obj_coff_section PARAMS ((int)); 2662159047fSniklas 267c074d1c9Sdrahn /* The number of auxiliary entries. */ 268b305b0f1Sespie #define S_GET_NUMBER_AUXILIARY(s) \ 269b305b0f1Sespie (coffsymbol (symbol_get_bfdsym (s))->native->u.syment.n_numaux) 270c074d1c9Sdrahn /* The number of auxiliary entries. */ 2712159047fSniklas #define S_SET_NUMBER_AUXILIARY(s,v) (S_GET_NUMBER_AUXILIARY (s) = (v)) 2722159047fSniklas 2732159047fSniklas /* True if a symbol name is in the string table, i.e. its length is > 8. */ 2742159047fSniklas #define S_IS_STRING(s) (strlen(S_GET_NAME(s)) > 8 ? 1 : 0) 2752159047fSniklas 276b305b0f1Sespie extern int S_SET_DATA_TYPE PARAMS ((symbolS *, int)); 277b305b0f1Sespie extern int S_SET_STORAGE_CLASS PARAMS ((symbolS *, int)); 278b305b0f1Sespie extern int S_GET_STORAGE_CLASS PARAMS ((symbolS *)); 279b305b0f1Sespie extern void SA_SET_SYM_ENDNDX PARAMS ((symbolS *, symbolS *)); 2802159047fSniklas 281c074d1c9Sdrahn /* Auxiliary entry macros. SA_ stands for symbol auxiliary. */ 282c074d1c9Sdrahn /* Omit the tv related fields. */ 283c074d1c9Sdrahn /* Accessors. */ 2842159047fSniklas 2852159047fSniklas #define SA_GET_SYM_TAGNDX(s) (SYM_AUXENT (s)->x_sym.x_tagndx.l) 2862159047fSniklas #define SA_GET_SYM_LNNO(s) (SYM_AUXENT (s)->x_sym.x_misc.x_lnsz.x_lnno) 2872159047fSniklas #define SA_GET_SYM_SIZE(s) (SYM_AUXENT (s)->x_sym.x_misc.x_lnsz.x_size) 2882159047fSniklas #define SA_GET_SYM_FSIZE(s) (SYM_AUXENT (s)->x_sym.x_misc.x_fsize) 2892159047fSniklas #define SA_GET_SYM_LNNOPTR(s) (SYM_AUXENT (s)->x_sym.x_fcnary.x_fcn.x_lnnoptr) 2902159047fSniklas #define SA_GET_SYM_ENDNDX(s) (SYM_AUXENT (s)->x_sym.x_fcnary.x_fcn.x_endndx) 2912159047fSniklas #define SA_GET_SYM_DIMEN(s,i) (SYM_AUXENT (s)->x_sym.x_fcnary.x_ary.x_dimen[(i)]) 2922159047fSniklas #define SA_GET_FILE_FNAME(s) (SYM_AUXENT (s)->x_file.x_fname) 2932159047fSniklas #define SA_GET_SCN_SCNLEN(s) (SYM_AUXENT (s)->x_scn.x_scnlen) 2942159047fSniklas #define SA_GET_SCN_NRELOC(s) (SYM_AUXENT (s)->x_scn.x_nreloc) 2952159047fSniklas #define SA_GET_SCN_NLINNO(s) (SYM_AUXENT (s)->x_scn.x_nlinno) 2962159047fSniklas 2972159047fSniklas #define SA_SET_SYM_LNNO(s,v) (SYM_AUXENT (s)->x_sym.x_misc.x_lnsz.x_lnno=(v)) 2982159047fSniklas #define SA_SET_SYM_SIZE(s,v) (SYM_AUXENT (s)->x_sym.x_misc.x_lnsz.x_size=(v)) 2992159047fSniklas #define SA_SET_SYM_FSIZE(s,v) (SYM_AUXENT (s)->x_sym.x_misc.x_fsize=(v)) 3002159047fSniklas #define SA_SET_SYM_LNNOPTR(s,v) (SYM_AUXENT (s)->x_sym.x_fcnary.x_fcn.x_lnnoptr=(v)) 3012159047fSniklas #define SA_SET_SYM_DIMEN(s,i,v) (SYM_AUXENT (s)->x_sym.x_fcnary.x_ary.x_dimen[(i)]=(v)) 3022159047fSniklas #define SA_SET_FILE_FNAME(s,v) strncpy(SYM_AUXENT (s)->x_file.x_fname,(v),FILNMLEN) 3032159047fSniklas #define SA_SET_SCN_SCNLEN(s,v) (SYM_AUXENT (s)->x_scn.x_scnlen=(v)) 3042159047fSniklas #define SA_SET_SCN_NRELOC(s,v) (SYM_AUXENT (s)->x_scn.x_nreloc=(v)) 3052159047fSniklas #define SA_SET_SCN_NLINNO(s,v) (SYM_AUXENT (s)->x_scn.x_nlinno=(v)) 3062159047fSniklas 307c074d1c9Sdrahn /* Internal use only definitions. SF_ stands for symbol flags. 308c074d1c9Sdrahn 309c074d1c9Sdrahn These values can be assigned to sy_symbol.ost_flags field of a symbolS. 310c074d1c9Sdrahn 311c074d1c9Sdrahn You'll break i960 if you shift the SYSPROC bits anywhere else. for 312c074d1c9Sdrahn more on the balname/callname hack, see tc-i960.h. b.out is done 313c074d1c9Sdrahn differently. */ 3142159047fSniklas 3152159047fSniklas #define SF_I960_MASK (0x000001ff) /* Bits 0-8 are used by the i960 port. */ 3162159047fSniklas #define SF_SYSPROC (0x0000003f) /* bits 0-5 are used to store the sysproc number */ 3172159047fSniklas #define SF_IS_SYSPROC (0x00000040) /* bit 6 marks symbols that are sysprocs */ 3182159047fSniklas #define SF_BALNAME (0x00000080) /* bit 7 marks BALNAME symbols */ 3192159047fSniklas #define SF_CALLNAME (0x00000100) /* bit 8 marks CALLNAME symbols */ 3202159047fSniklas 3212159047fSniklas #define SF_NORMAL_MASK (0x0000ffff) /* bits 12-15 are general purpose. */ 3222159047fSniklas 3232159047fSniklas #define SF_STATICS (0x00001000) /* Mark the .text & all symbols */ 3242159047fSniklas #define SF_DEFINED (0x00002000) /* Symbol is defined in this file */ 3252159047fSniklas #define SF_STRING (0x00004000) /* Symbol name length > 8 */ 3262159047fSniklas #define SF_LOCAL (0x00008000) /* Symbol must not be emitted */ 3272159047fSniklas 3282159047fSniklas #define SF_DEBUG_MASK (0xffff0000) /* bits 16-31 are debug info */ 3292159047fSniklas 3302159047fSniklas #define SF_FUNCTION (0x00010000) /* The symbol is a function */ 3312159047fSniklas #define SF_PROCESS (0x00020000) /* Process symbol before write */ 3322159047fSniklas #define SF_TAGGED (0x00040000) /* Is associated with a tag */ 3332159047fSniklas #define SF_TAG (0x00080000) /* Is a tag */ 3342159047fSniklas #define SF_DEBUG (0x00100000) /* Is in debug or abs section */ 3352159047fSniklas #define SF_GET_SEGMENT (0x00200000) /* Get the section of the forward symbol. */ 3362159047fSniklas /* All other bits are unused. */ 3372159047fSniklas 338c074d1c9Sdrahn /* Accessors. */ 339b305b0f1Sespie #define SF_GET(s) (*symbol_get_obj (s)) 340b305b0f1Sespie #define SF_GET_DEBUG(s) (symbol_get_bfdsym (s)->flags & BSF_DEBUGGING) 341b305b0f1Sespie #define SF_SET_DEBUG(s) (symbol_get_bfdsym (s)->flags |= BSF_DEBUGGING) 3422159047fSniklas #define SF_GET_NORMAL_FIELD(s) (SF_GET (s) & SF_NORMAL_MASK) 3432159047fSniklas #define SF_GET_DEBUG_FIELD(s) (SF_GET (s) & SF_DEBUG_MASK) 3442159047fSniklas #define SF_GET_FILE(s) (SF_GET (s) & SF_FILE) 3452159047fSniklas #define SF_GET_STATICS(s) (SF_GET (s) & SF_STATICS) 3462159047fSniklas #define SF_GET_DEFINED(s) (SF_GET (s) & SF_DEFINED) 3472159047fSniklas #define SF_GET_STRING(s) (SF_GET (s) & SF_STRING) 3482159047fSniklas #define SF_GET_LOCAL(s) (SF_GET (s) & SF_LOCAL) 3492159047fSniklas #define SF_GET_FUNCTION(s) (SF_GET (s) & SF_FUNCTION) 3502159047fSniklas #define SF_GET_PROCESS(s) (SF_GET (s) & SF_PROCESS) 3512159047fSniklas #define SF_GET_TAGGED(s) (SF_GET (s) & SF_TAGGED) 3522159047fSniklas #define SF_GET_TAG(s) (SF_GET (s) & SF_TAG) 3532159047fSniklas #define SF_GET_GET_SEGMENT(s) (SF_GET (s) & SF_GET_SEGMENT) 3542159047fSniklas #define SF_GET_I960(s) (SF_GET (s) & SF_I960_MASK) /* used by i960 */ 3552159047fSniklas #define SF_GET_BALNAME(s) (SF_GET (s) & SF_BALNAME) /* used by i960 */ 3562159047fSniklas #define SF_GET_CALLNAME(s) (SF_GET (s) & SF_CALLNAME) /* used by i960 */ 3572159047fSniklas #define SF_GET_IS_SYSPROC(s) (SF_GET (s) & SF_IS_SYSPROC) /* used by i960 */ 3582159047fSniklas #define SF_GET_SYSPROC(s) (SF_GET (s) & SF_SYSPROC) /* used by i960 */ 3592159047fSniklas 360c074d1c9Sdrahn /* Modifiers. */ 3612159047fSniklas #define SF_SET(s,v) (SF_GET (s) = (v)) 3622159047fSniklas #define SF_SET_NORMAL_FIELD(s,v) (SF_GET (s) |= ((v) & SF_NORMAL_MASK)) 3632159047fSniklas #define SF_SET_DEBUG_FIELD(s,v) (SF_GET (s) |= ((v) & SF_DEBUG_MASK)) 3642159047fSniklas #define SF_SET_FILE(s) (SF_GET (s) |= SF_FILE) 3652159047fSniklas #define SF_SET_STATICS(s) (SF_GET (s) |= SF_STATICS) 3662159047fSniklas #define SF_SET_DEFINED(s) (SF_GET (s) |= SF_DEFINED) 3672159047fSniklas #define SF_SET_STRING(s) (SF_GET (s) |= SF_STRING) 3682159047fSniklas #define SF_SET_LOCAL(s) (SF_GET (s) |= SF_LOCAL) 3692159047fSniklas #define SF_CLEAR_LOCAL(s) (SF_GET (s) &= ~SF_LOCAL) 3702159047fSniklas #define SF_SET_FUNCTION(s) (SF_GET (s) |= SF_FUNCTION) 3712159047fSniklas #define SF_SET_PROCESS(s) (SF_GET (s) |= SF_PROCESS) 3722159047fSniklas #define SF_SET_TAGGED(s) (SF_GET (s) |= SF_TAGGED) 3732159047fSniklas #define SF_SET_TAG(s) (SF_GET (s) |= SF_TAG) 3742159047fSniklas #define SF_SET_GET_SEGMENT(s) (SF_GET (s) |= SF_GET_SEGMENT) 3752159047fSniklas #define SF_SET_I960(s,v) (SF_GET (s) |= ((v) & SF_I960_MASK)) /* used by i960 */ 3762159047fSniklas #define SF_SET_BALNAME(s) (SF_GET (s) |= SF_BALNAME) /* used by i960 */ 3772159047fSniklas #define SF_SET_CALLNAME(s) (SF_GET (s) |= SF_CALLNAME) /* used by i960 */ 3782159047fSniklas #define SF_SET_IS_SYSPROC(s) (SF_GET (s) |= SF_IS_SYSPROC) /* used by i960 */ 3792159047fSniklas #define SF_SET_SYSPROC(s,v) (SF_GET (s) |= ((v) & SF_SYSPROC)) /* used by i960 */ 3802159047fSniklas 3812159047fSniklas /* -------------- Line number handling ------- */ 3822159047fSniklas extern int text_lineno_number; 3832159047fSniklas extern int coff_line_base; 3842159047fSniklas extern int coff_n_line_nos; 3852159047fSniklas 3862159047fSniklas #define obj_emit_lineno(WHERE,LINE,FILE_START) abort () 387b305b0f1Sespie extern void coff_add_linesym PARAMS ((symbolS *)); 3882159047fSniklas 389b55d4692Sfgsch void c_dot_file_symbol PARAMS ((const char *filename)); 3902159047fSniklas #define obj_app_file c_dot_file_symbol 3912159047fSniklas 392b305b0f1Sespie extern void coff_frob_symbol PARAMS ((symbolS *, int *)); 3932159047fSniklas extern void coff_adjust_symtab PARAMS ((void)); 3942159047fSniklas extern void coff_frob_section PARAMS ((segT)); 3952159047fSniklas extern void coff_adjust_section_syms PARAMS ((bfd *, asection *, PTR)); 396b305b0f1Sespie extern void coff_frob_file_after_relocs PARAMS ((void)); 3972159047fSniklas #define obj_frob_symbol(S,P) coff_frob_symbol(S,&P) 398b305b0f1Sespie #ifndef obj_adjust_symtab 3992159047fSniklas #define obj_adjust_symtab() coff_adjust_symtab() 400b305b0f1Sespie #endif 4012159047fSniklas #define obj_frob_section(S) coff_frob_section (S) 402b305b0f1Sespie #define obj_frob_file_after_relocs() coff_frob_file_after_relocs () 4032159047fSniklas 404b305b0f1Sespie extern symbolS *coff_last_function; 4052159047fSniklas 4062159047fSniklas /* Forward the segment of a forwarded symbol, handle assignments that 4072159047fSniklas just copy symbol values, etc. */ 408b305b0f1Sespie #ifndef OBJ_COPY_SYMBOL_ATTRIBUTES 4092159047fSniklas #ifndef TE_I386AIX 4102159047fSniklas #define OBJ_COPY_SYMBOL_ATTRIBUTES(dest,src) \ 4112159047fSniklas (SF_GET_GET_SEGMENT (dest) \ 4122159047fSniklas ? (S_SET_SEGMENT (dest, S_GET_SEGMENT (src)), 0) \ 4132159047fSniklas : 0) 4142159047fSniklas #else 4152159047fSniklas #define OBJ_COPY_SYMBOL_ATTRIBUTES(dest,src) \ 4162159047fSniklas (SF_GET_GET_SEGMENT (dest) && S_GET_SEGMENT (dest) == SEG_UNKNOWN \ 4172159047fSniklas ? (S_SET_SEGMENT (dest, S_GET_SEGMENT (src)), 0) \ 4182159047fSniklas : 0) 4192159047fSniklas #endif 420b305b0f1Sespie #endif 4212159047fSniklas 422c074d1c9Sdrahn /* Sanity check. */ 4232159047fSniklas 4242159047fSniklas #ifdef TC_I960 4252159047fSniklas #ifndef C_LEAFSTAT 4262159047fSniklas hey ! Where is the C_LEAFSTAT definition ? i960 - coff support is depending on it. 4272159047fSniklas #endif /* no C_LEAFSTAT */ 4282159047fSniklas #endif /* TC_I960 */ 4292159047fSniklas 4302159047fSniklas #else /* not BFD_ASSEMBLER */ 4312159047fSniklas 432c074d1c9Sdrahn #if defined TC_A29K || defined TC_OR32 433c074d1c9Sdrahn /* Allow translate from aout relocs to coff relocs. */ 4342159047fSniklas #define NO_RELOC 20 4352159047fSniklas #define RELOC_32 1 4362159047fSniklas #define RELOC_8 2 4372159047fSniklas #define RELOC_CONST 3 4382159047fSniklas #define RELOC_CONSTH 4 4392159047fSniklas #define RELOC_JUMPTARG 5 4402159047fSniklas #define RELOC_BASE22 6 4412159047fSniklas #define RELOC_HI22 7 4422159047fSniklas #define RELOC_LO10 8 4432159047fSniklas #define RELOC_BASE13 9 4442159047fSniklas #define RELOC_WDISP22 10 4452159047fSniklas #define RELOC_WDISP30 11 4462159047fSniklas #endif 4472159047fSniklas 4482159047fSniklas extern const segT N_TYPE_seg[]; 4492159047fSniklas 4502159047fSniklas /* Magic number of paged executable. */ 4512159047fSniklas #define DEFAULT_MAGIC_NUMBER_FOR_OBJECT_FILE 0x8300 4522159047fSniklas 4532159047fSniklas /* SYMBOL TABLE */ 4542159047fSniklas 455c074d1c9Sdrahn /* Symbol table entry data type. */ 4562159047fSniklas 4572159047fSniklas typedef struct 4582159047fSniklas { 4592159047fSniklas /* Basic symbol */ 4602159047fSniklas struct internal_syment ost_entry; 4612159047fSniklas /* Auxiliary entry. */ 4622159047fSniklas union internal_auxent ost_auxent[OBJ_COFF_MAX_AUXENTRIES]; 463c074d1c9Sdrahn /* obj_coff internal use only flags. */ 4642159047fSniklas unsigned int ost_flags; 4652159047fSniklas } obj_symbol_type; 4662159047fSniklas 4672159047fSniklas #ifndef DO_NOT_STRIP 4682159047fSniklas #define DO_NOT_STRIP 0 4692159047fSniklas #endif 470c074d1c9Sdrahn /* Symbol table macros and constants. */ 4712159047fSniklas 472*007c2a45Smiod /* Possible and useful section number in symbol table 473c074d1c9Sdrahn The values of TEXT, DATA and BSS may not be portable. */ 4742159047fSniklas 4752159047fSniklas #define C_ABS_SECTION N_ABS 4762159047fSniklas #define C_UNDEF_SECTION N_UNDEF 4772159047fSniklas #define C_DEBUG_SECTION N_DEBUG 4782159047fSniklas #define C_NTV_SECTION N_TV 4792159047fSniklas #define C_PTV_SECTION P_TV 480191aa565Sniklas #define C_REGISTER_SECTION 50 4812159047fSniklas 482c074d1c9Sdrahn /* Macros to extract information from a symbol table entry. 483*007c2a45Smiod This syntactic indirection allows independence regarding a.out or coff. 484c074d1c9Sdrahn The argument (s) of all these macros is a pointer to a symbol table entry. */ 4852159047fSniklas 486c074d1c9Sdrahn /* Predicates. */ 487c074d1c9Sdrahn /* True if the symbol is external. */ 488c074d1c9Sdrahn #define S_IS_EXTERNAL(s) \ 489c074d1c9Sdrahn ((s)->sy_symbol.ost_entry.n_scnum == C_UNDEF_SECTION) 490c074d1c9Sdrahn 4912159047fSniklas /* True if symbol has been defined, ie : 4922159047fSniklas section > 0 (DATA, TEXT or BSS) 493c074d1c9Sdrahn section == 0 and value > 0 (external bss symbol). */ 4942159047fSniklas #define S_IS_DEFINED(s) \ 4952159047fSniklas ((s)->sy_symbol.ost_entry.n_scnum > C_UNDEF_SECTION \ 4962159047fSniklas || ((s)->sy_symbol.ost_entry.n_scnum == C_UNDEF_SECTION \ 4972159047fSniklas && S_GET_VALUE (s) > 0) \ 4982159047fSniklas || ((s)->sy_symbol.ost_entry.n_scnum == C_ABS_SECTION)) 499c074d1c9Sdrahn 500c074d1c9Sdrahn /* Return true for symbols that should not be reduced to section 501c074d1c9Sdrahn symbols or eliminated from expressions, because they may be 502c074d1c9Sdrahn overridden by the linker. */ 503c074d1c9Sdrahn #define S_FORCE_RELOC(s, strict) \ 504c074d1c9Sdrahn (!SEG_NORMAL (S_GET_SEGMENT (s)) || (strict && S_IS_WEAK (s))) 505c074d1c9Sdrahn 506c074d1c9Sdrahn /* True if a debug special symbol entry. */ 507c074d1c9Sdrahn #define S_IS_DEBUG(s) \ 508c074d1c9Sdrahn ((s)->sy_symbol.ost_entry.n_scnum == C_DEBUG_SECTION) 509c074d1c9Sdrahn 510c074d1c9Sdrahn /* True if a symbol is local symbol name. */ 511c074d1c9Sdrahn /* A symbol name whose name includes ^A is a gas internal pseudo symbol. */ 5122159047fSniklas #define S_IS_LOCAL(s) \ 5132159047fSniklas ((s)->sy_symbol.ost_entry.n_scnum == C_REGISTER_SECTION \ 514b305b0f1Sespie || (S_LOCAL_NAME(s) && ! flag_keep_locals && ! S_IS_DEBUG (s)) \ 515191aa565Sniklas || strchr (S_GET_NAME (s), '\001') != NULL \ 516b305b0f1Sespie || strchr (S_GET_NAME (s), '\002') != NULL \ 517b305b0f1Sespie || (flag_strip_local_absolute \ 518b305b0f1Sespie && !S_IS_EXTERNAL(s) \ 519b305b0f1Sespie && (s)->sy_symbol.ost_entry.n_scnum == C_ABS_SECTION)) 520c074d1c9Sdrahn 521c074d1c9Sdrahn /* True if a symbol is not defined in this file. */ 5222159047fSniklas #define S_IS_EXTERN(s) ((s)->sy_symbol.ost_entry.n_scnum == 0 \ 5232159047fSniklas && S_GET_VALUE (s) == 0) 524c074d1c9Sdrahn 525c074d1c9Sdrahn /* True if a symbol can be multiply defined (bss symbols have this def 526c074d1c9Sdrahn though it is bad practice). */ 5272159047fSniklas #define S_IS_COMMON(s) ((s)->sy_symbol.ost_entry.n_scnum == 0 \ 5282159047fSniklas && S_GET_VALUE (s) != 0) 529c074d1c9Sdrahn 5302159047fSniklas /* True if a symbol name is in the string table, i.e. its length is > 8. */ 5312159047fSniklas #define S_IS_STRING(s) (strlen(S_GET_NAME(s)) > 8 ? 1 : 0) 5322159047fSniklas 533b305b0f1Sespie /* True if a symbol is defined as weak. */ 534b305b0f1Sespie #ifdef TE_PE 535b305b0f1Sespie #define S_IS_WEAK(s) \ 536b305b0f1Sespie ((s)->sy_symbol.ost_entry.n_sclass == C_NT_WEAK \ 537b305b0f1Sespie || (s)->sy_symbol.ost_entry.n_sclass == C_WEAKEXT) 538b305b0f1Sespie #else 539b305b0f1Sespie #define S_IS_WEAK(s) \ 540b305b0f1Sespie ((s)->sy_symbol.ost_entry.n_sclass == C_WEAKEXT) 541b305b0f1Sespie #endif 542b305b0f1Sespie 543c074d1c9Sdrahn /* Accessors. */ 544c074d1c9Sdrahn /* The name of the symbol. */ 5452159047fSniklas #define S_GET_NAME(s) ((char*) (s)->sy_symbol.ost_entry.n_offset) 546c074d1c9Sdrahn 547c074d1c9Sdrahn /* The pointer to the string table. */ 5482159047fSniklas #define S_GET_OFFSET(s) ((s)->sy_symbol.ost_entry.n_offset) 549c074d1c9Sdrahn 550c074d1c9Sdrahn /* The numeric value of the segment. */ 5512159047fSniklas #define S_GET_SEGMENT(s) s_get_segment(s) 552c074d1c9Sdrahn 553c074d1c9Sdrahn /* The data type. */ 5542159047fSniklas #define S_GET_DATA_TYPE(s) ((s)->sy_symbol.ost_entry.n_type) 555c074d1c9Sdrahn 556c074d1c9Sdrahn /* The storage class. */ 5572159047fSniklas #define S_GET_STORAGE_CLASS(s) ((s)->sy_symbol.ost_entry.n_sclass) 558c074d1c9Sdrahn 559c074d1c9Sdrahn /* The number of auxiliary entries. */ 5602159047fSniklas #define S_GET_NUMBER_AUXILIARY(s) ((s)->sy_symbol.ost_entry.n_numaux) 5612159047fSniklas 562c074d1c9Sdrahn /* Modifiers. */ 563c074d1c9Sdrahn /* Set the name of the symbol. */ 564c074d1c9Sdrahn #define S_SET_NAME(s,v) \ 565c074d1c9Sdrahn ((s)->sy_symbol.ost_entry.n_offset = (unsigned long) (v)) 5662159047fSniklas 567c074d1c9Sdrahn /* Set the offset of the symbol. */ 568c074d1c9Sdrahn #define S_SET_OFFSET(s,v) \ 569c074d1c9Sdrahn ((s)->sy_symbol.ost_entry.n_offset = (v)) 5702159047fSniklas 571c074d1c9Sdrahn /* The numeric value of the segment. */ 572c074d1c9Sdrahn #define S_SET_SEGMENT(s,v) \ 573c074d1c9Sdrahn ((s)->sy_symbol.ost_entry.n_scnum = SEGMENT_TO_SYMBOL_TYPE(v)) 574c074d1c9Sdrahn 575c074d1c9Sdrahn /* The data type. */ 576c074d1c9Sdrahn #define S_SET_DATA_TYPE(s,v) \ 577c074d1c9Sdrahn ((s)->sy_symbol.ost_entry.n_type = (v)) 578c074d1c9Sdrahn 579c074d1c9Sdrahn /* The storage class. */ 580c074d1c9Sdrahn #define S_SET_STORAGE_CLASS(s,v) \ 581c074d1c9Sdrahn ((s)->sy_symbol.ost_entry.n_sclass = (v)) 582c074d1c9Sdrahn 583c074d1c9Sdrahn /* The number of auxiliary entries. */ 584c074d1c9Sdrahn #define S_SET_NUMBER_AUXILIARY(s,v) \ 585c074d1c9Sdrahn ((s)->sy_symbol.ost_entry.n_numaux = (v)) 586c074d1c9Sdrahn 587c074d1c9Sdrahn /* Additional modifiers. */ 588c074d1c9Sdrahn /* The symbol is external (does not mean undefined). */ 589c074d1c9Sdrahn #define S_SET_EXTERNAL(s) \ 590c074d1c9Sdrahn { S_SET_STORAGE_CLASS(s, C_EXT) ; SF_CLEAR_LOCAL(s); } 591c074d1c9Sdrahn 592c074d1c9Sdrahn /* Auxiliary entry macros. SA_ stands for symbol auxiliary. */ 593c074d1c9Sdrahn /* Omit the tv related fields. */ 594c074d1c9Sdrahn /* Accessors. */ 5952159047fSniklas #define SYM_AUXENT(S) (&(S)->sy_symbol.ost_auxent[0]) 5962159047fSniklas 5972159047fSniklas #define SA_GET_SYM_TAGNDX(s) (SYM_AUXENT (s)->x_sym.x_tagndx.l) 5982159047fSniklas #define SA_GET_SYM_LNNO(s) (SYM_AUXENT (s)->x_sym.x_misc.x_lnsz.x_lnno) 5992159047fSniklas #define SA_GET_SYM_SIZE(s) (SYM_AUXENT (s)->x_sym.x_misc.x_lnsz.x_size) 6002159047fSniklas #define SA_GET_SYM_FSIZE(s) (SYM_AUXENT (s)->x_sym.x_misc.x_fsize) 6012159047fSniklas #define SA_GET_SYM_LNNOPTR(s) (SYM_AUXENT (s)->x_sym.x_fcnary.x_fcn.x_lnnoptr) 6022159047fSniklas #define SA_GET_SYM_ENDNDX(s) (SYM_AUXENT (s)->x_sym.x_fcnary.x_fcn.x_endndx.l) 6032159047fSniklas #define SA_GET_SYM_DIMEN(s,i) (SYM_AUXENT (s)->x_sym.x_fcnary.x_ary.x_dimen[(i)]) 6042159047fSniklas #define SA_GET_FILE_FNAME(s) (SYM_AUXENT (s)->x_file.x_fname) 6052159047fSniklas #define SA_GET_FILE_FNAME_OFFSET(s) (SYM_AUXENT (s)->x_file.x_n.x_offset) 6062159047fSniklas #define SA_GET_FILE_FNAME_ZEROS(s) (SYM_AUXENT (s)->x_file.x_n.x_zeroes) 6072159047fSniklas #define SA_GET_SCN_SCNLEN(s) (SYM_AUXENT (s)->x_scn.x_scnlen) 6082159047fSniklas #define SA_GET_SCN_NRELOC(s) (SYM_AUXENT (s)->x_scn.x_nreloc) 6092159047fSniklas #define SA_GET_SCN_NLINNO(s) (SYM_AUXENT (s)->x_scn.x_nlinno) 6102159047fSniklas 611c074d1c9Sdrahn /* Modifiers. */ 6122159047fSniklas #define SA_SET_SYM_TAGNDX(s,v) (SYM_AUXENT (s)->x_sym.x_tagndx.l=(v)) 6132159047fSniklas #define SA_SET_SYM_LNNO(s,v) (SYM_AUXENT (s)->x_sym.x_misc.x_lnsz.x_lnno=(v)) 6142159047fSniklas #define SA_SET_SYM_SIZE(s,v) (SYM_AUXENT (s)->x_sym.x_misc.x_lnsz.x_size=(v)) 6152159047fSniklas #define SA_SET_SYM_FSIZE(s,v) (SYM_AUXENT (s)->x_sym.x_misc.x_fsize=(v)) 6162159047fSniklas #define SA_SET_SYM_LNNOPTR(s,v) (SYM_AUXENT (s)->x_sym.x_fcnary.x_fcn.x_lnnoptr=(v)) 6172159047fSniklas #define SA_SET_SYM_ENDNDX(s,v) (SYM_AUXENT (s)->x_sym.x_fcnary.x_fcn.x_endndx.l=(v)) 6182159047fSniklas #define SA_SET_SYM_DIMEN(s,i,v) (SYM_AUXENT (s)->x_sym.x_fcnary.x_ary.x_dimen[(i)]=(v)) 6192159047fSniklas #define SA_SET_FILE_FNAME(s,v) strncpy(SYM_AUXENT (s)->x_file.x_fname,(v),FILNMLEN) 6202159047fSniklas #define SA_SET_FILE_FNAME_OFFSET(s,v) (SYM_AUXENT (s)->x_file.x_n.x_offset=(v)) 6212159047fSniklas #define SA_SET_FILE_FNAME_ZEROS(s,v) (SYM_AUXENT (s)->x_file.x_n.x_zeroes=(v)) 6222159047fSniklas #define SA_SET_SCN_SCNLEN(s,v) (SYM_AUXENT (s)->x_scn.x_scnlen=(v)) 6232159047fSniklas #define SA_SET_SCN_NRELOC(s,v) (SYM_AUXENT (s)->x_scn.x_nreloc=(v)) 6242159047fSniklas #define SA_SET_SCN_NLINNO(s,v) (SYM_AUXENT (s)->x_scn.x_nlinno=(v)) 6252159047fSniklas 626c074d1c9Sdrahn /* Internal use only definitions. SF_ stands for symbol flags. 627c074d1c9Sdrahn 628c074d1c9Sdrahn These values can be assigned to sy_symbol.ost_flags field of a symbolS. 629c074d1c9Sdrahn 630c074d1c9Sdrahn You'll break i960 if you shift the SYSPROC bits anywhere else. for 631c074d1c9Sdrahn more on the balname/callname hack, see tc-i960.h. b.out is done 632c074d1c9Sdrahn differently. */ 6332159047fSniklas 6342159047fSniklas #define SF_I960_MASK (0x000001ff) /* Bits 0-8 are used by the i960 port. */ 6352159047fSniklas #define SF_SYSPROC (0x0000003f) /* bits 0-5 are used to store the sysproc number */ 6362159047fSniklas #define SF_IS_SYSPROC (0x00000040) /* bit 6 marks symbols that are sysprocs */ 6372159047fSniklas #define SF_BALNAME (0x00000080) /* bit 7 marks BALNAME symbols */ 6382159047fSniklas #define SF_CALLNAME (0x00000100) /* bit 8 marks CALLNAME symbols */ 6392159047fSniklas 6402159047fSniklas #define SF_NORMAL_MASK (0x0000ffff) /* bits 12-15 are general purpose. */ 6412159047fSniklas 6422159047fSniklas #define SF_STATICS (0x00001000) /* Mark the .text & all symbols */ 6432159047fSniklas #define SF_DEFINED (0x00002000) /* Symbol is defined in this file */ 6442159047fSniklas #define SF_STRING (0x00004000) /* Symbol name length > 8 */ 6452159047fSniklas #define SF_LOCAL (0x00008000) /* Symbol must not be emitted */ 6462159047fSniklas 6472159047fSniklas #define SF_DEBUG_MASK (0xffff0000) /* bits 16-31 are debug info */ 6482159047fSniklas 6492159047fSniklas #define SF_FUNCTION (0x00010000) /* The symbol is a function */ 6502159047fSniklas #define SF_PROCESS (0x00020000) /* Process symbol before write */ 6512159047fSniklas #define SF_TAGGED (0x00040000) /* Is associated with a tag */ 6522159047fSniklas #define SF_TAG (0x00080000) /* Is a tag */ 6532159047fSniklas #define SF_DEBUG (0x00100000) /* Is in debug or abs section */ 6542159047fSniklas #define SF_GET_SEGMENT (0x00200000) /* Get the section of the forward symbol. */ 655191aa565Sniklas #define SF_ADJ_LNNOPTR (0x00400000) /* Has a lnnoptr */ 6562159047fSniklas /* All other bits are unused. */ 6572159047fSniklas 658c074d1c9Sdrahn /* Accessors. */ 6592159047fSniklas #define SF_GET(s) ((s)->sy_symbol.ost_flags) 6602159047fSniklas #define SF_GET_NORMAL_FIELD(s) (SF_GET (s) & SF_NORMAL_MASK) 6612159047fSniklas #define SF_GET_DEBUG_FIELD(s) (SF_GET (s) & SF_DEBUG_MASK) 6622159047fSniklas #define SF_GET_FILE(s) (SF_GET (s) & SF_FILE) 6632159047fSniklas #define SF_GET_STATICS(s) (SF_GET (s) & SF_STATICS) 6642159047fSniklas #define SF_GET_DEFINED(s) (SF_GET (s) & SF_DEFINED) 6652159047fSniklas #define SF_GET_STRING(s) (SF_GET (s) & SF_STRING) 6662159047fSniklas #define SF_GET_LOCAL(s) (SF_GET (s) & SF_LOCAL) 6672159047fSniklas #define SF_GET_FUNCTION(s) (SF_GET (s) & SF_FUNCTION) 6682159047fSniklas #define SF_GET_PROCESS(s) (SF_GET (s) & SF_PROCESS) 6692159047fSniklas #define SF_GET_DEBUG(s) (SF_GET (s) & SF_DEBUG) 6702159047fSniklas #define SF_GET_TAGGED(s) (SF_GET (s) & SF_TAGGED) 6712159047fSniklas #define SF_GET_TAG(s) (SF_GET (s) & SF_TAG) 6722159047fSniklas #define SF_GET_GET_SEGMENT(s) (SF_GET (s) & SF_GET_SEGMENT) 673191aa565Sniklas #define SF_GET_ADJ_LNNOPTR(s) (SF_GET (s) & SF_ADJ_LNNOPTR) 6742159047fSniklas #define SF_GET_I960(s) (SF_GET (s) & SF_I960_MASK) /* used by i960 */ 6752159047fSniklas #define SF_GET_BALNAME(s) (SF_GET (s) & SF_BALNAME) /* used by i960 */ 6762159047fSniklas #define SF_GET_CALLNAME(s) (SF_GET (s) & SF_CALLNAME) /* used by i960 */ 6772159047fSniklas #define SF_GET_IS_SYSPROC(s) (SF_GET (s) & SF_IS_SYSPROC) /* used by i960 */ 6782159047fSniklas #define SF_GET_SYSPROC(s) (SF_GET (s) & SF_SYSPROC) /* used by i960 */ 6792159047fSniklas 680c074d1c9Sdrahn /* Modifiers. */ 6812159047fSniklas #define SF_SET(s,v) (SF_GET (s) = (v)) 6822159047fSniklas #define SF_SET_NORMAL_FIELD(s,v) (SF_GET (s) |= ((v) & SF_NORMAL_MASK)) 6832159047fSniklas #define SF_SET_DEBUG_FIELD(s,v) (SF_GET (s) |= ((v) & SF_DEBUG_MASK)) 6842159047fSniklas #define SF_SET_FILE(s) (SF_GET (s) |= SF_FILE) 6852159047fSniklas #define SF_SET_STATICS(s) (SF_GET (s) |= SF_STATICS) 6862159047fSniklas #define SF_SET_DEFINED(s) (SF_GET (s) |= SF_DEFINED) 6872159047fSniklas #define SF_SET_STRING(s) (SF_GET (s) |= SF_STRING) 6882159047fSniklas #define SF_SET_LOCAL(s) (SF_GET (s) |= SF_LOCAL) 6892159047fSniklas #define SF_CLEAR_LOCAL(s) (SF_GET (s) &= ~SF_LOCAL) 6902159047fSniklas #define SF_SET_FUNCTION(s) (SF_GET (s) |= SF_FUNCTION) 6912159047fSniklas #define SF_SET_PROCESS(s) (SF_GET (s) |= SF_PROCESS) 6922159047fSniklas #define SF_SET_DEBUG(s) (SF_GET (s) |= SF_DEBUG) 6932159047fSniklas #define SF_SET_TAGGED(s) (SF_GET (s) |= SF_TAGGED) 6942159047fSniklas #define SF_SET_TAG(s) (SF_GET (s) |= SF_TAG) 6952159047fSniklas #define SF_SET_GET_SEGMENT(s) (SF_GET (s) |= SF_GET_SEGMENT) 696191aa565Sniklas #define SF_SET_ADJ_LNNOPTR(s) (SF_GET (s) |= SF_ADJ_LNNOPTR) 6972159047fSniklas #define SF_SET_I960(s,v) (SF_GET (s) |= ((v) & SF_I960_MASK)) /* used by i960 */ 6982159047fSniklas #define SF_SET_BALNAME(s) (SF_GET (s) |= SF_BALNAME) /* used by i960 */ 6992159047fSniklas #define SF_SET_CALLNAME(s) (SF_GET (s) |= SF_CALLNAME) /* used by i960 */ 7002159047fSniklas #define SF_SET_IS_SYSPROC(s) (SF_GET (s) |= SF_IS_SYSPROC) /* used by i960 */ 7012159047fSniklas #define SF_SET_SYSPROC(s,v) (SF_GET (s) |= ((v) & SF_SYSPROC)) /* used by i960 */ 7022159047fSniklas 703c074d1c9Sdrahn /* File header macro and type definition. */ 7042159047fSniklas 705c074d1c9Sdrahn /* File position calculators. Beware to use them when all the 706c074d1c9Sdrahn appropriate fields are set in the header. */ 7072159047fSniklas 7082159047fSniklas #ifdef OBJ_COFF_OMIT_OPTIONAL_HEADER 7092159047fSniklas #define OBJ_COFF_AOUTHDRSZ (0) 7102159047fSniklas #else 7112159047fSniklas #define OBJ_COFF_AOUTHDRSZ (AOUTHDRSZ) 7122159047fSniklas #endif /* OBJ_COFF_OMIT_OPTIONAL_HEADER */ 7132159047fSniklas 7142159047fSniklas #define H_GET_FILE_SIZE(h) \ 7152159047fSniklas (long) (FILHSZ + OBJ_COFF_AOUTHDRSZ + \ 7162159047fSniklas H_GET_NUMBER_OF_SECTIONS(h) * SCNHSZ + \ 7172159047fSniklas H_GET_TEXT_SIZE(h) + H_GET_DATA_SIZE(h) + \ 7182159047fSniklas H_GET_RELOCATION_SIZE(h) + H_GET_LINENO_SIZE(h) + \ 7192159047fSniklas H_GET_SYMBOL_TABLE_SIZE(h) + \ 7202159047fSniklas (h)->string_table_size) 7212159047fSniklas #define H_GET_TEXT_FILE_OFFSET(h) \ 7222159047fSniklas (long) (FILHSZ + OBJ_COFF_AOUTHDRSZ + \ 7232159047fSniklas H_GET_NUMBER_OF_SECTIONS(h) * SCNHSZ) 7242159047fSniklas #define H_GET_DATA_FILE_OFFSET(h) \ 7252159047fSniklas (long) (FILHSZ + OBJ_COFF_AOUTHDRSZ + \ 7262159047fSniklas H_GET_NUMBER_OF_SECTIONS(h) * SCNHSZ + \ 7272159047fSniklas H_GET_TEXT_SIZE(h)) 7282159047fSniklas #define H_GET_BSS_FILE_OFFSET(h) 0 7292159047fSniklas #define H_GET_RELOCATION_FILE_OFFSET(h) \ 7302159047fSniklas (long) (FILHSZ + OBJ_COFF_AOUTHDRSZ + \ 7312159047fSniklas H_GET_NUMBER_OF_SECTIONS(h) * SCNHSZ + \ 7322159047fSniklas H_GET_TEXT_SIZE(h) + H_GET_DATA_SIZE(h)) 7332159047fSniklas #define H_GET_LINENO_FILE_OFFSET(h) \ 7342159047fSniklas (long) (FILHSZ + OBJ_COFF_AOUTHDRSZ + \ 7352159047fSniklas H_GET_NUMBER_OF_SECTIONS(h) * SCNHSZ + \ 7362159047fSniklas H_GET_TEXT_SIZE(h) + H_GET_DATA_SIZE(h) + \ 7372159047fSniklas H_GET_RELOCATION_SIZE(h)) 7382159047fSniklas #define H_GET_SYMBOL_TABLE_FILE_OFFSET(h) \ 7392159047fSniklas (long) (FILHSZ + OBJ_COFF_AOUTHDRSZ + \ 7402159047fSniklas H_GET_NUMBER_OF_SECTIONS(h) * SCNHSZ + \ 7412159047fSniklas H_GET_TEXT_SIZE(h) + H_GET_DATA_SIZE(h) + \ 7422159047fSniklas H_GET_RELOCATION_SIZE(h) + H_GET_LINENO_SIZE(h)) 7432159047fSniklas 744c074d1c9Sdrahn /* Accessors. */ 745c074d1c9Sdrahn /* aouthdr. */ 7462159047fSniklas #define H_GET_MAGIC_NUMBER(h) ((h)->aouthdr.magic) 7472159047fSniklas #define H_GET_VERSION_STAMP(h) ((h)->aouthdr.vstamp) 7482159047fSniklas #define H_GET_TEXT_SIZE(h) ((h)->aouthdr.tsize) 7492159047fSniklas #define H_GET_DATA_SIZE(h) ((h)->aouthdr.dsize) 7502159047fSniklas #define H_GET_BSS_SIZE(h) ((h)->aouthdr.bsize) 7512159047fSniklas #define H_GET_ENTRY_POINT(h) ((h)->aouthdr.entry) 7522159047fSniklas #define H_GET_TEXT_START(h) ((h)->aouthdr.text_start) 7532159047fSniklas #define H_GET_DATA_START(h) ((h)->aouthdr.data_start) 754c074d1c9Sdrahn /* filehdr. */ 7552159047fSniklas #define H_GET_FILE_MAGIC_NUMBER(h) ((h)->filehdr.f_magic) 7562159047fSniklas #define H_GET_NUMBER_OF_SECTIONS(h) ((h)->filehdr.f_nscns) 7572159047fSniklas #define H_GET_TIME_STAMP(h) ((h)->filehdr.f_timdat) 7582159047fSniklas #define H_GET_SYMBOL_TABLE_POINTER(h) ((h)->filehdr.f_symptr) 7592159047fSniklas #define H_GET_SYMBOL_COUNT(h) ((h)->filehdr.f_nsyms) 7602159047fSniklas #define H_GET_SYMBOL_TABLE_SIZE(h) (H_GET_SYMBOL_COUNT(h) * SYMESZ) 7612159047fSniklas #define H_GET_SIZEOF_OPTIONAL_HEADER(h) ((h)->filehdr.f_opthdr) 7622159047fSniklas #define H_GET_FLAGS(h) ((h)->filehdr.f_flags) 763c074d1c9Sdrahn /* Extra fields to achieve bsd a.out compatibility and for convenience. */ 7642159047fSniklas #define H_GET_RELOCATION_SIZE(h) ((h)->relocation_size) 7652159047fSniklas #define H_GET_STRING_SIZE(h) ((h)->string_table_size) 7662159047fSniklas #define H_GET_LINENO_SIZE(h) ((h)->lineno_size) 7672159047fSniklas 7682159047fSniklas #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER 7692159047fSniklas #define H_GET_HEADER_SIZE(h) (sizeof (FILHDR) \ 7702159047fSniklas + sizeof (AOUTHDR)\ 7712159047fSniklas + (H_GET_NUMBER_OF_SECTIONS(h) * SCNHSZ)) 7722159047fSniklas #else /* OBJ_COFF_OMIT_OPTIONAL_HEADER */ 7732159047fSniklas #define H_GET_HEADER_SIZE(h) (sizeof (FILHDR) \ 7742159047fSniklas + (H_GET_NUMBER_OF_SECTIONS(h) * SCNHSZ)) 7752159047fSniklas #endif /* OBJ_COFF_OMIT_OPTIONAL_HEADER */ 7762159047fSniklas 7772159047fSniklas #define H_GET_TEXT_RELOCATION_SIZE(h) (text_section_header.s_nreloc * RELSZ) 7782159047fSniklas #define H_GET_DATA_RELOCATION_SIZE(h) (data_section_header.s_nreloc * RELSZ) 7792159047fSniklas 780c074d1c9Sdrahn /* Modifiers. */ 781c074d1c9Sdrahn /* aouthdr. */ 7822159047fSniklas #define H_SET_MAGIC_NUMBER(h,v) ((h)->aouthdr.magic = (v)) 7832159047fSniklas #define H_SET_VERSION_STAMP(h,v) ((h)->aouthdr.vstamp = (v)) 7842159047fSniklas #define H_SET_TEXT_SIZE(h,v) ((h)->aouthdr.tsize = (v)) 7852159047fSniklas #define H_SET_DATA_SIZE(h,v) ((h)->aouthdr.dsize = (v)) 7862159047fSniklas #define H_SET_BSS_SIZE(h,v) ((h)->aouthdr.bsize = (v)) 7872159047fSniklas #define H_SET_ENTRY_POINT(h,v) ((h)->aouthdr.entry = (v)) 7882159047fSniklas #define H_SET_TEXT_START(h,v) ((h)->aouthdr.text_start = (v)) 7892159047fSniklas #define H_SET_DATA_START(h,v) ((h)->aouthdr.data_start = (v)) 790c074d1c9Sdrahn /* filehdr. */ 7912159047fSniklas #define H_SET_FILE_MAGIC_NUMBER(h,v) ((h)->filehdr.f_magic = (v)) 7922159047fSniklas #define H_SET_NUMBER_OF_SECTIONS(h,v) ((h)->filehdr.f_nscns = (v)) 7932159047fSniklas #define H_SET_TIME_STAMP(h,v) ((h)->filehdr.f_timdat = (v)) 7942159047fSniklas #define H_SET_SYMBOL_TABLE_POINTER(h,v) ((h)->filehdr.f_symptr = (v)) 7952159047fSniklas #define H_SET_SYMBOL_TABLE_SIZE(h,v) ((h)->filehdr.f_nsyms = (v)) 7962159047fSniklas #define H_SET_SIZEOF_OPTIONAL_HEADER(h,v) ((h)->filehdr.f_opthdr = (v)) 7972159047fSniklas #define H_SET_FLAGS(h,v) ((h)->filehdr.f_flags = (v)) 798*007c2a45Smiod /* Extra fields to achieve bsd a.out compatibility and for convenience. */ 7992159047fSniklas #define H_SET_RELOCATION_SIZE(h,t,d) ((h)->relocation_size = (t)+(d)) 8002159047fSniklas #define H_SET_STRING_SIZE(h,v) ((h)->string_table_size = (v)) 8012159047fSniklas #define H_SET_LINENO_SIZE(h,v) ((h)->lineno_size = (v)) 8022159047fSniklas 803c074d1c9Sdrahn /* Segment flipping. */ 8042159047fSniklas 8052159047fSniklas typedef struct 8062159047fSniklas { 8072159047fSniklas struct internal_aouthdr aouthdr; /* a.out header */ 8082159047fSniklas struct internal_filehdr filehdr; /* File header, not machine dep. */ 8092159047fSniklas long string_table_size; /* names + '\0' + sizeof (int) */ 8102159047fSniklas long relocation_size; /* Cumulated size of relocation 8112159047fSniklas information for all sections in 8122159047fSniklas bytes. */ 8132159047fSniklas long lineno_size; /* Size of the line number information 814c074d1c9Sdrahn table in bytes. */ 8152159047fSniklas } object_headers; 8162159047fSniklas 8172159047fSniklas struct lineno_list 8182159047fSniklas { 8192159047fSniklas struct bfd_internal_lineno line; 820c074d1c9Sdrahn char *frag; /* Frag to which the line number is related. */ 821c074d1c9Sdrahn struct lineno_list *next; /* Forward chain pointer. */ 8222159047fSniklas }; 8232159047fSniklas 8242159047fSniklas #define obj_segment_name(i) (segment_info[(int) (i)].scnhdr.s_name) 8252159047fSniklas 8262159047fSniklas #define obj_add_segment(s) obj_coff_add_segment (s) 8272159047fSniklas 8282159047fSniklas extern segT obj_coff_add_segment PARAMS ((const char *)); 8292159047fSniklas 8302159047fSniklas extern void obj_coff_section PARAMS ((int)); 8312159047fSniklas 8322159047fSniklas extern void c_dot_file_symbol PARAMS ((char *filename)); 8332159047fSniklas #define obj_app_file c_dot_file_symbol 8342159047fSniklas extern void obj_extra_stuff PARAMS ((object_headers * headers)); 8352159047fSniklas 836b305b0f1Sespie extern segT s_get_segment PARAMS ((symbolS *ptr)); 8372159047fSniklas 8382159047fSniklas extern void c_section_header PARAMS ((struct internal_scnhdr * header, 8392159047fSniklas char *name, 8402159047fSniklas long core_address, 8412159047fSniklas long size, 8422159047fSniklas long data_ptr, 8432159047fSniklas long reloc_ptr, 8442159047fSniklas long lineno_ptr, 8452159047fSniklas long reloc_number, 8462159047fSniklas long lineno_number, 8472159047fSniklas long alignment)); 8482159047fSniklas 8492159047fSniklas #ifndef tc_coff_symbol_emit_hook 850b305b0f1Sespie void tc_coff_symbol_emit_hook PARAMS ((symbolS *)); 8512159047fSniklas #endif 8522159047fSniklas 853c074d1c9Sdrahn /* Sanity check. */ 8542159047fSniklas 8552159047fSniklas #ifdef TC_I960 8562159047fSniklas #ifndef C_LEAFSTAT 8572159047fSniklas hey ! Where is the C_LEAFSTAT definition ? i960 - coff support is depending on it. 8582159047fSniklas #endif /* no C_LEAFSTAT */ 8592159047fSniklas #endif /* TC_I960 */ 8602159047fSniklas extern struct internal_scnhdr data_section_header; 8612159047fSniklas extern struct internal_scnhdr text_section_header; 8622159047fSniklas 8632159047fSniklas /* Forward the segment of a forwarded symbol. */ 8642159047fSniklas #define OBJ_COPY_SYMBOL_ATTRIBUTES(dest,src) \ 8652159047fSniklas (SF_GET_GET_SEGMENT (dest) \ 8662159047fSniklas ? (S_SET_SEGMENT (dest, S_GET_SEGMENT (src)), 0) \ 8672159047fSniklas : 0) 8682159047fSniklas 869191aa565Sniklas #ifdef TE_PE 870191aa565Sniklas #define obj_handle_link_once(t) obj_coff_pe_handle_link_once (t) 871191aa565Sniklas extern void obj_coff_pe_handle_link_once (); 872191aa565Sniklas #endif 873191aa565Sniklas 8742159047fSniklas #endif /* not BFD_ASSEMBLER */ 8752159047fSniklas 876b305b0f1Sespie extern const pseudo_typeS coff_pseudo_table[]; 877b305b0f1Sespie 878b305b0f1Sespie #ifndef obj_pop_insert 879b305b0f1Sespie #define obj_pop_insert() pop_insert (coff_pseudo_table) 880b305b0f1Sespie #endif 881b305b0f1Sespie 882b305b0f1Sespie /* In COFF, if a symbol is defined using .def/.val SYM/.endef, it's OK 883b305b0f1Sespie to redefine the symbol later on. This can happen if C symbols use 884b305b0f1Sespie a prefix, and a symbol is defined both with and without the prefix, 885b305b0f1Sespie as in start/_start/__start in gcc/libgcc1-test.c. */ 886b305b0f1Sespie #define RESOLVE_SYMBOL_REDEFINITION(sym) \ 887b305b0f1Sespie (SF_GET_GET_SEGMENT (sym) \ 888b305b0f1Sespie ? (sym->sy_frag = frag_now, \ 889b305b0f1Sespie S_SET_VALUE (sym, frag_now_fix ()), \ 890b305b0f1Sespie S_SET_SEGMENT (sym, now_seg), \ 891b305b0f1Sespie 0) \ 892b305b0f1Sespie : 0) 893b305b0f1Sespie 8942159047fSniklas /* Stabs in a coff file go into their own section. */ 8952159047fSniklas #define SEPARATE_STAB_SECTIONS 1 8962159047fSniklas 8972159047fSniklas /* We need 12 bytes at the start of the section to hold some initial 8982159047fSniklas information. */ 8992159047fSniklas extern void obj_coff_init_stab_section PARAMS ((segT)); 9002159047fSniklas #define INIT_STAB_SECTION(seg) obj_coff_init_stab_section (seg) 9012159047fSniklas 902b305b0f1Sespie /* Store the number of relocations in the section aux entry. */ 903b305b0f1Sespie #define SET_SECTION_RELOCS(sec, relocs, n) \ 904b305b0f1Sespie SA_SET_SCN_NRELOC (section_symbol (sec), n) 905b305b0f1Sespie 9062159047fSniklas #endif /* OBJ_FORMAT_H */ 907