public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH, modula2] PR-108182 gm2 driver mishandles target and multilib options
@ 2023-01-06 21:42 Gaius Mulley
  2023-01-07 10:59 ` Iain Sandoe
  0 siblings, 1 reply; 3+ messages in thread
From: Gaius Mulley @ 2023-01-06 21:42 UTC (permalink / raw)
  To: GCC Patches; +Cc: Iain Sandoe


Hi,

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

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)
--------

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH, modula2] PR-108182 gm2 driver mishandles target and multilib options
  2023-01-06 21:42 [PATCH, modula2] PR-108182 gm2 driver mishandles target and multilib options Gaius Mulley
@ 2023-01-07 10:59 ` Iain Sandoe
  0 siblings, 0 replies; 3+ messages in thread
From: Iain Sandoe @ 2023-01-07 10:59 UTC (permalink / raw)
  To: Gaius Mulley; +Cc: GCC Patches



> 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)
> --------


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH, modula2] PR-108182 gm2 driver mishandles target and multilib options
@ 2023-01-06 21:58 Gaius Mulley
  0 siblings, 0 replies; 3+ messages in thread
From: Gaius Mulley @ 2023-01-06 21:58 UTC (permalink / raw)
  To: GCC Patches



ChangeLog entry follows:

regards,
Gaius



[PATCH, modula2] 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 include a language callback
(lang_post_spec) which could fixup target related 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.  Assign multilib_dir with the result of
	get_multilib_dir.  Call reset_mdswitches afterwards.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-01-07 11:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-06 21:42 [PATCH, modula2] PR-108182 gm2 driver mishandles target and multilib options Gaius Mulley
2023-01-07 10:59 ` Iain Sandoe
2023-01-06 21:58 Gaius Mulley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).