[PATCH/committed] sim: switch to libiberty environ.h

Mike Frysinger vapier@gentoo.org
Sat May 15 14:59:51 GMT 2021


Drop our compat code and assume environ exists to simplify.
---
 sim/common/ChangeLog |  6 ++++++
 sim/common/nrun.c    |  9 +--------
 sim/cris/ChangeLog   |  6 ++++++
 sim/cris/sim-if.c    | 21 +++++----------------
 4 files changed, 18 insertions(+), 24 deletions(-)

diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog
index b360ebdd759a..b221166212aa 100644
--- a/sim/common/ChangeLog
+++ b/sim/common/ChangeLog
@@ -1,3 +1,9 @@
+2021-05-15  Mike Frysinger  <vapier@gentoo.org>
+
+	* nrun.c: Include environ.h.
+	(environ): Delete prototype.
+	(main): Delete HAVE_ENVIRON check.
+
 2021-05-14  Mike Frysinger  <vapier@gentoo.org>
 
 	* callback.c (os_lseek): Change return and 3rd arg to int64_t.
diff --git a/sim/common/nrun.c b/sim/common/nrun.c
index 1ceb0837e2c2..8a1b3c19acc1 100644
--- a/sim/common/nrun.c
+++ b/sim/common/nrun.c
@@ -27,16 +27,13 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 #include "sim-main.h"
 
 #include "bfd.h"
+#include "environ.h"
 
 #ifndef HAVE_STRSIGNAL
 /* While libiberty provides a fallback, it doesn't provide a prototype.  */
 extern const char *strsignal (int);
 #endif
 
-#ifdef HAVE_ENVIRON
-extern char **environ;
-#endif
-
 #ifdef HAVE_UNISTD_H
 /* For chdir.  */
 #include <unistd.h>
@@ -133,11 +130,7 @@ main (int argc, char **argv)
     exit (1);
 
   /* Prepare the program for execution.  */
-#ifdef HAVE_ENVIRON
   sim_create_inferior (sd, prog_bfd, prog_argv, environ);
-#else
-  sim_create_inferior (sd, prog_bfd, prog_argv, NULL);
-#endif
 
   /* To accommodate relative file paths, chdir to sysroot now.  We
      mustn't do this until BFD has opened the program, else we wouldn't
diff --git a/sim/cris/ChangeLog b/sim/cris/ChangeLog
index 68cd0bfd52cf..7dfc8873275f 100644
--- a/sim/cris/ChangeLog
+++ b/sim/cris/ChangeLog
@@ -1,3 +1,9 @@
+2021-05-15  Mike Frysinger  <vapier@gentoo.org>
+
+	* sim-if.c: Include environ.h.
+	(environ, GET_ENVIRON): Delete.
+	(sim_open): Replace my_environ with environ.
+
 2021-05-14  Mike Frysinger  <vapier@gentoo.org>
 
 	* traps.c (cris_break_13_handler): Delete 2nd arg to time callback.
diff --git a/sim/cris/sim-if.c b/sim/cris/sim-if.c
index edd7885caf70..388d1ef89627 100644
--- a/sim/cris/sim-if.c
+++ b/sim/cris/sim-if.c
@@ -30,16 +30,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <errno.h>
 #include "sim-options.h"
 #include "dis-asm.h"
-
-/* Apparently the autoconf bits are missing (though HAVE_ENVIRON is used
-   in other dirs; also lacking there).  Patch around it for major systems.  */
-#if defined (HAVE_ENVIRON) || defined (__GLIBC__)
-extern char **environ;
-#define GET_ENVIRON() environ
-#else
-char *missing_environ[] = { "SHELL=/bin/sh", "PATH=/bin:/usr/bin", NULL };
-#define GET_ENVIRON() missing_environ
-#endif
+#include "environ.h"
 
 /* Used with get_progbounds to find out how much memory is needed for the
    program.  We don't want to allocate more, since that could mask
@@ -747,7 +738,6 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
   if (abfd != NULL && !cris_bare_iron)
     {
       const char *name = bfd_get_filename (abfd);
-      char **my_environ = GET_ENVIRON ();
       /* We use these maps to give the same behavior as the old xsim
 	 simulator.  */
       USI envtop = 0x40000000;
@@ -764,8 +754,8 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
       bfd_byte buf[4];
 
       /* Count in the environment as well. */
-      for (envc = 0; my_environ[envc] != NULL; envc++)
-	len += strlen (my_environ[envc]) + 1;
+      for (envc = 0; environ[envc] != NULL; envc++)
+	len += strlen (environ[envc]) + 1;
 
       for (i = 0; prog_argv[i] != NULL; my_argc++, i++)
 	len += strlen (prog_argv[i]) + 1;
@@ -849,10 +839,9 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, struct bfd *abfd,
 
       for (i = 0; i < envc; i++, csp += 4)
 	{
-	  unsigned int strln = strlen (my_environ[i]) + 1;
+	  unsigned int strln = strlen (environ[i]) + 1;
 
-	  if (sim_core_write_buffer (sd, NULL, NULL_CIA, my_environ[i], epp,
-				     strln)
+	  if (sim_core_write_buffer (sd, NULL, NULL_CIA, environ[i], epp, strln)
 	      != strln)
 	    goto abandon_chip;
 
-- 
2.31.1



More information about the Gdb-patches mailing list