diff -up firefox-112.0/build/pgo/profileserver.py.pgo firefox-112.0/build/pgo/profileserver.py
--- firefox-112.0/build/pgo/profileserver.py.pgo	2023-04-06 17:27:40.000000000 +0200
+++ firefox-112.0/build/pgo/profileserver.py	2023-04-06 21:29:33.772294479 +0200
@@ -11,7 +11,7 @@ import subprocess
 import sys
 
 import mozcrash
-from mozbuild.base import BinaryNotFoundException, MozbuildObject
+from mozbuild.base import BinaryNotFoundException, MozbuildObject, BuildEnvironmentNotFoundException
 from mozfile import TemporaryDirectory
 from mozhttpd import MozHttpd
 from mozprofile import FirefoxProfile, Preferences
@@ -87,9 +87,22 @@ if __name__ == "__main__":
     locations = ServerLocations()
     locations.add_host(host="127.0.0.1", port=PORT, options="primary,privileged")
 
-    old_profraw_files = glob.glob("*.profraw")
-    for f in old_profraw_files:
-        os.remove(f)
+    using_gcc = False
+    try:
+        if build.config_environment.substs.get('CC_TYPE') == 'gcc':
+            using_gcc = True
+    except BuildEnvironmentNotFoundException:
+        pass
+
+    if using_gcc:
+        for dirpath, _, filenames in os.walk('.'):
+            for f in filenames:
+                if f.endswith('.gcda'):
+                    os.remove(os.path.join(dirpath, f))
+    else:
+        old_profraw_files = glob.glob('*.profraw')
+        for f in old_profraw_files:
+            os.remove(f)
 
     with TemporaryDirectory() as profilePath:
         # TODO: refactor this into mozprofile
diff -up firefox-112.0/toolkit/components/terminator/nsTerminator.cpp.pgo firefox-112.0/toolkit/components/terminator/nsTerminator.cpp
--- firefox-112.0/toolkit/components/terminator/nsTerminator.cpp.pgo	2023-04-06 17:27:57.000000000 +0200
+++ firefox-112.0/toolkit/components/terminator/nsTerminator.cpp	2023-04-06 21:27:32.538089108 +0200
@@ -460,6 +460,11 @@ void nsTerminator::StartWatchdog() {
   }
 #endif
 
+  // Disable watchdog for PGO train builds - writting profile information at
+  // exit may take time and it is better to make build hang rather than
+  // silently produce poorly performing binary.
+  crashAfterMS = INT32_MAX;
+
   UniquePtr<Options> options(new Options());
   // crashAfterTicks is guaranteed to be > 0 as
   // crashAfterMS >= ADDITIONAL_WAIT_BEFORE_CRASH_MS >> HEARTBEAT_INTERVAL_MS
diff -up firefox-114.0.2/build/moz.configure/lto-pgo.configure.pgo firefox-114.0.2/build/moz.configure/lto-pgo.configure
--- firefox-114.0.2/build/moz.configure/lto-pgo.configure.pgo	2023-06-22 11:17:37.428552356 +0200
+++ firefox-114.0.2/build/moz.configure/lto-pgo.configure	2023-06-22 11:17:51.476033691 +0200
@@ -86,7 +86,7 @@ def pgo_flags(compiler, profdata, target
         return namespace(
             gen_cflags=["-fprofile-generate"],
             gen_ldflags=["-fprofile-generate"],
-            use_cflags=["-fprofile-use", "-fprofile-correction", "-Wcoverage-mismatch"],
+            use_cflags=["-fprofile-use", "-fprofile-correction", "-Wno-coverage-mismatch"],
             use_ldflags=["-fprofile-use"],
         )
 

