From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19536 invoked by alias); 17 May 2010 12:54:03 -0000 Received: (qmail 19514 invoked by uid 48); 17 May 2010 12:54:01 -0000 Date: Mon, 17 May 2010 12:54:00 -0000 Message-ID: <20100517125401.19509.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug libgcj/38812] gcj-built executables don't run after strip (libgcj erroneously references _environ) In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: java-prs@gcc.gnu.org From: "fxcoudert at gcc dot gnu dot org" Mailing-List: contact java-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: java-prs-owner@gcc.gnu.org X-SW-Source: 2010-q2/txt/msg00053.txt.bz2 ------- 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 . Example of use: #include #include #include 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 +#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