This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libgcj/38812] New: gcj-built executables don't run after strip (libgcj erroneously references _environ)


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]