Skip to content

Commit

Permalink
[AsmPrinter] Don't emit __patchable_function_entries entry if "patcha…
Browse files Browse the repository at this point in the history
…ble-function-entry"="0"

Add improve tests
  • Loading branch information
MaskRay committed Jan 21, 2020
1 parent c81fe34 commit d232c21
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 28 deletions.
6 changes: 5 additions & 1 deletion llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
Expand Up @@ -3189,7 +3189,11 @@ void AsmPrinter::recordSled(MCSymbol *Sled, const MachineInstr &MI,

void AsmPrinter::emitPatchableFunctionEntries() {
const Function &F = MF->getFunction();
if (!F.hasFnAttribute("patchable-function-entry"))
unsigned PatchableFunctionEntry = 0;
(void)F.getFnAttribute("patchable-function-entry")
.getValueAsString()
.getAsInteger(10, PatchableFunctionEntry);
if (!PatchableFunctionEntry)
return;
const unsigned PointerSize = getPointerSize();
if (TM.getTargetTriple().isOSBinFormatELF()) {
Expand Down
13 changes: 6 additions & 7 deletions llvm/test/CodeGen/AArch64/patchable-function-entry-bti.ll
Expand Up @@ -2,22 +2,21 @@

define i32 @f0() "patchable-function-entry"="0" "branch-target-enforcement" {
; CHECK-LABEL: f0:
; CHECK-NEXT: .Lfunc_begin0:
; CHECK: hint #34
; CHECK-NEXT: .Lfunc_begin0:
; CHECK: %bb.0:
; CHECK-NEXT: hint #34
; CHECK-NEXT: mov w0, wzr
; CHECK: .section __patchable_function_entries,"awo",@progbits,f0,unique,0
; CHECK-NEXT: .p2align 3
; CHECK-NEXT: .xword .Lfunc_begin0
; CHECK-NOT: .section __patchable_function_entries
ret i32 0
}

define i32 @f1() "patchable-function-entry"="1" "branch-target-enforcement" {
; CHECK-LABEL: f1:
; CHECK-NEXT: .Lfunc_begin1:
; CHECK-NEXT: .Lfunc_begin1:
; CHECK: hint #34
; CHECK-NEXT: nop
; CHECK-NEXT: mov w0, wzr
; CHECK: .section __patchable_function_entries,"awo",@progbits,f0,unique,0
; CHECK: .section __patchable_function_entries,"awo",@progbits,f1,unique,0
; CHECK-NEXT: .p2align 3
; CHECK-NEXT: .xword .Lfunc_begin1
ret i32 0
Expand Down
27 changes: 18 additions & 9 deletions llvm/test/CodeGen/AArch64/patchable-function-entry.ll
Expand Up @@ -10,9 +10,7 @@ define i32 @f0() "patchable-function-entry"="0" {
; CHECK-NEXT: .Lfunc_begin0:
; CHECK-NOT: nop
; CHECK: mov w0, wzr
; CHECK: .section __patchable_function_entries,"awo",@progbits,f0,unique,0
; CHECK-NEXT: .p2align 3
; CHECK-NEXT: .xword .Lfunc_begin0
; CHECK-NOT: .section __patchable_function_entries
ret i32 0
}

Expand All @@ -21,36 +19,47 @@ define i32 @f1() "patchable-function-entry"="1" {
; CHECK-NEXT: .Lfunc_begin1:
; CHECK: nop
; CHECK-NEXT: mov w0, wzr
; NOFSECT: .section __patchable_function_entries,"awo",@progbits,f0,unique,0
; FSECT: .section __patchable_function_entries,"awo",@progbits,f1,unique,1
; CHECK: .section __patchable_function_entries,"awo",@progbits,f1,unique,0
; CHECK-NEXT: .p2align 3
; CHECK-NEXT: .xword .Lfunc_begin1
ret i32 0
}

define void @f2() "patchable-function-entry"="2" {
; CHECK-LABEL: f2:
; CHECK-NEXT: .Lfunc_begin2:
; CHECK-COUNT-2: nop
; CHECK-NEXT: ret
; NOFSECT: .section __patchable_function_entries,"awo",@progbits,f1,unique,0
; FSECT: .section __patchable_function_entries,"awo",@progbits,f2,unique,1
; CHECK-NEXT: .p2align 3
; CHECK-NEXT: .xword .Lfunc_begin2
ret void
}

$f3 = comdat any
define void @f3() "patchable-function-entry"="3" comdat {
; CHECK-LABEL: f3:
; CHECK-NEXT: .Lfunc_begin2:
; CHECK-NEXT: .Lfunc_begin3:
; CHECK-COUNT-3: nop
; CHECK-NEXT: ret
; NOFSECT: .section __patchable_function_entries,"aGwo",@progbits,f3,comdat,f3,unique,1
; FSECT: .section __patchable_function_entries,"aGwo",@progbits,f3,comdat,f3,unique,2
; CHECK-NEXT: .p2align 3
; CHECK-NEXT: .xword .Lfunc_begin2
; CHECK-NEXT: .xword .Lfunc_begin3
ret void
}

$f5 = comdat any
define void @f5() "patchable-function-entry"="5" comdat {
; CHECK-LABEL: f5:
; CHECK-NEXT: .Lfunc_begin3:
; CHECK-NEXT: .Lfunc_begin4:
; CHECK-COUNT-5: nop
; CHECK-NEXT: sub sp, sp, #16
; NOFSECT .section __patchable_function_entries,"aGwo",@progbits,f5,comdat,f5,unique,2
; FSECT: .section __patchable_function_entries,"aGwo",@progbits,f5,comdat,f5,unique,3
; CHECK: .p2align 3
; CHECK-NEXT: .xword .Lfunc_begin3
; CHECK-NEXT: .xword .Lfunc_begin4
%frame = alloca i8, i32 16
ret void
}
33 changes: 22 additions & 11 deletions llvm/test/CodeGen/X86/patchable-function-entry.ll
@@ -1,32 +1,43 @@
; RUN: llc -mtriple=i386 %s -o - | FileCheck --check-prefixes=CHECK,NOFSECT,32 %s
; RUN: llc -mtriple=x86_64 %s -o - | FileCheck --check-prefixes=CHECK,NOFSECT,64 %s
; RUN: llc -mtriple=x86_64 -function-sections %s -o - | FileCheck --check-prefixes=CHECK,FSECT,64 %s

define void @f0() "patchable-function-entry"="0" {
; CHECK-LABEL: f0:
; CHECK-NEXT: .Lfunc_begin0:
; CHECK-NOT: nop
; CHECK: ret
; CHECK: .section __patchable_function_entries,"awo",@progbits,f0,unique,0
; 32: .p2align 2
; 32-NEXT: .long .Lfunc_begin0
; 64: .p2align 3
; 64-NEXT: .quad .Lfunc_begin0
; CHECK-NOT: .section __patchable_function_entries
ret void
}

define void @f1() "patchable-function-entry"="1" {
; CHECK-LABEL: f1:
; CHECK-NEXT: .Lfunc_begin1:
; CHECK: nop
; CHECK-NEXT: ret
; NOFSECT: .section __patchable_function_entries,"awo",@progbits,f0,unique,0
; FSECT: .section __patchable_function_entries,"awo",@progbits,f1,unique,1
; CHECK: .section __patchable_function_entries,"awo",@progbits,f1,unique,0
; 32: .p2align 2
; 32-NEXT: .long .Lfunc_begin1
; 64: .p2align 3
; 64-NEXT: .quad .Lfunc_begin1
ret void
}

define void @f2() "patchable-function-entry"="2" {
; CHECK-LABEL: f2:
; 32-COUNT-2: nop
; 64: xchgw %ax, %ax
; CHECK-NEXT: ret
; NOFSECT: .section __patchable_function_entries,"awo",@progbits,f1,unique,0
; FSECT: .section __patchable_function_entries,"awo",@progbits,f2,unique,1
; 32: .p2align 2
; 32-NEXT: .long .Lfunc_begin2
; 64: .p2align 3
; 64-NEXT: .quad .Lfunc_begin2
ret void
}

$f3 = comdat any
define void @f3() "patchable-function-entry"="3" comdat {
; CHECK-LABEL: f3:
Expand All @@ -36,9 +47,9 @@ define void @f3() "patchable-function-entry"="3" comdat {
; NOFSECT: .section __patchable_function_entries,"aGwo",@progbits,f3,comdat,f3,unique,1
; FSECT: .section __patchable_function_entries,"aGwo",@progbits,f3,comdat,f3,unique,2
; 32: .p2align 2
; 32-NEXT: .long .Lfunc_begin2
; 32-NEXT: .long .Lfunc_begin3
; 64: .p2align 3
; 64-NEXT: .quad .Lfunc_begin2
; 64-NEXT: .quad .Lfunc_begin3
ret void
}

Expand All @@ -51,8 +62,8 @@ define void @f5() "patchable-function-entry"="5" comdat {
; NOFSECT .section __patchable_function_entries,"aGwo",@progbits,f5,comdat,f5,unique,2
; FSECT: .section __patchable_function_entries,"aGwo",@progbits,f5,comdat,f5,unique,3
; 32: .p2align 2
; 32-NEXT: .long .Lfunc_begin3
; 32-NEXT: .long .Lfunc_begin4
; 64: .p2align 3
; 64-NEXT: .quad .Lfunc_begin3
; 64-NEXT: .quad .Lfunc_begin4
ret void
}

0 comments on commit d232c21

Please sign in to comment.