系统版本:22.03LTS,
llvm版本:llvm-12.0.1-2.oe2203.x86_64
编译ebpf时会崩溃退出
测试程序:
#include <stdio.h>
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
__u32 test_data32 = 0;
__u32 test1_result = 0;
SEC("sockops")
int bpf_sockmap(struct bpf_sock_ops *skops)
{
test1_result = __sync_fetch_and_add(&test_data32, 1);
bpf_printk("test");
return 0;
}
char _license[] SEC("license") = "GPL";
int _version SEC("version") = 1;
crash:
[root@k8s-node2 test]# clang -target bpf -D__x86_64__ -O2 -c test.c
fatal error: error in backend: Invalid usage of the XADD return value
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0. Program arguments: clang -target bpf -D__x86_64__ -O2 -c test.c
<eof> parser at end of file
Code generation
Running pass 'Function Pass Manager' on module 'test.c'.
Running pass 'BPF PreEmit Checking' on function '@bpf_sockmap'
#0 0x00007f5a6f33f0ad llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib64/libLLVM-12.so+0xbb70ad)
#1 0x00007f5a6f33cf84 llvm::sys::RunSignalHandlers() (/usr/lib64/libLLVM-12.so+0xbb4f84)
#2 0x00007f5a6f27e404 llvm::CrashRecoveryContext::HandleExit(int) (/usr/lib64/libLLVM-12.so+0xaf6404)
#3 0x00007f5a6f337a6e llvm::sys::Process::Exit(int, bool) (/usr/lib64/libLLVM-12.so+0xbafa6e)
#4 0x0000557621b6683c (/usr/bin/clang-12+0x1383c)
#5 0x00007f5a6f28d478 llvm::report_fatal_error(llvm::Twine const&, bool) (/usr/lib64/libLLVM-12.so+0xb05478)
#6 0x00007f5a6f28d5ba (/usr/lib64/libLLVM-12.so+0xb055ba)
#7 0x00007f5a71348bb5 (/usr/lib64/libLLVM-12.so+0x2bc0bb5)
#8 0x00007f5a6f6794a7 (/usr/lib64/libLLVM-12.so+0xef14a7)
#9 0x00007f5a6f460a1d llvm::FPPassManager::runOnFunction(llvm::Function&) (/usr/lib64/libLLVM-12.so+0xcd8a1d)
#10 0x00007f5a6f460e93 llvm::FPPassManager::runOnModule(llvm::Module&) (/usr/lib64/libLLVM-12.so+0xcd8e93)
#11 0x00007f5a6f460472 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/usr/lib64/libLLVM-12.so+0xcd8472)
#12 0x00007f5a75a98aec (/usr/lib64/libclang-cpp.so.12+0x178eaec)
#13 0x00007f5a75a9a403 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::DataLayout const&, llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_deletellvm::raw_pwrite_stream >) (/usr/lib64/libclang-cpp.so.12+0x1790403)
#14 0x00007f5a75d948b2 (/usr/lib64/libclang-cpp.so.12+0x1a8a8b2)
#15 0x00007f5a74cd5079 clang::ParseAST(clang::Sema&, bool, bool) (/usr/lib64/libclang-cpp.so.12+0x9cb079)
#16 0x00007f5a76442fd9 clang::FrontendAction::Execute() (/usr/lib64/libclang-cpp.so.12+0x2138fd9)
#17 0x00007f5a763ea1cb clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/lib64/libclang-cpp.so.12+0x20e01cb)
#18 0x00007f5a764b2f88 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/lib64/libclang-cpp.so.12+0x21a8f88)
#19 0x0000557621b6749c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/bin/clang-12+0x1449c)
#20 0x0000557621b64cd6 (/usr/bin/clang-12+0x11cd6)
#21 0x00007f5a7611ded5 (/usr/lib64/libclang-cpp.so.12+0x1e13ed5)
#22 0x00007f5a6f27e293 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/usr/lib64/libLLVM-12.so+0xaf6293)
#23 0x00007f5a7611efd6 (/usr/lib64/libclang-cpp.so.12+0x1e14fd6)
#24 0x00007f5a760f4b07 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&) const (/usr/lib64/libclang-cpp.so.12+0x1deab07)
#25 0x00007f5a760f52b6 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) const (/usr/lib64/libclang-cpp.so.12+0x1deb2b6)
#26 0x00007f5a760ff14b clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) (/usr/lib64/libclang-cpp.so.12+0x1df514b)
#27 0x0000557621b628e1 main (/usr/bin/clang-12+0xf8e1)
#28 0x00007f5a6e2e2210 (/usr/lib64/libc.so.6+0x2d210)
#29 0x00007f5a6e2e22bc __libc_start_main (/usr/lib64/libc.so.6+0x2d2bc)
#30 0x0000557621b64105 _start (/usr/bin/clang-12+0x11105)
[root@k8s-node2 test]#
Hi bitcoffee, welcome to the openEuler Community.
I'm the Bot here serving you. You can find the instructions on how to interact with me at Here.
If you have any questions, please contact the SIG: Compiler, and any of the maintainers: @Peilin Guo , @kuen , @Noah , @eastb233 , @cf-zhao , @周磊 , @编译小伙 , @stubCode
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
The cause of the problem is that the default instruction set of eBPF in llvm is "generic" (an alias of "v1"), which does not contain the alu32 feature. For details, see the llvm open-source commit https://reviews.llvm.org/D72184.
Therefore, there are two ways to solve this problem.
Method 1: Modify the source code. Change the data type from "__u32" to "__u64".
__u64 test_data32 = 0;
__u64 test1_result = 0;
Method 2: Add the compilation option "-mcpu=v3". "v3" contains the alu32 feature.
clang -target bpf -D__x86_64__ -O2 -c test.c -mcpu=v3
当前5.10内核无法支持ebpf中的fetch_and_add的全部能力,issue先行关闭,内核更新后再尝试此功能
登录 后才可以发表评论