[llvm-branch-commits] [llvm] [SHT_LLVM_FUNC_MAP][llvm-readobj]Introduce function address map section and emit dynamic instruction count(readobj part) (PR #124333)

James Henderson via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Feb 19 01:14:15 PST 2025


================
@@ -7922,6 +7928,59 @@ void LLVMELFDumper<ELFT>::printBBAddrMaps(bool PrettyPGOAnalysis) {
   }
 }
 
+template <class ELFT> void LLVMELFDumper<ELFT>::printFuncMaps() {
+  bool IsRelocatable = this->Obj.getHeader().e_type == ELF::ET_REL;
+  using Elf_Shdr = typename ELFT::Shdr;
+  auto IsMatch = [](const Elf_Shdr &Sec) -> bool {
+    return Sec.sh_type == ELF::SHT_LLVM_FUNC_MAP;
+  };
+  Expected<MapVector<const Elf_Shdr *, const Elf_Shdr *>> SecRelocMapOrErr =
+      this->Obj.getSectionAndRelocations(IsMatch);
+  if (!SecRelocMapOrErr) {
+    this->reportUniqueWarning("failed to get SHT_LLVM_FUNC_MAP section(s): " +
+                              toString(SecRelocMapOrErr.takeError()));
+    return;
+  }
+
+  for (auto const &[Sec, RelocSec] : *SecRelocMapOrErr) {
+    std::optional<const Elf_Shdr *> FunctionSec;
+    if (IsRelocatable)
+      FunctionSec =
+          unwrapOrError(this->FileName, this->Obj.getSection(Sec->sh_link));
----------------
jh7370 wrote:

Do not use `unwrapOrError` in new code. The dumper should be tolerant of slightly dodgy looking object files, as the dumper is often the only way of finding out what's gone wrong (short of decoding the bytes be hand).

A warning is fine here and you can then either continue as if the relocation section didn't exist or bail out. See my comments elsewhere about the requirement for a relocation section.

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


More information about the llvm-branch-commits mailing list