mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-27 05:05:32 +03:00
c5898806d2
By setting CMAKE_MODULE_PATH in the LLVM initial cache scripts, we can make the "SerenityOS" CMAKE_SYSTEM_NAME usable in the builds of compiler-rt, libunwind, libcxxabi and libcxx. This simplifies some toolchain patches and brings the cross-compiler patches closer to the Port's patches, and closer to something upstreamable.
845 lines
30 KiB
Diff
845 lines
30 KiB
Diff
diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
|
|
index ba91d0439..42265d547 100644
|
|
--- a/clang/lib/Basic/Targets.cpp
|
|
+++ b/clang/lib/Basic/Targets.cpp
|
|
@@ -149,6 +149,8 @@ TargetInfo *AllocateTarget(const llvm::Triple &Triple,
|
|
return new NetBSDTargetInfo<AArch64leTargetInfo>(Triple, Opts);
|
|
case llvm::Triple::OpenBSD:
|
|
return new OpenBSDTargetInfo<AArch64leTargetInfo>(Triple, Opts);
|
|
+ case llvm::Triple::Serenity:
|
|
+ return new SerenityTargetInfo<AArch64leTargetInfo>(Triple, Opts);
|
|
case llvm::Triple::Win32:
|
|
switch (Triple.getEnvironment()) {
|
|
case llvm::Triple::GNU:
|
|
@@ -538,6 +540,8 @@ TargetInfo *AllocateTarget(const llvm::Triple &Triple,
|
|
return new MCUX86_32TargetInfo(Triple, Opts);
|
|
case llvm::Triple::Hurd:
|
|
return new HurdTargetInfo<X86_32TargetInfo>(Triple, Opts);
|
|
+ case llvm::Triple::Serenity:
|
|
+ return new SerenityTargetInfo<X86_32TargetInfo>(Triple, Opts);
|
|
default:
|
|
return new X86_32TargetInfo(Triple, Opts);
|
|
}
|
|
@@ -590,6 +594,8 @@ TargetInfo *AllocateTarget(const llvm::Triple &Triple,
|
|
return new NaClTargetInfo<X86_64TargetInfo>(Triple, Opts);
|
|
case llvm::Triple::PS4:
|
|
return new PS4OSTargetInfo<X86_64TargetInfo>(Triple, Opts);
|
|
+ case llvm::Triple::Serenity:
|
|
+ return new SerenityTargetInfo<X86_64TargetInfo>(Triple, Opts);
|
|
default:
|
|
return new X86_64TargetInfo(Triple, Opts);
|
|
}
|
|
diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h
|
|
index 3fe39ed64..51e7a6cca 100644
|
|
--- a/clang/lib/Basic/Targets/OSTargets.h
|
|
+++ b/clang/lib/Basic/Targets/OSTargets.h
|
|
@@ -966,6 +966,22 @@ public:
|
|
}
|
|
};
|
|
|
|
+// SerenityOS target
|
|
+template <typename Target>
|
|
+class LLVM_LIBRARY_VISIBILITY SerenityTargetInfo : public OSTargetInfo<Target> {
|
|
+protected:
|
|
+ void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
|
|
+ MacroBuilder &Builder) const override {
|
|
+ Builder.defineMacro("__serenity__");
|
|
+ DefineStd(Builder, "unix", Opts);
|
|
+ Builder.defineMacro("__ELF__");
|
|
+ }
|
|
+
|
|
+public:
|
|
+ SerenityTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
|
|
+ : OSTargetInfo<Target>(Triple, Opts) {}
|
|
+};
|
|
+
|
|
} // namespace targets
|
|
} // namespace clang
|
|
#endif // LLVM_CLANG_LIB_BASIC_TARGETS_OSTARGETS_H
|
|
diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt
|
|
index 08be9f011..69038ff00 100644
|
|
--- a/clang/lib/Driver/CMakeLists.txt
|
|
+++ b/clang/lib/Driver/CMakeLists.txt
|
|
@@ -67,6 +67,7 @@ add_clang_library(clangDriver
|
|
ToolChains/OpenBSD.cpp
|
|
ToolChains/PS4CPU.cpp
|
|
ToolChains/RISCVToolchain.cpp
|
|
+ ToolChains/Serenity.cpp
|
|
ToolChains/Solaris.cpp
|
|
ToolChains/TCE.cpp
|
|
ToolChains/VEToolchain.cpp
|
|
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
|
|
index 94a7553e2..c6b3210f6 100644
|
|
--- a/clang/lib/Driver/Driver.cpp
|
|
+++ b/clang/lib/Driver/Driver.cpp
|
|
@@ -41,6 +41,7 @@
|
|
#include "ToolChains/PPCLinux.h"
|
|
#include "ToolChains/PS4CPU.h"
|
|
#include "ToolChains/RISCVToolchain.h"
|
|
+#include "ToolChains/Serenity.h"
|
|
#include "ToolChains/Solaris.h"
|
|
#include "ToolChains/TCE.h"
|
|
#include "ToolChains/VEToolchain.h"
|
|
@@ -5299,6 +5300,9 @@ const ToolChain &Driver::getToolChain(const ArgList &Args,
|
|
case llvm::Triple::Fuchsia:
|
|
TC = std::make_unique<toolchains::Fuchsia>(*this, Target, Args);
|
|
break;
|
|
+ case llvm::Triple::Serenity:
|
|
+ TC = std::make_unique<toolchains::Serenity>(*this, Target, Args);
|
|
+ break;
|
|
case llvm::Triple::Solaris:
|
|
TC = std::make_unique<toolchains::Solaris>(*this, Target, Args);
|
|
break;
|
|
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
|
|
index 6c1b88141..c77ff78be 100644
|
|
--- a/clang/lib/Driver/ToolChain.cpp
|
|
+++ b/clang/lib/Driver/ToolChain.cpp
|
|
@@ -404,6 +404,8 @@ StringRef ToolChain::getOSLibName() const {
|
|
return "sunos";
|
|
case llvm::Triple::AIX:
|
|
return "aix";
|
|
+ case llvm::Triple::Serenity:
|
|
+ return "serenity";
|
|
default:
|
|
return getOS();
|
|
}
|
|
diff --git a/clang/lib/Driver/ToolChains/Arch/X86.cpp b/clang/lib/Driver/ToolChains/Arch/X86.cpp
|
|
index 12749c7ec..91f744a26 100644
|
|
--- a/clang/lib/Driver/ToolChains/Arch/X86.cpp
|
|
+++ b/clang/lib/Driver/ToolChains/Arch/X86.cpp
|
|
@@ -100,6 +100,7 @@ std::string x86::getX86TargetCPU(const ArgList &Args,
|
|
case llvm::Triple::OpenBSD:
|
|
return "i586";
|
|
case llvm::Triple::FreeBSD:
|
|
+ case llvm::Triple::Serenity:
|
|
return "i686";
|
|
default:
|
|
// Fallback to p4.
|
|
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
|
|
index 58ae08a38..8e9a3fee6 100644
|
|
--- a/clang/lib/Driver/ToolChains/Clang.cpp
|
|
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
|
|
@@ -5695,7 +5695,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
|
|
options::OPT_fno_visibility_inlines_hidden_static_local_var);
|
|
Args.AddLastArg(CmdArgs, options::OPT_fvisibility_global_new_delete_hidden);
|
|
|
|
- Args.AddLastArg(CmdArgs, options::OPT_ftlsmodel_EQ);
|
|
+ if (Triple.isOSSerenity()) {
|
|
+ StringRef tls_model =
|
|
+ Args.getLastArgValue(options::OPT_ftlsmodel_EQ, "initial-exec");
|
|
+ CmdArgs.push_back(Args.MakeArgString("-ftls-model=" + tls_model));
|
|
+ } else {
|
|
+ Args.AddLastArg(CmdArgs, options::OPT_ftlsmodel_EQ);
|
|
+ }
|
|
|
|
if (Args.hasFlag(options::OPT_fno_operator_names,
|
|
options::OPT_foperator_names, false))
|
|
diff --git a/clang/lib/Driver/ToolChains/Serenity.cpp b/clang/lib/Driver/ToolChains/Serenity.cpp
|
|
new file mode 100644
|
|
index 000000000..4d653d86f
|
|
--- /dev/null
|
|
+++ b/clang/lib/Driver/ToolChains/Serenity.cpp
|
|
@@ -0,0 +1,327 @@
|
|
+//===---- Serenity.cpp - SerenityOS ToolChain Implementation ----*- C++ -*-===//
|
|
+//
|
|
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
+// See https://llvm.org/LICENSE.txt for license information.
|
|
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
+//
|
|
+//===----------------------------------------------------------------------===//
|
|
+
|
|
+#include "Serenity.h"
|
|
+#include "CommonArgs.h"
|
|
+#include "clang/Config/config.h"
|
|
+#include "clang/Driver/Compilation.h"
|
|
+#include "clang/Driver/Driver.h"
|
|
+#include "clang/Driver/DriverDiagnostic.h"
|
|
+#include "clang/Driver/Options.h"
|
|
+#include "clang/Driver/SanitizerArgs.h"
|
|
+#include "llvm/Option/ArgList.h"
|
|
+#include "llvm/Support/VirtualFileSystem.h"
|
|
+#include <string>
|
|
+
|
|
+using namespace clang::driver;
|
|
+using namespace clang::driver::toolchains;
|
|
+using namespace clang;
|
|
+using namespace llvm::opt;
|
|
+
|
|
+static bool getPIE(const ArgList &Args, const ToolChain &TC) {
|
|
+ if (Args.hasArg(options::OPT_static, options::OPT_shared,
|
|
+ options::OPT_static_pie))
|
|
+ return false;
|
|
+ Arg *Last = Args.getLastArg(options::OPT_pie, options::OPT_no_pie,
|
|
+ options::OPT_nopie);
|
|
+ return Last ? Last->getOption().matches(options::OPT_pie) : TC.isPIEDefault();
|
|
+}
|
|
+
|
|
+void tools::serenity::Linker::ConstructJob(Compilation &C, const JobAction &JA,
|
|
+ const InputInfo &Output,
|
|
+ const InputInfoList &Inputs,
|
|
+ const ArgList &Args,
|
|
+ const char *LinkingOutput) const {
|
|
+ const auto &TC = getToolChain();
|
|
+ const auto &D = TC.getDriver();
|
|
+ const bool IsShared = Args.hasArg(options::OPT_shared);
|
|
+ const bool IsStatic =
|
|
+ Args.hasArg(options::OPT_static) && !Args.hasArg(options::OPT_static_pie);
|
|
+ const bool IsRdynamic = Args.hasArg(options::OPT_rdynamic);
|
|
+ const bool IsStaticPIE = Args.hasArg(options::OPT_static_pie);
|
|
+ const bool IsPIE = getPIE(Args, TC);
|
|
+ ArgStringList CmdArgs;
|
|
+
|
|
+ if (!D.SysRoot.empty())
|
|
+ CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
|
|
+
|
|
+ if (IsPIE || IsStaticPIE)
|
|
+ CmdArgs.push_back("-pie");
|
|
+
|
|
+ if (IsShared)
|
|
+ CmdArgs.push_back("-shared");
|
|
+
|
|
+ if (IsStatic || IsStaticPIE)
|
|
+ CmdArgs.push_back("-static");
|
|
+
|
|
+ if (IsStaticPIE) {
|
|
+ CmdArgs.push_back("--no-dynamic-linker");
|
|
+ CmdArgs.push_back("-z");
|
|
+ CmdArgs.push_back("text");
|
|
+ }
|
|
+
|
|
+ if (!IsStatic && !IsStaticPIE) {
|
|
+ if (IsRdynamic)
|
|
+ CmdArgs.push_back("-export-dynamic");
|
|
+ CmdArgs.push_back("-dynamic-linker");
|
|
+ CmdArgs.push_back("/usr/lib/Loader.so");
|
|
+ }
|
|
+
|
|
+ if (!IsStatic || IsStaticPIE)
|
|
+ CmdArgs.push_back("--eh-frame-hdr");
|
|
+
|
|
+ if (Output.isFilename()) {
|
|
+ CmdArgs.push_back("-o");
|
|
+ CmdArgs.push_back(Output.getFilename());
|
|
+ }
|
|
+
|
|
+ if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
|
|
+ CmdArgs.push_back(Args.MakeArgString(
|
|
+ TC.GetFilePath((IsShared) ? "crt0_shared.o" : "crt0.o")));
|
|
+ CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("crti.o")));
|
|
+
|
|
+ std::string crtbegin_path;
|
|
+ if (TC.GetRuntimeLibType(Args) == ToolChain::RLT_CompilerRT) {
|
|
+ std::string crtbegin =
|
|
+ TC.getCompilerRT(Args, "crtbegin", ToolChain::FT_Object);
|
|
+ if (TC.getVFS().exists(crtbegin))
|
|
+ crtbegin_path = crtbegin;
|
|
+ }
|
|
+ if (crtbegin_path.empty()) {
|
|
+ const char *crtbegin = (IsShared || IsPIE) ? "crtbeginS.o" : "crtbegin.o";
|
|
+ crtbegin_path = TC.GetFilePath(crtbegin);
|
|
+ }
|
|
+ CmdArgs.push_back(Args.MakeArgString(crtbegin_path));
|
|
+ }
|
|
+
|
|
+ Args.AddAllArgs(CmdArgs, options::OPT_L);
|
|
+ Args.AddAllArgs(CmdArgs, options::OPT_u);
|
|
+
|
|
+ TC.AddFilePathLibArgs(Args, CmdArgs);
|
|
+
|
|
+ if (D.isUsingLTO()) {
|
|
+ assert(!Inputs.empty() && "Must have at least one input.");
|
|
+ addLTOOptions(TC, Args, CmdArgs, Output, Inputs[0],
|
|
+ D.getLTOMode() == LTOK_Thin);
|
|
+ }
|
|
+
|
|
+ Args.AddAllArgs(CmdArgs, options::OPT_T_Group);
|
|
+ Args.AddAllArgs(CmdArgs, options::OPT_e);
|
|
+ Args.AddAllArgs(CmdArgs, options::OPT_s);
|
|
+ Args.AddAllArgs(CmdArgs, options::OPT_t);
|
|
+ Args.AddAllArgs(CmdArgs, options::OPT_Z_Flag);
|
|
+ Args.AddAllArgs(CmdArgs, options::OPT_r);
|
|
+
|
|
+ addLinkerCompressDebugSectionsOption(TC, Args, CmdArgs);
|
|
+
|
|
+ AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA);
|
|
+
|
|
+ if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
|
|
+ AddRunTimeLibs(TC, D, CmdArgs, Args);
|
|
+
|
|
+ // We supply our own sanitizer runtimes
|
|
+ // FIXME: What if we want to use Clang-supplied ones as well?
|
|
+ const SanitizerArgs &Sanitize = TC.getSanitizerArgs();
|
|
+ if (Sanitize.needsUbsanRt())
|
|
+ CmdArgs.push_back("-lubsan");
|
|
+ }
|
|
+
|
|
+ if (D.CCCIsCXX() && TC.ShouldLinkCXXStdlib(Args)) {
|
|
+ bool OnlyLibstdcxxStatic = Args.hasArg(options::OPT_static_libstdcxx) &&
|
|
+ !Args.hasArg(options::OPT_static);
|
|
+ CmdArgs.push_back("--push-state");
|
|
+ CmdArgs.push_back("--as-needed");
|
|
+ if (OnlyLibstdcxxStatic)
|
|
+ CmdArgs.push_back("-Bstatic");
|
|
+ TC.AddCXXStdlibLibArgs(Args, CmdArgs);
|
|
+ if (OnlyLibstdcxxStatic)
|
|
+ CmdArgs.push_back("-Bdynamic");
|
|
+ CmdArgs.push_back("-lm");
|
|
+ CmdArgs.push_back("--pop-state");
|
|
+ }
|
|
+
|
|
+ if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
|
|
+ if (Args.hasArg(options::OPT_pthread, options::OPT_pthreads))
|
|
+ CmdArgs.push_back("-lpthread");
|
|
+
|
|
+ if (!Args.hasArg(options::OPT_nolibc))
|
|
+ CmdArgs.push_back("-lc");
|
|
+ }
|
|
+
|
|
+ if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
|
|
+ std::string crtend_path;
|
|
+ if (TC.GetRuntimeLibType(Args) == ToolChain::RLT_CompilerRT) {
|
|
+ std::string crtend =
|
|
+ TC.getCompilerRT(Args, "crtend", ToolChain::FT_Object);
|
|
+ if (TC.getVFS().exists(crtend))
|
|
+ crtend_path = crtend;
|
|
+ }
|
|
+ if (crtend_path.empty()) {
|
|
+ const char *crtend = (IsShared || IsPIE) ? "crtendS.o" : "crtend.o";
|
|
+ crtend_path = TC.GetFilePath(crtend);
|
|
+ }
|
|
+ CmdArgs.push_back(Args.MakeArgString(crtend_path));
|
|
+
|
|
+ CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("crtn.o")));
|
|
+ }
|
|
+
|
|
+ Args.AddAllArgs(CmdArgs, options::OPT_T);
|
|
+
|
|
+ const char *Exec = Args.MakeArgString(TC.GetLinkerPath());
|
|
+ C.addCommand(std::make_unique<Command>(JA, *this,
|
|
+ ResponseFileSupport::AtFileCurCP(),
|
|
+ Exec, CmdArgs, Inputs, Output));
|
|
+}
|
|
+
|
|
+Serenity::Serenity(const Driver &D, const llvm::Triple &Triple,
|
|
+ const ArgList &Args)
|
|
+ : ToolChain(D, Triple, Args) {
|
|
+ getProgramPaths().push_back(getDriver().getInstalledDir());
|
|
+ if (getDriver().getInstalledDir() != getDriver().Dir)
|
|
+ getProgramPaths().push_back(getDriver().Dir);
|
|
+ getFilePaths().push_back(getDriver().SysRoot + "/usr/lib");
|
|
+}
|
|
+
|
|
+Tool *Serenity::buildLinker() const {
|
|
+ return new tools::serenity::Linker(*this);
|
|
+}
|
|
+
|
|
+void Serenity::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
|
|
+ ArgStringList &CC1Args) const {
|
|
+ const Driver &D = getDriver();
|
|
+
|
|
+ if (DriverArgs.hasArg(options::OPT_nostdinc))
|
|
+ return;
|
|
+
|
|
+ if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
|
|
+ addSystemInclude(DriverArgs, CC1Args, D.ResourceDir + "/include");
|
|
+ }
|
|
+
|
|
+ if (DriverArgs.hasArg(options::OPT_nostdlibinc))
|
|
+ return;
|
|
+
|
|
+ addSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/usr/local/include");
|
|
+ addSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/usr/include");
|
|
+}
|
|
+
|
|
+static std::string getLibStdCXXVersion(const Driver &D, StringRef IncludePath) {
|
|
+ SmallString<128> Path(IncludePath);
|
|
+ llvm::sys::path::append(Path, "c++");
|
|
+
|
|
+ std::error_code EC;
|
|
+ std::tuple<int, int, int> Newest{0, 0, 0};
|
|
+ std::string Result;
|
|
+
|
|
+ for (llvm::vfs::directory_iterator LI = D.getVFS().dir_begin(Path, EC), LE;
|
|
+ !EC && LI != LE; LI = LI.increment(EC)) {
|
|
+ StringRef VersionText = llvm::sys::path::filename(LI->path());
|
|
+
|
|
+ // This is libc++
|
|
+ if (VersionText[0] == 'v')
|
|
+ continue;
|
|
+
|
|
+ llvm::SmallVector<StringRef, 3> Parts;
|
|
+ VersionText.split(Parts, '.');
|
|
+
|
|
+ // SerenityOS always builds GCC with <major>.<minor>.<patch> versions
|
|
+ if (Parts.size() < 3)
|
|
+ continue;
|
|
+
|
|
+ std::tuple<int, int, int> Current;
|
|
+ if (!llvm::to_integer(Parts[0], std::get<0>(Current)))
|
|
+ continue;
|
|
+ if (!llvm::to_integer(Parts[1], std::get<1>(Current)))
|
|
+ continue;
|
|
+ if (!llvm::to_integer(Parts[2], std::get<2>(Current)))
|
|
+ continue;
|
|
+
|
|
+ if (Current > Newest) {
|
|
+ Newest = Current;
|
|
+ Result = VersionText.str();
|
|
+ }
|
|
+ }
|
|
+ return Result;
|
|
+}
|
|
+
|
|
+void Serenity::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
|
|
+ ArgStringList &CC1Args) const {
|
|
+ if (DriverArgs.hasArg(options::OPT_nostdinc, options::OPT_nostdincxx,
|
|
+ options::OPT_nostdlibinc))
|
|
+ return;
|
|
+
|
|
+ const auto StdLib = GetCXXStdlibType(DriverArgs);
|
|
+
|
|
+ const Driver &D = getDriver();
|
|
+ std::string SysRoot = computeSysRoot();
|
|
+ std::string Target = getTripleString();
|
|
+
|
|
+ auto AddIncludePath = [&](std::string Path) {
|
|
+ std::string Version = StdLib == CXXStdlibType::CST_Libstdcxx
|
|
+ ? getLibStdCXXVersion(D, Path)
|
|
+ : detectLibcxxVersion(Path);
|
|
+ if (Version.empty())
|
|
+ return false;
|
|
+
|
|
+ std::string TargetDir;
|
|
+ if (StdLib == CXXStdlibType::CST_Libstdcxx) {
|
|
+ TargetDir = Path + "/c++/" + Version + "/" + Target;
|
|
+ } else {
|
|
+ TargetDir = Path + "/" + Target + "/c++/" + Version;
|
|
+ }
|
|
+
|
|
+ if (D.getVFS().exists(TargetDir))
|
|
+ addSystemInclude(DriverArgs, CC1Args, TargetDir);
|
|
+
|
|
+ addSystemInclude(DriverArgs, CC1Args, Path + "/c++/" + Version);
|
|
+ return true;
|
|
+ };
|
|
+
|
|
+ if (AddIncludePath(getDriver().Dir + "/../include"))
|
|
+ return;
|
|
+ if (AddIncludePath(SysRoot + "/usr/local/include"))
|
|
+ return;
|
|
+ if (AddIncludePath(SysRoot + "/usr/include"))
|
|
+ return;
|
|
+}
|
|
+
|
|
+void Serenity::addClangTargetOptions(
|
|
+ const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
|
|
+ Action::OffloadKind DeviceOffloadKind) const {
|
|
+ if (!DriverArgs.hasFlag(options::OPT_fuse_init_array,
|
|
+ options::OPT_fno_use_init_array, true))
|
|
+ CC1Args.push_back("-fno-use-init-array");
|
|
+}
|
|
+
|
|
+ToolChain::UnwindLibType
|
|
+Serenity::GetUnwindLibType(const llvm::opt::ArgList &Args) const {
|
|
+
|
|
+ const Arg *A = Args.getLastArg(options::OPT_unwindlib_EQ);
|
|
+ StringRef LibName = A ? A->getValue() : CLANG_DEFAULT_UNWINDLIB;
|
|
+
|
|
+ if (LibName == "none") {
|
|
+ return ToolChain::UNW_None;
|
|
+ } else if (LibName == "platform" || LibName == "") {
|
|
+ ToolChain::RuntimeLibType RtLibType = GetRuntimeLibType(Args);
|
|
+ if (RtLibType == ToolChain::RLT_CompilerRT) {
|
|
+ return ToolChain::UNW_CompilerRT;
|
|
+ } else if (RtLibType == ToolChain::RLT_Libgcc)
|
|
+ return ToolChain::UNW_Libgcc;
|
|
+ } else if (LibName == "libunwind") {
|
|
+ if (GetRuntimeLibType(Args) == RLT_Libgcc)
|
|
+ getDriver().Diag(diag::err_drv_incompatible_unwindlib);
|
|
+ return ToolChain::UNW_CompilerRT;
|
|
+ } else if (LibName == "libgcc") {
|
|
+ return ToolChain::UNW_Libgcc;
|
|
+ }
|
|
+
|
|
+ if (A)
|
|
+ getDriver().Diag(diag::err_drv_invalid_unwindlib_name)
|
|
+ << A->getAsString(Args);
|
|
+
|
|
+ return ToolChain::UNW_None;
|
|
+}
|
|
diff --git a/clang/lib/Driver/ToolChains/Serenity.h b/clang/lib/Driver/ToolChains/Serenity.h
|
|
new file mode 100644
|
|
index 000000000..50b0dbe62
|
|
--- /dev/null
|
|
+++ b/clang/lib/Driver/ToolChains/Serenity.h
|
|
@@ -0,0 +1,99 @@
|
|
+//===---- Serenity.h - SerenityOS ToolChain Implementation ------*- C++ -*-===//
|
|
+//
|
|
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
+// See https://llvm.org/LICENSE.txt for license information.
|
|
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
+//
|
|
+//===----------------------------------------------------------------------===//
|
|
+
|
|
+#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_SERENITY_H
|
|
+#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_SERENITY_H
|
|
+
|
|
+#include "clang/Basic/LangOptions.h"
|
|
+#include "clang/Driver/Tool.h"
|
|
+#include "clang/Driver/ToolChain.h"
|
|
+
|
|
+namespace clang {
|
|
+namespace driver {
|
|
+namespace tools {
|
|
+namespace serenity {
|
|
+
|
|
+class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
|
|
+public:
|
|
+ Linker(const ToolChain &TC) : Tool("serenity::Linker", "linker", TC) {}
|
|
+
|
|
+ bool hasIntegratedCPP() const override { return false; }
|
|
+ bool isLinkJob() const override { return true; }
|
|
+
|
|
+ void ConstructJob(Compilation &C, const JobAction &JA,
|
|
+ const InputInfo &Output, const InputInfoList &Inputs,
|
|
+ const llvm::opt::ArgList &TCArgs,
|
|
+ const char *LinkingOutput) const override;
|
|
+};
|
|
+} // end namespace serenity
|
|
+} // end namespace tools
|
|
+
|
|
+namespace toolchains {
|
|
+
|
|
+class LLVM_LIBRARY_VISIBILITY Serenity : public ToolChain {
|
|
+public:
|
|
+ Serenity(const Driver &D, const llvm::Triple &Triple,
|
|
+ const llvm::opt::ArgList &Args);
|
|
+
|
|
+ void
|
|
+ AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
|
|
+ llvm::opt::ArgStringList &CC1Args) const override;
|
|
+
|
|
+ void AddClangCXXStdlibIncludeArgs(
|
|
+ const llvm::opt::ArgList &DriverArgs,
|
|
+ llvm::opt::ArgStringList &CC1Args) const override;
|
|
+
|
|
+ RuntimeLibType GetDefaultRuntimeLibType() const override {
|
|
+ return ToolChain::RLT_CompilerRT;
|
|
+ }
|
|
+
|
|
+ CXXStdlibType GetDefaultCXXStdlibType() const override {
|
|
+ return ToolChain::CST_Libcxx;
|
|
+ }
|
|
+
|
|
+ UnwindLibType GetUnwindLibType(const llvm::opt::ArgList &Args) const override;
|
|
+
|
|
+ void
|
|
+ addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
|
|
+ llvm::opt::ArgStringList &CC1Args,
|
|
+ Action::OffloadKind DeviceOffloadKind) const override;
|
|
+
|
|
+ const char *getDefaultLinker() const override { return "ld.lld"; }
|
|
+
|
|
+ bool HasNativeLLVMSupport() const override { return true; }
|
|
+
|
|
+ bool IsIntegratedAssemblerDefault() const override { return true; }
|
|
+
|
|
+ bool isPICDefault() const override { return true; }
|
|
+ bool isPIEDefault() const override { return true; }
|
|
+ bool isPICDefaultForced() const override { return false; }
|
|
+
|
|
+ bool IsMathErrnoDefault() const override { return false; }
|
|
+
|
|
+ bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const override {
|
|
+ return true;
|
|
+ }
|
|
+
|
|
+ bool useRelaxRelocations() const override { return true; }
|
|
+
|
|
+ LangOptions::StackProtectorMode
|
|
+ GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
|
|
+ return LangOptions::SSPStrong;
|
|
+ }
|
|
+
|
|
+ unsigned GetDefaultDwarfVersion() const override { return 5; }
|
|
+
|
|
+protected:
|
|
+ Tool *buildLinker() const override;
|
|
+};
|
|
+
|
|
+} // end namespace toolchains
|
|
+} // end namespace driver
|
|
+} // end namespace clang
|
|
+
|
|
+#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_SERENITY_H
|
|
diff --git a/clang/lib/Frontend/InitHeaderSearch.cpp b/clang/lib/Frontend/InitHeaderSearch.cpp
|
|
index ba9f96384..4aecfeee2 100644
|
|
--- a/clang/lib/Frontend/InitHeaderSearch.cpp
|
|
+++ b/clang/lib/Frontend/InitHeaderSearch.cpp
|
|
@@ -233,6 +233,7 @@ void InitHeaderSearch::AddDefaultCIncludePaths(const llvm::Triple &triple,
|
|
case llvm::Triple::PS4:
|
|
case llvm::Triple::ELFIAMCU:
|
|
case llvm::Triple::Fuchsia:
|
|
+ case llvm::Triple::Serenity:
|
|
break;
|
|
case llvm::Triple::Win32:
|
|
if (triple.getEnvironment() != llvm::Triple::Cygnus)
|
|
@@ -432,6 +433,7 @@ void InitHeaderSearch::AddDefaultIncludePaths(const LangOptions &Lang,
|
|
case llvm::Triple::Solaris:
|
|
case llvm::Triple::WASI:
|
|
case llvm::Triple::AIX:
|
|
+ case llvm::Triple::Serenity:
|
|
return;
|
|
|
|
case llvm::Triple::Win32:
|
|
diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake
|
|
index 39b9120f0..1a49ac3e5 100644
|
|
--- a/compiler-rt/cmake/config-ix.cmake
|
|
+++ b/compiler-rt/cmake/config-ix.cmake
|
|
@@ -684,7 +684,7 @@ endif()
|
|
|
|
# TODO: Add builtins support.
|
|
|
|
-if (CRT_SUPPORTED_ARCH AND OS_NAME MATCHES "Linux" AND NOT LLVM_USE_SANITIZER)
|
|
+if (CRT_SUPPORTED_ARCH AND OS_NAME MATCHES "Linux|SerenityOS" AND NOT LLVM_USE_SANITIZER)
|
|
set(COMPILER_RT_HAS_CRT TRUE)
|
|
else()
|
|
set(COMPILER_RT_HAS_CRT FALSE)
|
|
diff --git a/libcxx/cmake/Modules/HandleOutOfTreeLLVM.cmake b/libcxx/cmake/Modules/HandleOutOfTreeLLVM.cmake
|
|
index ad2820b32..deaa2c380 100644
|
|
--- a/libcxx/cmake/Modules/HandleOutOfTreeLLVM.cmake
|
|
+++ b/libcxx/cmake/Modules/HandleOutOfTreeLLVM.cmake
|
|
@@ -14,6 +14,8 @@ set(LLVM_INCLUDE_DIR ${LLVM_PATH}/include CACHE PATH "Path to llvm/include")
|
|
set(LLVM_PATH ${LLVM_PATH} CACHE PATH "Path to LLVM source tree")
|
|
set(LLVM_MAIN_SRC_DIR ${LLVM_PATH})
|
|
set(LLVM_CMAKE_PATH "${LLVM_PATH}/cmake/modules")
|
|
+set(LLVM_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
|
+set(LLVM_LIBRARY_OUTPUT_INTDIR "${CMAKE_CURRENT_BINARY_DIR}/lib")
|
|
|
|
if (EXISTS "${LLVM_CMAKE_PATH}")
|
|
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_PATH}")
|
|
diff --git a/libcxx/include/__config b/libcxx/include/__config
|
|
index 97e33f315..179bd2a67 100644
|
|
--- a/libcxx/include/__config
|
|
+++ b/libcxx/include/__config
|
|
@@ -1148,6 +1148,7 @@ extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
|
|
defined(__sun__) || \
|
|
defined(__MVS__) || \
|
|
defined(_AIX) || \
|
|
+ defined(__serenity__) || \
|
|
(defined(__MINGW32__) && __has_include(<pthread.h>))
|
|
# define _LIBCPP_HAS_THREAD_API_PTHREAD
|
|
# elif defined(__Fuchsia__)
|
|
diff --git a/libcxx/include/__locale b/libcxx/include/__locale
|
|
index ad742997d..c75dcb458 100644
|
|
--- a/libcxx/include/__locale
|
|
+++ b/libcxx/include/__locale
|
|
@@ -31,7 +31,7 @@
|
|
#elif defined(__sun__)
|
|
# include <xlocale.h>
|
|
# include <__support/solaris/xlocale.h>
|
|
-#elif defined(_NEWLIB_VERSION)
|
|
+#elif defined(_NEWLIB_VERSION) || defined(__serenity__)
|
|
# include <__support/newlib/xlocale.h>
|
|
#elif defined(__OpenBSD__)
|
|
# include <__support/openbsd/xlocale.h>
|
|
@@ -490,7 +490,7 @@ public:
|
|
static const mask xdigit = _ISXDIGIT;
|
|
static const mask blank = _ISBLANK;
|
|
static const mask __regex_word = 0x80;
|
|
-#elif defined(_NEWLIB_VERSION)
|
|
+#elif defined(_NEWLIB_VERSION) || defined(__serenity__)
|
|
// Same type as Newlib's _ctype_ array in newlib/libc/include/ctype.h.
|
|
typedef char mask;
|
|
static const mask space = _S;
|
|
diff --git a/libcxx/include/__support/newlib/xlocale.h b/libcxx/include/__support/newlib/xlocale.h
|
|
index b75f9263a..f5ffb9003 100644
|
|
--- a/libcxx/include/__support/newlib/xlocale.h
|
|
+++ b/libcxx/include/__support/newlib/xlocale.h
|
|
@@ -9,7 +9,7 @@
|
|
#ifndef _LIBCPP_SUPPORT_NEWLIB_XLOCALE_H
|
|
#define _LIBCPP_SUPPORT_NEWLIB_XLOCALE_H
|
|
|
|
-#if defined(_NEWLIB_VERSION)
|
|
+#if defined(_NEWLIB_VERSION) || defined(__serenity__)
|
|
|
|
#include <cstdlib>
|
|
#include <clocale>
|
|
@@ -22,6 +22,6 @@
|
|
#include <__support/xlocale/__strtonum_fallback.h>
|
|
#endif
|
|
|
|
-#endif // _NEWLIB_VERSION
|
|
+#endif // _NEWLIB_VERSION || __serenity__
|
|
|
|
#endif
|
|
diff --git a/libcxx/include/initializer_list b/libcxx/include/initializer_list
|
|
index ea1f23467..45631ac2f 100644
|
|
--- a/libcxx/include/initializer_list
|
|
+++ b/libcxx/include/initializer_list
|
|
@@ -43,7 +43,9 @@ template<class E> const E* end(initializer_list<E> il) noexcept; // constexpr in
|
|
*/
|
|
|
|
#include <__config>
|
|
+#if !defined(__serenity__) || !defined(KERNEL)
|
|
#include <cstddef>
|
|
+#endif
|
|
|
|
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
|
#pragma GCC system_header
|
|
diff --git a/libcxx/include/locale b/libcxx/include/locale
|
|
index 8e584005d..f29f3453e 100644
|
|
--- a/libcxx/include/locale
|
|
+++ b/libcxx/include/locale
|
|
@@ -206,7 +206,7 @@ template <class charT> class messages_byname;
|
|
|
|
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
|
// Most unix variants have catopen. These are the specific ones that don't.
|
|
-# if !defined(__BIONIC__) && !defined(_NEWLIB_VERSION)
|
|
+# if !defined(__BIONIC__) && !defined(_NEWLIB_VERSION) && !defined(__serenity__)
|
|
# define _LIBCPP_HAS_CATOPEN 1
|
|
# include <nl_types.h>
|
|
# endif
|
|
diff --git a/libcxx/include/new b/libcxx/include/new
|
|
index aefc08c16..7ee71d16b 100644
|
|
--- a/libcxx/include/new
|
|
+++ b/libcxx/include/new
|
|
@@ -310,7 +310,7 @@ inline _LIBCPP_INLINE_VISIBILITY void __libcpp_deallocate_unsized(void* __ptr, s
|
|
// Returns the allocated memory, or `nullptr` on failure.
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
void* __libcpp_aligned_alloc(std::size_t __alignment, std::size_t __size) {
|
|
-#if defined(_LIBCPP_MSVCRT_LIKE)
|
|
+#if defined(_LIBCPP_MSVCRT_LIKE) || (defined(__serenity__) && !defined(KERNEL))
|
|
return ::_aligned_malloc(__size, __alignment);
|
|
#else
|
|
void* __result = nullptr;
|
|
@@ -322,7 +322,7 @@ void* __libcpp_aligned_alloc(std::size_t __alignment, std::size_t __size) {
|
|
|
|
inline _LIBCPP_INLINE_VISIBILITY
|
|
void __libcpp_aligned_free(void* __ptr) {
|
|
-#if defined(_LIBCPP_MSVCRT_LIKE)
|
|
+#if defined(_LIBCPP_MSVCRT_LIKE) || (defined(__serenity__) && !defined(KERNEL))
|
|
::_aligned_free(__ptr);
|
|
#else
|
|
::free(__ptr);
|
|
diff --git a/libcxx/src/include/config_elast.h b/libcxx/src/include/config_elast.h
|
|
index 7880c733f..87b25cf42 100644
|
|
--- a/libcxx/src/include/config_elast.h
|
|
+++ b/libcxx/src/include/config_elast.h
|
|
@@ -33,6 +33,8 @@
|
|
#define _LIBCPP_ELAST 4095
|
|
#elif defined(__APPLE__)
|
|
// No _LIBCPP_ELAST needed on Apple
|
|
+#elif defined(__serenity__)
|
|
+// No _LIBCPP_ELAST needed on SerenityOS
|
|
#elif defined(__sun__)
|
|
#define _LIBCPP_ELAST ESTALE
|
|
#elif defined(__MVS__)
|
|
diff --git a/libcxx/src/locale.cpp b/libcxx/src/locale.cpp
|
|
index d5ab8fb3b..5039c1987 100644
|
|
--- a/libcxx/src/locale.cpp
|
|
+++ b/libcxx/src/locale.cpp
|
|
@@ -1145,6 +1145,8 @@ ctype<char>::classic_table() noexcept
|
|
return __pctype_func();
|
|
#elif defined(__EMSCRIPTEN__)
|
|
return *__ctype_b_loc();
|
|
+#elif defined(__serenity__)
|
|
+ return _ctype_;
|
|
#elif defined(_NEWLIB_VERSION)
|
|
// Newlib has a 257-entry table in ctype_.c, where (char)0 starts at [1].
|
|
return _ctype_ + 1;
|
|
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
|
|
index 0c3419390..7673b9183 100644
|
|
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
|
|
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
|
|
@@ -228,7 +228,7 @@ endif()
|
|
|
|
# Pass -Wl,-z,defs. This makes sure all symbols are defined. Otherwise a DSO
|
|
# build might work on ELF but fail on MachO/COFF.
|
|
-if(NOT (CMAKE_SYSTEM_NAME MATCHES "Darwin|FreeBSD|OpenBSD|DragonFly|AIX|SunOS|OS390" OR
|
|
+if(NOT (CMAKE_SYSTEM_NAME MATCHES "Darwin|FreeBSD|OpenBSD|DragonFly|AIX|SunOS|OS390|SerenityOS" OR
|
|
WIN32 OR CYGWIN) AND
|
|
NOT LLVM_USE_SANITIZER)
|
|
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,defs")
|
|
diff --git a/llvm/include/llvm/ADT/Triple.h b/llvm/include/llvm/ADT/Triple.h
|
|
index 76f351405..b81556c55 100644
|
|
--- a/llvm/include/llvm/ADT/Triple.h
|
|
+++ b/llvm/include/llvm/ADT/Triple.h
|
|
@@ -199,7 +199,8 @@ public:
|
|
Hurd, // GNU/Hurd
|
|
WASI, // Experimental WebAssembly OS
|
|
Emscripten,
|
|
- LastOSType = Emscripten
|
|
+ Serenity,
|
|
+ LastOSType = Serenity
|
|
};
|
|
enum EnvironmentType {
|
|
UnknownEnvironment,
|
|
@@ -628,6 +629,11 @@ public:
|
|
return getOS() == Triple::AIX;
|
|
}
|
|
|
|
+ /// Tests whether the OS is SerenityOS
|
|
+ bool isOSSerenity() const {
|
|
+ return getOS() == Triple::Serenity;
|
|
+ }
|
|
+
|
|
/// Tests whether the OS uses the ELF binary format.
|
|
bool isOSBinFormatELF() const {
|
|
return getObjectFormat() == Triple::ELF;
|
|
diff --git a/llvm/lib/Support/Triple.cpp b/llvm/lib/Support/Triple.cpp
|
|
index 883115463..22b39d8f5 100644
|
|
--- a/llvm/lib/Support/Triple.cpp
|
|
+++ b/llvm/lib/Support/Triple.cpp
|
|
@@ -218,6 +218,7 @@ StringRef Triple::getOSTypeName(OSType Kind) {
|
|
case PS4: return "ps4";
|
|
case RTEMS: return "rtems";
|
|
case Solaris: return "solaris";
|
|
+ case Serenity: return "serenity";
|
|
case TvOS: return "tvos";
|
|
case WASI: return "wasi";
|
|
case WatchOS: return "watchos";
|
|
@@ -538,6 +539,7 @@ static Triple::OSType parseOS(StringRef OSName) {
|
|
.StartsWith("hurd", Triple::Hurd)
|
|
.StartsWith("wasi", Triple::WASI)
|
|
.StartsWith("emscripten", Triple::Emscripten)
|
|
+ .StartsWith("serenity", Triple::Serenity)
|
|
.Default(Triple::UnknownOS);
|
|
}
|
|
|
|
diff --git a/runtimes/CMakeLists.txt b/runtimes/CMakeLists.txt
|
|
index 1ffce323d..552521192 100644
|
|
--- a/runtimes/CMakeLists.txt
|
|
+++ b/runtimes/CMakeLists.txt
|
|
@@ -58,17 +58,28 @@ if(compiler_rt_path)
|
|
endif()
|
|
endif()
|
|
|
|
+# If building standalone by pointing CMake at this runtimes directory,
|
|
+# LLVM_BINARY_DIR isn't set, find_package(LLVM) will fail and these
|
|
+# intermediate paths are unset.
|
|
+if (LLVM_BINARY_DIR STREQUAL "")
|
|
+ set(LLVM_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
|
+endif()
|
|
+if (NOT LLVM_FOUND)
|
|
+ set(LLVM_TOOLS_BINARY_DIR ${LLVM_BINARY_DIR}/bin)
|
|
+ set(LLVM_LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/lib)
|
|
+endif()
|
|
+
|
|
# Setting these variables will allow the sub-build to put their outputs into
|
|
# the library and bin directories of the top-level build.
|
|
set(LLVM_LIBRARY_OUTPUT_INTDIR ${LLVM_LIBRARY_DIR})
|
|
set(LLVM_RUNTIME_OUTPUT_INTDIR ${LLVM_TOOLS_BINARY_DIR})
|
|
|
|
# This variable makes sure that e.g. llvm-lit is found.
|
|
-set(LLVM_MAIN_SRC_DIR ${LLVM_BUILD_MAIN_SRC_DIR})
|
|
+set(LLVM_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../llvm)
|
|
set(LLVM_CMAKE_PATH ${LLVM_MAIN_SRC_DIR}/cmake/modules)
|
|
|
|
# This variable is used by individual runtimes to locate LLVM files.
|
|
-set(LLVM_PATH ${LLVM_BUILD_MAIN_SRC_DIR})
|
|
+set(LLVM_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../llvm)
|
|
|
|
if(APPLE)
|
|
set(LLVM_ENABLE_LIBCXX ON CACHE BOOL "")
|