Relocate DWARF using .oat_patches.

The current solution is to hard-code knowledge of DWARF in the linker.
This works for simple use of DWARF, but breaks as soon as I try to do
anything more complex.  Making the linker fully support DWARF would be
non-trivial task and would be essentially rewrite.  Using .oat_patches
is much easier solution.

Relocating .debug_* sections required extending .oat_patches to support
more sections than just .text.  I have encoded each section as
null-terminated section name followed by ULEB128 deltas.

The ULEB128 encoding shrinks .oat_patches for .text by factor of
about 6 with 64-bit compiler, and factor of 3 with 32-bit compiler.

On the other hand, it grows by the extra .oat_patches for DWARF which
were not present before (if debug symbols are included).

Overall, it is still a clear improvement even with the DWARF patches.

Change-Id: I78ffeda0f8a3da03341995a3b5ef15c954e16e9f
diff --git a/compiler/elf_writer_debug.cc b/compiler/elf_writer_debug.cc
index 5e8e24b..6df5ea9 100644
--- a/compiler/elf_writer_debug.cc
+++ b/compiler/elf_writer_debug.cc
@@ -159,7 +159,7 @@
  * @param debug_line Line number table.
  */
 void WriteDebugSections(const CompilerDriver* compiler,
-                        const OatWriter* oat_writer,
+                        OatWriter* oat_writer,
                         uint32_t text_section_offset,
                         std::vector<uint8_t>* eh_frame,
                         std::vector<uint8_t>* debug_info,
@@ -176,6 +176,7 @@
   }
 
   // Write .eh_frame section.
+  auto* eh_frame_patches = oat_writer->GetAbsolutePatchLocationsFor(".eh_frame");
   size_t cie_offset = eh_frame->size();
   WriteEhFrameCIE(isa, eh_frame);
   for (const OatWriter::DebugInfo& mi : method_infos) {
@@ -183,7 +184,7 @@
     if (opcodes != nullptr) {
       WriteEhFrameFDE(Is64BitInstructionSet(isa), cie_offset,
                       text_section_offset + mi.low_pc_, mi.high_pc_ - mi.low_pc_,
-                      opcodes, eh_frame);
+                      opcodes, eh_frame, eh_frame_patches);
     }
   }
 
@@ -211,7 +212,8 @@
     info.EndTag();  // DW_TAG_subprogram
   }
   info.EndTag();  // DW_TAG_compile_unit
-  WriteDebugInfoCU(debug_abbrev_offset, info, debug_info);
+  auto* debug_info_patches = oat_writer->GetAbsolutePatchLocationsFor(".debug_info");
+  WriteDebugInfoCU(debug_abbrev_offset, info, debug_info, debug_info_patches);
 
   // TODO: in gdb info functions <regexp> - reports Java functions, but
   // source file is <unknown> because .debug_line is formed as one
@@ -353,7 +355,8 @@
   }
   opcodes.AdvancePC(text_section_offset + cunit_high_pc);
   opcodes.EndSequence();
-  WriteDebugLineTable(directories, files, opcodes, debug_line);
+  auto* debug_line_patches = oat_writer->GetAbsolutePatchLocationsFor(".debug_line");
+  WriteDebugLineTable(directories, files, opcodes, debug_line, debug_line_patches);
 }
 
 }  // namespace dwarf