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