Fix compilation error when built with llvm17
authorYonghong Song <yhs@fb.com>
Sun, 26 Mar 2023 20:10:49 +0000 (13:10 -0700)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Thu, 22 Feb 2024 14:17:55 +0000 (15:17 +0100)
With llvm17, building bcc hits the following compilation errors:
  ...
  /home/yhs/work/bcc/src/cc/bpf_module.cc:21:10: fatal error: llvm-c/Transforms/IPO.h: No such file or directory
   21 | #include <llvm-c/Transforms/IPO.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~
  /home/yhs/work/bcc/src/cc/bpf_module.cc:48:10: fatal error: llvm/Transforms/IPO/PassManagerBuilder.h: No such file or directory
   48 | #include <llvm/Transforms/IPO/PassManagerBuilder.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The above two files are removed by https://reviews.llvm.org/D144970 and https://reviews.llvm.org/D145835

Change-Id: I5f72ae78ed22734e5a786dd745f21293a057e46f
Signed-off-by: Yonghong Song <yhs@fb.com>
src/cc/bpf_module.cc

index f48df7af244ce9e101555d76aac3bae09fcbe390..c8bff5caf339253663e5dac83b1b1aa94376c78a 100644 (file)
@@ -21,8 +21,9 @@
 #include <vector>
 #include <set>
 #include <linux/bpf.h>
-#include <net/if.h>
-
+#if LLVM_MAJOR_VERSION <= 16
+#include <llvm-c/Transforms/IPO.h>
+#endif
 #include <llvm/ExecutionEngine/MCJIT.h>
 #include <llvm/ExecutionEngine/SectionMemoryManager.h>
 #if LLVM_MAJOR_VERSION >= 16
 #include <llvm/IR/Verifier.h>
 #include <llvm/Support/TargetSelect.h>
 #include <llvm/Transforms/IPO.h>
+#if LLVM_MAJOR_VERSION <= 16
 #include <llvm/Transforms/IPO/PassManagerBuilder.h>
-#include <llvm-c/Transforms/IPO.h>
+#endif
+#include <net/if.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include <map>
+#include <set>
+#include <string>
+#include <iostream>
+#include <vector>
 
 #include "common.h"
 #include "bcc_debug.h"