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