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

Job Noorman via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 9 02:47:38 PDT 2023


================
@@ -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());
----------------
mtvec wrote:

Shouldn't we call these `__bolt_instr_start`/`__bolt_instr_fini` for consistency with `instr.cpp`?

I guess that ideally, we should just copy the whole symbol table from `instr.cpp` (then we wouldn't need to duplicate symbol names and this would also make debugging a bit easier) but this would need some rework of the linker.

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


More information about the llvm-commits mailing list