diff mbox

[libada] Fix PR64349 - make darwin use the correct interface to access _environ.

Message ID E2BCCCB6-53B4-4937-BE1E-F34CFC22A25A@codesourcery.com
State New
Headers show

Commit Message

Iain Sandoe Dec. 22, 2014, 11:49 a.m. UTC
Hi Eric,

For the main executable, it is permitted for Darwin to access _environ directly.  For shared libraries, it is not (one is supposed use _NSGetEnviron()).

At present, the more recent darwin ports are "getting away" with the omission because they have a blanket setting of -Wl,-undefined,dynamic_lookup which means that the symbol can be satisfied from the executable at dynamic load time.  However, the change is applicable generally (not just to the older ports mentioned in the PR).

The attached patch fixes this properly (we can bike-shed over whether __APPLE__ or __MACH__ is a better guard, I don't have an axe to grind particularly).

This is one of two remaining bootstrap blockers across the Darwin patch.

OK for trunk?
Iain

gcc/ada:

	PR ada/64349
	* env.c (__gnat_environ): Use the _NSGetEnviron() interface to access the environment
        for Darwin.
From c336acb970b21589368948bc1bdc502546b568fc Mon Sep 17 00:00:00 2001
From: Iain Sandoe <iain@codesourcery.com>
Date: Mon, 22 Dec 2014 10:47:40 +0000
Subject: [PATCH] Arrange for libada to use the approved interface to obtain
 _environ on Darwin

---
 gcc/ada/env.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Arnaud Charlet Dec. 22, 2014, 1:53 p.m. UTC | #1
Iain,

The change isn't quite right for iOS (aka arm-darwin), but the general idea
is the right one.

Tristan (cc:ed) has prepared a patch for this issue which works on both
MAC OS and darwin), which I'll merge soon. This will address this PR.

Arno
Eric Botcazou Dec. 22, 2014, 1:54 p.m. UTC | #2
> 	PR ada/64349
> 	* env.c (__gnat_environ): Use the _NSGetEnviron() interface to access
> 	the environment for Darwin.

OK if Tristan has no objections to the patch:
  https://gcc.gnu.org/ml/gcc-patches/2014-12/msg01753.html
Iain Sandoe Dec. 22, 2014, 2:02 p.m. UTC | #3
hi Arnaud,

On 22 Dec 2014, at 13:53, Arnaud Charlet wrote:

> The change isn't quite right for iOS (aka arm-darwin), but the general idea
> is the right one.

hmm.. I wasn't aware of a [> 4.2.1] arm-mach-o backend .. if that's a general issue, then I'll consider it for future patches.

> Tristan (cc:ed) has prepared a patch for this issue which works on both
> MAC OS and darwin), which I'll merge soon. This will address this PR.

Thanks, that's fine .. always better to be general.
Iain
Arnaud Charlet Dec. 22, 2014, 2:14 p.m. UTC | #4
> hmm.. I wasn't aware of a [> 4.2.1] arm-mach-o backend .. if that's a general
> issue, then I'll consider it for future patches.

Yes please.

> > Tristan (cc:ed) has prepared a patch for this issue which works on both
> > MAC OS and darwin), which I'll merge soon. This will address this PR.
> 
> Thanks, that's fine .. always better to be general.

Great.

Arno
diff mbox

Patch

diff --git a/gcc/ada/env.c b/gcc/ada/env.c
index 9530813..ff602b2 100644
--- a/gcc/ada/env.c
+++ b/gcc/ada/env.c
@@ -198,6 +198,11 @@  __gnat_setenv (char *name, char *value)
 #endif
 }
 
+#ifdef __APPLE__
+#include <crt_externs.h>
+#define environ (*_NSGetEnviron ())
+#endif
+
 char **
 __gnat_environ (void)
 {
@@ -209,10 +214,10 @@  __gnat_environ (void)
 #elif defined (sun)
   extern char **_environ;
   return _environ;
-#elif ! (defined (__vxworks))
-  extern char **environ;
+#elif defined (__vxworks) || defined (__APPLE__)
   return environ;
 #else
+  extern char **environ;
   return environ;
 #endif
 }