]> git.ipfire.org Git - thirdparty/gcc.git/commit
ada: Stop using gnat_envp
authorRonan Desplanques <desplanques@adacore.com>
Tue, 17 Mar 2026 14:38:44 +0000 (15:38 +0100)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Fri, 29 May 2026 08:49:48 +0000 (10:49 +0200)
commitcf703b60e49d39d3ea80f3c23c490bf005481caf
treec4c82873f71dd768ccc348f5eeaa04bd652c44a0
parent99574f2500631b48c2d267bbb53421b8c5986516
ada: Stop using gnat_envp

First, a bit of context: Ada has only had support for manipulating
environment variables in the standard library since Ada 2005 and the
introduction of Ada.Environment_Variables.

Prior to that, GNAT had introduced the implementation-specific
Ada.Command_Line.Environment, which still exists today. Until now,
Ada.Command_Line.Environment used a global variable, gnat_envp, which
must be initialized with envp, the optional third parameter to main in C.
When the main was in Ada, the binder generated the appropriate assignment.
The rest of the time, it was the responsibility of the user to write this
assignment. Failure to do so would cause null pointer dereferences when
using Ada.Command_Line.Environment. Although documented in the spec of
Ada.Command_Line, this was rather easy to miss.

Worse, the assignment caused linking failures in the rather common case
of a C GPR project with'ing an Ada GPR project and linking dynamically.

Also, Ada.Command_Line.Environment was inconsistent across platforms with
regard to how it was affected by calls to putenv.

When we added support for the standard Ada.Environment_Variables, the
gnat_envp machinery wasn't reused. Instead, another mechanism based on
the Unix global variable environ (and its close equivalents on other
platforms) was introduced.

What this patch does is switch Ada.Command_Line.Environment over to this
new environ-based mechanism. All uses of gnat_envp are removed, but the
definition itself is kept for backwards compatibility.

gcc/ada/ChangeLog:

* argv-lynxos178-raven-cert.c: Update comments.
* argv.c (gnat_envp): Add comment about it being unused.
(__gnat_env_count, __gnat_len_env, __gnat_fill_env): Use
__gnat_environ instead of gnat_envp.
* bindgen.adb (Command_Line_Used): Update comment.
(Gen_Main): Remove gnat_envp assignment generation. Remove generated
envp parameter.
(Gen_Output_File_Ada): Remove generated envp parameter.
* env.h: Make usable as C++.
* libgnat/a-colien.ads: Remove comment.
* libgnat/a-comlin.ads: Update comment.
* targparm.ads: Update comment.
gcc/ada/argv-lynxos178-raven-cert.c
gcc/ada/argv.c
gcc/ada/bindgen.adb
gcc/ada/env.h
gcc/ada/libgnat/a-colien.ads
gcc/ada/libgnat/a-comlin.ads
gcc/ada/targparm.ads