-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[DirectX] Add ObjectFile boilerplate for objdump #151434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |||||
| #include "llvm/ADT/Twine.h" | ||||||
| #include "llvm/BinaryFormat/DXContainer.h" | ||||||
| #include "llvm/Object/Error.h" | ||||||
| #include "llvm/Object/ObjectFile.h" | ||||||
| #include "llvm/Support/Compiler.h" | ||||||
| #include "llvm/Support/Endian.h" | ||||||
| #include "llvm/Support/Error.h" | ||||||
|
|
@@ -499,6 +500,7 @@ class DXContainer { | |||||
| } IteratorState; | ||||||
|
|
||||||
| friend class DXContainer; | ||||||
| friend class DXContainerObjectFile; | ||||||
|
|
||||||
| PartIterator(const DXContainer &C, | ||||||
| SmallVectorImpl<uint32_t>::const_iterator It) | ||||||
|
|
@@ -584,6 +586,85 @@ class DXContainer { | |||||
| } | ||||||
| }; | ||||||
|
|
||||||
| class DXContainerObjectFile : public ObjectFile { | ||||||
| private: | ||||||
| friend class ObjectFile; | ||||||
| DXContainer Container; | ||||||
|
|
||||||
| using PartData = DXContainer::PartIterator::PartData; | ||||||
| llvm::SmallVector<PartData> Parts; | ||||||
| using PartIterator = llvm::SmallVector<PartData>::iterator; | ||||||
|
|
||||||
| DXContainerObjectFile(DXContainer C) | ||||||
| : ObjectFile(ID_DXContainer, MemoryBufferRef(C.getData(), "")), | ||||||
| Container(C) { | ||||||
| for (auto &P : C) | ||||||
| Parts.push_back(P); | ||||||
| } | ||||||
|
|
||||||
| public: | ||||||
| static bool classof(const Binary *v) { return v->isDXContainer(); } | ||||||
|
|
||||||
| Expected<StringRef> getSymbolName(DataRefImpl) const override { return ""; } | ||||||
| Expected<uint64_t> getSymbolAddress(DataRefImpl Symb) const override; | ||||||
| uint64_t getSymbolValueImpl(DataRefImpl Symb) const override { return 0; } | ||||||
| uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override { | ||||||
| return 0; | ||||||
| } | ||||||
|
||||||
| Expected<SymbolRef::Type> getSymbolType(DataRefImpl Symb) const override { | ||||||
| return SymbolRef::Type::ST_Unknown; | ||||||
| } | ||||||
|
||||||
|
|
||||||
| Expected<section_iterator> getSymbolSection(DataRefImpl Symb) const override; | ||||||
| void moveSectionNext(DataRefImpl &Sec) const override; | ||||||
| Expected<StringRef> getSectionName(DataRefImpl Sec) const override; | ||||||
| uint64_t getSectionAddress(DataRefImpl Sec) const override; | ||||||
| uint64_t getSectionIndex(DataRefImpl Sec) const override; | ||||||
| uint64_t getSectionSize(DataRefImpl Sec) const override; | ||||||
| Expected<ArrayRef<uint8_t>> | ||||||
| getSectionContents(DataRefImpl Sec) const override; | ||||||
|
|
||||||
| uint64_t getSectionAlignment(DataRefImpl Sec) const override; | ||||||
| bool isSectionCompressed(DataRefImpl Sec) const override; | ||||||
| bool isSectionText(DataRefImpl Sec) const override; | ||||||
| bool isSectionData(DataRefImpl Sec) const override; | ||||||
| bool isSectionBSS(DataRefImpl Sec) const override; | ||||||
| bool isSectionVirtual(DataRefImpl Sec) const override; | ||||||
|
|
||||||
| relocation_iterator section_rel_begin(DataRefImpl Sec) const override; | ||||||
| relocation_iterator section_rel_end(DataRefImpl Sec) const override; | ||||||
|
|
||||||
| void moveRelocationNext(DataRefImpl &Rel) const override; | ||||||
| uint64_t getRelocationOffset(DataRefImpl Rel) const override; | ||||||
| symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override; | ||||||
| uint64_t getRelocationType(DataRefImpl Rel) const override; | ||||||
| void getRelocationTypeName(DataRefImpl Rel, | ||||||
| SmallVectorImpl<char> &Result) const override; | ||||||
|
|
||||||
| section_iterator section_begin() const override; | ||||||
| section_iterator section_end() const override; | ||||||
|
|
||||||
| uint8_t getBytesInAddress() const override; | ||||||
| StringRef getFileFormatName() const override; | ||||||
| Triple::ArchType getArch() const override; | ||||||
| Expected<SubtargetFeatures> getFeatures() const override; | ||||||
|
|
||||||
| void moveSymbolNext(DataRefImpl &Symb) const override {} | ||||||
| Error printSymbolName(raw_ostream &OS, DataRefImpl Symb) const override; | ||||||
| Expected<uint32_t> getSymbolFlags(DataRefImpl Symb) const override { | ||||||
| return 0; | ||||||
| } | ||||||
| basic_symbol_iterator symbol_begin() const override { | ||||||
| return basic_symbol_iterator(SymbolRef()); | ||||||
| } | ||||||
| basic_symbol_iterator symbol_end() const override { | ||||||
| return basic_symbol_iterator(SymbolRef()); | ||||||
| } | ||||||
| bool is64Bit() const override { return 0; } | ||||||
|
||||||
| bool is64Bit() const override { return 0; } | |
| bool is64Bit() const override { return false; } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
| #include "llvm/Object/Error.h" | ||
| #include "llvm/Support/Endian.h" | ||
| #include "llvm/Support/FormatVariadic.h" | ||
| #include "llvm/TargetParser/SubtargetFeature.h" | ||
|
|
||
| using namespace llvm; | ||
| using namespace llvm::object; | ||
|
|
@@ -515,3 +516,157 @@ uint8_t DirectX::PSVRuntimeInfo::getSigPatchOrPrimCount() const { | |
| return P->SigPatchOrPrimElements; | ||
| return 0; | ||
| } | ||
|
|
||
| class DXNotSupportedError : public ErrorInfo<DXNotSupportedError> { | ||
| public: | ||
| static char ID; | ||
|
|
||
| DXNotSupportedError(StringRef S) : FeatureString(S) {} | ||
|
|
||
| void log(raw_ostream &OS) const override { | ||
| OS << "DXContainer does not support " << FeatureString; | ||
| } | ||
|
|
||
| std::error_code convertToErrorCode() const override { | ||
| return inconvertibleErrorCode(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's an |
||
| } | ||
|
|
||
| private: | ||
| StringRef FeatureString; | ||
| }; | ||
|
|
||
| char DXNotSupportedError::ID = 0; | ||
|
|
||
| Expected<section_iterator> | ||
| DXContainerObjectFile::getSymbolSection(DataRefImpl Symb) const { | ||
| return make_error<DXNotSupportedError>("Symbol sections"); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These should all be lower-case 's' for "Symbol". |
||
| } | ||
|
|
||
| Expected<uint64_t> | ||
| DXContainerObjectFile::getSymbolAddress(DataRefImpl Symb) const { | ||
| return make_error<DXNotSupportedError>("Symbol addresses"); | ||
| } | ||
|
|
||
| void DXContainerObjectFile::moveSectionNext(DataRefImpl &Sec) const { | ||
| PartIterator It = reinterpret_cast<PartIterator>(Sec.p); | ||
| if (It == Parts.end()) | ||
| return; | ||
|
|
||
| It++; | ||
llvm-beanz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Sec.p = reinterpret_cast<uintptr_t>(It); | ||
| } | ||
|
|
||
| Expected<StringRef> | ||
| DXContainerObjectFile::getSectionName(DataRefImpl Sec) const { | ||
| PartIterator It = reinterpret_cast<PartIterator>(Sec.p); | ||
| return StringRef(It->Part.getName()); | ||
| } | ||
|
|
||
| uint64_t DXContainerObjectFile::getSectionAddress(DataRefImpl Sec) const { | ||
| PartIterator It = reinterpret_cast<PartIterator>(Sec.p); | ||
| return It->Offset; | ||
| } | ||
|
|
||
| uint64_t DXContainerObjectFile::getSectionIndex(DataRefImpl Sec) const { | ||
| return (Sec.p - reinterpret_cast<uintptr_t>(Parts.begin())) / | ||
| sizeof(PartIterator); | ||
| } | ||
|
|
||
| uint64_t DXContainerObjectFile::getSectionSize(DataRefImpl Sec) const { | ||
| PartIterator It = reinterpret_cast<PartIterator>(Sec.p); | ||
| return It->Data.size(); | ||
| } | ||
| Expected<ArrayRef<uint8_t>> | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: blank line between functions. |
||
| DXContainerObjectFile::getSectionContents(DataRefImpl Sec) const { | ||
| PartIterator It = reinterpret_cast<PartIterator>(Sec.p); | ||
| return ArrayRef<uint8_t>(It->Data.bytes_begin(), It->Data.size()); | ||
| } | ||
|
|
||
| uint64_t DXContainerObjectFile::getSectionAlignment(DataRefImpl Sec) const { | ||
| return 1; | ||
| } | ||
|
|
||
| bool DXContainerObjectFile::isSectionCompressed(DataRefImpl Sec) const { | ||
| return false; | ||
| } | ||
|
|
||
| bool DXContainerObjectFile::isSectionText(DataRefImpl Sec) const { | ||
| return false; | ||
| } | ||
|
|
||
| bool DXContainerObjectFile::isSectionData(DataRefImpl Sec) const { | ||
| return false; | ||
| } | ||
|
Comment on lines
+610
to
+616
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't actually see where these APIs are used, but arguably the DXIL section could be text and the other sections data I think.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really wasn't sure what to do about DXIL. I'm not sure if it should be Text or Bitcode (both are potentially reasonable). My gut is actually bitcode so we can create an IRObject from it to disassemble, but I'd like to defer that. I suppose we could make everything else data sections. It isn't really what they traditionally mean by data because it isn't constant data referred to by the program. These are mostly used during symbol dumping to denote what type of section a symbol points into. Are you okay pushing off any work on this into subsequent changes when we can figure out how to handle other features? Alternatively I could just make |
||
|
|
||
| bool DXContainerObjectFile::isSectionBSS(DataRefImpl Sec) const { | ||
| return false; | ||
| } | ||
|
|
||
| bool DXContainerObjectFile::isSectionVirtual(DataRefImpl Sec) const { | ||
| return false; | ||
| } | ||
|
|
||
| relocation_iterator | ||
| DXContainerObjectFile::section_rel_begin(DataRefImpl Sec) const { | ||
| return relocation_iterator(RelocationRef()); | ||
| } | ||
|
|
||
| relocation_iterator | ||
| DXContainerObjectFile::section_rel_end(DataRefImpl Sec) const { | ||
| return relocation_iterator(RelocationRef()); | ||
| } | ||
|
|
||
| void DXContainerObjectFile::moveRelocationNext(DataRefImpl &Rel) const {} | ||
|
|
||
| uint64_t DXContainerObjectFile::getRelocationOffset(DataRefImpl Rel) const { | ||
| return 0; | ||
| } | ||
|
||
|
|
||
| symbol_iterator | ||
| DXContainerObjectFile::getRelocationSymbol(DataRefImpl Rel) const { | ||
| return symbol_iterator(SymbolRef()); | ||
| } | ||
|
|
||
| uint64_t DXContainerObjectFile::getRelocationType(DataRefImpl Rel) const { | ||
| return 0; | ||
| } | ||
|
|
||
| void DXContainerObjectFile::getRelocationTypeName( | ||
| DataRefImpl Rel, SmallVectorImpl<char> &Result) const {} | ||
|
|
||
| section_iterator DXContainerObjectFile::section_begin() const { | ||
| DataRefImpl Sec; | ||
| Sec.p = reinterpret_cast<uintptr_t>(Parts.begin()); | ||
| return section_iterator(SectionRef(Sec, this)); | ||
| } | ||
| section_iterator DXContainerObjectFile::section_end() const { | ||
| DataRefImpl Sec; | ||
| Sec.p = reinterpret_cast<uintptr_t>(Parts.end()); | ||
| return section_iterator(SectionRef(Sec, this)); | ||
| } | ||
|
|
||
| uint8_t DXContainerObjectFile::getBytesInAddress() const { return 4; } | ||
|
|
||
| StringRef DXContainerObjectFile::getFileFormatName() const { | ||
| return "DirectX Container"; | ||
| } | ||
|
|
||
| Triple::ArchType DXContainerObjectFile::getArch() const { return Triple::dxil; } | ||
|
|
||
| Expected<SubtargetFeatures> DXContainerObjectFile::getFeatures() const { | ||
| return SubtargetFeatures(); | ||
| } | ||
|
|
||
| Error DXContainerObjectFile::printSymbolName(raw_ostream &OS, | ||
| DataRefImpl Symb) const { | ||
| return make_error<DXNotSupportedError>("Symbol names"); | ||
| } | ||
|
|
||
| Expected<std::unique_ptr<DXContainerObjectFile>> | ||
| ObjectFile::createDXContainerObjectFile(MemoryBufferRef Object) { | ||
| auto ExC = DXContainer::create(Object); | ||
| if (!ExC) | ||
| return ExC.takeError(); | ||
| std::unique_ptr<DXContainerObjectFile> Obj(new DXContainerObjectFile(*ExC)); | ||
| return std::move(Obj); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const &surely? Also, it's far from obvious what the type ofPis from this immediate code, soautois inappropriate, in my mind.