Coverage Report

Created: 2023-08-22 09:22

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Driver/ToolChains/Minix.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- Minix.cpp - Minix 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 "Minix.h"
10
#include "CommonArgs.h"
11
#include "clang/Driver/Compilation.h"
12
#include "clang/Driver/Driver.h"
13
#include "clang/Driver/InputInfo.h"
14
#include "clang/Driver/Options.h"
15
#include "llvm/Option/ArgList.h"
16
#include "llvm/Support/VirtualFileSystem.h"
17
18
using namespace clang::driver;
19
using namespace clang;
20
using namespace llvm::opt;
21
22
void tools::minix::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
23
                                           const InputInfo &Output,
24
                                           const InputInfoList &Inputs,
25
                                           const ArgList &Args,
26
0
                                           const char *LinkingOutput) const {
27
0
  claimNoWarnArgs(Args);
28
0
  ArgStringList CmdArgs;
29
30
0
  Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
31
32
0
  CmdArgs.push_back("-o");
33
0
  CmdArgs.push_back(Output.getFilename());
34
35
0
  for (const auto &II : Inputs)
36
0
    CmdArgs.push_back(II.getFilename());
37
38
0
  const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as"));
39
0
  C.addCommand(std::make_unique<Command>(JA, *this,
40
0
                                         ResponseFileSupport::AtFileCurCP(),
41
0
                                         Exec, CmdArgs, Inputs, Output));
42
0
}
43
44
void tools::minix::Linker::ConstructJob(Compilation &C, const JobAction &JA,
45
                                 const InputInfo &Output,
46
                                 const InputInfoList &Inputs,
47
                                 const ArgList &Args,
48
1
                                 const char *LinkingOutput) const {
49
1
  const Driver &D = getToolChain().getDriver();
50
1
  ArgStringList CmdArgs;
51
52
1
  if (Output.isFilename()) {
53
1
    CmdArgs.push_back("-o");
54
1
    CmdArgs.push_back(Output.getFilename());
55
1
  } else {
56
0
    assert(Output.isNothing() && "Invalid output.");
57
0
  }
58
59
1
  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
60
1
                   options::OPT_r)) {
61
0
    CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crt1.o")));
62
0
    CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crti.o")));
63
0
    CmdArgs.push_back(
64
0
        Args.MakeArgString(getToolChain().GetFilePath("crtbegin.o")));
65
0
    CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crtn.o")));
66
0
  }
67
68
1
  Args.AddAllArgs(CmdArgs,
69
1
                  {options::OPT_L, options::OPT_T_Group, options::OPT_e});
70
71
1
  AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
72
73
1
  getToolChain().addProfileRTLibs(Args, CmdArgs);
74
75
1
  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
76
1
                   options::OPT_r)) {
77
0
    if (D.CCCIsCXX()) {
78
0
      if (getToolChain().ShouldLinkCXXStdlib(Args))
79
0
        getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
80
0
      CmdArgs.push_back("-lm");
81
0
    }
82
0
  }
83
84
1
  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
85
1
                   options::OPT_r)) {
86
0
    if (Args.hasArg(options::OPT_pthread))
87
0
      CmdArgs.push_back("-lpthread");
88
0
    CmdArgs.push_back("-lc");
89
0
    CmdArgs.push_back("-lCompilerRT-Generic");
90
0
    CmdArgs.push_back("-L/usr/pkg/compiler-rt/lib");
91
0
    CmdArgs.push_back(
92
0
        Args.MakeArgString(getToolChain().GetFilePath("crtend.o")));
93
0
  }
94
95
1
  const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath());
96
1
  C.addCommand(std::make_unique<Command>(JA, *this,
97
1
                                         ResponseFileSupport::AtFileCurCP(),
98
1
                                         Exec, CmdArgs, Inputs, Output));
99
1
}
100
101
/// Minix - Minix tool chain which can call as(1) and ld(1) directly.
102
103
toolchains::Minix::Minix(const Driver &D, const llvm::Triple &Triple,
104
                         const ArgList &Args)
105
1
    : Generic_ELF(D, Triple, Args) {
106
1
  getFilePaths().push_back(getDriver().Dir + "/../lib");
107
1
  getFilePaths().push_back("/usr/lib");
108
1
}
109
110
0
Tool *toolchains::Minix::buildAssembler() const {
111
0
  return new tools::minix::Assembler(*this);
112
0
}
113
114
1
Tool *toolchains::Minix::buildLinker() const {
115
1
  return new tools::minix::Linker(*this);
116
1
}