Skip to content

Commit 543f13c

Browse files
nhuhuanaaupov
authored andcommitted
[BOLT] Allow function entry to be a cold fragment
Allow cold fragment to get new address. Our previous assumption is that a fragment (.cold) is only reached through the main fragment of same function. In addition, .cold fragment must be reached through either (a) direct transfer, or (b) split jump table. For (a), we perform a simple fix-up. For (b), we currently mark all relevant fragments as non-simple. Therefore, there is no need to get new address for .cold fragment. This is not always the case, as function entry can be rarely executed, and is placed in .text.cold segment. Essentially we cannot tell which the source-level function entry is based on hot and cold segments, so we must treat each fragment a function on its own. Therfore, we remove the assertion that a function entry cannot be cold fragment. Test Plan: ``` ninja check-bolt ``` Reviewed By: Amir Differential Revision: https://reviews.llvm.org/D128111
1 parent 545a71c commit 543f13c

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5207,8 +5207,6 @@ uint64_t RewriteInstance::getNewFunctionAddress(uint64_t OldAddress) {
52075207
if (!Function)
52085208
return 0;
52095209

5210-
assert(!Function->isFragment() && "cannot get new address for a fragment");
5211-
52125210
return Function->getOutputAddress();
52135211
}
52145212

bolt/test/X86/shared_object_entry.s

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o
2+
# RUN: ld.lld %t.o -o %t.so --shared --entry=func1.cold.1 --emit-relocs
3+
# RUN: llvm-bolt -relocs %t.so -o %t -reorder-functions=hfsort+ \
4+
# RUN: -split-functions=3 -reorder-blocks=ext-tsp -split-all-cold \
5+
# RUN: -dyno-stats -icf=1 -use-gnu-stack
6+
7+
# Check that an entry point is a cold symbol
8+
# RUN: llvm-readelf -h %t.so > %t.log
9+
# RUN: llvm-nm %t.so >> %t.log
10+
# RUN: FileCheck %s --input-file %t.log
11+
# CHECK: Entry point address: 0x[[#%X,ENTRY:]]
12+
# CHECK: [[#%x,ENTRY]] {{.*}} func1.cold.1
13+
14+
.globl func1.cold.1
15+
.type func1.cold.1,@function
16+
func1.cold.1:
17+
.cfi_startproc
18+
.L1:
19+
movq %rbx, %rdx
20+
jmp .L3
21+
.L2:
22+
# exit(0)
23+
movq $60, %rax
24+
xorq %rdi, %rdi
25+
syscall
26+
.size func1.cold.1, .-func1.cold.1
27+
.cfi_endproc
28+
29+
.globl func1
30+
.type func1,@function
31+
func1:
32+
.cfi_startproc
33+
.L3:
34+
movq %rax, %rdi
35+
jmp .L2
36+
call exit
37+
.size func1, .-func1
38+
.cfi_endproc

0 commit comments

Comments
 (0)