Coverage Report

Created: 2017-10-03 07:32

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/tools/lld/lib/ReaderWriter/MachO/SectCreateFile.h
Line
Count
Source (jump to first uncovered line)
1
//===---- lib/ReaderWriter/MachO/SectCreateFile.h ---------------*- c++ -*-===//
2
//
3
//                             The LLVM Linker
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
10
#ifndef LLD_READER_WRITER_MACHO_SECTCREATE_FILE_H
11
#define LLD_READER_WRITER_MACHO_SECTCREATE_FILE_H
12
13
#include "lld/Core/DefinedAtom.h"
14
#include "lld/Core/Simple.h"
15
#include "lld/ReaderWriter/MachOLinkingContext.h"
16
17
namespace lld {
18
namespace mach_o {
19
20
//
21
// A FlateNamespaceFile instance may be added as a resolution source of last
22
// resort, depending on how -flat_namespace and -undefined are set.
23
//
24
class SectCreateFile : public File {
25
public:
26
  class SectCreateAtom : public SimpleDefinedAtom {
27
  public:
28
    SectCreateAtom(const File &file, StringRef segName, StringRef sectName,
29
                   std::unique_ptr<MemoryBuffer> content)
30
      : SimpleDefinedAtom(file),
31
        _combinedName((segName + "/" + sectName).str()),
32
1
        _content(std::move(content)) {}
33
34
1
    ~SectCreateAtom() override = default;
35
36
4
    uint64_t size() const override { return _content->getBufferSize(); }
37
38
1
    Scope scope() const override { return scopeGlobal; }
39
40
8
    ContentType contentType() const override { return typeSectCreate; }
41
42
2
    SectionChoice sectionChoice() const override { return sectionCustomRequired; }
43
44
2
    StringRef customSectionName() const override { return _combinedName; }
45
46
1
    DeadStripKind deadStrip() const override { return deadStripNever; }
47
48
3
    ArrayRef<uint8_t> rawContent() const override {
49
3
      const uint8_t *data =
50
3
        reinterpret_cast<const uint8_t*>(_content->getBufferStart());
51
3
      return ArrayRef<uint8_t>(data, _content->getBufferSize());
52
3
    }
53
54
0
    StringRef segmentName() const { return _segName; }
55
0
    StringRef sectionName() const { return _sectName; }
56
57
  private:
58
    std::string _combinedName;
59
    StringRef _segName;
60
    StringRef _sectName;
61
    std::unique_ptr<MemoryBuffer> _content;
62
  };
63
64
1
  SectCreateFile() : File("sectcreate", kindSectCreateObject) {}
65
66
  void addSection(StringRef seg, StringRef sect,
67
1
                  std::unique_ptr<MemoryBuffer> content) {
68
1
    _definedAtoms.push_back(
69
1
      new (allocator()) SectCreateAtom(*this, seg, sect, std::move(content)));
70
1
  }
71
72
1
  const AtomRange<DefinedAtom> defined() const override {
73
1
    return _definedAtoms;
74
1
  }
75
76
1
  const AtomRange<UndefinedAtom> undefined() const override {
77
1
    return _noUndefinedAtoms;
78
1
  }
79
80
1
  const AtomRange<SharedLibraryAtom> sharedLibrary() const override {
81
1
    return _noSharedLibraryAtoms;
82
1
  }
83
84
1
  const AtomRange<AbsoluteAtom> absolute() const override {
85
1
    return _noAbsoluteAtoms;
86
1
  }
87
88
1
  void clearAtoms() override {
89
1
    _definedAtoms.clear();
90
1
    _noUndefinedAtoms.clear();
91
1
    _noSharedLibraryAtoms.clear();
92
1
    _noAbsoluteAtoms.clear();
93
1
  }
94
95
private:
96
  AtomVector<DefinedAtom> _definedAtoms;
97
};
98
99
} // namespace mach_o
100
} // namespace lld
101
102
#endif // LLD_READER_WRITER_MACHO_SECTCREATE_FILE_H