[lld-link] [LTO] Assertion "Empty/Tombstone value shouldn't be inserted into map!" in `CodeViewDebug`
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Hi,
I'm trying to build [Vulkan-Loader](https://github.com/KhronosGroup/Vulkan-Loader) with a `clang-cl` toolchain with LTO enabled, but linking `vulkan-1.dll` with `lld-link` fails.
With an official release distribution of LLVM 19, the linker just hangs indefinitely, while consuming CPU.
With the latest LLVM built from source (a903b9512750cf1c5cd6c6f233f74257bae5d4bf) with assertions enabled, it crashes with the assertion `Assertion failed: !KeyInfoT::isEqual(Val, EmptyKey) && !KeyInfoT::isEqual(Val, TombstoneKey) && "Empty/Tombstone value shouldn't be inserted into map!", file llvm\include\llvm/ADT/DenseMap.h, line 690`.
As far as I can tell from debugging, `GloballyHashedType::hashType()` called here: https://github.com/llvm/llvm-project/blob/3718ab29aa885036143a630ecd53dea52c41b57c/llvm/lib/DebugInfo/CodeView/GlobalTypeTableBuilder.cpp#L88
ends up returning an empty hash here: https://github.com/llvm/llvm-project/blob/3718ab29aa885036143a630ecd53dea52c41b57c/llvm/lib/DebugInfo/CodeView/TypeHashing.cpp#L65
This behaviour can be reproduced when the sources are compiled with `-flto=full` or `-flto=thin`, but not without LTO.
Here's the full output of `lld-link`:
```
Assertion failed: !KeyInfoT::isEqual(Val, EmptyKey) && !KeyInfoT::isEqual(Val, TombstoneKey) && "Empty/Tombstone value shouldn't be inserted into map!", file llvm\include\llvm/ADT/DenseMap.h, line 690
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0. Program arguments: llvm\build\Release\bin\lld-link.exe /nologo loader\CMakeFiles\vulkan.dir\allocation.c.obj loader\CMakeFiles\vulkan.dir\cJSON.c.obj loader\CMakeFiles\vulkan.dir\debug_utils.c.obj loader\CMakeFiles\vulkan.dir\extension_manual.c.obj loader\CMakeFiles\vulkan.dir\loader_environment.c.obj loader\CMakeFiles\vulkan.dir\gpa_helper.c.obj loader\CMakeFiles\vulkan.dir\loader.c.obj loader\CMakeFiles\vulkan.dir\log.c.obj loader\CMakeFiles\vulkan.dir\loader_json.c.obj loader\CMakeFiles\vulkan.dir\settings.c.obj loader\CMakeFiles\vulkan.dir\terminator.c.obj loader\CMakeFiles\vulkan.dir\trampoline.c.obj loader\CMakeFiles\vulkan.dir\unknown_function_handling.c.obj loader\CMakeFiles\vulkan.dir\wsi.c.obj loader\CMakeFiles\vulkan.dir\loader_windows.c.obj loader\CMakeFiles\vulkan.dir\dirent_on_windows.c.obj loader\CMakeFiles\vulkan.dir\dev_ext_trampoline.c.obj loader\CMakeFiles\vulkan.dir\phys_dev_ext.c.obj loader\CMakeFiles\vulkan.dir\unknown_ext_chain_masm.asm.obj loader\CMakeFiles\vulkan.dir\loader.rc.res /out:loader\vulkan-1.dll /implib:loader\vulkan-1.lib /pdb:loader\vulkan-1.pdb /dll /version:0.0 -debug:full -pdbaltpath:%_PDB% -opt:ref -opt:icf /machine:x64 /INCREMENTAL:NO /DEF:..\src\loader\vulkan-1.def cfgmgr32.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST:EMBED,ID=2
1. Running pass 'Function Pass Manager' on module 'ld-temp.o'.
2. Running pass 'X86 Assembly Printer' on function '@loader_icd_scan'
Exception Code: 0xC000001D
#0 0x00007ff711641996 HandleAbort llvm\lib\Support\Windows\Signals.inc:372:0
#1 0x00007ff714bba189 raise llvm\build\Release\minkernel\crts\ucrt\src\appcrt\misc\signal.cpp:547:0
#2 0x00007ff714bb1de0 abort llvm\build\Release\minkernel\crts\ucrt\src\appcrt\startup\abort.cpp:71:0
#3 0x00007ff714bb2437 common_assert_to_stderr llvm\build\Release\minkernel\crts\ucrt\src\appcrt\startup\assert.cpp:186:0
#4 0x00007ff714bb22ae _wassert llvm\build\Release\minkernel\crts\ucrt\src\appcrt\startup\assert.cpp:443:0
#5 0x00007ff71257d879 llvm::DenseMapBase, struct llvm::detail::DenseMapPair>, struct llvm::codeview::GloballyHashedType, class llvm::codeview::TypeIndex, struct llvm::DenseMapInfo, struct llvm::detail::DenseMapPair>::LookupBucketFor(struct llvm::codeview::GloballyHashedType const &, struct llvm::detail::DenseMapPair *&) llvm\include\llvm\ADT\DenseMap.h:688:0
#6 0x00007ff713c73bae llvm::DenseMapBase,llvm::detail::DenseMapPair >,llvm::codeview::GloballyHashedType,llvm::codeview::TypeIndex,llvm::DenseMapInfo,llvm::detail::DenseMapPair >::lookupOrInsertIntoBucket llvm\include\llvm\ADT\DenseMap.h:532:0
#7 0x00007ff713c73bae llvm::DenseMapBase,llvm::detail::DenseMapPair >,llvm::codeview::GloballyHashedType,llvm::codeview::TypeIndex,llvm::DenseMapInfo,llvm::detail::DenseMapPair >::try_emplace_impl llvm\include\llvm\ADT\DenseMap.h:544:0
#8 0x00007ff713c73bae llvm::DenseMapBase,llvm::detail::DenseMapPair >,llvm::codeview::GloballyHashedType,llvm::codeview::TypeIndex,llvm::DenseMapInfo,llvm::detail::DenseMapPair >::try_emplace llvm\include\llvm\ADT\DenseMap.h:263:0
#9 0x00007ff713c73bae llvm::codeview::GlobalTypeTableBuilder::insertRecordAs llvm\include\llvm\DebugInfo\CodeView\GlobalTypeTableBuilder.h:79:0
#10 0x00007ff713c73bae llvm::codeview::GlobalTypeTableBuilder::insertRecordBytes(class llvm::ArrayRef) llvm\lib\DebugInfo\CodeView\GlobalTypeTableBuilder.cpp:89:0
#11 0x00007ff713c73e36 std::_Vector_const_iterator > > >::operator++ C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\vector:82:0
#12 0x00007ff713c73e36 std::_Vector_iterator > > >::operator++ C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\vector:287:0
#13 0x00007ff713c73e36 llvm::codeview::GlobalTypeTableBuilder::insertRecord(class llvm::codeview::ContinuationRecordBuilder &) llvm\lib\DebugInfo\CodeView\GlobalTypeTableBuilder.cpp:102:0
#14 0x00007ff71330b663 llvm::CodeViewDebug::lowerTypeEnum llvm\lib\CodeGen\AsmPrinter\CodeViewDebug.cpp:2292:0
#15 0x00007ff71330b663 llvm::CodeViewDebug::lowerType llvm\lib\CodeGen\AsmPrinter\CodeViewDebug.cpp:1699:0
#16 0x00007ff71330b663 llvm::CodeViewDebug::getTypeIndex llvm\lib\CodeGen\AsmPrinter\CodeViewDebug.cpp:2701:0
#17 0x00007ff71330a434 llvm::DINode::getStringOperand llvm\include\llvm\IR\DebugInfoMetadata.h:147:0
#18 0x00007ff71330a434 llvm::DIType::getName llvm\include\llvm\IR\DebugInfoMetadata.h:754:0
#19 0x00007ff71330a434 llvm::CodeViewDebug::lowerTypeAlias llvm\lib\CodeGen\AsmPrinter\CodeViewDebug.cpp:1719:0
#20 0x00007ff71330a434 llvm::CodeViewDebug::lowerType llvm\lib\CodeGen\AsmPrinter\CodeViewDebug.cpp:1672:0
#21 0x00007ff71330a434 llvm::CodeViewDebug::getTypeIndex llvm\lib\CodeGen\AsmPrinter\CodeViewDebug.cpp:2701:0
#22 0x00007ff71331b54c llvm::DINode::getStringOperand llvm\include\llvm\IR\DebugInfoMetadata.h:147:0
#23 0x00007ff71331b54c llvm::DIType::getName llvm\include\llvm\IR\DebugInfoMetadata.h:754:0
#24 0x00007ff71331b54c llvm::CodeViewDebug::lowerRecordFieldList llvm\lib\CodeGen\AsmPrinter\CodeViewDebug.cpp:2585:0
#25 0x00007ff7133176ee std::tuple::operator= C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\tuple:614:0
#26 0x00007ff7133176ee llvm::CodeViewDebug::lowerCompleteTypeClass llvm\lib\CodeGen\AsmPrinter\CodeViewDebug.cpp:2473:0
#27 0x00007ff7133176ee llvm::CodeViewDebug::getCompleteTypeIndex llvm\lib\CodeGen\AsmPrinter\CodeViewDebug.cpp:2784:0
#28 0x00007ff71330be60 llvm::CodeViewDebug::emitDeferredCompleteTypes llvm\lib\CodeGen\AsmPrinter\CodeViewDebug.cpp:2809:0
#29 0x00007ff71330be60 llvm::CodeViewDebug::TypeLoweringScope::~TypeLoweringScope llvm\lib\CodeGen\AsmPrinter\CodeViewDebug.cpp:319:0
#30 0x00007ff71330be60 llvm::CodeViewDebug::getTypeIndex llvm\lib\CodeGen\AsmPrinter\CodeViewDebug.cpp:2703:0
#31 0x00007ff713309415 llvm::codeview::TypeRecord::TypeRecord llvm\include\llvm\DebugInfo\CodeView\TypeRecord.h:121:0
#32 0x00007ff713309415 llvm::codeview::FuncIdRecord::FuncIdRecord llvm\include\llvm\DebugInfo\CodeView\TypeRecord.h:616:0
#33 0x00007ff713309415 llvm::CodeViewDebug::getFuncIdForSubprogram llvm\lib\CodeGen\AsmPrinter\CodeViewDebug.cpp:414:0
#34 0x00007ff713308a7f llvm::MDNode::Header::getNumOperands llvm\include\llvm\IR\Metadata.h:1179:0
#35 0x00007ff713308a7f llvm::MDNode::getNumOperands llvm\include\llvm\IR\Metadata.h:1450:0
#36 0x00007ff713308a7f llvm::DILocation::getRawInlinedAt llvm\include\llvm\IR\DebugInfoMetadata.h:2917:0
#37 0x00007ff713308a7f llvm::DILocation::getInlinedAt llvm\include\llvm\IR\DebugInfoMetadata.h:2717:0
#38 0x00007ff713308a7f llvm::CodeViewDebug::getInlineSite llvm\lib\CodeGen\AsmPrinter\CodeViewDebug.cpp:256:0
#39 0x00007ff713308725 llvm::CodeViewDebug::getInlineSite llvm\lib\CodeGen\AsmPrinter\CodeViewDebug.cpp:244:0
#40 0x00007ff71330d345 llvm::CodeViewDebug::maybeRecordLocation llvm\lib\CodeGen\AsmPrinter\CodeViewDebug.cpp:545:0
#41 0x00007ff713320c57 llvm::TrackingMDRef::untrack llvm\include\llvm\IR\TrackingMDRef.h:89:0
#42 0x00007ff713320c57 llvm::TrackingMDRef::~TrackingMDRef llvm\include\llvm\IR\TrackingMDRef.h:55:0
#43 0x00007ff713320c57 llvm::TypedTrackingMDRef::~TypedTrackingMDRef llvm\include\llvm\IR\TrackingMDRef.h:106:0
#44 0x00007ff713320c57 llvm::DebugLoc::~DebugLoc llvm\include\llvm\IR\DebugLoc.h:123:0
#45 0x00007ff713320c57 llvm::CodeViewDebug::beginInstruction llvm\lib\CodeGen\AsmPrinter\CodeViewDebug.cpp:3174:0
#46 0x00007ff712130d4d llvm::AsmPrinter::emitFunctionBody(void) llvm\lib\CodeGen\AsmPrinter\AsmPrinter.cpp:2132:0
#47 0x00007ff7117ac524 llvm::X86AsmPrinter::runOnMachineFunction llvm\lib\Target\X86\X86AsmPrinter.cpp:109:0
#48 0x00007ff711db7a23 llvm::MachineFunctionPass::runOnFunction(class llvm::Function &) llvm\lib\CodeGen\MachineFunctionPass.cpp:112:0
#49 0x00007ff711dbc01f llvm::FPPassManager::runOnFunction(class llvm::Function &) llvm\lib\IR\LegacyPassManager.cpp:1385:0
#50 0x00007ff711dc646d llvm::FPPassManager::runOnModule(class llvm::Module &) llvm\lib\IR\LegacyPassManager.cpp:1431:0
#51 0x00007ff711dbce15 `anonymous namespace'::MPPassManager::runOnModule llvm\lib\IR\LegacyPassManager.cpp:1500:0
#52 0x00007ff711dbce15 llvm::legacy::PassManagerImpl::run(class llvm::Module &) llvm\lib\IR\LegacyPassManager.cpp:531:0
#53 0x00007ff7121a2a54 std::unique_ptr >::operator bool C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\memory:3461:0
#54 0x00007ff7121a2a54 codegen llvm\lib\LTO\LTOBackend.cpp:502:0
#55 0x00007ff7121a11ec llvm::Error::setChecked llvm\include\llvm\Support\Error.h:306:0
#56 0x00007ff7121a11ec llvm::Error::operator= llvm\include\llvm\Support\Error.h:221:0
#57 0x00007ff7121a11ec llvm::Error::Error llvm\include\llvm\Support\Error.h:198:0
#58 0x00007ff7121a11ec llvm::lto::backend(struct llvm::lto::Config const &, class std::function<(unsigned int, class llvm::Twine const &)>, unsigned int, class llvm::Module &, class llvm::ModuleSummaryIndex &, class llvm::ArrayRef) llvm\lib\LTO\LTOBackend.cpp:0:0
#59 0x00007ff7117db451 llvm::Error::getPtr llvm\include\llvm\Support\Error.h:277:0
#60 0x00007ff7117db451 llvm::Error::operator bool llvm\include\llvm\Support\Error.h:241:0
#61 0x00007ff7117db451 llvm::lto::LTO::runRegularLTO llvm\lib\LTO\LTO.cpp:1484:0
#62 0x00007ff7117db451 llvm::lto::LTO::run(class std::function<(unsigned int, class llvm::Twine const &)>, struct llvm::FileCache) llvm\lib\LTO\LTO.cpp:1355:0
#63 0x00007ff7117c99f1 lld::coff::BitcodeCompiler::compile(void) lld\COFF\LTO.cpp:216:0
#64 0x00007ff711706818 std::vector >::begin C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\vector:1842:0
#65 0x00007ff711706818 lld::coff::SymbolTable::compileBitcodeFiles(void) lld\COFF\SymbolTable.cpp:1507:0
#66 0x00007ff711594294 std::_Func_class::_Getimpl C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\functional:1051:0
#67 0x00007ff711594294 std::_Func_class::_Empty C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\functional:945:0
#68 0x00007ff711594294 std::_Func_class::_Tidy C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\functional:1008:0
#69 0x00007ff711594294 std::_Func_class::~_Func_class C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\include\functional:930:0
#70 0x00007ff711594294 lld::coff::COFFLinkerContext::forEachSymtab lld\COFF\COFFLinkerContext.h:52:0
#71 0x00007ff711583a70 lld::coff::LinkerDriver::linkerMain(class llvm::ArrayRef) lld\COFF\Driver.cpp:2774:0
#72 0x00007ff711574d65 lld::coff::link(class llvm::ArrayRef, class llvm::raw_ostream &, class llvm::raw_ostream &, bool, bool) lld\COFF\Driver.cpp:98:0
#73 0x00007ff71157408a lld::unsafeLldMain(class llvm::ArrayRef, class llvm::raw_ostream &, class llvm::raw_ostream &, class llvm::ArrayRef, bool) lld\Common\DriverDispatcher.cpp:163:0
#74 0x00007ff7115314d5 lld_main(int, char **, struct llvm::ToolContext const &) lld\tools\lld\lld.cpp:89:0
#75 0x00007ff711531dcc main llvm\build\Release\tools\lld\tools\lld\lld-driver.cpp:17:0
#76 0x00007ff714b9a578 invoke_main D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78:0
#77 0x00007ff714b9a578 __scrt_common_main_seh D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288:0
#78 0x00007ffba3f1e957 (C:\WINDOWS\System32\KERNEL32.DLL+0x2e957)
#79 0x00007ffba548427c (C:\WINDOWS\SYSTEM32\ntdll.dll+0x427c)
Illegal instruction
```
I'm attaching a reproducer, generated with the `/reproduce:` flag: [repro-full.tar.gz](https://github.com/user-attachments/files/28274014/repro-full.tar.gz).
Here's an example of the `clang-cl` command line:
```
clang-cl.exe /nologo -DNDEBUG -DNTDDI_VERSION=0x0A000007 -DUNKNOWN_FUNCTIONS_SUPPORTED -DVK_ENABLE_BETA_EXTENSIONS -DVK_USE_PLATFORM_WIN32_KHR -DWIN32_LEAN_AND_MEAN -D_WIN32_WINNT=0x0A00 -Dvulkan_EXPORTS -I..\src\loader -I..\src\loader\generated -Iloader -imsvcG:\.conan2\p\b\vulkaa66eb1f8635f5\p\include -volatile:iso -Werror=writable-strings -Z7 -march=x86-64-v3 -O2 -Gw -flto=thin /DWIN32 /D_WINDOWS /O2 /Ob2 /DNDEBUG /std:c17 -MD -flto=full /W4 -Wno-missing-field-initializers /clang:-fno-strict-aliasing -Wpointer-arith /wd4152 /wd4201 -clang:-MD -clang:-MTloader\CMakeFiles\vulkan.dir\unknown_function_handling.c.obj -clang:-MFloader\CMakeFiles\vulkan.dir\unknown_function_handling.c.obj.d /Foloader\CMakeFiles\vulkan.dir\unknown_function_handling.c.obj /Fdloader\CMakeFiles\vulkan.dir\ -c -- ..\src\loader\unknown_function_handling.c
```
Please let me know if there's anything else I can provide which would help.
I'm currently building using Conan, but if needed I can try and make a standalone reproducer using the original `Vulkan-Loader` repo.
Contributor guide
Assessment
This issue has not been assessed yet.