Skip to content

Commit

Permalink
Initial support of Cosmo target (Cosmopolitan Libc)
Browse files Browse the repository at this point in the history
Issue #666 (bdwgc).

* include/private/gcconfig.h [__COSMOPOLITAN__] (COSMO): New macro.
* include/private/gcconfig.h [__aarch64__ && !ANY_BSD && !DARWIN
&& !LINUX && !KOS && !QNX] (NOSYS): Do not define if COSMO.
* include/private/gcconfig.h [__aarch64__ && COSMO] (AARCH64,
mach_type_known): Define macro.
* include/private/gcconfig.h [(__x86_64 || __x86_64__ || __amd64__
|| __X86_64__) && COSMO] (X86_64, mach_type_known): Likewise.
* include/private/gcconfig.h [COSMO] (OS_TYPE, LINUX_STACKBOTTOM,
DATASTART, DATAEND, USE_MMAP_ANON): Likewise.
* include/private/gcconfig.h [COSMO] (UNIX_LIKE): Likewise.
* include/private/gcconfig.h [COSMO] (__data_start, _end): Declare
global variable.
* tests/gctest.c [!BIG && COSMO && THREADS] (BIG): Define to 500.

Co-authored-by: Ivan Maidanski <[email protected]>
  • Loading branch information
ahgamut and ivmai committed Oct 10, 2024
1 parent ec79784 commit 4920ad4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
42 changes: 31 additions & 11 deletions include/private/gcconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ EXTERN_C_BEGIN
# define ANY_BSD
#endif

#if defined(__COSMOPOLITAN__)
# define COSMO
#endif

#if defined(__EMBOX__)
# define EMBOX
#endif
Expand Down Expand Up @@ -154,8 +158,8 @@ EXTERN_C_BEGIN
/* Here we will rely upon arch-specific defines. */
# endif
#endif
#if defined(__aarch64__) && !defined(ANY_BSD) && !defined(DARWIN) \
&& !defined(LINUX) && !defined(KOS) && !defined(QNX) \
#if defined(__aarch64__) && !defined(ANY_BSD) && !defined(COSMO) \
&& !defined(DARWIN) && !defined(LINUX) && !defined(KOS) && !defined(QNX) \
&& !defined(NN_BUILD_TARGET_PLATFORM_NX) && !defined(_WIN32)
# define AARCH64
# define NOSYS
Expand Down Expand Up @@ -480,9 +484,9 @@ EXTERN_C_BEGIN
# define mach_type_known
#endif

#if defined(__aarch64__) \
&& (defined(ANY_BSD) || defined(DARWIN) || defined(LINUX) || defined(KOS) \
|| defined(QNX))
#if defined(__aarch64__) \
&& (defined(ANY_BSD) || defined(COSMO) || defined(DARWIN) \
|| defined(LINUX) || defined(KOS) || defined(QNX))
# define AARCH64
# define mach_type_known
#elif defined(__arc__) && defined(LINUX)
Expand Down Expand Up @@ -562,8 +566,8 @@ EXTERN_C_BEGIN
# define mach_type_known
#elif (defined(__x86_64) || defined(__x86_64__) || defined(__amd64__) \
|| defined(__X86_64__)) \
&& (defined(ANY_BSD) || defined(DARWIN) || defined(LINUX) \
|| defined(QNX))
&& (defined(ANY_BSD) || defined(COSMO) || defined(DARWIN) \
|| defined(LINUX) || defined(QNX))
# define X86_64
# define mach_type_known
#endif
Expand Down Expand Up @@ -800,6 +804,16 @@ EXTERN_C_BEGIN
# endif
#endif /* CYGWIN32 */

#ifdef COSMO
# define OS_TYPE "COSMO"
# define LINUX_STACKBOTTOM
extern int __data_start[] __attribute__((__weak__));
# define DATASTART ((ptr_t)__data_start)
extern int _end[];
# define DATAEND ((ptr_t)_end)
# define USE_MMAP_ANON
#endif /* COSMO */

#ifdef DARWIN
# define OS_TYPE "DARWIN"
# define DYNAMIC_LOADING
Expand Down Expand Up @@ -1982,6 +1996,9 @@ extern int __data_start[] __attribute__((__weak__));
# define DATASTART ((ptr_t)__data_start)
# endif
# endif
# ifdef COSMO
/* Empty. */
# endif
# ifdef DARWIN
/* OS X, iOS, visionOS */
# define DARWIN_DONT_PARSE_STACK 1
Expand Down Expand Up @@ -2216,6 +2233,9 @@ EXTERN_C_BEGIN
# define SOFT_VDB
# endif
# endif
# ifdef COSMO
/* Empty. */
# endif
# ifdef DARWIN
# define DARWIN_DONT_PARSE_STACK 1
# define STACKBOTTOM ((ptr_t)0x7fff5fc00000)
Expand Down Expand Up @@ -2604,10 +2624,10 @@ EXTERN_C_END
EXTERN_C_BEGIN
#endif /* GC_OPENBSD_THREADS */

#if defined(AIX) || defined(ANY_BSD) || defined(BSD) || defined(DARWIN) \
|| defined(DGUX) || defined(HAIKU) || defined(HPUX) || defined(HURD) \
|| defined(IRIX5) || defined(LINUX) || defined(OSF1) || defined(QNX) \
|| defined(SVR4)
#if defined(AIX) || defined(ANY_BSD) || defined(BSD) || defined(COSMO) \
|| defined(DARWIN) || defined(DGUX) || defined(HAIKU) || defined(HPUX) \
|| defined(HURD) || defined(IRIX5) || defined(LINUX) || defined(OSF1) \
|| defined(QNX) || defined(SVR4)
# define UNIX_LIKE /* Basic Unix-like system calls work. */
#endif

Expand Down
3 changes: 2 additions & 1 deletion tests/gctest.c
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,8 @@ reverse_test_inner(void *data)
# else
# define BIG 1000
# endif
# elif defined(MSWINCE) || defined(EMBOX) || defined(RTEMS)
# elif defined(MSWINCE) || defined(EMBOX) || defined(RTEMS) \
|| (defined(COSMO) && defined(THREADS))
/* WinCE only allows 64 KB stacks. */
# define BIG 500
# elif defined(EMSCRIPTEN) || defined(OSF1)
Expand Down

0 comments on commit 4920ad4

Please sign in to comment.