This is the mail archive of the
java-prs@gcc.gnu.org
mailing list for the Java project.
[Bug libgcj/38812] gcj-built executables don't run after strip (libgcj erroneously references _environ)
- From: "fxcoudert at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: java-prs at gcc dot gnu dot org
- Date: 17 May 2010 12:54:01 -0000
- Subject: [Bug libgcj/38812] gcj-built executables don't run after strip (libgcj erroneously references _environ)
- References: <bug-38812-17178@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #5 from fxcoudert at gcc dot gnu dot org 2010-05-17 12:53 -------
On Mac OS X (all versions), the correct fix is to use _NSGetEnviron() instead
of extern variable environ, and to include <crt_externs.h>. Example of use:
#include <stdlib.h>
#include <string.h>
#include <crt_externs.h>
int main (void)
{
// Instead of: extern char **environ;
#define environ (*_NSGetEnviron())
char **env = malloc (3 * sizeof(char *));
env[0] = strdup ("VAR1=this is variable one");
env[1] = strdup ("PATH=/dev/null");
env[2] = NULL;
environ = env;
system ("/usr/bin/env");
return 0;
}
(see http://www.gnu.org/software/gnulib/manual/html_node/environ.html)
So, a possible patch (protecting target-specific code with #idef's; I don't
know if that's the style libjava maintainers would like best) is:
Index: java/lang/natPosixProcess.cc
===================================================================
--- java/lang/natPosixProcess.cc (revision 159481)
+++ java/lang/natPosixProcess.cc (working copy)
@@ -54,7 +54,12 @@
using gnu::java::nio::channels::FileChannelImpl;
using namespace java::lang;
+#ifdef __APPLE__
+#include <crt_externs.h>
+#define environ (*_NSGetEnviron())
+#else
extern char **environ;
+#endif
static char *
new_string (jstring string)
--
fxcoudert at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |fxcoudert at gcc dot gnu dot
| |org, tromey at redhat dot
| |com, aph at redhat dot com
Last reconfirmed|2009-01-13 01:03:10 |2010-05-17 12:53:59
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38812