summaryrefslogtreecommitdiff
path: root/Toolchain/Patches/llvm
diff options
context:
space:
mode:
authorAndrew Kaster <akaster@serenityos.org>2022-03-04 17:45:04 -0700
committerAndreas Kling <kling@serenityos.org>2022-05-02 01:46:18 +0200
commit4334bd06b8fe40d26c401cf315777045259c40fe (patch)
tree115de0850e4950f456e1b765374e58421c6d627d /Toolchain/Patches/llvm
parent9b041786ac76e925a664a44b1e0a0f8947643d5f (diff)
downloadserenity-4334bd06b8fe40d26c401cf315777045259c40fe.zip
Toolchain: Enable LLVM Profile instrumentation
Add a patch to let llvm's InstrProfiling modules know serenity supports all the Unix-y features required to make -fprofile-instr-generate and -fcoverage-mapping work properly on target.
Diffstat (limited to 'Toolchain/Patches/llvm')
-rw-r--r--Toolchain/Patches/llvm/0001-Support-Add-support-for-building-LLVM-on-SerenityOS.patch2
-rw-r--r--Toolchain/Patches/llvm/0002-Triple-Add-triple-for-SerenityOS.patch2
-rw-r--r--Toolchain/Patches/llvm/0003-Driver-Add-support-for-SerenityOS.patch2
-rw-r--r--Toolchain/Patches/llvm/0004-Driver-Default-to-ftls-model-initial-exec-on-Serenit.patch2
-rw-r--r--Toolchain/Patches/llvm/0005-libc-Add-support-for-SerenityOS.patch2
-rw-r--r--Toolchain/Patches/llvm/0006-compiler-rt-Build-crtbegin.o-crtend.o-for-SerenityOS.patch2
-rw-r--r--Toolchain/Patches/llvm/0007-cmake-Allow-undefined-symbols-on-SerenityOS.patch2
-rw-r--r--Toolchain/Patches/llvm/0008-cmake-Support-building-shared-libLLVM-and-libClang-f.patch2
-rw-r--r--Toolchain/Patches/llvm/0009-compiler-rt-llvm-Enable-profile-instrumentation-for-.patch75
-rw-r--r--Toolchain/Patches/llvm/ReadMe.md9
10 files changed, 92 insertions, 8 deletions
diff --git a/Toolchain/Patches/llvm/0001-Support-Add-support-for-building-LLVM-on-SerenityOS.patch b/Toolchain/Patches/llvm/0001-Support-Add-support-for-building-LLVM-on-SerenityOS.patch
index 50d571ab7d..90de24380c 100644
--- a/Toolchain/Patches/llvm/0001-Support-Add-support-for-building-LLVM-on-SerenityOS.patch
+++ b/Toolchain/Patches/llvm/0001-Support-Add-support-for-building-LLVM-on-SerenityOS.patch
@@ -1,7 +1,7 @@
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
+Subject: [PATCH 1/9] [Support] Add support for building LLVM on SerenityOS
Adds SerenityOS `#ifdef`s for platform-specific code.
diff --git a/Toolchain/Patches/llvm/0002-Triple-Add-triple-for-SerenityOS.patch b/Toolchain/Patches/llvm/0002-Triple-Add-triple-for-SerenityOS.patch
index 25275c7d5f..bcfe1a2ac7 100644
--- a/Toolchain/Patches/llvm/0002-Triple-Add-triple-for-SerenityOS.patch
+++ b/Toolchain/Patches/llvm/0002-Triple-Add-triple-for-SerenityOS.patch
@@ -1,7 +1,7 @@
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
+Subject: [PATCH 2/9] [Triple] Add triple for SerenityOS
---
llvm/include/llvm/ADT/Triple.h | 8 +++++++-
diff --git a/Toolchain/Patches/llvm/0003-Driver-Add-support-for-SerenityOS.patch b/Toolchain/Patches/llvm/0003-Driver-Add-support-for-SerenityOS.patch
index 36cebcc697..a41edd67ab 100644
--- a/Toolchain/Patches/llvm/0003-Driver-Add-support-for-SerenityOS.patch
+++ b/Toolchain/Patches/llvm/0003-Driver-Add-support-for-SerenityOS.patch
@@ -1,7 +1,7 @@
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
+Subject: [PATCH 3/9] [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
diff --git a/Toolchain/Patches/llvm/0004-Driver-Default-to-ftls-model-initial-exec-on-Serenit.patch b/Toolchain/Patches/llvm/0004-Driver-Default-to-ftls-model-initial-exec-on-Serenit.patch
index 11eb6e6937..7c12a2e364 100644
--- a/Toolchain/Patches/llvm/0004-Driver-Default-to-ftls-model-initial-exec-on-Serenit.patch
+++ b/Toolchain/Patches/llvm/0004-Driver-Default-to-ftls-model-initial-exec-on-Serenit.patch
@@ -1,7 +1,7 @@
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
+Subject: [PATCH 4/9] [Driver] Default to -ftls-model=initial-exec on
SerenityOS
This is a hack to make Clang use the initial-exec TLS model instead of
diff --git a/Toolchain/Patches/llvm/0005-libc-Add-support-for-SerenityOS.patch b/Toolchain/Patches/llvm/0005-libc-Add-support-for-SerenityOS.patch
index 3407153388..aa55de19ad 100644
--- a/Toolchain/Patches/llvm/0005-libc-Add-support-for-SerenityOS.patch
+++ b/Toolchain/Patches/llvm/0005-libc-Add-support-for-SerenityOS.patch
@@ -1,7 +1,7 @@
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
+Subject: [PATCH 5/9] [libc++] Add support for SerenityOS
This commit teaches libc++ about what features are available in our
LibC, namely:
diff --git a/Toolchain/Patches/llvm/0006-compiler-rt-Build-crtbegin.o-crtend.o-for-SerenityOS.patch b/Toolchain/Patches/llvm/0006-compiler-rt-Build-crtbegin.o-crtend.o-for-SerenityOS.patch
index 25a01acc94..297fa542b9 100644
--- a/Toolchain/Patches/llvm/0006-compiler-rt-Build-crtbegin.o-crtend.o-for-SerenityOS.patch
+++ b/Toolchain/Patches/llvm/0006-compiler-rt-Build-crtbegin.o-crtend.o-for-SerenityOS.patch
@@ -1,7 +1,7 @@
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
+Subject: [PATCH 6/9] [compiler-rt] Build crtbegin.o/crtend.o for SerenityOS
---
compiler-rt/cmake/config-ix.cmake | 2 +-
diff --git a/Toolchain/Patches/llvm/0007-cmake-Allow-undefined-symbols-on-SerenityOS.patch b/Toolchain/Patches/llvm/0007-cmake-Allow-undefined-symbols-on-SerenityOS.patch
index 6f85426ba4..276dc630bf 100644
--- a/Toolchain/Patches/llvm/0007-cmake-Allow-undefined-symbols-on-SerenityOS.patch
+++ b/Toolchain/Patches/llvm/0007-cmake-Allow-undefined-symbols-on-SerenityOS.patch
@@ -1,7 +1,7 @@
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
+Subject: [PATCH 7/9] [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
diff --git a/Toolchain/Patches/llvm/0008-cmake-Support-building-shared-libLLVM-and-libClang-f.patch b/Toolchain/Patches/llvm/0008-cmake-Support-building-shared-libLLVM-and-libClang-f.patch
index abb9c098e4..88d2f88340 100644
--- a/Toolchain/Patches/llvm/0008-cmake-Support-building-shared-libLLVM-and-libClang-f.patch
+++ b/Toolchain/Patches/llvm/0008-cmake-Support-building-shared-libLLVM-and-libClang-f.patch
@@ -1,7 +1,7 @@
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
+Subject: [PATCH 8/9] [cmake] Support building shared libLLVM and libClang for
SerenityOS
This patch tells CMake that the --whole-archive linker option should be
diff --git a/Toolchain/Patches/llvm/0009-compiler-rt-llvm-Enable-profile-instrumentation-for-.patch b/Toolchain/Patches/llvm/0009-compiler-rt-llvm-Enable-profile-instrumentation-for-.patch
new file mode 100644
index 0000000000..15370af2ce
--- /dev/null
+++ b/Toolchain/Patches/llvm/0009-compiler-rt-llvm-Enable-profile-instrumentation-for-.patch
@@ -0,0 +1,75 @@
+From 539a12f2955a737f550be655c56a1a993eaa1ae2 Mon Sep 17 00:00:00 2001
+From: Andrew Kaster <akaster@serenityos.org>
+Date: Fri, 4 Mar 2022 15:13:42 -0700
+Subject: [PATCH 9/9] [compiler-rt/llvm] 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.
+
+Curiously, enabling profiling for the SerenityOS target changes the ELF
+OS ABI for userspace binaries to 3, or GNU/Linux.
+---
+ compiler-rt/cmake/config-ix.cmake | 2 +-
+ compiler-rt/lib/profile/InstrProfilingPlatformLinux.c | 3 ++-
+ compiler-rt/lib/profile/InstrProfilingPlatformOther.c | 2 +-
+ llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp | 3 ++-
+ 4 files changed, 6 insertions(+), 4 deletions(-)
+
+diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake
+index 7a47b7f..8d4211d 100644
+--- a/compiler-rt/cmake/config-ix.cmake
++++ b/compiler-rt/cmake/config-ix.cmake
+@@ -738,7 +738,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 592c09b..1833682 100644
+--- a/compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
++++ b/compiler-rt/lib/profile/InstrProfilingPlatformLinux.c
+@@ -7,7 +7,8 @@
+ \*===----------------------------------------------------------------------===*/
+
+ #if defined(__linux__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \
+- (defined(__sun__) && defined(__svr4__)) || defined(__NetBSD__)
++ (defined(__sun__) && defined(__svr4__)) || defined(__NetBSD__) || \
++ defined(__serenity__)
+
+ #include <elf.h>
+ #include <link.h>
+diff --git a/compiler-rt/lib/profile/InstrProfilingPlatformOther.c b/compiler-rt/lib/profile/InstrProfilingPlatformOther.c
+index 3e9b3ca..d257013 100644
+--- a/compiler-rt/lib/profile/InstrProfilingPlatformOther.c
++++ b/compiler-rt/lib/profile/InstrProfilingPlatformOther.c
+@@ -8,7 +8,7 @@
+
+ #if !defined(__APPLE__) && !defined(__linux__) && !defined(__FreeBSD__) && \
+ !(defined(__sun__) && defined(__svr4__)) && !defined(__NetBSD__) && \
+- !defined(_WIN32)
++ !defined(_WIN32) && !defined(__serenity__)
+
+ #include <stdlib.h>
+ #include <stdio.h>
+diff --git a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
+index 6868408..eaa1b64 100644
+--- a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
++++ b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
+@@ -857,7 +857,8 @@ static bool needsRuntimeRegistrationOfSectionRange(const Triple &TT) {
+ return false;
+ // Use linker script magic to get data/cnts/name start/end.
+ if (TT.isOSLinux() || TT.isOSFreeBSD() || TT.isOSNetBSD() ||
+- TT.isOSSolaris() || TT.isOSFuchsia() || TT.isPS4CPU() || TT.isOSWindows())
++ TT.isOSSolaris() || TT.isOSFuchsia() || TT.isPS4CPU() ||
++ TT.isOSWindows() || TT.isOSSerenity())
+ return false;
+
+ return true;
+--
+2.32.0
+
diff --git a/Toolchain/Patches/llvm/ReadMe.md b/Toolchain/Patches/llvm/ReadMe.md
index 7ebf072a6f..54dfdca6cc 100644
--- a/Toolchain/Patches/llvm/ReadMe.md
+++ b/Toolchain/Patches/llvm/ReadMe.md
@@ -76,3 +76,12 @@ 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.
+## `0009-compiler-rt-llvm-Enable-profile-instrumentation-for-.patch`
+
+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.
+
+Curiously, enabling profiling for the SerenityOS target changes the ELF
+OS ABI for userspace binaries to 3, or GNU/Linux.