[ELF] x86-64: place .lrodata, .lbss, and .ldata away from code sections
The x86-64 medium code model utilizes large data sections, namely .lrodata, .lbss, and .ldata (along with some variants of .ldata). There is a proposal to extend the use of large data sections to the large code model as well[1]. This patch aims to place large data sections away from code sections in order to alleviate relocation overflow pressure caused by code sections referencing regular data sections. ``` .lrodata .rodata .text # if --ro-segment, MAXPAGESIZE alignment RELRO # MAXPAGESIZE alignment .data # MAXPAGESIZE alignment .bss .ldata # MAXPAGESIZE alignment .lbss ``` In comparison to GNU ld, which places .lbss, .lrodata, and .ldata after .bss, we place .lrodata above .rodata to minimize the number of permission transitions in the memory image. While GNU ld places .lbss after .bss, the subsequent sections don't reuse the file offset bytes of BSS. Our approach is to place .ldata and .lbss after .bss and create a PT_LOAD segment for .bss to large data section transition in the absence of SECTIONS commands. assignFileOffsets ensures we insert an alignment instead of allocating space for BSS, and therefore we don't waste more than MAXPAGESIZE bytes. We have a missing optimization to prevent all waste, but implementing it would introduce complexity and likely be error-prone. GNU ld's layout introduces 2 more MAXPAGESIZE alignments while ours introduces just one. [1]: https://groups.google.com/g/x86-64-abi/c/jnQdJeabxiU "Large data sections for the large code model" With help from Arthur Eubanks. Co-authored-by:James Y Knight <jyknight@google.com> Reviewed By: aeubanks, tkoeppe Differential Revision: https://reviews.llvm.org/D150510
Loading
Please sign in to comment