[all-commits] [llvm/llvm-project] c03fdd: [ELF] Fix the branch range computation when reusin...

Fangrui Song via All-commits all-commits at lists.llvm.org
Mon Jan 24 09:03:37 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: c03fdd340356c9a29242975f39786529eb99f194
      https://github.com/llvm/llvm-project/commit/c03fdd340356c9a29242975f39786529eb99f194
  Author: Fangrui Song <i at maskray.me>
  Date:   2022-01-24 (Mon, 24 Jan 2022)

  Changed paths:
    M lld/ELF/Relocations.cpp
    A lld/test/ELF/aarch64-thunk-reuse.s
    A lld/test/ELF/arm-thunk-reuse.s

  Log Message:
  -----------
  [ELF] Fix the branch range computation when reusing a thunk

Notation: dst is `t->getThunkTargetSym()->getVA()`

On AArch64, when `src-0x8000000-r_addend <= dst < src-0x8000000`, the condition
`target->inBranchRange(rel.type, src, rel.sym->getVA(rel.addend))` may
incorrectly consider a thunk reusable.
`rel.addend = -getPCBias(rel.type)` resets the addend to 0 for AArch64/PPC
and the zero addend is used by `rel.sym->getVA(rel.addend)` to check
out-of-range relocations.

See the test for a case this computation is wrong:
`error: a.o:(.text_high+0x4): relocation R_AARCH64_JUMP26 out of range: -134217732 is not in [-134217728, 134217727]`
I have seen a real world case with r_addend=19960.

Reviewed By: peter.smith

Differential Revision: https://reviews.llvm.org/D117734




More information about the All-commits mailing list