public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Re: GCC Plugins and global_options
       [not found] ` <CAFiYyc2BKV2r+tD5iyC03XMqvwaQQ+3GZjn9PHDefFiVWA2iNg@mail.gmail.com>
@ 2020-08-24  8:37   ` Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2020-08-24  8:37 UTC (permalink / raw)
  To: Richard Biener, Nick Clifton; +Cc: gcc-patches

On Mon, Aug 24, 2020 at 09:23:58AM +0200, Richard Biener wrote:
> I'd say we ignore this since we do not provide any ABI stability guarantees.

While that is true, in reality the ABI doesn't change every other week on
release branches, especially the things that usual plugins care about.
We don't add randomly fields into the middle of core data structures all the
time etc.
The options are an exception, because they are generated using the scripts
and even a change completely unrelated to what the plugin cares about, say
addition of some target specific option, results in the whole struct
gcc_options being reshuffled.

As minimal patch, we'd need something like the patch below, which adds an
800 bytes long array and 1024 bytes in string literals, so 1824 .rodata
bytes in total.

If needed, this could be guarded by some configure option if those 1824
.rodata (0.02% of .rodata size) bytes is something that people don't want
to sacrifice for this.

2020-08-24  Jakub Jelinek  <jakub@redhat.com>

	* opts.h (struct cl_var): New type.
	(cl_vars): Declare.
	* optc-gen.awk: Generate cl_vars array.

--- gcc/opts.h.jj	2020-04-30 11:49:28.462900760 +0200
+++ gcc/opts.h	2020-08-24 10:21:08.563288412 +0200
@@ -124,6 +124,14 @@ struct cl_option
   int range_max;
 };
 
+struct cl_var
+{
+  /* Name of the variable.  */
+  const char *var_name;
+  /* Offset of field for this var in struct gcc_options.  */
+  unsigned short var_offset;
+};
+
 /* Records that the state of an option consists of SIZE bytes starting
    at DATA.  DATA might point to CH in some cases.  */
 struct cl_option_state {
@@ -134,6 +142,7 @@ struct cl_option_state {
 
 extern const struct cl_option cl_options[];
 extern const unsigned int cl_options_count;
+extern const struct cl_var cl_vars[];
 extern const char *const lang_names[];
 extern const unsigned int cl_lang_count;
 
--- gcc/optc-gen.awk.jj	2020-01-12 11:54:36.691409214 +0100
+++ gcc/optc-gen.awk	2020-08-24 10:19:49.410410288 +0200
@@ -592,5 +592,29 @@ for (i = 0; i < n_opts; i++) {
 }
 print "}               "
 
+split("", var_seen, ":")
+print "\n#ifndef GENERATOR_FILE"
+print "const struct cl_var cl_vars[] =\n{"
+
+for (i = 0; i < n_opts; i++) {
+	name = var_name(flags[i]);
+	if (name == "")
+		continue;
+	var_seen[name] = 1;
+}
+
+for (i = 0; i < n_extra_vars; i++) {
+	var = extra_vars[i]
+	sub(" *=.*", "", var)
+	name = var
+	sub("^.*[ *]", "", name)
+	sub("\\[.*\\]$", "", name)
+	if (name in var_seen)
+		continue;
+	print "  { " quote name quote ", offsetof (struct gcc_options, x_" name ") },"
+	var_seen[name] = 1
 }
 
+print "  { NULL, (unsigned short) -1 }\n};\n#endif"
+
+}


	Jakub


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-08-24  8:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20200813083818.GX2363@tucnak>
     [not found] ` <CAFiYyc2BKV2r+tD5iyC03XMqvwaQQ+3GZjn9PHDefFiVWA2iNg@mail.gmail.com>
2020-08-24  8:37   ` [PATCH] Re: GCC Plugins and global_options Jakub Jelinek

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