[PATCH] D87286: AArch64: make sure jump table entries can reach entire image

Tim Northover via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 8 06:34:03 PDT 2020


t.p.northover created this revision.
Herald added subscribers: danielkiss, hiraditya, kristof.beyls, mcrosier.
Herald added a project: LLVM.
t.p.northover requested review of this revision.

This patch is addressing two issues:

1. https://bugs.llvm.org/show_bug.cgi?id=47124. A weak function containing a jump table causes a linker warning on Darwin because the entries (`LBB - lJTI`) refer back to the function and can't be overridden.
2. The AArch64 "small" code model that we default to requires that all statically allocated code and data is within a 4GB window, somewhere in memory. Unfortunately our jump table entries are 32-bit signed constants which only have a 2GB reach, and they're located in a different section (to allow for things like execute-only memory).

Without that second issue I'd prefer to silence the linker warning somehow, and without the first I'd be tempted to let sleeping dogs lie, but together I think they make a compelling enough case to change how we do jump tables. Currently we emit something like

      adrp x0, LJTI0_0 at PAGE
      add x0, x0, LJTI0_0 at PAGEOFF
      ldrsw x1, [x0, x2, lsl #2]
      add x0, x0, x1
      br x0
      [...]
  LJTI0_0:
      .word LBB0_0 - LJTI0_0

If we can no longer use `LJTI0_0` as the base we need something within the function that has to be materialized separately. So this changes the sequence to be

      adrp x0, LJTI0_0 at PAGE
      add x0, x0, LJTI0_0 at PAGEOFF
  Ltmp0:
      adr x1, Ltmp0
      ldrsw x2, [x0, x2, lsl #2]
      add x1, x1, x2, lsl #2
      br x1
  [...]
  LJTI0_0:
      .word (LBB0_0 - Ltmp0)>>2


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87286

Files:
  llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.h
  llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
  llvm/test/CodeGen/AArch64/jump-table-exynos.ll
  llvm/test/CodeGen/AArch64/win64-jumptable.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87286.290466.patch
Type: text/x-patch
Size: 10611 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200908/4085218f/attachment.bin>


More information about the llvm-commits mailing list