> On 6 Jan 2023, at 21:42, Gaius Mulley via Gcc-patches
> <gcc-patches@gcc.gnu.org> wrote:
>
> 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 include a language callback
> (lang_post_spec) which could fixup target related paths.
>
> Nevertheless as a stage3 bugfix (workaround) they are presented below:
>
> I wonder if they would be suitable for master?
>
> Tested on Darwin (prior cleanup) and X86_64 Linux
retested this on Darwin, still fixes the issue.
Iain
>
> regards,
> Gaius
>
> ----- o< ----- o< ----- o< ----- o< ----- o< ----- o< ----- o< ----- o<
> diff --git a/gcc/gcc.cc b/gcc/gcc.cc
> index d629ca5e424..362a6a96b63 100644
> --- a/gcc/gcc.cc
> +++ b/gcc/gcc.cc
> @@ -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
> diff --git a/gcc/gcc.h b/gcc/gcc.h
> index 19a61b373ee..03646ff2d87 100644
> --- a/gcc/gcc.h
> +++ b/gcc/gcc.h
> @@ -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. */
>
> diff --git a/gcc/m2/gm2spec.cc b/gcc/m2/gm2spec.cc
> index 583723da416..dbfd1cacccc 100644
> --- a/gcc/m2/gm2spec.cc
> +++ b/gcc/m2/gm2spec.cc
> @@ -797,8 +797,14 @@ 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);
> + 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);
> + break;
> }
> }
> if (language != NULL && (strcmp (language, "modula-2") != 0))
> @@ -864,10 +870,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)
> --------