[all-commits] [llvm/llvm-project] 6b1d15: [ELF] Fix displacement computation for intra-secti...

Fangrui Song via All-commits all-commits at lists.llvm.org
Wed Jul 13 00:17:30 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 6b1d151fe3dc530195d8802f1ecc247c8235dd3a
      https://github.com/llvm/llvm-project/commit/6b1d151fe3dc530195d8802f1ecc247c8235dd3a
  Author: Fangrui Song <i at maskray.me>
  Date:   2022-07-13 (Wed, 13 Jul 2022)

  Changed paths:
    M lld/ELF/Arch/RISCV.cpp
    A lld/test/ELF/riscv-relax-call-intra-sec.s

  Log Message:
  -----------
  [ELF] Fix displacement computation for intra-section branch after D127611

D127611 computed st_value is inaccurate:

* For a backward branch, the destination address may be wrong if there is no
  relaxable relocation between it and the current location due to `if (remove)`.
  We may incorrectly relax a branch to c.j which ends up an overflow.
* For a forward branch, the destination address may be overestimated
  and lose relaxation opportunities.

To fix the issues,

* Don't reset st_value to the original value.
* Save the st_value delta from the previous iteration into valueDelta, and use
  `sa[0].d->value -= delta - valueDelta.find(sa[0].d)->second`.




More information about the All-commits mailing list