Skip to content

Commit d63e6b4

Browse files
bgamarihasufell
authored andcommitted
Don't foreign import environ
`musl` defines the `environ` symbol as a weak alias, which on AArch64 requires particular treatment by the compiler. As GHC doesn't have access to the prototype of the symbol, it doesn't know that this treatment is necessary and consequently we emit assembly that the linker will choke on. See GHC #24011.
1 parent 25b0f11 commit d63e6b4

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

System/Posix/Env/Internal.hsc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ getCEnviron = nsGetEnviron >>= peek
2222
foreign import ccall unsafe "_NSGetEnviron"
2323
nsGetEnviron :: IO (Ptr (Ptr CString))
2424
#else
25-
getCEnviron = peek c_environ_p
25+
getCEnviron = _getCEnviron
2626

27-
foreign import ccall unsafe "&environ"
28-
c_environ_p :: Ptr (Ptr CString)
27+
-- N.B. we cannot import `environ` directly in Haskell as it may be a weak symbol
28+
-- which requires special treatment by the compiler, which GHC is not equipped to
29+
-- provide. See GHC #24011.
30+
foreign import ccall unsafe "__hsunix_get_environ"
31+
_getCEnviron :: IO (Ptr CString)
2932
#endif

cbits/HsUnix.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include "HsUnix.h"
1010

11+
char **__hsunix_get_environ (void) {return environ;}
12+
1113
#ifdef HAVE_RTLDNEXT
1214
void *__hsunix_rtldNext (void) {return RTLD_NEXT;}
1315
#endif

0 commit comments

Comments
 (0)