Skip to content

Commit 479f585

Browse files
committed
[PAC][ThinLTO] Fix auth key for GOT entries of function symbols
Symtab is first filled with the data from the bitcode file, and all symbols except TLS ones are `STT_NOTYPE`. Since auth key for a signed GOT entry depends on the symbol type being `STT_FUNC` or not, we need to update the symtab after the bitcode is compiled to an ELF object and update symbol types for function symbols. This patch implements the described behavior.
1 parent 7722d75 commit 479f585

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

lld/ELF/Driver.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2618,6 +2618,13 @@ void LinkerDriver::compileBitcodeFiles(bool skipLinkedOutput) {
26182618
auto *obj = cast<ObjFile<ELFT>>(file.get());
26192619
obj->parse(/*ignoreComdats=*/true);
26202620

2621+
for (typename ELFT::Sym elfSym : obj->template getGlobalELFSyms<ELFT>()) {
2622+
StringRef elfSymName = check(elfSym.getName(obj->getStringTable()));
2623+
if (Symbol *sym = ctx.symtab->find(elfSymName))
2624+
if (sym->type == STT_NOTYPE)
2625+
sym->type = elfSym.getType();
2626+
}
2627+
26212628
// For defined symbols in non-relocatable output,
26222629
// compute isExported and parse '@'.
26232630
if (!ctx.arg.relocatable)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
; REQUIRES: aarch64
2+
3+
; RUN: llvm-as %s -o %t.o
4+
; RUN: ld.lld %t.o -shared -o %t
5+
; RUN: llvm-readelf -r -x.got %t | FileCheck %s
6+
7+
; CHECK: Relocation section '.rela.dyn' at offset 0x2a8 contains 2 entries:
8+
; CHECK-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
9+
; CHECK-NEXT: 00000000000203d8 0000000100000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 foo + 0
10+
; CHECK-NEXT: 00000000000203e0 0000000200000412 R_AARCH64_AUTH_GLOB_DAT 0000000000000000 var + 0
11+
12+
; CHECK: Hex dump of section '.got':
13+
; CHECK-NEXT: 0x000203d8 00000000 00000080 00000000 000000a0
14+
;; ^^ 0b10000000 bit 63 address diversity = true, bits 61..60 key = IA
15+
;; ^^ 0b10100000 bit 63 address diversity = true, bits 61..60 key = DA
16+
17+
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
18+
target triple = "aarch64-unknown-linux-gnu"
19+
20+
@var = external global ptr
21+
22+
declare void @foo()
23+
24+
define void @bar() #0 {
25+
entry:
26+
store ptr ptrauth (ptr @foo, i32 0), ptr @var
27+
ret void
28+
}
29+
30+
define void @_start() {
31+
entry:
32+
ret void
33+
}
34+
35+
attributes #0 = {"target-features"="+pauth"}
36+
37+
!llvm.module.flags = !{!0}
38+
!0 = !{i32 8, !"ptrauth-elf-got", i32 1}

0 commit comments

Comments
 (0)