Coverage Report

Created: 2019-07-24 05:18

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