Stream: t-compiler/help

Topic: llvm static calling

simulacrum (Jan 30 2020 at 15:25, on Zulip):

If anyone here has thoughts on how to fix the problem described here: I'd love to hear them

simulacrum (Jan 30 2020 at 15:26, on Zulip):

the static is static FOO: unsafe extern "C" fn(*mut u8) -> ! = ... fwiw

Amanieu (Jan 30 2020 at 15:27, on Zulip):

Try inserting a load here:

simulacrum (Jan 30 2020 at 15:28, on Zulip):

@Amanieu so bx.load_operand(bx.eh_unwind_resume()).immediate()?

simulacrum (Jan 30 2020 at 15:29, on Zulip):

maybe the problem is really with eh_unwind_resume itself, and the fallback case of the "declare_fn" being wrong now (since there's no such fn)

Amanieu (Jan 30 2020 at 15:32, on Zulip):

Well you're definitely missing a load instruction. You can't call a static, you need to get the function pointer out of it first.

simulacrum (Jan 30 2020 at 15:33, on Zulip):

hm, what does get_static do then?

Amanieu (Jan 30 2020 at 15:33, on Zulip):

I'm not too familiar with the codegen API, so I can't really tell you what the correct method to use on bx is.

simulacrum (Jan 30 2020 at 15:33, on Zulip):

i.e. what is it returning?

Amanieu (Jan 30 2020 at 15:33, on Zulip):

A pointer to the static?

simulacrum (Jan 30 2020 at 15:33, on Zulip):

oh, so I thought it was a load

simulacrum (Jan 30 2020 at 15:33, on Zulip):

but I guess a pointer makes more sense

Amanieu (Jan 30 2020 at 15:47, on Zulip):

It still looks wrong. The second half of eh_unwind_resume in declares rust_eh_unwind_resume as a function pointer if it can't find the lang item (which is the case when compiling libcore). You need to change that half to declare rust_eh_unwind_resume as a static and return a pointer to it.

Amanieu (Jan 30 2020 at 15:48, on Zulip):

That way you can just have an unconditional load in codegen_resume_terminator.

simulacrum (Jan 30 2020 at 20:17, on Zulip):

I think the code right now is correct, just "wrong" in the sense that it's not as nice as it could be, right? I'm thinking that unconditionally returning a function pointer from eh_unwind_resume is the right thing to do, and then we don't need a static, right?

simulacrum (Jan 30 2020 at 20:18, on Zulip):

(in the second case)

Amanieu (Jan 30 2020 at 20:41, on Zulip):

That won't work since the value is cached. You need to emit a load instruction at every use point.

simulacrum (Jan 30 2020 at 20:42, on Zulip):

hm, right, that makes sense -- we can't stick a load instruction into nowhere, I guess?

simulacrum (Jan 30 2020 at 20:42, on Zulip):

bit sad to have to load from memory every time, but I guess maybe the optimizer can optimize away the load too

Amanieu (Jan 30 2020 at 20:43, on Zulip):

It should be able to optimize it away with LTO since the static is a constant.

eddyb (Mar 24 2020 at 18:46, on Zulip):

is this done with weak linkage or something?

Last update: Jul 02 2020 at 19:45UTC