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