[all-commits] [llvm/llvm-project] 19d53d: [ELF][AArch64] Refine and fix the condition when B...

Fangrui Song via All-commits all-commits at lists.llvm.org
Wed Sep 22 11:51:21 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 19d53d45f2709d37b07bcd73dc5300304ce2ffee
      https://github.com/llvm/llvm-project/commit/19d53d45f2709d37b07bcd73dc5300304ce2ffee
  Author: Fangrui Song <i at maskray.me>
  Date:   2021-09-22 (Wed, 22 Sep 2021)

  Changed paths:
    M lld/ELF/Arch/AArch64.cpp
    M lld/test/ELF/Inputs/aarch64-addrifunc.s
    M lld/test/ELF/aarch64-feature-bti.s
    M lld/test/ELF/aarch64-feature-btipac.s
    M lld/test/ELF/aarch64-ifunc-bti.s

  Log Message:
  -----------
  [ELF][AArch64] Refine and fix the condition when BTI/PAC PLT needs bti c

(As I mentioned in https://reviews.llvm.org/D62609#1534158 ,
the condition for using bti c for executable can be loosened.)

In two cases the address of a PLT may escape:

* canonical PLT entry for a STT_FUNC
* non-preemptible STT_GNU_IFUNC which is converted to STT_FUNC

The first case can be detected with `needsPltAddr`.

The second case is not straightforward to detect because for the Relocations.cpp
created `directSym`, it's difficult to know whether the associated `sym` has
exercised the `!needsPlt(expr)` code path. Just use the conservative `isInIplt`
condition. A non-preemptible ifunc not referenced by non-GOT-generating
non-PLT-generating relocations will have an unneeded `bti c`, but the cost is acceptable.

The second case fixes a bug as well: a -shared link may have non-preemptible ifunc.
Before the patch we did not emit `bti c` and could be wrong if the PLT address escaped.
GNU ld doesn't handle the case: `relocation R_AARCH64_ADR_PREL_PG_HI21 against STT_GNU_IFUNC symbol 'ifunc2' isn't handled by elf64_aarch64_final_link_relocate` (https://sourceware.org/bugzilla/show_bug.cgi?id=28370)

For -shared, if BTI is enabled but PAC is disabled, the PLT entry size increases
from 16 to 24 because we have to select the PLT scheme early, but the cost is
acceptable.

Reviewed By: peter.smith

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




More information about the All-commits mailing list