mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-14 20:03:29 +00:00
fa1eef8bbe
Apart from bumping the toolchain Clang's and port's version, this commit completely overhauls the way LLVM toolchain is built. First, it gets rid of a complicated two-stage process of first compiling clang and compiler-rt builtins and then building libunwind, libc++abi, and libc++ -- it is possible to create a complete cross-compilation toolchain in a single CMake invocation with a modern LLVM. Moreover, the old method was inherently unsupported and subtly broken. Next, it utilizes full potential of the Stubs "framework". Now we are even able to compile Clang with -Wl,-z,defs which makes one of the patches obsolete and the whole installation less error-prone. Note that it comes at a cost of complicating the bootstrap process on a completely novel architecture but this hopefully won't happen often. Lastly, it fixes handling of the -no*lib* family of flags in the Serenity LLVM driver and correctly uses -nostartfiles in conjunction with stubs to make necessary CMake configure-time checks succeed.
111 lines
5 KiB
Diff
111 lines
5 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Andrew Kaster <akaster@serenityos.org>
|
|
Date: Fri, 4 Mar 2022 15:13:42 -0700
|
|
Subject: [PATCH] [compiler-rt] Enable profile instrumentation for SerenityOS
|
|
|
|
Treat SerenityOS the same as other *NIX platforms that behave close
|
|
enough to linux to use the pre-canned InstrProfiling implementation.
|
|
---
|
|
clang/lib/Driver/ToolChains/Serenity.cpp | 3 +++
|
|
clang/test/Driver/instrprof-ld.c | 20 +++++++++++++++++++
|
|
compiler-rt/cmake/config-ix.cmake | 2 +-
|
|
.../lib/profile/InstrProfilingPlatformLinux.c | 2 +-
|
|
.../lib/profile/InstrProfilingPlatformOther.c | 3 ++-
|
|
5 files changed, 27 insertions(+), 3 deletions(-)
|
|
|
|
diff --git a/clang/lib/Driver/ToolChains/Serenity.cpp b/clang/lib/Driver/ToolChains/Serenity.cpp
|
|
index 2167758100bc..c132e5c41185 100644
|
|
--- a/clang/lib/Driver/ToolChains/Serenity.cpp
|
|
+++ b/clang/lib/Driver/ToolChains/Serenity.cpp
|
|
@@ -183,6 +183,9 @@ void tools::serenity::Linker::ConstructJob(Compilation &C, const JobAction &JA,
|
|
CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("crtn.o")));
|
|
}
|
|
|
|
+ if (ShouldLinkCompilerRuntime)
|
|
+ TC.addProfileRTLibs(Args, CmdArgs);
|
|
+
|
|
const char *Exec = Args.MakeArgString(TC.GetLinkerPath());
|
|
C.addCommand(std::make_unique<Command>(JA, *this,
|
|
ResponseFileSupport::AtFileCurCP(),
|
|
diff --git a/clang/test/Driver/instrprof-ld.c b/clang/test/Driver/instrprof-ld.c
|
|
index 9a58cd3a0be7..d37de48b9d83 100644
|
|
--- a/clang/test/Driver/instrprof-ld.c
|
|
+++ b/clang/test/Driver/instrprof-ld.c
|
|
@@ -54,6 +54,15 @@
|
|
// CHECK-OPENBSD-X86-64: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
|
|
// CHECK-OPENBSD-X86-64: "{{.*}}/Inputs/resource_dir{{/|\\\\}}lib{{/|\\\\}}openbsd{{/|\\\\}}libclang_rt.profile-x86_64.a"
|
|
|
|
+// RUN: %clang -### %s 2>&1 \
|
|
+// RUN: --target=x86_64-pc-serenity -fprofile-instr-generate -fuse-ld=ld \
|
|
+// RUN: -resource-dir=%S/Inputs/resource_dir \
|
|
+// RUN: --sysroot=%S/Inputs/serenity_x86_64_tree \
|
|
+// RUN: | FileCheck --check-prefix=CHECK-SERENITY-X86-64 %s
|
|
+
|
|
+// CHECK-SERENITY-X86-64: "{{(.*[^-.0-9A-Z_a-z])?}}ld.lld{{(.exe)?}}"
|
|
+// CHECK-SERENITY-X86-64: "{{.*}}/Inputs/resource_dir{{/|\\\\}}lib{{/|\\\\}}serenity{{/|\\\\}}libclang_rt.profile-x86_64.a"
|
|
+
|
|
// RUN: %clang -### %s 2>&1 \
|
|
// RUN: -shared \
|
|
// RUN: --target=i386-unknown-linux -fprofile-instr-generate -fuse-ld=ld \
|
|
@@ -104,6 +113,17 @@
|
|
// CHECK-OPENBSD-X86-64-SHARED: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
|
|
// CHECK-OPENBSD-X86-64-SHARED: "{{.*}}/Inputs/resource_dir{{/|\\\\}}lib{{/|\\\\}}openbsd{{/|\\\\}}libclang_rt.profile-x86_64.a"
|
|
|
|
+// RUN: %clang -### %s 2>&1 \
|
|
+// RUN: -shared \
|
|
+// RUN: --target=x86_64-pc-serenity -fprofile-instr-generate -fuse-ld=ld \
|
|
+// RUN: -resource-dir=%S/Inputs/resource_dir \
|
|
+// RUN: --sysroot=%S/Inputs/serenity_x86_64_tree \
|
|
+// RUN: | FileCheck --check-prefix=CHECK-SERENITY-X86-64-SHARED %s
|
|
+
|
|
+// CHECK-SERENITY-X86-64-SHARED: "{{(.*[^-.0-9A-Z_a-z])?}}ld.lld{{(.exe)?}}"
|
|
+// CHECK-SERENITY-X86-64-SHARED: "{{.*}}/Inputs/resource_dir{{/|\\\\}}lib{{/|\\\\}}serenity{{/|\\\\}}libclang_rt.profile-x86_64.a"
|
|
+
|
|
+
|
|
// RUN: %clang -### %s 2>&1 \
|
|
// RUN: --target=x86_64-apple-darwin14 -fprofile-instr-generate -fuse-ld=ld \
|
|
// RUN: -resource-dir=%S/Inputs/resource_dir \
|
|
diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake
|
|
index 2ca18ebb4ad4..e9e00e6fec5c 100644
|
|
--- a/compiler-rt/cmake/config-ix.cmake
|
|
+++ b/compiler-rt/cmake/config-ix.cmake
|
|
@@ -795,7 +795,7 @@ else()
|
|
endif()
|
|
|
|
if (PROFILE_SUPPORTED_ARCH AND NOT LLVM_USE_SANITIZER AND
|
|
- OS_NAME MATCHES "Darwin|Linux|FreeBSD|Windows|Android|Fuchsia|SunOS|NetBSD|AIX")
|
|
+ OS_NAME MATCHES "Darwin|Linux|FreeBSD|Windows|Android|Fuchsia|SunOS|NetBSD|AIX|SerenityOS")
|
|
set(COMPILER_RT_HAS_PROFILE TRUE)
|
|
else()
|
|
set(COMPILER_RT_HAS_PROFILE FALSE)
|
|
diff --git a/compiler-rt/lib/profile/InstrProfilingPlatformLinux.c b/compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
|
|
index 19266ab6c6fb..ee7200730f86 100644
|
|
--- a/compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
|
|
+++ b/compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
|
|
@@ -8,7 +8,7 @@
|
|
|
|
#if defined(__linux__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \
|
|
(defined(__sun__) && defined(__svr4__)) || defined(__NetBSD__) || \
|
|
- defined(_AIX)
|
|
+ defined(_AIX) || defined(__serenity__)
|
|
|
|
#if !defined(_AIX)
|
|
#include <elf.h>
|
|
diff --git a/compiler-rt/lib/profile/InstrProfilingPlatformOther.c b/compiler-rt/lib/profile/InstrProfilingPlatformOther.c
|
|
index 5319ca813b43..40ff14b75e7c 100644
|
|
--- a/compiler-rt/lib/profile/InstrProfilingPlatformOther.c
|
|
+++ b/compiler-rt/lib/profile/InstrProfilingPlatformOther.c
|
|
@@ -8,7 +8,8 @@
|
|
|
|
#if !defined(__APPLE__) && !defined(__linux__) && !defined(__FreeBSD__) && \
|
|
!defined(__Fuchsia__) && !(defined(__sun__) && defined(__svr4__)) && \
|
|
- !defined(__NetBSD__) && !defined(_WIN32) && !defined(_AIX)
|
|
+ !defined(__NetBSD__) && !defined(_WIN32) && !defined(_AIX) && \
|
|
+ !defined(__serenity__)
|
|
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
--
|
|
2.44.0
|
|
|