* Changes to keep a full expression as the value of a symbol, not
[external/binutils.git] / gas / config / obj-coff.h
1 /* coff object file format
2    Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
3
4    This file is part of GAS.
5
6    GAS is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2, or (at your option)
9    any later version.
10
11    GAS is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with GAS; see the file COPYING.  If not, write to
18    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
19
20 #define OBJ_COFF 1
21
22 #include "targ-cpu.h"
23
24 #if defined (BFD_HEADERS) || defined (BFD_ASSEMBLER)
25
26 /* This internal_lineno crap is to stop namespace pollution from the
27    bfd internal coff headerfile. */
28
29 #include "bfd.h"
30 #define internal_lineno bfd_internal_lineno
31 #include "coff/internal.h"
32 #undef internal_lineno
33
34 #ifdef BFD_ASSEMBLER
35 #include "../bfd/libcoff.h"
36 #endif
37
38 #ifdef TC_A29K
39 #include "coff/a29k.h"
40
41 /*
42   #undef RELOC
43   #undef SYMENT
44   #undef AUXENT
45   #undef LINENO
46   #undef FILHDR
47   #undef SCNHDR
48   #define RELOC struct internal_reloc
49   #define SYMENT struct internal_syment
50   #define AUXENT union internal_auxent
51   #define SCNHDR struct internal_scnhdr
52   #define LINENO struct bfd_internal_lineno
53   #define AOUTHDR struct internal_aouthdr
54   #define FILHDR struct internal_filehdr
55   #define AOUTHDRSZ sizeof(struct external_aouthdr)
56   */
57 /*#define x_endndx x_endndx.l
58   #define x_tagndx x_tagndx.l*/
59 #define TARGET_FORMAT "coff-a29k-big"
60 extern bfd *stdoutput;
61
62 #endif /* TC_A29K */
63
64 #ifdef TC_I960
65 #include "coff/i960.h"
66 #define TARGET_FORMAT "coff-i960-big"
67 #endif
68
69 #ifdef TC_I386
70 #  include "coff/i386.h"
71 #  define TARGET_FORMAT "coff-i386"
72 extern bfd *stdoutput;
73
74 #endif /* TC_I386 */
75
76 #ifdef TC_M68K
77 #  include "coff/m68k.h"
78 #  define TARGET_FORMAT "coff-m68k"
79 #endif /* TC_M68K */
80
81 #else /* not BFD_HEADERS */
82
83 #ifdef USE_NATIVE_HEADERS
84 #include <filehdr.h>
85 #include <aouthdr.h>
86 #include <scnhdr.h>
87 #include <storclass.h>
88 #include <linenum.h>
89 #include <syms.h>
90 #include <reloc.h>
91 #include <sys/types.h>
92 #else /* not USE_NATIVE_HEADERS */
93 #include "coff_gnu.h"
94 #endif /* not USE_NATIVE_HEADERS */
95
96 #endif /* not BFD_HEADERS */
97
98 #ifndef BFD_ASSEMBLER
99 /* Define some processor dependent values according to the processor
100    we are on. */
101 #ifdef TC_M68K
102
103 #define BYTE_ORDERING           F_AR32W /* See filehdr.h for more info. */
104 #ifndef FILE_HEADER_MAGIC
105 #define FILE_HEADER_MAGIC       MC68MAGIC       /* ... */
106 #endif /* FILE_HEADER_MAGIC */
107
108 #endif /* TC_M68K */
109
110 #if defined(TC_I386)
111
112 #define BYTE_ORDERING           F_AR32WR        /* See filehdr.h for more info. */
113 #ifndef FILE_HEADER_MAGIC
114 #define FILE_HEADER_MAGIC       I386MAGIC       /* ... */
115 #endif /* FILE_HEADER_MAGIC */
116
117 #endif /* TC_I386 */
118
119 #if defined(TC_I960)
120
121 #define BYTE_ORDERING           F_AR32WR        /* See filehdr.h for more info. */
122 #ifndef FILE_HEADER_MAGIC
123 #define FILE_HEADER_MAGIC       I960ROMAGIC     /* ... */
124 #endif /* FILE_HEADER_MAGIC */
125
126 #endif /* TC_I960 */
127
128 #if defined(TC_A29K)
129
130 #define BYTE_ORDERING           F_AR32W /* big endian. */
131 #ifndef FILE_HEADER_MAGIC
132 #define FILE_HEADER_MAGIC       SIPFBOMAGIC
133 #endif /* FILE_HEADER_MAGIC */
134
135 #endif /* TC_A29K */
136
137 #ifndef OBJ_COFF_MAX_AUXENTRIES
138 #define OBJ_COFF_MAX_AUXENTRIES 1
139 #endif /* OBJ_COFF_MAX_AUXENTRIES */
140
141 extern const short seg_N_TYPE[];
142 extern const segT N_TYPE_seg[];
143
144 /* Magic number of paged executable. */
145 #define DEFAULT_MAGIC_NUMBER_FOR_OBJECT_FILE    (FILE_HEADER_MAGIC)
146
147 #ifndef BFD_HEADERS
148
149 /* Add these definitions to have a consistent convention for all the
150    types used in COFF format. */
151 #define AOUTHDR                 struct aouthdr
152 #define AOUTHDRSZ               sizeof(AOUTHDR)
153 #endif
154
155 #endif /* not BFD_ASSEMBLER */
156
157
158 /* SYMBOL TABLE */
159
160 /* targets may also set this */
161 #ifndef SYMBOLS_NEED_BACKPOINTERS
162 #define SYMBOLS_NEED_BACKPOINTERS 1
163 #endif /* SYMBOLS_NEED_BACKPOINTERS */
164
165 #ifdef BFD_ASSEMBLER
166
167 #ifdef TC_I960
168 #define I960_SYM_FIELDS         struct symbol *bal;
169 #else
170 #define I960_SYM_FIELDS
171 #endif
172
173 #define TARGET_SYMBOL_FIELDS    unsigned long sy_flags; I960_SYM_FIELDS
174
175 #ifndef OBJ_COFF_MAX_AUXENTRIES
176 #define OBJ_COFF_MAX_AUXENTRIES 1
177 #endif
178
179 #else
180
181 /* Symbol table entry data type */
182
183 typedef struct
184   {
185 #ifdef BFD_HEADERS
186     struct internal_syment ost_entry;   /* Basic symbol */
187     union internal_auxent ost_auxent[OBJ_COFF_MAX_AUXENTRIES];  /* Auxiliary entry. */
188 #else
189     SYMENT ost_entry;           /* Basic symbol */
190     AUXENT ost_auxent[OBJ_COFF_MAX_AUXENTRIES]; /* Auxiliary entry. */
191 #endif
192     unsigned int ost_flags;     /* obj_coff internal use only flags */
193   }
194 obj_symbol_type;
195 #endif /* ! BFD_ASSEMBLER */
196
197 #ifdef BFD_ASSEMBLER
198 #define SYM_AUXENT(S)   (&coffsymbol ((S)->bsym)->native[1].u.auxent)
199 #else
200 #define SYM_AUXENT(S)   (&(S)->sy_symbol.ost_auxent[0])
201 #endif
202
203 #define DO_NOT_STRIP    0
204 #define DO_STRIP        1
205
206 #ifndef BFD_ASSEMBLER
207
208 /* Symbol table macros and constants */
209
210 /* Possible and usefull section number in symbol table
211  * The values of TEXT, DATA and BSS may not be portable.
212  */
213
214 #define C_TEXT_SECTION          ((short)1)
215 #define C_DATA_SECTION          ((short)2)
216 #define C_BSS_SECTION           ((short)3)
217 #define C_ABS_SECTION           N_ABS
218 #define C_UNDEF_SECTION         N_UNDEF
219 #define C_DEBUG_SECTION         N_DEBUG
220 #define C_NTV_SECTION           N_TV
221 #define C_PTV_SECTION           P_TV
222 #define C_REGISTER_SECTION      4
223
224 /*
225  *  Macros to extract information from a symbol table entry.
226  *  This syntaxic indirection allows independence regarding a.out or coff.
227  *  The argument (s) of all these macros is a pointer to a symbol table entry.
228  */
229
230 /* Predicates */
231 /* True if the symbol is external */
232 #define S_IS_EXTERNAL(s)        ((s)->sy_symbol.ost_entry.n_scnum == C_UNDEF_SECTION)
233 /* True if symbol has been defined, ie :
234    section > 0 (DATA, TEXT or BSS)
235    section == 0 and value > 0 (external bss symbol) */
236 #define S_IS_DEFINED(s)         ((s)->sy_symbol.ost_entry.n_scnum > C_UNDEF_SECTION || \
237                                  ((s)->sy_symbol.ost_entry.n_scnum == C_UNDEF_SECTION && \
238                                   S_GET_VALUE(s) > 0))
239 /* True if a debug special symbol entry */
240 #define S_IS_DEBUG(s)           ((s)->sy_symbol.ost_entry.n_scnum == C_DEBUG_SECTION)
241 /* True if a symbol is local symbol name */
242 /* A symbol name whose name begin with ^A is a gas internal pseudo symbol */
243 #define S_IS_LOCAL(s)           (S_GET_NAME(s)[0] == '\001' || \
244                                  (s)->sy_symbol.ost_entry.n_scnum == C_REGISTER_SECTION || \
245                                  (S_LOCAL_NAME(s) && !flagseen['L']))
246 /* True if a symbol is not defined in this file */
247 #define S_IS_EXTERN(s)          ((s)->sy_symbol.ost_entry.n_scnum == 0 \
248                                  && S_GET_VALUE (s) == 0)
249 /*
250  * True if a symbol can be multiply defined (bss symbols have this def
251  * though it is bad practice)
252  */
253 #define S_IS_COMMON(s)          ((s)->sy_symbol.ost_entry.n_scnum == 0
254                                  && S_GET_VALUE (s) != 0)
255 /* True if a symbol name is in the string table, i.e. its length is > 8. */
256 #define S_IS_STRING(s)          (strlen(S_GET_NAME(s)) > 8 ? 1 : 0)
257
258 /* Accessors */
259 /* The name of the symbol */
260 #define S_GET_NAME(s)           ((char*)(s)->sy_symbol.ost_entry.n_offset)
261 /* The pointer to the string table */
262 #define S_GET_OFFSET(s)         ((s)->sy_symbol.ost_entry.n_offset)
263 /* The zeroes if symbol name is longer than 8 chars */
264 #define S_GET_ZEROES(s)         ((s)->sy_symbol.ost_entry.n_zeroes)
265 /* The numeric value of the segment */
266 #define S_GET_SEGMENT(s)        (N_TYPE_seg[(s)->sy_symbol.ost_entry.n_scnum+4])
267 /* The data type */
268 #define S_GET_DATA_TYPE(s)      ((s)->sy_symbol.ost_entry.n_type)
269 /* The storage class */
270 #define S_GET_STORAGE_CLASS(s)  ((s)->sy_symbol.ost_entry.n_sclass)
271 /* The number of auxiliary entries */
272 #define S_GET_NUMBER_AUXILIARY(s)       ((s)->sy_symbol.ost_entry.n_numaux)
273
274 /* Modifiers */
275 /* Set the name of the symbol */
276 #define S_SET_NAME(s,v)         ((s)->sy_symbol.ost_entry.n_offset = (unsigned long)(v))
277 /* Set the offset of the symbol */
278 #define S_SET_OFFSET(s,v)       ((s)->sy_symbol.ost_entry.n_offset = (v))
279 /* The zeroes if symbol name is longer than 8 chars */
280 #define S_SET_ZEROES(s,v)               ((s)->sy_symbol.ost_entry.n_zeroes = (v))
281 /* The numeric value of the segment */
282 #define S_SET_SEGMENT(s,v)      ((s)->sy_symbol.ost_entry.n_scnum = SEGMENT_TO_SYMBOL_TYPE(v))
283 /* The data type */
284 #define S_SET_DATA_TYPE(s,v)    ((s)->sy_symbol.ost_entry.n_type = (v))
285 /* The storage class */
286 #define S_SET_STORAGE_CLASS(s,v)        ((s)->sy_symbol.ost_entry.n_sclass = (v))
287 /* The number of auxiliary entries */
288 #define S_SET_NUMBER_AUXILIARY(s,v)     ((s)->sy_symbol.ost_entry.n_numaux = (v))
289
290 /* Additional modifiers */
291 /* The symbol is external (does not mean undefined) */
292 #define S_SET_EXTERNAL(s)       { S_SET_STORAGE_CLASS(s, C_EXT) ; SF_CLEAR_LOCAL(s); }
293
294 #else /* BFD_ASSEMBLER */
295
296 /* The data type */
297 #define S_GET_DATA_TYPE(s)      (coffsymbol ((s)->bsym)->native->u.syment.n_type)
298 /* The storage class */
299 #define S_GET_STORAGE_CLASS(s)  (coffsymbol((s)->bsym)->native->u.syment.n_sclass)
300 /* The number of auxiliary entries */
301 #define S_GET_NUMBER_AUXILIARY(s)       (coffsymbol((s)->bsym)->native->u.syment.n_numaux)
302 /* The data type */
303 #define S_SET_DATA_TYPE(s,v)    (S_GET_DATA_TYPE (s) = (v))
304 /* The storage class */
305 #define S_SET_STORAGE_CLASS(s,v)        (S_GET_STORAGE_CLASS (s) = (v))
306 /* The number of auxiliary entries */
307 #define S_SET_NUMBER_AUXILIARY(s,v)     (S_GET_NUMBER_AUXILIARY (s) = (v))
308
309 /* True if a symbol name is in the string table, i.e. its length is > 8. */
310 #define S_IS_STRING(s)          (strlen(S_GET_NAME(s)) > 8 ? 1 : 0)
311
312
313 #endif /* ! BFD_ASSEMBLER */
314
315 /* Auxiliary entry macros. SA_ stands for symbol auxiliary */
316 /* Omit the tv related fields */
317 /* Accessors */
318
319 #ifdef BFD_HEADERS
320 #define SA_GET_SYM_TAGNDX(s)    (SYM_AUXENT (s)->x_sym.x_tagndx.l)
321 #else
322 #define SA_GET_SYM_TAGNDX(s)    (SYM_AUXENT (s)->x_sym.x_tagndx)
323 #endif
324 #define SA_GET_SYM_LNNO(s)      (SYM_AUXENT (s)->x_sym.x_misc.x_lnsz.x_lnno)
325 #define SA_GET_SYM_SIZE(s)      (SYM_AUXENT (s)->x_sym.x_misc.x_lnsz.x_size)
326 #define SA_GET_SYM_FSIZE(s)     (SYM_AUXENT (s)->x_sym.x_misc.x_fsize)
327 #define SA_GET_SYM_LNNOPTR(s)   (SYM_AUXENT (s)->x_sym.x_fcnary.x_fcn.x_lnnoptr)
328 #ifdef BFD_HEADERS
329 #define SA_GET_SYM_ENDNDX(s)    (SYM_AUXENT (s)->x_sym.x_fcnary.x_fcn.x_endndx.l)
330 #else
331 #define SA_GET_SYM_ENDNDX(s)    (SYM_AUXENT (s)->x_sym.x_fcnary.x_fcn.x_endndx)
332 #endif
333 #define SA_GET_SYM_DIMEN(s,i)   (SYM_AUXENT (s)->x_sym.x_fcnary.x_ary.x_dimen[(i)])
334 #define SA_GET_FILE_FNAME(s)    (SYM_AUXENT (s)->x_file.x_fname)
335 #define SA_GET_SCN_SCNLEN(s)    (SYM_AUXENT (s)->x_scn.x_scnlen)
336 #define SA_GET_SCN_NRELOC(s)    (SYM_AUXENT (s)->x_scn.x_nreloc)
337 #define SA_GET_SCN_NLINNO(s)    (SYM_AUXENT (s)->x_scn.x_nlinno)
338
339 /* Modifiers */
340 #ifndef BFD_ASSEMBLER
341 #ifdef BFD_HEADERS
342 #define SA_SET_SYM_TAGNDX(s,v)  (SYM_AUXENT (s)->x_sym.x_tagndx.l=(v))
343 #define SA_SET_SYM_ENDNDX(s,v)  (SYM_AUXENT (s)->x_sym.x_fcnary.x_fcn.x_endndx.l=(v))
344 #else
345 #define SA_SET_SYM_ENDNDX(s,v)  (SYM_AUXENT (s)->x_sym.x_fcnary.x_fcn.x_endndx=(v))
346 #define SA_SET_SYM_TAGNDX(s,v)  (SYM_AUXENT (s)->x_sym.x_tagndx=(v))
347 #endif
348 #endif
349
350 #define SA_SET_SYM_LNNO(s,v)    (SYM_AUXENT (s)->x_sym.x_misc.x_lnsz.x_lnno=(v))
351 #define SA_SET_SYM_SIZE(s,v)    (SYM_AUXENT (s)->x_sym.x_misc.x_lnsz.x_size=(v))
352 #define SA_SET_SYM_FSIZE(s,v)   (SYM_AUXENT (s)->x_sym.x_misc.x_fsize=(v))
353 #define SA_SET_SYM_LNNOPTR(s,v) (SYM_AUXENT (s)->x_sym.x_fcnary.x_fcn.x_lnnoptr=(v))
354 #define SA_SET_SYM_DIMEN(s,i,v) (SYM_AUXENT (s)->x_sym.x_fcnary.x_ary.x_dimen[(i)]=(v))
355 #define SA_SET_FILE_FNAME(s,v)  strncpy(SYM_AUXENT (s)->x_file.x_fname,(v),FILNMLEN)
356 #define SA_SET_SCN_SCNLEN(s,v)  (SYM_AUXENT (s)->x_scn.x_scnlen=(v))
357 #define SA_SET_SCN_NRELOC(s,v)  (SYM_AUXENT (s)->x_scn.x_nreloc=(v))
358 #define SA_SET_SCN_NLINNO(s,v)  (SYM_AUXENT (s)->x_scn.x_nlinno=(v))
359
360 /*
361  * Internal use only definitions. SF_ stands for symbol flags.
362  *
363  * These values can be assigned to sy_symbol.ost_flags field of a symbolS.
364  *
365  * You'll break i960 if you shift the SYSPROC bits anywhere else.  for
366  * more on the balname/callname hack, see tc-i960.h.  b.out is done
367  * differently.
368  */
369
370 #define SF_I960_MASK    (0x000001ff)    /* Bits 0-8 are used by the i960 port. */
371 #define SF_SYSPROC      (0x0000003f)    /* bits 0-5 are used to store the sysproc number */
372 #define SF_IS_SYSPROC   (0x00000040)    /* bit 6 marks symbols that are sysprocs */
373 #define SF_BALNAME      (0x00000080)    /* bit 7 marks BALNAME symbols */
374 #define SF_CALLNAME     (0x00000100)    /* bit 8 marks CALLNAME symbols */
375
376 #define SF_NORMAL_MASK  (0x0000ffff)    /* bits 12-15 are general purpose. */
377
378 #define SF_STATICS      (0x00001000)    /* Mark the .text & all symbols */
379 #define SF_DEFINED      (0x00002000)    /* Symbol is defined in this file */
380 #define SF_STRING       (0x00004000)    /* Symbol name length > 8 */
381 #define SF_LOCAL        (0x00008000)    /* Symbol must not be emitted */
382
383 #define SF_DEBUG_MASK   (0xffff0000)    /* bits 16-31 are debug info */
384
385 #define SF_FUNCTION     (0x00010000)    /* The symbol is a function */
386 #define SF_PROCESS      (0x00020000)    /* Process symbol before write */
387 #define SF_TAGGED       (0x00040000)    /* Is associated with a tag */
388 #define SF_TAG          (0x00080000)    /* Is a tag */
389 #define SF_DEBUG        (0x00100000)    /* Is in debug or abs section */
390 #define SF_GET_SEGMENT  (0x00200000)    /* Get the section of the forward symbol. */
391 /* All other bits are unused. */
392
393 /* Accessors */
394 #ifdef BFD_ASSEMBLER
395 #define SF_GET(s)               ((s)->sy_flags)
396 #define SF_GET_DEBUG(s)         ((s)->bsym->flags & BSF_DEBUGGING)
397 #define SF_SET_DEBUG(s)         ((s)->bsym->flags |= BSF_DEBUGGING)
398 #else
399 #define SF_GET(s)               ((s)->sy_symbol.ost_flags)
400 #define SF_GET_DEBUG(s)         ((s)->sy_symbol.ost_flags & SF_DEBUG)
401 #define SF_SET_DEBUG(s)         ((s)->sy_symbol.ost_flags |= SF_DEBUG)
402 #endif
403 #define SF_GET_NORMAL_FIELD(s)  (SF_GET (s) & SF_NORMAL_MASK)
404 #define SF_GET_DEBUG_FIELD(s)   (SF_GET (s) & SF_DEBUG_MASK)
405 #define SF_GET_FILE(s)          (SF_GET (s) & SF_FILE)
406 #define SF_GET_STATICS(s)       (SF_GET (s) & SF_STATICS)
407 #define SF_GET_DEFINED(s)       (SF_GET (s) & SF_DEFINED)
408 #define SF_GET_STRING(s)        (SF_GET (s) & SF_STRING)
409 #define SF_GET_LOCAL(s)         (SF_GET (s) & SF_LOCAL)
410 #define SF_GET_FUNCTION(s)      (SF_GET (s) & SF_FUNCTION)
411 #define SF_GET_PROCESS(s)       (SF_GET (s) & SF_PROCESS)
412 #define SF_GET_TAGGED(s)        (SF_GET (s) & SF_TAGGED)
413 #define SF_GET_TAG(s)           (SF_GET (s) & SF_TAG)
414 #define SF_GET_GET_SEGMENT(s)   (SF_GET (s) & SF_GET_SEGMENT)
415 #define SF_GET_I960(s)          (SF_GET (s) & SF_I960_MASK)     /* used by i960 */
416 #define SF_GET_BALNAME(s)       (SF_GET (s) & SF_BALNAME)       /* used by i960 */
417 #define SF_GET_CALLNAME(s)      (SF_GET (s) & SF_CALLNAME)      /* used by i960 */
418 #define SF_GET_IS_SYSPROC(s)    (SF_GET (s) & SF_IS_SYSPROC)    /* used by i960 */
419 #define SF_GET_SYSPROC(s)       (SF_GET (s) & SF_SYSPROC)       /* used by i960 */
420
421 /* Modifiers */
422 #define SF_SET(s,v)             (SF_GET (s) = (v))
423 #define SF_SET_NORMAL_FIELD(s,v)(SF_GET (s) |= ((v) & SF_NORMAL_MASK))
424 #define SF_SET_DEBUG_FIELD(s,v) (SF_GET (s) |= ((v) & SF_DEBUG_MASK))
425 #define SF_SET_FILE(s)          (SF_GET (s) |= SF_FILE)
426 #define SF_SET_STATICS(s)       (SF_GET (s) |= SF_STATICS)
427 #define SF_SET_DEFINED(s)       (SF_GET (s) |= SF_DEFINED)
428 #define SF_SET_STRING(s)        (SF_GET (s) |= SF_STRING)
429 #define SF_SET_LOCAL(s)         (SF_GET (s) |= SF_LOCAL)
430 #define SF_CLEAR_LOCAL(s)       (SF_GET (s) &= ~SF_LOCAL)
431 #define SF_SET_FUNCTION(s)      (SF_GET (s) |= SF_FUNCTION)
432 #define SF_SET_PROCESS(s)       (SF_GET (s) |= SF_PROCESS)
433 #define SF_SET_TAGGED(s)        (SF_GET (s) |= SF_TAGGED)
434 #define SF_SET_TAG(s)           (SF_GET (s) |= SF_TAG)
435 #define SF_SET_GET_SEGMENT(s)   (SF_GET (s) |= SF_GET_SEGMENT)
436 #define SF_SET_I960(s,v)        (SF_GET (s) |= ((v) & SF_I960_MASK))    /* used by i960 */
437 #define SF_SET_BALNAME(s)       (SF_GET (s) |= SF_BALNAME)      /* used by i960 */
438 #define SF_SET_CALLNAME(s)      (SF_GET (s) |= SF_CALLNAME)     /* used by i960 */
439 #define SF_SET_IS_SYSPROC(s)    (SF_GET (s) |= SF_IS_SYSPROC)   /* used by i960 */
440 #define SF_SET_SYSPROC(s,v)     (SF_GET (s) |= ((v) & SF_SYSPROC))      /* used by i960 */
441
442 /* File header macro and type definition */
443
444 #ifndef BFD_ASSEMBLER
445 /*
446  * File position calculators. Beware to use them when all the
447  * appropriate fields are set in the header.
448  */
449
450 #ifdef OBJ_COFF_OMIT_OPTIONAL_HEADER
451 #define OBJ_COFF_AOUTHDRSZ (0)
452 #else
453 #define OBJ_COFF_AOUTHDRSZ (AOUTHDRSZ)
454 #endif /* OBJ_COFF_OMIT_OPTIONAL_HEADER */
455
456 #define H_GET_FILE_SIZE(h) \
457     (long)(FILHSZ + OBJ_COFF_AOUTHDRSZ + \
458            H_GET_NUMBER_OF_SECTIONS(h) * SCNHSZ + \
459            H_GET_TEXT_SIZE(h) + H_GET_DATA_SIZE(h) + \
460            H_GET_RELOCATION_SIZE(h) + H_GET_LINENO_SIZE(h) + \
461            H_GET_SYMBOL_TABLE_SIZE(h) + \
462            (h)->string_table_size)
463 #define H_GET_TEXT_FILE_OFFSET(h) \
464     (long)(FILHSZ + OBJ_COFF_AOUTHDRSZ + \
465            H_GET_NUMBER_OF_SECTIONS(h) * SCNHSZ)
466 #define H_GET_DATA_FILE_OFFSET(h) \
467     (long)(FILHSZ + OBJ_COFF_AOUTHDRSZ + \
468            H_GET_NUMBER_OF_SECTIONS(h) * SCNHSZ + \
469            H_GET_TEXT_SIZE(h))
470 #define H_GET_BSS_FILE_OFFSET(h) 0
471 #define H_GET_RELOCATION_FILE_OFFSET(h) \
472     (long)(FILHSZ + OBJ_COFF_AOUTHDRSZ + \
473            H_GET_NUMBER_OF_SECTIONS(h) * SCNHSZ + \
474            H_GET_TEXT_SIZE(h) + H_GET_DATA_SIZE(h))
475 #define H_GET_LINENO_FILE_OFFSET(h) \
476     (long)(FILHSZ + OBJ_COFF_AOUTHDRSZ + \
477            H_GET_NUMBER_OF_SECTIONS(h) * SCNHSZ + \
478            H_GET_TEXT_SIZE(h) + H_GET_DATA_SIZE(h) + \
479            H_GET_RELOCATION_SIZE(h))
480 #define H_GET_SYMBOL_TABLE_FILE_OFFSET(h) \
481     (long)(FILHSZ + OBJ_COFF_AOUTHDRSZ + \
482            H_GET_NUMBER_OF_SECTIONS(h) * SCNHSZ + \
483            H_GET_TEXT_SIZE(h) + H_GET_DATA_SIZE(h) + \
484            H_GET_RELOCATION_SIZE(h) + H_GET_LINENO_SIZE(h))
485
486 /* Accessors */
487 /* aouthdr */
488 #define H_GET_MAGIC_NUMBER(h)           ((h)->aouthdr.magic)
489 #define H_GET_VERSION_STAMP(h)          ((h)->aouthdr.vstamp)
490 #define H_GET_TEXT_SIZE(h)              ((h)->aouthdr.tsize)
491 #define H_GET_DATA_SIZE(h)              ((h)->aouthdr.dsize)
492 #define H_GET_BSS_SIZE(h)               ((h)->aouthdr.bsize)
493 #define H_GET_ENTRY_POINT(h)            ((h)->aouthdr.entry)
494 #define H_GET_TEXT_START(h)             ((h)->aouthdr.text_start)
495 #define H_GET_DATA_START(h)             ((h)->aouthdr.data_start)
496 /* filehdr */
497 #define H_GET_FILE_MAGIC_NUMBER(h)      ((h)->filehdr.f_magic)
498 #define H_GET_NUMBER_OF_SECTIONS(h)     ((h)->filehdr.f_nscns)
499 #define H_GET_TIME_STAMP(h)             ((h)->filehdr.f_timdat)
500 #define H_GET_SYMBOL_TABLE_POINTER(h)   ((h)->filehdr.f_symptr)
501 #define H_GET_SYMBOL_COUNT(h)           ((h)->filehdr.f_nsyms)
502 #define H_GET_SYMBOL_TABLE_SIZE(h)      (H_GET_SYMBOL_COUNT(h) * SYMESZ)
503 #define H_GET_SIZEOF_OPTIONAL_HEADER(h) ((h)->filehdr.f_opthdr)
504 #define H_GET_FLAGS(h)                  ((h)->filehdr.f_flags)
505 /* Extra fields to achieve bsd a.out compatibility and for convenience */
506 #define H_GET_RELOCATION_SIZE(h)        ((h)->relocation_size)
507 #define H_GET_STRING_SIZE(h)            ((h)->string_table_size)
508 #define H_GET_LINENO_SIZE(h)            ((h)->lineno_size)
509
510 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
511 #define H_GET_HEADER_SIZE(h)            (sizeof(FILHDR) \
512                                          + sizeof(AOUTHDR)\
513                                          + (H_GET_NUMBER_OF_SECTIONS(h) * SCNHSZ))
514 #else /* OBJ_COFF_OMIT_OPTIONAL_HEADER */
515 #define H_GET_HEADER_SIZE(h)            (sizeof(FILHDR) \
516                                          + (H_GET_NUMBER_OF_SECTIONS(h) * SCNHSZ))
517 #endif /* OBJ_COFF_OMIT_OPTIONAL_HEADER */
518
519 #define H_GET_TEXT_RELOCATION_SIZE(h)   (text_section_header.s_nreloc * RELSZ)
520 #define H_GET_DATA_RELOCATION_SIZE(h)   (data_section_header.s_nreloc * RELSZ)
521
522 /* Modifiers */
523 /* aouthdr */
524 #define H_SET_MAGIC_NUMBER(h,v)         ((h)->aouthdr.magic = (v))
525 #define H_SET_VERSION_STAMP(h,v)        ((h)->aouthdr.vstamp = (v))
526 #define H_SET_TEXT_SIZE(h,v)            ((h)->aouthdr.tsize = (v))
527 #define H_SET_DATA_SIZE(h,v)            ((h)->aouthdr.dsize = (v))
528 #define H_SET_BSS_SIZE(h,v)             ((h)->aouthdr.bsize = (v))
529 #define H_SET_ENTRY_POINT(h,v)          ((h)->aouthdr.entry = (v))
530 #define H_SET_TEXT_START(h,v)           ((h)->aouthdr.text_start = (v))
531 #define H_SET_DATA_START(h,v)           ((h)->aouthdr.data_start = (v))
532 /* filehdr */
533 #define H_SET_FILE_MAGIC_NUMBER(h,v)    ((h)->filehdr.f_magic = (v))
534 #define H_SET_NUMBER_OF_SECTIONS(h,v)   ((h)->filehdr.f_nscns = (v))
535 #define H_SET_TIME_STAMP(h,v)           ((h)->filehdr.f_timdat = (v))
536 #define H_SET_SYMBOL_TABLE_POINTER(h,v) ((h)->filehdr.f_symptr = (v))
537 #define H_SET_SYMBOL_TABLE_SIZE(h,v)    ((h)->filehdr.f_nsyms = (v))
538 #define H_SET_SIZEOF_OPTIONAL_HEADER(h,v) ((h)->filehdr.f_opthdr = (v))
539 #define H_SET_FLAGS(h,v)                ((h)->filehdr.f_flags = (v))
540 /* Extra fields to achieve bsd a.out compatibility and for convinience */
541 #define H_SET_RELOCATION_SIZE(h,t,d)    ((h)->relocation_size = (t)+(d))
542 #define H_SET_STRING_SIZE(h,v)          ((h)->string_table_size = (v))
543 #define H_SET_LINENO_SIZE(h,v)          ((h)->lineno_size = (v))
544
545 /* Segment flipping */
546
547 typedef struct
548   {
549 #ifdef BFD_HEADERS
550     struct internal_aouthdr aouthdr;    /* a.out header */
551     struct internal_filehdr filehdr;    /* File header, not machine dep. */
552 #else
553     AOUTHDR aouthdr;            /* a.out header */
554     FILHDR filehdr;             /* File header, not machine dep. */
555 #endif
556     long string_table_size;     /* names + '\0' + sizeof(int) */
557     long relocation_size;       /* Cumulated size of relocation
558                                            information for all sections in
559                                            bytes. */
560     long lineno_size;           /* Size of the line number information
561                                            table in bytes */
562   }
563
564 object_headers;
565 #endif /* ! BFD_ASSEMBLER */
566
567 /* --------------  Line number handling ------- */
568 extern int text_lineno_number;
569
570 #ifndef BFD_ASSEMBLER
571 /* line numbering stuff. */
572
573 typedef struct internal_lineno
574   {
575 #ifdef BFD_HEADERS
576     struct bfd_internal_lineno line;
577 #else
578     LINENO line;                /* The lineno structure itself */
579 #endif
580     char *frag;                 /* Frag to which the line number is related */
581     struct internal_lineno *next;       /* Forward chain pointer */
582   } lineno;
583
584 extern lineno *lineno_lastP;
585 extern lineno *lineno_rootP;
586 #define OBJ_EMIT_LINENO(a, b, c)        obj_emit_lineno((a),(b),(c))
587
588 #endif /* not BFD_ASSEMBLER */
589
590 void obj_emit_lineno PARAMS ((char **where, lineno * line, char *file_start));
591
592 /* stack stuff */
593 typedef struct
594   {
595     unsigned long chunk_size;
596     unsigned long element_size;
597     unsigned long size;
598     char *data;
599     unsigned long pointer;
600   }
601
602 stack;
603
604 char *stack_pop PARAMS ((stack * st));
605 char *stack_push PARAMS ((stack * st, char *element));
606 char *stack_top PARAMS ((stack * st));
607 stack *stack_init PARAMS ((unsigned long chunk_size,
608                            unsigned long element_size));
609 void c_dot_file_symbol PARAMS ((char *filename));
610 void obj_extra_stuff PARAMS ((object_headers * headers));
611 void stack_delete PARAMS ((stack * st));
612
613 #ifndef tc_headers_hook
614 void tc_headers_hook PARAMS ((object_headers * headers));
615 #endif
616
617 #ifndef tc_coff_symbol_emit_hook
618 void tc_coff_symbol_emit_hook PARAMS ((/* symbolS * */));
619 #endif
620
621 #define obj_check_file_symbols coff_check_file_symbols
622
623 #ifndef BFD_ASEMBLER
624 void c_section_header PARAMS ((
625 #ifdef BFD_HEADERS
626                                struct internal_scnhdr *header,
627 #else
628                                SCNHDR * header,
629 #endif
630                                char *name, long core_address, long size,
631                                long data_ptr, long reloc_ptr, long lineno_ptr,
632                                long reloc_number, long lineno_number,
633                                long alignment));
634 #endif
635
636 /* sanity check */
637
638 #ifdef TC_I960
639 #ifndef C_LEAFSTAT
640 hey ! Where is the C_LEAFSTAT definition ? i960 - coff support is depending on it.
641 #endif /* no C_LEAFSTAT */
642 #endif /* TC_I960 */
643 #ifndef BFD_ASSEMBLER
644 #ifdef BFD_HEADERS
645 extern struct internal_scnhdr data_section_header;
646 extern struct internal_scnhdr text_section_header;
647 #else
648 extern SCNHDR data_section_header;
649 extern SCNHDR text_section_header;
650 #endif
651 #endif
652
653 /* end of obj-coff.h */