-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[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 all commits
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 |
---|---|---|
|
@@ -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,183 @@ 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(); | ||
} | ||
|
||
private: | ||
StringRef FeatureString; | ||
}; | ||
|
||
char DXNotSupportedError::ID = 0; | ||
|
||
Expected<section_iterator> | ||
DXContainerObjectFile::getSymbolSection(DataRefImpl Symb) const { | ||
return make_error<DXNotSupportedError>("Symbol sections"); | ||
} | ||
|
||
Expected<StringRef> DXContainerObjectFile::getSymbolName(DataRefImpl) const { | ||
return make_error<DXNotSupportedError>("Symbol names"); | ||
} | ||
|
||
Expected<uint64_t> | ||
DXContainerObjectFile::getSymbolAddress(DataRefImpl Symb) const { | ||
return make_error<DXNotSupportedError>("Symbol addresses"); | ||
} | ||
|
||
uint64_t DXContainerObjectFile::getSymbolValueImpl(DataRefImpl Symb) const { | ||
llvm_unreachable("DXContainer does not support symbols"); | ||
} | ||
uint64_t | ||
DXContainerObjectFile::getCommonSymbolSizeImpl(DataRefImpl Symb) const { | ||
llvm_unreachable("DXContainer does not support symbols"); | ||
} | ||
|
||
Expected<SymbolRef::Type> | ||
DXContainerObjectFile::getSymbolType(DataRefImpl Symb) const { | ||
return make_error<DXNotSupportedError>("Symbol types"); | ||
} | ||
|
||
void DXContainerObjectFile::moveSectionNext(DataRefImpl &Sec) const { | ||
PartIterator It = reinterpret_cast<PartIterator>(Sec.p); | ||
if (It == Parts.end()) | ||
return; | ||
|
||
++It; | ||
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>> | ||
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
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. 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 { | ||
llvm_unreachable("DXContainer does not support relocations"); | ||
} | ||
|
||
uint64_t DXContainerObjectFile::getRelocationOffset(DataRefImpl Rel) const { | ||
llvm_unreachable("DXContainer does not support relocations"); | ||
} | ||
|
||
symbol_iterator | ||
DXContainerObjectFile::getRelocationSymbol(DataRefImpl Rel) const { | ||
return symbol_iterator(SymbolRef()); | ||
} | ||
|
||
uint64_t DXContainerObjectFile::getRelocationType(DataRefImpl Rel) const { | ||
llvm_unreachable("DXContainer does not support relocations"); | ||
} | ||
|
||
void DXContainerObjectFile::getRelocationTypeName( | ||
DataRefImpl Rel, SmallVectorImpl<char> &Result) const { | ||
llvm_unreachable("DXContainer does not support relocations"); | ||
} | ||
|
||
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<uint32_t> | ||
DXContainerObjectFile::getSymbolFlags(DataRefImpl Symb) const { | ||
return make_error<DXNotSupportedError>("Symbol flags"); | ||
} | ||
|
||
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.
@bogner @llvm-beanz I think the
DXContainerObjectFile
should present as if it had empty symbol and relocation tables, rather than making these operations unreachable.From a design perspective you should be able to iterate over the set of symbols and relocations in an object file, and empty sets are perfectly legal.
As a practical matter presenting empty sets will allow
llvm-objdump -r
andllvm-objdump -t
to behave sensibly, whereas unreachable will cause them to crash.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.
I don't think what you're saying here is in conflict to having
llvm_unreachable
here. With this patchllvm-objdump -r
produces the output:and
llvm-objdump -t
produces:The iterators are implemented and all effectively return end iterators so that the result is an empty set. The only way you'd really hit these unreachable is if you tried to access or increment one of the iterators, and since they would be invalid, that would always be a logic error.
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.
Oh, you're totally right. My bad!
LGTM. :)