1 //===-- lib/CodeGen/ELF.h - ELF constants and data structures ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This header contains common, non-processor-specific data structures and
11 // constants for the ELF file format.
13 // The details of the ELF32 bits in this file are largely based on
14 // the Tool Interface Standard (TIS) Executable and Linking Format
15 // (ELF) Specification Version 1.2, May 1995. The ELF64 stuff is not
16 // standardized, as far as I can tell. It was largely based on information
17 // I found in OpenBSD header files.
19 //===----------------------------------------------------------------------===//
24 #include "llvm/Support/DataTypes.h"
30 // Identification Indexes
40 ET_NONE = 0, // No file type
41 ET_REL = 1, // Relocatable file
42 ET_EXEC = 2, // Executable file
43 ET_DYN = 3, // Shared object file
44 ET_CORE = 4, // Core file
45 ET_LOPROC = 0xff00, // Beginning of processor-specific codes
46 ET_HIPROC = 0xffff // Processor-specific
49 // Object file classes.
51 ELFCLASS32 = 1, // 32-bit object file
52 ELFCLASS64 = 2 // 64-bit object file
55 // Object file byte orderings.
57 ELFDATA2LSB = 1, // Little-endian object file
58 ELFDATA2MSB = 2 // Big-endian object file
67 /// ELFSection - This struct contains information about each section that is
68 /// emitted to the file. This is eventually turned into the section header
69 /// table at the end of the file.
72 // ELF specific fields
73 std::string Name; // Name of the section.
74 unsigned NameIdx; // Index in .shstrtab of name, once emitted.
85 // Section Header Flags
87 SHF_WRITE = 1 << 0, // Writable
88 SHF_ALLOC = 1 << 1, // Mapped into the process addr space
89 SHF_EXECINSTR = 1 << 2, // Executable
90 SHF_MERGE = 1 << 4, // Might be merged if equal
91 SHF_STRINGS = 1 << 5, // Contains null-terminated strings
92 SHF_INFO_LINK = 1 << 6, // 'sh_info' contains SHT index
93 SHF_LINK_ORDER = 1 << 7, // Preserve order after combining
94 SHF_OS_NONCONFORMING = 1 << 8, // nonstandard OS support required
95 SHF_GROUP = 1 << 9, // Section is a member of a group
96 SHF_TLS = 1 << 10 // Section holds thread-local data
101 SHT_NULL = 0, // No associated section (inactive entry).
102 SHT_PROGBITS = 1, // Program-defined contents.
103 SHT_SYMTAB = 2, // Symbol table.
104 SHT_STRTAB = 3, // String table.
105 SHT_RELA = 4, // Relocation entries; explicit addends.
106 SHT_HASH = 5, // Symbol hash table.
107 SHT_DYNAMIC = 6, // Information for dynamic linking.
108 SHT_NOTE = 7, // Information about the file.
109 SHT_NOBITS = 8, // Data occupies no space in the file.
110 SHT_REL = 9, // Relocation entries; no explicit addends.
111 SHT_SHLIB = 10, // Reserved.
112 SHT_DYNSYM = 11, // Symbol table.
113 SHT_LOPROC = 0x70000000, // Lowest processor architecture-specific type.
114 SHT_HIPROC = 0x7fffffff, // Highest processor architecture-specific type.
115 SHT_LOUSER = 0x80000000, // Lowest type reserved for applications.
116 SHT_HIUSER = 0xffffffff // Highest type reserved for applications.
119 // Special section indices.
121 SHN_UNDEF = 0, // Undefined, missing, irrelevant, or meaningless
122 SHN_LORESERVE = 0xff00, // Lowest reserved index
123 SHN_LOPROC = 0xff00, // Lowest processor-specific index
124 SHN_HIPROC = 0xff1f, // Highest processor-specific index
125 SHN_ABS = 0xfff1, // Symbol has absolute value; does not need relocation
126 SHN_COMMON = 0xfff2, // FORTRAN COMMON or C external global variables
127 SHN_HIRESERVE = 0xffff // Highest reserved index
130 /// SectionIdx - The number of the section in the Section Table.
131 unsigned short SectionIdx;
133 /// SectionData - The actual data for this section which we are building
134 /// up for emission to the file.
135 std::vector<unsigned char> SectionData;
137 ELFSection(const std::string &name)
138 : Name(name), Type(0), Flags(0), Addr(0), Offset(0), Size(0),
139 Link(0), Info(0), Align(0), EntSize(0) {}
142 /// ELFSym - This struct contains information about each symbol that is
143 /// added to logical symbol table for the module. This is eventually
144 /// turned into a real symbol table in the file.
146 const GlobalValue *GV; // The global value this corresponds to.
148 // ELF specific fields
149 unsigned NameIdx; // Index in .strtab of name, once emitted.
154 unsigned short SectionIdx;
170 ELFSym(const GlobalValue *gv) : GV(gv), Value(0),
171 Size(0), Info(0), Other(0),
172 SectionIdx(ELFSection::SHN_UNDEF) {}
174 void SetBind(unsigned X) {
175 assert(X == (X & 0xF) && "Bind value out of range!");
176 Info = (Info & 0x0F) | (X << 4);
178 void SetType(unsigned X) {
179 assert(X == (X & 0xF) && "Type value out of range!");
180 Info = (Info & 0xF0) | X;
184 } // end namespace llvm