Coverage Report

Created: 2018-08-19 21:11

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/lld/lib/Core/LinkingContext.cpp
Line
Count
Source
1
//===- lib/Core/LinkingContext.cpp - Linker Context Object Interface ------===//
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
#include "lld/Core/LinkingContext.h"
11
#include "lld/Core/File.h"
12
#include "lld/Core/Node.h"
13
#include "lld/Core/Simple.h"
14
#include "lld/Core/Writer.h"
15
#include <algorithm>
16
17
namespace lld {
18
19
243
LinkingContext::LinkingContext() = default;
20
21
243
LinkingContext::~LinkingContext() = default;
22
23
225
bool LinkingContext::validate() {
24
225
  return validateImpl();
25
225
}
26
27
168
llvm::Error LinkingContext::writeFile(const File &linkedFile) const {
28
168
  return this->writer().writeFile(linkedFile, _outputPath);
29
168
}
30
31
183
std::unique_ptr<File> LinkingContext::createEntrySymbolFile() const {
32
183
  return createEntrySymbolFile("<command line option -e>");
33
183
}
34
35
std::unique_ptr<File>
36
183
LinkingContext::createEntrySymbolFile(StringRef filename) const {
37
183
  if (entrySymbolName().empty())
38
129
    return nullptr;
39
54
  std::unique_ptr<SimpleFile> entryFile(new SimpleFile(filename,
40
54
                                                       File::kindEntryObject));
41
54
  entryFile->addAtom(
42
54
      *(new (_allocator) SimpleUndefinedAtom(*entryFile, entrySymbolName())));
43
54
  return std::move(entryFile);
44
54
}
45
46
183
std::unique_ptr<File> LinkingContext::createUndefinedSymbolFile() const {
47
183
  return createUndefinedSymbolFile("<command line option -u or --defsym>");
48
183
}
49
50
std::unique_ptr<File>
51
183
LinkingContext::createUndefinedSymbolFile(StringRef filename) const {
52
183
  if (_initialUndefinedSymbols.empty())
53
175
    return nullptr;
54
8
  std::unique_ptr<SimpleFile> undefinedSymFile(
55
8
    new SimpleFile(filename, File::kindUndefinedSymsObject));
56
8
  for (StringRef undefSym : _initialUndefinedSymbols)
57
12
    undefinedSymFile->addAtom(*(new (_allocator) SimpleUndefinedAtom(
58
12
                                   *undefinedSymFile, undefSym)));
59
8
  return std::move(undefinedSymFile);
60
8
}
61
62
void LinkingContext::createInternalFiles(
63
183
    std::vector<std::unique_ptr<File>> &result) const {
64
183
  if (std::unique_ptr<File> file = createEntrySymbolFile())
65
54
    result.push_back(std::move(file));
66
183
  if (std::unique_ptr<File> file = createUndefinedSymbolFile())
67
8
    result.push_back(std::move(file));
68
183
}
69
70
} // end namespace lld