[llvm] [BOLT] Preserve label annotations for injected functions (PR #68713)

Job Noorman via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 10 07:22:14 PDT 2023


https://github.com/mtvec created https://github.com/llvm/llvm-project/pull/68713

Needed for instrumentation on RISC-V.

>From eceed794bc135c005f8c8a35af3848515468cc4f Mon Sep 17 00:00:00 2001
From: Job Noorman <jnoorman at igalia.com>
Date: Tue, 10 Oct 2023 16:18:27 +0200
Subject: [PATCH] [BOLT] Preserve label annotations for injected functions

Needed for instrumentation on RISC-V.
---
 bolt/lib/Passes/BinaryPasses.cpp | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/bolt/lib/Passes/BinaryPasses.cpp b/bolt/lib/Passes/BinaryPasses.cpp
index 3ba53d7b2b79882..e50fa9dea602bc7 100644
--- a/bolt/lib/Passes/BinaryPasses.cpp
+++ b/bolt/lib/Passes/BinaryPasses.cpp
@@ -619,8 +619,11 @@ void LowerAnnotations::runOnFunctions(BinaryContext &BC) {
   }
   for (BinaryFunction *BF : BC.getInjectedBinaryFunctions())
     for (BinaryBasicBlock &BB : *BF)
-      for (MCInst &Instruction : BB)
+      for (MCInst &Instruction : BB) {
+        if (auto Label = BC.MIB->getLabel(Instruction))
+          PreservedLabelAnnotations.emplace_back(&Instruction, *Label);
         BC.MIB->stripAnnotations(Instruction);
+      }
 
   // Release all memory taken by annotations
   BC.MIB->freeAnnotations();



More information about the llvm-commits mailing list