Home | History | Annotate | Download | only in elf
      1 /*
      2  * ELF object format helpers
      3  *
      4  *  Copyright (C) 2003-2007  Michael Urman
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  *
     15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS''
     16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE
     19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     25  * POSSIBILITY OF SUCH DAMAGE.
     26  */
     27 
     28 #ifndef ELF_H_INCLUDED
     29 #define ELF_H_INCLUDED
     30 
     31 typedef struct elf_reloc_entry elf_reloc_entry;
     32 typedef struct elf_reloc_head elf_reloc_head;
     33 typedef struct elf_secthead elf_secthead;
     34 typedef struct elf_strtab_entry elf_strtab_entry;
     35 typedef struct elf_strtab_head elf_strtab_head;
     36 typedef struct elf_symtab_entry elf_symtab_entry;
     37 typedef struct elf_symtab_head elf_symtab_head;
     38 
     39 typedef struct elf_machine_handler elf_machine_handler;
     40 
     41 typedef unsigned long   elf_address;
     42 typedef unsigned long   elf_offset;
     43 typedef unsigned long   elf_size;
     44 typedef unsigned long   elf_section_info;
     45 
     46 typedef enum {
     47     ET_NONE = 0,
     48     ET_REL = 1,                                 /* Relocatable */
     49     ET_EXEC = 2,                                /* Executable */
     50     ET_DYN = 3,                                 /* Shared object */
     51     ET_CORE = 4,                                /* Core */
     52     ET_LOOS = 0xfe00,                           /* Environment specific */
     53     ET_HIOS = 0xfeff,
     54     ET_LOPROC = 0xff00,                         /* Processor specific */
     55     ET_HIPROC = 0xffff
     56 } elf_file_type;
     57 
     58 typedef enum {
     59     EM_NONE = 0,
     60     EM_M32 = 1,                                 /* AT&T WE 32100 */
     61     EM_SPARC = 2,                               /* SPARC */
     62     EM_386 = 3,                                 /* Intel 80386 */
     63     EM_68K = 4,                                 /* Motorola 68000 */
     64     EM_88K = 5,                                 /* Motorola 88000 */
     65     EM_860 = 7,                                 /* Intel 80860 */
     66     EM_MIPS = 8,                                /* MIPS RS3000 */
     67 
     68     EM_S370 = 9,                                /* IBM System/370 */
     69     EM_MIPS_RS4_BE = 10,                        /* MIPS R4000 Big-Endian (dep)*/
     70     EM_PARISC = 15,                             /* HPPA */
     71     EM_SPARC32PLUS = 18,                        /* SPARC v8plus */
     72     EM_PPC = 20,                                /* PowerPC 32-bit */
     73     EM_PPC64 = 21,                              /* PowerPC 64-bit */
     74     EM_ARM = 40,                                /* ARM */
     75     EM_SPARCV9 = 43,                            /* SPARC v9 64-bit */
     76     EM_IA_64 = 50,                              /* Intel IA-64 */
     77     EM_X86_64 = 62,                             /* AMD x86-64 */
     78     EM_ALPHA = 0x9026                           /* Alpha (no ABI) */
     79 } elf_machine;
     80 
     81 typedef enum {
     82     ELFMAG0 = 0x7f,
     83     ELFMAG1 = 0x45,
     84     ELFMAG2 = 0x4c,
     85     ELFMAG3 = 0x46
     86 } elf_magic;
     87 
     88 typedef enum {
     89     EV_NONE = 0,                                /* invalid */
     90     EV_CURRENT = 1                              /* current */
     91 } elf_version;
     92 
     93 typedef enum {
     94     EI_MAG0 = 0,                                /* File id */
     95     EI_MAG1 = 1,
     96     EI_MAG2 = 2,
     97     EI_MAG3 = 3,
     98     EI_CLASS = 4,                               /* File class */
     99     EI_DATA = 5,                                /* Data encoding */
    100     EI_VERSION = 6,                             /* File version */
    101     EI_OSABI = 7,                               /* OS and ABI */
    102     EI_ABIVERSION = 8,                          /* version of ABI */
    103 
    104     EI_PAD = 9,                                 /* Pad to end; start here */
    105     EI_NIDENT = 16                              /* Sizeof e_ident[] */
    106 } elf_identification_index;
    107 
    108 typedef enum {
    109     ELFOSABI_SYSV = 0,                          /* System V ABI */
    110     ELFOSABI_HPUX = 1,                          /* HP-UX os */
    111     ELFOSABI_STANDALONE = 255                   /* Standalone / embedded app */
    112 } elf_osabi_index;
    113 
    114 typedef enum {
    115     ELFCLASSNONE = 0,                           /* invalid */
    116     ELFCLASS32 = 1,                             /* 32-bit */
    117     ELFCLASS64 = 2                              /* 64-bit */
    118 } elf_class;
    119 
    120 typedef enum {
    121     ELFDATANONE = 0,
    122     ELFDATA2LSB = 1,
    123     ELFDATA2MSB = 2
    124 } elf_data_encoding;
    125 
    126 /* elf section types - index of semantics */
    127 typedef enum {
    128     SHT_NULL = 0,               /* inactive section - no associated data */
    129     SHT_PROGBITS = 1,           /* defined by program for its own meaning */
    130     SHT_SYMTAB = 2,             /* symbol table (primarily) for linking */
    131     SHT_STRTAB = 3,             /* string table - symbols need names */
    132     SHT_RELA = 4,               /* relocation entries w/ explicit addends */
    133     SHT_HASH = 5,               /* symbol hash table - for dynamic linking */
    134     SHT_DYNAMIC = 6,            /* information for dynamic linking */
    135     SHT_NOTE = 7,               /* extra data marking the file somehow */
    136     SHT_NOBITS = 8,             /* no stored data, but occupies runtime space */
    137     SHT_REL = 9,                /* relocations entries w/o explicit addends */
    138     SHT_SHLIB = 10,             /* reserved; unspecified semantics */
    139     SHT_DYNSYM = 11,            /* like symtab, but more for dynamic linking */
    140 
    141     SHT_LOOS = 0x60000000,      /* reserved for environment specific use */
    142     SHT_HIOS = 0x6fffffff,
    143     SHT_LOPROC = 0x70000000,    /* reserved for processor specific semantics */
    144     SHT_HIPROC = 0x7fffffff/*,
    145     SHT_LOUSER = 0x80000000,*/  /* reserved for applications; safe */
    146     /*SHT_HIUSER = 0xffffffff*/
    147 } elf_section_type;
    148 
    149 /* elf section flags - bitfield of attributes */
    150 typedef enum {
    151     SHF_WRITE = 0x1,            /* data should be writable at runtime */
    152     SHF_ALLOC = 0x2,            /* occupies memory at runtime */
    153     SHF_EXECINSTR = 0x4,        /* contains machine instructions */
    154     SHF_MERGE = 0x10,           /* data can be merged */
    155     SHF_STRINGS = 0x20,         /* contains 0-terminated strings */
    156     SHF_GROUP = 0x200,          /* member of a section group */
    157     SHF_TLS = 0x400,            /* thread local storage */
    158     SHF_MASKOS = 0x0f000000/*,*//* environment specific use */
    159     /*SHF_MASKPROC = 0xf0000000*/       /* bits reserved for processor specific needs */
    160 } elf_section_flags;
    161 
    162 /* elf section index - just the special ones */
    163 typedef enum {
    164     SHN_UNDEF = 0,              /* undefined symbol; requires other global */
    165     SHN_LORESERVE = 0xff00,     /* reserved for various semantics */
    166     SHN_LOPROC = 0xff00,        /* reserved for processor specific semantics */
    167     SHN_HIPROC = 0xff1f,
    168     SHN_LOOS = 0xff20,          /* reserved for environment specific use */
    169     SHN_HIOS = 0xff3f,
    170     SHN_ABS = 0xfff1,           /* associated symbols don't change on reloc */
    171     SHN_COMMON = 0xfff2,        /* associated symbols refer to unallocated */
    172     SHN_HIRESERVE = 0xffff
    173 } elf_section_index;
    174 
    175 /* elf symbol binding - index of visibility/behavior */
    176 typedef enum {
    177     STB_LOCAL = 0,              /* invisible outside defining file */
    178     STB_GLOBAL = 1,             /* visible to all combined object files */
    179     STB_WEAK = 2,               /* global but lower precedence */
    180 
    181     STB_LOOS = 10,              /* Environment specific use */
    182     STB_HIOS = 12,
    183     STB_LOPROC = 13,            /* reserved for processor specific semantics */
    184     STB_HIPROC = 15
    185 } elf_symbol_binding;
    186 
    187 /* elf symbol type - index of classifications */
    188 typedef enum {
    189     STT_NOTYPE = 0,             /* type not specified */
    190     STT_OBJECT = 1,             /* data object such as a variable, array, etc */
    191     STT_FUNC = 2,               /* a function or executable code */
    192     STT_SECTION = 3,            /* a section: often for relocation, STB_LOCAL */
    193     STT_FILE = 4,               /* often source filename: STB_LOCAL, SHN_ABS */
    194     STT_COMMON = 5,             /* Uninitialized common block. */
    195     STT_TLS = 6,                /* TLS object. */
    196     STT_NUM = 7,
    197 
    198     STT_LOOS = 10,              /* Environment specific use */
    199     STT_HIOS = 12,
    200     STT_LOPROC = 13,            /* reserved for processor specific semantics */
    201     STT_HIPROC = 15
    202 } elf_symbol_type;
    203 
    204 typedef enum {
    205     STN_UNDEF = 0
    206 } elf_symbol_index;
    207 
    208 /* elf symbol visibility - lower two bits of OTHER field */
    209 typedef enum {
    210     STV_DEFAULT = 0,            /* Default symbol visibility rules */
    211     STV_INTERNAL = 1,           /* Processor specific hidden class */
    212     STV_HIDDEN = 2,             /* Sym unavailable in other modules */
    213     STV_PROTECTED = 3           /* Not preemptable, not exported */
    214 } elf_symbol_vis;
    215 
    216 
    217 /* internal only object definitions */
    218 #ifdef YASM_OBJFMT_ELF_INTERNAL
    219 
    220 #define ELF_VISIBILITY_MASK             0x03
    221 #define ELF_ST_VISIBILITY(v)            ((v) & ELF_VISIBILITY_MASK)
    222 
    223 #define ELF32_ST_INFO(bind, type)       (((bind) << 4) + ((type) & 0xf))
    224 #define ELF32_R_INFO(s,t)               (((s)<<8)+(unsigned char)(t))
    225 #define ELF32_ST_OTHER(vis)             ELF_ST_VISIBILITY(vis)
    226 
    227 #define ELF64_ST_INFO(bind, type)       (((bind) << 4) + ((type) & 0xf))
    228 #define ELF64_R_INFO(s,t)               (((s)<<32) + ((t) & 0xffffffffL))
    229 #define ELF64_ST_OTHER(vis)             ELF_ST_VISIBILITY(vis)
    230 
    231 #define EHDR32_SIZE 52
    232 #define EHDR64_SIZE 64
    233 #define EHDR_MAXSIZE 64
    234 
    235 #define SHDR32_SIZE 40
    236 #define SHDR64_SIZE 64
    237 #define SHDR_MAXSIZE 64
    238 
    239 #define SYMTAB32_SIZE 16
    240 #define SYMTAB64_SIZE 24
    241 #define SYMTAB_MAXSIZE 24
    242 
    243 #define SYMTAB32_ALIGN 4
    244 #define SYMTAB64_ALIGN 8
    245 
    246 #define RELOC32_SIZE 8
    247 #define RELOC32A_SIZE 12
    248 #define RELOC64_SIZE 16
    249 #define RELOC64A_SIZE 24
    250 #define RELOC_MAXSIZE 24
    251 
    252 #define RELOC32_ALIGN 4
    253 #define RELOC64_ALIGN 8
    254 
    255 
    256 /* elf relocation type - index of semantics
    257  *
    258  * A = Addend (r_addend for RELA, value at location for REL)
    259  * B = Base address
    260  * G = Offset into global offset table (GOT)
    261  * GOT = Address of the global offset table (GOT)
    262  * L = Location of procedure linkage table (PLT)
    263  * P = Location of location being relocated (r_offset)
    264  * S = Value of symbol
    265  */
    266 typedef enum {
    267     R_386_NONE = 0,             /* none */
    268     R_386_32 = 1,               /* word32, S + A */
    269     R_386_PC32 = 2,             /* word32, S + A - P */
    270     R_386_GOT32 = 3,            /* word32, G + A - P */
    271     R_386_PLT32 = 4,            /* word32, L + A - P */
    272     R_386_COPY = 5,             /* none */
    273     R_386_GLOB_DAT = 6,         /* word32, S */
    274     R_386_JMP_SLOT = 7,         /* word32, S */
    275     R_386_RELATIVE = 8,         /* word32, B + A */
    276     R_386_GOTOFF = 9,           /* word32, S + A - GOT */
    277     R_386_GOTPC = 10,           /* word32, GOT + A - P */
    278     R_386_TLS_TPOFF = 14,       /* Negative offset in static TLS block (GNU
    279                                    version) */
    280     R_386_TLS_IE = 15,          /* Absolute address of GOT entry for negative
    281                                    static TLS block offset */
    282     R_386_TLS_GOTIE = 16,       /* GOT entry for negative static TLS block
    283                                    offset */
    284     R_386_TLS_LE = 17,          /* Negative offset relative to static TLS
    285                                    (GNU version) */
    286     R_386_TLS_GD = 18,          /* Direct 32 bit for GNU version of GD TLS */
    287     R_386_TLS_LDM = 19,         /* Direct 32 bit for GNU version of LD TLS
    288                                    in LE code */
    289     R_386_16 = 20,              /* word16, S + A (GNU extension) */
    290     R_386_PC16 = 21,            /* word16, S + A - P (GNU extension) */
    291     R_386_8 = 22,               /* word8, S + A (GNU extension) */
    292     R_386_PC8 = 23,             /* word8, S + A - P (GNU extension) */
    293     R_386_TLS_GD_32 = 24,       /* Direct 32 bit for GD TLS */
    294     R_386_TLS_GD_PUSH = 25,     /* Tag for pushl in GD TLS code */
    295     R_386_TLS_GD_CALL = 26,     /* Relocation for call to */
    296     R_386_TLS_GD_POP = 27,      /* Tag for popl in GD TLS code */
    297     R_386_TLS_LDM_32 = 28,      /* Direct 32 bit for local dynamic code */
    298     R_386_TLS_LDM_PUSH = 29,    /* Tag for pushl in LDM TLS code */
    299     R_386_TLS_LDM_CALL = 30,    /* Relocation for call to */
    300     R_386_TLS_LDM_POP = 31,     /* Tag for popl in LDM TLS code */
    301     R_386_TLS_LDO_32 = 32,      /* Offset relative to TLS block */
    302     R_386_TLS_IE_32 = 33,       /* GOT entry for static TLS block */
    303     R_386_TLS_LE_32 = 34,       /* Offset relative to static TLS block */
    304     R_386_TLS_DTPMOD32 = 35,    /* ID of module containing symbol */
    305     R_386_TLS_DTPOFF32 = 36,    /* Offset in TLS block */
    306     R_386_TLS_TPOFF32 = 37,     /* Offset in static TLS block */
    307     R_386_TLS_GOTDESC = 39,
    308     R_386_TLS_DESC_CALL = 40,
    309     R_386_TLS_DESC = 41
    310 } elf_386_relocation_type;
    311 
    312 typedef enum {
    313     R_X86_64_NONE = 0,          /* none */
    314     R_X86_64_64 = 1,            /* word64, S + A */
    315     R_X86_64_PC32 = 2,          /* word32, S + A - P */
    316     R_X86_64_GOT32 = 3,         /* word32, G + A */
    317     R_X86_64_PLT32 = 4,         /* word32, L + A - P */
    318     R_X86_64_COPY = 5,          /* none */
    319     R_X86_64_GLOB_DAT = 6,      /* word64, S, set GOT entry to data address */
    320     R_X86_64_JMP_SLOT = 7,      /* word64, S, set GOT entry to code address */
    321     R_X86_64_RELATIVE = 8,      /* word64, B + A */
    322     R_X86_64_GOTPCREL = 9,      /* word32, G + GOT + A - P */
    323     R_X86_64_32 = 10,           /* word32 (zero extend), S + A */
    324     R_X86_64_32S = 11,          /* word32 (sign extend), S + A */
    325     R_X86_64_16 = 12,           /* word16, S + A */
    326     R_X86_64_PC16 = 13,         /* word16, S + A - P */
    327     R_X86_64_8 = 14,            /* word8, S + A */
    328     R_X86_64_PC8 = 15,          /* word8, S + A - P */
    329     R_X86_64_DPTMOD64 = 16,     /* word64, ID of module containing symbol */
    330     R_X86_64_DTPOFF64 = 17,     /* word64, offset in TLS block */
    331     R_X86_64_TPOFF64 = 18,      /* word64, offset in initial TLS block */
    332     R_X86_64_TLSGD = 19,        /* word32, PC-rel offset to GD GOT block */
    333     R_X86_64_TLSLD = 20,        /* word32, PC-rel offset to LD GOT block */
    334     R_X86_64_DTPOFF32 = 21,     /* word32, offset to TLS block */
    335     R_X86_64_GOTTPOFF = 22,     /* word32, PC-rel offset to IE GOT entry */
    336     R_X86_64_TPOFF32 = 23,      /* word32, offset in initial TLS block */
    337     R_X86_64_PC64 = 24,         /* word64, PC relative */
    338     R_X86_64_GOTOFF64 = 25,     /* word64, offset to GOT */
    339     R_X86_64_GOTPC32 = 26,      /* word32, signed pc relative to GOT */
    340     R_X86_64_GOT64 = 27,        /* word64, GOT entry offset */
    341     R_X86_64_GOTPCREL64 = 28,   /* word64, signed pc relative to GOT entry */
    342     R_X86_64_GOTPC64 = 29,      /* word64, signed pc relative to GOT */
    343     R_X86_64_GOTPLT64 = 30,     /* like GOT64, but indicates PLT entry needed */
    344     R_X86_64_PLTOFF64 = 31,     /* word64, GOT relative offset to PLT entry */
    345     R_X86_64_GOTPC32_TLSDESC = 34, /* GOT offset for TLS descriptor */
    346     R_X86_64_TLSDESC_CALL = 35, /* Marker for call through TLS descriptor */
    347     R_X86_64_TLSDESC = 36       /* TLS descriptor */
    348 } elf_x86_64_relocation_type;
    349 
    350 struct elf_secthead {
    351     elf_section_type     type;
    352     elf_section_flags    flags;
    353     elf_address          offset;
    354     yasm_intnum         *size;
    355     elf_section_index    link;
    356     elf_section_info     info;      /* see note ESD1 */
    357     unsigned long        align;
    358     elf_size             entsize;
    359 
    360     yasm_symrec         *sym;
    361     elf_strtab_entry    *name;
    362     elf_section_index    index;
    363 
    364     elf_strtab_entry    *rel_name;
    365     elf_section_index    rel_index;
    366     elf_address          rel_offset;
    367     unsigned long        nreloc;
    368 };
    369 
    370 /* Note ESD1:
    371  *   for section types SHT_REL, SHT_RELA:
    372  *     link -> index of associated symbol table
    373  *     info -> index of relocated section
    374  *   for section types SHT_SYMTAB, SHT_DYNSYM:
    375  *     link -> index of associated string table
    376  *     info -> 1+index of last "local symbol" (bind == STB_LOCAL)
    377  *  (for section type SHT_DNAMIC:
    378  *     link -> index of string table
    379  *     info -> 0 )
    380  *  (for section type SHT_HASH:
    381  *     link -> index of symbol table to which hash applies
    382  *     info -> 0 )
    383  *   for all others:
    384  *     link -> SHN_UNDEF
    385  *     info -> 0
    386  */
    387 
    388 struct elf_reloc_entry {
    389     yasm_reloc           reloc;
    390     int                  rtype_rel;
    391     size_t               valsize;
    392     yasm_intnum         *addend;
    393     /*@null@*/ yasm_symrec *wrt;
    394     int                  is_GOT_sym;
    395 };
    396 
    397 STAILQ_HEAD(elf_strtab_head, elf_strtab_entry);
    398 struct elf_strtab_entry {
    399     STAILQ_ENTRY(elf_strtab_entry) qlink;
    400     unsigned long        index;
    401     char                *str;
    402 };
    403 
    404 STAILQ_HEAD(elf_symtab_head, elf_symtab_entry);
    405 struct elf_symtab_entry {
    406     STAILQ_ENTRY(elf_symtab_entry) qlink;
    407     int                 in_table;
    408     yasm_symrec         *sym;
    409     yasm_section        *sect;
    410     elf_strtab_entry    *name;
    411     elf_address          value;
    412     /*@dependent@*/ yasm_expr *xsize;
    413     elf_size             size;
    414     elf_section_index    index;
    415     elf_symbol_binding   bind;
    416     elf_symbol_type      type;
    417     elf_symbol_vis       vis;
    418     elf_symbol_index     symindex;
    419 };
    420 
    421 #endif /* defined(YASM_OBJFMT_ELF_INTERNAL) */
    422 
    423 extern const yasm_assoc_data_callback elf_section_data;
    424 extern const yasm_assoc_data_callback elf_symrec_data;
    425 extern const yasm_assoc_data_callback elf_ssym_symrec_data;
    426 
    427 
    428 const elf_machine_handler *elf_set_arch(struct yasm_arch *arch,
    429                                         yasm_symtab *symtab,
    430                                         int bits_pref);
    431 
    432 yasm_symrec *elf_get_special_sym(const char *name, const char *parser);
    433 
    434 /* reloc functions */
    435 int elf_is_wrt_sym_relative(yasm_symrec *wrt);
    436 int elf_is_wrt_pos_adjusted(yasm_symrec *wrt);
    437 elf_reloc_entry *elf_reloc_entry_create(yasm_symrec *sym,
    438                                         /*@null@*/ yasm_symrec *wrt,
    439                                         yasm_intnum *addr,
    440                                         int rel,
    441                                         size_t valsize,
    442                                         int is_GOT_sym);
    443 void elf_reloc_entry_destroy(void *entry);
    444 
    445 /* strtab functions */
    446 elf_strtab_entry *elf_strtab_entry_create(const char *str);
    447 void elf_strtab_entry_set_str(elf_strtab_entry *entry, const char *str);
    448 elf_strtab_head *elf_strtab_create(void);
    449 elf_strtab_entry *elf_strtab_append_str(elf_strtab_head *head, const char *str);
    450 void elf_strtab_destroy(elf_strtab_head *head);
    451 unsigned long elf_strtab_output_to_file(FILE *f, elf_strtab_head *head);
    452 
    453 /* symtab functions */
    454 elf_symtab_entry *elf_symtab_entry_create(elf_strtab_entry *name,
    455                                           struct yasm_symrec *sym);
    456 elf_symtab_head *elf_symtab_create(void);
    457 void elf_symtab_append_entry(elf_symtab_head *symtab, elf_symtab_entry *entry);
    458 void elf_symtab_insert_local_sym(elf_symtab_head *symtab,
    459                                  elf_symtab_entry *entry);
    460 void elf_symtab_destroy(elf_symtab_head *head);
    461 unsigned long elf_symtab_assign_indices(elf_symtab_head *symtab);
    462 unsigned long elf_symtab_write_to_file(FILE *f, elf_symtab_head *symtab,
    463                                        yasm_errwarns *errwarns);
    464 void elf_symtab_set_nonzero(elf_symtab_entry    *entry,
    465                             struct yasm_section *sect,
    466                             elf_section_index    sectidx,
    467                             elf_symbol_binding   bind,
    468                             elf_symbol_type      type,
    469                             struct yasm_expr    *size,
    470                             elf_address         *value);
    471 void elf_sym_set_visibility(elf_symtab_entry    *entry,
    472                             elf_symbol_vis       vis);
    473 void elf_sym_set_type(elf_symtab_entry *entry, elf_symbol_type type);
    474 void elf_sym_set_size(elf_symtab_entry *entry, struct yasm_expr *size);
    475 int elf_sym_in_table(elf_symtab_entry *entry);
    476 
    477 /* section header functions */
    478 elf_secthead *elf_secthead_create(elf_strtab_entry      *name,
    479                                   elf_section_type      type,
    480                                   elf_section_flags     flags,
    481                                   elf_address           offset,
    482                                   elf_size              size);
    483 void elf_secthead_destroy(elf_secthead *esd);
    484 unsigned long elf_secthead_write_to_file(FILE *f, elf_secthead *esd,
    485                                          elf_section_index sindex);
    486 void elf_secthead_append_reloc(yasm_section *sect, elf_secthead *shead,
    487                                elf_reloc_entry *reloc);
    488 elf_section_type elf_secthead_get_type(elf_secthead *shead);
    489 void elf_secthead_set_typeflags(elf_secthead *shead, elf_section_type type,
    490                                 elf_section_flags flags);
    491 int elf_secthead_is_empty(elf_secthead *shead);
    492 struct yasm_symrec *elf_secthead_get_sym(elf_secthead *shead);
    493 unsigned long elf_secthead_get_align(const elf_secthead *shead);
    494 unsigned long elf_secthead_set_align(elf_secthead *shead, unsigned long align);
    495 elf_section_index elf_secthead_get_index(elf_secthead *shead);
    496 elf_section_info elf_secthead_set_info(elf_secthead *shead,
    497                                        elf_section_info info);
    498 elf_section_index elf_secthead_set_index(elf_secthead *shead,
    499                                          elf_section_index sectidx);
    500 elf_section_index elf_secthead_set_link(elf_secthead *shead,
    501                                         elf_section_index link);
    502 elf_section_index elf_secthead_set_rel_index(elf_secthead *shead,
    503                                              elf_section_index sectidx);
    504 elf_strtab_entry *elf_secthead_set_rel_name(elf_secthead *shead,
    505                                             elf_strtab_entry *entry);
    506 elf_size elf_secthead_set_entsize(elf_secthead *shead, elf_size size);
    507 struct yasm_symrec *elf_secthead_set_sym(elf_secthead *shead,
    508                                          struct yasm_symrec *sym);
    509 void elf_secthead_add_size(elf_secthead *shead, yasm_intnum *size);
    510 char *elf_secthead_name_reloc_section(const char *basesect);
    511 void elf_handle_reloc_addend(yasm_intnum *intn,
    512                              elf_reloc_entry *reloc,
    513                              unsigned long offset);
    514 unsigned long elf_secthead_write_rel_to_file(FILE *f, elf_section_index symtab,
    515                                              yasm_section *sect,
    516                                              elf_secthead *esd,
    517                                              elf_section_index sindex);
    518 unsigned long elf_secthead_write_relocs_to_file(FILE *f, yasm_section *sect,
    519                                                 elf_secthead *shead,
    520                                                 yasm_errwarns *errwarns);
    521 long elf_secthead_set_file_offset(elf_secthead *shead, long pos);
    522 
    523 /* program header function */
    524 unsigned long
    525 elf_proghead_get_size(void);
    526 unsigned long
    527 elf_proghead_write_to_file(FILE *f,
    528                            elf_offset secthead_addr,
    529                            unsigned long secthead_count,
    530                            elf_section_index shstrtab_index);
    531 
    532 #endif /* ELF_H_INCLUDED */
    533