diff options
author | Cyrill Gorcunov <gorcunov@gmail.com> | 2009-11-06 11:15:37 +0300 |
---|---|---|
committer | Cyrill Gorcunov <gorcunov@gmail.com> | 2009-11-06 22:00:41 +0300 |
commit | a50f829435ad72c6b4afd5ce065b5fa1b82941aa (patch) | |
tree | 710e5ea94a39a0daa8ae0d8a69f30a8d158742d6 | |
parent | 4139c9af86edfb9a6d4846518f12f6347632bdc9 (diff) | |
download | nasm-a50f829435ad72c6b4afd5ce065b5fa1b82941aa.tar.gz nasm-a50f829435ad72c6b4afd5ce065b5fa1b82941aa.tar.bz2 nasm-a50f829435ad72c6b4afd5ce065b5fa1b82941aa.zip |
Merge elf header files
Merge elfcommon.h, elf32.h, elf64.h into
single elf.h -- we do support both elf32
and elf64 anyway. Let put them into common
place.
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
-rw-r--r-- | Makefile.in | 10 | ||||
-rw-r--r-- | Mkfiles/msvc.mak | 8 | ||||
-rw-r--r-- | Mkfiles/netware.mak | 6 | ||||
-rw-r--r-- | Mkfiles/openwcom.mak | 6 | ||||
-rw-r--r-- | Mkfiles/owlinux.mak | 6 | ||||
-rw-r--r-- | output/elf.h (renamed from output/elfcommon.h) | 291 | ||||
-rw-r--r-- | output/elf32.h | 167 | ||||
-rw-r--r-- | output/elf64.h | 189 | ||||
-rw-r--r-- | output/outelf.c | 2 | ||||
-rw-r--r-- | output/outelf32.c | 2 | ||||
-rw-r--r-- | output/outelf64.c | 2 |
11 files changed, 307 insertions, 382 deletions
diff --git a/Makefile.in b/Makefile.in index 80af30a..7033b96 100644 --- a/Makefile.in +++ b/Makefile.in @@ -313,15 +313,15 @@ output/outcoff.$(O): output/outcoff.c compiler.h config.h directives.h \ output/outdbg.$(O): output/outdbg.c compiler.h config.h directives.h \ insnsi.h nasm.h nasmlib.h output/outform.h pptok.h preproc.h regs.h output/outelf.$(O): output/outelf.c compiler.h config.h directives.h \ - insnsi.h nasm.h nasmlib.h output/dwarf.h output/elfcommon.h output/outelf.h \ + insnsi.h nasm.h nasmlib.h output/dwarf.h output/elf.h output/outelf.h \ output/outform.h pptok.h preproc.h regs.h output/outelf32.$(O): output/outelf32.c compiler.h config.h directives.h \ - eval.h insnsi.h nasm.h nasmlib.h output/dwarf.h output/elf32.h \ - output/elfcommon.h output/outelf.h output/outform.h output/outlib.h pptok.h \ + eval.h insnsi.h nasm.h nasmlib.h output/dwarf.h output/elf.h \ + output/outelf.h output/outform.h output/outlib.h pptok.h \ preproc.h raa.h rbtree.h regs.h saa.h stdscan.h output/outelf64.$(O): output/outelf64.c compiler.h config.h directives.h \ - eval.h insnsi.h nasm.h nasmlib.h output/dwarf.h output/elf64.h \ - output/elfcommon.h output/outelf.h output/outform.h output/outlib.h pptok.h \ + eval.h insnsi.h nasm.h nasmlib.h output/dwarf.h output/elf.h \ + output/outelf.h output/outform.h output/outlib.h pptok.h \ preproc.h raa.h rbtree.h regs.h saa.h stdscan.h output/outform.$(O): output/outform.c compiler.h config.h directives.h \ insnsi.h nasm.h nasmlib.h output/outform.h pptok.h preproc.h regs.h diff --git a/Mkfiles/msvc.mak b/Mkfiles/msvc.mak index 6318b22..614d4fb 100644 --- a/Mkfiles/msvc.mak +++ b/Mkfiles/msvc.mak @@ -242,15 +242,15 @@ output/outcoff.$(O): output/outcoff.c compiler.h directives.h eval.h \ output/outdbg.$(O): output/outdbg.c compiler.h directives.h insnsi.h nasm.h \ nasmlib.h output/outform.h pptok.h preproc.h regs.h output/outelf.$(O): output/outelf.c compiler.h directives.h insnsi.h nasm.h \ - nasmlib.h output/dwarf.h output/elfcommon.h output/outelf.h \ + nasmlib.h output/dwarf.h output/elf.h output/outelf.h \ output/outform.h pptok.h preproc.h regs.h output/outelf32.$(O): output/outelf32.c compiler.h directives.h eval.h \ - insnsi.h nasm.h nasmlib.h output/dwarf.h output/elf32.h output/elfcommon.h \ + insnsi.h nasm.h nasmlib.h output/dwarf.h output/elf.h \ output/outelf.h output/outform.h output/outlib.h pptok.h preproc.h raa.h \ rbtree.h regs.h saa.h stdscan.h output/outelf64.$(O): output/outelf64.c compiler.h directives.h eval.h \ - insnsi.h nasm.h nasmlib.h output/dwarf.h output/elf64.h output/elfcommon.h \ - output/outelf.h output/outform.h output/outlib.h pptok.h preproc.h raa.h \ + insnsi.h nasm.h nasmlib.h output/dwarf.h output/elf.h \ + output/outform.h output/outlib.h pptok.h preproc.h raa.h \ rbtree.h regs.h saa.h stdscan.h output/outform.$(O): output/outform.c compiler.h directives.h insnsi.h \ nasm.h nasmlib.h output/outform.h pptok.h preproc.h regs.h diff --git a/Mkfiles/netware.mak b/Mkfiles/netware.mak index 8811f36..6c74375 100644 --- a/Mkfiles/netware.mak +++ b/Mkfiles/netware.mak @@ -180,12 +180,12 @@ outcoff.o: outcoff.c compiler.h config.h directives.h eval.h insnsi.h nasm.h \ outdbg.o: outdbg.c compiler.h config.h directives.h insnsi.h nasm.h \ nasmlib.h outform.h pptok.h preproc.h regs.h outelf.o: outelf.c compiler.h config.h directives.h insnsi.h nasm.h \ - nasmlib.h dwarf.h elfcommon.h outelf.h outform.h pptok.h preproc.h regs.h + nasmlib.h dwarf.h elf.h outelf.h outform.h pptok.h preproc.h regs.h outelf32.o: outelf32.c compiler.h config.h directives.h eval.h insnsi.h \ - nasm.h nasmlib.h dwarf.h elf32.h elfcommon.h outelf.h outform.h outlib.h \ + nasm.h nasmlib.h dwarf.h elf.h outelf.h outform.h outlib.h \ pptok.h preproc.h raa.h rbtree.h regs.h saa.h stdscan.h outelf64.o: outelf64.c compiler.h config.h directives.h eval.h insnsi.h \ - nasm.h nasmlib.h dwarf.h elf64.h elfcommon.h outelf.h outform.h outlib.h \ + nasm.h nasmlib.h dwarf.h elf.h outelf.h outform.h outlib.h \ pptok.h preproc.h raa.h rbtree.h regs.h saa.h stdscan.h outform.o: outform.c compiler.h config.h directives.h insnsi.h nasm.h \ nasmlib.h outform.h pptok.h preproc.h regs.h diff --git a/Mkfiles/openwcom.mak b/Mkfiles/openwcom.mak index 2e63634..e842e07 100644 --- a/Mkfiles/openwcom.mak +++ b/Mkfiles/openwcom.mak @@ -271,14 +271,14 @@ output\outcoff.$(O): output\outcoff.c compiler.h directives.h eval.h & output\outdbg.$(O): output\outdbg.c compiler.h directives.h insnsi.h nasm.h & nasmlib.h output\outform.h pptok.h preproc.h regs.h output\outelf.$(O): output\outelf.c compiler.h directives.h insnsi.h nasm.h & - nasmlib.h output\dwarf.h output\elfcommon.h output\outelf.h & + nasmlib.h output\dwarf.h output\elf.h output\outelf.h & output\outform.h pptok.h preproc.h regs.h output\outelf32.$(O): output\outelf32.c compiler.h directives.h eval.h & - insnsi.h nasm.h nasmlib.h output\dwarf.h output\elf32.h output\elfcommon.h & + insnsi.h nasm.h nasmlib.h output\dwarf.h output\elf.h & output\outelf.h output\outform.h output\outlib.h pptok.h preproc.h raa.h & rbtree.h regs.h saa.h stdscan.h output\outelf64.$(O): output\outelf64.c compiler.h directives.h eval.h & - insnsi.h nasm.h nasmlib.h output\dwarf.h output\elf64.h output\elfcommon.h & + insnsi.h nasm.h nasmlib.h output\dwarf.h output\elf.h & output\outelf.h output\outform.h output\outlib.h pptok.h preproc.h raa.h & rbtree.h regs.h saa.h stdscan.h output\outform.$(O): output\outform.c compiler.h directives.h insnsi.h & diff --git a/Mkfiles/owlinux.mak b/Mkfiles/owlinux.mak index 8b3a824..f6bc0e1 100644 --- a/Mkfiles/owlinux.mak +++ b/Mkfiles/owlinux.mak @@ -281,14 +281,14 @@ output/outcoff.$(O): output/outcoff.c compiler.h directives.h eval.h \ output/outdbg.$(O): output/outdbg.c compiler.h directives.h insnsi.h nasm.h \ nasmlib.h output/outform.h pptok.h preproc.h regs.h output/outelf.$(O): output/outelf.c compiler.h directives.h insnsi.h nasm.h \ - nasmlib.h output/dwarf.h output/elfcommon.h output/outelf.h \ + nasmlib.h output/dwarf.h output/elf.h output/outelf.h \ output/outform.h pptok.h preproc.h regs.h output/outelf32.$(O): output/outelf32.c compiler.h directives.h eval.h \ - insnsi.h nasm.h nasmlib.h output/dwarf.h output/elf32.h output/elfcommon.h \ + insnsi.h nasm.h nasmlib.h output/dwarf.h output/elf.h \ output/outelf.h output/outform.h output/outlib.h pptok.h preproc.h raa.h \ rbtree.h regs.h saa.h stdscan.h output/outelf64.$(O): output/outelf64.c compiler.h directives.h eval.h \ - insnsi.h nasm.h nasmlib.h output/dwarf.h output/elf64.h output/elfcommon.h \ + insnsi.h nasm.h nasmlib.h output/dwarf.h output/elf.h \ output/outelf.h output/outform.h output/outlib.h pptok.h preproc.h raa.h \ rbtree.h regs.h saa.h stdscan.h output/outform.$(O): output/outform.c compiler.h directives.h insnsi.h \ diff --git a/output/elfcommon.h b/output/elf.h index 78434a7..4ee8635 100644 --- a/output/elfcommon.h +++ b/output/elf.h @@ -31,8 +31,13 @@ * * ----------------------------------------------------------------------- */ -#ifndef OUTPUT_ELFCOMMON_H -#define OUTPUT_ELFCOMMON_H +#ifndef OUTPUT_ELF_H +#define OUTPUT_ELF_H + +/* + * Since NASM support both Elf32/64 file formats + * we need to cover all types, structures, typedefs and etc + */ #include "compiler.h" #include <inttypes.h> @@ -170,8 +175,7 @@ #define SHF_STRINGS (1 << 5) /* Contains nul-terminated strings */ #define SHF_INFO_LINK (1 << 6) /* `sh_info' contains SHT index */ #define SHF_LINK_ORDER (1 << 7) /* Preserve order after combining */ -#define SHF_OS_NONCONFORMING (1 << 8) /* Non-standard OS specific handling - required */ +#define SHF_OS_NONCONFORMING (1 << 8) /* Non-standard OS specific handling required */ #define SHF_GROUP (1 << 9) /* Section is member of a group. */ #define SHF_TLS (1 << 10) /* Section hold thread-local data. */ @@ -247,4 +251,281 @@ #define STV_HIDDEN 2 /* Sym unavailable in other modules */ #define STV_PROTECTED 3 /* Not preemptible, not exported */ -#endif /* OUTPUT_ELFCOMMON_H */ +/* + * ELF standard typedefs (yet more proof that <stdint.h> was way overdue) + */ + +typedef uint16_t Elf32_Half; +typedef int16_t Elf32_SHalf; +typedef uint32_t Elf32_Word; +typedef int32_t Elf32_Sword; +typedef uint64_t Elf32_Xword; +typedef int64_t Elf32_Sxword; + +typedef uint32_t Elf32_Off; +typedef uint32_t Elf32_Addr; +typedef uint16_t Elf32_Section; + +typedef uint16_t Elf64_Half; +typedef int16_t Elf64_SHalf; +typedef uint32_t Elf64_Word; +typedef int32_t Elf64_Sword; +typedef uint64_t Elf64_Xword; +typedef int64_t Elf64_Sxword; + +typedef uint64_t Elf64_Off; +typedef uint64_t Elf64_Addr; +typedef uint16_t Elf64_Section; + +/* + * Dynamic header + */ + +typedef struct elf32_dyn { + Elf32_Sword d_tag; + union { + Elf32_Sword d_val; + Elf32_Addr d_ptr; + } d_un; +} Elf32_Dyn; + +typedef struct elf64_dyn { + Elf64_Sxword d_tag; + union { + Elf64_Xword d_val; + Elf64_Addr d_ptr; + } d_un; +} Elf64_Dyn; + +/* + * Relocations + */ + +#define ELF32_R_SYM(x) ((x) >> 8) +#define ELF32_R_TYPE(x) ((x) & 0xff) + +typedef struct elf32_rel { + Elf32_Addr r_offset; + Elf32_Word r_info; +} Elf32_Rel; + +typedef struct elf32_rela { + Elf32_Addr r_offset; + Elf32_Word r_info; + Elf32_Sword r_addend; +} Elf32_Rela; + +enum reloc32_type { + R_386_32 = 1, /* ordinary absolute relocation */ + R_386_PC32 = 2, /* PC-relative relocation */ + R_386_GOT32 = 3, /* an offset into GOT */ + R_386_PLT32 = 4, /* a PC-relative offset into PLT */ + R_386_COPY = 5, /* ??? */ + R_386_GLOB_DAT = 6, /* ??? */ + R_386_JUMP_SLOT = 7, /* ??? */ + R_386_RELATIVE = 8, /* ??? */ + R_386_GOTOFF = 9, /* an offset from GOT base */ + R_386_GOTPC = 10, /* a PC-relative offset _to_ GOT */ + R_386_TLS_TPOFF = 14, /* Offset in static TLS block */ + R_386_TLS_IE = 15, /* Address of GOT entry for static TLS block offset */ + /* These are GNU extensions, but useful */ + R_386_16 = 20, /* A 16-bit absolute relocation */ + R_386_PC16 = 21, /* A 16-bit PC-relative relocation */ + R_386_8 = 22, /* An 8-bit absolute relocation */ + R_386_PC8 = 23 /* An 8-bit PC-relative relocation */ +}; + +#define ELF64_R_SYM(x) ((x) >> 32) +#define ELF64_R_TYPE(x) ((x) & 0xffffffff) + +typedef struct elf64_rel { + Elf64_Addr r_offset; + Elf64_Xword r_info; +} Elf64_Rel; + +typedef struct elf64_rela { + Elf64_Addr r_offset; + Elf64_Xword r_info; + Elf64_Sxword r_addend; +} Elf64_Rela; + +enum reloc64_type { + R_X86_64_NONE = 0, /* No reloc */ + R_X86_64_64 = 1, /* Direct 64 bit */ + R_X86_64_PC32 = 2, /* PC relative 32 bit signed */ + R_X86_64_GOT32 = 3, /* 32 bit GOT entry */ + R_X86_64_PLT32 = 4, /* 32 bit PLT address */ + R_X86_64_COPY = 5, /* Copy symbol at runtime */ + R_X86_64_GLOB_DAT = 6, /* Create GOT entry */ + R_X86_64_JUMP_SLOT = 7, /* Create PLT entry */ + R_X86_64_RELATIVE = 8, /* Adjust by program base */ + R_X86_64_GOTPCREL = 9, /* 32 bit signed PC relative offset to GOT */ + R_X86_64_32 = 10, /* Direct 32 bit zero extended */ + R_X86_64_32S = 11, /* Direct 32 bit sign extended */ + R_X86_64_16 = 12, /* Direct 16 bit zero extended */ + R_X86_64_PC16 = 13, /* 16 bit sign extended pc relative */ + R_X86_64_8 = 14, /* Direct 8 bit sign extended */ + R_X86_64_PC8 = 15, /* 8 bit sign extended pc relative */ + R_X86_64_DTPMOD64 = 16, /* ID of module containing symbol */ + R_X86_64_DTPOFF64 = 17, /* Offset in module's TLS block */ + R_X86_64_TPOFF64 = 18, /* Offset in initial TLS block */ + R_X86_64_TLSGD = 19, /* 32 bit signed PC relative offset to two GOT entries for GD symbol */ + R_X86_64_TLSLD = 20, /* 32 bit signed PC relative offset to two GOT entries for LD symbol */ + R_X86_64_DTPOFF32 = 21, /* Offset in TLS block */ + R_X86_64_GOTTPOFF = 22, /* 32 bit signed PC relative offset to GOT entry for IE symbol */ + R_X86_64_TPOFF32 = 23, /* Offset in initial TLS block */ + R_X86_64_PC64 = 24, /* word64 S + A - P */ + R_X86_64_GOTOFF64 = 25, /* word64 S + A - GOT */ + R_X86_64_GOTPC32 = 26, /* word32 GOT + A - P */ + R_X86_64_GOT64 = 27, /* word64 G + A */ + R_X86_64_GOTPCREL64 = 28, /* word64 G + GOT - P + A */ + R_X86_64_GOTPC64 = 29, /* word64 GOT - P + A */ + R_X86_64_GOTPLT64 = 30, /* word64 G + A */ + R_X86_64_PLTOFF64 = 31, /* word64 L - GOT + A */ + R_X86_64_SIZE32 = 32, /* word32 Z + A */ + R_X86_64_SIZE64 = 33, /* word64 Z + A */ + R_X86_64_GOTPC32_TLSDESC = 34, /* word32 */ + R_X86_64_TLSDESC_CALL = 35, /* none */ + R_X86_64_TLSDESC = 36 /* word64?2 */ +}; + +/* + * Symbol + */ + +typedef struct elf32_sym { + Elf32_Word st_name; + Elf32_Addr st_value; + Elf32_Word st_size; + unsigned char st_info; + unsigned char st_other; + Elf32_Half st_shndx; +} Elf32_Sym; + +typedef struct elf64_sym { + Elf64_Word st_name; + unsigned char st_info; + unsigned char st_other; + Elf64_Half st_shndx; + Elf64_Addr st_value; + Elf64_Xword st_size; +} Elf64_Sym; + +/* + * Main file header + */ + +typedef struct elf32_hdr { + unsigned char e_ident[EI_NIDENT]; + Elf32_Half e_type; + Elf32_Half e_machine; + Elf32_Word e_version; + Elf32_Addr e_entry; + Elf32_Off e_phoff; + Elf32_Off e_shoff; + Elf32_Word e_flags; + Elf32_Half e_ehsize; + Elf32_Half e_phentsize; + Elf32_Half e_phnum; + Elf32_Half e_shentsize; + Elf32_Half e_shnum; + Elf32_Half e_shstrndx; +} Elf32_Ehdr; + +typedef struct elf64_hdr { + unsigned char e_ident[EI_NIDENT]; + Elf64_Half e_type; + Elf64_Half e_machine; + Elf64_Word e_version; + Elf64_Addr e_entry; + Elf64_Off e_phoff; + Elf64_Off e_shoff; + Elf64_Word e_flags; + Elf64_Half e_ehsize; + Elf64_Half e_phentsize; + Elf64_Half e_phnum; + Elf64_Half e_shentsize; + Elf64_Half e_shnum; + Elf64_Half e_shstrndx; +} Elf64_Ehdr; + +/* + * Program header + */ + +typedef struct elf32_phdr { + Elf32_Word p_type; + Elf32_Off p_offset; + Elf32_Addr p_vaddr; + Elf32_Addr p_paddr; + Elf32_Word p_filesz; + Elf32_Word p_memsz; + Elf32_Word p_flags; + Elf32_Word p_align; +} Elf32_Phdr; + +typedef struct elf64_phdr { + Elf64_Word p_type; + Elf64_Word p_flags; + Elf64_Off p_offset; + Elf64_Addr p_vaddr; + Elf64_Addr p_paddr; + Elf64_Xword p_filesz; + Elf64_Xword p_memsz; + Elf64_Xword p_align; +} Elf64_Phdr; + +/* + * Section header + */ + +typedef struct elf32_shdr { + Elf32_Word sh_name; + Elf32_Word sh_type; + Elf32_Word sh_flags; + Elf32_Addr sh_addr; + Elf32_Off sh_offset; + Elf32_Word sh_size; + Elf32_Word sh_link; + Elf32_Word sh_info; + Elf32_Word sh_addralign; + Elf32_Word sh_entsize; +} Elf32_Shdr; + +typedef struct elf64_shdr { + Elf64_Word sh_name; + Elf64_Word sh_type; + Elf64_Xword sh_flags; + Elf64_Addr sh_addr; + Elf64_Off sh_offset; + Elf64_Xword sh_size; + Elf64_Word sh_link; + Elf64_Word sh_info; + Elf64_Xword sh_addralign; + Elf64_Xword sh_entsize; +} Elf64_Shdr; + +/* + * Note header + */ +typedef struct elf32_note { + Elf32_Word n_namesz; /* Name size */ + Elf32_Word n_descsz; /* Content size */ + Elf32_Word n_type; /* Content type */ +} Elf32_Nhdr; + +typedef struct elf64_note { + Elf64_Word n_namesz; /* Name size */ + Elf64_Word n_descsz; /* Content size */ + Elf64_Word n_type; /* Content type */ +} Elf64_Nhdr; + +/* How to extract and insert information held in the st_info field. */ +#define ELF32_ST_BIND(val) (((unsigned char) (val)) >> 4) +#define ELF32_ST_TYPE(val) ((val) & 0xf) + +/* Both Elf32_Sym and Elf64_Sym use the same one-byte st_info field. */ +#define ELF64_ST_BIND(val) ELF32_ST_BIND (val) +#define ELF64_ST_TYPE(val) ELF32_ST_TYPE (val) + +#endif /* OUTPUT_ELF_H */ diff --git a/output/elf32.h b/output/elf32.h deleted file mode 100644 index cd4e70f..0000000 --- a/output/elf32.h +++ /dev/null @@ -1,167 +0,0 @@ -/* ----------------------------------------------------------------------- * - * - * Copyright 1996-2009 The NASM Authors - All Rights Reserved - * See the file AUTHORS included with the NASM distribution for - * the specific copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following - * conditions are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * ----------------------------------------------------------------------- */ - -#ifndef OUTPUT_ELF32_H -#define OUTPUT_ELF32_H - -#include "output/elfcommon.h" - -/* ELF standard typedefs (yet more proof that <stdint.h> was way overdue) */ -typedef uint16_t Elf32_Half; -typedef int16_t Elf32_SHalf; -typedef uint32_t Elf32_Word; -typedef int32_t Elf32_Sword; -typedef uint64_t Elf32_Xword; -typedef int64_t Elf32_Sxword; - -typedef uint32_t Elf32_Off; -typedef uint32_t Elf32_Addr; -typedef uint16_t Elf32_Section; - -/* Dynamic header */ - -typedef struct elf32_dyn { - Elf32_Sword d_tag; - union { - Elf32_Sword d_val; - Elf32_Addr d_ptr; - } d_un; -} Elf32_Dyn; - -/* Relocations */ - -#define ELF32_R_SYM(x) ((x) >> 8) -#define ELF32_R_TYPE(x) ((x) & 0xff) - -typedef struct elf32_rel { - Elf32_Addr r_offset; - Elf32_Word r_info; -} Elf32_Rel; - -typedef struct elf32_rela { - Elf32_Addr r_offset; - Elf32_Word r_info; - Elf32_Sword r_addend; -} Elf32_Rela; - -enum reloc32_type { - R_386_32 = 1, /* ordinary absolute relocation */ - R_386_PC32 = 2, /* PC-relative relocation */ - R_386_GOT32 = 3, /* an offset into GOT */ - R_386_PLT32 = 4, /* a PC-relative offset into PLT */ - R_386_COPY = 5, /* ??? */ - R_386_GLOB_DAT = 6, /* ??? */ - R_386_JUMP_SLOT = 7, /* ??? */ - R_386_RELATIVE = 8, /* ??? */ - R_386_GOTOFF = 9, /* an offset from GOT base */ - R_386_GOTPC = 10, /* a PC-relative offset _to_ GOT */ - R_386_TLS_TPOFF = 14, /* Offset in static TLS block */ - R_386_TLS_IE = 15, /* Address of GOT entry for static TLS - block offset */ - /* These are GNU extensions, but useful */ - R_386_16 = 20, /* A 16-bit absolute relocation */ - R_386_PC16 = 21, /* A 16-bit PC-relative relocation */ - R_386_8 = 22, /* An 8-bit absolute relocation */ - R_386_PC8 = 23 /* An 8-bit PC-relative relocation */ -}; - -/* Symbol */ - -typedef struct elf32_sym { - Elf32_Word st_name; - Elf32_Addr st_value; - Elf32_Word st_size; - unsigned char st_info; - unsigned char st_other; - Elf32_Half st_shndx; -} Elf32_Sym; - -/* Main file header */ - -typedef struct elf32_hdr { - unsigned char e_ident[EI_NIDENT]; - Elf32_Half e_type; - Elf32_Half e_machine; - Elf32_Word e_version; - Elf32_Addr e_entry; - Elf32_Off e_phoff; - Elf32_Off e_shoff; - Elf32_Word e_flags; - Elf32_Half e_ehsize; - Elf32_Half e_phentsize; - Elf32_Half e_phnum; - Elf32_Half e_shentsize; - Elf32_Half e_shnum; - Elf32_Half e_shstrndx; -} Elf32_Ehdr; - -/* Program header */ - -typedef struct elf32_phdr { - Elf32_Word p_type; - Elf32_Off p_offset; - Elf32_Addr p_vaddr; - Elf32_Addr p_paddr; - Elf32_Word p_filesz; - Elf32_Word p_memsz; - Elf32_Word p_flags; - Elf32_Word p_align; -} Elf32_Phdr; - -/* Section header */ - -typedef struct elf32_shdr { - Elf32_Word sh_name; - Elf32_Word sh_type; - Elf32_Word sh_flags; - Elf32_Addr sh_addr; - Elf32_Off sh_offset; - Elf32_Word sh_size; - Elf32_Word sh_link; - Elf32_Word sh_info; - Elf32_Word sh_addralign; - Elf32_Word sh_entsize; -} Elf32_Shdr; - -/* Note header */ -typedef struct elf32_note { - Elf32_Word n_namesz; /* Name size */ - Elf32_Word n_descsz; /* Content size */ - Elf32_Word n_type; /* Content type */ -} Elf32_Nhdr; - -/* How to extract and insert information held in the st_info field. */ -#define ELF32_ST_BIND(val) (((unsigned char) (val)) >> 4) -#define ELF32_ST_TYPE(val) ((val) & 0xf) - -#endif /* OUTPUT_ELF32_H */ diff --git a/output/elf64.h b/output/elf64.h deleted file mode 100644 index 91aef94..0000000 --- a/output/elf64.h +++ /dev/null @@ -1,189 +0,0 @@ -/* ----------------------------------------------------------------------- * - * - * Copyright 1996-2009 The NASM Authors - All Rights Reserved - * See the file AUTHORS included with the NASM distribution for - * the specific copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following - * conditions are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * ----------------------------------------------------------------------- */ - -#ifndef OUTPUT_ELF64_H -#define OUTPUT_ELF64_H - -#include "output/elfcommon.h" - -/* ELF standard typedefs (yet more proof that <stdint.h> was way overdue) */ -typedef uint16_t Elf64_Half; -typedef int16_t Elf64_SHalf; -typedef uint32_t Elf64_Word; -typedef int32_t Elf64_Sword; -typedef uint64_t Elf64_Xword; -typedef int64_t Elf64_Sxword; - -typedef uint64_t Elf64_Off; -typedef uint64_t Elf64_Addr; -typedef uint16_t Elf64_Section; - -/* Dynamic header */ - -typedef struct elf64_dyn { - Elf64_Sxword d_tag; - union { - Elf64_Xword d_val; - Elf64_Addr d_ptr; - } d_un; -} Elf64_Dyn; - -/* Relocations */ - -#define ELF64_R_SYM(x) ((x) >> 32) -#define ELF64_R_TYPE(x) ((x) & 0xffffffff) - -typedef struct elf64_rel { - Elf64_Addr r_offset; - Elf64_Xword r_info; -} Elf64_Rel; - -typedef struct elf64_rela { - Elf64_Addr r_offset; - Elf64_Xword r_info; - Elf64_Sxword r_addend; -} Elf64_Rela; - -enum reloc64_type { - R_X86_64_NONE = 0, /* No reloc */ - R_X86_64_64 = 1, /* Direct 64 bit */ - R_X86_64_PC32 = 2, /* PC relative 32 bit signed */ - R_X86_64_GOT32 = 3, /* 32 bit GOT entry */ - R_X86_64_PLT32 = 4, /* 32 bit PLT address */ - R_X86_64_COPY = 5, /* Copy symbol at runtime */ - R_X86_64_GLOB_DAT = 6, /* Create GOT entry */ - R_X86_64_JUMP_SLOT = 7, /* Create PLT entry */ - R_X86_64_RELATIVE = 8, /* Adjust by program base */ - R_X86_64_GOTPCREL = 9, /* 32 bit signed PC relative offset to GOT */ - R_X86_64_32 = 10, /* Direct 32 bit zero extended */ - R_X86_64_32S = 11, /* Direct 32 bit sign extended */ - R_X86_64_16 = 12, /* Direct 16 bit zero extended */ - R_X86_64_PC16 = 13, /* 16 bit sign extended pc relative */ - R_X86_64_8 = 14, /* Direct 8 bit sign extended */ - R_X86_64_PC8 = 15, /* 8 bit sign extended pc relative */ - R_X86_64_DTPMOD64 = 16, /* ID of module containing symbol */ - R_X86_64_DTPOFF64 = 17, /* Offset in module's TLS block */ - R_X86_64_TPOFF64 = 18, /* Offset in initial TLS block */ - R_X86_64_TLSGD = 19, /* 32 bit signed PC relative offset - to two GOT entries for GD symbol */ - R_X86_64_TLSLD = 20, /* 32 bit signed PC relative offset - to two GOT entries for LD symbol */ - R_X86_64_DTPOFF32 = 21, /* Offset in TLS block */ - R_X86_64_GOTTPOFF = 22, /* 32 bit signed PC relative offset - to GOT entry for IE symbol */ - R_X86_64_TPOFF32 = 23, /* Offset in initial TLS block */ - R_X86_64_PC64 = 24, /* word64 S + A - P */ - R_X86_64_GOTOFF64 = 25, /* word64 S + A - GOT */ - R_X86_64_GOTPC32 = 26, /* word32 GOT + A - P */ - R_X86_64_GOT64 = 27, /* word64 G + A */ - R_X86_64_GOTPCREL64 = 28, /* word64 G + GOT - P + A */ - R_X86_64_GOTPC64 = 29, /* word64 GOT - P + A */ - R_X86_64_GOTPLT64 = 30, /* word64 G + A */ - R_X86_64_PLTOFF64 = 31, /* word64 L - GOT + A */ - R_X86_64_SIZE32 = 32, /* word32 Z + A */ - R_X86_64_SIZE64 = 33, /* word64 Z + A */ - R_X86_64_GOTPC32_TLSDESC = 34, /* word32 */ - R_X86_64_TLSDESC_CALL = 35, /* none */ - R_X86_64_TLSDESC = 36 /* word64×2 */ -}; - -/* Symbol */ - -typedef struct elf64_sym { - Elf64_Word st_name; - unsigned char st_info; - unsigned char st_other; - Elf64_Half st_shndx; - Elf64_Addr st_value; - Elf64_Xword st_size; -} Elf64_Sym; - -/* Main file header */ - -typedef struct elf64_hdr { - unsigned char e_ident[EI_NIDENT]; - Elf64_Half e_type; - Elf64_Half e_machine; - Elf64_Word e_version; - Elf64_Addr e_entry; - Elf64_Off e_phoff; - Elf64_Off e_shoff; - Elf64_Word e_flags; - Elf64_Half e_ehsize; - Elf64_Half e_phentsize; - Elf64_Half e_phnum; - Elf64_Half e_shentsize; - Elf64_Half e_shnum; - Elf64_Half e_shstrndx; -} Elf64_Ehdr; - -/* Program header */ - -typedef struct elf64_phdr { - Elf64_Word p_type; - Elf64_Word p_flags; - Elf64_Off p_offset; - Elf64_Addr p_vaddr; - Elf64_Addr p_paddr; - Elf64_Xword p_filesz; - Elf64_Xword p_memsz; - Elf64_Xword p_align; -} Elf64_Phdr; - -/* Section header */ - -typedef struct elf64_shdr { - Elf64_Word sh_name; - Elf64_Word sh_type; - Elf64_Xword sh_flags; - Elf64_Addr sh_addr; - Elf64_Off sh_offset; - Elf64_Xword sh_size; - Elf64_Word sh_link; - Elf64_Word sh_info; - Elf64_Xword sh_addralign; - Elf64_Xword sh_entsize; -} Elf64_Shdr; - -/* Note header */ -typedef struct elf64_note { - Elf64_Word n_namesz; /* Name size */ - Elf64_Word n_descsz; /* Content size */ - Elf64_Word n_type; /* Content type */ -} Elf64_Nhdr; - -/* Both Elf32_Sym and Elf64_Sym use the same one-byte st_info field. */ -#define ELF64_ST_BIND(val) ELF32_ST_BIND (val) -#define ELF64_ST_TYPE(val) ELF32_ST_TYPE (val) - -#endif /* OUTPUT_ELF64_H */ diff --git a/output/outelf.c b/output/outelf.c index a865440..e80d913 100644 --- a/output/outelf.c +++ b/output/outelf.c @@ -44,8 +44,8 @@ #include "nasm.h" #include "output/outform.h" -#include "output/elfcommon.h" #include "output/dwarf.h" +#include "output/elf.h" #include "output/outelf.h" #if defined(OF_ELF32) || defined(OF_ELF64) diff --git a/output/outelf32.c b/output/outelf32.c index c491fdd..b0a5a4c 100644 --- a/output/outelf32.c +++ b/output/outelf32.c @@ -54,8 +54,8 @@ #include "output/outlib.h" #include "rbtree.h" -#include "output/elf32.h" #include "output/dwarf.h" +#include "output/elf.h" #include "output/outelf.h" #ifdef OF_ELF32 diff --git a/output/outelf64.c b/output/outelf64.c index 5713f09..34fda6b 100644 --- a/output/outelf64.c +++ b/output/outelf64.c @@ -54,8 +54,8 @@ #include "output/outlib.h" #include "rbtree.h" -#include "output/elf64.h" #include "output/dwarf.h" +#include "output/elf.h" #include "output/outelf.h" #ifdef OF_ELF64 |