Skip to content

Commit dbc2d36

Browse files
authored
Enable mono cross-build on SunOS-like OS (#37560)
1 parent 846ff25 commit dbc2d36

File tree

7 files changed

+127
-12
lines changed

7 files changed

+127
-12
lines changed

src/mono/Directory.Build.props

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
<!-- Set up common target properties that we use to conditionally include sources -->
3535
<PropertyGroup>
3636
<TargetsFreeBSD Condition="'$(TargetOS)' == 'FreeBSD'">true</TargetsFreeBSD>
37+
<TargetsIllumos Condition="'$(TargetOS)' == 'illumos'">true</TargetsIllumos>
38+
<TargetsSolaris Condition="'$(TargetOS)' == 'Solaris'">true</TargetsSolaris>
3739
<TargetsLinux Condition="'$(TargetOS)' == 'Linux' or '$(TargetOS)' == 'Android'">true</TargetsLinux>
3840
<TargetsNetBSD Condition="'$(TargetOS)' == 'NetBSD'">true</TargetsNetBSD>
3941
<TargetsOSX Condition="'$(TargetOS)' == 'OSX'">true</TargetsOSX>
@@ -44,7 +46,7 @@
4446
<TargetsAndroid Condition="'$(TargetOS)' == 'Android'">true</TargetsAndroid>
4547
<TargetsBrowser Condition="'$(TargetOS)' == 'Browser'">true</TargetsBrowser>
4648
<TargetsWindows Condition="'$(TargetOS)' == 'Windows_NT'">true</TargetsWindows>
47-
<TargetsUnix Condition="'$(TargetsFreeBSD)' == 'true' or '$(TargetsLinux)' == 'true' or '$(TargetsNetBSD)' == 'true' or '$(TargetsOSX)' == 'true' or '$(TargetstvOS)' == 'true' or '$(TargetsiOS)' == 'true' or '$(TargetsAndroid)' == 'true' or '$(TargetsBrowser)' == 'true'">true</TargetsUnix>
49+
<TargetsUnix Condition="'$(TargetsFreeBSD)' == 'true' or '$(TargetsIllumos)' == 'true' or '$(TargetsSolaris)' == 'true' or '$(TargetsLinux)' == 'true' or '$(TargetsNetBSD)' == 'true' or '$(TargetsOSX)' == 'true' or '$(TargetstvOS)' == 'true' or '$(TargetsiOS)' == 'true' or '$(TargetsAndroid)' == 'true' or '$(TargetsBrowser)' == 'true'">true</TargetsUnix>
4850
</PropertyGroup>
4951

5052
<PropertyGroup>

src/mono/configure.ac

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ platform_ios=no
139139
host_darwin=no
140140
host_linux=no
141141
build_darwin=no
142+
host_sunos=no
142143

143144
case "$host" in
144145
wasm32*)
@@ -397,13 +398,14 @@ case "$host" in
397398
use_sigposix=yes
398399
;;
399400
*-*-solaris*)
400-
CPPFLAGS="$CPPFLAGS -DGC_SOLARIS_THREADS -DGC_SOLARIS_PTHREADS -D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS -DUSE_MMAP -DUSE_MUNMAP -DHOST_SOLARIS"
401+
CPPFLAGS="$CPPFLAGS -DGC_SOLARIS_THREADS -DGC_SOLARIS_PTHREADS -D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS -DUSE_MMAP -DUSE_MUNMAP -DHOST_SOLARIS -D__EXTENSIONS__ -D_XPG4_2"
401402
need_link_unlink=yes
402403
libmono_cflags="-D_REENTRANT"
403404
libgc_threads=pthreads
404405
has_dtrace=yes
405406
use_sigposix=yes
406407
enable_solaris_tar_check=yes
408+
host_sunos=yes
407409
;;
408410
*-*-darwin*)
409411
parallel_mark="Disabled_Currently_Hangs_On_MacOSX"
@@ -2274,14 +2276,13 @@ if test x$host_win32 = xno; then
22742276
AC_CHECK_FUNCS(getresuid)
22752277
AC_CHECK_FUNCS(setresuid)
22762278
AC_CHECK_FUNCS(kqueue)
2277-
# IBM provides a compatibility library for i offering this function.
2279+
# IBM provides a compatibility library for offering this function.
22782280
# BSDs and others, have execinfo in base or packages.
22792281
AC_SEARCH_LIBS(backtrace_symbols, execinfo util)
22802282
# Two-step so it sets it in config.h
22812283
AC_CHECK_FUNCS(backtrace_symbols)
22822284
AC_CHECK_FUNCS(mkstemp)
22832285
AC_CHECK_FUNCS(mmap)
2284-
AC_CHECK_FUNCS(madvise)
22852286
AC_CHECK_FUNCS(getrusage)
22862287
AC_CHECK_FUNCS(getpriority)
22872288
AC_CHECK_FUNCS(setpriority)
@@ -2747,7 +2748,7 @@ if test x$host_win32 = xno; then
27472748
dnl *** Checks for libxnet ***
27482749
dnl *****************************
27492750
case "${host}" in
2750-
*solaris* )
2751+
*solaris*)
27512752
AC_MSG_CHECKING(for Solaris XPG4 support)
27522753
if test -f /usr/lib/libxnet.so; then
27532754
CPPFLAGS="$CPPFLAGS -D_XOPEN_SOURCE=500"
@@ -3215,7 +3216,6 @@ if test x$host_win32 = xno; then
32153216
AC_CHECK_FUNCS(remap_file_pages)
32163217
AC_CHECK_FUNCS(posix_fadvise)
32173218
AC_CHECK_FUNCS(posix_fallocate)
3218-
AC_CHECK_FUNCS(posix_madvise)
32193219
AC_CHECK_FUNCS(vsnprintf)
32203220
AC_CHECK_FUNCS(sendfile)
32213221
AC_CHECK_FUNCS(gethostid sethostid)
@@ -3921,6 +3921,19 @@ if test x$host_win32 = xno; then
39213921

39223922
AC_CHECK_DECL(IN_EXCL_UNLINK, [AC_DEFINE(HAVE_IN_EXCL_UNLINK, 1, [IN_EXCL_UNLINK])], [], [[#include <sys/inotify.h>]])
39233923

3924+
if test x$host_sunos = xyes; then
3925+
# set -Werror=strict-prototypes, to match the flags used during the compilation.
3926+
ORIG_CFLAGS="$CFLAGS"
3927+
CFLAGS="$CFLAGS -Werror=strict-prototypes"
3928+
fi
3929+
3930+
AC_CHECK_FUNCS(madvise)
3931+
AC_CHECK_FUNCS(posix_madvise)
3932+
3933+
if test x$host_sunos = xyes; then
3934+
CFLAGS="$ORIG_CFLAGS"
3935+
fi
3936+
39243937
# *** End of Mono.Native checks ***
39253938
else
39263939
AM_CONDITIONAL(ENABLE_GSS, false)
@@ -6836,9 +6849,9 @@ if test x$with_core = xonly; then
68366849
ICU_CFLAGS="$CPPFLAGS -DPALEXPORT="" -DOSX_ICU_LIBRARY_PATH=AS_ESCAPE(\"/usr/lib/libicucore.dylib\", '\"') -DTARGET_UNIX -DU_DISABLE_RENAMING -Wno-reserved-id-macro -Wno-documentation -Wno-documentation-unknown-command -Wno-switch-enum -Wno-covered-switch-default -Wno-covered-switch-default -Wno-extra-semi-stmt -Wno-unknown-warning-option -Wno-deprecated-declarations"
68376850
fi
68386851
CPPFLAGS=$ORIG_CPPFLAGS
6839-
elif test x$platform_android = xyes; then
6852+
elif test x$platform_android = xyes; then
68406853
ICU_CFLAGS="-DPALEXPORT="" -DHAVE_UDAT_STANDALONE_SHORTER_WEEKDAYS -DHAVE_SET_MAX_VARIABLE -DTARGET_UNIX -DTARGET_ANDROID -Wno-reserved-id-macro -Wno-documentation -Wno-documentation-unknown-command -Wno-switch-enum -Wno-covered-switch-default -Wno-covered-switch-default -Wno-extra-semi-stmt -Wno-unknown-warning-option"
6841-
have_sys_icu=yes
6854+
have_sys_icu=yes
68426855
elif test x$host_linux = xyes; then
68436856
AC_CHECK_LIB(icuuc, main, LIBS=$LIBS,
68446857
[AC_MSG_ERROR([Cannot find libicuuc, try installing libicu-dev (or the appropriate package for your platform).])])
@@ -6848,14 +6861,17 @@ if test x$with_core = xonly; then
68486861
if test x$have_sys_icu = xyes; then
68496862
ICU_CFLAGS="-DPALEXPORT="" -DTARGET_UNIX -Wno-reserved-id-macro -Wno-documentation -Wno-documentation-unknown-command -Wno-switch-enum -Wno-covered-switch-default -Wno-covered-switch-default -Wno-extra-semi-stmt -Wno-unknown-warning-option"
68506863
fi
6864+
elif test x$host_sunos = xyes; then
6865+
ICU_CFLAGS="-DPALEXPORT="" -DTARGET_UNIX -Wno-reserved-id-macro -Wno-documentation -Wno-documentation-unknown-command -Wno-switch-enum -Wno-covered-switch-default -Wno-extra-semi-stmt -Wno-unknown-warning-option"
6866+
have_sys_icu=yes
68516867
else
68526868
GLOBALIZATION_SHIM_DEFINES="-DNO_GLOBALIZATION_SHIM"
68536869
fi
68546870
AC_SUBST(ICU_CFLAGS)
6855-
else
6871+
else
68566872
GLOBALIZATION_SHIM_DEFINES="-DNO_GLOBALIZATION_SHIM"
68576873
fi
6858-
else
6874+
else
68596875
GLOBALIZATION_SHIM_DEFINES="-DNO_GLOBALIZATION_SHIM"
68606876
fi
68616877

src/mono/mono.proj

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
<BuildMonoAOTCrossCompiler Condition="'$(TargetsBrowser)' == 'true'">true</BuildMonoAOTCrossCompiler>
3232
<CrossConfigH Condition="'$(BuildMonoAOTCrossCompiler)' == 'true'">$(MonoObjDir)cross\config.h</CrossConfigH>
3333
<MonoBundleLLVMOptimizer Condition="'$(MonoEnableLLVM)' == 'true'">true</MonoBundleLLVMOptimizer>
34+
<MonoCCompiler>$(Compiler)</MonoCCompiler>
35+
<MonoCCompiler Condition="'$(MonoCCompiler)' == ''">clang</MonoCCompiler>
36+
<!-- when we use runtime/build.sh -gcc, it is passed to eng/build.sh which sets the raw value to $(Compiler); strip the leading hyphens. -->
37+
<MonoCCompiler Condition="$(MonoCCompiler.StartsWith('-'))">$(MonoCCompiler.TrimStart('-'))</MonoCCompiler>
38+
<MonoCxxCompiler Condition="'$(MonoCCompiler)' == 'clang'">clang++</MonoCxxCompiler>
39+
<MonoCxxCompiler Condition="'$(MonoCCompiler)' == 'gcc'">g++</MonoCxxCompiler>
3440
</PropertyGroup>
3541

3642
<!-- OSX/iOS/tvOS/Android/Linux Mono runtime build -->
@@ -580,6 +586,33 @@
580586
<_MonoSTRIPOption>STRIP="$(_MonoTuple)-strip"</_MonoSTRIPOption>
581587
</PropertyGroup>
582588

589+
<!-- x64 illumos cross build options -->
590+
<PropertyGroup Condition="'$(TargetsIllumos)' == 'true' and '$(MonoCrossDir)' != ''">
591+
<_MonoTuple>x86_64-sun-solaris2.10</_MonoTuple>
592+
<_ToolPrefix>$(MonoCrossDir)/bin/x86_64-illumos</_ToolPrefix>
593+
594+
<_MonoRANLIBOption>RANLIB="$(_ToolPrefix)-ranlib"</_MonoRANLIBOption>
595+
<_MonoAROption>AR="$(_ToolPrefix)-ar"</_MonoAROption>
596+
<_MonoASOption>AS="$(_ToolPrefix)-as"</_MonoASOption>
597+
<_MonoLDOption>LD="$(_ToolPrefix)-ld"</_MonoLDOption>
598+
<_MonoSTRIPOption>STRIP="$(_ToolPrefix)-strip"</_MonoSTRIPOption>
599+
600+
<_MonoCCOption>CC="$(_ToolPrefix)-$(MonoCCompiler)"</_MonoCCOption>
601+
<_MonoCXXOption>CXX="$(_ToolPrefix)-$(MonoCxxCompiler)"</_MonoCXXOption>
602+
</PropertyGroup>
603+
604+
<ItemGroup Condition="'$(TargetsIllumos)' == 'true' and '$(MonoCrossDir)' != ''">
605+
<_MonoConfigureParams Include="--host=$(_MonoTuple)" />
606+
<_MonoConfigureParams Include="--target=$(_MonoTuple)" />
607+
608+
<_MonoCFLAGS Include="--sysroot=$(MonoCrossDir)" />
609+
<_MonoCFLAGS Include="-I$(MonoCrossDir)/include" />
610+
<_MonoCXXFLAGS Include="--sysroot=$(MonoCrossDir)" />
611+
<_MonoLDFLAGS Include="--sysroot=$(MonoCrossDir)" />
612+
<_MonoCCLDFLAGS Include="-XCClinker" />
613+
<_MonoConfigureParams Include="--with-tls=pthread" />
614+
</ItemGroup>
615+
583616
<Error Condition="'$(TargetsBrowser)' == 'true' and '$(EMSDK_PATH)' == ''" Text="The EMSDK_PATH environment variable should be set pointing to the emscripten SDK root dir."/>
584617

585618
<!-- WASM specific options -->
@@ -675,7 +708,7 @@
675708
<_MonoCCLDFLAGSOption Condition="@(_MonoCCLDFLAGS->Count()) &gt; 0">CCLDFLAGS="@(_MonoCCLDFLAGS, ' ')"</_MonoCCLDFLAGSOption>
676709

677710
<_MonoConfigureOptions>@(_MonoConfigureParams, ' ') @(_MonoAC_VARS, ' ') $(_MonoCFLAGSOption) $(_MonoCXXFLAGSOption) $(_MonoCPPFLAGSOption) $(_MonoCXXCPPFLAGSOption) $(_MonoLDFLAGSOption) $(_MonoCCLDFLAGSOption) $(_MonoCCOption) $(_MonoCXXOption) $(_MonoAROption) $(_MonoASOption) $(_MonoCPPOption) $(_MonoCXXCPPOption) $(_MonoDLLTOOLOption) $(_MonoLDOption) $(_MonoOBJDUMPOption) $(_MonoRANLIBOption) $(_MonoCMAKEOption) $(_MonoSTRIPOption)</_MonoConfigureOptions>
678-
<_MonoConfigureCommand Condition="'$(_MonoCCOption)' == '' and '$(_MonoCXXOption)' == ''">bash -c 'source $(RepositoryEngineeringDir)native/init-compiler.sh $(Platform) clang &amp;&amp; $(MonoProjectRoot)configure $(_MonoConfigureOptions)'</_MonoConfigureCommand>
711+
<_MonoConfigureCommand Condition="'$(_MonoCCOption)' == '' and '$(_MonoCXXOption)' == ''">bash -c 'source $(RepositoryEngineeringDir)native/init-compiler.sh $(Platform) $(MonoCCompiler) &amp;&amp; $(MonoProjectRoot)configure $(_MonoConfigureOptions)'</_MonoConfigureCommand>
679712
<_MonoConfigureCommand Condition="'$(_MonoCCOption)' != '' and '$(_MonoCXXOption)' != ''">$(MonoProjectRoot)configure $(_MonoConfigureOptions)</_MonoConfigureCommand>
680713
<_MonoConfigureCommand Condition="'$(TargetsBrowser)' == 'true'">bash -c 'source $(EMSDK_PATH)/emsdk_env.sh &amp;&amp; emconfigure $(MonoProjectRoot)configure $(_MonoConfigureOptions)'</_MonoConfigureCommand>
681714
</PropertyGroup>

src/mono/mono/metadata/threads.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,15 @@ mono_thread_internal_set_priority (MonoInternalThread *internal, MonoThreadPrior
805805
break;
806806
#ifdef SCHED_BATCH
807807
case SCHED_BATCH:
808+
#endif
809+
#ifdef SCHED_IA
810+
case SCHED_IA:
811+
#endif
812+
#ifdef SCHED_FSS
813+
case SCHED_FSS:
814+
#endif
815+
#ifdef SCHED_FX
816+
case SCHED_FX:
808817
#endif
809818
case SCHED_OTHER:
810819
param.sched_priority = 0;

src/mono/mono/mini/mini-amd64.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ typedef struct {
390390

391391
#endif /* !HOST_WIN32 */
392392

393-
#if !defined(__linux__)
393+
#if !defined(__linux__) && !defined(__sun)
394394
#define MONO_ARCH_NOMAP32BIT 1
395395
#endif
396396

src/mono/mono/utils/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ monoutils_sources = \
186186
mono-threads-haiku.c \
187187
mono-threads-aix.c \
188188
mono-threads-wasm.c \
189+
mono-threads-sunos.c \
189190
mono-threads.h \
190191
mono-threads-debug.h \
191192
mono-threads-api.h \
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* \file
3+
*/
4+
5+
#include <config.h>
6+
7+
#if defined(__sun__)
8+
9+
#include <mono/utils/mono-threads.h>
10+
#include <pthread.h>
11+
#include <sys/syscall.h>
12+
13+
void
14+
mono_threads_platform_get_stack_bounds (guint8 **staddr, size_t *stsize)
15+
{
16+
pthread_attr_t attr;
17+
gint res;
18+
19+
*staddr = NULL;
20+
*stsize = (size_t)-1;
21+
22+
res = pthread_attr_init (&attr);
23+
if (G_UNLIKELY (res != 0))
24+
g_error ("%s: pthread_attr_init failed with \"%s\" (%d)", __func__, g_strerror (res), res);
25+
26+
res = pthread_attr_get_np (pthread_self (), &attr);
27+
if (G_UNLIKELY (res != 0))
28+
g_error ("%s: pthread_getattr_np failed with \"%s\" (%d)", __func__, g_strerror (res), res);
29+
30+
res = pthread_attr_getstack (&attr, (void**)staddr, stsize);
31+
if (G_UNLIKELY (res != 0))
32+
g_error ("%s: pthread_attr_getstack failed with \"%s\" (%d)", __func__, g_strerror (res), res);
33+
34+
res = pthread_attr_destroy (&attr);
35+
if (G_UNLIKELY (res != 0))
36+
g_error ("%s: pthread_attr_destroy failed with \"%s\" (%d)", __func__, g_strerror (res), res);
37+
38+
}
39+
40+
guint64
41+
mono_native_thread_os_id_get (void)
42+
{
43+
// TODO: investigate whether to use light weight process lwp ID of keep pthread_self()
44+
// after the libraries and SDK ports are completed on illumos and/or Solaris platform.
45+
return (guint64)pthread_self ();
46+
}
47+
48+
#else
49+
50+
#include <mono/utils/mono-compiler.h>
51+
52+
MONO_EMPTY_SOURCE_FILE (mono_threads_sunos);
53+
54+
#endif

0 commit comments

Comments
 (0)