Improve FreeBSD kernel debugging

FreeBSD kernel modules are actually relocatable (.o) ELF files and this
previously caused some issues for LLDB. This change addresses these when
using lldb to symbolicate FreeBSD kernel backtraces. 

The major problems:

- Relocations were not being applied to the DWARF debug info despite
  there being code to do this. Several issues prevented it from working:

  - Relocations are computed at the same time as the symbol table, but
    in the case of split debug files, symbol table parsing always
    redirects to the primary object file, meaning that relocations would
    never be applied in the debug file.

  - There's actually no guarantee that the symbol table has been parsed
    yet when trying to parse debug information.

  - When actually applying relocations, it will segfault because the
    object files are not mapped with MAP_PRIVATE and PROT_WRITE.

- LLDB returned invalid results when performing ordinary address-to-
  symbol resolution. It turned out that the addresses specified in the
  section headers were all 0, so LLDB believed all the sections had
  overlapping "file addresses" and would sometimes return a symbol from
  the wrong section.

Patch by Brian Koropoff

Differential Revision:	https://reviews.llvm.org/D38142

llvm-svn: 314672
diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
index 6d8717b..e0478cc 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
@@ -154,6 +154,8 @@
   llvm::StringRef
   StripLinkerSymbolAnnotations(llvm::StringRef symbol_name) const override;
 
+  void RelocateSection(lldb_private::Section *section) override;
+
 private:
   ObjectFileELF(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
                 lldb::offset_t data_offset, const lldb_private::FileSpec *file,
@@ -296,17 +298,18 @@
 
   /// Relocates debug sections
   unsigned RelocateDebugSections(const elf::ELFSectionHeader *rel_hdr,
-                                 lldb::user_id_t rel_id);
+                                 lldb::user_id_t rel_id,
+                                 lldb_private::Symtab *thetab);
 
-  unsigned RelocateSection(lldb_private::Symtab *symtab,
-                           const elf::ELFHeader *hdr,
-                           const elf::ELFSectionHeader *rel_hdr,
-                           const elf::ELFSectionHeader *symtab_hdr,
-                           const elf::ELFSectionHeader *debug_hdr,
-                           lldb_private::DataExtractor &rel_data,
-                           lldb_private::DataExtractor &symtab_data,
-                           lldb_private::DataExtractor &debug_data,
-                           lldb_private::Section *rel_section);
+  unsigned ApplyRelocations(lldb_private::Symtab *symtab,
+                            const elf::ELFHeader *hdr,
+                            const elf::ELFSectionHeader *rel_hdr,
+                            const elf::ELFSectionHeader *symtab_hdr,
+                            const elf::ELFSectionHeader *debug_hdr,
+                            lldb_private::DataExtractor &rel_data,
+                            lldb_private::DataExtractor &symtab_data,
+                            lldb_private::DataExtractor &debug_data,
+                            lldb_private::Section *rel_section);
 
   /// Loads the section name string table into m_shstr_data.  Returns the
   /// number of bytes constituting the table.