[all-commits] [llvm/llvm-project] 6ab034: [ELF] Add BPSectionOrderer options (#125559)

Fangrui Song via All-commits all-commits at lists.llvm.org
Tue Feb 4 09:12:55 PST 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 6ab034b828d3a66acca61e28ac41f2e8b300e355
      https://github.com/llvm/llvm-project/commit/6ab034b828d3a66acca61e28ac41f2e8b300e355
  Author: Fangrui Song <i at maskray.me>
  Date:   2025-02-04 (Tue, 04 Feb 2025)

  Changed paths:
    A lld/ELF/BPSectionOrderer.cpp
    A lld/ELF/BPSectionOrderer.h
    M lld/ELF/CMakeLists.txt
    M lld/ELF/Config.h
    M lld/ELF/Driver.cpp
    M lld/ELF/Options.td
    M lld/ELF/Writer.cpp
    M lld/include/lld/Common/BPSectionOrdererBase.inc
    A lld/test/ELF/bp-section-orderer-stress.s
    A lld/test/ELF/bp-section-orderer.s

  Log Message:
  -----------
  [ELF] Add BPSectionOrderer options (#125559)

Reland #120514 after 2f6e3df08a8b7cd29273980e47310cf09c6fdbd8 fixed
iteration order issue and libstdc++/libc++ differences.

---

Both options instruct the linker to optimize section layout with the
following goals:

* `--bp-compression-sort=[data|function|both]`: Improve Lempel-Ziv
compression by grouping similar sections together, resulting in a
smaller compressed app size.
* `--bp-startup-sort=function --irpgo-profile=<file>`: Utilize a
temporal profile file to reduce page faults during program startup.

The linker determines the section order by considering three groups:

* Function sections ordered according to the temporal profile
(`--irpgo-profile=`), prioritizing early-accessed and frequently
accessed functions.
* Function sections. Sections containing similar functions are placed
together, maximizing compression opportunities.
* Data sections. Similar data sections are placed together.

Within each group, the sections are ordered using the Balanced
Partitioning algorithm.

The linker constructs a bipartite graph with two sets of vertices:
sections and utility vertices.

* For profile-guided function sections:
  + The number of utility vertices is determined by the symbol order
within the profile file.
  + If `--bp-compression-sort-startup-functions` is specified, extra
utility vertices are allocated to prioritize nearby function similarity.
* For sections ordered for compression: Utility vertices are determined
by analyzing k-mers of the section content and relocations.

The call graph profile is disabled during this optimization.

When `--symbol-ordering-file=` is specified, sections described in that
file are placed earlier.

Co-authored-by: Pengying Xu <xpy66swsry at gmail.com>



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list