1 //===- SymbolicFile.cpp - Interface that only provides symbols --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines a file format independent SymbolicFile class.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Object/COFF.h"
15 #include "llvm/Object/COFFImportFile.h"
16 #include "llvm/Object/IRObjectFile.h"
17 #include "llvm/Object/ObjectFile.h"
18 #include "llvm/Object/SymbolicFile.h"
19 #include "llvm/Support/MemoryBuffer.h"
22 using namespace object;
24 SymbolicFile::SymbolicFile(unsigned int Type, MemoryBufferRef Source)
25 : Binary(Type, Source) {}
27 SymbolicFile::~SymbolicFile() {}
29 ErrorOr<std::unique_ptr<SymbolicFile>> SymbolicFile::createSymbolicFile(
30 MemoryBufferRef Object, sys::fs::file_magic Type, LLVMContext *Context) {
31 StringRef Data = Object.getBuffer();
32 if (Type == sys::fs::file_magic::unknown)
33 Type = sys::fs::identify_magic(Data);
36 case sys::fs::file_magic::bitcode:
38 return IRObjectFile::create(Object, *Context);
40 case sys::fs::file_magic::unknown:
41 case sys::fs::file_magic::archive:
42 case sys::fs::file_magic::macho_universal_binary:
43 case sys::fs::file_magic::windows_resource:
44 return object_error::invalid_file_type;
45 case sys::fs::file_magic::elf:
46 case sys::fs::file_magic::elf_executable:
47 case sys::fs::file_magic::elf_shared_object:
48 case sys::fs::file_magic::elf_core:
49 case sys::fs::file_magic::macho_executable:
50 case sys::fs::file_magic::macho_fixed_virtual_memory_shared_lib:
51 case sys::fs::file_magic::macho_core:
52 case sys::fs::file_magic::macho_preload_executable:
53 case sys::fs::file_magic::macho_dynamically_linked_shared_lib:
54 case sys::fs::file_magic::macho_dynamic_linker:
55 case sys::fs::file_magic::macho_bundle:
56 case sys::fs::file_magic::macho_dynamically_linked_shared_lib_stub:
57 case sys::fs::file_magic::macho_dsym_companion:
58 case sys::fs::file_magic::macho_kext_bundle:
59 case sys::fs::file_magic::pecoff_executable:
60 return ObjectFile::createObjectFile(Object, Type);
61 case sys::fs::file_magic::coff_import_library:
62 return std::unique_ptr<SymbolicFile>(new COFFImportFile(Object));
63 case sys::fs::file_magic::elf_relocatable:
64 case sys::fs::file_magic::macho_object:
65 case sys::fs::file_magic::coff_object: {
66 ErrorOr<std::unique_ptr<ObjectFile>> Obj =
67 ObjectFile::createObjectFile(Object, Type);
69 return std::move(Obj);
71 ErrorOr<MemoryBufferRef> BCData =
72 IRObjectFile::findBitcodeInObject(*Obj->get());
74 return std::move(Obj);
76 return IRObjectFile::create(
77 MemoryBufferRef(BCData->getBuffer(), Object.getBufferIdentifier()),
81 llvm_unreachable("Unexpected Binary File Type");