[all-commits] [llvm/llvm-project] 156e60: [lld-macho] Fix branch extension thunk estimation ...

alx32 via All-commits all-commits at lists.llvm.org
Thu Jan 9 14:14:35 PST 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 156e6051630d136b48090c0d1cb79a4457564e9d
      https://github.com/llvm/llvm-project/commit/156e6051630d136b48090c0d1cb79a4457564e9d
  Author: alx32 <103613512+alx32 at users.noreply.github.com>
  Date:   2025-01-09 (Thu, 09 Jan 2025)

  Changed paths:
    M lld/MachO/ConcatOutputSection.cpp

  Log Message:
  -----------
  [lld-macho] Fix branch extension thunk estimation logic (#120529)

This patch improves the linker’s ability to estimate stub reachability
in the `TextOutputSection::estimateStubsInRangeVA` function. It does so
by including thunks that have already been placed ahead of the current
call site address when calculating the threshold for direct stub calls.

Before this fix, the estimation process overlooked existing forward
thunks. This could result in some thunks not being inserted where
needed. In rare situations, particularly with large and specially
arranged codebases, this might lead to branch instructions being out of
range, causing linking errors.

Although this patch successfully addresses the problem, it is not
feasible to create a test for this issue. The specific layout and order
of thunk creation required to reproduce the corner case are too complex,
making test creation impractical.

Example error messages the issue could generate:
```
ld64.lld: error: banana.o:(symbol OUTLINED_FUNCTION_24949_3875): relocation BRANCH26 is out of range: 134547892 is not in [-134217728, 134217727]; references objc_autoreleaseReturnValue
ld64.lld: error: main.o:(symbol _main+0xc): relocation BRANCH26 is out of range: 134544132 is not in [-134217728, 134217727]; references objc_release
```



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