[all-commits] [llvm/llvm-project] 668309: [ELF] Optimize RelocationSection<ELFT>::writeTo

Fangrui Song via All-commits all-commits at lists.llvm.org
Tue Dec 21 09:43:56 PST 2021

  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 6683099a0d0a17fcde3576733e9c85e3b5f71de5
  Author: Fangrui Song <i at maskray.me>
  Date:   2021-12-21 (Tue, 21 Dec 2021)

  Changed paths:
    M lld/ELF/OutputSections.cpp
    M lld/ELF/SyntheticSections.cpp
    M lld/ELF/SyntheticSections.h

  Log Message:
  [ELF] Optimize RelocationSection<ELFT>::writeTo

When linking a 1.2G output (nearly no debug info, 2846621 dynamic relocations) using `--threads=8`, I measured

9.131462 Total ExecuteLinker
1.449913 Total Write output file
1.445784 Total Write sections
0.657152 Write sections {"detail":".rela.dyn"}

This change decreases the .rela.dyn time to 0.25, leading to 4% speed up in the total time.

* The parallelSort is slow because of expensive r_sym/r_offset computation. Cache the values.
* The iteration is slow. Move r_sym/r_addend computation ahead of time and parallelize it.

With the change, the new encodeDynamicReloc is cheap (0.05s). So no need to parallelize it.

Reviewed By: ikudrin

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

More information about the All-commits mailing list