Problem with main routine during linking

Martin Kahlert martin.kahlert@infineon.com
Mon May 7 23:37:00 GMT 2001


Hi,
thanks for the patch, this was in fact the thing i tried (see the thread
I need help for changing the java driver (gcj and libs with a main()) in 
the java-mailing list) except that i wanted that to go into gcc.c instead of
jvspec.c.
I tried your patch and it works for me, but i do not consider this patch
a nice one; it's some kind of a quick hack:
- it makes internal variables of the general build process public just for
 one specific language
- it does not solve David Billinghurst's Problem with main in cygwin libs
So my question is this: Should there be a general function 
(bryce suggested lang_specific_pre_compile()) for all languages,
which produces additional objects?
Does it do any harm, if we sort the -l options towards the end of outfiles 
*inside gcc.c* before linking?
Thanks,
Martin.
On Mon, May 07, 2001 at 11:20:49PM -0700, Per Bothner wrote:
> 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;
> }
>
-- 
The early bird gets the worm. If you want something else for 
breakfast, get up later.


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /