part-cw / lambdanative

LambdaNative is a cross-platform development environment written in Scheme, supporting Android, iOS, BlackBerry 10, OS X, Linux, Windows, OpenBSD, NetBSD, FreeBSD and OpenWrt.
http://www.lambdanative.org
Other
1.39k stars 85 forks source link

OSX issue: gsc segaults #443

Open zwieblum opened 10 months ago

zwieblum commented 10 months ago

I got my hand on an iMac mini and tried to get lambdanative running. Problem is, the created gsc binary segfaults. Any idea what goes wrong there?

Mac OS Version ist 14.0 Xcode Version ist 15.0

==> creating libraries needed for pngtool..
 => liblambdanative..
gcc  -DMACOSX -m64  -mmacosx-version-min=10.6 -fPIC -c *.c -I/Users/klepp/Library/Caches/lambdanative/macosx/include
ar ru liblambdanative.a *.o
ar: creating archive liblambdanative.a
ranlib liblambdanative.a
 => cleaning up..
 => exploding library libgambc..
 => exploding library liblambdanative..
 => exploding library libz..
 => exploding library libpng..
 => exploding library libfreetype..
 => exploding library libjpeg..
 => exploding library libgd..
searching supported languages in /Users/klepp/Projects/lambdanative
loading support for scm..
supported languages =  scm
 => compiling scheme payload..
    /Users/klepp/Projects/lambdanative/modules/config/config.scm ..
/Users/klepp/Library/Caches/lambdanative/macosx/bin/gsc -:~~tgt=/Users/klepp/Library/Caches/lambdanative/macosx -prelude "(declare (block)(not safe)(standard-bindings)(extended-bindings))(define-cond-expand-feature macosx)" -c -o /Users/klepp/Library/Caches/lambdanative/macosx/build/458336386.c   /Users/klepp/Projects/lambdanative/modules/config/config.scm
./scripts/verbose.sh: line 6: 12326 Segmentation fault: 11  /Users/klepp/Library/Caches/lambdanative/macosx/bin/gsc -:~~tgt=/Users/klepp/Library/Caches/lambdanative/macosx -prelude "(declare (block)(not safe)(standard-bindings)(extended-bindings))(define-cond-expand-feature macosx)" -c -o /Users/klepp/Library/Caches/lambdanative/macosx/build/458336386.c /Users/klepp/Projects/lambdanative/modules/config/config.scm
ERROR: failed on file /Users/klepp/Library/Caches/lambdanative/macosx/build/458336386.c
BUILD FAILED
make: *** [all] Error 1
mgorges commented 10 months ago

What error do you get if you simply run /Users/klepp/Library/Caches/lambdanative/macosx/bin/gsc ? I.e. is this a code signing error, a linking problem, or something else entirely?

zwieblum commented 10 months ago

Sorry for this beeing an image, but I don't have access to the machine right now and the person I asked ... well ... at least it's what lldb spits out:

image003
mgorges commented 10 months ago

To me this sounds like an issue with Gambit? Unless it is a codesign thing that is why I was wondering if it ran outside of lldb? It might relate to https://github.com/part-cw/lambdanative/issues/275 * thread #1, queue = 'com.apple.main-thread', stop reason = EXC BAD ACCESS (code=1, address=0x0) frame #0: 0x000000010001bdd7 gsc getenv UCS_ 2 + 103

zwieblum commented 10 months ago

It segaults when run by lldb or from shell. That reminds me, the shell on that computer is set to zsh for some reason. I think that getenv() is called with a NULL argument - why ever that might be.

mgorges commented 10 months ago

In 2019, with the introduction of MacOS Catalina, the operating system suggested changing the default shell to zsh, and while I can't recall when it became required, it has been a while. I guess the next step is to see if anything was obvious in the build process of when Gambit was made? It could also be a libgambit vs libgambc - I can look into the latter more.

zwieblum commented 10 months ago

I'm wondering: which verson of OSx and xcode do you use? Would using the precompiled gambit version https://gambitscheme.org/4.7.9/gambc-v4_7_9-macosx-intel64.dmg solve the issue? Or would it be usefull if you provide your compiled gambit version? Sorry, I don't know enough of the internals of OSX.

mgorges commented 10 months ago

Both of my work machines use macOS Monterey (12.7) and Xcode 14.2. I also have set modules/config/LIBRARIES to libgambit many years ago, which is 4.9.2, whereas the current default is libgambc, which is 4.7.9. We never changed the default as it requires a flushing of the entire build cache and while I can force that by bumping VERSION it might make people unhappy having to rebuild their entire pipeline so we never forced it. Relevant issues to the switch are https://github.com/part-cw/lambdanative/issues/343, https://github.com/part-cw/lambdanative/pull/241, https://github.com/part-cw/lambdanative/issues/275.

I have access to another Mac that runs macOS Sonoma (14.0) and the latest Xcode but I won't get to that until Friday at the earliest. Finally, I have never used a pre-compiled GambC (as I think we patch ours to backport some functionality - e.g. see https://github.com/part-cw/lambdanative/pull/336), but you could try if that runs.

zwieblum commented 10 months ago

So I repaced in modules/config/LIBRARIES libgambc with libgambit```, then I changed [VERSION](https://github.com/part-cw/lambdanative/blob/master/VERSION) to ```1.1.1, then cleard all caches:

rm -R ~/.lambdanative ~/Library/Caches/lambdanative
./configure uSquish
make

Anyway, the compiled gsc fails with the same segfault as before:

 => libgambit..
 => downloading https://github.com/gambit/gambit/archive/v4.9.2.tar.gz..
 == hash 3e0521b84ba4a13cafac04eb6671a13fe10a3b01
 => extracting /Users/klepp/Library/Caches/lambdanative/packages/v4.9.2.tar.gz..
 => patching source...
 => applying patches from ../0001-Fix-incorrect-space-allocation-report-by-time-specia.patch
 => applying patches from ../configure.patch
 => applying patches from ../fix_IPv6.patch
 => applying patches from ../fix_IPv6_precompiled.patch
 => configuring source in /Users/klepp/.lambdanative/tmp_install/gambit-4.9.2 ...
 => compiling source..
 => compiling source..
 => cleaning up..
 => liblambdanative..
 => cleaning up..
 => exploding library libgambit..
 => exploding library liblambdanative..
 => exploding library libz..
 => exploding library libpng..
 => exploding library libfreetype..
 => exploding library libjpeg..
 => exploding library libgd..
 => compiling scheme payload..
    /Users/klepp/Projects/lambdanative/modules/config/config.scm ..
/Users/klepp/Library/Caches/lambdanative/macosx/bin/gsc -:~~tgt=/Users/klepp/Library/Caches/lambdanative/macosx -prelude "(declare (block)(not safe)(standard-bindings)(extended-bindings))(define-cond-expand-feature macosx)" -c -o /Users/klepp/Library/Caches/lambdanative/macosx/build/458336386.c   /Users/klepp/Projects/lambdanative/modules/config/config.scm
./scripts/verbose.sh: line 10: 81004 Segmentation fault: 11  /Users/klepp/Library/Caches/lambdanative/macosx/bin/gsc -:~~tgt=/Users/klepp/Library/Caches/lambdanative/macosx -prelude "(declare (block)(not safe)(standard-bindings)(extended-bindings))(define-cond-expand-feature macosx)" -c -o /Users/klepp/Library/Caches/lambdanative/macosx/build/458336386.c /Users/klepp/Projects/lambdanative/modules/config/config.scm
ERROR: failed on file /Users/klepp/Library/Caches/lambdanative/macosx/build/458336386.c
BUILD FAILED - configure with verbose option for more information
make: *** [all] Error 1
mgorges commented 10 months ago

Too bad, thanks for trying - I will ask one of my colleagues to test it locally on the latest MacOS and Xcode and report if the pre-build DMG or our compiled versions run. Update: The DMG doesn't work, even after disabling gatekeeper; it ends with "The installation failed".

mgorges commented 10 months ago

However, compiling 4.9.2 from source seems to work for us, thus unless there is different when you call it to compile or link I currently cannot reproduce this: Screenshot 2023-10-18 at 4 34 13 PM

zwieblum commented 10 months ago

Hm ... it might be that this is an xcode 15 problem after all. I just installed gambit using brew and that version works.