[llvm] [Bolt] Fix issue 110407 (Support CREL) (PR #119150)

2 via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 8 14:49:22 PST 2024


https://github.com/0xfk0 created https://github.com/llvm/llvm-project/pull/119150

This commit fixes issue #110407 in Bolt subproject: BOLT programs not support CREL-type relocations.

>From e76d7498b2d85eb555a09e6b08b1b48c865df1ce Mon Sep 17 00:00:00 2001
From: Kirill Frolov <k.frolov at samsung.com>
Date: Mon, 9 Dec 2024 01:40:27 +0300
Subject: [PATCH] [Bolt] Fix issue 110407 (Support CREL)

This commit fixes issue #110407 in Bolt subproject:
BOLT programs not support CREL-type relocations.
---
 bolt/lib/Rewrite/RewriteInstance.cpp | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index 76e1f0156f828d..f1ef97888a26ce 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -1938,8 +1938,11 @@ Error RewriteInstance::readSpecialSections() {
                   "Use -update-debug-sections to keep it.\n";
   }
 
-  HasTextRelocations = (bool)BC->getUniqueSectionByName(
-      ".rela" + std::string(BC->getMainCodeSectionName()));
+  const char *code_sec = BC->getMainCodeSectionName();
+  HasTextRelocations = !!BC->getUniqueSectionByName(std::string{".rela"} + code_sec);
+  if (!HasTextRelocations)
+    HasTextRelocations = !!BC->getUniqueSectionByName(std::string{".crel"} + code_sec);
+
   HasSymbolTable = (bool)BC->getUniqueSectionByName(".symtab");
   EHFrameSection = BC->getUniqueSectionByName(".eh_frame");
 
@@ -2127,6 +2130,11 @@ int64_t getRelocationAddend(const ELFObjectFile<ELFT> *Obj,
     llvm_unreachable("unexpected relocation section type");
   case ELF::SHT_REL:
     break;
+  case ELF::SHT_CREL: {
+    auto ERela = Obj->getCrel(Rel);
+    Addend = ERela.r_addend;
+    break; 
+  }
   case ELF::SHT_RELA: {
     const Elf_Rela *RelA = Obj->getRela(Rel);
     Addend = RelA->r_addend;



More information about the llvm-commits mailing list