[llvm] [BOLT] addRelocation does not add pending relocs (PR #123635)
Paschalis Mpeis via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 20 07:47:34 PST 2025
https://github.com/paschalis-mpeis created https://github.com/llvm/llvm-project/pull/123635
Use addPendingRelocation for that.
>From f235ceec17c9096870408de7515f9c9e9b22d2b5 Mon Sep 17 00:00:00 2001
From: Paschalis Mpeis <Paschalis.Mpeis at arm.com>
Date: Mon, 20 Jan 2025 15:39:59 +0000
Subject: [PATCH] [BOLT] addRelocation does not add pending relocs
Use addPendingRelocation for that.
---
bolt/include/bolt/Core/BinarySection.h | 10 ++--------
bolt/unittests/Core/BinaryContext.cpp | 16 +++++++++-------
2 files changed, 11 insertions(+), 15 deletions(-)
diff --git a/bolt/include/bolt/Core/BinarySection.h b/bolt/include/bolt/Core/BinarySection.h
index d362961176b326..dedee361882497 100644
--- a/bolt/include/bolt/Core/BinarySection.h
+++ b/bolt/include/bolt/Core/BinarySection.h
@@ -358,15 +358,9 @@ class BinarySection {
/// Add a new relocation at the given /p Offset.
void addRelocation(uint64_t Offset, MCSymbol *Symbol, uint64_t Type,
- uint64_t Addend, uint64_t Value = 0,
- bool Pending = false) {
+ uint64_t Addend, uint64_t Value = 0) {
assert(Offset < getSize() && "offset not within section bounds");
- if (!Pending) {
- Relocations.emplace(Relocation{Offset, Symbol, Type, Addend, Value});
- } else {
- PendingRelocations.emplace_back(
- Relocation{Offset, Symbol, Type, Addend, Value});
- }
+ Relocations.emplace(Relocation{Offset, Symbol, Type, Addend, Value});
}
/// Add a dynamic relocation at the given /p Offset.
diff --git a/bolt/unittests/Core/BinaryContext.cpp b/bolt/unittests/Core/BinaryContext.cpp
index 05b898d34af56c..6e8ad4f62baeff 100644
--- a/bolt/unittests/Core/BinaryContext.cpp
+++ b/bolt/unittests/Core/BinaryContext.cpp
@@ -92,12 +92,13 @@ TEST_P(BinaryContextTester, FlushPendingRelocCALL26) {
DataSize, 4);
MCSymbol *RelSymbol1 = BC->getOrCreateGlobalSymbol(4, "Func1");
ASSERT_TRUE(RelSymbol1);
- BS.addRelocation(8, RelSymbol1, ELF::R_AARCH64_CALL26, 0, 0, true);
+ BS.addPendingRelocation(
+ Relocation{8, RelSymbol1, ELF::R_AARCH64_CALL26, 0, 0});
MCSymbol *RelSymbol2 = BC->getOrCreateGlobalSymbol(16, "Func2");
ASSERT_TRUE(RelSymbol2);
- BS.addRelocation(12, RelSymbol2, ELF::R_AARCH64_CALL26, 0, 0, true);
+ BS.addPendingRelocation(
+ Relocation{12, RelSymbol2, ELF::R_AARCH64_CALL26, 0, 0});
- std::error_code EC;
SmallVector<char> Vect(DataSize);
raw_svector_ostream OS(Vect);
@@ -133,12 +134,13 @@ TEST_P(BinaryContextTester, FlushPendingRelocJUMP26) {
(uint8_t *)Data, Size, 4);
MCSymbol *RelSymbol1 = BC->getOrCreateGlobalSymbol(4, "Func1");
ASSERT_TRUE(RelSymbol1);
- BS.addRelocation(8, RelSymbol1, ELF::R_AARCH64_JUMP26, 0, 0, true);
+ BS.addPendingRelocation(
+ Relocation{8, RelSymbol1, ELF::R_AARCH64_JUMP26, 0, 0});
MCSymbol *RelSymbol2 = BC->getOrCreateGlobalSymbol(16, "Func2");
ASSERT_TRUE(RelSymbol2);
- BS.addRelocation(12, RelSymbol2, ELF::R_AARCH64_JUMP26, 0, 0, true);
+ BS.addPendingRelocation(
+ Relocation{12, RelSymbol2, ELF::R_AARCH64_JUMP26, 0, 0});
- std::error_code EC;
SmallVector<char> Vect(Size);
raw_svector_ostream OS(Vect);
@@ -216,4 +218,4 @@ TEST_P(BinaryContextTester, BaseAddressSegmentsSmallerThanAlignment) {
BC->getBaseAddressForMapping(0xaaaaaaab1000, 0x1000);
ASSERT_TRUE(BaseAddress.has_value());
ASSERT_EQ(*BaseAddress, 0xaaaaaaaa0000ULL);
-}
\ No newline at end of file
+}
More information about the llvm-commits
mailing list