From: Iain Sandoe <iain@sandoe.co.uk>
To: fortran List <fortran@gcc.gnu.org>
Cc: GCC Patches <GCC-patches@gcc.gnu.org>,
Thomas Koenig <tkoenig@netcologne.de>
Subject: [PATCH] Darwin, libgfortran : Do not use environ directly from the library.
Date: Fri, 20 Nov 2020 20:54:30 +0000 [thread overview]
Message-ID: <573D3BC5-53B5-4B29-8C03-5B8D60B5B485@sandoe.co.uk> (raw)
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 <spawn.h>
+# ifdef __APPLE__
+# include <crt_externs.h>
+# define environ (*_NSGetEnviron ())
+# else
extern char **environ;
+# endif
#endif
#if defined(HAVE_POSIX_SPAWN) || defined(HAVE_FORK)
#include <signal.h>
--
2.24.1
next reply other threads:[~2020-11-20 20:55 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-20 20:54 Iain Sandoe [this message]
2020-11-21 8:12 ` Thomas Koenig
2020-11-21 9:46 ` Iain Sandoe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=573D3BC5-53B5-4B29-8C03-5B8D60B5B485@sandoe.co.uk \
--to=iain@sandoe.co.uk \
--cc=GCC-patches@gcc.gnu.org \
--cc=fortran@gcc.gnu.org \
--cc=tkoenig@netcologne.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).