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

Build fails with gcc14: error: assignment to 'Objptr' {aka 'unsigned char *'} from 'int' makes pointer from integer without a cast [-Wint-conversion] #578

Closed
barracuda156 opened this issue Aug 9, 2024 · 6 comments

Comments

@barracuda156
Copy link
Contributor

The first error is with an old MLton which is used for bootstrap, so we can only patch it locally. The second should be fixed here, perhaps:

          /opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_mlton/mlton/work/.tmp/fileRpMQu9.o \
          /opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_mlton/mlton/work/.tmp/fileEQaoED.363.c
In file included from /opt/local/libexec/mlton-bootstrap/lib/mlton/include/c-chunk.h:216,
                 from /opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_mlton/mlton/work/.tmp/fileEQaoED.363.c:110:
/opt/local/libexec/mlton-bootstrap/lib/mlton/include/basis/coerce.h: In function 'Real32_castToWord32':
/opt/local/libexec/mlton-bootstrap/lib/mlton/include/basis/coerce.h:42:5: error: implicit declaration of function 'memcpy' [-Wimplicit-function-declaration]
   42 |     memcpy(&y, &x, sizeof(t));                  \
      |     ^~~~~~
/opt/local/libexec/mlton-bootstrap/lib/mlton/include/basis/coerce.h:46:1: note: in expansion of macro 'cast'
   46 | cast(Real32, Word32)
      | ^~~~
/opt/local/libexec/mlton-bootstrap/lib/mlton/include/basis/coerce.h:1:1: note: include '<string.h>' or provide a declaration of 'memcpy'
  +++ |+#include <string.h>
    1 | 
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_mlton/mlton/work/.tmp/fileEQaoED.363.c: In function 'Chunk0':
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_mlton/mlton/work/.tmp/fileEQaoED.363.c:27869:39: error: assignment to 'Objptr' {aka 'unsigned char *'} from 'int' makes pointer from integer without a cast [-Wint-conversion]
27869 |         O(Objptr, G(Objptr, 5277), 0) = 0x11;
      |                                       ^
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_mlton/mlton/work/.tmp/fileEQaoED.363.c:27874:39: error: assignment to 'Objptr' {aka 'unsigned char *'} from 'int' makes pointer from integer without a cast [-Wint-conversion]
27874 |         O(Objptr, G(Objptr, 5278), 0) = 0x9;
      |                                       ^
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_mlton/mlton/work/.tmp/fileEQaoED.363.c:27879:39: error: assignment to 'Objptr' {aka 'unsigned char *'} from 'int' makes pointer from integer without a cast [-Wint-conversion]
27879 |         O(Objptr, G(Objptr, 5279), 0) = 0x5;
      |                                       ^
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_mlton/mlton/work/.tmp/fileEQaoED.363.c:31807:39: error: assignment to 'Objptr' {aka 'unsigned char *'} from 'int' makes pointer from integer without a cast [-Wint-conversion]
31807 |         O(Objptr, G(Objptr, 5990), 0) = 0x81;
      |                                       ^
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_mlton/mlton/work/.tmp/fileEQaoED.363.c:31812:39: error: assignment to 'Objptr' {aka 'unsigned char *'} from 'int' makes pointer from integer without a cast [-Wint-conversion]
31812 |         O(Objptr, G(Objptr, 5991), 0) = 0x41;
      |                                       ^
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_lang_mlton/mlton/work/.tmp/fileEQaoED.363.c:31817:39: error: assignment to 'Objptr' {aka 'unsigned char *'} from 'int' makes pointer from integer without a cast [-Wint-conversion]
31817 |         O(Objptr, G(Objptr, 5992), 0) = 0x21;
      |                                       ^
   Compile and Assemble raised in 3.62 + 0.00 (0% GC)
MLton raised in 365.82 + 149.95 (29% GC)
@MatthewFluet
Copy link
Member

The former is certainly already fixed: 3edda85

I do not observe an error with a C codegen self-compile on Fedora 40 (gcc 14); looking at the generated C code, I see statements like:

O(Objptr, T(Q, 97), 0) = (Objptr)(Word64)(0x21ull);

so there seem to be sufficient casts. I'm not precisely sure when those casts were introduced; there was a fair amount of refactoring of the RSSA and Machine IRs prior to the 20210117 release (which also includes the commit linked above).

What version of MLton is being used for the bootstrap?

@barracuda156
Copy link
Contributor Author

@MatthewFluet The last version for ppc was 20070826, which is what we use: https://github.com/macports/macports-ports/blob/master/lang/mlton-bootstrap/Portfile

If a newer version is required, perhaps the only non-painful way would be if you could host my bootstrap binary (I can build it against 10.5 or possibly 10.4 target). And then I can update the port to pick a new version for bootstrapping mlton.

@MatthewFluet
Copy link
Member

@barracuda156 Sure, I suppose we could host a ppc build on sourceforge.

@barracuda156
Copy link
Contributor Author

@MatthewFluet Thank you! I will handle it in 2–3 days and update here.

@MatthewFluet
Copy link
Member

Closing stale issue.

@barracuda156
Copy link
Contributor Author

Sorry, I have a hard time managing all the stuff :(

However the issue can be closed as resolved. I have built the latest mlton now:

36-39:~ svacchanda$ port -v installed mlton
The following ports are currently installed:
  mlton @20241230_0 requested_variants='' platform='darwin 10' archs='ppc' date='2024-12-31T05:46:02+0800'

I had to patch the archaic mlton-bootstrap to fix headers and pass flags to downgrade errors. This is the patch, just for the reference (for 2007 mlton, not for the current one):

--- bin/mlton	2007-08-30 07:10:03.000000000 +0800
+++ bin/mlton	2024-12-31 03:19:24.000000000 +0800
@@ -5,9 +5,9 @@
 set -e
 
 dir=`dirname "$0"`
-lib='/usr/local/lib/mlton'
+lib='@MLTON@'
 eval `"$lib/platform"`
-gcc='gcc'
+gcc='@CC@'
 case "$HOST_OS" in
 mingw)
 	exe='.exe'
@@ -70,11 +70,8 @@
 # The darwin linker complains (loudly) about non-existent library
 # search paths.
 darwinLinkOpts=''
-if [ -d '/opt/local/lib' ]; then
-        darwinLinkOpts="$darwinLinkOpts -L/opt/local/lib"
-fi
-if [ -d '/sw/lib' ]; then
-        darwinLinkOpts="$darwinLinkOpts -L/sw/lib"
+if [ -d '@PREFIX@/lib' ]; then
+        darwinLinkOpts="$darwinLinkOpts -L@PREFIX@/lib"
 fi
 
 doit "$lib" \
@@ -82,12 +79,15 @@
         -cc-opt-quote "-I$lib/include"                           \
         -cc-opt '-O1'                                            \
         -cc-opt '-fno-strict-aliasing -fomit-frame-pointer -w'   \
+        -cc-opt '-Wno-error=int-conversion'                      \
+        -cc-opt '-Wno-error=incompatible-pointer-types'          \
         -link-opt '-lgdtoa -lm -lgmp'                            \
         -mlb-path-map "$lib/mlb-path-map"                        \
         -target-as-opt amd64 '-m64'                              \
         -target-cc-opt amd64 '-m64'                              \
-        -target-cc-opt darwin                                    \
-                '-I/opt/local/include -I/sw/include'             \
+        -target-cc-opt powerpc64 '-arch ppc64'                   \
+        -target-cc-opt powerpc '-arch ppc'                       \
+        -target-cc-opt darwin '-I@PREFIX@/include'               \
         -target-cc-opt freebsd '-I/usr/local/include'            \
         -target-cc-opt netbsd '-I/usr/pkg/include'               \
         -target-cc-opt openbsd '-I/usr/local/include'            \
@@ -100,7 +100,10 @@
                 -malign-jumps=2
                 -malign-loops=2'                                 \
         -target-link-opt amd64 '-m64'                            \
-        -target-link-opt darwin "$darwinLinkOpts"                \
+        -target-link-opt powerpc64 '-arch ppc64'                 \
+        -target-link-opt powerpc '-arch ppc'                     \
+        -target-link-opt darwin                                  \
+                "$darwinLinkOpts -lSystemStubs"                  \
         -target-link-opt freebsd '-L/usr/local/lib/'             \
         -target-link-opt mingw                                   \
                 '-lws2_32 -lkernel32 -lpsapi -lnetapi32'         \

--- lib/mlton/include/platform/darwin.h	2007-08-27 05:03:52.000000000 +0800
+++ lib/mlton/include/platform/darwin.h	2024-12-31 03:14:08.000000000 +0800
@@ -1,3 +1,7 @@
+#ifndef __STDC_FORMAT_MACROS
+#define __STDC_FORMAT_MACROS
+#endif
+
 #include <fenv.h>
 #include <inttypes.h>
 #include <stdint.h>
@@ -27,8 +31,14 @@
 #include <sys/wait.h>
 #include <syslog.h>
 #include <termios.h>
+
+#ifndef _XOPEN_SOURCE
+#define _XOPEN_SOURCE /* In order for <ucontext.h> to work. */
+#endif
+
 #include <ucontext.h>
 #include <utime.h>
+#include <crt_externs.h> /* for environ */
 
 #define HAS_FEROUND TRUE
 #define HAS_FPCLASSIFY TRUE
@@ -48,4 +58,4 @@
 #define SIGPOLL 7
 #endif
 
-extern char **environ; /* for Posix_ProcEnv_environ */
+#define environ *_NSGetEnviron() /* for Posix_ProcEnv_environ */

--- lib/mlton/include/cenv.h	2007-08-27 05:03:54.000000000 +0800
+++ lib/mlton/include/cenv.h	2023-07-21 18:33:40.000000000 +0800
@@ -61,7 +61,7 @@
 COMPILE_TIME_ASSERT(sizeof_float__is_four, sizeof(float) == 4);
 COMPILE_TIME_ASSERT(sizeof_double__is_eight, sizeof(double) == 8);
 
-#if (defined (__APPLE_CC__))
+#if (defined (__APPLE_CC__) || defined (__APPLE__))
 #define __Darwin__
 #endif
 
@@ -104,7 +104,7 @@
 #include "platform/m68k.h"
 #elif (defined (__mips__))
 #include "platform/mips.h"
-#elif (defined (__ppc__)) || (defined (__powerpc__))
+#elif (defined (__ppc__)) || (defined (__powerpc__)) || (defined (__POWERPC__))
 #include "platform/powerpc.h"
 #elif (defined (__s390__))
 #include "platform/s390.h"

--- lib/mlton/include/basis/coerce.h	2007-08-27 05:03:53.000000000 +0800
+++ lib/mlton/include/basis/coerce.h	2024-12-31 03:02:54.000000000 +0800
@@ -1,3 +1,4 @@
+#include <string.h>
 
 #define coerce(n, f, t)                         \
   MLTON_CODEGEN_STATIC_INLINE                   \

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants