Debugging a compiler segfault OR building the compiler in debug mode

I have run into a segfault with the compiler. I understand the change that introduced it, but I’d like to get a better backtrace to understand more fully where the issue is.
Using the 0.16.0 release of the compiler strips out the debug information, so the backtrace is not helpful.

I pulled the 0.16.0 tag from the compiler repo and built it using the 0.16.0 release. It built just fine, no issues. However, when I try to compile my project with this debug version, I get a bunch of aro errors:

/home/redacted/hush/zig-pkg/freetype-2.14.1-alzUkceCqgDRZIP8PnxnNCd8jwfbwY0k1VhlTV2O5Ivo/builds/unix/ftsystem.c:1:1: error: aro does not support compiling C objects yet
/home/redacted/hush/zig-pkg/freetype-2.14.1-alzUkceCqgDRZIP8PnxnNCd8jwfbwY0k1VhlTV2O5Ivo/src/base/ftdebug.c:1:1: error: aro does not support compiling C objects yet
...
/home/redacted/hush/zig-pkg/sdl_linux_deps-0.0.0-SDL_ltg8hgAOayMwFN6BhHW3Rs5UPtf6n8m-2qcQHuGS/src/xdg-output-unstable-v1-protocol.c:1:1: error: aro does not support compiling C objects yet
/home/redacted/hush/zig-pkg/sdl_linux_deps-0.0.0-SDL_ltg8hgAOayMwFN6BhHW3Rs5UPtf6n8m-2qcQHuGS/src/xdg-decoration-unstable-v1-protocol.c:1:1: error: aro does not support compiling C objects yet
...

All are basically the same: aro does not support compiling C objects yet.

The confusing part for me is that the aro version should be the same since I’m using the 0.16.0 tag. So I’m not sure why the pre-built compiler is file, but my debug built one is not.

I also tried the 0.16.x branch, but that had other issues.

I guess my main questions are:
Why would aro be different from the built-from-source debug compiler and the pre-build release compiler?
Is there any way to work around this?

I guess you built zig without llvm. In the compilation config, zig can use one of two c backends: clang (llvm) and aro (which does not support compiling C objects yet…). If you compile zig with llvm, clang is used by default, but zig without llvm currently can’t compile c code.

I think that is the right direction. I’ll have to figure out the right incantation for getting it to compile with llvm and then report back.

I could also try to reproduce it, if you tell me how you got the segfault.

The commit is on this branch:
https://codeberg.org/Southporter/hush/src/branch/segfault-investigation
Exact commit: https://codeberg.org/Southporter/hush/commit/d9c41d21062cd502b5a45d26dd4253fac0581ae0
Basically, adding the zigimg package leades to the following:

zig build
install
└─ install hush
   └─ compile exe hush Debug native failure
error: process terminated with signal SEGV
failed command: /home/southporter/.local/share/mise/installs/zig/0.16.0/zig build-exe -ODebug --dep hush --dep shtml --dep dvui --dep dvui_backend=backend -Mroot=/home/southporter/git/learning/hush/src/main.zig --dep shtml --dep dvui --dep zigimg -Mhush=/home/southporter/git/learning/hush/src/root.zig -ODebug --dep scripty --dep tracy --dep language-tag-registry -Mshtml=/home/southporter/git/learning/hush/zig-pkg/superhtml-0.6.2-mHhhCHSLJAAbpYuXf_F-ANJsqUUJGU_CgM8QKF3DKMC7/src/root.zig /home/southporter/git/learning/hush/zig-pkg/dvui-0.5.0-dev-AQFJmXZaAwFyjRMmfm-MzaWySUrspcmRkaw9kMgOipa5/vendor/stb/stb_image_impl.c /home/southporter/git/learning/hush/zig-pkg/dvui-0.5.0-dev-AQFJmXZaAwFyjRMmfm-MzaWySUrspcmRkaw9kMgOipa5/vendor/stb/stb_image_write_impl.c .zig-cache/o/841cbff6582020dd77a0696068bbe372/libfreetype.a /home/southporter/git/learning/hush/zig-pkg/dvui-0.5.0-dev-AQFJmXZaAwFyjRMmfm-MzaWySUrspcmRkaw9kMgOipa5/vendor/tfd/tinyfiledialogs.c .zig-cache/o/5bc66efecd673c555a8ac9a1baf77b99/libtree-sitter.a -cflags -std=c11 -- /home/southporter/git/learning/hush/zig-pkg/N-V-__8AAHNaAgD6kjK3HX6lAf89chPqS5zIm0tLpvBQLOtX/src/parser.c -cflags -std=c11 -- /home/southporter/git/learning/hush/zig-pkg/tree_sitter_zig-1.1.2-YNf2GAt8XACdbaWHHiNMMfw--bLN1Av1rMsnq6bokMdL/src/parser.c -ODebug -I .zig-cache/o/ce280dcaf6543e1da8d8905062bdeb95 -I .zig-cache/o/283650e3a821c52ad712259cf3c80d06 -I /home/southporter/git/learning/hush/zig-pkg/N-V-__8AAHNaAgD6kjK3HX6lAf89chPqS5zIm0tLpvBQLOtX/src -I /home/southporter/git/learning/hush/zig-pkg/tree_sitter_zig-1.1.2-YNf2GAt8XACdbaWHHiNMMfw--bLN1Av1rMsnq6bokMdL/src --dep dvui-c --dep build_options --dep default_options --dep svg2tvg --dep render_backend --dep backend -Mdvui=/home/southporter/git/learning/hush/zig-pkg/dvui-0.5.0-dev-AQFJmXZaAwFyjRMmfm-MzaWySUrspcmRkaw9kMgOipa5/src/dvui.zig .zig-cache/o/3a71bce449eaca92b4297515d2af7013/libSDL3.a -fsanitize-c=full -ODebug -I .zig-cache/o/2eb3e920d42cad7730a4884db61f5457 --dep sdl3-c --dep sdl_options --dep dvui -Mbackend=/home/southporter/git/learning/hush/zig-pkg/dvui-0.5.0-dev-AQFJmXZaAwFyjRMmfm-MzaWySUrspcmRkaw9kMgOipa5/src/backends/sdl.zig -ODebug --dep zigimg -Mzigimg=/home/southporter/git/learning/hush/zig-pkg/zigimg-0.1.0-8_eo2oyaFwBZwJpmqPkCfVXWBrHcqbYwmrp1I6bTD3lI/zigimg.zig -ODebug --dep tracy -Mscripty=/home/southporter/git/learning/hush/zig-pkg/scripty-0.1.0-LKK5OzcUAQDVndpJNPAm4eC_-G0HaXUdQejzb9X6C2vq/src/root.zig -ODebug --dep options -Mtracy=/home/southporter/git/learning/hush/zig-pkg/tracy-0.0.0-4Xw-1pwwAABTfMgoDP1unCbZDZhJEfict7XCBGF6IdIn/src/root.zig -Mlanguage-tag-registry=.zig-cache/o/be4aca0b167239519e09e95e2b5d8587/registry.zon -ODebug -Mdvui-c=.zig-cache/o/d013f584848d4507630b92820cae6667/dvui-c.zig -Mbuild_options=.zig-cache/c/3306d23fe0380d55e805df14402583a4/options.zig -Mdefault_options=.zig-cache/c/7c42a3baa45fa01fda7e9f273f854462/options.zig -ODebug --dep xml -Msvg2tvg=/home/southporter/git/learning/hush/zig-pkg/svg2tvg-0.0.0-HpMZuaP8BQALdwSolfst0dPGUUn2ptqgfSxVs8RoQJ6K/src/root.zig -ODebug --dep dvui -Mrender_backend=/home/southporter/git/learning/hush/zig-pkg/dvui-0.5.0-dev-AQFJmXZaAwFyjRMmfm-MzaWySUrspcmRkaw9kMgOipa5/src/backends/render/default.zig -ODebug -Msdl3-c=.zig-cache/o/9ed535e4a5d0b2b7d63bf263ea13d292/sdl3-c.zig -Msdl_options=.zig-cache/c/ac41c617acd2a010b34606fb3295e313/options.zig -Moptions=.zig-cache/c/f0d58b6b26cdc396238f6287a0f6c3b9/options.zig -ODebug -Mxml=/home/southporter/git/learning/hush/zig-pkg/xml-0.2.0-ZTbP3yI6AgB9Rpd2hQrueO63ib0Bm6mQiL_WB1t7JAmP/src/xml.zig -lc --cache-dir .zig-cache --global-cache-dir /home/southporter/.cache/zig --name hush --zig-lib-dir /home/southporter/.local/share/mise/installs/zig/0.16.0/lib/ --listen=-

Without haven’t it reproduced, I suspect it is caused by #31633, which is known to occur when using zigimg.

Now managed to get a stacktrace. It seems to be #31633.

Thanks for the issue link. That looks like what I’m hitting, appreciate the verification. I will still try to get the compiler built with LLVM so I can do some digging myself. I appreciate your help.

1 Like