diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp --- a/bolt/lib/Core/BinaryFunction.cpp +++ b/bolt/lib/Core/BinaryFunction.cpp @@ -4129,8 +4129,14 @@ (void)FragmentBaseAddress; } - const uint64_t BBAddress = - *BC.getIOAddressMap().lookup(BB->getInputOffset() + getAddress()); + // Injected functions likely will fail lookup, as they have no + // input range. Just assign the BB the output address of the + // function. + auto MaybeBBAddress = + BC.getIOAddressMap().lookup(BB->getInputOffset() + getAddress()); + const uint64_t BBAddress = MaybeBBAddress ? *MaybeBBAddress + : BB->isSplit() ? FF.getAddress() + : getOutputAddress(); BB->setOutputStartAddress(BBAddress); if (PrevBB) diff --git a/bolt/test/X86/patch-entries.c b/bolt/test/X86/patch-entries.c new file mode 100644 --- /dev/null +++ b/bolt/test/X86/patch-entries.c @@ -0,0 +1,19 @@ +// Checking crashes against injected binary functions created by patch +// entries pass and debug info turned on. In these cases, we were +// trying to fetch input to output maps on injected functions and +// crashing. + +// REQUIRES: system-linux + +// RUN: %clang %cflags -no-pie -g %s -fuse-ld=lld -o %t.exe -Wl,-q +// RUN: llvm-bolt -relocs %t.exe -o %t.out --update-debug-sections \ +// RUN: --force-patch + +#include + +static void foo() { printf("foo\n"); } + +int main() { + foo(); + return 0; +}