/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Object/SymbolicFile.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===- SymbolicFile.cpp - Interface that only provides symbols ------------===// |
2 | | // |
3 | | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | | // See https://llvm.org/LICENSE.txt for license information. |
5 | | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | // |
9 | | // This file defines a file format independent SymbolicFile class. |
10 | | // |
11 | | //===----------------------------------------------------------------------===// |
12 | | |
13 | | #include "llvm/Object/SymbolicFile.h" |
14 | | #include "llvm/ADT/StringRef.h" |
15 | | #include "llvm/BinaryFormat/Magic.h" |
16 | | #include "llvm/Object/COFFImportFile.h" |
17 | | #include "llvm/Object/Error.h" |
18 | | #include "llvm/Object/IRObjectFile.h" |
19 | | #include "llvm/Object/ObjectFile.h" |
20 | | #include "llvm/Support/Compiler.h" |
21 | | #include "llvm/Support/Error.h" |
22 | | #include "llvm/Support/ErrorHandling.h" |
23 | | #include "llvm/Support/ErrorOr.h" |
24 | | #include "llvm/Support/FileSystem.h" |
25 | | #include "llvm/Support/MemoryBuffer.h" |
26 | | #include <algorithm> |
27 | | #include <memory> |
28 | | |
29 | | using namespace llvm; |
30 | | using namespace object; |
31 | | |
32 | | SymbolicFile::SymbolicFile(unsigned int Type, MemoryBufferRef Source) |
33 | 30.6k | : Binary(Type, Source) {} |
34 | | |
35 | 30.4k | SymbolicFile::~SymbolicFile() = default; |
36 | | |
37 | | Expected<std::unique_ptr<SymbolicFile>> |
38 | | SymbolicFile::createSymbolicFile(MemoryBufferRef Object, file_magic Type, |
39 | 13.2k | LLVMContext *Context) { |
40 | 13.2k | StringRef Data = Object.getBuffer(); |
41 | 13.2k | if (Type == file_magic::unknown) |
42 | 1.53k | Type = identify_magic(Data); |
43 | 13.2k | |
44 | 13.2k | switch (Type) { |
45 | 13.2k | case file_magic::bitcode: |
46 | 61 | if (Context) |
47 | 61 | return IRObjectFile::create(Object, *Context); |
48 | 0 | LLVM_FALLTHROUGH; |
49 | 306 | case file_magic::unknown: |
50 | 306 | case file_magic::archive: |
51 | 306 | case file_magic::coff_cl_gl_object: |
52 | 306 | case file_magic::macho_universal_binary: |
53 | 306 | case file_magic::windows_resource: |
54 | 306 | case file_magic::pdb: |
55 | 306 | case file_magic::minidump: |
56 | 306 | return errorCodeToError(object_error::invalid_file_type); |
57 | 4.66k | case file_magic::elf: |
58 | 4.66k | case file_magic::elf_executable: |
59 | 4.66k | case file_magic::elf_shared_object: |
60 | 4.66k | case file_magic::elf_core: |
61 | 4.66k | case file_magic::macho_executable: |
62 | 4.66k | case file_magic::macho_fixed_virtual_memory_shared_lib: |
63 | 4.66k | case file_magic::macho_core: |
64 | 4.66k | case file_magic::macho_preload_executable: |
65 | 4.66k | case file_magic::macho_dynamically_linked_shared_lib: |
66 | 4.66k | case file_magic::macho_dynamic_linker: |
67 | 4.66k | case file_magic::macho_bundle: |
68 | 4.66k | case file_magic::macho_dynamically_linked_shared_lib_stub: |
69 | 4.66k | case file_magic::macho_dsym_companion: |
70 | 4.66k | case file_magic::macho_kext_bundle: |
71 | 4.66k | case file_magic::pecoff_executable: |
72 | 4.66k | case file_magic::xcoff_object_32: |
73 | 4.66k | case file_magic::xcoff_object_64: |
74 | 4.66k | case file_magic::wasm_object: |
75 | 4.66k | return ObjectFile::createObjectFile(Object, Type); |
76 | 4.66k | case file_magic::coff_import_library: |
77 | 316 | return std::unique_ptr<SymbolicFile>(new COFFImportFile(Object)); |
78 | 7.92k | case file_magic::elf_relocatable: |
79 | 7.92k | case file_magic::macho_object: |
80 | 7.92k | case file_magic::coff_object: { |
81 | 7.92k | Expected<std::unique_ptr<ObjectFile>> Obj = |
82 | 7.92k | ObjectFile::createObjectFile(Object, Type); |
83 | 7.92k | if (!Obj || !Context7.79k ) |
84 | 7.53k | return std::move(Obj); |
85 | 397 | |
86 | 397 | Expected<MemoryBufferRef> BCData = |
87 | 397 | IRObjectFile::findBitcodeInObject(*Obj->get()); |
88 | 397 | if (!BCData) { |
89 | 393 | consumeError(BCData.takeError()); |
90 | 393 | return std::move(Obj); |
91 | 393 | } |
92 | 4 | |
93 | 4 | return IRObjectFile::create( |
94 | 4 | MemoryBufferRef(BCData->getBuffer(), Object.getBufferIdentifier()), |
95 | 4 | *Context); |
96 | 4 | } |
97 | 0 | } |
98 | 0 | llvm_unreachable("Unexpected Binary File Type"); |
99 | 0 | } |