Skip to content

Commit 2b3d827

Browse files
maksfbkrishna2803
authored andcommitted
[BOLT][AArch64] Compensate for missing code markers (llvm#151060)
Code written in assembly can have missing code markers. In BOLT, we can compensate by recognizing that a function entry point should start a code sequence. Seen such code in lua jit library.
1 parent 0860766 commit 2b3d827

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,20 @@ void RewriteInstance::discoverFileObjects() {
896896
continue;
897897

898898
MarkerSymType MarkerType = BC->getMarkerType(SymInfo.Symbol);
899+
900+
// Treat ST_Function as code.
901+
Expected<object::SymbolRef::Type> TypeOrError = SymInfo.Symbol.getType();
902+
consumeError(TypeOrError.takeError());
903+
if (TypeOrError && *TypeOrError == SymbolRef::ST_Function) {
904+
if (IsData) {
905+
Expected<StringRef> NameOrError = SymInfo.Symbol.getName();
906+
consumeError(NameOrError.takeError());
907+
BC->errs() << "BOLT-WARNING: function symbol " << *NameOrError
908+
<< " lacks code marker\n";
909+
}
910+
MarkerType = MarkerSymType::CODE;
911+
}
912+
899913
if (MarkerType != MarkerSymType::NONE) {
900914
SortedMarkerSymbols.push_back(MarkerSym{SymInfo.Address, MarkerType});
901915
LastAddr = SymInfo.Address;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
## Check that llvm-bolt is able to recover a missing code marker.
2+
3+
# RUN: %clang %cflags %s -o %t.exe -nostdlib -fuse-ld=lld -Wl,-q
4+
# RUN: llvm-bolt %t.exe -o %t.bolt 2>&1 | FileCheck %s
5+
6+
# CHECK: BOLT-WARNING: function symbol foo lacks code marker
7+
8+
.text
9+
.balign 4
10+
11+
.word 0
12+
13+
## Function foo starts immediately after a data object and does not have
14+
## a matching "$x" symbol to indicate the start of code.
15+
.global foo
16+
.type foo, %function
17+
foo:
18+
.word 0xd65f03c0
19+
.size foo, .-foo
20+
21+
.global _start
22+
.type _start, %function
23+
_start:
24+
bl foo
25+
ret
26+
.size _start, .-_start

0 commit comments

Comments
 (0)