[llvm] [llvm-readobj] Dump callgraph section info for ELF (PR #157499)
Paul Kirth via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 21 10:45:33 PST 2025
================
@@ -5263,6 +5299,181 @@ template <class ELFT> void GNUELFDumper<ELFT>::printCGProfile() {
OS << "GNUStyle::printCGProfile not implemented\n";
}
+namespace callgraph {
+LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
+enum Flags : uint8_t {
+ None = 0,
+ IsIndirectTarget = 1u << 0,
+ HasDirectCallees = 1u << 1,
+ HasIndirectCallees = 1u << 2,
+ LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue*/ HasIndirectCallees)
+};
+} // namespace callgraph
+
+template <class ELFT> bool ELFDumper<ELFT>::processCallGraphSection() {
+ const Elf_Shdr *CGSection = findSectionByName(".llvm.callgraph");
+ if (!CGSection) {
+ reportWarning(createError("No .llvm.callgraph section found."),
+ "missing section");
+ return false;
+ }
+
+ Expected<ArrayRef<uint8_t>> SectionBytesOrErr =
+ Obj.getSectionContents(*CGSection);
+ if (!SectionBytesOrErr) {
+ reportError(SectionBytesOrErr.takeError(),
+ "unable to read the .llvm.callgraph section");
+ }
+
+ auto PrintMalformedError = [&](Error &E, Twine FuncPC, StringRef Component) {
+ reportError(std::move(E),
+ Twine("while reading call graph info's [" + Component +
+ "] for function at [0x" + FuncPC + "]")
+ .str());
+ };
+
+ DataExtractor Data(SectionBytesOrErr.get(), Obj.isLE(),
+ ObjF.getBytesInAddress());
+
+ uint64_t UnknownCount = 0;
+ uint64_t Offset = 0;
+ while (Offset < CGSection->sh_size) {
+ Error CGSectionErr = Error::success();
+ uint8_t FormatVersionNumber = Data.getU8(&Offset, &CGSectionErr);
+ if (CGSectionErr) {
+ reportWarning(std::move(CGSectionErr),
+ "while reading call graph info FormatVersionNumber");
+ return false;
+ }
+ if (FormatVersionNumber != 0) {
+ reportError(createError("Unknown format version value [" +
+ std::to_string(FormatVersionNumber) +
+ "] in .llvm.callgraph section."),
+ "unknown value");
----------------
ilovepi wrote:
```suggestion
FileStr);
```
https://github.com/llvm/llvm-project/pull/157499
More information about the llvm-commits
mailing list