From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31079 invoked by alias); 12 Jan 2009 11:29:09 -0000 Received: (qmail 31061 invoked by uid 48); 12 Jan 2009 11:29:09 -0000 Date: Mon, 12 Jan 2009 11:29:00 -0000 Subject: [Bug libgcj/38812] New: gcj-built executables don't run after strip (libgcj erroneously references _environ) X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: java-prs@gcc.gnu.org From: "pkeller at globalphasing dot com" 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: 2009-q1/txt/msg00021.txt.bz2 On OS X 10.5 (Leopard), compile/link HelloWorld: class HelloWorld { static public void main( String args[] ) { System.out.println( "Hello World!" ); } } as follows: gcj --main=HelloWorld HelloWorld.java Then strip and run a.out: strip a.out ./a.out dyld: Symbol not found: _environ Referenced from: /public/sw/gcc-4.3.2/Darwin-i386-buildhost2/lib/libgcj.9.dylib Expected in: flat namespace Trace/BPT trap Applying the following patch and rebuilding libgcj.9.dylib fixes the problem: --- libjava/java/lang/natPosixProcess.cc.orig 2009-01-08 17:06:14.000000000 +0000 +++ libjava/java/lang/natPosixProcess.cc 2009-01-09 21:13:34.000000000 +0000 @@ -54,7 +54,6 @@ using gnu::java::nio::channels::FileChannelImpl; using namespace java::lang; -extern char **environ; static char * new_string (jstring string) @@ -371,8 +370,16 @@ if (pid_tmp == 0) { // Child process, so remap descriptors, chdir and exec. - if (envp) - environ = env; + if (envp) { + for ( char *p, *e = *env; *e; e++ ) { + p=index(e, '='); + if ( p ) { + *p = '\0'; + setenv (e, p+1, 1); + *p = '='; + } + } + } // We ignore errors from dup2 because they should never occur. dup2 (outp[0], 0); More information: the OS X man page for environ(7) says: Shared libraries and bundles don't have direct access to environ, which is only available to the loader ld(1) when a complete program is being linked. -- Summary: gcj-built executables don't run after strip (libgcj erroneously references _environ) Product: gcc Version: 4.3.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libgcj AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: pkeller at globalphasing dot com GCC build triplet: i386-apple-darwin9.5.0 GCC host triplet: i386-apple-darwin9.5.0 GCC target triplet: i386-apple-darwin9.5.0 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38812