From 1469bacfaf7157e92009ea5c1ec4ca9e17126901 Mon Sep 17 00:00:00 2001 From: Kien Nguyen Date: Sun, 11 Aug 2024 03:37:59 -0700 Subject: [PATCH 2/6] mingw64: support mingw64 --- code/comm.gmk | 18 ++++++++++------ code/global.c | 2 +- code/mingw.gmk | 33 +++++++++++++++-------------- code/mps.c | 2 +- code/mps.h | 14 ++----------- code/mpstd.h | 16 ++++++++++++++ code/scan.c | 1 - code/ss.c | 7 +++++++ code/testlib.h | 4 ++-- code/w3i3gc.gmk | 23 --------------------- code/w3i6gc.gmk | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ configure | 55 +++++++++++++++++++++++++++++++++++-------------- configure.ac | 27 ++++++++++++++++++++++-- 13 files changed, 176 insertions(+), 80 deletions(-) create mode 100644 code/w3i6gc.gmk diff --git a/code/comm.gmk b/code/comm.gmk index bcb19f1..3efa66a 100644 --- a/code/comm.gmk +++ b/code/comm.gmk @@ -161,11 +161,15 @@ POOLN = pooln.c MV2 = poolmv2.c MVFF = poolmvff.c TESTLIB = testlib.c -ifneq ($(PFM),w3i3gc) -TESTTHR = testthrix.c -else + +ifeq ($(PFM),w3i3gc) +TESTTHR = testthrw3.c +else ifeq ($(PFM),w3i6gc) TESTTHR = testthrw3.c +else +TESTTHR = testthrix.c endif + FMTDY = fmtdy.c fmtno.c FMTDYTST = fmtdy.c fmtno.c fmtdytst.c FMTHETST = fmthe.c fmtdy.c fmtno.c fmtdytst.c @@ -222,7 +226,8 @@ MPMCOMMON = \ tree.c \ version.c \ vm.c \ - walk.c + walk.c \ + POOLS = $(AMC) $(AMS) $(AWL) $(LO) $(MV2) $(MVFF) $(SNC) MPM = $(MPMCOMMON) $(MPMPF) $(POOLS) $(PLINTH) @@ -303,8 +308,9 @@ TEST_TARGETS=\ ztfm$(EXEEXT) ifneq ($(PFM),w3i3gc) -TEST_TARGETS = $(TEST_TARGETS) forktest$(EXEEXT) - +ifneq ($(PFM),w3i6gc) +TEST_TARGETS := $(TEST_TARGETS) forktest$(EXEEXT) +endif endif # This target records programs that we were once able to build but diff --git a/code/global.c b/code/global.c index 6c7cd39..50dd41a 100644 --- a/code/global.c +++ b/code/global.c @@ -825,7 +825,7 @@ Bool ArenaStep(Globals globals, double interval, double multiplier) Res ArenaFinalize(Arena arena, Ref obj) { Res res; - Pool refpool; + Pool refpool = NULL; AVERT(Arena, arena); AVER(PoolOfAddr(&refpool, arena, (Addr)obj)); diff --git a/code/mingw.gmk b/code/mingw.gmk index fa792aa..229e8b6 100644 --- a/code/mingw.gmk +++ b/code/mingw.gmk @@ -10,26 +10,27 @@ # common makefile fragment () requires. CC = gcc -CFLAGSDEBUG = -Og -gdwarf-4 -g3 -CFLAGSOPT = -O2 -gdwarf-4 -g3 +CFLAGSDEBUG = -Og -g3 +CFLAGSOPT = -O2 -g3 EXEEXT = .exe # Warnings that might be enabled by clients . CFLAGSCOMPILER := \ --Waggregate-return \ --Wall \ --Wcast-qual \ --Werror \ --Wextra \ --Winline \ --Wmissing-prototypes \ --Wnested-externs \ --Wpointer-arith \ --Wshadow \ --Wstrict-aliasing=2 \ --Wstrict-prototypes \ --Wswitch-default \ --Wwrite-strings + -Waggregate-return \ + -Wall \ + -Wcast-qual \ + -Werror \ + -Wextra \ + -Winline \ + -Wmissing-prototypes \ + -Wnested-externs \ + -Wpointer-arith \ + -Wshadow \ + -Wstrict-aliasing=2 \ + -Wstrict-prototypes \ + -Wswitch-default \ + -Wwrite-strings \ + CFLAGSCOMPILERSTRICT := -std=gnu89 -pedantic # A different set of compiler flags for less strict compilation, for diff --git a/code/mps.c b/code/mps.c index 89047ce..edd7438 100644 --- a/code/mps.c +++ b/code/mps.c @@ -244,7 +244,7 @@ /* Windows on x86-64 with Microsoft Visual Studio or Pelles C */ -#elif defined(MPS_PF_W3I6MV) || defined(MPS_PF_W3I6PC) +#elif defined(MPS_PF_W3I6MV) || defined(MPS_PF_W3I6PC) || defined(MPS_PF_W3I6GC) #include "lockw3.c" /* Windows locks */ #include "thw3.c" /* Windows threading */ diff --git a/code/mps.h b/code/mps.h index 700c414..46df73f 100644 --- a/code/mps.h +++ b/code/mps.h @@ -28,20 +28,10 @@ #include #include #include +#include "mpstd.h" -/* Platform Dependencies - * - * We went for over ten years without any platform ifdefs in this header. - * Then Microsoft made unsigned long shorter than a pointer on Win64. Ugh. - */ - -#if defined(_MSC_VER) && defined(_WIN32) && defined(_WIN64) && defined(_M_X64) -typedef unsigned __int64 mps_word_t; -#else -typedef unsigned long mps_word_t; -#endif - +typedef MPS_T_WORD mps_word_t; /* Abstract Types */ diff --git a/code/mpstd.h b/code/mpstd.h index fb852c5..cc78104 100644 --- a/code/mpstd.h +++ b/code/mpstd.h @@ -408,6 +408,22 @@ #define MPS_PF_ALIGN 4 +#elif defined(__MINGW64__) && defined(__x86_64) && defined(__GNUC__) +# if defined(CONFIG_PF_STRING) && ! defined(CONFIG_PF_W3I6GC) +# error "specified CONFIG_PF_... inconsistent with detected w3i6gc" +# endif +#define MPS_PF_W3I6GC +#define MPS_PF_STRING "w3i6gc" +#define MPS_OS_W3 +#define MPS_ARCH_I6 +#define MPS_BUILD_GC +#define MPS_T_WORD unsigned __int64 +#define MPS_T_ULONGEST unsigned __int64 +#define MPS_WORD_WIDTH 64 +#define MPS_WORD_SHIFT 6 +#define MPS_PF_ALIGN 16 + + #else #error "The MPS Kit does not have a configuration for this platform out of the box; see manual/build.txt" #endif diff --git a/code/scan.c b/code/scan.c index 308cffc..c9c6d6b 100644 --- a/code/scan.c +++ b/code/scan.c @@ -22,7 +22,6 @@ #pragma warning( disable : 4127 ) #endif - #define MPS_SCAN_AREA(test) \ MPS_SCAN_BEGIN(ss) { \ mps_word_t *p = base; \ diff --git a/code/ss.c b/code/ss.c index ce08810..2694a05 100644 --- a/code/ss.c +++ b/code/ss.c @@ -32,12 +32,19 @@ SRCID(ss, "$Id$"); * is a hot stack pointer. . */ +#pragma GCC diagnostic push + +#if defined(MPS_BUILD_GC) && (__GNUC__ >= 12) +#pragma GCC diagnostic ignored "-Wdangling-pointer" +#endif + ATTRIBUTE_NOINLINE void StackHot(void **stackOut) { *stackOut = &stackOut; } +#pragma GCC diagnostic pop /* StackScan -- scan the mutator's stack and registers */ diff --git a/code/testlib.h b/code/testlib.h index a06fb58..7432faf 100644 --- a/code/testlib.h +++ b/code/testlib.h @@ -118,8 +118,8 @@ #define SCNuLONGEST "llu" #define SCNXLONGEST "llX" #define PRIXLONGEST "llX" -typedef unsigned long long ulongest_t; -typedef long long longest_t; +typedef unsigned __int64 ulongest_t; +typedef __int64 longest_t; #define MPS_WORD_CONST(n) (n##ull) #else #define PRIuLONGEST "lu" diff --git a/code/w3i3gc.gmk b/code/w3i3gc.gmk index 150c7f9..7ad5915 100644 --- a/code/w3i3gc.gmk +++ b/code/w3i3gc.gmk @@ -21,29 +21,6 @@ MPMPF = \ include mingw.gmk include comm.gmk -# Installation stuff copied from ../Makefile.in - -prefix ?= /usr -INSTALL_PROGRAM = /bin/install -c -INSTALL_DATA = /bin/install -c -m 644 -MPS_TARGET_NAME = w3i3gc - -build-via-make: - $(MAKE) -f $(MPS_TARGET_NAME).gmk EXTRA_TARGETS="$(EXTRA_TARGETS)" - -install-make-build: make-install-dirs build-via-make - $(INSTALL_DATA) mps*.h $(prefix)/include/ - $(INSTALL_DATA) $(MPS_TARGET_NAME)/cool/mps.a $(prefix)/lib/libmps-debug.a - $(INSTALL_DATA) $(MPS_TARGET_NAME)/hot/mps.a $(prefix)/lib/libmps.a - for PROGRAM in $(EXTRA_TARGETS); do $(INSTALL_PROGRAM) $(MPS_TARGET_NAME)/hot/$$PROGRAM $(prefix)/bin/$$PROGRAM; done - -make-install-dirs: - mkdir -p $(prefix)/bin - mkdir -p $(prefix)/lib - mkdir -p $(prefix)/include - -install: install-make-build - # C. COPYRIGHT AND LICENSE # # Copyright (C) 2001-2020 Ravenbrook Limited . diff --git a/code/w3i6gc.gmk b/code/w3i6gc.gmk new file mode 100644 index 0000000..fa70844 --- /dev/null +++ b/code/w3i6gc.gmk @@ -0,0 +1,54 @@ +# -*- makefile-gmake -*- +# +# w3i6gc.gmk: BUILD FOR Windows/x64/MinGW/UCRT64 PLATFORM +# +# $Id$ +# Copyright (c) 2001-2020 Ravenbrook Limited. See end of file for license. + +PFM = w3i6gc + +CFLAGS = -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast + +MPMPF = \ + lockw3.c \ + mpsiw3.c \ + prmci6.c \ + prmcw3.c \ + prmcw3i6.c \ + protw3.c \ + spw3i6.c \ + thw3.c \ + vmw3.c \ + +include mingw.gmk +include comm.gmk + +CFLAGSCOMPILERSTRICT := -std=gnu99 -pedantic + +# C. COPYRIGHT AND LICENSE +# +# Copyright (C) 2001-2020 Ravenbrook Limited . +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the +# distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/configure b/configure index 9f06a0d..78657f7 100755 --- a/configure +++ b/configure @@ -1461,7 +1461,7 @@ else /* end confdefs.h. */ $4 int -main () +main (void) { #ifndef $as_decl_name #ifdef __cplusplus @@ -2405,7 +2405,7 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main () +main (void) { ; @@ -2545,7 +2545,7 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int -main () +main (void) { FILE *f = fopen ("conftest.out", "w"); return ferror (f) || fclose (f) != 0; @@ -2609,7 +2609,7 @@ else /* end confdefs.h. */ int -main () +main (void) { ; @@ -2660,7 +2660,7 @@ else /* end confdefs.h. */ int -main () +main (void) { #ifndef __GNUC__ choke me @@ -2701,7 +2701,7 @@ else /* end confdefs.h. */ int -main () +main (void) { ; @@ -2716,7 +2716,7 @@ else /* end confdefs.h. */ int -main () +main (void) { ; @@ -2732,7 +2732,7 @@ else /* end confdefs.h. */ int -main () +main (void) { ; @@ -2781,9 +2781,7 @@ struct stat; /* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ struct buf { int x; }; FILE * (*rcsopen) (struct buf *, struct stat *, int); -static char *e (p, i) - char **p; - int i; +static char *e (char **p, int i) { return p[i]; } @@ -2818,7 +2816,7 @@ int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, i int argc; char **argv; int -main () +main (void) { return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; ; @@ -3245,7 +3243,7 @@ else #include int -main () +main (void) { ; @@ -3315,7 +3313,7 @@ else #define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) int -main () +main (void) { int i; for (i = 0; i < 256; i++) @@ -3453,6 +3451,7 @@ BUILD_TARGET=build-via-make CLEAN_TARGET=clean-make-build INSTALL_TARGET=install-make-build TEST_TARGET=test-make-build +EXEEXT= case $host/$CLANG in aarch64-*-linux*/no) { $as_echo "$as_me:${as_lineno-$LINENO}: result: Linux ARM64" >&5 @@ -3585,6 +3584,30 @@ $as_echo "FreeBSD x86_64" >&6; } CPP="$CC -I/usr/local/include -E" PFMCFLAGS="$CFLAGS_LL" ;; + i*86-*-mingw*/*) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: Mingw x86" >&5 +$as_echo "Mingw x86" >&6; } + MPS_OS_NAME=w3 + MPS_ARCH_NAME=i3 + MPS_BUILD_NAME=gc + # Need /usr/local/include in order to find sqlite3.h + CFLAGS="-I/usr/local/include" + CPP="$CC -I/usr/local/include -E" + PFMCFLAGS="$CFLAGS_GC" + EXEEXT=.exe + ;; + x86_64-*-mingw*/*) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: Mingw x86_64" >&5 +$as_echo "Mingw x86_64" >&6; } + MPS_OS_NAME=w3 + MPS_ARCH_NAME=i6 + MPS_BUILD_NAME=gc + # Need /usr/local/include in order to find sqlite3.h + CFLAGS="-I/usr/local/include" + CPP="$CC -I/usr/local/include -E" + PFMCFLAGS="$CFLAGS_GC" + EXEEXT=.exe + ;; *) as_fn_error $? "MPS does not support this platform out of the box. See manual/build.txt" "$LINENO" 5 esac @@ -3636,10 +3659,10 @@ if ! $MAKE --version | grep -q "GNU" 2> /dev/null; then as_fn_error $? "MPS requires GNU make to build from configure, but see manual/build.txt" "$LINENO" 5 fi -EXTRA_TARGETS="mpseventcnv mpseventpy mpseventtxt" +EXTRA_TARGETS="mpseventcnv$EXEEXT mpseventpy$EXEEXT mpseventtxt$EXEEXT" ac_fn_c_check_header_mongrel "$LINENO" "sqlite3.h" "ac_cv_header_sqlite3_h" "$ac_includes_default" if test "x$ac_cv_header_sqlite3_h" = xyes; then : - EXTRA_TARGETS="$EXTRA_TARGETS mpseventsql" + EXTRA_TARGETS="$EXTRA_TARGETS mpseventsql$EXEEXT" fi diff --git a/configure.ac b/configure.ac index e10e832..765df99 100644 --- a/configure.ac +++ b/configure.ac @@ -44,6 +44,7 @@ BUILD_TARGET=build-via-make CLEAN_TARGET=clean-make-build INSTALL_TARGET=install-make-build TEST_TARGET=test-make-build +EXEEXT= case $host/$CLANG in aarch64-*-linux*/no) AC_MSG_RESULT([Linux ARM64]) @@ -163,6 +164,28 @@ case $host/$CLANG in CPP="$CC -I/usr/local/include -E" PFMCFLAGS="$CFLAGS_LL" ;; + i*86-*-mingw*/*) + AC_MSG_RESULT([Mingw x86]) + MPS_OS_NAME=w3 + MPS_ARCH_NAME=i3 + MPS_BUILD_NAME=gc + # Need /usr/local/include in order to find sqlite3.h + CFLAGS="-I/usr/local/include" + CPP="$CC -I/usr/local/include -E" + PFMCFLAGS="$CFLAGS_GC" + EXEEXT=.exe + ;; + x86_64-*-mingw*/*) + AC_MSG_RESULT([Mingw x86_64]) + MPS_OS_NAME=w3 + MPS_ARCH_NAME=i6 + MPS_BUILD_NAME=gc + # Need /usr/local/include in order to find sqlite3.h + CFLAGS="-I/usr/local/include" + CPP="$CC -I/usr/local/include -E" + PFMCFLAGS="$CFLAGS_GC" + EXEEXT=.exe + ;; *) AC_MSG_ERROR([MPS does not support this platform out of the box. See manual/build.txt]) esac @@ -172,8 +195,8 @@ if ! $MAKE --version | grep -q "GNU" 2> /dev/null; then AC_MSG_ERROR([MPS requires GNU make to build from configure, but see manual/build.txt]) fi -EXTRA_TARGETS="mpseventcnv mpseventpy mpseventtxt" -AC_CHECK_HEADER([sqlite3.h], [EXTRA_TARGETS="$EXTRA_TARGETS mpseventsql"]) +EXTRA_TARGETS="mpseventcnv$EXEEXT mpseventpy$EXEEXT mpseventtxt$EXEEXT" +AC_CHECK_HEADER([sqlite3.h], [EXTRA_TARGETS="$EXTRA_TARGETS mpseventsql$EXEEXT"]) # Put platform compiler flags like -ansi -pedantic into CFLAGS only # after checking for sqlite3.h -- that header doesn't compile with -- 2.46.0.windows.1