[Bug ada/33857] Cannot bootstrap Ada with host gnatmake-4.2

2008-02-27 Thread charles dot w dot lambert at gmail dot com


--- Comment #2 from charles dot w dot lambert at gmail dot com  2008-02-27 
16:32 ---
I can confirm this bug against gcc 4.2.3 and gcc 4.3.0 on os x (10.5.2).
Apparently apple has changed the way that putenv is handled. From the `man 3 
getenv` page i quote:
"COMPATIBILITY
 putenv() no longer copies its input buffer.  This often appears in crash
logs as a
 crash in getenv().  Avoid passing local buffers or freeing the memory that
is passed
 to putenv().  Use setenv(), which still makes an internal copy of its
buffers."

I have examined the source code and found the error to be in the file
/gcc/ada/env.c near line 179 in __gnat_setenv() with the following
code:
179:  putenv (expression);
180: #if (defined (__FreeBSD__) && (__FreeBSD__ < 7)) \
181:   || defined (__APPLE__) || defined (__MINGW32__) \
182:   ||(defined (__vxworks) && ! defined (__RTP__))
183:  /* On some systems like FreeBSD 6.x and earlier, MacOS X and Windows,
184: putenv is making a copy of the expression string so we can free
185: it after the call to putenv */
186:  free (expression);
187:#endif

On current versions of OS X (10.5 on my system). This call to free on line 186
is causing all calls to getenv() after calling __gnat_setenv() to return NULL

This happens when calling gnatmake during the Initialize procedure in make.adb
near line
6645 with the following code:
6645:   declare
6646:  PATH : constant String :=
6647:   Prefix & Directory_Separator & "bin" &
6648:   Path_Separator &
6649:   Getenv ("PATH").all;
6650:   begin
6651:  Setenv ("PATH", PATH);
6652:   end;

Setenv here is located in /gcc/ada/s-os_lib.adb near line 2285
Setenv imports __gnat_setenv

I can confirm that removing the call to free fixes the problem in this bug
report. However i do not know  what proper preprocessor flags to use.


-- 

charles dot w dot lambert at gmail dot com changed:

   What|Removed |Added
--------------------
     CC||charles dot w dot lambert at
   ||gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33857



[Bug ada/33857] Cannot bootstrap Ada with host gnatmake-4.2

2008-02-27 Thread charles dot w dot lambert at gmail dot com


--- Comment #4 from charles dot w dot lambert at gmail dot com  2008-02-27 
18:16 ---
I agree, what flags can be used to determine when to use it?
I used
...
#elif (defined (__vxworks) && defined (__RTP__)) \
   || (defined (__i386__) && (__APPLE__))
  setenv (name, value, 1);

#else
...
but i know that is most likely not the correct fix. If someone could verify
that setenv copies the input buffer on all versions of OS X then it could
simply be changed to
...
#elif (defined (__vxworks) && defined (__RTP__)) \
   || defined (__APPLE__)
  setenv (name, value, 1);

#else
...


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33857



[Bug ada/33857] Cannot bootstrap Ada with host gnatmake-4.2

2008-02-27 Thread charles dot w dot lambert at gmail dot com


--- Comment #5 from charles dot w dot lambert at gmail dot com  2008-02-27 
18:20 ---
I also forgot to add that changing to
...
#elif (defined (__vxworks) && defined (__RTP__)) \
   || defined (__APPLE__)
  setenv (name, value, 1);

#else
...
would involve changing
...
  putenv (expression);
#if (defined (__FreeBSD__) && (__FreeBSD__ < 7)) \
   || defined (__APPLE__) || defined (__MINGW32__) \
   ||(defined (__vxworks) && ! defined (__RTP__))
  /* On some systems like FreeBSD 6.x and earlier, MacOS X and Windows,
 putenv is making a copy of the expression string so we can free
 it after the call to putenv */
  free (expression);
#endif
...
to
...
  putenv (expression);
#if (defined (__FreeBSD__) && (__FreeBSD__ < 7)) \
   defined (__MINGW32__) \
   ||(defined (__vxworks) && ! defined (__RTP__))
  /* On some systems like FreeBSD 6.x and earlier, and Windows,
 putenv is making a copy of the expression string so we can free
 it after the call to putenv */
  free (expression);
#endif
...


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33857