Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/lib/Driver/ToolChains/DragonFly.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- DragonFly.cpp - DragonFly 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 "DragonFly.h"
10
#include "CommonArgs.h"
11
#include "clang/Driver/Compilation.h"
12
#include "clang/Driver/Driver.h"
13
#include "clang/Driver/Options.h"
14
#include "llvm/Option/ArgList.h"
15
16
using namespace clang::driver;
17
using namespace clang::driver::tools;
18
using namespace clang::driver::toolchains;
19
using namespace clang;
20
using namespace llvm::opt;
21
22
/// DragonFly Tools
23
24
// For now, DragonFly Assemble does just about the same as for
25
// FreeBSD, but this may change soon.
26
void dragonfly::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
27
                                        const InputInfo &Output,
28
                                        const InputInfoList &Inputs,
29
                                        const ArgList &Args,
30
0
                                        const char *LinkingOutput) const {
31
0
  claimNoWarnArgs(Args);
32
0
  ArgStringList CmdArgs;
33
0
34
0
  // When building 32-bit code on DragonFly/pc64, we have to explicitly
35
0
  // instruct as in the base system to assemble 32-bit code.
36
0
  if (getToolChain().getArch() == llvm::Triple::x86)
37
0
    CmdArgs.push_back("--32");
38
0
39
0
  Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
40
0
41
0
  CmdArgs.push_back("-o");
42
0
  CmdArgs.push_back(Output.getFilename());
43
0
44
0
  for (const auto &II : Inputs)
45
0
    CmdArgs.push_back(II.getFilename());
46
0
47
0
  const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as"));
48
0
  C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
49
0
}
50
51
void dragonfly::Linker::ConstructJob(Compilation &C, const JobAction &JA,
52
                                     const InputInfo &Output,
53
                                     const InputInfoList &Inputs,
54
                                     const ArgList &Args,
55
1
                                     const char *LinkingOutput) const {
56
1
  const Driver &D = getToolChain().getDriver();
57
1
  ArgStringList CmdArgs;
58
1
59
1
  if (!D.SysRoot.empty())
60
0
    CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
61
1
62
1
  CmdArgs.push_back("--eh-frame-hdr");
63
1
  if (Args.hasArg(options::OPT_static)) {
64
0
    CmdArgs.push_back("-Bstatic");
65
1
  } else {
66
1
    if (Args.hasArg(options::OPT_rdynamic))
67
0
      CmdArgs.push_back("-export-dynamic");
68
1
    if (Args.hasArg(options::OPT_shared))
69
0
      CmdArgs.push_back("-Bshareable");
70
1
    else {
71
1
      CmdArgs.push_back("-dynamic-linker");
72
1
      CmdArgs.push_back("/usr/libexec/ld-elf.so.2");
73
1
    }
74
1
    CmdArgs.push_back("--hash-style=gnu");
75
1
    CmdArgs.push_back("--enable-new-dtags");
76
1
  }
77
1
78
1
  // When building 32-bit code on DragonFly/pc64, we have to explicitly
79
1
  // instruct ld in the base system to link 32-bit code.
80
1
  if (getToolChain().getArch() == llvm::Triple::x86) {
81
0
    CmdArgs.push_back("-m");
82
0
    CmdArgs.push_back("elf_i386");
83
0
  }
84
1
85
1
  if (Output.isFilename()) {
86
1
    CmdArgs.push_back("-o");
87
1
    CmdArgs.push_back(Output.getFilename());
88
1
  } else {
89
0
    assert(Output.isNothing() && "Invalid output.");
90
0
  }
91
1
92
1
  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
93
1
    if (!Args.hasArg(options::OPT_shared)) {
94
1
      if (Args.hasArg(options::OPT_pg))
95
0
        CmdArgs.push_back(
96
0
            Args.MakeArgString(getToolChain().GetFilePath("gcrt1.o")));
97
1
      else {
98
1
        if (Args.hasArg(options::OPT_pie))
99
0
          CmdArgs.push_back(
100
0
              Args.MakeArgString(getToolChain().GetFilePath("Scrt1.o")));
101
1
        else
102
1
          CmdArgs.push_back(
103
1
              Args.MakeArgString(getToolChain().GetFilePath("crt1.o")));
104
1
      }
105
1
    }
106
1
    CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crti.o")));
107
1
    if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie))
108
0
      CmdArgs.push_back(
109
0
          Args.MakeArgString(getToolChain().GetFilePath("crtbeginS.o")));
110
1
    else
111
1
      CmdArgs.push_back(
112
1
          Args.MakeArgString(getToolChain().GetFilePath("crtbegin.o")));
113
1
  }
114
1
115
1
  Args.AddAllArgs(CmdArgs,
116
1
                  {options::OPT_L, options::OPT_T_Group, options::OPT_e});
117
1
118
1
  AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
119
1
120
1
  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
121
1
    CmdArgs.push_back("-L/usr/lib/gcc50");
122
1
123
1
    if (!Args.hasArg(options::OPT_static)) {
124
1
      CmdArgs.push_back("-rpath");
125
1
      CmdArgs.push_back("/usr/lib/gcc50");
126
1
    }
127
1
128
1
    if (D.CCCIsCXX()) {
129
0
      if (getToolChain().ShouldLinkCXXStdlib(Args))
130
0
        getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
131
0
      CmdArgs.push_back("-lm");
132
0
    }
133
1
134
1
    if (Args.hasArg(options::OPT_pthread))
135
0
      CmdArgs.push_back("-lpthread");
136
1
137
1
    if (!Args.hasArg(options::OPT_nolibc)) {
138
1
      CmdArgs.push_back("-lc");
139
1
    }
140
1
141
1
    if (Args.hasArg(options::OPT_static) ||
142
1
        Args.hasArg(options::OPT_static_libgcc)) {
143
0
        CmdArgs.push_back("-lgcc");
144
0
        CmdArgs.push_back("-lgcc_eh");
145
1
    } else {
146
1
      if (Args.hasArg(options::OPT_shared_libgcc)) {
147
0
          CmdArgs.push_back("-lgcc_pic");
148
0
          if (!Args.hasArg(options::OPT_shared))
149
0
            CmdArgs.push_back("-lgcc");
150
1
      } else {
151
1
          CmdArgs.push_back("-lgcc");
152
1
          CmdArgs.push_back("--as-needed");
153
1
          CmdArgs.push_back("-lgcc_pic");
154
1
          CmdArgs.push_back("--no-as-needed");
155
1
      }
156
1
    }
157
1
  }
158
1
159
1
  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
160
1
    if (Args.hasArg(options::OPT_shared) || Args.hasArg(options::OPT_pie))
161
0
      CmdArgs.push_back(
162
0
          Args.MakeArgString(getToolChain().GetFilePath("crtendS.o")));
163
1
    else
164
1
      CmdArgs.push_back(
165
1
          Args.MakeArgString(getToolChain().GetFilePath("crtend.o")));
166
1
    CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crtn.o")));
167
1
  }
168
1
169
1
  getToolChain().addProfileRTLibs(Args, CmdArgs);
170
1
171
1
  const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath());
172
1
  C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
173
1
}
174
175
/// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly.
176
177
DragonFly::DragonFly(const Driver &D, const llvm::Triple &Triple,
178
                     const ArgList &Args)
179
2
    : Generic_ELF(D, Triple, Args) {
180
2
181
2
  // Path mangling to find libexec
182
2
  getProgramPaths().push_back(getDriver().getInstalledDir());
183
2
  if (getDriver().getInstalledDir() != getDriver().Dir)
184
0
    getProgramPaths().push_back(getDriver().Dir);
185
2
186
2
  getFilePaths().push_back(getDriver().Dir + "/../lib");
187
2
  getFilePaths().push_back("/usr/lib");
188
2
  getFilePaths().push_back("/usr/lib/gcc50");
189
2
}
190
191
0
Tool *DragonFly::buildAssembler() const {
192
0
  return new tools::dragonfly::Assembler(*this);
193
0
}
194
195
1
Tool *DragonFly::buildLinker() const {
196
1
  return new tools::dragonfly::Linker(*this);
197
1
}