3b52fb7
diff -up firefox-81.0.1/build/moz.configure/lto-pgo.configure.pgo firefox-81.0.1/build/moz.configure/lto-pgo.configure
3b52fb7
--- firefox-81.0.1/build/moz.configure/lto-pgo.configure.pgo	2020-09-30 19:41:10.000000000 +0200
2875cd5
+++ firefox-81.0.1/build/moz.configure/lto-pgo.configure	2020-10-07 09:16:44.071786956 +0200
18fd042
@@ -69,12 +69,14 @@ set_config('PGO_PROFILE_PATH', pgo_profi
18fd042
 @imports(_from='__builtin__', _import='min')
18fd042
 def pgo_flags(compiler, profdata, target_is_windows):
18fd042
     if compiler.type == 'gcc':
18fd042
+        #profile_use = '-fprofile-use=$(topobjdir)'
18fd042
+        profile_use = '-fprofile-use'
18fd042
         return namespace(
18fd042
             gen_cflags=['-fprofile-generate'],
18fd042
             gen_ldflags=['-fprofile-generate'],
18fd042
-            use_cflags=['-fprofile-use', '-fprofile-correction',
18fd042
+            use_cflags=[profile_use, '-fprofile-correction',
18fd042
                         '-Wcoverage-mismatch'],
18fd042
-            use_ldflags=['-fprofile-use'],
18fd042
+            use_ldflags=[profile_use],
18fd042
         )
18fd042
 
18fd042
     if compiler.type in ('clang-cl', 'clang'):
3b52fb7
@@ -192,13 +194,13 @@ def lto(value, c_compiler, ld64_known_go
3b52fb7
                 cflags.append("-flto")
3b52fb7
                 ldflags.append("-flto")
3b52fb7
             else:
3b52fb7
-                cflags.append("-flto=thin")
3b52fb7
-                ldflags.append("-flto=thin")
3b52fb7
+                cflags.append("-flto")
3b52fb7
+                ldflags.append("-flto")
3b52fb7
         elif c_compiler.type == 'clang-cl':
3b52fb7
             if len(value) and value[0].lower() == 'full':
3b52fb7
                 cflags.append("-flto")
3b52fb7
             else:
3b52fb7
-                cflags.append("-flto=thin")
3b52fb7
+                cflags.append("-flto")
3b52fb7
             # With clang-cl, -flto can only be used with -c or -fuse-ld=lld.
3b52fb7
             # AC_TRY_LINKs during configure don't have -c, so pass -fuse-ld=lld.
3b52fb7
             cflags.append("-fuse-ld=lld");
3b52fb7
@@ -232,7 +234,7 @@ def lto(value, c_compiler, ld64_known_go
3b52fb7
             if len(value) and value[0].lower() == 'full':
3b52fb7
                 cflags.append("-flto")
3b52fb7
             else:
3b52fb7
-                cflags.append("-flto=thin")
3b52fb7
+                cflags.append("-flto")
3b52fb7
             cflags.append("-flifetime-dse=1")
3b52fb7
 
3b52fb7
             ldflags.append("-flto=%s" % num_cores)
3b52fb7
diff -up firefox-81.0.1/build/pgo/profileserver.py.pgo firefox-81.0.1/build/pgo/profileserver.py
3b52fb7
--- firefox-81.0.1/build/pgo/profileserver.py.pgo	2020-09-30 19:41:10.000000000 +0200
2875cd5
+++ firefox-81.0.1/build/pgo/profileserver.py	2020-10-07 09:16:44.071786956 +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
18fd042
@@ -84,9 +84,22 @@ if __name__ == '__main__':
18fd042
                        port=PORT,
18fd042
                        options='primary,privileged')
18fd042
 
18fd042
-    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
18fd042
@@ -191,6 +204,11 @@ if __name__ == '__main__':
18fd042
             print("Firefox exited successfully, but produced a crashreport")
18fd042
             sys.exit(1)
18fd042
 
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
+
18fd042
         llvm_profdata = env.get('LLVM_PROFDATA')
18fd042
         if llvm_profdata:
18fd042
             profraw_files = glob.glob('*.profraw')
3b52fb7
diff -up firefox-81.0.1/build/unix/mozconfig.unix.pgo firefox-81.0.1/build/unix/mozconfig.unix
3b52fb7
--- firefox-81.0.1/build/unix/mozconfig.unix.pgo	2020-09-30 19:41:10.000000000 +0200
2875cd5
+++ firefox-81.0.1/build/unix/mozconfig.unix	2020-10-07 09:16:44.071786956 +0200
8fe69a3
@@ -6,6 +6,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"
3b52fb7
diff -up firefox-81.0.1/extensions/spellcheck/src/moz.build.pgo firefox-81.0.1/extensions/spellcheck/src/moz.build
3b52fb7
--- firefox-81.0.1/extensions/spellcheck/src/moz.build.pgo	2020-09-30 19:41:17.000000000 +0200
2875cd5
+++ firefox-81.0.1/extensions/spellcheck/src/moz.build	2020-10-07 09:16:44.071786956 +0200
302967b
@@ -31,3 +31,5 @@ EXPORTS.mozilla += [
6cd2d43
 
6cd2d43
 if CONFIG['CC_TYPE'] in ('clang', 'gcc'):
6cd2d43
     CXXFLAGS += ['-Wno-error=shadow']
6cd2d43
+
6cd2d43
+CXXFLAGS += ['-fno-devirtualize']
6cd2d43
\ No newline at end of file
3b52fb7
diff -up firefox-81.0.1/python/mozbuild/mozbuild/build_commands.py.pgo firefox-81.0.1/python/mozbuild/mozbuild/build_commands.py
3b52fb7
--- firefox-81.0.1/python/mozbuild/mozbuild/build_commands.py.pgo	2020-09-30 19:41:46.000000000 +0200
2875cd5
+++ firefox-81.0.1/python/mozbuild/mozbuild/build_commands.py	2020-10-07 09:16:44.071786956 +0200
3b52fb7
@@ -108,7 +108,8 @@ class Build(MachCommandBase):
18fd042
                 return status
18fd042
 
18fd042
             pgo_env = os.environ.copy()
18fd042
-            pgo_env['LLVM_PROFDATA'] = instr.config_environment.substs.get('LLVM_PROFDATA')
18fd042
+            if instr.config_environment.substs.get('CC_TYPE') != 'gcc':
18fd042
+                pgo_env['LLVM_PROFDATA'] = instr.config_environment.substs.get('LLVM_PROFDATA')
18fd042
             pgo_env['JARLOG_FILE'] = mozpath.join(orig_topobjdir, 'jarlog/en-US.log')
18fd042
             pgo_cmd = [
18fd042
                 instr.virtualenv_manager.python_path,
2875cd5
diff -up firefox-81.0.1/toolkit/components/terminator/nsTerminator.cpp.pgo firefox-81.0.1/toolkit/components/terminator/nsTerminator.cpp
2875cd5
--- firefox-81.0.1/toolkit/components/terminator/nsTerminator.cpp.pgo	2020-10-07 09:22:26.698243673 +0200
2875cd5
+++ firefox-81.0.1/toolkit/components/terminator/nsTerminator.cpp	2020-10-07 09:22:43.026312999 +0200
2875cd5
@@ -418,6 +418,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());
2875cd5
   const PRIntervalTime ticksDuration = PR_MillisecondsToInterval(1000);
2875cd5
   options->crashAfterTicks = crashAfterMS / ticksDuration;