clang  15.0.0git
PPCLinux.cpp
Go to the documentation of this file.
1 //===-- PPCLinux.cpp - PowerPC 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 "PPCLinux.h"
10 #include "clang/Driver/Driver.h"
12 #include "clang/Driver/Options.h"
13 #include "llvm/Support/FileSystem.h"
14 #include "llvm/Support/Path.h"
15 
16 using namespace clang::driver;
17 using namespace clang::driver::toolchains;
18 using namespace llvm::opt;
19 using namespace llvm::sys;
20 
21 // Glibc older than 2.32 doesn't fully support IEEE float128. Here we check
22 // glibc version by looking at dynamic linker name.
23 static bool GlibcSupportsFloat128(const std::string &Linker) {
25 
26  // Resolve potential symlinks to linker.
27  if (fs::real_path(Linker, Path))
28  return false;
29  llvm::StringRef LinkerName =
30  path::filename(llvm::StringRef(Path.data(), Path.size()));
31 
32  // Since glibc 2.34, the installed .so file is not symlink anymore. But we can
33  // still safely assume it's newer than 2.32.
34  if (LinkerName.startswith("ld64.so"))
35  return true;
36 
37  if (!LinkerName.startswith("ld-2."))
38  return false;
39  unsigned Minor = (LinkerName[5] - '0') * 10 + (LinkerName[6] - '0');
40  if (Minor < 32)
41  return false;
42 
43  return true;
44 }
45 
47  const llvm::Triple &Triple,
48  const llvm::opt::ArgList &Args)
49  : Linux(D, Triple, Args) {
50  if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) {
51  StringRef ABIName = A->getValue();
52  if (ABIName == "ieeelongdouble" && !SupportIEEEFloat128(D, Triple, Args))
53  D.Diag(diag::warn_drv_unsupported_float_abi_by_lib) << ABIName;
54  }
55 }
56 
57 void PPCLinuxToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
58  ArgStringList &CC1Args) const {
59  if (!DriverArgs.hasArg(clang::driver::options::OPT_nostdinc) &&
60  !DriverArgs.hasArg(options::OPT_nobuiltininc)) {
61  const Driver &D = getDriver();
63  llvm::sys::path::append(P, "include", "ppc_wrappers");
64  addSystemInclude(DriverArgs, CC1Args, P);
65  }
66 
67  Linux::AddClangSystemIncludeArgs(DriverArgs, CC1Args);
68 }
69 
70 bool PPCLinuxToolChain::SupportIEEEFloat128(
71  const Driver &D, const llvm::Triple &Triple,
72  const llvm::opt::ArgList &Args) const {
73  if (!Triple.isLittleEndian() || !Triple.isPPC64())
74  return false;
75 
76  if (Args.hasArg(options::OPT_nostdlib, options::OPT_nostdlibxx))
77  return true;
78 
80  bool HasUnsupportedCXXLib =
81  StdLib == CST_Libcxx ||
82  (StdLib == CST_Libstdcxx &&
84 
86  !(D.CCCIsCXX() && HasUnsupportedCXXLib);
87 }
clang::driver::toolchains
Definition: AIX.h:55
Driver.h
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
llvm::SmallVector
Definition: LLVM.h:38
clang::driver::toolchains::Generic_GCC::GCCInstallation
GCCInstallationDetector GCCInstallation
Definition: Gnu.h:288
clang::driver::ToolChain::getDriver
const Driver & getDriver() const
Definition: ToolChain.h:228
clang::driver::toolchains::Linux::AddClangSystemIncludeArgs
void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Add the clang cc1 arguments for system include paths.
Definition: Linux.cpp:569
clang::driver::Driver::Diag
DiagnosticBuilder Diag(unsigned DiagID) const
Definition: Driver.h:139
clang::driver::toolchains::Generic_GCC::GCCVersion::isOlderThan
bool isOlderThan(int RHSMajor, int RHSMinor, int RHSPatch, StringRef RHSPatchSuffix=StringRef()) const
Generic_GCC - A tool chain using the 'gcc' command to perform all subcommands; this relies on gcc tra...
Definition: Gnu.cpp:1863
Options.h
llvm::opt
Definition: DiagnosticOptions.h:19
DriverDiagnostic.h
clang::driver::ToolChain::CXXStdlibType
CXXStdlibType
Definition: ToolChain.h:95
llvm::SmallString< 128 >
clang::driver::toolchains::Linux
Definition: Linux.h:19
clang::driver::ToolChain::CST_Libcxx
@ CST_Libcxx
Definition: ToolChain.h:96
clang::driver::Driver::CCCIsCXX
bool CCCIsCXX() const
Whether the driver should follow g++ like behavior.
Definition: Driver.h:208
clang::driver::ToolChain::CST_Libstdcxx
@ CST_Libstdcxx
Definition: ToolChain.h:97
clang::driver::Driver::ResourceDir
std::string ResourceDir
The path to the compiler resource directory.
Definition: Driver.h:162
P
StringRef P
Definition: ASTMatchersInternal.cpp:563
PPCLinux.h
clang::driver::toolchains::PPCLinuxToolChain::PPCLinuxToolChain
PPCLinuxToolChain(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
Definition: PPCLinux.cpp:46
clang::driver::toolchains::Generic_GCC::GCCInstallationDetector::getVersion
const GCCVersion & getVersion() const
Get the detected GCC version string.
Definition: Gnu.h:246
clang::driver::ToolChain::GetCXXStdlibType
virtual CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const
Definition: ToolChain.cpp:880
GlibcSupportsFloat128
static bool GlibcSupportsFloat128(const std::string &Linker)
Definition: PPCLinux.cpp:23
clang::driver::Driver
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:72
clang::driver::toolchains::Linux::getDynamicLinker
std::string getDynamicLinker(const llvm::opt::ArgList &Args) const override
Definition: Linux.cpp:405
clang::driver::toolchains::PPCLinuxToolChain::AddClangSystemIncludeArgs
void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Add the clang cc1 arguments for system include paths.
Definition: PPCLinux.cpp:57
clang::driver
Definition: Action.h:31
clang::driver::ToolChain::addSystemInclude
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:906