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