Coverage Report

Created: 2019-05-19 14:56

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