Skip to content

Commit 4db0cc4

Browse files
authored
[BOLT] Allow sections in --print-only flag (#109622)
While printing functions, expand --print-only flag to accept section names. E.g., "--print-only=\.init" will only print functions from ".init" section.
1 parent 1bfca99 commit 4db0cc4

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ bool shouldPrint(const BinaryFunction &Function) {
165165
}
166166
}
167167

168+
std::optional<StringRef> Origin = Function.getOriginSectionName();
169+
if (Origin && llvm::any_of(opts::PrintOnly, [&](const std::string &Name) {
170+
return Name == *Origin;
171+
}))
172+
return true;
173+
168174
return false;
169175
}
170176

bolt/test/X86/print-only-section.s

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
## Check that --print-only flag works with sections.
2+
3+
# REQUIRES: system-linux
4+
5+
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-linux %s -o %t.o
6+
# RUN: ld.lld %t.o -o %t.exe
7+
# RUN: llvm-bolt %t.exe -o %t.out --print-cfg --print-only=unused_code 2>&1 \
8+
# RUN: | FileCheck %s
9+
10+
# CHECK: Binary Function "foo"
11+
# CHECK-NOT: Binary Function "_start"
12+
13+
.text
14+
.globl _start
15+
.type _start, %function
16+
_start:
17+
.cfi_startproc
18+
ret
19+
.cfi_endproc
20+
.size _start, .-_start
21+
22+
.section unused_code,"ax",@progbits
23+
.globl foo
24+
.type foo, %function
25+
foo:
26+
.cfi_startproc
27+
ret
28+
.cfi_endproc
29+
.size foo, .-foo

0 commit comments

Comments
 (0)