[llvm] d232c21 - [AsmPrinter] Don't emit __patchable_function_entries entry if "patchable-function-entry"="0"
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 20 16:14:50 PST 2020
Author: Fangrui Song
Date: 2020-01-20T16:13:48-08:00
New Revision: d232c215669cb57f5eb4ead40a4a336220dbc429
URL: https://github.com/llvm/llvm-project/commit/d232c215669cb57f5eb4ead40a4a336220dbc429
DIFF: https://github.com/llvm/llvm-project/commit/d232c215669cb57f5eb4ead40a4a336220dbc429.diff
LOG: [AsmPrinter] Don't emit __patchable_function_entries entry if "patchable-function-entry"="0"
Add improve tests
Added:
Modified:
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/test/CodeGen/AArch64/patchable-function-entry-bti.ll
llvm/test/CodeGen/AArch64/patchable-function-entry.ll
llvm/test/CodeGen/X86/patchable-function-entry.ll
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 368a7975bbbc..4d2bcd1ed57c 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -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()) {
diff --git a/llvm/test/CodeGen/AArch64/patchable-function-entry-bti.ll b/llvm/test/CodeGen/AArch64/patchable-function-entry-bti.ll
index 9b406d45da6e..00b9b2329fd5 100644
--- a/llvm/test/CodeGen/AArch64/patchable-function-entry-bti.ll
+++ b/llvm/test/CodeGen/AArch64/patchable-function-entry-bti.ll
@@ -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", at 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", at progbits,f0,unique,0
+; CHECK: .section __patchable_function_entries,"awo", at progbits,f1,unique,0
; CHECK-NEXT: .p2align 3
; CHECK-NEXT: .xword .Lfunc_begin1
ret i32 0
diff --git a/llvm/test/CodeGen/AArch64/patchable-function-entry.ll b/llvm/test/CodeGen/AArch64/patchable-function-entry.ll
index 12b8a35cb93a..6d84f23ba5ef 100644
--- a/llvm/test/CodeGen/AArch64/patchable-function-entry.ll
+++ b/llvm/test/CodeGen/AArch64/patchable-function-entry.ll
@@ -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", at progbits,f0,unique,0
-; CHECK-NEXT: .p2align 3
-; CHECK-NEXT: .xword .Lfunc_begin0
+; CHECK-NOT: .section __patchable_function_entries
ret i32 0
}
@@ -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", at progbits,f0,unique,0
-; FSECT: .section __patchable_function_entries,"awo", at progbits,f1,unique,1
+; CHECK: .section __patchable_function_entries,"awo", at 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", at progbits,f1,unique,0
+; FSECT: .section __patchable_function_entries,"awo", at 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", at progbits,f3,comdat,f3,unique,1
; FSECT: .section __patchable_function_entries,"aGwo", at 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", at progbits,f5,comdat,f5,unique,2
; FSECT: .section __patchable_function_entries,"aGwo", at 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
}
diff --git a/llvm/test/CodeGen/X86/patchable-function-entry.ll b/llvm/test/CodeGen/X86/patchable-function-entry.ll
index 89d94f8336e1..2fbb0c9cd62e 100644
--- a/llvm/test/CodeGen/X86/patchable-function-entry.ll
+++ b/llvm/test/CodeGen/X86/patchable-function-entry.ll
@@ -1,25 +1,22 @@
; 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", at 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", at progbits,f0,unique,0
-; FSECT: .section __patchable_function_entries,"awo", at progbits,f1,unique,1
+; CHECK: .section __patchable_function_entries,"awo", at progbits,f1,unique,0
; 32: .p2align 2
; 32-NEXT: .long .Lfunc_begin1
; 64: .p2align 3
@@ -27,6 +24,20 @@ define void @f1() "patchable-function-entry"="1" {
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", at progbits,f1,unique,0
+; FSECT: .section __patchable_function_entries,"awo", at 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:
@@ -36,9 +47,9 @@ define void @f3() "patchable-function-entry"="3" comdat {
; NOFSECT: .section __patchable_function_entries,"aGwo", at progbits,f3,comdat,f3,unique,1
; FSECT: .section __patchable_function_entries,"aGwo", at 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
}
@@ -51,8 +62,8 @@ define void @f5() "patchable-function-entry"="5" comdat {
; NOFSECT .section __patchable_function_entries,"aGwo", at progbits,f5,comdat,f5,unique,2
; FSECT: .section __patchable_function_entries,"aGwo", at 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
}
More information about the llvm-commits
mailing list