diff options
| author | Fangrui Song <i@maskray.me> | 2020-01-20 15:52:38 -0800 |
|---|---|---|
| committer | Fangrui Song <maskray@google.com> | 2020-01-24 10:38:40 -0800 |
| commit | 0e2eea29cc4f360fc95638fbfc8aca24cec3fc5f (patch) | |
| tree | 569796329fbe8c6afc5c93f1a29a65cdac707cd4 | |
| parent | 6c1e479db225897cbbff7894ffe77824c03ab8fd (diff) | |
| download | bcm5719-llvm-0e2eea29cc4f360fc95638fbfc8aca24cec3fc5f.tar.gz bcm5719-llvm-0e2eea29cc4f360fc95638fbfc8aca24cec3fc5f.zip | |
[AsmPrinter] Don't emit __patchable_function_entries entry if "patchable-function-entry"="0"
Add improve tests
(cherry picked from commit d232c215669cb57f5eb4ead40a4a336220dbc429)
4 files changed, 51 insertions, 28 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 6f9aa4dd79f..e7a7ca79e33 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -3199,7 +3199,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 9b406d45da6..00b9b2329fd 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",@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 diff --git a/llvm/test/CodeGen/AArch64/patchable-function-entry.ll b/llvm/test/CodeGen/AArch64/patchable-function-entry.ll index 12b8a35cb93..6d84f23ba5e 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",@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",@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 } diff --git a/llvm/test/CodeGen/X86/patchable-function-entry.ll b/llvm/test/CodeGen/X86/patchable-function-entry.ll index 89d94f8336e..2fbb0c9cd62 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",@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 @@ -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",@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: @@ -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 } @@ -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 } |

