17 Star 4 Fork 58

src-openEuler / llvm

 / 详情

clang编译ebpf时使用原子操作函数__sync_fetch_and_add并取返回值时会崩溃

已完成
任务
创建于  
2022-11-21 17:24

系统版本: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

  1.  <eof> parser at end of file
    
  2.  Code generation
    
  3.  Running pass 'Function Pass Manager' on module 'test.c'.
    
  4.  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]#

评论 (4)

L.X. 创建了任务
L.X. 里程碑设置为openEuler-22.03-LTS-SP1
L.X. 添加了
 
20.03-LTS-SP1
标签
L.X. 移除了
 
20.03-LTS-SP1
标签
展开全部操作日志

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

openeuler-ci-bot 添加了
 
sig/Compiler
标签

@L.X.

  • 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   

@L.X. can we close this issue now?

当前5.10内核无法支持ebpf中的fetch_and_add的全部能力,issue先行关闭,内核更新后再尝试此功能

L.X. 任务状态待办的 修改为已完成

登录 后才可以发表评论

状态
负责人
项目
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
预计工期 (小时)
参与者(4)
5329419 openeuler ci bot 1632792936 10066618 cf zhao 1683191126 1568919 bitcoffee 1668093949
1
https://gitee.com/src-openeuler/llvm.git
git@gitee.com:src-openeuler/llvm.git
src-openeuler
llvm
llvm

搜索帮助

53164aa7 5694891 3bd8fe86 5694891