Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop support for LLVM 10 and below #5202

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ if(NOT PYTHON_ONLY)

# clang is linked as a library, but the library path searching is
# primitively supported, unlike libLLVM
set(CLANG_SEARCH "/opt/local/llvm/lib;/usr/lib/llvm-3.7/lib;${LLVM_LIBRARY_DIRS}")
set(CLANG_SEARCH "/opt/local/llvm/lib;${LLVM_LIBRARY_DIRS}")
find_library(libclangAnalysis NAMES clangAnalysis clang-cpp HINTS ${CLANG_SEARCH})
find_library(libclangAST NAMES clangAST clang-cpp HINTS ${CLANG_SEARCH})
find_library(libclangBasic NAMES clangBasic clang-cpp HINTS ${CLANG_SEARCH})
Expand Down
13 changes: 3 additions & 10 deletions cmake/clang_libs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ if(ENABLE_LLVM_SHARED)
set(llvm_libs "LLVM")
else()
set(llvm_raw_libs bitwriter bpfcodegen debuginfodwarf irreader linker
mcjit objcarcopts option passes lto)
mcjit objcarcopts option passes lto bpfasmparser bpfdisassembler)
if(ENABLE_LLVM_NATIVECODEGEN)
set(llvm_raw_libs ${llvm_raw_libs} nativecodegen)
endif()
Expand All @@ -18,10 +18,6 @@ list(FIND LLVM_AVAILABLE_LIBS "LLVMFrontendOpenMP" _llvm_frontendOpenMP)
if (${_llvm_frontendOpenMP} GREATER -1)
list(APPEND llvm_raw_libs frontendopenmp)
endif()
if (${LLVM_PACKAGE_VERSION} VERSION_EQUAL 6 OR ${LLVM_PACKAGE_VERSION} VERSION_GREATER 6)
list(APPEND llvm_raw_libs bpfasmparser)
list(APPEND llvm_raw_libs bpfdisassembler)
endif()
if (${LLVM_PACKAGE_VERSION} VERSION_EQUAL 15 OR ${LLVM_PACKAGE_VERSION} VERSION_GREATER 15)
list(APPEND llvm_raw_libs windowsdriver)
endif()
Expand All @@ -43,11 +39,8 @@ else()
set(clang_libs
${libclangFrontend}
${libclangSerialization}
${libclangDriver})

if (${LLVM_PACKAGE_VERSION} VERSION_EQUAL 8 OR ${LLVM_PACKAGE_VERSION} VERSION_GREATER 8)
list(APPEND clang_libs ${libclangASTMatchers})
endif()
${libclangDriver}
${libclangASTMatchers})

list(APPEND clang_libs
${libclangParse}
Expand Down
28 changes: 3 additions & 25 deletions src/cc/bcc_debug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,9 @@ void SourceDebugger::dump() {
errs() << "Debug Error: cannot get register info\n";
return;
}
#if LLVM_VERSION_MAJOR >= 10

MCTargetOptions MCOptions;
std::unique_ptr<MCAsmInfo> MAI(T->createMCAsmInfo(*MRI, TripleStr, MCOptions));
#else
std::unique_ptr<MCAsmInfo> MAI(T->createMCAsmInfo(*MRI, TripleStr));
#endif
if (!MAI) {
errs() << "Debug Error: cannot get assembly info\n";
return;
Expand Down Expand Up @@ -174,13 +171,7 @@ void SourceDebugger::dump() {
return;
}

// bcc has only one compilation unit
// getCompileUnitAtIndex() was gone in llvm 8.0 (https://reviews.llvm.org/D49741)
#if LLVM_VERSION_MAJOR >= 8
DWARFCompileUnit *CU = cast<DWARFCompileUnit>(DwarfCtx->getUnitAtIndex(0));
#else
DWARFCompileUnit *CU = DwarfCtx->getCompileUnitAtIndex(0);
#endif
if (!CU) {
errs() << "Debug Error: dwarf context failed to get compile unit\n";
return;
Expand All @@ -202,15 +193,15 @@ void SourceDebugger::dump() {
uint64_t Size;
uint8_t *FuncStart = info.start_;
uint64_t FuncSize = info.size_;
#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_
<< '\n';
return;
}
unsigned SectionID = get<2>(section->second);
#endif

ArrayRef<uint8_t> Data(FuncStart, FuncSize);
uint32_t CurrentSrcLine = 0;

Expand All @@ -219,24 +210,15 @@ 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_VERSION_MAJOR >= 10
S = DisAsm->getInstruction(Inst, Size, Data.slice(Index), Index, nulls());
#else
S = DisAsm->getInstruction(Inst, Size, Data.slice(Index), Index, nulls(),
nulls());
#endif
if (S != MCDisassembler::Success) {
os << "Debug Error: disassembler failed: " << std::to_string(S) << '\n';
break;
} else {
DILineInfo LineInfo;

LineTable->getFileLineInfoForAddress(
#if LLVM_VERSION_MAJOR >= 9
{(uint64_t)FuncStart + Index, SectionID},
#else
(uint64_t)FuncStart + Index,
#endif
#if LLVM_VERSION_MAJOR >= 20
false,
#endif
Expand All @@ -248,11 +230,7 @@ void SourceDebugger::dump() {
os);
os << format("%4" PRIu64 ":", Index >> 3) << '\t';
dumpBytes(Data.slice(Index, Size), os);
#if LLVM_VERSION_MAJOR >= 10
IP->printInst(&Inst, 0, "", *STI, os);
#else
IP->printInst(&Inst, os, "", *STI);
#endif
os << '\n';
}
}
Expand Down
12 changes: 0 additions & 12 deletions src/cc/bcc_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,6 @@ class SourceDebugger {
prog_func_info_(prog_func_info),
mod_src_(mod_src),
src_dbg_fmap_(src_dbg_fmap) {}
// Only support dump for llvm 6.x and later.
//
// The llvm 5.x, but not earlier versions, also supports create
// a dwarf context for source debugging based
// on a set of in-memory sections with slightly different interfaces.
// FIXME: possibly to support 5.x
//
#if LLVM_VERSION_MAJOR >= 6
void dump();

private:
Expand All @@ -47,10 +39,6 @@ class SourceDebugger {
uint32_t &CurrentSrcLine, llvm::raw_ostream &os);
void getDebugSections(
llvm::StringMap<std::unique_ptr<llvm::MemoryBuffer>> &DebugSections);
#else
void dump() {
}
#endif

private:
llvm::Module *mod_;
Expand Down
18 changes: 1 addition & 17 deletions src/cc/bpf_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,10 @@ class MyMemoryManager : public SectionMemoryManager {
if (!section)
continue;

#if LLVM_VERSION_MAJOR >= 10
auto sec_name = section.get()->getName();
if (!sec_name)
continue;
#else
llvm::StringRef sec_name_obj;
if (!section.get()->getName(sec_name_obj))
continue;

auto sec_name = &sec_name_obj;
#endif
info->section_ = sec_name->str();
info->size_ = ss.second;
}
Expand All @@ -160,11 +153,9 @@ BPFModule::BPFModule(unsigned flags, TableStorage *ts, bool rw_engine_enabled,
LLVMInitializeBPFTargetMC();
LLVMInitializeBPFTargetInfo();
LLVMInitializeBPFAsmPrinter();
#if LLVM_VERSION_MAJOR >= 6
LLVMInitializeBPFAsmParser();
if (flags & DEBUG_SOURCE)
LLVMInitializeBPFDisassembler();
#endif
LLVMLinkInMCJIT(); /* call empty function to force linking of MCJIT */
if (!ts_) {
local_ts_ = createSharedTableStorage();
Expand Down Expand Up @@ -553,19 +544,12 @@ int BPFModule::finalize() {
*sections_p;

mod->setTargetTriple("bpf-pc-linux");
#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
mod->setDataLayout("E-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
#endif
#else
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
mod->setDataLayout("e-m:e-p:64:64-i64:64-n32:64-S128");
#else
mod->setDataLayout("E-m:e-p:64:64-i64:64-n32:64-S128");
#endif
#endif

sections_p = rw_engine_enabled_ ? &sections_ : &tmp_sections;

string err;
Expand Down
24 changes: 1 addition & 23 deletions src/cc/frontends/clang/b_frontend_action.cc
Original file line number Diff line number Diff line change
Expand Up @@ -758,11 +758,7 @@ bool ProbeVisitor::IsContextMemberExpr(Expr *E) {

SourceRange
ProbeVisitor::expansionRange(SourceRange range) {
#if LLVM_VERSION_MAJOR >= 7
return rewriter_.getSourceMgr().getExpansionRange(range).getAsRange();
#else
return rewriter_.getSourceMgr().getExpansionRange(range);
#endif
}

SourceLocation
Expand Down Expand Up @@ -1431,11 +1427,7 @@ bool BTypeVisitor::VisitImplicitCastExpr(ImplicitCastExpr *E) {

SourceRange
BTypeVisitor::expansionRange(SourceRange range) {
#if LLVM_VERSION_MAJOR >= 7
return rewriter_.getSourceMgr().getExpansionRange(range).getAsRange();
#else
return rewriter_.getSourceMgr().getExpansionRange(range);
#endif
}

template <unsigned N>
Expand All @@ -1454,17 +1446,10 @@ 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_VERSION_MAJOR >= 8
Expr::EvalResult res;
if (I->getInit(idx)->EvaluateAsInt(res, C)) {
return res.Val.getInt().getExtValue();
}
#else
llvm::APSInt res;
if (I->getInit(idx)->EvaluateAsInt(res, C)) {
return res.getExtValue();
}
#endif
}

return OrigFValue;
Expand Down Expand Up @@ -1871,17 +1856,10 @@ void BFrontendAction::EndSourceFileAction() {

if (flags_ & DEBUG_PREPROCESSOR)
rewriter_->getEditBuffer(rewriter_->getSourceMgr().getMainFileID()).write(llvm::errs());
#if LLVM_VERSION_MAJOR >= 9

llvm::raw_string_ostream tmp_os(mod_src_);
rewriter_->getEditBuffer(rewriter_->getSourceMgr().getMainFileID())
.write(tmp_os);
#else
if (flags_ & DEBUG_SOURCE) {
llvm::raw_string_ostream tmp_os(mod_src_);
rewriter_->getEditBuffer(rewriter_->getSourceMgr().getMainFileID())
.write(tmp_os);
}
#endif

for (auto func : func_range_) {
auto f = func.first;
Expand Down
5 changes: 0 additions & 5 deletions src/cc/frontends/clang/frontend_action_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,5 @@
*/
#include <llvm/Config/llvm-config.h>

#if LLVM_VERSION_MAJOR >= 8
#define GET_BEGINLOC(E) ((E)->getBeginLoc())
#define GET_ENDLOC(E) ((E)->getEndLoc())
#else
#define GET_BEGINLOC(E) ((E)->getLocStart())
#define GET_ENDLOC(E) ((E)->getLocEnd())
#endif
15 changes: 2 additions & 13 deletions src/cc/frontends/clang/loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,7 @@ static int CreateFromArgs(clang::CompilerInvocation &invocation,
const llvm::opt::ArgStringList &ccargs,
clang::DiagnosticsEngine &diags)
{
#if LLVM_VERSION_MAJOR >= 10
return clang::CompilerInvocation::CreateFromArgs(invocation, ccargs, diags);
#else
return clang::CompilerInvocation::CreateFromArgs(
invocation, const_cast<const char **>(ccargs.data()),
const_cast<const char **>(ccargs.data()) + ccargs.size(), diags);
#endif
}

}
Expand Down Expand Up @@ -288,13 +282,10 @@ int ClangLoader::parse(
vector<string> kflags;
if (kbuild_helper.get_flags(un.machine, &kflags))
return -1;
#if LLVM_VERSION_MAJOR >= 9

flags_cstr.push_back("-g");
flags_cstr.push_back("-gdwarf-4");
#else
if (flags_ & DEBUG_SOURCE)
flags_cstr.push_back("-g");
#endif

for (auto it = kflags.begin(); it != kflags.end(); ++it)
flags_cstr.push_back(it->c_str());

Expand Down Expand Up @@ -416,10 +407,8 @@ int ClangLoader::do_compile(
string target_triple = get_clang_target();
driver::Driver drv("", target_triple, diags);

#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

drv.setTitle("bcc-clang-driver");
drv.setCheckInputsExist(false);
Expand Down
Loading