[PATCH] D158685: [BOLT] Don't choke on injected functions' IO map

Rafael Auler via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 23 17:09:37 PDT 2023


rafauler created this revision.
rafauler added a reviewer: bolt.
Herald added subscribers: treapster, ayermolo.
Herald added a reviewer: Amir.
Herald added a reviewer: maksfb.
Herald added a project: All.
rafauler requested review of this revision.
Herald added subscribers: llvm-commits, yota9.
Herald added a project: LLVM.

AddressMap would fail lookup for injected functions and crash
BOLT. Fix that.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158685

Files:
  bolt/lib/Core/BinaryFunction.cpp
  bolt/test/X86/patch-entries.c


Index: bolt/test/X86/patch-entries.c
===================================================================
--- /dev/null
+++ bolt/test/X86/patch-entries.c
@@ -0,0 +1,20 @@
+// 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 \
+// RUN:   -update-debug-sections \
+// RUN:  --force-patch
+
+#include <stdio.h>
+
+static void foo() { printf("foo\n"); }
+
+int main() {
+  foo();
+  return 0;
+}
Index: bolt/lib/Core/BinaryFunction.cpp
===================================================================
--- bolt/lib/Core/BinaryFunction.cpp
+++ 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)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158685.552927.patch
Type: text/x-patch
Size: 1603 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230824/c059ebc2/attachment.bin>


More information about the llvm-commits mailing list