Skip to content

Cannot build zstd 1.3.1 with -mbmi #868

@Totktonada

Description

@Totktonada

ZStd has the following defines in common/threading.h:

#define pthread_mutex_t int
#define pthread_cond_t int

The defines interfere with /usr/include/bits/pthreadtypes.h, which included by ZStd transitively via immintrin.h when -mbmi is enabled:

$ gcc -mbmi   -I./common -c compress/zstdmt_compress.c
In file included from compress/zstdmt_compress.c:25:0:
./common/threading.h:82:25: error: expected ‘;’, identifier or ‘(’ before ‘int’
 #define pthread_mutex_t int   /* #define rather than typedef, because sometimes pthread support is implicit, resulting in duplicated symbols */
                         ^
./common/threading.h:82:25: warning: useless type name in empty declaration
In file included from compress/zstdmt_compress.c:25:0:
./common/threading.h:88:24: error: expected ‘;’, identifier or ‘(’ before ‘int’
 #define pthread_cond_t int
                        ^
./common/threading.h:88:24: warning: useless type name in empty declaration

The error becomes less ambiguous when the file preprocessed before trying to compile:

$ gcc -mbmi   -I./common -c compress/zstdmt_compress.c -E >ppp.c && gcc ppp.c
In file included from /usr/include/sys/types.h:266:0,
                 from /usr/include/stdlib.h:291,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/6.4.0/include/mm_malloc.h:27,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/6.4.0/include/xmmintrin.h:34,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/6.4.0/include/immintrin.h:29,
                 from ./common/bitstream.h:71,
                 from ./common/fse.h:307,
                 from ./common/zstd_internal.h:23,
                 from compress/zstdmt_compress.c:26:
/usr/include/bits/pthreadtypes.h:128:2: error: expected ‘;’, identifier or ‘(’ before ‘int’
 } pthread_mutex_t;
  ^~~
In file included from /usr/include/sys/types.h:266:0,
                 from /usr/include/stdlib.h:291,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/6.4.0/include/mm_malloc.h:27,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/6.4.0/include/xmmintrin.h:34,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/6.4.0/include/immintrin.h:29,
                 from ./common/bitstream.h:71,
                 from ./common/fse.h:307,
                 from ./common/zstd_internal.h:23,
                 from compress/zstdmt_compress.c:26:
/usr/include/bits/pthreadtypes.h:167:2: error: expected ‘;’, identifier or ‘(’ before ‘int’
 } pthread_cond_t;
  ^~~

The problem appears on every haswell, broadwell, skylake targets, when -march=native is used (it assumes -mbmi). It is very commom case for Gentoo Linux installations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions