contextgarden / luametatex

Temporary/draft repository with luametatex
30 stars 6 forks source link

Fails to link on some processor arches (mipsel / m68k / powerpc / sh4) #8

Open hpreusse opened 11 months ago

hpreusse commented 11 months ago

Building (linking) the luametatex binary on some arches fails, as mimalloc uses symbols, which are only available in the atomic library. I run on Debian unstable and use gcc-13.

/usr/bin/cc -g -O2 -ffile-prefix-map=/root/luametatex-2.10.08+ds=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -Wl,-z,relro CMakeFiles/luametatex.dir/source/luametatex.c.o -o luametatex  libtex.a liblua.a libmp.a libluarest.a libluasocket.a libluaoptional.a libpplib.a libminiz.a libsoftposit.a -ldl libmimalloc.a -lpthread -lm
/usr/bin/ld: libmimalloc.a(stats.c.o): in function `mi_process_info':
./obj-m68k-linux-gnu/./source/libraries/mimalloc/src/stats.c:449:(.text+0x111a): undefined reference to `__atomic_load_8'
/usr/bin/ld: libmimalloc.a(stats.c.o): in function `mi_atomic_addi64_relaxed':
./obj-m68k-linux-gnu/./source/libraries/mimalloc/include/mimalloc/atomic.h:112:(.text+0x28): undefined reference to `__atomic_fetch_add_8'
/usr/bin/ld: libmimalloc.a(stats.c.o): in function `mi_atomic_maxi64_relaxed':
./obj-m68k-linux-gnu/./source/libraries/mimalloc/include/mimalloc/atomic.h:115:(.text+0x40): undefined reference to `__atomic_load_8'
/usr/bin/ld: ./obj-m68k-linux-gnu/./source/libraries/mimalloc/include/mimalloc/atomic.h:116:(.text+0x70): undefined reference to `__atomic_compare_exchange_8'
/usr/bin/ld: libmimalloc.a(stats.c.o): in function `mi_atomic_addi64_relaxed':
<snip>

After adding the atomc lib, linking works fine:

(m68k-sid)root@sid-amd64:~/luametatex-2.10.08+ds/obj-m68k-linux-gnu# /usr/bin/cc -g -O2 -ffile-prefix-map=/root/luametatex-2.10.08+ds=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -Wl,-z,relro CMakeFiles/luametatex.dir/source/luametatex.c.o -o luametatex  libtex.a liblua.a libmp.a libluarest.a libluasocket.a libluaoptional.a libpplib.a libminiz.a libsoftposit.a -ldl libmimalloc.a -lpthread -lm -latomic
(m68k-sid)root@sid-amd64:~/luametatex-2.10.08+ds/obj-m68k-linux-gnu# ldd luametatex
        libm.so.6 => /lib/m68k-linux-gnu/libm.so.6 (0x7ffb0000)
        libatomic.so.1 => /lib/m68k-linux-gnu/libatomic.so.1 (0x7ffa6000)
        libc.so.6 => /lib/m68k-linux-gnu/libc.so.6 (0x7fe20000)
        /lib/ld.so.1 (0x40000000)
(m68k-sid)root@sid-amd64:~/luametatex-2.10.08+ds/obj-m68k-linux-gnu# ls -l luametatex
-rwxr-xr-x 1 root root 12734240 Aug  2 09:45 luametatex

The full build logs are visible here.

barracuda156 commented 1 week ago

@hpreusse This looks like mimalloc fails to link, not luametatex, but anyway, you need to pass -latomic flag.

hpreusse commented 6 days ago

@hpreusse This looks like mimalloc fails to link, not luametatex, but anyway, you need to pass -latomic flag.

Yeah, looks like. So, this issue could have been solved by upgrading mimalloc (which was done in the last few month). I'll test if the patch I'm using is still needed (we link dynamically anyway).

barracuda156 commented 6 days ago

@hpreusse This looks like mimalloc fails to link, not luametatex, but anyway, you need to pass -latomic flag.

Yeah, looks like. So, this issue could have been solved by upgrading mimalloc (which was done in the last few month). I'll test if the patch I'm using is still needed (we link dynamically anyway).

Do they have a working test for it? We still add an option manually, though it could be outdated: https://github.com/macports/macports-ports/blob/f0387ce27bf3c62212c2bcabce601b1cb2a4897d/devel/mimalloc/Portfile#L52-L55

P. S. Out of curiosity, which hardware do you run m68k on? Pre-PowerPC Apple?