LLVM  6.0.0svn
SymbolicFile.cpp
Go to the documentation of this file.
1 //===- SymbolicFile.cpp - Interface that only provides symbols ------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines a file format independent SymbolicFile class.
11 //
12 //===----------------------------------------------------------------------===//
13 
15 #include "llvm/ADT/StringRef.h"
18 #include "llvm/Object/Error.h"
20 #include "llvm/Object/ObjectFile.h"
21 #include "llvm/Support/Compiler.h"
22 #include "llvm/Support/Error.h"
24 #include "llvm/Support/ErrorOr.h"
27 #include <algorithm>
28 #include <memory>
29 
30 using namespace llvm;
31 using namespace object;
32 
34  : Binary(Type, Source) {}
35 
36 SymbolicFile::~SymbolicFile() = default;
37 
41  StringRef Data = Object.getBuffer();
42  if (Type == file_magic::unknown)
43  Type = identify_magic(Data);
44 
45  switch (Type) {
47  if (Context)
48  return IRObjectFile::create(Object, *Context);
56  case file_magic::elf:
72  return ObjectFile::createObjectFile(Object, Type);
74  return std::unique_ptr<SymbolicFile>(new COFFImportFile(Object));
79  ObjectFile::createObjectFile(Object, Type);
80  if (!Obj || !Context)
81  return std::move(Obj);
82 
85  if (!BCData) {
86  consumeError(BCData.takeError());
87  return std::move(Obj);
88  }
89 
90  return IRObjectFile::create(
91  MemoryBufferRef(BCData->getBuffer(), Object.getBufferIdentifier()),
92  *Context);
93  }
94  }
95  llvm_unreachable("Unexpected Binary File Type");
96 }
static Expected< OwningBinary< ObjectFile > > createObjectFile(StringRef ObjectPath)
Create ObjectFile from path.
Definition: ObjectFile.cpp:152
Mach-O Object file.
Definition: Magic.h:31
LLVMContext & Context
ELF core image.
Definition: Magic.h:30
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
Microsoft cl.exe&#39;s intermediate code file.
Definition: Magic.h:43
ELF dynamically linked shared lib.
Definition: Magic.h:29
static Expected< std::unique_ptr< SymbolicFile > > createSymbolicFile(MemoryBufferRef Object, llvm::file_magic Type, LLVMContext *Context)
Windows compiled resource file (.res)
Definition: Magic.h:47
Error takeError()
Take ownership of the stored error.
Definition: Error.h:537
Mach-O Bundle file.
Definition: Magic.h:38
Mach-O Preloaded Executable.
Definition: Magic.h:35
Bitcode file.
Definition: Magic.h:24
SymbolicFile(unsigned int Type, MemoryBufferRef Source)
StringRef getBuffer() const
Definition: MemoryBuffer.h:170
file_magic identify_magic(StringRef magic)
Identify the type of a binary file based on how magical it is.
Definition: Magic.cpp:34
The Mach-O dynamic linker.
Definition: Magic.h:37
Tagged union holding either a T or a Error.
Definition: CachePruning.h:23
ELF Relocatable object file.
Definition: Magic.h:27
COFF import library.
Definition: Magic.h:45
Mach-O universal binary.
Definition: Magic.h:42
Mach-O Core File.
Definition: Magic.h:34
static Expected< std::unique_ptr< IRObjectFile > > create(MemoryBufferRef Object, LLVMContext &Context)
Mach-O dSYM companion file.
Definition: Magic.h:40
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:69
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
Definition: Error.cpp:78
PECOFF executable file.
Definition: Magic.h:46
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:962
COFF object file.
Definition: Magic.h:44
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Mach-O kext bundle file.
Definition: Magic.h:41
ar style archive file
Definition: Magic.h:25
static Expected< MemoryBufferRef > findBitcodeInObject(const ObjectFile &Obj)
Finds and returns bitcode embedded in the given object file, or an error code if not found...
reference get()
Returns a reference to the stored T value.
Definition: Error.h:517
ELF Unknown type.
Definition: Magic.h:26
ELF Executable image.
Definition: Magic.h:28
MemoryBufferRef Data
Definition: Binary.h:37
StringRef getBufferIdentifier() const
Definition: MemoryBuffer.h:172
WebAssembly Object file.
Definition: Magic.h:48
Provides ErrorOr<T> smart pointer.
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition: Compiler.h:235
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
Mach-O Executable.
Definition: Magic.h:32
Unrecognized file.
Definition: Magic.h:23
file_magic - An "enum class" enumeration of file types based on magic (the first N bytes of the file)...
Definition: Magic.h:21