microsoft / mimalloc

mimalloc is a compact general purpose allocator with excellent performance.
MIT License
9.74k stars 791 forks source link

2.1.4: build fail on centos7 #885

Closed jimying closed 1 month ago

jimying commented 2 months ago

I try use clang17 and gcc9 build mimalloc on centos7 x86_64, same error log:

In file included from /usr/include/string.h:633,
                 from /home/build/mimalloc-2.1.4/include/mimalloc/internal.h:291,
                 from /home/build/mimalloc-2.1.4/src/alloc.c:12:
/home/build/mimalloc-2.1.4/src/alloc-override.c:139:24: error: expected identifier or ‘(’ before ‘__extension__’
  139 |   mi_decl_export char* strdup(const char* str)             MI_FORWARD1(mi_strdup, str)
hombit commented 2 months ago

I have the same issue with Python's manylinux2014 images, which are Centos7.

The issue can be reproduced with this Dockerfile:

FROM quay.io/pypa/manylinux2014_x86_64

RUN curl -LOJ https://github.com/microsoft/mimalloc/archive/refs/tags/v2.1.4.tar.gz \
    && tar -xzf mimalloc-2.1.4.tar.gz \
    && rm mimalloc-2.1.4.tar.gz

WORKDIR /mimalloc-2.1.4
RUN mkdir -p out/release \
    && cd out/release \
    && cmake ../..

WORKDIR /mimalloc-2.1.4/out/release
CMD ["make"]
docker build --tag manylinux-mimalloc .
docker run --rm manylinux-mimalloc

Please also see the relevant discussion in this mimalloc_rust issue: https://github.com/purpleprotocol/mimalloc_rust/issues/111

daanx commented 2 months ago

Thanks for the repro steps -- I hope to get this resolved soon.

jimying commented 2 months ago

@daanx centos7 can use scl install gcc9

yum install centos-release-scl  scl-utils  devtoolset-9  -y
scl enable devtoolset-9 bash

help this can give you some help

keyihao commented 1 month ago

Same issue with gcc 9 and gcc 11 on CentOS7

tbzhang commented 1 month ago

This seems to be incompatible with older glibc version, because of an unexpected macro expansion coming from bits/string2.h :

# ifndef _HAVE_STRING_ARCH_strdup

extern char *__strdup (const char *__string) __THROW __attribute_malloc__;
#  define __strdup(s) \
  (__extension__ (__builtin_constant_p (s) && __string2_1bptr_p (s)           \
                  ? (((const char *) (s))[0] == '\0'                          \
                     ? (char *) calloc ((size_t) 1, (size_t) 1)               \
                     : ({ size_t __len = strlen (s) + 1;                      \
                          char *__retval = (char *) malloc (__len);           \
                          if (__retval != NULL)                               \
                            __retval = (char *) memcpy (__retval, s, __len);  \
                          __retval; }))                                       \
                  : __strdup (s)))

#  if defined __USE_SVID || defined __USE_BSD || defined __USE_XOPEN_EXTENDED
#   define strdup(s) __strdup (s)
#  endif
# endif
nautaa commented 1 month ago

This may be due to strdup being a preprocessor macro. if it's ok, I'll submit a PR to fix this? ref: https://stackoverflow.com/questions/51233563/is-it-possible-to-overwrite-strdup-from-string-h-with-my-own

hombit commented 1 month ago

I believe it is fixed by the latest release