Hello everyone,
at $WORK I have introduced Nix when we ported an application to Linux. It’s worked wonderfully and provides the development environment everyone on the team uses. The application is also bundled as a package and works without a hitch.
Now I wanted to build the application on macOS, as well. We must link against proprietary binaries, which were built for a minimum target of 10.15, which initially caused some issues. I was able to resolve these simply by using a toolchain based on the macOS 11 SDK. The application now builds successfully, but crashes immediately with a SEGFAULT. Attaching lldb yields the following information:
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
frame #0: 0x0000000000000000
error: memory read failed for 0x0
This seems peculiar to me, like we never even jumped to _start
. This may be related to these warnings that are also printed:
warning: (x86_64) /nix/store/pavi51i5f5j5cl9s2rq1q4kqd58vxg2j-app-x86_64-apple-darwin-90/bin/app(0x0000000100000000) address 0x0000000100000000 maps to more than one section: app.__TEXT and app.__TEXT
warning: (x86_64) /nix/store/pavi51i5f5j5cl9s2rq1q4kqd58vxg2j-app-x86_64-apple-darwin-90/bin/app(0x0000000100000000) address 0x00000001035a7000 maps to more than one section: app.__DATA_CONST and app.__DATA_CONST
warning: (x86_64) /nix/store/pavi51i5f5j5cl9s2rq1q4kqd58vxg2j-app-x86_64-apple-darwin-90/bin/app(0x0000000100000000) address 0x00000001037cc000 maps to more than one section: app.__DATA and app.__DATA
Process 12440 launched: '/Users/zimmermann/development/development/result/bin/app' (x86_64)
warning: (x86_64) /nix/store/pavi51i5f5j5cl9s2rq1q4kqd58vxg2j-app-x86_64-apple-darwin-90/bin/app(0x0000000100000000) address 0x0000000100000000 maps to more than one section: app.__TEXT and app.__TEXT
warning: (x86_64) /nix/store/pavi51i5f5j5cl9s2rq1q4kqd58vxg2j-app-x86_64-apple-darwin-90/bin/app(0x0000000100000000) address 0x00000001035a7000 maps to more than one section: app.__DATA_CONST and app.__DATA_CONST
warning: (x86_64) /nix/store/pavi51i5f5j5cl9s2rq1q4kqd58vxg2j-app-x86_64-apple-darwin-90/bin/app(0x0000000100000000) address 0x00000001037cc000 maps to more than one section: app.__DATA and app.__DATA
warning: (x86_64) /nix/store/pavi51i5f5j5cl9s2rq1q4kqd58vxg2j-app-x86_64-apple-darwin-90/bin/app(0x0000000100000000) address 0x0000000100000000 maps to more than one section: app.__TEXT and app.__TEXT
warning: (x86_64) /nix/store/pavi51i5f5j5cl9s2rq1q4kqd58vxg2j-app-x86_64-apple-darwin-90/bin/app(0x0000000100000000) address 0x00000001035a7000 maps to more than one section: app.__DATA_CONST and app.__DATA_CONST
warning: (x86_64) /nix/store/pavi51i5f5j5cl9s2rq1q4kqd58vxg2j-app-x86_64-apple-darwin-90/bin/app(0x0000000100000000) address 0x00000001037cc000 maps to more than one section: app.__DATA and app.__DATA
Looking at otool -l
, I cannot see any duplicate load commands. When building the application with the native toolchain and dependencies installed through brew, it runs as expected and attaching lldb does not yield any such errors.
I have never seen this behaviour before and have not been successful in Googling what could cause this issue. The warnings lead me to believe it may be related to linker problems, but I don’t understand why that would behave so differently between the native and Nix-provided toolchain.
The application is built using some decently complicated CMake files, which I am unfortunately not at liberty to share. I will try to recreate a minimal example that reproduces the issue. In the meantime, does anyone have any pointers for potential causes?
Thank you for your time!