]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - include/coff/xcoff.h
Add except and typeck section strings. Fix xcoff_big_format_p macro.
[thirdparty/binutils-gdb.git] / include / coff / xcoff.h
1 /* Internal format of XCOFF object file data structures for BFD.
2
3 Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001
4 Free Software Foundation, Inc.
5 Written by Ian Lance Taylor <ian@cygnus.com>, Cygnus Support.
6
7 This file is part of BFD, the Binary File Descriptor library.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22
23 #ifndef _INTERNAL_XCOFF_H
24 #define _INTERNAL_XCOFF_H
25
26 /* Linker */
27
28 /* Names of "special" sections. */
29 #define _TEXT ".text"
30 #define _DATA ".data"
31 #define _BSS ".bss"
32 #define _PAD ".pad"
33 #define _LOADER ".loader"
34 #define _EXCEPT ".except"
35 #define _TYPCHK ".typchk"
36
37 /* XCOFF uses a special .loader section with type STYP_LOADER. */
38 #define STYP_LOADER 0x1000
39
40 /* XCOFF uses a special .debug section with type STYP_DEBUG. */
41 #define STYP_DEBUG 0x2000
42
43 /* XCOFF handles line number or relocation overflow by creating
44 another section header with STYP_OVRFLO set. */
45 #define STYP_OVRFLO 0x8000
46
47 #define RS6K_AOUTHDR_OMAGIC 0x0107 /* old: text & data writeable */
48 #define RS6K_AOUTHDR_NMAGIC 0x0108 /* new: text r/o, data r/w */
49 #define RS6K_AOUTHDR_ZMAGIC 0x010B /* paged: text r/o, both page-aligned */
50
51 /* XCOFF relocation types.
52 The relocations are described in the function
53 xcoff[64]_ppc_relocate_section in coff64-rs6000.c and coff-rs6000.c */
54
55 #define R_POS (0x00)
56 #define R_NEG (0x01)
57 #define R_REL (0x02)
58 #define R_TOC (0x03)
59 #define R_RTB (0x04)
60 #define R_GL (0x05)
61 #define R_TCL (0x06)
62 #define R_BA (0x08)
63 #define R_BR (0x0a)
64 #define R_RL (0x0c)
65 #define R_RLA (0x0d)
66 #define R_REF (0x0f)
67 #define R_TRL (0x12)
68 #define R_TRLA (0x13)
69 #define R_RRTBI (0x14)
70 #define R_RRTBA (0x15)
71 #define R_CAI (0x16)
72 #define R_CREL (0x17)
73 #define R_RBA (0x18)
74 #define R_RBAC (0x19)
75 #define R_RBR (0x1a)
76 #define R_RBRC (0x1b)
77
78 /* Storage class #defines, from /usr/include/storclass.h that are not already
79 defined in internal.h */
80
81 /* Comment string in .info section */
82 #define C_INFO 110
83
84 /* Auxillary Symbol Entries */
85
86 /* x_smtyp values: */
87 #define SMTYP_ALIGN(x) ((x) >> 3) /* log2 of alignment */
88 #define SMTYP_SMTYP(x) ((x) & 0x7) /* symbol type */
89 /* Symbol type values: */
90 #define XTY_ER 0 /* External reference */
91 #define XTY_SD 1 /* Csect definition */
92 #define XTY_LD 2 /* Label definition */
93 #define XTY_CM 3 /* .BSS */
94 #define XTY_EM 4 /* Error message */
95 #define XTY_US 5 /* "Reserved for internal use" */
96
97 /* x_smclas values: */
98 #define XMC_PR 0 /* Read-only program code */
99 #define XMC_RO 1 /* Read-only constant */
100 #define XMC_DB 2 /* Read-only debug dictionary table */
101 #define XMC_TC 3 /* Read-write general TOC entry */
102 #define XMC_UA 4 /* Read-write unclassified */
103 #define XMC_RW 5 /* Read-write data */
104 #define XMC_GL 6 /* Read-only global linkage */
105 #define XMC_XO 7 /* Read-only extended operation */
106 #define XMC_SV 8 /* Read-only supervisor call */
107 #define XMC_BS 9 /* Read-write BSS */
108 #define XMC_DS 10 /* Read-write descriptor csect */
109 #define XMC_UC 11 /* Read-write unnamed Fortran common */
110 #define XMC_TI 12 /* Read-only traceback index csect */
111 #define XMC_TB 13 /* Read-only traceback table csect */
112 /* 14 ??? */
113 #define XMC_TC0 15 /* Read-write TOC anchor */
114 #define XMC_TD 16 /* Read-write data in TOC */
115 #define XMC_SV64 17 /* Read-only 64 bit supervisor call */
116 #define XMC_SV3264 18 /* Read-only 32 or 64 bit supervisor call */
117
118 /* The ldhdr structure. This appears at the start of the .loader
119 section. */
120
121 struct internal_ldhdr
122 {
123 /* The version number:
124 1 : 32 bit
125 2 : 64 bit */
126 unsigned long l_version;
127
128 /* The number of symbol table entries. */
129 bfd_size_type l_nsyms;
130
131 /* The number of relocation table entries. */
132 bfd_size_type l_nreloc;
133
134 /* The length of the import file string table. */
135 bfd_size_type l_istlen;
136
137 /* The number of import files. */
138 bfd_size_type l_nimpid;
139
140 /* The offset from the start of the .loader section to the first
141 entry in the import file table. */
142 bfd_size_type l_impoff;
143
144 /* The length of the string table. */
145 bfd_size_type l_stlen;
146
147 /* The offset from the start of the .loader section to the first
148 entry in the string table. */
149 bfd_size_type l_stoff;
150
151 /* The offset to start of the symbol table, only in XCOFF64 */
152 bfd_vma l_symoff;
153
154 /* The offset to the start of the relocation table, only in XCOFF64 */
155 bfd_vma l_rldoff;
156 };
157
158 /* The ldsym structure. This is used to represent a symbol in the
159 .loader section. */
160
161 struct internal_ldsym
162 {
163 union
164 {
165 /* The symbol name if <= SYMNMLEN characters. */
166 char _l_name[SYMNMLEN];
167 struct
168 {
169 /* Zero if the symbol name is more than SYMNMLEN characters. */
170 long _l_zeroes;
171
172 /* The offset in the string table if the symbol name is more
173 than SYMNMLEN characters. */
174 long _l_offset;
175 }
176 _l_l;
177 }
178 _l;
179
180 /* The symbol value. */
181 bfd_vma l_value;
182
183 /* The symbol section number. */
184 short l_scnum;
185
186 /* The symbol type and flags. */
187 char l_smtype;
188
189 /* The symbol storage class. */
190 char l_smclas;
191
192 /* The import file ID. */
193 bfd_size_type l_ifile;
194
195 /* Offset to the parameter type check string. */
196 bfd_size_type l_parm;
197 };
198
199 /* These flags are for the l_smtype field (the lower three bits are an
200 XTY_* value). */
201
202 /* Imported symbol. */
203 #define L_IMPORT (0x40)
204 /* Entry point. */
205 #define L_ENTRY (0x20)
206 /* Exported symbol. */
207 #define L_EXPORT (0x10)
208
209 /* The ldrel structure. This is used to represent a reloc in the
210 .loader section. */
211
212 struct internal_ldrel
213 {
214 /* The reloc address. */
215 bfd_vma l_vaddr;
216
217 /* The symbol table index in the .loader section symbol table. */
218 bfd_size_type l_symndx;
219
220 /* The relocation type and size. */
221 short l_rtype;
222
223 /* The section number this relocation applies to. */
224 short l_rsecnm;
225 };
226
227 /* An entry in the XCOFF linker hash table. */
228 struct xcoff_link_hash_entry
229 {
230 struct bfd_link_hash_entry root;
231
232 /* Symbol index in output file. Set to -1 initially. Set to -2 if
233 there is a reloc against this symbol. */
234 long indx;
235
236 /* If we have created a TOC entry for this symbol, this is the .tc
237 section which holds it. */
238 asection *toc_section;
239
240 union
241 {
242 /* If we have created a TOC entry (the XCOFF_SET_TOC flag is
243 set), this is the offset in toc_section. */
244 bfd_vma toc_offset;
245
246 /* If the TOC entry comes from an input file, this is set to the
247 symbol index of the C_HIDEXT XMC_TC or XMC_TD symbol. */
248 long toc_indx;
249 }
250 u;
251
252 /* If this symbol is a function entry point which is called, this
253 field holds a pointer to the function descriptor. If this symbol
254 is a function descriptor, this field holds a pointer to the
255 function entry point. */
256 struct xcoff_link_hash_entry *descriptor;
257
258 /* The .loader symbol table entry, if there is one. */
259 struct internal_ldsym *ldsym;
260
261 /* If XCOFF_BUILT_LDSYM is set, this is the .loader symbol table
262 index. If XCOFF_BUILD_LDSYM is clear, and XCOFF_IMPORT is set,
263 this is the l_ifile value. */
264 long ldindx;
265
266 /* Some linker flags. */
267 unsigned long flags;
268
269 /* The storage mapping class. */
270 unsigned char smclas;
271 };
272
273 /* Flags for xcoff_link_hash_entry. */
274
275 /* Symbol is referenced by a regular object. */
276 #define XCOFF_REF_REGULAR 0x00000001
277 /* Symbol is defined by a regular object. */
278 #define XCOFF_DEF_REGULAR 0x00000002
279 /* Symbol is defined by a dynamic object. */
280 #define XCOFF_DEF_DYNAMIC 0x00000004
281 /* Symbol is used in a reloc being copied into the .loader section. */
282 #define XCOFF_LDREL 0x00000008
283 /* Symbol is the entry point. */
284 #define XCOFF_ENTRY 0x00000010
285 /* Symbol is called; this is, it appears in a R_BR reloc. */
286 #define XCOFF_CALLED 0x00000020
287 /* Symbol needs the TOC entry filled in. */
288 #define XCOFF_SET_TOC 0x00000040
289 /* Symbol is explicitly imported. */
290 #define XCOFF_IMPORT 0x00000080
291 /* Symbol is explicitly exported. */
292 #define XCOFF_EXPORT 0x00000100
293 /* Symbol has been processed by xcoff_build_ldsyms. */
294 #define XCOFF_BUILT_LDSYM 0x00000200
295 /* Symbol is mentioned by a section which was not garbage collected. */
296 #define XCOFF_MARK 0x00000400
297 /* Symbol size is recorded in size_list list from hash table. */
298 #define XCOFF_HAS_SIZE 0x00000800
299 /* Symbol is a function descriptor. */
300 #define XCOFF_DESCRIPTOR 0x00001000
301 /* Multiple definitions have been for the symbol. */
302 #define XCOFF_MULTIPLY_DEFINED 0x00002000
303 /* Symbol is the __rtinit symbol. */
304 #define XCOFF_RTINIT 0x00004000
305 /* Symbol is an imported 32 bit syscall. */
306 #define XCOFF_SYSCALL32 0x00008000
307 /* Symbol is an imported 64 bit syscall. */
308 #define XCOFF_SYSCALL64 0x00010000
309
310 /* The XCOFF linker hash table. */
311
312 #define XCOFF_NUMBER_OF_SPECIAL_SECTIONS 6
313 #define XCOFF_SPECIAL_SECTION_TEXT 0
314 #define XCOFF_SPECIAL_SECTION_ETEXT 1
315 #define XCOFF_SPECIAL_SECTION_DATA 2
316 #define XCOFF_SPECIAL_SECTION_EDATA 3
317 #define XCOFF_SPECIAL_SECTION_END 4
318 #define XCOFF_SPECIAL_SECTION_END2 5
319
320 struct xcoff_link_hash_table
321 {
322 struct bfd_link_hash_table root;
323
324 /* The .debug string hash table. We need to compute this while
325 reading the input files, so that we know how large the .debug
326 section will be before we assign section positions. */
327 struct bfd_strtab_hash *debug_strtab;
328
329 /* The .debug section we will use for the final output. */
330 asection *debug_section;
331
332 /* The .loader section we will use for the final output. */
333 asection *loader_section;
334
335 /* A count of non TOC relative relocs which will need to be
336 allocated in the .loader section. */
337 size_t ldrel_count;
338
339 /* The .loader section header. */
340 struct internal_ldhdr ldhdr;
341
342 /* The .gl section we use to hold global linkage code. */
343 asection *linkage_section;
344
345 /* The .tc section we use to hold toc entries we build for global
346 linkage code. */
347 asection *toc_section;
348
349 /* The .ds section we use to hold function descriptors which we
350 create for exported symbols. */
351 asection *descriptor_section;
352
353 /* The list of import files. */
354 struct xcoff_import_file *imports;
355
356 /* Required alignment of sections within the output file. */
357 unsigned long file_align;
358
359 /* Whether the .text section must be read-only. */
360 boolean textro;
361
362 /* Whether garbage collection was done. */
363 boolean gc;
364
365 /* A linked list of symbols for which we have size information. */
366 struct xcoff_link_size_list
367 {
368 struct xcoff_link_size_list *next;
369 struct xcoff_link_hash_entry *h;
370 bfd_size_type size;
371 }
372 *size_list;
373
374 /* Magic sections: _text, _etext, _data, _edata, _end, end. */
375 asection *special_sections[XCOFF_NUMBER_OF_SPECIAL_SECTIONS];
376 };
377
378
379 /* This structure is used to pass information through
380 xcoff_link_hash_traverse. */
381
382 struct xcoff_loader_info
383 {
384 /* Set if a problem occurred. */
385 boolean failed;
386
387 /* Output BFD. */
388 bfd *output_bfd;
389
390 /* Link information structure. */
391 struct bfd_link_info *info;
392
393 /* Whether all defined symbols should be exported. */
394 boolean export_defineds;
395
396 /* Number of ldsym structures. */
397 size_t ldsym_count;
398
399 /* Size of string table. */
400 size_t string_size;
401
402 /* String table. */
403 bfd_byte *strings;
404
405 /* Allocated size of string table. */
406 size_t string_alc;
407 };
408
409 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
410 from smaller values. Start with zero, widen, *then* decrement. */
411 #define MINUS_ONE (((bfd_vma) 0) - 1)
412
413 /* __rtinit, from /usr/include/rtinit.h. */
414 struct __rtinit
415 {
416 /* Pointer to runtime linker.
417 XXX: Is the parameter really void? */
418 int (*rtl) PARAMS ((void));
419
420 /* Offset to array of init functions, 0 if none. */
421 int init_offset;
422
423 /* Offset to array of fini functions, 0 if none. */
424 int fini_offset;
425
426 /* Size of __RTINIT_DESCRIPTOR. This value should be used instead of
427 sizeof(__RTINIT_DESCRIPTOR). */
428 int __rtinit_descriptor_size;
429 };
430
431 #define RTINIT_DESCRIPTOR_SIZE (12)
432
433 struct __rtinit_descriptor
434 {
435 /* Init/fini function. */
436 int f;
437
438 /* Offset, relative to the start of the __rtinit symbol, to name of the
439 function. */
440
441 int name_offset;
442
443 /* Flags */
444 unsigned char flags;
445 };
446
447 /* Archive */
448
449 #define XCOFFARMAG "<aiaff>\012"
450 #define XCOFFARMAGBIG "<bigaf>\012"
451 #define SXCOFFARMAG 8
452
453 /* This terminates an XCOFF archive member name. */
454
455 #define XCOFFARFMAG "`\012"
456 #define SXCOFFARFMAG 2
457
458 /* XCOFF archives start with this (printable) structure. */
459
460 struct xcoff_ar_file_hdr
461 {
462 /* Magic string. */
463 char magic[SXCOFFARMAG];
464
465 /* Offset of the member table (decimal ASCII string). */
466 char memoff[12];
467
468 /* Offset of the global symbol table (decimal ASCII string). */
469 char symoff[12];
470
471 /* Offset of the first member in the archive (decimal ASCII string). */
472 char firstmemoff[12];
473
474 /* Offset of the last member in the archive (decimal ASCII string). */
475 char lastmemoff[12];
476
477 /* Offset of the first member on the free list (decimal ASCII
478 string). */
479 char freeoff[12];
480 };
481
482 #define SIZEOF_AR_FILE_HDR (5 * 12 + SXCOFFARMAG)
483
484 /* This is the equivalent data structure for the big archive format. */
485
486 struct xcoff_ar_file_hdr_big
487 {
488 /* Magic string. */
489 char magic[SXCOFFARMAG];
490
491 /* Offset of the member table (decimal ASCII string). */
492 char memoff[20];
493
494 /* Offset of the global symbol table for 32-bit objects (decimal ASCII
495 string). */
496 char symoff[20];
497
498 /* Offset of the global symbol table for 64-bit objects (decimal ASCII
499 string). */
500 char symoff64[20];
501
502 /* Offset of the first member in the archive (decimal ASCII string). */
503 char firstmemoff[20];
504
505 /* Offset of the last member in the archive (decimal ASCII string). */
506 char lastmemoff[20];
507
508 /* Offset of the first member on the free list (decimal ASCII
509 string). */
510 char freeoff[20];
511 };
512
513 #define SIZEOF_AR_FILE_HDR_BIG (6 * 20 + SXCOFFARMAG)
514
515
516 /* Each XCOFF archive member starts with this (printable) structure. */
517
518 struct xcoff_ar_hdr
519 {
520 /* File size not including the header (decimal ASCII string). */
521 char size[12];
522
523 /* File offset of next archive member (decimal ASCII string). */
524 char nextoff[12];
525
526 /* File offset of previous archive member (decimal ASCII string). */
527 char prevoff[12];
528
529 /* File mtime (decimal ASCII string). */
530 char date[12];
531
532 /* File UID (decimal ASCII string). */
533 char uid[12];
534
535 /* File GID (decimal ASCII string). */
536 char gid[12];
537
538 /* File mode (octal ASCII string). */
539 char mode[12];
540
541 /* Length of file name (decimal ASCII string). */
542 char namlen[4];
543
544 /* This structure is followed by the file name. The length of the
545 name is given in the namlen field. If the length of the name is
546 odd, the name is followed by a null byte. The name and optional
547 null byte are followed by XCOFFARFMAG, which is not included in
548 namlen. The contents of the archive member follow; the number of
549 bytes is given in the size field. */
550 };
551
552 #define SIZEOF_AR_HDR (7 * 12 + 4)
553
554 /* The equivalent for the big archive format. */
555
556 struct xcoff_ar_hdr_big
557 {
558 /* File size not including the header (decimal ASCII string). */
559 char size[20];
560
561 /* File offset of next archive member (decimal ASCII string). */
562 char nextoff[20];
563
564 /* File offset of previous archive member (decimal ASCII string). */
565 char prevoff[20];
566
567 /* File mtime (decimal ASCII string). */
568 char date[12];
569
570 /* File UID (decimal ASCII string). */
571 char uid[12];
572
573 /* File GID (decimal ASCII string). */
574 char gid[12];
575
576 /* File mode (octal ASCII string). */
577 char mode[12];
578
579 /* Length of file name (decimal ASCII string). */
580 char namlen[4];
581
582 /* This structure is followed by the file name. The length of the
583 name is given in the namlen field. If the length of the name is
584 odd, the name is followed by a null byte. The name and optional
585 null byte are followed by XCOFFARFMAG, which is not included in
586 namlen. The contents of the archive member follow; the number of
587 bytes is given in the size field. */
588 };
589
590 #define SIZEOF_AR_HDR_BIG (3 * 20 + 4 * 12 + 4)
591
592 /* We often have to distinguish between the old and big file format.
593 Make it a bit cleaner. We can use `xcoff_ardata' here because the
594 `hdr' member has the same size and position in both formats. */
595 #define xcoff_big_format_p(abfd) \
596 ((NULL != bfd_ardata(abfd)) && \
597 (NULL != xcoff_ardata(abfd)) && \
598 (xcoff_ardata (abfd)->magic[1] == 'b'))
599
600 /* We store a copy of the xcoff_ar_file_hdr in the tdata field of the
601 artdata structure. Similar for the big archive. */
602 #define xcoff_ardata(abfd) \
603 ((struct xcoff_ar_file_hdr *) bfd_ardata (abfd)->tdata)
604 #define xcoff_ardata_big(abfd) \
605 ((struct xcoff_ar_file_hdr_big *) bfd_ardata (abfd)->tdata)
606
607 /* We store a copy of the xcoff_ar_hdr in the arelt_data field of an
608 archive element. Similar for the big archive. */
609 #define arch_eltdata(bfd) ((struct areltdata *) ((bfd)->arelt_data))
610 #define arch_xhdr(bfd) \
611 ((struct xcoff_ar_hdr *) arch_eltdata (bfd)->arch_header)
612 #define arch_xhdr_big(bfd) \
613 ((struct xcoff_ar_hdr_big *) arch_eltdata (bfd)->arch_header)
614
615 #endif /* _INTERNAL_XCOFF_H */