Coverage Report

Created: 2020-03-31 06:27

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Driver/ToolChains/AIX.cpp
Line
Count
Source (jump to first uncovered line)
1
//===--- AIX.cpp - AIX 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 "AIX.h"
10
#include "Arch/PPC.h"
11
#include "CommonArgs.h"
12
#include "clang/Driver/Compilation.h"
13
#include "clang/Driver/Options.h"
14
#include "clang/Driver/SanitizerArgs.h"
15
#include "llvm/Option/ArgList.h"
16
17
using AIX = clang::driver::toolchains::AIX;
18
using namespace clang::driver;
19
using namespace clang::driver::tools;
20
21
using namespace llvm::opt;
22
23
void aix::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
24
                                  const InputInfo &Output,
25
                                  const InputInfoList &Inputs,
26
                                  const ArgList &Args,
27
17
                                  const char *LinkingOutput) const {
28
17
  ArgStringList CmdArgs;
29
17
30
17
  const bool IsArch32Bit = getToolChain().getTriple().isArch32Bit();
31
17
  const bool IsArch64Bit = getToolChain().getTriple().isArch64Bit();
32
17
  // Only support 32 and 64 bit.
33
17
  if (!IsArch32Bit && 
!IsArch64Bit6
)
34
17
    
llvm_unreachable0
("Unsupported bit width value.");
35
17
36
17
  // Specify the mode in which the as(1) command operates.
37
17
  if (IsArch32Bit) {
38
11
    CmdArgs.push_back("-a32");
39
11
  } else {
40
6
    // Must be 64-bit, otherwise asserted already.
41
6
    CmdArgs.push_back("-a64");
42
6
  }
43
17
44
17
  // Accept an undefined symbol as an extern so that an error message is not
45
17
  // displayed. Otherwise, undefined symbols are flagged with error messages.
46
17
  // FIXME: This should be removed when the assembly generation from the
47
17
  // compiler is able to write externs properly.
48
17
  CmdArgs.push_back("-u");
49
17
50
17
  // Accept any mixture of instructions.
51
17
  // On Power for AIX and Linux, this behaviour matches that of GCC for both the
52
17
  // user-provided assembler source case and the compiler-produced assembler
53
17
  // source case. Yet XL with user-provided assembler source would not add this.
54
17
  CmdArgs.push_back("-many");
55
17
56
17
  Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
57
17
58
17
  // Specify assembler output file.
59
17
  assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
60
17
  if (Output.isFilename()) {
61
17
    CmdArgs.push_back("-o");
62
17
    CmdArgs.push_back(Output.getFilename());
63
17
  }
64
17
65
17
  // Specify assembler input file.
66
17
  // The system assembler on AIX takes exactly one input file. The driver is
67
17
  // expected to invoke as(1) separately for each assembler source input file.
68
17
  if (Inputs.size() != 1)
69
17
    
llvm_unreachable0
("Invalid number of input files.");
70
17
  const InputInfo &II = Inputs[0];
71
17
  assert((II.isFilename() || II.isNothing()) && "Invalid input.");
72
17
  if (II.isFilename())
73
17
    CmdArgs.push_back(II.getFilename());
74
17
75
17
  const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as"));
76
17
  C.addCommand(std::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
77
17
}
78
79
void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA,
80
                               const InputInfo &Output,
81
                               const InputInfoList &Inputs, const ArgList &Args,
82
10
                               const char *LinkingOutput) const {
83
10
  const AIX &ToolChain = static_cast<const AIX &>(getToolChain());
84
10
  ArgStringList CmdArgs;
85
10
86
10
  const bool IsArch32Bit = ToolChain.getTriple().isArch32Bit();
87
10
  const bool IsArch64Bit = ToolChain.getTriple().isArch64Bit();
88
10
  // Only support 32 and 64 bit.
89
10
  if (!(IsArch32Bit || 
IsArch64Bit4
))
90
10
    
llvm_unreachable0
("Unsupported bit width value.");
91
10
92
10
  // Force static linking when "-static" is present.
93
10
  if (Args.hasArg(options::OPT_static))
94
1
    CmdArgs.push_back("-bnso");
95
10
96
10
  // Specify linker output file.
97
10
  assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
98
10
  if (Output.isFilename()) {
99
10
    CmdArgs.push_back("-o");
100
10
    CmdArgs.push_back(Output.getFilename());
101
10
  }
102
10
103
10
  // Set linking mode (i.e., 32/64-bit) and the address of
104
10
  // text and data sections based on arch bit width.
105
10
  if (IsArch32Bit) {
106
6
    CmdArgs.push_back("-b32");
107
6
    CmdArgs.push_back("-bpT:0x10000000");
108
6
    CmdArgs.push_back("-bpD:0x20000000");
109
6
  } else {
110
4
    // Must be 64-bit, otherwise asserted already.
111
4
    CmdArgs.push_back("-b64");
112
4
    CmdArgs.push_back("-bpT:0x100000000");
113
4
    CmdArgs.push_back("-bpD:0x110000000");
114
4
  }
115
10
116
10
  auto getCrt0Basename = [&Args, IsArch32Bit] {
117
9
    // Enable gprofiling when "-pg" is specified.
118
9
    if (Args.hasArg(options::OPT_pg))
119
1
      return IsArch32Bit ? 
"gcrt0.o"0
: "gcrt0_64.o";
120
8
    // Enable profiling when "-p" is specified.
121
8
    else if (Args.hasArg(options::OPT_p))
122
1
      return IsArch32Bit ? "mcrt0.o" : 
"mcrt0_64.o"0
;
123
7
    else
124
7
      return IsArch32Bit ? 
"crt0.o"4
:
"crt0_64.o"3
;
125
9
  };
126
10
127
10
  if (!Args.hasArg(options::OPT_nostdlib)) {
128
9
    CmdArgs.push_back(
129
9
        Args.MakeArgString(ToolChain.GetFilePath(getCrt0Basename())));
130
9
  }
131
10
132
10
  // Specify linker input file(s).
133
10
  AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
134
10
135
10
  // Add directory to library search path.
136
10
  Args.AddAllArgs(CmdArgs, options::OPT_L);
137
10
  ToolChain.AddFilePathLibArgs(Args, CmdArgs);
138
10
139
10
  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
140
8
    // Support POSIX threads if "-pthreads" or "-pthread" is present.
141
8
    if (Args.hasArg(options::OPT_pthreads, options::OPT_pthread))
142
2
      CmdArgs.push_back("-lpthreads");
143
8
144
8
    CmdArgs.push_back("-lc");
145
8
  }
146
10
147
10
  const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath());
148
10
  C.addCommand(std::make_unique<Command>(JA, *this, Exec, CmdArgs, Inputs));
149
10
}
150
151
/// AIX - AIX tool chain which can call as(1) and ld(1) directly.
152
AIX::AIX(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
153
17
    : ToolChain(D, Triple, Args) {
154
17
  getFilePaths().push_back(getDriver().SysRoot + "/usr/lib");
155
17
}
156
157
15
auto AIX::buildAssembler() const -> Tool * { return new aix::Assembler(*this); }
158
159
10
auto AIX::buildLinker() const -> Tool * { return new aix::Linker(*this); }