Skip to content

Commit

Permalink
This patch adds missing pieces to clang, including the PS4 toolchain
Browse files Browse the repository at this point in the history
definition, added warnings, PS4 defaults, and Driver changes needed for
our compiler.

A patch by Filipe Cabecinhas, Pierre Gousseau and Katya Romanova!

Differential Revision: http://reviews.llvm.org/D13482



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@250252 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Ekaterina Romanova committed Oct 13, 2015
1 parent edf6059 commit 1254d89
Show file tree
Hide file tree
Showing 18 changed files with 749 additions and 7 deletions.
14 changes: 14 additions & 0 deletions include/clang/Basic/DiagnosticDriverKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,18 @@ def warn_target_unsupported_nan2008 : Warning<
def warn_target_unsupported_nanlegacy : Warning<
"ignoring '-mnan=legacy' option because the '%0' architecture does not support it">,
InGroup<UnsupportedNan>;

def warn_drv_unable_to_find_directory_expected : Warning<
"unable to find %0 directory, expected to be in '%1'">,
InGroup<InvalidOrNonExistentDirectory>, DefaultIgnore;

def warn_drv_ps4_force_pic : Warning<
"option '%0' was ignored by the PS4 toolchain, using '-fPIC'">,
InGroup<OptionIgnored>;

def warn_drv_ps4_sdk_dir : Warning<
"environment variable SCE_PS4_SDK_DIR is set, but points to invalid or nonexistent directory '%0'">,
InGroup<InvalidOrNonExistentDirectory>;

def err_drv_unsupported_linker : Error<"unsupported value '%0' for -linker option">;
}
4 changes: 4 additions & 0 deletions include/clang/Basic/DiagnosticGroups.td
Original file line number Diff line number Diff line change
Expand Up @@ -823,3 +823,7 @@ def CudaCompat : DiagGroup<"cuda-compat">;

// A warning group for things that will change semantics in the future.
def FutureCompat : DiagGroup<"future-compat">;

def InvalidOrNonExistentDirectory : DiagGroup<"invalid-or-nonexistent-directory">;

def OptionIgnored : DiagGroup<"option-ignored">;
3 changes: 3 additions & 0 deletions lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2261,6 +2261,9 @@ const ToolChain &Driver::getToolChain(const ArgList &Args,
case llvm::Triple::CUDA:
TC = new toolchains::CudaToolChain(*this, Target, Args);
break;
case llvm::Triple::PS4:
TC = new toolchains::PS4CPU(*this, Target, Args);
break;
default:
// Of these targets, Hexagon is the only one that might have
// an OS of Linux, in which case it got handled above already.
Expand Down
74 changes: 74 additions & 0 deletions lib/Driver/ToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4066,3 +4066,77 @@ void WebAssembly::addClangTargetOptions(const ArgList &DriverArgs,
options::OPT_fno_use_init_array, true))
CC1Args.push_back("-fuse-init-array");
}

PS4CPU::PS4CPU(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
: Generic_ELF(D, Triple, Args) {
if (Args.hasArg(options::OPT_static))
D.Diag(diag::err_drv_unsupported_opt_for_target) << "-static" << "PS4";

// Determine where to find the PS4 libraries. We use SCE_PS4_SDK_DIR
// if it exists; otherwise use the driver's installation path, which
// should be <SDK_DIR>/host_tools/bin.

SmallString<512> PS4SDKDir;
if (const char *EnvValue = getenv("SCE_PS4_SDK_DIR"))
if (!llvm::sys::fs::exists(EnvValue))
getDriver().Diag(clang::diag::warn_drv_ps4_sdk_dir) << EnvValue;
PS4SDKDir = EnvValue;
} else {
PS4SDKDir = getDriver().Dir;
llvm::sys::path::append(PS4SDKDir, "/../../");
}

// By default, the driver won't report a warning if it can't find
// PS4's include or lib directories. This behavior could be changed if
// -Weverything or -Winvalid-or-nonexistent-directory options are passed.
// If -isysroot was passed, use that as the SDK base path.
std::string PrefixDir;
if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) {
PrefixDir = A->getValue();
if (!llvm::sys::fs::exists(PrefixDir))
getDriver().Diag(clang::diag::warn_missing_sysroot) << PrefixDir;
} else
PrefixDir = PS4SDKDir.str();

SmallString<512> PS4SDKIncludeDir(PrefixDir);
llvm::sys::path::append(PS4SDKIncludeDir, "target/include");
if (!Args.hasArg(options::OPT_nostdinc) &&
!Args.hasArg(options::OPT_nostdlibinc) &&
!Args.hasArg(options::OPT_isysroot) &&
!Args.hasArg(options::OPT__sysroot_EQ) &&
!llvm::sys::fs::exists(PS4SDKIncludeDir)) {
getDriver().Diag(clang::diag::warn_drv_unable_to_find_directory_expected)
<< "PS4 system headers" << PS4SDKIncludeDir;
}

SmallString<512> PS4SDKLibDir(PS4SDKDir);
llvm::sys::path::append(PS4SDKLibDir, "target/lib");
if (!Args.hasArg(options::OPT_nostdlib) &&
!Args.hasArg(options::OPT_nodefaultlibs) &&
!Args.hasArg(options::OPT__sysroot_EQ) && !Args.hasArg(options::OPT_E) &&
!Args.hasArg(options::OPT_c) && !Args.hasArg(options::OPT_S) &&
!Args.hasArg(options::OPT_emit_ast) &&
!llvm::sys::fs::exists(PS4SDKLibDir)) {
getDriver().Diag(clang::diag::warn_drv_unable_to_find_directory_expected)
<< "PS4 system libraries" << PS4SDKLibDir;
return;
}
getFilePaths().push_back(PS4SDKLibDir.str());
}

Tool *PS4CPU::buildAssembler() const {
return new tools::PS4cpu::Assemble(*this);
}

Tool *PS4CPU::buildLinker() const { return new tools::PS4cpu::Link(*this); }

bool PS4CPU::isPICDefault() const { return true; }

bool PS4CPU::HasNativeLLVMSupport() const { return true; }

SanitizerMask PS4CPU::getSupportedSanitizers() const {
SanitizerMask Res = ToolChain::getSupportedSanitizers();
Res |= SanitizerKind::Address;
Res |= SanitizerKind::Vptr;
return Res;
}
21 changes: 21 additions & 0 deletions lib/Driver/ToolChains.h
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,27 @@ class LLVM_LIBRARY_VISIBILITY WebAssembly final : public ToolChain {
llvm::opt::ArgStringList &CC1Args) const override;
};

class LLVM_LIBRARY_VISIBILITY PS4CPU : public Generic_ELF {
public:
PS4CPU(const Driver &D, const llvm::Triple &Triple,
const llvm::opt::ArgList &Args);

bool IsMathErrnoDefault() const override { return false; }
bool IsObjCNonFragileABIDefault() const override { return true; }
bool HasNativeLLVMSupport() const override;
bool isPICDefault() const override;

unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
return 2; // SSPStrong
}

SanitizerMask getSupportedSanitizers() const override;

protected:
Tool *buildAssembler() const override;
Tool *buildLinker() const override;
};

} // end namespace toolchains
} // end namespace driver
} // end namespace clang
Expand Down
Loading

0 comments on commit 1254d89

Please sign in to comment.