1 /* coff object file format
2 Copyright (C) 1989-2014 Free Software Foundation, Inc.
4 This file is part of GAS.
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)
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.
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
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
34 /* CPU-specific setup: */
39 #define TARGET_FORMAT "coff-arm"
45 #include "coff/powerpc.h"
47 #include "coff/rs6000.h"
52 #include "coff/sparc.h"
57 #include "coff/x86_64.h"
59 #include "coff/i386.h"
64 #define TARGET_FORMAT "coff-x86-64"
66 #define TARGET_FORMAT "coff-i386"
72 #include "coff/m68k.h"
74 #define TARGET_FORMAT "coff-m68k"
79 #include "coff/or32.h"
80 #define TARGET_FORMAT "coff-or32-big"
84 #include "coff/i960.h"
85 #define TARGET_FORMAT "coff-Intel-little"
90 #define TARGET_FORMAT "coff-z80"
95 #define TARGET_FORMAT "coff-z8k"
99 #include "coff/h8300.h"
100 #define TARGET_FORMAT "coff-h8300"
104 #include "coff/h8500.h"
105 #define TARGET_FORMAT "coff-h8500"
117 #define TARGET_FORMAT "pe-shl"
120 #define TARGET_FORMAT \
121 (!target_big_endian \
122 ? (sh_small ? "coff-shl-small" : "coff-shl") \
123 : (sh_small ? "coff-sh-small" : "coff-sh"))
130 #include "coff/mipspe.h"
132 #define TARGET_FORMAT "pe-mips"
136 #include "coff/tic30.h"
137 #define TARGET_FORMAT "coff-tic30"
141 #include "coff/tic4x.h"
142 #define TARGET_FORMAT "coff2-tic4x"
146 #include "coff/tic54x.h"
147 #define TARGET_FORMAT "coff1-c54x"
151 #include "coff/mcore.h"
152 #ifndef TARGET_FORMAT
153 #define TARGET_FORMAT "pe-mcore"
158 #define obj_set_weak_hook pecoff_obj_set_weak_hook
159 #define obj_clear_weak_hook pecoff_obj_clear_weak_hook
162 #ifndef OBJ_COFF_MAX_AUXENTRIES
163 #define OBJ_COFF_MAX_AUXENTRIES 1
166 #define obj_symbol_new_hook coff_obj_symbol_new_hook
167 #define obj_symbol_clone_hook coff_obj_symbol_clone_hook
168 #define obj_read_begin_hook coff_obj_read_begin_hook
170 #include "bfd/libcoff.h"
172 #define OUTPUT_FLAVOR bfd_target_coff_flavour
174 /* Alter the field names, for now, until we've fixed up the other
175 references to use the new name. */
177 #define TC_SYMFIELD_TYPE symbolS *
181 #define OBJ_SYMFIELD_TYPE unsigned long
182 #define sy_obj sy_obj_flags
184 /* We can't use the predefined section symbols in bfd/section.c, as
185 COFF symbols have extra fields. See bfd/libcoff.h:coff_symbol_type. */
186 #ifndef obj_sec_sym_ok_for_reloc
187 #define obj_sec_sym_ok_for_reloc(SEC) ((SEC)->owner != 0)
190 #define SYM_AUXENT(S) \
191 (&coffsymbol (symbol_get_bfdsym (S))->native[1].u.auxent)
192 #define SYM_AUXINFO(S) \
193 (&coffsymbol (symbol_get_bfdsym (S))->native[1])
195 /* The number of auxiliary entries. */
196 #define S_GET_NUMBER_AUXILIARY(s) \
197 (coffsymbol (symbol_get_bfdsym (s))->native->u.syment.n_numaux)
198 /* The number of auxiliary entries. */
199 #define S_SET_NUMBER_AUXILIARY(s, v) (S_GET_NUMBER_AUXILIARY (s) = (v))
201 /* True if a symbol name is in the string table, i.e. its length is > 8. */
202 #define S_IS_STRING(s) (strlen (S_GET_NAME (s)) > 8 ? 1 : 0)
204 /* Auxiliary entry macros. SA_ stands for symbol auxiliary. */
205 /* Omit the tv related fields. */
208 #define SA_GET_SYM_TAGNDX(s) (SYM_AUXENT (s)->x_sym.x_tagndx.l)
209 #define SA_GET_SYM_LNNO(s) (SYM_AUXENT (s)->x_sym.x_misc.x_lnsz.x_lnno)
210 #define SA_GET_SYM_SIZE(s) (SYM_AUXENT (s)->x_sym.x_misc.x_lnsz.x_size)
211 #define SA_GET_SYM_FSIZE(s) (SYM_AUXENT (s)->x_sym.x_misc.x_fsize)
212 #define SA_GET_SYM_LNNOPTR(s) (SYM_AUXENT (s)->x_sym.x_fcnary.x_fcn.x_lnnoptr)
213 #define SA_GET_SYM_ENDNDX(s) (SYM_AUXENT (s)->x_sym.x_fcnary.x_fcn.x_endndx)
214 #define SA_GET_SYM_DIMEN(s,i) (SYM_AUXENT (s)->x_sym.x_fcnary.x_ary.x_dimen[(i)])
215 #define SA_GET_FILE_FNAME(s) (SYM_AUXENT (s)->x_file.x_fname)
216 #define SA_GET_SCN_SCNLEN(s) (SYM_AUXENT (s)->x_scn.x_scnlen)
217 #define SA_GET_SCN_NRELOC(s) (SYM_AUXENT (s)->x_scn.x_nreloc)
218 #define SA_GET_SCN_NLINNO(s) (SYM_AUXENT (s)->x_scn.x_nlinno)
220 #define SA_SET_SYM_LNNO(s,v) (SYM_AUXENT (s)->x_sym.x_misc.x_lnsz.x_lnno = (v))
221 #define SA_SET_SYM_SIZE(s,v) (SYM_AUXENT (s)->x_sym.x_misc.x_lnsz.x_size = (v))
222 #define SA_SET_SYM_FSIZE(s,v) (SYM_AUXENT (s)->x_sym.x_misc.x_fsize = (v))
223 #define SA_SET_SYM_LNNOPTR(s,v) (SYM_AUXENT (s)->x_sym.x_fcnary.x_fcn.x_lnnoptr = (v))
224 #define SA_SET_SYM_DIMEN(s,i,v) (SYM_AUXENT (s)->x_sym.x_fcnary.x_ary.x_dimen[(i)] = (v))
225 #define SA_SET_FILE_FNAME(s,v) strncpy (SYM_AUXENT (s)->x_file.x_fname, (v), FILNMLEN)
226 #define SA_SET_SCN_SCNLEN(s,v) (SYM_AUXENT (s)->x_scn.x_scnlen = (v))
227 #define SA_SET_SCN_NRELOC(s,v) (SYM_AUXENT (s)->x_scn.x_nreloc = (v))
228 #define SA_SET_SCN_NLINNO(s,v) (SYM_AUXENT (s)->x_scn.x_nlinno = (v))
230 /* Internal use only definitions. SF_ stands for symbol flags.
232 These values can be assigned to sy_symbol.ost_flags field of a symbolS.
234 You'll break i960 if you shift the SYSPROC bits anywhere else. for
235 more on the balname/callname hack, see tc-i960.h. b.out is done
238 #define SF_I960_MASK 0x000001ff /* Bits 0-8 are used by the i960 port. */
239 #define SF_SYSPROC 0x0000003f /* bits 0-5 are used to store the sysproc number. */
240 #define SF_IS_SYSPROC 0x00000040 /* bit 6 marks symbols that are sysprocs. */
241 #define SF_BALNAME 0x00000080 /* bit 7 marks BALNAME symbols. */
242 #define SF_CALLNAME 0x00000100 /* bit 8 marks CALLNAME symbols. */
244 #define SF_NORMAL_MASK 0x0000ffff /* bits 12-15 are general purpose. */
246 #define SF_STATICS 0x00001000 /* Mark the .text & all symbols. */
247 #define SF_DEFINED 0x00002000 /* Symbol is defined in this file. */
248 #define SF_STRING 0x00004000 /* Symbol name length > 8. */
249 #define SF_LOCAL 0x00008000 /* Symbol must not be emitted. */
251 #define SF_DEBUG_MASK 0xffff0000 /* bits 16-31 are debug info. */
253 #define SF_FUNCTION 0x00010000 /* The symbol is a function. */
254 #define SF_PROCESS 0x00020000 /* Process symbol before write. */
255 #define SF_TAGGED 0x00040000 /* Is associated with a tag. */
256 #define SF_TAG 0x00080000 /* Is a tag. */
257 #define SF_DEBUG 0x00100000 /* Is in debug or abs section. */
258 #define SF_GET_SEGMENT 0x00200000 /* Get the section of the forward symbol. */
259 /* All other bits are unused. */
262 #define SF_GET(s) (* symbol_get_obj (s))
263 #define SF_GET_DEBUG(s) (symbol_get_bfdsym (s)->flags & BSF_DEBUGGING)
264 #define SF_SET_DEBUG(s) (symbol_get_bfdsym (s)->flags |= BSF_DEBUGGING)
265 #define SF_GET_NORMAL_FIELD(s) (SF_GET (s) & SF_NORMAL_MASK)
266 #define SF_GET_DEBUG_FIELD(s) (SF_GET (s) & SF_DEBUG_MASK)
267 #define SF_GET_FILE(s) (SF_GET (s) & SF_FILE)
268 #define SF_GET_STATICS(s) (SF_GET (s) & SF_STATICS)
269 #define SF_GET_DEFINED(s) (SF_GET (s) & SF_DEFINED)
270 #define SF_GET_STRING(s) (SF_GET (s) & SF_STRING)
271 #define SF_GET_LOCAL(s) (SF_GET (s) & SF_LOCAL)
272 #define SF_GET_FUNCTION(s) (SF_GET (s) & SF_FUNCTION)
273 #define SF_GET_PROCESS(s) (SF_GET (s) & SF_PROCESS)
274 #define SF_GET_TAGGED(s) (SF_GET (s) & SF_TAGGED)
275 #define SF_GET_TAG(s) (SF_GET (s) & SF_TAG)
276 #define SF_GET_GET_SEGMENT(s) (SF_GET (s) & SF_GET_SEGMENT)
277 #define SF_GET_I960(s) (SF_GET (s) & SF_I960_MASK) /* Used by i960. */
278 #define SF_GET_BALNAME(s) (SF_GET (s) & SF_BALNAME) /* Used by i960. */
279 #define SF_GET_CALLNAME(s) (SF_GET (s) & SF_CALLNAME) /* Used by i960. */
280 #define SF_GET_IS_SYSPROC(s) (SF_GET (s) & SF_IS_SYSPROC) /* Used by i960. */
281 #define SF_GET_SYSPROC(s) (SF_GET (s) & SF_SYSPROC) /* Used by i960. */
284 #define SF_SET(s,v) (SF_GET (s) = (v))
285 #define SF_SET_NORMAL_FIELD(s,v)(SF_GET (s) |= ((v) & SF_NORMAL_MASK))
286 #define SF_SET_DEBUG_FIELD(s,v) (SF_GET (s) |= ((v) & SF_DEBUG_MASK))
287 #define SF_SET_FILE(s) (SF_GET (s) |= SF_FILE)
288 #define SF_SET_STATICS(s) (SF_GET (s) |= SF_STATICS)
289 #define SF_SET_DEFINED(s) (SF_GET (s) |= SF_DEFINED)
290 #define SF_SET_STRING(s) (SF_GET (s) |= SF_STRING)
291 #define SF_SET_LOCAL(s) (SF_GET (s) |= SF_LOCAL)
292 #define SF_CLEAR_LOCAL(s) (SF_GET (s) &= ~SF_LOCAL)
293 #define SF_SET_FUNCTION(s) (SF_GET (s) |= SF_FUNCTION)
294 #define SF_SET_PROCESS(s) (SF_GET (s) |= SF_PROCESS)
295 #define SF_SET_TAGGED(s) (SF_GET (s) |= SF_TAGGED)
296 #define SF_SET_TAG(s) (SF_GET (s) |= SF_TAG)
297 #define SF_SET_GET_SEGMENT(s) (SF_GET (s) |= SF_GET_SEGMENT)
298 #define SF_SET_I960(s,v) (SF_GET (s) |= ((v) & SF_I960_MASK)) /* Used by i960. */
299 #define SF_SET_BALNAME(s) (SF_GET (s) |= SF_BALNAME) /* Used by i960. */
300 #define SF_SET_CALLNAME(s) (SF_GET (s) |= SF_CALLNAME) /* Used by i960. */
301 #define SF_SET_IS_SYSPROC(s) (SF_GET (s) |= SF_IS_SYSPROC) /* Used by i960. */
302 #define SF_SET_SYSPROC(s,v) (SF_GET (s) |= ((v) & SF_SYSPROC)) /* Used by i960. */
305 /* Line number handling. */
306 extern int text_lineno_number
;
307 extern int coff_line_base
;
308 extern int coff_n_line_nos
;
309 extern symbolS
*coff_last_function
;
311 #define obj_emit_lineno(WHERE, LINE, FILE_START) abort ()
312 #define obj_app_file(name, app) c_dot_file_symbol (name, app)
313 #define obj_frob_symbol(S,P) coff_frob_symbol (S, & P)
314 #define obj_frob_section(S) coff_frob_section (S)
315 #define obj_frob_file_after_relocs() coff_frob_file_after_relocs ()
316 #ifndef obj_adjust_symtab
317 #define obj_adjust_symtab() coff_adjust_symtab ()
320 /* Forward the segment of a forwarded symbol, handle assignments that
321 just copy symbol values, etc. */
322 #ifndef OBJ_COPY_SYMBOL_ATTRIBUTES
324 #define OBJ_COPY_SYMBOL_ATTRIBUTES(dest, src) \
325 (SF_GET_GET_SEGMENT (dest) \
326 ? (S_SET_SEGMENT (dest, S_GET_SEGMENT (src)), 0) \
329 #define OBJ_COPY_SYMBOL_ATTRIBUTES(dest, src) \
330 (SF_GET_GET_SEGMENT (dest) && S_GET_SEGMENT (dest) == SEG_UNKNOWN \
331 ? (S_SET_SEGMENT (dest, S_GET_SEGMENT (src)), 0) \
340 hey
! Where is the C_LEAFSTAT definition
? i960
- coff support is depending on it
.
341 #endif /* no C_LEAFSTAT */
344 extern const pseudo_typeS coff_pseudo_table
[];
346 #ifndef obj_pop_insert
347 #define obj_pop_insert() pop_insert (coff_pseudo_table)
350 /* In COFF, if a symbol is defined using .def/.val SYM/.endef, it's OK
351 to redefine the symbol later on. This can happen if C symbols use
352 a prefix, and a symbol is defined both with and without the prefix,
353 as in start/_start/__start in gcc/libgcc1-test.c. */
354 #define RESOLVE_SYMBOL_REDEFINITION(sym) \
355 (SF_GET_GET_SEGMENT (sym) \
356 ? (sym->sy_frag = frag_now, \
357 S_SET_VALUE (sym, frag_now_fix ()), \
358 S_SET_SEGMENT (sym, now_seg), \
362 /* Stabs in a coff file go into their own section. */
363 #define SEPARATE_STAB_SECTIONS 1
365 /* We need 12 bytes at the start of the section to hold some initial
367 #define INIT_STAB_SECTION(seg) obj_coff_init_stab_section (seg)
369 /* Store the number of relocations in the section aux entry. */
370 #define SET_SECTION_RELOCS(sec, relocs, n) \
371 SA_SET_SCN_NRELOC (section_symbol (sec), n)
373 #define obj_app_file(name, app) c_dot_file_symbol (name, app)
375 extern int S_SET_DATA_TYPE (symbolS
*, int);
376 extern int S_SET_STORAGE_CLASS (symbolS
*, int);
377 extern int S_GET_STORAGE_CLASS (symbolS
*);
378 extern void SA_SET_SYM_ENDNDX (symbolS
*, symbolS
*);
379 extern void coff_add_linesym (symbolS
*);
380 extern void c_dot_file_symbol (const char *, int);
381 extern void coff_frob_symbol (symbolS
*, int *);
382 extern void coff_adjust_symtab (void);
383 extern void coff_frob_section (segT
);
384 extern void coff_adjust_section_syms (bfd
*, asection
*, void *);
385 extern void coff_frob_file_after_relocs (void);
386 extern void coff_obj_symbol_new_hook (symbolS
*);
387 extern void coff_obj_symbol_clone_hook (symbolS
*, symbolS
*);
388 extern void coff_obj_read_begin_hook (void);
390 extern void pecoff_obj_set_weak_hook (symbolS
*);
391 extern void pecoff_obj_clear_weak_hook (symbolS
*);
393 extern void obj_coff_section (int);
394 extern segT
obj_coff_add_segment (const char *);
395 extern void obj_coff_section (int);
396 extern void c_dot_file_symbol (const char *, int);
397 extern segT
s_get_segment (symbolS
*);
398 #ifndef tc_coff_symbol_emit_hook
399 extern void tc_coff_symbol_emit_hook (symbolS
*);
401 extern void obj_coff_pe_handle_link_once (void);
402 extern void obj_coff_init_stab_section (segT
);
403 extern void c_section_header (struct internal_scnhdr
*,
404 char *, long, long, long, long,
405 long, long, long, long);
406 extern void obj_coff_seh_do_final (void);
408 #ifndef obj_coff_generate_pdata
409 #define obj_coff_generate_pdata obj_coff_seh_do_final
413 #endif /* OBJ_FORMAT_H */