Skip to content

Commit eacd62a

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 fc6fd6a commit eacd62a

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

lld/ELF/Driver.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2618,6 +2618,12 @@ 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+
sym->type = elfSym.getType();
2625+
}
2626+
26212627
// For defined symbols in non-relocatable output,
26222628
// compute isExported and parse '@'.
26232629
if (!ctx.arg.relocatable)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
15+
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
16+
target triple = "aarch64-unknown-linux-gnu"
17+
18+
@var = external global ptr
19+
20+
declare void @foo()
21+
22+
define void @bar() #0 {
23+
entry:
24+
store ptr ptrauth (ptr @foo, i32 0), ptr @var
25+
ret void
26+
}
27+
28+
define void @_start() {
29+
entry:
30+
ret void
31+
}
32+
33+
attributes #0 = {"target-features"="+pauth"}
34+
35+
!llvm.module.flags = !{!0}
36+
!0 = !{i32 8, !"ptrauth-elf-got", i32 1}

0 commit comments

Comments
 (0)