Bug 86872 - [9 Regression] LTO bootstrap failed with profiledbootstrap
Summary: [9 Regression] LTO bootstrap failed with profiledbootstrap
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: bootstrap (show other bugs)
Version: 9.0
: P3 normal
Target Milestone: 9.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-08-06 22:29 UTC by H.J. Lu
Modified: 2023-02-23 18:14 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-08-07 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2018-08-06 22:29:15 UTC
On x86-64, r263300 gave

In function ‘gimple_simplify_32’:
lto1: internal compiler error: in linemap_check_ordinary, at libcpp/include/line-map.h:587
0x5e2991 ???
        ../../src-trunk/libcpp/include/line-map.h:587
0x93aeae ???
        ../../src-trunk/libcpp/line-map.c:754
0x1d653e2 ???
        ../../src-trunk/gcc/lto-streamer-in.c:194
0x1d6661f ???
        ../../src-trunk/gcc/lto-streamer-in.c:304
0xbc5f88 ???
        ../../src-trunk/gcc/gimple-streamer-in.c:111
0x91d3c7 lto_read_body_or_constructor(lto_file_decl_data*, symtab_node*, char const*, lto_section_type) [clone .isra.95] [clone .constprop.697]
        ../../src-trunk/gcc/lto-streamer-in.c:1092
0x22631cd ???
        ../../src-trunk/gcc/lto-streamer-in.c:1343
0x226e950 ???
        ../../src-trunk/gcc/cgraphunit.c:2086
0x227fa1b ???
        ../../src-trunk/gcc/cgraphunit.c:2254
0x23a9564 ???
        ../../src-trunk/gcc/lto/lto.c:3426
0x1ab4a59 ???
        ../../src-trunk/gcc/toplev.c:455
0x1ab7d67 ???
        ../../src-trunk/gcc/toplev.c:2161
0x904cca ???
        ../../src-trunk/gcc/main.c:39
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

when GCC is configured with

--with-build-config=bootstrap-lto --disable-werror

and built with profiledbootstrap. r263286 is OK.
Comment 1 H.J. Lu 2018-08-07 01:45:51 UTC
This is caused by r263298.
Comment 2 Jan Hubicka 2018-08-07 11:15:20 UTC
I have seen failure at same point coming and going while working on the streaming changes. I think it is some kind of overflow problem in linemaps that needs specific series of events to trigger which is there for some time.
Comment 3 David Malcolm 2018-08-07 15:04:00 UTC
(In reply to H.J. Lu from comment #0)
> On x86-64, r263300 gave

Annotating it with the code in question:

> In function ‘gimple_simplify_32’:
> lto1: internal compiler error: in linemap_check_ordinary, at libcpp/include/line-map.h:587
> 0x5e2991 ???
>         ../../src-trunk/libcpp/include/line-map.h:587

  linemap_assert (MAP_ORDINARY_P (map));

> 0x93aeae ???
>         ../../src-trunk/libcpp/line-map.c:754

In linemap_line_start:
      /* Allocate the new line_map.  However, if the current map only has a
	 single line we can sometimes just increase its column_bits instead. */
      if (line_delta < 0
	  || last_line != ORDINARY_MAP_STARTING_LINE_NUMBER (map)
	  || SOURCE_COLUMN (map, highest) >= (1U << (column_bits - range_bits))
	  || range_bits < map->m_range_bits)
	map = linemap_check_ordinary
	        (const_cast <line_map *>
		  (linemap_add (set, LC_RENAME,
				ORDINARY_MAP_IN_SYSTEM_HEADER_P (map),
				ORDINARY_MAP_FILE_NAME (map),
				to_line)));

> 0x1d653e2 ???
>         ../../src-trunk/gcc/lto-streamer-in.c:194

in lto_location_cache::apply_location_cache ():
	  linemap_line_start (line_table, loc.line, max + 1);

> 0x1d6661f ???
>         ../../src-trunk/gcc/lto-streamer-in.c:304

in stream_input_location_now:

  data_in->location_cache.apply_location_cache ();


> 0xbc5f88 ???
>         ../../src-trunk/gcc/gimple-streamer-in.c:111

in input_gimple_stmt:
  /* Read location information.  Caching here makes no sense until streamer
     cache can handle the following gimple_set_block.  */
  gimple_set_location (stmt, stream_input_location_now (&bp, data_in));


(etc)


linemap_add can return NULL with LC_LEAVE, but we have LC_RENAME.
The return value ("map") comes from:

  linemap_assert (reason != LC_ENTER_MACRO);
  line_map_ordinary *map
    = linemap_check_ordinary (new_linemap (set, start_location));
  map->reason = reason;


linemap_check_ordinary is:
   linemap_assert (MAP_ORDINARY_P (map));

which, in turn is:

inline bool
MAP_ORDINARY_P (const line_map *map)
{
  return map->start_location < LINE_MAP_MAX_LOCATION;
}

map->start_location shouldn't be able to change.

I believe what's happened is that:
  to_line >= LINE_MAP_MAX_LOCATION
within linemap_line_start.

That way, linemap_add would (unexpectedly) create a macro map, rather than an ordinary map.

Presumably we need some kind of overflow handling here (assuming that the above correctly characterizes the cause of the crash).

Also, it seems bad to be running out of location_t values.  We probably should double-check that we're packing things efficiently.
Comment 4 H.J. Lu 2018-08-14 22:41:11 UTC
line-map.c has

 linemap_assert (reason != LC_ENTER_MACRO);
  line_map_ordinary *map
    = linemap_check_ordinary (new_linemap (set, start_location));
  map->reason = reason;

We get here with reason != LC_ENTER_MACRO and create linemap with
start_location >= LINE_MAP_MAX_LOCATION.
Comment 5 H.J. Lu 2018-08-15 11:39:30 UTC
A patch is posted at

https://gcc.gnu.org/ml/gcc-patches/2018-08/msg00866.html
Comment 6 hjl@gcc.gnu.org 2018-08-24 23:38:24 UTC
Author: hjl
Date: Fri Aug 24 23:37:53 2018
New Revision: 263845

URL: https://gcc.gnu.org/viewcvs?rev=263845&root=gcc&view=rev
Log:
Set start_location to 0 if we ran out of line map space

With profiledbootstrap and --with-build-config=bootstrap-lto, linemap_add
may create a macro map when we run out of line map space.  This patch
changes start_location to UNKNOWN_LOCATION (0) in this case.

Tested with profiledbootstrap and --with-build-config=bootstrap-lto on
Linux/x86-64.

	PR bootstrap/86872
	* line-map.c (pure_location_p): Return true if linemap_lookup
	returns NULL.
	(linemap_add): Set start_location to 0 if we run out of line map
	space.

Modified:
    trunk/libcpp/ChangeLog
    trunk/libcpp/line-map.c
Comment 7 H.J. Lu 2018-08-25 13:38:34 UTC
Fixed.