public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Richard Biener <richard.guenther@gmail.com>,
	Nick Clifton <nickc@redhat.com>
Cc: gcc-patches@gcc.gnu.org
Subject: [PATCH] Re: GCC Plugins and global_options
Date: Mon, 24 Aug 2020 10:37:17 +0200	[thread overview]
Message-ID: <20200824083717.GL2363@tucnak> (raw)
In-Reply-To: <CAFiYyc2BKV2r+tD5iyC03XMqvwaQQ+3GZjn9PHDefFiVWA2iNg@mail.gmail.com>

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


           reply	other threads:[~2020-08-24  8:37 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <CAFiYyc2BKV2r+tD5iyC03XMqvwaQQ+3GZjn9PHDefFiVWA2iNg@mail.gmail.com>]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200824083717.GL2363@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=nickc@redhat.com \
    --cc=richard.guenther@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).