[lld] ELF: Add branch-to-branch optimization. (PR #138366)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 18 22:19:33 PDT 2025


================
@@ -430,8 +430,10 @@ InputSectionBase *InputSection::getRelocatedSection() const {
 
 template <class ELFT, class RelTy>
 void InputSection::copyRelocations(Ctx &ctx, uint8_t *buf) {
-  if (ctx.arg.relax && !ctx.arg.relocatable &&
-      (ctx.arg.emachine == EM_RISCV || ctx.arg.emachine == EM_LOONGARCH)) {
+  if (!ctx.arg.relocatable &&
----------------
MaskRay wrote:

The condition is now complex... Perhaps define a variable for linker relaxation targets (RISCV,LoongArch)?
```
bool linkerRelax = ctx.arg.relax && (is_contained({EM_RISCV, EM_LOONGARCH}, ctx.arg.emachine);
...
(linkerRelax || ctx.arg.branchToBranch)
```

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


More information about the llvm-commits mailing list