[modula2] v2 PR-108182 gm2 driver mishandles target and multilib options
Checks
Commit Message
Hi,
This is version 2 with the SKIPOPT applied to every option given to
save_switch.
ok for master? Bootstrapped on x86_64 gnu/linux and darwin.
regards,
Gaius
PR-108182 gm2 driver mishandles target and multilib options
here are some patches which attempt to allow target specific include
paths and library paths in the gm2 driver. I admit that the patch has
flaws in that it only processes options -f, -m in the lang_specific_driver.
[Called after driver::set_up_specs but before read_specs is called].
I suspect a better implementation might be to use a spec function
to fixup the paths.
gcc/ChangeLog:
* gcc.cc (save_switch): Remove static declaration.
(get_multilib_dir): New function.
(reset_mdswitches): New function.
* gcc/gcc.h (save_switch): Declare extern.
(get_multilib_dir): New extern.
(reset_mdswitches): New extern.
gcc/m2/ChangeLog:
* gm2spec.cc (lang_specific_driver): Detect -m and -f options and
call save_switch and SKIPOPT. Assign multilib_dir with the result
of get_multilib_dir. Call reset_mdswitches afterwards.
@@ -3849,7 +3849,7 @@ alloc_switch (void)
/* Save an option OPT with N_ARGS arguments in array ARGS, marking it
as validated if VALIDATED and KNOWN if it is an internal switch. */
-static void
+void
save_switch (const char *opt, size_t n_args, const char *const *args,
bool validated, bool known)
{
@@ -9559,6 +9559,24 @@ default_arg (const char *p, int len)
return 0;
}
+/* Return the value of multilib_dir. */
+
+const char *
+get_multilib_dir (void)
+{
+ set_multilib_dir ();
+ return multilib_dir;
+}
+
+/* Reset the mdswitches array to empty. */
+
+void
+reset_mdswitches (void)
+{
+ n_mdswitches = 0;
+ mdswitches = NULL;
+}
+
/* Work out the subdirectory to use based on the options. The format of
multilib_select is a list of elements. Each element is a subdirectory
name followed by a list of options followed by a semicolon. The format
@@ -73,6 +73,11 @@ struct spec_function
extern int do_spec (const char *);
extern void record_temp_file (const char *, int, int);
extern void set_input (const char *);
+extern const char *get_multilib_dir (void);
+extern void reset_mdswitches (void);
+extern void save_switch (const char *opt, size_t n_args,
+ const char *const *args,
+ bool validated, bool known);
/* Spec files linked with gcc.cc must provide definitions for these. */
@@ -797,8 +797,20 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options,
if ((decoded_options[i].orig_option_with_args_text != NULL)
&& (strncmp (decoded_options[i].orig_option_with_args_text,
"-m", 2) == 0))
- multilib_dir = xstrdup (decoded_options[i].orig_option_with_args_text
- + 2);
+ {
+ save_switch (decoded_options[i].orig_option_with_args_text,
+ 0, NULL, true, true);
+ args[i] |= SKIPOPT;
+ }
+ else if ((decoded_options[i].orig_option_with_args_text != NULL)
+ && (strncmp (decoded_options[i].orig_option_with_args_text,
+ "-f", 2) == 0))
+ {
+ save_switch (decoded_options[i].orig_option_with_args_text,
+ 0, NULL, true, true);
+ args[i] |= SKIPOPT;
+ }
+ break;
}
}
if (language != NULL && (strcmp (language, "modula-2") != 0))
@@ -864,10 +876,13 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options,
if ((! (seen_uselist || seen_gen_module_list)) && linking)
append_option (OPT_fgen_module_list_, "-", 1);
+ multilib_dir = get_multilib_dir ();
+ reset_mdswitches ();
if (allow_libraries)
{
/* If the libraries have not been specified by the user but the
- dialect has been specified then select the appropriate libraries. */
+ dialect has been specified then select the appropriate
+ libraries. */
if (libraries == NULL)
{
if (strcmp (dialect, "iso") == 0)