[PATCH] D70637: [ELF][AArch64] Support R_AARCH64_{CALL26,JUMP26} range extension thunks with addends

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 23 14:56:29 PST 2019


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

Fixes AArch64 part of PR40438

The current range extension thunk framework does not handle a relocation
relative to a STT_SECTION symbol with a non-zero addend, which may be
used by jumps/calls to local functions on some RELA targets (AArch64,
powerpc ELFv1, powerpc64 ELFv2, etc).  See PR40438 and the following
code for examples:

  // clang -target $target -c a.cc
  static void foo() {}
  __attribute__((section(".text.cold"))) static int bar() { foo(); return
  0; }
  __attribute__((used)) static int dummy = bar();

This patch makes such thunks with addends work for AArch64. The target
independent part can be reused by PPC in the future.

On REL targets (ARM, MIPS), jumps/calls are not represented as
STT_SECTION + non-zero addend (see
MCELFObjectTargetWriter::needsRelocateWithSymbol), so they don't need
this feature, but we need to make sure this patch does not affect them.

On ARM, the compensation of implicit addends is done in ARM::needsThunk.
This makes it tricky not to affect ARM. I feel that the code can be
generalized (see `config->isRela` introduced in the patch) if we
reorganize the code (ARM::needsThunk).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70637

Files:
  lld/ELF/Arch/AArch64.cpp
  lld/ELF/Arch/ARM.cpp
  lld/ELF/Arch/Mips.cpp
  lld/ELF/Arch/PPC.cpp
  lld/ELF/Arch/PPC64.cpp
  lld/ELF/Relocations.cpp
  lld/ELF/Relocations.h
  lld/ELF/Target.cpp
  lld/ELF/Target.h
  lld/ELF/Thunks.cpp
  lld/ELF/Thunks.h
  lld/test/ELF/aarch64-thunk-pi.s
  lld/test/ELF/aarch64-thunk-script.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70637.230776.patch
Type: text/x-patch
Size: 22452 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191123/babf0331/attachment.bin>


More information about the llvm-commits mailing list