Add pgo build type

One of the ways we can optimize our builds is with profile guided
optimization.  This entails doing several things:

1) Building with --coverage
2) Running an application against the openssl library from step (1) to
   generate profile data
3) rebuilding openssl using the input profile from step (2) to optimize
   the build.

This new build configuration will let developers use the profiled data
to see what type of optimizations might be possible, as well as giving
end users the ability to squeeze a bit more performance out of openssl

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/27839)
This commit is contained in:
Neil Horman 2025-06-16 16:33:22 -04:00
parent effba0ee65
commit d8277a6fba
3 changed files with 41 additions and 1 deletions

View File

@ -679,7 +679,9 @@ my %targets = (
CXX => "g++",
CFLAGS => picker(default => "-Wall",
debug => "-O0 -g",
release => "-O3"),
release => "-O3",
profiled => "-O3 -fprofile-generate -fprofile-arcs -fprofile-values -ftest-coverage",
pgo => "-O3 -fprofile-use -Wno-missing-profile"),
CXXFLAGS => picker(default => "-Wall",
debug => "-O0 -g",
release => "-O3"),

View File

@ -990,6 +990,10 @@ while (@argvcopy)
{
$config{build_type} = "debug";
}
elsif (/^-p$/)
{
$config{build_type} = "profiled";
}
elsif (/^-v$/) # From older 'config'
{
$guess_opts{verbose} = 1;
@ -1017,6 +1021,14 @@ while (@argvcopy)
{
$config{build_type} = "release";
}
elsif (/^--profiled$/)
{
$config{build_type} = "profiled";
}
elsif (/^--pgo$/)
{
$config{build_type} = "pgo";
}
elsif (/^386$/)
{ $config{processor}=386; }
elsif (/^rsaref$/)

View File

@ -335,6 +335,14 @@ Build OpenSSL with debugging symbols and zero optimization level.
Build OpenSSL without debugging symbols. This is the default.
--coverage
Build OpenSSL with gcov profiling information included
--pgo
Build OpenSSL optimized using gcov data obtained from --coverage build
Directories
-----------
@ -2033,6 +2041,24 @@ around the problem by forcing the build procedure to use the following script:
instead of the real clang. In which case it doesn't matter what clang version
is used, as it is the version of the GNU assembler that will be checked.
Notes on profile guided optimization
------------------------------------
Some compilers support the concept of profile guided optimization. This feature
allows a user to build openssl and use profiling data gathered while running an
application such that it can then be rebuilt in a way that is optimized specifically
for that application, increasing performance. Currently this feature is built into
the openssl build system for x86_64 only.
1) Configure openssl with the --coverage option. This will configure the compiler to
record profiling data for the libcrypto and libssl libraries
2) Run the application(s) which you wish to optimize for, ensuring that they use
the libraries compiled in step (1) (note this may entail the use of LD_LIBRARY_PATH)
3) Clean the openssl build with make clean. Note that the profile data (the .gcda and .gcno
files are retained through the clean operation). This is intentional.
4) Configure openssl again, but this time select the --pgo build type. This will use the
profiled data to optimize code layout for the application in question.
---
<!-- Links -->