Import binutils 2.18
[nacl-binutils.git] / include / coff / ecoff.h
blobd4d3fa52d2358d67901ab9567f3d5193d9a7c465
1 /* Generic ECOFF support.
2 This does not include symbol information, found in sym.h and
3 symconst.h.
5 Copyright 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
21 #ifndef ECOFF_H
22 #define ECOFF_H
24 /* Mips magic numbers used in filehdr. MIPS_MAGIC_LITTLE is used on
25 little endian machines. MIPS_MAGIC_BIG is used on big endian
26 machines. Where is MIPS_MAGIC_1 from? */
27 #define MIPS_MAGIC_1 0x0180
28 #define MIPS_MAGIC_LITTLE 0x0162
29 #define MIPS_MAGIC_BIG 0x0160
31 /* These are the magic numbers used for MIPS code compiled at ISA
32 level 2. */
33 #define MIPS_MAGIC_LITTLE2 0x0166
34 #define MIPS_MAGIC_BIG2 0x0163
36 /* These are the magic numbers used for MIPS code compiled at ISA
37 level 3. */
38 #define MIPS_MAGIC_LITTLE3 0x142
39 #define MIPS_MAGIC_BIG3 0x140
41 /* Alpha magic numbers used in filehdr. */
42 #define ALPHA_MAGIC 0x183
43 #define ALPHA_MAGIC_BSD 0x185
44 /* A compressed version of an ALPHA_MAGIC file created by DEC's tools. */
45 #define ALPHA_MAGIC_COMPRESSED 0x188
47 /* Magic numbers used in a.out header. */
48 #define ECOFF_AOUT_OMAGIC 0407 /* not demand paged (ld -N). */
49 #define ECOFF_AOUT_ZMAGIC 0413 /* demand load format, eg normal ld output */
51 /* Names of special sections. */
52 #define _TEXT ".text"
53 #define _DATA ".data"
54 #define _BSS ".bss"
55 #define _RDATA ".rdata"
56 #define _SDATA ".sdata"
57 #define _SBSS ".sbss"
58 #define _LITA ".lita"
59 #define _LIT4 ".lit4"
60 #define _LIT8 ".lit8"
61 #define _LIB ".lib"
62 #define _INIT ".init"
63 #define _FINI ".fini"
64 #define _PDATA ".pdata"
65 #define _XDATA ".xdata"
66 #define _GOT ".got"
67 #define _HASH ".hash"
68 #define _DYNSYM ".dynsym"
69 #define _DYNSTR ".dynstr"
70 #define _RELDYN ".rel.dyn"
71 #define _CONFLIC ".conflic"
72 #define _COMMENT ".comment"
73 #define _LIBLIST ".liblist"
74 #define _DYNAMIC ".dynamic"
75 #define _RCONST ".rconst"
77 /* ECOFF uses some additional section flags. */
78 #define STYP_RDATA 0x100
79 #define STYP_SDATA 0x200
80 #define STYP_SBSS 0x400
81 #define STYP_GOT 0x1000
82 #define STYP_DYNAMIC 0x2000
83 #define STYP_DYNSYM 0x4000
84 #define STYP_RELDYN 0x8000
85 #define STYP_DYNSTR 0x10000
86 #define STYP_HASH 0x20000
87 #define STYP_LIBLIST 0x40000
88 #define STYP_CONFLIC 0x100000
89 #define STYP_ECOFF_FINI 0x1000000
90 #define STYP_EXTENDESC 0x2000000 /* 0x02FFF000 bits => scn type, rest clr */
91 #define STYP_LITA 0x4000000
92 #define STYP_LIT8 0x8000000
93 #define STYP_LIT4 0x10000000
94 #define STYP_ECOFF_LIB 0x40000000
95 #define STYP_ECOFF_INIT 0x80000000
96 #define STYP_OTHER_LOAD (STYP_ECOFF_INIT | STYP_ECOFF_FINI)
98 /* extended section types */
99 #define STYP_COMMENT 0x2100000
100 #define STYP_RCONST 0x2200000
101 #define STYP_XDATA 0x2400000
102 #define STYP_PDATA 0x2800000
104 /* The linker needs a section to hold small common variables while
105 linking. There is no convenient way to create it when the linker
106 needs it, so we always create one for each BFD. We then avoid
107 writing it out. */
108 #define SCOMMON ".scommon"
110 /* If the extern bit in a reloc is 1, then r_symndx is an index into
111 the external symbol table. If the extern bit is 0, then r_symndx
112 indicates a section, and is one of the following values. */
113 #define RELOC_SECTION_NONE 0
114 #define RELOC_SECTION_TEXT 1
115 #define RELOC_SECTION_RDATA 2
116 #define RELOC_SECTION_DATA 3
117 #define RELOC_SECTION_SDATA 4
118 #define RELOC_SECTION_SBSS 5
119 #define RELOC_SECTION_BSS 6
120 #define RELOC_SECTION_INIT 7
121 #define RELOC_SECTION_LIT8 8
122 #define RELOC_SECTION_LIT4 9
123 #define RELOC_SECTION_XDATA 10
124 #define RELOC_SECTION_PDATA 11
125 #define RELOC_SECTION_FINI 12
126 #define RELOC_SECTION_LITA 13
127 #define RELOC_SECTION_ABS 14
128 #define RELOC_SECTION_RCONST 15
130 #define NUM_RELOC_SECTIONS 16
132 /********************** STABS **********************/
134 /* gcc uses mips-tfile to output type information in special stabs
135 entries. These must match the corresponding definition in
136 gcc/config/mips.h. At some point, these should probably go into a
137 shared include file, but currently gcc and gdb do not share any
138 directories. */
139 #define CODE_MASK 0x8F300
140 #define ECOFF_IS_STAB(sym) (((sym)->index & 0xFFF00) == CODE_MASK)
141 #define ECOFF_MARK_STAB(code) ((code)+CODE_MASK)
142 #define ECOFF_UNMARK_STAB(code) ((code)-CODE_MASK)
143 #define STABS_SYMBOL "@stabs"
145 /********************** COFF **********************/
147 /* gcc also uses mips-tfile to output COFF debugging information.
148 These are the values it uses when outputting the .type directive.
149 These should also be in a shared include file. */
150 #define N_BTMASK (017)
151 #define N_TMASK (060)
152 #define N_BTSHFT (4)
153 #define N_TSHIFT (2)
155 /********************** AUX **********************/
157 /* The auxiliary type information is the same on all known ECOFF
158 targets. I can't see any reason that it would ever change, so I am
159 going to gamble and define the external structures here, in the
160 target independent ECOFF header file. The internal forms are
161 defined in coff/sym.h, which was originally donated by MIPS
162 Computer Systems. */
164 /* Type information external record */
166 struct tir_ext {
167 unsigned char t_bits1[1];
168 unsigned char t_tq45[1];
169 unsigned char t_tq01[1];
170 unsigned char t_tq23[1];
173 #define TIR_BITS1_FBITFIELD_BIG ((unsigned int) 0x80)
174 #define TIR_BITS1_FBITFIELD_LITTLE ((unsigned int) 0x01)
176 #define TIR_BITS1_CONTINUED_BIG ((unsigned int) 0x40)
177 #define TIR_BITS1_CONTINUED_LITTLE ((unsigned int) 0x02)
179 #define TIR_BITS1_BT_BIG ((unsigned int) 0x3F)
180 #define TIR_BITS1_BT_SH_BIG 0
181 #define TIR_BITS1_BT_LITTLE ((unsigned int) 0xFC)
182 #define TIR_BITS1_BT_SH_LITTLE 2
184 #define TIR_BITS_TQ4_BIG ((unsigned int) 0xF0)
185 #define TIR_BITS_TQ4_SH_BIG 4
186 #define TIR_BITS_TQ5_BIG ((unsigned int) 0x0F)
187 #define TIR_BITS_TQ5_SH_BIG 0
188 #define TIR_BITS_TQ4_LITTLE ((unsigned int) 0x0F)
189 #define TIR_BITS_TQ4_SH_LITTLE 0
190 #define TIR_BITS_TQ5_LITTLE ((unsigned int) 0xF0)
191 #define TIR_BITS_TQ5_SH_LITTLE 4
193 #define TIR_BITS_TQ0_BIG ((unsigned int) 0xF0)
194 #define TIR_BITS_TQ0_SH_BIG 4
195 #define TIR_BITS_TQ1_BIG ((unsigned int) 0x0F)
196 #define TIR_BITS_TQ1_SH_BIG 0
197 #define TIR_BITS_TQ0_LITTLE ((unsigned int) 0x0F)
198 #define TIR_BITS_TQ0_SH_LITTLE 0
199 #define TIR_BITS_TQ1_LITTLE ((unsigned int) 0xF0)
200 #define TIR_BITS_TQ1_SH_LITTLE 4
202 #define TIR_BITS_TQ2_BIG ((unsigned int) 0xF0)
203 #define TIR_BITS_TQ2_SH_BIG 4
204 #define TIR_BITS_TQ3_BIG ((unsigned int) 0x0F)
205 #define TIR_BITS_TQ3_SH_BIG 0
206 #define TIR_BITS_TQ2_LITTLE ((unsigned int) 0x0F)
207 #define TIR_BITS_TQ2_SH_LITTLE 0
208 #define TIR_BITS_TQ3_LITTLE ((unsigned int) 0xF0)
209 #define TIR_BITS_TQ3_SH_LITTLE 4
211 /* Relative symbol external record */
213 struct rndx_ext {
214 unsigned char r_bits[4];
217 #define RNDX_BITS0_RFD_SH_LEFT_BIG 4
218 #define RNDX_BITS1_RFD_BIG ((unsigned int) 0xF0)
219 #define RNDX_BITS1_RFD_SH_BIG 4
221 #define RNDX_BITS0_RFD_SH_LEFT_LITTLE 0
222 #define RNDX_BITS1_RFD_LITTLE ((unsigned int) 0x0F)
223 #define RNDX_BITS1_RFD_SH_LEFT_LITTLE 8
225 #define RNDX_BITS1_INDEX_BIG ((unsigned int) 0x0F)
226 #define RNDX_BITS1_INDEX_SH_LEFT_BIG 16
227 #define RNDX_BITS2_INDEX_SH_LEFT_BIG 8
228 #define RNDX_BITS3_INDEX_SH_LEFT_BIG 0
230 #define RNDX_BITS1_INDEX_LITTLE ((unsigned int) 0xF0)
231 #define RNDX_BITS1_INDEX_SH_LITTLE 4
232 #define RNDX_BITS2_INDEX_SH_LEFT_LITTLE 4
233 #define RNDX_BITS3_INDEX_SH_LEFT_LITTLE 12
235 /* Auxiliary symbol information external record */
237 union aux_ext {
238 struct tir_ext a_ti;
239 struct rndx_ext a_rndx;
240 unsigned char a_dnLow[4];
241 unsigned char a_dnHigh[4];
242 unsigned char a_isym[4];
243 unsigned char a_iss[4];
244 unsigned char a_width[4];
245 unsigned char a_count[4];
248 #define AUX_GET_ANY(bigend, ax, field) \
249 ((bigend) ? bfd_getb32 ((ax)->field) : bfd_getl32 ((ax)->field))
251 #define AUX_GET_DNLOW(bigend, ax) AUX_GET_ANY ((bigend), (ax), a_dnLow)
252 #define AUX_GET_DNHIGH(bigend, ax) AUX_GET_ANY ((bigend), (ax), a_dnHigh)
253 #define AUX_GET_ISYM(bigend, ax) AUX_GET_ANY ((bigend), (ax), a_isym)
254 #define AUX_GET_ISS(bigend, ax) AUX_GET_ANY ((bigend), (ax), a_iss)
255 #define AUX_GET_WIDTH(bigend, ax) AUX_GET_ANY ((bigend), (ax), a_width)
256 #define AUX_GET_COUNT(bigend, ax) AUX_GET_ANY ((bigend), (ax), a_count)
258 #define AUX_PUT_ANY(bigend, val, ax, field) \
259 ((bigend) \
260 ? (bfd_putb32 ((bfd_vma) (val), (ax)->field), 0) \
261 : (bfd_putl32 ((bfd_vma) (val), (ax)->field), 0))
263 #define AUX_PUT_DNLOW(bigend, val, ax) \
264 AUX_PUT_ANY ((bigend), (val), (ax), a_dnLow)
265 #define AUX_PUT_DNHIGH(bigend, val, ax) \
266 AUX_PUT_ANY ((bigend), (val), (ax), a_dnHigh)
267 #define AUX_PUT_ISYM(bigend, val, ax) \
268 AUX_PUT_ANY ((bigend), (val), (ax), a_isym)
269 #define AUX_PUT_ISS(bigend, val, ax) \
270 AUX_PUT_ANY ((bigend), (val), (ax), a_iss)
271 #define AUX_PUT_WIDTH(bigend, val, ax) \
272 AUX_PUT_ANY ((bigend), (val), (ax), a_width)
273 #define AUX_PUT_COUNT(bigend, val, ax) \
274 AUX_PUT_ANY ((bigend), (val), (ax), a_count)
276 /********************** SYMBOLS **********************/
278 /* For efficiency, gdb deals directly with the unswapped symbolic
279 information (that way it only takes the time to swap information
280 that it really needs to read). gdb originally retrieved the
281 information directly from the BFD backend information, but that
282 strategy, besides being sort of ugly, does not work for MIPS ELF,
283 which also uses ECOFF debugging information. This structure holds
284 pointers to the (mostly) unswapped symbolic information. */
286 struct ecoff_debug_info
288 /* The swapped ECOFF symbolic header. */
289 HDRR symbolic_header;
291 /* Pointers to the unswapped symbolic information. Note that the
292 pointers to external structures point to different sorts of
293 information on different ECOFF targets. The ecoff_debug_swap
294 structure provides the sizes of the structures and the functions
295 needed to swap the information in and out. These pointers are
296 all pointers to arrays, not single structures. They will be NULL
297 if there are no instances of the relevant structure. These
298 fields are also used by the assembler to output ECOFF debugging
299 information. */
300 unsigned char *line;
301 void *external_dnr; /* struct dnr_ext */
302 void *external_pdr; /* struct pdr_ext */
303 void *external_sym; /* struct sym_ext */
304 void *external_opt; /* struct opt_ext */
305 union aux_ext *external_aux;
306 char *ss;
307 char *ssext;
308 void *external_fdr; /* struct fdr_ext */
309 void *external_rfd; /* struct rfd_ext */
310 void *external_ext; /* struct ext_ext */
312 /* These fields are used when linking. They may disappear at some
313 point. */
314 char *ssext_end;
315 void *external_ext_end;
317 /* When linking, this field holds a mapping from the input FDR
318 numbers to the output numbers, and is used when writing out the
319 external symbols. It is NULL if no mapping is required. */
320 RFDT *ifdmap;
322 /* The swapped FDR information. Currently this is never NULL, but
323 code using this structure should probably double-check in case
324 this changes in the future. This is a pointer to an array, not a
325 single structure. */
326 FDR *fdr;
329 /* These structures are used by the ECOFF find_nearest_line function. */
331 struct ecoff_fdrtab_entry
333 /* Base address in .text of this FDR. */
334 bfd_vma base_addr;
335 FDR *fdr;
338 struct ecoff_find_line
340 /* Allocated memory to hold function and file names. */
341 char *find_buffer;
343 /* FDR table, sorted by address: */
344 long fdrtab_len;
345 struct ecoff_fdrtab_entry *fdrtab;
347 /* Cache entry for most recently found line information. The sect
348 field is NULL if this cache does not contain valid information. */
349 struct
351 asection *sect;
352 bfd_vma start;
353 bfd_vma stop;
354 const char *filename;
355 const char *functionname;
356 unsigned int line_num;
357 } cache;
360 /********************** SWAPPING **********************/
362 /* The generic ECOFF code needs to be able to swap debugging
363 information in and out in the specific format used by a particular
364 ECOFF implementation. This structure provides the information
365 needed to do this. */
367 struct ecoff_debug_swap
369 /* Symbol table magic number. */
370 int sym_magic;
371 /* Alignment of debugging information. E.g., 4. */
372 bfd_size_type debug_align;
373 /* Sizes of external symbolic information. */
374 bfd_size_type external_hdr_size;
375 bfd_size_type external_dnr_size;
376 bfd_size_type external_pdr_size;
377 bfd_size_type external_sym_size;
378 bfd_size_type external_opt_size;
379 bfd_size_type external_fdr_size;
380 bfd_size_type external_rfd_size;
381 bfd_size_type external_ext_size;
382 /* Functions to swap in external symbolic data. */
383 void (*swap_hdr_in) (bfd *, void *, HDRR *);
384 void (*swap_dnr_in) (bfd *, void *, DNR *);
385 void (*swap_pdr_in) (bfd *, void *, PDR *);
386 void (*swap_sym_in) (bfd *, void *, SYMR *);
387 void (*swap_opt_in) (bfd *, void *, OPTR *);
388 void (*swap_fdr_in) (bfd *, void *, FDR *);
389 void (*swap_rfd_in) (bfd *, void *, RFDT *);
390 void (*swap_ext_in) (bfd *, void *, EXTR *);
391 void (*swap_tir_in) (int, const struct tir_ext *, TIR *);
392 void (*swap_rndx_in) (int, const struct rndx_ext *, RNDXR *);
393 /* Functions to swap out external symbolic data. */
394 void (*swap_hdr_out) (bfd *, const HDRR *, void *);
395 void (*swap_dnr_out) (bfd *, const DNR *, void *);
396 void (*swap_pdr_out) (bfd *, const PDR *, void *);
397 void (*swap_sym_out) (bfd *, const SYMR *, void *);
398 void (*swap_opt_out) (bfd *, const OPTR *, void *);
399 void (*swap_fdr_out) (bfd *, const FDR *, void *);
400 void (*swap_rfd_out) (bfd *, const RFDT *, void *);
401 void (*swap_ext_out) (bfd *, const EXTR *, void *);
402 void (*swap_tir_out) (int, const TIR *, struct tir_ext *);
403 void (*swap_rndx_out) (int, const RNDXR *, struct rndx_ext *);
404 /* Function to read symbol data and set up pointers in
405 ecoff_debug_info structure. The section argument is used for
406 ELF, not straight ECOFF. */
407 bfd_boolean (*read_debug_info) (bfd *, asection *, struct ecoff_debug_info *);
410 #endif /* ! defined (ECOFF_H) */