-
Notifications
You must be signed in to change notification settings - Fork 12k
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
LLVM do not generate __emutls_v.xx symbol for TLS variable alias #79732
Comments
@llvm/issue-subscribers-orcjit Author: Thrrreeee (Thrrreeee)
When I use ORC JIT to compile a .bc file that contains a TLS (Thread Local Storage) variable alias, the following error occurs.
From [the code of ORC JIT](https://github.com/llvm/llvm-project/blob/5abbb7b5d038c62d3dc37ac8a2d7d57deebac0c7/llvm/lib/ExecutionEngine/Orc/Layer.cpp#L51), `auto &GV = cast<GlobalVariable>(G);` means that only `GlobalVariable` can be be treated as __emutls_v.xx symbol, a GlobalAlias cannot be cast to a GlobalVariable. But in [LowerToTLSEmulatedModel()](https://github.com/llvm/llvm-project/blob/5abbb7b5d038c62d3dc37ac8a2d7d57deebac0c7/llvm/lib/Target/X86/X86ISelLowering.cpp) function, the TLS variable alias will be treated the same as a GlobalVariable. It will look up __emutls_v.xx symbol for alias, due to the absence of the addition of __emutls_v to the alias earlier, it fails to be located, resulting in an error.
So I have some doubts: Does ORC JIT by default not involve aliases in TLS-related processing (due to theoretical reasons, aliases do not need processing), or is it that ORC JIT does not yet support TLS variable aliases?
log info:
> TestReadIRcode: /home/jinrui/llvm-project-main/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp:9750: virtual SDValue llvm::TargetLowering::LowerToTLSEmulatedModel(const GlobalAddressSDNode *, SelectionDAG &) const: Assertion `EmuTlsVar && "Cannot find EmuTlsVar "' failed.
Stack dump:
> #0 0x00007fb5d83ce6ed llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/jinrui/llvm-project-main/llvm/lib/Support/Unix/Signals.inc:723:11
#1 0x00007fb5d83cebdb PrintStackTraceSignalHandler(void*) /home/jinrui/llvm-project-main/llvm/lib/Support/Unix/Signals.inc:798:1
#2 0x00007fb5d83ccc46 llvm::sys::RunSignalHandlers() /home/jinrui/llvm-project-main/llvm/lib/Support/Signals.cpp:105:5
#3 0x00007fb5d83cf395 SignalHandler(int) /home/jinrui/llvm-project-main/llvm/lib/Support/Unix/Signals.inc:413:1
#4 0x00007fb5d7b40520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#5 0x00007fb5d7b94a7c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#6 0x00007fb5d7b94a7c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
#7 0x00007fb5d7b94a7c pthread_kill ./nptl/pthread_kill.c:89:10
#8 0x00007fb5d7b40476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
#9 0x00007fb5d7b267f3 abort ./stdlib/abort.c:81:7
#10 0x00007fb5d7b2671b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#11 0x00007fb5d7b37e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#12 0x00007fb5e0a99b58 llvm::TargetLowering::LowerToTLSEmulatedModel(llvm::GlobalAddressSDNode const*, llvm::SelectionDAG&) const /home/jinrui/llvm-project-main/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp:9751:16
#13 0x00007fb5e16d245d llvm::X86TargetLowering::LowerGlobalTLSAddress(llvm::SDValue, llvm::SelectionDAG&) const /home/jinrui/llvm-project-main/llvm/lib/Target/X86/X86ISelLowering.cpp:18561:12
#14 0x00007fb5e1718ccd llvm::X86TargetLowering::LowerOperation(llvm::SDValue, llvm::SelectionDAG&) const /home/jinrui/llvm-project-main/llvm/lib/Target/X86/X86ISelLowering.cpp:31787:40
#15 0x00007fb5e077a468 (anonymous namespace)::SelectionDAGLegalize::LegalizeOp(llvm::SDNode*) /home/jinrui/llvm-project-main/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1308:29
#16 0x00007fb5e0778b04 llvm::SelectionDAG::Legalize() /home/jinrui/llvm-project-main/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:5587:13
#17 0x00007fb5e09f6aca llvm::SelectionDAGISel::CodeGenAndEmitDAG() /home/jinrui/llvm-project-main/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:908:3
#18 0x00007fb5e09f58cd llvm::SelectionDAGISel::SelectBasicBlock(llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, false, true>, llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, false, true>, bool&) /home/jinrui/llvm-project-main/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:702:1
#19 0x00007fb5e09f5306 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) /home/jinrui/llvm-project-main/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1709:11
#20 0x00007fb5e09f2847 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) /home/jinrui/llvm-project-main/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:482:3
#21 0x00007fb5e165d54a (anonymous namespace)::X86DAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) /home/jinrui/llvm-project-main/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp:192:7
#22 0x00007fb5dd61d92f llvm::MachineFunctionPass::runOnFunction(llvm::Function&) /home/jinrui/llvm-project-main/llvm/lib/CodeGen/MachineFunctionPass.cpp:91:8
#23 0x00007fb5d8b6ed9a llvm::FPPassManager::runOnFunction(llvm::Function&) /home/jinrui/llvm-project-main/llvm/lib/IR/LegacyPassManager.cpp:1435:23
#24 0x00007fb5d8b73bb2 llvm::FPPassManager::runOnModule(llvm::Module&) /home/jinrui/llvm-project-main/llvm/lib/IR/LegacyPassManager.cpp:1481:16
#25 0x00007fb5d8b6f64b (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) /home/jinrui/llvm-project-main/llvm/lib/IR/LegacyPassManager.cpp:1550:23
#26 0x00007fb5d8b6f1ca llvm::legacy::PassManagerImpl::run(llvm::Module&) /home/jinrui/llvm-project-main/llvm/lib/IR/LegacyPassManager.cpp:535:16
#27 0x00007fb5d8b73e91 llvm::legacy::PassManager::run(llvm::Module&) /home/jinrui/llvm-project-main/llvm/lib/IR/LegacyPassManager.cpp:1677:3
#28 0x00007fb5dfd3552e llvm::orc::SimpleCompiler::operator()(llvm::Module&) /home/jinrui/llvm-project-main/llvm/lib/ExecutionEngine/Orc/CompileUtils.cpp:54:3
#29 0x00007fb5dfe6c542 decltype(auto) llvm::orc::ThreadSafeModule::withModuleDo<llvm::orc::IRCompileLayer::IRCompiler&>(llvm::orc::IRCompileLayer::IRCompiler&) /home/jinrui/llvm-project-main/llvm/include/llvm/ExecutionEngine/Orc/ThreadSafeModule.h:137:3
#30 0x00007fb5dfe6c11c llvm::orc::IRCompileLayer::emit(std::unique_ptr<llvm::orc::MaterializationResponsibility, std::default_delete<llvm::orc::MaterializationResponsibility>>, llvm::orc::ThreadSafeModule) /home/jinrui/llvm-project-main/llvm/lib/ExecutionEngine/Orc/IRCompileLayer.cpp:32:12
#31 0x00007fb5dfe6d519 llvm::orc::IRTransformLayer::emit(std::unique_ptr<llvm::orc::MaterializationResponsibility, std::default_delete<llvm::orc::MaterializationResponsibility>>, llvm::orc::ThreadSafeModule) /home/jinrui/llvm-project-main/llvm/lib/ExecutionEngine/Orc/IRTransformLayer.cpp:25:5
#32 0x00007fb5dfe6d519 llvm::orc::IRTransformLayer::emit(std::unique_ptr<llvm::orc::MaterializationResponsibility, std::default_delete<llvm::orc::MaterializationResponsibility>>, llvm::orc::ThreadSafeModule) /home/jinrui/llvm-project-main/llvm/lib/ExecutionEngine/Orc/IRTransformLayer.cpp:25:5
#33 0x00007fb5dfe79bb5 llvm::orc::BasicIRLayerMaterializationUnit::materialize(std::unique_ptr<llvm::orc::MaterializationResponsibility, std::default_delete<llvm::orc::MaterializationResponsibility>>) /home/jinrui/llvm-project-main/llvm/lib/ExecutionEngine/Orc/Layer.cpp:171:3
#34 0x00007fb5dfd420a0 llvm::orc::MaterializationTask::run() /home/jinrui/llvm-project-main/llvm/lib/ExecutionEngine/Orc/Core.cpp:1921:35
#35 0x00007fb5dfd5d16a llvm::orc::ExecutionSession::runOnCurrentThread(std::unique_ptr<llvm::orc::Task, std::default_delete<llvm::orc::Task>>) /home/jinrui/llvm-project-main/llvm/include/llvm/ExecutionEngine/Orc/Core.h:1718:71
#36 0x00007fb5dfd9179a void llvm::detail::UniqueFunctionBase<void, std::unique_ptr<llvm::orc::Task, std::default_delete<llvm::orc::Task>>>::CallImpl<void (*)(std::unique_ptr<llvm::orc::Task, std::default_delete<llvm::orc::Task>>)>(void*, std::unique_ptr<llvm::orc::Task, std::default_delete<llvm::orc::Task>>&) /home/jinrui/llvm-project-main/llvm/include/llvm/ADT/FunctionExtras.h:220:5
#37 0x00007fb5dfd6128b llvm::unique_function<void (std::unique_ptr<llvm::orc::Task, std::default_delete<llvm::orc::Task>>)>::operator()(std::unique_ptr<llvm::orc::Task, std::default_delete<llvm::orc::Task>>) /home/jinrui/llvm-project-main/llvm/include/llvm/ADT/FunctionExtras.h:382:5
#38 0x00007fb5dfd5687d llvm::orc::ExecutionSession::dispatchTask(std::unique_ptr<llvm::orc::Task, std::default_delete<llvm::orc::Task>>) /home/jinrui/llvm-project-main/llvm/include/llvm/ExecutionEngine/Orc/Core.h:1609:5
#39 0x00007fb5dfd431ec llvm::orc::ExecutionSession::dispatchOutstandingMUs() /home/jinrui/llvm-project-main/llvm/lib/ExecutionEngine/Orc/Core.cpp:2309:5
#40 0x00007fb5dfd44b56 llvm::orc::ExecutionSession::OL_completeLookup(std::unique_ptr<llvm::orc::InProgressLookupState, std::default_delete<llvm::orc::InProgressLookupState>>, std::shared_ptr<llvm::orc::AsynchronousSymbolQuery>, std::function<void (llvm::DenseMap<llvm::orc::JITDylib*, llvm::DenseSet<llvm::orc::SymbolStringPtr, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr, void>>, llvm::DenseMapInfo<llvm::orc::JITDylib*, void>, llvm::detail::DenseMapPair<llvm::orc::JITDylib*, llvm::DenseSet<llvm::orc::SymbolStringPtr, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr, void>>>> const&)>) /home/jinrui/llvm-project-main/llvm/lib/ExecutionEngine/Orc/Core.cpp:2920:1
#41 0x00007fb5dfd95f03 llvm::orc::InProgressFullLookupState::complete(std::unique_ptr<llvm::orc::InProgressLookupState, std::default_delete<llvm::orc::InProgressLookupState>>) /home/jinrui/llvm-project-main/llvm/lib/ExecutionEngine/Orc/Core.cpp:580:5
#42 0x00007fb5dfd3cf93 llvm::orc::ExecutionSession::OL_applyQueryPhase1(std::unique_ptr<llvm::orc::InProgressLookupState, std::default_delete<llvm::orc::InProgressLookupState>>, llvm::Error) /home/jinrui/llvm-project-main/llvm/lib/ExecutionEngine/Orc/Core.cpp:2675:5
#43 0x00007fb5dfd3b140 llvm::orc::ExecutionSession::lookup(llvm::orc::LookupKind, std::vector<std::pair<llvm::orc::JITDylib*, llvm::orc::JITDylibLookupFlags>, std::allocator<std::pair<llvm::orc::JITDylib*, llvm::orc::JITDylibLookupFlags>>> const&, llvm::orc::SymbolLookupSet, llvm::orc::SymbolState, llvm::unique_function<void (llvm::Expected<llvm::DenseMap<llvm::orc::SymbolStringPtr, llvm::orc::ExecutorSymbolDef, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr, void>, llvm::detail::DenseMapPair<llvm::orc::SymbolStringPtr, llvm::orc::ExecutorSymbolDef>>>)>, std::function<void (llvm::DenseMap<llvm::orc::JITDylib*, llvm::DenseSet<llvm::orc::SymbolStringPtr, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr, void>>, llvm::DenseMapInfo<llvm::orc::JITDylib*, void>, llvm::detail::DenseMapPair<llvm::orc::JITDylib*, llvm::DenseSet<llvm::orc::SymbolStringPtr, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr, void>>>> const&)>) /home/jinrui/llvm-project-main/llvm/lib/ExecutionEngine/Orc/Core.cpp:2147:3
#44 0x00007fb5dfd433bd llvm::orc::ExecutionSession::lookup(std::vector<std::pair<llvm::orc::JITDylib*, llvm::orc::JITDylibLookupFlags>, std::allocator<std::pair<llvm::orc::JITDylib*, llvm::orc::JITDylibLookupFlags>>> const&, llvm::orc::SymbolLookupSet, llvm::orc::LookupKind, llvm::orc::SymbolState, std::function<void (llvm::DenseMap<llvm::orc::JITDylib*, llvm::DenseSet<llvm::orc::SymbolStringPtr, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr, void>>, llvm::DenseMapInfo<llvm::orc::JITDylib*, void>, llvm::detail::DenseMapPair<llvm::orc::JITDylib*, llvm::DenseSet<llvm::orc::SymbolStringPtr, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr, void>>>> const&)>) /home/jinrui/llvm-project-main/llvm/lib/ExecutionEngine/Orc/Core.cpp:2184:3
#45 0x00007fb5dfd43633 llvm::orc::ExecutionSession::lookup(std::vector<std::pair<llvm::orc::JITDylib*, llvm::orc::JITDylibLookupFlags>, std::allocator<std::pair<llvm::orc::JITDylib*, llvm::orc::JITDylibLookupFlags>>> const&, llvm::orc::SymbolStringPtr, llvm::orc::SymbolState) /home/jinrui/llvm-project-main/llvm/lib/ExecutionEngine/Orc/Core.cpp:2209:24
#46 0x00007fb5dfe80480 llvm::orc::LLJIT::lookupLinkerMangled(llvm::orc::JITDylib&, llvm::orc::SymbolStringPtr) /home/jinrui/llvm-project-main/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp:881:18
#47 0x000055bdc6ff8a29 llvm::orc::LLJIT::lookupLinkerMangled(llvm::orc::JITDylib&, llvm::StringRef) /home/jinrui/llvm-project-main/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h:164:5
#48 0x000055bdc6ff8997 llvm::orc::LLJIT::lookup(llvm::orc::JITDylib&, llvm::StringRef) /home/jinrui/llvm-project-main/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h:176:5
#49 0x000055bdc6ff1754 llvm::orc::LLJIT::lookup(llvm::StringRef) /home/jinrui/llvm-project-main/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h:181:12
#50 0x000055bdc6ff090d main /home/jinrui/llvm-project-main/sjr-test/SBTtest/TestReadIRcode.cpp:40:23
#51 0x00007fb5d7b27d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#52 0x00007fb5d7b27e40 call_init ./csu/../csu/libc-start.c:128:20
#53 0x00007fb5d7b27e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#54 0x000055bdc6ff04c5 _start (./TestReadIRcode+0x64c5)
If I compile it statically using clang, it compiles successfully. However, the same problem arises when I add the > JIT session error: In /home/jinrui/coremark_pro_x86tox86/mazeTest/maze.ll-jitted-objectbuffer, symbol data_403ff8 (0x3ff8 -- 0x8099) extends 0x3ff8 bytes past the end of its containing block (0x0 -- 0x40a1) So I am curious as to why this problem occurs. I found a similar issue in another issue from 2019, but it has not been resolved yet. |
I believe we just haven't encountered them before. I think it would be reasonable to treat them similarly to how they're treated in ahead-of-time code.
That looks like a bug in ahead of time compilation. If clang is working for you now then I suspect it has been fixed by not yet resolved. I'll close it. |
When I set the emulateTLS option of ORC JIT to false, it still can't handle TLS aliases.
However, Ahead of Time (clang) compiler with emulateTLS model also results in errors, which might indicate that the emulateTLS model does not properly consider the handling of TLS aliases. |
I think there are still some problems with the EmulatedTLS model in ahead of time compilation and JIT compilation. This is because it only generates the __emutls_v.xx symbol when the -femulated-tls option is used, which is necessary to obtain the address of a global TLS variable.
LLVM do not generate __emutls_v.xx symbol for TLS variable alias, because that code just perform a cast on the GlobalVariable, this cast will directly fail for variables of GlobalAlias type. Does this mean that in this model, GlobalAlias is not processed or it has not supported for GlobalAlias ? |
The option of |
When I use ORC JIT to compile a .bc file that contains a TLS (Thread Local Storage) variable alias, the following error occurs.
From the code of ORC JIT,
auto &GV = cast<GlobalVariable>(G);
means that onlyGlobalVariable
can be be treated as __emutls_v.xx symbol, a GlobalAlias cannot be cast to a GlobalVariable. But in LowerToTLSEmulatedModel() function, the TLS variable alias will be treated the same as a GlobalVariable. It will look up __emutls_v.xx symbol for alias, due to the absence of the addition of __emutls_v to the alias earlier, it fails to be located, resulting in an error.So I have some doubts: Does ORC JIT by default not involve aliases in TLS-related processing (due to theoretical reasons, aliases do not need processing), or is it that ORC JIT does not yet support TLS variable aliases?
log info:
If I compile it statically using clang, it compiles successfully. However, the same problem arises when I add the
-femulated-tls
option. If I turn off theEmulatedTLS option by using JTMB->getOptions().EmulatedTLS = false;
with ORC JIT, the following new issue arises.So I am curious as to why this problem occurs. I found a similar issue in another issue from 2019, but it has not been resolved yet.
The text was updated successfully, but these errors were encountered: