Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 94556bd2d2ae842db20073afba23f52412dc6d81
https://github.com/WebKit/WebKit/commit/94556bd2d2ae842db20073afba23f52412dc6d81
Author: Lauro Moura <[email protected]>
Date: 2026-04-10 (Fri, 10 Apr 2026)
Changed paths:
M Source/WebKit/Shared/unix/AuxiliaryProcessMain.cpp
M Source/WebKit/UIProcess/Launcher/glib/ProcessLauncherGLib.cpp
M Source/cmake/OptionsCommon.cmake
M Source/cmake/WebKitCommon.cmake
M Source/cmake/WebKitFeatures.cmake
M Source/cmake/WebKitMacros.cmake
Log Message:
-----------
[CMake][GLIB] Support PGO features in regular CMake builds with clang
https://bugs.webkit.org/show_bug.cgi?id=309318
Reviewed by Adrian Perez de Castro.
PGO (Profile Guided Optimization) is usually performed in two phases,
which in WebKit are controlled by the following two cmake options:
- ENABLE_LLVM_PROFILE_GENERATION: Tells clang to add IR-profiling
instrumentation code to the build. When we run the instrumented
binaries, this code will collect the profile data and save into
.profraw files at the PGO_PROFILE_DIR directory (overridden by
LLVM_PROFILE_FILE envvar). These files are then merged into a single
.profdata file.
- USE_PGO_PROFILE: Tells clang to use the profdata at PGO_PROFILE_PATH
as an example of the expected workload, so it can make better
predictions when generating the final build.
While GCC also supports `-fprofile-generate` and `-fprofile-use`, it
appeared much more strict during compilation, emitting various warnings
related to missing/mismatched coverage, string formatters, etc.. It also
had issues with profile generation in distributed builds, generating the
wrong annotations in remote compilation jobs. So we'll focus on clang in
this initial patch, adding GCC support in the future.
By default, the instrumented build will save the profiles using clang's
default path, but this can be overridden at compile time with
`-DPGO_PROFILE_DIR=PATH`, and at runtime with `LLVM_PROFILE_FILE`. You
might want to set it to an absolute path for distributed builds with
icecc, as the usage of `-fprofile-generate` might lead it to think we're
generating files during compilation, forcing local jobs.
During instrumented builds, there were some problems with the symbols
when compiling executables and linking, so actual instrumentation is
compiled only into WEBKIT_LIBRARY and WEBKIT_FRAMEWORK. Given the hot
paths are usually on the library itself, should not be a problem. Also,
instrumented builds add multiple __llvm_profile_filename definitions,
that clash when LTO is enabled. Given they have the same value, taken
from PGO_PROFILE_DIR, it's safe to turn this into a non-fatal warning.
By default, clang dumps the instrumented data in the `atexit` handler,
which might not be called in forced terminations. For example,
`ProcessLauncherGLib.cpp` uses SIGKILL to terminate the children. That
means that we could potentially lose the data from the WebProcess even
if the UIProcess exits cleanly.
This commit adds a SIGTERM handler in auxiliary process to explicitly
dump the collected data. It also makes the ProcessLauncher send first
SIGTERM, and wait 500ms before sending SIGKILL, which should be enough
to save the profile. Note that this only affects instrumented builds.
* Source/WebKit/Shared/unix/AuxiliaryProcessMain.cpp:
(WebKit::AuxiliaryProcess::platformInitialize):
* Source/WebKit/UIProcess/Launcher/glib/ProcessLauncherGLib.cpp:
(WebKit::ProcessLauncher::terminateProcess):
* Source/cmake/OptionsCommon.cmake:
* Source/cmake/WebKitCommon.cmake:
* Source/cmake/WebKitFeatures.cmake:
* Source/cmake/WebKitMacros.cmake:
Canonical link: https://commits.webkit.org/310954@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications