Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 503138 - games-emulation/zsnes-1.51-r4 crashes with segmentation fault in libc-2.18.so on startup
Summary: games-emulation/zsnes-1.51-r4 crashes with segmentation fault in libc-2.18.so...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Games (show other bugs)
Hardware: AMD64 Linux
: Normal normal
Assignee: Gentoo Games
URL: https://bugs.archlinux.org/task/36556
Whiteboard:
Keywords: PATCH
Depends on:
Blocks:
 
Reported: 2014-03-01 17:34 UTC by nvinson234
Modified: 2018-07-06 22:33 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments
zsnes stack realignment patch (zsnes-1.51-sse42.patch,377 bytes, patch)
2014-03-01 17:43 UTC, nvinson234
Details | Diff
emerge --verbose --info zsnes (emerge_info.log,16.29 KB, text/plain)
2014-03-01 17:44 UTC, nvinson234
Details

Note You need to log in before you can comment on or make changes to this bug.
Description nvinson234 2014-03-01 17:34:18 UTC
zsnes crashes with segmentation fault on startup and the linux kernel reports general protection ip:f740f88d sp:fff20af8 error:0 in libc-2.18.so[f72e5000+1a1000]

The issue appears to be due to glibc optimizing strstr() by calling __strstr_sse42() which requires the stack to be 16-byte aligned.

Reproducible: Always

Steps to Reproduce:
1. Emerge zsnes on a system with glibc-2.18 and has SSE 4.2 extensions
2. run zsnes

Actual Results:  
zsnes crashes on startup.

Expected Results:  
Zsnes starts up and runs normally.

When zsnes first crashed on me it was in libGL.so not libc.so.  However, I added the vaapi and vdapu USE flags to my system since then in hopes that it would fix the problem (as well as improve video performance).  However, since the issue lies in the use of sse4.2 instructions and misaligned stacks, I suspect the same root cause as I am reporting now.
Comment 1 nvinson234 2014-03-01 17:40:44 UTC
This is actually a duplicate of the archlinux bug (sorry, I didn't follow the URL in 488918 until just now).  However, instead of patching glibc, I'll use the oppertunity to propose a patch for zsnes just in case my supposition in the additional notes section is correct.
Comment 2 nvinson234 2014-03-01 17:43:53 UTC
Created attachment 371508 [details, diff]
zsnes stack realignment patch

This patch instructs gcc to realign the stack to a 16-byte boundary when startgame() is called.  This patch allows zsnes to run correctly without the need to patch glibc.
Comment 3 nvinson234 2014-03-01 17:44:27 UTC
Created attachment 371510 [details]
emerge --verbose --info zsnes
Comment 4 Andreas Klauer 2014-04-18 21:29:15 UTC
For me (on Haswell/~amd64) it used to work without until yesterday or so but a world update broke it again. Segfault on startup - gone with your patch. Thanks...
Comment 5 Mr. Bones. (RETIRED) gentoo-dev 2015-01-24 07:19:06 UTC
ok, patch is in portage.
Comment 6 Larry the Git Cow gentoo-dev 2018-07-06 22:33:15 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=c068f68557e6a0d7d2f5232221900205076429aa

commit c068f68557e6a0d7d2f5232221900205076429aa
Author:     Sergei Trofimovich <slyfox@gentoo.org>
AuthorDate: 2018-07-06 22:32:25 +0000
Commit:     Sergei Trofimovich <slyfox@gentoo.org>
CommitDate: 2018-07-06 22:33:09 +0000

    games-emulation/zsnes: apply stack realignment to more functions
    
    Expand existing stack realignment hack to more C functions
    that get called from early init assembly. Fixes zsnes startup
    for me.
    
    Bug: https://bugs.gentoo.org/503138
    Package-Manager: Portage-2.3.41, Repoman-2.3.9

 .../zsnes/files/zsnes-1.51-stack-align-v2.patch    |  56 ++++++++++
 games-emulation/zsnes/zsnes-1.51-r7.ebuild         | 122 +++++++++++++++++++++
 2 files changed, 178 insertions(+)