[llvm] [BOLT][runtime] Add start & fini symbols (PR #68505)
Vladislav Khmelevsky via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 7 23:00:46 PDT 2023
https://github.com/yota9 created https://github.com/llvm/llvm-project/pull/68505
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.
>From 972a94ae205d6d6caf87f727ab1829f8dacb7cab 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..daccef1678d26de 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_runtime_start", RtLibrary->getRuntimeStartAddress());
+ AddSymbol("__bolt_runtime_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