File mozilla-pgo.patch of Package MozillaThunderbird.40006

# HG changeset patch

From: Martin Sirringhaus <martin.sirringhaus@suse.com>

# User Wolfgang Rosenauer <wr@rosenauer.org>
# Parent  9959fe2a13a39cbeb98ca1bef2e21caba16717bd
---
 build/moz.configure/lto-pgo.configure          |    6 +++---
 build/pgo/profileserver.py                     |   25 ++++++++++++++++++++----
 build/unix/mozconfig.unix                      |    9 +++++++++
 extensions/spellcheck/src/moz.build            |    2 ++
 toolkit/components/terminator/nsTerminator.cpp |    5 +++++
 5 files changed, 40 insertions(+), 7 deletions(-)

diff --git a/build/moz.configure/lto-pgo.configure b/build/moz.configure/lto-pgo.configure
index eb0f87400885..257a71a4e5df 100644
--- a/build/moz.configure/lto-pgo.configure
+++ b/build/moz.configure/lto-pgo.configure
@@ -347,8 +347,8 @@ def lto(
             cflags.append("-flto")
             ldflags.append("-flto")
         else:
-            cflags.append("-flto=thin")
-            ldflags.append("-flto=thin")
+            cflags.append("-flto")
+            ldflags.append("-flto")
 
         if target.os == "Android" and "cross" in values:
             # Work around https://github.com/rust-lang/rust/issues/90088
@@ -364,7 +364,7 @@ def lto(
         if "full" in values:
             cflags.append("-flto")
         else:
-            cflags.append("-flto=thin")
+            cflags.append("-flto")
         # With clang-cl, -flto can only be used with -c or -fuse-ld=lld.
         # AC_TRY_LINKs during configure don't have -c, so pass -fuse-ld=lld.
         cflags.append("-fuse-ld=lld")
diff --git a/build/pgo/profileserver.py b/build/pgo/profileserver.py
index 6017810c873f..64c76af933ea 100755
--- a/build/pgo/profileserver.py
+++ b/build/pgo/profileserver.py
@@ -11,7 +11,7 @@ import subprocess
 import sys
 
 import mozcrash
-from mozbuild.base import BinaryNotFoundException, MozbuildObject
+from mozbuild.base import BinaryNotFoundException, MozbuildObject, BuildEnvironmentNotFoundException
 from mozfile import TemporaryDirectory
 from mozhttpd import MozHttpd
 from mozprofile import FirefoxProfile, Preferences
@@ -97,9 +97,22 @@ if __name__ == "__main__":
     locations = ServerLocations()
     locations.add_host(host="127.0.0.1", port=PORT, options="primary,privileged")
 
-    old_profraw_files = glob.glob("*.profraw")
-    for f in old_profraw_files:
-        os.remove(f)
+    using_gcc = False
+    try:
+        if build.config_environment.substs.get('CC_TYPE') == 'gcc':
+            using_gcc = True
+    except BuildEnvironmentNotFoundException:
+        pass
+
+    if using_gcc:
+        for dirpath, _, filenames in os.walk('.'):
+            for f in filenames:
+                if f.endswith('.gcda'):
+                    os.remove(os.path.join(dirpath, f))
+    else:
+        old_profraw_files = glob.glob('*.profraw')
+        for f in old_profraw_files:
+            os.remove(f)
 
     with TemporaryDirectory() as profilePath:
         # TODO: refactor this into mozprofile
@@ -229,6 +242,10 @@ if __name__ == "__main__":
             print("Firefox exited successfully, but produced a crashreport")
             sys.exit(1)
 
+        print('Copying profile data....')
+        os.system('pwd');
+        os.system('tar cf profdata.tar.gz `find . -name "*.gcda"`; cd ..; tar xf instrumented/profdata.tar.gz;');
+
         llvm_profdata = env.get("LLVM_PROFDATA")
         if llvm_profdata:
             profraw_files = glob.glob("*.profraw")
diff --git a/build/unix/mozconfig.unix b/build/unix/mozconfig.unix
index 05bf666b3925..de449359b01f 100644
--- a/build/unix/mozconfig.unix
+++ b/build/unix/mozconfig.unix
@@ -4,6 +4,15 @@ if [ -n "$FORCE_GCC" ]; then
     CC="$MOZ_FETCHES_DIR/gcc/bin/gcc"
     CXX="$MOZ_FETCHES_DIR/gcc/bin/g++"
 
+    if [ -n "$MOZ_PGO" ]; then
+       if [ -z "$USE_ARTIFACT" ]; then
+           ac_add_options --enable-lto
+       fi
+       export AR="$topsrcdir/gcc/bin/gcc-ar"
+       export NM="$topsrcdir/gcc/bin/gcc-nm"
+       export RANLIB="$topsrcdir/gcc/bin/gcc-ranlib"
+    fi
+
     # We want to make sure we use binutils and other binaries in the tooltool
     # package.
     mk_add_options "export PATH=$MOZ_FETCHES_DIR/gcc/bin:$MOZ_FETCHES_DIR/binutils/bin:$PATH"
diff --git a/extensions/spellcheck/src/moz.build b/extensions/spellcheck/src/moz.build
index c4ce09efca34..ee64cb1f48fa 100644
--- a/extensions/spellcheck/src/moz.build
+++ b/extensions/spellcheck/src/moz.build
@@ -26,3 +26,5 @@ EXPORTS.mozilla += [
     "mozInlineSpellChecker.h",
     "mozSpellChecker.h",
 ]
+
+CXXFLAGS += ['-fno-devirtualize']
diff --git a/toolkit/components/terminator/nsTerminator.cpp b/toolkit/components/terminator/nsTerminator.cpp
index 8c456b142a4f..cb8109f7f966 100644
--- a/toolkit/components/terminator/nsTerminator.cpp
+++ b/toolkit/components/terminator/nsTerminator.cpp
@@ -330,6 +330,11 @@ void nsTerminator::StartWatchdog() {
   }
 #endif
 
+  // Disable watchdog for PGO train builds - writting profile information at
+  // exit may take time and it is better to make build hang rather than
+  // silently produce poorly performing binary.
+  crashAfterMS = INT32_MAX;
+
   UniquePtr<Options> options(new Options());
   // crashAfterTicks is guaranteed to be > 0 as
   // crashAfterMS >= ADDITIONAL_WAIT_BEFORE_CRASH_MS >> HEARTBEAT_INTERVAL_MS
openSUSE Build Service is sponsored by