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