Generalize compression tool

 1. One binary for all architectures
 2. Generalize (and slightly improve) compression
 2.1 works on all relocation types (rela?.dyn section only so far)
 2.2 Uses same format to encode ElfW(Rel) as well as ElfW(Rela) tables

Bug: 18051137
Change-Id: I66c95d9076954ca115816fc577d0f5ef274e5e72
diff --git a/tools/relocation_packer/src/elf_traits.h b/tools/relocation_packer/src/elf_traits.h
index f099bab..41b06c8 100644
--- a/tools/relocation_packer/src/elf_traits.h
+++ b/tools/relocation_packer/src/elf_traits.h
@@ -10,31 +10,10 @@
 #include "elf.h"
 #include "libelf.h"
 
-// The TARGET_ macro controls which Elf types we expect and handle.
-// Either TARGET_ARM or TARGET_ARM64 must be defined, but not both.
-
-#if !defined(TARGET_ARM) && !defined(TARGET_ARM64)
-# error "Unsupported target, define one of TARGET_ARM or TARGET_ARM64"
-#elif defined(TARGET_ARM) && defined(TARGET_ARM64)
-# error "Define one of TARGET_ARM or TARGET_ARM64, but not both"
-#endif
-
-// TODO(simonb): Eliminate these once AARCH64 appears reliably in elf.h.
-#ifndef EM_AARCH64
-#define EM_AARCH64 183
-#endif
-#ifndef R_AARCH64_RELATIVE
-#define R_AARCH64_RELATIVE 1027
-#endif
-#ifndef R_AARCH64_NONE
-#define R_AARCH64_NONE 0
-#endif
-
 // ELF is a traits structure used to provide convenient aliases for
-// 32/64 bit Elf types and functions, depending on the target specified.
+// 32/64 bit Elf types and functions, depending on the target file.
 
-#if defined(TARGET_ARM)
-struct ELF {
+struct ELF32_traits {
   typedef Elf32_Addr Addr;
   typedef Elf32_Dyn Dyn;
   typedef Elf32_Ehdr Ehdr;
@@ -48,27 +27,17 @@
   typedef Elf32_Sym Sym;
   typedef Elf32_Word Word;
   typedef Elf32_Xword Xword;
+  typedef Elf32_Half Half;
 
   static inline Ehdr* getehdr(Elf* elf) { return elf32_getehdr(elf); }
   static inline Phdr* getphdr(Elf* elf) { return elf32_getphdr(elf); }
   static inline Shdr* getshdr(Elf_Scn* scn) { return elf32_getshdr(scn); }
-
-  enum { kMachine = EM_ARM };
-  enum { kFileClass = ELFCLASS32 };
-  enum { kRelativeRelocationCode = R_ARM_RELATIVE };
-  enum { kNoRelocationCode = R_ARM_NONE };
-  enum { kGnuStackSegmentAlignment = 0 };
-
-  static inline const char* Machine() { return "ARM"; }
-
-# define ELF_R_SYM(val) ELF32_R_SYM(val)
-# define ELF_R_TYPE(val) ELF32_R_TYPE(val)
-# define ELF_R_INFO(sym, type) ELF32_R_INFO(sym, type)
-# define ELF_ST_TYPE(val) ELF32_ST_TYPE(val)
+  static inline Word elf_r_type(Word info) { return ELF32_R_TYPE(info); }
+  static inline int elf_st_type(uint8_t info) { return ELF32_ST_TYPE(info); }
+  static inline Word elf_r_sym(Word info) { return ELF32_R_SYM(info); }
 };
 
-#elif defined(TARGET_ARM64)
-struct ELF {
+struct ELF64_traits {
   typedef Elf64_Addr Addr;
   typedef Elf64_Dyn Dyn;
   typedef Elf64_Ehdr Ehdr;
@@ -82,24 +51,14 @@
   typedef Elf64_Sym Sym;
   typedef Elf64_Word Word;
   typedef Elf64_Xword Xword;
+  typedef Elf64_Half Half;
 
   static inline Ehdr* getehdr(Elf* elf) { return elf64_getehdr(elf); }
   static inline Phdr* getphdr(Elf* elf) { return elf64_getphdr(elf); }
   static inline Shdr* getshdr(Elf_Scn* scn) { return elf64_getshdr(scn); }
-
-  enum { kMachine = EM_AARCH64 };
-  enum { kFileClass = ELFCLASS64 };
-  enum { kRelativeRelocationCode = R_AARCH64_RELATIVE };
-  enum { kNoRelocationCode = R_AARCH64_NONE };
-  enum { kGnuStackSegmentAlignment = 16 };
-
-  static inline const char* Machine() { return "ARM64"; }
-
-# define ELF_R_SYM(val) ELF64_R_SYM(val)
-# define ELF_R_TYPE(val) ELF64_R_TYPE(val)
-# define ELF_R_INFO(sym, type) ELF64_R_INFO(sym, type)
-# define ELF_ST_TYPE(val) ELF64_ST_TYPE(val)
+  static inline Xword elf_r_type(Xword info) { return ELF64_R_TYPE(info); }
+  static inline int elf_st_type(uint8_t info) { return ELF64_ST_TYPE(info); }
+  static inline Word elf_r_sym(Xword info) { return ELF64_R_SYM(info); }
 };
-#endif
 
 #endif  // TOOLS_RELOCATION_PACKER_SRC_ELF_TRAITS_H_