public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Martin Liška" <mliska@suse.cz>
To: Jan Hubicka <hubicka@ucw.cz>
Cc: Richard Biener <richard.guenther@gmail.com>,
	Thomas Koenig <tkoenig@netcologne.de>,
	Andrew Pinski <pinskia@gmail.com>, Jeff Law <law@redhat.com>,
	GCC Development <gcc@gcc.gnu.org>,
	GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] Add .gnu.lto_.meta section.
Date: Fri, 21 Jun 2019 14:01:00 -0000	[thread overview]
Message-ID: <cfd510ba-59b9-d2fa-a49e-c562cc422713@suse.cz> (raw)
In-Reply-To: <20190621125718.qv2m5iygqj2b43fe@kam.mff.cuni.cz>

[-- Attachment #1: Type: text/plain, Size: 619 bytes --]

On 6/21/19 2:57 PM, Jan Hubicka wrote:
> This looks like good step (and please stream it in host independent
> way). I suppose all these issues can be done one-by-one.

So there's a working patch for that. However one will see following errors
when using an older compiler or older LTO bytecode:

$ gcc main9.o -flto
lto1: fatal error: bytecode stream in file ‘main9.o’ generated with LTO version -25480.4493 instead of the expected 9.0

$ gcc main.o
lto1: internal compiler error: compressed stream: data error

To be honest, I would prefer the new .gnu.lto_.meta section.
Richi why is that so ugly?

Martin

[-- Attachment #2: 0001-Come-up-with-ELF-LTO-section-header.patch --]
[-- Type: text/x-patch, Size: 5453 bytes --]

From cbba4d8209bfeed11856baeaa2f82e44d93f4cb7 Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
Date: Fri, 21 Jun 2019 15:57:08 +0200
Subject: [PATCH] Come up with ELF LTO section header.

---
 gcc/lto-section-in.c   | 14 +++++++++++---
 gcc/lto-section-out.c  | 16 ++++++++++++++--
 gcc/lto-streamer-out.c | 12 ++++--------
 gcc/lto-streamer.h     | 14 +++++++++++---
 4 files changed, 40 insertions(+), 16 deletions(-)

diff --git a/gcc/lto-section-in.c b/gcc/lto-section-in.c
index 4cfc0cad4be..28dfb412b67 100644
--- a/gcc/lto-section-in.c
+++ b/gcc/lto-section-in.c
@@ -143,6 +143,17 @@ lto_get_section_data (struct lto_file_decl_data *file_data,
   if (data == NULL)
     return NULL;
 
+  /* First check LTO section header.  */
+  if (*len < sizeof(lto_section_header))
+    return NULL;
+
+  const lto_section_header *sh = (const lto_section_header *)data;
+  lto_check_version (sh->major_version, sh->minor_version,
+		     file_data->file_name);
+
+  data += sizeof (lto_section_header);
+  *len -= sizeof (lto_section_header);
+
   /* WPA->ltrans streams are not compressed with exception of function bodies
      and variable initializers that has been verbatim copied from earlier
      compilations.  */
@@ -167,9 +178,6 @@ lto_get_section_data (struct lto_file_decl_data *file_data,
       data = buffer.data + header_length;
     }
 
-  lto_check_version (((const lto_header *)data)->major_version,
-		     ((const lto_header *)data)->minor_version,
-		     file_data->file_name);
   return data;
 }
 
diff --git a/gcc/lto-section-out.c b/gcc/lto-section-out.c
index c91e58f0465..9417bc9c174 100644
--- a/gcc/lto-section-out.c
+++ b/gcc/lto-section-out.c
@@ -81,6 +81,19 @@ lto_begin_section (const char *name, bool compress)
     compression_stream = lto_start_compression (lto_append_data, NULL);
 }
 
+/* Emit section header with LTO bytecode version and information about used
+   compression.  */
+
+void lto_emit_section_header (void)
+{
+  lto_compression compression = RAW;
+  if (compression_stream != NULL)
+    compression = ZLIB;
+
+  lto_section_header header
+    = { LTO_major_version, LTO_minor_version, compression };
+  lto_write_raw_data (&header, sizeof header);
+}
 
 /* End the current output section.  */
 
@@ -285,8 +298,7 @@ lto_destroy_simple_output_block (struct lto_simple_output_block *ob)
   /* Write the header which says how to decode the pieces of the
      t.  */
   memset (&header, 0, sizeof (struct lto_simple_header));
-  header.major_version = LTO_major_version;
-  header.minor_version = LTO_minor_version;
+  lto_emit_section_header ();
   header.main_size = ob->main_stream->total_size;
   lto_write_data (&header, sizeof header);
 
diff --git a/gcc/lto-streamer-out.c b/gcc/lto-streamer-out.c
index b1084f4d3c5..42f03ac504e 100644
--- a/gcc/lto-streamer-out.c
+++ b/gcc/lto-streamer-out.c
@@ -1973,8 +1973,7 @@ produce_asm (struct output_block *ob, tree fn)
   memset (&header, 0, sizeof (struct lto_function_header));
 
   /* Write the header.  */
-  header.major_version = LTO_major_version;
-  header.minor_version = LTO_minor_version;
+  lto_emit_section_header ();
 
   if (section_type == LTO_section_function_body)
     header.cfg_size = ob->cfg_stream->total_size;
@@ -2269,8 +2268,7 @@ lto_output_toplevel_asms (void)
   memset (&header, 0, sizeof (header));
 
   /* Write the header.  */
-  header.major_version = LTO_major_version;
-  header.minor_version = LTO_minor_version;
+  lto_emit_section_header ();
 
   header.main_size = ob->main_stream->total_size;
   header.string_size = ob->string_stream->total_size;
@@ -2826,8 +2824,7 @@ lto_write_mode_table (void)
   memset (&header, 0, sizeof (header));
 
   /* Write the header.  */
-  header.major_version = LTO_major_version;
-  header.minor_version = LTO_minor_version;
+  lto_emit_section_header ();
 
   header.main_size = ob->main_stream->total_size;
   header.string_size = ob->string_stream->total_size;
@@ -2899,8 +2896,7 @@ produce_asm_for_decls (void)
       lto_output_decl_state_streams (ob, fn_out_state);
     }
 
-  header.major_version = LTO_major_version;
-  header.minor_version = LTO_minor_version;
+  lto_emit_section_header ();
 
   /* Currently not used.  This field would allow us to preallocate
      the globals vector, so that it need not be resized as it is extended.  */
diff --git a/gcc/lto-streamer.h b/gcc/lto-streamer.h
index d087cba9bf0..8fc1ac01356 100644
--- a/gcc/lto-streamer.h
+++ b/gcc/lto-streamer.h
@@ -378,18 +378,25 @@ public:
   unsigned int len;
 };
 
+enum lto_compression
+{
+  RAW,
+  ZLIB,
+  ZSTD
+};
 
 /* The is the first part of the record for a function or constructor
    in the .o file.  */
-struct lto_header
+struct lto_section_header
 {
   int16_t major_version;
-  int16_t minor_version;
+  int16_t minor_version : 14;
+  lto_compression compression : 2;
 };
 
 /* The is the first part of the record in an LTO file for many of the
    IPA passes.  */
-struct lto_simple_header : lto_header
+struct lto_simple_header
 {
   /* Size of main gimple body of function.  */
   int32_t main_size;
@@ -784,6 +791,7 @@ extern void lto_value_range_error (const char *,
 
 /* In lto-section-out.c  */
 extern void lto_begin_section (const char *, bool);
+extern void lto_emit_section_header (void);
 extern void lto_end_section (void);
 extern void lto_write_data (const void *, unsigned int);
 extern void lto_write_raw_data (const void *, unsigned int);
-- 
2.21.0


  reply	other threads:[~2019-06-21 14:01 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-19  9:21 [RFC] zstd as a compression algorithm for LTO Martin Liška
2019-06-19 16:03 ` Jeff Law
2019-06-19 18:55   ` Richard Biener
2019-06-19 19:26     ` Andrew Pinski
2019-06-19 19:29       ` Jan Hubicka
2019-06-19 19:34         ` Andrew Pinski
2019-06-20  9:08           ` Martin Liška
2019-06-20 10:59             ` Thomas Koenig
2019-06-20 11:42               ` Martin Liška
2019-06-20 12:02                 ` Jan Hubicka
2019-06-21 10:20                   ` [PATCH] Add .gnu.lto_.meta section Martin Liška
2019-06-21 12:34                     ` Richard Biener
2019-06-21 12:49                       ` Martin Liška
2019-06-21 12:57                         ` Jan Hubicka
2019-06-21 14:01                           ` Martin Liška [this message]
2019-06-24 12:02                             ` Richard Biener
2019-06-24 12:12                               ` Martin Liška
2019-06-24 12:44                                 ` Richard Biener
2019-06-24 13:31                                   ` Martin Liška
2019-06-24 14:25                                     ` Iain Sandoe
2019-06-24 18:05                                     ` Richard Biener
2019-06-25  8:14                                       ` Martin Liška
2019-06-25 14:15                                         ` Richard Biener
2019-06-27 12:28                                           ` [PATCH] Add .gnu.lto_.lto section Martin Liška
2019-07-01 10:59                                             ` Martin Liška
2019-07-01 11:01                                               ` [PATCH 2/2] Add zstd support for LTO bytecode compression Martin Liška
2019-07-02 20:50                                                 ` Jeff Law
2019-07-02 20:49                                               ` [PATCH] Add .gnu.lto_.lto section Jeff Law
2019-06-20 12:12                 ` [RFC] zstd as a compression algorithm for LTO Thomas Koenig
2019-06-20 17:02             ` Joseph Myers
2019-06-20 10:46         ` Segher Boessenkool
2019-06-20 11:44           ` Martin Liška

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=cfd510ba-59b9-d2fa-a49e-c562cc422713@suse.cz \
    --to=mliska@suse.cz \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=gcc@gcc.gnu.org \
    --cc=hubicka@ucw.cz \
    --cc=law@redhat.com \
    --cc=pinskia@gmail.com \
    --cc=richard.guenther@gmail.com \
    --cc=tkoenig@netcologne.de \
    /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).