Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 413661

Summary: media-libs/x264-0.0.20111220 on x86 enables SSE even on non-SSE host
Product: Gentoo Linux Reporter: Petr Pisar <petr.pisar>
Component: [OLD] LibraryAssignee: Gentoo Media-video project <media-video>
Status: RESOLVED FIXED    
Severity: normal CC: bug
Priority: Normal Keywords: PATCH
Version: unspecified   
Hardware: x86   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---
Attachments: Fix

Description Petr Pisar 2012-04-26 18:48:54 UTC
I have AMD Duron processor which does not support SSE:

vendor_id       : AuthenticAMD
cpu family      : 6
model           : 3
model name      : AMD Duron(tm) processor
stepping        : 1
cpu MHz         : 951.632
cache size      : 64 KB
fdiv_bug        : no
hlt_bug         : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 1
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 mmx fxsr syscall mmxext 3dnowext 3dnow
bogomips        : 1903.26
clflush size    : 32
cache_alignment : 32
address sizes   : 36 bits physical, 32 bits virtual
power management:

But compiling media-libs/x264-0.0.20111220 with USE="custom-cflags threads" creates a binary which uses SSE instructions resulting in run-time error:

[libx264 @ 0x92af240] your cpu does not support SSE1, but x264 was compiled with asm support
[libx264 @ 0x92af240] to run x264, recompile without asm support (configure --disable-asm)

This is because x264 configure script injects "-msse" into CFLAGS:

case $host_cpu in
    i*86)
        ARCH="X86"
        AS="yasm"
        ASFLAGS="$ASFLAGS -O2"
        if [ $compiler = GNU ]; then
            if [[ "$asm" == auto && "$CFLAGS" != *-march* ]]; then
                CFLAGS="$CFLAGS -march=i686"
            fi
            if [[ "$asm" == auto && "$CFLAGS" != *-mfpmath* ]]; then
                CFLAGS="$CFLAGS -mfpmath=sse -msse"
            fi
        else
[...]
esac

and encoder/encoder.c code looks like:

static int x264_validate_parameters( x264_t *h, int b_open )
{
#if HAVE_MMX
#ifdef __SSE__
    if( b_open && !(x264_cpu_detect() & X264_CPU_SSE) )
    {
        x264_log( h, X264_LOG_ERROR, "your cpu does not support SSE1, but x264 was compiled with asm support\n");
#else
    if( b_open && !(x264_cpu_detect() & X264_CPU_MMX2) )
    {
        x264_log( h, X264_LOG_ERROR, "your cpu does not support MMXEXT, but x264 was compiled with asm support\n");
#endif
        x264_log( h, X264_LOG_ERROR, "to run x264, recompile without asm support (configure --disable-asm)\n");
        return -1;
    }
#endif

I think ebuilds CLFAGS hack:

    if use custom-cflags; then
        local cflags
        cflags="$(grep "^CFLAGS=" config.mak | sed 's/CFLAGS=//')"

does not catch this occurrence. I think harnessing USE flags "sse" or "mmx" would be more appropriate.
Comment 1 Petr Pisar 2012-04-26 19:16:18 UTC
Created attachment 310215 [details, diff]
Fix

This is yet another CFLAGS hack to remove SSE options if USE="custom-cflags -sse".
Comment 2 Alexis Ballier gentoo-dev 2013-08-01 16:59:25 UTC
+  01 Aug 2013; Alexis Ballier <aballier@gentoo.org> x264-9999.ebuild,
+  +files/x264-cflags.patch:
+  Do not mess too much with CFLAGS. Should fix bug #413661 and bug #351219.
+