-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
[RISC-V][ORCJIT] PostgreSql JIT fails with "error during JITing: In graph pg-jitted-objectbuffer, section .text: relocation target "CurrentMemoryContext" at address 0x555555e84b00 is out of range of R_RISCV_PCREL_HI20 fixup at 0x7f221c4bb1e4 (evalexpr_0_0, 0x7f221c4bb000 + 0x1e4)" #106203
Comments
@llvm/issue-subscribers-backend-risc-v Author: Andreas Schwab (andreas-schwab)
When postgresql is configured with --with-llvm the regression testsuite causes a lot of crashed that all look like this:
#0 std::_Deque_iterator<llvm::SectionEntry, llvm::SectionEntry&, llvm::SectionEntry*>::_M_set_node (__new_node=0x19db8a08, this=<optimized out>) IIUC RuntimeDyld is part of MC JIT and should not be used by ORC JIT. |
@llvm/issue-subscribers-orcjit Author: Andreas Schwab (andreas-schwab)
When postgresql is configured with --with-llvm the regression testsuite causes a lot of crashed that all look like this:
#0 std::_Deque_iterator<llvm::SectionEntry, llvm::SectionEntry&, llvm::SectionEntry*>::_M_set_node (__new_node=0x19db8a08, this=<optimized out>) IIUC RuntimeDyld is part of MC JIT and should not be used by ORC JIT. |
#0 llvm::RuntimeDyldImpl::applyExternalSymbolRelocations (this=0x243a91b0, |
ORC can use RuntimeDyld or JITLink as the underlying JIT linker. RuntimeDyld does not support RISC-V, at least not in llvm.org/main -- Is your JIT'd code actually targeting RISC-V? |
2024-08-28 18:08:52.635 CEST client backend[48551] pg_regress/boolean DEBUG: LLVMJIT detected CPU "sifive-u74", with features "" |
How does it decide? |
What is the JITLink equivalent of LLVMOrcCreateRTDyldObjectLinkingLayerWithSectionMemoryManager? |
I had this issue on Gentoo and have a old patch that I haven't got time to update. It is probably needed to be rebased/modified. PS: pls ignore the comments I made on that thread about riscv ABIs. It is probably no longer valid or wrong. https://www.postgresql.org/message-id/flat/20220829074622.2474104-1-alex.fan.q%40gmail.com |
If you're constructing your JIT manually then it just depends on whether you use an In LLVM 20 we'll be aiming to switch the default to JITLink, with fallbacks to RuntimeDyld for architectures where JITLink is unavailable / under-development.
There isn't one yet, but we could easily add an |
WARNING: error during JITing: In graph pg-jitted-objectbuffer, section .text: relocation target "CurrentMemoryContext" at address 0x802398 is out of range of R_RISCV_PCREL_HI20 fixup at 0x3f8c165162 (evalexpr_0_0, 0x3f8c165000 + 0x162) WARNING: error during JITing: In graph pg-jitted-objectbuffer, section .text: relocation target "CurrentMemoryContext" at address 0x802398 is out of range of R_RISCV_PCREL_HI20 fixup at 0x3f8c166182 (evalexpr_0_0, 0x3f8c166000 + 0x182) |
How is |
The source is using the default model. The problem is that RISC-V's default isn't large, which is perfectly fine for normal compiled code but generally too restrictive for a JIT. We'll want to do something similar to what getEffectiveAArch64CodeModel does (the AArch64 and RISC-V code models are similar in their restrictions) when it sees a JIT is in use and pick a different code model, likely by changing RISCVTargetMachine to pass |
How are small/static references to external symbols handled by AOT compilation? Presumably these could be at any place in the address range too? Or is the default Small / PIC? In which case we should have the JIT default to that too. In general we assume that the JIT is subject to the same constraints as regular compilation: code within a JITDylib must be within the range specified by the code model, and in general external references may be located anywhere in memory. |
Helped by a combination of copy relocations and PLTs. You can do PLTs for a JIT, but you can't do copy relocations for existing symbols. |
Where are copy relocations documented? The RISCV ABI doc that I found wasn't much help. I'm assuming
just produces |
@andreas-schwab Sounds like it might be worth specifying PIC relocations. (thought eventually I hope the JIT will support the default code / relocation model for RISCV, since that makes it easy for users to import precompiled libraries). |
That's what the patch does? +#ifdef __riscv
+#endif |
@alexfanqi's patch? Looks like iit -- but I think the default code model (probably small?) should be fine, as long as the reloc model is PIC. |
Finally got around to looking for this again: https://docs.oracle.com/cd/E19120-01/open.solaris/819-0690/chapter4-84604/index.html
I think the full answer to this is: JIT'd code is always shared library code (conceptually), since it's necessarily loaded after the main executable, and is distinct from it. I'll make PIC the default relocation model for ELF in LLJIT. At a stretch we could support copy relocations in JIT'd code under two conditions:
Interesting cases to consider, but I don't think they're a priority right now. |
WARNING: error during JITing: In graph pg-jitted-objectbuffer, section .text: relocation target "CurrentMemoryContext" at address 0x555555e84b00 is out of range of R_RISCV_PCREL_HI20 fixup at 0x7f221c4bb1e4 (evalexpr_0_0, 0x7f221c4bb000 + 0x1e4) |
What code / relocation model did this occur under? |
+#ifdef __riscv
|
With LLVMCodeModelLarge nothing changes, still the same JIT error. |
With what version? RISC-V only gained large code model support recently in main, with older versions falling back I assume to medium aka medany. |
I'm testing with LLVM 18. |
When postgresql is configured with --with-llvm the regression testsuite causes a lot of crashed that all look like this:
#0 std::_Deque_iterator<llvm::SectionEntry, llvm::SectionEntry&, llvm::SectionEntry*>::_M_set_node (__new_node=0x19db8a08, this=)
at /usr/lib64/gcc/riscv64-suse-linux/13/../../../../include/c++/13/bits/stl_deque.h:266
#1 std::_Deque_iterator<llvm::SectionEntry, llvm::SectionEntry&, llvm::SectionEntry*>::operator+= (__n=, this=)
at /usr/lib64/gcc/riscv64-suse-linux/13/../../../../include/c++/13/bits/stl_deque.h:241
#2 std::operator+ (__x=..., __n=)
at /usr/lib64/gcc/riscv64-suse-linux/13/../../../../include/c++/13/bits/stl_deque.h:400
#3 std::_Deque_iterator<llvm::SectionEntry, llvm::SectionEntry&, llvm::SectionEntry*>::operator[] (this=, __n=)
at /usr/lib64/gcc/riscv64-suse-linux/13/../../../../include/c++/13/bits/stl_deque.h:255
#4 std::deque<llvm::SectionEntry, std::allocatorllvm::SectionEntry >::operator[] (this=, __n=)
at /usr/lib64/gcc/riscv64-suse-linux/13/../../../../include/c++/13/bits/stl_deque.h:1386
#5 llvm::RuntimeDyldELF::computePlaceholderAddress (this=,
SectionID=, Offset=848)
at /usr/src/debug/llvm-18.1.8.src/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp:1086
#6 0x0000003f83fc33ca in llvm::RuntimeDyldImpl::resolveRelocationList (
this=0xb117b80, Relocs=..., Value=0)
at /usr/src/debug/llvm-18.1.8.src/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp:1106
#7 llvm::RuntimeDyldImpl::applyExternalSymbolRelocations (this=0xb117b80,
ExternalSymbolMap=<error reading variable: Cannot access memory at address 0x18>)
at /usr/src/debug/llvm-18.1.8.src/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp:1119
#8 0x000000000a287310 in ?? ()
IIUC RuntimeDyld is part of MC JIT and should not be used by ORC JIT.
The text was updated successfully, but these errors were encountered: