microsoft / mimalloc

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

Fails to build on mipsel / m68k / powerpc / sh4 #798

Open hpreusse opened 11 months ago

hpreusse commented 11 months ago

Not sure, if it even was intended to run on these arches. I use the library, b/c it is pulled in by luametatex. I notice that linking of the libs fails on a few CPU architectures (mipsel / m68k / powerpc / sh4) when linking:

./obj-mipsel-linux-gnu/./source/libraries/mimalloc/src/arena.c:477:(.text+0x1440): undefined reference to `__atomic_load_8'
/usr/bin/ld: ./obj-mipsel-linux-gnu/./source/libraries/mimalloc/src/arena.c:479:(.text+0x1480): undefined reference to `__atomic_fetch_add_8'
/usr/bin/ld: ./obj-mipsel-linux-gnu/./source/libraries/mimalloc/src/arena.c:482:(.text+0x14e4): undefined reference to `__atomic_store_8'
/usr/bin/ld: ./obj-mipsel-linux-gnu/./source/libraries/mimalloc/src/arena.c:471:(.text+0x1370): undefined reference to `__atomic_load_8'
/usr/bin/ld: ./obj-mipsel-linux-gnu/./source/libraries/mimalloc/src/arena.c:479:(.text+0x1458): undefined reference to `__atomic_fetch_add_8'
/usr/bin/ld: ./obj-mipsel-linux-gnu/./source/libraries/mimalloc/src/arena.c:482:(.text+0x14d8): undefined reference to `__atomic_store_8'
collect2: error: ld returned 1 exit status

There a lot more error messages like these and at least they are common to all these CPU arches. I build (and link) using the gcc compiler suite and as far as I found out on these arches the library libatomic1 needs to linked. Maybe I can patch that in my Makefile. Hmm, the CMakeLists.txt says:

option(MI_USE_LIBATOMIC "Explicitly link with -latomic (on older systems) (deprecated and detected automatically)" OFF)

..but that doesn't seem to work reliably. At least in the Debian package they do something like:

LIBATOMIC=OFF
ifneq (,$(filter $(DEB_HOST_ARCH), armel m68k mips mipsel powerpc powerpcspe sh4))
  LIBATOMIC=ON
endif

configure (...) -DMI_USE_LIBATOMIC=$(LIBATOMIC)
hpreusse commented 11 months ago

OK, I'm able to reproduce the issue inside an m68k emulated by qemu. I use Debian and gcc-13. I installed the packages needed to build the Debian package, then downloaded the 2.1.2 tar ball (and "git clone" as 2nd try). The build fails at the end:

[ 80%] Linking C static library libmimalloc.a
[ 80%] Built target mimalloc-static
[ 82%] Building C object CMakeFiles/mimalloc-obj.dir/src/static.c.o
[ 82%] Built target mimalloc-obj
[ 85%] Generating mimalloc.o
[ 85%] Built target mimalloc-obj-target
[ 87%] Building C object CMakeFiles/mimalloc-test-api.dir/test/test-api.c.o
[ 90%] Linking C executable mimalloc-test-api
/usr/bin/ld: libmimalloc.so.2.1: undefined reference to `__atomic_load_8'
/usr/bin/ld: libmimalloc.so.2.1: undefined reference to `__atomic_store_8'
/usr/bin/ld: libmimalloc.so.2.1: undefined reference to `__atomic_fetch_add_8'
/usr/bin/ld: libmimalloc.so.2.1: undefined reference to `__atomic_compare_exchange_8'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/mimalloc-test-api.dir/build.make:100: mimalloc-test-api] Error 1
make[1]: *** [CMakeFiles/Makefile2:199: CMakeFiles/mimalloc-test-api.dir/all] Error 2
make: *** [Makefile:146: all] Error 2

I could upload the full build log, but I guess it is not of any help.