Bug 1316999

Summary: gcc6 fails when optimizing c++ code for nightly (firefox development version)
Product: [Fedora] Fedora Reporter: stan <gryt2>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: rawhideCC: davejohansen, gryt2, jakub, jwakely, law, mpolacek
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-03-17 15:29:41 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Attachments:
Description Flags
The .mozconfig that I am using to compile nightly. none

Description stan 2016-03-11 16:41:06 UTC
Description of problem:
I keep an hg repository of the firefox development version, nightly.  I compile it on f21 with gcc 4.9 and rawhide (f25) with gcc6.  With gcc 4.9, I can use -O3 and the resulting executable runs fine.  With gcc6, neither -O2 or -O3 will run.  The compile appears to complete successfully, but gets a seg fault on start.  If I compile using gcc6, with -O0, the resulting executable runs fine, though slowly.

Version-Release number of selected component (if applicable):
Name        : gcc
Version     : 6.0.0
Release     : 0.15.fc25
Architecture: x86_64


How reproducible:
Every time.

Steps to Reproduce:
1.  Clone the hg repository for nightly
2.  Default optimization is -O2, have to add 
    ac_add_options --enable-optimize=" -O3 "
    if O3 wanted.
3.  cd into the directory and run ./mach build
4.  run ./mach install (the appended .mozconfig will put into /usr/local)
5.  Observe the crash

Actual results:
Successful build, crash on start

Expected results:
Nightly runs fine

Additional info:
This is a bug at mozilla with some information about tests I've done to work around this.  It's actually about another problem, but contains the extra data.
https://bugzilla.mozilla.org/show_bug.cgi?id=1245076

I'll attach the .mozconfig I use to build nightly.

It's possible this isn't a bug in gcc at all, but the fact that the code compiles and runs fine without optimization, -O0, leads me to believe it is.

I've compiled C programs with gcc 6 and -O3, and they have worked correctly.  So it could be only in g++.

Comment 1 Jakub Jelinek 2016-03-11 16:45:01 UTC
Please try -flifetime-dse=1 or -fno-lifetime-dse and/or -fno-delete-null-pointer-checks, forgot which of these violates firefox, whether trying to preserve data from before construction to after construction, or calling methods on NULL pointers (or both).

Comment 2 stan 2016-03-11 16:45:30 UTC
Created attachment 1135307 [details]
The .mozconfig that I am using to compile nightly.

Copy this into ~/.mozconfig in order to use it to compile nightly instead of the built in defaults.

Comment 3 stan 2016-03-11 17:24:30 UTC
@comment1, thanks jakub for the fast response.  Will try those (will search first to profit from other's experience) to see what works.  Progress!

Comment 4 Jakub Jelinek 2016-03-11 17:27:08 UTC
See https://gcc.gnu.org/gcc-6/porting_to.html for some details.

Comment 5 stan 2016-03-11 19:01:09 UTC
Thanks for that reference.  Very informative.

Comment 6 stan 2016-03-11 19:02:19 UTC
Once I confirm that following the advice in the reference allows nightly to compile, I'll close this ticket, as it isn't a problem with gcc 6.

Comment 7 stan 2016-03-11 21:48:46 UTC
I tried several variations of options, and nightly crashes on start with any optimization regardless of what I do.
ac_add_options --enable-optimize=" -Wall -std=gnu++11 -O3"
ac_add_options --enable-optimize=" -Wall -std=gnu++98 -O3"  # this wouldn't compile
ac_add_options --enable-optimize=" -Wall -fno-delete-null-pointer-checks -O3"
ac_add_options --enable-optimize=" -Wnull-dereference -fno-delete-null-pointer-checks -O3"

I don't know whether it is gcc or nightly with the problem.  I'm out of my depth here.  So, I'll just drop it.

I leave it up to you whether to close the ticket.

Comment 8 Jonathan Wakely 2016-03-12 12:02:05 UTC
Did you try -fno-lifetime-dse ?

Comment 9 stan 2016-03-13 19:26:08 UTC
Aarrrgh!  No, I didn't.  I'll give that a try today.

Comment 10 stan 2016-03-13 20:22:37 UTC
Thanks for the question.  That was it!

When I used 
ac_add_options --enable-optimize=" -Wall -fno-lifetime-dse -fno-delete-null-pointer-checks -O3"
nightly compiled fine, and started and is running fine.  I'm using it to write this message.

So, I assume that means there is no issue with g++ optimization in gcc 6, and that it is coding style in nightly that is the cause of this because it is to a different standard than gcc 6.

If that is the case, then I think this ticket can be closed as NOTABUG.

Thanks for the help.

Comment 11 Jakub Jelinek 2016-03-17 15:29:41 UTC
Not a gcc bug.