[PATCH] D70937: [ELF][PPC64] Support long branch thunks with addends

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 2 18:15:25 PST 2019


MaskRay created this revision.
MaskRay added reviewers: grimar, kbarton, peter.smith, ruiu, sfertile.
Herald added subscribers: llvm-commits, jsji, kristof.beyls, arichardson, nemanjai, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.

Fixes PPC64 part of PR40438

  // clang -target ppc64le -c a.cc
  // .text.unlikely may be placed in a separate output section (via -z keep-text-section-prefix)
  // The distance between bar in .text.unlikely and foo in .text may be larger than 32MiB.
  static void foo() {}
  __attribute__((section(".text.unlikely"))) static int bar() { foo(); return 0; }
  __attribute__((used)) static int dummy = bar();

This patch makes such thunks with addends work for PPC64.

AArch64: .text -> __AArch64ADRPThunk_ (adrp x16, ...; add x16, x16, ...; br x16) -> target
PPC64: .text -> __long_branch_ (addis 12, 2, ...; ld 12, ...(12); mtctr 12; bctr) -> target

AArch64 can leverage ADRP to jump to the target directly, but PPC64
needs to load an address from .branch_lt . Before Power ISA v3.0, the
PC-relative ADDPCIS was not available. .branch_lt was invented to work
around the limitation.

Symbol::ppc64BranchltIndex is replaced by
PPC64LongBranchTargetSection::entry_index which take addends into
consideration.

The tests are rewritten: ppc64-long-branch.s (-no-pie) and
ppc64-long-branch-pi.s (-pie and -shared).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70937

Files:
  lld/ELF/Arch/PPC64.cpp
  lld/ELF/Relocations.cpp
  lld/ELF/Symbols.cpp
  lld/ELF/Symbols.h
  lld/ELF/SyntheticSections.cpp
  lld/ELF/SyntheticSections.h
  lld/ELF/Thunks.cpp
  lld/test/ELF/ppc64-long-branch-pi.s
  lld/test/ELF/ppc64-long-branch.s
  lld/test/ELF/ppc64-shared-long_branch.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70937.231806.patch
Type: text/x-patch
Size: 21282 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191203/7e6dfc25/attachment.bin>


More information about the llvm-commits mailing list