Repository: iree-org/iree

Issue #8574: NPE on initialization of compiling for a TargetMachine not compiled in
Created: 2022-03-18T00:53:16Z
Repro:

Set -DIREE_DEFAULT_CPU_TARGETS=X86
ninja iree-test-deps

The issue is in LLVMAOTTarget.cpp initConfiguration(), which accepts options and does not have a failure path for createTargetMachine returning nullptr.

Duplicate issue #9482: Building `simple_embedding_test.mlir` when using `IREE_DEFAULT_CPU_LLVM_TARGETS=X86` segfaults for tests meant for ARM and RISC-V platforms
Created: 2022-06-14T00:11:53Z
What happened?
Setting -DIREE_DEFAULT_CPU_LLVM_TARGETS=X86 and building the targets all fails when building simple_embeddings_test.mlir.
[build] FAILED: samples/simple_embedding/simple_embedding_test_bytecode_module_dylib_arm_32.vmfb /usr/local/google/home/ravishankarm/iree/build_debug/samples/simple_embedding/simple_embedding_test_bytecode_module_dylib_arm_32.vmfb 
[build] cd /usr/local/google/home/ravishankarm/iree/build_debug/samples/simple_embedding && /usr/local/google/home/ravishankarm/iree/build_debug/tools/iree-compile --output-format=vm-bytecode --iree-input-type=mhlo --iree-hal-target-backends=dylib-llvm-aot --iree-llvm-target-triple=armv7a-pc-linux-elf --iree-llvm-target-float-abi=hard --iree-llvm-debug-symbols=false --iree-vm-bytecode-module-strip-source-map=true --iree-vm-emit-polyglot-zip=false /usr/local/google/home/ravishankarm/iree/iree/samples/simple_embedding/simple_embedding_test.mlir -o simple_embedding_test_bytecode_module_dylib_arm_32.vmfb --iree-llvm-embedded-linker-path=\"/usr/local/google/home/ravishankarm/iree/build_debug/third_party/llvm-project/llvm/bin/lld\" --iree-llvm-wasm-linker-path=\"/usr/local/google/home/ravishankarm/iree/build_debug/third_party/llvm-project/llvm/bin/lld\"
[build] PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
[build] Stack dump:
[build] 0.	Program arguments: /usr/local/google/home/ravishankarm/iree/build_debug/tools/iree-compile --output-format=vm-bytecode --iree-input-type=mhlo --iree-hal-target-backends=dylib-llvm-aot --iree-llvm-target-triple=armv7a-pc-linux-elf --iree-llvm-target-float-abi=hard --iree-llvm-debug-symbols=false --iree-vm-bytecode-module-strip-source-map=true --iree-vm-emit-polyglot-zip=false /usr/local/google/home/ravishankarm/iree/iree/samples/simple_embedding/simple_embedding_test.mlir -o simple_embedding_test_bytecode_module_dylib_arm_32.vmfb --iree-llvm-embedded-linker-path=\"/usr/local/google/home/ravishankarm/iree/build_debug/third_party/llvm-project/llvm/bin/lld\" --iree-llvm-wasm-linker-path=\"/usr/local/google/home/ravishankarm/iree/build_debug/third_party/llvm-project/llvm/bin/lld\"
[build]  #0 0x000000000b9fbdca llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /usr/local/google/home/ravishankarm/iree/iree/third_party/llvm-project/llvm/lib/Support/Unix/Signals.inc:569:11
[build]  #1 0x000000000b9fbf9b PrintStackTraceSignalHandler(void*) /usr/local/google/home/ravishankarm/iree/iree/third_party/llvm-project/llvm/lib/Support/Unix/Signals.inc:636:1
[build]  #2 0x000000000b9fa53b llvm::sys::RunSignalHandlers() /usr/local/google/home/ravishankarm/iree/iree/third_party/llvm-project/llvm/lib/Support/Signals.cpp:102:5
[build]  #3 0x000000000b9fc711 SignalHandler(int) /usr/local/google/home/ravishankarm/iree/iree/third_party/llvm-project/llvm/lib/Support/Unix/Signals.inc:407:1
[build]  #4 0x00007fe4921d7200 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12200)
[build]  #5 0x00007fe4920880c6 std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_assign(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (/lib/x86_64-linux-gnu/libstdc++.so.6+0x1400c6)
[build]  #6 0x00007fe49208848d std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator=(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (/lib/x86_64-linux-gnu/libstdc++.so.6+0x14048d)
[build]  #7 0x00000000041aaba0 llvm::DataLayout::operator=(llvm::DataLayout const&) /usr/local/google/home/ravishankarm/iree/iree/third_party/llvm-project/llvm/include/llvm/IR/DataLayout.h:216:17
[build]  #8 0x00000000041aaa6e llvm::DataLayout::DataLayout(llvm::DataLayout const&) /usr/local/google/home/ravishankarm/iree/iree/third_party/llvm-project/llvm/include/llvm/IR/DataLayout.h:209:50
[build]  #9 0x00000000041aa65d llvm::TargetMachine::createDataLayout() const /usr/local/google/home/ravishankarm/iree/iree/third_party/llvm-project/llvm/include/llvm/Target/TargetMachine.h:169:54
[build] #10 0x00000000041a8148 mlir::iree_compiler::IREE::HAL::LLVMAOTTargetBackend::initConfiguration() /usr/local/google/home/ravishankarm/iree/iree/compiler/src/iree/compiler/Dialect/HAL/Target/LLVM/LLVMAOTTarget.cpp:739:32
[build] #11 0x00000000041a7c92 mlir::iree_compiler::IREE::HAL::LLVMAOTTargetBackend::LLVMAOTTargetBackend(mlir::iree_compiler::IREE::HAL::LLVMTargetOptions) /usr/local/google/home/ravishankarm/iree/iree/compiler/src/iree/compiler/Dialect/HAL/Target/LLVM/LLVMAOTTarget.cpp:145:3
[build] #12 0x00000000041a7a8d void __gnu_cxx::new_allocator<mlir::iree_compiler::IREE::HAL::LLVMAOTTargetBackend>::construct<mlir::iree_compiler::IREE::HAL::LLVMAOTTargetBackend, mlir::iree_compiler::IREE::HAL::LLVMTargetOptions>(mlir::iree_compiler::IREE::HAL::LLVMAOTTargetBackend*, mlir::iree_compiler::IREE::HAL::LLVMTargetOptions&&) /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/ext/new_allocator.h:162:4
[build] #13 0x00000000041a77fd void std::allocator_traits<std::allocator<mlir::iree_compiler::IREE::HAL::LLVMAOTTargetBackend> >::construct<mlir::iree_compiler::IREE::HAL::LLVMAOTTargetBackend, mlir::iree_compiler::IREE::HAL::LLVMTargetOptions>(std::allocator<mlir::iree_compiler::IREE::HAL::LLVMAOTTargetBackend>&, mlir::iree_compiler::IREE::HAL::LLVMAOTTargetBackend*, mlir::iree_compiler::IREE::HAL::LLVMTargetOptions&&) /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/alloc_traits.h:520:2
[build] #14 0x00000000041a756f std::_Sp_counted_ptr_inplace<mlir::iree_compiler::IREE::HAL::LLVMAOTTargetBackend, std::allocator<mlir::iree_compiler::IREE::HAL::LLVMAOTTargetBackend>, (__gnu_cxx::_Lock_policy)2>::_Sp_counted_ptr_inplace<mlir::iree_compiler::IREE::HAL::LLVMTargetOptions>(std::allocator<mlir::iree_compiler::IREE::HAL::LLVMAOTTargetBackend>, mlir::iree_compiler::IREE::HAL::LLVMTargetOptions&&) /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/shared_ptr_base.h:521:2
[build] #15 0x00000000041a7395 std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<mlir::iree_compiler::IREE::HAL::LLVMAOTTargetBackend, std::allocator<mlir::iree_compiler::IREE::HAL::LLVMAOTTargetBackend>, mlir::iree_compiler::IREE::HAL::LLVMTargetOptions>(mlir::iree_compiler::IREE::HAL::LLVMAOTTargetBackend*&, std::_Sp_alloc_shared_tag<std::allocator<mlir::iree_compiler::IREE::HAL::LLVMAOTTargetBackend> >, mlir::iree_compiler::IREE::HAL::LLVMTargetOptions&&) /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/shared_ptr_base.h:650:16
[build] #16 0x00000000041a7306 std::__shared_ptr<mlir::iree_compiler::IREE::HAL::LLVMAOTTargetBackend, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<std::allocator<mlir::iree_compiler::IREE::HAL::LLVMAOTTargetBackend>, mlir::iree_compiler::IREE::HAL::LLVMTargetOptions>(std::_Sp_alloc_shared_tag<std::allocator<mlir::iree_compiler::IREE::HAL::LLVMAOTTargetBackend> >, mlir::iree_compiler::IREE::HAL::LLVMTargetOptions&&) /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/shared_ptr_base.h:1342:14
[build] #17 0x00000000041a729d std::shared_ptr<mlir::iree_compiler::IREE::HAL::LLVMAOTTargetBackend>::shared_ptr<std::allocator<mlir::iree_compiler::IREE::HAL::LLVMAOTTargetBackend>, mlir::iree_compiler::IREE::HAL::LLVMTargetOptions>(std::_Sp_alloc_shared_tag<std::allocator<mlir::iree_compiler::IREE::HAL::LLVMAOTTargetBackend> >, mlir::iree_compiler::IREE::HAL::LLVMTargetOptions&&) /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/shared_ptr.h:410:4
[build] #18 0x00000000041a7206 std::shared_ptr<mlir::iree_compiler::IREE::HAL::LLVMAOTTargetBackend> std::allocate_shared<mlir::iree_compiler::IREE::HAL::LLVMAOTTargetBackend, std::allocator<mlir::iree_compiler::IREE::HAL::LLVMAOTTargetBackend>, mlir::iree_compiler::IREE::HAL::LLVMTargetOptions>(std::allocator<mlir::iree_compiler::IREE::HAL::LLVMAOTTargetBackend> const&, mlir::iree_compiler::IREE::HAL::LLVMTargetOptions&&) /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/shared_ptr.h:862:14
[build] #19 0x00000000041a7143 std::shared_ptr<mlir::iree_compiler::IREE::HAL::LLVMAOTTargetBackend> std::make_shared<mlir::iree_compiler::IREE::HAL::LLVMAOTTargetBackend, mlir::iree_compiler::IREE::HAL::LLVMTargetOptions>(mlir::iree_compiler::IREE::HAL::LLVMTargetOptions&&) /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/shared_ptr.h:878:7
[build] #20 0x00000000041a61cd mlir::iree_compiler::IREE::HAL::registerLLVMAOTTargetBackends(std::function<mlir::iree_compiler::IREE::HAL::LLVMTargetOptions ()>)::$_1::operator()() const /usr/local/google/home/ravishankarm/iree/iree/compiler/src/iree/compiler/Dialect/HAL/Target/LLVM/LLVMAOTTarget.cpp:828:5
[build] #21 0x00000000041a6176 std::shared_ptr<mlir::iree_compiler::IREE::HAL::LLVMAOTTargetBackend> std::__invoke_impl<std::shared_ptr<mlir::iree_compiler::IREE::HAL::LLVMAOTTargetBackend>, mlir::iree_compiler::IREE::HAL::registerLLVMAOTTargetBackends(std::function<mlir::iree_compiler::IREE::HAL::LLVMTargetOptions ()>)::$_1&>(std::__invoke_other, mlir::iree_compiler::IREE::HAL::registerLLVMAOTTargetBackends(std::function<mlir::iree_compiler::IREE::HAL::LLVMTargetOptions ()>)::$_1&) /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/invoke.h:61:14
[build] #22 0x00000000041a60f6 std::enable_if<__and_<std::__not_<std::is_void<std::shared_ptr<mlir::iree_compiler::IREE::HAL::TargetBackend> > >, std::is_convertible<std::__invoke_result<mlir::iree_compiler::IREE::HAL::registerLLVMAOTTargetBackends(std::function<mlir::iree_compiler::IREE::HAL::LLVMTargetOptions ()>)::$_1&>::type, std::shared_ptr<mlir::iree_compiler::IREE::HAL::TargetBackend> > >::value, std::shared_ptr<mlir::iree_compiler::IREE::HAL::TargetBackend> >::type std::__invoke_r<std::shared_ptr<mlir::iree_compiler::IREE::HAL::TargetBackend>, mlir::iree_compiler::IREE::HAL::registerLLVMAOTTargetBackends(std::function<mlir::iree_compiler::IREE::HAL::LLVMTargetOptions ()>)::$_1&>(mlir::iree_compiler::IREE::HAL::registerLLVMAOTTargetBackends(std::function<mlir::iree_compiler::IREE::HAL::LLVMTargetOptions ()>)::$_1&) /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/invoke.h:142:14
[build] #23 0x00000000041a5fa6 std::_Function_handler<std::shared_ptr<mlir::iree_compiler::IREE::HAL::TargetBackend> (), mlir::iree_compiler::IREE::HAL::registerLLVMAOTTargetBackends(std::function<mlir::iree_compiler::IREE::HAL::LLVMTargetOptions ()>)::$_1>::_M_invoke(std::_Any_data const&) /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/std_function.h:290:9
[build] #24 0x0000000007289464 std::function<std::shared_ptr<mlir::iree_compiler::IREE::HAL::TargetBackend> ()>::operator()() const /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/std_function.h:590:9
[build] #25 0x0000000007285643 mlir::iree_compiler::IREE::HAL::TargetBackendRegistration::acquire()::$_0::operator()() const /usr/local/google/home/ravishankarm/iree/iree/compiler/src/iree/compiler/Dialect/HAL/Target/TargetRegistry.cpp:36:50
[build] #26 0x000000000728560d void std::__invoke_impl<void, mlir::iree_compiler::IREE::HAL::TargetBackendRegistration::acquire()::$_0>(std::__invoke_other, mlir::iree_compiler::IREE::HAL::TargetBackendRegistration::acquire()::$_0&&) /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/invoke.h:61:7
[build] #27 0x00000000072855cd std::__invoke_result<mlir::iree_compiler::IREE::HAL::TargetBackendRegistration::acquire()::$_0>::type std::__invoke<mlir::iree_compiler::IREE::HAL::TargetBackendRegistration::acquire()::$_0>(mlir::iree_compiler::IREE::HAL::TargetBackendRegistration::acquire()::$_0&&) /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/invoke.h:96:7
[build] #28 0x00000000072855a0 void std::call_once<mlir::iree_compiler::IREE::HAL::TargetBackendRegistration::acquire()::$_0>(std::once_flag&, mlir::iree_compiler::IREE::HAL::TargetBackendRegistration::acquire()::$_0&&)::'lambda'()::operator()() const /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/mutex:778:7
[build] #29 0x0000000007285577 std::once_flag::_Prepare_execution::_Prepare_execution<void std::call_once<mlir::iree_compiler::IREE::HAL::TargetBackendRegistration::acquire()::$_0>(std::once_flag&, mlir::iree_compiler::IREE::HAL::TargetBackendRegistration::acquire()::$_0&&)::'lambda'()>(mlir::iree_compiler::IREE::HAL::TargetBackendRegistration::acquire()::$_0&)::'lambda'()::operator()() const /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/mutex:712:68
[build] #30 0x0000000007285549 std::once_flag::_Prepare_execution::_Prepare_execution<void std::call_once<mlir::iree_compiler::IREE::HAL::TargetBackendRegistration::acquire()::$_0>(std::once_flag&, mlir::iree_compiler::IREE::HAL::TargetBackendRegistration::acquire()::$_0&&)::'lambda'()>(mlir::iree_compiler::IREE::HAL::TargetBackendRegistration::acquire()::$_0&)::'lambda'()::__invoke() /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/mutex:712:16
[build] #31 0x00007fe4921d4610 __pthread_once_slow ./nptl/pthread_once.c:118:7
[build] #32 0x00000000072854eb __gthread_once(int*, void (*)()) /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/x86_64-linux-gnu/c++/11/bits/gthr-default.h:700:5
[build] #33 0x0000000007284e95 void std::call_once<mlir::iree_compiler::IREE::HAL::TargetBackendRegistration::acquire()::$_0>(std::once_flag&, mlir::iree_compiler::IREE::HAL::TargetBackendRegistration::acquire()::$_0&&) /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/mutex:783:15
[build] #34 0x0000000007284e40 mlir::iree_compiler::IREE::HAL::TargetBackendRegistration::acquire() /usr/local/google/home/ravishankarm/iree/iree/compiler/src/iree/compiler/Dialect/HAL/Target/TargetRegistry.cpp:36:3
[build] #35 0x00000000072850ea mlir::iree_compiler::IREE::HAL::getTargetBackend(llvm::StringRef) /usr/local/google/home/ravishankarm/iree/iree/compiler/src/iree/compiler/Dialect/HAL/Target/TargetRegistry.cpp:57:7
[build] #36 0x00000000072851af mlir::iree_compiler::IREE::HAL::getTargetBackends(llvm::ArrayRef<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >) /usr/local/google/home/ravishankarm/iree/iree/compiler/src/iree/compiler/Dialect/HAL/Target/TargetRegistry.cpp:68:9
[build] #37 0x00000000070da5c3 mlir::iree_compiler::IREE::HAL::AssignTargetDevicesPass::getDependentDialects(mlir::DialectRegistry&) const /usr/local/google/home/ravishankarm/iree/iree/compiler/src/iree/compiler/Dialect/HAL/Transforms/AssignTargetDevices.cpp:39:10
[build] #38 0x000000000b4152be registerDialectsForPipeline(mlir::OpPassManager const&, mlir::DialectRegistry&) /usr/local/google/home/ravishankarm/iree/iree/third_party/llvm-project/mlir/lib/Pass/Pass.cpp:384:25
[build] #39 0x000000000b41522d mlir::OpPassManager::getDependentDialects(mlir::DialectRegistry&) const /usr/local/google/home/ravishankarm/iree/iree/third_party/llvm-project/mlir/lib/Pass/Pass.cpp:390:1
[build] #40 0x000000000b417353 mlir::PassManager::run(mlir::Operation*) /usr/local/google/home/ravishankarm/iree/iree/third_party/llvm-project/mlir/lib/Pass/Pass.cpp:792:3
[build] #41 0x0000000003fef49f mlir::iree_compiler::runIreecMain(int, char**)::$_2::operator()(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, llvm::raw_ostream&) const /usr/local/google/home/ravishankarm/iree/iree/compiler/src/iree/compiler/Tools/iree_compile_lib.cc:273:28
[build] #42 0x0000000003feeb2f mlir::iree_compiler::runIreecMain(int, char**) /usr/local/google/home/ravishankarm/iree/iree/compiler/src/iree/compiler/Tools/iree_compile_lib.cc:321:16
[build] #43 0x0000000003fedf72 main /usr/local/google/home/ravishankarm/iree/iree/tools/iree-compile-main.cc:10:3
[build] #44 0x00007fe491d727fd __libc_start_main ./csu/../csu/libc-start.c:332:16
[build] #45 0x0000000003fede8a _start (/usr/local/google/home/ravishankarm/iree/build_debug/tools/iree-compile+0x3fede8a)

There are other similar failures as well for RISC-V.Build shouldnt fail, but wondering if we can have a way to control which tests get built based on the cmake flag above.
Steps to reproduce your issue

Go to '...'
Click on '....'
Scroll down to '....'
See error

What component(s) does this issue relate to?
No response
Version information
No response
Additional context
No response

Closing comment (2022-06-15T00:07:16Z): This is duplicate of #8574