[ELF] Parallelize relocation scanning
authorFangrui Song <i@maskray.me>
Mon, 12 Sep 2022 19:56:35 +0000 (12:56 -0700)
committerFangrui Song <i@maskray.me>
Mon, 12 Sep 2022 19:56:35 +0000 (12:56 -0700)
commite6aebff67426fa0f9779a0c19d6188a043bf15e7
treecc7065c489614dbdd54642373a6241c42790ffca
parent7cfff0f2769b8923c5d86a9c137460e8df80d4da
[ELF] Parallelize relocation scanning

* Change `Symbol::flags` to a `std::atomic<uint16_t>`
* Add `llvm::parallel::threadIndex` as a thread-local non-negative integer
* Add `relocsVec` to part.relaDyn and part.relrDyn so that relative relocations can be added without a mutex
* Arbitrarily change -z nocombreloc to move relative relocations to the end. Disable parallelism for deterministic output.

MIPS and PPC64 use global states for relocation scanning. Keep serial scanning.

Speed-up with mimalloc and --threads=8 on an Intel Skylake machine:

* clang (Release): 1.27x as fast
* clang (Debug): 1.06x as fast
* chrome (default): 1.05x as fast
* scylladb (default): 1.04x as fast

Speed-up with glibc malloc and --threads=16 on a ThunderX2 (AArch64):

* clang (Release): 1.31x as fast
* scylladb (default): 1.06x as fast

Reviewed By: andrewng

Differential Revision: https://reviews.llvm.org/D133003
12 files changed:
lld/ELF/Config.h
lld/ELF/Relocations.cpp
lld/ELF/Symbols.h
lld/ELF/SyntheticSections.cpp
lld/ELF/SyntheticSections.h
lld/ELF/Writer.cpp
lld/test/ELF/combreloc.s
lld/test/ELF/comdat-discarded-error.s
lld/test/ELF/undef-multi.s
lld/test/ELF/undef.s
llvm/include/llvm/Support/Parallel.h
llvm/lib/Support/Parallel.cpp