How to put Large const data to .lrodata on Linux x86_64 (mcmodel)

Linux x86_64 Elf file has a size limitation for Initialized data segment .rodata section - 2GB.
If your Total const data is larger than 2GB then Large data can be put to .lrodata section.
How to ask clang to put Large data to .lrodata?

In gcc we can simply say -mcmodel=medium during object file creation.

But I think clang ignores this parameter on Linux x86_64 platform.
Also clang does not have -mlarge-data-threshold=threshold parameter (defaults to 65535 in gcc)

For now I have to explicitly specify .lrodata section in C code using __attribute__

extern const long long int B1[131072];
const long long int B1[131072] = {...}

Iā€™m sure clang has a better/simpler way to support large arrays placement to .lrodata on Linux x86_64 platform.

Related Error:
if object file .rodata section is large than 2GB then linking to .so will fail with error relocation truncated to fit: R_X86_64_PC32

āš™ D149288 [X86] Introduce a large data threshold for the medium code model will implement this.

I have proposed that GCC allows -mcmodel=large with -mlarge-data-threshold= as well and started an x86-64 ABI discussion:

Relocation overflow and code models | MaskRay contains my current understanding of relocation overflow issues. Feel free to make suggestions:)

1 Like