[PATCH] D153264: [lld][AArch64] Add BTI landing pad to PLT entries when the symbol is exported.

Daniel Kiss via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 29 13:17:36 PDT 2023


This revision was automatically updated to reflect the committed changes.
danielkiss marked an inline comment as done.
Closed by commit rG92fbb602f3b6: [lld][AArch64] Add BTI landing pad to PLT entries when the symbol is exported. (authored by danielkiss).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D153264?vs=535880&id=535976#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153264/new/

https://reviews.llvm.org/D153264

Files:
  lld/ELF/Arch/AArch64.cpp
  lld/test/ELF/aarch64-feature-bti.s


Index: lld/test/ELF/aarch64-feature-bti.s
===================================================================
--- lld/test/ELF/aarch64-feature-bti.s
+++ lld/test/ELF/aarch64-feature-bti.s
@@ -1,6 +1,7 @@
 # REQUIRES: aarch64
 # RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu %s -o %t.o
 # RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu --defsym CANONICAL_PLT=1 %s -o %tcanon.o
+# RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu --defsym RELVTABLE_PLT=1 %s -o %trelvtable.o
 # RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu %p/Inputs/aarch64-bti1.s -o %t1.o
 # RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu %p/Inputs/aarch64-func3.s -o %t2.o
 # RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu %p/Inputs/aarch64-func3-bti.s -o %t3.o
@@ -154,6 +155,42 @@
 # PIE-NEXT:           nop
 # PIE-NEXT:           nop
 
+## We expect the same for R_AARCH64_PLT32, as the address of an plt entry escapes
+# RUN: ld.lld --shared %trelvtable.o -o %trelv.exe
+# RUN: llvm-readelf -n %trelv.exe | FileCheck --check-prefix=BTIPROP %s
+# RUN: llvm-readelf --dynamic-table -n %trelv.exe | FileCheck --check-prefix=BTIPROP %s
+# RUN: llvm-objdump --no-print-imm-hex -d --mattr=+bti --no-show-raw-insn %trelv.exe | FileCheck --check-prefix=RELV %s
+
+# RELV:       Disassembly of section .text:
+# RELV-LABEL: <func1>:
+# RELV-NEXT:    10380: bl     0x103b0 <func2 at plt>
+# RELV-NEXT:           bl      0x103c8 <funcRelVtable at plt>
+# RELV-NEXT:           ret
+# RELV:        Disassembly of section .plt:
+# RELV-LABEL:  <.plt>:
+# RELV-NEXT:    10390: bti    c
+# RELV-NEXT:           stp    x16, x30, [sp, #-16]!
+# RELV-NEXT:           adrp   x16, 0x30000
+# RELV-NEXT:           ldr    x17, [x16, #1200]
+# RELV-NEXT:           add    x16, x16, #1200
+# RELV-NEXT:           br     x17
+# RELV-NEXT:           nop
+# RELV-NEXT:           nop
+# RELV-LABEL: <func2 at plt>:
+# RELV-NEXT:    103b0: adrp   x16, 0x30000
+# RELV-NEXT:           ldr    x17, [x16, #1208]
+# RELV-NEXT:           add    x16, x16, #1208
+# RELV-NEXT:           br     x17
+# RELV-NEXT:           nop
+# RELV-NEXT:           nop
+# RELV-LABEL: <funcRelVtable at plt>:
+# RELV-NEXT:   103c8:  bti     c
+# RELV-NEXT:           adrp    x16, 0x30000 <_DYNAMIC+0xfc20>
+# RELV-NEXT:           ldr     x17, [x16, #1216]
+# RELV-NEXT:           add     x16, x16, #1216
+# RELV-NEXT:           br      x17
+# RELV-NEXT:           nop
+
 ## Build and executable with not all relocatable inputs having the BTI
 ## .note.property, expect no bti c and no .note.gnu.property entry
 
@@ -241,5 +278,13 @@
   add  x0, x0, :lo12:func2
 .else
   bl func2
+.endif
+.ifdef RELVTABLE_PLT
+  bl funcRelVtable
 .endif
   ret
+
+.ifdef RELVTABLE_PLT
+// R_AARCH64_PLT32
+.word funcRelVtable at PLT - .
+.endif
Index: lld/ELF/Arch/AArch64.cpp
===================================================================
--- lld/ELF/Arch/AArch64.cpp
+++ lld/ELF/Arch/AArch64.cpp
@@ -136,7 +136,9 @@
   case R_AARCH64_CONDBR19:
   case R_AARCH64_JUMP26:
   case R_AARCH64_TSTBR14:
+    return R_PLT_PC;
   case R_AARCH64_PLT32:
+    const_cast<Symbol &>(s).thunkAccessed = true;
     return R_PLT_PC;
   case R_AARCH64_PREL16:
   case R_AARCH64_PREL32:
@@ -910,8 +912,9 @@
 
   // NEEDS_COPY indicates a non-ifunc canonical PLT entry whose address may
   // escape to shared objects. isInIplt indicates a non-preemptible ifunc. Its
-  // address may escape if referenced by a direct relocation. The condition is
-  // conservative.
+  // address may escape if referenced by a direct relocation. If relative
+  // vtables are used then if the vtable is in a shared object the offsets will
+  // be to the PLT entry. The condition is conservative.
   bool hasBti = btiHeader &&
                 (sym.hasFlag(NEEDS_COPY) || sym.isInIplt || sym.thunkAccessed);
   if (hasBti) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153264.535976.patch
Type: text/x-patch
Size: 3821 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230629/be8b122c/attachment.bin>


More information about the llvm-commits mailing list