Stream DWARF debug section directly to disk.

Change the structure so that the debug sections are written to
disk as we go.  There are still some temporary buffers, however,
we no longer hold all of the data in memory before writing it.
We can not avoid buffering of some things (e.g. .debug_str).

Change-Id: Id4940cf10ae5b6f3cac7fb8d20197f0304079b92
diff --git a/compiler/elf_builder.h b/compiler/elf_builder.h
index 895dfcc..6e8dfd6 100644
--- a/compiler/elf_builder.h
+++ b/compiler/elf_builder.h
@@ -156,8 +156,13 @@
 
     // Returns the size of the content of this section.
     Elf_Word GetSize() const {
-      CHECK(finished_);
-      return header_.sh_size;
+      if (finished_) {
+        return header_.sh_size;
+      } else {
+        CHECK(started_);
+        CHECK_NE(header_.sh_type, (Elf_Word)SHT_NOBITS);
+        return owner_->Seek(0, kSeekCurrent) - header_.sh_offset;
+      }
     }
 
     // Set desired allocation size for .bss section.
@@ -281,6 +286,8 @@
       strtab_(this, ".strtab", 0, kPageSize),
       symtab_(this, ".symtab", SHT_SYMTAB, 0, &strtab_),
       debug_frame_(this, ".debug_frame", SHT_PROGBITS, 0, nullptr, 0, sizeof(Elf_Addr), 0),
+      debug_info_(this, ".debug_info", SHT_PROGBITS, 0, nullptr, 0, 1, 0),
+      debug_line_(this, ".debug_line", SHT_PROGBITS, 0, nullptr, 0, 1, 0),
       shstrtab_(this, ".shstrtab", 0, 1),
       virtual_address_(0) {
     text_.phdr_flags_ = PF_R | PF_X;
@@ -300,6 +307,8 @@
   Section* GetEhFrame() { return &eh_frame_; }
   Section* GetEhFrameHdr() { return &eh_frame_hdr_; }
   Section* GetDebugFrame() { return &debug_frame_; }
+  Section* GetDebugInfo() { return &debug_info_; }
+  Section* GetDebugLine() { return &debug_line_; }
 
   // Encode patch locations as LEB128 list of deltas between consecutive addresses.
   // (exposed publicly for tests)
@@ -667,6 +676,8 @@
   StringSection strtab_;
   SymbolSection symtab_;
   Section debug_frame_;
+  Section debug_info_;
+  Section debug_line_;
   StringSection shstrtab_;
   std::vector<std::unique_ptr<Section>> other_sections_;