jart / cosmopolitan

build-once run-anywhere c library
ISC License
18.35k stars 630 forks source link

libgc `make check` only reports 10 of 11 passing #939

Closed jcalve closed 1 month ago

jcalve commented 1 year ago

I was trying to build: libgc from https://www.hboehm.info/gc/ but the compiler throws this error:

cosmocc: -fexceptions not supported

I tried to compile it as:

EXPORT CC=cosmocc
EXPORT CXX=cosmoc++
./configure --prefix=/opt/cosmos --disable-shared --enable-static && make
ahgamut commented 1 year ago

Ok, I checked the source of gc-8.2.4 and we can get it to build with Cosmopolitan Libc with the following steps

#if defined(__COSMOPOLITAN__)
#if defined(__x86_64__)
#define mach_type_known
#define X86_64
#define LINUX // optional?
#elif defined(__aarch64__)
#define mach_type_known
#define AARCH64
#define LINUX // optional?
#endif
#endif

with these above changes make runs successfully, and make check passes 10 of the 11 tests provided.

jart commented 1 year ago

Congratulations on getting libgc to mostly work. I didn't think we were there yet. C++ exceptions is a huge ask, a jupetarian ask. So I've changed the focus of this issue to be a small achievable victory if anyone wants to take it on. Let's get 100% of make check passing for libgc if possible!

jcalve commented 1 year ago

Thanks @ahgamut, that worked. @jart just to provide some more context, I was trying to see if it's possible to compile guile and libgc is one of the dependencies.

jart commented 1 month ago

We have c++ exception support now. Is this still an issue?

GabrielRavier commented 1 month ago

I've tried to build the latest version of libgc myself without disabling C++ and while I didn't encounter any issues with C++ exceptions the build failed fairly early here:

make[1]: Entering directory '/home/gravier/tmp/tmp-libboehm-gc-for-cosmo-test/bdwgc'
depbase=`echo os_dep.lo | sed 's|[^/]*$|.deps/&|;s|\.lo$||'`;\
/bin/sh ./libtool  --tag=CC   --mode=compile /home/gravier/src/libraries/programming/languages-implementations/standard-libraries/c/implementations/cosmopolitan-libc/built-cosmocc-toolchain/bin/cosmocc -DHAVE_CONFIG_H   -I./include -I./include      -fexceptions -Wall -Wextra -Wpedantic -Wno-long-long -g -O2 -fno-strict-aliasing -Wno-frame-address  -MT os_dep.lo -MD -MP -MF $depbase.Tpo -c -o os_dep.lo os_dep.c &&\
mv -f $depbase.Tpo $depbase.Plo
libtool: compile:  /home/gravier/src/libraries/programming/languages-implementations/standard-libraries/c/implementations/cosmopolitan-libc/built-cosmocc-toolchain/bin/cosmocc -DHAVE_CONFIG_H -I./include -I./include -fexceptions -Wall -Wextra -Wpedantic -Wno-long-long -g -O2 -fno-strict-aliasing -Wno-frame-address -MT os_dep.lo -MD -MP -MF .deps/os_dep.Tpo -c os_dep.c -o os_dep.o
os_dep.c: In function 'block_unmap_inner':
os_dep.c:2673:17: error: implicit declaration of function 'madvise'; did you mean 'raise'? [-Wimplicit-function-declaration]
 2673 |             if (madvise(start_addr, len, MADV_DONTNEED) == -1)
      |                 ^~~~~~~
      |                 raise
make[1]: *** [Makefile:1688: os_dep.lo] Error 1
make[1]: Leaving directory '/home/gravier/tmp/tmp-libboehm-gc-for-cosmo-test/bdwgc'
make: *** [Makefile:1954: all-recursive] Error 1

...it looks like libgc simply assumes madvise is always defined by sys/mman.h on Linux (this is pretty true on e.g. glibc - madvise is defined by default there) even though it's non-standard and cosmopolitan requires _COSMO_SOURCE or _GNU_SOURCE to be defined for it to be available.

ahgamut commented 1 month ago

with this patch I got libgc to build, and now the tests appear to pass on both x86_64 and aarch64

jart commented 1 month ago

Mission accomplished.

image