Hello Clang-Experts,
I have a very simple code like this:
extern int far_value;
void Initialize() {
far_value = 12345;
}
Which we will then compile to a static library ahead of time for our platform, not providing an implementation for far_value
. At runtime our system will be aware of the address for far_value
and relocate the symbol with the address. That works fine so far.
However, sometimes we run into the issue, that far_value
is to far away from our code to be referenced by a relative address encoded into the assembly instruction.
mov dword ptr [rip + "?far_value@@3HA"], 12345
With the -mcmodel=large
setting we were able to work around this issue creating code like this:
movabs rax, offset "?far_value@@3HA"
mov dword ptr [rax], 12345
Which is okay for the access to far_value
- but it will effect all other referenced variables and functions as well!
Can we somehow tell Clang to only assume the large
code model for certain symbols or code sections? For MIPS targets I have seen the far
attribute which however is only platform specific. Would it help to first compile to the LLVM IR to modify the code accordingly? Sadly the output in the end has to be a static library so we can currently not uset he OrcJIT.
Any help and guidance is welcome!