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_file.h b/tools/relocation_packer/src/elf_file.h
index 6550274..73c3192 100644
--- a/tools/relocation_packer/src/elf_file.h
+++ b/tools/relocation_packer/src/elf_file.h
@@ -67,12 +67,13 @@
 // An ElfFile reads shared objects, and shuttles relative relocations
 // between .rel.dyn or .rela.dyn and .android.rel.dyn or .android.rela.dyn
 // sections.
+template <typename ELF>
 class ElfFile {
  public:
   explicit ElfFile(int fd)
       : fd_(fd), is_padding_relocations_(false), elf_(NULL),
         relocations_section_(NULL), dynamic_section_(NULL),
-        android_relocations_section_(NULL), relocations_type_(NONE) {}
+        relocations_type_(NONE) {}
   ~ElfFile() {}
 
   // Set padding mode.  When padding, PackRelocations() will not shrink
@@ -92,6 +93,10 @@
   bool UnpackRelocations();
 
  private:
+  enum relocations_type_t {
+    NONE = 0, REL, RELA
+  };
+
   // Load a new ElfFile from a filedescriptor.  If flushing, the file must
   // be open for read/write.  Returns true on successful ELF file load.
   // |fd| is an open file descriptor for the shared object.
@@ -99,17 +104,34 @@
 
   // Templated packer, helper for PackRelocations().  Rel type is one of
   // ELF::Rel or ELF::Rela.
-  template <typename Rel>
-  bool PackTypedRelocations(const std::vector<Rel>& relocations);
+  bool PackTypedRelocations(std::vector<typename ELF::Rela>* relocations);
 
   // Templated unpacker, helper for UnpackRelocations().  Rel type is one of
   // ELF::Rel or ELF::Rela.
-  template <typename Rel>
   bool UnpackTypedRelocations(const std::vector<uint8_t>& packed);
 
   // Write ELF file changes.
   void Flush();
 
+  void AdjustRelativeRelocationTargets(typename ELF::Off hole_start,
+                                       ssize_t hole_size,
+                                       std::vector<typename ELF::Rela>* relocations);
+
+  static void ResizeSection(Elf* elf, Elf_Scn* section, size_t new_size,
+                            typename ELF::Word new_sh_type, relocations_type_t relocations_type);
+
+  static void AdjustDynamicSectionForHole(Elf_Scn* dynamic_section,
+                                          typename ELF::Off hole_start,
+                                          ssize_t hole_size,
+                                          relocations_type_t relocations_type);
+
+  static void ConvertRelArrayToRelaVector(const typename ELF::Rel* rel_array, size_t rel_array_size,
+                                          std::vector<typename ELF::Rela>* rela_vector);
+
+  static void ConvertRelaVectorToRelVector(const std::vector<typename ELF::Rela>& rela_vector,
+                                           std::vector<typename ELF::Rel>* rel_vector);
+
+
   // File descriptor opened on the shared object.
   int fd_;
 
@@ -123,10 +145,9 @@
   // Sections that we manipulate, assigned by Load().
   Elf_Scn* relocations_section_;
   Elf_Scn* dynamic_section_;
-  Elf_Scn* android_relocations_section_;
 
   // Relocation type found, assigned by Load().
-  enum { NONE = 0, REL, RELA } relocations_type_;
+  relocations_type_t relocations_type_;
 };
 
 }  // namespace relocation_packer