[all-commits] [llvm/llvm-project] 8aea10: [ELF] x86-64: place .lrodata, .lbss, and .ldata aw...

Fangrui Song via All-commits all-commits at lists.llvm.org
Thu May 25 07:35:51 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 8aea10950463f915781cca6affde963e4565db2f
      https://github.com/llvm/llvm-project/commit/8aea10950463f915781cca6affde963e4565db2f
  Author: Fangrui Song <i at maskray.me>
  Date:   2023-05-25 (Thu, 25 May 2023)

  Changed paths:
    M lld/ELF/LinkerScript.cpp
    M lld/ELF/Writer.cpp
    A lld/test/ELF/x86-64-section-layout.s

  Log Message:
  -----------
  [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 at google.com>

Reviewed By: aeubanks, tkoeppe

Differential Revision: https://reviews.llvm.org/D150510




More information about the All-commits mailing list