Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alacritty does not include glibc in rpath #219213

Closed
blucoat opened this issue Mar 2, 2023 · 12 comments · Fixed by #240773
Closed

Alacritty does not include glibc in rpath #219213

blucoat opened this issue Mar 2, 2023 · 12 comments · Fixed by #240773

Comments

@blucoat
Copy link

blucoat commented Mar 2, 2023

Describe the bug

Alacritty has the wrong RPATH. It does not include glibc or libgcc, which causes it to use the system's libraries on non-nixos systems.

This is likely because the derivation for Alacritty sets RPATH manually, and does not include these libraries (probably just an oversight, since these are normally taken care of by stdenv.mkDerivation).

Steps To Reproduce

$ ldd $(which alacritty)
/home/james/.nix-profile/bin/alacritty: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by /home/james/.nix-profile/bin/alacritty)
/home/james/.nix-profile/bin/alacritty: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.32' not found (required by /home/james/.nix-profile/bin/alacritty)
/home/james/.nix-profile/bin/alacritty: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by /home/james/.nix-profile/bin/alacritty)
/home/james/.nix-profile/bin/alacritty: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by /nix/store/970v1z9hdxby0s2dcj06ri1mxiyajj12-freetype-2.12.1/lib/libfreetype.so.6)
/home/james/.nix-profile/bin/alacritty: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by /nix/store/s6slp93zplkd70zsahrvsp615vlcy2i8-fontconfig-2.14.0-lib/lib/libfontconfig.so.1)
/home/james/.nix-profile/bin/alacritty: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by /nix/store/y68a044xy6mrysszvpf50hadls4ijj61-libXau-1.0.9/lib/libXau.so.6)
	linux-vdso.so.1 (0x00007ffd4663a000)
	libxcb.so.1 => /nix/store/g9wiz0czjlhippnyd3p6v10wvj9if4yy-libxcb-1.14/lib/libxcb.so.1 (0x00007f06cdf46000)
	libfreetype.so.6 => /nix/store/970v1z9hdxby0s2dcj06ri1mxiyajj12-freetype-2.12.1/lib/libfreetype.so.6 (0x00007f06cde7a000)
	libfontconfig.so.1 => /nix/store/s6slp93zplkd70zsahrvsp615vlcy2i8-fontconfig-2.14.0-lib/lib/libfontconfig.so.1 (0x00007f06cde2e000)
	libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f06cddd6000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f06cdc92000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f06cdabd000)
	libXau.so.6 => /nix/store/y68a044xy6mrysszvpf50hadls4ijj61-libXau-1.0.9/lib/libXau.so.6 (0x00007f06cdab8000)
	libXdmcp.so.6 => /nix/store/2sbvvb4a86953sxn05gnrfkmali7wvp0-libXdmcp-1.1.3/lib/libXdmcp.so.6 (0x00007f06cdab0000)
	libz.so.1 => /nix/store/9dz5lmff9ywas225g6cpn34s0wbldnxa-zlib-1.2.13/lib/libz.so.1 (0x00007f06cda90000)
	libbz2.so.1 => /nix/store/2a6yagz3pa8kiawg5mk2js70f8kwqzqd-bzip2-1.0.8/lib/libbz2.so.1 (0x00007f06cda7d000)
	libpng16.so.16 => /nix/store/d1b4yv4wgydcazgz4d76z1srpnf29n5v-libpng-apng-1.6.39/lib/libpng16.so.16 (0x00007f06cda44000)
	libbrotlidec.so.1 => /nix/store/9pdbnv128m77c9g3sr840vk0gfg94zy0-brotli-1.0.9-lib/lib/libbrotlidec.so.1 (0x00007f06cda36000)
	libpthread.so.0 => /nix/store/lqz6hmd86viw83f9qll2ip87jhb7p1ah-glibc-2.35-224/lib/libpthread.so.0 (0x00007f06cda31000)
	libexpat.so.1 => /nix/store/22wig7q4bj2clxz1ysl7gmh4667i00m4-expat-2.5.0/lib/libexpat.so.1 (0x00007f06cda04000)
	/nix/store/lqz6hmd86viw83f9qll2ip87jhb7p1ah-glibc-2.35-224/lib/ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2 (0x00007f06ce65d000)
	libbrotlicommon.so.1 => /nix/store/9pdbnv128m77c9g3sr840vk0gfg94zy0-brotli-1.0.9-lib/lib/libbrotlicommon.so.1 (0x00007f06cd9e1000)

Notice that libgcc_s, libm and libc all end up using system libraries. This is because the runpath is wrong:

$ readelf -d $(which alacritty)

Dynamic section at offset 0x5e8670 contains 34 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libxcb.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libfreetype.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libfontconfig.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libgcc_s.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libm.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x000000000000001d (RUNPATH)            Library runpath: [/nix/store/22wig7q4bj2clxz1ysl7gmh4667i00m4-expat-2.5.0/lib:/nix/store/s6slp93zplkd70zsahrvsp615vlcy2i8-fontconfig-2.14.0-lib/lib:/nix/store/970v1z9hdxby0s2dcj06ri1mxiyajj12-freetype-2.12.1/lib:/nix/store/m2w17l2v8lil49dskfkgzn3b1m1fszr9-libGL-1.6.0/lib:/nix/store/b6dyy0mxd4xhkkimlm0v8g0pbq0qpay5-libX11-1.8.3/lib:/nix/store/j5qck88fjfc32aghfxhsz41drkxswfi1-libXcursor-1.2.0/lib:/nix/store/vlry6bc6b8hiyg12cc4nr0726cz9gv3y-libXi-1.8/lib:/nix/store/25s737gk43a986fg8wq0j2n3z8751nbi-libXrandr-1.5.2/lib:/nix/store/3i6qbdsyyp0cc3fsf4v0xmlxjg06dss1-libXxf86vm-1.1.4/lib:/nix/store/g9wiz0czjlhippnyd3p6v10wvj9if4yy-libxcb-1.14/lib:/nix/store/yfvj8b1gq8wgqkhn7ag0nlcqd929akfk-libxkbcommon-1.5.0/lib:/nix/store/k0r8kbd579gmg4bq7mxhj3kiwz6i5vc0-wayland-1.21.0/lib]
 0x000000000000000c (INIT)               0x5f000
 0x000000000000000d (FINI)               0x49be94
 0x0000000000000019 (INIT_ARRAY)         0x5aad90
 0x000000000000001b (INIT_ARRAYSZ)       16 (bytes)
 0x000000000000001a (FINI_ARRAY)         0x5aada0
 0x000000000000001c (FINI_ARRAYSZ)       8 (bytes)
 0x0000000000000004 (HASH)               0x6e91c8
 0x000000006ffffef5 (GNU_HASH)           0xe10
 0x0000000000000005 (STRTAB)             0x6e8000
 0x0000000000000006 (SYMTAB)             0xe38
 0x000000000000000a (STRSZ)              4550 (bytes)
 0x000000000000000b (SYMENT)             24 (bytes)
 0x0000000000000015 (DEBUG)              0x0
 0x0000000000000003 (PLTGOT)             0x5e98d0
 0x0000000000000002 (PLTRELSZ)           24 (bytes)
 0x0000000000000014 (PLTREL)             RELA
 0x0000000000000017 (JMPREL)             0x5e288
 0x0000000000000007 (RELA)               0x3628
 0x0000000000000008 (RELASZ)             371808 (bytes)
 0x0000000000000009 (RELAENT)            24 (bytes)
 0x000000000000001e (FLAGS)              BIND_NOW
 0x000000006ffffffb (FLAGS_1)            Flags: NOW PIE
 0x000000006ffffffe (VERNEED)            0x3468
 0x000000006fffffff (VERNEEDNUM)         3
 0x000000006ffffff0 (VERSYM)             0x329a
 0x000000006ffffff9 (RELACOUNT)          15266
 0x0000000000000000 (NULL)               0x0

Expected behavior

Alacritty should link to the libc in the nix store at runtime.

Notify maintainers

@Br1ght0ne @Mic92 @Ma27

Metadata

 - system: `"x86_64-linux"`
 - host os: `Linux 5.10.0-19-amd64, Debian GNU/Linux, 11 (bullseye), nobuild`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.11.1`
 - channels(jade): `""`
 - channels(root): `"home-manager, nixpkgs, oldpkgs-18.09"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixpkgs`
@trofi
Copy link
Contributor

trofi commented Mar 5, 2023

AFAIU glibc does not have to be in RPATH: those paths are already present in ld.so specified in in INTERP section. I suspect you are using ldd from the host system and thus use it's interpreter, not alacritty's. Try lddtree from pax-utils. More direct way to se what loads what is to run it via LD_DEBUG=files alacritty.

I suspect you are loading wrong glibc via mesa drivers.

@kchibisov
Copy link

I think I've seen something like that with cross, but I haven't bother sending a fix upstream. What happens is that manual --rpath setting purges everything, so if you cross build it simply doesn't work the way alacritty's derivation is doing so.

What I was doing instead, is appending path for runtime deps in postFixup phase and enable default patchelf running.

That's an example of what I do for other package using the exact same dependencies as alacritty.

  postFixup = ''
    patchelf --add-rpath "${libGL}/lib" $out/bin/alacritty
  '';

Which makes it start when nix copy to other target.

@trofi
Copy link
Contributor

trofi commented Apr 13, 2023

I think the correct way to override default search paths of vlvnd is via environment variables like GBM_BACKENDS_PATH= LIBGL_DRIVERS_PATH= __EGL_VENDOR_LIBRARY_DIRS=. But NixOS/nixpkgs intentionally does not embed those into binaries to allow mesa or vendor drivers to be pluged in without the rebuild of the all client apps.

@trofi
Copy link
Contributor

trofi commented Apr 13, 2023

https://github.com/nixpkgs-architecture/issues/issues/15 is a related issue in nixpkgs-architecture component.

@kchibisov
Copy link

The --set-rpath in alacritty.nix removes all default searching and break. Using libglvnd variables is not really a solution to it, given that OpenGL is not the only thing dlopened by alacritty, it also dlopens libwayland and libX11. Similar thing is done by other windowing libs, like glfw and SDL.

@trofi
Copy link
Contributor

trofi commented Apr 13, 2023

The --set-rpath in alacritty.nix removes all default searching and break. Using libglvnd variables is not really a solution to it, given that OpenGL is not the only thing dlopened by alacritty, it also dlopens libwayland and libX11. Similar thing is done by other windowing libs, like glfw and SDL.

I think alacritty derivation already passes x11 and wayland to --set-rpath: https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/terminal-emulators/alacritty/default.nix#L34-L49 . My suggestion to use GL* variables (as a workaround on non-NixOS) was only for mesa drivers. alacritty should still embed needed RPATHs to make the rest of libraries work.

Initial report claims libc and libm are loaded from the wrong location. I don't believe it's true.

@kchibisov
Copy link

But I think it's sort of expected given that you purge rpath, so you load from whatever you can find?

I might be not experienced here, but if you cross alacritty for aarch64-linux to x86_64-linux, it won't ever find a libc, libgcc_s.so and similar. The only way to make it find is to allow patchElf and then, on a fixup phase, do

postFixup = ''
    patchelf --add-rpath "${libGL}/lib" $out/bin/alacritty
  '';

With all the libs alacritty wants. Be aware, it's --add-rpath, not --set-rpath, I don't even understand what is the motivation for --set-rpath, other derivation like wezterm(similar situation), are adding stuff, not setting.

Initial report claims libc and libm are loaded from the wrong location. I don't believe it's true.

@blucoat Could you strace alacritty in your setup? I think that should be enough to verify that, @trofi ?

@trofi
Copy link
Contributor

trofi commented Apr 13, 2023

Running it under LD_DEBUG=files alacritty might be enough as well.

@ghost ghost self-assigned this Jun 16, 2023
@ghost
Copy link

ghost commented Jun 16, 2023

I encountered this too, and cheated with LD_LIBRARY_PATH. I am working on a fix.

@kchibisov
Copy link

I do something like that in my overlay, works in my cases with cross https://git.sr.ht/~kchibisov/nixos-config/tree/main/item/overlay/alacritty.nix#L107 , setting rpath will prune the old one according to readelf, and I haven't seen much projects doing so, most use add.

@trofi
Copy link
Contributor

trofi commented Jun 16, 2023

Yeah, I agree --set-rpath looks fishy.

@ghost
Copy link

ghost commented Jun 29, 2023

I think I've seen something like that with cross, but I haven't bother sending a fix upstream. What happens is that manual --rpath setting purges everything, so if you cross build it simply doesn't work the way alacritty's derivation is doing so.

Unfortunately there are serious problems with the libgcc_s in cross-compiled builds right now:

#240484

Fortunately there is a fix: #238154. Now that that is taken care of I will work on this issue next.

@kchibisov, I think you have the right strategy with this idea:

postFixup = ''
patchelf --add-rpath "${libGL}/lib" $out/bin/alacritty
'';

... that is the first thing I will try.

mitchmindtree pushed a commit to mitchmindtree/nixpkgs that referenced this issue Jul 2, 2023
As reported by @blucoat in
NixOS#219213 alacritty's RPATH is
missing many of the libraries which it links to, including for
example glibc.

The problem was diagnosed by @kchibisov as being caused by
alacritty's use of `--set-rpath` (which completely replaces the
rpath) instead of `--add-rpath` (which adds additional entries to
the rpath):

  NixOS#219213 (comment)

This commit implements @kchibisov's idea to change `--set-rpath` to
`--add-rpath`:

  NixOS#219213 (comment)

Closes NixOS#219213
mitchmindtree pushed a commit to mitchmindtree/nixpkgs that referenced this issue Jul 2, 2023
As reported by @blucoat in
NixOS#219213 alacritty's RPATH is
missing many of the libraries which it links to, including for
example glibc.

The problem was diagnosed by @kchibisov as being caused by
alacritty's use of `--set-rpath` (which completely replaces the
rpath) instead of `--add-rpath` (which adds additional entries to
the rpath):

  NixOS#219213 (comment)

This commit implements @kchibisov's idea to change `--set-rpath` to
`--add-rpath`:

  NixOS#219213 (comment)

Closes NixOS#219213
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants