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