LLVM  8.0.0svn
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 //===----------------------------------------------------------------------===//
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>
30 using namespace llvm;
31 using namespace object;
34  : Binary(Type, Source) {}
36 SymbolicFile::~SymbolicFile() = default;
41  StringRef Data = Object.getBuffer();
42  if (Type == file_magic::unknown)
43  Type = identify_magic(Data);
45  switch (Type) {
47  if (Context)
48  return IRObjectFile::create(Object, *Context);
55  case file_magic::pdb:
57  case file_magic::elf:
73  return ObjectFile::createObjectFile(Object, Type);
75  return std::unique_ptr<SymbolicFile>(new COFFImportFile(Object));
80  ObjectFile::createObjectFile(Object, Type);
81  if (!Obj || !Context)
82  return std::move(Obj);
86  if (!BCData) {
87  consumeError(BCData.takeError());
88  return std::move(Obj);
89  }
91  return IRObjectFile::create(
92  MemoryBufferRef(BCData->getBuffer(), Object.getBufferIdentifier()),
93  *Context);
94  }
95  }
96  llvm_unreachable("Unexpected Binary File Type");
97 }
static Expected< OwningBinary< ObjectFile > > createObjectFile(StringRef ObjectPath)
Definition: ObjectFile.cpp:153
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
Definition: Compiler.h:86
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:553
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:273
file_magic identify_magic(StringRef magic)
Identify the type of a binary file based on how magical it is.
Definition: Magic.cpp:35
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:87
PECOFF executable file.
Definition: Magic.h:46
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:978
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:533
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:275
WebAssembly Object file.
Definition: Magic.h:48
Provides ErrorOr<T> smart pointer.
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
Windows PDB debug info file.
Definition: Magic.h:49
file_magic - An "enum class" enumeration of file types based on magic (the first N bytes of the file)...
Definition: Magic.h:21