microsoft / mimalloc

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

2.1.4 Failure build for ppc64le error: ‘__builtin_thread_pointer’ is not supported on this target #883

Closed Vascom closed 1 month ago

Vascom commented 2 months ago

Can't build mimalloc 2.1.4 for Fedora GNU Linux ppc64le arch. GCC 14.0.1

error: ‘__builtin_thread_pointer’ is not supported on this target

How to fix it?

In file included from /builddir/build/BUILD/mimalloc-2.1.4/src/init.c:9:
In function ‘_mi_prim_thread_id’,
    inlined from ‘_mi_thread_id’ at /builddir/build/BUILD/mimalloc-2.1.4/src/init.c:145:10,
    inlined from ‘mi_heap_main_init.part.0’ at /builddir/build/BUILD/mimalloc-2.1.4/src/init.c:184:31:
/builddir/build/BUILD/mimalloc-2.1.4/include/mimalloc/prim.h:240:21: error: ‘__builtin_thread_pointer’ is not supported on this target
  240 |   return (uintptr_t)__builtin_thread_pointer();
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~
In function ‘_mi_prim_thread_id’,
    inlined from ‘_mi_thread_id’ at /builddir/build/BUILD/mimalloc-2.1.4/src/init.c:145:10:
/builddir/build/BUILD/mimalloc-2.1.4/include/mimalloc/prim.h:240:21: error: ‘__builtin_thread_pointer’ is not supported on this target
  240 |   return (uintptr_t)__builtin_thread_pointer();
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~
In function ‘_mi_prim_thread_id’,
    inlined from ‘_mi_thread_id’ at /builddir/build/BUILD/mimalloc-2.1.4/src/init.c:145:10,
    inlined from ‘_mi_is_main_thread’ at /builddir/build/BUILD/mimalloc-2.1.4/src/init.c:405:68:
/builddir/build/BUILD/mimalloc-2.1.4/include/mimalloc/prim.h:240:21: error: ‘__builtin_thread_pointer’ is not supported on this target
  240 |   return (uintptr_t)__builtin_thread_pointer();
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /builddir/build/BUILD/mimalloc-2.1.4/src/alloc.c:14:
In function ‘_mi_prim_thread_id’,
    inlined from ‘mi_free’ at /builddir/build/BUILD/mimalloc-2.1.4/src/free.c:143:26:
/builddir/build/BUILD/mimalloc-2.1.4/include/mimalloc/prim.h:240:21: error: ‘__builtin_thread_pointer’ is not supported on this target
  240 |   return (uintptr_t)__builtin_thread_pointer();
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~
In function ‘_mi_prim_thread_id’,
    inlined from ‘_mi_thread_id’ at /builddir/build/BUILD/mimalloc-2.1.4/src/init.c:145:10,
    inlined from ‘_mi_thread_done’ at /builddir/build/BUILD/mimalloc-2.1.4/src/init.c:452:26:
/builddir/build/BUILD/mimalloc-2.1.4/include/mimalloc/prim.h:240:21: error: ‘__builtin_thread_pointer’ is not supported on this target
  240 |   return (uintptr_t)__builtin_thread_pointer();
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~
In function ‘_mi_prim_thread_id’,
    inlined from ‘_mi_thread_id’ at /builddir/build/BUILD/mimalloc-2.1.4/src/init.c:145:10,
    inlined from ‘mi_process_init’ at /builddir/build/BUILD/mimalloc-2.1.4/src/init.c:578:3,
    inlined from ‘mi_process_init’ at /builddir/build/BUILD/mimalloc-2.1.4/src/init.c:570:6:
/builddir/build/BUILD/mimalloc-2.1.4/include/mimalloc/prim.h:240:21: error: ‘__builtin_thread_pointer’ is not supported on this target
  240 |   return (uintptr_t)__builtin_thread_pointer();
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~
In function ‘_mi_prim_thread_id’,
    inlined from ‘_mi_thread_id’ at /builddir/build/BUILD/mimalloc-2.1.4/src/init.c:145:10,
    inlined from ‘_mi_is_main_thread’ at /builddir/build/BUILD/mimalloc-2.1.4/src/init.c:405:68,
    inlined from ‘_mi_heap_init’ at /builddir/build/BUILD/mimalloc-2.1.4/src/init.c:293:7,
    inlined from ‘mi_thread_init’ at /builddir/build/BUILD/mimalloc-2.1.4/src/init.c:423:7:
/builddir/build/BUILD/mimalloc-2.1.4/include/mimalloc/prim.h:240:21: error: ‘__builtin_thread_pointer’ is not supported on this target
  240 |   return (uintptr_t)__builtin_thread_pointer();
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~

Full build log https://kojipkgs.fedoraproject.org//work/tasks/4072/116804072/build.log

cfvescovo commented 2 months ago

Same issue on x86_64 GNU/Linux (GCC). See https://github.com/purpleprotocol/mimalloc_rust/issues/111

Vascom commented 2 months ago

Same issue on x86_64 GNU/Linux (GCC). See purpleprotocol/mimalloc_rust#111

In my case other arches built successfully https://koji.fedoraproject.org/koji/taskinfo?taskID=116804025

cfvescovo commented 2 months ago

My build logs

> [build 6/7] RUN cargo build --locked --release:
12.70   cargo:warning=  240 |   return (uintptr_t)__builtin_thread_pointer();
12.70   cargo:warning=      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~
12.70 
12.70   --- stderr
12.70 
12.70 
12.70   error occurred: Command "cc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-I" "c_src/mimalloc/include" "-I" "c_src/mimalloc/src" "-Wall" "-Wextra" "-ftls-model=initial-exec" "-DMI_DEBUG=0" "-o" "/app/target/release/build/libmimalloc-sys-9bc557761968b710/out/98cfcaec7182b1d8-static.o" "-c" "c_src/mimalloc/src/static.c" with args cc did not execute successfully (status code exit status: 1).
cfvescovo commented 2 months ago

Will give more verbose output ASAP

cfvescovo commented 2 months ago

I got it to work by changing the distro I am using for my containers. I switched from debian bullseye to ubuntu latest (LTS). However, I did not investigate further.

daanx commented 2 months ago

ah, that is a shame. I wonder what goes wrong since the check:

// Do we have __builtin_thread_pointer? (do not make this a compound test as it fails on older gcc's, see issue #851)
#if defined(__has_builtin)
#if __has_builtin(__builtin_thread_pointer)
#define MI_HAS_BUILTIN_THREAD_POINTER  1
#endif
#elif defined(__GNUC__) && (__GNUC__ >= 7) && defined(__aarch64__)  // special case aarch64 for older gcc versions (issue #851)
#define MI_HAS_BUILTIN_THREAD_POINTER  1
#endif

seems to correctly test if __builtin_thread_pointer exists?

I think I will switch the default to prefer the TLS slot assembly after all and fall back to __builtin_thread_pointer otherwise.

daanx commented 2 months ago

I just pushed a potential fix to dev and dev-slice. If this fixes the build issues I will update the release soon. Please test if you can.

Vascom commented 2 months ago

This patch not fixed ppc64le build. Error is the same. I mean 146f9d2

daanx commented 2 months ago

This patch not fixed ppc64le build. Error is the same. I mean 146f9d2

Darn -- it looks like we cannot check for __builtin_thread_pointer reliably. Maybe we should only enable it for platforms that we explicitly tested for :-(

daanx commented 2 months ago

@vascom, I hope the latest commits fix the build issues now. fingers crossed. (At some point I would like to figure out though why the is_builtin tests are positive even though the builtin is not actually supported? )

hpreusse commented 1 month ago

Same here for ppc64el, hppa, ia64, m68k, powerpc, ppc64, sparc64. See build server of Debian. I'll try your commit ASAP.

hpreusse commented 1 month ago

I can confirm that adding the two commits https://github.com/microsoft/mimalloc/commit/cc3c14f2ed374f908e60a3bf29c1dff84fc8cfc2 and https://github.com/microsoft/mimalloc/commit/146f9d2333bc0aeed1593dc659b17e65b38a33e7 solved the build issue for me.