aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManu Bretelle <chantr4@gmail.com>2023-09-13 21:10:36 +0000
committerManu Bretelle <chantr4@gmail.com>2023-09-13 23:24:35 +0000
commit6f11bf7e2806658c4bd69415b921cedf85d9ebfe (patch)
treef48b759dce964334cf1098460d5237e05b30f1ee
parentec49363e2e9daec026ee6cae4c5fc316f8fab0ff (diff)
downloadbcc-6f11bf7e2806658c4bd69415b921cedf85d9ebfe.tar.gz
Use LLVM_VERSION_MAJOR from llvm-config.h instead of inferred LLVM_MAJOR_VERSION
Instead of inferring this from within the CMakeList.txt file, we can pull it directly from llvm-config.h.
-rw-r--r--examples/cpp/CMakeLists.txt2
-rw-r--r--src/cc/CMakeLists.txt3
-rw-r--r--src/cc/bcc_debug.cc20
-rw-r--r--src/cc/bcc_debug.h2
-rw-r--r--src/cc/bpf_module.cc20
-rw-r--r--src/cc/bpf_module.h2
-rw-r--r--src/cc/bpf_module_rw_engine.cc12
-rw-r--r--src/cc/frontends/clang/b_frontend_action.cc10
-rw-r--r--src/cc/frontends/clang/frontend_action_common.h4
-rw-r--r--src/cc/frontends/clang/loader.cc6
-rw-r--r--src/cc/json_map_decl_visitor.cc3
-rw-r--r--tests/cc/CMakeLists.txt1
12 files changed, 45 insertions, 40 deletions
diff --git a/examples/cpp/CMakeLists.txt b/examples/cpp/CMakeLists.txt
index 8d09ae11..5264f8d3 100644
--- a/examples/cpp/CMakeLists.txt
+++ b/examples/cpp/CMakeLists.txt
@@ -4,6 +4,8 @@
include_directories(${PROJECT_BINARY_DIR}/src/cc)
include_directories(${PROJECT_SOURCE_DIR}/src/cc)
include_directories(${PROJECT_SOURCE_DIR}/src/cc/api)
+include_directories(${LLVM_INCLUDE_DIRS})
+
if (CMAKE_USE_LIBBPF_PACKAGE AND LIBBPF_FOUND)
include_directories(${PROJECT_SOURCE_DIR}/src/cc/compat)
else()
diff --git a/src/cc/CMakeLists.txt b/src/cc/CMakeLists.txt
index af0118cb..104eff0e 100644
--- a/src/cc/CMakeLists.txt
+++ b/src/cc/CMakeLists.txt
@@ -44,9 +44,6 @@ if (NOT HAVE_REALLOCARRAY_SUPPORT)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DCOMPAT_NEED_REALLOCARRAY")
endif()
-string(REGEX MATCH "^([0-9]+).*" _ ${LLVM_PACKAGE_VERSION})
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DLLVM_MAJOR_VERSION=${CMAKE_MATCH_1}")
-
include(static_libstdc++)
if(LIBBPF_INCLUDE_DIR)
diff --git a/src/cc/bcc_debug.cc b/src/cc/bcc_debug.cc
index d7ed49fa..b73d0f10 100644
--- a/src/cc/bcc_debug.cc
+++ b/src/cc/bcc_debug.cc
@@ -19,7 +19,7 @@
#include <tuple>
#include <vector>
-#if LLVM_MAJOR_VERSION >= 15
+#if LLVM_VERSION_MAJOR >= 15
#include <llvm/DebugInfo/DWARF/DWARFCompileUnit.h>
#endif
#include <llvm/DebugInfo/DWARF/DWARFContext.h>
@@ -32,10 +32,10 @@
#include <llvm/MC/MCInstrInfo.h>
#include <llvm/MC/MCObjectFileInfo.h>
#include <llvm/MC/MCRegisterInfo.h>
-#if LLVM_MAJOR_VERSION >= 15
+#if LLVM_VERSION_MAJOR >= 15
#include <llvm/MC/MCSubtargetInfo.h>
#endif
-#if LLVM_MAJOR_VERSION >= 14
+#if LLVM_VERSION_MAJOR >= 14
#include <llvm/MC/TargetRegistry.h>
#else
#include <llvm/Support/TargetRegistry.h>
@@ -127,7 +127,7 @@ void SourceDebugger::dump() {
errs() << "Debug Error: cannot get register info\n";
return;
}
-#if LLVM_MAJOR_VERSION >= 10
+#if LLVM_VERSION_MAJOR >= 10
MCTargetOptions MCOptions;
std::unique_ptr<MCAsmInfo> MAI(T->createMCAsmInfo(*MRI, TripleStr, MCOptions));
#else
@@ -141,7 +141,7 @@ void SourceDebugger::dump() {
std::unique_ptr<MCSubtargetInfo> STI(
T->createMCSubtargetInfo(TripleStr, "", ""));
MCObjectFileInfo MOFI;
-#if LLVM_MAJOR_VERSION >= 13
+#if LLVM_VERSION_MAJOR >= 13
MCContext Ctx(TheTriple, MAI.get(), MRI.get(), STI.get(), nullptr);
Ctx.setObjectFileInfo(&MOFI);
MOFI.initMCObjectFileInfo(Ctx, false, false);
@@ -176,7 +176,7 @@ void SourceDebugger::dump() {
// bcc has only one compilation unit
// getCompileUnitAtIndex() was gone in llvm 8.0 (https://reviews.llvm.org/D49741)
-#if LLVM_MAJOR_VERSION >= 8
+#if LLVM_VERSION_MAJOR >= 8
DWARFCompileUnit *CU = cast<DWARFCompileUnit>(DwarfCtx->getUnitAtIndex(0));
#else
DWARFCompileUnit *CU = DwarfCtx->getCompileUnitAtIndex(0);
@@ -202,7 +202,7 @@ void SourceDebugger::dump() {
uint64_t Size;
uint8_t *FuncStart = info.start_;
uint64_t FuncSize = info.size_;
-#if LLVM_MAJOR_VERSION >= 9
+#if LLVM_VERSION_MAJOR >= 9
auto section = sections_.find(info.section_);
if (section == sections_.end()) {
errs() << "Debug Error: no section entry for section " << info.section_
@@ -219,7 +219,7 @@ void SourceDebugger::dump() {
string src_dbg_str;
llvm::raw_string_ostream os(src_dbg_str);
for (uint64_t Index = 0; Index < FuncSize; Index += Size) {
-#if LLVM_MAJOR_VERSION >= 10
+#if LLVM_VERSION_MAJOR >= 10
S = DisAsm->getInstruction(Inst, Size, Data.slice(Index), Index, nulls());
#else
S = DisAsm->getInstruction(Inst, Size, Data.slice(Index), Index, nulls(),
@@ -232,7 +232,7 @@ void SourceDebugger::dump() {
DILineInfo LineInfo;
LineTable->getFileLineInfoForAddress(
-#if LLVM_MAJOR_VERSION >= 9
+#if LLVM_VERSION_MAJOR >= 9
{(uint64_t)FuncStart + Index, SectionID},
#else
(uint64_t)FuncStart + Index,
@@ -245,7 +245,7 @@ void SourceDebugger::dump() {
os);
os << format("%4" PRIu64 ":", Index >> 3) << '\t';
dumpBytes(Data.slice(Index, Size), os);
-#if LLVM_MAJOR_VERSION >= 10
+#if LLVM_VERSION_MAJOR >= 10
IP->printInst(&Inst, 0, "", *STI, os);
#else
IP->printInst(&Inst, os, "", *STI);
diff --git a/src/cc/bcc_debug.h b/src/cc/bcc_debug.h
index f9bda118..1d20e108 100644
--- a/src/cc/bcc_debug.h
+++ b/src/cc/bcc_debug.h
@@ -36,7 +36,7 @@ class SourceDebugger {
// on a set of in-memory sections with slightly different interfaces.
// FIXME: possibly to support 5.x
//
-#if LLVM_MAJOR_VERSION >= 6
+#if LLVM_VERSION_MAJOR >= 6
void dump();
private:
diff --git a/src/cc/bpf_module.cc b/src/cc/bpf_module.cc
index ee7f7f75..91ab9af6 100644
--- a/src/cc/bpf_module.cc
+++ b/src/cc/bpf_module.cc
@@ -17,12 +17,12 @@
#include <fcntl.h>
#include <linux/bpf.h>
-#if LLVM_MAJOR_VERSION <= 16
+#if LLVM_VERSION_MAJOR <= 16
#include <llvm-c/Transforms/IPO.h>
#endif
#include <llvm/ExecutionEngine/MCJIT.h>
#include <llvm/ExecutionEngine/SectionMemoryManager.h>
-#if LLVM_MAJOR_VERSION >= 16
+#if LLVM_VERSION_MAJOR >= 16
#include <llvm/IRPrinter/IRPrintingPasses.h>
#else
#include <llvm/IR/IRPrintingPasses.h>
@@ -30,7 +30,7 @@
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/Module.h>
-#if LLVM_MAJOR_VERSION >= 15
+#if LLVM_VERSION_MAJOR >= 15
#include <llvm/Pass.h>
#include <llvm/IR/PassManager.h>
#include <llvm/Passes/PassBuilder.h>
@@ -45,7 +45,7 @@
#include <llvm/Object/SymbolSize.h>
#include <llvm/Support/TargetSelect.h>
#include <llvm/Transforms/IPO.h>
-#if LLVM_MAJOR_VERSION <= 16
+#if LLVM_VERSION_MAJOR <= 16
#include <llvm/Transforms/IPO/PassManagerBuilder.h>
#endif
#include <net/if.h>
@@ -122,7 +122,7 @@ class MyMemoryManager : public SectionMemoryManager {
if (!section)
continue;
-#if LLVM_MAJOR_VERSION >= 10
+#if LLVM_VERSION_MAJOR >= 10
auto sec_name = section.get()->getName();
if (!sec_name)
continue;
@@ -159,7 +159,7 @@ BPFModule::BPFModule(unsigned flags, TableStorage *ts, bool rw_engine_enabled,
LLVMInitializeBPFTargetMC();
LLVMInitializeBPFTargetInfo();
LLVMInitializeBPFAsmPrinter();
-#if LLVM_MAJOR_VERSION >= 6
+#if LLVM_VERSION_MAJOR >= 6
LLVMInitializeBPFAsmParser();
if (flags & DEBUG_SOURCE)
LLVMInitializeBPFDisassembler();
@@ -254,7 +254,7 @@ void BPFModule::annotate_light() {
}
void BPFModule::dump_ir(Module &mod) {
-#if LLVM_MAJOR_VERSION >= 15
+#if LLVM_VERSION_MAJOR >= 15
// Create the analysis managers
LoopAnalysisManager LAM;
FunctionAnalysisManager FAM;
@@ -287,7 +287,7 @@ int BPFModule::run_pass_manager(Module &mod) {
return -1;
}
-#if LLVM_MAJOR_VERSION >= 15
+#if LLVM_VERSION_MAJOR >= 15
// Create the analysis managers
LoopAnalysisManager LAM;
FunctionAnalysisManager FAM;
@@ -552,7 +552,7 @@ int BPFModule::finalize() {
*sections_p;
mod->setTargetTriple("bpf-pc-linux");
-#if LLVM_MAJOR_VERSION >= 11
+#if LLVM_VERSION_MAJOR >= 11
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
mod->setDataLayout("e-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
#else
@@ -573,7 +573,7 @@ int BPFModule::finalize() {
builder.setMCJITMemoryManager(
ebpf::make_unique<MyMemoryManager>(sections_p, &*prog_func_info_));
builder.setMArch("bpf");
-#if LLVM_MAJOR_VERSION <= 11
+#if LLVM_VERSION_MAJOR <= 11
builder.setUseOrcMCJITReplacement(false);
#endif
engine_ = unique_ptr<ExecutionEngine>(builder.create());
diff --git a/src/cc/bpf_module.h b/src/cc/bpf_module.h
index fc491cfe..56786e90 100644
--- a/src/cc/bpf_module.h
+++ b/src/cc/bpf_module.h
@@ -22,6 +22,8 @@
#include <string>
#include <vector>
+#include <llvm/Config/llvm-config.h>
+
#include "bcc_exception.h"
#include "table_storage.h"
diff --git a/src/cc/bpf_module_rw_engine.cc b/src/cc/bpf_module_rw_engine.cc
index 52c877e4..bbdc26ee 100644
--- a/src/cc/bpf_module_rw_engine.cc
+++ b/src/cc/bpf_module_rw_engine.cc
@@ -49,12 +49,12 @@ void BPFModule::cleanup_rw_engine() {
static LoadInst *createLoad(IRBuilder<> &B, Value *addr, bool isVolatile = false)
{
-#if LLVM_MAJOR_VERSION >= 15
+#if LLVM_VERSION_MAJOR >= 15
if (isa<AllocaInst>(addr))
return B.CreateLoad(dyn_cast<AllocaInst>(addr)->getAllocatedType(), addr, isVolatile);
else
return B.CreateLoad(addr->getType(), addr, isVolatile);
-#elif LLVM_MAJOR_VERSION >= 13
+#elif LLVM_VERSION_MAJOR >= 13
return B.CreateLoad(addr->getType()->getPointerElementType(), addr, isVolatile);
#else
return B.CreateLoad(addr, isVolatile);
@@ -63,12 +63,12 @@ static LoadInst *createLoad(IRBuilder<> &B, Value *addr, bool isVolatile = false
static Value *createInBoundsGEP(IRBuilder<> &B, Value *ptr, ArrayRef<Value *>idxlist)
{
-#if LLVM_MAJOR_VERSION >= 15
+#if LLVM_VERSION_MAJOR >= 15
if (isa<GlobalValue>(ptr))
return B.CreateInBoundsGEP(dyn_cast<GlobalValue>(ptr)->getValueType(), ptr, idxlist);
else
return B.CreateInBoundsGEP(ptr->getType(), ptr, idxlist);
-#elif LLVM_MAJOR_VERSION >= 13
+#elif LLVM_VERSION_MAJOR >= 13
return B.CreateInBoundsGEP(ptr->getType()->getScalarType()->getPointerElementType(),
ptr, idxlist);
#else
@@ -385,7 +385,7 @@ unique_ptr<ExecutionEngine> BPFModule::finalize_rw(unique_ptr<Module> m) {
string err;
EngineBuilder builder(move(m));
builder.setErrorStr(&err);
-#if LLVM_MAJOR_VERSION <= 11
+#if LLVM_VERSION_MAJOR <= 11
builder.setUseOrcMCJITReplacement(false);
#endif
auto engine = unique_ptr<ExecutionEngine>(builder.create());
@@ -410,7 +410,7 @@ int BPFModule::annotate() {
table_names_[table.name] = id++;
GlobalValue *gvar = mod_->getNamedValue(table.name);
if (!gvar) continue;
-#if LLVM_MAJOR_VERSION >= 14
+#if LLVM_VERSION_MAJOR >= 14
{
Type *t = gvar->getValueType();
StructType *st = dyn_cast<StructType>(t);
diff --git a/src/cc/frontends/clang/b_frontend_action.cc b/src/cc/frontends/clang/b_frontend_action.cc
index dd093a0d..df0ff5d5 100644
--- a/src/cc/frontends/clang/b_frontend_action.cc
+++ b/src/cc/frontends/clang/b_frontend_action.cc
@@ -729,7 +729,7 @@ bool ProbeVisitor::IsContextMemberExpr(Expr *E) {
SourceRange
ProbeVisitor::expansionRange(SourceRange range) {
-#if LLVM_MAJOR_VERSION >= 7
+#if LLVM_VERSION_MAJOR >= 7
return rewriter_.getSourceMgr().getExpansionRange(range).getAsRange();
#else
return rewriter_.getSourceMgr().getExpansionRange(range);
@@ -1387,7 +1387,7 @@ bool BTypeVisitor::VisitImplicitCastExpr(ImplicitCastExpr *E) {
SourceRange
BTypeVisitor::expansionRange(SourceRange range) {
-#if LLVM_MAJOR_VERSION >= 7
+#if LLVM_VERSION_MAJOR >= 7
return rewriter_.getSourceMgr().getExpansionRange(range).getAsRange();
#else
return rewriter_.getSourceMgr().getExpansionRange(range);
@@ -1410,7 +1410,7 @@ int64_t BTypeVisitor::getFieldValue(VarDecl *Decl, FieldDecl *FDecl, int64_t Ori
unsigned idx = FDecl->getFieldIndex();
if (auto I = dyn_cast_or_null<InitListExpr>(Decl->getInit())) {
-#if LLVM_MAJOR_VERSION >= 8
+#if LLVM_VERSION_MAJOR >= 8
Expr::EvalResult res;
if (I->getInit(idx)->EvaluateAsInt(res, C)) {
return res.Val.getInt().getExtValue();
@@ -1809,7 +1809,7 @@ void BFrontendAction::DoMiscWorkAround() {
false);
rewriter_->getEditBuffer(rewriter_->getSourceMgr().getMainFileID()).InsertTextAfter(
-#if LLVM_MAJOR_VERSION >= 12
+#if LLVM_VERSION_MAJOR >= 12
rewriter_->getSourceMgr().getBufferOrFake(rewriter_->getSourceMgr().getMainFileID()).getBufferSize(),
#else
rewriter_->getSourceMgr().getBuffer(rewriter_->getSourceMgr().getMainFileID())->getBufferSize(),
@@ -1823,7 +1823,7 @@ void BFrontendAction::EndSourceFileAction() {
if (flags_ & DEBUG_PREPROCESSOR)
rewriter_->getEditBuffer(rewriter_->getSourceMgr().getMainFileID()).write(llvm::errs());
-#if LLVM_MAJOR_VERSION >= 9
+#if LLVM_VERSION_MAJOR >= 9
llvm::raw_string_ostream tmp_os(mod_src_);
rewriter_->getEditBuffer(rewriter_->getSourceMgr().getMainFileID())
.write(tmp_os);
diff --git a/src/cc/frontends/clang/frontend_action_common.h b/src/cc/frontends/clang/frontend_action_common.h
index ec819f66..e6ca4d54 100644
--- a/src/cc/frontends/clang/frontend_action_common.h
+++ b/src/cc/frontends/clang/frontend_action_common.h
@@ -13,7 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#if LLVM_MAJOR_VERSION >= 8
+#include <llvm/Config/llvm-config.h>
+
+#if LLVM_VERSION_MAJOR >= 8
#define GET_BEGINLOC(E) ((E)->getBeginLoc())
#define GET_ENDLOC(E) ((E)->getEndLoc())
#else
diff --git a/src/cc/frontends/clang/loader.cc b/src/cc/frontends/clang/loader.cc
index cbc83af4..5c65a469 100644
--- a/src/cc/frontends/clang/loader.cc
+++ b/src/cc/frontends/clang/loader.cc
@@ -179,7 +179,7 @@ static int CreateFromArgs(clang::CompilerInvocation &invocation,
const llvm::opt::ArgStringList &ccargs,
clang::DiagnosticsEngine &diags)
{
-#if LLVM_MAJOR_VERSION >= 10
+#if LLVM_VERSION_MAJOR >= 10
return clang::CompilerInvocation::CreateFromArgs(invocation, ccargs, diags);
#else
return clang::CompilerInvocation::CreateFromArgs(
@@ -284,7 +284,7 @@ int ClangLoader::parse(
vector<string> kflags;
if (kbuild_helper.get_flags(un.machine, &kflags))
return -1;
-#if LLVM_MAJOR_VERSION >= 9
+#if LLVM_VERSION_MAJOR >= 9
flags_cstr.push_back("-g");
flags_cstr.push_back("-gdwarf-4");
#else
@@ -412,7 +412,7 @@ int ClangLoader::do_compile(
string target_triple = get_clang_target();
driver::Driver drv("", target_triple, diags);
-#if LLVM_MAJOR_VERSION >= 4
+#if LLVM_VERSION_MAJOR >= 4
if (target_triple == "x86_64-unknown-linux-gnu" || target_triple == "aarch64-unknown-linux-gnu")
flags_cstr.push_back("-fno-jump-tables");
#endif
diff --git a/src/cc/json_map_decl_visitor.cc b/src/cc/json_map_decl_visitor.cc
index 53896199..22ed03ab 100644
--- a/src/cc/json_map_decl_visitor.cc
+++ b/src/cc/json_map_decl_visitor.cc
@@ -21,6 +21,7 @@
#include <clang/AST/RecordLayout.h>
#include <clang/AST/RecursiveASTVisitor.h>
#include <llvm/ADT/StringExtras.h>
+#include <llvm/Config/llvm-config.h>
#include "common.h"
#include "table_desc.h"
@@ -80,7 +81,7 @@ void BMapDeclVisitor::genJSONForField(FieldDecl *F) {
result_ += "[";
TraverseDecl(F);
if (const ConstantArrayType *T = dyn_cast<ConstantArrayType>(F->getType()))
-#if LLVM_MAJOR_VERSION >= 13
+#if LLVM_VERSION_MAJOR >= 13
result_ += ", [" + toString(T->getSize(), 10, false) + "]";
#else
result_ += ", [" + T->getSize().toString(10, false) + "]";
diff --git a/tests/cc/CMakeLists.txt b/tests/cc/CMakeLists.txt
index b45f2369..b4dd3f9a 100644
--- a/tests/cc/CMakeLists.txt
+++ b/tests/cc/CMakeLists.txt
@@ -9,6 +9,7 @@ else()
include_directories(${PROJECT_SOURCE_DIR}/src/cc/libbpf/include/uapi)
endif()
include_directories(${PROJECT_SOURCE_DIR}/tests/python/include)
+include_directories(${LLVM_INCLUDE_DIRS})
add_executable(test_static test_static.c)
if(NOT CMAKE_USE_LIBBPF_PACKAGE)