From fefdce3ee47ca6b833191a4364e0db696516c712 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Wed, 15 May 2024 21:12:54 +0200 Subject: [PATCH 1/5] macOS: Fix linking statically `__attribute__((constructor))` does not mark the symbol as used, so the linker ends up dead-stripping the symbol when linked statically. Adding the `used` attribute fixes that. --- src/prim/osx/alloc-override-zone.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/prim/osx/alloc-override-zone.c b/src/prim/osx/alloc-override-zone.c index 9a317750..1515b886 100644 --- a/src/prim/osx/alloc-override-zone.c +++ b/src/prim/osx/alloc-override-zone.c @@ -422,6 +422,7 @@ __attribute__((constructor(0))) #else __attribute__((constructor)) // seems not supported by g++-11 on the M1 #endif +__attribute__((used)) static void _mi_macos_override_malloc(void) { malloc_zone_t* purgeable_zone = NULL; From b9b321d3284b517344ea71fb49830d953b5f4be9 Mon Sep 17 00:00:00 2001 From: daanx Date: Sun, 19 May 2024 20:42:28 -0700 Subject: [PATCH 2/5] use _builtin_thread_pointer also on gcc 11-x64 and clang-14-x64 --- include/mimalloc/prim.h | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/include/mimalloc/prim.h b/include/mimalloc/prim.h index 126ea7cd..3f4574dd 100644 --- a/include/mimalloc/prim.h +++ b/include/mimalloc/prim.h @@ -198,7 +198,7 @@ static inline void mi_prim_tls_slot_set(size_t slot, void* value) mi_attr_noexce tcb[slot] = value; #elif defined(__APPLE__) && defined(__POWERPC__) // ppc, issue #781 MI_UNUSED(ofs); - pthread_setspecific(slot, value); + pthread_setspecific(slot, value); #endif } @@ -208,13 +208,18 @@ static inline void mi_prim_tls_slot_set(size_t slot, void* value) mi_attr_noexce // but unfortunately, it seems we cannot test for this reliably at this time (see issue #883) // Nevertheless, it seems needed on older graviton platforms (see issue #851). // For now, we only enable this for specific platforms. -#if defined(__GNUC__) && (__GNUC__ >= 7) && defined(__aarch64__) /* special case aarch64 for older gcc versions (issue #851) */ \ - && !defined(__APPLE__) /* on apple (M1) the wrong register is read (tpidr_el0 instead of tpidrro_el0) so fall back to TLS slot assembly ()*/ \ +#if !defined(__APPLE__) /* on apple (M1) the wrong register is read (tpidr_el0 instead of tpidrro_el0) so fall back to TLS slot assembly ()*/ \ + && !defined(MI_LIBC_MUSL) \ && (!defined(__clang_major__) || __clang_major__ >= 14) /* older clang versions emit bad code; fall back to using the TLS slot () */ -#define MI_USE_BUILTIN_THREAD_POINTER 1 + #if (defined(__GNUC__) && (__GNUC__ >= 7) && defined(__aarch64__)) /* aarch64 for older gcc versions (issue #851) */ \ + || (defined(__GNUC__) && (__GNUC__ >= 11) && defined(__x86_64__)) \ + || (defined(__clang_major__) && (__clang_major__ >= 14) && (defined(__aarch64__) || defined(__x86_64__))) + #define MI_USE_BUILTIN_THREAD_POINTER 1 + #endif #endif + // defined in `init.c`; do not use these directly extern mi_decl_thread mi_heap_t* _mi_heap_default; // default heap to allocate from extern bool _mi_process_is_initialized; // has mi_process_init been called? @@ -239,11 +244,11 @@ static inline mi_threadid_t _mi_prim_thread_id(void) mi_attr_noexcept { return (uintptr_t)NtCurrentTeb(); } -#elif MI_USE_BUILTIN_THREAD_POINTER +#elif MI_USE_BUILTIN_THREAD_POINTER static inline mi_threadid_t _mi_prim_thread_id(void) mi_attr_noexcept { // Works on most Unix based platforms with recent compilers - return (uintptr_t)__builtin_thread_pointer(); + return (uintptr_t)__builtin_thread_pointer(); } #elif defined(MI_HAS_TLS_SLOT) From d5ac4f7b95dfdd886ae69cd8798e8defbbefd664 Mon Sep 17 00:00:00 2001 From: daanx Date: Sun, 19 May 2024 20:42:58 -0700 Subject: [PATCH 3/5] add example docker file for testing on manylinux-x64 --- docker/manylinux-x64/Dockerfile | 22 ++++++++++++++++++++++ docker/readme.md | 10 ++++++++++ 2 files changed, 32 insertions(+) create mode 100644 docker/manylinux-x64/Dockerfile create mode 100644 docker/readme.md diff --git a/docker/manylinux-x64/Dockerfile b/docker/manylinux-x64/Dockerfile new file mode 100644 index 00000000..566685d4 --- /dev/null +++ b/docker/manylinux-x64/Dockerfile @@ -0,0 +1,22 @@ +FROM quay.io/pypa/manylinux2014_x86_64 + +# Install tools +RUN yum install -y openssl-devel +RUN yum install -y gcc gcc-c++ kernel-devel make +RUN yum install -y git cmake +RUN yum install -y vim + +RUN mkdir -p /home/dev +WORKDIR /home/dev + +# Get mimalloc +RUN git clone https://github.com/microsoft/mimalloc -b dev-slice +RUN mkdir -p mimalloc/out/release +RUN mkdir -p mimalloc/out/debug + +# Build mimalloc debug +WORKDIR /home/dev/mimalloc/out/debug +RUN cmake ../.. -DMI_DEBUG_FULL=ON +RUN make -j + +CMD ["/bin/sh"] \ No newline at end of file diff --git a/docker/readme.md b/docker/readme.md new file mode 100644 index 00000000..b3d90094 --- /dev/null +++ b/docker/readme.md @@ -0,0 +1,10 @@ +Various example docker files used for testing. + +Usage: + +``` +> cd +> docker build -t -mimalloc . +> docker run -it -mimalloc +>> make test +``` From 836ee0a94c568eab171ab63ab655c7b64fa10c98 Mon Sep 17 00:00:00 2001 From: Daan Date: Sun, 19 May 2024 21:32:22 -0700 Subject: [PATCH 4/5] add alpine docker files --- .gitignore | 2 ++ docker/alpine-arm32v7/Dockerfile | 28 ++++++++++++++++++++++++++++ docker/alpine/Dockerfile | 23 +++++++++++++++++++++++ docker/manylinux-x64/Dockerfile | 1 + 4 files changed, 54 insertions(+) create mode 100644 docker/alpine-arm32v7/Dockerfile create mode 100644 docker/alpine/Dockerfile diff --git a/.gitignore b/.gitignore index f8b7f5eb..df1d58eb 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ ide/vs20??/VTune* out/ docs/ *.zip +*.tar +*.gz diff --git a/docker/alpine-arm32v7/Dockerfile b/docker/alpine-arm32v7/Dockerfile new file mode 100644 index 00000000..56f071db --- /dev/null +++ b/docker/alpine-arm32v7/Dockerfile @@ -0,0 +1,28 @@ +# install from an image +# download first an appropiate tar.gz image into the current directory +# from: +FROM scratch + +# Substitute the image name that was downloaded +ADD alpine-minirootfs-20240329-armv7.tar.gz / + +# Install tools +RUN apk add build-base make cmake +RUN apk add git +RUN apk add vim + +RUN mkdir -p /home/dev +WORKDIR /home/dev + +# Get mimalloc +RUN git clone https://github.com/microsoft/mimalloc -b dev-slice +RUN mkdir -p mimalloc/out/release +RUN mkdir -p mimalloc/out/debug + +# Build mimalloc debug +WORKDIR /home/dev/mimalloc/out/debug +RUN cmake ../.. -DMI_DEBUG_FULL=ON +RUN make -j +RUN make test + +CMD ["/bin/sh"] diff --git a/docker/alpine/Dockerfile b/docker/alpine/Dockerfile new file mode 100644 index 00000000..b222b791 --- /dev/null +++ b/docker/alpine/Dockerfile @@ -0,0 +1,23 @@ +# alpine image +FROM alpine + +# Install tools +RUN apk add build-base make cmake +RUN apk add git +RUN apk add vim + +RUN mkdir -p /home/dev +WORKDIR /home/dev + +# Get mimalloc +RUN git clone https://github.com/microsoft/mimalloc -b dev-slice +RUN mkdir -p mimalloc/out/release +RUN mkdir -p mimalloc/out/debug + +# Build mimalloc debug +WORKDIR /home/dev/mimalloc/out/debug +RUN cmake ../.. -DMI_DEBUG_FULL=ON +RUN make -j +RUN make test + +CMD ["/bin/sh"] \ No newline at end of file diff --git a/docker/manylinux-x64/Dockerfile b/docker/manylinux-x64/Dockerfile index 566685d4..22d37e5a 100644 --- a/docker/manylinux-x64/Dockerfile +++ b/docker/manylinux-x64/Dockerfile @@ -18,5 +18,6 @@ RUN mkdir -p mimalloc/out/debug WORKDIR /home/dev/mimalloc/out/debug RUN cmake ../.. -DMI_DEBUG_FULL=ON RUN make -j +RUN make test CMD ["/bin/sh"] \ No newline at end of file From bd04cec1c45595cd048b434fa35258002952b4e5 Mon Sep 17 00:00:00 2001 From: Daan Date: Tue, 21 May 2024 11:57:52 -0700 Subject: [PATCH 5/5] roll back export ignore on the bin directory as it needed by vcpkg (et al) to build on Windows --- .gitattributes | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitattributes b/.gitattributes index f083b107..0332e031 100644 --- a/.gitattributes +++ b/.gitattributes @@ -10,4 +10,3 @@ *.dll binary *.lib binary *.exe binary -bin export-ignore