]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Add pgo build type
authorNeil Horman <nhorman@openssl.org>
Mon, 16 Jun 2025 20:33:22 +0000 (16:33 -0400)
committerNeil Horman <nhorman@openssl.org>
Fri, 20 Jun 2025 10:40:14 +0000 (06:40 -0400)
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)

Configurations/10-main.conf
Configure
INSTALL.md

index 0701b733ecbba89a4771008fac02b409101ba4c6..6465651507e646bb087246ceb27b1865184def36 100644 (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"),
index 499585438a162a18c160969119b85ef90389f19c..ef6ba49f6bb2aa6fda8ecb9249bed6d4e8065b01 100755 (executable)
--- a/Configure
+++ b/Configure
@@ -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$/)
index cb54c7ea717a0480ac30680745047e84f1f71101..731144b67fd06417119dcfc6b3e8c2ace5c859ee 100644 (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  -->