anyc / steam-overlay

Gentoo overlay for Valve's Steam client and Steam-based games
GNU General Public License v2.0
202 stars 44 forks source link

Steam ebuild should have glibc[stack-align] as a USE flag requirement #321

Open unhappy-ending opened 1 year ago

unhappy-ending commented 1 year ago

I'm fairly certain it's a default USE flag, but I'm an idiot who likes to ignore such things. My system is currently built with somewhat minimal USE flags. The USE flag stack-align was disabled because of the supposed performance costs of leaving it enabled. Turns out with it disabled it seems Steam can't start any games. No proton games, no native games, nothing. Soon as the flag was turned back on, games started working again.

STEAM_RUNTIME on or off doesn't seem to make a difference, either.

Yeah I doubt there is many people this would affect but I figured if Steam isn't going to work with it off the ebuild should force it as a dependency for ding dongs like me.

chewi commented 1 year ago

It must have been something else. I only know of about 4 games where it makes a difference.

unhappy-ending commented 1 year ago

The only thing I had changed on my system was that single flag. Nothing worked before, Steam would try to start a game and immediately close it. Once changed, everything worked after.

Have you tested this yourself? I don't have the ability to make a video of a before and after, so I'm not sure how I could give you any sort of proof other than to try it yourself?

chewi commented 1 year ago

I implemented this USE flag, so I think I'd know, unless something has changed since. Especially as we lived without this flag for years and nearly everything worked fine!

Were any of the native games 64-bit? Can you give some examples?

unhappy-ending commented 1 year ago

Yeah I don't really recall the flag ever being a thing and don't remember when it was implemented. All I know is that one day Steam stopped working for me and the only reason I came across this is because Steam Beta's -gamepadui was giving me a segfault error with glibc and I decided to check a default install vs my custom flags.

I've already double tested this and recompiled glibc multiple times. I have over 700 games in my library, I don't know which exactly are 32 bit vs 64 bit but any game I tried didn't work. I will do this one more time and try a random set of games, but if you any in particular in mind that I might have I will test it.

unhappy-ending commented 1 year ago

I've tested:

140 (Native) 10 Second Ninja X (Proton) 99 Levels to Hell (Native) Bastion (Native) Bionic Commando ReArmed (Proton) (32 bit I think) Dark Souls 2 (Proton) Downwell (Proton) Final Fantasy Pixel Remaster (Proton) Hollow Knight (Native) Mark of the Ninja (Native) The Messenger (Proton) Papers Please (Native) Resonance of Fate (Proton) Shovel Knight (Native) Soul Fire (Proton) Street Fighter 30th Anniversary (Proton) Thief Gold (Proton) (Definitely 32 bit haha) Ultra Street Fighter 4 (Proton)

I can pick any random game and it won't start up at all. As you can see, that list has both native, Proton, and 32 bit vs 64 games on it. Soon as the flag is compiled in, things work fine. I'm recompiling the flag back in now.

If it helps, I have an AMD Ryzen 3950X, a RTX 3070 using proprietary drivers and a Plasma Wayland desktop. I've tried both Wayland and X11 sessions which doesn't make a difference. I've tried Zink on Nvidia, native OpenGL, DXVK, WineD3D, anything. The only thing that changes things is the USE flag stack-realign.

chewi commented 1 year ago

I don't have any of those installed through Steam, but I do have Shovel Knight installed from GOG, and it is 64-bit. The thing is this flag literally does nothing to 64-bit binaries. All it does is add a single compile flag to the 32-bit build of glibc.

I'll see whether I can reproduce this anyway, but exactly which games this affects does vary between systems, as it depends on a lot of factors. I have a similar environment to you, save for the NVIDIA card.

emerge --info would be handy.

unhappy-ending commented 1 year ago

Steam is still 32 bit though, so I'm wondering if it's something within the steam launcher itself that is relying on the flag. I don't think it's the games themselves but I don't have any non-steam games currently installed to try, and no time to test that scenario. I really think they'd be fine and this isn't related to that.

emerge --info
Portage 3.0.38.1 (python 3.10.8-final-0, default/linux/amd64/17.1, gcc-11, glibc-2.36-r5, 5.19.16-lqx1-clang x86_64)
=================================================================
System uname: Linux-5.19.16-lqx1-clang-x86_64-AMD_Ryzen_9_3950X_16-Core_Processor-with-glibc2.36
KiB Mem:    32800384 total,   6584304 free
KiB Swap:          0 total,         0 free
Head commit of repository gentoo: 4b84491db726a8b5a55d772dcf3a2766b6154f46

Head commit of repository audio-overlay: 61a8ceb241d1eedffa190373816b0b4fbd8d095b

Head commit of repository brave-overlay: 5042b11e57d79d3260613b1eb9aad8b476868a1d

Head commit of repository cg: 51b80474b553c72c86a3d6d47fa3e687d66c610c

Head commit of repository guru: 26216daf5ff6d9ade63f841106d72bb69935ecee

Head commit of repository src_prepare-overlay: b955077aa56f96deea45ee98e433b211c400ab01

Head commit of repository steam-overlay: 226725c26fa7f88b72889a494139342ca1729f82

sh bash 5.1_p16-r2
ld GNU ld (Gentoo 2.38 p4) 2.38
app-misc/pax-utils:        1.3.5::gentoo
app-shells/bash:           5.1_p16-r2::gentoo
dev-lang/perl:             5.36.0-r1::gentoo
dev-lang/python:           3.10.8_p1::gentoo
dev-lang/rust-bin:         1.64.0-r1::gentoo
dev-util/cmake:            3.24.2::gentoo
dev-util/meson:            9999::gentoo
sys-apps/baselayout:       2.9::gentoo
sys-apps/sandbox:          2.29::gentoo
sys-apps/systemd:          251.7::gentoo
sys-devel/autoconf:        2.71-r4::gentoo
sys-devel/automake:        1.16.5::gentoo
sys-devel/binutils:        2.38-r2::gentoo, 2.39-r4::gentoo
sys-devel/binutils-config: 5.4.1::gentoo
sys-devel/clang:           15.0.3::gentoo
sys-devel/gcc:             11.3.1_p20221007::gentoo
sys-devel/gcc-config:      2.8::gentoo
sys-devel/libtool:         2.4.7::gentoo
sys-devel/lld:             15.0.3::gentoo
sys-devel/llvm:            15.0.3::gentoo
sys-devel/make:            4.3::gentoo
sys-kernel/linux-headers:  6.0::gentoo (virtual/os-headers)
sys-libs/glibc:            2.36-r5::gentoo
Repositories:

gentoo
    location: /etc/portage/repos/gentoo
    sync-type: git
    sync-uri: https://anongit.gentoo.org/git/repo/gentoo.git
    sync-user: timothy:users
    priority: 0
    eclass-overrides: unhappy-ending

audio-overlay
    location: /etc/portage/repos/audio-overlay
    sync-type: git
    sync-uri: https://github.com/gentoo-audio/audio-overlay.git
    sync-user: timothy:users
    masters: gentoo
    priority: 50
    eclass-overrides: audio-overlay

brave-overlay
    location: /etc/portage/repos/brave-overlay
    sync-type: git
    sync-uri: https://gitlab.com/jason.oliveira/brave-overlay.git
    sync-user: timothy:users
    masters: gentoo
    priority: 50
    eclass-overrides: brave-overlay

cg
    location: /etc/portage/repos/cg
    sync-type: git
    sync-uri: https://github.com/brothermechanic/cg
    sync-user: timothy:users
    masters: gentoo
    priority: 50
    eclass-overrides: cg

guru
    location: /etc/portage/repos/guru
    sync-type: git
    sync-uri: https://gitweb.gentoo.org/repo/proj/guru
    sync-user: timothy:users
    masters: gentoo
    priority: 50
    eclass-overrides: guru

src_prepare-overlay
    location: /etc/portage/repos/src_prepare-overlay
    sync-type: git
    sync-uri: https://gitlab.com/src_prepare/src_prepare-overlay
    sync-user: timothy:users
    masters: gentoo
    priority: 50
    eclass-overrides: src_prepare-overlay

steam-overlay
    location: /etc/portage/repos/steam-overlay
    sync-type: git
    sync-uri: https://github.com/anyc/steam-overlay
    sync-user: timothy:users
    masters: gentoo
    priority: 50
    eclass-overrides: steam-overlay

unhappy-ending
    location: /etc/portage/repos/unhappy-ending
    masters: gentoo
    priority: 100
    eclass-overrides: unhappy-ending

Installed sets: @desktop-apps, @dev-python, @kde-frameworks, @kde-plasma, @missing-test-deps, @production-audio, @production-video, @qt-frameworks, @steam-client, @system-hardware, @system-kernel, @system-tools, @toolchain-llvm
ACCEPT_KEYWORDS="amd64 ~amd64"
ACCEPT_LICENSE="*"
ADDR2LINE="llvm-addr2line"
AR="llvm-ar"
AS="llvm-as"
CBUILD="x86_64-pc-linux-gnu"
CC="clang"
CFLAGS="-O2 -pipe -fdiagnostics-color=always -frecord-gcc-switches -Wall -Werror=format-security -Werror=implicit-function-declaration -Werror=incompatible-library-redeclaration -Werror=odr -Wextra"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/share/config"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo"
CPP="clang-cpp"
CXX="clang++"
CXXFLAGS="-O2 -pipe -fdiagnostics-color=always -frecord-gcc-switches -Wall -Werror=format-security -Werror=incompatible-library-redeclaration -Werror=odr -Wextra"
DISTDIR="/etc/portage/package.distfiles"
EMERGE_DEFAULT_OPTS="-a -j28 -l28 --alphabetical --autounmask=n --columns --fail-clean=n --quiet-build --quiet-unmerge-warn --with-bdeps-auto=n --with-test-deps=n"
ENV_UNSET="CARGO_HOME DBUS_SESSION_BUS_ADDRESS DISPLAY GOBIN GOPATH PERL5LIB PERL5OPT PERLPREFIX PERL_CORE PERL_MB_OPT PERL_MM_OPT XAUTHORITY XDG_CACHE_HOME XDG_CONFIG_HOME XDG_DATA_HOME XDG_RUNTIME_DIR XDG_STATE_HOME"
FCFLAGS="-O2 -pipe"
FEATURES="assume-digests binpkg-docompress binpkg-dostrip binpkg-logs buildpkg-live candy config-protect-if-modified distlocks ebuild-locks fixlafiles ipc-sandbox merge-sync multilib-strict network-sandbox news parallel-fetch pid-sandbox preserve-libs protect-owned qa-unresolved-soname-deps sandbox sfperms split-log strict unknown-features-warn unmerge-orphans userfetch userpriv usersandbox usersync xattr"
FFLAGS="-O2 -pipe"
GENTOO_MIRRORS="http://distfiles.gentoo.org /etc/portage/package.mirrors"
LANG="en_US.utf8"
LD="ld.lld"
LDFLAGS="-Wl,-O1 -Wl,--as-needed -Wl,--defsym=__gentoo_check_ldflags__=0 -Wl,--verbose"
LINGUAS="*"
MAKEOPTS="-j28 -l28"
NM="llvm-nm"
OBJCOPY="llvm-objcopy"
OBJDUMP="llvm-objdump"
PKGDIR="/etc/portage/package.distfiles/bin"
PORTAGE_BINHOST="https://calculate.mirror.garr.it/grp/x86_64"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --exclude=/.git"
PORTAGE_TMPDIR="/etc/portage/package.tmp"
RANLIB="llvm-ranlib"
READELF="llvm-readelf"
SHELL="/bin/bash"
STRINGS="llvm-strings"
STRIP="llvm-strip"
USE="acl aes amd64 avx avx2 bzip2 cli crypt dri f16c fma3 fortran gdbm iconv ipv6 libglvnd libtirpc mmx mmxext multilib ncurses nls nptl openmp pam pclmul pcre popcnt rdrand readline seccomp sha split-usr sse sse2 sse3 sse4_1 sse4_2 sse4a ssl ssse3 test-rust unicode xattr zlib" ABI_X86="32 64" ADA_TARGET="gnat_2021" ALSA_CARDS="emu10k1 emu1212 emu1616" CALLIGRA_FEATURES="karbon sheets words" CPU_FLAGS_X86="aes avx avx2 f16c fma3 mmx mmxext pclmul popcnt rdrand sha sse sse2 sse3 sse4_1 sse4_2 sse4a ssse3" ELIBC="glibc" GRUB_PLATFORMS="efi-64" INPUT_DEVICES="libinput wacom" KERNEL="linux" L10N="*" LLVM_TARGETS="AArch64 AMDGPU ARM AVR BPF Hexagon Lanai MSP430 Mips NVPTX PowerPC RISCV Sparc SystemZ VE WebAssembly X86 XCore" LUA_SINGLE_TARGET="lua5-4" LUA_TARGETS="lua5-4" PHP_TARGETS="php8-1" POSTGRES_TARGETS="postgres14" PYTHON_SINGLE_TARGET="python3_10" PYTHON_TARGETS="python3_10" RUBY_TARGETS="ruby27" USERLAND="GNU" VIDEO_CARDS="nvidia"
Unset:  ARFLAGS, ASFLAGS, CCLD, CONFIG_SHELL, CPPFLAGS, CTARGET, CXXFILT, ELFEDIT, EXTRA_ECONF, F77FLAGS, FC, GCOV, GPROF, INSTALL_MASK, LC_ALL, LEX, LFLAGS, LIBTOOL, MAKE, MAKEFLAGS, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, RUSTFLAGS, SIZE, YACC, YFLAGS
chewi commented 1 year ago

I still haven't been able to reproduce this with the Steam beta and at least when forcing a different glibc with this:

LD_PRELOAD=/var/tmp/portage/sys-libs/glibc-2.36-r5/image/lib32/libc.so.6 steam

I notice you're using clang. I can't tell whether glibc has been built with this (you need USE=custom-cflags), but I can't even get it to build when I try that.

I'm at a loss. I'll leave this open in case anyone else hits it.

unhappy-ending commented 1 year ago

glibc is still built with gcc and bfd. One of the 2.35 patch sets broke building glibc with LLD, and AFAIK it's never been able to be built with Clang although work is being done on that.

I'll post about this on r/gentoo and see if I can find anyone to reproduce it. Thank you for your time.

unhappy-ending commented 1 year ago

Hello, I finally have my equipment set back up so I was able to do some testing. I'm still using GCC 11.3.1 as you could see from my emerge ---info. I did several glibc builds.

  1. glibc[-custom-cflags -stack-realign] no CFLAGS set so only the defaults built. Steam launches games.
  2. glibc[-custom-cflags stack-realign] no CFLAGS set so only the defaults built. Steam launches games.
  3. glibc[custom-cflags -stack-realign] CFLAGS="-O3" as the only flag set. Steam doesn't launch games.
  4. glibc[custom-cflags -stack-realign] CFLAGS="-O3 -fno-tree-vectorize" set. Steam launches games.
  5. glibc[custom-cflags stack-realign] CFLAGS="-O3" as the only flag set. Steam launches games.

Apparently, -ftree-vectorize which is enabled in -O3 and higher, kills Steam's binaries used to launch games as posted by a user in my reddit thread. You can also see on the Steam bugtracker here how the code used to launch games is stack aligned differently.

Sam from the Gentoo team mentioned:

"Note that in Gentoo, we've worked around this by adding a USE=stack-realign USE flag to the sys-libs/glibc and sys-libs/ncurses ebuilds."

Soon -ftree-vectorize will be the default for -O2 so even if the user doesn't have USE="custom-cflags" this will be a problem. IMO, steam ebuild should require glibc[stack-realign] since -ftree-vectorize works with the flag enabled and this is soon to be default behavior. It isn't just an issue for a handful of games, it's an issue for the gameoverlayrenderer and reaper binary.

stefan11111 commented 8 months ago

glibc[custom-cflags -stack-realign] CFLAGS="-O3 -fno-tree-vectorize" set. Steam launches games. glibc[custom-cflags stack-realign] CFLAGS="-O3" as the only flag set. Steam launches games.

What setup gives the best performance?

Techwolf commented 2 weeks ago

Just adding some info about this issue. I am pretty sure this bug https://github.com/ValveSoftware/Source-1-Games/issues/3727 and https://wiki.gentoo.org/wiki/Steam/Games_troubleshooting#Half-Life_2 is the issue here. I created an env file only one line, "CFLAGS_x86="${CFLAGS_x86} -mstackrealign" and only point glibc to it. Nothing else is required to fix the 32bitaliment bug with the steam client.

UPDATE: The above hacks are no longer needed as USE flag stack-realign was added some time ago. https://github.com/gentoo/gentoo/commit/02aa6328a720c86d0157c4582f7e5bac72ae9296

The USE flag stack-realign is only applied to the 32bit build of glibc, so there is no performance decrease on 64-bit builds. The only binaries left that are 32-bit is mostly older games and they don't suffer a performance penintly due to hardware back then was 10 times slower then the 64-bit hardware use today.

chewi commented 2 weeks ago

Right, but that flag already existed when this thread was opened.