[PATCH] D86542: [llvm/Object] - Make dyn_cast<XCOFFObjectFile> work as it should.
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 25 07:55:29 PDT 2020
grimar created this revision.
grimar added reviewers: jhenderson, MaskRay.
Herald added subscribers: rupprecht, sunfish.
Herald added a project: LLVM.
grimar requested review of this revision.
Herald added a subscriber: aheejin.
Currently, `dyn_cast<XCOFFObjectFile>` always does cast and returns a pointer,
even when we pass `ELF`/`Wasm`/`Mach-O` or `COFF` instead of `XCOFF`.
It happens because `XCOFFObjectFile` class does not implement `classof`.
In this patch I've reordered dyn_cast's in `llvm-objdump` code to
group `COFF` and `XCOFF` together, what allows to trigger the issue.
https://reviews.llvm.org/D86542
Files:
llvm/include/llvm/Object/XCOFFObjectFile.h
llvm/tools/llvm-objdump/llvm-objdump.cpp
Index: llvm/tools/llvm-objdump/llvm-objdump.cpp
===================================================================
--- llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -537,12 +537,12 @@
return getELFRelocationValueString(ELF, Rel, Result);
if (auto *COFF = dyn_cast<COFFObjectFile>(Obj))
return getCOFFRelocationValueString(COFF, Rel, Result);
+ if (auto *XCOFF = dyn_cast<XCOFFObjectFile>(Obj))
+ return getXCOFFRelocationValueString(XCOFF, Rel, Result);
if (auto *Wasm = dyn_cast<WasmObjectFile>(Obj))
return getWasmRelocationValueString(Wasm, Rel, Result);
if (auto *MachO = dyn_cast<MachOObjectFile>(Obj))
return getMachORelocationValueString(MachO, Rel, Result);
- if (auto *XCOFF = dyn_cast<XCOFFObjectFile>(Obj))
- return getXCOFFRelocationValueString(XCOFF, Rel, Result);
llvm_unreachable("unknown object file format");
}
Index: llvm/include/llvm/Object/XCOFFObjectFile.h
===================================================================
--- llvm/include/llvm/Object/XCOFFObjectFile.h
+++ llvm/include/llvm/Object/XCOFFObjectFile.h
@@ -372,6 +372,8 @@
Expected<ArrayRef<XCOFFRelocation32>>
relocations(const XCOFFSectionHeader32 &) const;
+
+ static bool classof(const Binary *B) { return B->isXCOFF(); }
}; // XCOFFObjectFile
class XCOFFSymbolRef {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86542.287667.patch
Type: text/x-patch
Size: 1358 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200825/aa74318b/attachment.bin>
More information about the llvm-commits
mailing list