From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14458 invoked by alias); 24 Jun 2015 18:44:33 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 14411 invoked by uid 48); 24 Jun 2015 18:44:29 -0000 From: "amonakov at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/66655] New: [5.1 Regression] miscompilation due to ipa-ra on MinGW Date: Wed, 24 Jun 2015 18:44:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: unknown X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: amonakov at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status keywords bug_severity priority component assigned_to reporter target_milestone cf_gcctarget attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-06/txt/msg02425.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66655 Bug ID: 66655 Summary: [5.1 Regression] miscompilation due to ipa-ra on MinGW Product: gcc Version: unknown Status: UNCONFIRMED Keywords: wrong-code Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: amonakov at gcc dot gnu.org Target Milestone: --- Target: x86_64-w64-mingw32 Created attachment 35846 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35846&action=edit testcase Attached is a testcase that, when compiled with a MinGW GCC 5.1, aborts on execution. Swapping the order of .o files in the final link, or compiling main.cc with -O2 will produce a correct executable. The failure is caused by interplay of -fipa-ra (enabled by default at -O2) and MinGW's treatment of symbols that would normally be weak on ELF platforms. When compiling c.cc, ipa-ra does not save/restore %rax around the call to S::set (a static inline class method), apparently since the body emitted in that translation unit does not indeed clobber %rax and is not considered replaceable. On Linux, S::set is weak and optimization is not performed. However, S::set is also emitted when compiling main.cc, and its copy in main.o clobbers %rax since optimization is not enabled. During final link, the copy of S::set from main.o is used, producing a broken executable. (this issue is reduced from a miscompiled Clang produced by mingw-w64 5.1 cross-compiler)