clang 22.0.0git
Cygwin.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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 "Cygwin.h"
10#include "clang/Config/config.h"
12#include "clang/Driver/Driver.h"
14#include "llvm/Support/Path.h"
15#include "llvm/Support/VirtualFileSystem.h"
16
17using namespace clang::driver;
18using namespace clang::driver::toolchains;
19using namespace clang;
20using namespace llvm::opt;
21
23
24Cygwin::Cygwin(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
25 : Generic_GCC(D, Triple, Args) {
26 GCCInstallation.init(Triple, Args);
27 std::string SysRoot = computeSysRoot();
29
31
32 path_list &Paths = getFilePaths();
33
34 Generic_GCC::AddMultiarchPaths(D, SysRoot, "lib", Paths);
35
36 // Similar to the logic for GCC above, if we are currently running Clang
37 // inside of the requested system root, add its parent library path to those
38 // searched.
39 // FIXME: It's not clear whether we should use the driver's installed
40 // directory ('Dir' below) or the ResourceDir.
41 if (StringRef(D.Dir).starts_with(SysRoot))
42 addPathIfExists(D, D.Dir + "/../lib", Paths);
43
44 addPathIfExists(D, SysRoot + "/lib", Paths);
45 addPathIfExists(D, SysRoot + "/usr/lib", Paths);
46 addPathIfExists(D, SysRoot + "/usr/lib/w32api", Paths);
47}
48
49llvm::ExceptionHandling Cygwin::GetExceptionModel(const ArgList &Args) const {
50 if (getArch() == llvm::Triple::x86_64 || getArch() == llvm::Triple::aarch64 ||
51 getArch() == llvm::Triple::arm || getArch() == llvm::Triple::thumb)
52 return llvm::ExceptionHandling::WinEH;
53 return llvm::ExceptionHandling::DwarfCFI;
54}
55
56void Cygwin::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
57 ArgStringList &CC1Args) const {
58 const Driver &D = getDriver();
59 std::string SysRoot = computeSysRoot();
60
61 if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
62 return;
63
64 if (!DriverArgs.hasArg(options::OPT_nostdlibinc))
65 addSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/local/include");
66
67 if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
68 SmallString<128> P(D.ResourceDir);
69 llvm::sys::path::append(P, "include");
70 addSystemInclude(DriverArgs, CC1Args, P);
71 }
72
73 if (DriverArgs.hasArg(options::OPT_nostdlibinc))
74 return;
75
76 // Check for configure-time C include directories.
77 StringRef CIncludeDirs(C_INCLUDE_DIRS);
78 if (CIncludeDirs != "") {
80 CIncludeDirs.split(Dirs, ":");
81 for (StringRef Dir : Dirs) {
82 StringRef Prefix =
83 llvm::sys::path::is_absolute(Dir) ? "" : StringRef(SysRoot);
84 addExternCSystemInclude(DriverArgs, CC1Args, Prefix + Dir);
85 }
86 return;
87 }
88
89 // Lacking those, try to detect the correct set of system includes for the
90 // target triple.
91
92 AddMultilibIncludeArgs(DriverArgs, CC1Args);
93
94 // On systems using multiarch, add /usr/include/$triple before
95 // /usr/include.
96 std::string MultiarchIncludeDir = getTriple().str();
97 if (!MultiarchIncludeDir.empty() &&
98 D.getVFS().exists(SysRoot + "/usr/include/" + MultiarchIncludeDir))
99 addExternCSystemInclude(DriverArgs, CC1Args,
100 SysRoot + "/usr/include/" + MultiarchIncludeDir);
101
102 // Add an include of '/include' directly. This isn't provided by default by
103 // system GCCs, but is often used with cross-compiling GCCs, and harmless to
104 // add even when Clang is acting as-if it were a system compiler.
105 addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/include");
106
107 addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include");
108 addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include/w32api");
109}
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.
virtual std::string computeSysRoot() const
Return the sysroot, possibly searching for a default sysroot using target-specific logic.
static void addExternCSystemInclude(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const Twine &Path)
Utility function to add a system include directory with extern "C" semantics to CC1 arguments.
path_list & getFilePaths()
Definition ToolChain.h:295
llvm::Triple::ArchType getArch() const
Definition ToolChain.h:269
const Driver & getDriver() const
Definition ToolChain.h:253
path_list & getProgramPaths()
Definition ToolChain.h:298
const llvm::Triple & getTriple() const
Definition ToolChain.h:255
SmallVector< std::string, 16 > path_list
Definition ToolChain.h:94
llvm::ExceptionHandling GetExceptionModel(const llvm::opt::ArgList &Args) const override
GetExceptionModel - Return the tool chain exception model.
Definition Cygwin.cpp:49
void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Add the clang cc1 arguments for system include paths.
Definition Cygwin.cpp:56
Cygwin(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
Definition Cygwin.cpp:24
void PushPPaths(ToolChain::path_list &PPaths)
Definition Gnu.cpp:3072
Generic_GCC(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
Definition Gnu.cpp:2984
GCCInstallationDetector GCCInstallation
Definition Gnu.h:357
void AddMultilibIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
Definition Gnu.cpp:3168
void AddMultiarchPaths(const Driver &D, const std::string &SysRoot, const std::string &OSLibDir, path_list &Paths)
Definition Gnu.cpp:3153
void addPathIfExists(const Driver &D, const Twine &Path, ToolChain::path_list &Paths)
The JSON file list parser is used to communicate input to InstallAPI.