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