[PATCH] D110217: [ELF][AArch64] Refine and fix the condition when BTI/PAC PLT needs bti c

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 21 20:15:08 PDT 2021


MaskRay created this revision.
MaskRay added a reviewer: peter.smith.
Herald added subscribers: kristof.beyls, arichardson, emaste.
MaskRay requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

(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 original symbol has
exercised the `!needsPlt(expr)` code path. Just use the conservative `isInIplt`
condition to detect it. 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 as well.
Before the patch we did not emit `bti c` and could be wrong if its 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`

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110217

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110217.374101.patch
Type: text/x-patch
Size: 14086 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210922/6a11d0c7/attachment-0001.bin>


More information about the llvm-commits mailing list