[llvm-branch-commits] [llvm] [BOLT] Emit empty FDE for injected functions (PR #87967)

Amir Ayupov via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Apr 9 16:40:32 PDT 2024


https://github.com/aaupov updated https://github.com/llvm/llvm-project/pull/87967

>From c856716bbb987e09ee86b31287808736ef4f2f9b Mon Sep 17 00:00:00 2001
From: Amir Ayupov <aaupov at fb.com>
Date: Tue, 9 Apr 2024 04:52:43 -0700
Subject: [PATCH 1/3] Added test

Created using spr 1.3.4
---
 bolt/include/bolt/Core/BinaryFunction.h |  3 ++-
 bolt/lib/Core/BinaryEmitter.cpp         |  4 ++--
 bolt/test/X86/patch-entries.test        | 23 ++++++++++++++++++++++-
 3 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/bolt/include/bolt/Core/BinaryFunction.h b/bolt/include/bolt/Core/BinaryFunction.h
index bc047fefa3151c..26d2d01f862671 100644
--- a/bolt/include/bolt/Core/BinaryFunction.h
+++ b/bolt/include/bolt/Core/BinaryFunction.h
@@ -1402,7 +1402,8 @@ class BinaryFunction {
 
   /// Return true if the function has CFI instructions
   bool hasCFI() const {
-    return !FrameInstructions.empty() || !CIEFrameInstructions.empty();
+    return !FrameInstructions.empty() || !CIEFrameInstructions.empty() ||
+           IsInjected;
   }
 
   /// Return unique number associated with the function.
diff --git a/bolt/lib/Core/BinaryEmitter.cpp b/bolt/lib/Core/BinaryEmitter.cpp
index 56bd65a51600d1..97d19b75200f51 100644
--- a/bolt/lib/Core/BinaryEmitter.cpp
+++ b/bolt/lib/Core/BinaryEmitter.cpp
@@ -347,7 +347,7 @@ bool BinaryEmitter::emitFunction(BinaryFunction &Function,
   }
 
   // Emit CFI start
-  if (Function.hasCFI() || Function.isInjected()) {
+  if (Function.hasCFI()) {
     Streamer.emitCFIStartProc(/*IsSimple=*/false);
     if (Function.getPersonalityFunction() != nullptr)
       Streamer.emitCFIPersonality(Function.getPersonalityFunction(),
@@ -394,7 +394,7 @@ bool BinaryEmitter::emitFunction(BinaryFunction &Function,
     Streamer.emitBytes(BC.MIB->getTrapFillValue());
 
   // Emit CFI end
-  if (Function.hasCFI() || Function.isInjected())
+  if (Function.hasCFI())
     Streamer.emitCFIEndProc();
 
   MCSymbol *EndSymbol = Function.getFunctionEndLabel(FF.getFragmentNum());
diff --git a/bolt/test/X86/patch-entries.test b/bolt/test/X86/patch-entries.test
index 54f358f273e793..331f8a312f4820 100644
--- a/bolt/test/X86/patch-entries.test
+++ b/bolt/test/X86/patch-entries.test
@@ -7,4 +7,25 @@ REQUIRES: system-linux
 
 RUN: %clang %cflags -no-pie -g %p/Inputs/patch-entries.c -fuse-ld=lld -o %t.exe \
 RUN:   -Wl,-q -I%p/../Inputs
-RUN: llvm-bolt -relocs %t.exe -o %t.out --update-debug-sections --force-patch
+RUN: llvm-bolt -relocs %t.exe -o %t.out --update-debug-sections --force-patch \
+RUN:   --enable-bat
+
+# Check that patched functions can be disassembled (override FDE from the
+# original function)
+# PREAGG: B X:0 #foo.org.0# 1 0
+RUN: link_fdata %s %t.out %t.preagg PREAGG
+RUN: perf2bolt %t.out -p %t.preagg --pa -o %t.yaml --profile-format=yaml \
+RUN:   -print-disasm -print-only=foo.org.0/1 2>&1 | FileCheck %s
+CHECK-NOT: BOLT-WARNING: sizes differ for function foo.org.0/1. FDE : 23; symbol table : 5. Using max size.
+CHECK: Binary Function "foo.org.0/1(*2)" after disassembly {
+
+# Check the expected eh_frame contents
+RUN: llvm-nm --print-size %t.out > %t.foo
+RUN: llvm-objdump %t.out --dwarf=frames >> %t.foo
+RUN: FileCheck %s --input-file %t.foo --check-prefix=CHECK-FOO
+CHECK-FOO: [[#FOO:]] {{.*}} foo
+CHECK-FOO: [[#ORG:]] {{.*}} foo.org.0
+# patched FDE comes first
+CHECK-FOO: FDE {{.*}} pc=00[[#ORG]]...00[[#ORG+5]]
+# original FDE comes second
+CHECK-FOO: FDE {{.*}} pc=00[[#ORG]]...00[[#ORG+23]]

>From ed991a81eb7975c41c5db75fa772329752911c00 Mon Sep 17 00:00:00 2001
From: Amir Ayupov <aaupov at fb.com>
Date: Tue, 9 Apr 2024 15:23:28 -0700
Subject: [PATCH 2/3] Fix test

Created using spr 1.3.4
---
 bolt/test/X86/patch-entries.test | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/bolt/test/X86/patch-entries.test b/bolt/test/X86/patch-entries.test
index 331f8a312f4820..2821501fd9baad 100644
--- a/bolt/test/X86/patch-entries.test
+++ b/bolt/test/X86/patch-entries.test
@@ -16,7 +16,7 @@ RUN:   --enable-bat
 RUN: link_fdata %s %t.out %t.preagg PREAGG
 RUN: perf2bolt %t.out -p %t.preagg --pa -o %t.yaml --profile-format=yaml \
 RUN:   -print-disasm -print-only=foo.org.0/1 2>&1 | FileCheck %s
-CHECK-NOT: BOLT-WARNING: sizes differ for function foo.org.0/1. FDE : 23; symbol table : 5. Using max size.
+CHECK-NOT: BOLT-WARNING: sizes differ for function foo.org.0/1
 CHECK: Binary Function "foo.org.0/1(*2)" after disassembly {
 
 # Check the expected eh_frame contents
@@ -28,4 +28,4 @@ CHECK-FOO: [[#ORG:]] {{.*}} foo.org.0
 # patched FDE comes first
 CHECK-FOO: FDE {{.*}} pc=00[[#ORG]]...00[[#ORG+5]]
 # original FDE comes second
-CHECK-FOO: FDE {{.*}} pc=00[[#ORG]]...00[[#ORG+23]]
+CHECK-FOO: FDE {{.*}} pc=00[[#ORG]]

>From cb1096ef2e86d7f7ff628e033cf88a46268533d6 Mon Sep 17 00:00:00 2001
From: Amir Ayupov <aaupov at fb.com>
Date: Tue, 9 Apr 2024 16:40:21 -0700
Subject: [PATCH 3/3] Update test

Created using spr 1.3.4
---
 bolt/test/X86/patch-entries.test | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/bolt/test/X86/patch-entries.test b/bolt/test/X86/patch-entries.test
index 2821501fd9baad..4a725412dd616a 100644
--- a/bolt/test/X86/patch-entries.test
+++ b/bolt/test/X86/patch-entries.test
@@ -23,9 +23,9 @@ CHECK: Binary Function "foo.org.0/1(*2)" after disassembly {
 RUN: llvm-nm --print-size %t.out > %t.foo
 RUN: llvm-objdump %t.out --dwarf=frames >> %t.foo
 RUN: FileCheck %s --input-file %t.foo --check-prefix=CHECK-FOO
-CHECK-FOO: [[#FOO:]] {{.*}} foo
-CHECK-FOO: [[#ORG:]] {{.*}} foo.org.0
+CHECK-FOO: 0000000000[[#%x,FOO:]] [[#%x,OPTSIZE:]] t foo
+CHECK-FOO: 0000000000[[#%x,ORG:]] [[#%x,ORGSIZE:]] t foo.org.0
 # patched FDE comes first
-CHECK-FOO: FDE {{.*}} pc=00[[#ORG]]...00[[#ORG+5]]
+CHECK-FOO: FDE {{.*}} pc=00[[#%x,ORG]]...00[[#%x,ORG+ORGSIZE]]
 # original FDE comes second
-CHECK-FOO: FDE {{.*}} pc=00[[#ORG]]
+CHECK-FOO: FDE {{.*}} pc=00[[#%x,ORG]]...00[[#%x,ORG+OPTSIZE]]



More information about the llvm-branch-commits mailing list