8168dc2cc10adb57526ba5b4b1741ac9bdfd2b26
[deliverable/binutils-gdb.git] / gas / config / obj-coff.h
1 /* coff object file format
2 Copyright (C) 1989-2018 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 3, 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 the Free
18 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
19 02110-1301, USA. */
20
21 #ifndef OBJ_FORMAT_H
22 #define OBJ_FORMAT_H
23
24 #define OBJ_COFF 1
25
26 #include "targ-cpu.h"
27
28 /* This internal_lineno crap is to stop namespace pollution from the
29 bfd internal coff headerfile. */
30 #define internal_lineno bfd_internal_lineno
31 #include "coff/internal.h"
32 #undef internal_lineno
33
34 /* CPU-specific setup: */
35
36 #ifdef TC_ARM
37 #include "coff/arm.h"
38 #ifndef TARGET_FORMAT
39 #define TARGET_FORMAT "coff-arm"
40 #endif
41 #endif
42
43 #ifdef TC_PPC
44 #ifdef TE_PE
45 #include "coff/powerpc.h"
46 #else
47 #include "coff/rs6000.h"
48 #endif
49 #endif
50
51 #ifdef TC_SPARC
52 #include "coff/sparc.h"
53 #endif
54
55 #ifdef TC_I386
56 #ifdef TE_PEP
57 #include "coff/x86_64.h"
58 #else
59 #include "coff/i386.h"
60 #endif
61
62 #ifndef TARGET_FORMAT
63 #ifdef TE_PEP
64 #define TARGET_FORMAT "coff-x86-64"
65 #else
66 #define TARGET_FORMAT "coff-i386"
67 #endif
68 #endif
69 #endif
70
71 #ifdef TC_M68K
72 #include "coff/m68k.h"
73 #ifndef TARGET_FORMAT
74 #define TARGET_FORMAT "coff-m68k"
75 #endif
76 #endif
77
78 #ifdef TC_Z80
79 #include "coff/z80.h"
80 #define TARGET_FORMAT "coff-z80"
81 #endif
82
83 #ifdef TC_Z8K
84 #include "coff/z8k.h"
85 #define TARGET_FORMAT "coff-z8k"
86 #endif
87
88 #ifdef TC_H8500
89 #include "coff/h8500.h"
90 #define TARGET_FORMAT "coff-h8500"
91 #endif
92
93 #ifdef TC_SH
94
95 #ifdef TE_PE
96 #define COFF_WITH_PE
97 #endif
98
99 #include "coff/sh.h"
100
101 #ifdef TE_PE
102 #define TARGET_FORMAT "pe-shl"
103 #else
104
105 #define TARGET_FORMAT \
106 (!target_big_endian \
107 ? (sh_small ? "coff-shl-small" : "coff-shl") \
108 : (sh_small ? "coff-sh-small" : "coff-sh"))
109
110 #endif
111 #endif
112
113 #ifdef TC_MIPS
114 #define COFF_WITH_PE
115 #include "coff/mipspe.h"
116 #undef TARGET_FORMAT
117 #define TARGET_FORMAT "pe-mips"
118 #endif
119
120 #ifdef TC_TIC30
121 #include "coff/tic30.h"
122 #define TARGET_FORMAT "coff-tic30"
123 #endif
124
125 #ifdef TC_TIC4X
126 #include "coff/tic4x.h"
127 #define TARGET_FORMAT "coff2-tic4x"
128 #endif
129
130 #ifdef TC_TIC54X
131 #include "coff/tic54x.h"
132 #define TARGET_FORMAT "coff1-c54x"
133 #endif
134
135 #ifdef TC_MCORE
136 #include "coff/mcore.h"
137 #ifndef TARGET_FORMAT
138 #define TARGET_FORMAT "pe-mcore"
139 #endif
140 #endif
141
142 #ifdef TE_PE
143 #define obj_set_weak_hook pecoff_obj_set_weak_hook
144 #define obj_clear_weak_hook pecoff_obj_clear_weak_hook
145 #endif
146
147 #ifndef OBJ_COFF_MAX_AUXENTRIES
148 #define OBJ_COFF_MAX_AUXENTRIES 1
149 #endif
150
151 #define obj_symbol_new_hook coff_obj_symbol_new_hook
152 #define obj_symbol_clone_hook coff_obj_symbol_clone_hook
153 #define obj_read_begin_hook coff_obj_read_begin_hook
154
155 #include "bfd/libcoff.h"
156
157 #define OUTPUT_FLAVOR bfd_target_coff_flavour
158
159 /* Alter the field names, for now, until we've fixed up the other
160 references to use the new name. */
161 #define OBJ_SYMFIELD_TYPE unsigned long
162 #define sy_obj sy_obj_flags
163
164 /* We can't use the predefined section symbols in bfd/section.c, as
165 COFF symbols have extra fields. See bfd/libcoff.h:coff_symbol_type. */
166 #ifndef obj_sec_sym_ok_for_reloc
167 #define obj_sec_sym_ok_for_reloc(SEC) ((SEC)->owner != 0)
168 #endif
169
170 #define SYM_AUXENT(S) \
171 (&coffsymbol (symbol_get_bfdsym (S))->native[1].u.auxent)
172 #define SYM_AUXINFO(S) \
173 (&coffsymbol (symbol_get_bfdsym (S))->native[1])
174
175 /* The number of auxiliary entries. */
176 #define S_GET_NUMBER_AUXILIARY(s) \
177 (coffsymbol (symbol_get_bfdsym (s))->native->u.syment.n_numaux)
178 /* The number of auxiliary entries. */
179 #define S_SET_NUMBER_AUXILIARY(s, v) (S_GET_NUMBER_AUXILIARY (s) = (v))
180
181 /* True if a symbol name is in the string table, i.e. its length is > 8. */
182 #define S_IS_STRING(s) (strlen (S_GET_NAME (s)) > 8 ? 1 : 0)
183
184 /* Auxiliary entry macros. SA_ stands for symbol auxiliary. */
185 /* Omit the tv related fields. */
186 /* Accessors. */
187
188 #define SA_GET_SYM_TAGNDX(s) (SYM_AUXENT (s)->x_sym.x_tagndx.l)
189 #define SA_GET_SYM_LNNO(s) (SYM_AUXENT (s)->x_sym.x_misc.x_lnsz.x_lnno)
190 #define SA_GET_SYM_SIZE(s) (SYM_AUXENT (s)->x_sym.x_misc.x_lnsz.x_size)
191 #define SA_GET_SYM_FSIZE(s) (SYM_AUXENT (s)->x_sym.x_misc.x_fsize)
192 #define SA_GET_SYM_LNNOPTR(s) (SYM_AUXENT (s)->x_sym.x_fcnary.x_fcn.x_lnnoptr)
193 #define SA_GET_SYM_ENDNDX(s) (SYM_AUXENT (s)->x_sym.x_fcnary.x_fcn.x_endndx)
194 #define SA_GET_SYM_DIMEN(s,i) (SYM_AUXENT (s)->x_sym.x_fcnary.x_ary.x_dimen[(i)])
195 #define SA_GET_FILE_FNAME(s) (SYM_AUXENT (s)->x_file.x_fname)
196 #define SA_GET_SCN_SCNLEN(s) (SYM_AUXENT (s)->x_scn.x_scnlen)
197 #define SA_GET_SCN_NRELOC(s) (SYM_AUXENT (s)->x_scn.x_nreloc)
198 #define SA_GET_SCN_NLINNO(s) (SYM_AUXENT (s)->x_scn.x_nlinno)
199
200 #define SA_SET_SYM_LNNO(s,v) (SYM_AUXENT (s)->x_sym.x_misc.x_lnsz.x_lnno = (v))
201 #define SA_SET_SYM_SIZE(s,v) (SYM_AUXENT (s)->x_sym.x_misc.x_lnsz.x_size = (v))
202 #define SA_SET_SYM_FSIZE(s,v) (SYM_AUXENT (s)->x_sym.x_misc.x_fsize = (v))
203 #define SA_SET_SYM_LNNOPTR(s,v) (SYM_AUXENT (s)->x_sym.x_fcnary.x_fcn.x_lnnoptr = (v))
204 #define SA_SET_SYM_DIMEN(s,i,v) (SYM_AUXENT (s)->x_sym.x_fcnary.x_ary.x_dimen[(i)] = (v))
205 #define SA_SET_FILE_FNAME(s,v) strncpy (SYM_AUXENT (s)->x_file.x_fname, (v), FILNMLEN)
206 #define SA_SET_SCN_SCNLEN(s,v) (SYM_AUXENT (s)->x_scn.x_scnlen = (v))
207 #define SA_SET_SCN_NRELOC(s,v) (SYM_AUXENT (s)->x_scn.x_nreloc = (v))
208 #define SA_SET_SCN_NLINNO(s,v) (SYM_AUXENT (s)->x_scn.x_nlinno = (v))
209
210 /* Internal use only definitions. SF_ stands for symbol flags.
211
212 These values can be assigned to sy_symbol.ost_flags field of a symbolS. */
213
214 #define SF_NORMAL_MASK 0x0000ffff /* bits 12-15 are general purpose. */
215
216 #define SF_STATICS 0x00001000 /* Mark the .text & all symbols. */
217 #define SF_DEFINED 0x00002000 /* Symbol is defined in this file. */
218 #define SF_STRING 0x00004000 /* Symbol name length > 8. */
219 #define SF_LOCAL 0x00008000 /* Symbol must not be emitted. */
220
221 #define SF_DEBUG_MASK 0xffff0000 /* bits 16-31 are debug info. */
222
223 #define SF_FUNCTION 0x00010000 /* The symbol is a function. */
224 #define SF_PROCESS 0x00020000 /* Process symbol before write. */
225 #define SF_TAGGED 0x00040000 /* Is associated with a tag. */
226 #define SF_TAG 0x00080000 /* Is a tag. */
227 #define SF_DEBUG 0x00100000 /* Is in debug or abs section. */
228 #define SF_GET_SEGMENT 0x00200000 /* Get the section of the forward symbol. */
229 /* All other bits are unused. */
230
231 /* Accessors. */
232 #define SF_GET(s) (* symbol_get_obj (s))
233 #define SF_GET_DEBUG(s) (symbol_get_bfdsym (s)->flags & BSF_DEBUGGING)
234 #define SF_SET_DEBUG(s) (symbol_get_bfdsym (s)->flags |= BSF_DEBUGGING)
235 #define SF_GET_NORMAL_FIELD(s) (SF_GET (s) & SF_NORMAL_MASK)
236 #define SF_GET_DEBUG_FIELD(s) (SF_GET (s) & SF_DEBUG_MASK)
237 #define SF_GET_FILE(s) (SF_GET (s) & SF_FILE)
238 #define SF_GET_STATICS(s) (SF_GET (s) & SF_STATICS)
239 #define SF_GET_DEFINED(s) (SF_GET (s) & SF_DEFINED)
240 #define SF_GET_STRING(s) (SF_GET (s) & SF_STRING)
241 #define SF_GET_LOCAL(s) (SF_GET (s) & SF_LOCAL)
242 #define SF_GET_FUNCTION(s) (SF_GET (s) & SF_FUNCTION)
243 #define SF_GET_PROCESS(s) (SF_GET (s) & SF_PROCESS)
244 #define SF_GET_TAGGED(s) (SF_GET (s) & SF_TAGGED)
245 #define SF_GET_TAG(s) (SF_GET (s) & SF_TAG)
246 #define SF_GET_GET_SEGMENT(s) (SF_GET (s) & SF_GET_SEGMENT)
247
248 /* Modifiers. */
249 #define SF_SET(s,v) (SF_GET (s) = (v))
250 #define SF_SET_NORMAL_FIELD(s,v)(SF_GET (s) |= ((v) & SF_NORMAL_MASK))
251 #define SF_SET_DEBUG_FIELD(s,v) (SF_GET (s) |= ((v) & SF_DEBUG_MASK))
252 #define SF_SET_FILE(s) (SF_GET (s) |= SF_FILE)
253 #define SF_SET_STATICS(s) (SF_GET (s) |= SF_STATICS)
254 #define SF_SET_DEFINED(s) (SF_GET (s) |= SF_DEFINED)
255 #define SF_SET_STRING(s) (SF_GET (s) |= SF_STRING)
256 #define SF_SET_LOCAL(s) (SF_GET (s) |= SF_LOCAL)
257 #define SF_CLEAR_LOCAL(s) (SF_GET (s) &= ~SF_LOCAL)
258 #define SF_SET_FUNCTION(s) (SF_GET (s) |= SF_FUNCTION)
259 #define SF_SET_PROCESS(s) (SF_GET (s) |= SF_PROCESS)
260 #define SF_SET_TAGGED(s) (SF_GET (s) |= SF_TAGGED)
261 #define SF_SET_TAG(s) (SF_GET (s) |= SF_TAG)
262 #define SF_SET_GET_SEGMENT(s) (SF_GET (s) |= SF_GET_SEGMENT)
263
264
265 /* Line number handling. */
266 extern int text_lineno_number;
267 extern int coff_line_base;
268 extern int coff_n_line_nos;
269 extern symbolS *coff_last_function;
270
271 #define obj_emit_lineno(WHERE, LINE, FILE_START) abort ()
272 #define obj_app_file(name, app) c_dot_file_symbol (name, app)
273 #define obj_frob_symbol(S,P) coff_frob_symbol (S, & P)
274 #define obj_frob_section(S) coff_frob_section (S)
275 #define obj_frob_file_after_relocs() coff_frob_file_after_relocs ()
276 #ifndef obj_adjust_symtab
277 #define obj_adjust_symtab() coff_adjust_symtab ()
278 #endif
279
280 /* Forward the segment of a forwarded symbol, handle assignments that
281 just copy symbol values, etc. */
282 #ifndef OBJ_COPY_SYMBOL_ATTRIBUTES
283 #ifndef TE_I386AIX
284 #define OBJ_COPY_SYMBOL_ATTRIBUTES(dest, src) \
285 (SF_GET_GET_SEGMENT (dest) \
286 ? (S_SET_SEGMENT (dest, S_GET_SEGMENT (src)), 0) \
287 : 0)
288 #else
289 #define OBJ_COPY_SYMBOL_ATTRIBUTES(dest, src) \
290 (SF_GET_GET_SEGMENT (dest) && S_GET_SEGMENT (dest) == SEG_UNKNOWN \
291 ? (S_SET_SEGMENT (dest, S_GET_SEGMENT (src)), 0) \
292 : 0)
293 #endif
294 #endif
295
296 /* Sanity check. */
297
298 extern const pseudo_typeS coff_pseudo_table[];
299
300 #ifndef obj_pop_insert
301 #define obj_pop_insert() pop_insert (coff_pseudo_table)
302 #endif
303
304 /* In COFF, if a symbol is defined using .def/.val SYM/.endef, it's OK
305 to redefine the symbol later on. This can happen if C symbols use
306 a prefix, and a symbol is defined both with and without the prefix,
307 as in start/_start/__start in gcc/libgcc1-test.c. */
308 #define RESOLVE_SYMBOL_REDEFINITION(sym) \
309 (SF_GET_GET_SEGMENT (sym) \
310 ? (sym->sy_frag = frag_now, \
311 S_SET_VALUE (sym, frag_now_fix ()), \
312 S_SET_SEGMENT (sym, now_seg), \
313 0) \
314 : 0)
315
316 /* Stabs in a coff file go into their own section. */
317 #define SEPARATE_STAB_SECTIONS 1
318
319 /* We need 12 bytes at the start of the section to hold some initial
320 information. */
321 #define INIT_STAB_SECTION(seg) obj_coff_init_stab_section (seg)
322
323 /* Store the number of relocations in the section aux entry. */
324 #define SET_SECTION_RELOCS(sec, relocs, n) \
325 SA_SET_SCN_NRELOC (section_symbol (sec), n)
326
327 #define obj_app_file(name, app) c_dot_file_symbol (name, app)
328
329 extern int S_SET_DATA_TYPE (symbolS *, int);
330 extern int S_SET_STORAGE_CLASS (symbolS *, int);
331 extern int S_GET_STORAGE_CLASS (symbolS *);
332 extern void SA_SET_SYM_ENDNDX (symbolS *, symbolS *);
333 extern void coff_add_linesym (symbolS *);
334 extern void c_dot_file_symbol (const char *, int);
335 extern void coff_frob_symbol (symbolS *, int *);
336 extern void coff_adjust_symtab (void);
337 extern void coff_frob_section (segT);
338 extern void coff_adjust_section_syms (bfd *, asection *, void *);
339 extern void coff_frob_file_after_relocs (void);
340 extern void coff_obj_symbol_new_hook (symbolS *);
341 extern void coff_obj_symbol_clone_hook (symbolS *, symbolS *);
342 extern void coff_obj_read_begin_hook (void);
343 #ifdef TE_PE
344 extern void pecoff_obj_set_weak_hook (symbolS *);
345 extern void pecoff_obj_clear_weak_hook (symbolS *);
346 #endif
347 extern void obj_coff_section (int);
348 extern segT obj_coff_add_segment (const char *);
349 extern void obj_coff_section (int);
350 extern void c_dot_file_symbol (const char *, int);
351 extern segT s_get_segment (symbolS *);
352 #ifndef tc_coff_symbol_emit_hook
353 extern void tc_coff_symbol_emit_hook (symbolS *);
354 #endif
355 extern void obj_coff_pe_handle_link_once (void);
356 extern void obj_coff_init_stab_section (segT);
357 extern void c_section_header (struct internal_scnhdr *,
358 char *, long, long, long, long,
359 long, long, long, long);
360 extern void obj_coff_seh_do_final (void);
361
362 #ifndef obj_coff_generate_pdata
363 #define obj_coff_generate_pdata obj_coff_seh_do_final
364 #endif
365
366
367 #endif /* OBJ_FORMAT_H */
This page took 0.047754 seconds and 4 git commands to generate.