From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp2.wavenetuk.net (unknown [195.26.37.10]) by sourceware.org (Postfix) with ESMTP id DD9CA3857808; Fri, 20 Nov 2020 20:55:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DD9CA3857808 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=sandoe.co.uk Authentication-Results: sourceware.org; spf=none smtp.mailfrom=iain@sandoe.co.uk Received: from [192.168.1.212] (host81-138-1-83.in-addr.btopenworld.com [81.138.1.83]) by smtp2.wavenetuk.net (Postfix) with ESMTPA id 937EE6001A3; Fri, 20 Nov 2020 20:55:07 +0000 (GMT) From: Iain Sandoe Content-Type: text/plain; charset=utf-8; delsp=yes; format=flowed Content-Transfer-Encoding: 8bit Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Date: Fri, 20 Nov 2020 20:54:30 +0000 Subject: [PATCH] Darwin, libgfortran : Do not use environ directly from the library. Cc: GCC Patches , Thomas Koenig To: fortran List Message-Id: <573D3BC5-53B5-4B29-8C03-5B8D60B5B485@sandoe.co.uk> X-Mailer: Apple Mail (2.3273) X-Spam-Status: No, score=-14.4 required=5.0 tests=BAYES_00, BODY_8BITS, GIT_PATCH_0, KAM_COUK, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KHOP_HELO_FCRDNS, MAY_BE_FORGED, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: fortran@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Fortran mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Nov 2020 20:55:10 -0000 Hi, not sure if this is covered directly by my Darwin maintainer’s hat so … ----- 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 such cases, the function _NSGetEnviron should be called to get the address of 'environ’. tested on a number of Darwin platforms old and new, and on x86_64/powerpc64-linux, OK for master? … and backports to open branches? thanks Iain ** we’ve been “getting away with it” because of the application of dynamic_lookup in a rather broad manner, which I’m about to get rid of. ————— 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.24.1