public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Darwin, libgfortran : Do not use environ directly from the  library.
@ 2020-11-20 20:54 Iain Sandoe
  2020-11-21  8:12 ` Thomas Koenig
  0 siblings, 1 reply; 3+ messages in thread
From: Iain Sandoe @ 2020-11-20 20:54 UTC (permalink / raw)
  To: fortran List; +Cc: GCC Patches, Thomas Koenig

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



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Darwin, libgfortran : Do not use environ directly from the library.
  2020-11-20 20:54 [PATCH] Darwin, libgfortran : Do not use environ directly from the library Iain Sandoe
@ 2020-11-21  8:12 ` Thomas Koenig
  2020-11-21  9:46   ` Iain Sandoe
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas Koenig @ 2020-11-21  8:12 UTC (permalink / raw)
  To: Iain Sandoe, fortran List; +Cc: GCC Patches

Hi Iain,

> tested on a number of Darwin platforms old and new, and on
> x86_64/powerpc64-linux,
> 
> OK for master?
> … and backports to open branches?

One question...

> +# ifdef __APPLE__
> +#  include <crt_externs.h>
> +#  define environ (*_NSGetEnviron ())

Is it guaranteed that crt_externs.h is present if __APPLE__
is defined?

If that's the case, OK for master and backports.

Best regards

	Thomas

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Darwin, libgfortran : Do not use environ directly from the library.
  2020-11-21  8:12 ` Thomas Koenig
@ 2020-11-21  9:46   ` Iain Sandoe
  0 siblings, 0 replies; 3+ messages in thread
From: Iain Sandoe @ 2020-11-21  9:46 UTC (permalink / raw)
  To: Thomas Koenig; +Cc: Fortran List, GCC Patches

Hi Thomas,

Thomas Koenig via Fortran <fortran@gcc.gnu.org> wrote:
>>
>> tested on a number of Darwin platforms old and new, and on
>> x86_64/powerpc64-linux,
>> OK for master?
>> … and backports to open branches?
>
> One question...
>
>> +# ifdef __APPLE__
>> +#  include <crt_externs.h>
>> +#  define environ (*_NSGetEnviron ())
>
> Is it guaranteed that crt_externs.h is present if __APPLE__
> is defined?

__APPLE__ is defined by GCC when targetting macOS (actually by other  
compilers too,
although that’s probably not important for building libgfortran).

The header is present on all macOS systems supported by GCC (and at least  
two revisions
prior to the earliest that currently builds GCC open branches).

Of course, a user with -D on the command line can define it .. but then  
will get a build
error - which is fine __APPLE__ is in the implementation namespace, the  
user gets what
they deserve ;)

We could be paranoid and write #if defined (__APPLE__) &&  
__has_include(<crt_externs.h>)
but that seems over the top here.

> If that's the case, OK for master and backports.

applied to master,
will deal with the backports along with other Darwin ones.
thanks
Iain


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-11-21  9:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-20 20:54 [PATCH] Darwin, libgfortran : Do not use environ directly from the library Iain Sandoe
2020-11-21  8:12 ` Thomas Koenig
2020-11-21  9:46   ` Iain Sandoe

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).