git.iko.soy/typeable/nixpkgs
on master help sign in
firefox: overhaul LTO

Enable LTO support on Linux by default again. Add patch to fix dependentlibs.list generation under LTO. This is necessary for fixing firefox-wayland crashing when built with LTO. Add makeFlags which set ar, ranlib, and nm to be llvm-ar, llvm-ranlib and llvm-nm when building with llvm-based LTO. (bmo#1480005)

commit7415d0589d596fd1b61f230e29761f138d46b756 authorS. Nordin Abouzahra <abouzahra.9@wright.edu> dateWed 9 Dec 2020, 22:20 (6 years ago) parent40b4eb1
2 files changed+69−8
pkgs/applications/networking/browsers/firefox/common.nix+24−8 pkgs/applications/networking/browsers/firefox/lto-dependentlibs-generation-ffx83.patch+45
pkgs/applications/networking/browsers/firefox/common.nix+24−8
@@ -23,8 +23,7 @@
2323, ffmpegSupport ? true
2424, gtk3Support ? true, gtk2, gtk3, wrapGAppsHook
2525, waylandSupport ? true, libxkbcommon
26−# LTO is disabled since it caused segfaults on wayland see https://github.com/NixOS/nixpkgs/issues/101429
27−, ltoSupport ? false, overrideCC, buildPackages
26+, ltoSupport ? stdenv.isLinux, overrideCC, buildPackages
2827, gssSupport ? true, kerberos
2928, pipewireSupport ? waylandSupport && webrtcSupport, pipewire
3029
@@ -91,11 +90,19 @@ let
9190 then "/Applications/${binaryNameCapitalized}.app/Contents/MacOS"
9291 else "/bin";
9392
93+ # 78 ESR won't build with rustc 1.47
94+ inherit (if lib.versionAtLeast ffversion "82" then rustPackages else rustPackages_1_45)
95+ rustc cargo;
96+
9497 # Darwin's stdenv provides the default llvmPackages version, match that since
9598 # clang LTO on Darwin is broken so the stdenv is not being changed.
99+ # Target the LLVM version that rustc -Vv reports it is built with for LTO.
100+ # rustPackages_1_45 -> LLVM 10, rustPackages -> LLVM 11
96101 llvmPackages = if stdenv.isDarwin
97102 then buildPackages.llvmPackages
98− else buildPackages.llvmPackages_10;
103+ else if lib.versionAtLeast rustc.llvm.version "11"
104+ then buildPackages.llvmPackages_11
105+ else buildPackages.llvmPackages_10;
99106
100107 # When LTO for Darwin is fixed, the following will need updating as lld
101108 # doesn't work on it. For now it is fine since ltoSupport implies no Darwin.
@@ -103,10 +110,6 @@ let
103110 then overrideCC stdenv llvmPackages.lldClang
104111 else stdenv;
105112
106− # 78 ESR won't build with rustc 1.47
107− inherit (if lib.versionAtLeast ffversion "82" then rustPackages else rustPackages_1_45)
108− rustc cargo;
109−
110113 nss_pkg = if lib.versionOlder ffversion "83" then nss_3_53 else nss;
111114in
112115
@@ -121,13 +124,19 @@ buildStdenv.mkDerivation ({
121124 ] ++
122125 lib.optional (lib.versionOlder ffversion "83") ./no-buildconfig-ffx76.patch ++
123126 lib.optional (lib.versionAtLeast ffversion "84") ./no-buildconfig-ffx84.patch ++
127+ lib.optional (ltoSupport && lib.versionOlder ffversion "84") ./lto-dependentlibs-generation-ffx83.patch ++
128+ lib.optional (ltoSupport && lib.versionAtLeast ffversion "84" && lib.versionOlder ffversion "86")
129+ (fetchpatch {
130+ url = "https://hg.mozilla.org/mozilla-central/raw-rev/fdff20c37be3";
131+ sha256 = "135n9brliqy42lj3nqgb9d9if7x6x9nvvn0z4anbyf89bikixw48";
132+ })
124133
125134 # there are two flavors of pipewire support
126135 # The patches for the ESR release and the patches for the current stable
127136 # release.
128137 # Until firefox upstream stabilizes pipewire support we will have to continue
129138 # tracking multiple versions here.
130− lib.optional (pipewireSupport && lib.versionOlder ffversion "83")
139+ ++ lib.optional (pipewireSupport && lib.versionOlder ffversion "83")
131140 (fetchpatch {
132141 # https://src.fedoraproject.org/rpms/firefox/blob/master/f/firefox-pipewire-0-3.patch
133142 url = "https://src.fedoraproject.org/rpms/firefox/raw/e99b683a352cf5b2c9ff198756859bae408b5d9d/f/firefox-pipewire-0-3.patch";
@@ -316,6 +325,13 @@ buildStdenv.mkDerivation ({
316325 "MOZILLA_OFFICIAL=1"
317326 "BUILD_OFFICIAL=1"
318327 ]
328+ ++ lib.optionals ltoSupport [
329+ "AR=${llvmPackages.bintools}/bin/llvm-ar"
330+ "LLVM_OBJDUMP=${llvmPackages.bintools}/bin/llvm-objdump"
331+ "NM=${llvmPackages.bintools}/bin/llvm-nm"
332+ "RANLIB=${llvmPackages.bintools}/bin/llvm-ranlib"
333+ "STRIP=${llvmPackages.bintools}/bin/llvm-strip"
334+ ]
319335 ++ extraMakeFlags;
320336
321337 enableParallelBuilding = true;
pkgs/applications/networking/browsers/firefox/lto-dependentlibs-generation-ffx83.patchnew file+45
@@ -0,0 +1,45 @@
1+--- a/toolkit/library/build/dependentlibs.py
2++++ b/toolkit/library/build/dependentlibs.py
3+@@ -36,26 +36,17 @@ def dependentlibs_win32_objdump(lib):
4+ proc.wait()
5+ return deps
6+
7+-def dependentlibs_readelf(lib):
8++def dependentlibs_elf_objdump(lib):
9+ '''Returns the list of dependencies declared in the given ELF .so'''
10+- proc = subprocess.Popen([substs.get('TOOLCHAIN_PREFIX', '') + 'readelf', '-d', lib], stdout = subprocess.PIPE,
11++ proc = subprocess.Popen([substs['LLVM_OBJDUMP'], '--private-headers', lib], stdout = subprocess.PIPE,
12+ universal_newlines=True)
13+ deps = []
14+ for line in proc.stdout:
15+- # Each line has the following format:
16+- # tag (TYPE) value
17+- # or with BSD readelf:
18+- # tag TYPE value
19+- # Looking for NEEDED type entries
20+- tmp = line.split(' ', 3)
21+- if len(tmp) > 3 and 'NEEDED' in tmp[2]:
22+- # NEEDED lines look like:
23+- # 0x00000001 (NEEDED) Shared library: [libname]
24+- # or with BSD readelf:
25+- # 0x00000001 NEEDED Shared library: [libname]
26+- match = re.search('\[(.*)\]', tmp[3])
27+- if match:
28+- deps.append(match.group(1))
29++ # We are looking for lines with the format:
30++ # NEEDED libname
31++ tmp = line.split()
32++ if len(tmp) == 2 and tmp[0] == 'NEEDED':
33++ deps.append(tmp[1])
34+ proc.wait()
35+ return deps
36+
37+@@ -110,7 +101,7 @@ def gen_list(output, lib):
38+ libpaths = [os.path.join(substs['DIST'], 'bin')]
39+ binary_type = get_type(lib)
40+ if binary_type == ELF:
41+- func = dependentlibs_readelf
42++ func = dependentlibs_elf_objdump
43+ elif binary_type == MACHO:
44+ func = dependentlibs_mac_objdump
45+ else: