[llvm] [llvm-readobj] Dump callgraph section info for ELF (PR #157499)
James Henderson via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 19 02:27:33 PST 2025
================
@@ -5263,6 +5297,185 @@ template <class ELFT> void GNUELFDumper<ELFT>::printCGProfile() {
OS << "GNUStyle::printCGProfile not implemented\n";
}
+template <class ELFT>
+static std::optional<object::SectionRef>
+getCallGraphSection(const object::ELFObjectFile<ELFT> &ObjF) {
+ // Get the .llvm.callgraph section.
+ StringRef CallGraphSectionName(".llvm.callgraph");
+ for (auto Sec : ObjF.sections()) {
+ if (Expected<StringRef> NameOrErr = Sec.getName()) {
+ StringRef Name = *NameOrErr;
+ if (Name == CallGraphSectionName)
+ return Sec;
+ } else
+ consumeError(NameOrErr.takeError());
+ }
+ return std::nullopt;
+}
+
+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)
+ reportError(createError("No .llvm.callgraph section found."),
+ "Missing section");
----------------
jh7370 wrote:
https://llvm.org/docs/CodingStandards.html#error-and-warning-messages
Same applies to other error/warning messages.
That being said, we don't tend to emit an error for other options that do similar things, if the respective section doesn't exist.
When a diagnostic message is appropriate, we usually prefer warnings, rather than errors, so that we can continue dumping other requested items, or we emit a warning then try to dump the information we can for the requested section and use placeholder values (e.g. "<?>").
https://github.com/llvm/llvm-project/pull/157499
More information about the llvm-commits
mailing list