kanjitalk755 / macemu

Basilisk II and SheepShaver Macintosh emulators
332 stars 50 forks source link

Compilation with link-time optimization fails, and suggested patch to solve that #194

Closed frankspace closed 3 months ago

frankspace commented 3 months ago

When attempting to compile with link-time optimization on linux (because Arch now enables LTO by default), configure fails with checking floating point format... configure: error: Unknown floating point format.

It appears that a similar issue was noticed with other emulation software, specifically ARAnyM, on Gentoo (see here), and that issue was resolved by ARAnyM disabling lto while compiling the floating point format test (see here). The relevant code in ARAnyM's float.m4 looks an awful lot like code in configure.ac here.

I found that the following patch allows compilation to succeed with LTO enabled:

--- a/BasiliskII/src/Unix/configure.ac
+++ b/BasiliskII/src/Unix/configure.ac
@@ -1691,16 +1691,29 @@
 dnl result of all this processing is in the file conftest.dmp, which
 dnl may be examined by the commands in the second argument.
 dnl
+
 AC_DEFUN([gcc_AC_EXAMINE_OBJECT],
 [AC_LANG_SAVE
-AC_LANG_C
+AC_LANG([C])
 dnl Next bit cribbed from AC_TRY_COMPILE.
 cat > conftest.$ac_ext <<EOF
 [#line __oline__ "configure"
 #include "confdefs.h"
 $1
 ]EOF
+ac_save_CFLAGS="$CFLAGS"
+CFLAGS="$CFLAGS -fno-lto"
+gcc_ac_compile_ok=0
 if AC_TRY_EVAL(ac_compile); then
+  gcc_ac_compile_ok=1
+else
+  CFLAGS=$ac_save_CFLAGS
+  if AC_TRY_EVAL(ac_compile); then
+    gcc_ac_compile_ok=1
+  fi
+fi
+CFLAGS="$ac_save_CFLAGS"
+if test "$gcc_ac_compile_ok" = 1; then
   od -c conftest.o |
     sed ['s/^[0-7]*[   ]*/ /
      s/\*/./g
@@ -1730,7 +1743,7 @@
 dnl not presently supported by GCC.  S/390 "binary floating point"
 dnl is in fact IEEE (but maybe we should have that in EBCDIC as well
 dnl as ASCII?)
-dnl
+
 AC_DEFUN([gcc_AC_C_FLOAT_FORMAT],
 [AC_CACHE_CHECK(floating point format, ac_cv_c_float_format,
 [gcc_AC_EXAMINE_OBJECT(
@@ -1784,11 +1797,17 @@
    if test $ac_cv_c_bigendian = no; then
        fbigend=1
    fi
+   if test $ac_cv_c_bigendian = universal; then
+       fbigend=WORDS_BIGENDIAN
+   fi
    ;;
     'IEEE (little-endian)' )
    if test $ac_cv_c_bigendian = yes; then
        fbigend=0
    fi
+   if test $ac_cv_c_bigendian = universal; then
+       fbigend='!WORDS_BIGENDIAN'
+   fi
    ;;
     'VAX D-float' )
    format=VAX_FLOAT_FORMAT

That's for Basilisk II, but I expect the same would work for SheepSaver.

Would it be possible to tamper with the configure.ac files to incorporate the above patch? (I've never tried making a pull reqest before, but if you'd rather, I can try to do that.)

Thank you!

kanjitalk755 commented 3 months ago

Fixed. The latter part seems unnecessary, so I haven't modified it.

frankspace commented 3 months ago

I can confirm that with commit e12789a, this now compiles fine on Artix with LTO enabled. Thank you!