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