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