[llvm] [BOLT][runtime] Add start & fini symbols (PR #68505)

Vladislav Khmelevsky via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 9 02:57:41 PDT 2023


https://github.com/yota9 updated https://github.com/llvm/llvm-project/pull/68505

>From 72d45145b338dffe1eb3f95086ff2e723d71b700 Mon Sep 17 00:00:00 2001
From: Vladislav Khmelevsky <och95 at yandex.ru>
Date: Sun, 8 Oct 2023 09:57:38 +0400
Subject: [PATCH] [BOLT][runtime] Add start & fini symbols

Add absent start & fini symbols, currently setted by bolt for runtime
libraries at DT_INIT and DT_FINI. The proper tests would be added by the
https://github.com/llvm/llvm-project/pull/67348 PR.
---
 bolt/lib/Rewrite/RewriteInstance.cpp | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index 03cbe0461b21127..41302fd5d98dbc3 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -4568,6 +4568,26 @@ void RewriteInstance::updateELFSymbolTable(
     }
   }
 
+  // Add runtime library start and fini address symbols
+  if (RuntimeLibrary *RtLibrary = BC->getRuntimeLibrary()) {
+    auto AddSymbol = [&](StringRef Name, uint64_t Address) {
+      if (!Address)
+        return;
+
+      ELFSymTy NewSymbol;
+      NewSymbol.st_shndx = ELF::SHN_ABS;
+      NewSymbol.st_value = Address;
+      NewSymbol.st_name = AddToStrTab(Name);
+      NewSymbol.st_size = 0;
+      NewSymbol.st_other = 0;
+      NewSymbol.setBindingAndType(ELF::STB_LOCAL, ELF::STT_NOTYPE);
+      Symbols.emplace_back(NewSymbol);
+    };
+
+    AddSymbol("__bolt_instr_start", RtLibrary->getRuntimeStartAddress());
+    AddSymbol("__bolt_instr_fini", RtLibrary->getRuntimeFiniAddress());
+  }
+
   assert((!NumHotTextSymsUpdated || NumHotTextSymsUpdated == 2) &&
          "either none or both __hot_start/__hot_end symbols were expected");
   assert((!NumHotDataSymsUpdated || NumHotDataSymsUpdated == 2) &&



More information about the llvm-commits mailing list