clang 22.0.0git
VEToolchain.cpp
Go to the documentation of this file.
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"
12#include "clang/Driver/Driver.h"
14#include "llvm/Option/ArgList.h"
15#include "llvm/Support/Path.h"
16#include <cstdlib> // ::getenv
17
18using namespace clang::driver;
19using namespace clang::driver::toolchains;
20using namespace clang;
21using namespace llvm::opt;
22
23/// VE tool chain
24VEToolChain::VEToolChain(const Driver &D, const llvm::Triple &Triple,
25 const ArgList &Args)
26 : Linux(D, Triple, Args) {
27 getProgramPaths().push_back("/opt/nec/ve/bin");
28 // ProgramPaths are found via 'PATH' environment variable.
29
30 // Default library paths are following:
31 // ${RESOURCEDIR}/lib/ve-unknown-linux-gnu,
32 // These are OK.
33
34 // Default file paths are following:
35 // ${RESOURCEDIR}/lib/ve-unknown-linux-gnu, (== getArchSpecificLibPaths)
36 // ${RESOURCEDIR}/lib/linux/ve, (== getArchSpecificLibPaths)
37 // /lib/../lib64,
38 // /usr/lib/../lib64,
39 // ${BINPATH}/../lib,
40 // /lib,
41 // /usr/lib,
42 // These are OK for host, but no go for VE.
43
44 // Define file paths from scratch here.
45 getFilePaths().clear();
46
47 // Add library directories:
48 // ${BINPATH}/../lib/ve-unknown-linux-gnu, (== getStdlibPath)
49 // ${RESOURCEDIR}/lib/ve-unknown-linux-gnu, (== getArchSpecificLibPaths)
50 // ${RESOURCEDIR}/lib/linux/ve, (== getArchSpecificLibPaths)
51 // ${SYSROOT}/opt/nec/ve/lib,
52 if (std::optional<std::string> Path = getStdlibPath())
53 getFilePaths().push_back(std::move(*Path));
54 for (const auto &Path : getArchSpecificLibPaths())
55 getFilePaths().push_back(Path);
56 getFilePaths().push_back(computeSysRoot() + "/opt/nec/ve/lib");
57}
58
60 return new tools::gnutools::Assembler(*this);
61}
62
64 return new tools::gnutools::Linker(*this);
65}
66
67bool VEToolChain::isPICDefault() const { return false; }
68
69bool VEToolChain::isPIEDefault(const llvm::opt::ArgList &Args) const {
70 return false;
71}
72
73bool VEToolChain::isPICDefaultForced() const { return false; }
74
75bool VEToolChain::SupportsProfiling() const { return false; }
76
77bool VEToolChain::hasBlocksRuntime() const { return false; }
78
79void VEToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
80 ArgStringList &CC1Args) const {
81 if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
82 return;
83
84 if (DriverArgs.hasArg(options::OPT_nobuiltininc) &&
85 DriverArgs.hasArg(options::OPT_nostdlibinc))
86 return;
87
88 if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
89 SmallString<128> P(getDriver().ResourceDir);
90 llvm::sys::path::append(P, "include");
91 addSystemInclude(DriverArgs, CC1Args, P);
92 }
93
94 if (!DriverArgs.hasArg(options::OPT_nostdlibinc)) {
95 if (const char *cl_include_dir = getenv("NCC_C_INCLUDE_PATH")) {
97 const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'};
98 StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr));
99 ArrayRef<StringRef> DirVec(Dirs);
100 addSystemIncludes(DriverArgs, CC1Args, DirVec);
101 } else {
102 addSystemInclude(DriverArgs, CC1Args,
103 getDriver().SysRoot + "/opt/nec/ve/include");
104 }
105 }
106}
107
108void VEToolChain::addClangTargetOptions(const ArgList &DriverArgs,
109 ArgStringList &CC1Args,
110 Action::OffloadKind) const {
111 CC1Args.push_back("-nostdsysteminc");
112 bool UseInitArrayDefault = true;
113 if (!DriverArgs.hasFlag(options::OPT_fuse_init_array,
114 options::OPT_fno_use_init_array, UseInitArrayDefault))
115 CC1Args.push_back("-fno-use-init-array");
116}
117
118void VEToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
119 ArgStringList &CC1Args) const {
120 if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc) ||
121 DriverArgs.hasArg(options::OPT_nostdlibinc) ||
122 DriverArgs.hasArg(options::OPT_nostdincxx))
123 return;
124 if (const char *cl_include_dir = getenv("NCC_CPLUS_INCLUDE_PATH")) {
126 const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator, '\0'};
127 StringRef(cl_include_dir).split(Dirs, StringRef(EnvPathSeparatorStr));
128 ArrayRef<StringRef> DirVec(Dirs);
129 addSystemIncludes(DriverArgs, CC1Args, DirVec);
130 } else {
131 // Add following paths for multiple target installation.
132 // ${INSTALLDIR}/include/ve-unknown-linux-gnu/c++/v1,
133 // ${INSTALLDIR}/include/c++/v1,
134 addLibCxxIncludePaths(DriverArgs, CC1Args);
135 }
136}
137
138void VEToolChain::AddCXXStdlibLibArgs(const ArgList &Args,
139 ArgStringList &CmdArgs) const {
140 assert((GetCXXStdlibType(Args) == ToolChain::CST_Libcxx) &&
141 "Only -lc++ (aka libxx) is supported in this toolchain.");
142
143 tools::addArchSpecificRPath(*this, Args, CmdArgs);
144
145 // Add paths for libc++.so and other shared libraries.
146 if (std::optional<std::string> Path = getStdlibPath()) {
147 CmdArgs.push_back("-rpath");
148 CmdArgs.push_back(Args.MakeArgString(*Path));
149 }
150
151 CmdArgs.push_back("-lc++");
152 if (Args.hasArg(options::OPT_fexperimental_library))
153 CmdArgs.push_back("-lc++experimental");
154 CmdArgs.push_back("-lc++abi");
155 CmdArgs.push_back("-lunwind");
156 // libc++ requires -lpthread under glibc environment
157 CmdArgs.push_back("-lpthread");
158 // libunwind requires -ldl under glibc environment
159 CmdArgs.push_back("-ldl");
160}
161
162llvm::ExceptionHandling
163VEToolChain::GetExceptionModel(const ArgList &Args) const {
164 // VE uses SjLj exceptions.
165 return llvm::ExceptionHandling::SjLj;
166}
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition Driver.h:99
static void addSystemInclude(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const Twine &Path)
Utility function to add a system include directory to CC1 arguments.
std::optional< std::string > getStdlibPath() const
path_list & getFilePaths()
Definition ToolChain.h:295
const Driver & getDriver() const
Definition ToolChain.h:253
path_list & getProgramPaths()
Definition ToolChain.h:298
static void addSystemIncludes(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, ArrayRef< StringRef > Paths)
Utility function to add a list of system include directories to CC1.
virtual path_list getArchSpecificLibPaths() const
Tool - Information on a specific compilation tool.
Definition Tool.h:32
virtual void addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
Definition Gnu.cpp:3211
std::string computeSysRoot() const override
Return the sysroot, possibly searching for a default sysroot using target-specific logic.
Definition Linux.cpp:395
Linux(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
Definition Linux.cpp:212
llvm::ExceptionHandling GetExceptionModel(const llvm::opt::ArgList &Args) const override
GetExceptionModel - Return the tool chain exception model.
VEToolChain(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
VE tool chain.
void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override
AddCXXStdlibLibArgs - Add the system specific linker arguments to use for the given C++ standard libr...
bool SupportsProfiling() const override
SupportsProfiling - Does this tool chain support -pg.
void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Add the clang cc1 arguments for system include paths.
CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override
Definition VEToolchain.h:51
bool isPICDefaultForced() const override
Tests whether this toolchain forces its default for PIC, PIE or non-PIC.
bool isPIEDefault(const llvm::opt::ArgList &Args) const override
Test whether this toolchain defaults to PIE.
bool hasBlocksRuntime() const override
hasBlocksRuntime - Given that the user is compiling with -fblocks, does this tool chain guarantee the...
Tool * buildLinker() const override
Tool * buildAssembler() const override
void AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set the include paths to use for...
void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, Action::OffloadKind DeviceOffloadKind) const override
Add options that need to be passed to cc1 for this target.
bool isPICDefault() const override
Test whether this toolchain defaults to PIC.
void addArchSpecificRPath(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
The JSON file list parser is used to communicate input to InstallAPI.