This is the mail archive of the java@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]

Re: Problem with main routine during linking


Could people try the following?

Index: gcc.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gcc.c,v
retrieving revision 1.205.2.10
diff -u -p -r1.205.2.10 gcc.c
--- gcc.c	2001/05/01 18:56:21	1.205.2.10
+++ gcc.c	2001/05/08 05:58:42
@@ -2801,7 +2801,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.  */
@@ -2810,7 +2810,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;
@@ -3871,7 +3871,7 @@ process_command (argc, argv)
    of characters starting there excluding the suffix .c or whatever.  */
 
 const char *input_filename;
-static int input_file_number;
+int input_file_number;
 size_t input_filename_length;
 static int basename_length;
 static int suffixed_basename_length;
Index: gcc.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gcc.h,v
retrieving revision 1.3.6.1
diff -u -p -r1.3.6.1 gcc.h
--- gcc.h	2001/03/17 19:56:09	1.3.6.1
+++ gcc.h	2001/05/08 05:58:42
@@ -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: java/jvspec.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/jvspec.c,v
retrieving revision 1.35.2.4
diff -u -p -r1.35.2.4 jvspec.c
--- jvspec.c	2001/04/29 11:26:30	1.35.2.4
+++ jvspec.c	2001/05/08 05:58:42
@@ -524,9 +524,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]