Coverage Report

Created: 2017-10-03 07:32

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