NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.08k stars 13.39k forks source link

32-bit Source games do not launch properly #271483

Open itsvic-dev opened 8 months ago

itsvic-dev commented 8 months ago

Team Fortress 2 (downloaded via Steam) does not run in NixOS 23.11. It ran fine under NixOS 23.05.

Additional context

/bin/sh\0-c\0/home/vic/.local/share/Steam/ubuntu12_32/reaper SteamLaunch AppId=440 -- /home/vic/.local/share/Steam/ubuntu12_32/steam-launch-wrapper -- '/home/vic/.local/share/Steam/steamapps/common/Team Fortress 2/hl2.sh' -game tf -steam\0
chdir "/home/vic/.local/share/Steam/steamapps/common/Team Fortress 2"
ERROR: ld.so: object '/home/vic/.local/share/Steam/ubuntu12_32/gameoverlayrenderer.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS32): ignored.
ERROR: ld.so: object '/home/vic/.local/share/Steam/ubuntu12_64/gameoverlayrenderer.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS64): ignored.
ERROR: ld.so: object '/home/vic/.local/share/Steam/ubuntu12_32/gameoverlayrenderer.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS32): ignored.
ERROR: ld.so: object '/home/vic/.local/share/Steam/ubuntu12_32/gameoverlayrenderer.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS32): ignored.
pid 13955 != 13954, skipping destruction (fork without exec?)
ERROR: ld.so: object '/home/vic/.local/share/Steam/ubuntu12_32/gameoverlayrenderer.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS32): ignored.
ERROR: ld.so: object '/home/vic/.local/share/Steam/ubuntu12_64/gameoverlayrenderer.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS64): ignored.
src/tcmalloc.cc:278] Attempt to free invalid pointer 0x9e37af0 
/home/vic/.local/share/Steam/steamapps/common/Team Fortress 2/hl2.sh: line 72: 13957 Aborted                 (core dumped) ${GAME_DEBUGGER} "${GAMEROOT}"/${GAMEEXE} "$@"

Notify maintainers

@mkg20001

Metadata

vic@e6nix ~ % nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.1.64, NixOS, 23.11 (Tapir), 23.11.928.50aa30a13c4a`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.1`
 - channels(root): `"nixos-23.11"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`
varris1 commented 8 months ago

This bug is not only affecting NixOS. You can work around the crash by adding pkgsi686Linux.gperftools to systemPackages and then use this launch option within Steam: LD_PRELOAD=$LD_PRELOAD:/run/current-system/sw/lib/libtcmalloc_minimal.so %command%

itsvic-dev commented 8 months ago

This bug is not only affecting NixOS. You can work around the crash by adding pkgsi686Linux.gperftools to systemPackages and then use this launch option within Steam: LD_PRELOAD=$LD_PRELOAD:/run/current-system/sw/lib/libtcmalloc_minimal.so %command%

The workaround seems to work, thank you!

If the bug is reproducible on other distros, it should probably be reported upstream it if wasn't yet.

varris1 commented 8 months ago

If the bug is reproducible on other distros, it should probably be reported upstream it if wasn't yet.

https://github.com/ValveSoftware/Source-1-Games/issues/5043

chaorace commented 8 months ago

Here's an alternative method which fixes all Source 1 games without modifying launch options.

(steam.override { extraLibraries = pkgs: [ pkgs.gperftools ]; })

Mostly unrelated, but I actually do quite a few whacky things with Steam's package in home-manager so I'll share below what my actual steam package declaration looks like:

# This creates a wrapper forcing the binary to always run through nixGL, enabling hardware accel outside NixOS
# Not necessary on nixOS. Needs tweaking to work with NVIDIA, details here: https://github.com/nix-community/nixGL
let
  nixVulkan = nixgl.packages.${pkgs.system}.nixVulkanIntel; # nixgl refers to the nixGL flake (see above link)
  nixVulkanWrap = pkg: lib.meta.hiPrio (pkgs.symlinkJoin {
    name = pkg.name;
    paths = [
      (pkgs.writeShellApplication {
        name = pkg.meta.mainProgram;
        runtimeInputs = [ nixVulkan ];
        text = ''exec ${lib.getExe nixVulkan} ${lib.getExe pkg} "$@"'';
      })
      pkg
    ];
  });
# The above wrapper is overkill for just Steam, but in my full config I use it with lots of packages
in (nixVulkanWrap (steam.override {
  # Fixes Source 1 games like TF2, unlikely chance of breaking other Linux native games though?
  extraLibraries = pkgs: [ pkgs.gperftools ]; 
  # Here we do some linker tricks to achieve two different goals:
  # - Automatically enable gamemode whenever Steam is running
  # -- NOTE: Assumes that a working system install of gamemode already exists!
  # - Fix invisible Steam Input cursors on Wayland using extest
  # -- extest is not yet on nixpkgs, but will be soon (see https://github.com/NixOS/nixpkgs/pull/269881)
  # -- For the time being I've been using my own flake to overlay it in: https://github.com/chaorace/extest-nix
  extraProfile = let gmLib = "${lib.getLib(pkgs.gamemode)}/lib"; in ''
    export LD_PRELOAD="${pkgs.extest}/lib/libextest.so:${gmLib}/libgamemodeauto.so:$LD_PRELOAD"
    export LD_LIBRARY_PATH="${gmLib}:$LD_LIBRARY_PATH"
  '';
}))
ImUrX commented 8 months ago

Here's an alternative method which fixes all Source 1 games without modifying launch options.

* Pros: Doesn't pollute system libraries, No LD_PRELOAD, Same solution on all Linux platforms

* Cons: Might break other Linux native games if they don't like gperftools?
(steam.override { extraLibraries = pkgs: [ pkgs.gperftools ]; })

Sad, I tried this and I can't manage to make it work, I have checked with steam-run ldconfig -p if the libraries got overridden and yeah, I can see libtcmalloc_minimal.so exist but TF2 still crashes

chaorace commented 8 months ago

Sad, I tried this and I can't manage to make it work, I have checked with steam-run ldconfig -p if the libraries got overridden and yeah, I can see libtcmalloc_minimal.so exist but TF2 still crashes

Hmm... are you using a Wayland environment? If so, try forcing x11 SDL with the following launch option in the Steam TF2 settings: SDL_VIDEODRIVER=x11 %command%. TF2's vendored version of SDL at bin/libSDL2-2.0.so.0 is known to be fairly busted at the moment.

If you're still having issues after trying that, then perhaps it's a driver issue? Earlier this year, NVIDIA introduced a crash starting in driver version 525.60.11 (Nov. 2022) which was patched starting with driver 530.41.03 (April 2023).

If you've verified that's not the issue, are you sure if it's truly crashing every single time? In my experience, the client is super flakey during launch, but can be brute-forced if you retry enough times (5-10 times).

ImUrX commented 8 months ago

It's the same src/tcmalloc.cc:278] Attempt to free invalid pointer 0x9e37af0 crash, and I do use wayland but I use AMD.

This bug is not only affecting NixOS. You can work around the crash by adding pkgsi686Linux.gperftools to systemPackages and then use this launch option within Steam: LD_PRELOAD=$LD_PRELOAD:/run/current-system/sw/lib/libtcmalloc_minimal.so %command%

this works perfectly tho!

Jaculabilis commented 8 months ago

I can confirm the systemPackages fix works for me. Adding the following module:

({ pkgs, ... }: {
  environment.systemPackages = [ pkgs.pkgsi686Linux.gperftools ];
})

and launch option:

LD_PRELOAD=$LD_PRELOAD:/run/current-system/sw/lib/libtcmalloc_minimal.so %command%

fixed the core dump crash.

I tried the override, thinking that maybe it didn't work for @ImUrX as written because it wasn't picking out the i686 version specifically:

  nixpkgs.overlays = [
    (final: prev: {
      steam = prev.steam.override {
        extraLibraries = pkgs: [ pkgs.pkgsi686Linux.gperftools ];
      };
    })
  ];

but this didn't work when I tried it. I don't know if the override is wrong, or if it needs to be somewhere else.

varris1 commented 8 months ago

I switched to the override method in the meantime. Just make sure to restart Steam after the nixos-rebuild or it won't pick up the changed environment. I guess this is why a few people are not able to play TF2 still without doing my own hacky workaround.

jh-devv commented 7 months ago

This bug is not only affecting NixOS. You can work around the crash by adding pkgsi686Linux.gperftools to systemPackages and then use this launch option within Steam: LD_PRELOAD=$LD_PRELOAD:/run/current-system/sw/lib/libtcmalloc_minimal.so %command%

Works! I can confirm I got Portal Stories Mel working with this

jh-devv commented 7 months ago

Here's an alternative method which fixes all Source 1 games without modifying launch options.

* Pros: Doesn't pollute system libraries, No LD_PRELOAD, Same solution on all Linux platforms

* Cons: Might break other Linux native games if they don't like gperftools?
(steam.override { extraLibraries = pkgs: [ pkgs.gperftools ]; })

Mostly unrelated, but I actually do quite a few whacky things with Steam's package in home-manager so I'll share below what my actual steam package declaration looks like:

# This creates a wrapper forcing the binary to always run through nixGL, enabling hardware accel outside NixOS
# Not necessary on nixOS. Needs tweaking to work with NVIDIA, details here: https://github.com/nix-community/nixGL
let
  nixVulkan = nixgl.packages.${pkgs.system}.nixVulkanIntel; # nixgl refers to the nixGL flake (see above link)
  nixVulkanWrap = pkg: lib.meta.hiPrio (pkgs.symlinkJoin {
    name = pkg.name;
    paths = [
      (pkgs.writeShellApplication {
        name = pkg.meta.mainProgram;
        runtimeInputs = [ nixVulkan ];
        text = ''exec ${lib.getExe nixVulkan} ${lib.getExe pkg} "$@"'';
      })
      pkg
    ];
  });
# The above wrapper is overkill for just Steam, but in my full config I use it with lots of packages
in (nixVulkanWrap (steam.override {
  # Fixes Source 1 games like TF2, unlikely chance of breaking other Linux native games though?
  extraLibraries = pkgs: [ pkgs.gperftools ]; 
  # Here we do some linker tricks to achieve two different goals:
  # - Automatically enable gamemode whenever Steam is running
  # -- NOTE: Assumes that a working system install of gamemode already exists!
  # - Fix invisible Steam Input cursors on Wayland using extest
  # -- extest is not yet on nixpkgs, but will be soon (see https://github.com/NixOS/nixpkgs/pull/269881)
  # -- For the time being I've been using my own flake to overlay it in: https://github.com/chaorace/extest-nix
  extraProfile = let gmLib = "${lib.getLib(pkgs.gamemode)}/lib"; in ''
    export LD_PRELOAD="${pkgs.extest}/lib/libextest.so:${gmLib}/libgamemodeauto.so:$LD_PRELOAD"
    export LD_LIBRARY_PATH="${gmLib}:$LD_LIBRARY_PATH"
  '';
}))

@chaorace You don't need libgamemodeauto unless you want to use it for all games? https://github.com/FeralInteractive/gamemode/issues/345

chaorace commented 7 months ago

@jh-devv You are correct. As the config comments mention, it's something that I do so that gamemode is enabled whenever Steam is running without needing to fiddle with individual game launch options.

I specifically want the behavior you mention because I view it as a convenience. It is not necessary to do this to fix TF2 or use gamemode and I am sorry for having inadvertently implied otherwise.

jh-devv commented 7 months ago

@jh-devv You are correct. As the config comments mention, it's something that I do so that gamemode is enabled whenever Steam is running without needing to fiddle with individual game launch options.

I specifically want the behavior you mention because I view it as a convenience. It is not necessary to do this to fix TF2 or use gamemode and I am sorry for having inadvertently implied otherwise.

No problem! The help ya provided with TF2 is cool though, I got it working finally!!

asymmetric commented 6 months ago

FTR, I was having this issue with Against the Storm after the game was updated (it used to run fine without), and fixed using @chaorace's steam.override from https://github.com/NixOS/nixpkgs/issues/271483#issuecomment-1847417013.

Jayman2000 commented 5 months ago

As it turns out, there’s commits in GCC’s 14.x, 13.x and 12.x branches that prevent outdated versions of tcmalloc from causing this issue. Those commits are from 2024, but the most recent releases of GCC are all from 2023, so the fix isn’t in any stable release of GCC yet. Perhaps we could patch GCC in the meantime?

justinrubek commented 5 months ago

@chaorace's solution doesn't work for me. There's an issue with the nixos module calling override in the package option's apply. I am guessing this is because I install steam through nixos and not home-manager. I tried to look for context how the snippet was used in their configuration but didn't find a public repo with it.

using environment.systemPackages = [ pkgs.pkgsi686Linux.gperftools ]; and setting launch options works though.

willswats commented 4 months ago

It's now fixed for TF2 due to the 64-bit update, but it's still broken with Counter-Strike: Source, and probably others.

itsvic-dev commented 3 months ago

changed the title to be slightly more accurate