On 8 Jan 2015, at 13:52, Tristan Gingold wrote: > >> On 08 Jan 2015, at 13:49, Iain Sandoe <i...@codesourcery.com> wrote: >> >> 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 <ging...@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? > > Yes you're right. The added code should have been added after the #endif for > IN_RTS.
How about this? It uses the interface where needed, avoids it for main exes and gets rid of the negative conditional (which IMO makes the code a little more readable). Iain P.S. this is not Darwin9/10 - specific the only reason it doesn't fail on Darwin >= 11 is because they default to -undefined dynamic_lookup .. and so find the symbol from the exe. ==== ada: PR ada/64349 * env.c (__gnat_environ): Adjust environ access for Darwin. Index: gcc/ada/env.c =================================================================== --- gcc/ada/env.c (revision 219325) +++ gcc/ada/env.c (working copy) @@ -215,12 +215,12 @@ #elif defined (sun) extern char **_environ; return _environ; -#elif ! (defined (__vxworks)) - extern char **environ; +#elif defined (IN_RTS) && defined (__APPLE__) && !defined (__arm__) + return *_NSGetEnviron (); +#elif defined (__vxworks) return environ; -#elif defined (__APPLE__) && !defined (__arm__) - return *_NSGetEnviron (); #else + extern char **environ; return environ; #endif }