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