[all-commits] [llvm/llvm-project] 4b8875: [ELF] Add target-specific relocation scanning for ...

Fangrui Song via All-commits all-commits at lists.llvm.org
Thu Feb 12 22:10:36 PST 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 4b887533389c78e3e678b3af85d1dc8e3bf59e83
      https://github.com/llvm/llvm-project/commit/4b887533389c78e3e678b3af85d1dc8e3bf59e83
  Author: Fangrui Song <i at maskray.me>
  Date:   2026-02-12 (Thu, 12 Feb 2026)

  Changed paths:
    M lld/ELF/Arch/X86.cpp
    M lld/ELF/Arch/X86_64.cpp
    M lld/ELF/RelocScan.h
    M lld/ELF/Relocations.cpp

  Log Message:
  -----------
  [ELF] Add target-specific relocation scanning for x86 (#178846)

Implement scanSection/scanSectionImpl for i386 and x86-64 to

* enable devirtualization of getRelExpr calls
* eliminate abstraction overhead for PLT-to-PCRel optimization, TLS
relocations
* optimize for R_X86_64_PC32 and R_X86_64_PLT32: they consist of 95%
  relocations in `lld/ELF/**/*.o` files.
* enable future optimization to remove `loc` from `getRelExpr` (only
  used by X86.cpp `R_386_GOT32[X]`)

at the cost of more boilerplate.

TLS relocation handling is inlined into scanSectionImpl. Also,

- Remove getTlsGdRelaxSkip
- Replace TLS-optimization-specific expressions:
- R_RELAX_TLS_GD_TO_LE, R_RELAX_TLS_LD_TO_LE, R_RELAX_TLS_IE_TO_LE →
R_TPREL
  - R_RELAX_TLS_GD_TO_IE → R_GOT_PC

This follows the pattern established for MIPS and PPC64 in `#163138`.

getRelExpr is simplified to only handle relocations needed for
relocateNonAlloc and relocateEH.

Average "Scan relocations" time (measured by --time-trace) decreases
from 110078 to 101585.

(
```
ruby -rjson -e 't=[]; 50.times { system("numactl -C 0-7 /t/lld1 -flavor gnu --threads=8 @response.txt -o a.out --time-trace"); t << JSON.parse(File.read("a.out.time-trace"))["traceEvents"].find { |e| e["name"] == "Scan relocations" }["dur"] }; puts "Average: #{t.sum / t.size}"'
```
)



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