[llvm] [BOLT] Use new contents when emitting sections with relocations (PR #80782)

Maksim Panchenko via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 5 18:04:11 PST 2024


https://github.com/maksfb created https://github.com/llvm/llvm-project/pull/80782

We can use BinarySection::updateContents() to change section contents. However, if we also add relocations for new contents, then the original data (i.e. not updated) is going to be used. Fix that. A follow-up diff will use the update interface and will include a test case.

>From dc44ad2ff82681764ba0694b5ed34f6e41535290 Mon Sep 17 00:00:00 2001
From: Maksim Panchenko <maks at fb.com>
Date: Mon, 5 Feb 2024 16:40:08 -0800
Subject: [PATCH] [BOLT] Use new contents when emitting sections with
 relocations

We can use BinarySection::updateContents() to change section contents.
However, if we also add relocations for new contents, then the original
data (i.e. not updated) is going to be used. Fix that. A follow-up diff
will use the update interface and will include a test case.
---
 bolt/lib/Core/BinarySection.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/bolt/lib/Core/BinarySection.cpp b/bolt/lib/Core/BinarySection.cpp
index a8fc4f07bd3e8..97bc251935475 100644
--- a/bolt/lib/Core/BinarySection.cpp
+++ b/bolt/lib/Core/BinarySection.cpp
@@ -72,7 +72,8 @@ BinarySection::hash(const BinaryData &BD,
 
 void BinarySection::emitAsData(MCStreamer &Streamer,
                                const Twine &SectionName) const {
-  StringRef SectionContents = getContents();
+  StringRef SectionContents =
+      isFinalized() ? getOutputContents() : getContents();
   MCSectionELF *ELFSection =
       BC.Ctx->getELFSection(SectionName, getELFType(), getELFFlags());
 



More information about the llvm-commits mailing list