summaryrefslogtreecommitdiff
path: root/lib/Object/ObjectFile.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-12-18 20:10:56 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-12-18 20:10:56 +0000
commit044eb2f6afba375a914ac9d8024f8f5142bb912e (patch)
tree1475247dc9f9fe5be155ebd4c9069c75aadf8c20 /lib/Object/ObjectFile.cpp
parenteb70dddbd77e120e5d490bd8fbe7ff3f8fa81c6b (diff)
Notes
Diffstat (limited to 'lib/Object/ObjectFile.cpp')
-rw-r--r--lib/Object/ObjectFile.cpp31
1 files changed, 29 insertions, 2 deletions
diff --git a/lib/Object/ObjectFile.cpp b/lib/Object/ObjectFile.cpp
index 8377dd0d73fa..652a2b2497ef 100644
--- a/lib/Object/ObjectFile.cpp
+++ b/lib/Object/ObjectFile.cpp
@@ -75,10 +75,37 @@ bool ObjectFile::isSectionBitcode(DataRefImpl Sec) const {
return false;
}
+bool ObjectFile::isSectionStripped(DataRefImpl Sec) const { return false; }
+
section_iterator ObjectFile::getRelocatedSection(DataRefImpl Sec) const {
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();
@@ -98,7 +125,7 @@ ObjectFile::createObjectFile(MemoryBufferRef Object, file_magic Type) {
case file_magic::elf_executable:
case file_magic::elf_shared_object:
case file_magic::elf_core:
- return errorOrToExpected(createELFObjectFile(Object));
+ return createELFObjectFile(Object);
case file_magic::macho_object:
case file_magic::macho_executable:
case file_magic::macho_fixed_virtual_memory_shared_lib:
@@ -114,7 +141,7 @@ ObjectFile::createObjectFile(MemoryBufferRef Object, file_magic Type) {
case file_magic::coff_object:
case file_magic::coff_import_library:
case file_magic::pecoff_executable:
- return errorOrToExpected(createCOFFObjectFile(Object));
+ return createCOFFObjectFile(Object);
case file_magic::wasm_object:
return createWasmObjectFile(Object);
}