[llvm-branch-commits] [ELF] Place .lbss/.lrodata/.ldata after .bss (PR #81224)

Fangrui Song via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Feb 8 20:13:45 PST 2024


https://github.com/MaskRay created https://github.com/llvm/llvm-project/pull/81224

https://reviews.llvm.org/D150510 places .lrodata before .rodata to
minimize the number of permission transitions in the memory image.
However, this layout is not ideal for -fno-pic code (which is still
important).

Small code model -fno-pic code has R_X86_64_32S relocations with a range
of [0,2**31) (if we ignore the negative area). Placing `.lrodata`
earlier exerts relocation pressure on such code. Non-x86 64-bit
architectures generally have a similar [0,2**31) limitation if they
don't use PC-relative relocations.

If we place .lrodata later, two layouts are appealing:

* .bss/.lbss/.lrodata/.ldata (GNU ld)
* .bss/.ldata/.lbss/.lrodata

The GNU ld style has the nice property that there is only one BSS
(except .tbss/.relro_padding). Let's match GNU ld. While here, also
place `_edata` at a location similar to GNU ld.





More information about the llvm-branch-commits mailing list