On Mon, 31 Aug 2015, Richard Biener wrote:

> 
> Hi,
> 
> with LTO early debug and LTO bootstrap I now get
> 
> /usr/include/sys/resource.h:51:12: error: type of ‘getrlimit’ does not 
> match original declaration [-Werror=lto-type-mismatch]
>  extern int getrlimit (__rlimit_resource_t __resource,
>             ^
> /usr/include/sys/resource.h:51:12: note: type mismatch in parameter 1
>  extern int getrlimit (__rlimit_resource_t __resource,
>             ^
> /usr/include/sys/resource.h:43:13: note: type ‘__rlimit_resource_t’ should 
> match type ‘__rlimit_resource_t’
>  typedef int __rlimit_resource_t;
>              ^
> /usr/include/sys/resource.h:39:32: note: the incompatible type is defined 
> here
>  typedef enum __rlimit_resource __rlimit_resource_t;
>                                 ^
> /usr/include/sys/resource.h:51:12: note: ‘getrlimit’ was previously 
> declared here
>  extern int getrlimit (__rlimit_resource_t __resource,
>             ^
> 
> the issue is wrt C / C++ context where glibc headers have
> 
> #if defined __USE_GNU && !defined __cplusplus
> typedef enum __rlimit_resource __rlimit_resource_t;
> typedef enum __rusage_who __rusage_who_t;
> typedef enum __priority_which __priority_which_t;
> #else
> typedef int __rlimit_resource_t;
> typedef int __rusage_who_t;
> typedef int __priority_which_t;
> #endif
> 
> and the enum is unsigned:
> 
> (gdb) p debug_tree (0x7fffe7aa2690)
>  <enumeral_type 0x7fffe7aa2690 __rlimit_resource_t unsigned SI
>     size <integer_cst 0x7ffff6281df8 type <integer_type 0x7ffff62852a0 
> bitsizetype> constant 32>
>     unit size <integer_cst 0x7ffff6281e10 type <integer_type 
> 0x7ffff62851f8 sizetype> constant 4>
> 
> which currently isn't compatible with signed int.
> 
> I'm now double-checking unpatched LTO bootstrap but I guess I somehow
> just keep streaming some more decls or get different partitioning.
> 
> I know in the end you'd like to make int and unsigned int compatible
> for this check(?) but I wonder whether glibc really desired to make
> the enum unsigned...  it's just
> 
> /* Kinds of resource limit.  */
> enum __rlimit_resource
> {
>   /* Per-process CPU limit, in seconds.  */
>   RLIMIT_CPU = 0,
> ...
> #define RLIMIT_NLIMITS __RLIMIT_NLIMITS
> #define RLIM_NLIMITS __RLIM_NLIMITS
> };
> 
> one reason I get here might be also that somehow the locations of
> the decls are not in-system-header.  This would be an artifact of
> LTO location streaming I guess.
> 
> Oh, seems unpatched LTO bootstrap is broken (possibly by me).

The following two patches are necessary to bring back LTO bootstrap
to the point where it runs LTRANS stage for cc1 and friends.  It
then still breaks (I have to analyze why).

The first patch avoids replacing strrchr with __builtin_strrchr
in the abstract origin for IPA transforms.  The second patch avoids
the above getrlimit errors by properly streaming whether locations
are in system headers or not.

I'm currently separately bootstrapping and testing them on 
x86_64-unknown-linux-gnu.

2015-08-31  Richard Biener  <rguent...@suse.de>

        lto/
        * lto-symtab.c (lto_symtab_prevailing_decl): Remove redundant
        test, do not replace a non-builtin with a builtin.
        * lto.c (compare_tree_sccs_1): Do not merge things we stream
        as builtins vs. non-builtins.

Index: gcc/lto/lto-symtab.c
===================================================================
--- gcc/lto/lto-symtab.c        (revision 227293)
+++ gcc/lto/lto-symtab.c        (working copy)
@@ -798,11 +798,6 @@ lto_symtab_prevailing_decl (tree decl)
   if (TREE_CODE (decl) == FUNCTION_DECL && DECL_ABSTRACT_P (decl))
     return decl;
 
-  /* Likewise builtins are their own prevailing decl.  This preserves
-     non-builtin vs. builtin uses from compile-time.  */
-  if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl))
-    return decl;
-
   /* Ensure DECL_ASSEMBLER_NAME will not set assembler name.  */
   gcc_assert (DECL_ASSEMBLER_NAME_SET_P (decl));
 
@@ -811,5 +806,9 @@ lto_symtab_prevailing_decl (tree decl)
   if (!ret)
     return decl;
 
+  /* Do not replace a non-builtin with a builtin.  */
+  if (is_builtin_fn (ret->decl))
+    return decl;
+
   return ret->decl;
 }
Index: gcc/lto/lto.c
===================================================================
--- gcc/lto/lto.c       (revision 227293)
+++ gcc/lto/lto.c       (working copy)
@@ -1054,8 +1054,10 @@ compare_tree_sccs_1 (tree t1, tree t2, t
       return false;
 
 
-  /* We don't want to compare locations, so there is nothing do compare
-     for TS_DECL_MINIMAL.  */
+  /* We want to compare locations up to the point where it makes
+     a difference for streaming - thus whether the decl is builtin or not.  */
+  if (CODE_CONTAINS_STRUCT (code, TS_DECL_MINIMAL))
+    compare_values (streamer_handle_as_builtin_p);
 
   if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
     {



2015-08-31  Richard Biener  <rguent...@suse.de>

        * lto-streamer.h (lto_location_cache::cached_location::sysp): Add.
        (lto_location_cache::current_sysp): Likewise.
        (output_block::current_sysp): Likewise.
        * lto-streamer-in.c (lto_location_cache::cmp_loc): Compare sysp.
        (lto_location_cache::apply_location_cache): Properly record
        system header locations.
        (lto_location_cache::input_location): Input whether a file
        is a system header.
        * lto-streamer-out.c (lto_output_location): Stream whether a file
        is a system header.

Index: trunk/gcc/lto-streamer-in.c
===================================================================
--- trunk.orig/gcc/lto-streamer-in.c    2015-08-31 10:02:42.522639934 +0200
+++ trunk/gcc/lto-streamer-in.c 2015-08-31 09:57:31.131783273 +0200
@@ -172,6 +172,8 @@ lto_location_cache::cmp_loc (const void
     }
   if (a->file != b->file)
     return strcmp (a->file, b->file);
+  if (a->sysp != b->sysp)
+    return a->sysp ? 1 : -1;
   if (a->line != b->line)
     return a->line - b->line;
   return a->col - b->col;
@@ -195,7 +197,7 @@ lto_location_cache::apply_location_cache
 
       if (current_file != loc.file)
        linemap_add (line_table, prev_file ? LC_RENAME : LC_ENTER,
-                    false, loc.file, loc.line);
+                    loc.sysp, loc.file, loc.line);
       else if (current_line != loc.line)
        {
          int max = loc.col;
@@ -252,6 +254,7 @@ lto_location_cache::input_location (loca
   static const char *stream_file;
   static int stream_line;
   static int stream_col;
+  static bool stream_sysp;
   bool file_change, line_change, column_change;
 
   gcc_assert (current_cache == this);
@@ -269,7 +272,10 @@ lto_location_cache::input_location (loca
   column_change = bp_unpack_value (bp, 1);
 
   if (file_change)
-    stream_file = canon_file_name (bp_unpack_string (data_in, bp));
+    {
+      stream_file = canon_file_name (bp_unpack_string (data_in, bp));
+      stream_sysp = bp_unpack_value (bp, 1);
+    }
 
   if (line_change)
     stream_line = bp_unpack_var_len_unsigned (bp);
@@ -281,13 +287,14 @@ lto_location_cache::input_location (loca
      streaming.  */
      
   if (current_file == stream_file && current_line == stream_line
-      && current_col == stream_col)
+      && current_col == stream_col && current_sysp == stream_sysp)
     {
       *loc = current_loc;
       return;
     }
 
-  struct cached_location entry = {stream_file, loc, stream_line, stream_col};
+  struct cached_location entry
+    = {stream_file, loc, stream_line, stream_col, stream_sysp};
   loc_cache.safe_push (entry);
 }
 
Index: trunk/gcc/lto-streamer-out.c
===================================================================
--- trunk.orig/gcc/lto-streamer-out.c   2015-08-31 10:02:42.522639934 +0200
+++ trunk/gcc/lto-streamer-out.c        2015-08-31 09:58:51.011515415 +0200
@@ -192,8 +192,12 @@ lto_output_location (struct output_block
   bp_pack_value (bp, ob->current_col != xloc.column, 1);
 
   if (ob->current_file != xloc.file)
-    bp_pack_string (ob, bp, xloc.file, true);
+    {
+      bp_pack_string (ob, bp, xloc.file, true);
+      bp_pack_value (bp, xloc.sysp, 1);
+    }
   ob->current_file = xloc.file;
+  ob->current_sysp = xloc.sysp;
 
   if (ob->current_line != xloc.line)
     bp_pack_var_len_unsigned (bp, xloc.line);
Index: trunk/gcc/lto-streamer.h
===================================================================
--- trunk.orig/gcc/lto-streamer.h       2015-08-31 10:02:42.522639934 +0200
+++ trunk/gcc/lto-streamer.h    2015-08-31 09:59:32.964900166 +0200
@@ -345,6 +345,7 @@ private:
     const char *file;
     location_t *loc;
     int line, col;
+    bool sysp;
   };
 
   /* The location cache.  */
@@ -364,6 +365,7 @@ private:
   const char *current_file;
   int current_line;
   int current_col;
+  bool current_sysp;
   location_t current_loc;
 };
 
@@ -711,6 +713,7 @@ struct output_block
   const char *current_file;
   int current_line;
   int current_col;
+  bool current_sysp;
 
   /* Cache of nodes written in this section.  */
   struct streamer_tree_cache_d *writer_cache;

Reply via email to