Skip to content

Commit d232c21

Browse files
committed
[AsmPrinter] Don't emit __patchable_function_entries entry if "patchable-function-entry"="0"
Add improve tests
1 parent c81fe34 commit d232c21

File tree

4 files changed

+51
-28
lines changed

4 files changed

+51
-28
lines changed

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3189,7 +3189,11 @@ void AsmPrinter::recordSled(MCSymbol *Sled, const MachineInstr &MI,
31893189

31903190
void AsmPrinter::emitPatchableFunctionEntries() {
31913191
const Function &F = MF->getFunction();
3192-
if (!F.hasFnAttribute("patchable-function-entry"))
3192+
unsigned PatchableFunctionEntry = 0;
3193+
(void)F.getFnAttribute("patchable-function-entry")
3194+
.getValueAsString()
3195+
.getAsInteger(10, PatchableFunctionEntry);
3196+
if (!PatchableFunctionEntry)
31933197
return;
31943198
const unsigned PointerSize = getPointerSize();
31953199
if (TM.getTargetTriple().isOSBinFormatELF()) {

llvm/test/CodeGen/AArch64/patchable-function-entry-bti.ll

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,21 @@
22

33
define i32 @f0() "patchable-function-entry"="0" "branch-target-enforcement" {
44
; CHECK-LABEL: f0:
5-
; CHECK-NEXT: .Lfunc_begin0:
6-
; CHECK: hint #34
5+
; CHECK-NEXT: .Lfunc_begin0:
6+
; CHECK: %bb.0:
7+
; CHECK-NEXT: hint #34
78
; CHECK-NEXT: mov w0, wzr
8-
; CHECK: .section __patchable_function_entries,"awo",@progbits,f0,unique,0
9-
; CHECK-NEXT: .p2align 3
10-
; CHECK-NEXT: .xword .Lfunc_begin0
9+
; CHECK-NOT: .section __patchable_function_entries
1110
ret i32 0
1211
}
1312

1413
define i32 @f1() "patchable-function-entry"="1" "branch-target-enforcement" {
1514
; CHECK-LABEL: f1:
16-
; CHECK-NEXT: .Lfunc_begin1:
15+
; CHECK-NEXT: .Lfunc_begin1:
1716
; CHECK: hint #34
1817
; CHECK-NEXT: nop
1918
; CHECK-NEXT: mov w0, wzr
20-
; CHECK: .section __patchable_function_entries,"awo",@progbits,f0,unique,0
19+
; CHECK: .section __patchable_function_entries,"awo",@progbits,f1,unique,0
2120
; CHECK-NEXT: .p2align 3
2221
; CHECK-NEXT: .xword .Lfunc_begin1
2322
ret i32 0

llvm/test/CodeGen/AArch64/patchable-function-entry.ll

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ define i32 @f0() "patchable-function-entry"="0" {
1010
; CHECK-NEXT: .Lfunc_begin0:
1111
; CHECK-NOT: nop
1212
; CHECK: mov w0, wzr
13-
; CHECK: .section __patchable_function_entries,"awo",@progbits,f0,unique,0
14-
; CHECK-NEXT: .p2align 3
15-
; CHECK-NEXT: .xword .Lfunc_begin0
13+
; CHECK-NOT: .section __patchable_function_entries
1614
ret i32 0
1715
}
1816

@@ -21,36 +19,47 @@ define i32 @f1() "patchable-function-entry"="1" {
2119
; CHECK-NEXT: .Lfunc_begin1:
2220
; CHECK: nop
2321
; CHECK-NEXT: mov w0, wzr
24-
; NOFSECT: .section __patchable_function_entries,"awo",@progbits,f0,unique,0
25-
; FSECT: .section __patchable_function_entries,"awo",@progbits,f1,unique,1
22+
; CHECK: .section __patchable_function_entries,"awo",@progbits,f1,unique,0
2623
; CHECK-NEXT: .p2align 3
2724
; CHECK-NEXT: .xword .Lfunc_begin1
2825
ret i32 0
2926
}
3027

28+
define void @f2() "patchable-function-entry"="2" {
29+
; CHECK-LABEL: f2:
30+
; CHECK-NEXT: .Lfunc_begin2:
31+
; CHECK-COUNT-2: nop
32+
; CHECK-NEXT: ret
33+
; NOFSECT: .section __patchable_function_entries,"awo",@progbits,f1,unique,0
34+
; FSECT: .section __patchable_function_entries,"awo",@progbits,f2,unique,1
35+
; CHECK-NEXT: .p2align 3
36+
; CHECK-NEXT: .xword .Lfunc_begin2
37+
ret void
38+
}
39+
3140
$f3 = comdat any
3241
define void @f3() "patchable-function-entry"="3" comdat {
3342
; CHECK-LABEL: f3:
34-
; CHECK-NEXT: .Lfunc_begin2:
43+
; CHECK-NEXT: .Lfunc_begin3:
3544
; CHECK-COUNT-3: nop
3645
; CHECK-NEXT: ret
3746
; NOFSECT: .section __patchable_function_entries,"aGwo",@progbits,f3,comdat,f3,unique,1
3847
; FSECT: .section __patchable_function_entries,"aGwo",@progbits,f3,comdat,f3,unique,2
3948
; CHECK-NEXT: .p2align 3
40-
; CHECK-NEXT: .xword .Lfunc_begin2
49+
; CHECK-NEXT: .xword .Lfunc_begin3
4150
ret void
4251
}
4352

4453
$f5 = comdat any
4554
define void @f5() "patchable-function-entry"="5" comdat {
4655
; CHECK-LABEL: f5:
47-
; CHECK-NEXT: .Lfunc_begin3:
56+
; CHECK-NEXT: .Lfunc_begin4:
4857
; CHECK-COUNT-5: nop
4958
; CHECK-NEXT: sub sp, sp, #16
5059
; NOFSECT .section __patchable_function_entries,"aGwo",@progbits,f5,comdat,f5,unique,2
5160
; FSECT: .section __patchable_function_entries,"aGwo",@progbits,f5,comdat,f5,unique,3
5261
; CHECK: .p2align 3
53-
; CHECK-NEXT: .xword .Lfunc_begin3
62+
; CHECK-NEXT: .xword .Lfunc_begin4
5463
%frame = alloca i8, i32 16
5564
ret void
5665
}
Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,43 @@
11
; RUN: llc -mtriple=i386 %s -o - | FileCheck --check-prefixes=CHECK,NOFSECT,32 %s
22
; RUN: llc -mtriple=x86_64 %s -o - | FileCheck --check-prefixes=CHECK,NOFSECT,64 %s
3+
; RUN: llc -mtriple=x86_64 -function-sections %s -o - | FileCheck --check-prefixes=CHECK,FSECT,64 %s
34

45
define void @f0() "patchable-function-entry"="0" {
56
; CHECK-LABEL: f0:
67
; CHECK-NEXT: .Lfunc_begin0:
78
; CHECK-NOT: nop
89
; CHECK: ret
9-
; CHECK: .section __patchable_function_entries,"awo",@progbits,f0,unique,0
10-
; 32: .p2align 2
11-
; 32-NEXT: .long .Lfunc_begin0
12-
; 64: .p2align 3
13-
; 64-NEXT: .quad .Lfunc_begin0
10+
; CHECK-NOT: .section __patchable_function_entries
1411
ret void
1512
}
1613

1714
define void @f1() "patchable-function-entry"="1" {
1815
; CHECK-LABEL: f1:
16+
; CHECK-NEXT: .Lfunc_begin1:
1917
; CHECK: nop
2018
; CHECK-NEXT: ret
21-
; NOFSECT: .section __patchable_function_entries,"awo",@progbits,f0,unique,0
22-
; FSECT: .section __patchable_function_entries,"awo",@progbits,f1,unique,1
19+
; CHECK: .section __patchable_function_entries,"awo",@progbits,f1,unique,0
2320
; 32: .p2align 2
2421
; 32-NEXT: .long .Lfunc_begin1
2522
; 64: .p2align 3
2623
; 64-NEXT: .quad .Lfunc_begin1
2724
ret void
2825
}
2926

27+
define void @f2() "patchable-function-entry"="2" {
28+
; CHECK-LABEL: f2:
29+
; 32-COUNT-2: nop
30+
; 64: xchgw %ax, %ax
31+
; CHECK-NEXT: ret
32+
; NOFSECT: .section __patchable_function_entries,"awo",@progbits,f1,unique,0
33+
; FSECT: .section __patchable_function_entries,"awo",@progbits,f2,unique,1
34+
; 32: .p2align 2
35+
; 32-NEXT: .long .Lfunc_begin2
36+
; 64: .p2align 3
37+
; 64-NEXT: .quad .Lfunc_begin2
38+
ret void
39+
}
40+
3041
$f3 = comdat any
3142
define void @f3() "patchable-function-entry"="3" comdat {
3243
; CHECK-LABEL: f3:
@@ -36,9 +47,9 @@ define void @f3() "patchable-function-entry"="3" comdat {
3647
; NOFSECT: .section __patchable_function_entries,"aGwo",@progbits,f3,comdat,f3,unique,1
3748
; FSECT: .section __patchable_function_entries,"aGwo",@progbits,f3,comdat,f3,unique,2
3849
; 32: .p2align 2
39-
; 32-NEXT: .long .Lfunc_begin2
50+
; 32-NEXT: .long .Lfunc_begin3
4051
; 64: .p2align 3
41-
; 64-NEXT: .quad .Lfunc_begin2
52+
; 64-NEXT: .quad .Lfunc_begin3
4253
ret void
4354
}
4455

@@ -51,8 +62,8 @@ define void @f5() "patchable-function-entry"="5" comdat {
5162
; NOFSECT .section __patchable_function_entries,"aGwo",@progbits,f5,comdat,f5,unique,2
5263
; FSECT: .section __patchable_function_entries,"aGwo",@progbits,f5,comdat,f5,unique,3
5364
; 32: .p2align 2
54-
; 32-NEXT: .long .Lfunc_begin3
65+
; 32-NEXT: .long .Lfunc_begin4
5566
; 64: .p2align 3
56-
; 64-NEXT: .quad .Lfunc_begin3
67+
; 64-NEXT: .quad .Lfunc_begin4
5768
ret void
5869
}

0 commit comments

Comments
 (0)