I need help for changing the java driver (gcj and libs with a main())

Bryce McKinlay bryce@waitaki.otago.ac.nz
Mon May 7 22:47:00 GMT 2001

Martin Kahlert wrote:

> b) do something similar like Fortran: put a main() into libgcj and call the generated
>     __MAIN__JAVA__ (which one will win if i do the above gcj command???)

This ought to work, but could it cause problems for people who want to use a C main
method and the not-yet-implemented invocation API? On linux it would be okay, since the
application's main will override the one in the shared library, but is that portable? An
alternative would be to pass the main class name as a java property. jvgenmain would
still be required, and I'm not entirely sure about portability of the property mechanism

> c) Put lang_specific_pre_link at the beginning of the argument processing in
>    gcc.c, so the generated_main.o will become outfiles[0]

pre_link sort of implies that it is run after all other files have been processed.
Perhaps a new lang_specific_pre_compile (or whatever) could be added?

> d) Define another function (which has to be provided by all languages) which
>    generates additional object files (not libraries) and call that early in
>    gcc.c before the libs have a chance to show up.


> I would be glad to hear some ideas from you gurus, since i am very new to
> coding for gcc.

This nasty hack will do the trick. I leave it as an exercise for the reader to come up
with something more tasteful ;-)


  [ bryce ]

Index: jvspec.c
RCS file: /cvs/gcc/gcc/gcc/java/jvspec.c,v
retrieving revision 1.41
diff -u -r1.41 jvspec.c
--- jvspec.c    2001/04/29 11:24:37     1.41
+++ jvspec.c    2001/05/08 05:23:17
@@ -522,12 +522,26 @@
   *in_added_libraries = added_libraries;

+extern const char **outfiles;
+extern int input_file_number;
 lang_specific_pre_link ()
+  const char *jvgenmain_outfile;
+  int i;
   if (main_class_name == NULL)
     return 0;
   input_filename = main_class_name;
   input_filename_length = strlen (main_class_name);
-  return do_spec (jvgenmain_spec);
+  if (do_spec (jvgenmain_spec))
+    return -1;
+  jvgenmain_outfile = outfiles[input_file_number];
+  for (i = input_file_number - 1; i >= 0; --i)
+    {
+      outfiles[i + 1] = outfiles[i];
+    }
+  outfiles[0] = jvgenmain_outfile;
+  return 0;

More information about the Java mailing list