diff options
author | George Rimar <grimar@accesssoftek.com> | 2019-01-10 14:55:26 +0000 |
---|---|---|
committer | George Rimar <grimar@accesssoftek.com> | 2019-01-10 14:55:26 +0000 |
commit | 70d197d466d17ff540cf1218f6d958bc31d1be0c (patch) | |
tree | 22c2838969272649f25ec8dea0c7c888549ce4c4 /llvm/tools/llvm-objdump/llvm-objdump.cpp | |
parent | 8c221b3f76ea833a92e521c641a7322a7417c02a (diff) | |
download | bcm5719-llvm-70d197d466d17ff540cf1218f6d958bc31d1be0c.tar.gz bcm5719-llvm-70d197d466d17ff540cf1218f6d958bc31d1be0c.zip |
[llvm-objdump] - Implement -z/--disassemble-zeroes.
This is https://bugs.llvm.org/show_bug.cgi?id=37151,
GNU objdump spec says that "Normally the disassembly output will skip blocks of zeroes.",
but currently, llvm-objdump prints them.
The patch implements the -z/--disassemble-zeroes option and switches the default to always
skip blocks of zeroes.
Differential revision: https://reviews.llvm.org/D56083
llvm-svn: 350823
Diffstat (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp')
-rw-r--r-- | llvm/tools/llvm-objdump/llvm-objdump.cpp | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index 22fd1eb7dc2..21359a702c6 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -265,8 +265,17 @@ cl::opt<unsigned long long> StartAddress("start-address", cl::desc("Disassemble beginning at address"), cl::value_desc("address"), cl::init(0)); cl::opt<unsigned long long> - StopAddress("stop-address", cl::desc("Stop disassembly at address"), + StopAddress("stop-address", + cl::desc("Do not skip blocks of zeroes when disassembling"), cl::value_desc("address"), cl::init(UINT64_MAX)); + +cl::opt<bool> DisassembleZeroes("disassemble-zeroes", + cl::desc("Do not skip blocks of zeroes when " + "disassembling the blocks of zeroes")); +cl::alias DisassembleZeroesShort("z", + cl::desc("Alias for --disassemble-zeroes"), + cl::aliasopt(DisassembleZeroes)); + static StringRef ToolName; typedef std::vector<std::tuple<uint64_t, StringRef, uint8_t>> SectionSymbolsTy; @@ -1298,6 +1307,29 @@ static void addPltEntries(const ObjectFile *Obj, } } +// Normally the disassembly output will skip blocks of zeroes. This function +// returns the number of zero bytes that can be skipped when dumping the +// disassembly of the instructions in Buf. +static size_t countSkippableZeroBytes(ArrayRef<uint8_t> Buf) { + // When -z or --disassemble-zeroes are given we always dissasemble them. + if (DisassembleZeroes) + return 0; + + // Find the number of leading zeroes. + size_t N = 0; + while (N < Buf.size() && !Buf[N]) + ++N; + + // We may want to skip blocks of zero bytes, but unless we see + // at least 8 of them in a row. + if (N < 8) + return 0; + + // We skip zeroes in multiples of 4 because do not want to truncate an + // instruction if it starts with a zero byte. + return N & ~0x3; +} + static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) { if (StartAddress > StopAddress) error("Start address should be less than stop address"); @@ -1732,6 +1764,14 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) { if (Index >= End) break; + if (size_t N = + countSkippableZeroBytes(Bytes.slice(Index, End - Index))) { + outs() << "\t\t..." << '\n'; + Index += N; + if (Index >= End) + break; + } + // Disassemble a real instruction or a data when disassemble all is // provided bool Disassembled = DisAsm->getInstruction(Inst, Size, Bytes.slice(Index), |