Repository navigation
[clang] Add support for SerenityOS - #187941
Conversation
Adds support for the $arch-unknown-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. Co-authored-by: Daniel Bertalan <[email protected]> Co-authored-by: kleines Filmröllchen <[email protected]> Co-authored-by: Andrew Kaster <[email protected]> Co-authored-by: Dan Klishch <[email protected]>
|
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-driver Author: Lucas Chollet (LucasChollet) ChangesAdds support for the $arch-unknown-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. A first attempt at upstreaming this patch was made here. I hope I fixed everything mentioned there. I intentionally kept @MaskRay, @brad0 as you already reviewed the original patch. Patch is 33.43 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/187941.diff 20 Files Affected:
diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index dc6ef6ed8f3f8..b24794d26c7c3 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -177,6 +177,9 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
case llvm::Triple::Hurd:
return std::make_unique<HurdTargetInfo<AArch64leTargetInfo>>(Triple,
Opts);
+ case llvm::Triple::Serenity:
+ return std::make_unique<SerenityTargetInfo<AArch64leTargetInfo>>(Triple,
+ Opts);
case llvm::Triple::Win32:
switch (Triple.getEnvironment()) {
case llvm::Triple::GNU:
@@ -477,6 +480,10 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
Opts);
case llvm::Triple::Hurd:
return std::make_unique<HurdTargetInfo<RISCV64TargetInfo>>(Triple, Opts);
+
+ case llvm::Triple::Serenity:
+ return std::make_unique<SerenityTargetInfo<RISCV64TargetInfo>>(Triple,
+ Opts);
default:
return std::make_unique<RISCV64TargetInfo>(Triple, Opts);
}
@@ -664,6 +671,9 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
case llvm::Triple::Managarm:
return std::make_unique<ManagarmTargetInfo<X86_64TargetInfo>>(Triple,
Opts);
+ case llvm::Triple::Serenity:
+ return std::make_unique<SerenityTargetInfo<X86_64TargetInfo>>(Triple,
+ Opts);
default:
return std::make_unique<X86_64TargetInfo>(Triple, Opts);
}
diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h
index 16337d56f82c3..9e2916eace079 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -1104,6 +1104,23 @@ class LLVM_LIBRARY_VISIBILITY QURTTargetInfo : public OSTargetInfo<Target> {
using OSTargetInfo<Target>::OSTargetInfo;
};
+// 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);
+ }
+
+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 e3eff21986181..ff8557e8ced97 100644
--- a/clang/lib/Driver/CMakeLists.txt
+++ b/clang/lib/Driver/CMakeLists.txt
@@ -81,6 +81,7 @@ add_clang_library(clangDriver
ToolChains/OHOS.cpp
ToolChains/OpenBSD.cpp
ToolChains/PS4CPU.cpp
+ ToolChains/Serenity.cpp
ToolChains/Solaris.cpp
ToolChains/SPIRV.cpp
ToolChains/SPIRVOpenMP.cpp
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index c559855ac91f5..a57a0e2676052 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -46,6 +46,7 @@
#include "ToolChains/SPIRV.h"
#include "ToolChains/SPIRVOpenMP.h"
#include "ToolChains/SYCL.h"
+#include "ToolChains/Serenity.h"
#include "ToolChains/Solaris.h"
#include "ToolChains/TCE.h"
#include "ToolChains/UEFI.h"
@@ -7012,6 +7013,9 @@ const ToolChain &Driver::getToolChain(const ArgList &Args,
case llvm::Triple::Managarm:
TC = std::make_unique<toolchains::Managarm>(*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 94913837f5339..6c99b4ca837e9 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -724,6 +724,8 @@ StringRef ToolChain::getOSLibName() const {
return "sunos";
case llvm::Triple::AIX:
return "aix";
+ case llvm::Triple::Serenity:
+ return "serenity";
default:
return getOS();
}
@@ -1365,7 +1367,8 @@ ToolChain::UnwindLibType ToolChain::GetUnwindLibType(
else if (LibName == "platform" || LibName == "") {
ToolChain::RuntimeLibType RtLibType = GetRuntimeLibType(Args);
if (RtLibType == ToolChain::RLT_CompilerRT) {
- if (getTriple().isAndroid() || getTriple().isOSAIX())
+ if (getTriple().isAndroid() || getTriple().isOSAIX() ||
+ getTriple().isOSSerenity())
unwindLibType = ToolChain::UNW_CompilerRT;
else
unwindLibType = ToolChain::UNW_None;
diff --git a/clang/lib/Driver/ToolChains/Serenity.cpp b/clang/lib/Driver/ToolChains/Serenity.cpp
new file mode 100644
index 0000000000000..a61f2f81d1f66
--- /dev/null
+++ b/clang/lib/Driver/ToolChains/Serenity.cpp
@@ -0,0 +1,206 @@
+//===---- 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 "clang/Config/config.h"
+#include "clang/Driver/CommonArgs.h"
+#include "clang/Driver/Compilation.h"
+#include "clang/Driver/Driver.h"
+#include "clang/Driver/SanitizerArgs.h"
+#include "clang/Options/Options.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;
+
+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 = cast<Generic_ELF const&>(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 IsStaticPIE = Args.hasArg(options::OPT_static_pie);
+ ArgStringList CmdArgs;
+
+ if (!D.SysRoot.empty())
+ CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
+
+ if (IsShared)
+ CmdArgs.push_back("-shared");
+
+ if (IsStaticPIE) {
+ CmdArgs.push_back("-static");
+ CmdArgs.push_back("-pie");
+ CmdArgs.push_back("--no-dynamic-linker");
+ CmdArgs.push_back("-z");
+ CmdArgs.push_back("text");
+ } else if (IsStatic) {
+ CmdArgs.push_back("-static");
+ } else if (!Args.hasArg(options::OPT_r)) {
+ if (Args.hasArg(options::OPT_rdynamic))
+ CmdArgs.push_back("-export-dynamic");
+ if (!IsShared) {
+ Arg *A = Args.getLastArg(options::OPT_pie, options::OPT_no_pie,
+ options::OPT_nopie);
+ bool IsPIE = A ? A->getOption().matches(options::OPT_pie) :
+ TC.isPIEDefault(Args);
+ if (IsPIE)
+ CmdArgs.push_back("-pie");
+ CmdArgs.push_back("-dynamic-linker");
+ CmdArgs.push_back(Args.MakeArgString(TC.getDynamicLinker(Args)));
+ }
+ }
+
+ CmdArgs.push_back("--eh-frame-hdr");
+
+ assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
+ if (Output.isFilename()) {
+ CmdArgs.push_back("-o");
+ CmdArgs.push_back(Output.getFilename());
+ }
+
+ CmdArgs.push_back("-z");
+ CmdArgs.push_back("pack-relative-relocs");
+
+ bool HasNoStdLib = Args.hasArg(options::OPT_nostdlib, options::OPT_r);
+ bool HasNoStdLibXX = Args.hasArg(options::OPT_nostdlibxx);
+ bool HasNoLibC = Args.hasArg(options::OPT_nolibc);
+ bool HasNoStartFiles = Args.hasArg(options::OPT_nostartfiles);
+ bool HasNoDefaultLibs = Args.hasArg(options::OPT_nodefaultlibs);
+
+ bool ShouldLinkStartFiles = !HasNoStartFiles && !HasNoStdLib;
+ bool ShouldLinkCompilerRuntime = !HasNoDefaultLibs && !HasNoStdLib;
+ bool ShouldLinkLibC = !HasNoLibC && !HasNoStdLib && !HasNoDefaultLibs;
+ bool ShouldLinkLibCXX =
+ D.CCCIsCXX() && !HasNoStdLibXX && !HasNoStdLib && !HasNoDefaultLibs;
+
+ if (ShouldLinkStartFiles) {
+ if (!IsShared)
+ CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("crt0.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())
+ crtbegin_path = TC.GetFilePath("crtbeginS.o");
+ CmdArgs.push_back(Args.MakeArgString(crtbegin_path));
+ }
+
+ Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_u});
+
+ TC.AddFilePathLibArgs(Args, CmdArgs);
+
+ if (D.isUsingLTO())
+ addLTOOptions(TC, Args, CmdArgs, Output, Inputs,
+ D.getLTOMode() == LTOK_Thin);
+
+ Args.addAllArgs(CmdArgs, {options::OPT_T_Group, options::OPT_s,
+ options::OPT_t, options::OPT_r});
+
+ addLinkerCompressDebugSectionsOption(TC, Args, CmdArgs);
+
+ AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA);
+
+ if (ShouldLinkCompilerRuntime) {
+ AddRunTimeLibs(TC, D, CmdArgs, Args);
+
+ // We supply our own sanitizer runtimes that output errors to the
+ // Kernel debug log as well as stderr.
+ // FIXME: Properly port clang/gcc sanitizers and use those instead.
+ const SanitizerArgs &Sanitize = TC.getSanitizerArgs(Args);
+ if (Sanitize.needsUbsanRt())
+ CmdArgs.push_back("-lubsan");
+ }
+
+ if (ShouldLinkLibCXX) {
+ 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("--pop-state");
+ }
+
+ // FIXME: This is currently required to building Ports, but we should take
+ // care of that in the Port's build system rather than here.
+ CmdArgs.push_back("-L=/usr/local/lib");
+
+ // Silence warnings when linking C code with a C++ '-stdlib' argument.
+ Args.ClaimAllArgs(options::OPT_stdlib_EQ);
+
+ if (ShouldLinkLibC)
+ CmdArgs.push_back("-lc");
+
+ if (ShouldLinkStartFiles) {
+ 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())
+ crtend_path = TC.GetFilePath("crtendS.o");
+ CmdArgs.push_back(Args.MakeArgString(crtend_path));
+ }
+
+ const char *Exec = Args.MakeArgString(TC.GetLinkerPath());
+ C.addCommand(std::make_unique<Command>(JA, *this,
+ ResponseFileSupport::AtFileCurCP(),
+ Exec, CmdArgs, Inputs, Output));
+}
+
+SanitizerMask Serenity::getSupportedSanitizers() const {
+ return ToolChain::getSupportedSanitizers() | SanitizerKind::KernelAddress;
+}
+
+Serenity::Serenity(const Driver &D, const llvm::Triple &Triple,
+ const ArgList &Args)
+ : Generic_ELF(D, Triple, Args) {
+ getFilePaths().push_back(concat(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, concat(D.ResourceDir, "/include"));
+
+ if (DriverArgs.hasArg(options::OPT_nostdlibinc))
+ return;
+
+ // FIXME: See FIXME about "/usr/local/lib" in Linker::ConstructJob.
+ addSystemInclude(DriverArgs, CC1Args,
+ concat(D.SysRoot, "/usr/local/include"));
+
+ addSystemInclude(DriverArgs, CC1Args, concat(D.SysRoot, "/usr/include"));
+}
diff --git a/clang/lib/Driver/ToolChains/Serenity.h b/clang/lib/Driver/ToolChains/Serenity.h
new file mode 100644
index 0000000000000..dcf94f016dc6a
--- /dev/null
+++ b/clang/lib/Driver/ToolChains/Serenity.h
@@ -0,0 +1,90 @@
+//===---- 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 "Gnu.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 final : 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 final : public Generic_ELF {
+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;
+
+ RuntimeLibType GetDefaultRuntimeLibType() const override {
+ return ToolChain::RLT_CompilerRT;
+ }
+
+ CXXStdlibType GetDefaultCXXStdlibType() const override {
+ return ToolChain::CST_Libcxx;
+ }
+
+ const char *getDefaultLinker() const override { return "ld.lld"; }
+
+ std::string getDynamicLinker(const llvm::opt::ArgList &) const override {
+ return "/usr/lib/Loader.so";
+ }
+
+ bool HasNativeLLVMSupport() const override { return true; }
+
+ bool isPICDefault() const override { return true; }
+ bool isPIEDefault(const llvm::opt::ArgList &) const override { return true; }
+ bool isPICDefaultForced() const override { return false; }
+
+ SanitizerMask getSupportedSanitizers() const override;
+
+ bool IsMathErrnoDefault() const override { return false; }
+
+ UnwindTableLevel
+ getDefaultUnwindTableLevel(const llvm::opt::ArgList &Args) const override {
+ return UnwindTableLevel::Asynchronous;
+ }
+
+ LangOptions::StackProtectorMode
+ GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
+ return LangOptions::SSPStrong;
+ }
+
+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/Lex/InitHeaderSearch.cpp b/clang/lib/Lex/InitHeaderSearch.cpp
index 3b0e0704ff8c4..e894086b66e76 100644
--- a/clang/lib/Lex/InitHeaderSearch.cpp
+++ b/clang/lib/Lex/InitHeaderSearch.cpp
@@ -227,6 +227,7 @@ bool InitHeaderSearch::ShouldAddDefaultIncludePaths(
case llvm::Triple::PS4:
case llvm::Triple::PS5:
case llvm::Triple::RTEMS:
+ case llvm::Triple::Serenity:
case llvm::Triple::Solaris:
case llvm::Triple::UEFI:
case llvm::Triple::WASI:
diff --git a/clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-unknown-serenity/clang_rt.crtbegin.o b/clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-unknown-serenity/clang_rt.crtbegin.o
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git a/clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-unknown-serenity/clang_rt.crtend.o b/clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/aarch64-unknown-serenity/clang_rt.crtend.o
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git a/clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/riscv64-unknown-serenity/clang_rt.crtbegin.o b/clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/riscv64-unknown-serenity/clang_rt.crtbegin.o
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git a/clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/riscv64-unknown-serenity/clang_rt.crtend.o b/clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/riscv64-unknown-serenity/clang_rt.crtend.o
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git a/clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-unknown-serenity/clang_rt.crtbegin.o b/clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-unknown-serenity/clang_rt.crtbegin.o
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git a/clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-unknown-serenity/clang_rt.crtend.o b/clang/test/Driver/Inputs/resource_dir_with_per_target_subdir/lib/x86_64-unknown-serenity/clang_rt.crtend.o
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git a/clang/test/Driver/Inputs/serenity_tree/usr/include/c++/v1/.keep b/clang/test/Driver/Inputs/serenity_tree/usr/include/c++/v1/.keep
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git a/clang/test/Driver/Inputs/serenity_tree/usr/lib/crt0.o b/clang/test/Driver/Inputs/serenity_tree/usr/lib/crt0.o
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git a/clang/test/Driver/Inputs/serenity_tree/usr/local/.keep b/clang/test/Driver/Inputs/serenity_tree/usr/local/.keep
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git a/clang/test/Driver/pic.c b/clang/test/Driver/pic.c
index f5d0745422790..7a63e79742f85 100644
--- a/clang/test/Driver/pic.c
+++ b/clang/test/Driver/pic.c
@@ -329,3 +329,11 @@
// RUN: | FileCheck %s --check-prefix=CHECK-PIC2
// RUN: %clang -c %s --target=i586-pc-haiku -### 2>&1 \
// RUN: | FileCheck %s --check-prefix=CHECK-PIC2
+
+// Serenity has PIC and PIE by default
+// RUN: %clang -c %s --target=x86_64-unkown-serenity -### 2>&1 \
+// RUN: | FileCheck %s --check-prefix=CHECK-PIE2
+// RUN: %clang -c %s --target=aarch64-unkown-serenity -### 2>&1 \
+// RUN: | FileCheck %s --check-prefix=CHECK-PIE2
+// RUN: %clang -c %s --target=riscv64-unkown-serenity -### 2>&1 \
+// RUN: | FileCheck %s --check-prefix=CHECK-PIE2
diff --git a/clang/test/Driver/save-stats.c b/clang/test/Driver/save-stats.c
index ad7867a991686..4821a2f175c32 100644
--- a/clang/test/Driver/save-stats.c
+++ b/clang/test/Driver/save-stats.c
@@ -30,6 +30,8 @@
// RUN: %clang --target=x86_64-unknown-fuchsia -save-stats -flto -o obj/dir/save-stats.exe -Wl,-plugin-opt=-dummy %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
// RUN: %clang --target=x86_64-unknown-haiku -save-stats -flto -o obj/dir/save-stats.exe %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
// RUN: %clang --target=x86_64-unknown-haiku -save-stats -flto -o obj/dir/save-stats.exe -Wl,-plugin-opt=-dummy %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
+// RUN: %clang --target=x86_64-unknown-serenity -save-stats -flto -o obj/dir/save-stats.exe %s -### 2>&1 | F...
[truncated]
|
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
🐧 Linux x64 Test Results
✅ The build succeeded and all tests passed. |
🪟 Windows x64 Test Results
✅ The build succeeded and all tests passed. |
It surprisingly compiles just fine with GCC.
|
Thanks for the review @MaskRay! |
|
@MaskRay Weekly ping. |
|
You should click "Re-request review". I read https://github.com/pulls/review-requested for PRs that require my attention. |
|
Noted! |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/17/builds/15418 Here is the relevant piece of the build log for the reference |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/143/builds/15127 Here is the relevant piece of the build log for the reference |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/127/builds/6956 Here is the relevant piece of the build log for the reference |
This one was fixed by #192231. All issues reported on this PR are fixed now, I believe. Please shout if that's not the case :) |
|
Hi, serenity.cpp is still failing on the AIX bot: |
Oh sorry about that, I should be able to open a PR tomorow. (Note to self: the aix buildbot is in the staging area https://lab.llvm.org/staging/#/builders/231) |
… r=davidtwco
compiler: Add `{x86_64,aarch64}-unknown-serenity` targets
This patch aims to add `x86_64-unknown-serenity` and `aarch64-unknown-serenity` targets as tier 3.
SerenityOS is a Unix-like hobbyist operating system with a UI that echoes back to the late '90s. The userspace libraries, applications and OS Kernel are entirely NIH, with only data dependencies on third parties (such as the UCD/CLDR for unicode support).
RISC-V is also supported, but I decided not to include it in this patch due to my lack of familiarity with the target. A follow-up adding it is likely.
Previous work in 2022 allowed us to write rust applications with std support as part of the base OS image, but those patches have bitrotted since. This is the first step of upstreaming that work.
cc @nico
<details>
<summary>Tier 3 Target Policy and responses</summary>
>Tier 3 target policy
>At this tier, the Rust project provides no official support for a target, so we
>place minimal requirements on the introduction of targets.
>A proposed new tier 3 target must be reviewed and approved by a member of the
>compiler team based on these requirements. The reviewer may choose to gauge
>broader compiler team consensus via a [Major Change Proposal (MCP)][MCP].
>A proposed target or target-specific patch that substantially changes code
>shared with other targets (not just target-specific code) must be reviewed and
>approved by the appropriate team for that shared code before acceptance.
>- A tier 3 target must have a designated developer or developers (the "target
> maintainers") on record to be CCed when issues arise regarding the target.
> (The mechanism to track and CC such developers may evolve over time.)
The maintainers will be @ADKaster and @nico
> - Targets must use naming consistent with any existing targets; for instance, a
> target for the same CPU or OS as an existing Rust target should use the same
> name for that CPU or OS. Targets should normally use the same names and
> naming conventions as used elsewhere in the broader ecosystem beyond Rust
> (such as in other toolchains), unless they have a very good reason to
> diverge. Changing the name of a target can be highly disruptive, especially
> once the target reaches a higher tier, so getting the name right is important
> even for a tier 3 target.
> - Target names should not introduce undue confusion or ambiguity unless
> absolutely necessary to maintain ecosystem compatibility. For example, if
> the name of the target makes people extremely likely to form incorrect
> beliefs about what it targets, the name should be changed or augmented to
> disambiguate it.
> - If possible, use only letters, numbers, dashes and underscores for the name.
> Periods (`.`) are known to cause issues in Cargo.
The target triples are `<arch>-unknown-serenity`. This is supported in LLVM and the upstream sources for config.sub and config.guess. GCC patches have not been upstreamed.
> - Tier 3 targets may have unusual requirements to build or use, but must not
> create legal issues or impose onerous legal terms for the Rust project or for
> Rust developers or users.
> - The target must not introduce license incompatibilities.
> - Anything added to the Rust repository must be under the standard Rust
> license (`MIT OR Apache-2.0`).
> - The target must not cause the Rust tools or libraries built for any other
> host (even when supporting cross-compilation to the target) to depend
> on any new dependency less permissive than the Rust licensing policy. This
> applies whether the dependency is a Rust crate that would require adding
> new license exceptions (as specified by the `tidy` tool in the
> rust-lang/rust repository), or whether the dependency is a native library
> or binary. In other words, the introduction of the target must not cause a
> user installing or running a version of Rust or the Rust tools to be
> subject to any new license requirements.
> - Compiling, linking, and emitting functional binaries, libraries, or other
> code for the target (whether hosted on the target itself or cross-compiling
> from another target) must not depend on proprietary (non-FOSS) libraries.
> Host tools built for the target itself may depend on the ordinary runtime
> libraries supplied by the platform and commonly used by other applications
> built for the target, but those libraries must not be required for code
> generation for the target; cross-compilation to the target must not require
> such libraries at all. For instance, `rustc` built for the target may
> depend on a common proprietary C runtime library or console output library,
> but must not depend on a proprietary code generation library or code
> optimization library. Rust's license permits such combinations, but the
> Rust project has no interest in maintaining such combinations within the
> scope of Rust itself, even at tier 3.
> - "onerous" here is an intentionally subjective term. At a minimum, "onerous"
> legal/licensing terms include but are *not* limited to: non-disclosure
> requirements, non-compete requirements, contributor license agreements
> (CLAs) or equivalent, "non-commercial"/"research-only"/etc terms,
> requirements conditional on the employer or employment of any particular
> Rust developers, revocable terms, any requirements that create liability
> for the Rust project or its developers or users, or any requirements that
> adversely affect the livelihood or prospects of the Rust project or its
> developers or users.
All the source code for the OS Kernel and Userland libraries is BSD 2-Clause licensed.
> - Neither this policy nor any decisions made regarding targets shall create any
> binding agreement or estoppel by any party. If any member of an approving
> Rust team serves as one of the maintainers of a target, or has any legal or
> employment requirement (explicit or implicit) that might affect their
> decisions regarding a target, they must recuse themselves from any approval
> decisions regarding the target's tier status, though they may otherwise
> participate in discussions.
> - This requirement does not prevent part or all of this policy from being
> cited in an explicit contract or work agreement (e.g. to implement or
> maintain support for a target). This requirement exists to ensure that a
> developer or team responsible for reviewing and approving a target does not
> face any legal threats or obligations that would prevent them from freely
> exercising their judgment in such approval, even if such judgment involves
> subjective matters or goes beyond the letter of these requirements.
Understood.
>- Tier 3 targets should attempt to implement as much of the standard libraries
> as possible and appropriate (`core` for most targets, `alloc` for targets
> that can support dynamic memory allocation, `std` for targets with an
> operating system or equivalent layer of system-provided functionality), but
> may leave some code unimplemented (either unavailable or stubbed out as
> appropriate), whether because the target makes it impossible to implement or
> challenging to implement. The authors of pull requests are not obligated to
> avoid calling any portions of the standard library on the basis of a tier 3
> target not implementing those portions.
This patch is based on previous work from 2022 that included full std support, including rust-lang/libc patches. Those patches will be updated to work with current main and uploaded for review after this patch.
>- The target must provide documentation for the Rust community explaining how
> to build for the target, using cross-compilation if possible. If the target
> supports running binaries, or running tests (even if they do not pass), the
> documentation must explain how to run such binaries or tests for the target,
> using emulation if possible or dedicated hardware if necessary.
The [BuildInstructions](https://github.com/SerenityOS/serenity/blob/master/Documentation/BuildInstructions.md) document includes host prerequisites and how to use the `Meta/serenity.sh` script to build a cross-compilation toolchain and launch a QEMU VM instance (with hardware acceleration if supported). The Ports/ subtree has information on building ported software. Out of tree applications have been known to work, but are not a primary target for OS developers.
>- Tier 3 targets must not impose burden on the authors of pull requests, or
> other developers in the community, to maintain the target. In particular,
> do not post comments (automated or manual) on a PR that derail or suggest a
> block on the PR based on a tier 3 target. Do not send automated messages or
> notifications (via any medium, including via `@`) to a PR author or others
> involved with a PR regarding a tier 3 target, unless they have opted into
> such messages.
> - Backlinks such as those generated by the issue/PR tracker when linking to
> an issue or PR are not considered a violation of this policy, within
> reason. However, such messages (even on a separate repository) must not
> generate notifications to anyone involved with a PR who has not requested
> such notifications.
Understood
>- Patches adding or updating tier 3 targets must not break any existing tier 2
> or tier 1 target, and must not knowingly break another tier 3 target without
> approval of either the compiler team or the maintainers of the other tier 3
> target.
> - In particular, this may come up when working on closely related targets,
> such as variations of the same architecture with different features. Avoid
> introducing unconditional uses of features that another variation of the
> target may not have; use conditional compilation or runtime detection, as
> appropriate, to let each target run code supported by that target.
This should not be an issue.
>- Tier 3 targets must be able to produce assembly using at least one of
> rustc's supported backends from any host target. (Having support in a fork
> of the backend is not sufficient, it must be upstream.)
Clang Driver support landed in LLVM 23. llvm/llvm-project#187941
There are several patches still in SerenityOS/serenity's Toolchain/Patches/llvm folder, but they are all related to hosting llvm and libcxx.
>If a tier 3 target stops meeting these requirements, or the target maintainers
>no longer have interest or time, or the target shows no signs of activity and
>has not built for some time, or removing the target would improve the quality
>of the Rust codebase, we may post a PR to remove it; any such PR will be CCed
>to the target maintainers (and potentially other people who have previously
>worked on the target), to check potential interest in improving the situation.
Understood.
</details>
Rollup merge of #164483 - ADKaster:serenity-initial-support, r=davidtwco compiler: Add `{x86_64,aarch64}-unknown-serenity` targets This patch aims to add `x86_64-unknown-serenity` and `aarch64-unknown-serenity` targets as tier 3. SerenityOS is a Unix-like hobbyist operating system with a UI that echoes back to the late '90s. The userspace libraries, applications and OS Kernel are entirely NIH, with only data dependencies on third parties (such as the UCD/CLDR for unicode support). RISC-V is also supported, but I decided not to include it in this patch due to my lack of familiarity with the target. A follow-up adding it is likely. Previous work in 2022 allowed us to write rust applications with std support as part of the base OS image, but those patches have bitrotted since. This is the first step of upstreaming that work. cc @nico <details> <summary>Tier 3 Target Policy and responses</summary> >Tier 3 target policy >At this tier, the Rust project provides no official support for a target, so we >place minimal requirements on the introduction of targets. >A proposed new tier 3 target must be reviewed and approved by a member of the >compiler team based on these requirements. The reviewer may choose to gauge >broader compiler team consensus via a [Major Change Proposal (MCP)][MCP]. >A proposed target or target-specific patch that substantially changes code >shared with other targets (not just target-specific code) must be reviewed and >approved by the appropriate team for that shared code before acceptance. >- A tier 3 target must have a designated developer or developers (the "target > maintainers") on record to be CCed when issues arise regarding the target. > (The mechanism to track and CC such developers may evolve over time.) The maintainers will be @ADKaster and @nico > - Targets must use naming consistent with any existing targets; for instance, a > target for the same CPU or OS as an existing Rust target should use the same > name for that CPU or OS. Targets should normally use the same names and > naming conventions as used elsewhere in the broader ecosystem beyond Rust > (such as in other toolchains), unless they have a very good reason to > diverge. Changing the name of a target can be highly disruptive, especially > once the target reaches a higher tier, so getting the name right is important > even for a tier 3 target. > - Target names should not introduce undue confusion or ambiguity unless > absolutely necessary to maintain ecosystem compatibility. For example, if > the name of the target makes people extremely likely to form incorrect > beliefs about what it targets, the name should be changed or augmented to > disambiguate it. > - If possible, use only letters, numbers, dashes and underscores for the name. > Periods (`.`) are known to cause issues in Cargo. The target triples are `<arch>-unknown-serenity`. This is supported in LLVM and the upstream sources for config.sub and config.guess. GCC patches have not been upstreamed. > - Tier 3 targets may have unusual requirements to build or use, but must not > create legal issues or impose onerous legal terms for the Rust project or for > Rust developers or users. > - The target must not introduce license incompatibilities. > - Anything added to the Rust repository must be under the standard Rust > license (`MIT OR Apache-2.0`). > - The target must not cause the Rust tools or libraries built for any other > host (even when supporting cross-compilation to the target) to depend > on any new dependency less permissive than the Rust licensing policy. This > applies whether the dependency is a Rust crate that would require adding > new license exceptions (as specified by the `tidy` tool in the > rust-lang/rust repository), or whether the dependency is a native library > or binary. In other words, the introduction of the target must not cause a > user installing or running a version of Rust or the Rust tools to be > subject to any new license requirements. > - Compiling, linking, and emitting functional binaries, libraries, or other > code for the target (whether hosted on the target itself or cross-compiling > from another target) must not depend on proprietary (non-FOSS) libraries. > Host tools built for the target itself may depend on the ordinary runtime > libraries supplied by the platform and commonly used by other applications > built for the target, but those libraries must not be required for code > generation for the target; cross-compilation to the target must not require > such libraries at all. For instance, `rustc` built for the target may > depend on a common proprietary C runtime library or console output library, > but must not depend on a proprietary code generation library or code > optimization library. Rust's license permits such combinations, but the > Rust project has no interest in maintaining such combinations within the > scope of Rust itself, even at tier 3. > - "onerous" here is an intentionally subjective term. At a minimum, "onerous" > legal/licensing terms include but are *not* limited to: non-disclosure > requirements, non-compete requirements, contributor license agreements > (CLAs) or equivalent, "non-commercial"/"research-only"/etc terms, > requirements conditional on the employer or employment of any particular > Rust developers, revocable terms, any requirements that create liability > for the Rust project or its developers or users, or any requirements that > adversely affect the livelihood or prospects of the Rust project or its > developers or users. All the source code for the OS Kernel and Userland libraries is BSD 2-Clause licensed. > - Neither this policy nor any decisions made regarding targets shall create any > binding agreement or estoppel by any party. If any member of an approving > Rust team serves as one of the maintainers of a target, or has any legal or > employment requirement (explicit or implicit) that might affect their > decisions regarding a target, they must recuse themselves from any approval > decisions regarding the target's tier status, though they may otherwise > participate in discussions. > - This requirement does not prevent part or all of this policy from being > cited in an explicit contract or work agreement (e.g. to implement or > maintain support for a target). This requirement exists to ensure that a > developer or team responsible for reviewing and approving a target does not > face any legal threats or obligations that would prevent them from freely > exercising their judgment in such approval, even if such judgment involves > subjective matters or goes beyond the letter of these requirements. Understood. >- Tier 3 targets should attempt to implement as much of the standard libraries > as possible and appropriate (`core` for most targets, `alloc` for targets > that can support dynamic memory allocation, `std` for targets with an > operating system or equivalent layer of system-provided functionality), but > may leave some code unimplemented (either unavailable or stubbed out as > appropriate), whether because the target makes it impossible to implement or > challenging to implement. The authors of pull requests are not obligated to > avoid calling any portions of the standard library on the basis of a tier 3 > target not implementing those portions. This patch is based on previous work from 2022 that included full std support, including rust-lang/libc patches. Those patches will be updated to work with current main and uploaded for review after this patch. >- The target must provide documentation for the Rust community explaining how > to build for the target, using cross-compilation if possible. If the target > supports running binaries, or running tests (even if they do not pass), the > documentation must explain how to run such binaries or tests for the target, > using emulation if possible or dedicated hardware if necessary. The [BuildInstructions](https://github.com/SerenityOS/serenity/blob/master/Documentation/BuildInstructions.md) document includes host prerequisites and how to use the `Meta/serenity.sh` script to build a cross-compilation toolchain and launch a QEMU VM instance (with hardware acceleration if supported). The Ports/ subtree has information on building ported software. Out of tree applications have been known to work, but are not a primary target for OS developers. >- Tier 3 targets must not impose burden on the authors of pull requests, or > other developers in the community, to maintain the target. In particular, > do not post comments (automated or manual) on a PR that derail or suggest a > block on the PR based on a tier 3 target. Do not send automated messages or > notifications (via any medium, including via `@`) to a PR author or others > involved with a PR regarding a tier 3 target, unless they have opted into > such messages. > - Backlinks such as those generated by the issue/PR tracker when linking to > an issue or PR are not considered a violation of this policy, within > reason. However, such messages (even on a separate repository) must not > generate notifications to anyone involved with a PR who has not requested > such notifications. Understood >- Patches adding or updating tier 3 targets must not break any existing tier 2 > or tier 1 target, and must not knowingly break another tier 3 target without > approval of either the compiler team or the maintainers of the other tier 3 > target. > - In particular, this may come up when working on closely related targets, > such as variations of the same architecture with different features. Avoid > introducing unconditional uses of features that another variation of the > target may not have; use conditional compilation or runtime detection, as > appropriate, to let each target run code supported by that target. This should not be an issue. >- Tier 3 targets must be able to produce assembly using at least one of > rustc's supported backends from any host target. (Having support in a fork > of the backend is not sufficient, it must be upstream.) Clang Driver support landed in LLVM 23. llvm/llvm-project#187941 There are several patches still in SerenityOS/serenity's Toolchain/Patches/llvm folder, but they are all related to hosting llvm and libcxx. >If a tier 3 target stops meeting these requirements, or the target maintainers >no longer have interest or time, or the target shows no signs of activity and >has not built for some time, or removing the target would improve the quality >of the Rust codebase, we may post a PR to remove it; any such PR will be CCed >to the target maintainers (and potentially other people who have previously >worked on the target), to check potential interest in improving the situation. Understood. </details>
compiler: Add `{x86_64,aarch64}-unknown-serenity` targets
This patch aims to add `x86_64-unknown-serenity` and `aarch64-unknown-serenity` targets as tier 3.
SerenityOS is a Unix-like hobbyist operating system with a UI that echoes back to the late '90s. The userspace libraries, applications and OS Kernel are entirely NIH, with only data dependencies on third parties (such as the UCD/CLDR for unicode support).
RISC-V is also supported, but I decided not to include it in this patch due to my lack of familiarity with the target. A follow-up adding it is likely.
Previous work in 2022 allowed us to write rust applications with std support as part of the base OS image, but those patches have bitrotted since. This is the first step of upstreaming that work.
cc @nico
<details>
<summary>Tier 3 Target Policy and responses</summary>
>Tier 3 target policy
>At this tier, the Rust project provides no official support for a target, so we
>place minimal requirements on the introduction of targets.
>A proposed new tier 3 target must be reviewed and approved by a member of the
>compiler team based on these requirements. The reviewer may choose to gauge
>broader compiler team consensus via a [Major Change Proposal (MCP)][MCP].
>A proposed target or target-specific patch that substantially changes code
>shared with other targets (not just target-specific code) must be reviewed and
>approved by the appropriate team for that shared code before acceptance.
>- A tier 3 target must have a designated developer or developers (the "target
> maintainers") on record to be CCed when issues arise regarding the target.
> (The mechanism to track and CC such developers may evolve over time.)
The maintainers will be @ADKaster and @nico
> - Targets must use naming consistent with any existing targets; for instance, a
> target for the same CPU or OS as an existing Rust target should use the same
> name for that CPU or OS. Targets should normally use the same names and
> naming conventions as used elsewhere in the broader ecosystem beyond Rust
> (such as in other toolchains), unless they have a very good reason to
> diverge. Changing the name of a target can be highly disruptive, especially
> once the target reaches a higher tier, so getting the name right is important
> even for a tier 3 target.
> - Target names should not introduce undue confusion or ambiguity unless
> absolutely necessary to maintain ecosystem compatibility. For example, if
> the name of the target makes people extremely likely to form incorrect
> beliefs about what it targets, the name should be changed or augmented to
> disambiguate it.
> - If possible, use only letters, numbers, dashes and underscores for the name.
> Periods (`.`) are known to cause issues in Cargo.
The target triples are `<arch>-unknown-serenity`. This is supported in LLVM and the upstream sources for config.sub and config.guess. GCC patches have not been upstreamed.
> - Tier 3 targets may have unusual requirements to build or use, but must not
> create legal issues or impose onerous legal terms for the Rust project or for
> Rust developers or users.
> - The target must not introduce license incompatibilities.
> - Anything added to the Rust repository must be under the standard Rust
> license (`MIT OR Apache-2.0`).
> - The target must not cause the Rust tools or libraries built for any other
> host (even when supporting cross-compilation to the target) to depend
> on any new dependency less permissive than the Rust licensing policy. This
> applies whether the dependency is a Rust crate that would require adding
> new license exceptions (as specified by the `tidy` tool in the
> rust-lang/rust repository), or whether the dependency is a native library
> or binary. In other words, the introduction of the target must not cause a
> user installing or running a version of Rust or the Rust tools to be
> subject to any new license requirements.
> - Compiling, linking, and emitting functional binaries, libraries, or other
> code for the target (whether hosted on the target itself or cross-compiling
> from another target) must not depend on proprietary (non-FOSS) libraries.
> Host tools built for the target itself may depend on the ordinary runtime
> libraries supplied by the platform and commonly used by other applications
> built for the target, but those libraries must not be required for code
> generation for the target; cross-compilation to the target must not require
> such libraries at all. For instance, `rustc` built for the target may
> depend on a common proprietary C runtime library or console output library,
> but must not depend on a proprietary code generation library or code
> optimization library. Rust's license permits such combinations, but the
> Rust project has no interest in maintaining such combinations within the
> scope of Rust itself, even at tier 3.
> - "onerous" here is an intentionally subjective term. At a minimum, "onerous"
> legal/licensing terms include but are *not* limited to: non-disclosure
> requirements, non-compete requirements, contributor license agreements
> (CLAs) or equivalent, "non-commercial"/"research-only"/etc terms,
> requirements conditional on the employer or employment of any particular
> Rust developers, revocable terms, any requirements that create liability
> for the Rust project or its developers or users, or any requirements that
> adversely affect the livelihood or prospects of the Rust project or its
> developers or users.
All the source code for the OS Kernel and Userland libraries is BSD 2-Clause licensed.
> - Neither this policy nor any decisions made regarding targets shall create any
> binding agreement or estoppel by any party. If any member of an approving
> Rust team serves as one of the maintainers of a target, or has any legal or
> employment requirement (explicit or implicit) that might affect their
> decisions regarding a target, they must recuse themselves from any approval
> decisions regarding the target's tier status, though they may otherwise
> participate in discussions.
> - This requirement does not prevent part or all of this policy from being
> cited in an explicit contract or work agreement (e.g. to implement or
> maintain support for a target). This requirement exists to ensure that a
> developer or team responsible for reviewing and approving a target does not
> face any legal threats or obligations that would prevent them from freely
> exercising their judgment in such approval, even if such judgment involves
> subjective matters or goes beyond the letter of these requirements.
Understood.
>- Tier 3 targets should attempt to implement as much of the standard libraries
> as possible and appropriate (`core` for most targets, `alloc` for targets
> that can support dynamic memory allocation, `std` for targets with an
> operating system or equivalent layer of system-provided functionality), but
> may leave some code unimplemented (either unavailable or stubbed out as
> appropriate), whether because the target makes it impossible to implement or
> challenging to implement. The authors of pull requests are not obligated to
> avoid calling any portions of the standard library on the basis of a tier 3
> target not implementing those portions.
This patch is based on previous work from 2022 that included full std support, including rust-lang/libc patches. Those patches will be updated to work with current main and uploaded for review after this patch.
>- The target must provide documentation for the Rust community explaining how
> to build for the target, using cross-compilation if possible. If the target
> supports running binaries, or running tests (even if they do not pass), the
> documentation must explain how to run such binaries or tests for the target,
> using emulation if possible or dedicated hardware if necessary.
The [BuildInstructions](https://github.com/SerenityOS/serenity/blob/master/Documentation/BuildInstructions.md) document includes host prerequisites and how to use the `Meta/serenity.sh` script to build a cross-compilation toolchain and launch a QEMU VM instance (with hardware acceleration if supported). The Ports/ subtree has information on building ported software. Out of tree applications have been known to work, but are not a primary target for OS developers.
>- Tier 3 targets must not impose burden on the authors of pull requests, or
> other developers in the community, to maintain the target. In particular,
> do not post comments (automated or manual) on a PR that derail or suggest a
> block on the PR based on a tier 3 target. Do not send automated messages or
> notifications (via any medium, including via `@`) to a PR author or others
> involved with a PR regarding a tier 3 target, unless they have opted into
> such messages.
> - Backlinks such as those generated by the issue/PR tracker when linking to
> an issue or PR are not considered a violation of this policy, within
> reason. However, such messages (even on a separate repository) must not
> generate notifications to anyone involved with a PR who has not requested
> such notifications.
Understood
>- Patches adding or updating tier 3 targets must not break any existing tier 2
> or tier 1 target, and must not knowingly break another tier 3 target without
> approval of either the compiler team or the maintainers of the other tier 3
> target.
> - In particular, this may come up when working on closely related targets,
> such as variations of the same architecture with different features. Avoid
> introducing unconditional uses of features that another variation of the
> target may not have; use conditional compilation or runtime detection, as
> appropriate, to let each target run code supported by that target.
This should not be an issue.
>- Tier 3 targets must be able to produce assembly using at least one of
> rustc's supported backends from any host target. (Having support in a fork
> of the backend is not sufficient, it must be upstream.)
Clang Driver support landed in LLVM 23. llvm/llvm-project#187941
There are several patches still in SerenityOS/serenity's Toolchain/Patches/llvm folder, but they are all related to hosting llvm and libcxx.
>If a tier 3 target stops meeting these requirements, or the target maintainers
>no longer have interest or time, or the target shows no signs of activity and
>has not built for some time, or removing the target would improve the quality
>of the Rust codebase, we may post a PR to remove it; any such PR will be CCed
>to the target maintainers (and potentially other people who have previously
>worked on the target), to check potential interest in improving the situation.
Understood.
</details>
compiler: Add `{x86_64,aarch64}-unknown-serenity` targets
This patch aims to add `x86_64-unknown-serenity` and `aarch64-unknown-serenity` targets as tier 3.
SerenityOS is a Unix-like hobbyist operating system with a UI that echoes back to the late '90s. The userspace libraries, applications and OS Kernel are entirely NIH, with only data dependencies on third parties (such as the UCD/CLDR for unicode support).
RISC-V is also supported, but I decided not to include it in this patch due to my lack of familiarity with the target. A follow-up adding it is likely.
Previous work in 2022 allowed us to write rust applications with std support as part of the base OS image, but those patches have bitrotted since. This is the first step of upstreaming that work.
cc @nico
<details>
<summary>Tier 3 Target Policy and responses</summary>
>Tier 3 target policy
>At this tier, the Rust project provides no official support for a target, so we
>place minimal requirements on the introduction of targets.
>A proposed new tier 3 target must be reviewed and approved by a member of the
>compiler team based on these requirements. The reviewer may choose to gauge
>broader compiler team consensus via a [Major Change Proposal (MCP)][MCP].
>A proposed target or target-specific patch that substantially changes code
>shared with other targets (not just target-specific code) must be reviewed and
>approved by the appropriate team for that shared code before acceptance.
>- A tier 3 target must have a designated developer or developers (the "target
> maintainers") on record to be CCed when issues arise regarding the target.
> (The mechanism to track and CC such developers may evolve over time.)
The maintainers will be @ADKaster and @nico
> - Targets must use naming consistent with any existing targets; for instance, a
> target for the same CPU or OS as an existing Rust target should use the same
> name for that CPU or OS. Targets should normally use the same names and
> naming conventions as used elsewhere in the broader ecosystem beyond Rust
> (such as in other toolchains), unless they have a very good reason to
> diverge. Changing the name of a target can be highly disruptive, especially
> once the target reaches a higher tier, so getting the name right is important
> even for a tier 3 target.
> - Target names should not introduce undue confusion or ambiguity unless
> absolutely necessary to maintain ecosystem compatibility. For example, if
> the name of the target makes people extremely likely to form incorrect
> beliefs about what it targets, the name should be changed or augmented to
> disambiguate it.
> - If possible, use only letters, numbers, dashes and underscores for the name.
> Periods (`.`) are known to cause issues in Cargo.
The target triples are `<arch>-unknown-serenity`. This is supported in LLVM and the upstream sources for config.sub and config.guess. GCC patches have not been upstreamed.
> - Tier 3 targets may have unusual requirements to build or use, but must not
> create legal issues or impose onerous legal terms for the Rust project or for
> Rust developers or users.
> - The target must not introduce license incompatibilities.
> - Anything added to the Rust repository must be under the standard Rust
> license (`MIT OR Apache-2.0`).
> - The target must not cause the Rust tools or libraries built for any other
> host (even when supporting cross-compilation to the target) to depend
> on any new dependency less permissive than the Rust licensing policy. This
> applies whether the dependency is a Rust crate that would require adding
> new license exceptions (as specified by the `tidy` tool in the
> rust-lang/rust repository), or whether the dependency is a native library
> or binary. In other words, the introduction of the target must not cause a
> user installing or running a version of Rust or the Rust tools to be
> subject to any new license requirements.
> - Compiling, linking, and emitting functional binaries, libraries, or other
> code for the target (whether hosted on the target itself or cross-compiling
> from another target) must not depend on proprietary (non-FOSS) libraries.
> Host tools built for the target itself may depend on the ordinary runtime
> libraries supplied by the platform and commonly used by other applications
> built for the target, but those libraries must not be required for code
> generation for the target; cross-compilation to the target must not require
> such libraries at all. For instance, `rustc` built for the target may
> depend on a common proprietary C runtime library or console output library,
> but must not depend on a proprietary code generation library or code
> optimization library. Rust's license permits such combinations, but the
> Rust project has no interest in maintaining such combinations within the
> scope of Rust itself, even at tier 3.
> - "onerous" here is an intentionally subjective term. At a minimum, "onerous"
> legal/licensing terms include but are *not* limited to: non-disclosure
> requirements, non-compete requirements, contributor license agreements
> (CLAs) or equivalent, "non-commercial"/"research-only"/etc terms,
> requirements conditional on the employer or employment of any particular
> Rust developers, revocable terms, any requirements that create liability
> for the Rust project or its developers or users, or any requirements that
> adversely affect the livelihood or prospects of the Rust project or its
> developers or users.
All the source code for the OS Kernel and Userland libraries is BSD 2-Clause licensed.
> - Neither this policy nor any decisions made regarding targets shall create any
> binding agreement or estoppel by any party. If any member of an approving
> Rust team serves as one of the maintainers of a target, or has any legal or
> employment requirement (explicit or implicit) that might affect their
> decisions regarding a target, they must recuse themselves from any approval
> decisions regarding the target's tier status, though they may otherwise
> participate in discussions.
> - This requirement does not prevent part or all of this policy from being
> cited in an explicit contract or work agreement (e.g. to implement or
> maintain support for a target). This requirement exists to ensure that a
> developer or team responsible for reviewing and approving a target does not
> face any legal threats or obligations that would prevent them from freely
> exercising their judgment in such approval, even if such judgment involves
> subjective matters or goes beyond the letter of these requirements.
Understood.
>- Tier 3 targets should attempt to implement as much of the standard libraries
> as possible and appropriate (`core` for most targets, `alloc` for targets
> that can support dynamic memory allocation, `std` for targets with an
> operating system or equivalent layer of system-provided functionality), but
> may leave some code unimplemented (either unavailable or stubbed out as
> appropriate), whether because the target makes it impossible to implement or
> challenging to implement. The authors of pull requests are not obligated to
> avoid calling any portions of the standard library on the basis of a tier 3
> target not implementing those portions.
This patch is based on previous work from 2022 that included full std support, including rust-lang/libc patches. Those patches will be updated to work with current main and uploaded for review after this patch.
>- The target must provide documentation for the Rust community explaining how
> to build for the target, using cross-compilation if possible. If the target
> supports running binaries, or running tests (even if they do not pass), the
> documentation must explain how to run such binaries or tests for the target,
> using emulation if possible or dedicated hardware if necessary.
The [BuildInstructions](https://github.com/SerenityOS/serenity/blob/master/Documentation/BuildInstructions.md) document includes host prerequisites and how to use the `Meta/serenity.sh` script to build a cross-compilation toolchain and launch a QEMU VM instance (with hardware acceleration if supported). The Ports/ subtree has information on building ported software. Out of tree applications have been known to work, but are not a primary target for OS developers.
>- Tier 3 targets must not impose burden on the authors of pull requests, or
> other developers in the community, to maintain the target. In particular,
> do not post comments (automated or manual) on a PR that derail or suggest a
> block on the PR based on a tier 3 target. Do not send automated messages or
> notifications (via any medium, including via `@`) to a PR author or others
> involved with a PR regarding a tier 3 target, unless they have opted into
> such messages.
> - Backlinks such as those generated by the issue/PR tracker when linking to
> an issue or PR are not considered a violation of this policy, within
> reason. However, such messages (even on a separate repository) must not
> generate notifications to anyone involved with a PR who has not requested
> such notifications.
Understood
>- Patches adding or updating tier 3 targets must not break any existing tier 2
> or tier 1 target, and must not knowingly break another tier 3 target without
> approval of either the compiler team or the maintainers of the other tier 3
> target.
> - In particular, this may come up when working on closely related targets,
> such as variations of the same architecture with different features. Avoid
> introducing unconditional uses of features that another variation of the
> target may not have; use conditional compilation or runtime detection, as
> appropriate, to let each target run code supported by that target.
This should not be an issue.
>- Tier 3 targets must be able to produce assembly using at least one of
> rustc's supported backends from any host target. (Having support in a fork
> of the backend is not sufficient, it must be upstream.)
Clang Driver support landed in LLVM 23. llvm/llvm-project#187941
There are several patches still in SerenityOS/serenity's Toolchain/Patches/llvm folder, but they are all related to hosting llvm and libcxx.
>If a tier 3 target stops meeting these requirements, or the target maintainers
>no longer have interest or time, or the target shows no signs of activity and
>has not built for some time, or removing the target would improve the quality
>of the Rust codebase, we may post a PR to remove it; any such PR will be CCed
>to the target maintainers (and potentially other people who have previously
>worked on the target), to check potential interest in improving the situation.
Understood.
</details>
Adds support for the $arch-unknown-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.
A first attempt at upstreaming this patch was made here. I hope I fixed everything mentioned there.
I intentionally kept
/usr/local/in the default lookup path. I consider it the more practical option, and I’d prefer to have the patch merged as is and revisit the FIXME later. If this is absolutely unacceptable to the maintainers, I will happily drop it and keep it as a local patch until we address the underlying issue.@MaskRay, @brad0 as you already reviewed the original patch.