Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/lib/Driver/ToolChains/Ananas.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- Ananas.cpp - Ananas 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 "Ananas.h"
10
#include "InputInfo.h"
11
#include "CommonArgs.h"
12
#include "clang/Driver/Compilation.h"
13
#include "clang/Driver/Driver.h"
14
#include "clang/Driver/Options.h"
15
#include "llvm/ADT/SmallString.h"
16
#include "llvm/Option/ArgList.h"
17
#include "llvm/Support/Path.h"
18
19
using namespace clang::driver;
20
using namespace clang::driver::tools;
21
using namespace clang::driver::toolchains;
22
using namespace clang;
23
using namespace llvm::opt;
24
25
void ananas::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
26
                                     const InputInfo &Output,
27
                                     const InputInfoList &Inputs,
28
                                     const ArgList &Args,
29
0
                                     const char *LinkingOutput) const {
30
0
  claimNoWarnArgs(Args);
31
0
  ArgStringList CmdArgs;
32
0
33
0
  Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
34
0
35
0
  CmdArgs.push_back("-o");
36
0
  CmdArgs.push_back(Output.getFilename());
37
0
38
0
  for (const auto &II : Inputs)
39
0
    CmdArgs.push_back(II.getFilename());
40
0
41
0
  const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as"));
42
0
  C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
43
0
}
44
45
void ananas::Linker::ConstructJob(Compilation &C, const JobAction &JA,
46
                                  const InputInfo &Output,
47
                                  const InputInfoList &Inputs,
48
                                  const ArgList &Args,
49
2
                                  const char *LinkingOutput) const {
50
2
  const ToolChain &ToolChain = getToolChain();
51
2
  const Driver &D = ToolChain.getDriver();
52
2
  ArgStringList CmdArgs;
53
2
54
2
  // Silence warning for "clang -g foo.o -o foo"
55
2
  Args.ClaimAllArgs(options::OPT_g_Group);
56
2
  // and "clang -emit-llvm foo.o -o foo"
57
2
  Args.ClaimAllArgs(options::OPT_emit_llvm);
58
2
  // and for "clang -w foo.o -o foo". Other warning options are already
59
2
  // handled somewhere else.
60
2
  Args.ClaimAllArgs(options::OPT_w);
61
2
62
2
  if (!D.SysRoot.empty())
63
2
    CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
64
2
65
2
  if (Args.hasArg(options::OPT_static)) {
66
1
    CmdArgs.push_back("-Bstatic");
67
1
  } else {
68
1
    if (Args.hasArg(options::OPT_rdynamic))
69
0
      CmdArgs.push_back("-export-dynamic");
70
1
    if (Args.hasArg(options::OPT_shared)) {
71
1
      CmdArgs.push_back("-Bshareable");
72
1
    } else {
73
0
      Args.AddAllArgs(CmdArgs, options::OPT_pie);
74
0
      CmdArgs.push_back("-dynamic-linker");
75
0
      CmdArgs.push_back("/lib/ld-ananas.so");
76
0
    }
77
1
  }
78
2
79
2
  if (Output.isFilename()) {
80
2
    CmdArgs.push_back("-o");
81
2
    CmdArgs.push_back(Output.getFilename());
82
2
  } else {
83
0
    assert(Output.isNothing() && "Invalid output.");
84
0
  }
85
2
86
2
  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
87
2
    if (!Args.hasArg(options::OPT_shared)) {
88
1
      CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crt0.o")));
89
1
    }
90
2
    CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crti.o")));
91
2
    if (Args.hasArg(options::OPT_shared) || 
Args.hasArg(options::OPT_pie)1
) {
92
1
      CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtbeginS.o")));
93
1
    } else {
94
1
      CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtbegin.o")));
95
1
    }
96
2
  }
97
2
98
2
  Args.AddAllArgs(CmdArgs, options::OPT_L);
99
2
  ToolChain.AddFilePathLibArgs(Args, CmdArgs);
100
2
  Args.AddAllArgs(CmdArgs,
101
2
                  {options::OPT_T_Group, options::OPT_e, options::OPT_s,
102
2
                   options::OPT_t, options::OPT_Z_Flag, options::OPT_r});
103
2
104
2
  if (D.isUsingLTO()) {
105
0
    assert(!Inputs.empty() && "Must have at least one input.");
106
0
    AddGoldPlugin(ToolChain, Args, CmdArgs, Output, Inputs[0],
107
0
                  D.getLTOMode() == LTOK_Thin);
108
0
  }
109
2
110
2
  AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
111
2
112
2
  if (ToolChain.ShouldLinkCXXStdlib(Args))
113
0
    ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
114
2
  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs))
115
2
    CmdArgs.push_back("-lc");
116
2
117
2
  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
118
2
    if (Args.hasArg(options::OPT_shared) || 
Args.hasArg(options::OPT_pie)1
)
119
1
      CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtendS.o")));
120
1
    else
121
1
      CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtend.o")));
122
2
    CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtn.o")));
123
2
  }
124
2
125
2
  const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath());
126
2
  C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
127
2
}
128
129
// Ananas - Ananas tool chain which can call as(1) and ld(1) directly.
130
131
Ananas::Ananas(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
132
2
    : Generic_ELF(D, Triple, Args) {
133
2
  getFilePaths().push_back(getDriver().SysRoot + "/usr/lib");
134
2
}
135
136
0
Tool *Ananas::buildAssembler() const {
137
0
  return new tools::ananas::Assembler(*this);
138
0
}
139
140
2
Tool *Ananas::buildLinker() const { return new tools::ananas::Linker(*this); }