magic icon indicating copy to clipboard operation
magic copied to clipboard

[macOS-13.4.1] `Segmentation fault: 11` starting `magic`

Open gnawhleinad opened this issue 2 years ago • 9 comments

I've installed magic following the instructions from INSTALL_MacOS.md#with-brew.

I've validated that the configure[^1] ran successfully:

Configuration Summary (principle requirements):

X11:          yes
Python3:      yes
OpenGL:       yes
Vector fonts: yes
Cairo:        yes
Tcl/Tk:       yes

I've also validated the DISPLAY is set and I'm running magic from the XQuartz window:

$ echo $DISPLAY
/private/tmp/com.apple.launchd.2proAh9BYB/org.xquartz:0

Unfortunately, magic immediately exits with a Segmentation fault: 11:

Process:               wish8.6 [96060]
Path:                  /opt/homebrew/*/wish
Identifier:            wish8.6
Version:               ???
Code Type:             ARM-64 (Native)
Parent Process:        bash [72771]
Responsible:           X11.bin [72377]
User ID:               501

Date/Time:             2023-11-19 10:01:41.7780 -0800
OS Version:            macOS 13.4.1 (22F770820d)
Report Version:        12
Anonymous UUID:        82A0E882-AF1C-BA2F-79F6-AB9F63A53DB2

Sleep/Wake UUID:       4A5EA58B-8933-453A-B017-36BA26F99D95

Time Awake Since Boot: 2000000 seconds
Time Since Wake:       1860 seconds

System Integrity Protection: enabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000000000050
Exception Codes:       0x0000000000000001, 0x0000000000000050

Termination Reason:    Namespace SIGNAL, Code 11 Segmentation fault: 11
Terminating Process:   exc handler [96060]

VM Region Info: 0x50 is not in any region.  Bytes before following region: 105553518919600
      REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      UNUSED SPACE AT START
--->  
      MALLOC_NANO (reserved)   600018000000-600020000000 [128.0M] rw-/rwx SM=NUL  ...(unallocated)

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   libX11.6.dylib                	       0x10e57ee40 XDefaultColormap + 12
1   tclmagic.dylib                	       0x10d7be140 GrTkInit + 412
2   tclmagic.dylib                	       0x10d7c0b00 x11SetDisplay + 1004
3   tclmagic.dylib                	       0x10d7b0000 GrSetDisplay + 620
4   tclmagic.dylib                	       0x10d8413d8 mainInitAfterArgs + 564
5   tclmagic.dylib                	       0x10d93dea0 _magic_initialize + 652
6   libtcl8.6.dylib               	       0x1008bd91c TclInvokeStringCommand + 120
7   libtcl8.6.dylib               	       0x1008bf068 TclNRRunCallbacks + 80
8   libtcl8.6.dylib               	       0x10094c5a8 ChildEval + 132
9   libtcl8.6.dylib               	       0x10094a13c NRInterpCmd + 1692
10  libtcl8.6.dylib               	       0x1008bf068 TclNRRunCallbacks + 80
11  libtcl8.6.dylib               	       0x1008bfdcc TclEvalEx + 1640
12  libtcl8.6.dylib               	       0x100960788 Tcl_FSEvalFileEx + 512
13  libtk8.6.dylib                	       0x10075f3c8 Tk_MainEx + 1388
14  wish8.6                       	       0x100572e3c main + 56
15  dyld                          	       0x19687bf28 start + 2236

Thread 1:
0   libsystem_pthread.dylib       	       0x196bced8c start_wqthread + 0

Thread 2:
0   libsystem_pthread.dylib       	       0x196bced8c start_wqthread + 0

Thread 3:: com.apple.NSEventThread
0   libsystem_kernel.dylib        	       0x196b93f14 mach_msg2_trap + 8
1   libsystem_kernel.dylib        	       0x196ba6240 mach_msg2_internal + 80
2   libsystem_kernel.dylib        	       0x196b9cb78 mach_msg_overwrite + 604
3   libsystem_kernel.dylib        	       0x196b94290 mach_msg + 24
4   CoreFoundation                	       0x196cb27e4 __CFRunLoopServiceMachPort + 160
5   CoreFoundation                	       0x196cb10c4 __CFRunLoopRun + 1208
6   CoreFoundation                	       0x196cb04b8 CFRunLoopRunSpecific + 612
7   AppKit                        	       0x199ffc334 _NSEventThread + 172
8   libsystem_pthread.dylib       	       0x196bd3fa8 _pthread_start + 148
9   libsystem_pthread.dylib       	       0x196bceda0 thread_start + 8

Thread 4:
0   libsystem_kernel.dylib        	       0x196b9eff0 __select + 8
1   libtcl8.6.dylib               	       0x1009b71f0 NotifierThreadProc + 628
2   libsystem_pthread.dylib       	       0x196bd3fa8 _pthread_start + 148
3   libsystem_pthread.dylib       	       0x196bceda0 thread_start + 8

Thread 5:
0   libsystem_pthread.dylib       	       0x196bced8c start_wqthread + 0


Thread 0 crashed with ARM Thread State (64-bit):
    x0: 0x0000000136071a10   x1: 0x0000000000000000   x2: 0x0000000000000000   x3: 0x0000000000000000
    x4: 0x0000000000000036   x5: 0x0000000000000035   x6: 0x0000000000000035   x7: 0x000000016f892728
    x8: 0x0000000000000000   x9: 0x0000000000000000  x10: 0x0000000000000000  x11: 0x0000000136326910
   x12: 0x000000010e2420b8  x13: 0x0000000000000020  x14: 0x0000000000000001  x15: 0x0018000000000001
   x16: 0x000000010e57ee34  x17: 0x0000000000000035  x18: 0x0000000000000000  x19: 0x0000000135b14610
   x20: 0x0000000000000002  x21: 0x0000000135b5adc0  x22: 0x0000000135ac4090  x23: 0x000000013615b730
   x24: 0x0000000000000000  x25: 0x0000000135b5add0  x26: 0x000000013601d290  x27: 0x000000013601d2f0
   x28: 0x00000000000014cf   fp: 0x000000016f892860   lr: 0x000000010d7be140
    sp: 0x000000016f892670   pc: 0x000000010e57ee40 cpsr: 0x20001000
   far: 0x0000000000000050  esr: 0x92000006 (Data Abort) byte read Translation fault

Binary Images:
       0x10056c000 -        0x100573fff wish8.6 (*) <e5231774-8b61-3d29-9f04-04a8688a8592> /opt/homebrew/*/wish8.6
       0x100738000 -        0x10083ffff libtk8.6.dylib (*) <887d3269-6be3-3d4d-a7ed-327ef55e3f64> /opt/homebrew/*/libtk8.6.dylib
       0x1008ac000 -        0x1009d7fff libtcl8.6.dylib (*) <d0dfb9ec-d5cb-3e77-8fd4-b72df97057be> /opt/homebrew/*/libtcl8.6.dylib
       0x10c07c000 -        0x10c087fff libobjc-trampolines.dylib (*) <570c31f7-94c6-3b86-ae44-1694db0a4bcd> /usr/lib/libobjc-trampolines.dylib
       0x10d6c4000 -        0x10d96bfff tclmagic.dylib (*) <bec49421-f089-3532-86b7-024723e96597> /usr/local/lib/magic/tcl/tclmagic.dylib
       0x10e56c000 -        0x10e65bfff libX11.6.dylib (*) <85a7413a-7238-3ecb-af88-78deb37dc2bf> /opt/X11/*/libX11.6.dylib
       0x10d4a0000 -        0x10d4e3fff libGL.1.dylib (*) <15e96a6a-55c1-3a51-a1ec-69340ca81d8d> /opt/X11/*/libGL.1.dylib
       0x10d35c000 -        0x10d3bbfff libGLU.1.dylib (*) <b8b8a1bd-dc0d-3df8-b361-51db30a51045> /opt/X11/*/libGLU.1.dylib
       0x10d514000 -        0x10d5e3fff libcairo.2.dylib (*) <3f554ab9-d686-307b-b383-ec34ea504ed9> /opt/X11/*/libcairo.2.dylib
       0x10d3e8000 -        0x10d41bfff libfontconfig.1.dylib (*) <0ef5df10-dbec-3fa0-a6e9-19dde3252132> /opt/X11/*/libfontconfig.1.dylib
       0x10e888000 -        0x10e90bfff libfreetype.6.dylib (*) <083cb0b5-37a3-346d-a77c-96c957aeeab6> /opt/X11/*/libfreetype.6.dylib
       0x10d434000 -        0x10d447fff libxcb.1.dylib (*) <335e5b70-9435-366b-a17a-b980bcd5a4f2> /opt/X11/*/libxcb.1.dylib
       0x10d62c000 -        0x10d62ffff libXau.6.dylib (*) <aa9a4a03-f4a3-3c9d-8e67-1cbc9682f841> /opt/X11/*/libXau.6.dylib
       0x10d640000 -        0x10d677fff libglapi.0.dylib (*) <91fd2107-3155-3182-9a8c-edbb84bdb3f1> /opt/X11/*/libglapi.0.dylib
       0x10d464000 -        0x10d46bfff libxcb-glx.0.dylib (*) <dc684108-4977-36bb-9e06-35f12b68912b> /opt/X11/*/libxcb-glx.0.dylib
       0x10d488000 -        0x10d48bfff libX11-xcb.1.dylib (*) <1db0a4a4-8bab-3552-9395-145ec5b16d58> /opt/X11/*/libX11-xcb.1.dylib
       0x10d6a0000 -        0x10d6abfff libXext.6.dylib (*) <3149eef3-7b2a-3472-b066-5a2a1a14f20e> /opt/X11/*/libXext.6.dylib
       0x10e730000 -        0x10e753fff libpng16.16.dylib (*) <5d5b3658-605b-3f8b-a569-a47786842858> /opt/X11/*/libpng16.16.dylib
       0x10e6dc000 -        0x10e6e3fff libxcb-render.0.dylib (*) <c669b761-9a4e-3af6-aacb-67303c34ef8a> /opt/X11/*/libxcb-render.0.dylib
       0x10e6c4000 -        0x10e6c7fff libxcb-shm.0.dylib (*) <e020df55-1f72-3a4d-96d5-e87a2a45ab14> /opt/X11/*/libxcb-shm.0.dylib
       0x10e768000 -        0x10e7abfff libpixman-1.0.dylib (*) <0ac92f10-605d-3ec1-896f-8376a6795b23> /opt/X11/*/libpixman-1.0.dylib
       0x196876000 -        0x196904553 dyld (*) <2237410f-d39c-30ce-9a94-13aacb66b766> /usr/lib/dyld
       0x196bcd000 -        0x196bd9fff libsystem_pthread.dylib (*) <46d35233-a051-3f4f-bba4-ba56dddc4d1a> /usr/lib/system/libsystem_pthread.dylib
       0x196b93000 -        0x196bccfe7 libsystem_kernel.dylib (*) <34a49b54-82b2-37a1-9314-f6a4a2bb3ff8> /usr/lib/system/libsystem_kernel.dylib
       0x196c33000 -        0x19710cfff com.apple.CoreFoundation (6.9) <203e4401-8c2e-3157-a24b-92f52551d43e> /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
       0x199e99000 -        0x19ada7fff com.apple.AppKit (6.9) <041c7d21-21cc-3eea-ae53-d39f5ca6a24e> /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit
               0x0 - 0xffffffffffffffff ??? (*) <00000000-0000-0000-0000-000000000000> ???

External Modification Summary:
  Calls made by other processes targeting this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by all processes on this machine:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0

VM Region Summary:
ReadOnly portion of Libraries: Total=1.0G resident=0K(0%) swapped_out_or_unallocated=1.0G(100%)
Writable regions: Total=1.1G written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=1.1G(100%)

[^1]: I made one minor change to set PYTHON3. I'm using pyenv and wanted to forcibly set the magic installation to the brew-managed python3 installation. I can open this as a formal pull request now but was hoping to validate a full magic installation first. See https://github.com/dangerdevices/magic/commit/ce4831faf7ccb0c00f3e7c3acca3fb65977a707a.

gnawhleinad avatar Nov 19 '23 18:11 gnawhleinad

I'm running into the same issue, but I was able to build and run magic using MacPorts. I don't understand the inner workings of MacPorts to start to guess what might be different.

shaunplee avatar Jan 04 '24 07:01 shaunplee

@shaunplee, :sparkles:, thanks for the comment!

I'm running into the same issue, but I was able to build and run magic using MacPorts.

For clarification, does it build and run magic without a crash? Are you using XQuartz?

I don't understand the inner workings of MacPorts to start to guess what might be different.

From a cursory pass, it looks like the magic installation [by MacPorts] is done via https://github.com/macports/macports-ports/blob/master/science/magic/Portfile. I'm going to try following this to see if that yields better results.

gnawhleinad avatar Jan 04 '24 16:01 gnawhleinad

The problem may be due to TCL/TK not using x11 graphics when installed via brew. See https://gitlab.freedesktop.org/xorg/xserver/-/issues/796 for more details.

jatoben avatar Jan 04 '24 22:01 jatoben

The instructions in INSTALL_MacOS.md imply that the brew installation of tcl-tk will be X11-compatible. This is the most reliable set of instructions I currently have (which I can't vouch for personally because I don't have a Mac):

cd ~
echo Create common directory for tool sources
mkdir -p gits
cd gits

echo Install homebrew
echo Note:  The command below takes a few minutes to install stuff
/bin/bash -c "$(curl -fsSL \ https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

echo Compile and install X11-based Tcl/Tk for magic
brew install wget coreutils
wget [https://prdownloads.sourceforge.net/tcl/tcl8.6.13-src.tar.gz](https://prdownloads.sourceforge.net/tcl/tcl8.6.10-src.tar.gz)
tar xfz tcl8.6.13-src.tar.gz
rm tcl8.6.13-src.tar.gz
cd tcl8.6.13/unix
echo Using opt2 in case homebrew tcl/tk was installed
./configure --prefix=/usr/local/opt2/tcl-tk
make -j$(nproc)
sudo make install
make clean
cd ~/gits
brew install libx11
wget [https://prdownloads.sourceforge.net/tcl/tk8.6.13-src.tar.gz](https://prdownloads.sourceforge.net/tcl/tk8.6.10-src.tar.gz)
tar xfz tk8.6.13-src.tar.gz
rm tk8.6.13-src.tar.gz
cd tk8.6.13/unix
./configure --prefix=/usr/local/opt2/tcl-tk --with-tcl=/usr/local/opt2/tcl-tk/lib --with-x --x-includes=/usr/local/include/X11 --x-libraries=/usr/local/lib
sed -i.bak 's/(libdir):.*$/(libdir)/g' Makefile
make -j$(nproc)
sudo make install
make clean
cd ~/gits

echo Install prerequisite packages for Mac OS using homebrew
brew install cairo
brew install libglu freeglut
brew install --cask xquartz

echo Run the X11 server
open -a XQuartz

echo Allow X11 permission (may or may not be necessary)
xhost + localhost

echo Set the DISPLAY environment variable
export DISPLAY=:0

echo Get the Magic VLSI layout editor
git clone https://github.com/RTimothyEdwards/magic
cd magic
./configure --with-tcl=/usr/local/opt2/tcl-tk/lib --with-tk=/usr/local/opt2/tcl-tk/lib --with-cairo=$(brew --prefix cairo)/include --x-includes=/usr/local/include/X11 --x-libraries=/usr/local/lib --enable-cairo-offscreen
make -j$(nproc)
sudo make install
make clean

RTimothyEdwards avatar Jan 05 '24 01:01 RTimothyEdwards

Thank you for the quick response.

@jatoben I agree, the homebrew formula for tcl-tk currently builds tk with the --without-x flag: https://github.com/Homebrew/homebrew-core/blob/61aaee83a6155c0e6179817b6c30264a07e529b9/Formula/t/tcl-tk.rb#L105

I edited my local copy of the formula for tcl-tk to match the configuration settings in the "Without Brew" instructions, but that didn't solve the problem and magic still segfaults with the same error.

It seems that the "With Brew" instructions from INSTALL_MacOS no longer work.

shaunplee avatar Jan 05 '24 07:01 shaunplee

@gnawhleinad OK, so I followed the "Without Brew" instructions in the INSTALL_MacOS.md file and it worked for me.

So then I translated those instructions into a Homebrew Formula (magic-vlsi.rb) that builds its own copy of Tcl/Tk with X11 enabled. It works on my machine.

If you'd like, you can try it on yours:

brew tap shaunplee/asic
brew install shaunplee/asic/magic

shaunplee avatar Jan 09 '24 07:01 shaunplee

@shaunplee, this is amazing - nice work!

So then I translated those instructions into a Homebrew Formula (magic-vlsi.rb) and it works on my machine. If you'd like, you can try it on

I have also been exploring a Homebrew formula that follows the instructions / workarounds mentioned in this thread... but haven't been as successful.

One implicit dependency in your formula is X11 via /usr/X11/include. Is that via XQuartz?

gnawhleinad avatar Jan 09 '24 07:01 gnawhleinad

@shaunplee, this is amazing - nice work!

@gnawhleinad Thanks!

One implicit dependency in your formula is X11 via /usr/X11/include. Is that via XQuartz?

Yes, that comes from XQuartz. I don't remember why I chose to use that path, because /usr/X11 is actually a symlink (via /private/var/select/X11) to the actual XQuartz install path of /opt/X11. The script would probably work fine with /opt/X11/include instead.

Unfortunately, Homebrew doesn't allow dependencies on casks, but that does remind me that I should include a note in the formula about installing XQuartz.

shaunplee avatar Jan 09 '24 07:01 shaunplee

brew install shaunplee/asic/magic

I believe your formula is:

$ brew install shaunplee/asic/magic-vlsi

Unfortunately, I'm failing to build tk with:

/private/tmp/magic-vlsi--tk-20240109-95599-igxg08/tk8.6.13/unix/../generic/tk.h:99:13: fatal error: 'X11/Xlib.h' file not found
#   include <X11/Xlib.h>
            ^~~~~~~~~~~~
1 error generated.
make: *** [tkStubLib.o] Error 1

I'll keep investigating on my end...

gnawhleinad avatar Jan 09 '24 17:01 gnawhleinad