While working on an existing project I've run into a really weird issue. The project already had a JIT mode that uses cranelift_jit, and is capable of importing libc functions by declaring them by name with the import linkage, and that seems to be all. At no point does the compiler explicitly link in any libc functions or libc itself. But while writing a lazy jit backend, which needs hotswap and thus enables PIC (it's normally disabled by the non-lazy JIT) suddenly these functions crash when called, but the crash can be avoided by adding them to the symbol table (or presumably adding a lookup function that can find them).
Why does the non-PIC backend not need to import libc functions, and what would be the easiest way to fix this/import the libc functions?
I'm aware that there's a default fallback function that searches both the program's symbol table and the system's default C runtime, which I assume is how it's working in greedy jit mode. But I'm confused as to why enabling PIC seems to prevent this lookup from working.
Nevermind- I think the issue was elsewhere. It appeared to be crashing when calling extern functions but it was actually unrelated, but happened to occur right around them
Last updated: Nov 22 2024 at 16:03 UTC