KhronosGroup / KhronosGroup/SPIRV-LLVM-Translator
llvm-spirv failing with SIGSEGV or abort() from glibc when built with `-UNDEBUG` (via LLVM)
- Dominant language
- LLVM
- Stars
- 625
- Forks
- 279
- Avg merge
- 3d 5h
- Merged PRs (30d)
- 34
Description
If LLVM is built with `-DCMAKE_BUILD_TYPE=RelWithDebInfo -DLLVM_ENABLE_ASSERTIONS=ON`, it causes `-UNDEBUG` to be implicitly appended to SPIRV-LLVM-Translator compiler flags. This in turn causes `llvm-spirv` to crash a lot. I've originally hit it while attempting to build libclc but I can also reproduce the problem with SPIRV-LLVM-Translator's test suite:
```
Testing Time: 29.34s
Unsupported : 43
Passed : 12
Expectedly Failed: 3
Failed : 612
```
Example assertion failures I'm seeing are:
```
+ /tmp/portage/dev-util/spirv-llvm-translator-16.0.0/work/SPIRV-LLVM-Translator-16.0.0_build/tools/llvm-spirv/llvm-spirv -r -emit-opaque-pointers /tmp/portage/dev-util/spirv-llvm-translator-16.0.0/work/SPIRV-LLVM-Translator-16.0.0_build/test/test_output/DebugInfo/Output/DebugInfoSubrangeWithOnlyCount.spt.tmp.spv -o /tmp/portage/dev-util/spirv-llvm-translator-16.0.0/work/SPIRV-LLVM-Translator-16.0.0_build/test/test_output/DebugInfo/Output/DebugInfoSubrangeWithOnlyCount.spt.tmp.rev.bc
Fatal glibc error: malloc.c:2593 (sysmalloc): assertion failed: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: /tmp/portage/dev-util/spirv-llvm-translator-16.0.0/work/SPIRV-LLVM-Translator-16.0.0_build/tools/llvm-spirv/llvm-spirv -r -emit-opaque-pointers /tmp/portage/dev-util/spirv-llvm-translator-16.0.0/work/SPIRV-LLVM-Translator-16.0.0_build/test/test_output/DebugInfo/Output/DebugInfoSubrangeWithOnlyCount.spt.tmp.spv -o /tmp/portage/dev-util/spirv-llvm-translator-16.0.0/work/SPIRV-LLVM-Translator-16.0.0_build/test/test_output/DebugInfo/Output/DebugInfoSubrangeWithOnlyCount.spt.tmp.rev.bc
```
and:
```
+ /tmp/portage/dev-util/spirv-llvm-translator-16.0.0/work/SPIRV-LLVM-Translator-16.0.0_build/tools/llvm-spirv/llvm-spirv -r -emit-opaque-pointers /tmp/portage/dev-util/spirv-llvm-translator-16.0.0/work/SPIRV-LLVM-Translator-16.0.0_build/test/test_output/Output/OpLoopMergeNone.spt.tmp.spv -o /tmp/portage/dev-util/spirv-llvm-translator-16.0.0/work/SPIRV-LLVM-Translator-16.0.0_build/test/test_output/Output/OpLoopMergeNone.spt.tmp.bc
llvm-spirv: /var/tmp/portage/sys-devel/llvm-16.0.3/work/llvm/include/llvm/Support/GenericDomTreeConstruction.h:352: static llvm::DomTreeBuilder::SemiNCAInfo::RootsT llvm::DomTreeBuilder::SemiNCAInfo::FindRoots(const DomTreeT&, BatchUpdatePtr) [with DomTreeT = llvm::DominatorTreeBase; RootsT = llvm::SmallVector; BatchUpdatePtr = llvm::DomTreeBuilder::SemiNCAInfo >::BatchUpdateInfo*]: Assertion `DT.Parent && "Parent pointer is not set"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: /tmp/portage/dev-util/spirv-llvm-translator-16.0.0/work/SPIRV-LLVM-Translator-16.0.0_build/tools/llvm-spirv/llvm-spirv -r -emit-opaque-pointers /tmp/portage/dev-util/spirv-llvm-translator-16.0.0/work/SPIRV-LLVM-Translator-16.0.0_build/test/test_output/Output/OpLoopMergeNone.spt.tmp.spv -o /tmp/portage/dev-util/spirv-llvm-translator-16.0.0/work/SPIRV-LLVM-Translator-16.0.0_build/test/test_output/Output/OpLoopMergeNone.spt.tmp.bc
#0 0x00007ff08a474771 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib/llvm/16/lib64/libLLVM-16.so+0x1274771)
#1 0x00007ff08a471fb4 llvm::sys::RunSignalHandlers() (/usr/lib/llvm/16/lib64/libLLVM-16.so+0x1271fb4)
#2 0x00007ff08a472136 (/usr/lib/llvm/16/lib64/libLLVM-16.so+0x1272136)
#3 0x00007ff088c53ba0 (/lib64/libc.so.6+0x38ba0)
#4 0x00007ff088ca386c __pthread_kill_implementation /tmp/portage/sys-libs/glibc-2.37-r2/work/glibc-2.37/nptl/pthread_kill.c:44:76
#5 0x00007ff088c53af2 raise /tmp/portage/sys-libs/glibc-2.37-r2/work/glibc-2.37/signal/../sysdeps/posix/raise.c:27:6
#6 0x00007ff088c3d4b2 abort /tmp/portage/sys-libs/glibc-2.37-r2/work/glibc-2.37/stdlib/abort.c:81:7
#7 0x00007ff088c3d3d5 _nl_load_domain /tmp/portage/sys-libs/glibc-2.37-r2/work/glibc-2.37/intl/loadmsgcat.c:1177:9
#8 0x00007ff088c4c812 (/lib64/libc.so.6+0x31812)
#9 0x00007ff08a5714a3 (/usr/lib/llvm/16/lib64/libLLVM-16.so+0x13714a3)
#10 0x00007ff08a582afa (/usr/lib/llvm/16/lib64/libLLVM-16.so+0x1382afa)
#11 0x00007ff092a04321 SPIRV::SPIRVToLLVM::transLLVMLoopMetadata(llvm::Function const*) (/usr/lib/llvm/16/lib64/libLLVMSPIRVLib.so.16+0x204321)
#12 0x00007ff092a0d212 SPIRV::SPIRVToLLVM::transFunction(SPIRV::SPIRVFunction*) (/usr/lib/llvm/16/lib64/libLLVMSPIRVLib.so.16+0x20d212)
#13 0x00007ff092a0deb7 SPIRV::SPIRVToLLVM::translate() (/usr/lib/llvm/16/lib64/libLLVMSPIRVLib.so.16+0x20deb7)
#14 0x00007ff092a17d99 llvm::convertSpirvToLLVM(llvm::LLVMContext&, SPIRV::SPIRVModule&, SPIRV::TranslatorOpts const&, std::__cxx11::basic_string, std::allocator>&) (/usr/lib/llvm/16/lib64/libLLVMSPIRVLib.so.16+0x217d99)
#15 0x00007ff092a189a0 llvm::readSpirv(llvm::LLVMContext&, SPIRV::TranslatorOpts const&, std::istream&, llvm::Module*&, std::__cxx11::basic_string, std::allocator>&) (/usr/lib/llvm/16/lib64/libLLVMSPIRVLib.so.16+0x2189a0)
#16 0x000056520fc9818e convertSPIRVToLLVM(SPIRV::TranslatorOpts const&) /tmp/portage/dev-util/spirv-llvm-translator-16.0.0/work/SPIRV-LLVM-Translator-16.0.0/tools/llvm-spirv/llvm-spirv.cpp:362:7
#17 0x000056520fc9cd4c main /tmp/portage/dev-util/spirv-llvm-translator-16.0.0/work/SPIRV-LLVM-Translator-16.0.0/tools/llvm-spirv/llvm-spirv.cpp:758:30
#18 0x00007ff088c3e8ca __libc_start_call_main /tmp/portage/sys-libs/glibc-2.37-r2/work/glibc-2.37/csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#19 0x00007ff088c3e985 call_init /tmp/portage/sys-libs/glibc-2.37-r2/work/glibc-2.37/csu/../csu/libc-start.c:128:20
#20 0x00007ff088c3e985 __libc_start_main /tmp/portage/sys-libs/glibc-2.37-r2/work/glibc-2.37/csu/../csu/libc-start.c:347:5
#21 0x000056520fc949a1 _start (/tmp/portage/dev-util/spirv-llvm-translator-16.0.0/work/SPIRV-LLVM-Translator-16.0.0_build/tools/llvm-spirv/llvm-spirv+0x89a1)
/tmp/portage/dev-util/spirv-llvm-translator-16.0.0/work/SPIRV-LLVM-Translator-16.0.0_build/test/test_output/Output/OpLoopMergeNone.spt.script: line 4: 764 Aborted (core dumped) /tmp/portage/dev-util/spirv-llvm-translator-16.0.0/work/SPIRV-LLVM-Translator-16.0.0_build/tools/llvm-spirv/llvm-spirv -r -emit-opaque-pointers /tmp/portage/dev-util/spirv-llvm-translator-16.0.0/work/SPIRV-LLVM-Translator-16.0.0_build/test/test_output/Output/OpLoopMergeNone.spt.tmp.spv -o /tmp/portage/dev-util/spirv-llvm-translator-16.0.0/work/SPIRV-LLVM-Translator-16.0.0_build/test/test_output/Output/OpLoopMergeNone.spt.tmp.bc
```
Full build and test log (3.7M): [dev-util:spirv-llvm-translator-16.0.0:20230503-131244.log](https://github.com/KhronosGroup/SPIRV-LLVM-Translator/files/11384802/dev-util.spirv-llvm-translator-16.0.0.20230503-131244.log)
I can try digging deeper but since I have limited computing power I'd prefer if you tried if you can reproduce it first.
Contributor guide
Research direction
Reproduce the failure with LLVM built using RelWithDebInfo and assertions enabled, then run the SPIRV-LLVM-Translator test suite. Start at tools/llvm-spirv/llvm-spirv.cpp around convertSPIRVToLLVM (line 362) and main (line 758), together with the failing DebugInfo and OpLoopMergeNone tests. Done means the cause is addressed and these crashes no longer occur under the reported build configuration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cmake, cpp
- Domain
- build-system, compilers, testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100