mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 13:36:13 +03:00
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.
This commit is contained in:
parent
9b041786ac
commit
4334bd06b8
Notes:
sideshowbarker
2024-07-17 11:23:59 +09:00
Author: https://github.com/ADKaster Commit: https://github.com/SerenityOS/serenity/commit/4334bd06b8 Pull-request: https://github.com/SerenityOS/serenity/pull/12881 Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/bgianfo Reviewed-by: https://github.com/kleinesfilmroellchen
@ -232,7 +232,7 @@ pushd "$DIR/Tarballs"
|
||||
git init > /dev/null
|
||||
git add . > /dev/null
|
||||
git commit -am "BASE" > /dev/null
|
||||
git am "$DIR"/Patches/llvm/*.patch > /dev/null
|
||||
git am --keep-non-patch "$DIR"/Patches/llvm/*.patch > /dev/null
|
||||
else
|
||||
for patch in "$DIR"/Patches/llvm/*.patch; do
|
||||
patch -p1 < "$patch" > /dev/null
|
||||
|
@ -37,7 +37,7 @@ foreach(target i686-pc-serenity;x86_64-pc-serenity;aarch64-pc-serenity)
|
||||
set(RUNTIMES_${target}_COMPILER_RT_BUILD_SANITIZERS OFF CACHE BOOL "")
|
||||
set(RUNTIMES_${target}_COMPILER_RT_BUILD_LIBFUZZER OFF CACHE BOOL "")
|
||||
set(RUNTIMES_${target}_COMPILER_RT_BUILD_MEMPROF OFF CACHE BOOL "")
|
||||
set(RUNTIMES_${target}_COMPILER_RT_BUILD_PROFILE OFF CACHE BOOL "")
|
||||
set(RUNTIMES_${target}_COMPILER_RT_BUILD_PROFILE ON CACHE BOOL "")
|
||||
set(RUNTIMES_${target}_COMPILER_RT_BUILD_XRAY OFF CACHE BOOL "")
|
||||
set(RUNTIMES_${target}_COMPILER_RT_BUILD_ORC OFF CACHE BOOL "")
|
||||
set(RUNTIMES_${target}_CMAKE_SYSTEM_NAME SerenityOS CACHE STRING "")
|
||||
|
@ -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.
|
||||
|
||||
|
@ -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 +++++++-
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
@ -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 +-
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user