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

LLVM do not generate __emutls_v.xx symbol for TLS variable alias #79732

Open
Thrrreeee opened this issue Jan 28, 2024 · 5 comments
Open

LLVM do not generate __emutls_v.xx symbol for TLS variable alias #79732

Thrrreeee opened this issue Jan 28, 2024 · 5 comments
Labels

Comments

@Thrrreeee
Copy link

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 only GlobalVariable 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:

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::withModuleDollvm::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_deletellvm::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_deletellvm::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_deletellvm::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_deletellvm::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_deletellvm::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_deletellvm::orc::Task>>::CallImpl<void ()(std::unique_ptr<llvm::orc::Task, std::default_deletellvm::orc::Task>)>(void, std::unique_ptr<llvm::orc::Task, std::default_deletellvm::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_deletellvm::orc::Task>)>::operator()(std::unique_ptr<llvm::orc::Task, std::default_deletellvm::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_deletellvm::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_deletellvm::orc::InProgressLookupState>, std::shared_ptrllvm::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_deletellvm::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_deletellvm::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 -femulated-tls option. If I turn off the EmulatedTLS option by using JTMB->getOptions().EmulatedTLS = false; with ORC JIT, the following new issue arises.

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)
Failed to materialize symbols: { (main, { main, __remill_missing_block, __mcsema_debug_get_reg_state, __mcsema_reg_state, gmon_start, draw, __mcsema_init_reg_state, __remill_error, __mcsema_detach_call_value }) }

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.

@llvmbot
Copy link
Collaborator

llvmbot commented Jan 28, 2024

@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 -femulated-tls option. If I turn off the EmulatedTLS option by using JTMB-&gt;getOptions().EmulatedTLS = false; with ORC JIT, the following new issue arises.

> 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)
Failed to materialize symbols: { (main, { main, __remill_missing_block, __mcsema_debug_get_reg_state, __mcsema_reg_state, gmon_start, draw, __mcsema_init_reg_state, __remill_error, __mcsema_detach_call_value }) }

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.

@lhames
Copy link
Contributor

lhames commented Jan 28, 2024

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?

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.

I found a similar issue in #43046 from 2019, but it has not been resolved yet.

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.

@Thrrreeee
Copy link
Author

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.

When I set the emulateTLS option of ORC JIT to false, it still can't handle TLS aliases.

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.

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.

@Thrrreeee
Copy link
Author

Thrrreeee commented Jan 29, 2024

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.

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.
From #43046 issue , we can see the program arguments which alse has the -femulated-tls option:

Program arguments: /usr/lib/llvm-7/bin/clang -cc1 -triple x86_64-pc-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name test.c -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -coverage-notes-file /home/xxx/path/test.gcno -resource-dir /usr/lib/llvm-7/lib/clang/7.0.1 -D INCLUDE_SOURCE -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-7/lib/clang/7.0.1/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir /home/xxx/path -ferror-limit 19 -fmessage-length 321 -femulated-tls -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -o test.o -x c test.c -faddrsig

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 ?

@Thrrreeee
Copy link
Author

Thrrreeee commented Mar 28, 2024

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.
@lhames
Hello hames,
I find that it has't been solved when I use this command to compile my file clang++ -g maze.bc -femulated-tls -o maze. It will report the same error as fllows:

$ clang++ -g maze.bc -femulated-tls -o maze
warning: overriding the module target triple with x86_64-unknown-linux-gnu [-Woverride-module]
clang-18: /home/sole/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.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
#0 0x000071aef24aab61 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/sole/llvm-project-main/llvm/lib/Support/Unix/Signals.inc:723:11
#1 0x000071aef24ab05b PrintStackTraceSignalHandler(void
) /home/sole/llvm-project-main/llvm/lib/Support/Unix/Signals.inc:798:1
#2 0x000071aef24a9056 llvm::sys::RunSignalHandlers() /home/sole/llvm-project-main/llvm/lib/Support/Signals.cpp:105:5
#3 0x000071aef24ab7f5 SignalHandler(int) /home/sole/llvm-project-main/llvm/lib/Support/Unix/Signals.inc:413:1
#4 0x000071aef1a42990 (/lib/x86_64-linux-gnu/libc.so.6+0x42990)
#5 0x000071aef1a99a1b pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x99a1b)
#6 0x000071aef1a428e6 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x428e6)
#7 0x000071aef1a268b7 abort (/lib/x86_64-linux-gnu/libc.so.6+0x268b7)
#8 0x000071aef1a267db (/lib/x86_64-linux-gnu/libc.so.6+0x267db)
#9 0x000071aef1a39206 (/lib/x86_64-linux-gnu/libc.so.6+0x39206)
#10 0x000071aef0f3d6c8 llvm::TargetLowering::LowerToTLSEmulatedModel(llvm::GlobalAddressSDNode const*, llvm::SelectionDAG&) const /home/sole/llvm-project-main/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp:9751:16
#11 0x000071aefc0cbd5d llvm::X86TargetLowering::LowerGlobalTLSAddress(llvm::SDValue, llvm::SelectionDAG&) const /home/sole/llvm-project-main/llvm/lib/Target/X86/X86ISelLowering.cpp:18561:12
#12 0x000071aefc1125fd llvm::X86TargetLowering::LowerOperation(llvm::SDValue, llvm::SelectionDAG&) const /home/sole/llvm-project-main/llvm/lib/Target/X86/X86ISelLowering.cpp:31787:40
#13 0x000071aef0c19a48 (anonymous namespace)::SelectionDAGLegalize::LegalizeOp(llvm::SDNode*) /home/sole/llvm-project-main/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1308:29
#14 0x000071aef0c180e4 llvm::SelectionDAG::Legalize() /home/sole/llvm-project-main/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:5587:13
#15 0x000071aef0e9a4ba llvm::SelectionDAGISel::CodeGenAndEmitDAG() /home/sole/llvm-project-main/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:908:3

The option of -femulated-tls is to use EmulateTLSmodel to deal with TLS varaiable. For this option, "clang" defaults to false unless "-femulated-tls" is selected, whereas ORC JIT defaults to true.

@Thrrreeee Thrrreeee reopened this Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants