1d65182f1818d1c19e6f3866ab6e68a262fad5185hbono@chromium.org/* 245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * ELF object format helpers 345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * Copyright (C) 2003-2007 Michael Urman 545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * Redistribution and use in source and binary forms, with or without 745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * modification, are permitted provided that the following conditions 845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * are met: 945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 1. Redistributions of source code must retain the above copyright 1045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * notice, this list of conditions and the following disclaimer. 1145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 2. Redistributions in binary form must reproduce the above copyright 1245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * notice, this list of conditions and the following disclaimer in the 1345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * documentation and/or other materials provided with the distribution. 1445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 1545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS'' 1645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE 1945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * POSSIBILITY OF SUCH DAMAGE. 2645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 2745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 2845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#ifndef ELF_H_INCLUDED 2945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define ELF_H_INCLUDED 3045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 3145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct elf_reloc_entry elf_reloc_entry; 3245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct elf_reloc_head elf_reloc_head; 3345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct elf_secthead elf_secthead; 3445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct elf_strtab_entry elf_strtab_entry; 3545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct elf_strtab_head elf_strtab_head; 3645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct elf_symtab_entry elf_symtab_entry; 3745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct elf_symtab_head elf_symtab_head; 3845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 3945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef struct elf_machine_handler elf_machine_handler; 4045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 4145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef unsigned long elf_address; 4245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef unsigned long elf_offset; 4345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef unsigned long elf_size; 4445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef unsigned long elf_section_info; 4545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 4645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef enum { 4745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ET_NONE = 0, 4845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ET_REL = 1, /* Relocatable */ 4945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ET_EXEC = 2, /* Executable */ 5045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ET_DYN = 3, /* Shared object */ 5145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ET_CORE = 4, /* Core */ 5245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ET_LOOS = 0xfe00, /* Environment specific */ 5345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ET_HIOS = 0xfeff, 5445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ET_LOPROC = 0xff00, /* Processor specific */ 5545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ET_HIPROC = 0xffff 5645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} elf_file_type; 5745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 5845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef enum { 5945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org EM_NONE = 0, 6045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org EM_M32 = 1, /* AT&T WE 32100 */ 6145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org EM_SPARC = 2, /* SPARC */ 6245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org EM_386 = 3, /* Intel 80386 */ 6345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org EM_68K = 4, /* Motorola 68000 */ 6445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org EM_88K = 5, /* Motorola 88000 */ 6545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org EM_860 = 7, /* Intel 80860 */ 6645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org EM_MIPS = 8, /* MIPS RS3000 */ 6745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 6845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org EM_S370 = 9, /* IBM System/370 */ 6945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org EM_MIPS_RS4_BE = 10, /* MIPS R4000 Big-Endian (dep)*/ 7045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org EM_PARISC = 15, /* HPPA */ 7145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org EM_SPARC32PLUS = 18, /* SPARC v8plus */ 7245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org EM_PPC = 20, /* PowerPC 32-bit */ 7345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org EM_PPC64 = 21, /* PowerPC 64-bit */ 7445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org EM_ARM = 40, /* ARM */ 7545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org EM_SPARCV9 = 43, /* SPARC v9 64-bit */ 7645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org EM_IA_64 = 50, /* Intel IA-64 */ 7745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org EM_X86_64 = 62, /* AMD x86-64 */ 7845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org EM_ALPHA = 0x9026 /* Alpha (no ABI) */ 7945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} elf_machine; 8045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 8145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef enum { 8245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ELFMAG0 = 0x7f, 8345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ELFMAG1 = 0x45, 8445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ELFMAG2 = 0x4c, 8545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ELFMAG3 = 0x46 8645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} elf_magic; 8745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 8845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef enum { 8945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org EV_NONE = 0, /* invalid */ 9045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org EV_CURRENT = 1 /* current */ 9145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} elf_version; 9245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 9345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef enum { 9445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org EI_MAG0 = 0, /* File id */ 9545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org EI_MAG1 = 1, 9645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org EI_MAG2 = 2, 9745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org EI_MAG3 = 3, 9845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org EI_CLASS = 4, /* File class */ 9945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org EI_DATA = 5, /* Data encoding */ 10045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org EI_VERSION = 6, /* File version */ 10145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org EI_OSABI = 7, /* OS and ABI */ 10245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org EI_ABIVERSION = 8, /* version of ABI */ 10345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 10445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org EI_PAD = 9, /* Pad to end; start here */ 10545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org EI_NIDENT = 16 /* Sizeof e_ident[] */ 10645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} elf_identification_index; 10745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 10845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef enum { 10945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ELFOSABI_SYSV = 0, /* System V ABI */ 11045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ELFOSABI_HPUX = 1, /* HP-UX os */ 11145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ELFOSABI_STANDALONE = 255 /* Standalone / embedded app */ 11245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} elf_osabi_index; 11345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 11445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef enum { 11545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ELFCLASSNONE = 0, /* invalid */ 11645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ELFCLASS32 = 1, /* 32-bit */ 11745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ELFCLASS64 = 2 /* 64-bit */ 11845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} elf_class; 11945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 12045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef enum { 12145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ELFDATANONE = 0, 12245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ELFDATA2LSB = 1, 12345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org ELFDATA2MSB = 2 12445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} elf_data_encoding; 12545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 12645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/* elf section types - index of semantics */ 12745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef enum { 12845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SHT_NULL = 0, /* inactive section - no associated data */ 12945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SHT_PROGBITS = 1, /* defined by program for its own meaning */ 13045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SHT_SYMTAB = 2, /* symbol table (primarily) for linking */ 13145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SHT_STRTAB = 3, /* string table - symbols need names */ 13245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SHT_RELA = 4, /* relocation entries w/ explicit addends */ 13345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SHT_HASH = 5, /* symbol hash table - for dynamic linking */ 13445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SHT_DYNAMIC = 6, /* information for dynamic linking */ 13545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SHT_NOTE = 7, /* extra data marking the file somehow */ 13645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SHT_NOBITS = 8, /* no stored data, but occupies runtime space */ 13745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SHT_REL = 9, /* relocations entries w/o explicit addends */ 13845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SHT_SHLIB = 10, /* reserved; unspecified semantics */ 13945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SHT_DYNSYM = 11, /* like symtab, but more for dynamic linking */ 14045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 14145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SHT_LOOS = 0x60000000, /* reserved for environment specific use */ 14245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SHT_HIOS = 0x6fffffff, 14345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SHT_LOPROC = 0x70000000, /* reserved for processor specific semantics */ 14445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SHT_HIPROC = 0x7fffffff/*, 14545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SHT_LOUSER = 0x80000000,*/ /* reserved for applications; safe */ 14645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /*SHT_HIUSER = 0xffffffff*/ 14745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} elf_section_type; 14845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 14945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/* elf section flags - bitfield of attributes */ 15045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef enum { 15145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SHF_WRITE = 0x1, /* data should be writable at runtime */ 15245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SHF_ALLOC = 0x2, /* occupies memory at runtime */ 15345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SHF_EXECINSTR = 0x4, /* contains machine instructions */ 15445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SHF_MERGE = 0x10, /* data can be merged */ 15545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SHF_STRINGS = 0x20, /* contains 0-terminated strings */ 15645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SHF_GROUP = 0x200, /* member of a section group */ 15745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SHF_TLS = 0x400, /* thread local storage */ 15845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SHF_MASKOS = 0x0f000000/*,*//* environment specific use */ 15945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /*SHF_MASKPROC = 0xf0000000*/ /* bits reserved for processor specific needs */ 16045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} elf_section_flags; 16145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 16245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/* elf section index - just the special ones */ 16345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef enum { 16445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SHN_UNDEF = 0, /* undefined symbol; requires other global */ 16545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SHN_LORESERVE = 0xff00, /* reserved for various semantics */ 16645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SHN_LOPROC = 0xff00, /* reserved for processor specific semantics */ 16745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SHN_HIPROC = 0xff1f, 16845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SHN_LOOS = 0xff20, /* reserved for environment specific use */ 16945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SHN_HIOS = 0xff3f, 17045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SHN_ABS = 0xfff1, /* associated symbols don't change on reloc */ 17145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SHN_COMMON = 0xfff2, /* associated symbols refer to unallocated */ 17245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org SHN_HIRESERVE = 0xffff 17345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} elf_section_index; 17445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 17545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/* elf symbol binding - index of visibility/behavior */ 17645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef enum { 17745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org STB_LOCAL = 0, /* invisible outside defining file */ 17845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org STB_GLOBAL = 1, /* visible to all combined object files */ 17945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org STB_WEAK = 2, /* global but lower precedence */ 18045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 18145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org STB_LOOS = 10, /* Environment specific use */ 18245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org STB_HIOS = 12, 18345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org STB_LOPROC = 13, /* reserved for processor specific semantics */ 18445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org STB_HIPROC = 15 18545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} elf_symbol_binding; 18645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 18745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/* elf symbol type - index of classifications */ 18845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef enum { 18945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org STT_NOTYPE = 0, /* type not specified */ 19045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org STT_OBJECT = 1, /* data object such as a variable, array, etc */ 19145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org STT_FUNC = 2, /* a function or executable code */ 19245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org STT_SECTION = 3, /* a section: often for relocation, STB_LOCAL */ 19345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org STT_FILE = 4, /* often source filename: STB_LOCAL, SHN_ABS */ 19445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org STT_COMMON = 5, /* Uninitialized common block. */ 19545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org STT_TLS = 6, /* TLS object. */ 19645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org STT_NUM = 7, 19745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 19845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org STT_LOOS = 10, /* Environment specific use */ 19945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org STT_HIOS = 12, 20045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org STT_LOPROC = 13, /* reserved for processor specific semantics */ 20145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org STT_HIPROC = 15 20245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} elf_symbol_type; 20345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 20445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef enum { 20545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org STN_UNDEF = 0 20645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} elf_symbol_index; 20745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 20845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/* elf symbol visibility - lower two bits of OTHER field */ 20945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef enum { 21045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org STV_DEFAULT = 0, /* Default symbol visibility rules */ 21145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org STV_INTERNAL = 1, /* Processor specific hidden class */ 21245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org STV_HIDDEN = 2, /* Sym unavailable in other modules */ 21345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org STV_PROTECTED = 3 /* Not preemptable, not exported */ 21445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} elf_symbol_vis; 21545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 21645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 21745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/* internal only object definitions */ 21845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#ifdef YASM_OBJFMT_ELF_INTERNAL 21945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 22045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define ELF_VISIBILITY_MASK 0x03 22145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define ELF_ST_VISIBILITY(v) ((v) & ELF_VISIBILITY_MASK) 22245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 22345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf)) 22445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define ELF32_R_INFO(s,t) (((s)<<8)+(unsigned char)(t)) 22545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define ELF32_ST_OTHER(vis) ELF_ST_VISIBILITY(vis) 22645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 22745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define ELF64_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf)) 22845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define ELF64_R_INFO(s,t) (((s)<<32) + ((t) & 0xffffffffL)) 22945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define ELF64_ST_OTHER(vis) ELF_ST_VISIBILITY(vis) 23045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 23145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define EHDR32_SIZE 52 23245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define EHDR64_SIZE 64 23345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define EHDR_MAXSIZE 64 23445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 23545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define SHDR32_SIZE 40 23645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define SHDR64_SIZE 64 23745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define SHDR_MAXSIZE 64 23845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 23945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define SYMTAB32_SIZE 16 24045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define SYMTAB64_SIZE 24 24145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define SYMTAB_MAXSIZE 24 24245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 24345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define SYMTAB32_ALIGN 4 24445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define SYMTAB64_ALIGN 8 24545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 24645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define RELOC32_SIZE 8 24745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define RELOC32A_SIZE 12 24845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define RELOC64_SIZE 16 24945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define RELOC64A_SIZE 24 25045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define RELOC_MAXSIZE 24 25145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 25245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define RELOC32_ALIGN 4 25345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#define RELOC64_ALIGN 8 25445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 25545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 25645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/* elf relocation type - index of semantics 25745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * 25845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * A = Addend (r_addend for RELA, value at location for REL) 25945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * B = Base address 26045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * G = Offset into global offset table (GOT) 26145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * GOT = Address of the global offset table (GOT) 26245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * L = Location of procedure linkage table (PLT) 26345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * P = Location of location being relocated (r_offset) 26445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * S = Value of symbol 26545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 26645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef enum { 26745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_386_NONE = 0, /* none */ 26845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_386_32 = 1, /* word32, S + A */ 26945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_386_PC32 = 2, /* word32, S + A - P */ 27045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_386_GOT32 = 3, /* word32, G + A - P */ 27145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_386_PLT32 = 4, /* word32, L + A - P */ 27245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_386_COPY = 5, /* none */ 27345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_386_GLOB_DAT = 6, /* word32, S */ 27445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_386_JMP_SLOT = 7, /* word32, S */ 27545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_386_RELATIVE = 8, /* word32, B + A */ 27645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_386_GOTOFF = 9, /* word32, S + A - GOT */ 27745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_386_GOTPC = 10, /* word32, GOT + A - P */ 27845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_386_TLS_TPOFF = 14, /* Negative offset in static TLS block (GNU 27945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org version) */ 28045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_386_TLS_IE = 15, /* Absolute address of GOT entry for negative 28145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org static TLS block offset */ 28245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_386_TLS_GOTIE = 16, /* GOT entry for negative static TLS block 28345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org offset */ 28445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_386_TLS_LE = 17, /* Negative offset relative to static TLS 28545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org (GNU version) */ 28645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_386_TLS_GD = 18, /* Direct 32 bit for GNU version of GD TLS */ 28745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_386_TLS_LDM = 19, /* Direct 32 bit for GNU version of LD TLS 28845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org in LE code */ 28945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_386_16 = 20, /* word16, S + A (GNU extension) */ 29045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_386_PC16 = 21, /* word16, S + A - P (GNU extension) */ 29145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_386_8 = 22, /* word8, S + A (GNU extension) */ 29245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_386_PC8 = 23, /* word8, S + A - P (GNU extension) */ 29345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_386_TLS_GD_32 = 24, /* Direct 32 bit for GD TLS */ 29445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_386_TLS_GD_PUSH = 25, /* Tag for pushl in GD TLS code */ 29545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_386_TLS_GD_CALL = 26, /* Relocation for call to */ 29645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_386_TLS_GD_POP = 27, /* Tag for popl in GD TLS code */ 29745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_386_TLS_LDM_32 = 28, /* Direct 32 bit for local dynamic code */ 29845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_386_TLS_LDM_PUSH = 29, /* Tag for pushl in LDM TLS code */ 29945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_386_TLS_LDM_CALL = 30, /* Relocation for call to */ 30045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_386_TLS_LDM_POP = 31, /* Tag for popl in LDM TLS code */ 30145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_386_TLS_LDO_32 = 32, /* Offset relative to TLS block */ 30245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_386_TLS_IE_32 = 33, /* GOT entry for static TLS block */ 30345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_386_TLS_LE_32 = 34, /* Offset relative to static TLS block */ 30445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_386_TLS_DTPMOD32 = 35, /* ID of module containing symbol */ 30545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_386_TLS_DTPOFF32 = 36, /* Offset in TLS block */ 306a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org R_386_TLS_TPOFF32 = 37, /* Offset in static TLS block */ 307a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org R_386_TLS_GOTDESC = 39, 308a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org R_386_TLS_DESC_CALL = 40, 309a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org R_386_TLS_DESC = 41 31045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} elf_386_relocation_type; 31145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 31245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgtypedef enum { 31345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_X86_64_NONE = 0, /* none */ 31445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_X86_64_64 = 1, /* word64, S + A */ 31545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_X86_64_PC32 = 2, /* word32, S + A - P */ 31645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_X86_64_GOT32 = 3, /* word32, G + A */ 31745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_X86_64_PLT32 = 4, /* word32, L + A - P */ 31845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_X86_64_COPY = 5, /* none */ 31945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_X86_64_GLOB_DAT = 6, /* word64, S, set GOT entry to data address */ 32045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_X86_64_JMP_SLOT = 7, /* word64, S, set GOT entry to code address */ 32145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_X86_64_RELATIVE = 8, /* word64, B + A */ 32245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_X86_64_GOTPCREL = 9, /* word32, G + GOT + A - P */ 32345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_X86_64_32 = 10, /* word32 (zero extend), S + A */ 32445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_X86_64_32S = 11, /* word32 (sign extend), S + A */ 32545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_X86_64_16 = 12, /* word16, S + A */ 32645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_X86_64_PC16 = 13, /* word16, S + A - P */ 32745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_X86_64_8 = 14, /* word8, S + A */ 32845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_X86_64_PC8 = 15, /* word8, S + A - P */ 32945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_X86_64_DPTMOD64 = 16, /* word64, ID of module containing symbol */ 33045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_X86_64_DTPOFF64 = 17, /* word64, offset in TLS block */ 33145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_X86_64_TPOFF64 = 18, /* word64, offset in initial TLS block */ 33245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_X86_64_TLSGD = 19, /* word32, PC-rel offset to GD GOT block */ 33345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_X86_64_TLSLD = 20, /* word32, PC-rel offset to LD GOT block */ 33445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_X86_64_DTPOFF32 = 21, /* word32, offset to TLS block */ 33545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org R_X86_64_GOTTPOFF = 22, /* word32, PC-rel offset to IE GOT entry */ 336a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org R_X86_64_TPOFF32 = 23, /* word32, offset in initial TLS block */ 337a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org R_X86_64_PC64 = 24, /* word64, PC relative */ 338a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org R_X86_64_GOTOFF64 = 25, /* word64, offset to GOT */ 339a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org R_X86_64_GOTPC32 = 26, /* word32, signed pc relative to GOT */ 340a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org R_X86_64_GOT64 = 27, /* word64, GOT entry offset */ 341a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org R_X86_64_GOTPCREL64 = 28, /* word64, signed pc relative to GOT entry */ 342a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org R_X86_64_GOTPC64 = 29, /* word64, signed pc relative to GOT */ 343a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org R_X86_64_GOTPLT64 = 30, /* like GOT64, but indicates PLT entry needed */ 344a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org R_X86_64_PLTOFF64 = 31, /* word64, GOT relative offset to PLT entry */ 345a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org R_X86_64_GOTPC32_TLSDESC = 34, /* GOT offset for TLS descriptor */ 346a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org R_X86_64_TLSDESC_CALL = 35, /* Marker for call through TLS descriptor */ 347a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org R_X86_64_TLSDESC = 36 /* TLS descriptor */ 34845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org} elf_x86_64_relocation_type; 34945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 35045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgstruct elf_secthead { 35145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_section_type type; 35245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_section_flags flags; 35345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_address offset; 35445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm_intnum *size; 35545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_section_index link; 35645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_section_info info; /* see note ESD1 */ 35745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org unsigned long align; 35845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_size entsize; 35945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 36045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm_symrec *sym; 36145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_strtab_entry *name; 36245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_section_index index; 36345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 36445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_strtab_entry *rel_name; 36545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_section_index rel_index; 36645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_address rel_offset; 36745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org unsigned long nreloc; 36845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org}; 36945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 37045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/* Note ESD1: 37145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * for section types SHT_REL, SHT_RELA: 37245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * link -> index of associated symbol table 37345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * info -> index of relocated section 37445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * for section types SHT_SYMTAB, SHT_DYNSYM: 37545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * link -> index of associated string table 37645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * info -> 1+index of last "local symbol" (bind == STB_LOCAL) 37745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * (for section type SHT_DNAMIC: 37845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * link -> index of string table 37945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * info -> 0 ) 38045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * (for section type SHT_HASH: 38145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * link -> index of symbol table to which hash applies 38245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * info -> 0 ) 38345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * for all others: 38445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * link -> SHN_UNDEF 38545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org * info -> 0 38645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org */ 38745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 38845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgstruct elf_reloc_entry { 38945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm_reloc reloc; 39045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org int rtype_rel; 39145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org size_t valsize; 39245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm_intnum *addend; 39345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /*@null@*/ yasm_symrec *wrt; 394a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org int is_GOT_sym; 39545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org}; 39645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 39745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgSTAILQ_HEAD(elf_strtab_head, elf_strtab_entry); 39845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgstruct elf_strtab_entry { 39945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org STAILQ_ENTRY(elf_strtab_entry) qlink; 40045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org unsigned long index; 40145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org char *str; 40245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org}; 40345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 40445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgSTAILQ_HEAD(elf_symtab_head, elf_symtab_entry); 40545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgstruct elf_symtab_entry { 40645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org STAILQ_ENTRY(elf_symtab_entry) qlink; 40745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org int in_table; 40845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm_symrec *sym; 40945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm_section *sect; 41045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_strtab_entry *name; 41145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_address value; 41245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /*@dependent@*/ yasm_expr *xsize; 41345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_size size; 41445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_section_index index; 41545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_symbol_binding bind; 41645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_symbol_type type; 41745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_symbol_vis vis; 41845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_symbol_index symindex; 41945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org}; 42045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 42145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#endif /* defined(YASM_OBJFMT_ELF_INTERNAL) */ 42245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 42345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgextern const yasm_assoc_data_callback elf_section_data; 42445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgextern const yasm_assoc_data_callback elf_symrec_data; 425a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.orgextern const yasm_assoc_data_callback elf_ssym_symrec_data; 42645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 42745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 42845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgconst elf_machine_handler *elf_set_arch(struct yasm_arch *arch, 42945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm_symtab *symtab, 43045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org int bits_pref); 43145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 43245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgyasm_symrec *elf_get_special_sym(const char *name, const char *parser); 43345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 43445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/* reloc functions */ 43545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgint elf_is_wrt_sym_relative(yasm_symrec *wrt); 43645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgint elf_is_wrt_pos_adjusted(yasm_symrec *wrt); 43745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgelf_reloc_entry *elf_reloc_entry_create(yasm_symrec *sym, 43845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org /*@null@*/ yasm_symrec *wrt, 43945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm_intnum *addr, 44045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org int rel, 441a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org size_t valsize, 442a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org int is_GOT_sym); 44345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid elf_reloc_entry_destroy(void *entry); 44445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 44545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/* strtab functions */ 44645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgelf_strtab_entry *elf_strtab_entry_create(const char *str); 44745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid elf_strtab_entry_set_str(elf_strtab_entry *entry, const char *str); 44845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgelf_strtab_head *elf_strtab_create(void); 44945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgelf_strtab_entry *elf_strtab_append_str(elf_strtab_head *head, const char *str); 45045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid elf_strtab_destroy(elf_strtab_head *head); 45145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgunsigned long elf_strtab_output_to_file(FILE *f, elf_strtab_head *head); 45245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 45345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/* symtab functions */ 45445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgelf_symtab_entry *elf_symtab_entry_create(elf_strtab_entry *name, 45545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org struct yasm_symrec *sym); 45645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgelf_symtab_head *elf_symtab_create(void); 45745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid elf_symtab_append_entry(elf_symtab_head *symtab, elf_symtab_entry *entry); 45845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid elf_symtab_insert_local_sym(elf_symtab_head *symtab, 45945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_symtab_entry *entry); 46045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid elf_symtab_destroy(elf_symtab_head *head); 46145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgunsigned long elf_symtab_assign_indices(elf_symtab_head *symtab); 46245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgunsigned long elf_symtab_write_to_file(FILE *f, elf_symtab_head *symtab, 46345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm_errwarns *errwarns); 46445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid elf_symtab_set_nonzero(elf_symtab_entry *entry, 46545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org struct yasm_section *sect, 46645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_section_index sectidx, 46745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_symbol_binding bind, 46845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_symbol_type type, 46945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org struct yasm_expr *size, 47045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_address *value); 47145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid elf_sym_set_visibility(elf_symtab_entry *entry, 47245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_symbol_vis vis); 47345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid elf_sym_set_type(elf_symtab_entry *entry, elf_symbol_type type); 47445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid elf_sym_set_size(elf_symtab_entry *entry, struct yasm_expr *size); 47545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgint elf_sym_in_table(elf_symtab_entry *entry); 47645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 47745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/* section header functions */ 47845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgelf_secthead *elf_secthead_create(elf_strtab_entry *name, 47945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_section_type type, 48045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_section_flags flags, 48145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_address offset, 48245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_size size); 48345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid elf_secthead_destroy(elf_secthead *esd); 48445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgunsigned long elf_secthead_write_to_file(FILE *f, elf_secthead *esd, 48545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_section_index sindex); 48645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid elf_secthead_append_reloc(yasm_section *sect, elf_secthead *shead, 48745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_reloc_entry *reloc); 48845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgelf_section_type elf_secthead_get_type(elf_secthead *shead); 48945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid elf_secthead_set_typeflags(elf_secthead *shead, elf_section_type type, 49045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_section_flags flags); 49145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgint elf_secthead_is_empty(elf_secthead *shead); 49245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgstruct yasm_symrec *elf_secthead_get_sym(elf_secthead *shead); 49345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgunsigned long elf_secthead_get_align(const elf_secthead *shead); 49445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgunsigned long elf_secthead_set_align(elf_secthead *shead, unsigned long align); 49545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgelf_section_index elf_secthead_get_index(elf_secthead *shead); 49645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgelf_section_info elf_secthead_set_info(elf_secthead *shead, 49745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_section_info info); 49845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgelf_section_index elf_secthead_set_index(elf_secthead *shead, 49945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_section_index sectidx); 50045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgelf_section_index elf_secthead_set_link(elf_secthead *shead, 50145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_section_index link); 50245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgelf_section_index elf_secthead_set_rel_index(elf_secthead *shead, 50345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_section_index sectidx); 50445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgelf_strtab_entry *elf_secthead_set_rel_name(elf_secthead *shead, 50545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_strtab_entry *entry); 50645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgelf_size elf_secthead_set_entsize(elf_secthead *shead, elf_size size); 50745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgstruct yasm_symrec *elf_secthead_set_sym(elf_secthead *shead, 50845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org struct yasm_symrec *sym); 50945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgvoid elf_secthead_add_size(elf_secthead *shead, yasm_intnum *size); 51045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgchar *elf_secthead_name_reloc_section(const char *basesect); 511a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.orgvoid elf_handle_reloc_addend(yasm_intnum *intn, 512a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org elf_reloc_entry *reloc, 513a1b5233e6d340f45f4846131fec9d0b92e203ce4hbono@chromium.org unsigned long offset); 51445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgunsigned long elf_secthead_write_rel_to_file(FILE *f, elf_section_index symtab, 51545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm_section *sect, 51645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_secthead *esd, 51745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_section_index sindex); 51845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgunsigned long elf_secthead_write_relocs_to_file(FILE *f, yasm_section *sect, 51945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_secthead *shead, 52045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org yasm_errwarns *errwarns); 52145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orglong elf_secthead_set_file_offset(elf_secthead *shead, long pos); 52245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 52345afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org/* program header function */ 52445afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgunsigned long 52545afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgelf_proghead_get_size(void); 52645afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgunsigned long 52745afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.orgelf_proghead_write_to_file(FILE *f, 52845afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_offset secthead_addr, 52945afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org unsigned long secthead_count, 53045afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org elf_section_index shstrtab_index); 53145afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org 53245afe016bed87b9c6946184709058b39ede3f77ajwong@chromium.org#endif /* ELF_H_INCLUDED */ 533