Skip to content

Commit c6bde0b

Browse files
Yonghong Songyonghong-song
authored andcommitted
Fix various build issues with latest llvm18
Latest llvm18 cannot build with bcc now. There are 3 issues: - In IRBuilder, getInt8PtrTy() renamed to getPtrTy(). - Newly introdeuced clang library libclangAPINotes.a. - Newly introduced llvm library libLLVMFrontendDriver.a This patch fixed the above three issues so bcc can be built with llvm18 successfully. I then tried a few bcc tools and they all works fine. Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
1 parent 0ae3b12 commit c6bde0b

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ if(NOT PYTHON_ONLY)
163163
find_library(libclangSupport NAMES clangSupport clang-cpp HINTS ${CLANG_SEARCH})
164164
endif()
165165

166+
if(${LLVM_PACKAGE_VERSION} VERSION_EQUAL 18 OR ${LLVM_PACKAGE_VERSION} VERSION_GREATER 18)
167+
find_library(libclangAPINotes NAMES clangAPINotes clang-cpp HINTS ${CLANG_SEARCH})
168+
endif()
169+
166170
find_library(libclang-shared libclang-cpp.so HINTS ${CLANG_SEARCH})
167171

168172
if(libclangBasic STREQUAL "libclangBasic-NOTFOUND")

cmake/clang_libs.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ endif()
2828
if (${LLVM_PACKAGE_VERSION} VERSION_EQUAL 16 OR ${LLVM_PACKAGE_VERSION} VERSION_GREATER 16)
2929
list(APPEND llvm_raw_libs frontendhlsl)
3030
endif()
31+
if (${LLVM_PACKAGE_VERSION} VERSION_EQUAL 18 OR ${LLVM_PACKAGE_VERSION} VERSION_GREATER 18)
32+
list(APPEND llvm_raw_libs frontenddriver)
33+
endif()
3134

3235
llvm_map_components_to_libnames(_llvm_libs ${llvm_raw_libs})
3336
llvm_expand_dependencies(llvm_libs ${_llvm_libs})
@@ -60,6 +63,10 @@ list(APPEND clang_libs
6063
list(APPEND clang_libs ${libclangSupport})
6164
# endif()
6265

66+
if (${LLVM_PACKAGE_VERSION} VERSION_EQUAL 18 OR ${LLVM_PACKAGE_VERSION} VERSION_GREATER 18)
67+
list(APPEND clang_libs ${libclangAPINotes})
68+
endif()
69+
6370
list(APPEND clang_libs
6471
${libclangBasic})
6572
endif()

src/cc/bpf_module_rw_engine.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ static void debug_printf(Module *mod, IRBuilder<> &B, const string &fmt, vector<
8282
args.insert(args.begin(), B.getInt64((uintptr_t)stderr));
8383
Function *fprintf_fn = mod->getFunction("fprintf");
8484
if (!fprintf_fn) {
85+
#if LLVM_VERSION_MAJOR >= 18
86+
vector<Type *> fprintf_fn_args({B.getInt64Ty(), B.getPtrTy()});
87+
#else
8588
vector<Type *> fprintf_fn_args({B.getInt64Ty(), B.getInt8PtrTy()});
89+
#endif
8690
FunctionType *fprintf_fn_type = FunctionType::get(B.getInt32Ty(), fprintf_fn_args, /*isvarArg=*/true);
8791
fprintf_fn = Function::Create(fprintf_fn_type, GlobalValue::ExternalLinkage, "fprintf", mod);
8892
fprintf_fn->setCallingConv(CallingConv::C);
@@ -267,7 +271,11 @@ string BPFModule::make_reader(Module *mod, Type *type) {
267271
IRBuilder<> B(*ctx_);
268272

269273
FunctionType *sscanf_fn_type = FunctionType::get(
274+
#if LLVM_VERSION_MAJOR >= 18
275+
B.getInt32Ty(), {B.getPtrTy(), B.getPtrTy()}, /*isVarArg=*/true);
276+
#else
270277
B.getInt32Ty(), {B.getInt8PtrTy(), B.getInt8PtrTy()}, /*isVarArg=*/true);
278+
#endif
271279
Function *sscanf_fn = mod->getFunction("sscanf");
272280
if (!sscanf_fn) {
273281
sscanf_fn = Function::Create(sscanf_fn_type, GlobalValue::ExternalLinkage,
@@ -277,7 +285,11 @@ string BPFModule::make_reader(Module *mod, Type *type) {
277285
}
278286

279287
string name = "reader" + std::to_string(readers_.size());
288+
#if LLVM_VERSION_MAJOR >= 18
289+
vector<Type *> fn_args({B.getPtrTy(), PointerType::getUnqual(type)});
290+
#else
280291
vector<Type *> fn_args({B.getInt8PtrTy(), PointerType::getUnqual(type)});
292+
#endif
281293
FunctionType *fn_type = FunctionType::get(B.getInt32Ty(), fn_args, /*isVarArg=*/false);
282294
Function *fn =
283295
Function::Create(fn_type, GlobalValue::ExternalLinkage, name, mod);
@@ -293,7 +305,11 @@ string BPFModule::make_reader(Module *mod, Type *type) {
293305
B.SetInsertPoint(label_entry);
294306

295307
Value *nread = B.CreateAlloca(B.getInt32Ty());
308+
#if LLVM_VERSION_MAJOR >= 18
309+
Value *sptr = B.CreateAlloca(B.getPtrTy());
310+
#else
296311
Value *sptr = B.CreateAlloca(B.getInt8PtrTy());
312+
#endif
297313
map<string, Value *> locals{{"nread", nread}, {"sptr", sptr}};
298314
B.CreateStore(arg_in, sptr);
299315
vector<Value *> args({nullptr, nullptr});
@@ -337,7 +353,11 @@ string BPFModule::make_writer(Module *mod, Type *type) {
337353
IRBuilder<> B(*ctx_);
338354

339355
string name = "writer" + std::to_string(writers_.size());
356+
#if LLVM_VERSION_MAJOR >= 18
357+
vector<Type *> fn_args({B.getPtrTy(), B.getInt64Ty(), PointerType::getUnqual(type)});
358+
#else
340359
vector<Type *> fn_args({B.getInt8PtrTy(), B.getInt64Ty(), PointerType::getUnqual(type)});
360+
#endif
341361
FunctionType *fn_type = FunctionType::get(B.getInt32Ty(), fn_args, /*isVarArg=*/false);
342362
Function *fn =
343363
Function::Create(fn_type, GlobalValue::ExternalLinkage, name, mod);
@@ -369,7 +389,11 @@ string BPFModule::make_writer(Module *mod, Type *type) {
369389
if (0)
370390
debug_printf(mod, B, "%d %p %p\n", vector<Value *>({arg_len, arg_out, arg_in}));
371391

392+
#if LLVM_VERSION_MAJOR >= 18
393+
vector<Type *> snprintf_fn_args({B.getPtrTy(), B.getInt64Ty(), B.getPtrTy()});
394+
#else
372395
vector<Type *> snprintf_fn_args({B.getInt8PtrTy(), B.getInt64Ty(), B.getInt8PtrTy()});
396+
#endif
373397
FunctionType *snprintf_fn_type = FunctionType::get(B.getInt32Ty(), snprintf_fn_args, /*isVarArg=*/true);
374398
Function *snprintf_fn = mod->getFunction("snprintf");
375399
if (!snprintf_fn)

0 commit comments

Comments
 (0)