Skip to content

Commit 0dc4282

Browse files
authored
Drop support for LLVM 10 and below (#5202)
It has been 3 years since Dave propose to bump minimun LLVM version to 11. The CI is ready. So let's move on. Closes #3808. Signed-off-by: Hengqi Chen <[email protected]>
1 parent 10ee9d9 commit 0dc4282

File tree

8 files changed

+11
-106
lines changed

8 files changed

+11
-106
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ if(NOT PYTHON_ONLY)
144144

145145
# clang is linked as a library, but the library path searching is
146146
# primitively supported, unlike libLLVM
147-
set(CLANG_SEARCH "/opt/local/llvm/lib;/usr/lib/llvm-3.7/lib;${LLVM_LIBRARY_DIRS}")
147+
set(CLANG_SEARCH "/opt/local/llvm/lib;${LLVM_LIBRARY_DIRS}")
148148
find_library(libclangAnalysis NAMES clangAnalysis clang-cpp HINTS ${CLANG_SEARCH})
149149
find_library(libclangAST NAMES clangAST clang-cpp HINTS ${CLANG_SEARCH})
150150
find_library(libclangBasic NAMES clangBasic clang-cpp HINTS ${CLANG_SEARCH})

cmake/clang_libs.cmake

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ if(ENABLE_LLVM_SHARED)
22
set(llvm_libs "LLVM")
33
else()
44
set(llvm_raw_libs bitwriter bpfcodegen debuginfodwarf irreader linker
5-
mcjit objcarcopts option passes lto)
5+
mcjit objcarcopts option passes lto bpfasmparser bpfdisassembler)
66
if(ENABLE_LLVM_NATIVECODEGEN)
77
set(llvm_raw_libs ${llvm_raw_libs} nativecodegen)
88
endif()
@@ -18,10 +18,6 @@ list(FIND LLVM_AVAILABLE_LIBS "LLVMFrontendOpenMP" _llvm_frontendOpenMP)
1818
if (${_llvm_frontendOpenMP} GREATER -1)
1919
list(APPEND llvm_raw_libs frontendopenmp)
2020
endif()
21-
if (${LLVM_PACKAGE_VERSION} VERSION_EQUAL 6 OR ${LLVM_PACKAGE_VERSION} VERSION_GREATER 6)
22-
list(APPEND llvm_raw_libs bpfasmparser)
23-
list(APPEND llvm_raw_libs bpfdisassembler)
24-
endif()
2521
if (${LLVM_PACKAGE_VERSION} VERSION_EQUAL 15 OR ${LLVM_PACKAGE_VERSION} VERSION_GREATER 15)
2622
list(APPEND llvm_raw_libs windowsdriver)
2723
endif()
@@ -43,11 +39,8 @@ else()
4339
set(clang_libs
4440
${libclangFrontend}
4541
${libclangSerialization}
46-
${libclangDriver})
47-
48-
if (${LLVM_PACKAGE_VERSION} VERSION_EQUAL 8 OR ${LLVM_PACKAGE_VERSION} VERSION_GREATER 8)
49-
list(APPEND clang_libs ${libclangASTMatchers})
50-
endif()
42+
${libclangDriver}
43+
${libclangASTMatchers})
5144

5245
list(APPEND clang_libs
5346
${libclangParse}

src/cc/bcc_debug.cc

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,9 @@ void SourceDebugger::dump() {
127127
errs() << "Debug Error: cannot get register info\n";
128128
return;
129129
}
130-
#if LLVM_VERSION_MAJOR >= 10
130+
131131
MCTargetOptions MCOptions;
132132
std::unique_ptr<MCAsmInfo> MAI(T->createMCAsmInfo(*MRI, TripleStr, MCOptions));
133-
#else
134-
std::unique_ptr<MCAsmInfo> MAI(T->createMCAsmInfo(*MRI, TripleStr));
135-
#endif
136133
if (!MAI) {
137134
errs() << "Debug Error: cannot get assembly info\n";
138135
return;
@@ -174,13 +171,7 @@ void SourceDebugger::dump() {
174171
return;
175172
}
176173

177-
// bcc has only one compilation unit
178-
// getCompileUnitAtIndex() was gone in llvm 8.0 (https://reviews.llvm.org/D49741)
179-
#if LLVM_VERSION_MAJOR >= 8
180174
DWARFCompileUnit *CU = cast<DWARFCompileUnit>(DwarfCtx->getUnitAtIndex(0));
181-
#else
182-
DWARFCompileUnit *CU = DwarfCtx->getCompileUnitAtIndex(0);
183-
#endif
184175
if (!CU) {
185176
errs() << "Debug Error: dwarf context failed to get compile unit\n";
186177
return;
@@ -202,15 +193,15 @@ void SourceDebugger::dump() {
202193
uint64_t Size;
203194
uint8_t *FuncStart = info.start_;
204195
uint64_t FuncSize = info.size_;
205-
#if LLVM_VERSION_MAJOR >= 9
196+
206197
auto section = sections_.find(info.section_);
207198
if (section == sections_.end()) {
208199
errs() << "Debug Error: no section entry for section " << info.section_
209200
<< '\n';
210201
return;
211202
}
212203
unsigned SectionID = get<2>(section->second);
213-
#endif
204+
214205
ArrayRef<uint8_t> Data(FuncStart, FuncSize);
215206
uint32_t CurrentSrcLine = 0;
216207

@@ -219,24 +210,15 @@ void SourceDebugger::dump() {
219210
string src_dbg_str;
220211
llvm::raw_string_ostream os(src_dbg_str);
221212
for (uint64_t Index = 0; Index < FuncSize; Index += Size) {
222-
#if LLVM_VERSION_MAJOR >= 10
223213
S = DisAsm->getInstruction(Inst, Size, Data.slice(Index), Index, nulls());
224-
#else
225-
S = DisAsm->getInstruction(Inst, Size, Data.slice(Index), Index, nulls(),
226-
nulls());
227-
#endif
228214
if (S != MCDisassembler::Success) {
229215
os << "Debug Error: disassembler failed: " << std::to_string(S) << '\n';
230216
break;
231217
} else {
232218
DILineInfo LineInfo;
233219

234220
LineTable->getFileLineInfoForAddress(
235-
#if LLVM_VERSION_MAJOR >= 9
236221
{(uint64_t)FuncStart + Index, SectionID},
237-
#else
238-
(uint64_t)FuncStart + Index,
239-
#endif
240222
#if LLVM_VERSION_MAJOR >= 20
241223
false,
242224
#endif
@@ -248,11 +230,7 @@ void SourceDebugger::dump() {
248230
os);
249231
os << format("%4" PRIu64 ":", Index >> 3) << '\t';
250232
dumpBytes(Data.slice(Index, Size), os);
251-
#if LLVM_VERSION_MAJOR >= 10
252233
IP->printInst(&Inst, 0, "", *STI, os);
253-
#else
254-
IP->printInst(&Inst, os, "", *STI);
255-
#endif
256234
os << '\n';
257235
}
258236
}

src/cc/bcc_debug.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,6 @@ class SourceDebugger {
2929
prog_func_info_(prog_func_info),
3030
mod_src_(mod_src),
3131
src_dbg_fmap_(src_dbg_fmap) {}
32-
// Only support dump for llvm 6.x and later.
33-
//
34-
// The llvm 5.x, but not earlier versions, also supports create
35-
// a dwarf context for source debugging based
36-
// on a set of in-memory sections with slightly different interfaces.
37-
// FIXME: possibly to support 5.x
38-
//
39-
#if LLVM_VERSION_MAJOR >= 6
4032
void dump();
4133

4234
private:
@@ -47,10 +39,6 @@ class SourceDebugger {
4739
uint32_t &CurrentSrcLine, llvm::raw_ostream &os);
4840
void getDebugSections(
4941
llvm::StringMap<std::unique_ptr<llvm::MemoryBuffer>> &DebugSections);
50-
#else
51-
void dump() {
52-
}
53-
#endif
5442

5543
private:
5644
llvm::Module *mod_;

src/cc/bpf_module.cc

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,10 @@ class MyMemoryManager : public SectionMemoryManager {
123123
if (!section)
124124
continue;
125125

126-
#if LLVM_VERSION_MAJOR >= 10
127126
auto sec_name = section.get()->getName();
128127
if (!sec_name)
129128
continue;
130-
#else
131-
llvm::StringRef sec_name_obj;
132-
if (!section.get()->getName(sec_name_obj))
133-
continue;
134129

135-
auto sec_name = &sec_name_obj;
136-
#endif
137130
info->section_ = sec_name->str();
138131
info->size_ = ss.second;
139132
}
@@ -160,11 +153,9 @@ BPFModule::BPFModule(unsigned flags, TableStorage *ts, bool rw_engine_enabled,
160153
LLVMInitializeBPFTargetMC();
161154
LLVMInitializeBPFTargetInfo();
162155
LLVMInitializeBPFAsmPrinter();
163-
#if LLVM_VERSION_MAJOR >= 6
164156
LLVMInitializeBPFAsmParser();
165157
if (flags & DEBUG_SOURCE)
166158
LLVMInitializeBPFDisassembler();
167-
#endif
168159
LLVMLinkInMCJIT(); /* call empty function to force linking of MCJIT */
169160
if (!ts_) {
170161
local_ts_ = createSharedTableStorage();
@@ -553,19 +544,12 @@ int BPFModule::finalize() {
553544
*sections_p;
554545

555546
mod->setTargetTriple("bpf-pc-linux");
556-
#if LLVM_VERSION_MAJOR >= 11
557547
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
558548
mod->setDataLayout("e-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
559549
#else
560550
mod->setDataLayout("E-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
561551
#endif
562-
#else
563-
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
564-
mod->setDataLayout("e-m:e-p:64:64-i64:64-n32:64-S128");
565-
#else
566-
mod->setDataLayout("E-m:e-p:64:64-i64:64-n32:64-S128");
567-
#endif
568-
#endif
552+
569553
sections_p = rw_engine_enabled_ ? &sections_ : &tmp_sections;
570554

571555
string err;

src/cc/frontends/clang/b_frontend_action.cc

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -758,11 +758,7 @@ bool ProbeVisitor::IsContextMemberExpr(Expr *E) {
758758

759759
SourceRange
760760
ProbeVisitor::expansionRange(SourceRange range) {
761-
#if LLVM_VERSION_MAJOR >= 7
762761
return rewriter_.getSourceMgr().getExpansionRange(range).getAsRange();
763-
#else
764-
return rewriter_.getSourceMgr().getExpansionRange(range);
765-
#endif
766762
}
767763

768764
SourceLocation
@@ -1431,11 +1427,7 @@ bool BTypeVisitor::VisitImplicitCastExpr(ImplicitCastExpr *E) {
14311427

14321428
SourceRange
14331429
BTypeVisitor::expansionRange(SourceRange range) {
1434-
#if LLVM_VERSION_MAJOR >= 7
14351430
return rewriter_.getSourceMgr().getExpansionRange(range).getAsRange();
1436-
#else
1437-
return rewriter_.getSourceMgr().getExpansionRange(range);
1438-
#endif
14391431
}
14401432

14411433
template <unsigned N>
@@ -1454,17 +1446,10 @@ int64_t BTypeVisitor::getFieldValue(VarDecl *Decl, FieldDecl *FDecl, int64_t Ori
14541446
unsigned idx = FDecl->getFieldIndex();
14551447

14561448
if (auto I = dyn_cast_or_null<InitListExpr>(Decl->getInit())) {
1457-
#if LLVM_VERSION_MAJOR >= 8
14581449
Expr::EvalResult res;
14591450
if (I->getInit(idx)->EvaluateAsInt(res, C)) {
14601451
return res.Val.getInt().getExtValue();
14611452
}
1462-
#else
1463-
llvm::APSInt res;
1464-
if (I->getInit(idx)->EvaluateAsInt(res, C)) {
1465-
return res.getExtValue();
1466-
}
1467-
#endif
14681453
}
14691454

14701455
return OrigFValue;
@@ -1871,17 +1856,10 @@ void BFrontendAction::EndSourceFileAction() {
18711856

18721857
if (flags_ & DEBUG_PREPROCESSOR)
18731858
rewriter_->getEditBuffer(rewriter_->getSourceMgr().getMainFileID()).write(llvm::errs());
1874-
#if LLVM_VERSION_MAJOR >= 9
1859+
18751860
llvm::raw_string_ostream tmp_os(mod_src_);
18761861
rewriter_->getEditBuffer(rewriter_->getSourceMgr().getMainFileID())
18771862
.write(tmp_os);
1878-
#else
1879-
if (flags_ & DEBUG_SOURCE) {
1880-
llvm::raw_string_ostream tmp_os(mod_src_);
1881-
rewriter_->getEditBuffer(rewriter_->getSourceMgr().getMainFileID())
1882-
.write(tmp_os);
1883-
}
1884-
#endif
18851863

18861864
for (auto func : func_range_) {
18871865
auto f = func.first;

src/cc/frontends/clang/frontend_action_common.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,5 @@
1515
*/
1616
#include <llvm/Config/llvm-config.h>
1717

18-
#if LLVM_VERSION_MAJOR >= 8
1918
#define GET_BEGINLOC(E) ((E)->getBeginLoc())
2019
#define GET_ENDLOC(E) ((E)->getEndLoc())
21-
#else
22-
#define GET_BEGINLOC(E) ((E)->getLocStart())
23-
#define GET_ENDLOC(E) ((E)->getLocEnd())
24-
#endif

src/cc/frontends/clang/loader.cc

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,7 @@ static int CreateFromArgs(clang::CompilerInvocation &invocation,
179179
const llvm::opt::ArgStringList &ccargs,
180180
clang::DiagnosticsEngine &diags)
181181
{
182-
#if LLVM_VERSION_MAJOR >= 10
183182
return clang::CompilerInvocation::CreateFromArgs(invocation, ccargs, diags);
184-
#else
185-
return clang::CompilerInvocation::CreateFromArgs(
186-
invocation, const_cast<const char **>(ccargs.data()),
187-
const_cast<const char **>(ccargs.data()) + ccargs.size(), diags);
188-
#endif
189183
}
190184

191185
}
@@ -288,13 +282,10 @@ int ClangLoader::parse(
288282
vector<string> kflags;
289283
if (kbuild_helper.get_flags(un.machine, &kflags))
290284
return -1;
291-
#if LLVM_VERSION_MAJOR >= 9
285+
292286
flags_cstr.push_back("-g");
293287
flags_cstr.push_back("-gdwarf-4");
294-
#else
295-
if (flags_ & DEBUG_SOURCE)
296-
flags_cstr.push_back("-g");
297-
#endif
288+
298289
for (auto it = kflags.begin(); it != kflags.end(); ++it)
299290
flags_cstr.push_back(it->c_str());
300291

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

419-
#if LLVM_VERSION_MAJOR >= 4
420410
if (target_triple == "x86_64-unknown-linux-gnu" || target_triple == "aarch64-unknown-linux-gnu")
421411
flags_cstr.push_back("-fno-jump-tables");
422-
#endif
423412

424413
drv.setTitle("bcc-clang-driver");
425414
drv.setCheckInputsExist(false);

0 commit comments

Comments
 (0)