aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-objdump/llvm-objdump.cpp
diff options
context:
space:
mode:
authorRonak Chauhan <ronaknilesh.chauhan@amd.com>2020-06-12 14:00:33 -0400
committerScott Linder <Scott.Linder@amd.com>2020-06-12 15:51:37 -0400
commit480a16d5c8092f4eac181fb669c7ac05dc446a00 (patch)
treef1c78cc8141d1319bfe465567a7188d0d86aa2ba /llvm/tools/llvm-objdump/llvm-objdump.cpp
parent339177d1da0c6f0cf181ba987836148acb526926 (diff)
downloadllvm-480a16d5c8092f4eac181fb669c7ac05dc446a00.zip
llvm-480a16d5c8092f4eac181fb669c7ac05dc446a00.tar.gz
llvm-480a16d5c8092f4eac181fb669c7ac05dc446a00.tar.bz2
[MC] Changes to help improve target specific symbol disassembly
Summary: This commit slightly modifies the MCDisassembler, and llvm-objdump to allow targets to also decode entire symbols. WebAssembly uses the onSymbolStart hook it to decode preludes. WebAssembly partially disassembles the symbol in its target specific way; and then falls back to the normal flow of llvm-objdump. AMDGPU needs it to decode kernel descriptors entirely, and move to the next symbol. This commit is to split the above task into 2. - Changes to llvm-objdump and MC-layer without breaking WebAssembly code [ this commit ] - AMDGPU's implementation of onSymbolStart that decodes kernel descriptors. [ https://reviews.llvm.org/D80713 ] Reviewers: scott.linder, t-tye, sunfish, arsenm, jhenderson, MaskRay, aardappel Reviewed By: scott.linder, jhenderson, aardappel Subscribers: bcain, dschuff, wdng, tpr, sbc100, jgravelle-google, hiraditya, aheejin, MaskRay, rupprecht, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D80512
Diffstat (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp')
-rw-r--r--llvm/tools/llvm-objdump/llvm-objdump.cpp35
1 files changed, 31 insertions, 4 deletions
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index d130e5c..c27e487 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -1429,10 +1429,37 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj,
continue;
}
- // Some targets (like WebAssembly) have a special prelude at the start
- // of each symbol.
- DisAsm->onSymbolStart(SymbolName, Size, Bytes.slice(Start, End - Start),
- SectionAddr + Start, CommentStream);
+ auto Status = DisAsm->onSymbolStart(SymbolName, Size,
+ Bytes.slice(Start, End - Start),
+ SectionAddr + Start, CommentStream);
+ // To have round trippable disassembly, we fall back to decoding the
+ // remaining bytes as instructions.
+ //
+ // If there is a failure, we disassemble the failed region as bytes before
+ // falling back. The target is expected to print nothing in this case.
+ //
+ // If there is Success or SoftFail i.e no 'real' failure, we go ahead by
+ // Size bytes before falling back.
+ // So if the entire symbol is 'eaten' by the target:
+ // Start += Size // Now Start = End and we will never decode as
+ // // instructions
+ //
+ // Right now, most targets return None i.e ignore to treat a symbol
+ // separately. But WebAssembly decodes preludes for some symbols.
+ //
+ if (Status.hasValue()) {
+ if (Status.getValue() == MCDisassembler::Fail) {
+ outs() << "// Error in decoding " << SymbolName
+ << " : 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";
+ }
+ }
+ } else {
+ Size = 0;
+ }
+
Start += Size;
Index = Start;