gdb/dap: allow some requests when the process is running
[binutils-gdb.git] / gas / config / obj-ecoff.c
blobc79d57d6f63b17ea0a0ba076e9510857ed519646
1 /* ECOFF object file format.
2 Copyright (C) 1993-2024 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
4 This file was put together by Ian Lance Taylor <ian@cygnus.com>.
6 This file is part of GAS.
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 3, or (at your option)
11 any later version.
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.
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, 51 Franklin Street - Fifth Floor, Boston, MA
21 02110-1301, USA. */
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 #include "bfd/ecoff-bfd.h"
30 /* Almost all of the ECOFF support is actually in ecoff.c in the main
31 gas directory. This file mostly just arranges to call that one at
32 the right times. */
34 /* Set section VMAs and GP values before reloc processing. */
36 void
37 ecoff_frob_file_before_fix (void)
39 bfd_vma addr;
40 asection *sec;
42 /* Set the section VMA values. We force the .sdata and .sbss
43 sections to the end to ensure that their VMA addresses are close
44 together so that the GP register can address both of them. We
45 put the .bss section after the .sbss section.
47 Also, for the Alpha, we must sort the sections, to make sure they
48 appear in the output file in the correct order. (Actually, maybe
49 this is a job for BFD. But the VMAs computed would be out of
50 whack if we computed them given our initial, random ordering.
51 It's possible that that wouldn't break things; I could do some
52 experimenting sometime and find out.
54 This output ordering of sections is magic, on the Alpha, at
55 least. The .lita section must come before .lit8 and .lit4,
56 otherwise the OSF/1 linker may silently trash the .lit{4,8}
57 section contents. Also, .text must precede .rdata. These differ
58 from the order described in some parts of the DEC OSF/1 Assembly
59 Language Programmer's Guide, but that order doesn't seem to work
60 with their linker.
62 I don't know if section ordering on the MIPS is important. */
64 static const char *const names[] =
66 /* text segment */
67 ".text", ".rdata", ".init", ".fini",
68 /* data segment */
69 ".data", ".lita", ".lit8", ".lit4", ".sdata", ".got",
70 /* bss segment */
71 ".sbss", ".bss",
73 #define n_names ((int) (sizeof (names) / sizeof (names[0])))
75 /* Sections that match names, order to be straightened out later. */
76 asection *secs[n_names];
77 int i;
79 addr = 0;
80 for (i = 0; i < n_names; i++)
81 secs[i] = NULL;
83 for (sec = stdoutput->sections; sec != NULL; sec = sec->next)
85 for (i = 0; i < n_names; i++)
86 if (!strcmp (sec->name, names[i]))
88 secs[i] = sec;
89 bfd_section_list_remove (stdoutput, sec);
90 break;
92 if (i == n_names)
94 bfd_set_section_vma (sec, addr);
95 addr += bfd_section_size (sec);
98 for (i = 0; i < n_names; i++)
99 if (secs[i])
101 bfd_set_section_vma (secs[i], addr);
102 addr += bfd_section_size (secs[i]);
104 for (i = n_names - 1; i >= 0; i--)
105 if (secs[i])
106 bfd_section_list_prepend (stdoutput, secs[i]);
108 /* Fill in the register masks. */
110 unsigned long gprmask = 0;
111 unsigned long fprmask = 0;
112 unsigned long *cprmask = NULL;
114 #ifdef TC_MIPS
115 /* Fill in the MIPS register masks. It's probably not worth
116 setting up a generic interface for this. */
117 gprmask = mips_gprmask;
118 cprmask = mips_cprmask;
119 #endif
121 #ifdef TC_ALPHA
122 alpha_frob_ecoff_data ();
124 if (! bfd_ecoff_set_gp_value (stdoutput, alpha_gp_value))
125 as_fatal (_("Can't set GP value"));
127 gprmask = alpha_gprmask;
128 fprmask = alpha_fprmask;
129 #endif
131 if (! bfd_ecoff_set_regmasks (stdoutput, gprmask, fprmask, cprmask))
132 as_fatal (_("Can't set register masks"));
136 /* Swap out the symbols and debugging information for BFD. */
138 void
139 ecoff_frob_file (void)
141 const struct ecoff_debug_swap * const debug_swap
142 = &ecoff_backend (stdoutput)->debug_swap;
143 bfd_vma addr ATTRIBUTE_UNUSED;
144 HDRR *hdr;
145 char *buf;
146 char *set;
148 /* Build the ECOFF debugging information. */
149 gas_assert (ecoff_data (stdoutput) != 0);
150 hdr = &ecoff_data (stdoutput)->debug_info.symbolic_header;
151 ecoff_build_debug (hdr, &buf, debug_swap);
153 /* Finish up the ecoff_tdata structure. */
154 ecoff_data (stdoutput)->debug_info.alloc_syments = true;
155 set = buf;
156 #define SET(ptr, count, type, size) \
157 if (hdr->count == 0) \
158 ecoff_data (stdoutput)->debug_info.ptr = NULL; \
159 else \
161 ecoff_data (stdoutput)->debug_info.ptr = (type) set; \
162 set += hdr->count * size; \
165 SET (line, cbLine, unsigned char *, sizeof (unsigned char));
166 SET (external_dnr, idnMax, void *, debug_swap->external_dnr_size);
167 SET (external_pdr, ipdMax, void *, debug_swap->external_pdr_size);
168 SET (external_sym, isymMax, void *, debug_swap->external_sym_size);
169 SET (external_opt, ioptMax, void *, debug_swap->external_opt_size);
170 SET (external_aux, iauxMax, union aux_ext *, sizeof (union aux_ext));
171 SET (ss, issMax, char *, sizeof (char));
172 SET (ssext, issExtMax, char *, sizeof (char));
173 SET (external_rfd, crfd, void *, debug_swap->external_rfd_size);
174 SET (external_fdr, ifdMax, void *, debug_swap->external_fdr_size);
175 SET (external_ext, iextMax, void *, debug_swap->external_ext_size);
176 #undef SET
179 /* This is called by the ECOFF code to set the external information
180 for a symbol. We just pass it on to BFD, which expects the swapped
181 information to be stored in the native field of the symbol. */
183 void
184 obj_ecoff_set_ext (symbolS *sym, EXTR *ext)
186 const struct ecoff_debug_swap * const debug_swap
187 = &ecoff_backend (stdoutput)->debug_swap;
188 ecoff_symbol_type *esym;
190 know (bfd_asymbol_flavour (symbol_get_bfdsym (sym))
191 == bfd_target_ecoff_flavour);
192 esym = ecoffsymbol (symbol_get_bfdsym (sym));
193 esym->local = false;
194 esym->native = xmalloc (debug_swap->external_ext_size);
195 (*debug_swap->swap_ext_out) (stdoutput, ext, esym->native);
198 /* These are the pseudo-ops we support in this file. Only those
199 relating to debugging information are supported here.
201 The following pseudo-ops from the Kane and Heinrich MIPS book
202 should be defined here, but are currently unsupported: .bgnb,
203 .endb, .verstamp, .vreg.
205 The following pseudo-ops from the Kane and Heinrich MIPS book are
206 MIPS CPU specific, and should be defined by tc-mips.c: .alias,
207 .extern, .galive, .gjaldef, .gjrlive, .livereg, .noalias, .option,
208 .rdata, .sdata, .set.
210 The following pseudo-ops from the Kane and Heinrich MIPS book are
211 not MIPS CPU specific, but are also not ECOFF specific. I have
212 only listed the ones which are not already in read.c. It's not
213 completely clear where these should be defined, but tc-mips.c is
214 probably the most reasonable place: .asciiz, .asm0, .endr, .err,
215 .half, .lab, .repeat, .struct, .weakext. */
217 const pseudo_typeS obj_pseudo_table[] =
219 /* COFF style debugging information. .ln is not used; .loc is used
220 instead. */
221 { "def", ecoff_directive_def, 0 },
222 { "dim", ecoff_directive_dim, 0 },
223 { "endef", ecoff_directive_endef, 0 },
224 { "file", ecoff_directive_file, 0 },
225 { "scl", ecoff_directive_scl, 0 },
226 { "size", ecoff_directive_size, 0 },
227 { "esize", ecoff_directive_size, 0 },
228 { "tag", ecoff_directive_tag, 0 },
229 { "type", ecoff_directive_type, 0 },
230 { "etype", ecoff_directive_type, 0 },
231 { "val", ecoff_directive_val, 0 },
233 /* ECOFF specific debugging information. */
234 { "aent", ecoff_directive_ent, 1 },
235 { "begin", ecoff_directive_begin, 0 },
236 { "bend", ecoff_directive_bend, 0 },
237 { "end", ecoff_directive_end, 0 },
238 { "ent", ecoff_directive_ent, 0 },
239 { "fmask", ecoff_directive_fmask, 0 },
240 { "frame", ecoff_directive_frame, 0 },
241 { "loc", ecoff_directive_loc, 0 },
242 { "mask", ecoff_directive_mask, 0 },
244 /* Other ECOFF directives. */
245 { "extern", ecoff_directive_extern, 0 },
247 #ifndef TC_MIPS
248 /* For TC_MIPS, tc-mips.c adds this. */
249 { "weakext", ecoff_directive_weakext, 0 },
250 #endif
252 /* These are used on Irix. I don't know how to implement them. */
253 { "bgnb", s_ignore, 0 },
254 { "endb", s_ignore, 0 },
255 { "verstamp", s_ignore, 0 },
257 /* Sentinel. */
258 { NULL, s_ignore, 0 }
261 #ifdef USE_EMULATIONS
263 static int
264 ecoff_sec_sym_ok_for_reloc (asection *sec ATTRIBUTE_UNUSED)
266 return 1;
269 static void
270 obj_ecoff_frob_symbol (symbolS *sym, int *puntp ATTRIBUTE_UNUSED)
272 ecoff_frob_symbol (sym);
275 static void
276 ecoff_pop_insert (void)
278 pop_insert (obj_pseudo_table);
281 static int
282 ecoff_separate_stab_sections (void)
284 return 0;
287 const struct format_ops ecoff_format_ops =
289 bfd_target_ecoff_flavour,
290 0, /* dfl_leading_underscore. */
292 /* FIXME: A comment why emit_section_symbols is different here (1) from
293 the single-format definition (0) would be in order. */
294 1, /* emit_section_symbols. */
295 0, /* begin. */
296 0, /* end. */
297 ecoff_new_file,
298 NULL, /* assign_symbol */
299 obj_ecoff_frob_symbol,
300 ecoff_frob_file,
301 0, /* frob_file_before_adjust. */
302 ecoff_frob_file_before_fix,
303 0, /* frob_file_after_relocs. */
304 0, /* s_get_size. */
305 0, /* s_set_size. */
306 0, /* s_get_align. */
307 0, /* s_set_align. */
308 0, /* s_get_other. */
309 0, /* s_set_other. */
310 0, /* s_get_desc. */
311 0, /* s_set_desc. */
312 0, /* s_get_type. */
313 0, /* s_set_type. */
314 0, /* copy_symbol_attributes. */
315 ecoff_stab,
316 ecoff_separate_stab_sections,
317 0, /* init_stab_section. */
318 ecoff_sec_sym_ok_for_reloc,
319 ecoff_pop_insert,
320 ecoff_set_ext,
321 ecoff_read_begin_hook,
322 ecoff_symbol_new_hook,
323 ecoff_symbol_clone_hook,
324 0 /* adjust_symtab. */
327 #endif /* USE_EMULATIONS */