Coverage Report

Created: 2017-10-03 07:32

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/tools/lld/lib/ReaderWriter/MachO/Atoms.h
Line
Count
Source (jump to first uncovered line)
1
//===- lib/ReaderWriter/MachO/Atoms.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_ATOMS_H
11
#define LLD_READER_WRITER_MACHO_ATOMS_H
12
13
#include "lld/Core/Atom.h"
14
#include "lld/Core/DefinedAtom.h"
15
#include "lld/Core/SharedLibraryAtom.h"
16
#include "lld/Core/Simple.h"
17
#include "llvm/ADT/ArrayRef.h"
18
#include "llvm/ADT/StringRef.h"
19
#include <cstdint>
20
#include <string>
21
22
namespace lld {
23
24
class File;
25
26
namespace mach_o {
27
28
class MachODefinedAtom : public SimpleDefinedAtom {
29
public:
30
  MachODefinedAtom(const File &f, const StringRef name, Scope scope,
31
                   ContentType type, Merge merge, bool thumb, bool noDeadStrip,
32
                   const ArrayRef<uint8_t> content, Alignment align)
33
      : SimpleDefinedAtom(f), _name(name), _content(content),
34
        _align(align), _contentType(type), _scope(scope), _merge(merge),
35
694
        _thumb(thumb), _noDeadStrip(noDeadStrip) {}
36
37
  // Constructor for zero-fill content
38
  MachODefinedAtom(const File &f, const StringRef name, Scope scope,
39
                   ContentType type, uint64_t size, bool noDeadStrip,
40
                   Alignment align)
41
      : SimpleDefinedAtom(f), _name(name),
42
        _content(ArrayRef<uint8_t>(nullptr, size)), _align(align),
43
        _contentType(type), _scope(scope), _merge(mergeNo), _thumb(false),
44
3
        _noDeadStrip(noDeadStrip) {}
45
46
697
  ~MachODefinedAtom() override = default;
47
48
1.94k
  uint64_t size() const override { return _content.size(); }
49
50
9.05k
  ContentType contentType() const override { return _contentType; }
51
52
698
  Alignment alignment() const override { return _align; }
53
54
4.34k
  StringRef name() const override { return _name; }
55
56
1.47k
  Scope scope() const override { return _scope; }
57
58
1.41k
  Merge merge() const override { return _merge; }
59
60
702
  DeadStripKind deadStrip() const override {
61
702
    if (_contentType == DefinedAtom::typeInitializerPtr)
62
4
      return deadStripNever;
63
698
    
if (698
_contentType == DefinedAtom::typeTerminatorPtr698
)
64
2
      return deadStripNever;
65
696
    
if (696
_noDeadStrip696
)
66
168
      return deadStripNever;
67
528
    return deadStripNormal;
68
702
  }
69
70
3.46k
  ArrayRef<uint8_t> rawContent() const override {
71
3.46k
    // Note: Zerofill atoms have a content pointer which is null.
72
3.46k
    return _content;
73
3.46k
  }
74
75
61
  bool isThumb() const { return _thumb; }
76
77
private:
78
  const StringRef _name;
79
  const ArrayRef<uint8_t> _content;
80
  const DefinedAtom::Alignment _align;
81
  const ContentType _contentType;
82
  const Scope _scope;
83
  const Merge _merge;
84
  const bool _thumb;
85
  const bool _noDeadStrip;
86
};
87
88
class MachODefinedCustomSectionAtom : public MachODefinedAtom {
89
public:
90
  MachODefinedCustomSectionAtom(const File &f, const StringRef name,
91
                                Scope scope, ContentType type, Merge merge,
92
                                bool thumb, bool noDeadStrip,
93
                                const ArrayRef<uint8_t> content,
94
                                StringRef sectionName, Alignment align)
95
      : MachODefinedAtom(f, name, scope, type, merge, thumb, noDeadStrip,
96
                         content, align),
97
23
        _sectionName(sectionName) {}
98
99
23
  ~MachODefinedCustomSectionAtom() override = default;
100
101
41
  SectionChoice sectionChoice() const override {
102
41
    return DefinedAtom::sectionCustomRequired;
103
41
  }
104
105
43
  StringRef customSectionName() const override {
106
43
    return _sectionName;
107
43
  }
108
private:
109
  StringRef _sectionName;
110
};
111
112
class MachOTentativeDefAtom : public SimpleDefinedAtom {
113
public:
114
  MachOTentativeDefAtom(const File &f, const StringRef name, Scope scope,
115
                        uint64_t size, DefinedAtom::Alignment align)
116
      : SimpleDefinedAtom(f), _name(name), _scope(scope), _size(size),
117
5
        _align(align) {}
118
119
5
  ~MachOTentativeDefAtom() override = default;
120
121
10
  uint64_t size() const override { return _size; }
122
123
10
  Merge merge() const override { return DefinedAtom::mergeAsTentative; }
124
125
66
  ContentType contentType() const override { return DefinedAtom::typeZeroFill; }
126
127
10
  Alignment alignment() const override { return _align; }
128
129
46
  StringRef name() const override { return _name; }
130
131
15
  Scope scope() const override { return _scope; }
132
133
0
  ArrayRef<uint8_t> rawContent() const override { return ArrayRef<uint8_t>(); }
134
135
private:
136
  const std::string _name;
137
  const Scope _scope;
138
  const uint64_t _size;
139
  const DefinedAtom::Alignment _align;
140
};
141
142
class MachOSharedLibraryAtom : public SharedLibraryAtom {
143
public:
144
  MachOSharedLibraryAtom(const File &file, StringRef name,
145
                         StringRef dylibInstallName, bool weakDef)
146
      : SharedLibraryAtom(), _file(file), _name(name),
147
136
        _dylibInstallName(dylibInstallName) {}
148
136
  ~MachOSharedLibraryAtom() override = default;
149
150
186
  StringRef loadName() const override { return _dylibInstallName; }
151
152
39
  bool canBeNullAtRuntime() const override {
153
39
    // FIXME: this may actually be changeable. For now, all symbols are strongly
154
39
    // defined though.
155
39
    return false;
156
39
  }
157
158
0
  const File &file() const override { return _file; }
159
160
577
  StringRef name() const override { return _name; }
161
162
8
  Type type() const override {
163
8
    // Unused in MachO (I think).
164
8
    return Type::Unknown;
165
8
  }
166
167
8
  uint64_t size() const override {
168
8
    // Unused in MachO (I think)
169
8
    return 0;
170
8
  }
171
172
private:
173
  const File &_file;
174
  StringRef _name;
175
  StringRef _dylibInstallName;
176
};
177
178
} // end namespace mach_o
179
} // end namespace lld
180
181
#endif // LLD_READER_WRITER_MACHO_ATOMS_H