Bug 55551 - Revision 193999 breaks lto/profiledbootstrap
Summary: Revision 193999 breaks lto/profiledbootstrap
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: gcov-profile (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-11-30 17:19 UTC by Markus Trippelsdorf
Modified: 2012-12-03 11:45 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
gcda testfile (590 bytes, application/octet-stream)
2012-12-01 07:14 UTC, Markus Trippelsdorf
Details
testcase (28.90 KB, text/plain)
2012-12-01 07:16 UTC, Markus Trippelsdorf
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Trippelsdorf 2012-11-30 17:19:51 UTC
...
/var/tmp/gcc_build_dir2/./prev-gcc/xg++ -B/var/tmp/gcc_build_dir2/./prev-gcc/ -B/usr/x86_64-pc-linux-gnu/bin/ -nostdinc++ -B/var/tmp/gcc_build_dir2/prev-x86_64-pc-linux-gnu/libstdc++-v3/src/.libs -B/var/tmp/gcc_build_dir2/prev-x86_64-pc-linux-gnu/libstdc++-v3/libsupc++/.libs -I/var/tmp/gcc_build_dir2/prev-x86_64-pc-linux-gnu/libstdc++-v3/include/x86_64-pc-linux-gnu -I/var/tmp/gcc_build_dir2/prev-x86_64-pc-linux-gnu/libstdc++-v3/include -I/home/markus/gcc/libstdc++-v3/libsupc++ -L/var/tmp/gcc_build_dir2/prev-x86_64-pc-linux-gnu/libstdc++-v3/src/.libs -L/var/tmp/gcc_build_dir2/prev-x86_64-pc-linux-gnu/libstdc++-v3/libsupc++/.libs -c   -march=native -O3 -pipe -fuse-linker-plugin -flto=jobserver -fno-fat-lto-objects -frandom-seed=1 -fprofile-use -DIN_GCC   -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wmissing-format-attribute -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings   -DHAVE_CONFIG_H -DGENERATOR_FILE -I. -Ibuild -I/home/markus/gcc/gcc -I/home/markus/gcc/gcc/build -I/home/markus/gcc/gcc/../include -I/home/markus/gcc/gcc/../libcpp/include  -I/home/markus/gcc/gcc/../libdecnumber -I/home/markus/gcc/gcc/../libdecnumber/bid -I../libdecnumber -I/home/markus/gcc/gcc/../libbacktrace    \
        -o build/gengtype-state.o /home/markus/gcc/gcc/gengtype-state.c
/var/tmp/gcc_build_dir2/./prev-gcc/xg++ -B/var/tmp/gcc_build_dir2/./prev-gcc/ -B/usr/x86_64-pc-linux-gnu/bin/ -nostdinc++ -B/var/tmp/gcc_build_dir2/prev-x86_64-pc-linux-gnu/libstdc++-v3/src/.libs -B/var/tmp/gcc_build_dir2/prev-x86_64-pc-linux-gnu/libstdc++-v3/libsupc++/.libs -I/var/tmp/gcc_build_dir2/prev-x86_64-pc-linux-gnu/libstdc++-v3/include/x86_64-pc-linux-gnu -I/var/tmp/gcc_build_dir2/prev-x86_64-pc-linux-gnu/libstdc++-v3/include -I/home/markus/gcc/libstdc++-v3/libsupc++ -L/var/tmp/gcc_build_dir2/prev-x86_64-pc-linux-gnu/libstdc++-v3/src/.libs -L/var/tmp/gcc_build_dir2/prev-x86_64-pc-linux-gnu/libstdc++-v3/libsupc++/.libs   -march=native -O3 -pipe -fuse-linker-plugin -flto=jobserver -fno-fat-lto-objects -frandom-seed=1 -fprofile-use -DIN_GCC   -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wmissing-format-attribute -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings   -DHAVE_CONFIG_H -DGENERATOR_FILE -Wl,-O1,--hash-style=gnu,--as-needed,--gc-sections,--icf=safe,--icf-iterations=3  -o build/gengenrtl \
    build/gengenrtl.o build/errors.o .././libiberty/libiberty.a
/var/tmp/gcc_build_dir2/./prev-gcc/xg++ -B/var/tmp/gcc_build_dir2/./prev-gcc/ -B/usr/x86_64-pc-linux-gnu/bin/ -nostdinc++ -B/var/tmp/gcc_build_dir2/prev-x86_64-pc-linux-gnu/libstdc++-v3/src/.libs -B/var/tmp/gcc_build_dir2/prev-x86_64-pc-linux-gnu/libstdc++-v3/libsupc++/.libs -I/var/tmp/gcc_build_dir2/prev-x86_64-pc-linux-gnu/libstdc++-v3/include/x86_64-pc-linux-gnu -I/var/tmp/gcc_build_dir2/prev-x86_64-pc-linux-gnu/libstdc++-v3/include -I/home/markus/gcc/libstdc++-v3/libsupc++ -L/var/tmp/gcc_build_dir2/prev-x86_64-pc-linux-gnu/libstdc++-v3/src/.libs -L/var/tmp/gcc_build_dir2/prev-x86_64-pc-linux-gnu/libstdc++-v3/libsupc++/.libs   -march=native -O3 -pipe -fuse-linker-plugin -flto=jobserver -fno-fat-lto-objects -frandom-seed=1 -fprofile-use -DIN_GCC   -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wmissing-format-attribute -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings   -DHAVE_CONFIG_H -DGENERATOR_FILE -Wl,-O1,--hash-style=gnu,--as-needed,--gc-sections,--icf=safe,--icf-iterations=3  -o build/genhooks \
    build/genhooks.o build/errors.o .././libiberty/libiberty.a
lto1: internal compiler error: in compute_working_sets, at profile.c:307
0x7f46676278b4 __libc_start_main
        /var/tmp/glibc/csu/libc-start.c:258
0x4be7c8 ???
        ../sysdeps/x86_64/start.S:123
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://gcc.gnu.org/bugs.html> for instructions.
lto-wrapper: /var/tmp/gcc_build_dir2/./prev-gcc/xg++ returned 1 exit status
/usr/x86_64-pc-linux-gnu/bin/ld: fatal error: lto-wrapper failed


 % ~/gcc/configure --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.8.0 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.0/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.8.0 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.8.0/man --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.8.0/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.8.0/include/g++-v4 --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --disable-altivec --disable-fixed-point --without-ppl --without-cloog --enable-lto --enable-nls --without-included-gettext --with-system-zlib --disable-werror --enable-initfini-array --with-gold --enable-secureplt --disable-multilib --enable-libmudflap --disable-libssp --disable-libgomp --enable-cld --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.8.0/python --enable-checking=release --disable-libgcj --enable-languages=c,c++ --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --with-build-config=slim-lto-bootstrap --with-boot-ldflags="-Wl,-O1,--hash-style=gnu,--as-needed,--gc-sections,--icf=safe,--icf-iterations=3" --enable-version-specific-runtime-libs --disable-libstdcxx-pch --enable-libstdcxx-time=ye

 % make -j4 BOOT_CFLAGS="-march=native -O3 -pipe" STAGE1_CFLAGS="-march=native -O3 -pipe" CFLAGS_FOR_TARGET="-march=native -O3 -pipe" CXXFLAGS_FOR_TARGET="-march=native -O3 -pipe" profiledbootstrap
Comment 1 Teresa Johnson 2012-11-30 17:38:07 UTC
Working on reproducing right now. Teresa

On Fri, Nov 30, 2012 at 9:20 AM, markus at trippelsdorf dot de
<gcc-bugzilla@gcc.gnu.org> wrote:
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55551
>
> Markus Trippelsdorf <markus at trippelsdorf dot de> changed:
>
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>                  CC|                            |tejohnson at gcc dot
>                    |                            |gnu.org
>
> --
> Configure bugmail: http://gcc.gnu.org/bugzilla/userprefs.cgi?tab=email
> ------- You are receiving this mail because: -------
> You are on the CC list for the bug.
Comment 2 Teresa Johnson 2012-11-30 22:05:22 UTC
Found the issue. Doing final testing, but the patch is below. FTR, I
couldn't do a slim-lto-bootstrap, it appears this config file is not
yet committed to trunk? Reproduced with just a normal lto bootstrap
though.

Teresa


2012-11-30  Teresa Johnson  <tejohnson@google.com>

* lto-cgraph.c (merge_profile_summaries): Handle scaled histogram
        entries that map to the same index.

Index: lto-cgraph.c
===================================================================
--- lto-cgraph.c (revision 193999)
+++ lto-cgraph.c (working copy)
@@ -1363,17 +1363,20 @@ merge_profile_summaries (struct lto_file_decl_data
          above. Use that to find the new histogram index.  */
       int scaled_min = RDIV (saved_profile_info->histogram[h_ix].min_value
                              * saved_scale, REG_BR_PROB_BASE);
+      /* The new index may be shared with another scaled histogram entry,
+         so we need to account for a non-zero histogram entry at new_ix.  */
       unsigned new_ix = gcov_histo_index (scaled_min);
-      lto_gcov_summary.histogram[new_ix].min_value = scaled_min;
+      lto_gcov_summary.histogram[new_ix].min_value
+          = MIN (lto_gcov_summary.histogram[new_ix].min_value, scaled_min);
       /* Some of the scaled counter values would ostensibly need to be placed
          into different (larger) histogram buckets, but we keep things simple
          here and place the scaled cumulative counter value in the bucket
          corresponding to the scaled minimum counter value.  */
       lto_gcov_summary.histogram[new_ix].cum_value
-          = RDIV (saved_profile_info->histogram[h_ix].cum_value
-                  * saved_scale, REG_BR_PROB_BASE);
+          += RDIV (saved_profile_info->histogram[h_ix].cum_value
+                   * saved_scale, REG_BR_PROB_BASE);
       lto_gcov_summary.histogram[new_ix].num_counters
-          = saved_profile_info->histogram[h_ix].num_counters;
+          += saved_profile_info->histogram[h_ix].num_counters;
     }

   /* Watch roundoff errors.  */


On Fri, Nov 30, 2012 at 9:37 AM, Teresa Johnson <tejohnson@google.com> wrote:
> Working on reproducing right now. Teresa
>
> On Fri, Nov 30, 2012 at 9:20 AM, markus at trippelsdorf dot de
> <gcc-bugzilla@gcc.gnu.org> wrote:
>>
>> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55551
>>
>> Markus Trippelsdorf <markus at trippelsdorf dot de> changed:
>>
>>            What    |Removed                     |Added
>> ----------------------------------------------------------------------------
>>                  CC|                            |tejohnson at gcc dot
>>                    |                            |gnu.org
>>
>> --
>> Configure bugmail: http://gcc.gnu.org/bugzilla/userprefs.cgi?tab=email
>> ------- You are receiving this mail because: -------
>> You are on the CC list for the bug.
>
>
>
> --
> Teresa Johnson | Software Engineer | tejohnson@google.com | 408-460-2413
Comment 3 Markus Trippelsdorf 2012-11-30 22:20:43 UTC
On 2012.11.30 at 22:05 +0000, tejohnson at google dot com wrote:
> Found the issue. Doing final testing, but the patch is below. FTR, I
> couldn't do a slim-lto-bootstrap, it appears this config file is not
> yet committed to trunk? Reproduced with just a normal lto bootstrap
> though.

Yes, it's a config that I only use locally. Sorry for the confusion.
Comment 4 Markus Trippelsdorf 2012-12-01 06:51:14 UTC
With your patch applied, Firefox fails to build:

/var/tmp/moz-build-dir/_virtualenv/bin/python /var/tmp/mozilla-central/config/pythonpath.py -I../../../config /var/tmp/mozilla-central/config/expandlibs_exec.py --depend .deps/libsoundtouch.so.pp --target libsoundtouch.so --uselist --  c++  -pedantic -Wall -Wpointer-arith -Woverloaded-virtual -Werror=return-type -Wtype-limits -Wempty-body -Wno-ctor-dtor-privacy -Wno-overlength-strings -Wno-invalid-offsetof -Wno-variadic-macros -Wcast-align -Wno-long-long -w -march=native -fno-exceptions -fno-strict-aliasing -fno-rtti -ffunction-sections -fdata-sections -fno-exceptions -std=gnu++0x -pthread -pipe  -DNDEBUG -DTRIMMED -flto=4 -fno-fat-lto-objects -fprofile-use -fprofile-correction -Wcoverage-mismatch -O3 -fomit-frame-pointer -fPIC -shared -Wl,-z,defs -Wl,--gc-sections -Wl,-h,libsoundtouch.so -o libsoundtouch.so  AAFilter.o cpu_detect_x86.o FIFOSampleBuffer.o FIRFilter.o RateTransposer.o SoundTouch.o TDStretch.o sse_optimized.o    -lpthread -fuse-linker-plugin -Wl,-O1,--hash-style=gnu -Wl,-z,noexecstack -Wl,--icf=safe  -fprofile-use -Wl,-rpath-link,/var/tmp/moz-build-dir/dist/bin -Wl,-rpath-link,/usr/lib    ../../../dist/lib/libmozalloc.a  -ldl    
lto1: internal compiler error: in merge_profile_summaries, at lto-cgraph.c:1356

I will try to reduce this later.
Comment 5 Teresa Johnson 2012-12-01 07:12:24 UTC
Hmm, I'm not sure how that assert can be hit, since we would have
returned earlier if none of the files being merged has any profile
runs. Presumably any profile run should have a sum_all of the counters
> 0, so the saved_profile_info would have to be set in the above loop.
If it is possible somehow that it doesn't, though, the following
additional patch would fix it:

Index: lto-cgraph.c
===================================================================
--- lto-cgraph.c        (revision 193999)
+++ lto-cgraph.c        (working copy)
@@ -1345,7 +1345,8 @@ merge_profile_summaries (struct lto_file_decl_data
         /* Save a pointer to the profile_info with the largest
            scaled sum_all and the scale for use in merging the
            histogram.  */
-        if (lto_gcov_summary.sum_all > saved_sum_all)
+        if (!saved_profile_info
+            || lto_gcov_summary.sum_all > saved_sum_all)
           {
             saved_profile_info = &file_data->profile_info;
             saved_sum_all = lto_gcov_summary.sum_all;

Can you try adding this patch and seeing if that fixes the issue? I
will hold off on sending the first fix for review  to see if I should
add this one.

Thanks,
Teresa

On Fri, Nov 30, 2012 at 10:51 PM, markus at trippelsdorf dot de
<gcc-bugzilla@gcc.gnu.org> wrote:
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55551
>
> --- Comment #4 from Markus Trippelsdorf <markus at trippelsdorf dot de> 2012-12-01 06:51:14 UTC ---
> With your patch applied, Firefox fails to build:
>
> /var/tmp/moz-build-dir/_virtualenv/bin/python
> /var/tmp/mozilla-central/config/pythonpath.py -I../../../config
> /var/tmp/mozilla-central/config/expandlibs_exec.py --depend
> .deps/libsoundtouch.so.pp --target libsoundtouch.so --uselist --  c++
> -pedantic -Wall -Wpointer-arith -Woverloaded-virtual -Werror=return-type
> -Wtype-limits -Wempty-body -Wno-ctor-dtor-privacy -Wno-overlength-strings
> -Wno-invalid-offsetof -Wno-variadic-macros -Wcast-align -Wno-long-long -w
> -march=native -fno-exceptions -fno-strict-aliasing -fno-rtti
> -ffunction-sections -fdata-sections -fno-exceptions -std=gnu++0x -pthread -pipe
>  -DNDEBUG -DTRIMMED -flto=4 -fno-fat-lto-objects -fprofile-use
> -fprofile-correction -Wcoverage-mismatch -O3 -fomit-frame-pointer -fPIC -shared
> -Wl,-z,defs -Wl,--gc-sections -Wl,-h,libsoundtouch.so -o libsoundtouch.so
> AAFilter.o cpu_detect_x86.o FIFOSampleBuffer.o FIRFilter.o RateTransposer.o
> SoundTouch.o TDStretch.o sse_optimized.o    -lpthread -fuse-linker-plugin
> -Wl,-O1,--hash-style=gnu -Wl,-z,noexecstack -Wl,--icf=safe  -fprofile-use
> -Wl,-rpath-link,/var/tmp/moz-build-dir/dist/bin -Wl,-rpath-link,/usr/lib
> ../../../dist/lib/libmozalloc.a  -ldl
> lto1: internal compiler error: in merge_profile_summaries, at lto-cgraph.c:1356
>
> I will try to reduce this later.
>
> --
> Configure bugmail: http://gcc.gnu.org/bugzilla/userprefs.cgi?tab=email
> ------- You are receiving this mail because: -------
> You are on the CC list for the bug.
Comment 6 Markus Trippelsdorf 2012-12-01 07:14:48 UTC
Created attachment 28841 [details]
gcda testfile
Comment 7 Markus Trippelsdorf 2012-12-01 07:16:03 UTC
Created attachment 28842 [details]
testcase

 % c++ -fPIC -fno-exceptions -std=gnu++0x -flto -fprofile-use -fprofile-correction -O3 test.ii
lto1: internal compiler error: in merge_profile_summaries, at lto-cgraph.c:1356
Comment 8 Markus Trippelsdorf 2012-12-01 09:01:33 UTC
(In reply to comment #5)
> 
> Index: lto-cgraph.c
> ===================================================================
> --- lto-cgraph.c        (revision 193999)
> +++ lto-cgraph.c        (working copy)
> @@ -1345,7 +1345,8 @@ merge_profile_summaries (struct lto_file_decl_data
>          /* Save a pointer to the profile_info with the largest
>             scaled sum_all and the scale for use in merging the
>             histogram.  */
> -        if (lto_gcov_summary.sum_all > saved_sum_all)
> +        if (!saved_profile_info
> +            || lto_gcov_summary.sum_all > saved_sum_all)
>            {
>              saved_profile_info = &file_data->profile_info;
>              saved_sum_all = lto_gcov_summary.sum_all;
> 
> Can you try adding this patch and seeing if that fixes the issue? I
> will hold off on sending the first fix for review  to see if I should
> add this one.

Yes this fixes the issue. Firefox now builds fine.
Thanks.
Comment 9 Teresa Johnson 2012-12-01 16:38:25 UTC
On Sat, Dec 1, 2012 at 1:01 AM, markus at trippelsdorf dot de
<gcc-bugzilla@gcc.gnu.org> wrote:
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55551
>
> --- Comment #8 from Markus Trippelsdorf <markus at trippelsdorf dot de> 2012-12-01 09:01:33 UTC ---
> (In reply to comment #5)
>>
>> Index: lto-cgraph.c
>> ===================================================================
>> --- lto-cgraph.c        (revision 193999)
>> +++ lto-cgraph.c        (working copy)
>> @@ -1345,7 +1345,8 @@ merge_profile_summaries (struct lto_file_decl_data
>>          /* Save a pointer to the profile_info with the largest
>>             scaled sum_all and the scale for use in merging the
>>             histogram.  */
>> -        if (lto_gcov_summary.sum_all > saved_sum_all)
>> +        if (!saved_profile_info
>> +            || lto_gcov_summary.sum_all > saved_sum_all)
>>            {
>>              saved_profile_info = &file_data->profile_info;
>>              saved_sum_all = lto_gcov_summary.sum_all;
>>
>> Can you try adding this patch and seeing if that fixes the issue? I
>> will hold off on sending the first fix for review  to see if I should
>> add this one.
>
> Yes this fixes the issue. Firefox now builds fine.
> Thanks.

This is exactly what is happening. From gcov-dump on test.gcda:

test.gcda: a3000000:  22:PROGRAM_SUMMARY checksum=0x01847361
test.gcda:              counts=617, runs=5, sum_all=0, run_max=0, sum_max=0
test.gcda:              counter histogram:
test.gcda:              0: num counts=617, min counter=0, cum_counter=0

Not sure why there are no non-zero counters when there are >0 runs,
but the above patch handles this situation.

Will send in patch a little later today when bootstrap tests complete.
Teresa


>
> --
> Configure bugmail: http://gcc.gnu.org/bugzilla/userprefs.cgi?tab=email
> ------- You are receiving this mail because: -------
> You are on the CC list for the bug.



--
Teresa Johnson | Software Engineer | tejohnson@google.com | 408-460-2413
Comment 10 tejohnson 2012-12-02 16:40:34 UTC
Author: tejohnson
Date: Sun Dec  2 16:40:28 2012
New Revision: 194055

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=194055
Log:
2012-12-02  Teresa Johnson  <tejohnson@google.com>

        PR gcov-profile/55551
	* lto-cgraph.c (merge_profile_summaries): Handle scaled histogram
        entries that map to the same index.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/lto-cgraph.c
Comment 11 Richard Biener 2012-12-03 11:45:59 UTC
Fixed.