Switch <elf.h> over to linux uapi under the covers.

Remove the linker's reliance on BSD cruft and use the glibc-style
ElfW macro. (Other code too, but the linker contains the majority
of the code that needs to work for Elf32 and Elf64.)

All platforms need dl_iterate_phdr_static, so it doesn't make sense
to have that part of the per-architecture configuration.

Bug: 12476126
Change-Id: I1d7f918f1303a392794a6cd8b3512ff56bd6e487
diff --git a/libc/include/elf.h b/libc/include/elf.h
index 3f2e4f2..7a217b0 100644
--- a/libc/include/elf.h
+++ b/libc/include/elf.h
@@ -28,33 +28,58 @@
 #ifndef _ELF_H
 #define _ELF_H
 
-#include <stdint.h>
 #include <linux/auxvec.h>
+#include <linux/elf.h>
+#include <linux/elf-em.h>
 
-/* TODO: can we switch to <linux/elf.h> instead? http://b/12476126. */
-#include <sys/exec_elf.h>
+#include <machine/elf_machdep.h>
 
 typedef struct {
-  uint32_t a_type;
+  __u32 a_type;
   union {
-    uint32_t a_val;
+    __u32 a_val;
   } a_un;
 } Elf32_auxv_t;
 
 typedef struct {
-  uint64_t a_type;
+  __u64 a_type;
   union {
-    uint64_t a_val;
+    __u64 a_val;
   } a_un;
 } Elf64_auxv_t;
 
-#ifdef __LP64__
-#  define Elf_auxv_t Elf64_auxv_t
-#else
-#  define Elf_auxv_t Elf32_auxv_t
-#endif
+#define DF_ORIGIN     0x00000001
+#define DF_SYMBOLIC   0x00000002
+#define DF_TEXTREL    0x00000004
+#define DF_BIND_NOW   0x00000008
+#define DF_STATIC_TLS 0x00000010
 
-/* <sys/exec_elf.h> doesn't contain any NT_ constants. aarch64 strace needs this one. */
-#define NT_PRSTATUS 1
+#define DT_BIND_NOW 24
+#define DT_INIT_ARRAY 25
+#define DT_FINI_ARRAY 26
+#define DT_INIT_ARRAYSZ 27
+#define DT_FINI_ARRAYSZ 28
+#define DT_RUNPATH 29
+#define DT_FLAGS 30
+/* glibc and BSD disagree for DT_ENCODING; glibc looks wrong. */
+#define DT_PREINIT_ARRAY 32
+#define DT_PREINIT_ARRAYSZ 33
+
+#define ELFOSABI_SYSV 0 /* Synonym for ELFOSABI_NONE used by valgrind. */
+
+#define EM_ARM 40
+#define EM_AARCH64 183
+
+#define PT_GNU_RELRO 0x6474e552
+
+#define STB_LOOS   10
+#define STB_HIOS   12
+#define STB_LOPROC 13
+#define STB_HIPROC 15
+
+#define STT_LOOS   10
+#define STT_HIOS   12
+#define STT_LOPROC 13
+#define STT_HIPROC 15
 
 #endif /* _ELF_H */