mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-26 04:32:44 +01:00
Allow public Triple deduction from ObjectFiles.
Move logic that allows for Triple deduction from an ObjectFile object out of llvm-objdump.cpp into a public factory, found in the ObjectFile class. This should allow other tools in the future to use this logic without reimplementation. Patch by Mitch Phillips Differential Revision: https://reviews.llvm.org/D37719 llvm-svn: 313605
This commit is contained in:
parent
019979919f
commit
f226d9a550
@ -282,6 +282,9 @@ public:
|
|||||||
virtual SubtargetFeatures getFeatures() const = 0;
|
virtual SubtargetFeatures getFeatures() const = 0;
|
||||||
virtual void setARMSubArch(Triple &TheTriple) const { }
|
virtual void setARMSubArch(Triple &TheTriple) const { }
|
||||||
|
|
||||||
|
/// @brief Create a triple from the data in this object file.
|
||||||
|
Triple makeTriple() const;
|
||||||
|
|
||||||
/// Returns platform-specific object flags, if any.
|
/// Returns platform-specific object flags, if any.
|
||||||
virtual std::error_code getPlatformFlags(unsigned &Result) const {
|
virtual std::error_code getPlatformFlags(unsigned &Result) const {
|
||||||
Result = 0;
|
Result = 0;
|
||||||
|
@ -79,6 +79,31 @@ section_iterator ObjectFile::getRelocatedSection(DataRefImpl Sec) const {
|
|||||||
return section_iterator(SectionRef(Sec, this));
|
return section_iterator(SectionRef(Sec, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Triple ObjectFile::makeTriple() const {
|
||||||
|
Triple TheTriple;
|
||||||
|
auto Arch = getArch();
|
||||||
|
TheTriple.setArch(Triple::ArchType(Arch));
|
||||||
|
|
||||||
|
// For ARM targets, try to use the build attributes to build determine
|
||||||
|
// the build target. Target features are also added, but later during
|
||||||
|
// disassembly.
|
||||||
|
if (Arch == Triple::arm || Arch == Triple::armeb)
|
||||||
|
setARMSubArch(TheTriple);
|
||||||
|
|
||||||
|
// TheTriple defaults to ELF, and COFF doesn't have an environment:
|
||||||
|
// the best we can do here is indicate that it is mach-o.
|
||||||
|
if (isMachO())
|
||||||
|
TheTriple.setObjectFormat(Triple::MachO);
|
||||||
|
|
||||||
|
if (isCOFF()) {
|
||||||
|
const auto COFFObj = dyn_cast<COFFObjectFile>(this);
|
||||||
|
if (COFFObj->getArch() == Triple::thumb)
|
||||||
|
TheTriple.setTriple("thumbv7-windows");
|
||||||
|
}
|
||||||
|
|
||||||
|
return TheTriple;
|
||||||
|
}
|
||||||
|
|
||||||
Expected<std::unique_ptr<ObjectFile>>
|
Expected<std::unique_ptr<ObjectFile>>
|
||||||
ObjectFile::createObjectFile(MemoryBufferRef Object, file_magic Type) {
|
ObjectFile::createObjectFile(MemoryBufferRef Object, file_magic Type) {
|
||||||
StringRef Data = Object.getBuffer();
|
StringRef Data = Object.getBuffer();
|
||||||
|
@ -362,29 +362,11 @@ static const Target *getTarget(const ObjectFile *Obj = nullptr) {
|
|||||||
llvm::Triple TheTriple("unknown-unknown-unknown");
|
llvm::Triple TheTriple("unknown-unknown-unknown");
|
||||||
if (TripleName.empty()) {
|
if (TripleName.empty()) {
|
||||||
if (Obj) {
|
if (Obj) {
|
||||||
auto Arch = Obj->getArch();
|
TheTriple = Obj->makeTriple();
|
||||||
TheTriple.setArch(Triple::ArchType(Arch));
|
|
||||||
|
|
||||||
// For ARM targets, try to use the build attributes to build determine
|
|
||||||
// the build target. Target features are also added, but later during
|
|
||||||
// disassembly.
|
|
||||||
if (Arch == Triple::arm || Arch == Triple::armeb) {
|
|
||||||
Obj->setARMSubArch(TheTriple);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TheTriple defaults to ELF, and COFF doesn't have an environment:
|
|
||||||
// the best we can do here is indicate that it is mach-o.
|
|
||||||
if (Obj->isMachO())
|
|
||||||
TheTriple.setObjectFormat(Triple::MachO);
|
|
||||||
|
|
||||||
if (Obj->isCOFF()) {
|
|
||||||
const auto COFFObj = dyn_cast<COFFObjectFile>(Obj);
|
|
||||||
if (COFFObj->getArch() == Triple::thumb)
|
|
||||||
TheTriple.setTriple("thumbv7-windows");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
TheTriple.setTriple(Triple::normalize(TripleName));
|
TheTriple.setTriple(Triple::normalize(TripleName));
|
||||||
|
|
||||||
// Use the triple, but also try to combine with ARM build attributes.
|
// Use the triple, but also try to combine with ARM build attributes.
|
||||||
if (Obj) {
|
if (Obj) {
|
||||||
auto Arch = Obj->getArch();
|
auto Arch = Obj->getArch();
|
||||||
|
Loading…
Reference in New Issue
Block a user