1 //===--- VE.cpp - VE 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 "VEToolchain.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 #include "llvm/Support/FileSystem.h"
16 #include "llvm/Support/Path.h"
17 #include <cstdlib> // ::getenv
18
19 using namespace clang::driver;
20 using namespace clang::driver::toolchains;
21 using namespace clang;
22 using namespace llvm::opt;
23
24 /// VE tool chain
VEToolChain(const Driver & D,const llvm::Triple & Triple,const ArgList & Args)25 VEToolChain::VEToolChain(const Driver &D, const llvm::Triple &Triple,
26 const ArgList &Args)
27 : Linux(D, Triple, Args) {
28 getProgramPaths().push_back("/opt/nec/ve/bin");
29 // ProgramPaths are found via 'PATH' environment variable.
30
31 // default file paths are:
32 // ${RESOURCEDIR}/lib/linux/ve (== getArchSpecificLibPath)
33 // /lib/../lib64
34 // /usr/lib/../lib64
35 // ${BINPATH}/../lib
36 // /lib
37 // /usr/lib
38 //
39 // These are OK for host, but no go for VE. So, defines them all
40 // from scratch here.
41 getFilePaths().clear();
42 getFilePaths().push_back(getArchSpecificLibPath());
43 getFilePaths().push_back(computeSysRoot() + "/opt/nec/ve/lib");
44 }
45
buildAssembler() const46 Tool *VEToolChain::buildAssembler() const {
47 return new tools::gnutools::Assembler(*this);
48 }
49
buildLinker() const50 Tool *VEToolChain::buildLinker() const {
51 return new tools::gnutools::Linker(*this);
52 }
53
isPICDefault() const54 bool VEToolChain::isPICDefault() const { return false; }
55
isPIEDefault() const56 bool VEToolChain::isPIEDefault() const { return false; }
57
isPICDefaultForced() const58 bool VEToolChain::isPICDefaultForced() const { return false; }
59
SupportsProfiling() const60 bool VEToolChain::SupportsProfiling() const { return false; }
61
hasBlocksRuntime() const62 bool VEToolChain::hasBlocksRuntime() const { return false; }
63
AddClangSystemIncludeArgs(const ArgList & DriverArgs,ArgStringList & CC1Args) const64 void VEToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
65 ArgStringList &CC1Args) const {
66 if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
67 return;
68
69 if (DriverArgs.hasArg(options::OPT_nobuiltininc) &&
70 DriverArgs.hasArg(options::OPT_nostdlibinc))
71 return;
72
73 if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
74 SmallString<128> P(getDriver().ResourceDir);
75 llvm::sys::path::append(P, "include");
76 addSystemInclude(DriverArgs, CC1Args, P);
77 }
78
79 if (!DriverArgs.hasArg(options::OPT_nostdlibinc)) {
80 if (const char *cl_include_dir = getenv("NCC_C_INCLUDE_PATH")) {
81 SmallVector<StringRef, 4> Dirs;
82 const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'};
83 StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr));
84 ArrayRef<StringRef> DirVec(Dirs);
85 addSystemIncludes(DriverArgs, CC1Args, DirVec);
86 } else {
87 addSystemInclude(DriverArgs, CC1Args,
88 getDriver().SysRoot + "/opt/nec/ve/include");
89 }
90 }
91 }
92
addClangTargetOptions(const ArgList & DriverArgs,ArgStringList & CC1Args,Action::OffloadKind) const93 void VEToolChain::addClangTargetOptions(const ArgList &DriverArgs,
94 ArgStringList &CC1Args,
95 Action::OffloadKind) const {
96 CC1Args.push_back("-nostdsysteminc");
97 bool UseInitArrayDefault = true;
98 if (!DriverArgs.hasFlag(options::OPT_fuse_init_array,
99 options::OPT_fno_use_init_array, UseInitArrayDefault))
100 CC1Args.push_back("-fno-use-init-array");
101 }
102
AddClangCXXStdlibIncludeArgs(const ArgList & DriverArgs,ArgStringList & CC1Args) const103 void VEToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
104 ArgStringList &CC1Args) const {
105 if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc) ||
106 DriverArgs.hasArg(options::OPT_nostdlibinc) ||
107 DriverArgs.hasArg(options::OPT_nostdincxx))
108 return;
109 if (const char *cl_include_dir = getenv("NCC_CPLUS_INCLUDE_PATH")) {
110 SmallVector<StringRef, 4> Dirs;
111 const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'};
112 StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr));
113 ArrayRef<StringRef> DirVec(Dirs);
114 addSystemIncludes(DriverArgs, CC1Args, DirVec);
115 } else {
116 SmallString<128> P(getDriver().ResourceDir);
117 llvm::sys::path::append(P, "include/c++/v1");
118 addSystemInclude(DriverArgs, CC1Args, P);
119 }
120 }
121
AddCXXStdlibLibArgs(const ArgList & Args,ArgStringList & CmdArgs) const122 void VEToolChain::AddCXXStdlibLibArgs(const ArgList &Args,
123 ArgStringList &CmdArgs) const {
124 assert((GetCXXStdlibType(Args) == ToolChain::CST_Libcxx) &&
125 "Only -lc++ (aka libxx) is supported in this toolchain.");
126
127 tools::addArchSpecificRPath(*this, Args, CmdArgs);
128
129 CmdArgs.push_back("-lc++");
130 CmdArgs.push_back("-lc++abi");
131 CmdArgs.push_back("-lunwind");
132 // libc++ requires -lpthread under glibc environment
133 CmdArgs.push_back("-lpthread");
134 // libunwind requires -ldl under glibc environment
135 CmdArgs.push_back("-ldl");
136 }
137
138 llvm::ExceptionHandling
GetExceptionModel(const ArgList & Args) const139 VEToolChain::GetExceptionModel(const ArgList &Args) const {
140 // VE uses SjLj exceptions.
141 return llvm::ExceptionHandling::SjLj;
142 }
143