[llvm] Reland "[llvm-readobj] Dump callgraph section info for ELF" (PR #176260)
James Henderson via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 16 03:04:40 PST 2026
================
@@ -8154,6 +8302,110 @@ template <class ELFT> void LLVMELFDumper<ELFT>::printCGProfile() {
}
}
+template <class ELFT> void LLVMELFDumper<ELFT>::printCallGraphInfo() {
+ // Call graph section is of type SHT_LLVM_CALL_GRAPH. Typically named
+ // ".llvm.callgraph". First fetch the section by its type.
+ using Elf_Shdr = typename ELFT::Shdr;
+ Expected<MapVector<const Elf_Shdr *, const Elf_Shdr *>> MapOrErr =
+ this->Obj.getSectionAndRelocations([](const Elf_Shdr &Sec) {
+ return Sec.sh_type == ELF::SHT_LLVM_CALL_GRAPH;
+ });
+ if (!MapOrErr || MapOrErr->empty()) {
+ reportWarning(createError("no SHT_LLVM_CALL_GRAPH section found: " +
+ toString(MapOrErr.takeError())),
+ this->FileName);
+ return;
+ }
+ // Process and print the first SHT_LLVM_CALL_GRAPH type section found.
+ if (!this->processCallGraphSection(MapOrErr->begin()->first) ||
+ this->FuncCGInfos.empty())
+ return;
+
+ std::vector<Relocation<ELFT>> Relocations;
+ const Elf_Shdr *RelocSymTab = nullptr;
+ if (this->Obj.getHeader().e_type == ELF::ET_REL) {
+ const Elf_Shdr *CGRelSection = MapOrErr->front().second;
+ if (CGRelSection) {
+ RelocSymTab = unwrapOrError(this->FileName,
----------------
jh7370 wrote:
As I believe I mentioned before, `unwrapOrError` should be considered deprecated in the context of new code in llvm-readobj. The preferred approach is to report a warning and bail out of the function (or loop) or produce placeholder values, depending on the context. For example, here you could produce the warning and then treat it as if there are no relocations for the section (perhaps with something indicating that no warnings about missing relocations should be emitted in that case).
https://github.com/llvm/llvm-project/pull/176260
More information about the llvm-commits
mailing list