[lld] [ELF] Refactor RelocScan::scan to be target-specific (PR #163138)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 14 09:55:47 PDT 2025


================
@@ -87,6 +88,11 @@ class TargetInfo {
   virtual bool inBranchRange(RelType type, uint64_t src,
                              uint64_t dst) const;
 
+  template <class ELFT, class RelTy>
----------------
MaskRay wrote:

The latest revision has these comments. MIPS and PPC64 demonstrate how `scanSection` is overridden. We probably also need comments in RelocScan.h. 
```
  // Function for scanning relocation. Typically overridden by targets that
  // require special type or addend adjustment.
  virtual void scanSection(InputSectionBase &); 2 refs | 2 derived
  // Called by scanSection as a default implementation for specific ELF
  // relocation types.
  template <class ELFT> void scanSection1(InputSectionBase &); 0 ref | 2 refs
  template <class ELFT, class RelTy> 0 ref | 1 ref
  void scanSectionImpl(InputSectionBase &, Relocs<RelTy>); 3 refs
```

In the future, we probably should make RelocScan fully target-specific, eliminating `ctx.arg.emachine` overhead. Newer linkers mold and wild use arch as a template parameter, making relocation scanner substantially faster at the cost of binary size.

https://github.com/llvm/llvm-project/pull/163138


More information about the llvm-commits mailing list