obj-coff.h 14 KB

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