From 0107aa5e2227b952f70c8ead5c355c21ef955315 Mon Sep 17 00:00:00 2001 From: Adam Goode Date: Wed, 7 Feb 2024 21:51:48 -0500 Subject: [PATCH 1/6] Fix up some compiler warnings related to prototypes --- runtime/gc/gc_state.h | 2 +- runtime/gc/init.c | 2 +- runtime/gc/profiling.h | 2 +- runtime/gc/signals.c | 6 +++--- runtime/gc/signals.h | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/runtime/gc/gc_state.h b/runtime/gc/gc_state.h index 971410245c..2fdd0b8965 100644 --- a/runtime/gc/gc_state.h +++ b/runtime/gc/gc_state.h @@ -113,4 +113,4 @@ PRIVATE void GC_setGCSignalHandled (GC_state s, Bool_t b); PRIVATE Bool_t GC_getGCSignalPending (GC_state s); PRIVATE void GC_setGCSignalPending (GC_state s, Bool_t b); -PRIVATE GC_state MLton_gcState (); +PRIVATE GC_state MLton_gcState (void); diff --git a/runtime/gc/init.c b/runtime/gc/init.c index beceb854f9..97c19f6937 100644 --- a/runtime/gc/init.c +++ b/runtime/gc/init.c @@ -342,7 +342,7 @@ int GC_init (GC_state s, int argc, char **argv) { s->saveWorldStatus = true; initIntInf (s); - initSignalStack (s); + initSignalStack (); worldFile = NULL; unless (isAligned (s->sysvals.pageSize, CARD_SIZE)) diff --git a/runtime/gc/profiling.h b/runtime/gc/profiling.h index c6b7e95729..699bf91d5c 100644 --- a/runtime/gc/profiling.h +++ b/runtime/gc/profiling.h @@ -107,7 +107,7 @@ PRIVATE GC_profileData profileMalloc (GC_state s); PRIVATE void profileWrite (GC_state s, GC_profileData p, const char* fileName); PRIVATE void profileFree (GC_state s, GC_profileData p); -static void GC_handleSigProf (); +static void GC_handleSigProf (int signum); static void setProfTimer (suseconds_t usec); static void initProfilingTime (GC_state s); static void atexitForProfiling (void); diff --git a/runtime/gc/signals.c b/runtime/gc/signals.c index d7b3119430..224899ce90 100644 --- a/runtime/gc/signals.c +++ b/runtime/gc/signals.c @@ -9,12 +9,12 @@ #if not HAS_SIGALTSTACK -void initSignalStack () { +void initSignalStack (void) { } #else -void initSignalStack () { +void initSignalStack (void) { static stack_t altstack = { .ss_sp = NULL, .ss_size = 0, .ss_flags = 0 }; if (! altstack.ss_sp) { @@ -33,6 +33,6 @@ void initSignalStack () { #endif -void GC_initSignalStack () { +void GC_initSignalStack (void) { initSignalStack (); } diff --git a/runtime/gc/signals.h b/runtime/gc/signals.h index 0df6024c81..38312d8439 100644 --- a/runtime/gc/signals.h +++ b/runtime/gc/signals.h @@ -32,8 +32,8 @@ struct GC_signalsInfo { #if (defined (MLTON_GC_INTERNAL_FUNCS)) -static void initSignalStack (); +static void initSignalStack (void); #endif /* (defined (MLTON_GC_INTERNAL_FUNCS)) */ -void GC_initSignalStack (); +void GC_initSignalStack (void); From 659e0d2814a896042d53472c7d481e5268e0dee2 Mon Sep 17 00:00:00 2001 From: Adam Goode Date: Mon, 12 Feb 2024 11:22:49 -0500 Subject: [PATCH 2/6] Fix "unused function" warning in gc/profiling.h --- runtime/gc/profiling.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/runtime/gc/profiling.h b/runtime/gc/profiling.h index 699bf91d5c..0b4d6267bb 100644 --- a/runtime/gc/profiling.h +++ b/runtime/gc/profiling.h @@ -107,7 +107,10 @@ PRIVATE GC_profileData profileMalloc (GC_state s); PRIVATE void profileWrite (GC_state s, GC_profileData p, const char* fileName); PRIVATE void profileFree (GC_state s, GC_profileData p); +#if HAS_TIME_PROFILING static void GC_handleSigProf (int signum); +#endif + static void setProfTimer (suseconds_t usec); static void initProfilingTime (GC_state s); static void atexitForProfiling (void); From c1a710995d267cc415ae5e51cecf1dc7e0f5d4ac Mon Sep 17 00:00:00 2001 From: Adam Goode Date: Sat, 10 Feb 2024 21:22:57 -0500 Subject: [PATCH 3/6] Automatically detect various rounding modes As defined in the standard, each of these macros are only defined if the platform supports that rounding mode. https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/fenv.h.html --- runtime/basis/Real/IEEEReal-consts.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/runtime/basis/Real/IEEEReal-consts.c b/runtime/basis/Real/IEEEReal-consts.c index a4852a7bf0..db4675c080 100644 --- a/runtime/basis/Real/IEEEReal-consts.c +++ b/runtime/basis/Real/IEEEReal-consts.c @@ -1,7 +1,27 @@ #include "platform.h" +const C_Int_t IEEEReal_RoundingMode_FE_NOSUPPORT = FE_NOSUPPORT; + +#ifdef FE_TONEAREST const C_Int_t IEEEReal_RoundingMode_FE_TONEAREST = FE_TONEAREST; +#else +const C_Int_t IEEEReal_RoundingMode_FE_TONEAREST = FE_NOSUPPORT; +#endif + +#ifdef FE_DOWNWARD const C_Int_t IEEEReal_RoundingMode_FE_DOWNWARD = FE_DOWNWARD; -const C_Int_t IEEEReal_RoundingMode_FE_NOSUPPORT = FE_NOSUPPORT; +#else +const C_Int_t IEEEReal_RoundingMode_FE_DOWNWARD = FE_NOSUPPORT; +#endif + +#ifdef FE_UPWARD const C_Int_t IEEEReal_RoundingMode_FE_UPWARD = FE_UPWARD; +#else +const C_Int_t IEEEReal_RoundingMode_FE_UPWARD = FE_NOSUPPORT; +#endif + +#ifdef FE_TOWARDZERO const C_Int_t IEEEReal_RoundingMode_FE_TOWARDZERO = FE_TOWARDZERO; +#else +const C_Int_t IEEEReal_RoundingMode_FE_TOWARDZERO = FE_NOSUPPORT; +#endif From 4d05837c6e94bf5a42a842fcbbc5b44c9b06c9b0 Mon Sep 17 00:00:00 2001 From: Adam Goode Date: Sat, 10 Feb 2024 21:25:34 -0500 Subject: [PATCH 4/6] Store some target-specific variables in $TARGET/vars This will allow running mlton as a cross-compiler more easily, since the CC and GMP vars may be different between targets. --- Makefile | 8 ++++---- Makefile.binary | 7 +++---- bin/mlton-script | 29 ++++++++++++++++++++--------- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index cb2cde5fe3..4aae8d0dc8 100644 --- a/Makefile +++ b/Makefile @@ -154,15 +154,15 @@ runtime: $(MKDIR) "$(INC)/$$d"; \ $(CP) "$(SRC)/runtime/$$d/"*.h "$(INC)/$$d"; \ done + echo "EXE=\"$(EXE)\"" > "$(LIB)/targets/$(TARGET)/vars" + echo "CC=\"$(CC)\"" >> "$(LIB)/targets/$(TARGET)/vars" + echo "GMP_INC_DIR=\"$(WITH_GMP_INC_DIR)\"" >> "$(LIB)/targets/$(TARGET)/vars" + echo "GMP_LIB_DIR=\"$(WITH_GMP_LIB_DIR)\"" >> "$(LIB)/targets/$(TARGET)/vars" .PHONY: script script: $(SED) \ -e "s;^LIB_REL_BIN=.*;LIB_REL_BIN=\"$(LIB_REL_BIN)\";" \ - -e "s;^EXE=.*;EXE=\"$(EXE)\";" \ - -e "s;^CC=.*;CC=\"$(CC)\";" \ - -e "s;^GMP_INC_DIR=.*;GMP_INC_DIR=\"$(WITH_GMP_INC_DIR)\";" \ - -e "s;^GMP_LIB_DIR=.*;GMP_LIB_DIR=\"$(WITH_GMP_LIB_DIR)\";" \ -e 's/mlton-compile/$(MLTON_OUTPUT)/' \ -e "s;^ SMLNJ=.*; SMLNJ=\"$(SMLNJ)\";" \ < "$(SRC)/bin/mlton-script" > "$(BIN)/$(MLTON)" diff --git a/Makefile.binary b/Makefile.binary index 101f4323b3..e20ce5aaf2 100644 --- a/Makefile.binary +++ b/Makefile.binary @@ -65,14 +65,13 @@ install: .PHONY: update update: - $(CP) "$(SBIN)/mlton" "$(SBIN)/mlton.bak" + $(CP) "$(SLIB)/targets/self/vars" "$(SLIB)/targets/self/vars.bak" $(SED) \ -e "s;^CC=.*;CC=\"$(CC)\";" \ -e "s;^GMP_INC_DIR=.*;GMP_INC_DIR=$(if $(WITH_GMP_INC_DIR),\"$(WITH_GMP_INC_DIR)\");" \ -e "s;^GMP_LIB_DIR=.*;GMP_LIB_DIR=$(if $(WITH_GMP_LIB_DIR),\"$(WITH_GMP_LIB_DIR)\");" \ - < "$(SBIN)/mlton.bak" > "$(SBIN)/mlton" - chmod a+x "$(SBIN)/mlton" - $(RM) "$(SBIN)/mlton.bak" + < "$(SLIB)/targets/self/vars.bak" > "$(SLIB)/targets/self/vars" + $(RM) "$(SLIB)/targets/self/vars.bak" $(CP) "$(SLIB)/targets/self/constants" "$(SLIB)/targets/self/constants.bak" $(SED) \ -e "s;^default::pie=.*;default::pie=$(subst __pie__,0,$(shell echo "__pie__" | $(CC) -P -E -));" \ diff --git a/bin/mlton-script b/bin/mlton-script index 13657b6491..296a2867af 100644 --- a/bin/mlton-script +++ b/bin/mlton-script @@ -5,20 +5,31 @@ LIB_REL_BIN="../lib/mlton" -EXE= +set -e -CC="cc" +dir=$(dirname "$0") +lib=$(cd "$dir/$LIB_REL_BIN" && pwd) -# You may need to set 'GMP_INC_DIR' so the C compiler can find gmp.h. -GMP_INC_DIR= -# You may need to set 'GMP_LIB_DIR' so the C compiler can find libgmp. -GMP_LIB_DIR= +# Find if "-target" is set, to read cross-specific variables. +# Default to "self". +TARGET=self +prev_arg= +for arg in "$@" +do + if [ "$prev_arg" = "-target" ]; then + TARGET="$arg" + fi + prev_arg="$arg" +done +TARGET_VARS="$lib/targets/$TARGET/vars" +if [ ! -f "$TARGET_VARS" ]; then + echo "Unable to read $TARGET_VARS." >&2 + exit 1 +fi +. "$TARGET_VARS" -set -e -dir=$(dirname "$0") -lib=$(cd "$dir/$LIB_REL_BIN" && pwd) doitMLton () { From 21d94b88d9207c19546e84235f7e9eab47735250 Mon Sep 17 00:00:00 2001 From: Adam Goode Date: Mon, 12 Feb 2024 11:17:01 -0500 Subject: [PATCH 5/6] Add install-runtime to Makefile This makes it easier to build multiple per-target runtime targets and install them together. --- Makefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Makefile b/Makefile index 4aae8d0dc8..091cf4d15a 100644 --- a/Makefile +++ b/Makefile @@ -159,6 +159,11 @@ runtime: echo "GMP_INC_DIR=\"$(WITH_GMP_INC_DIR)\"" >> "$(LIB)/targets/$(TARGET)/vars" echo "GMP_LIB_DIR=\"$(WITH_GMP_LIB_DIR)\"" >> "$(LIB)/targets/$(TARGET)/vars" +.PHONY: install-runtime +install-runtime: + $(MKDIR) "$(TLIB)/targets/$(TARGET)" + $(CP) "$(LIB)/targets/$(TARGET)" "$(TLIB)/targets/" + .PHONY: script script: $(SED) \ From f39bec2b89263feb8b6747cadb35b083748f2508 Mon Sep 17 00:00:00 2001 From: Adam Goode Date: Mon, 12 Feb 2024 22:48:29 -0500 Subject: [PATCH 6/6] Always pass flags to mlton in bin/regression This makes any `-target` flag get passed to get the right OBJPTR_REP for cross regressions. --- bin/regression | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/regression b/bin/regression index 64b6d2702b..0270587043 100755 --- a/bin/regression +++ b/bin/regression @@ -88,12 +88,12 @@ compFail () { "$mlton" -verbose 1 || (echo 'no mlton present' && exitFail=true) echo "flags = ${flags[*]}" -TARGET_ARCH=$("$mlton" -show path-map | sed -n 's/TARGET_ARCH \(.*\)/\1/p') -TARGET_OS=$("$mlton" -show path-map | sed -n 's/TARGET_OS \(.*\)/\1/p') -OBJPTR_REP=$("$mlton" -show path-map | sed -n 's/OBJPTR_REP \(.*\)/\1/p') +TARGET_ARCH=$("$mlton" "${flags[@]}" -show path-map | sed -n 's/TARGET_ARCH \(.*\)/\1/p') +TARGET_OS=$("$mlton" "${flags[@]}" -show path-map | sed -n 's/TARGET_OS \(.*\)/\1/p') +OBJPTR_REP=$("$mlton" "${flags[@]}" -show path-map | sed -n 's/OBJPTR_REP \(.*\)/\1/p') ALIGN=$(echo "${flags[@]}" | sed -n 's/.*-align \(.\).*/\1/p') if [ -z "$ALIGN" ]; then - ALIGN=$("$mlton" -z 2>&1 | sed -n 's/.*-align {\(.\).*/\1/p') + ALIGN=$("$mlton" "${flags[@]}" -z 2>&1 | sed -n 's/.*-align {\(.\).*/\1/p') fi cd "$src/regression"