[PATCH] D143137: [RISCV] Permit tail call to an externally-defined function with weak linkage

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 2 10:05:52 PST 2023


MaskRay accepted this revision.
MaskRay added a comment.

In D143137#4099933 <https://reviews.llvm.org/D143137#4099933>, @reames wrote:

> I don't believe this is, in general, legal to do for RISCV psABI.  The problem is that a weak symbol can resolve to the address 0, and that 0 may be outside the addressable range of a pcrelative call/branch sequence.  There is disagreement between the linkers as to whether such sequences should be rewritten to a different instruction sequence.  For non-tail calls, we end up emitting an explicit load through the GOT and call sequence.
>
> Note that this concern does not apply in all code models.  (I believe medlow is not effected, but double check!)  You can look at the code which emits the GOT lookup for general calls, and there's probably cases where we can emit the direct tail call.  We just need to restrict it appropriately.
>
> p.s. Your example with gcc is a static (not pc relative) call.

@reames I think this change is fine. call and tail use the same relocation type. The zero address, possibly not reachable by the relocated location issue only applies to possibly address significant relocation types.
Branch relocations are not address significant and linkers can resolve the relocation to the current location (infinite loop if executed) to avoid relocation out-of-range errors (see D103001 <https://reviews.llvm.org/D103001>).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D143137/new/

https://reviews.llvm.org/D143137



More information about the llvm-commits mailing list