llvm / llvm/llvm-project

[lld_link] LTO-thin + O3 on Win causes crash on thread-local static global class member

Open
#199,462 0 comments 0 reactions 0 assignees View on GitHub
confirmed crash-on-valid
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

```
struct Ptr {
Ptr() {}
int *t;
};
struct DasThreadLocal {
inline static thread_local Ptr value_{};
};

DasThreadLocal g_AOT_lib;
```

Running code above causes lld_link.exe crash on windows with following stacktrace on current master:
```
$ bash crash.sh ../src/ast/ast.cpp
../src/ast/ast.cpp:8:5: warning: inline variables are a C++17 extension [-Wc++17-extensions]
8 | inline static thread_local Ptr value_{};
| ^
1 warning generated.
LLVM ERROR: Associative COMDAT symbol '?value_@DasThreadLocal@@2UPtr@@A' does not exist.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Exception Code: 0xC000001D
#0 0x00007ff7078da56c HandleAbort C:\Users\PC\Downloads\llvm-project\llvm\lib\Support\Windows\Signals.inc:372:0
#1 0x00007ffebf229e77 (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0x99e77)
#2 0x00007ffebf22bab9 (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0x9bab9)
#3 0x00007ff7077408f7 llvm::report_fatal_error(class llvm::Twine const &, bool) C:\Users\PC\Downloads\llvm-project\llvm\lib\Support\ErrorHandling.cpp:137:0
#4 0x00007ff7085dff8d getComdatGVForCOFF C:\Users\PC\Downloads\llvm-project\llvm\lib\CodeGen\TargetLoweringObjectFileImpl.cpp:1715:0
#5 0x00007ff7085dfd9e getSelectionForCOFF C:\Users\PC\Downloads\llvm-project\llvm\lib\CodeGen\TargetLoweringObjectFileImpl.cpp:1724:0
#6 0x00007ff7085dfafa llvm::TargetLoweringObjectFileCOFF::getExplicitSectionGlobal(class llvm::GlobalObject const *, class llvm::SectionKind, class llvm::TargetMachine const &) const C:\Users\PC\Downloads\llvm-project\llvm\lib\CodeGen\TargetLoweringObjectFileImpl.cpp:1764:0
#7 0x00007ff7085ec6db llvm::TargetLoweringObjectFile::SectionForGlobal(class llvm::GlobalObject const *, class llvm::SectionKind, class llvm::TargetMachine const &) const C:\Users\PC\Downloads\llvm-project\llvm\lib\Target\TargetLoweringObjectFile.cpp:378:0
#8 0x00007ff708ae0e69 llvm::AsmPrinter::emitGlobalVariable(class llvm::GlobalVariable const *) C:\Users\PC\Downloads\llvm-project\llvm\lib\CodeGen\AsmPrinter\AsmPrinter.cpp:865:0
#9 0x00007ff708aecf5d llvm::AsmPrinter::doFinalization(class llvm::Module &) C:\Users\PC\Downloads\llvm-project\llvm\lib\CodeGen\AsmPrinter\AsmPrinter.cpp:2907:0
#10 0x00007ff708a08ab0 llvm::FPPassManager::doFinalization(class llvm::Module &) C:\Users\PC\Downloads\llvm-project\llvm\lib\IR\LegacyPassManager.cpp:1446:0
#11 0x00007ff708a04eeb `anonymous namespace'::MPPassManager::runOnModule C:\Users\PC\Downloads\llvm-project\llvm\lib\IR\LegacyPassManager.cpp:1533:0
#12 0x00007ff708a04795 llvm::legacy::PassManagerImpl::run(class llvm::Module &) C:\Users\PC\Downloads\llvm-project\llvm\lib\IR\LegacyPassManager.cpp:531:0
#13 0x00007ff708a08c31 llvm::legacy::PassManager::run(class llvm::Module &) C:\Users\PC\Downloads\llvm-project\llvm\lib\IR\LegacyPassManager.cpp:1624:0
#14 0x00007ff708ba847e codegen C:\Users\PC\Downloads\llvm-project\llvm\lib\LTO\LTOBackend.cpp:508:0
#15 0x00007ff708ba9268 llvm::lto::thinBackend::::operator() C:\Users\PC\Downloads\llvm-project\llvm\lib\LTO\LTOBackend.cpp:701:0
#16 0x00007ff708ba904c llvm::lto::thinBackend(struct llvm::lto::Config const &, unsigned int, class std::function<(unsigned int, class llvm::Twine const &)>, class llvm::Module &, class llvm::ModuleSummaryIndex const &, class llvm::FunctionImporter::ImportMapTy const &, class llvm::DenseMap, struct llvm::detail::DenseMapPair> const &, class llvm::MapVector, struct llvm::detail::DenseMapPair>, class llvm::SmallVector, 0>, 0> *, bool, class llvm::ArrayRef, class std::function<(unsigned int, class llvm::Twine const &)>, class std::vector> const &) C:\Users\PC\Downloads\llvm-project\llvm\lib\LTO\LTOBackend.cpp:779:0
#17 0x00007ff707b840f8 `anonymous namespace'::InProcessThinBackend::runThinLTOBackendThread::::operator() C:\Users\PC\Downloads\llvm-project\llvm\lib\LTO\LTO.cpp:1630:0
#18 0x00007ff707b82db4 `anonymous namespace'::InProcessThinBackend::runThinLTOBackendThread C:\Users\PC\Downloads\llvm-project\llvm\lib\LTO\LTO.cpp:1644:0
#19 0x00007ff707b83d76 `anonymous namespace'::InProcessThinBackend::start::::operator() C:\Users\PC\Downloads\llvm-project\llvm\lib\LTO\LTO.cpp:1684:0
#20 0x00007ff707b83bc2 std::invoke<`lambda at C:\Users\PC\Downloads\llvm-project\llvm\lib\LTO\LTO.cpp:1671:9' &,llvm::BitcodeModule &,llvm::ModuleSummaryIndex &,const llvm::FunctionImporter::ImportMapTy &,const llvm::DenseSet > &,const std::map,std::allocator > > &,const llvm::DenseMap,llvm::detail::DenseMapPair > &,llvm::MapVector,llvm::detail::DenseMapPair >,llvm::SmallVector,0>,0> &> C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\include\type_traits:1680:0
#21 0x00007ff707b83ac6 std::_Invoker_ret::_Call<`lambda at C:\Users\PC\Downloads\llvm-project\llvm\lib\LTO\LTO.cpp:1671:9' &,llvm::BitcodeModule &,llvm::ModuleSummaryIndex &,const llvm::FunctionImporter::ImportMapTy &,const llvm::DenseSet > &,const std::map,std::allocator > > &,const llvm::DenseMap,llvm::detail::DenseMapPair > &,llvm::MapVector,llvm::detail::DenseMapPair >,llvm::SmallVector,0>,0> &> C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\include\functional:2117:0
#22 0x00007ff707b83a26 std::_Call_binder,std::reference_wrapper,std::reference_wrapper > >,std::reference_wrapper,std::allocator > > >,std::reference_wrapper,llvm::detail::DenseMapPair > >,std::reference_wrapper,llvm::detail::DenseMapPair >,llvm::SmallVector,0>,0> > >,std::tuple<> > C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\include\functional:2127:0
#23 0x00007ff707b83862 std::_Binder,std::reference_wrapper,std::reference_wrapper > >,std::reference_wrapper,std::allocator > > >,std::reference_wrapper,llvm::detail::DenseMapPair > >,std::reference_wrapper,llvm::detail::DenseMapPair >,llvm::SmallVector,0>,0> > >::operator()<0> C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\include\functional:2199:0
#24 0x00007ff707b837bd llvm::detail::UniqueFunctionBase::CallImpl,std::reference_wrapper,std::reference_wrapper > >,std::reference_wrapper,std::allocator > > >,std::reference_wrapper,llvm::detail::DenseMapPair > >,std::reference_wrapper,llvm::detail::DenseMapPair >,llvm::SmallVector,0>,0> > > > C:\Users\PC\Downloads\llvm-project\llvm\include\llvm\ADT\FunctionExtras.h:211:0
#25 0x00007ff707bd0a21 llvm::unique_function<(void)>::operator()(void) C:\Users\PC\Downloads\llvm-project\llvm\include\llvm\ADT\FunctionExtras.h:361:0
#26 0x00007ff707bd09d3 std::invoke>(class llvm::unique_function<(void)> &&) C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\include\type_traits:1670:0
#27 0x00007ff707bd09af std::_Invoke_stored_explicit, 0>(class std::tuple> &&, struct std::integer_sequence) C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\include\future:1310:0
#28 0x00007ff707bd0987 std::_Invoke_stored>(class std::tuple> &&) C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\include\future:1315:0
#29 0x00007ff707bd0963 std::_Fake_no_copy_callable_adapter>::operator()(void) C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\include\future:1342:0
#30 0x00007ff707bd0943 std::invoke> &>(class std::_Fake_no_copy_callable_adapter> &) C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\include\type_traits:1670:0
#31 0x00007ff707bcff27 std::_Func_impl_no_alloc>, void>::_Do_call(void) C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\include\functional:884:0
#32 0x00007ff707743cfd std::_Func_class::operator()(void) const C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\include\functional:926:0
#33 0x00007ff707bd0ccf std::_Packaged_state<(void)>::_Call_immediate(void) C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\include\future:533:0
#34 0x00007ff707bcfd2c std::_Deferred_async_state::_Run_deferred_function(class std::unique_lock &) C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\include\future:608:0
#35 0x00007ff70799d8c8 std::_Associated_state::_Maybe_run_deferred_function(class std::unique_lock &) C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\include\future:398:0
#36 0x00007ff70799d620 std::_Associated_state::_Wait(void) C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\include\future:239:0
#37 0x00007ff70799c8d4 std::_State_manager::wait(void) const C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\include\future:709:0
#38 0x00007ff707bd1b83 `private: class std::shared_future __cdecl llvm::ThreadPoolInterface::asyncImpl(class llvm::unique_function, class llvm::ThreadPoolTaskGroup *)'::`1'::::operator()(void) const C:\Users\PC\Downloads\llvm-project\llvm\include\llvm\Support\ThreadPool.h:116:0
#39 0x00007ff707bd1b0d llvm::detail::UniqueFunctionBase::CallImpl __cdecl llvm::ThreadPoolInterface::asyncImpl(class llvm::unique_function, class llvm::ThreadPoolTaskGroup *)'::`1'::>(void *) C:\Users\PC\Downloads\llvm-project\llvm\include\llvm\ADT\FunctionExtras.h:211:0
#40 0x00007ff707bd0a21 llvm::unique_function<(void)>::operator()(void) C:\Users\PC\Downloads\llvm-project\llvm\include\llvm\ADT\FunctionExtras.h:361:0
#41 0x00007ff708ee6df7 llvm::StdThreadPool::processTasks(class llvm::ThreadPoolTaskGroup *) C:\Users\PC\Downloads\llvm-project\llvm\lib\Support\ThreadPool.cpp:119:0
#42 0x00007ff708ee85ce llvm::StdThreadPool::grow::::operator() C:\Users\PC\Downloads\llvm-project\llvm\lib\Support\ThreadPool.cpp:63:0
#43 0x00007ff708ee8528 llvm::thread::GenericThreadProxy >::::operator()<`lambda at C:\Users\PC\Downloads\llvm-project\llvm\lib\Support\ThreadPool.cpp:51:26' &> C:\Users\PC\Downloads\llvm-project\llvm\include\llvm\Support\thread.h:47:0
#44 0x00007ff708ee84ed std::invoke<`lambda at C:\Users\PC\Downloads\llvm-project\llvm\include\llvm\Support\thread.h:45:9',`lambda at C:\Users\PC\Downloads\llvm-project\llvm\lib\Support\ThreadPool.cpp:51:26' &> C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\include\type_traits:1680:0
#45 0x00007ff708ee84ca std::_Apply_impl<`lambda at C:\Users\PC\Downloads\llvm-project\llvm\include\llvm\Support\thread.h:45:9',std::tuple<`lambda at C:\Users\PC\Downloads\llvm-project\llvm\lib\Support\ThreadPool.cpp:51:26'> &,0> C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\include\tuple:1058:0
#46 0x00007ff708ee8482 std::apply<`lambda at C:\Users\PC\Downloads\llvm-project\llvm\include\llvm\Support\thread.h:45:9',std::tuple<`lambda at C:\Users\PC\Downloads\llvm-project\llvm\lib\Support\ThreadPool.cpp:51:26'> &> C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\include\tuple:1069:0
#47 0x00007ff708ee844f llvm::thread::GenericThreadProxy > C:\Users\PC\Downloads\llvm-project\llvm\include\llvm\Support\thread.h:49:0
#48 0x00007ff708ee8303 llvm::thread::ThreadProxy > C:\Users\PC\Downloads\llvm-project\llvm\include\llvm\Support\thread.h:73:0
#49 0x00007ffebf232ec5 (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0xa2ec5)
#50 0x00007ffef4c4e8d7 (C:\WINDOWS\System32\KERNEL32.DLL+0x2e8d7)
#51 0x00007ffef616c3fc (C:\WINDOWS\SYSTEM32\ntdll.dll+0x8c3fc)
crash.sh: line 4: 2844 Illegal instruction /c/Users/PC/Downloads/llvm-project/build/bin/lld-link.exe crash_test.obj //DLL //FORCE
```

```
$ cat crash.sh
#!/bin/bash
INPUT_FILE="$1"
/c/Users/PC/Downloads/llvm-project/build/bin/clang++.exe -c "$INPUT_FILE" -o crash_test.obj -flto=thin -O3
/c/Users/PC/Downloads/llvm-project/build/bin/lld-link.exe crash_test.obj //DLL //FORCE
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.