Back to index

cell-binutils  2.17cvs20070401
obj-coff.h
Go to the documentation of this file.
00001 /* coff object file format
00002    Copyright 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
00003    1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
00004    Free Software Foundation, Inc.
00005 
00006    This file is part of GAS.
00007 
00008    GAS is free software; you can redistribute it and/or modify
00009    it under the terms of the GNU General Public License as published by
00010    the Free Software Foundation; either version 2, or (at your option)
00011    any later version.
00012 
00013    GAS is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016    GNU General Public License for more details.
00017 
00018    You should have received a copy of the GNU General Public License
00019    along with GAS; see the file COPYING.  If not, write to the Free
00020    Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
00021    02110-1301, USA.  */
00022 
00023 #ifndef OBJ_FORMAT_H
00024 #define OBJ_FORMAT_H
00025 
00026 #define OBJ_COFF 1
00027 
00028 #include "targ-cpu.h"
00029 
00030 /* This internal_lineno crap is to stop namespace pollution from the
00031    bfd internal coff headerfile.  */
00032 #define internal_lineno bfd_internal_lineno
00033 #include "coff/internal.h"
00034 #undef internal_lineno
00035 
00036 /* CPU-specific setup:  */
00037 
00038 #ifdef TC_ARM
00039 #include "coff/arm.h"
00040 #ifndef TARGET_FORMAT
00041 #define TARGET_FORMAT "coff-arm"
00042 #endif
00043 #endif
00044 
00045 #ifdef TC_PPC
00046 #ifdef TE_PE
00047 #include "coff/powerpc.h"
00048 #else
00049 #include "coff/rs6000.h"
00050 #endif
00051 #endif
00052 
00053 #ifdef TC_SPARC
00054 #include "coff/sparc.h"
00055 #endif
00056 
00057 #ifdef TC_I386
00058 #ifndef TE_PEP
00059 #include "coff/x86_64.h"
00060 #else
00061 #include "coff/i386.h"
00062 #endif
00063 
00064 #ifdef TE_PE
00065 #ifdef TE_PEP
00066 extern const char *   x86_64_target_format (void);
00067 #define TARGET_FORMAT x86_64_target_format ()
00068 #define COFF_TARGET_FORMAT "pe-x86-64"
00069 #else
00070 #define TARGET_FORMAT "pe-i386"
00071 #endif
00072 #endif
00073 
00074 #ifndef TARGET_FORMAT
00075 #ifdef TE_PEP
00076 #define TARGET_FORMAT "coff-x86-64"
00077 #else
00078 #define TARGET_FORMAT "coff-i386"
00079 #endif
00080 #endif
00081 #endif
00082 
00083 #ifdef TC_M68K
00084 #include "coff/m68k.h"
00085 #ifndef TARGET_FORMAT
00086 #define TARGET_FORMAT "coff-m68k"
00087 #endif
00088 #endif
00089 
00090 #ifdef TC_OR32
00091 #include "coff/or32.h"
00092 #define TARGET_FORMAT "coff-or32-big"
00093 #endif
00094 
00095 #ifdef TC_I960
00096 #include "coff/i960.h"
00097 #define TARGET_FORMAT "coff-Intel-little"
00098 #endif
00099 
00100 #ifdef TC_Z80
00101 #include "coff/z80.h"
00102 #define TARGET_FORMAT "coff-z80"
00103 #endif
00104 
00105 #ifdef TC_Z8K
00106 #include "coff/z8k.h"
00107 #define TARGET_FORMAT "coff-z8k"
00108 #endif
00109 
00110 #ifdef TC_H8300
00111 #include "coff/h8300.h"
00112 #define TARGET_FORMAT "coff-h8300"
00113 #endif
00114 
00115 #ifdef TC_H8500
00116 #include "coff/h8500.h"
00117 #define TARGET_FORMAT "coff-h8500"
00118 #endif
00119 
00120 #ifdef TC_MAXQ20
00121 #include "coff/maxq.h"
00122 #define TARGET_FORMAT "coff-maxq"
00123 #endif
00124 
00125 #ifdef TC_SH
00126 
00127 #ifdef TE_PE
00128 #define COFF_WITH_PE
00129 #endif
00130 
00131 #include "coff/sh.h"
00132 
00133 #ifdef TE_PE
00134 #define TARGET_FORMAT "pe-shl"
00135 #else
00136 
00137 #define TARGET_FORMAT                                   \
00138   (!target_big_endian                                   \
00139    ? (sh_small ? "coff-shl-small" : "coff-shl")         \
00140    : (sh_small ? "coff-sh-small" : "coff-sh"))
00141 
00142 #endif
00143 #endif
00144 
00145 #ifdef TC_MIPS
00146 #define COFF_WITH_PE
00147 #include "coff/mipspe.h"
00148 #undef  TARGET_FORMAT
00149 #define TARGET_FORMAT "pe-mips"
00150 #endif
00151 
00152 #ifdef TC_TIC30
00153 #include "coff/tic30.h"
00154 #define TARGET_FORMAT "coff-tic30"
00155 #endif
00156 
00157 #ifdef TC_TIC4X
00158 #include "coff/tic4x.h"
00159 #define TARGET_FORMAT "coff2-tic4x"
00160 #endif
00161 
00162 #ifdef TC_TIC54X
00163 #include "coff/tic54x.h"
00164 #define TARGET_FORMAT "coff1-c54x"
00165 #endif
00166 
00167 #ifdef TC_MCORE
00168 #include "coff/mcore.h"
00169 #ifndef TARGET_FORMAT
00170 #define TARGET_FORMAT "pe-mcore"
00171 #endif
00172 #endif
00173 
00174 #ifdef TE_PE
00175 /* PE weak symbols need USE_UNIQUE.  */
00176 #define USE_UNIQUE 1
00177 
00178 #define obj_set_weak_hook pecoff_obj_set_weak_hook
00179 #define obj_clear_weak_hook pecoff_obj_clear_weak_hook
00180 #endif
00181 
00182 #ifndef OBJ_COFF_MAX_AUXENTRIES
00183 #define OBJ_COFF_MAX_AUXENTRIES 1
00184 #endif
00185 
00186 #define obj_symbol_new_hook coff_obj_symbol_new_hook
00187 #define obj_symbol_clone_hook coff_obj_symbol_clone_hook
00188 #define obj_read_begin_hook coff_obj_read_begin_hook
00189 
00190 #include "bfd/libcoff.h"
00191 
00192 #define OUTPUT_FLAVOR bfd_target_coff_flavour
00193 
00194 /* Alter the field names, for now, until we've fixed up the other
00195    references to use the new name.  */
00196 #ifdef TC_I960
00197 #define TC_SYMFIELD_TYPE    symbolS *
00198 #define sy_tc               bal
00199 #endif
00200 
00201 #define OBJ_SYMFIELD_TYPE   unsigned long
00202 #define sy_obj                     sy_flags
00203 
00204 /* We can't use the predefined section symbols in bfd/section.c, as
00205    COFF symbols have extra fields.  See bfd/libcoff.h:coff_symbol_type.  */
00206 #ifndef obj_sec_sym_ok_for_reloc
00207 #define obj_sec_sym_ok_for_reloc(SEC)     ((SEC)->owner != 0)
00208 #endif
00209 
00210 #define SYM_AUXENT(S) \
00211   (&coffsymbol (symbol_get_bfdsym (S))->native[1].u.auxent)
00212 #define SYM_AUXINFO(S) \
00213   (&coffsymbol (symbol_get_bfdsym (S))->native[1])
00214 
00215 /* The number of auxiliary entries.  */
00216 #define S_GET_NUMBER_AUXILIARY(s) \
00217   (coffsymbol (symbol_get_bfdsym (s))->native->u.syment.n_numaux)
00218 /* The number of auxiliary entries.  */
00219 #define S_SET_NUMBER_AUXILIARY(s, v)      (S_GET_NUMBER_AUXILIARY (s) = (v))
00220 
00221 /* True if a symbol name is in the string table, i.e. its length is > 8.  */
00222 #define S_IS_STRING(s)             (strlen (S_GET_NAME (s)) > 8 ? 1 : 0)
00223 
00224 /* Auxiliary entry macros. SA_ stands for symbol auxiliary.  */
00225 /* Omit the tv related fields.  */
00226 /* Accessors.  */
00227 
00228 #define SA_GET_SYM_TAGNDX(s)       (SYM_AUXENT (s)->x_sym.x_tagndx.l)
00229 #define SA_GET_SYM_LNNO(s)  (SYM_AUXENT (s)->x_sym.x_misc.x_lnsz.x_lnno)
00230 #define SA_GET_SYM_SIZE(s)  (SYM_AUXENT (s)->x_sym.x_misc.x_lnsz.x_size)
00231 #define SA_GET_SYM_FSIZE(s) (SYM_AUXENT (s)->x_sym.x_misc.x_fsize)
00232 #define SA_GET_SYM_LNNOPTR(s)      (SYM_AUXENT (s)->x_sym.x_fcnary.x_fcn.x_lnnoptr)
00233 #define SA_GET_SYM_ENDNDX(s)       (SYM_AUXENT (s)->x_sym.x_fcnary.x_fcn.x_endndx)
00234 #define SA_GET_SYM_DIMEN(s,i)      (SYM_AUXENT (s)->x_sym.x_fcnary.x_ary.x_dimen[(i)])
00235 #define SA_GET_FILE_FNAME(s)       (SYM_AUXENT (s)->x_file.x_fname)
00236 #define SA_GET_SCN_SCNLEN(s)       (SYM_AUXENT (s)->x_scn.x_scnlen)
00237 #define SA_GET_SCN_NRELOC(s)       (SYM_AUXENT (s)->x_scn.x_nreloc)
00238 #define SA_GET_SCN_NLINNO(s)       (SYM_AUXENT (s)->x_scn.x_nlinno)
00239 
00240 #define SA_SET_SYM_LNNO(s,v)       (SYM_AUXENT (s)->x_sym.x_misc.x_lnsz.x_lnno = (v))
00241 #define SA_SET_SYM_SIZE(s,v)       (SYM_AUXENT (s)->x_sym.x_misc.x_lnsz.x_size = (v))
00242 #define SA_SET_SYM_FSIZE(s,v)      (SYM_AUXENT (s)->x_sym.x_misc.x_fsize = (v))
00243 #define SA_SET_SYM_LNNOPTR(s,v)    (SYM_AUXENT (s)->x_sym.x_fcnary.x_fcn.x_lnnoptr = (v))
00244 #define SA_SET_SYM_DIMEN(s,i,v)    (SYM_AUXENT (s)->x_sym.x_fcnary.x_ary.x_dimen[(i)] = (v))
00245 #define SA_SET_FILE_FNAME(s,v)     strncpy (SYM_AUXENT (s)->x_file.x_fname, (v), FILNMLEN)
00246 #define SA_SET_SCN_SCNLEN(s,v)     (SYM_AUXENT (s)->x_scn.x_scnlen = (v))
00247 #define SA_SET_SCN_NRELOC(s,v)     (SYM_AUXENT (s)->x_scn.x_nreloc = (v))
00248 #define SA_SET_SCN_NLINNO(s,v)     (SYM_AUXENT (s)->x_scn.x_nlinno = (v))
00249 
00250 /* Internal use only definitions. SF_ stands for symbol flags.
00251 
00252    These values can be assigned to sy_symbol.ost_flags field of a symbolS.
00253 
00254    You'll break i960 if you shift the SYSPROC bits anywhere else.  for
00255    more on the balname/callname hack, see tc-i960.h.  b.out is done
00256    differently.  */
00257 
00258 #define SF_I960_MASK 0x000001ff    /* Bits 0-8 are used by the i960 port.  */
00259 #define SF_SYSPROC   0x0000003f    /* bits 0-5 are used to store the sysproc number.  */
00260 #define SF_IS_SYSPROC       0x00000040    /* bit 6 marks symbols that are sysprocs.  */
00261 #define SF_BALNAME   0x00000080    /* bit 7 marks BALNAME symbols.  */
00262 #define SF_CALLNAME  0x00000100    /* bit 8 marks CALLNAME symbols.  */
00263                               
00264 #define SF_NORMAL_MASK      0x0000ffff    /* bits 12-15 are general purpose.  */
00265                               
00266 #define SF_STATICS   0x00001000    /* Mark the .text & all symbols.  */
00267 #define SF_DEFINED   0x00002000    /* Symbol is defined in this file.  */
00268 #define SF_STRING    0x00004000    /* Symbol name length > 8.  */
00269 #define SF_LOCAL     0x00008000    /* Symbol must not be emitted.  */
00270                               
00271 #define SF_DEBUG_MASK       0xffff0000    /* bits 16-31 are debug info.  */
00272                               
00273 #define SF_FUNCTION  0x00010000    /* The symbol is a function.  */
00274 #define SF_PROCESS   0x00020000    /* Process symbol before write.  */
00275 #define SF_TAGGED    0x00040000    /* Is associated with a tag.  */
00276 #define SF_TAG              0x00080000    /* Is a tag.  */
00277 #define SF_DEBUG     0x00100000    /* Is in debug or abs section.  */
00278 #define SF_GET_SEGMENT      0x00200000    /* Get the section of the forward symbol.  */
00279 /* All other bits are unused.  */
00280 
00281 /* Accessors.  */
00282 #define SF_GET(s)           (* symbol_get_obj (s))
00283 #define SF_GET_DEBUG(s)            (symbol_get_bfdsym (s)->flags & BSF_DEBUGGING)
00284 #define SF_SET_DEBUG(s)            (symbol_get_bfdsym (s)->flags |= BSF_DEBUGGING)
00285 #define SF_GET_NORMAL_FIELD(s)     (SF_GET (s) & SF_NORMAL_MASK)
00286 #define SF_GET_DEBUG_FIELD(s)      (SF_GET (s) & SF_DEBUG_MASK)
00287 #define SF_GET_FILE(s)             (SF_GET (s) & SF_FILE)
00288 #define SF_GET_STATICS(s)   (SF_GET (s) & SF_STATICS)
00289 #define SF_GET_DEFINED(s)   (SF_GET (s) & SF_DEFINED)
00290 #define SF_GET_STRING(s)    (SF_GET (s) & SF_STRING)
00291 #define SF_GET_LOCAL(s)            (SF_GET (s) & SF_LOCAL)
00292 #define SF_GET_FUNCTION(s)      (SF_GET (s) & SF_FUNCTION)
00293 #define SF_GET_PROCESS(s)   (SF_GET (s) & SF_PROCESS)
00294 #define SF_GET_TAGGED(s)    (SF_GET (s) & SF_TAGGED)
00295 #define SF_GET_TAG(s)              (SF_GET (s) & SF_TAG)
00296 #define SF_GET_GET_SEGMENT(s)      (SF_GET (s) & SF_GET_SEGMENT)
00297 #define SF_GET_I960(s)             (SF_GET (s) & SF_I960_MASK) /* Used by i960.  */
00298 #define SF_GET_BALNAME(s)   (SF_GET (s) & SF_BALNAME)   /* Used by i960.  */
00299 #define SF_GET_CALLNAME(s)  (SF_GET (s) & SF_CALLNAME)  /* Used by i960.  */
00300 #define SF_GET_IS_SYSPROC(s)       (SF_GET (s) & SF_IS_SYSPROC)       /* Used by i960.  */
00301 #define SF_GET_SYSPROC(s)   (SF_GET (s) & SF_SYSPROC)   /* Used by i960.  */
00302 
00303 /* Modifiers.  */
00304 #define SF_SET(s,v)         (SF_GET (s) = (v))
00305 #define SF_SET_NORMAL_FIELD(s,v)(SF_GET (s) |= ((v) & SF_NORMAL_MASK))
00306 #define SF_SET_DEBUG_FIELD(s,v)    (SF_GET (s) |= ((v) & SF_DEBUG_MASK))
00307 #define SF_SET_FILE(s)             (SF_GET (s) |= SF_FILE)
00308 #define SF_SET_STATICS(s)   (SF_GET (s) |= SF_STATICS)
00309 #define SF_SET_DEFINED(s)   (SF_GET (s) |= SF_DEFINED)
00310 #define SF_SET_STRING(s)    (SF_GET (s) |= SF_STRING)
00311 #define SF_SET_LOCAL(s)            (SF_GET (s) |= SF_LOCAL)
00312 #define SF_CLEAR_LOCAL(s)   (SF_GET (s) &= ~SF_LOCAL)
00313 #define SF_SET_FUNCTION(s)      (SF_GET (s) |= SF_FUNCTION)
00314 #define SF_SET_PROCESS(s)   (SF_GET (s) |= SF_PROCESS)
00315 #define SF_SET_TAGGED(s)    (SF_GET (s) |= SF_TAGGED)
00316 #define SF_SET_TAG(s)              (SF_GET (s) |= SF_TAG)
00317 #define SF_SET_GET_SEGMENT(s)      (SF_GET (s) |= SF_GET_SEGMENT)
00318 #define SF_SET_I960(s,v)    (SF_GET (s) |= ((v) & SF_I960_MASK))      /* Used by i960.  */
00319 #define SF_SET_BALNAME(s)   (SF_GET (s) |= SF_BALNAME)         /* Used by i960.  */
00320 #define SF_SET_CALLNAME(s)  (SF_GET (s) |= SF_CALLNAME)        /* Used by i960.  */
00321 #define SF_SET_IS_SYSPROC(s)       (SF_GET (s) |= SF_IS_SYSPROC)             /* Used by i960.  */
00322 #define SF_SET_SYSPROC(s,v) (SF_GET (s) |= ((v) & SF_SYSPROC)) /* Used by i960.  */
00323 
00324 
00325 /*  Line number handling.  */
00326 extern int text_lineno_number;
00327 extern int coff_line_base;
00328 extern int coff_n_line_nos;
00329 extern symbolS *coff_last_function;
00330 
00331 #define obj_emit_lineno(WHERE, LINE, FILE_START) abort ()
00332 #define obj_app_file(name, app)      c_dot_file_symbol (name, app)
00333 #define obj_frob_symbol(S,P)            coff_frob_symbol (S, & P)
00334 #define obj_frob_section(S)      coff_frob_section (S)
00335 #define obj_frob_file_after_relocs() coff_frob_file_after_relocs ()
00336 #ifndef obj_adjust_symtab
00337 #define obj_adjust_symtab()      coff_adjust_symtab ()
00338 #endif
00339 
00340 /* Forward the segment of a forwarded symbol, handle assignments that
00341    just copy symbol values, etc.  */
00342 #ifndef OBJ_COPY_SYMBOL_ATTRIBUTES
00343 #ifndef TE_I386AIX
00344 #define OBJ_COPY_SYMBOL_ATTRIBUTES(dest, src) \
00345   (SF_GET_GET_SEGMENT (dest) \
00346    ? (S_SET_SEGMENT (dest, S_GET_SEGMENT (src)), 0) \
00347    : 0)
00348 #else
00349 #define OBJ_COPY_SYMBOL_ATTRIBUTES(dest, src) \
00350   (SF_GET_GET_SEGMENT (dest) && S_GET_SEGMENT (dest) == SEG_UNKNOWN \
00351    ? (S_SET_SEGMENT (dest, S_GET_SEGMENT (src)), 0) \
00352    : 0)
00353 #endif
00354 #endif
00355 
00356 /* Sanity check.  */
00357 
00358 #ifdef TC_I960
00359 #ifndef C_LEAFSTAT
00360 hey ! Where is the C_LEAFSTAT definition ? i960 - coff support is depending on it.
00361 #endif /* no C_LEAFSTAT */
00362 #endif /* TC_I960 */
00363 
00364 extern const pseudo_typeS coff_pseudo_table[];
00365 
00366 #ifndef obj_pop_insert
00367 #define obj_pop_insert() pop_insert (coff_pseudo_table)
00368 #endif
00369 
00370 /* In COFF, if a symbol is defined using .def/.val SYM/.endef, it's OK
00371    to redefine the symbol later on.  This can happen if C symbols use
00372    a prefix, and a symbol is defined both with and without the prefix,
00373    as in start/_start/__start in gcc/libgcc1-test.c.  */
00374 #define RESOLVE_SYMBOL_REDEFINITION(sym)         \
00375 (SF_GET_GET_SEGMENT (sym)                        \
00376  ? (sym->sy_frag = frag_now,                            \
00377     S_SET_VALUE (sym, frag_now_fix ()),                 \
00378     S_SET_SEGMENT (sym, now_seg),                \
00379     0)                                           \
00380  : 0)
00381 
00382 /* Stabs in a coff file go into their own section.  */
00383 #define SEPARATE_STAB_SECTIONS 1
00384 
00385 /* We need 12 bytes at the start of the section to hold some initial
00386    information.  */
00387 #define INIT_STAB_SECTION(seg) obj_coff_init_stab_section (seg)
00388 
00389 /* Store the number of relocations in the section aux entry.  */
00390 #define SET_SECTION_RELOCS(sec, relocs, n) \
00391   SA_SET_SCN_NRELOC (section_symbol (sec), n)
00392 
00393 #define obj_app_file(name, app) c_dot_file_symbol (name, app)
00394 
00395 extern int  S_SET_DATA_TYPE              (symbolS *, int);
00396 extern int  S_SET_STORAGE_CLASS          (symbolS *, int);
00397 extern int  S_GET_STORAGE_CLASS          (symbolS *);
00398 extern void SA_SET_SYM_ENDNDX            (symbolS *, symbolS *);
00399 extern void coff_add_linesym             (symbolS *);
00400 extern void c_dot_file_symbol            (const char *, int);
00401 extern void coff_frob_symbol             (symbolS *, int *);
00402 extern void coff_adjust_symtab           (void);
00403 extern void coff_frob_section            (segT);
00404 extern void coff_adjust_section_syms     (bfd *, asection *, void *);
00405 extern void coff_frob_file_after_relocs  (void);
00406 extern void coff_obj_symbol_new_hook     (symbolS *);
00407 extern void coff_obj_symbol_clone_hook   (symbolS *, symbolS *);
00408 extern void coff_obj_read_begin_hook     (void);
00409 #ifdef TE_PE
00410 extern void pecoff_obj_set_weak_hook     (symbolS *);
00411 extern void pecoff_obj_clear_weak_hook   (symbolS *);
00412 #endif
00413 extern void obj_coff_section             (int);
00414 extern segT obj_coff_add_segment         (const char *);
00415 extern void obj_coff_section             (int);
00416 extern void c_dot_file_symbol            (const char *, int);
00417 extern segT s_get_segment                (symbolS *);
00418 #ifndef tc_coff_symbol_emit_hook
00419 extern void tc_coff_symbol_emit_hook     (symbolS *);
00420 #endif
00421 extern void obj_coff_pe_handle_link_once (void);
00422 extern void obj_coff_init_stab_section   (segT);
00423 extern void c_section_header             (struct internal_scnhdr *,
00424                                      char *, long, long, long, long,
00425                                      long, long, long, long);
00426 #endif /* OBJ_FORMAT_H */