Coverage Report

Created: 2017-10-03 07:32

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/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
242
LinkingContext::LinkingContext() = default;
20
21
242
LinkingContext::~LinkingContext() = default;
22
23
224
bool LinkingContext::validate(raw_ostream &diagnostics) {
24
224
  return validateImpl(diagnostics);
25
224
}
26
27
167
llvm::Error LinkingContext::writeFile(const File &linkedFile) const {
28
167
  return this->writer().writeFile(linkedFile, _outputPath);
29
167
}
30
31
182
std::unique_ptr<File> LinkingContext::createEntrySymbolFile() const {
32
182
  return createEntrySymbolFile("<command line option -e>");
33
182
}
34
35
std::unique_ptr<File>
36
182
LinkingContext::createEntrySymbolFile(StringRef filename) const {
37
182
  if (entrySymbolName().empty())
38
128
    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
182
std::unique_ptr<File> LinkingContext::createUndefinedSymbolFile() const {
47
182
  return createUndefinedSymbolFile("<command line option -u or --defsym>");
48
182
}
49
50
std::unique_ptr<File>
51
182
LinkingContext::createUndefinedSymbolFile(StringRef filename) const {
52
182
  if (_initialUndefinedSymbols.empty())
53
174
    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
182
  return std::move(undefinedSymFile);
60
182
}
61
62
void LinkingContext::createInternalFiles(
63
182
    std::vector<std::unique_ptr<File>> &result) const {
64
182
  if (std::unique_ptr<File> file = createEntrySymbolFile())
65
54
    result.push_back(std::move(file));
66
182
  if (std::unique_ptr<File> file = createUndefinedSymbolFile())
67
8
    result.push_back(std::move(file));
68
182
}
69
70
} // end namespace lld