Patchwork Fix host endianess issue in lto streamer (PR lto/47274)

login
register
mail settings
Submitter Jakub Jelinek
Date Feb. 2, 2011, 11:22 p.m.
Message ID <20110202232200.GO30899@tyan-ft48-01.lab.bos.redhat.com>
Download mbox | patch
Permalink /patch/81591/
State New
Headers show

Comments

Jakub Jelinek - Feb. 2, 2011, 11:22 p.m.
Hi!

Both kind and visibility are enum vars, i.e. 32-bit on practically all
hosts, but lto_output_data_stream (stream, &kind, 1); writes first
byte from it (which is the right thing on little endian hosts, but always
writes 0 on big endian).
I haven't found where this section is actually read (somewhere in lto
plugin, somewhere else?), so I assume the section format is fixed.

2011-02-02  Jakub Jelinek  <jakub@redhat.com>

	PR lto/47274
	* lto-streamer-out.c (write_symbol): When writing kind and visibility,
	copy them into a unsigned char variable and pass address of it to
	lto_output_data_stream.


	Jakub
Dave Korn - Feb. 3, 2011, 12:24 a.m.
On 02/02/2011 23:22, Jakub Jelinek wrote:

> Both kind and visibility are enum vars, i.e. 32-bit on practically all
> hosts, but lto_output_data_stream (stream, &kind, 1); writes first
> byte from it (which is the right thing on little endian hosts, but always
> writes 0 on big endian).
> I haven't found where this section is actually read (somewhere in lto
> plugin, somewhere else?)

  As you say; see parse_table_entry() in lto-plugin.c

    cheers,
      DaveK
Jakub Jelinek - Feb. 3, 2011, 7:46 a.m.
On Thu, Feb 03, 2011 at 12:24:19AM +0000, Dave Korn wrote:
> On 02/02/2011 23:22, Jakub Jelinek wrote:
> 
> > Both kind and visibility are enum vars, i.e. 32-bit on practically all
> > hosts, but lto_output_data_stream (stream, &kind, 1); writes first
> > byte from it (which is the right thing on little endian hosts, but always
> > writes 0 on big endian).
> > I haven't found where this section is actually read (somewhere in lto
> > plugin, somewhere else?)
> 
>   As you say; see parse_table_entry() in lto-plugin.c

Ah, the confusing thing was that it uses LDP{K,V}_* constants it defines
instead of GCCP{K,V}_* that the streamer uses.

	Jakub
Richard Guenther - Feb. 3, 2011, 10:22 a.m.
On Thu, Feb 3, 2011 at 8:46 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> On Thu, Feb 03, 2011 at 12:24:19AM +0000, Dave Korn wrote:
>> On 02/02/2011 23:22, Jakub Jelinek wrote:
>>
>> > Both kind and visibility are enum vars, i.e. 32-bit on practically all
>> > hosts, but lto_output_data_stream (stream, &kind, 1); writes first
>> > byte from it (which is the right thing on little endian hosts, but always
>> > writes 0 on big endian).
>> > I haven't found where this section is actually read (somewhere in lto
>> > plugin, somewhere else?)
>>
>>   As you say; see parse_table_entry() in lto-plugin.c
>
> Ah, the confusing thing was that it uses LDP{K,V}_* constants it defines
> instead of GCCP{K,V}_* that the streamer uses.

Yeah  (one of the most ugly functions ...).  And no, the format isn't really
fixed.

Ok.

Thanks,
Richard.

Patch

--- gcc/lto-streamer-out.c.jj	2011-01-15 11:26:42.402838693 +0100
+++ gcc/lto-streamer-out.c	2011-02-02 17:02:55.311388707 +0100
@@ -2410,6 +2410,7 @@  write_symbol (struct lto_streamer_cache_
   int slot_num;
   uint64_t size;
   const char *comdat;
+  unsigned char c;
 
   /* None of the following kinds of symbols are needed in the
      symbol table.  */
@@ -2505,8 +2506,10 @@  write_symbol (struct lto_streamer_cache_
 
   lto_output_data_stream (stream, name, strlen (name) + 1);
   lto_output_data_stream (stream, comdat, strlen (comdat) + 1);
-  lto_output_data_stream (stream, &kind, 1);
-  lto_output_data_stream (stream, &visibility, 1);
+  c = (unsigned char) kind;
+  lto_output_data_stream (stream, &c, 1);
+  c = (unsigned char) visibility;
+  lto_output_data_stream (stream, &c, 1);
   lto_output_data_stream (stream, &size, 8);
   lto_output_data_stream (stream, &slot_num, 4);
 }