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