Longcalls to runtime linked functions

Is there any way to force the compiler to create "long calls" when branching to runtime linked functions.

My binary needs to be relocatable and to be able to call late linked functions potentially anywhere in memory.

Currently, the compiler is emitting immediate form BL instructions and a relocation type of R_ARM_THM_CALL, which has a limited range. For my scenario, it would be more ideal if the compiler emitted a register form BL instruction and a more flexible R_ARM_ABS32 for the value that is loaded into the register. Or something similar to that. What I need is something that allows branching over very large distances.

By way of comparison, GCC has the long_call function attribute, or the -mlong-calls option. However, there doesn't seem to be any equivalent option or attribute for Rust.

Is there any way of achieving this with current Rust? Or Or does anyone have any other suggestions.

1 Like

In what context? Embedded? Linux? A custom linking format? On Linux the linker is already supposed to generate the right PLT entries necessary to handle dynamic libraries if the compiler generates PLT relative rather than GOT relative calls for non-local function calls.

Embedded. The binary if a relocatable ELF but no PIE or PIC.

The target is ARMv6m

I know it probably gives a warning, but does

-Ctarget-feature=+long-calls

work?

1 Like

Yes! It does. At least the assembly looks correct.
Thanks

Did it give a warning?

It did.

warning: unknown and unstable feature specified for -Ctarget-feature: long-calls
|
= note: it is still passed through to the codegen backend, but use of this feature might be unsound and the behavior of this feature can change in the future
= help: consider filing a feature request

To silence the warning you can either use a custom target.json, or submit a PR to rustc to add the target feature.

I think this feature is very useful and something that should be blessed and for the warning to be removed. I'm very new to the Rust world so I'm unsure how to submit a PR. Can you guide me to the correct place?

Thanks again

You can use this PR of mine as a template:

That PR didn't get merged, but that's for reasons that don't apply in your case.

2 Likes