Coverage Report

Created: 2017-10-03 07:32

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/tools/lld/lib/ReaderWriter/MachO/ExecutableAtoms.h
Line
Count
Source (jump to first uncovered line)
1
//===- lib/ReaderWriter/MachO/ExecutableAtoms.h ---------------------------===//
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_EXECUTABLE_ATOMS_H
11
#define LLD_READER_WRITER_MACHO_EXECUTABLE_ATOMS_H
12
13
#include "Atoms.h"
14
#include "File.h"
15
16
#include "llvm/BinaryFormat/MachO.h"
17
18
#include "lld/Core/DefinedAtom.h"
19
#include "lld/Core/File.h"
20
#include "lld/Core/LinkingContext.h"
21
#include "lld/Core/Reference.h"
22
#include "lld/Core/Simple.h"
23
#include "lld/Core/UndefinedAtom.h"
24
#include "lld/ReaderWriter/MachOLinkingContext.h"
25
26
namespace lld {
27
namespace mach_o {
28
29
30
//
31
// CEntryFile adds an UndefinedAtom for "_main" so that the Resolving
32
// phase will fail if "_main" is undefined.
33
//
34
class CEntryFile : public SimpleFile {
35
public:
36
  CEntryFile(const MachOLinkingContext &context)
37
      : SimpleFile("C entry", kindCEntryObject),
38
54
       _undefMain(*this, context.entrySymbolName()) {
39
54
    this->addAtom(_undefMain);
40
54
  }
41
42
private:
43
  SimpleUndefinedAtom   _undefMain;
44
};
45
46
47
//
48
// StubHelperFile adds an UndefinedAtom for "dyld_stub_binder" so that
49
// the Resolveing phase will fail if "dyld_stub_binder" is undefined.
50
//
51
class StubHelperFile : public SimpleFile {
52
public:
53
  StubHelperFile(const MachOLinkingContext &context)
54
      : SimpleFile("stub runtime", kindStubHelperObject),
55
101
        _undefBinder(*this, context.binderSymbolName()) {
56
101
    this->addAtom(_undefBinder);
57
101
  }
58
59
private:
60
  SimpleUndefinedAtom   _undefBinder;
61
};
62
63
64
//
65
// MachHeaderAliasFile lazily instantiates the magic symbols that mark the start
66
// of the mach_header for final linked images.
67
//
68
class MachHeaderAliasFile : public SimpleFile {
69
public:
70
  MachHeaderAliasFile(const MachOLinkingContext &context)
71
101
    : SimpleFile("mach_header symbols", kindHeaderObject) {
72
101
    StringRef machHeaderSymbolName;
73
101
    DefinedAtom::Scope symbolScope = DefinedAtom::scopeLinkageUnit;
74
101
    StringRef dsoHandleName;
75
101
    switch (context.outputMachOType()) {
76
0
    case llvm::MachO::MH_OBJECT:
77
0
      machHeaderSymbolName = "__mh_object_header";
78
0
      break;
79
54
    case llvm::MachO::MH_EXECUTE:
80
54
      machHeaderSymbolName = "__mh_execute_header";
81
54
      symbolScope = DefinedAtom::scopeGlobal;
82
54
      dsoHandleName = "___dso_handle";
83
54
      break;
84
0
    case llvm::MachO::MH_FVMLIB:
85
0
      llvm_unreachable("no mach_header symbol for file type");
86
0
    case llvm::MachO::MH_CORE:
87
0
      llvm_unreachable("no mach_header symbol for file type");
88
0
    case llvm::MachO::MH_PRELOAD:
89
0
      llvm_unreachable("no mach_header symbol for file type");
90
44
    case llvm::MachO::MH_DYLIB:
91
44
      machHeaderSymbolName = "__mh_dylib_header";
92
44
      dsoHandleName = "___dso_handle";
93
44
      break;
94
0
    case llvm::MachO::MH_DYLINKER:
95
0
      machHeaderSymbolName = "__mh_dylinker_header";
96
0
      dsoHandleName = "___dso_handle";
97
0
      break;
98
3
    case llvm::MachO::MH_BUNDLE:
99
3
      machHeaderSymbolName = "__mh_bundle_header";
100
3
      dsoHandleName = "___dso_handle";
101
3
      break;
102
0
    case llvm::MachO::MH_DYLIB_STUB:
103
0
      llvm_unreachable("no mach_header symbol for file type");
104
0
    case llvm::MachO::MH_DSYM:
105
0
      llvm_unreachable("no mach_header symbol for file type");
106
0
    case llvm::MachO::MH_KEXT_BUNDLE:
107
0
      dsoHandleName = "___dso_handle";
108
0
      break;
109
101
    }
110
101
    
if (101
!machHeaderSymbolName.empty()101
)
111
101
      _definedAtoms.push_back(new (allocator()) MachODefinedAtom(
112
101
          *this, machHeaderSymbolName, symbolScope,
113
101
          DefinedAtom::typeMachHeader, DefinedAtom::mergeNo, false,
114
101
          true /* noDeadStrip */,
115
101
          ArrayRef<uint8_t>(), DefinedAtom::Alignment(4096)));
116
101
117
101
    if (!dsoHandleName.empty())
118
101
      _definedAtoms.push_back(new (allocator()) MachODefinedAtom(
119
101
          *this, dsoHandleName, DefinedAtom::scopeLinkageUnit,
120
101
          DefinedAtom::typeDSOHandle, DefinedAtom::mergeNo, false,
121
101
          true /* noDeadStrip */,
122
101
          ArrayRef<uint8_t>(), DefinedAtom::Alignment(1)));
123
101
  }
124
125
101
  const AtomRange<DefinedAtom> defined() const override {
126
101
    return _definedAtoms;
127
101
  }
128
101
  const AtomRange<UndefinedAtom> undefined() const override {
129
101
    return _noUndefinedAtoms;
130
101
  }
131
132
101
  const AtomRange<SharedLibraryAtom> sharedLibrary() const override {
133
101
    return _noSharedLibraryAtoms;
134
101
  }
135
136
101
  const AtomRange<AbsoluteAtom> absolute() const override {
137
101
    return _noAbsoluteAtoms;
138
101
  }
139
140
101
  void clearAtoms() override {
141
101
    _definedAtoms.clear();
142
101
    _noUndefinedAtoms.clear();
143
101
    _noSharedLibraryAtoms.clear();
144
101
    _noAbsoluteAtoms.clear();
145
101
  }
146
147
148
private:
149
  mutable AtomVector<DefinedAtom> _definedAtoms;
150
};
151
152
} // namespace mach_o
153
} // namespace lld
154
155
#endif // LLD_READER_WRITER_MACHO_EXECUTABLE_ATOMS_H