//===- llvm/BinaryFormat/ELF.h - ELF constants and structures ---*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This header contains common, non-processor-specific data structures and // constants for the ELF file format. // // The details of the ELF32 bits in this file are largely based on the Tool // Interface Standard (TIS) Executable and Linking Format (ELF) Specification // Version 1.2, May 1995. The ELF64 stuff is based on ELF-64 Object File Format // Version 1.5, Draft 2, May 1998 as well as OpenBSD header files. // //===----------------------------------------------------------------------===// #ifndef LLVM_BINARYFORMAT_ELF_H #define LLVM_BINARYFORMAT_ELF_H #include "llvm/ADT/StringRef.h" #include <cstdint> #include <cstring> #include <type_traits> namespace llvm { namespace ELF { Elf32_Addr; // Program address Elf32_Off; // File offset Elf32_Half; Elf32_Word; Elf32_Sword; Elf64_Addr; Elf64_Off; Elf64_Half; Elf64_Word; Elf64_Sword; Elf64_Xword; Elf64_Sxword; // Object file magic string. static const char ElfMagic[] = …; // e_ident size and indices. enum { … }; struct Elf32_Ehdr { … }; // 64-bit ELF header. Fields are the same as for ELF32, but with different // types (see above). struct Elf64_Ehdr { … }; // File types. // See current registered ELF types at: // http://www.sco.com/developers/gabi/latest/ch4.eheader.html enum { … }; // Versioning enum { … }; // Machine architectures // See current registered ELF machine architectures at: // http://www.uxsglobal.com/developers/gabi/latest/ch4.eheader.html enum { … }; // Object file classes. enum { … }; // Object file byte orderings. enum { … }; // OS ABI identification. enum { … }; // AMDGPU OS ABI Version identification. enum { … }; #define ELF_RELOC … // X86_64 relocations. enum { … }; // i386 relocations. enum { … }; // ELF Relocation types for PPC32 enum { … }; // Specific e_flags for PPC64 enum { … }; // Special values for the st_other field in the symbol table entry for PPC64. enum { … }; static inline int64_t decodePPC64LocalEntryOffset(unsigned Other) { … } // ELF Relocation types for PPC64 enum { … }; // ELF Relocation types for AArch64 enum { … }; // Special values for the st_other field in the symbol table entry for AArch64. enum { … }; // ARM Specific e_flags enum : unsigned { … }; // ELF Relocation types for ARM enum { … }; // ARC Specific e_flags enum : unsigned { … }; // ELF Relocation types for ARC enum { … }; // AVR specific e_flags enum : unsigned { … }; // ELF Relocation types for AVR enum { … }; // Mips Specific e_flags enum : unsigned { … }; // MIPS-specific section indexes enum { … }; // ELF Relocation types for Mips enum { … }; // Special values for the st_other field in the symbol table entry for MIPS. enum { … }; // .MIPS.options section descriptor kinds enum { … }; // Hexagon-specific e_flags enum { … }; // Hexagon-specific section indexes for common small data enum { … }; // ELF Relocation types for Hexagon enum { … }; // ELF Relocation type for Lanai. enum { … }; // RISCV Specific e_flags enum : unsigned { … }; // ELF Relocation types for RISC-V enum { … }; enum { … }; // ELF Relocation types for S390/zSeries enum { … }; // SPARC Specific e_flags enum : unsigned { … }; // ELF Relocation type for Sparc. enum { … }; // AMDGPU specific e_flags. enum : unsigned { … }; // ELF Relocation types for AMDGPU enum { … }; // NVPTX specific e_flags. enum : unsigned { … }; // ELF Relocation types for BPF enum { … }; // ELF Relocation types for M68k enum { … }; // MSP430 specific e_flags enum : unsigned { … }; // ELF Relocation types for MSP430 enum { … }; // ELF Relocation type for VE. enum { … }; // CSKY Specific e_flags enum : unsigned { … }; // ELF Relocation types for CSKY enum { … }; // LoongArch Specific e_flags enum : unsigned { … }; // ELF Relocation types for LoongArch enum { … }; // Xtensa specific e_flags enum : unsigned { … }; // ELF Relocation types for Xtensa enum { … }; #undef ELF_RELOC // Section header. struct Elf32_Shdr { … }; // Section header for ELF64 - same fields as ELF32, different types. struct Elf64_Shdr { … }; // Special section indices. enum { … }; // Section types. enum : unsigned { … }; // Section flags. enum : unsigned { … }; // Section Group Flags enum : unsigned { … }; // Symbol table entries for ELF32. struct Elf32_Sym { … }; // Symbol table entries for ELF64. struct Elf64_Sym { … }; // The size (in bytes) of symbol table entries. enum { … }; // Symbol bindings. enum { … }; // Symbol types. enum { … }; enum { … }; // Symbol number. enum { … }; // Special relocation symbols used in the MIPS64 ELF relocation entries enum { … }; // Relocation entry, without explicit addend. struct Elf32_Rel { … }; // Relocation entry with explicit addend. struct Elf32_Rela { … }; // Relocation entry without explicit addend or info (relative relocations only). Elf32_Relr; // offset/bitmap for relative relocations // Relocation entry, without explicit addend. struct Elf64_Rel { … }; // Relocation entry with explicit addend. struct Elf64_Rela { … }; // In-memory representation of CREL. The serialized representation uses LEB128. template <bool Is64> struct Elf_Crel { … }; // Relocation entry without explicit addend or info (relative relocations only). Elf64_Relr; // offset/bitmap for relative relocations // Program header for ELF32. struct Elf32_Phdr { … }; // Program header for ELF64. struct Elf64_Phdr { … }; // Segment types. enum { … }; // Segment flag bits. enum : unsigned { … }; // Dynamic table entry for ELF32. struct Elf32_Dyn { … }; // Dynamic table entry for ELF64. struct Elf64_Dyn { … }; // Dynamic table entry tags. enum { … }; // DT_FLAGS values. enum { … }; // State flags selectable in the `d_un.d_val' element of the DT_FLAGS_1 entry. enum { … }; // DT_MIPS_FLAGS values. enum { … }; // ElfXX_VerDef structure version (GNU versioning) enum { … }; // VerDef Flags (ElfXX_VerDef::vd_flags) enum { … }; // Special constants for the version table. (SHT_GNU_versym/.gnu.version) enum { … }; // ElfXX_VerNeed structure version (GNU versioning) enum { … }; // SHT_NOTE section types. // Generic note types. enum : unsigned { … }; // Core note types. enum : unsigned { … }; // LLVM-specific notes. enum { … }; // GNU note types. enum { … }; // Android note types. enum { … }; // Memory tagging values used in NT_ANDROID_TYPE_MEMTAG notes. enum { … }; // Property types used in GNU_PROPERTY_TYPE_0 notes. enum : unsigned { … }; // aarch64 processor feature bits. enum : unsigned { … }; // aarch64 PAuth platforms. enum : unsigned { … }; // Bit positions of version flags for AARCH64_PAUTH_PLATFORM_LLVM_LINUX. enum : unsigned { … }; // x86 processor feature bits. enum : unsigned { … }; // FreeBSD note types. enum { … }; // NT_FREEBSD_FEATURE_CTL values (see FreeBSD's sys/sys/elf_common.h). enum { … }; // FreeBSD core note types. enum { … }; // NetBSD core note types. enum { … }; // OpenBSD core note types. enum { … }; // AMDGPU-specific section indices. enum { … }; // AMD vendor specific notes. (Code Object V2) enum { … }; // AMDGPU vendor specific notes. (Code Object V3) enum { … }; // LLVMOMPOFFLOAD specific notes. enum : unsigned { … }; enum { … }; constexpr const char *ELF_NOTE_GNU = …; // Android packed relocation group flags. enum { … }; // Compressed section header for ELF32. struct Elf32_Chdr { … }; // Compressed section header for ELF64. struct Elf64_Chdr { … }; // Note header for ELF32. struct Elf32_Nhdr { … }; // Note header for ELF64. struct Elf64_Nhdr { … }; // Legal values for ch_type field of compressed section header. enum { … }; constexpr unsigned CREL_HDR_ADDEND = …; /// Convert an architecture name into ELF's e_machine value. uint16_t convertArchNameToEMachine(StringRef Arch); /// Convert an ELF's e_machine value into an architecture name. StringRef convertEMachineToArchName(uint16_t EMachine); // Convert a lowercase string identifier into an OSABI value. uint8_t convertNameToOSABI(StringRef Name); // Convert an OSABI value into a string that identifies the OS- or ABI- // specific ELF extension. StringRef convertOSABIToName(uint8_t OSABI); } // end namespace ELF } // end namespace llvm #endif // LLVM_BINARYFORMAT_ELF_H