Skip to content

Commit de9b3ca

Browse files
authored
[BOLT] Always treat function entry as code (#160161)
If an address has both, a data marker "$d" and a function symbol associated with it, treat it as code.
1 parent 9c0e09e commit de9b3ca

File tree

3 files changed

+31
-22
lines changed

3 files changed

+31
-22
lines changed

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -917,9 +917,6 @@ void RewriteInstance::discoverFileObjects() {
917917
bool IsData = false;
918918
uint64_t LastAddr = 0;
919919
for (const auto &SymInfo : SortedSymbols) {
920-
if (LastAddr == SymInfo.Address) // don't repeat markers
921-
continue;
922-
923920
MarkerSymType MarkerType = BC->getMarkerType(SymInfo.Symbol);
924921

925922
// Treat ST_Function as code.
@@ -929,8 +926,14 @@ void RewriteInstance::discoverFileObjects() {
929926
if (IsData) {
930927
Expected<StringRef> NameOrError = SymInfo.Symbol.getName();
931928
consumeError(NameOrError.takeError());
932-
BC->errs() << "BOLT-WARNING: function symbol " << *NameOrError
933-
<< " lacks code marker\n";
929+
if (LastAddr == SymInfo.Address) {
930+
BC->errs() << "BOLT-WARNING: ignoring data marker conflicting with "
931+
"function symbol "
932+
<< *NameOrError << '\n';
933+
} else {
934+
BC->errs() << "BOLT-WARNING: function symbol " << *NameOrError
935+
<< " lacks code marker\n";
936+
}
934937
}
935938
MarkerType = MarkerSymType::CODE;
936939
}

bolt/test/AArch64/data-at-0-offset.c

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## Check that if a data marker is present at the start of a function, the
2+
## underlying bytes are still treated as code.
3+
4+
# RUN: %clang %cflags %s -o %t.exe
5+
# RUN: llvm-bolt %t.exe -o %t.bolt --print-cfg 2>&1 | FileCheck %s
6+
7+
# CHECK: BOLT-WARNING: ignoring data marker conflicting with function symbol _start
8+
9+
.text
10+
.balign 4
11+
12+
## Data marker is emitted because ".long" directive is used instead of ".inst".
13+
.global _start
14+
.type _start, %function
15+
_start:
16+
.long 0xcec08000 // sha512su0 v0.2d, v0.2d
17+
ret
18+
.size _start, .-_start
19+
20+
# CHECK-LABEL: Binary Function "_start"
21+
# CHECK: Entry Point
22+
# CHECK-NEXT: sha512su0 v0.2d, v0.2d
23+

0 commit comments

Comments
 (0)