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