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