Skip to content

Commit b59cf21

Browse files
committed
[BOLT] Don't choke on injected functions' IO map
AddressMap would fail lookup for injected functions and crash BOLT. Fix that. Reviewed By: #bolt, maksfb, jobnoorman Differential Revision: https://reviews.llvm.org/D158685
1 parent b5ac169 commit b59cf21

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4129,8 +4129,14 @@ void BinaryFunction::updateOutputValues(const MCAsmLayout &Layout) {
41294129
(void)FragmentBaseAddress;
41304130
}
41314131

4132-
const uint64_t BBAddress =
4133-
*BC.getIOAddressMap().lookup(BB->getInputOffset() + getAddress());
4132+
// Injected functions likely will fail lookup, as they have no
4133+
// input range. Just assign the BB the output address of the
4134+
// function.
4135+
auto MaybeBBAddress =
4136+
BC.getIOAddressMap().lookup(BB->getInputOffset() + getAddress());
4137+
const uint64_t BBAddress = MaybeBBAddress ? *MaybeBBAddress
4138+
: BB->isSplit() ? FF.getAddress()
4139+
: getOutputAddress();
41344140
BB->setOutputStartAddress(BBAddress);
41354141

41364142
if (PrevBB)

bolt/test/X86/patch-entries.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Checking crashes against injected binary functions created by patch
2+
// entries pass and debug info turned on. In these cases, we were
3+
// trying to fetch input to output maps on injected functions and
4+
// crashing.
5+
6+
// REQUIRES: system-linux
7+
8+
// RUN: %clang %cflags -no-pie -g %s -fuse-ld=lld -o %t.exe -Wl,-q
9+
// RUN: llvm-bolt -relocs %t.exe -o %t.out --update-debug-sections \
10+
// RUN: --force-patch
11+
12+
#include <stdio.h>
13+
14+
static void foo() { printf("foo\n"); }
15+
16+
int main() {
17+
foo();
18+
return 0;
19+
}

0 commit comments

Comments
 (0)