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