LLVM  10.0.0
XCOFF.h
Go to the documentation of this file.
1 //===-- llvm/BinaryFormat/XCOFF.h - The XCOFF file format -------*- C++/-*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines manifest constants for the XCOFF object file format.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_BINARYFORMAT_XCOFF_H
14 #define LLVM_BINARYFORMAT_XCOFF_H
15 
16 #include "llvm/ADT/StringRef.h"
17 #include <cstdint>
18 
19 namespace llvm {
20 namespace XCOFF {
21 
22 // Constants used in the XCOFF definition.
24 
25 enum ReservedSectionNum { N_DEBUG = -2, N_ABS = -1, N_UNDEF = 0 };
26 
27 // x_smclas field of x_csect from system header: /usr/include/syms.h
28 /// Storage Mapping Class definitions.
29 enum StorageMappingClass : uint8_t {
30  // READ ONLY CLASSES
31  XMC_PR = 0, ///< Program Code
32  XMC_RO = 1, ///< Read Only Constant
33  XMC_DB = 2, ///< Debug Dictionary Table
34  XMC_GL = 6, ///< Global Linkage (Interfile Interface Code)
35  XMC_XO = 7, ///< Extended Operation (Pseudo Machine Instruction)
36  XMC_SV = 8, ///< Supervisor Call (32-bit process only)
37  XMC_SV64 = 17, ///< Supervisor Call for 64-bit process
38  XMC_SV3264 = 18, ///< Supervisor Call for both 32- and 64-bit processes
39  XMC_TI = 12, ///< Traceback Index csect
40  XMC_TB = 13, ///< Traceback Table csect
41 
42  // READ WRITE CLASSES
43  XMC_RW = 5, ///< Read Write Data
44  XMC_TC0 = 15, ///< TOC Anchor for TOC Addressability
45  XMC_TC = 3, ///< General TOC item
46  XMC_TD = 16, ///< Scalar data item in the TOC
47  XMC_DS = 10, ///< Descriptor csect
48  XMC_UA = 4, ///< Unclassified - Treated as Read Write
49  XMC_BS = 9, ///< BSS class (uninitialized static internal)
50  XMC_UC = 11, ///< Un-named Fortran Common
51 
52  XMC_TL = 20, ///< Initialized thread-local variable
53  XMC_UL = 21, ///< Uninitialized thread-local variable
54  XMC_TE = 22 ///< Symbol mapped at the end of TOC
55 };
56 
57 // Flags for defining the section type. Used for the s_flags field of
58 // the section header structure. Defined in the system header `scnhdr.h`.
60  STYP_PAD = 0x0008,
61  STYP_DWARF = 0x0010,
62  STYP_TEXT = 0x0020,
63  STYP_DATA = 0x0040,
64  STYP_BSS = 0x0080,
65  STYP_EXCEPT = 0x0100,
66  STYP_INFO = 0x0200,
67  STYP_TDATA = 0x0400,
68  STYP_TBSS = 0x0800,
69  STYP_LOADER = 0x1000,
70  STYP_DEBUG = 0x2000,
71  STYP_TYPCHK = 0x4000,
72  STYP_OVRFLO = 0x8000
73 };
74 
75 // STORAGE CLASSES, n_sclass field of syment.
76 // The values come from `storclass.h` and `dbxstclass.h`.
77 enum StorageClass : uint8_t {
78  // Storage classes used for symbolic debugging symbols.
79  C_FILE = 103, // File name
80  C_BINCL = 108, // Beginning of include file
81  C_EINCL = 109, // Ending of include file
82  C_GSYM = 128, // Global variable
83  C_STSYM = 133, // Statically allocated symbol
84  C_BCOMM = 135, // Beginning of common block
85  C_ECOMM = 137, // End of common block
86  C_ENTRY = 141, // Alternate entry
87  C_BSTAT = 143, // Beginning of static block
88  C_ESTAT = 144, // End of static block
89  C_GTLS = 145, // Global thread-local variable
90  C_STTLS = 146, // Static thread-local variable
91 
92  // Storage classes used for DWARF symbols.
93  C_DWARF = 112, // DWARF section symbol
94 
95  // Storage classes used for absolute symbols.
96  C_LSYM = 129, // Automatic variable allocated on stack
97  C_PSYM = 130, // Argument to subroutine allocated on stack
98  C_RSYM = 131, // Register variable
99  C_RPSYM = 132, // Argument to function or procedure stored in register
100  C_ECOML = 136, // Local member of common block
101  C_FUN = 142, // Function or procedure
102 
103  // Storage classes used for undefined external symbols or
104  // symbols of general sections.
105  C_EXT = 2, // External symbol
106  C_WEAKEXT = 111, // Weak external symbol
107 
108  // Storage classes used for symbols of general sections.
109  C_NULL = 0,
110  C_STAT = 3, // Static
111  C_BLOCK = 100, // ".bb" or ".eb"
112  C_FCN = 101, // ".bf" or ".ef"
113  C_HIDEXT = 107, // Un-named external symbol
114  C_INFO = 110, // Comment string in .info section
115  C_DECL = 140, // Declaration of object (type)
116 
117  // Storage classes - Obsolete/Undocumented.
118  C_AUTO = 1, // Automatic variable
119  C_REG = 4, // Register variable
120  C_EXTDEF = 5, // External definition
121  C_LABEL = 6, // Label
122  C_ULABEL = 7, // Undefined label
123  C_MOS = 8, // Member of structure
124  C_ARG = 9, // Function argument
125  C_STRTAG = 10, // Structure tag
126  C_MOU = 11, // Member of union
127  C_UNTAG = 12, // Union tag
128  C_TPDEF = 13, // Type definition
129  C_USTATIC = 14, // Undefined static
130  C_ENTAG = 15, // Enumeration tag
131  C_MOE = 16, // Member of enumeration
132  C_REGPARM = 17, // Register parameter
133  C_FIELD = 18, // Bit field
134  C_EOS = 102, // End of structure
135  C_LINE = 104,
136  C_ALIAS = 105, // Duplicate tag
137  C_HIDDEN = 106, // Special storage class for external
138  C_EFCN = 255, // Physical end of function
139 
140  // Storage classes - reserved
141  C_TCSYM = 134 // Reserved
142 };
143 
145  XTY_ER = 0, ///< External reference.
146  XTY_SD = 1, ///< Csect definition for initialized storage.
147  XTY_LD = 2, ///< Label definition.
148  ///< Defines an entry point to an initialized csect.
149  XTY_CM = 3 ///< Common csect definition. For uninitialized storage.
150 };
151 
152 // Relocation types, defined in `/usr/include/reloc.h`.
153 enum RelocationType : uint8_t {
154  R_POS = 0x00, ///< Positive relocation. Provides the address of the referenced
155  ///< symbol.
156  R_RL = 0x0c, ///< Positive indirect load relocation. Modifiable instruction.
157  R_RLA = 0x0d, ///< Positive load address relocation. Modifiable instruction.
158 
159  R_NEG = 0x01, ///< Negative relocation. Provides the negative of the address
160  ///< of the referenced symbol.
161  R_REL = 0x02, ///< Relative to self relocation. Provides a displacement value
162  ///< between the address of the referenced symbol and the
163  ///< address being relocated.
164 
165  R_TOC = 0x03, ///< Relative to the TOC relocation. Provides a displacement
166  ///< that is the difference between the address of the
167  ///< referenced symbol and the TOC anchor csect.
168  R_TRL = 0x12, ///< TOC relative indirect load relocation. Similar to R_TOC,
169  ///< but not modifiable instruction.
170 
172  0x13, ///< Relative to the TOC or to the thread-local storage base
173  ///< relocation. Compilers are not permitted to generate this
174  ///< relocation type. It is the result of a reversible
175  ///< transformation by the linker of an R_TOC relation that turned a
176  ///< load instruction into an add-immediate instruction.
177 
178  R_GL = 0x05, ///< Global linkage-external TOC address relocation. Provides the
179  ///< address of the external TOC associated with a defined
180  ///< external symbol.
181  R_TCL = 0x06, ///< Local object TOC address relocation. Provides the address
182  ///< of the local TOC entry of a defined external symbol.
183 
184  R_REF = 0x0f, ///< A non-relocating relocation. Used to prevent the binder
185  ///< from garbage collecting a csect (such as code used for
186  ///< dynamic initialization of non-local statics) for which
187  ///< another csect has an implicit dependency.
188 
189  R_BA = 0x08, ///< Branch absolute relocation. Provides the address of the
190  ///< referenced symbol. References a non-modifiable instruction.
191  R_BR = 0x0a, ///< Branch relative to self relocation. Provides the
192  ///< displacement that is the difference between the address of
193  ///< the referenced symbol and the address of the referenced
194  ///< branch instruction. References a non-modifiable instruction.
195  R_RBA = 0x18, ///< Branch absolute relocation. Similar to R_BA but
196  ///< references a modifiable instruction.
197  R_RBR = 0x1a, ///< Branch relative to self relocation. Similar to the R_BR
198  ///< relocation type, but references a modifiable instruction.
199 
200  R_TLS = 0x20, ///< General-dynamic reference to TLS symbol.
201  R_TLS_IE = 0x21, ///< Initial-exec reference to TLS symbol.
202  R_TLS_LD = 0x22, ///< Local-dynamic reference to TLS symbol.
203  R_TLS_LE = 0x23, ///< Local-exec reference to TLS symbol.
204  R_TLSM = 0x24, ///< Module reference to TLS. Provides a handle for the module
205  ///< containing the referenced symbol.
206  R_TLSML = 0x25, ///< Module reference to the local TLS storage.
207 
208  R_TOCU = 0x30, ///< Relative to TOC upper. Specifies the high-order 16 bits of
209  ///< a large code model TOC-relative relocation.
210  R_TOCL = 0x31 ///< Relative to TOC lower. Specifies the low-order 16 bits of a
211  ///< large code model TOC-relative relocation.
212 };
213 
214 struct FileHeader32 {
217  int32_t TimeStamp;
222 };
223 
234  int32_t Flags;
235 };
236 
237 enum CFileStringType : uint8_t {
238  XFT_FN = 0, ///< Specifies the source-file name.
239  XFT_CT = 1, ///< Specifies the compiler time stamp.
240  XFT_CV = 2, ///< Specifies the compiler version number.
241  XFT_CD = 128 ///< Specifies compiler-defined information.
242 };
243 
244 enum CFileLangId : uint8_t {
245  TB_C = 0, ///< C language.
246  TB_CPLUSPLUS = 9 ///< C++ language.
247 };
248 
249 enum CFileCpuId : uint8_t {
250  TCPU_PPC64 = 2, ///< PowerPC common architecture 64-bit mode.
251  TCPU_COM = 3, ///< POWER and PowerPC architecture common.
252  TCPU_970 = 19 ///< PPC970 - PowerPC 64-bit architecture.
253 };
254 
256 
257 } // end namespace XCOFF
258 } // end namespace llvm
259 
260 #endif
Symbol mapped at the end of TOC.
Definition: XCOFF.h:54
Negative relocation.
Definition: XCOFF.h:159
C++ language.
Definition: XCOFF.h:246
This class represents lattice values for constants.
Definition: AllocatorList.h:23
General-dynamic reference to TLS symbol.
Definition: XCOFF.h:200
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
Supervisor Call for both 32- and 64-bit processes.
Definition: XCOFF.h:38
TOC Anchor for TOC Addressability.
Definition: XCOFF.h:44
Branch relative to self relocation.
Definition: XCOFF.h:197
Scalar data item in the TOC.
Definition: XCOFF.h:46
Initial-exec reference to TLS symbol.
Definition: XCOFF.h:201
Read Write Data.
Definition: XCOFF.h:43
uint16_t NumberOfLineNumbers
Definition: XCOFF.h:233
Module reference to the local TLS storage.
Definition: XCOFF.h:206
Traceback Table csect.
Definition: XCOFF.h:40
Specifies the compiler time stamp.
Definition: XCOFF.h:239
Branch absolute relocation.
Definition: XCOFF.h:189
SectionTypeFlags
Definition: XCOFF.h:59
StorageClass
Definition: XCOFF.h:77
Relative to the TOC or to the thread-local storage base relocation.
Definition: XCOFF.h:171
PPC970 - PowerPC 64-bit architecture.
Definition: XCOFF.h:252
Positive indirect load relocation. Modifiable instruction.
Definition: XCOFF.h:156
Global Linkage (Interfile Interface Code)
Definition: XCOFF.h:34
Common csect definition. For uninitialized storage.
Definition: XCOFF.h:149
uint32_t SymbolTableFileOffset
Definition: XCOFF.h:218
Supervisor Call for 64-bit process.
Definition: XCOFF.h:37
Module reference to TLS.
Definition: XCOFF.h:204
Specifies compiler-defined information.
Definition: XCOFF.h:241
External reference.
Definition: XCOFF.h:145
Program Code.
Definition: XCOFF.h:31
Relative to self relocation.
Definition: XCOFF.h:161
StorageMappingClass
Storage Mapping Class definitions.
Definition: XCOFF.h:29
Extended Operation (Pseudo Machine Instruction)
Definition: XCOFF.h:35
Uninitialized thread-local variable.
Definition: XCOFF.h:53
Local object TOC address relocation.
Definition: XCOFF.h:181
Initialized thread-local variable.
Definition: XCOFF.h:52
Un-named Fortran Common.
Definition: XCOFF.h:50
Branch relative to self relocation.
Definition: XCOFF.h:191
uint32_t FileOffsetToRelocations
Definition: XCOFF.h:230
Branch absolute relocation.
Definition: XCOFF.h:195
General TOC item.
Definition: XCOFF.h:45
Label definition.
Definition: XCOFF.h:147
StringRef getMappingClassString(XCOFF::StorageMappingClass SMC)
Definition: XCOFF.cpp:13
Traceback Index csect.
Definition: XCOFF.h:39
POWER and PowerPC architecture common.
Definition: XCOFF.h:251
Specifies the compiler version number.
Definition: XCOFF.h:240
Specifies the source-file name.
Definition: XCOFF.h:238
PowerPC common architecture 64-bit mode.
Definition: XCOFF.h:250
Supervisor Call (32-bit process only)
Definition: XCOFF.h:36
BSS class (uninitialized static internal)
Definition: XCOFF.h:49
Debug Dictionary Table.
Definition: XCOFF.h:33
RelocationType
Definition: XCOFF.h:153
uint16_t NumberOfSections
Definition: XCOFF.h:216
Relative to TOC upper.
Definition: XCOFF.h:208
Positive load address relocation. Modifiable instruction.
Definition: XCOFF.h:157
Unclassified - Treated as Read Write.
Definition: XCOFF.h:48
Global linkage-external TOC address relocation.
Definition: XCOFF.h:178
A non-relocating relocation.
Definition: XCOFF.h:184
Read Only Constant.
Definition: XCOFF.h:32
Csect definition for initialized storage.
Definition: XCOFF.h:146
ReservedSectionNum
Definition: XCOFF.h:25
Positive relocation.
Definition: XCOFF.h:154
Relative to TOC lower.
Definition: XCOFF.h:210
Relative to the TOC relocation.
Definition: XCOFF.h:165
CFileStringType
Definition: XCOFF.h:237
uint16_t NumberOfRelocations
Definition: XCOFF.h:232
TOC relative indirect load relocation.
Definition: XCOFF.h:168
Local-dynamic reference to TLS symbol.
Definition: XCOFF.h:202
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:54
int32_t NumberOfSymbolTableEntries
Definition: XCOFF.h:219
uint16_t AuxiliaryHeaderSize
Definition: XCOFF.h:220
uint32_t FileOffsetToLineNumbers
Definition: XCOFF.h:231
C language.
Definition: XCOFF.h:245
Descriptor csect.
Definition: XCOFF.h:47
Local-exec reference to TLS symbol.
Definition: XCOFF.h:203