From a3454130760bf51b76495663c60ac6dffbe3d130 Mon Sep 17 00:00:00 2001 From: Iain Sandoe Date: Sat, 21 Nov 2020 09:06:03 +0000 Subject: [PATCH] Darwin, libgfortran : Do not use environ directly from the library. On macOS / Darwin, the environ variable can be used directly in the code of an executable, but cannot be used in the code of a shared library (i.e. libgfortran.dylib), in this case. In such cases, the function _NSGetEnviron should be called to get the address of 'environ'. libgfortran/ChangeLog: * intrinsics/execute_command_line.c (environ): Use _NSGetEnviron to get the environment pointer on Darwin. --- libgfortran/intrinsics/execute_command_line.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libgfortran/intrinsics/execute_command_line.c b/libgfortran/intrinsics/execute_command_line.c index 71d61a766ad..6d7b8fc658e 100644 --- a/libgfortran/intrinsics/execute_command_line.c +++ b/libgfortran/intrinsics/execute_command_line.c @@ -34,7 +34,12 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #endif #ifdef HAVE_POSIX_SPAWN #include +# ifdef __APPLE__ +# include +# define environ (*_NSGetEnviron ()) +# else extern char **environ; +# endif #endif #if defined(HAVE_POSIX_SPAWN) || defined(HAVE_FORK) #include -- 2.30.2