[all-commits] [llvm/llvm-project] c8f0d3: [ELF][PPC64] Support long branch thunks with addends

Fangrui Song via All-commits all-commits at lists.llvm.org
Thu Dec 5 10:17:55 PST 2019


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: c8f0d3e130d336f49c204b9ee317bf99be192a82
      https://github.com/llvm/llvm-project/commit/c8f0d3e130d336f49c204b9ee317bf99be192a82
  Author: Fangrui Song <maskray at google.com>
  Date:   2019-12-05 (Thu, 05 Dec 2019)

  Changed paths:
    M lld/ELF/Arch/PPC64.cpp
    M lld/ELF/Relocations.cpp
    M lld/ELF/Symbols.cpp
    M lld/ELF/Symbols.h
    M lld/ELF/SyntheticSections.cpp
    M lld/ELF/SyntheticSections.h
    M lld/ELF/Thunks.cpp
    A lld/test/ELF/ppc64-long-branch-pi.s
    M lld/test/ELF/ppc64-long-branch.s
    R lld/test/ELF/ppc64-shared-long_branch.s

  Log Message:
  -----------
  [ELF][PPC64] Support long branch thunks with addends

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 tests -no-pie and
ppc64-long-branch-pi.s tests -pie and -shared.

Reviewed By: sfertile

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




More information about the All-commits mailing list