Coverage Report

Created: 2023-09-21 18:56

/Users/buildslave/jenkins/workspace/coverage/llvm-project/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
0
    : Linux(D, Triple, Args) {
29
  // Select the correct multilib according to the given arguments.
30
0
  DetectedMultilibs Result;
31
0
  findMIPSMultilibs(D, Triple, "", Args, Result);
32
0
  Multilibs = Result.Multilibs;
33
0
  SelectedMultilibs = Result.SelectedMultilibs;
34
35
  // Find out the library suffix based on the ABI.
36
0
  LibSuffix = tools::mips::getMipsABILibSuffix(Args, Triple);
37
0
  getFilePaths().clear();
38
0
  getFilePaths().push_back(computeSysRoot() + "/usr/lib" + LibSuffix);
39
0
}
40
41
void MipsLLVMToolChain::AddClangSystemIncludeArgs(
42
0
    const ArgList &DriverArgs, ArgStringList &CC1Args) const {
43
0
  if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
44
0
    return;
45
46
0
  const Driver &D = getDriver();
47
48
0
  if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
49
0
    SmallString<128> P(D.ResourceDir);
50
0
    llvm::sys::path::append(P, "include");
51
0
    addSystemInclude(DriverArgs, CC1Args, P);
52
0
  }
53
54
0
  if (DriverArgs.hasArg(options::OPT_nostdlibinc))
55
0
    return;
56
57
0
  const auto &Callback = Multilibs.includeDirsCallback();
58
0
  if (Callback) {
59
0
    for (const auto &Path : Callback(SelectedMultilibs.back()))
60
0
      addExternCSystemIncludeIfExists(DriverArgs, CC1Args,
61
0
                                      D.getInstalledDir() + Path);
62
0
  }
63
0
}
64
65
0
Tool *MipsLLVMToolChain::buildLinker() const {
66
0
  return new tools::gnutools::Linker(*this);
67
0
}
68
69
0
std::string MipsLLVMToolChain::computeSysRoot() const {
70
0
  if (!getDriver().SysRoot.empty())
71
0
    return getDriver().SysRoot + SelectedMultilibs.back().osSuffix();
72
73
0
  const std::string InstalledDir(getDriver().getInstalledDir());
74
0
  std::string SysRootPath =
75
0
      InstalledDir + "/../sysroot" + SelectedMultilibs.back().osSuffix();
76
0
  if (llvm::sys::fs::exists(SysRootPath))
77
0
    return SysRootPath;
78
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
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(SelectedMultilibs.back())) {
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
114
0
  CmdArgs.push_back("-lc++");
115
0
  if (Args.hasArg(options::OPT_fexperimental_library))
116
0
    CmdArgs.push_back("-lc++experimental");
117
0
  CmdArgs.push_back("-lc++abi");
118
0
  CmdArgs.push_back("-lunwind");
119
0
}
120
121
std::string MipsLLVMToolChain::getCompilerRT(const ArgList &Args,
122
                                             StringRef Component,
123
0
                                             FileType Type) const {
124
0
  SmallString<128> Path(getDriver().ResourceDir);
125
0
  llvm::sys::path::append(Path, SelectedMultilibs.back().osSuffix(), "lib" + LibSuffix,
126
0
                          getOS());
127
0
  const char *Suffix;
128
0
  switch (Type) {
129
0
  case ToolChain::FT_Object:
130
0
    Suffix = ".o";
131
0
    break;
132
0
  case ToolChain::FT_Static:
133
0
    Suffix = ".a";
134
0
    break;
135
0
  case ToolChain::FT_Shared:
136
0
    Suffix = ".so";
137
0
    break;
138
0
  }
139
0
  llvm::sys::path::append(
140
0
      Path, Twine("libclang_rt." + Component + "-" + "mips" + Suffix));
141
0
  return std::string(Path.str());
142
0
}