mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:27:45 +00:00
Toolchain+Ports: Update LLVM to 14.0.1
Besides a version bump, the following changes have been made to our toolchain infrastructure: - LLVM/Clang is now built with -march=native if the host compiler supports it. An exception to this is CI, as the toolchain cache is shared among many different machines there. - The LLVM tarball is not re-extracted if the hash of the applied patches doesn't differ. - The patches have been split up into atomic chunks. - Port-specific patches have been integrated into the main patches, which will aid in the work towards self-hosting. - <sysroot>/usr/local/lib is now appended to the linker's search path by default. - --pack-dyn-relocs=relr is appended to the linker command line by default, meaning ports take advantage of RELR relocations without any patches or additional compiler flags. The formatting of LLVM port's package.sh has been bothering me, so I also indented the arguments to the CMake invocation.
This commit is contained in:
parent
9a898df1cd
commit
01b31d9858
22 changed files with 664 additions and 1007 deletions
|
@ -0,0 +1,81 @@
|
|||
From 9ff3d5362c71dfa9b6aba1dd65a33bb6d8971164 Mon Sep 17 00:00:00 2001
|
||||
From: Daniel Bertalan <dani@danielbertalan.dev>
|
||||
Date: Thu, 14 Apr 2022 09:54:22 +0200
|
||||
Subject: [PATCH 1/8] [Support] Add support for building LLVM on SerenityOS
|
||||
|
||||
Adds SerenityOS `#ifdef`s for platform-specific code.
|
||||
|
||||
We stub out wait4, as SerenityOS doesn't support querying a child
|
||||
process's resource usage information.
|
||||
---
|
||||
llvm/include/llvm/Support/SwapByteOrder.h | 2 +-
|
||||
llvm/lib/Support/Unix/Path.inc | 5 ++++-
|
||||
llvm/lib/Support/Unix/Program.inc | 9 ++++++++-
|
||||
3 files changed, 13 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/llvm/include/llvm/Support/SwapByteOrder.h b/llvm/include/llvm/Support/SwapByteOrder.h
|
||||
index e8612ba66..f0109f4b3 100644
|
||||
--- a/llvm/include/llvm/Support/SwapByteOrder.h
|
||||
+++ b/llvm/include/llvm/Support/SwapByteOrder.h
|
||||
@@ -22,7 +22,7 @@
|
||||
#endif
|
||||
|
||||
#if defined(__linux__) || defined(__GNU__) || defined(__HAIKU__) || \
|
||||
- defined(__Fuchsia__) || defined(__EMSCRIPTEN__)
|
||||
+ defined(__Fuchsia__) || defined(__EMSCRIPTEN__) || defined(__serenity__)
|
||||
#include <endian.h>
|
||||
#elif defined(_AIX)
|
||||
#include <sys/machine.h>
|
||||
diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc
|
||||
index 788460d65..566628935 100644
|
||||
--- a/llvm/lib/Support/Unix/Path.inc
|
||||
+++ b/llvm/lib/Support/Unix/Path.inc
|
||||
@@ -112,7 +112,7 @@ typedef uint_t uint;
|
||||
#endif
|
||||
|
||||
#if defined(__NetBSD__) || defined(__DragonFly__) || defined(__GNU__) || \
|
||||
- defined(__MVS__)
|
||||
+ defined(__MVS__) || defined(__serenity__)
|
||||
#define STATVFS_F_FLAG(vfs) (vfs).f_flag
|
||||
#else
|
||||
#define STATVFS_F_FLAG(vfs) (vfs).f_flags
|
||||
@@ -512,6 +512,9 @@ static bool is_local_impl(struct STATVFS &Vfs) {
|
||||
#elif defined(__HAIKU__)
|
||||
// Haiku doesn't expose this information.
|
||||
return false;
|
||||
+#elif defined(__serenity__)
|
||||
+ // Serenity doesn't yet support remote filesystem mounts.
|
||||
+ return false;
|
||||
#elif defined(__sun)
|
||||
// statvfs::f_basetype contains a null-terminated FSType name of the mounted target
|
||||
StringRef fstype(Vfs.f_basetype);
|
||||
diff --git a/llvm/lib/Support/Unix/Program.inc b/llvm/lib/Support/Unix/Program.inc
|
||||
index 089342030..3ffe064e5 100644
|
||||
--- a/llvm/lib/Support/Unix/Program.inc
|
||||
+++ b/llvm/lib/Support/Unix/Program.inc
|
||||
@@ -336,7 +336,7 @@ static bool Execute(ProcessInfo &PI, StringRef Program,
|
||||
namespace llvm {
|
||||
namespace sys {
|
||||
|
||||
-#ifndef _AIX
|
||||
+#if !defined(_AIX) && !defined(__serenity__)
|
||||
using ::wait4;
|
||||
#else
|
||||
static pid_t (wait4)(pid_t pid, int *status, int options, struct rusage *usage);
|
||||
@@ -379,6 +379,13 @@ pid_t (llvm::sys::wait4)(pid_t pid, int *status, int options,
|
||||
}
|
||||
#endif
|
||||
|
||||
+#ifdef __serenity__
|
||||
+pid_t (llvm::sys::wait4)(pid_t pid, int *status, int options,
|
||||
+ struct rusage*) {
|
||||
+ return ::waitpid(pid, status, options);
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
ProcessInfo llvm::sys::Wait(const ProcessInfo &PI, unsigned SecondsToWait,
|
||||
bool WaitUntilTerminates, std::string *ErrMsg,
|
||||
Optional<ProcessStatistics> *ProcStat) {
|
||||
--
|
||||
2.35.3
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
From 0cf66d1dbcd3b7c0e2ddd65177066955c41352b7 Mon Sep 17 00:00:00 2001
|
||||
From: Daniel Bertalan <dani@danielbertalan.dev>
|
||||
Date: Thu, 14 Apr 2022 09:51:24 +0200
|
||||
Subject: [PATCH 2/8] [Triple] Add triple for SerenityOS
|
||||
|
||||
---
|
||||
llvm/include/llvm/ADT/Triple.h | 8 +++++++-
|
||||
llvm/lib/Support/Triple.cpp | 2 ++
|
||||
2 files changed, 9 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/llvm/include/llvm/ADT/Triple.h b/llvm/include/llvm/ADT/Triple.h
|
||||
index 42277c013..b0378dd3a 100644
|
||||
--- a/llvm/include/llvm/ADT/Triple.h
|
||||
+++ b/llvm/include/llvm/ADT/Triple.h
|
||||
@@ -205,7 +205,8 @@ public:
|
||||
Hurd, // GNU/Hurd
|
||||
WASI, // Experimental WebAssembly OS
|
||||
Emscripten,
|
||||
- LastOSType = Emscripten
|
||||
+ Serenity,
|
||||
+ LastOSType = Serenity
|
||||
};
|
||||
enum EnvironmentType {
|
||||
UnknownEnvironment,
|
||||
@@ -612,6 +613,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 a9afcc9db..aef8c7549 100644
|
||||
--- a/llvm/lib/Support/Triple.cpp
|
||||
+++ b/llvm/lib/Support/Triple.cpp
|
||||
@@ -224,6 +224,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";
|
||||
@@ -548,6 +549,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);
|
||||
}
|
||||
|
||||
--
|
||||
2.35.3
|
||||
|
|
@ -0,0 +1,595 @@
|
|||
From 70cbf6e9ed46f0d39f43ac4a43b9bd2cc10da6c3 Mon Sep 17 00:00:00 2001
|
||||
From: Daniel Bertalan <dani@danielbertalan.dev>
|
||||
Date: Thu, 14 Apr 2022 10:09:50 +0200
|
||||
Subject: [PATCH 3/8] [Driver] Add support for SerenityOS
|
||||
|
||||
Adds support for the `$arch-pc-serenity` target to the Clang front end.
|
||||
This makes the compiler look for libraries and headers in the right
|
||||
places, and enables some security mitigations like stack-smashing
|
||||
protection and position-independent code by default.
|
||||
---
|
||||
clang/lib/Basic/Targets.cpp | 6 +
|
||||
clang/lib/Basic/Targets/OSTargets.h | 18 ++
|
||||
clang/lib/Driver/CMakeLists.txt | 1 +
|
||||
clang/lib/Driver/Driver.cpp | 4 +
|
||||
clang/lib/Driver/ToolChain.cpp | 2 +
|
||||
clang/lib/Driver/ToolChains/Arch/X86.cpp | 1 +
|
||||
clang/lib/Driver/ToolChains/Serenity.cpp | 340 +++++++++++++++++++++++
|
||||
clang/lib/Driver/ToolChains/Serenity.h | 99 +++++++
|
||||
8 files changed, 471 insertions(+)
|
||||
create mode 100644 clang/lib/Driver/ToolChains/Serenity.cpp
|
||||
create mode 100644 clang/lib/Driver/ToolChains/Serenity.h
|
||||
|
||||
diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
|
||||
index 994a491cd..066c8140b 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 3c1830d5f..b0bae0535 100644
|
||||
--- a/clang/lib/Basic/Targets/OSTargets.h
|
||||
+++ b/clang/lib/Basic/Targets/OSTargets.h
|
||||
@@ -977,6 +977,24 @@ 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) {
|
||||
+ this->WIntType = TargetInfo::UnsignedInt;
|
||||
+ }
|
||||
+};
|
||||
+
|
||||
} // 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 78e8fd185..3b70257a9 100644
|
||||
--- a/clang/lib/Driver/CMakeLists.txt
|
||||
+++ b/clang/lib/Driver/CMakeLists.txt
|
||||
@@ -70,6 +70,7 @@ add_clang_library(clangDriver
|
||||
ToolChains/OpenBSD.cpp
|
||||
ToolChains/PS4CPU.cpp
|
||||
ToolChains/RISCVToolchain.cpp
|
||||
+ ToolChains/Serenity.cpp
|
||||
ToolChains/Solaris.cpp
|
||||
ToolChains/SPIRV.cpp
|
||||
ToolChains/TCE.cpp
|
||||
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
|
||||
index 3bfddeefc..a75e0ee14 100644
|
||||
--- a/clang/lib/Driver/Driver.cpp
|
||||
+++ b/clang/lib/Driver/Driver.cpp
|
||||
@@ -43,6 +43,7 @@
|
||||
#include "ToolChains/PPCLinux.h"
|
||||
#include "ToolChains/PS4CPU.h"
|
||||
#include "ToolChains/RISCVToolchain.h"
|
||||
+#include "ToolChains/Serenity.h"
|
||||
#include "ToolChains/SPIRV.h"
|
||||
#include "ToolChains/Solaris.h"
|
||||
#include "ToolChains/TCE.h"
|
||||
@@ -5564,6 +5565,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 d657d21bf..eea53e6ac 100644
|
||||
--- a/clang/lib/Driver/ToolChain.cpp
|
||||
+++ b/clang/lib/Driver/ToolChain.cpp
|
||||
@@ -413,6 +413,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 bfa008f96..b7f1780fd 100644
|
||||
--- a/clang/lib/Driver/ToolChains/Arch/X86.cpp
|
||||
+++ b/clang/lib/Driver/ToolChains/Arch/X86.cpp
|
||||
@@ -107,6 +107,7 @@ std::string x86::getX86TargetCPU(const Driver &D, 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/Serenity.cpp b/clang/lib/Driver/ToolChains/Serenity.cpp
|
||||
new file mode 100644
|
||||
index 000000000..955422438
|
||||
--- /dev/null
|
||||
+++ b/clang/lib/Driver/ToolChains/Serenity.cpp
|
||||
@@ -0,0 +1,340 @@
|
||||
+//===---- 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) : true;
|
||||
+}
|
||||
+
|
||||
+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());
|
||||
+ }
|
||||
+
|
||||
+ const char *Exec = Args.MakeArgString(TC.GetLinkerPath());
|
||||
+ auto linkerIs = [Exec](const char* name) {
|
||||
+ return llvm::sys::path::filename(Exec).equals_insensitive(name) ||
|
||||
+ llvm::sys::path::stem(Exec).equals_insensitive(name);
|
||||
+ };
|
||||
+
|
||||
+ if (linkerIs("ld.lld") || linkerIs("ld.mold")) {
|
||||
+ CmdArgs.push_back("--pack-dyn-relocs=relr");
|
||||
+ } else {
|
||||
+ CmdArgs.push_back("-z");
|
||||
+ CmdArgs.push_back("pack-relative-relocs");
|
||||
+ }
|
||||
+
|
||||
+ 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(Args);
|
||||
+ 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);
|
||||
+
|
||||
+ 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/local/lib");
|
||||
+ 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..d414f8366
|
||||
--- /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 llvm::opt::ArgList&) const override { return false; }
|
||||
+ 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
|
||||
--
|
||||
2.35.3
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
From 50e7b15efa5f7e2ff57e998879fee28fff4a5305 Mon Sep 17 00:00:00 2001
|
||||
From: Daniel Bertalan <dani@danielbertalan.dev>
|
||||
Date: Thu, 14 Apr 2022 10:12:54 +0200
|
||||
Subject: [PATCH 4/8] [Driver] Default to -ftls-model=initial-exec on
|
||||
SerenityOS
|
||||
|
||||
This is a hack to make Clang use the initial-exec TLS model instead of
|
||||
the default local-exec when building code for Serenity.
|
||||
|
||||
This patch should be removed when we implement proper TLS support.
|
||||
---
|
||||
clang/lib/Driver/ToolChains/Clang.cpp | 8 +++++++-
|
||||
1 file changed, 7 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
|
||||
index f2f18e901..39d6c18fe 100644
|
||||
--- a/clang/lib/Driver/ToolChains/Clang.cpp
|
||||
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
|
||||
@@ -5872,7 +5872,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
|
||||
Args.AddLastArg(CmdArgs, options::OPT_fvisibility_inlines_hidden_static_local_var,
|
||||
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_fnew_infallible,
|
||||
options::OPT_fno_new_infallible, false))
|
||||
--
|
||||
2.35.3
|
||||
|
|
@ -0,0 +1,153 @@
|
|||
From fae5030852da34db641d636ad4c599e56b92ccdf Mon Sep 17 00:00:00 2001
|
||||
From: Daniel Bertalan <dani@danielbertalan.dev>
|
||||
Date: Thu, 14 Apr 2022 10:17:13 +0200
|
||||
Subject: [PATCH 5/8] [libc++] Add support for SerenityOS
|
||||
|
||||
This commit teaches libc++ about what features are available in our
|
||||
LibC, namely:
|
||||
* We do not have locale support, so no-op shims should be used in place
|
||||
of the C locale API.
|
||||
* The number of errno constants defined by us is given by the value of
|
||||
the `ELAST` macro.
|
||||
* Multithreading is implemented though the pthread library.
|
||||
* Aligned memory allocation is provided by the MSVCRT-like
|
||||
`_aligned_{malloc,free}` functions.
|
||||
|
||||
Adds a hack for a header not found error when including
|
||||
`<initializer_list>` inside the SerenityOS kernel.
|
||||
|
||||
Makes libc++ use its builtin character type table instead of the one
|
||||
provided by LibC as it is incomplete.
|
||||
---
|
||||
libcxx/include/__config | 6 ++++--
|
||||
libcxx/include/__locale | 2 +-
|
||||
libcxx/include/__support/newlib/xlocale.h | 4 ++--
|
||||
libcxx/include/initializer_list | 2 ++
|
||||
libcxx/include/locale | 2 +-
|
||||
libcxx/include/new | 4 ++--
|
||||
libcxx/src/include/config_elast.h | 2 ++
|
||||
7 files changed, 14 insertions(+), 8 deletions(-)
|
||||
|
||||
diff --git a/libcxx/include/__config b/libcxx/include/__config
|
||||
index 458d0c1b8..69f627294 100644
|
||||
--- a/libcxx/include/__config
|
||||
+++ b/libcxx/include/__config
|
||||
@@ -1146,7 +1146,8 @@ extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
|
||||
defined(__APPLE__) || \
|
||||
defined(__sun__) || \
|
||||
defined(__MVS__) || \
|
||||
- defined(_AIX)
|
||||
+ defined(_AIX) || \
|
||||
+ defined(__serenity__)
|
||||
# define _LIBCPP_HAS_THREAD_API_PTHREAD
|
||||
# elif defined(__Fuchsia__)
|
||||
// TODO(44575): Switch to C11 thread API when possible.
|
||||
@@ -1225,7 +1226,8 @@ extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
|
||||
|
||||
#if defined(__BIONIC__) || defined(__NuttX__) || \
|
||||
defined(__Fuchsia__) || defined(__wasi__) || \
|
||||
- defined(_LIBCPP_HAS_MUSL_LIBC) || defined(__OpenBSD__)
|
||||
+ defined(_LIBCPP_HAS_MUSL_LIBC) || defined(__OpenBSD__) || \
|
||||
+ defined(__serenity__)
|
||||
#define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
|
||||
#endif
|
||||
|
||||
diff --git a/libcxx/include/__locale b/libcxx/include/__locale
|
||||
index 51f35eece..4bc91ecb5 100644
|
||||
--- a/libcxx/include/__locale
|
||||
+++ b/libcxx/include/__locale
|
||||
@@ -30,7 +30,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>
|
||||
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 fefaf8cf8..c388bc246 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 7c2d2361f..229ca7258 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 be0d972f4..d212bae46 100644
|
||||
--- a/libcxx/include/new
|
||||
+++ b/libcxx/include/new
|
||||
@@ -320,7 +320,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;
|
||||
@@ -332,7 +332,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 0ed53a3b2..7fffd937e 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__)
|
||||
--
|
||||
2.35.3
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
From 1cf9ec98aa817c13b94b42e4df80804a6757aa8a Mon Sep 17 00:00:00 2001
|
||||
From: Daniel Bertalan <dani@danielbertalan.dev>
|
||||
Date: Thu, 14 Apr 2022 10:20:46 +0200
|
||||
Subject: [PATCH 6/8] [compiler-rt] Build crtbegin.o/crtend.o for SerenityOS
|
||||
|
||||
---
|
||||
compiler-rt/cmake/config-ix.cmake | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake
|
||||
index fc62d5ecc..7a47b7f71 100644
|
||||
--- a/compiler-rt/cmake/config-ix.cmake
|
||||
+++ b/compiler-rt/cmake/config-ix.cmake
|
||||
@@ -696,7 +696,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)
|
||||
--
|
||||
2.35.3
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
From ac91fd973bdf23b24645336a470d5dfb31811aa6 Mon Sep 17 00:00:00 2001
|
||||
From: Daniel Bertalan <dani@danielbertalan.dev>
|
||||
Date: Thu, 14 Apr 2022 10:21:19 +0200
|
||||
Subject: [PATCH 7/8] [cmake] Allow undefined symbols on SerenityOS
|
||||
|
||||
Allow undefined symbols in LLVM libraries, which is needed because only
|
||||
stubs are available for SerenityOS libraries when libc++ and libunwind
|
||||
are built.
|
||||
---
|
||||
llvm/cmake/modules/HandleLLVMOptions.cmake | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
|
||||
index fcaa8f20b..c27209146 100644
|
||||
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
|
||||
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
|
||||
@@ -227,7 +227,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")
|
||||
--
|
||||
2.35.3
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
From eb1dbc59eaebdefd9735b738ca30478ce1788dca Mon Sep 17 00:00:00 2001
|
||||
From: Daniel Bertalan <dani@danielbertalan.dev>
|
||||
Date: Mon, 18 Apr 2022 22:32:29 +0200
|
||||
Subject: [PATCH 8/8] [cmake] Support building shared libLLVM and libClang for
|
||||
SerenityOS
|
||||
|
||||
This patch tells CMake that the --whole-archive linker option should be
|
||||
used for specifying the archives whose members will constitute these
|
||||
shared libraries.
|
||||
|
||||
Symbol versioning is disabled, as the SerenityOS loader doesn't support
|
||||
it, and the ELF sections that store version data would just waste space.
|
||||
---
|
||||
clang/tools/libclang/CMakeLists.txt | 2 +-
|
||||
llvm/tools/llvm-shlib/CMakeLists.txt | 3 ++-
|
||||
2 files changed, 3 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/clang/tools/libclang/CMakeLists.txt b/clang/tools/libclang/CMakeLists.txt
|
||||
index 4e0647971..2e4aeeab3 100644
|
||||
--- a/clang/tools/libclang/CMakeLists.txt
|
||||
+++ b/clang/tools/libclang/CMakeLists.txt
|
||||
@@ -80,7 +80,7 @@ if(MSVC)
|
||||
set(LLVM_EXPORTED_SYMBOL_FILE)
|
||||
endif()
|
||||
|
||||
-if (UNIX AND NOT APPLE)
|
||||
+if (UNIX AND NOT APPLE AND (NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "SerenityOS"))
|
||||
set(LLVM_EXPORTED_SYMBOL_FILE)
|
||||
set(USE_VERSION_SCRIPT ${LLVM_HAVE_LINK_VERSION_SCRIPT})
|
||||
endif()
|
||||
diff --git a/llvm/tools/llvm-shlib/CMakeLists.txt b/llvm/tools/llvm-shlib/CMakeLists.txt
|
||||
index 8e2b78f1b..909018753 100644
|
||||
--- a/llvm/tools/llvm-shlib/CMakeLists.txt
|
||||
+++ b/llvm/tools/llvm-shlib/CMakeLists.txt
|
||||
@@ -39,6 +39,7 @@ if(LLVM_BUILD_LLVM_DYLIB)
|
||||
OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "OpenBSD")
|
||||
OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "Fuchsia")
|
||||
OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "DragonFly")
|
||||
+ OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "SerenityOS")
|
||||
OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "SunOS")) # FIXME: It should be "GNU ld for elf"
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/simple_version_script.map.in
|
||||
@@ -46,7 +47,7 @@ if(LLVM_BUILD_LLVM_DYLIB)
|
||||
|
||||
# GNU ld doesn't resolve symbols in the version script.
|
||||
set(LIB_NAMES -Wl,--whole-archive ${LIB_NAMES} -Wl,--no-whole-archive)
|
||||
- if (NOT LLVM_LINKER_IS_SOLARISLD AND NOT MINGW)
|
||||
+ if (NOT LLVM_LINKER_IS_SOLARISLD AND NOT MINGW AND (NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "SerenityOS"))
|
||||
# Solaris ld does not accept global: *; so there is no way to version *all* global symbols
|
||||
set(LIB_NAMES -Wl,--version-script,${LLVM_LIBRARY_DIR}/tools/llvm-shlib/simple_version_script.map ${LIB_NAMES})
|
||||
endif()
|
||||
--
|
||||
2.35.3
|
||||
|
78
Toolchain/Patches/llvm/ReadMe.md
Normal file
78
Toolchain/Patches/llvm/ReadMe.md
Normal file
|
@ -0,0 +1,78 @@
|
|||
# Patches for llvm on SerenityOS
|
||||
|
||||
## `0001-Support-Add-support-for-building-LLVM-on-SerenityOS.patch`
|
||||
|
||||
Add support for building LLVM on SerenityOS
|
||||
|
||||
Adds SerenityOS `#ifdef`s for platform-specific code.
|
||||
|
||||
We stub out wait4, as SerenityOS doesn't support querying a child
|
||||
process's resource usage information.
|
||||
|
||||
## `0002-Triple-Add-triple-for-SerenityOS.patch`
|
||||
|
||||
Add triple for SerenityOS
|
||||
|
||||
|
||||
## `0003-Driver-Add-support-for-SerenityOS.patch`
|
||||
|
||||
Add support for SerenityOS
|
||||
|
||||
Adds support for the `$arch-pc-serenity` target to the Clang front end.
|
||||
This makes the compiler look for libraries and headers in the right
|
||||
places, and enables some security mitigations like stack-smashing
|
||||
protection and position-independent code by default.
|
||||
|
||||
## `0004-Driver-Default-to-ftls-model-initial-exec-on-Serenit.patch`
|
||||
|
||||
Default to -ftls-model=initial-exec on SerenityOS
|
||||
|
||||
This is a hack to make Clang use the initial-exec TLS model instead of
|
||||
the default local-exec when building code for Serenity.
|
||||
|
||||
This patch should be removed when we implement proper TLS support.
|
||||
|
||||
## `0005-libc-Add-support-for-SerenityOS.patch`
|
||||
|
||||
Add support for SerenityOS
|
||||
|
||||
This commit teaches libc++ about what features are available in our
|
||||
LibC, namely:
|
||||
* We do not have locale support, so no-op shims should be used in place
|
||||
of the C locale API.
|
||||
* The number of errno constants defined by us is given by the value of
|
||||
the `ELAST` macro.
|
||||
* Multithreading is implemented though the pthread library.
|
||||
* Aligned memory allocation is provided by the MSVCRT-like
|
||||
`_aligned_{malloc,free}` functions.
|
||||
|
||||
Adds a hack for a header not found error when including
|
||||
`<initializer_list>` inside the SerenityOS kernel.
|
||||
|
||||
Makes libc++ use its builtin character type table instead of the one
|
||||
provided by LibC as it is incomplete.
|
||||
|
||||
## `0006-compiler-rt-Build-crtbegin.o-crtend.o-for-SerenityOS.patch`
|
||||
|
||||
Build crtbegin.o/crtend.o for SerenityOS
|
||||
|
||||
|
||||
## `0007-cmake-Allow-undefined-symbols-on-SerenityOS.patch`
|
||||
|
||||
Allow undefined symbols on SerenityOS
|
||||
|
||||
Allow undefined symbols in LLVM libraries, which is needed because only
|
||||
stubs are available for SerenityOS libraries when libc++ and libunwind
|
||||
are built.
|
||||
|
||||
## `0008-cmake-Support-building-shared-libLLVM-and-libClang-f.patch`
|
||||
|
||||
Support building shared libLLVM and libClang for SerenityOS
|
||||
|
||||
This patch tells CMake that the --whole-archive linker option should be
|
||||
used for specifying the archives whose members will constitute these
|
||||
shared libraries.
|
||||
|
||||
Symbol versioning is disabled, as the SerenityOS loader doesn't support
|
||||
it, and the ELF sections that store version data would just waste space.
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue