[llvm] r313605 - Allow public Triple deduction from ObjectFiles.
Vlad Tsyrklevich via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 18 19:22:48 PDT 2017
Author: vlad.tsyrklevich
Date: Mon Sep 18 19:22:48 2017
New Revision: 313605
URL: http://llvm.org/viewvc/llvm-project?rev=313605&view=rev
Log:
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
Modified:
llvm/trunk/include/llvm/Object/ObjectFile.h
llvm/trunk/lib/Object/ObjectFile.cpp
llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
Modified: llvm/trunk/include/llvm/Object/ObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ObjectFile.h?rev=313605&r1=313604&r2=313605&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ObjectFile.h (original)
+++ llvm/trunk/include/llvm/Object/ObjectFile.h Mon Sep 18 19:22:48 2017
@@ -282,6 +282,9 @@ public:
virtual SubtargetFeatures getFeatures() const = 0;
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.
virtual std::error_code getPlatformFlags(unsigned &Result) const {
Result = 0;
Modified: llvm/trunk/lib/Object/ObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/ObjectFile.cpp?rev=313605&r1=313604&r2=313605&view=diff
==============================================================================
--- llvm/trunk/lib/Object/ObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/ObjectFile.cpp Mon Sep 18 19:22:48 2017
@@ -79,6 +79,31 @@ section_iterator ObjectFile::getRelocate
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>>
ObjectFile::createObjectFile(MemoryBufferRef Object, file_magic Type) {
StringRef Data = Object.getBuffer();
Modified: llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp?rev=313605&r1=313604&r2=313605&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp Mon Sep 18 19:22:48 2017
@@ -362,29 +362,11 @@ static const Target *getTarget(const Obj
llvm::Triple TheTriple("unknown-unknown-unknown");
if (TripleName.empty()) {
if (Obj) {
- auto Arch = Obj->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) {
- 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");
- }
+ TheTriple = Obj->makeTriple();
}
} else {
TheTriple.setTriple(Triple::normalize(TripleName));
+
// Use the triple, but also try to combine with ARM build attributes.
if (Obj) {
auto Arch = Obj->getArch();
More information about the llvm-commits
mailing list