Skip to content

Commit 6c70b60

Browse files
committed
darwin: Allow posix_spawn_file_actions_addchdir to be missing when linking against process
In 0699e41 we attempted to account for darwin toolchains missing this symbol, which is imported as a weak references. However, weak references on MachO objects don't work the same way as on ELF (see iains/gcc-darwin-arm64#133). A final link with undefined weak references still fails. To fix this, on darwin, we explicilty add `-Wl,-U,_posix_spawn_file_actions_addchdir` to `ld-options` so anything linking against process explicilty instructs the linker to ignore undefined references to this symbol (set it to NULL at runtime). Fixes #376
1 parent 92deb52 commit 6c70b60

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

process.cabal

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,19 @@ library
8787
cbits/posix/find_executable.c
8888
other-modules: System.Process.Posix
8989

90+
-- On macOS, posix_spawn_file_actions_addchdir is available from macOS >= 26.
91+
-- We weakly reference this symbol when we are build on such a platform.
92+
-- However, weak references on MachO are hints to the dynamic loader, not the
93+
-- static linker, which will still expect the symbol to be defined somewhere.
94+
-- This means linking fails when we try to link an executable depending on
95+
-- process on a toolchain which doesn't have this symbol against a process
96+
-- library build on a toolchain with the symbol.
97+
-- See https://github.com/haskell/process/issues/376
98+
-- Hence: instruct the linker to explicilty allow undefined references to
99+
-- the symbol when linking against process on darwin
100+
if os(darwin)
101+
ld-options: -Wl,-U,_posix_spawn_file_actions_addchdir
102+
90103
include-dirs: include
91104
install-includes:
92105
runProcess.h

0 commit comments

Comments
 (0)