Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UNREACHABLE executed at /tmp/llvm-cbe/lib/Target/CBackend/CBackend.cpp:5642! #139

Open
DarthGandalf opened this issue Jun 19, 2021 · 1 comment

Comments

@DarthGandalf
Copy link

I tried to compile something more complicated than hello world, and wrote this compiler wrapper to build native binary:

cbe.sh
#!/bin/bash

args=()
opt_args=()
o_file=""
c_option=no

while [[ $# -gt 0 ]]; do
	case "$1" in
		-o)
			o_file="$2"
			shift
			;;
		-c)
			c_option=yes
			;;
		-O*|-f*)
			opt_args+=("$1")
			args+=("$1")
			;;
		*)
			args+=("$1")
			;;
	esac
	shift
done

if [[ -z "$o_file" ]]; then
	if [[ "$c_option" == no ]]; then
		o_file=a.out
	fi
fi

echo "cbe: ${o_file}|${c_option}|${args[@]}|"

if [[ $c_option == yes ]]; then
	clang -S -emit-llvm -o "${o_file}.ll" ${args[@]} &&
	/tmp/llvm-cbe/build/tools/llvm-cbe/llvm-cbe "${o_file}.ll" -o "${o_file}.cbe.c" &&
	gcc -c "${o_file}.cbe.c" -o "${o_file}" ${opt_args[@]}
else
	g++ -o "${o_file}" ${args[@]}
fi

result=$?
ls -l "${o_file}"
exit $?

Then I passed it to cmake. Surprisingly, configure tests done by cmake itself passed.

env CXX=/tmp/cbe.sh CC=/tmp/cbe.sh cmake ..
$ env CXX=/tmp/cbe.sh CC=/tmp/cbe.sh cmake .. -DCMAKE_INSTALL_PREFIX=/tmp/znc -DCMAKE_CXX_FLAGS="-O1 -fno-omit-frame-pointer -fno-optimize-sibling-calls" -DCMAKE_BUILD_TYPE=Debug -DVERSION_EXTRA=+dev 
-- The CXX compiler identification is GNU 10.3.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /tmp/cbe.sh - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Checking for C++11 support
-- Checking for C++11 support - supported
-- Looking for C++ include pthread.h
-- Looking for C++ include pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - no
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Checking for 64-bit off_t
-- Checking for 64-bit off_t - present
-- Checking for fseeko/ftello
-- Checking for fseeko/ftello - present
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.2")
-- Found OpenSSL: /usr/lib64/libcrypto.so (found version "1.1.1k")
-- Found ZLIB: /usr/lib64/libz.so (found version "1.2.11")
-- Checking for module 'libsasl2'
--   Found libsasl2, version 2.1.27
-- Checking for module 'icu-uc'
--   Found icu-uc, version 69.1
-- Found SWIG: /usr/bin/swig (found suitable version "4.0.2", minimum required is "3.0.0")
-- Found PerlLibs: /usr/lib64/perl5/5.32/x86_64-linux/CORE (found suitable version "5.32.1", minimum required is "5.10")
-- Found Perl: /usr/bin/perl (found suitable version "5.32.1", minimum required is "5.10")
-- Found Python3: /usr/include/python3.9 (found version "3.9.4") found components: Development Development.Module Development.Embed
-- Found Boost: /usr/lib64/cmake/Boost-1.76.0/BoostConfig.cmake (found version "1.76.0") found components: locale
-- Found Gettext: /usr/bin/msgmerge (found version "0.21")
-- Looking for getopt_long
-- Looking for getopt_long - found
-- Looking for lstat
-- Looking for lstat - found
-- Looking for getpassphrase
-- Looking for getpassphrase - not found
-- Looking for tcsetattr
-- Looking for tcsetattr - found
-- Looking for clock_gettime
-- Looking for clock_gettime - found
-- Looking for AI_ADDRCONFIG
-- Looking for AI_ADDRCONFIG - found
-- Found Git: /usr/bin/git (found version "2.31.1")
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY - Success
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY - Success
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Success
-- Found GoogleTest: /home/somebody/znc/git/third_party/googletest/googletest
-- Found GoogleMock: /home/somebody/znc/git/third_party/googletest/googlemock
+--------------------------+
| ZNC 1.9.x+dev configured |
|                          |
| Prefix    : /tmp/znc     |
| SSL       : yes          |
| IPv6      : yes          |
| Async DNS : yes          |
| Perl      : yes          |
| Python    : yes          |
| Tcl       : no           |
| Cyrus     : yes          |
| Charset   : yes          |
| Zlib      : yes          |
| i18n      : yes          |
+--------------------------+

Now you can run 'make' to compile ZNC

-- Configuring done
-- Generating done
-- Build files have been written to: /home/somebody/znc/git/build-cbe

The problem started during "make":

make[2]: выход из каталога «/home/somebody/znc/git/build-cbe»
make  -f src/CMakeFiles/znclib.dir/build.make src/CMakeFiles/znclib.dir/build
make[2]: вход в каталог «/home/somebody/znc/git/build-cbe»
[  1%] Building CXX object src/CMakeFiles/znclib.dir/ZNCString.cpp.o
cd /home/somebody/znc/git/build-cbe/src && /tmp/cbe.sh -DBOOST_ALL_NO_LIB -DBOOST_CHRONO_DYN_LINK -DBOOST_LOCALE_DYN_LINK -DBOOST_SYSTEM_DYN_LINK -DBOOST_THREAD_DYN_LINK -I/home/somebody/znc/git/third_party/bpstd -I/home/somebody/znc/git/include -I/home/somebody/znc/git/build-cbe/include -O1 -fno-omit-frame-pointer -fno-optimize-sibling-calls -g -fPIC -include znc/zncconfig.h -std=c++11 -o CMakeFiles/znclib.dir/ZNCString.cpp.o -c /home/somebody/znc/git/src/ZNCString.cpp
cbe: CMakeFiles/znclib.dir/ZNCString.cpp.o|yes|-DBOOST_ALL_NO_LIB -DBOOST_CHRONO_DYN_LINK -DBOOST_LOCALE_DYN_LINK -DBOOST_SYSTEM_DYN_LINK -DBOOST_THREAD_DYN_LINK -I/home/somebody/znc/git/third_party/bpstd -I/home/somebody/znc/git/include -I/home/somebody/znc/git/build-cbe/include -O1 -fno-omit-frame-pointer -fno-optimize-sibling-calls -g -fPIC -include znc/zncconfig.h -std=c++11 /home/somebody/znc/git/src/ZNCString.cpp|
Unsupported 'constant with cast' type i8* in: i8* bitcast (i32 (i32*, void (i8*)*)* @__pthread_key_create to i8*) (#1619)
Unsupported 'constant with cast' type in:   br i1 icmp ne (i8* bitcast (i32 (i32*, void (i8*)*)* @__pthread_key_create to i8*), i8* null), label %2, label %7, !dbg !6432 @ /usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/include/g++-v10/ext/concurrence.h:147:11
Unsupported 'constant with cast' type
UNREACHABLE executed at /tmp/llvm-cbe/lib/Target/CBackend/CBackend.cpp:5642!
 #0 0x00007fbc7c2bf30a llvm::sys::PrintStackTrace(llvm::raw_ostream&) /mnt/portagetmp/portage/sys-devel/llvm-11.1.0/work/llvm/lib/Support/Unix/Signals.inc:568:3
 #1 0x00007fbc7c2bd0c4 llvm::sys::RunSignalHandlers() /mnt/portagetmp/portage/sys-devel/llvm-11.1.0/work/llvm/lib/Support/Signals.cpp:68:20
 #2 0x00007fbc7c2bd8e5 SignalHandler /mnt/portagetmp/portage/sys-devel/llvm-11.1.0/work/llvm/lib/Support/Unix/Signals.inc:396:31
 #3 0x00007fbc7b2f2670 (/lib64/libc.so.6+0x38670)
 #4 0x00007fbc7b2f25f1 raise /mnt/portagetmp/portage/sys-libs/glibc-2.33/work/glibc-2.33/signal/../sysdeps/unix/sysv/linux/raise.c:50:1
 #5 0x00007fbc7b2dc536 abort /mnt/portagetmp/portage/sys-libs/glibc-2.33/work/glibc-2.33/stdlib/abort.c:81:7
 #6 0x00007fbc7c1e93da (/usr/lib/llvm/11/lib64/libLLVM-11.so+0xa0b3da)
 #7 0x000056304461e0ff std::pair<std::__strip_reference_wrapper<std::decay<llvm::AttributeList>::type>::__type, std::__strip_reference_wrapper<std::decay<llvm::CallingConv::._anon_163>::type>::__type> std::make_pair<llvm::AttributeList, llvm::CallingConv::._anon_163>(llvm::AttributeList&&, llvm::CallingConv::._anon_163&&) (/tmp/llvm-cbe/build/tools/llvm-cbe/llvm-cbe+0x360ff)
 #8 0x000056304460ac89 llvm_cbe::CWriter::printConstantWithCast(llvm::Constant*, unsigned int) (/tmp/llvm-cbe/build/tools/llvm-cbe/llvm-cbe+0x22c89)
 #9 0x00005630446089ef llvm_cbe::CWriter::printConstant(llvm::Constant*, llvm_cbe::CWriter::OperandContext) (/tmp/llvm-cbe/build/tools/llvm-cbe/llvm-cbe+0x209ef)
#10 0x000056304460b325 llvm_cbe::CWriter::writeOperandInternal(llvm::Value*, llvm_cbe::CWriter::OperandContext) (/tmp/llvm-cbe/build/tools/llvm-cbe/llvm-cbe+0x23325)
#11 0x000056304460b440 llvm_cbe::CWriter::writeOperand(llvm::Value*, llvm_cbe::CWriter::OperandContext) (/tmp/llvm-cbe/build/tools/llvm-cbe/llvm-cbe+0x23440)
#12 0x000056304461661b llvm_cbe::CWriter::visitBranchInst(llvm::BranchInst&) (/tmp/llvm-cbe/build/tools/llvm-cbe/llvm-cbe+0x2e61b)
#13 0x0000563044637843 llvm::InstVisitor<llvm_cbe::CWriter, void>::visitBr(llvm::BranchInst&) (/tmp/llvm-cbe/build/tools/llvm-cbe/llvm-cbe+0x4f843)
#14 0x00005630446306fe llvm::InstVisitor<llvm_cbe::CWriter, void>::visit(llvm::Instruction&) (/tmp/llvm-cbe/build/tools/llvm-cbe/llvm-cbe+0x486fe)
#15 0x00005630446158bc llvm_cbe::CWriter::printBasicBlock(llvm::BasicBlock*) (/tmp/llvm-cbe/build/tools/llvm-cbe/llvm-cbe+0x2d8bc)
#16 0x0000563044615087 llvm_cbe::CWriter::printFunction(llvm::Function&) (/tmp/llvm-cbe/build/tools/llvm-cbe/llvm-cbe+0x2d087)
#17 0x00005630446033ae llvm_cbe::CWriter::runOnFunction(llvm::Function&) (/tmp/llvm-cbe/build/tools/llvm-cbe/llvm-cbe+0x1b3ae)
#18 0x00007fbc7c401033 llvm::FPPassManager::runOnFunction(llvm::Function&) /mnt/portagetmp/portage/sys-devel/llvm-11.1.0/work/llvm/lib/IR/LegacyPassManager.cpp:1517:7
#19 0x00007fbc7c401d23 llvm::ilist_node_impl<llvm::ilist_detail::node_options<llvm::Function, false, false, void> >::getNext() /mnt/portagetmp/portage/sys-devel/llvm-11.1.0/work/llvm/include/llvm/ADT/ilist_node.h:66:66
#20 0x00007fbc7c401d23 llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Function, false, false, void>, false, false>::operator++() /mnt/portagetmp/portage/sys-devel/llvm-11.1.0/work/llvm/include/llvm/ADT/ilist_iterator.h:157:25
#21 0x00007fbc7c401d23 llvm::FPPassManager::runOnModule(llvm::Module&) /mnt/portagetmp/portage/sys-devel/llvm-11.1.0/work/llvm/lib/IR/LegacyPassManager.cpp:1551:22
#22 0x00007fbc7c40021b runOnModule /mnt/portagetmp/portage/sys-devel/llvm-11.1.0/work/llvm/lib/IR/LegacyPassManager.cpp:1618:7
#23 0x00007fbc7c40021b llvm::legacy::PassManagerImpl::run(llvm::Module&) /mnt/portagetmp/portage/sys-devel/llvm-11.1.0/work/llvm/lib/IR/LegacyPassManager.cpp:614:55
#24 0x00005630445fab22 compileModule(char**, llvm::LLVMContext&) (/tmp/llvm-cbe/build/tools/llvm-cbe/llvm-cbe+0x12b22)
#25 0x00005630445f9efe main (/tmp/llvm-cbe/build/tools/llvm-cbe/llvm-cbe+0x11efe)
#26 0x00007fbc7b2dd80e __libc_start_main /mnt/portagetmp/portage/sys-libs/glibc-2.33/work/glibc-2.33/csu/../csu/libc-start.c:366:3
#27 0x00005630445f967a _start (/tmp/llvm-cbe/build/tools/llvm-cbe/llvm-cbe+0x1167a)
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /tmp/llvm-cbe/build/tools/llvm-cbe/llvm-cbe CMakeFiles/znclib.dir/ZNCString.cpp.o.ll -o CMakeFiles/znclib.dir/ZNCString.cpp.o.cbe.c 
1.      Running pass 'Function Pass Manager' on module 'CMakeFiles/znclib.dir/ZNCString.cpp.o.ll'.
2.      Running pass 'C backend' on function '@_ZN9__gnu_cxx7__mutex4lockEv'
/tmp/cbe.sh: строка 42:  2440 Аварийный останов         /tmp/llvm-cbe/build/tools/llvm-cbe/llvm-cbe "${o_file}.ll" -o "${o_file}.cbe.c"
ls: невозможно получить доступ к 'CMakeFiles/znclib.dir/ZNCString.cpp.o': Нет такого файла или каталога
make[2]: *** [src/CMakeFiles/znclib.dir/build.make:87: src/CMakeFiles/znclib.dir/ZNCString.cpp.o] Ошибка 2
make[2]: выход из каталога «/home/somebody/znc/git/build-cbe»
make[1]: *** [CMakeFiles/Makefile2:1567: src/CMakeFiles/znclib.dir/all] Ошибка 2
make[1]: выход из каталога «/home/somebody/znc/git/build-cbe»
make: *** [Makefile:149: all] Ошибка 2

$ clang -v
clang version 11.1.0
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm/11/bin
Selected GCC installation: /usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
Found CUDA installation: /opt/cuda, version 10.2

$ uname -a
Linux komputer 5.4.115-gentoo-dist #1 SMP Wed Apr 28 18:53:35 -00 2021 x86_64 AMD Ryzen 9 3900X 12-Core Processor AuthenticAMD GNU/Linux

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/10.3.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /mnt/portagetmp/portage/sys-devel/gcc-10.3.0/work/gcc-10.3.0/configure --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/10.3.0 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/10.3.0 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/10.3.0/man --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/10.3.0/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/include/g++-v10 --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/10.3.0/python --enable-languages=c,c++,fortran --enable-obsolete --enable-secureplt --disable-werror --with-system-zlib --enable-nls --without-included-gettext --enable-checking=release --with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo 10.3.0 p1' --disable-esp --enable-libstdcxx-time --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-multilib --with-multilib-list=m32,m64 --disable-fixed-point --enable-targets=all --enable-libgomp --disable-libssp --disable-libada --disable-systemtap --disable-vtable-verify --disable-libvtv --without-zstd --enable-lto --without-isl --enable-default-pie --enable-default-ssp
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.3.0 (Gentoo 10.3.0 p1)

Version d667885
The program which I was building is https://github.com/znc/znc at commit 688645413c258f1fe42a39e42e5b5d1dead03d71

@DarthGandalf
Copy link
Author

Here's the .ll file which was fed as input to llvm-cbe

ZNCString.cpp.o.ll.gz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant