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