Issue |
151632
|
Summary |
BPF Clang crashes when trying to align inline asm bytes to non 8-byte boundary
|
Labels |
clang
|
Assignees |
|
Reporter |
Ezlanding1
|
In the program below, Clang attempts to align the 7-bytes by adding a 1-byte NOP sequence in BPF [here](https://github.com/llvm/llvm-project/blob/c7bb105e97208295babd5e5efdc34f4fb72602b5/llvm/lib/MC/MCAssembler.cpp#L528). Since this instruction doesn't exist in BPF, (it can only do an 8-byte NOP sequence (what I believe is a `if r0 == 0 goto +0` instruction)), the BPF writeNopData fails [here](https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/BPF/MCTargetDesc/BPFAsmBackend.cpp#L57) and causes the fatal error.
## Program
```C
void foo() {
asm(".byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00");
}
int main() {
return 0;
}
```
## Stack Dump
```
fatal error: error in backend: unable to write nop sequence of 1 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 -target bpf -c bug.bpf.c -o bug.bpf.o
1. <eof> parser at end of file
2. Code generation
#0 0x00007dc57f23fd01 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/lib/x86_64-linux-gnu/libLLVM-14.so.1+0xe3fd01)
#1 0x00007dc57f23da3e llvm::sys::RunSignalHandlers() (/lib/x86_64-linux-gnu/libLLVM-14.so.1+0xe3da3e)
#2 0x00007dc57f23f0ab llvm::sys::CleanupOnSignal(unsigned long) (/lib/x86_64-linux-gnu/libLLVM-14.so.1+0xe3f0ab)
#3 0x00007dc57f16bbea (/lib/x86_64-linux-gnu/libLLVM-14.so.1+0xd6bbea)
#4 0x00007dc57f16bb8b (/lib/x86_64-linux-gnu/libLLVM-14.so.1+0xd6bb8b)
#5 0x00007dc57f23a007 llvm::sys::Process::Exit(int, bool) (/lib/x86_64-linux-gnu/libLLVM-14.so.1+0xe3a007)
#6 0x00000000004136d2 (/usr/lib/llvm-14/bin/clang+0x4136d2)
#7 0x00007dc57f17a673 llvm::report_fatal_error(llvm::Twine const&, bool) (/lib/x86_64-linux-gnu/libLLVM-14.so.1+0xd7a673)
#8 0x00007dc580796b27 llvm::MCAssembler::writeSectionData(llvm::raw_ostream&, llvm::MCSection const*, llvm::MCAsmLayout const&) const (/lib/x86_64-linux-gnu/libLLVM-14.so.1+0x2396b27)
#9 0x00007dc580781b48 (/lib/x86_64-linux-gnu/libLLVM-14.so.1+0x2381b48)
#10 0x00007dc5807808e0 (/lib/x86_64-linux-gnu/libLLVM-14.so.1+0x23808e0)
#11 0x00007dc5807979a7 llvm::MCAssembler::Finish() (/lib/x86_64-linux-gnu/libLLVM-14.so.1+0x23979a7)
#12 0x00007dc5807b4f6b llvm::MCELFStreamer::finishImpl() (/lib/x86_64-linux-gnu/libLLVM-14.so.1+0x23b4f6b)
#13 0x00007dc5807d91f7 llvm::MCStreamer::Finish(llvm::SMLoc) (/lib/x86_64-linux-gnu/libLLVM-14.so.1+0x23d91f7)
#14 0x00007dc57fac0194 llvm::AsmPrinter::doFinalization(llvm::Module&) (/lib/x86_64-linux-gnu/libLLVM-14.so.1+0x16c0194)
#15 0x00007dc57f381a41 llvm::FPPassManager::doFinalization(llvm::Module&) (/lib/x86_64-linux-gnu/libLLVM-14.so.1+0xf81a41)
#16 0x00007dc57f37ba81 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/lib/x86_64-linux-gnu/libLLVM-14.so.1+0xf7ba81)
#17 0x00007dc586657201 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>) (/lib/x86_64-linux-gnu/libclang-cpp.so.14+0x1857201)
#18 0x00007dc58697c855 (/lib/x86_64-linux-gnu/libclang-cpp.so.14+0x1b7c855)
#19 0x00007dc585804824 clang::ParseAST(clang::Sema&, bool, bool) (/lib/x86_64-linux-gnu/libclang-cpp.so.14+0xa04824)
#20 0x00007dc586978b71 clang::CodeGenAction::ExecuteAction() (/lib/x86_64-linux-gnu/libclang-cpp.so.14+0x1b78b71)
#21 0x00007dc587314b57 clang::FrontendAction::Execute() (/lib/x86_64-linux-gnu/libclang-cpp.so.14+0x2514b57)
#22 0x00007dc58726c3a6 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/lib/x86_64-linux-gnu/libclang-cpp.so.14+0x246c3a6)
#23 0x00007dc58738e45b clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/lib/x86_64-linux-gnu/libclang-cpp.so.14+0x258e45b)
#24 0x000000000041328b cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/lib/llvm-14/bin/clang+0x41328b)
#25 0x00000000004114bc (/usr/lib/llvm-14/bin/clang+0x4114bc)
#26 0x00007dc586eeaed2 (/lib/x86_64-linux-gnu/libclang-cpp.so.14+0x20eaed2)
#27 0x00007dc57f16bb6d llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/lib/x86_64-linux-gnu/libLLVM-14.so.1+0xd6bb6d)
#28 0x00007dc586eea9c0 clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (/lib/x86_64-linux-gnu/libclang-cpp.so.14+0x20ea9c0)
#29 0x00007dc586eb5183 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&) const (/lib/x86_64-linux-gnu/libclang-cpp.so.14+0x20b5183)
#30 0x00007dc586eb540a clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) const (/lib/x86_64-linux-gnu/libclang-cpp.so.14+0x20b540a)
#31 0x00007dc586ecf507 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/lib/x86_64-linux-gnu/libclang-cpp.so.14+0x20cf507)
#32 0x0000000000410f26 main (/usr/lib/llvm-14/bin/clang+0x410f26)
#33 0x00007dc57dc29d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#34 0x00007dc57dc29e40 call_init ./csu/../csu/libc-start.c:128:20
#35 0x00007dc57dc29e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#36 0x000000000040e3b5 _start (/usr/lib/llvm-14/bin/clang+0x40e3b5)
clang: error: clang frontend command failed with exit code 70 (use -v to see invocation)
Ubuntu clang version 14.0.0-1ubuntu1.1
Target: bpf
Thread model: posix
InstalledDir: /usr/bin
```
[bug-b9abe2.sh.txt](https://github.com/user-attachments/files/21541180/bug-b9abe2.sh.txt)
[bug-b9abe2.c.txt](https://github.com/user-attachments/files/21541181/bug-b9abe2.c.txt)
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs