Hi,

below is another diff of my elf.h cleanup work. I'm still keeping 
/usr/include/elf_abi.h to not break GHC and all
Haskell based ports.

What I have done in this version is went thorough whole spec and check 
everything in the exec_elf.h. What's not in spec
I commented out with "not in spec" mark. I've also reordered code to be in a 
line with spec so curious man can open spec
and header file side by side and check without jumping here and there either in 
spec or in file just scroll down both while reading...

The most important fixes in exec_elf.h were:
- Elf64 types (Half/Quarter/Shalf), either badly defined or not in spec at all
- __alpha__ specific type definition is not in spec, hence commented out, hence 
Alpha may be broken
- a lot of other fixed here and there. Mostly additions of missing stuff, but 
some stuff also removed, especially
  from machines definitions.
- I've also added clear comments where the following part of the code is 
specified (URL) to easy checking
- I've also added a comment where spec. ends in the code and that OS specific 
or historically usable definitions continue
- I've moved into OS specific section some values commented out in the spec. 
section originally -- just to make base
  compilable and runnable on AMD64


So with this base is compilable and runnable on AMD64. W.r.t. ports, yes, some 
of those fails. I've not investigated more closely strange failures which may 
be a cause of me not cleaning up fs from previous snapshots -- this machine is 
basically 2 years old snapshots accumulation withought files removal (ports 
failing: thunderbird, seamonkey, tor-browser, poco, pypy). But some failures 
are clearly result of the work: libdwarf -- conflicts with ELF types due to 
presence of elf.h. I would also guess lang/mono -- segfaults.

Thanks for review and/or comments how to improve stuff or prepare for inclusion,

Karel

diff --git a/distrib/sets/lists/comp/mi b/distrib/sets/lists/comp/mi
index 3777a4cb179..e7cec7f19cc 100644
--- a/distrib/sets/lists/comp/mi
+++ b/distrib/sets/lists/comp/mi
@@ -822,7 +822,7 @@
 ./usr/include/dirent.h
 ./usr/include/disktab.h
 ./usr/include/dlfcn.h
-./usr/include/elf_abi.h
+./usr/include/elf.h
 ./usr/include/endian.h
 ./usr/include/err.h
 ./usr/include/errno.h
diff --git a/games/hangman/ksyms.c b/games/hangman/ksyms.c
index 18ce231fd22..047b867caca 100644
--- a/games/hangman/ksyms.c
+++ b/games/hangman/ksyms.c
@@ -18,7 +18,7 @@
 
 #include <ctype.h>
 #include <curses.h>
-#include <elf_abi.h>
+#include <elf.h>
 #include <err.h>
 #include <errno.h>
 #include <fcntl.h>
diff --git a/include/Makefile b/include/Makefile
index 1d7f894b595..f5a0b3bbf3a 100644
--- a/include/Makefile
+++ b/include/Makefile
@@ -11,7 +11,7 @@
 
 FILES= a.out.h ar.h asr.h assert.h bitstring.h blf.h bsd_auth.h \
        complex.h cpio.h ctype.h curses.h db.h dirent.h disktab.h \
-       dlfcn.h elf_abi.h err.h errno.h fenv.h float.h fnmatch.h fstab.h fts.h \
+       dlfcn.h elf.h err.h errno.h fenv.h float.h fnmatch.h fstab.h fts.h \
        ftw.h getopt.h glob.h grp.h icdb.h ieeefp.h ifaddrs.h inttypes.h \
        iso646.h kvm.h langinfo.h libgen.h limits.h link.h link_elf.h \
        locale.h login_cap.h math.h md5.h memory.h ndbm.h netdb.h netgroup.h \
diff --git a/include/elf_abi.h b/include/elf.h
similarity index 91%
rename from include/elf_abi.h
rename to include/elf.h
index 489869b1654..c1bc247cc3c 100644
--- a/include/elf_abi.h
+++ b/include/elf.h
@@ -1,4 +1,4 @@
-/*     $OpenBSD: elf_abi.h,v 1.4 1996/05/22 07:46:22 etheisen Exp $    */
+/*     $OpenBSD: elf.h,v 1.4 1996/05/22 07:46:22 etheisen Exp $        */
 /*
  * Copyright (c) 1996 Erik Theisen
  * All rights reserved.
@@ -25,9 +25,9 @@
  * (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 _ELF_ABI_H_
-#define _ELF_ABI_H_
+#ifndef _ELF_H_
+#define _ELF_H_
 
 #include <sys/exec_elf.h>
 
-#endif /* _ELF_ABI_H_ */
+#endif /* _ELF_H_ */
diff --git a/include/link_elf.h b/include/link_elf.h
index 45fc1b9e0b9..137e64744aa 100644
--- a/include/link_elf.h
+++ b/include/link_elf.h
@@ -7,7 +7,7 @@
 #ifndef _LINK_ELF_H
 #define _LINK_ELF_H
 
-#include <elf_abi.h>
+#include <elf.h>
 
 #ifndef DT_PROCNUM
 #define DT_PROCNUM 0
diff --git a/lib/libc/gen/elf_hash.c b/lib/libc/gen/elf_hash.c
index 5fdc2815457..5c98f401395 100644
--- a/lib/libc/gen/elf_hash.c
+++ b/lib/libc/gen/elf_hash.c
@@ -37,7 +37,7 @@
 #include <unistd.h>
 #include <sys/exec.h>
 
-#include <elf_abi.h>
+#include <elf.h>
 
 /*
  * Standard ELF ABI hash function.
diff --git a/lib/libc/gen/nlist.c b/lib/libc/gen/nlist.c
index f4dae6eb32c..9a5b497b91e 100644
--- a/lib/libc/gen/nlist.c
+++ b/lib/libc/gen/nlist.c
@@ -40,7 +40,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <a.out.h>             /* pulls in nlist.h */
-#include <elf_abi.h>
+#include <elf.h>
 
 #define MINIMUM(a, b)  (((a) < (b)) ? (a) : (b))
 
diff --git a/libexec/ld.so/amd64/archdep.h b/libexec/ld.so/amd64/archdep.h
index 0b1f8e3fd05..a025b5c46a3 100644
--- a/libexec/ld.so/amd64/archdep.h
+++ b/libexec/ld.so/amd64/archdep.h
@@ -33,7 +33,7 @@
 
 #define        MACHID  EM_AMD64        /* ELF e_machine ID value checked */
 
-#include <elf_abi.h>
+#include <elf.h>
 #include <machine/reloc.h>
 #include "syscall.h"
 #include "util.h"
diff --git a/libexec/ld.so/ldd/ldd.c b/libexec/ld.so/ldd/ldd.c
index 5ebbe62cce3..e8aa5f2572a 100644
--- a/libexec/ld.so/ldd/ldd.c
+++ b/libexec/ld.so/ldd/ldd.c
@@ -26,7 +26,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <elf_abi.h>
+#include <elf.h>
 #include <err.h>
 #include <fcntl.h>
 #include <string.h>
diff --git a/sys/ddb/db_dwarf.c b/sys/ddb/db_dwarf.c
index 5956d602664..f10900ce037 100644
--- a/sys/ddb/db_dwarf.c
+++ b/sys/ddb/db_dwarf.c
@@ -397,7 +397,7 @@ next:
 #include <sys/endian.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
-#include <elf_abi.h>
+#include <elf.h>
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/sys/sys/exec_elf.h b/sys/sys/exec_elf.h
index 77c13a0372c..66ecfc8e30b 100644
--- a/sys/sys/exec_elf.h
+++ b/sys/sys/exec_elf.h
@@ -33,99 +33,69 @@
 #ifndef _SYS_EXEC_ELF_H_
 #define _SYS_EXEC_ELF_H_
 
-#include <sys/types.h>
 #include <machine/exec.h>
 
-typedef __uint8_t      Elf_Byte;
+/*
+ * System V Application Binary Interface - DRAFT - 10 June 2013
+ * http://www.sco.com/developers/gabi/latest/contents.html
+ */
+
+/*
+ * Introduction/Data Representation
+ * http://www.sco.com/developers/gabi/latest/ch4.intro.html
+ */
+/*
+ * 32-Bit Data Types
+ */
+
+/* typedef __uint8_t   Elf_Byte; -- not in spec! */
 
 typedef __uint32_t     Elf32_Addr;     /* Unsigned program address */
 typedef __uint32_t     Elf32_Off;      /* Unsigned file offset */
-typedef __int32_t      Elf32_Sword;    /* Signed large integer */
-typedef __uint32_t     Elf32_Word;     /* Unsigned large integer */
 typedef __uint16_t     Elf32_Half;     /* Unsigned medium integer */
+typedef __uint32_t     Elf32_Word;     /* Unsigned large integer */
+typedef __int32_t      Elf32_Sword;    /* Signed large integer */
+/* spec also counts with `unsigned char' being 1 byte long with
+   1 byte alignment as an unsigned small integer */
 
-typedef __uint64_t     Elf64_Addr;
-typedef __uint64_t     Elf64_Off;
-typedef __int32_t      Elf64_Shalf;
+/*
+ * 64-Bit Data Types
+ */
 
+typedef __uint64_t     Elf64_Addr;     /* Unsigned program address */
+typedef __uint64_t     Elf64_Off;      /* Unsigned file offset */
+typedef __uint16_t     Elf64_Half;     /* Unsigned medium integer */
+/* typedef __int32_t   Elf64_Shalf; -- not in spec! */
+/* alpha definition is not in spec!
 #ifdef __alpha__
-typedef __int64_t      Elf64_Sword;
 typedef __uint64_t     Elf64_Word;
-#else
-typedef __int32_t      Elf64_Sword;
-typedef __uint32_t     Elf64_Word;
-#endif
-
-typedef __int64_t      Elf64_Sxword;
-typedef __uint64_t     Elf64_Xword;
-
+typedef __int64_t      Elf64_Sword;
+#else */
+typedef __uint32_t     Elf64_Word;     /* Unsigned integer */
+typedef __int32_t      Elf64_Sword;    /* Signed integer */
+/* #endif */
+typedef __uint64_t     Elf64_Xword;    /* Unsigned long integer */
+typedef __int64_t      Elf64_Sxword;   /* Signed long integer */
+
+/* incorrect width with regarding to spec (Elf64_Half)
+   and not in spec at all (Elf64_Quarter)
 typedef __uint32_t     Elf64_Half;
 typedef __uint16_t     Elf64_Quarter;
+*/
+/* spec also counts with `unsigned char' being 1 byte long with
+   1 byte alignment as an unsigned small integer */
 
 /*
- * e_ident[] identification indexes
- * See http://www.sco.com/developers/gabi/latest/ch4.eheader.html
+ * ELF Header
+ * http://www.sco.com/developers/gabi/latest/ch4.eheader.html
  */
-#define EI_MAG0                0               /* file ID */
-#define EI_MAG1                1               /* file ID */
-#define EI_MAG2                2               /* file ID */
-#define EI_MAG3                3               /* file ID */
-#define EI_CLASS       4               /* file class */
-#define EI_DATA                5               /* data encoding */
-#define EI_VERSION     6               /* ELF header version */
-#define EI_OSABI       7               /* OS/ABI ID */
-#define EI_ABIVERSION  8               /* ABI version */
-#define EI_PAD         9               /* start of pad bytes */
-#define EI_NIDENT      16              /* Size of e_ident[] */
-
-/* e_ident[] magic number */
-#define        ELFMAG0         0x7f            /* e_ident[EI_MAG0] */
-#define        ELFMAG1         'E'             /* e_ident[EI_MAG1] */
-#define        ELFMAG2         'L'             /* e_ident[EI_MAG2] */
-#define        ELFMAG3         'F'             /* e_ident[EI_MAG3] */
-#define        ELFMAG          "\177ELF"       /* magic */
-#define        SELFMAG         4               /* size of magic */
-
-/* e_ident[] file class */
-#define        ELFCLASSNONE    0               /* invalid */
-#define        ELFCLASS32      1               /* 32-bit objs */
-#define        ELFCLASS64      2               /* 64-bit objs */
-#define        ELFCLASSNUM     3               /* number of classes */
-
-/* e_ident[] data encoding */
-#define ELFDATANONE    0               /* invalid */
-#define ELFDATA2LSB    1               /* Little-Endian */
-#define ELFDATA2MSB    2               /* Big-Endian */
-#define ELFDATANUM     3               /* number of data encode defines */
 
-/* e_ident[] Operating System/ABI */
-#define ELFOSABI_SYSV          0       /* UNIX System V ABI */
-#define ELFOSABI_HPUX          1       /* HP-UX operating system */
-#define ELFOSABI_NETBSD                2       /* NetBSD */
-#define ELFOSABI_LINUX         3       /* GNU/Linux */
-#define ELFOSABI_HURD          4       /* GNU/Hurd */
-#define ELFOSABI_86OPEN                5       /* 86Open common IA32 ABI */
-#define ELFOSABI_SOLARIS       6       /* Solaris */
-#define ELFOSABI_MONTEREY      7       /* Monterey */
-#define ELFOSABI_IRIX          8       /* IRIX */
-#define ELFOSABI_FREEBSD       9       /* FreeBSD */
-#define ELFOSABI_TRU64         10      /* TRU64 UNIX */
-#define ELFOSABI_MODESTO       11      /* Novell Modesto */
-#define ELFOSABI_OPENBSD       12      /* OpenBSD */
-#define ELFOSABI_ARM           97      /* ARM */
-#define ELFOSABI_STANDALONE    255     /* Standalone (embedded) application */
-
-/* e_ident */
-#define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \
-                      (ehdr).e_ident[EI_MAG1] == ELFMAG1 && \
-                      (ehdr).e_ident[EI_MAG2] == ELFMAG2 && \
-                      (ehdr).e_ident[EI_MAG3] == ELFMAG3)
+#define EI_NIDENT      16              /* Size of e_ident[] */
 
-/* ELF Header */
-typedef struct elfhdr {
+typedef struct {
        unsigned char   e_ident[EI_NIDENT]; /* ELF Identification */
        Elf32_Half      e_type;         /* object file type */
-       Elf32_Half      e_machine;      /* machine */
+       Elf32_Half      e_machine;      /* machine type */
        Elf32_Word      e_version;      /* object file version */
        Elf32_Addr      e_entry;        /* virtual entry point */
        Elf32_Off       e_phoff;        /* program header table offset */
@@ -141,70 +111,394 @@ typedef struct elfhdr {
 } Elf32_Ehdr;
 
 typedef struct {
-       unsigned char   e_ident[EI_NIDENT];     /* Id bytes */
-       Elf64_Quarter   e_type;                 /* file type */
-       Elf64_Quarter   e_machine;              /* machine type */
-       Elf64_Half      e_version;              /* version number */
+       unsigned char   e_ident[EI_NIDENT];     /* ELF Identification */
+       Elf64_Half      e_type;                 /* object file type */
+       Elf64_Half      e_machine;              /* machine type */
+       Elf64_Word      e_version;              /* object file version */
        Elf64_Addr      e_entry;                /* entry point */
        Elf64_Off       e_phoff;                /* Program hdr offset */
        Elf64_Off       e_shoff;                /* Section hdr offset */
-       Elf64_Half      e_flags;                /* Processor flags */
-       Elf64_Quarter   e_ehsize;               /* sizeof ehdr */
-       Elf64_Quarter   e_phentsize;            /* Program header entry size */
-       Elf64_Quarter   e_phnum;                /* Number of program headers */
-       Elf64_Quarter   e_shentsize;            /* Section header entry size */
-       Elf64_Quarter   e_shnum;                /* Number of section headers */
-       Elf64_Quarter   e_shstrndx;             /* String table index */
+       Elf64_Word      e_flags;                /* Processor flags */
+       Elf64_Half      e_ehsize;               /* sizeof ehdr */
+       Elf64_Half      e_phentsize;            /* Program header entry size */
+       Elf64_Half      e_phnum;                /* Number of program headers */
+       Elf64_Half      e_shentsize;            /* Section header entry size */
+       Elf64_Half      e_shnum;                /* Number of section headers */
+       Elf64_Half      e_shstrndx;             /* String table index */
 } Elf64_Ehdr;
 
-/* e_type */
+/* e_type  -- This member identifies the object file type. */
 #define ET_NONE                0               /* No file type */
 #define ET_REL         1               /* relocatable file */
 #define ET_EXEC                2               /* executable file */
 #define ET_DYN         3               /* shared object file */
 #define ET_CORE                4               /* core file */
-#define ET_NUM         5               /* number of types */
-#define ET_LOPROC      0xff00          /* reserved range for processor */
-#define ET_HIPROC      0xffff          /*  specific e_type */
-
-/* e_machine */
+/* #define ET_NUM              5*/             /* number of types */ /*-- not 
in spec! */
+#define ET_LOOS                0xfe00          /* operating system specific */
+#define ET_HIOS                0xfeff          /* operating system specific */
+#define ET_LOPROC      0xff00          /* processor specific */
+#define ET_HIPROC      0xffff          /* processor specific */
+
+/* e_machine  -- This member's value specifies the required architecture
+   for an individual file. */
 #define EM_NONE                0               /* No Machine */
 #define EM_M32         1               /* AT&T WE 32100 */
 #define EM_SPARC       2               /* SPARC */
 #define EM_386         3               /* Intel 80386 */
 #define EM_68K         4               /* Motorola 68000 */
 #define EM_88K         5               /* Motorola 88000 */
-#define EM_486         6               /* Intel 80486 - unused? */
+#define EM_IAMCU       6               /* Intel MCU */
 #define EM_860         7               /* Intel 80860 */
-#define EM_MIPS                8               /* MIPS R3000 Big-Endian only */
-/*
- * Don't know if EM_MIPS_RS4_BE,
- * EM_SPARC64, EM_PARISC,
- * or EM_PPC are ABI compliant
- */
-#define EM_MIPS_RS4_BE 10              /* MIPS R4000 Big-Endian */
-#define EM_SPARC64     11              /* SPARC v9 64-bit unofficial */
+#define EM_MIPS                8               /* MIPS I Architecture
+                                          (R3000 Big-Endian only) */
+#define        EM_S370         9               /* IBM System/370 Processor */
+#define EM_MIPS_RS3_LE 10              /* MIPS R3000 Little-Endian */
+       /* 11 - 14 reserved for future use */
 #define EM_PARISC      15              /* HPPA */
+       /* 16 reserved for future use */
+#define        EM_VPP500       17              /* Fujitsu VPP500 */
 #define EM_SPARC32PLUS 18              /* Enhanced instruction set SPARC */
+#define EM_960         19              /* Intel 960 */
 #define EM_PPC         20              /* PowerPC */
-#define EM_ARM         40              /* Advanced RISC Machines ARM */
+#define EM_PPC64       21              /* PowerPC 64 */
+#define EM_S390                22              /* IBM System/390 Processor */
+#define EM_SPU         23              /* IBM SPU/SPC */
+       /* 24 - 35 reserved for future use */
+#define EM_V800                36              /* NEC V800 */
+#define EM_FR20                37              /* Fujitsu FR20 */
+#define EM_RH32                38              /* TRW RH-32 */
+#define EM_RCE         39              /* Motorola RCE */
+#define EM_ARM         40              /* ARM 32-bit architecture (AARCH32) */
 #define EM_ALPHA       41              /* DEC ALPHA */
 #define        EM_SH           42              /* Hitachi/Renesas Super-H */
 #define EM_SPARCV9     43              /* SPARC version 9 */
+#define EM_TRICORE     44              /* Siemens TriCore embedded processor */
+#define EM_ARC         45              /* Argonaut RISC Core,
+                                          Argonaut Technologies Inc. */
+#define        EM_H8_300       46              /* Hitachi H8/300 */
+#define EM_H8_300H     47              /* Hitachi H8/300H */
+#define EM_H8S         48              /* Hitachi H8S */
+#define EM_H8_500      49              /* Hitachi H8/500 */
 #define EM_IA_64       50              /* Intel IA-64 Processor */
-#define EM_AMD64       62              /* AMD64 architecture */
+#define EM_MIPS_X      51              /* Stanford MIPS-X */
+#define EM_COLDFIRE    52              /* Motorola ColdFire */
+#define EM_68HC12      53              /* Motorola H68HC12 */
+#define EM_MMA         54              /* Fujitsu MMA Multimedia Accelerator */
+#define EM_PCP         55              /* Siemens PCP */
+#define EM_NCPU                56              /* Sony nCPU embedded RISC 
processor */
+#define EM_NDR1                57              /* Denso NDR1 microprocessor */
+#define EM_STARCORE    58              /* Motorola Star*Core processor */
+#define EM_ME16                59              /* Toyota ME16 processor */
+#define EM_ST100       60              /* STMicroelectronics ST100 processor */
+#define EM_TINYJ       61              /* Advanced Logic Corp. TineJ
+                                          embedded processor family */
+#define EM_X86_64      62              /* AMD x86-64 architecture */
+#define EM_DPSP                63              /* Sony DSP Processor */
+#define EM_PDP10       64              /* Digital Equipment Corp. PDP-10 */
+#define EM_PDP11       65              /* Digital Equipment Corp. PDP-11 */
+#define EM_FX66                66              /* Siemens FX66 microcontroller 
*/
+#define EM_ST9PLUS     67              /* STMicroelectronics ST9+
+                                          8/16 bit microcontroller */
+#define EM_ST7         68              /* STMicroelectronics ST7
+                                          8-bit microcontroller */
+#define        EM_68HC16       69              /* Motorola MC68HC16 
Microcontroller */
+#define        EM_68HC11       70              /* Motorola MC68HC11 
Microcontroller */
+#define        EM_68HC08       71              /* Motorola MC68HC08 
Microcontroller */
+#define        EM_68HC05       72              /* Motorola MC68HC05 
Microcontroller */
+#define        EM_SVX          73              /* Silicon Graphics SVx */
+#define        EM_ST19         74              /* STMicroelectronics ST19
+                                          8-bit microcontroller */
 #define EM_VAX         75              /* DEC VAX */
-#define EM_AARCH64     183             /* ARM 64-bit architecture (AArch64) */
+#define        EM_CRIS         76              /* Axis Communications
+                                          32-bit embedded processor */
+#define        EM_JAVELIN      77              /* Infineon Technologies
+                                          32-bit embedded processor */
+#define EM_FIREPATH    78              /* Element 14 64-bit DSP Processor */
+#define        EM_ZSP          79              /* LSI Logic 16-bit DSP 
Processor */
+#define        EM_MMIX         80              /* Donald Knuth's educational
+                                          64-bit processor */
+#define        EM_HUANY        81              /* Harvard Uni. 
machine-independent
+                                          object files */
+#define        EM_PRISM        82              /* SiTera Prism */
+#define        EM_AVR          83              /* Atmel AVR 8-bit 
microcontroller */
+#define        EM_FR30         84              /* Fujitsu FR30 */
+#define        EM_D10V         85              /* Mitsubishi D10V */
+#define        EM_D30V         86              /* Mitsubishi D30V */
+#define        EM_V850         87              /* NEC v850 */
+#define        EM_M32R         88              /* Mitsubishi M32R */
+#define        EM_MN10300      89              /* Matsushita MN10300 */
+#define        EM_MN10200      90              /* Matsushita MN10200 */
+#define        EM_PJ           91              /* picoJava */
+#define        EM_OPENRISC     92              /* OpenRISC 32-bit embedded 
processor */
+#define        EM_ARC_COMPACT  93              /* ARC International ARCompact 
processor
+                                          (old spelling/synonym: EM_ARC_A5) */
+#define        EM_XTENSA       94              /* Tensilica Xtensa 
Architecture */
+#define        EM_VIDEOCORE    95              /* Alphamosaic VideoCore 
processor */
+#define        EM_TMM_GPP      96              /* Thompson Multimedia General 
Purpose
+                                          Processor */
+#define        EM_NS32K        97              /* National Semiconductor 32000 
series*/
+#define        EM_TPC          98              /* Tenor Network TPC processor 
*/
+#define        EM_SNP1K        99              /* Trebia SNP 1000 processor */
+#define        EM_ST200        100             /* STMicroelectronics ST200
+                                          microcontroller */
+#define        EM_IP2K         101             /* Ubicom IP2xxx microcontroller
+                                          family */
+#define        EM_MAX          102             /* MAX Processor */
+#define        EM_CR           103             /* National Semiconductor 
CompactRISC
+                                          microprocessor */
+#define        EM_F2MC16       104             /* Fujitsu F2MC16 */
+#define        EM_MSP430       105             /* Texas Instruments embedded
+                                          microcontroller msp430 */
+#define        EM_BLACKFIN     106             /* Analog Devices Blackfin (DSP)
+                                          processor */
+#define        EM_SE_C33       107             /* S1C33 Family of Seiko Epson
+                                          processors */
+#define        EM_SEP          108             /* Sharp embedded 
microprocessor */
+#define        EM_ARCA         109             /* Arca RISC Microprocessor */
+#define        EM_UNICORE      110             /* Microprocessor series from 
PKU-Unity
+                                          Ltd. and MPRC of Peking University */
+#define        EM_EXCESS       111             /* eXcess: 16/32/64-bit 
configurable
+                                          embedded CPU */
+#define EM_DXP         112             /* Icera Semiconductor Inc. Deep
+                                          Execution Processor */
+#define EM_ALTERA_NIOS2        113             /* Altera Nios II soft-core 
processor */
+#define EM_CRX         114             /* National Semiconductor CompactRISC
+                                          CRX microprocessor */
+#define EM_XGATE       115             /* Motorola XGATE embedded processor */
+#define EM_C166                116             /* Infineon C16x/XC16x 
processor */
+#define EM_M16C                117             /* Renesas M16C series 
microprocessors*/
+#define EM_DSPIC30F    118             /* Microchip Technology dsPIC30F
+                                          Digital Signal Controller */
+#define EM_CE          119             /* Freescale Communication Engine RISC
+                                          core */
+#define EM_M32C                120             /* Renesas M32C series 
microprocessors*/
+       /* 121-130 Reserved for future use */
+#define EM_TSK3000     131             /* Altium TSK3000 core */
+#define EM_RS08                132             /* Freescale RS08 embedded 
processor */
+#define EM_SHARC       133             /* Analog Devices SHARC family
+                                          of 32-bit DSP processors */
+#define EM_ECOG2       134             /*Cyan Technology eCOG2 microprocessor*/
+#define EM_SCORE7      135             /* Sunplus S+core7 RISC processor */
+#define EM_DSP24       136             /* New Japan Radio (NJR) 24-bit DSP
+                                          Processor */
+#define EM_VIDEOCORE3  137             /* Broadcom VideoCore III processor */
+#define EM_LATTICEMICO32       138     /* RISC processor for Lattice FPGA
+                                          architecture */
+#define EM_SE_C17      139             /* Seiko Epson C17 family */
+#define EM_TI_C6000    140             /* The Texas Instruments TMS320C6000 DSP
+                                          family */
+#define EM_TI_C2000    141             /* The Texas Instruments TMS320C2000 DSP
+                                          family */
+#define EM_TI_C5500    142             /* The Texas Instruments TMS320C55x DSP
+                                          family */
+#define EM_TI_ARP32    143             /* Texas Instruments Application
+                                          Specific RISC Processor,32bit fetch*/
+#define EM_TI_PRU      144             /* Texas Instruments Programmable
+                                          Realtime Unit */
+       /* 145-159 Reserved for future use */
+#define EM_MMDSP_PLUS  160             /* STMicroelectronics 64bit VLIW Data
+                                          Signal Processor */
+#define EM_CYPRESS_M8C 161             /* Cypress M8C microprocessor */
+#define EM_R32C                162             /* Renesas R32C series 
microprocessors*/
+#define EM_TRIMEDIA    163             /* NXP Semiconductors TriMedia
+                                          architecture family */
+#define EM_QDSP6       164             /* QUALCOMM DSP6 Processor */
+#define EM_8051                165             /* Intel 8051 and variants */
+#define EM_STXP7X      166             /* STMicroelectronics STxP7x family
+                                          of configurable and extensible RISC
+                                          processors */
+#define EM_NDS32       167             /* Andes Technology compact code size
+                                          embedded RISC processor family */
+#define EM_ECOG1       168             /* Cyan Technology eCOG1X family */
+#define EM_ECOG1X      168             /* Cyan Technology eCOG1X family */
+#define EM_MAXQ30      169             /* Dallas Semiconductor MAXQ30 Core
+                                          Micro-controllers */
+#define EM_XIMO16      170             /* New Japan Radio (NJR) 16-bit DSP
+                                          Processor */
+#define EM_MANIK       171             /* M2000 Reconfigurable RISC
+                                          Microprocessor */
+#define EM_CRAYNV2     172             /* Cray Inc. NV2 vector architecture */
+#define EM_RX          173             /* Renesas RX family */
+#define EM_METAG       174             /* Imagination Technologies META
+                                          processor architecture */
+#define EM_MCST_ELBRUS 175             /* MCST Elbrus general purpose hardware
+                                          architecture */
+#define        EM_ECOG16       176             /* Cyan Technology eCOG16 
family */
+#define        EM_CR16         177             /* National Semiconductor 
CompactRISC
+                                          CR16 16-bit microprocessor */
+#define        EM_ETPU         178             /* Freescale Extended Time 
Processing
+                                          Unit */
+#define        EM_SLE9X        179             /* Infineon Technologies SLE9X 
core */
+#define        EM_L10M         180             /* Intel L10M */
+#define        EM_K10M         181             /* Intel K10M */
+       /* 182 Reserved for future Intel use */
+#define        EM_AARCH64      183             /* ARM 64-bit architecture 
(AARCH64) */
+       /* 184 Reserved for future ARM use */
+#define        EM_AVR32        185             /* Atmel Corporation 32-bit
+                                          microprocessor family */
+#define        EM_STM8         186             /* STMicroeletronics STM8 8-bit
+                                          microcontroller */
+#define        EM_TILE64       187             /* Tilera TILE64 multicore 
architecture
+                                          family */
+#define        EM_TILEPRO      188             /* Tilera TILEPro multicore
+                                          architecture family */
+#define        EM_MICROBLAZE   189             /* Xilinx MicroBlaze 32-bit 
RISC soft
+                                          processor core */
+#define        EM_CUDA         190             /* NVIDIA CUDA architecture */
+#define        EM_TILEGX       191             /* Tilera TILE-Gx multicore
+                                          architecture family */
+#define        EM_CLOUDSHIELD  192             /* CloudShield architecture 
family */
+#define        EM_COREA_1ST    193             /* KIPO-KAIST Core-A 1st 
generation
+                                          processor family */
+#define        EM_COREA_2ND    194             /* KIPO-KAIST Core-A 2nd 
generation
+                                          processor family */
+#define        EM_ARC_COMPACT2 195             /* Synopsys ARCompact V2 */
+#define        EM_OPEN8        196             /* Open8 8-bit RISC soft 
processor
+                                          core */
+#define        EM_RL78         197             /* Renesas RL78 family */
+#define        EM_VIDEOCORE5   198             /* Broadcom VideoCore V 
processor */
+#define        EM_78KOR        199             /* Renesas 78KOR family */
+#define        EM_56800EX      200             /* Freescale 56800EX Digital 
Signal
+                                          Controller (DSC) */
+#define        EM_BA1          201             /* Beyond BA1 CPU architecture 
*/
+#define        EM_BA2          202             /* Beyond BA2 CPU architecture 
*/
+#define        EM_XCORE        203             /* XMOS xCORE processor family 
*/
+#define        EM_MCHP_PIC     204             /* Microchip 8-bit PIC(r) 
family */
+#define        EM_INTEL205     205             /* Reserved by Intel */
+#define        EM_INTEL206     206             /* Reserved by Intel */
+#define        EM_INTEL207     207             /* Reserved by Intel */
+#define        EM_INTEL208     208             /* Reserved by Intel */
+#define        EM_INTEL209     209             /* Reserved by Intel */
+#define        EM_KM32         210             /* KM211 KM32 32-bit processor 
*/
+#define        EM_KMX32        211             /* KM211 KMX32 32-bit processor 
*/
+#define        EM_KMX16        212             /* KM211 KMX16 16-bit processor 
*/
+#define        EM_KMX8         213             /* KM211 KMX8 8-bit processor */
+#define        EM_KVARC        214             /* KM211 KVARC processor */
+#define        EM_CDP          215             /* Paneve CDP architecture 
family */
+#define        EM_COGE         216             /* Cognitive Smart Memory 
Processor */
+#define        EM_COOL         217             /* Bluechip Systems CoolEngine 
*/
+#define        EM_NORC         218             /* Nanoradio Optimized RISC */
+#define        EM_CSR_KALIMBA  219             /* CSR Kalimba architecture 
family */
+#define        EM_Z80          220             /* Zilog Z80 */
+#define        EM_VISIUM       221             /* Controls and Data Services
+                                          VISIUMcore processor */
+#define        EM_FT32         222             /* FTDI Chip FT32 high 
performance
+                                          32-bit RISC architecture */
+#define        EM_MOXIE        223             /* Moxie processor family */
+#define        EM_AMDGPU       224             /* AMD GPU architecture */
+       /* 225 - 242 */
+#define        EM_RISCV        243             /* RISC-V */
 
 /* Non-standard */
-#define EM_ALPHA_EXP   0x9026          /* DEC ALPHA */
+/* not in spec! */
+/* #define EM_ALPHA_EXP        0x9026*/                /* DEC ALPHA */
+/* not in spec! */
+/* #define EM_NUM              22*/            /* number of machine types */
 
-#define EM_NUM         22              /* number of machine types */
+/* e_version -- This member identifies the object file version. */
+#define EV_NONE                0               /* Invalid */
+#define EV_CURRENT     1               /* Current */
+/* not in spec!
+#define EV_NUM         2*/             /* number of versions */
 
-/* Version */
+/*
+ * ELF Indentification
+ */
+/*
+ * e_ident[] identification indexes
+ */
+#define EI_MAG0                0               /* file ID */
+#define EI_MAG1                1               /* file ID */
+#define EI_MAG2                2               /* file ID */
+#define EI_MAG3                3               /* file ID */
+#define EI_CLASS       4               /* file class */
+#define EI_DATA                5               /* data encoding */
+#define EI_VERSION     6               /* ELF header version */
+#define EI_OSABI       7               /* OS/ABI ID */
+#define EI_ABIVERSION  8               /* ABI version */
+#define EI_PAD         9               /* start of pad bytes */
+/* there is also EI_NIDENT 16 defined here, but it's moved up
+   to make ELF header code compilable */
+
+/* e_ident[] magic number */
+#define        ELFMAG0         0x7f            /* e_ident[EI_MAG0] */
+#define        ELFMAG1         'E'             /* e_ident[EI_MAG1] */
+#define        ELFMAG2         'L'             /* e_ident[EI_MAG2] */
+#define        ELFMAG3         'F'             /* e_ident[EI_MAG3] */
+/* not in spec!
+#define        ELFMAG          "\177ELF"*/     /* magic */
+/* not in spec!
+#define        SELFMAG         4*/             /* size of magic */
+
+/* e_ident[] file class */
+#define        ELFCLASSNONE    0               /* invalid */
+#define        ELFCLASS32      1               /* 32-bit objs */
+#define        ELFCLASS64      2               /* 64-bit objs */
+/* not in spec!
+#define        ELFCLASSNUM     3*/             /* number of classes */
+
+/* e_ident[] data encoding */
+#define ELFDATANONE    0               /* invalid */
+#define ELFDATA2LSB    1               /* Little-Endian */
+#define ELFDATA2MSB    2               /* Big-Endian */
+/* not in spec!
+#define ELFDATANUM     3*/             /* number of data encode defines */
+
+/* e_ident[] Operating System/ABI */
+#define ELFOSABI_SYSV          0       /* UNIX System V ABI */
+#define ELFOSABI_HPUX          1       /* HP-UX operating system */
+#define ELFOSABI_NETBSD                2       /* NetBSD */
+#define ELFOSABI_GNU           3       /* GNU */
+#define ELFOSABI_LINUX         3       /* Linux  historical - alias
+                                          for ELFOSABI_GNU */
+/* not in spec!
+#define ELFOSABI_HURD          4*/     /* GNU/Hurd */
+/* not in spec!
+#define ELFOSABI_86OPEN                5*/     /* 86Open common IA32 ABI */
+#define ELFOSABI_SOLARIS       6       /* Solaris */
+#define ELFOSABI_AIX           7       /* AIX */
+#define ELFOSABI_IRIX          8       /* IRIX */
+#define ELFOSABI_FREEBSD       9       /* FreeBSD */
+#define ELFOSABI_TRU64         10      /* TRU64 UNIX */
+#define ELFOSABI_MODESTO       11      /* Novell Modesto */
+#define ELFOSABI_OPENBSD       12      /* OpenBSD */
+#define ELFOSABI_OPENVMS       13      /* OpenVMS */
+#define ELFOSABI_NSK           14      /* HP Non-Stop Kernel */
+#define ELFOSABI_AROS          15      /* Amiga Research OS */
+#define ELFOSABI_FENIXOS       16      /* The FenixOS highly scalable
+                                          multi-core OS */
+#define ELFOSABI_CLOUDABI      17      /* Nuxi CloudABI */
+#define ELFOSABI_OPENVOS       18      /* Stratus Technologies OpenVOS */
+       /* 64 - 255 Architecture-specific value range */
+/* not in spec!
+#define ELFOSABI_ARM           97*/    /* ARM */
+/* not in spec!
+#define ELFOSABI_STANDALONE    255*/   /* Standalone (embedded) application */
+
+/* e_version This member identifies the object file version. */
 #define EV_NONE                0               /* Invalid */
 #define EV_CURRENT     1               /* Current */
-#define EV_NUM         2               /* number of versions */
+/* not in spec!
+#define EV_NUM         2*/             /* number of versions */
+
+/*
+ * Sections
+ * http://www.sco.com/developers/gabi/latest/ch4.sheader.html
+ */
+
+/* Special Section Indexes */
+#define SHN_UNDEF      0               /* undefined */
+#define SHN_LORESERVE  0xff00          /* lower bounds of reserved indexes */
+#define SHN_LOPROC     0xff00          /* reserved range for processor lowend*/
+#define SHN_HIPROC     0xff1f          /* reserved range for processor hiend*/
+#define SHN_LOOS       0xff20          /* reserved range for OS lowend */
+#define SHN_HIOS       0xff3f          /* reserved range for OS hiend */
+#define SHN_ABS                0xfff1          /* absolute value */
+#define SHN_COMMON     0xfff2          /* common symbol */
+#define SHN_XINDEX     0xffff          /* represents escape value to mark too
+                                          big index value */
+#define SHN_HIRESERVE  0xffff          /* upper bounds of reserved indexes */
+
 
 /* Section Header */
 typedef struct {
@@ -222,27 +516,18 @@ typedef struct {
 } Elf32_Shdr;
 
 typedef struct {
-       Elf64_Half      sh_name;        /* section name */
-       Elf64_Half      sh_type;        /* section type */
+       Elf64_Word      sh_name;        /* section name */
+       Elf64_Word      sh_type;        /* section type */
        Elf64_Xword     sh_flags;       /* section flags */
        Elf64_Addr      sh_addr;        /* virtual address */
        Elf64_Off       sh_offset;      /* file offset */
        Elf64_Xword     sh_size;        /* section size */
-       Elf64_Half      sh_link;        /* link to another */
-       Elf64_Half      sh_info;        /* misc info */
+       Elf64_Word      sh_link;        /* link to another */
+       Elf64_Word      sh_info;        /* misc info */
        Elf64_Xword     sh_addralign;   /* memory alignment */
        Elf64_Xword     sh_entsize;     /* table entry size */
 } Elf64_Shdr;
 
-/* Special Section Indexes */
-#define SHN_UNDEF      0               /* undefined */
-#define SHN_LORESERVE  0xff00          /* lower bounds of reserved indexes */
-#define SHN_LOPROC     0xff00          /* reserved range for processor */
-#define SHN_HIPROC     0xff1f          /*   specific section indexes */
-#define SHN_ABS                0xfff1          /* absolute value */
-#define SHN_COMMON     0xfff2          /* common symbol */
-#define SHN_HIRESERVE  0xffff          /* upper bounds of reserved indexes */
-
 /* sh_type */
 #define SHT_NULL       0               /* inactive */
 #define SHT_PROGBITS   1               /* program defined information */
@@ -256,24 +541,87 @@ typedef struct {
 #define SHT_REL                9               /* relation section without 
addends */
 #define SHT_SHLIB      10              /* reserved - purpose unknown */
 #define SHT_DYNSYM     11              /* dynamic symbol table section */
-#define SHT_NUM                12              /* number of section types */
-#define SHT_LOPROC     0x70000000      /* reserved range for processor */
-#define SHT_HIPROC     0x7fffffff      /*  specific section header types */
+#define SHT_INIT_ARRAY 14              /* pointers to init functions */
+#define SHT_FINI_ARRAY 15              /* pointers to termination functions */
+#define SHT_PREINIT_ARRAY      16      /* pointers to pre-init functions */
+#define SHT_GROUP      17              /* section group */
+#define SHT_SYMTAB_SHNDX       18      /* symbol table section */
+#define SHT_LOOS       0x60000000      /* OS specific semantics low-end */
+#define SHT_HIOS       0x6fffffff      /* OS specific semantics hi-end */
+/* not in spec!
+#define SHT_NUM                12*/            /* number of section types */
+#define SHT_LOPROC     0x70000000      /* CPU specific semantics low-end */
+#define SHT_HIPROC     0x7fffffff      /* CPU specific semantics hi-end */
 #define SHT_LOUSER     0x80000000      /* reserved range for application */
 #define SHT_HIUSER     0xffffffff      /*  specific indexes */
 
+/* sh_flags - Section Attribute Flags */
+#define SHF_WRITE      0x1             /* Writable */
+#define SHF_ALLOC      0x2             /* occupies memory */
+#define SHF_EXECINSTR  0x4             /* executable */
+#define SHF_MERGE      0x10            /* merge to eliminate duplication */
+#define SHF_STRINGS    0x20            /* null-terminated strings */
+#define SHF_INFO_LINK  0x40            /* sh_info holds section header index */
+#define SHF_LINK_ORDER 0x80            /* ordering requirements */
+#define SHF_OS_NONFONFORMING   0x100   /* OS specific processing necessary */
+#define SHF_GROUP      0x200           /* member of a section group */
+#define SHF_TLS                0x400           /* thread local storage */
+#define SHF_COMPRESSED 0x800           /* marks section with compressed data */
+#define SHF_MARKOS     0x0ff00000      /* reserved bits for OS */
+#define SHF_MASKPROC   0xf0000000      /* reserved bits for processor */
+
+/*
+ * Compression Header
+ */
+
+typedef struct {
+       Elf32_Word      ch_type;        /* compression algorithm */
+       Elf32_Word      ch_size;        /* size of uncompressed data */
+       Elf32_Word      ch_addralign;   /* required alignment for uncompressed
+                                          data */
+} Elf32_Chdr;
+
+typedef struct {
+       Elf64_Word      ch_type;        /* compression algorithm */
+       Elf64_Word      ch_reserved;
+       Elf64_Xword     ch_size;        /* size of uncompressed data */
+       Elf64_Xword     ch_addralign;   /* required alignment for uncompressed
+                                          data */
+} Elf64_Chdr;
+
+/* ch_type ELF Compression Types */
+#define        ELFCOMPRESS_ZLIB        1               /* ZLIB algorithm */
+#define ELFCOMPRESS_LOOS       0x60000000      /* OS spec. semantics low-end */
+#define ELFCOMPRESS_HIOS       0x6fffffff      /* OS spec. semantics hi-end */
+#define ELFCOMPRESS_LOPROC     0x70000000      /* CPU spec. semantics low-end*/
+#define ELFCOMPRESS_HIPROC     0x7fffffff      /* CPU spec. semantics hi-end*/
+
+
+/* Section Group Flags */
+#define        GRP_COMDAT      0x1             /* COMDAT group */
+#define GRP_MASKOS     0x0ff00000      /* OS specific semantics */
+#define GRP_MASKPROC   0xf0000000      /* Processor specific semantics */
+
+/* Special Sections -- following sections definitions ELF_* are not
+   part of the spec. Specification however defines all the sections name
+   E.g. .bss, .comment, .data etc. so I leave those defines here too. */
 /* Section names */
 #define ELF_BSS         ".bss"         /* uninitialized data */
+#define ELF_COMMENT    ".comment"      /* version control information */
 #define ELF_DATA        ".data"                /* initialized data */
-#define ELF_CTF                ".SUNW_ctf"     /* CTF data */
+#define ELF_DATA1      ".data1"        /* initialized data */
+/* not in spec!
+#define ELF_CTF                ".SUNW_ctf"*/   /* CTF data */
 #define ELF_DEBUG       ".debug"       /* debug */
 #define ELF_DYNAMIC     ".dynamic"     /* dynamic linking information */
 #define ELF_DYNSTR      ".dynstr"      /* dynamic string table */
 #define ELF_DYNSYM      ".dynsym"      /* dynamic symbol table */
 #define ELF_FINI        ".fini"                /* termination code */
+#define ELF_FINI_ARR   ".fini_array"   /* termination functions array */
 #define ELF_GOT         ".got"         /* global offset table */
 #define ELF_HASH        ".hash"                /* symbol hash table */
 #define ELF_INIT        ".init"                /* initialization code */
+#define ELF_INIT_ARR   ".init_array"   /* initialization functions array */
 #define ELF_REL_DATA    ".rel.data"    /* relocation data */
 #define ELF_REL_FINI    ".rel.fini"    /* relocation termination code */
 #define ELF_REL_INIT    ".rel.init"    /* relocation initialization code */
@@ -281,22 +629,28 @@ typedef struct {
 #define ELF_REL_RODATA  ".rel.rodata"  /* relocation read-only data */
 #define ELF_REL_TEXT    ".rel.text"    /* relocation code */
 #define ELF_RODATA      ".rodata"      /* read-only data */
+#define ELF_RODATA1    ".rodata1"      /* read-only data */
 #define ELF_SHSTRTAB    ".shstrtab"    /* section header string table */
 #define ELF_STRTAB      ".strtab"      /* string table */
 #define ELF_SYMTAB      ".symtab"      /* symbol table */
+#define ELF_SYMTAB_SHNDX       ".symtab_shndx" /* symbol table section index
+                                                  array */
+#define ELF_TBSS       ".tbss"         /* TLS uninitialized data */
+#define ELF_TDATA      ".tdata"        /* TLS initialized data */
+#define ELF_TDATA1     ".tdata1"       /* TLS initialized data */
 #define ELF_TEXT        ".text"                /* code */
 
 
-/* Section Attribute Flags - sh_flags */
-#define SHF_WRITE      0x1             /* Writable */
-#define SHF_ALLOC      0x2             /* occupies memory */
-#define SHF_EXECINSTR  0x4             /* executable */
-#define SHF_TLS                0x400           /* thread local storage */
-#define SHF_MASKPROC   0xf0000000      /* reserved bits for processor */
-                                       /*  specific section attributes */
+/*
+ * Symbol Table
+ * http://www.sco.com/developers/gabi/latest/ch4.symtab.html
+ */
+
+/* Symbol table index */
+#define STN_UNDEF      0               /* undefined */
 
 /* Symbol Table Entry */
-typedef struct elf32_sym {
+typedef struct {
        Elf32_Word      st_name;        /* name - index into string table */
        Elf32_Addr      st_value;       /* symbol value */
        Elf32_Word      st_size;        /* symbol size */
@@ -306,17 +660,14 @@ typedef struct elf32_sym {
 } Elf32_Sym;
 
 typedef struct {
-       Elf64_Half      st_name;        /* Symbol name index in str table */
-       Elf_Byte        st_info;        /* type / binding attrs */
-       Elf_Byte        st_other;       /* unused */
-       Elf64_Quarter   st_shndx;       /* section index of symbol */
-       Elf64_Xword     st_value;       /* value of symbol */
+       Elf64_Word      st_name;        /* Symbol name index in str table */
+       unsigned char   st_info;        /* type / binding attrs */
+       unsigned char   st_other;       /* unused */
+       Elf64_Half      st_shndx;       /* section index of symbol */
+       Elf64_Addr      st_value;       /* value of symbol */
        Elf64_Xword     st_size;        /* size of symbol */
 } Elf64_Sym;
 
-/* Symbol table index */
-#define STN_UNDEF      0               /* undefined */
-
 /* Extract symbol info - st_info */
 #define ELF32_ST_BIND(x)       ((x) >> 4)
 #define ELF32_ST_TYPE(x)       (((unsigned int) x) & 0xf)
@@ -326,11 +677,18 @@ typedef struct {
 #define ELF64_ST_TYPE(x)       (((unsigned int) x) & 0xf)
 #define ELF64_ST_INFO(b,t)     (((b) << 4) + ((t) & 0xf))
 
+/* Extract symbol other attribute - st_other -- used for symbol visibility */
+#define ELF32_ST_VISIBILITY(o) ((o)&0x3)
+#define ELF64_ST_VISIBILITY(o) ((o)&0x3)
+
 /* Symbol Binding - ELF32_ST_BIND - st_info */
 #define STB_LOCAL      0               /* Local symbol */
 #define STB_GLOBAL     1               /* Global symbol */
 #define STB_WEAK       2               /* like global - lower precedence */
-#define STB_NUM                3               /* number of symbol bindings */
+#define STB_LOOS       10              /* OS specific semantics low-end */
+#define STB_HIOS       12              /* OS specific semantics hi-end */
+/* not in spec!
+#define STB_NUM                3*/             /* number of symbol bindings */
 #define STB_LOPROC     13              /* reserved range for processor */
 #define STB_HIPROC     15              /*  specific symbol bindings */
 
@@ -340,10 +698,27 @@ typedef struct {
 #define STT_FUNC       2               /* function */
 #define STT_SECTION    3               /* section */
 #define STT_FILE       4               /* file */
+#define STT_COMMON     5               /* uninitialized common block */
 #define STT_TLS                6               /* thread local storage */
+#define STT_LOOS       10              /* reserved range for OS */
+#define STT_HIOS       12              /*  specific symbol types */
 #define STT_LOPROC     13              /* reserved range for processor */
 #define STT_HIPROC     15              /*  specific symbol types */
 
+/* Symbol Visibility */
+#define STV_DEFAULT    0               /* default visibility for given symbol's
+                                          binding type: global & weak are
+                                          visible. Locals are hidden */
+#define STV_INTERNAL   1               /* Visibility of this type is defined
+                                          by processor supplement(s) */
+#define STV_HIDDEN     2               /* not visible symbol */
+#define STV_PROTECTED  3               /* visible but not preemptable symbol */
+
+/*
+ * Relocation
+ * http://www.sco.com/developers/gabi/latest/ch4.reloc.html
+ */
+
 /* Relocation entry with implicit addend */
 typedef struct {
        Elf32_Addr      r_offset;       /* offset of relocation */
@@ -357,26 +732,28 @@ typedef struct {
        Elf32_Sword     r_addend;
 } Elf32_Rela;
 
-/* Extract relocation info - r_info */
-#define ELF32_R_SYM(i)         ((i) >> 8)
-#define ELF32_R_TYPE(i)                ((unsigned char) (i))
-#define ELF32_R_INFO(s,t)      (((s) << 8) + (unsigned char)(t))
-
 typedef struct {
-       Elf64_Xword     r_offset;       /* where to do it */
+       Elf64_Addr      r_offset;       /* where to do it */
        Elf64_Xword     r_info;         /* index & type of relocation */
 } Elf64_Rel;
 
 typedef struct {
-       Elf64_Xword     r_offset;       /* where to do it */
+       Elf64_Addr      r_offset;       /* where to do it */
        Elf64_Xword     r_info;         /* index & type of relocation */
        Elf64_Sxword    r_addend;       /* adjustment value */
 } Elf64_Rela;
 
+/* Extract relocation info - r_info */
+#define ELF32_R_SYM(i)         ((i) >> 8)
+#define ELF32_R_TYPE(i)                ((unsigned char) (i))
+#define ELF32_R_INFO(s,t)      (((s) << 8) + (unsigned char)(t))
+
 #define        ELF64_R_SYM(info)       ((info) >> 32)
 #define        ELF64_R_TYPE(info)      ((info) & 0xFFFFFFFF)
-#define ELF64_R_INFO(s,t)      (((s) << 32) + (__uint32_t)(t))
+#define ELF64_R_INFO(s,t)      (((s) << 32) + (__uint32_t)((t)&0xFFFFFFFF))
 
+/* spec allows processor specific relocation types to be added. As this is
+   allowed, let's keep those here inside the spec. stuff */
 #if defined(__mips64__) && defined(__MIPSEL__)
 /*
  * The 64-bit MIPS ELF ABI uses a slightly different relocation format
@@ -391,6 +768,10 @@ typedef struct {
 #define        ELF64_R_INFO(s,t)       (((__uint64_t)swap32(t) << 32) + 
(__uint32_t)(s))
 #endif /* __mips64__ && __MIPSEL__ */
 
+/*
+ * Program Header
+ * http://www.sco.com/developers/gabi/latest/ch5.pheader.html
+ */
 /* Program Header */
 typedef struct {
        Elf32_Word      p_type;         /* segment type */
@@ -404,8 +785,8 @@ typedef struct {
 } Elf32_Phdr;
 
 typedef struct {
-       Elf64_Half      p_type;         /* entry type */
-       Elf64_Half      p_flags;        /* flags */
+       Elf64_Word      p_type;         /* entry type */
+       Elf64_Word      p_flags;        /* flags */
        Elf64_Off       p_offset;       /* offset */
        Elf64_Addr      p_vaddr;        /* virtual address */
        Elf64_Addr      p_paddr;        /* physical address */
@@ -428,19 +809,17 @@ typedef struct {
 #define PT_LOPROC      0x70000000      /* reserved range for processor */
 #define PT_HIPROC      0x7fffffff      /*  specific segment types */
 
-#define PT_GNU_EH_FRAME                0x6474e550      /* Exception handling 
info */
-#define PT_GNU_RELRO           0x6474e552      /* Read-only after relocation */
-
-#define PT_OPENBSD_RANDOMIZE   0x65a3dbe6      /* fill with random data */
-#define PT_OPENBSD_WXNEEDED    0x65a3dbe7      /* program performs W^X 
violations */
-#define PT_OPENBSD_BOOTDATA    0x65a41be6      /* section for boot arguments */
-
 /* Segment flags - p_flags */
 #define PF_X           0x1             /* Executable */
 #define PF_W           0x2             /* Writable */
 #define PF_R           0x4             /* Readable */
+#define PF_MASKOS      0x0ff00000      /* OS specific semantics */
 #define PF_MASKPROC    0xf0000000      /* reserved bits for processor */
                                        /*  specific segment flags */
+/*
+ * Dynamic Linking
+ * http://www.sco.com/developers/gabi/latest/ch5.dynamic.html
+ */
 
 /* Dynamic structure */
 typedef struct {
@@ -451,14 +830,25 @@ typedef struct {
        } d_un;
 } Elf32_Dyn;
 
+/* spec also defines here:
+   extern Elf32_Dyn    _DYNAMIC[];
+   symbol, but this is defined below using Elf_Dyn to avoid name clash
+   with 64bit _DYNAMIC[] */
+
 typedef struct {
-       Elf64_Xword     d_tag;          /* controls meaning of d_val */
+       Elf64_Sxword    d_tag;          /* controls meaning of d_val */
        union {
-               Elf64_Addr      d_ptr;
                Elf64_Xword     d_val;
+               Elf64_Addr      d_ptr;
        } d_un;
 } Elf64_Dyn;
 
+/* spec also defines here:
+   extern Elf64_Dyn    _DYNAMIC[];
+   symbol, but this is defined below using Elf_Dyn to avoid name clash
+   with 32bit _DYNAMIC[] */
+
+
 /* Dynamic Array Tags - d_tag */
 #define DT_NULL                0               /* marks end of _DYNAMIC array 
*/
 #define DT_NEEDED      1               /* string table offset of needed lib */
@@ -495,16 +885,12 @@ typedef struct {
 #define DT_ENCODING    31              /* further DT_* follow encoding rules */
 #define DT_PREINIT_ARRAY       32      /* address of array of preinit func */
 #define DT_PREINIT_ARRAYSZ     33      /* size of array of preinit func */
+#define DT_SYMTAB_SHNDX        34              /* address of symtab section */
 #define DT_LOOS                0x6000000d      /* reserved range for OS */
 #define DT_HIOS                0x6ffff000      /*  specific dynamic array tags 
*/
 #define DT_LOPROC      0x70000000      /* reserved range for processor */
 #define DT_HIPROC      0x7fffffff      /*  specific dynamic array tags */
 
-/* some other useful tags */
-#define DT_RELACOUNT   0x6ffffff9      /* if present, number of RELATIVE */
-#define DT_RELCOUNT    0x6ffffffa      /* relocs, which must come first */
-#define DT_FLAGS_1      0x6ffffffb
-
 /* Dynamic Flags - DT_FLAGS .dynamic entry */
 #define DF_ORIGIN       0x00000001
 #define DF_SYMBOLIC     0x00000002
@@ -512,22 +898,6 @@ typedef struct {
 #define DF_BIND_NOW     0x00000008
 #define DF_STATIC_TLS   0x00000010
 
-/* Dynamic Flags - DT_FLAGS_1 .dynamic entry */
-#define DF_1_NOW       0x00000001
-#define DF_1_GLOBAL    0x00000002
-#define DF_1_GROUP     0x00000004
-#define DF_1_NODELETE  0x00000008
-#define DF_1_LOADFLTR  0x00000010
-#define DF_1_INITFIRST 0x00000020
-#define DF_1_NOOPEN    0x00000040
-#define DF_1_ORIGIN    0x00000080
-#define DF_1_DIRECT    0x00000100
-#define DF_1_TRANS     0x00000200
-#define DF_1_INTERPOSE 0x00000400
-#define DF_1_NODEFLIB  0x00000800
-#define DF_1_NODUMP    0x00001000
-#define DF_1_CONLFAT   0x00002000
-
 /* Standard ELF hashing function */
 unsigned int elf_hash(const unsigned char *name);
 
@@ -541,9 +911,9 @@ typedef struct {
 } Elf32_Nhdr;
 
 typedef struct {
-       Elf64_Half n_namesz;
-       Elf64_Half n_descsz;
-       Elf64_Half n_type;
+       Elf64_Word n_namesz;
+       Elf64_Word n_descsz;
+       Elf64_Word n_type;
 } Elf64_Nhdr;
 
 /*
@@ -556,12 +926,59 @@ typedef struct {
 } Elf32_Note;
 
 typedef struct {
-       Elf64_Half namesz;
-       Elf64_Half descsz;
-       Elf64_Half type;
+       Elf64_Word namesz;
+       Elf64_Word descsz;
+       Elf64_Word type;
 } Elf64_Note;
 
 /*
+ * here comes the end of the specification. The definitions below are either
+ * generally usable (or historic) or OS specific
+ */
+
+/* e_ident */
+#define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \
+                      (ehdr).e_ident[EI_MAG1] == ELFMAG1 && \
+                      (ehdr).e_ident[EI_MAG2] == ELFMAG2 && \
+                      (ehdr).e_ident[EI_MAG3] == ELFMAG3)
+
+#define        EM_AMD64        EM_X86_64       /* AMD x86-64 architecture */
+#define EM_ALPHA_EXP   0x9026          /* DEC ALPHA */
+
+#define        ELFMAG          "\177ELF"       /* magic */
+#define        SELFMAG         4               /* size of magic */
+/* this section type definition is used by vmd */
+#define ELF_CTF                ".SUNW_ctf"     /* CTF data */
+
+/* some other useful tags */
+#define DT_RELACOUNT   0x6ffffff9      /* if present, number of RELATIVE */
+#define DT_RELCOUNT    0x6ffffffa      /* relocs, which must come first */
+#define DT_FLAGS_1      0x6ffffffb
+
+/* Dynamic Flags - DT_FLAGS_1 .dynamic entry */
+#define DF_1_NOW       0x00000001
+#define DF_1_GLOBAL    0x00000002
+#define DF_1_GROUP     0x00000004
+#define DF_1_NODELETE  0x00000008
+#define DF_1_LOADFLTR  0x00000010
+#define DF_1_INITFIRST 0x00000020
+#define DF_1_NOOPEN    0x00000040
+#define DF_1_ORIGIN    0x00000080
+#define DF_1_DIRECT    0x00000100
+#define DF_1_TRANS     0x00000200
+#define DF_1_INTERPOSE 0x00000400
+#define DF_1_NODEFLIB  0x00000800
+#define DF_1_NODUMP    0x00001000
+#define DF_1_CONLFAT   0x00002000
+
+#define PT_GNU_EH_FRAME                0x6474e550      /* Exception handling 
info */
+#define PT_GNU_RELRO           0x6474e552      /* Read-only after relocation */
+
+#define PT_OPENBSD_RANDOMIZE   0x65a3dbe6      /* fill with random data */
+#define PT_OPENBSD_WXNEEDED    0x65a3dbe7      /* program performs W^X 
violations */
+#define PT_OPENBSD_BOOTDATA    0x65a41be6      /* section for boot arguments */
+
+/*
  * OpenBSD-specific core file information.
  *
  * OpenBSD ELF core files use notes to provide information about
@@ -587,6 +1004,8 @@ typedef struct {
  * bump the version.
  */
 
+#if defined(_KERNEL)
+
 #define NT_OPENBSD_PROCINFO    10
 #define NT_OPENBSD_AUXV                11
 
@@ -619,6 +1038,8 @@ struct elfcore_procinfo {
        int8_t          cpi_name[32];   /* copy of pr->ps_comm */
 };
 
+#endif /* _KERNEL */
+
 /*
  * XXX - these _KERNEL items aren't part of the ABI!
  */
@@ -634,7 +1055,7 @@ typedef struct {
 #define ELF64_NO_ADDR  ((__uint64_t) ~0)/* Indicates addr. not yet filled in */
 
 typedef struct {
-       Elf64_Shalf     au_id;                          /* 32-bit id */
+       Elf64_Sword     au_id;                          /* 32-bit id */
        Elf64_Xword     au_v;                           /* 64-bit value */
 } Aux64Info;
 
@@ -663,7 +1084,7 @@ struct elf_args {
         u_long  arg_phnum;             /* Number of program headers */
 };
 
-#endif
+#endif /* _KERNEL || _DYN_LOADER */
 
 #if !defined(ELFSIZE) && defined(ARCH_ELFSIZE)
 #define ELFSIZE ARCH_ELFSIZE
@@ -729,7 +1150,9 @@ struct elf_args {
 
 #define ELF_NO_ADDR    ELF64_NO_ADDR
 #define AuxInfo                Aux64Info
-#endif
+#else
+#error "wrong ELF size"
+#endif /* ELFSIZE */
 
 #ifndef _KERNEL
 extern Elf_Dyn         _DYNAMIC[];
diff --git a/usr.bin/nm/elf.c b/usr.bin/nm/elf.c
index 2c7676b1b13..a29cee02216 100644
--- a/usr.bin/nm/elf.c
+++ b/usr.bin/nm/elf.c
@@ -29,7 +29,7 @@
 #include <sys/mman.h>
 #include <unistd.h>
 #include <a.out.h>
-#include <elf_abi.h>
+#include <elf.h>
 #include <errno.h>
 #include <err.h>
 #include <stdint.h>
diff --git a/usr.bin/nm/nm.c b/usr.bin/nm/nm.c
index 5d2a1bfeb61..72f1f0b4cc7 100644
--- a/usr.bin/nm/nm.c
+++ b/usr.bin/nm/nm.c
@@ -36,7 +36,7 @@
 #include <sys/types.h>
 #include <sys/mman.h>
 #include <a.out.h>
-#include <elf_abi.h>
+#include <elf.h>
 #include <ar.h>
 #include <ranlib.h>
 #include <unistd.h>
diff --git a/usr.bin/rdist/isexec.c b/usr.bin/rdist/isexec.c
index e6d125a61f2..a69677d65e4 100644
--- a/usr.bin/rdist/isexec.c
+++ b/usr.bin/rdist/isexec.c
@@ -30,7 +30,7 @@
  */
 
 #include <sys/types.h>
-#include <elf_abi.h>
+#include <elf.h>
 #include <fcntl.h>
 #include <unistd.h>
 
diff --git a/usr.sbin/installboot/i386_installboot.c 
b/usr.sbin/installboot/i386_installboot.c
index 10acf8bef32..7af82463308 100644
--- a/usr.sbin/installboot/i386_installboot.c
+++ b/usr.sbin/installboot/i386_installboot.c
@@ -54,7 +54,7 @@
 #include <machine/cpu.h>
 #include <machine/biosvar.h>
 
-#include <elf_abi.h>
+#include <elf.h>
 #include <err.h>
 #include <errno.h>
 #include <fcntl.h>
diff --git a/usr.sbin/installboot/i386_nlist.c 
b/usr.sbin/installboot/i386_nlist.c
index f508d74d94e..6d6d93e3e57 100644
--- a/usr.sbin/installboot/i386_nlist.c
+++ b/usr.sbin/installboot/i386_nlist.c
@@ -34,7 +34,7 @@
 #include <sys/mman.h>
 #include <sys/stat.h>
 
-#include <elf_abi.h>
+#include <elf.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <nlist.h>
diff --git a/usr.sbin/kvm_mkdb/nlist.c b/usr.sbin/kvm_mkdb/nlist.c
index 18f895a97b0..3e5a11bbb49 100644
--- a/usr.sbin/kvm_mkdb/nlist.c
+++ b/usr.sbin/kvm_mkdb/nlist.c
@@ -50,7 +50,7 @@
 #include <sys/file.h>
 #include <sys/sysctl.h>
 
-#include <elf_abi.h>
+#include <elf.h>
 
 typedef struct nlist NLIST;
 #define        _strx   n_un.n_strx

Reply via email to