[llvm] [NFC][llvm-objdump] Add quiet disassembly (PR #139931)
via llvm-commits
llvm-commits at lists.llvm.org
Wed May 14 09:51:15 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-binary-utilities
Author: Prabhu Rajasekaran (Prabhuk)
<details>
<summary>Changes</summary>
Add a boolean to control whether object disassembly
(disassembleObject()) prints to console. It is always set to `false`
which makes this change an NFC.
This is introduced to support the upcoming `--call-graph-info` option
which will utilize the `disassembleObject` function to collect function
and call site addresses.
---
Full diff: https://github.com/llvm/llvm-project/pull/139931.diff
1 Files Affected:
- (modified) llvm/tools/llvm-objdump/llvm-objdump.cpp (+28-22)
``````````diff
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 2f839199712eb..0e1be02f52e60 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -349,6 +349,7 @@ bool objdump::UnwindInfo;
static bool Wide;
std::string objdump::Prefix;
uint32_t objdump::PrefixStrip;
+static bool QuietDisasm = false;
DebugVarsFormat objdump::DbgVariables = DVDisabled;
@@ -1374,6 +1375,8 @@ static uint64_t dumpARMELFData(uint64_t SectionAddr, uint64_t Index,
return 1;
}
+static raw_ostream &disasmOuts() { return QuietDisasm ? nulls() : outs(); }
+
static void dumpELFData(uint64_t SectionAddr, uint64_t Index, uint64_t End,
ArrayRef<uint8_t> Bytes) {
// print out data up to 8 bytes at a time in hex and ascii
@@ -1383,9 +1386,9 @@ static void dumpELFData(uint64_t SectionAddr, uint64_t Index, uint64_t End,
for (; Index < End; ++Index) {
if (NumBytes == 0)
- outs() << format("%8" PRIx64 ":", SectionAddr + Index);
+ disasmOuts() << format("%8" PRIx64 ":", SectionAddr + Index);
Byte = Bytes.slice(Index)[0];
- outs() << format(" %02x", Byte);
+ disasmOuts() << format(" %02x", Byte);
AsciiData[NumBytes] = isPrint(Byte) ? Byte : '.';
uint8_t IndentOffset = 0;
@@ -1400,9 +1403,9 @@ static void dumpELFData(uint64_t SectionAddr, uint64_t Index, uint64_t End,
}
if (NumBytes == 8) {
AsciiData[8] = '\0';
- outs() << std::string(IndentOffset, ' ') << " ";
- outs() << reinterpret_cast<char *>(AsciiData);
- outs() << '\n';
+ disasmOuts() << std::string(IndentOffset, ' ') << " ";
+ disasmOuts() << reinterpret_cast<char *>(AsciiData);
+ disasmOuts() << '\n';
NumBytes = 0;
}
}
@@ -2089,10 +2092,10 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
if (!PrintedSection) {
PrintedSection = true;
- outs() << "\nDisassembly of section ";
+ disasmOuts() << "\nDisassembly of section ";
if (!SegmentName.empty())
- outs() << SegmentName << ",";
- outs() << SectionName << ":\n";
+ disasmOuts() << SegmentName << ",";
+ disasmOuts() << SectionName << ":\n";
}
bool PrintedLabel = false;
@@ -2104,22 +2107,24 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
const StringRef SymbolName = SymNamesHere[i];
if (!PrintedLabel) {
- outs() << '\n';
+ disasmOuts() << '\n';
PrintedLabel = true;
}
if (LeadingAddr)
- outs() << format(Is64Bits ? "%016" PRIx64 " " : "%08" PRIx64 " ",
- SectionAddr + Start + VMAAdjustment);
+ disasmOuts() << format(Is64Bits ? "%016" PRIx64 " "
+ : "%08" PRIx64 " ",
+ SectionAddr + Start + VMAAdjustment);
if (Obj.isXCOFF() && SymbolDescription) {
- outs() << getXCOFFSymbolDescription(Symbol, SymbolName) << ":\n";
+ disasmOuts() << getXCOFFSymbolDescription(Symbol, SymbolName)
+ << ":\n";
} else
- outs() << '<' << SymbolName << ">:\n";
+ disasmOuts() << '<' << SymbolName << ">:\n";
}
// Don't print raw contents of a virtual section. A virtual section
// doesn't have any contents in the file.
if (Section.isVirtual()) {
- outs() << "...\n";
+ disasmOuts() << "...\n";
continue;
}
@@ -2156,17 +2161,17 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
do {
StringRef Line;
std::tie(Line, ErrMsg) = ErrMsg.split('\n');
- outs() << DT->Context->getAsmInfo()->getCommentString()
- << " error decoding " << SymNamesHere[SHI] << ": " << Line
- << '\n';
+ disasmOuts() << DT->Context->getAsmInfo()->getCommentString()
+ << " error decoding " << SymNamesHere[SHI] << ": "
+ << Line << '\n';
} while (!ErrMsg.empty());
if (Size) {
- outs() << DT->Context->getAsmInfo()->getCommentString()
- << " decoding failed region as bytes\n";
+ disasmOuts() << DT->Context->getAsmInfo()->getCommentString()
+ << " decoding failed region as bytes\n";
for (uint64_t I = 0; I < Size; ++I)
- outs() << "\t.byte\t " << format_hex(Bytes[I], 1, /*Upper=*/true)
- << '\n';
+ disasmOuts() << "\t.byte\t "
+ << format_hex(Bytes[I], 1, /*Upper=*/true) << '\n';
}
}
@@ -2203,7 +2208,7 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
Symbols[SI - 1].XCOFFSymInfo.StorageMappingClass &&
(*Symbols[SI - 1].XCOFFSymInfo.StorageMappingClass == XCOFF::XMC_PR);
- formatted_raw_ostream FOS(outs());
+ formatted_raw_ostream FOS(disasmOuts());
std::unordered_map<uint64_t, std::string> AllLabels;
std::unordered_map<uint64_t, std::vector<BBAddrMapLabel>> BBAddrMapLabels;
@@ -2551,6 +2556,7 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
set_difference(DisasmSymbolSet, FoundDisasmSymbolSet);
for (StringRef Sym : MissingDisasmSymbolSet.keys())
reportWarning("failed to disassemble missing symbol " + Sym, FileName);
+ QuietDisasm = false;
}
static void disassembleObject(ObjectFile *Obj, bool InlineRelocs) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/139931
More information about the llvm-commits
mailing list