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