Issue 129437
Summary [clang-17] [BPF] Crash to compile bpf code with .percpu section
Labels new issue
Assignees
Reporter Asphaltt
    I'm going to implement a new feature to support global percpu data in bpf. But it crashed to compile the following bpf code with clang-17:

```c
// SPDX-License-Identifier: GPL-2.0
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>

int data SEC(".percpu") = -1;
char run SEC(".percpu") = 0;
int nums[7] SEC(".percpu");
struct {
	char set;
	int i;
	int nums[7];
} struct_data SEC(".percpu") = {
	.set = 0,
	.i = -1,
};

SEC("raw_tp/task_rename")
int update_percpu_data(struct __sk_buff *skb)
{
	data = ""
	run = 1;
	nums[6] = 0xc0de;

	struct_data.i = 1;
	struct_data.set = 1;
	struct_data.nums[6] = 0xc0de;

	return 0;
}

char _license[] SEC("license") = "GPL";
```

Here is the crash log:

```crash
fatal error: error in backend: unable to write nop sequence of 3 bytes
  PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
  Stack dump:
  0.	Program arguments: clang-17 -g -Wall -Werror -D__TARGET_ARCH_x86 -mlittle-endian -I/tmp/work/bpf/bpf/tools/testing/selftests/bpf/tools/include -I/tmp/work/bpf/bpf/tools/testing/selftests/bpf -I/tmp/work/bpf/bpf/tools/include/uapi -I/tmp/work/bpf/bpf/tools/testing/selftests/usr/include -std=gnu11 -fno-strict-aliasing -Wno-compare-distinct-pointer-types -idirafter /usr/lib/llvm-17/lib/clang/17/include -idirafter /usr/local/include -idirafter /usr/include/x86_64-linux-gnu -idirafter /usr/include -DENABLE_ATOMICS_TESTS -O2 --target=bpfel -c progs/test_global_percpu_data.c -mcpu=v3 -o /tmp/work/bpf/bpf/tools/testing/selftests/bpf/test_global_percpu_data.bpf.o
 1.	<eof> parser at end of file
  2.	Code generation
  Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
    CLNG-BPF [test_progs] test_ksyms.bpf.o
    CLNG-BPF [test_progs] test_ksyms_module.bpf.o
    CLNG-BPF [test_progs] test_ksyms_weak.bpf.o
  0 libLLVM-17.so.1    0x00007fc1d214dbbf llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 63
  1 libLLVM-17.so.1    0x00007fc1d214bee9 llvm::sys::RunSignalHandlers() + 89
 2  libLLVM-17.so.1    0x00007fc1d209ce43
  3  libLLVM-17.so.1 0x00007fc1d209cdf2
  4  libLLVM-17.so.1    0x00007fc1d2148720 llvm::sys::Process::Exit(int, bool) + 48
  5  clang-17 0x00005575c8e4452b
  6  libLLVM-17.so.1    0x00007fc1d20aaffc llvm::report_fatal_error(llvm::Twine const&, bool) + 284
  7 libLLVM-17.so.1    0x00007fc1d3747512 llvm::MCAssembler::writeSectionData(llvm::raw_ostream&, llvm::MCSection const*, llvm::MCAsmLayout const&) const + 4658
  8  libLLVM-17.so.1 0x00007fc1d37324b9
  9  libLLVM-17.so.1    0x00007fc1d3730fd4
  10 libLLVM-17.so.1    0x00007fc1d3747eef llvm::MCAssembler::Finish() + 79
  11 libLLVM-17.so.1 0x00007fc1d3[767](https://github.com/kernel-patches/bpf/actions/runs/13483517280/job/37671704896?pr=8543#step:9:769)00a llvm::MCELFStreamer::finishImpl() + 202
  12 libLLVM-17.so.1 0x00007fc1d2a1f876 llvm::AsmPrinter::doFinalization(llvm::Module&) + 6214
 13 libLLVM-17.so.1    0x00007fc1d229d4d1 llvm::FPPassManager::doFinalization(llvm::Module&) + 65
  14 libLLVM-17.so.1 0x00007fc1d2297ca1 llvm::legacy::PassManagerImpl::run(llvm::Module&) + 1249
    CLNG-BPF [test_progs] test_l4lb.bpf.o
  15 libclang-cpp.so.17 0x00007fc1da51e2be clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>) + 6878
  16 libclang-cpp.so.17 0x00007fc1da89fee2
    CLNG-BPF [test_progs] test_l4lb_noinline.bpf.o
  17 libclang-cpp.so.17 0x00007fc1d9534ec6 clang::ParseAST(clang::Sema&, bool, bool) + 598
  18 libclang-cpp.so.17 0x00007fc1db2916dc clang::FrontendAction::Execute() + 92
  19 libclang-cpp.so.17 0x00007fc1db20efa4 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 708
  20 libclang-cpp.so.17 0x00007fc1db30c8d3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 675
  21 clang-17           0x00005575c8e44126 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) + 2454
  22 clang-17           0x00005575c8e41b94
  23 libclang-cpp.so.17 0x00007fc1daecf372
  24 libLLVM-17.so.1 0x00007fc1d209cdc7 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) + 151
 25 libclang-cpp.so.17 0x00007fc1daeceb07 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const + 407
  26 libclang-cpp.so.17 0x00007fc1dae97b8f clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const + 879
  27 libclang-cpp.so.17 0x00007fc1dae97def clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const + 159
    CLNG-BPF [test_progs] test_l4lb_noinline_dynptr.bpf.o
  28 libclang-cpp.so.17 0x00007fc1daeb3490 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) + 352
  29 clang-17           0x00005575c8e414e5 clang_main(int, char**, llvm::ToolContext const&) + 11253
  30 clang-17           0x00005575c8e4ddc5 main + 53
  31 libc.so.6          0x00007fc1d0ee71ca
  32 libc.so.6 0x00007fc1d0ee728b __libc_start_main + 139
  33 clang-17 0x00005575c8e3e505 _start + 37
  clang-17: error: clang frontend command failed with exit code 70 (use -v to see invocation)
  Ubuntu clang version 17.0.6 (9ubuntu1)
  Target: bpfel
  Thread model: posix
  InstalledDir: /usr/bin
    CLNG-BPF [test_progs] test_ldsx_insn.bpf.o
    CLNG-BPF [test_progs] test_legacy_printk.bpf.o
  clang-17: note: diagnostic msg: 
 ********************
  
  PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
  Preprocessed source(s) and associated run script(s) are located at:
  clang-17: note: diagnostic msg: /tmp/test_global_percpu_data-5ecaf1.c
  clang-17: note: diagnostic msg: /tmp/test_global_percpu_data-5ecaf1.sh
  clang-17: note: diagnostic msg: 
 
  ********************
```

More details can be found in the failed jobs of https://github.com/kernel-patches/bpf/pull/8543.

On Linux OS, if `clang version 17.0.6`, it should be reproduced by:

```bash
git clone --depth 5 --branch bpf/global-percpu-data-v3 https://github.com/Asphaltt/bpf.git
cd bpf
cat tools/testing/selftests/bpf/config{,.$(uname -m),.vm} > .config
make olddefconfig
make -j$(($(nproc)*4)) # build the kernel if necessary
make -j$(($(nproc)*4)) -C tools/testing/selftests/bpf
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to