[llvm] [llvm][IR] Add per-global code model attribute (PR #72077)

via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 14 19:44:05 PST 2023


heiher wrote:

> This should definitely have an RFC sent to discourse

https://discourse.llvm.org/t/rfc-add-per-global-code-model-attribute/74944

> 
> The annoying thing is that the x86-64 medium/large code model doesn't necessarily mean that all globals compiled like that are near/far, they mean that globals over a certain size are considered far (the linker places them farther from text to mitigate 32-bit relocation pressure). The way I want to use this feature is to unconditionally mark a global as far regardless of its size, so specifying a specific code model is not quite right for my use case. But maybe for x86-64 we can just say that an explicit "small" code model means the global is unconditionally near and an explicit "large" code model means the global is unconditionally far, even if that's not exactly what the x86-64 code models mean.

Yeah. From the [GCC document](https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html), the code model of x86-64 has two intentions, one is to change the ability to access the address space of the program. The other is to change the position according to the size of the symbol object, which may not be all architecture. The ability to access the address space is the need for this.

> 
> Do you need this for functions as well as global variables? For x86-64 theoretically this is useful for both, but in practice we'll probably only use this for global variables.

Just only global variable for LoongArch. When kernel module dynamic linking, PLT will be created for function calls.

https://github.com/llvm/llvm-project/pull/72077


More information about the llvm-commits mailing list