From c6f113a3f4bdcd21aae126deaf0225b57352aaf2 Mon Sep 17 00:00:00 2001 From: "S. Nordin Abouzahra" Date: Wed, 9 Dec 2020 14:05:10 -0500 Subject: [PATCH 1/7] firefox: remove superfluous NIX_CFLAGS_COMPILE It was added for nspr and nss back in the 55.0.3 to 56.0 upgrade. It also served as a workaround for an undeclared gio-unix-2.0 dependency. Sometime afterwards nspr was removed, leaving just the two. Since then, upstream has added a declaration for gio-unix-2.0 (in FF62). As for the nss include it seemingly has no purpose since current firefox builds with it removed. --- pkgs/applications/networking/browsers/firefox/common.nix | 5 ----- 1 file changed, 5 deletions(-) diff --git a/pkgs/applications/networking/browsers/firefox/common.nix b/pkgs/applications/networking/browsers/firefox/common.nix index 70fde21823a3..d335313df7bb 100644 --- a/pkgs/applications/networking/browsers/firefox/common.nix +++ b/pkgs/applications/networking/browsers/firefox/common.nix @@ -186,11 +186,6 @@ buildStdenv.mkDerivation ({ -rpath ${llvmPackages.libunwind.out}/lib ''; - NIX_CFLAGS_COMPILE = toString [ - "-I${glib.dev}/include/gio-unix-2.0" - "-I${nss_pkg.dev}/include/nss" - ]; - MACH_USE_SYSTEM_PYTHON = "1"; postPatch = '' From 96c34702e90dd4957aced6013886aed7d0eed0a7 Mon Sep 17 00:00:00 2001 From: "S. Nordin Abouzahra" Date: Wed, 9 Dec 2020 14:48:45 -0500 Subject: [PATCH 2/7] firefox: restrict system NSPR workaround It only affected FF80 so place an upper bound restriction. See bmo#1661096 for details. This fixes substituteStream() warnings about missing patterns which appeared in the logs. --- pkgs/applications/networking/browsers/firefox/common.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/applications/networking/browsers/firefox/common.nix b/pkgs/applications/networking/browsers/firefox/common.nix index d335313df7bb..c0822e478f33 100644 --- a/pkgs/applications/networking/browsers/firefox/common.nix +++ b/pkgs/applications/networking/browsers/firefox/common.nix @@ -197,7 +197,7 @@ buildStdenv.mkDerivation ({ substituteInPlace \ media/webrtc/trunk/webrtc/modules/desktop_capture/desktop_capture_generic_gn/moz.build \ --replace /usr/include ${pipewire.dev}/include - '' + lib.optionalString (lib.versionAtLeast ffversion "80") '' + '' + lib.optionalString (lib.versionAtLeast ffversion "80" && lib.versionOlder ffversion "81") '' substituteInPlace dom/system/IOUtils.h \ --replace '#include "nspr/prio.h"' '#include "prio.h"' From 80e863c52c3cf2c838ad80ade5dfea89cce1cd2d Mon Sep 17 00:00:00 2001 From: "S. Nordin Abouzahra" Date: Wed, 9 Dec 2020 20:36:16 -0500 Subject: [PATCH 3/7] firefox: clean up optionals Change `lib.optionals a [ b ]` to `lib.optional a b`. --- pkgs/applications/networking/browsers/firefox/common.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/applications/networking/browsers/firefox/common.nix b/pkgs/applications/networking/browsers/firefox/common.nix index c0822e478f33..b98ff47984f6 100644 --- a/pkgs/applications/networking/browsers/firefox/common.nix +++ b/pkgs/applications/networking/browsers/firefox/common.nix @@ -174,9 +174,9 @@ buildStdenv.mkDerivation ({ ++ lib.optional gtk3Support gtk3 ++ lib.optional gssSupport kerberos ++ lib.optional ltoSupport llvmPackages.libunwind - ++ lib.optionals waylandSupport [ libxkbcommon ] - ++ lib.optionals pipewireSupport [ pipewire ] - ++ lib.optionals (lib.versionAtLeast ffversion "82") [ gnum4 ] + ++ lib.optional waylandSupport libxkbcommon + ++ lib.optional pipewireSupport pipewire + ++ lib.optional (lib.versionAtLeast ffversion "82") gnum4 ++ lib.optionals buildStdenv.isDarwin [ CoreMedia ExceptionHandling Kerberos AVFoundation MediaToolbox CoreLocation Foundation libobjc AddressBook cups ]; From a277fca1c4bec931d4cec715ae029a5d99a1b23b Mon Sep 17 00:00:00 2001 From: "S. Nordin Abouzahra" Date: Wed, 9 Dec 2020 21:26:58 -0500 Subject: [PATCH 4/7] firefox: remove patchelf usage Firefox has a number of optional dependencies that get dlopened. Instead of using patchelf to set the RPATH use LD_LIBRARY_PATH. The motivation for this is we already set LD_LIBRARY_PATH in the wrapper on Linux. --- .../networking/browsers/firefox/common.nix | 17 +++-------------- .../networking/browsers/firefox/wrapper.nix | 8 +++++--- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/pkgs/applications/networking/browsers/firefox/common.nix b/pkgs/applications/networking/browsers/firefox/common.nix index b98ff47984f6..0378d0dc8595 100644 --- a/pkgs/applications/networking/browsers/firefox/common.nix +++ b/pkgs/applications/networking/browsers/firefox/common.nix @@ -4,7 +4,7 @@ { lib, stdenv, pkgconfig, pango, perl, python2, python3, zip , libjpeg, zlib, dbus, dbus-glib, bzip2, xorg -, freetype, fontconfig, file, nspr, nss, nss_3_53, libnotify +, freetype, fontconfig, file, nspr, nss, nss_3_53 , yasm, libGLU, libGL, sqlite, unzip, makeWrapper , hunspell, libXdamage, libevent, libstartup_notification , libvpx_1_8 @@ -157,7 +157,7 @@ buildStdenv.mkDerivation ({ gtk2 perl zip libjpeg zlib bzip2 dbus dbus-glib pango freetype fontconfig xorg.libXi xorg.libXcursor xorg.libX11 xorg.libXrender xorg.libXft xorg.libXt file - libnotify xorg.pixman yasm libGLU libGL + xorg.pixman yasm libGLU libGL xorg.xorgproto xorg.libXext unzip makeWrapper libevent libstartup_notification /* cairo */ @@ -336,18 +336,6 @@ buildStdenv.mkDerivation ({ gappsWrapperArgs+=(--argv0 "$out/bin/.${binaryName}-wrapped") ''; - postFixup = lib.optionalString buildStdenv.isLinux '' - # Fix notifications. LibXUL uses dlopen for this, unfortunately; see #18712. - patchelf --set-rpath "${lib.getLib libnotify - }/lib:$(patchelf --print-rpath "$out"/lib/${binaryName}*/libxul.so)" \ - "$out"/lib/${binaryName}*/libxul.so - patchelf --add-needed ${xorg.libXScrnSaver.out}/lib/libXss.so $out/lib/${binaryName}/${binaryName} - ${lib.optionalString (pipewireSupport && lib.versionAtLeast ffversion "83") '' - patchelf --add-needed "${lib.getLib pipewire}/lib/libpipewire-0.3.so" \ - "$out"/lib/${binaryName}/${binaryName} - ''} - ''; - doInstallCheck = true; installCheckPhase = '' # Some basic testing @@ -360,6 +348,7 @@ buildStdenv.mkDerivation ({ isFirefox3Like = true; gtk = gtk2; inherit alsaSupport; + inherit pipewireSupport; inherit nspr; inherit ffmpegSupport; inherit gssSupport; diff --git a/pkgs/applications/networking/browsers/firefox/wrapper.nix b/pkgs/applications/networking/browsers/firefox/wrapper.nix index 88fb6af4b016..c083dbe873e3 100644 --- a/pkgs/applications/networking/browsers/firefox/wrapper.nix +++ b/pkgs/applications/networking/browsers/firefox/wrapper.nix @@ -3,9 +3,9 @@ ## various stuff that can be plugged in , flashplayer, hal-flash -, ffmpeg, xorg, alsaLib, libpulseaudio, libcanberra-gtk2, libglvnd +, ffmpeg, xorg, alsaLib, libpulseaudio, libcanberra-gtk2, libglvnd, libnotify , gnome3/*.gnome-shell*/ -, browserpass, chrome-gnome-shell, uget-integrator, plasma5, bukubrow +, browserpass, chrome-gnome-shell, uget-integrator, plasma5, bukubrow, pipewire , tridactyl-native , fx_cast_bridge , udev @@ -51,6 +51,7 @@ let ffmpegSupport = browser.ffmpegSupport or false; gssSupport = browser.gssSupport or false; alsaSupport = browser.alsaSupport or false; + pipewireSupport = browser.pipewireSupport or false; plugins = let @@ -80,7 +81,8 @@ let ++ lib.optional (cfg.enableFXCastBridge or false) fx_cast_bridge ++ extraNativeMessagingHosts ); - libs = lib.optionals stdenv.isLinux [ udev libva mesa ] + libs = lib.optionals stdenv.isLinux [ udev libva mesa libnotify xorg.libXScrnSaver ] + ++ lib.optional (pipewireSupport && lib.versionAtLeast version "83") pipewire ++ lib.optional ffmpegSupport ffmpeg ++ lib.optional gssSupport kerberos ++ lib.optional useGlvnd libglvnd From 40b4eb1c52f2a87f8f99ac193782c1c8b665fb7b Mon Sep 17 00:00:00 2001 From: "S. Nordin Abouzahra" Date: Wed, 9 Dec 2020 21:53:39 -0500 Subject: [PATCH 5/7] firefox: simplify NIX_LDFLAGS usage This was required to solve the XPCOMGlueLoad error when building with LTO. However, it turns out libxul.so is supposed to have some libraries that are reported as not found by ldd. Setting the RPATH worked around the error as it forced dependency resolution but failed to fix the real issue of broken generation of dependentlibs.list. The libraries that are reported as not found by ldd are supposed to be dlopened through the logic found in nsXPCOMGlue.cpp. However since the generation of dependentlibs.list is broken under LTO this did not happen. Instead of pulling libwayland-client.so from the GTK libraries it found the stub library first (libmozwayland.so). The stub library causes (as it should) wl_display_connect to always return NULL which is the cause of the segmentation fault and LTO breaking wayland support. Remove the hardcoded path used for the XPCOMGlueLoad error workaround in NIX_LDFLAGS. libunwind is still unfortunately needed. Once the issue of the generation of dependentlibs.list being borked is fixed it should remedy the wayland crash issue on LTO. --- pkgs/applications/networking/browsers/firefox/common.nix | 2 -- 1 file changed, 2 deletions(-) diff --git a/pkgs/applications/networking/browsers/firefox/common.nix b/pkgs/applications/networking/browsers/firefox/common.nix index 0378d0dc8595..4a356995cde5 100644 --- a/pkgs/applications/networking/browsers/firefox/common.nix +++ b/pkgs/applications/networking/browsers/firefox/common.nix @@ -173,7 +173,6 @@ buildStdenv.mkDerivation ({ ++ lib.optional pulseaudioSupport libpulseaudio # only headers are needed ++ lib.optional gtk3Support gtk3 ++ lib.optional gssSupport kerberos - ++ lib.optional ltoSupport llvmPackages.libunwind ++ lib.optional waylandSupport libxkbcommon ++ lib.optional pipewireSupport pipewire ++ lib.optional (lib.versionAtLeast ffversion "82") gnum4 @@ -182,7 +181,6 @@ buildStdenv.mkDerivation ({ Foundation libobjc AddressBook cups ]; NIX_LDFLAGS = lib.optionalString ltoSupport '' - -rpath ${placeholder "out"}/lib/${binaryName} -rpath ${llvmPackages.libunwind.out}/lib ''; From 7415d0589d596fd1b61f230e29761f138d46b756 Mon Sep 17 00:00:00 2001 From: "S. Nordin Abouzahra" Date: Wed, 9 Dec 2020 22:20:59 -0500 Subject: [PATCH 6/7] 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) --- .../networking/browsers/firefox/common.nix | 32 +++++++++---- .../lto-dependentlibs-generation-ffx83.patch | 45 +++++++++++++++++++ 2 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 pkgs/applications/networking/browsers/firefox/lto-dependentlibs-generation-ffx83.patch diff --git a/pkgs/applications/networking/browsers/firefox/common.nix b/pkgs/applications/networking/browsers/firefox/common.nix index 4a356995cde5..c031b9e73267 100644 --- a/pkgs/applications/networking/browsers/firefox/common.nix +++ b/pkgs/applications/networking/browsers/firefox/common.nix @@ -23,8 +23,7 @@ , ffmpegSupport ? true , gtk3Support ? true, gtk2, gtk3, wrapGAppsHook , waylandSupport ? true, libxkbcommon -# LTO is disabled since it caused segfaults on wayland see https://github.com/NixOS/nixpkgs/issues/101429 -, ltoSupport ? false, overrideCC, buildPackages +, ltoSupport ? stdenv.isLinux, overrideCC, buildPackages , gssSupport ? true, kerberos , pipewireSupport ? waylandSupport && webrtcSupport, pipewire @@ -91,11 +90,19 @@ let then "/Applications/${binaryNameCapitalized}.app/Contents/MacOS" else "/bin"; + # 78 ESR won't build with rustc 1.47 + inherit (if lib.versionAtLeast ffversion "82" then rustPackages else rustPackages_1_45) + rustc cargo; + # Darwin's stdenv provides the default llvmPackages version, match that since # clang LTO on Darwin is broken so the stdenv is not being changed. + # Target the LLVM version that rustc -Vv reports it is built with for LTO. + # rustPackages_1_45 -> LLVM 10, rustPackages -> LLVM 11 llvmPackages = if stdenv.isDarwin then buildPackages.llvmPackages - else buildPackages.llvmPackages_10; + else if lib.versionAtLeast rustc.llvm.version "11" + then buildPackages.llvmPackages_11 + else buildPackages.llvmPackages_10; # When LTO for Darwin is fixed, the following will need updating as lld # doesn't work on it. For now it is fine since ltoSupport implies no Darwin. @@ -103,10 +110,6 @@ let then overrideCC stdenv llvmPackages.lldClang else stdenv; - # 78 ESR won't build with rustc 1.47 - inherit (if lib.versionAtLeast ffversion "82" then rustPackages else rustPackages_1_45) - rustc cargo; - nss_pkg = if lib.versionOlder ffversion "83" then nss_3_53 else nss; in @@ -121,13 +124,19 @@ buildStdenv.mkDerivation ({ ] ++ lib.optional (lib.versionOlder ffversion "83") ./no-buildconfig-ffx76.patch ++ lib.optional (lib.versionAtLeast ffversion "84") ./no-buildconfig-ffx84.patch ++ + lib.optional (ltoSupport && lib.versionOlder ffversion "84") ./lto-dependentlibs-generation-ffx83.patch ++ + lib.optional (ltoSupport && lib.versionAtLeast ffversion "84" && lib.versionOlder ffversion "86") + (fetchpatch { + url = "https://hg.mozilla.org/mozilla-central/raw-rev/fdff20c37be3"; + sha256 = "135n9brliqy42lj3nqgb9d9if7x6x9nvvn0z4anbyf89bikixw48"; + }) # there are two flavors of pipewire support # The patches for the ESR release and the patches for the current stable # release. # Until firefox upstream stabilizes pipewire support we will have to continue # tracking multiple versions here. - lib.optional (pipewireSupport && lib.versionOlder ffversion "83") + ++ lib.optional (pipewireSupport && lib.versionOlder ffversion "83") (fetchpatch { # https://src.fedoraproject.org/rpms/firefox/blob/master/f/firefox-pipewire-0-3.patch url = "https://src.fedoraproject.org/rpms/firefox/raw/e99b683a352cf5b2c9ff198756859bae408b5d9d/f/firefox-pipewire-0-3.patch"; @@ -316,6 +325,13 @@ buildStdenv.mkDerivation ({ "MOZILLA_OFFICIAL=1" "BUILD_OFFICIAL=1" ] + ++ lib.optionals ltoSupport [ + "AR=${llvmPackages.bintools}/bin/llvm-ar" + "LLVM_OBJDUMP=${llvmPackages.bintools}/bin/llvm-objdump" + "NM=${llvmPackages.bintools}/bin/llvm-nm" + "RANLIB=${llvmPackages.bintools}/bin/llvm-ranlib" + "STRIP=${llvmPackages.bintools}/bin/llvm-strip" + ] ++ extraMakeFlags; enableParallelBuilding = true; diff --git a/pkgs/applications/networking/browsers/firefox/lto-dependentlibs-generation-ffx83.patch b/pkgs/applications/networking/browsers/firefox/lto-dependentlibs-generation-ffx83.patch new file mode 100644 index 000000000000..b6f1b81fa9fe --- /dev/null +++ b/pkgs/applications/networking/browsers/firefox/lto-dependentlibs-generation-ffx83.patch @@ -0,0 +1,45 @@ +--- a/toolkit/library/build/dependentlibs.py ++++ b/toolkit/library/build/dependentlibs.py +@@ -36,26 +36,17 @@ def dependentlibs_win32_objdump(lib): + proc.wait() + return deps + +-def dependentlibs_readelf(lib): ++def dependentlibs_elf_objdump(lib): + '''Returns the list of dependencies declared in the given ELF .so''' +- proc = subprocess.Popen([substs.get('TOOLCHAIN_PREFIX', '') + 'readelf', '-d', lib], stdout = subprocess.PIPE, ++ proc = subprocess.Popen([substs['LLVM_OBJDUMP'], '--private-headers', lib], stdout = subprocess.PIPE, + universal_newlines=True) + deps = [] + for line in proc.stdout: +- # Each line has the following format: +- # tag (TYPE) value +- # or with BSD readelf: +- # tag TYPE value +- # Looking for NEEDED type entries +- tmp = line.split(' ', 3) +- if len(tmp) > 3 and 'NEEDED' in tmp[2]: +- # NEEDED lines look like: +- # 0x00000001 (NEEDED) Shared library: [libname] +- # or with BSD readelf: +- # 0x00000001 NEEDED Shared library: [libname] +- match = re.search('\[(.*)\]', tmp[3]) +- if match: +- deps.append(match.group(1)) ++ # We are looking for lines with the format: ++ # NEEDED libname ++ tmp = line.split() ++ if len(tmp) == 2 and tmp[0] == 'NEEDED': ++ deps.append(tmp[1]) + proc.wait() + return deps + +@@ -110,7 +101,7 @@ def gen_list(output, lib): + libpaths = [os.path.join(substs['DIST'], 'bin')] + binary_type = get_type(lib) + if binary_type == ELF: +- func = dependentlibs_readelf ++ func = dependentlibs_elf_objdump + elif binary_type == MACHO: + func = dependentlibs_mac_objdump + else: From dbe008a52a25a039653f3dec295859d1566ddafc Mon Sep 17 00:00:00 2001 From: "S. Nordin Abouzahra" Date: Fri, 25 Dec 2020 21:02:01 -0500 Subject: [PATCH 7/7] firefox: remove python2 dependency Python 2 is no longer required to build Firefox. --- pkgs/applications/networking/browsers/firefox/common.nix | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkgs/applications/networking/browsers/firefox/common.nix b/pkgs/applications/networking/browsers/firefox/common.nix index c031b9e73267..123c3cc08a6b 100644 --- a/pkgs/applications/networking/browsers/firefox/common.nix +++ b/pkgs/applications/networking/browsers/firefox/common.nix @@ -2,7 +2,7 @@ , src, unpackPhase ? null, patches ? [] , extraNativeBuildInputs ? [], extraConfigureFlags ? [], extraMakeFlags ? [] }: -{ lib, stdenv, pkgconfig, pango, perl, python2, python3, zip +{ lib, stdenv, pkgconfig, pango, perl, python3, zip , libjpeg, zlib, dbus, dbus-glib, bzip2, xorg , freetype, fontconfig, file, nspr, nss, nss_3_53 , yasm, libGLU, libGL, sqlite, unzip, makeWrapper @@ -223,7 +223,6 @@ buildStdenv.mkDerivation ({ nodejs perl pkgconfig - python2 python3 rust-cbindgen rustc