obj-coff.h 12 KB

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