[PATCH] D150510: [ELF] x86-64: place .lrodata, .lbss, and .ldata away from code sections

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat May 13 11:00:43 PDT 2023


MaskRay created this revision.
MaskRay added reviewers: aeubanks, jyknight, peter.smith, smeenai, tkoeppe.
Herald added subscribers: pengfei, arichardson, emaste.
Herald added a project: All.
MaskRay requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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. We have a similar missing optimization (implementing
it would introduce complexity and likely be error-prone).

Our approach is to simply place .ldata and .lbss after .bss. Although .ldata
cannot reuse the file offset bytes of .bss, non-SHF_ALLOC sections can reuse the
file offsets of .lbss. If .lbss is significantly larger than .bss, any impact on
saving .bss will be negligible.

GNU ld's layout introduces 2 more MAXPAGESIZE alignments while ours don't
introduce any.

[1]: https://groups.google.com/g/x86-64-abi/c/jnQdJeabxiU "Large data sections for the large code model"


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150510

Files:
  lld/ELF/LinkerScript.cpp
  lld/ELF/Writer.cpp
  lld/test/ELF/x86-64-section-layout.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150510.521933.patch
Type: text/x-patch
Size: 5097 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230513/bceff579/attachment.bin>


More information about the llvm-commits mailing list