obj-ecoff.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. /* ECOFF object file format.
  2. Copyright (C) 1993-2015 Free Software Foundation, Inc.
  3. Contributed by Cygnus Support.
  4. This file was put together by Ian Lance Taylor <ian@cygnus.com>.
  5. 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)
  9. any later version.
  10. GAS is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with GAS; see the file COPYING. If not, write to the Free
  16. Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
  17. 02110-1301, USA. */
  18. #define OBJ_HEADER "obj-ecoff.h"
  19. #include "as.h"
  20. #include "coff/internal.h"
  21. #include "bfd/libcoff.h"
  22. #include "bfd/libecoff.h"
  23. /* Almost all of the ECOFF support is actually in ecoff.c in the main
  24. gas directory. This file mostly just arranges to call that one at
  25. the right times. */
  26. /* Set section VMAs and GP values before reloc processing. */
  27. void
  28. ecoff_frob_file_before_fix (void)
  29. {
  30. bfd_vma addr;
  31. asection *sec;
  32. /* Set the section VMA values. We force the .sdata and .sbss
  33. sections to the end to ensure that their VMA addresses are close
  34. together so that the GP register can address both of them. We
  35. put the .bss section after the .sbss section.
  36. Also, for the Alpha, we must sort the sections, to make sure they
  37. appear in the output file in the correct order. (Actually, maybe
  38. this is a job for BFD. But the VMAs computed would be out of
  39. whack if we computed them given our initial, random ordering.
  40. It's possible that that wouldn't break things; I could do some
  41. experimenting sometime and find out.
  42. This output ordering of sections is magic, on the Alpha, at
  43. least. The .lita section must come before .lit8 and .lit4,
  44. otherwise the OSF/1 linker may silently trash the .lit{4,8}
  45. section contents. Also, .text must preceed .rdata. These differ
  46. from the order described in some parts of the DEC OSF/1 Assembly
  47. Language Programmer's Guide, but that order doesn't seem to work
  48. with their linker.
  49. I don't know if section ordering on the MIPS is important. */
  50. static const char *const names[] =
  51. {
  52. /* text segment */
  53. ".text", ".rdata", ".init", ".fini",
  54. /* data segment */
  55. ".data", ".lita", ".lit8", ".lit4", ".sdata", ".got",
  56. /* bss segment */
  57. ".sbss", ".bss",
  58. };
  59. #define n_names ((int) (sizeof (names) / sizeof (names[0])))
  60. /* Sections that match names, order to be straightened out later. */
  61. asection *secs[n_names];
  62. int i;
  63. addr = 0;
  64. for (i = 0; i < n_names; i++)
  65. secs[i] = NULL;
  66. for (sec = stdoutput->sections; sec != NULL; sec = sec->next)
  67. {
  68. for (i = 0; i < n_names; i++)
  69. if (!strcmp (sec->name, names[i]))
  70. {
  71. secs[i] = sec;
  72. bfd_section_list_remove (stdoutput, sec);
  73. break;
  74. }
  75. if (i == n_names)
  76. {
  77. bfd_set_section_vma (stdoutput, sec, addr);
  78. addr += bfd_section_size (stdoutput, sec);
  79. }
  80. }
  81. for (i = 0; i < n_names; i++)
  82. if (secs[i])
  83. {
  84. bfd_set_section_vma (stdoutput, secs[i], addr);
  85. addr += bfd_section_size (stdoutput, secs[i]);
  86. }
  87. for (i = n_names - 1; i >= 0; i--)
  88. if (secs[i])
  89. bfd_section_list_prepend (stdoutput, secs[i]);
  90. /* Fill in the register masks. */
  91. {
  92. unsigned long gprmask = 0;
  93. unsigned long fprmask = 0;
  94. unsigned long *cprmask = NULL;
  95. #ifdef TC_MIPS
  96. /* Fill in the MIPS register masks. It's probably not worth
  97. setting up a generic interface for this. */
  98. gprmask = mips_gprmask;
  99. cprmask = mips_cprmask;
  100. #endif
  101. #ifdef TC_ALPHA
  102. alpha_frob_ecoff_data ();
  103. if (! bfd_ecoff_set_gp_value (stdoutput, alpha_gp_value))
  104. as_fatal (_("Can't set GP value"));
  105. gprmask = alpha_gprmask;
  106. fprmask = alpha_fprmask;
  107. #endif
  108. if (! bfd_ecoff_set_regmasks (stdoutput, gprmask, fprmask, cprmask))
  109. as_fatal (_("Can't set register masks"));
  110. }
  111. }
  112. /* Swap out the symbols and debugging information for BFD. */
  113. void
  114. ecoff_frob_file (void)
  115. {
  116. const struct ecoff_debug_swap * const debug_swap
  117. = &ecoff_backend (stdoutput)->debug_swap;
  118. bfd_vma addr ATTRIBUTE_UNUSED;
  119. HDRR *hdr;
  120. char *buf;
  121. char *set;
  122. /* Build the ECOFF debugging information. */
  123. gas_assert (ecoff_data (stdoutput) != 0);
  124. hdr = &ecoff_data (stdoutput)->debug_info.symbolic_header;
  125. ecoff_build_debug (hdr, &buf, debug_swap);
  126. /* Finish up the ecoff_tdata structure. */
  127. set = buf;
  128. #define SET(ptr, count, type, size) \
  129. if (hdr->count == 0) \
  130. ecoff_data (stdoutput)->debug_info.ptr = NULL; \
  131. else \
  132. { \
  133. ecoff_data (stdoutput)->debug_info.ptr = (type) set; \
  134. set += hdr->count * size; \
  135. }
  136. SET (line, cbLine, unsigned char *, sizeof (unsigned char));
  137. SET (external_dnr, idnMax, void *, debug_swap->external_dnr_size);
  138. SET (external_pdr, ipdMax, void *, debug_swap->external_pdr_size);
  139. SET (external_sym, isymMax, void *, debug_swap->external_sym_size);
  140. SET (external_opt, ioptMax, void *, debug_swap->external_opt_size);
  141. SET (external_aux, iauxMax, union aux_ext *, sizeof (union aux_ext));
  142. SET (ss, issMax, char *, sizeof (char));
  143. SET (ssext, issExtMax, char *, sizeof (char));
  144. SET (external_rfd, crfd, void *, debug_swap->external_rfd_size);
  145. SET (external_fdr, ifdMax, void *, debug_swap->external_fdr_size);
  146. SET (external_ext, iextMax, void *, debug_swap->external_ext_size);
  147. #undef SET
  148. }
  149. /* This is called by the ECOFF code to set the external information
  150. for a symbol. We just pass it on to BFD, which expects the swapped
  151. information to be stored in the native field of the symbol. */
  152. void
  153. obj_ecoff_set_ext (symbolS *sym, EXTR *ext)
  154. {
  155. const struct ecoff_debug_swap * const debug_swap
  156. = &ecoff_backend (stdoutput)->debug_swap;
  157. ecoff_symbol_type *esym;
  158. know (bfd_asymbol_flavour (symbol_get_bfdsym (sym))
  159. == bfd_target_ecoff_flavour);
  160. esym = ecoffsymbol (symbol_get_bfdsym (sym));
  161. esym->local = FALSE;
  162. esym->native = xmalloc (debug_swap->external_ext_size);
  163. (*debug_swap->swap_ext_out) (stdoutput, ext, esym->native);
  164. }
  165. static int
  166. ecoff_sec_sym_ok_for_reloc (asection *sec ATTRIBUTE_UNUSED)
  167. {
  168. return 1;
  169. }
  170. static void
  171. obj_ecoff_frob_symbol (symbolS *sym, int *puntp ATTRIBUTE_UNUSED)
  172. {
  173. ecoff_frob_symbol (sym);
  174. }
  175. static void
  176. ecoff_pop_insert (void)
  177. {
  178. pop_insert (obj_pseudo_table);
  179. }
  180. static int
  181. ecoff_separate_stab_sections (void)
  182. {
  183. return 0;
  184. }
  185. /* These are the pseudo-ops we support in this file. Only those
  186. relating to debugging information are supported here.
  187. The following pseudo-ops from the Kane and Heinrich MIPS book
  188. should be defined here, but are currently unsupported: .aent,
  189. .bgnb, .endb, .verstamp, .vreg.
  190. The following pseudo-ops from the Kane and Heinrich MIPS book are
  191. MIPS CPU specific, and should be defined by tc-mips.c: .alias,
  192. .extern, .galive, .gjaldef, .gjrlive, .livereg, .noalias, .option,
  193. .rdata, .sdata, .set.
  194. The following pseudo-ops from the Kane and Heinrich MIPS book are
  195. not MIPS CPU specific, but are also not ECOFF specific. I have
  196. only listed the ones which are not already in read.c. It's not
  197. completely clear where these should be defined, but tc-mips.c is
  198. probably the most reasonable place: .asciiz, .asm0, .endr, .err,
  199. .half, .lab, .repeat, .struct, .weakext. */
  200. const pseudo_typeS obj_pseudo_table[] =
  201. {
  202. /* COFF style debugging information. .ln is not used; .loc is used
  203. instead. */
  204. { "def", ecoff_directive_def, 0 },
  205. { "dim", ecoff_directive_dim, 0 },
  206. { "endef", ecoff_directive_endef, 0 },
  207. { "file", ecoff_directive_file, 0 },
  208. { "scl", ecoff_directive_scl, 0 },
  209. { "size", ecoff_directive_size, 0 },
  210. { "esize", ecoff_directive_size, 0 },
  211. { "tag", ecoff_directive_tag, 0 },
  212. { "type", ecoff_directive_type, 0 },
  213. { "etype", ecoff_directive_type, 0 },
  214. { "val", ecoff_directive_val, 0 },
  215. /* ECOFF specific debugging information. */
  216. { "begin", ecoff_directive_begin, 0 },
  217. { "bend", ecoff_directive_bend, 0 },
  218. { "end", ecoff_directive_end, 0 },
  219. { "ent", ecoff_directive_ent, 0 },
  220. { "fmask", ecoff_directive_fmask, 0 },
  221. { "frame", ecoff_directive_frame, 0 },
  222. { "loc", ecoff_directive_loc, 0 },
  223. { "mask", ecoff_directive_mask, 0 },
  224. /* Other ECOFF directives. */
  225. { "extern", ecoff_directive_extern, 0 },
  226. #ifndef TC_MIPS
  227. /* For TC_MIPS, tc-mips.c adds this. */
  228. { "weakext", ecoff_directive_weakext, 0 },
  229. #endif
  230. /* These are used on Irix. I don't know how to implement them. */
  231. { "bgnb", s_ignore, 0 },
  232. { "endb", s_ignore, 0 },
  233. { "verstamp", s_ignore, 0 },
  234. /* Sentinel. */
  235. { NULL, s_ignore, 0 }
  236. };
  237. const struct format_ops ecoff_format_ops =
  238. {
  239. bfd_target_ecoff_flavour,
  240. 0, /* dfl_leading_underscore. */
  241. /* FIXME: A comment why emit_section_symbols is different here (1) from
  242. the single-format definition (0) would be in order. */
  243. 1, /* emit_section_symbols. */
  244. 0, /* begin. */
  245. ecoff_new_file,
  246. obj_ecoff_frob_symbol,
  247. ecoff_frob_file,
  248. 0, /* frob_file_before_adjust. */
  249. ecoff_frob_file_before_fix,
  250. 0, /* frob_file_after_relocs. */
  251. 0, /* s_get_size. */
  252. 0, /* s_set_size. */
  253. 0, /* s_get_align. */
  254. 0, /* s_set_align. */
  255. 0, /* s_get_other. */
  256. 0, /* s_set_other. */
  257. 0, /* s_get_desc. */
  258. 0, /* s_set_desc. */
  259. 0, /* s_get_type. */
  260. 0, /* s_set_type. */
  261. 0, /* copy_symbol_attributes. */
  262. ecoff_generate_asm_lineno,
  263. ecoff_stab,
  264. ecoff_separate_stab_sections,
  265. 0, /* init_stab_section. */
  266. ecoff_sec_sym_ok_for_reloc,
  267. ecoff_pop_insert,
  268. ecoff_set_ext,
  269. ecoff_read_begin_hook,
  270. ecoff_symbol_new_hook,
  271. ecoff_symbol_clone_hook,
  272. 0 /* adjust_symtab. */
  273. };