Skip to content

Commit 053825f

Browse files
committed
Fix static linking on MacOS by preventing '-optl-static' flag
The treatment of --executable-static means we pass `-optl-static` to GHC, which in turn just passes this to the linker. This flag can not work on macOS. Fully static linking is impossible as libSystem must be linked dynamically. Thus here we disable this flag for macOS.
1 parent adfd46f commit 053825f

File tree

1 file changed

+8
-0
lines changed
  • Cabal/src/Distribution/Simple/GHC/Build

1 file changed

+8
-0
lines changed

Cabal/src/Distribution/Simple/GHC/Build/Link.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ linkOrLoadComponent
121121
PD.ldOptions bi
122122
++ [ "-static"
123123
| withFullyStaticExe lbi
124+
-- MacOS can not link fully statically.
125+
-- Only kernels can be linked fully statically. Everything
126+
-- linking against libSystem must link dynamically. Thus even
127+
-- if we link all dependencies statically, we must not pass
128+
-- '-optl-static', as that will cause the linker to try and
129+
-- fail.
130+
, let Platform _hostArch hostOS = hostPlatform lbi
131+
in hostOS /= OSX
124132
]
125133
-- Pass extra `ld-options` given
126134
-- through to GHC's linker.

0 commit comments

Comments
 (0)