[all-commits] [llvm/llvm-project] 92fbb6: [lld][AArch64] Add BTI landing pad to PLT entries ...

Dani via All-commits all-commits at lists.llvm.org
Thu Jun 29 13:17:31 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 92fbb602f3b635110417e40e2f774b31798b0b1d
      https://github.com/llvm/llvm-project/commit/92fbb602f3b635110417e40e2f774b31798b0b1d
  Author: Daniel Kiss <daniel.kiss at arm.com>
  Date:   2023-06-29 (Thu, 29 Jun 2023)

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

  Log Message:
  -----------
  [lld][AArch64] Add BTI landing pad to PLT entries when the symbol is exported.

With relative vtables the caller jumps directly to the plt entries in the shared object,
therefore landing pad is need for these entries.

Reproducer:
main.cpp
```
#include "v.hpp"
int main() {
    A* a = new B();
    a->do_something2();
    return 0;
}
```
v.hpp
```
struct A {
    virtual void do_something() = 0;
    virtual void do_something2();
};
struct B : public A {
    void do_something() override;
    void do_something2() override;
};
```
v.cpp
```
#include "v.hpp"
void A::do_something2() { }
void B::do_something() { }
void B::do_something2() { }
```
```
CC="clang++ --target=aarch64-unknown-linux-gnu -fuse-ld=lld -mbranch-protection=bti"
F=-fexperimental-relative-c++-abi-vtables
${=CC} $F -shared v.cpp -o v.so -z force-bti
${=CC} $F main.cpp -L./ v.so -Wl,-rpath=. -z force-bti
qemu-aarch64-static -L /usr/aarch64-linux-gnu -cpu max ./a.out
```
For v.so, the regular vtable entry is relocated by an R_AARCH64_ABS64 relocation referencing _ZN1B13do_something2Ev.
```
_ZTV1B:
.xword  _ZN1B13do_something2Ev
```
Using relative vtable entry for a DSO has a downside of creating many PLT entries and making their addresses escape.
The relative vtable entry references a PLT entry _ZN1B13do_something2Ev at plt.
```
.L_ZTV1A.local:
        .word   (_ZN1A13do_something2Ev at PLT-.L_ZTV1A.local)-8
```

fixes: #63580

Reviewed By: peter.smith, MaskRay

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




More information about the All-commits mailing list