llvm / llvm/llvm-project

[crash, reproducer] X86 DAG->DAG Instruction Selection

Open
#164,427 4 comments 0 reactions 0 assignees View on GitHub
backend:X86 crash llvm:SelectionDAG
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

# context

i'm working on https://github.com/attila-lendvai/maru and trying to access `argv` and `argc` on a freestanding build directly on top of the linux kernel.

with current trunk, i.e. beyond version 21.1.0

# reproducer

https://godbolt.org/z/n78dsvnPo

```llvm
%word = type i64
%oop = type ptr
declare ptr @llvm.sponentry()

define %oop @m__start.code() {
%r3 = call ptr @llvm.sponentry()
ret %oop %r3
}
```

output from the actual context:

```
clang -O3 -nostdlib -nostartfiles -ffreestanding -Wl,-Bstatic,-Ttext=0x08048000,-no-pie -Qunused-arguments --target=x86_64-linux-gnu -o build/llvm-linux/x86_64-linux-gnu/eval1 build/llvm-linux/x86_64-linux-gnu/eval1.ll
warning: overriding the module target triple with x86_64-unknown-linux-gnu [-Woverride-module]
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: /gnu/store/0nmbzahh7blsn8xp8kmasa6zy147k5cd-clang-20.1.8/bin/clang-20 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir build/llvm-linux/x86_64-linux-gnu/eval1- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name eval1.ll -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -ffreestanding -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/home/alendvai/common-lisp/maru -fcoverage-compilation-dir=/home/alendvai/common-lisp/maru -resource-dir /gnu/store/0nmbzahh7blsn8xp8kmasa6zy147k5cd-clang-20.1.8/lib/clang/20 -O3 -ferror-limit 19 -fmessage-length=159 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -o /tmp/eval1-cfad08.o -x ir build/llvm-linux/x86_64-linux-gnu/eval1.ll
1. Code generation
2. Running pass 'Function Pass Manager' on module 'build/llvm-linux/x86_64-linux-gnu/eval1.ll'.
3. Running pass 'X86 DAG->DAG Instruction Selection' on function '@m__start.code'
#0 0x00007f12adc293fb llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/gnu/store/rrrgwn9xnx5v4k4bmlkf499vi8d6p8cd-llvm-20.1.8/lib/libLLVM.so.20.1+0xc293fb)
#1 0x00007f12adc26996 (/gnu/store/rrrgwn9xnx5v4k4bmlkf499vi8d6p8cd-llvm-20.1.8/lib/libLLVM.so.20.1+0xc26996)
#2 0x00007f12aca51b00 __restore_rt (/gnu/store/yj053cys0724p7vs9kir808x7fivz17m-glibc-2.41/lib/libc.so.6+0x3fb00)
#3 0x00007f12b24c9fc8 (/gnu/store/rrrgwn9xnx5v4k4bmlkf499vi8d6p8cd-llvm-20.1.8/lib/libLLVM.so.20.1+0x54c9fc8)
#4 0x00007f12ae6e7d1a (/gnu/store/rrrgwn9xnx5v4k4bmlkf499vi8d6p8cd-llvm-20.1.8/lib/libLLVM.so.20.1+0x16e7d1a)
#5 0x00007f12ae6eb235 llvm::SelectionDAG::Legalize() (/gnu/store/rrrgwn9xnx5v4k4bmlkf499vi8d6p8cd-llvm-20.1.8/lib/libLLVM.so.20.1+0x16eb235)
#6 0x00007f12ae8d0066 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/gnu/store/rrrgwn9xnx5v4k4bmlkf499vi8d6p8cd-llvm-20.1.8/lib/libLLVM.so.20.1+0x18d0066)
#7 0x00007f12ae8d2be4 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/gnu/store/rrrgwn9xnx5v4k4bmlkf499vi8d6p8cd-llvm-20.1.8/lib/libLLVM.so.20.1+0x18d2be4)
#8 0x00007f12ae8d4ac8 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/gnu/store/rrrgwn9xnx5v4k4bmlkf499vi8d6p8cd-llvm-20.1.8/lib/libLLVM.so.20.1+0x18d4ac8)
#9 0x00007f12ae8c2f29 llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) (/gnu/store/rrrgwn9xnx5v4k4bmlkf499vi8d6p8cd-llvm-20.1.8/lib/libLLVM.so.20.1+0x18c2f29)
#10 0x00007f12ae1d7193 (/gnu/store/rrrgwn9xnx5v4k4bmlkf499vi8d6p8cd-llvm-20.1.8/lib/libLLVM.so.20.1+0x11d7193)
#11 0x00007f12addfcd89 llvm::FPPassManager::runOnFunction(llvm::Function&) (/gnu/store/rrrgwn9xnx5v4k4bmlkf499vi8d6p8cd-llvm-20.1.8/lib/libLLVM.so.20.1+0xdfcd89)
#12 0x00007f12addfcf2c llvm::FPPassManager::runOnModule(llvm::Module&) (/gnu/store/rrrgwn9xnx5v4k4bmlkf499vi8d6p8cd-llvm-20.1.8/lib/libLLVM.so.20.1+0xdfcf2c)
#13 0x00007f12addfc154 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/gnu/store/rrrgwn9xnx5v4k4bmlkf499vi8d6p8cd-llvm-20.1.8/lib/libLLVM.so.20.1+0xdfc154)
#14 0x00007f12b8cd69db clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr, std::unique_ptr>, clang::BackendConsumer*) (/gnu/store/0nmbzahh7blsn8xp8kmasa6zy147k5cd-clang-20.1.8/lib/libclang-cpp.so.20.1+0x24d69db)
#15 0x00007f12b922c6eb clang::CodeGenAction::ExecuteAction() (/gnu/store/0nmbzahh7blsn8xp8kmasa6zy147k5cd-clang-20.1.8/lib/libclang-cpp.so.20.1+0x2a2c6eb)
#16 0x00007f12b9cc9ad1 clang::FrontendAction::Execute() (/gnu/store/0nmbzahh7blsn8xp8kmasa6zy147k5cd-clang-20.1.8/lib/libclang-cpp.so.20.1+0x34c9ad1)
#17 0x00007f12b9c42dee clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/gnu/store/0nmbzahh7blsn8xp8kmasa6zy147k5cd-clang-20.1.8/lib/libclang-cpp.so.20.1+0x3442dee)
#18 0x00007f12b9d68676 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/gnu/store/0nmbzahh7blsn8xp8kmasa6zy147k5cd-clang-20.1.8/lib/libclang-cpp.so.20.1+0x3568676)
#19 0x00000000004161bf cc1_main(llvm::ArrayRef, char const*, void*) (/gnu/store/0nmbzahh7blsn8xp8kmasa6zy147k5cd-clang-20.1.8/bin/clang-20+0x4161bf)
#20 0x000000000040e7f3 (/gnu/store/0nmbzahh7blsn8xp8kmasa6zy147k5cd-clang-20.1.8/bin/clang-20+0x40e7f3)
#21 0x0000000000411f7d clang_main(int, char**, llvm::ToolContext const&) (/gnu/store/0nmbzahh7blsn8xp8kmasa6zy147k5cd-clang-20.1.8/bin/clang-20+0x411f7d)
#22 0x000000000040e203 main (/gnu/store/0nmbzahh7blsn8xp8kmasa6zy147k5cd-clang-20.1.8/bin/clang-20+0x40e203)
#23 0x00007f12aca3cbd7 __libc_start_call_main (/gnu/store/yj053cys0724p7vs9kir808x7fivz17m-glibc-2.41/lib/libc.so.6+0x2abd7)
#24 0x00007f12aca3cc95 __libc_start_main@GLIBC_2.2.5 (/gnu/store/yj053cys0724p7vs9kir808x7fivz17m-glibc-2.41/lib/libc.so.6+0x2ac95)
#25 0x000000000040e241 _start (/gnu/store/0nmbzahh7blsn8xp8kmasa6zy147k5cd-clang-20.1.8/bin/clang-20+0x40e241)
clang: error: unable to execute command: Segmentation fault
clang: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 20.1.8
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /gnu/store/0nmbzahh7blsn8xp8kmasa6zy147k5cd-clang-20.1.8/bin
clang: note: diagnostic msg: Error generating preprocessed source(s) - no preprocessable inputs.
```

Contributor guide

Open the contributing guide

Research direction

Start by running the minimal LLVM IR reproducer from the Godbolt link with clang -O3 and confirm the crash in the X86 DAG->DAG Instruction Selection pass. Trace the failing path in the SelectionDAG legalization or instruction-selection entry points; done means the reproducer no longer segfaults and the regression is covered by an appropriate test.

Written by the indexing model from the issue text.

Assessment

Domain
backend, compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.