Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/lib/Driver/ToolChains/MipsLinux.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- MipsLinux.cpp - Mips ToolChain Implementations ----------*- C++ -*-===//
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 "MipsLinux.h"
10
#include "Arch/Mips.h"
11
#include "CommonArgs.h"
12
#include "clang/Driver/Driver.h"
13
#include "clang/Driver/DriverDiagnostic.h"
14
#include "clang/Driver/Options.h"
15
#include "llvm/Option/ArgList.h"
16
#include "llvm/Support/FileSystem.h"
17
#include "llvm/Support/Path.h"
18
19
using namespace clang::driver;
20
using namespace clang::driver::toolchains;
21
using namespace clang;
22
using namespace llvm::opt;
23
24
/// Mips Toolchain
25
MipsLLVMToolChain::MipsLLVMToolChain(const Driver &D,
26
                                     const llvm::Triple &Triple,
27
                                     const ArgList &Args)
28
2
    : Linux(D, Triple, Args) {
29
2
  // Select the correct multilib according to the given arguments.
30
2
  DetectedMultilibs Result;
31
2
  findMIPSMultilibs(D, Triple, "", Args, Result);
32
2
  Multilibs = Result.Multilibs;
33
2
  SelectedMultilib = Result.SelectedMultilib;
34
2
35
2
  // Find out the library suffix based on the ABI.
36
2
  LibSuffix = tools::mips::getMipsABILibSuffix(Args, Triple);
37
2
  getFilePaths().clear();
38
2
  getFilePaths().push_back(computeSysRoot() + "/usr/lib" + LibSuffix);
39
2
}
40
41
void MipsLLVMToolChain::AddClangSystemIncludeArgs(
42
2
    const ArgList &DriverArgs, ArgStringList &CC1Args) const {
43
2
  if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
44
0
    return;
45
2
46
2
  const Driver &D = getDriver();
47
2
48
2
  if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
49
2
    SmallString<128> P(D.ResourceDir);
50
2
    llvm::sys::path::append(P, "include");
51
2
    addSystemInclude(DriverArgs, CC1Args, P);
52
2
  }
53
2
54
2
  if (DriverArgs.hasArg(options::OPT_nostdlibinc))
55
0
    return;
56
2
57
2
  const auto &Callback = Multilibs.includeDirsCallback();
58
2
  if (Callback) {
59
2
    for (const auto &Path : Callback(SelectedMultilib))
60
2
      addExternCSystemIncludeIfExists(DriverArgs, CC1Args,
61
2
                                      D.getInstalledDir() + Path);
62
2
  }
63
2
}
64
65
2
Tool *MipsLLVMToolChain::buildLinker() const {
66
2
  return new tools::gnutools::Linker(*this);
67
2
}
68
69
2
std::string MipsLLVMToolChain::computeSysRoot() const {
70
2
  if (!getDriver().SysRoot.empty())
71
2
    return getDriver().SysRoot + SelectedMultilib.osSuffix();
72
0
73
0
  const std::string InstalledDir(getDriver().getInstalledDir());
74
0
  std::string SysRootPath =
75
0
      InstalledDir + "/../sysroot" + SelectedMultilib.osSuffix();
76
0
  if (llvm::sys::fs::exists(SysRootPath))
77
0
    return SysRootPath;
78
0
79
0
  return std::string();
80
0
}
81
82
ToolChain::CXXStdlibType
83
0
MipsLLVMToolChain::GetCXXStdlibType(const ArgList &Args) const {
84
0
  Arg *A = Args.getLastArg(options::OPT_stdlib_EQ);
85
0
  if (A) {
86
0
    StringRef Value = A->getValue();
87
0
    if (Value != "libc++")
88
0
      getDriver().Diag(clang::diag::err_drv_invalid_stdlib_name)
89
0
          << A->getAsString(Args);
90
0
  }
91
0
92
0
  return ToolChain::CST_Libcxx;
93
0
}
94
95
void MipsLLVMToolChain::addLibCxxIncludePaths(
96
    const llvm::opt::ArgList &DriverArgs,
97
0
    llvm::opt::ArgStringList &CC1Args) const {
98
0
  if (const auto &Callback = Multilibs.includeDirsCallback()) {
99
0
    for (std::string Path : Callback(SelectedMultilib)) {
100
0
      Path = getDriver().getInstalledDir() + Path + "/c++/v1";
101
0
      if (llvm::sys::fs::exists(Path)) {
102
0
        addSystemInclude(DriverArgs, CC1Args, Path);
103
0
        return;
104
0
      }
105
0
    }
106
0
  }
107
0
}
108
109
void MipsLLVMToolChain::AddCXXStdlibLibArgs(const ArgList &Args,
110
0
                                            ArgStringList &CmdArgs) const {
111
0
  assert((GetCXXStdlibType(Args) == ToolChain::CST_Libcxx) &&
112
0
         "Only -lc++ (aka libxx) is supported in this toolchain.");
113
0
114
0
  CmdArgs.push_back("-lc++");
115
0
  CmdArgs.push_back("-lc++abi");
116
0
  CmdArgs.push_back("-lunwind");
117
0
}
118
119
std::string MipsLLVMToolChain::getCompilerRT(const ArgList &Args,
120
                                             StringRef Component,
121
4
                                             FileType Type) const {
122
4
  SmallString<128> Path(getDriver().ResourceDir);
123
4
  llvm::sys::path::append(Path, SelectedMultilib.osSuffix(), "lib" + LibSuffix,
124
4
                          getOS());
125
4
  const char *Suffix;
126
4
  switch (Type) {
127
4
  case ToolChain::FT_Object:
128
0
    Suffix = ".o";
129
0
    break;
130
4
  case ToolChain::FT_Static:
131
4
    Suffix = ".a";
132
4
    break;
133
4
  case ToolChain::FT_Shared:
134
0
    Suffix = ".so";
135
0
    break;
136
4
  }
137
4
  llvm::sys::path::append(
138
4
      Path, Twine("libclang_rt." + Component + "-" + "mips" + Suffix));
139
4
  return Path.str();
140
4
}