[lld] [PAC][ThinLTO] Fix auth key for GOT entries of function symbols (PR #131467)
Daniil Kovalev via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 14 06:44:18 PDT 2025
================
@@ -0,0 +1,38 @@
+; REQUIRES: aarch64
+
+; RUN: llvm-as %s -o %t.o
+; RUN: ld.lld %t.o -shared -o %t
+; RUN: llvm-readelf -r -x.got %t | FileCheck %s
+
+; CHECK: Relocation section '.rela.dyn' at offset 0x2a8 contains 2 entries:
+; CHECK-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
+; CHECK-NEXT: 00000000000203d8 0000000100000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 foo + 0
+; CHECK-NEXT: 00000000000203e0 0000000200000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 var + 0
+
+; CHECK: Hex dump of section '.got':
+; CHECK-NEXT: 0x000203d8 00000000 00000080 00000000 000000a0
+;; ^^ 0b10000000 bit 63 address diversity = true, bits 61..60 key = IA
+;; ^^ 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
+
+target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
+target triple = "aarch64-unknown-linux-gnu"
+
+ at var = external global ptr
+
+declare void @foo()
+
+define void @bar() #0 {
+entry:
+ store ptr ptrauth (ptr @foo, i32 0), ptr @var
----------------
kovdan01 wrote:
> Use llvm.used so that the symbols will not be optimized out.
Maybe I'm doing smth wrong, but it looks like that `llvm.used` has no effect and only the symbol from the last store operation is present in GOT. This is what I've added to the code (right before `@bar` definition, just in case):
```
@llvm.used = appending global [4 x ptr] [ ptr @func, ptr @func_undef, ptr @var, ptr @var_undef], section "llvm.metadata"
```
Adding `@g` to this array, removing `section "llvm.metadata"`, moving this array definition to the end of the file does not change the behavior.
This smells like a bug, given `llvm.used` description from IR reference: https://llvm.org/docs/LangRef.html#the-llvm-used-global-variable.
@MaskRay does this look like a bug for you as well, or maybe I'm just mis-using this special array?
As for now, I've just used a separate global for each store - g1, g2, g3, g4. Not elegant, but at least it works :)
https://github.com/llvm/llvm-project/pull/131467
More information about the llvm-commits
mailing list