fix a compilation issue with latest llvm trunk (9.0) (#2242)

The following llvm change in trunk (9.0)
  https://reviews.llvm.org/D58194
breaks bcc build.

  [ 76%] Building CXX object src/cc/CMakeFiles/bcc-static.dir/bpf_module.cc.o
  /home/yhs/work/bcc/src/cc/bcc_debug.cc: In member function ‘void ebpf::SourceDebugger::dump()’:
  /home/yhs/work/bcc/src/cc/bcc_debug.cc:207:23: error: no matching function for call to ‘llvm::DWARFDebugLine::LineTable::getFileLineInfoForAddress(uint64_t, const char*, llvm::DILineInfoSpecifier::FileLineInfoKind, llvm::DILineInfo&) const’
               LineInfo);
                       ^
  /home/yhs/work/bcc/src/cc/bcc_debug.cc:207:23: note: candidate is:
  In file included from /home/yhs/work/llvm/build/install/include/llvm/DebugInfo/DWARF/DWARFContext.h:24:0,
                   from /home/yhs/work/bcc/src/cc/bcc_debug.cc:22:
  /home/yhs/work/llvm/build/install/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h:253:10: note: bool llvm::DWARFDebugLin
  e::LineTable::getFileLineInfoForAddress(llvm::object::SectionedAddress, const char*, llvm::DILineInfoSpecifier::FileLi
  neInfoKind, llvm::DILineInfo&) const
       bool getFileLineInfoForAddress(object::SectionedAddress Address,

The reason is that function getFileLineInfoForAddress() signature changed.
The first argument used to be "uint64_t" and now "object::SectionedAddress" which
includes both address and section ID.

This patch fixed this issue by specializing getFileLineInfoForAddress() for LLVM 9.
There exists no variant for getFileLineInfoForAddress() working for all LLVM versions.

Signed-off-by: Yonghong Song <yhs@fb.com>
diff --git a/src/cc/bcc_debug.cc b/src/cc/bcc_debug.cc
index 786074a..b856cd0 100644
--- a/src/cc/bcc_debug.cc
+++ b/src/cc/bcc_debug.cc
@@ -183,6 +183,7 @@
       uint64_t Size;
       uint8_t *FuncStart = get<0>(section.second);
       uint64_t FuncSize = get<1>(section.second);
+      unsigned SectionID = get<2>(section.second);
       ArrayRef<uint8_t> Data(FuncStart, FuncSize);
       uint32_t CurrentSrcLine = 0;
       string func_name = section.first.substr(fn_prefix_.size());
@@ -201,8 +202,14 @@
           break;
         } else {
           DILineInfo LineInfo;
+
           LineTable->getFileLineInfoForAddress(
-              (uint64_t)FuncStart + Index, CU->getCompilationDir(),
+#if LLVM_MAJOR_VERSION >= 9
+              {(uint64_t)FuncStart + Index, SectionID},
+#else
+              (uint64_t)FuncStart + Index,
+#endif
+              CU->getCompilationDir(),
               DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath,
               LineInfo);
 
diff --git a/src/cc/bcc_debug.h b/src/cc/bcc_debug.h
index 9b195be..1467ca8 100644
--- a/src/cc/bcc_debug.h
+++ b/src/cc/bcc_debug.h
@@ -13,13 +13,16 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
+#include "bpf_module.h"
+
 namespace ebpf {
 
 class SourceDebugger {
  public:
   SourceDebugger(
       llvm::Module *mod,
-      std::map<std::string, std::tuple<uint8_t *, uintptr_t>> &sections,
+      sec_map_def &sections,
       const std::string &fn_prefix, const std::string &mod_src,
       std::map<std::string, std::string> &src_dbg_fmap)
       : mod_(mod),
@@ -52,7 +55,7 @@
 
  private:
   llvm::Module *mod_;
-  const std::map<std::string, std::tuple<uint8_t *, uintptr_t>> &sections_;
+  const sec_map_def &sections_;
   const std::string &fn_prefix_;
   const std::string &mod_src_;
   std::map<std::string, std::string> &src_dbg_fmap_;
diff --git a/src/cc/bpf_module.cc b/src/cc/bpf_module.cc
index f0d3997..cf6ea8f 100644
--- a/src/cc/bpf_module.cc
+++ b/src/cc/bpf_module.cc
@@ -63,7 +63,7 @@
 class MyMemoryManager : public SectionMemoryManager {
  public:
 
-  explicit MyMemoryManager(map<string, tuple<uint8_t *, uintptr_t>> *sections)
+  explicit MyMemoryManager(sec_map_def *sections)
       : sections_(sections) {
   }
 
@@ -75,7 +75,7 @@
     uint8_t *Addr = SectionMemoryManager::allocateDataSection(Size, Alignment, SectionID, SectionName, false);
     //printf("allocateDataSection: %s Addr %p Size %ld Alignment %d SectionID %d\n",
     //       SectionName.str().c_str(), (void *)Addr, Size, Alignment, SectionID);
-    (*sections_)[SectionName.str()] = make_tuple(Addr, Size);
+    (*sections_)[SectionName.str()] = make_tuple(Addr, Size, SectionID);
     return Addr;
   }
   uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
@@ -86,10 +86,10 @@
     uint8_t *Addr = SectionMemoryManager::allocateDataSection(Size, Alignment, SectionID, SectionName, false);
     //printf("allocateDataSection: %s Addr %p Size %ld Alignment %d SectionID %d\n",
     //       SectionName.str().c_str(), (void *)Addr, Size, Alignment, SectionID);
-    (*sections_)[SectionName.str()] = make_tuple(Addr, Size);
+    (*sections_)[SectionName.str()] = make_tuple(Addr, Size, SectionID);
     return Addr;
   }
-  map<string, tuple<uint8_t *, uintptr_t>> *sections_;
+  sec_map_def *sections_;
 };
 
 BPFModule::BPFModule(unsigned flags, TableStorage *ts, bool rw_engine_enabled,
@@ -223,7 +223,7 @@
   return 0;
 }
 
-void BPFModule::load_btf(std::map<std::string, std::tuple<uint8_t *, uintptr_t>> &sections) {
+void BPFModule::load_btf(sec_map_def &sections) {
   uint8_t *btf_sec = nullptr, *btf_ext_sec = nullptr;
   uintptr_t btf_sec_size = 0, btf_ext_sec_size = 0;
 
@@ -268,7 +268,7 @@
   btf_ = btf;
 }
 
-int BPFModule::load_maps(std::map<std::string, std::tuple<uint8_t *, uintptr_t>> &sections) {
+int BPFModule::load_maps(sec_map_def &sections) {
   // find .maps.<table_name> sections and retrieve all map key/value type id's
   std::map<std::string, std::pair<int, int>> map_tids;
   if (btf_) {
@@ -386,7 +386,7 @@
 
 int BPFModule::finalize() {
   Module *mod = &*mod_;
-  std::map<std::string, std::tuple<uint8_t *, uintptr_t>> tmp_sections,
+  sec_map_def tmp_sections,
       *sections_p;
 
   mod->setTargetTriple("bpf-pc-linux");
@@ -443,7 +443,7 @@
         tmp_p = new uint8_t[size];
         memcpy(tmp_p, addr, size);
       }
-      sections_[fname] = make_tuple(tmp_p, size);
+      sections_[fname] = make_tuple(tmp_p, size, get<2>(section.second));
     }
     engine_.reset();
     ctx_.reset();
diff --git a/src/cc/bpf_module.h b/src/cc/bpf_module.h
index 18c71d3..63d998c 100644
--- a/src/cc/bpf_module.h
+++ b/src/cc/bpf_module.h
@@ -35,6 +35,8 @@
 
 namespace ebpf {
 
+typedef std::map<std::string, std::tuple<uint8_t *, uintptr_t, unsigned>> sec_map_def;
+
 // Options to enable different debug logging.
 enum {
   // Debug output compiled LLVM IR.
@@ -82,8 +84,8 @@
   StatusTuple sscanf(std::string fn_name, const char *str, void *val);
   StatusTuple snprintf(std::string fn_name, char *str, size_t sz,
                        const void *val);
-  void load_btf(std::map<std::string, std::tuple<uint8_t *, uintptr_t>> &sections);
-  int load_maps(std::map<std::string, std::tuple<uint8_t *, uintptr_t>> &sections);
+  void load_btf(sec_map_def &sections);
+  int load_maps(sec_map_def &sections);
 
  public:
   BPFModule(unsigned flags, TableStorage *ts = nullptr, bool rw_engine_enabled = true,
@@ -150,7 +152,7 @@
   std::unique_ptr<llvm::ExecutionEngine> rw_engine_;
   std::unique_ptr<llvm::Module> mod_;
   std::unique_ptr<FuncSource> func_src_;
-  std::map<std::string, std::tuple<uint8_t *, uintptr_t>> sections_;
+  sec_map_def sections_;
   std::vector<TableDesc *> tables_;
   std::map<std::string, size_t> table_names_;
   std::vector<std::string> function_names_;