Skip to content

Commit

Permalink
atom: avoid using LD_PRELOAD. Fixes glibc compat issues
Browse files Browse the repository at this point in the history
The wrapper for Atom was loading libraries via LD_PRELOAD, for example
libxkbfile. Now, if you installed atom via nix-env and happened to use a newer
nixpkgs for that than what your system environment is build against, you could
end up with an error like this:

```
uname: relocation error:
/nix/store/68sa3m89shpfaqq1b9xp5p1360vqhwx6-glibc-2.25/lib/libdl.so.2:
symbol _dl_catch_error, version GLIBC_PRIVATE not defined in file libc.so.6
with link time reference
```

This happens because atom calls the `uname` executable from the system to
determine the platform. Because that inherits the `LD_PRELOAD` environment
variable, so the libxkbfile library that the `atom` wrapper was build against
is loaded into `uname`. But since `atom` comes from `nix-env`, the `libxkbfile`
it was built with might be compiled against a newer version of `glibc` than
`uname`, which comes from the system, was! Having two versions of glibc loaded
into the same processes results in chaos.

To fix this, we avoid setting `LD_PRELOAD` and instead use patchelf to set the
correct RPATH. RPATH is not inherited by child processes, so the above issue
can no longer occur.

The only small complication here is that the library that actually loads
libxkbfile is not the atom binary itself, but a node extension that atom uses.
So instead of setting the RPATH on `atom` only, we also set the `rpath` on all
node extensions (`*.node`) the output.
  • Loading branch information
bennofs committed Mar 18, 2017
1 parent 63f1a14 commit a4d6e2c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions pkgs/applications/editors/atom/default.nix
@@ -1,4 +1,4 @@
{ stdenv, fetchurl, lib, makeWrapper, gvfs, atomEnv, libXScrnSaver, libxkbfile }:
{ stdenv, fetchurl, lib, makeWrapper, gvfs, atomEnv}:

stdenv.mkDerivation rec {
name = "atom-${version}";
Expand All @@ -21,9 +21,7 @@ stdenv.mkDerivation rec {
rm -r $out/share/lintian
rm -r $out/usr/
wrapProgram $out/bin/atom \
--prefix "PATH" : "${gvfs}/bin" \
--prefix LD_PRELOAD : ${stdenv.lib.makeLibraryPath [ libXScrnSaver ]}/libXss.so.1 \
--prefix LD_PRELOAD : ${stdenv.lib.makeLibraryPath [ libxkbfile ]}/libxkbfile.so.1
--prefix "PATH" : "${gvfs}/bin"
fixupPhase
Expand All @@ -33,8 +31,11 @@ stdenv.mkDerivation rec {
patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
--set-rpath "${atomEnv.libPath}" \
$out/share/atom/resources/app/apm/bin/node
patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
$out/share/atom/resources/app.asar.unpacked/node_modules/symbols-view/vendor/ctags-linux
find $out/share/atom -name "*.node" -exec patchelf --set-rpath "${atomEnv.libPath}:$out/share/atom" {} \;
'';

meta = with stdenv.lib; {
Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/editors/atom/env.nix
Expand Up @@ -9,7 +9,7 @@ let
fontconfig gdk_pixbuf cairo cups expat libgpgerror alsaLib nspr gconf nss
xorg.libXrender xorg.libX11 xorg.libXext xorg.libXdamage xorg.libXtst
xorg.libXcomposite xorg.libXi xorg.libXfixes xorg.libXrandr
xorg.libXcursor libcap systemd libnotify
xorg.libXcursor xorg.libxkbfile xorg.libXScrnSaver libcap systemd libnotify
];

libPathNative = lib.makeLibraryPath packages;
Expand Down

0 comments on commit a4d6e2c

Please sign in to comment.