This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


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

another patch to gcc.[hc] and jvspec.c


When gcj generates a main program, it gets added to the end of the
linker command line.  This causes some problems (see "Problem with
main routine during linking" in the java mailing list): We cannot do
static linking, since no symbols are needed until we get to the end of
the linker list, at which point it is too late, and we fail.  Another
problem is that an incorrect "main" may get pulled in from a library.

This particular patch isn't the cleanest.  It needs to break/extend
the abstraction interface between gcj and the lang-specific drivers,
but I don't see a problem with that, as it's not a very "abstract"
interface anyway.  At least this is a relatively simple change.

Mark, is this ok for the branch and the trunk?

        Changes needed for java/jvspec.c
        * gcc.h (n_infiles, outfiles):  Add declarations.
        * gcc.c (n_infiles, outfiles):  Mske no longer static.

Index: gcc.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gcc.h,v
retrieving revision 1.4
diff -u -p -r1.4 gcc.h
--- gcc.h	2001/02/24 03:20:18	1.4
+++ gcc.h	2001/05/15 23:19:08
@@ -42,7 +42,13 @@ extern void lang_specific_driver PARAMS 
 /* Called before linking.  Returns 0 on success and -1 on failure. */
 extern int lang_specific_pre_link PARAMS ((void));
 
+extern int n_infiles;
+
 /* Number of extra output files that lang_specific_pre_link may generate. */
 extern int lang_specific_extra_outfiles;
+
+/* A vector of corresponding output files is made up later.  */
+
+extern const char **outfiles;
 
 #endif /* ! __GCC_H__ */
Index: gcc.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gcc.c,v
retrieving revision 1.227
diff -u -p -r1.227 gcc.c
--- gcc.c	2001/05/15 01:45:10	1.227
+++ gcc.c	2001/05/15 23:19:12
@@ -2804,7 +2804,7 @@ struct infile
 
 static struct infile *infiles;
 
-static int n_infiles;
+int n_infiles;
 
 /* This counts the number of libraries added by lang_specific_driver, so that
    we can tell if there were any user supplied any files or libraries.  */
@@ -2813,7 +2813,7 @@ static int added_libraries;
 
 /* And a vector of corresponding output files is made up later.  */
 
-static const char **outfiles;
+const char **outfiles;
 
 /* Used to track if none of the -B paths are used.  */
 static int warn_B;

        * jvspec.c (lang_specific_pre_link):  Re-arrange the linker
        command line so the jvgenmain-generated main program comes first.

Index: java/jvspec.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/jvspec.c,v
retrieving revision 1.41
diff -u -p -r1.41 jvspec.c
--- jvspec.c	2001/04/29 11:24:37	1.41
+++ jvspec.c	2001/05/15 23:19:13
@@ -525,9 +525,23 @@ lang_specific_driver (in_argc, in_argv, 
 int
 lang_specific_pre_link ()
 {
+  int err;
   if (main_class_name == NULL)
     return 0;
   input_filename = main_class_name;
   input_filename_length = strlen (main_class_name);
-  return do_spec (jvgenmain_spec);
+  err = do_spec (jvgenmain_spec);
+  if (err == 0)
+    {
+      /* Shift the outfiles array so the generated main comes first.
+	 This is important when linking against (non-shared) libraries,
+	 since otherwise we risk (a) nothing getting linked or
+	 (b) 'main' getting picked up from a library. */
+      int i = n_infiles;
+      const char *generated = outfiles[i];
+      while (--i >= 0)
+	outfiles[i + 1] = outfiles[i];
+      outfiles[0] = generated;
+    }
+  return err;
 }

-- 
	--Per Bothner
per@bothner.com   http://www.bothner.com/per/


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