public inbox for java-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug libgcj/38812]  New: gcj-built executables don't run after strip (libgcj erroneously references _environ)
@ 2009-01-12 11:29 pkeller at globalphasing dot com
  2009-01-12 11:30 ` [Bug libgcj/38812] " pkeller at globalphasing dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: pkeller at globalphasing dot com @ 2009-01-12 11:29 UTC (permalink / raw)
  To: java-prs

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


^ permalink raw reply	[flat|nested] 8+ messages in thread
[parent not found: <bug-38812-8172@http.gcc.gnu.org/bugzilla/>]

end of thread, other threads:[~2015-09-03 18:03 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-01-12 11:29 [Bug libgcj/38812] New: gcj-built executables don't run after strip (libgcj erroneously references _environ) pkeller at globalphasing dot com
2009-01-12 11:30 ` [Bug libgcj/38812] " pkeller at globalphasing dot com
2009-01-12 11:31 ` pkeller at globalphasing dot com
2009-01-13  1:03 ` pinskia at gcc dot gnu dot org
2009-01-13 11:26 ` pkeller at globalphasing dot com
2010-05-17 12:54 ` fxcoudert at gcc dot gnu dot org
     [not found] <bug-38812-8172@http.gcc.gnu.org/bugzilla/>
2015-06-11  0:16 ` egall at gwmail dot gwu.edu
2015-09-03 18:03 ` egall at gwmail dot gwu.edu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).