public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Iain Sandoe <iain@codesourcery.com>
To: Tristan Gingold <gingold@adacore.com>
Cc: gcc-patches Patches <gcc-patches@gcc.gnu.org>,
	Arnaud Charlet	<charlet@adacore.com>
Subject: Re: [Ada] Fix bootstrapping on darwin9/10 (PR ada/64349).
Date: Thu, 08 Jan 2015 12:49:00 -0000	[thread overview]
Message-ID: <A77512A5-E3F7-4871-88E2-46ED76B1FEDC@codesourcery.com> (raw)
In-Reply-To: <20150107101530.GA22412@adacore.com>

Hi Tristan,

On 7 Jan 2015, at 10:15, Arnaud Charlet wrote:

> Use _NSGetEnviron to get environment.
> 
> Tested on x86_64-pc-linux-gnu, committed on trunk
> 
> 2015-01-07  Tristan Gingold  <gingold@adacore.com>
> 
> 	PR ada/64349
> 	* env.c (__gnat_environ): Adjust for darwin9/darwin10.
> 
> <difs.txt>

So my original patch assumed that, while it was not legal to use environ from a shlib, it is legal to use _NSGetEnviron () from an application ...

.. and, OK fine, I see the point about ! defined (__arm__) .. but a few other comments.

ISTM that there's a partial implementation to distinguish between IN_RTS and application?

Index: env.c
===================================================================
--- env.c	(revision 219191)
+++ env.c	(working copy)
@@ -44,6 +44,12 @@
 #include <stdlib.h>
 #endif
 
+#if defined (__APPLE__) && !defined (__arm__)
+/* On Darwin, _NSGetEnviron must be used for shared libraries; but it is not
+   available on iOS.  */
+#include <crt_externs.h>
+#endif
+

This definition ^ fires for IN_RTS ...
... but there's no definition of _NSGetEnviron in the other branch unless it happens to get pulled in via config.h / system.h - I don't know that this is guaranteed, do you?

----

 #if defined (__vxworks)
   #if defined (__RTP__)
     /* On VxWorks 6 Real-Time process mode, environ is defined in unistd.h.  */
@@ -212,6 +218,8 @@
 #elif ! (defined (__vxworks))
   extern char **environ;
   return environ;

 ^ I don't expect __vxworks to be defined for a Darwin compiler ...
.. so not sure what the code below will achieve.

+#elif defined (__APPLE__) && !defined (__arm__)
+  return *_NSGetEnviron ();

 ^ here you use _NSGetEnviron () unconditionally (see comment re. IN_RTS).
 #else
   return environ;
 #endif

====

If we want to distinguish between in IN_RTS and application maybe sth pseudo-code like:

if IN_RTS
  if apple && ! arm
   include crt_externals.h
   define environ (*_ _NSGetEnviron ())
  end
else
  if apple and ! arm 
   extern "C" char ** environ;
  end
end

......

amend the vxworks case ... 

+#elif defined (__APPLE__) && !defined (__arm__)
+  return environ;

====

Am I missing some point here?
Iain



  reply	other threads:[~2015-01-08 12:49 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-07 10:15 Arnaud Charlet
2015-01-08 12:49 ` Iain Sandoe [this message]
2015-01-08 13:52   ` Tristan Gingold
2015-01-08 23:42     ` Iain Sandoe
2015-01-14  9:11       ` Tristan Gingold
2015-01-20 11:05         ` Iain Sandoe
2015-01-20 11:05           ` Arnaud Charlet
2015-01-20 11:30             ` Iain Sandoe
2015-01-20 13:14               ` Dominique d'Humières
2015-01-30 16:35 Arnaud Charlet
2015-01-30 18:13 ` Iain Sandoe
2015-02-04  9:27   ` Tristan Gingold

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=A77512A5-E3F7-4871-88E2-46ED76B1FEDC@codesourcery.com \
    --to=iain@codesourcery.com \
    --cc=charlet@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=gingold@adacore.com \
    /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).