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