Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A handful of improvements related to cross compiling #562

Merged
merged 6 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions Makefile
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since CC and GMP_*_DIR variables are set via $(LIB)/targets/$(TARGET)/vars rather than directly in the mlton script, then a corresponding changes should be made to the Makefile.binary (https://github.com/MLton/mlton/blob/master/Makefile.binary#L69-L73), which allows for customizing those values when updating/installing a binary release. That can assume that TARGET is self.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I've updated Makefile.binary.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that is quite right. The Makefile.binary is copied into a binary release as Makefile to facilitate updating and installing a binary release. In particular, one uses the update target to adjust things like CC and GMP_LIB if they are different on the client machine than on the build machine. For example, one might do something like make CC=/path/to/clang update if the default cc isn't a suitable C compiler on the client machine.

So, I think the diff to Makefile.binary is more like:

 
 .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) \

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! Thank you. I had it 100% backwards. It should be good now.

Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,20 @@ 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: install-runtime
install-runtime:
$(MKDIR) "$(TLIB)/targets/$(TARGET)"
$(CP) "$(LIB)/targets/$(TARGET)" "$(TLIB)/targets/"

.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)"
Expand Down
7 changes: 3 additions & 4 deletions Makefile.binary
Original file line number Diff line number Diff line change
Expand Up @@ -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 -));" \
Expand Down
29 changes: 20 additions & 9 deletions bin/mlton-script
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
8 changes: 4 additions & 4 deletions bin/regression
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
22 changes: 21 additions & 1 deletion runtime/basis/Real/IEEEReal-consts.c
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion runtime/gc/gc_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 1 addition & 1 deletion runtime/gc/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
5 changes: 4 additions & 1 deletion runtime/gc/profiling.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

static void GC_handleSigProf ();
#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);
Expand Down
6 changes: 3 additions & 3 deletions runtime/gc/signals.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -33,6 +33,6 @@ void initSignalStack () {

#endif

void GC_initSignalStack () {
void GC_initSignalStack (void) {
initSignalStack ();
}
4 changes: 2 additions & 2 deletions runtime/gc/signals.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Loading