gas/
[deliverable/binutils-gdb.git] / gas / config / obj-coff.h
CommitLineData
252b5132 1/* coff object file format
f7e42eb4 2 Copyright 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
ebd1c875 3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
252b5132
RH
4 Free Software Foundation, Inc.
5
6 This file is part of GAS.
7
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
4b4da160
NC
20 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
21 02110-1301, USA. */
252b5132
RH
22
23#ifndef OBJ_FORMAT_H
24#define OBJ_FORMAT_H
25
26#define OBJ_COFF 1
27
252b5132
RH
28#include "targ-cpu.h"
29
252b5132 30/* This internal_lineno crap is to stop namespace pollution from the
dcd619be 31 bfd internal coff headerfile. */
252b5132
RH
32#define internal_lineno bfd_internal_lineno
33#include "coff/internal.h"
34#undef internal_lineno
35
36/* CPU-specific setup: */
37
38#ifdef TC_ARM
39#include "coff/arm.h"
40#ifndef TARGET_FORMAT
41#define TARGET_FORMAT "coff-arm"
42#endif
43#endif
44
45#ifdef TC_PPC
46#ifdef TE_PE
47#include "coff/powerpc.h"
48#else
49#include "coff/rs6000.h"
50#endif
51#endif
52
53#ifdef TC_SPARC
54#include "coff/sparc.h"
55#endif
56
57#ifdef TC_I386
99ad8390
NC
58#ifndef TE_PEP
59#include "coff/x86_64.h"
60#else
252b5132 61#include "coff/i386.h"
99ad8390 62#endif
252b5132
RH
63
64#ifdef TE_PE
99ad8390
NC
65#ifdef TE_PEP
66extern const char * x86_64_target_format (void);
67#define TARGET_FORMAT x86_64_target_format ()
68#define COFF_TARGET_FORMAT "pe-x86-64"
69#else
252b5132
RH
70#define TARGET_FORMAT "pe-i386"
71#endif
99ad8390 72#endif
252b5132
RH
73
74#ifndef TARGET_FORMAT
99ad8390
NC
75#ifdef TE_PEP
76#define TARGET_FORMAT "coff-x86-64"
77#else
252b5132
RH
78#define TARGET_FORMAT "coff-i386"
79#endif
80#endif
99ad8390 81#endif
252b5132
RH
82
83#ifdef TC_M68K
84#include "coff/m68k.h"
85#ifndef TARGET_FORMAT
86#define TARGET_FORMAT "coff-m68k"
87#endif
88#endif
89
3b16e843
NC
90#ifdef TC_OR32
91#include "coff/or32.h"
92#define TARGET_FORMAT "coff-or32-big"
93#endif
94
252b5132
RH
95#ifdef TC_I960
96#include "coff/i960.h"
97#define TARGET_FORMAT "coff-Intel-little"
98#endif
99
3c9b82ba
NC
100#ifdef TC_Z80
101#include "coff/z80.h"
102#define TARGET_FORMAT "coff-z80"
103#endif
104
252b5132
RH
105#ifdef TC_Z8K
106#include "coff/z8k.h"
107#define TARGET_FORMAT "coff-z8k"
108#endif
109
110#ifdef TC_H8300
111#include "coff/h8300.h"
112#define TARGET_FORMAT "coff-h8300"
113#endif
114
115#ifdef TC_H8500
116#include "coff/h8500.h"
117#define TARGET_FORMAT "coff-h8500"
118#endif
119
7499d566
NC
120#ifdef TC_MAXQ20
121#include "coff/maxq.h"
122#define TARGET_FORMAT "coff-maxq"
123#endif
124
252b5132 125#ifdef TC_SH
056350c6
NC
126
127#ifdef TE_PE
128#define COFF_WITH_PE
129#endif
130
252b5132 131#include "coff/sh.h"
056350c6
NC
132
133#ifdef TE_PE
134#define TARGET_FORMAT "pe-shl"
135#else
94f592af 136
252b5132 137#define TARGET_FORMAT \
a245a9aa 138 (!target_big_endian \
252b5132
RH
139 ? (sh_small ? "coff-shl-small" : "coff-shl") \
140 : (sh_small ? "coff-sh-small" : "coff-sh"))
94f592af 141
252b5132 142#endif
056350c6
NC
143#endif
144
145#ifdef TC_MIPS
146#define COFF_WITH_PE
147#include "coff/mipspe.h"
148#undef TARGET_FORMAT
149#define TARGET_FORMAT "pe-mips"
150#endif
252b5132 151
252b5132
RH
152#ifdef TC_TIC30
153#include "coff/tic30.h"
154#define TARGET_FORMAT "coff-tic30"
155#endif
156
026df7c5
NC
157#ifdef TC_TIC4X
158#include "coff/tic4x.h"
be33c5dd 159#define TARGET_FORMAT "coff2-tic4x"
026df7c5
NC
160#endif
161
39bec121
TW
162#ifdef TC_TIC54X
163#include "coff/tic54x.h"
164#define TARGET_FORMAT "coff1-c54x"
165#endif
166
252b5132
RH
167#ifdef TC_MCORE
168#include "coff/mcore.h"
169#ifndef TARGET_FORMAT
170#define TARGET_FORMAT "pe-mcore"
171#endif
172#endif
173
977cdf5a
NC
174#ifdef TE_PE
175/* PE weak symbols need USE_UNIQUE. */
176#define USE_UNIQUE 1
06e77878
AO
177
178#define obj_set_weak_hook pecoff_obj_set_weak_hook
179#define obj_clear_weak_hook pecoff_obj_clear_weak_hook
977cdf5a
NC
180#endif
181
252b5132
RH
182#ifndef OBJ_COFF_MAX_AUXENTRIES
183#define OBJ_COFF_MAX_AUXENTRIES 1
977cdf5a 184#endif
252b5132 185
252b5132 186#define obj_symbol_new_hook coff_obj_symbol_new_hook
6a2b6326 187#define obj_symbol_clone_hook coff_obj_symbol_clone_hook
252b5132
RH
188#define obj_read_begin_hook coff_obj_read_begin_hook
189
252b5132
RH
190#include "bfd/libcoff.h"
191
192#define OUTPUT_FLAVOR bfd_target_coff_flavour
193
252b5132
RH
194/* Alter the field names, for now, until we've fixed up the other
195 references to use the new name. */
196#ifdef TC_I960
49309057 197#define TC_SYMFIELD_TYPE symbolS *
252b5132
RH
198#define sy_tc bal
199#endif
200
201#define OBJ_SYMFIELD_TYPE unsigned long
202#define sy_obj sy_flags
203
a161fe53
AM
204/* We can't use the predefined section symbols in bfd/section.c, as
205 COFF symbols have extra fields. See bfd/libcoff.h:coff_symbol_type. */
206#ifndef obj_sec_sym_ok_for_reloc
207#define obj_sec_sym_ok_for_reloc(SEC) ((SEC)->owner != 0)
208#endif
209
49309057
ILT
210#define SYM_AUXENT(S) \
211 (&coffsymbol (symbol_get_bfdsym (S))->native[1].u.auxent)
212#define SYM_AUXINFO(S) \
213 (&coffsymbol (symbol_get_bfdsym (S))->native[1])
252b5132 214
3b16e843 215/* The number of auxiliary entries. */
49309057
ILT
216#define S_GET_NUMBER_AUXILIARY(s) \
217 (coffsymbol (symbol_get_bfdsym (s))->native->u.syment.n_numaux)
3b16e843 218/* The number of auxiliary entries. */
a5324a3e 219#define S_SET_NUMBER_AUXILIARY(s, v) (S_GET_NUMBER_AUXILIARY (s) = (v))
252b5132 220
dcd619be 221/* True if a symbol name is in the string table, i.e. its length is > 8. */
a5324a3e 222#define S_IS_STRING(s) (strlen (S_GET_NAME (s)) > 8 ? 1 : 0)
252b5132 223
3b16e843
NC
224/* Auxiliary entry macros. SA_ stands for symbol auxiliary. */
225/* Omit the tv related fields. */
226/* Accessors. */
252b5132
RH
227
228#define SA_GET_SYM_TAGNDX(s) (SYM_AUXENT (s)->x_sym.x_tagndx.l)
229#define SA_GET_SYM_LNNO(s) (SYM_AUXENT (s)->x_sym.x_misc.x_lnsz.x_lnno)
230#define SA_GET_SYM_SIZE(s) (SYM_AUXENT (s)->x_sym.x_misc.x_lnsz.x_size)
231#define SA_GET_SYM_FSIZE(s) (SYM_AUXENT (s)->x_sym.x_misc.x_fsize)
232#define SA_GET_SYM_LNNOPTR(s) (SYM_AUXENT (s)->x_sym.x_fcnary.x_fcn.x_lnnoptr)
233#define SA_GET_SYM_ENDNDX(s) (SYM_AUXENT (s)->x_sym.x_fcnary.x_fcn.x_endndx)
234#define SA_GET_SYM_DIMEN(s,i) (SYM_AUXENT (s)->x_sym.x_fcnary.x_ary.x_dimen[(i)])
235#define SA_GET_FILE_FNAME(s) (SYM_AUXENT (s)->x_file.x_fname)
236#define SA_GET_SCN_SCNLEN(s) (SYM_AUXENT (s)->x_scn.x_scnlen)
237#define SA_GET_SCN_NRELOC(s) (SYM_AUXENT (s)->x_scn.x_nreloc)
238#define SA_GET_SCN_NLINNO(s) (SYM_AUXENT (s)->x_scn.x_nlinno)
239
a5324a3e
NC
240#define SA_SET_SYM_LNNO(s,v) (SYM_AUXENT (s)->x_sym.x_misc.x_lnsz.x_lnno = (v))
241#define SA_SET_SYM_SIZE(s,v) (SYM_AUXENT (s)->x_sym.x_misc.x_lnsz.x_size = (v))
242#define SA_SET_SYM_FSIZE(s,v) (SYM_AUXENT (s)->x_sym.x_misc.x_fsize = (v))
243#define SA_SET_SYM_LNNOPTR(s,v) (SYM_AUXENT (s)->x_sym.x_fcnary.x_fcn.x_lnnoptr = (v))
244#define SA_SET_SYM_DIMEN(s,i,v) (SYM_AUXENT (s)->x_sym.x_fcnary.x_ary.x_dimen[(i)] = (v))
245#define SA_SET_FILE_FNAME(s,v) strncpy (SYM_AUXENT (s)->x_file.x_fname, (v), FILNMLEN)
246#define SA_SET_SCN_SCNLEN(s,v) (SYM_AUXENT (s)->x_scn.x_scnlen = (v))
247#define SA_SET_SCN_NRELOC(s,v) (SYM_AUXENT (s)->x_scn.x_nreloc = (v))
248#define SA_SET_SCN_NLINNO(s,v) (SYM_AUXENT (s)->x_scn.x_nlinno = (v))
252b5132 249
3b16e843 250/* Internal use only definitions. SF_ stands for symbol flags.
5d6255fe 251
3b16e843 252 These values can be assigned to sy_symbol.ost_flags field of a symbolS.
5d6255fe 253
3b16e843
NC
254 You'll break i960 if you shift the SYSPROC bits anywhere else. for
255 more on the balname/callname hack, see tc-i960.h. b.out is done
256 differently. */
252b5132 257
a5324a3e
NC
258#define SF_I960_MASK 0x000001ff /* Bits 0-8 are used by the i960 port. */
259#define SF_SYSPROC 0x0000003f /* bits 0-5 are used to store the sysproc number. */
260#define SF_IS_SYSPROC 0x00000040 /* bit 6 marks symbols that are sysprocs. */
261#define SF_BALNAME 0x00000080 /* bit 7 marks BALNAME symbols. */
262#define SF_CALLNAME 0x00000100 /* bit 8 marks CALLNAME symbols. */
263
264#define SF_NORMAL_MASK 0x0000ffff /* bits 12-15 are general purpose. */
265
266#define SF_STATICS 0x00001000 /* Mark the .text & all symbols. */
267#define SF_DEFINED 0x00002000 /* Symbol is defined in this file. */
268#define SF_STRING 0x00004000 /* Symbol name length > 8. */
269#define SF_LOCAL 0x00008000 /* Symbol must not be emitted. */
270
271#define SF_DEBUG_MASK 0xffff0000 /* bits 16-31 are debug info. */
272
273#define SF_FUNCTION 0x00010000 /* The symbol is a function. */
274#define SF_PROCESS 0x00020000 /* Process symbol before write. */
275#define SF_TAGGED 0x00040000 /* Is associated with a tag. */
276#define SF_TAG 0x00080000 /* Is a tag. */
277#define SF_DEBUG 0x00100000 /* Is in debug or abs section. */
278#define SF_GET_SEGMENT 0x00200000 /* Get the section of the forward symbol. */
dcd619be 279/* All other bits are unused. */
252b5132 280
3b16e843 281/* Accessors. */
a5324a3e 282#define SF_GET(s) (* symbol_get_obj (s))
49309057
ILT
283#define SF_GET_DEBUG(s) (symbol_get_bfdsym (s)->flags & BSF_DEBUGGING)
284#define SF_SET_DEBUG(s) (symbol_get_bfdsym (s)->flags |= BSF_DEBUGGING)
252b5132
RH
285#define SF_GET_NORMAL_FIELD(s) (SF_GET (s) & SF_NORMAL_MASK)
286#define SF_GET_DEBUG_FIELD(s) (SF_GET (s) & SF_DEBUG_MASK)
287#define SF_GET_FILE(s) (SF_GET (s) & SF_FILE)
288#define SF_GET_STATICS(s) (SF_GET (s) & SF_STATICS)
289#define SF_GET_DEFINED(s) (SF_GET (s) & SF_DEFINED)
290#define SF_GET_STRING(s) (SF_GET (s) & SF_STRING)
291#define SF_GET_LOCAL(s) (SF_GET (s) & SF_LOCAL)
292#define SF_GET_FUNCTION(s) (SF_GET (s) & SF_FUNCTION)
293#define SF_GET_PROCESS(s) (SF_GET (s) & SF_PROCESS)
294#define SF_GET_TAGGED(s) (SF_GET (s) & SF_TAGGED)
295#define SF_GET_TAG(s) (SF_GET (s) & SF_TAG)
296#define SF_GET_GET_SEGMENT(s) (SF_GET (s) & SF_GET_SEGMENT)
a5324a3e
NC
297#define SF_GET_I960(s) (SF_GET (s) & SF_I960_MASK) /* Used by i960. */
298#define SF_GET_BALNAME(s) (SF_GET (s) & SF_BALNAME) /* Used by i960. */
299#define SF_GET_CALLNAME(s) (SF_GET (s) & SF_CALLNAME) /* Used by i960. */
300#define SF_GET_IS_SYSPROC(s) (SF_GET (s) & SF_IS_SYSPROC) /* Used by i960. */
301#define SF_GET_SYSPROC(s) (SF_GET (s) & SF_SYSPROC) /* Used by i960. */
252b5132 302
3b16e843 303/* Modifiers. */
252b5132 304#define SF_SET(s,v) (SF_GET (s) = (v))
a5324a3e 305#define SF_SET_NORMAL_FIELD(s,v)(SF_GET (s) |= ((v) & SF_NORMAL_MASK))
252b5132
RH
306#define SF_SET_DEBUG_FIELD(s,v) (SF_GET (s) |= ((v) & SF_DEBUG_MASK))
307#define SF_SET_FILE(s) (SF_GET (s) |= SF_FILE)
308#define SF_SET_STATICS(s) (SF_GET (s) |= SF_STATICS)
309#define SF_SET_DEFINED(s) (SF_GET (s) |= SF_DEFINED)
310#define SF_SET_STRING(s) (SF_GET (s) |= SF_STRING)
311#define SF_SET_LOCAL(s) (SF_GET (s) |= SF_LOCAL)
312#define SF_CLEAR_LOCAL(s) (SF_GET (s) &= ~SF_LOCAL)
313#define SF_SET_FUNCTION(s) (SF_GET (s) |= SF_FUNCTION)
314#define SF_SET_PROCESS(s) (SF_GET (s) |= SF_PROCESS)
315#define SF_SET_TAGGED(s) (SF_GET (s) |= SF_TAGGED)
316#define SF_SET_TAG(s) (SF_GET (s) |= SF_TAG)
317#define SF_SET_GET_SEGMENT(s) (SF_GET (s) |= SF_GET_SEGMENT)
a5324a3e
NC
318#define SF_SET_I960(s,v) (SF_GET (s) |= ((v) & SF_I960_MASK)) /* Used by i960. */
319#define SF_SET_BALNAME(s) (SF_GET (s) |= SF_BALNAME) /* Used by i960. */
320#define SF_SET_CALLNAME(s) (SF_GET (s) |= SF_CALLNAME) /* Used by i960. */
321#define SF_SET_IS_SYSPROC(s) (SF_GET (s) |= SF_IS_SYSPROC) /* Used by i960. */
322#define SF_SET_SYSPROC(s,v) (SF_GET (s) |= ((v) & SF_SYSPROC)) /* Used by i960. */
252b5132 323
a5324a3e
NC
324
325/* Line number handling. */
252b5132
RH
326extern int text_lineno_number;
327extern int coff_line_base;
328extern int coff_n_line_nos;
a5324a3e 329extern symbolS *coff_last_function;
252b5132 330
a5324a3e
NC
331#define obj_emit_lineno(WHERE, LINE, FILE_START) abort ()
332#define obj_app_file(name, app) c_dot_file_symbol (name, app)
333#define obj_frob_symbol(S,P) coff_frob_symbol (S, & P)
334#define obj_frob_section(S) coff_frob_section (S)
335#define obj_frob_file_after_relocs() coff_frob_file_after_relocs ()
252b5132 336#ifndef obj_adjust_symtab
a5324a3e 337#define obj_adjust_symtab() coff_adjust_symtab ()
252b5132 338#endif
252b5132
RH
339
340/* Forward the segment of a forwarded symbol, handle assignments that
341 just copy symbol values, etc. */
2c1c4c62 342#ifndef OBJ_COPY_SYMBOL_ATTRIBUTES
252b5132 343#ifndef TE_I386AIX
a5324a3e 344#define OBJ_COPY_SYMBOL_ATTRIBUTES(dest, src) \
252b5132
RH
345 (SF_GET_GET_SEGMENT (dest) \
346 ? (S_SET_SEGMENT (dest, S_GET_SEGMENT (src)), 0) \
347 : 0)
348#else
a5324a3e 349#define OBJ_COPY_SYMBOL_ATTRIBUTES(dest, src) \
252b5132
RH
350 (SF_GET_GET_SEGMENT (dest) && S_GET_SEGMENT (dest) == SEG_UNKNOWN \
351 ? (S_SET_SEGMENT (dest, S_GET_SEGMENT (src)), 0) \
352 : 0)
353#endif
2c1c4c62 354#endif
252b5132 355
3b16e843 356/* Sanity check. */
252b5132
RH
357
358#ifdef TC_I960
359#ifndef C_LEAFSTAT
360hey ! Where is the C_LEAFSTAT definition ? i960 - coff support is depending on it.
361#endif /* no C_LEAFSTAT */
362#endif /* TC_I960 */
363
4c63da97
AM
364extern const pseudo_typeS coff_pseudo_table[];
365
366#ifndef obj_pop_insert
367#define obj_pop_insert() pop_insert (coff_pseudo_table)
368#endif
369
252b5132
RH
370/* In COFF, if a symbol is defined using .def/.val SYM/.endef, it's OK
371 to redefine the symbol later on. This can happen if C symbols use
372 a prefix, and a symbol is defined both with and without the prefix,
373 as in start/_start/__start in gcc/libgcc1-test.c. */
374#define RESOLVE_SYMBOL_REDEFINITION(sym) \
375(SF_GET_GET_SEGMENT (sym) \
376 ? (sym->sy_frag = frag_now, \
377 S_SET_VALUE (sym, frag_now_fix ()), \
378 S_SET_SEGMENT (sym, now_seg), \
379 0) \
380 : 0)
381
382/* Stabs in a coff file go into their own section. */
383#define SEPARATE_STAB_SECTIONS 1
384
385/* We need 12 bytes at the start of the section to hold some initial
386 information. */
252b5132
RH
387#define INIT_STAB_SECTION(seg) obj_coff_init_stab_section (seg)
388
945a1a6b
ILT
389/* Store the number of relocations in the section aux entry. */
390#define SET_SECTION_RELOCS(sec, relocs, n) \
391 SA_SET_SCN_NRELOC (section_symbol (sec), n)
392
a5324a3e
NC
393#define obj_app_file(name, app) c_dot_file_symbol (name, app)
394
a5324a3e
NC
395extern int S_SET_DATA_TYPE (symbolS *, int);
396extern int S_SET_STORAGE_CLASS (symbolS *, int);
397extern int S_GET_STORAGE_CLASS (symbolS *);
398extern void SA_SET_SYM_ENDNDX (symbolS *, symbolS *);
399extern void coff_add_linesym (symbolS *);
400extern void c_dot_file_symbol (const char *, int);
401extern void coff_frob_symbol (symbolS *, int *);
402extern void coff_adjust_symtab (void);
403extern void coff_frob_section (segT);
404extern void coff_adjust_section_syms (bfd *, asection *, void *);
405extern void coff_frob_file_after_relocs (void);
a5324a3e 406extern void coff_obj_symbol_new_hook (symbolS *);
6a2b6326 407extern void coff_obj_symbol_clone_hook (symbolS *, symbolS *);
a5324a3e 408extern void coff_obj_read_begin_hook (void);
06e77878
AO
409#ifdef TE_PE
410extern void pecoff_obj_set_weak_hook (symbolS *);
411extern void pecoff_obj_clear_weak_hook (symbolS *);
412#endif
a5324a3e
NC
413extern void obj_coff_section (int);
414extern segT obj_coff_add_segment (const char *);
415extern void obj_coff_section (int);
416extern void c_dot_file_symbol (const char *, int);
417extern segT s_get_segment (symbolS *);
36bfbdd3 418#ifndef tc_coff_symbol_emit_hook
a5324a3e 419extern void tc_coff_symbol_emit_hook (symbolS *);
36bfbdd3 420#endif
a5324a3e
NC
421extern void obj_coff_pe_handle_link_once (void);
422extern void obj_coff_init_stab_section (segT);
423extern void c_section_header (struct internal_scnhdr *,
424 char *, long, long, long, long,
425 long, long, long, long);
252b5132 426#endif /* OBJ_FORMAT_H */
This page took 0.330899 seconds and 4 git commands to generate.