JIT: link ccalls directly (removes DLSymOptimizer*) #61363
I assume this is aarch64 only because one would need to write the assembly for the other platforms?
I am okay with vendoring code from LLVM, but I would like to have a clear strategy on up streaming these changes. That helps us update to new LLVM versions and avoids us missing biu fixes.
Enzyme currently relies in being able to decode the ccall emissions we perform, to assign semantic meaning to those calls. Similarly AllocCheck and other GPUCompiler based tooling rely on being able to roundtrip LLVM modules without having a side table somewhere else.
So we would need a way to access that side table or serialize it into the LLVM module.
I assume this is aarch64 only because one would need to write the assembly for the other platforms?
Yep. In reality, I'm not so interested in lazy ORC materialization for this specific use, and wanted to get a version working so I can experiment with speculatively compiling on idle threads.
I am okay with vendoring code from LLVM, but I would like to have a clear strategy on up streaming these changes. That helps us update to new LLVM versions and avoids us missing biu fixes.
I've started upstreaming some LLVM changes (places where we need to be using asynchronous ORC lookups), but the modified LazyReexportsManager that can fail materialization is not something I expect they'd want. I'm also not sure I want it, now that I have the prototype in front of me. Expect another draft PR with a nicer approach sometime soon.
Enzyme currently relies in being able to decode the ccall emissions we perform, to assign semantic meaning to those calls. Similarly AllocCheck and other GPUCompiler based tooling rely on being able to roundtrip LLVM modules without having a side table somewhere else.
> So we would need a way to access that side table or serialize it into the LLVM module.
Agreed. I like the side tables in jl_linker_info_t more than the previous approach for tracking invoke names with global tables in jitlayers.cpp, but it's not ideal for stuff that doesn't depend on the running session. For a future version I'll try repurposing the julia.fname/julia.libname/julia.libidx attributes we already put on the julia GOT variables.
Why is this part of DLSymOptimizer kept? The lookup is just as problematic, isn't it?
It is, but this branch doesn't provide an alternative to DLSymOptimizer for cglobal.
topolarity
xal-0
In the interest of making the generated LLVM IR process-independent, we should find an alternative to DLSymOptimizer. For reference, right now we emit LLVM IR that calls through the Julia PLT, like this:
DLSymOptimizer initializes GOT with a constant:
Where
7008263280is the address offoothat was resolved in the current process. This causes the IR hash to depend on the address space layout, making it impossible to cache LLVM compilation across sessions.This PR implements one approach to making the IR predictable, on suppported platforms (currently, only aarch64). In the JIT, we emit direct ccalls, without loading from a Julia GOT, and track them in a table on
jl_codegen_output_t. When linking, we resolve these ccall symbols to their targets directly if possible, falling back to lazy symbol that will try resolving the symbol again when it's first called.We use vendored versions of LazyReexportsManager and RedirectableSymbolManager that support our cooperative task scheduler. The LazyReexportsManager is also modified so we can throw a Julia exception instead of materializing the destination symbol, which is required to preserve our ccall semantics (preserving the illusion that the dlsym happens at runtime).
On this branch, the
fooexample looks like this: