Stream: cranelift

Topic: ✔ how does JIT know where to find external symbols?


view this post on Zulip McCoy (Jun 19 2022 at 21:27):

Question as title says. I was reading about the JIT here: https://docs.rs/cranelift-jit/latest/cranelift_jit/struct.JITBuilder.html#method.symbol in preparation of trying to use some extern calls. It appears that there is some fallback path for symbol search (when symbol resolution does not resolve in the internal table).

How can I expose a runtime which I write to the JIT?

view this post on Zulip McCoy (Jun 19 2022 at 21:28):

Perhaps I need to add a https://docs.rs/cranelift-jit/latest/cranelift_jit/struct.JITBuilder.html#method.symbol_lookup_fn symbol_lookup_fn (?) Is there a simple example of extern function usage with the JIT I could look at somewhere?

view this post on Zulip McCoy (Jun 19 2022 at 21:40):

Edit: Found an answer in the simple jit.

view this post on Zulip Notification Bot (Jun 19 2022 at 21:40):

McCoy has marked this topic as resolved.

view this post on Zulip Adrian Sampson (Jun 19 2022 at 21:41):

Not sure if this is helpful beyond the example, but here's how I declared external symbols for a JIT I wrote recently: https://github.com/sampsyo/bril/blob/58b9794db5eefd4afbd4daf4566177cd03a84b1c/brilift/src/main.rs#L307
Namely, just calling builder.symbol is sufficient to make it possible to then use module.declare_function with import linkage:
https://github.com/sampsyo/bril/blob/58b9794db5eefd4afbd4daf4566177cd03a84b1c/brilift/src/main.rs#L202-L207

an educational compiler intermediate representation - bril/main.rs at 58b9794db5eefd4afbd4daf4566177cd03a84b1c · sampsyo/bril
an educational compiler intermediate representation - bril/main.rs at 58b9794db5eefd4afbd4daf4566177cd03a84b1c · sampsyo/bril

view this post on Zulip McCoy (Jun 19 2022 at 21:54):

@Adrian Sampson thanks for the tip! Love your compile course material btw.


Last updated: Oct 23 2024 at 20:03 UTC