Bug 53853 - FAIL: g++.dg/other/pr53811.C -std=gnu++* (internal compiler error)
Summary: FAIL: g++.dg/other/pr53811.C -std=gnu++* (internal compiler error)
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: 4.7.2
Assignee: Uroš Bizjak
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-07-04 12:25 UTC by Dominique d'Humieres
Modified: 2012-07-10 17:56 UTC (History)
3 users (show)

See Also:
Host: x86_64-apple-darwin10
Target: x86_64-apple-darwin10
Build: x86_64-apple-darwin10
Known to work:
Known to fail:
Last reconfirmed: 2012-07-04 00:00:00


Attachments
Patch to fix the ICE with -fPIC (906 bytes, patch)
2012-07-05 12:09 UTC, Uroš Bizjak
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dominique d'Humieres 2012-07-04 12:25:41 UTC
g++.dg/other/pr53811.C fails on x86_64-apple-darwin10 with -m64:

FAIL: g++.dg/other/pr53811.C -std=gnu++98 (internal compiler error)
FAIL: g++.dg/other/pr53811.C -std=gnu++98 (test for excess errors)
FAIL: g++.dg/other/pr53811.C -std=gnu++11 (internal compiler error)
FAIL: g++.dg/other/pr53811.C -std=gnu++11 (test for excess errors)

The ICE is

Excess errors:
/opt/gcc/work/gcc/testsuite/g++.dg/other/pr53811.C:29:1: error: insn does not
satisfy its constraints:
(insn 3 2 4 (set (reg:DI 59)
        (const:DI (unspec:DI [
                    (symbol_ref:DI ("_ZN12ScriptString12CreateStringEPKc")
[flags 0x403] <function_decl 0x142987100 CreateString>)
                ] UNSPEC_GOTOFF))) 62 {*movdi_internal_rex64}
     (nil))

Note that ' -mcmodel=large' seems to have issues on x86_64-apple-darwin10: see
pr50077.
Comment 1 Iain Sandoe 2012-07-04 13:05:45 UTC
Also on i686-darwin9 @m64

As commented in 50077, we don't support the large model.

I suppose the best thing to do in the short(ish) term is to make a target test for large model support and make the tests that require it do that test.

Addition of large model support would be nice - but might be optimistic for 4.8 with the resources available to darwin at present.
Comment 2 Uroš Bizjak 2012-07-05 12:07:31 UTC
It turned out that -mcmodel -fPIC also ICEd on x86_64-pc-linux-gnu.

We need additional part to handle CM_LARGE_PIC, basically:

--cut here--
@@ -33057,6 +33059,10 @@ x86_output_mi_thunk (FILE *file,
     emit_jump_insn (gen_indirect_jump (fnaddr));
   else
     {
+      if (ix86_cmodel == CM_LARGE_PIC
+	  && GET_CODE (fnaddr) == SYMBOL_REF)
+	fnaddr = construct_plt_address (fnaddr,
+					gen_rtx_REG (Pmode, tmp_regno));
       if (!sibcall_insn_operand (fnaddr, word_mode))
 	{
 	  tmp = gen_rtx_REG (word_mode, tmp_regno);
--cut here--

to create:

        .size   _ZN12ScriptString12CreateStringEPKc, .-_ZN12ScriptString12CreateStringEPKc
        .set    .LTHUNK0,_ZN12ScriptString12CreateStringEPKc
        .p2align 4,,15
        .globl  _ZThn8_N12ScriptString12CreateStringEPKc
        .type   _ZThn8_N12ScriptString12CreateStringEPKc, @function
_ZThn8_N12ScriptString12CreateStringEPKc:
.LFB1:
        .cfi_startproc
        subq    $8, %rdi
        movabsq $.LTHUNK0@PLTOFF, %r10
        addq    %rbx, %r10
        jmp     *%r10
        .cfi_endproc

I'd like to ask Jakub fo opinion here. The generated code otherwise works OK for a couple of tests (g++.dg/inherit/thunk*.C) when compiled with -mcmodel=large -fPIC.
Comment 3 Uroš Bizjak 2012-07-05 12:09:36 UTC
Created attachment 27746 [details]
Patch to fix the ICE with -fPIC

The complete patch in testing.
Comment 4 Dominique d'Humieres 2012-07-05 14:07:00 UTC
The patch in comment #3 fixes the PR. Full regstrapping scheduled for tonight.
Comment 5 Uroš Bizjak 2012-07-06 07:45:21 UTC
We can leave all the magic to legitimize_pic_address, so following alternative patch is much clearer:

--cut here--
Index: i386.c
===================================================================
--- i386.c      (revision 189310)
+++ i386.c      (working copy)
@@ -33057,6 +33057,10 @@ x86_output_mi_thunk (FILE *file,
     emit_jump_insn (gen_indirect_jump (fnaddr));
   else
     {
+      if (flag_pic && SYMBOLIC_CONST (fnaddr))
+       fnaddr = legitimize_pic_address (fnaddr,
+                                        gen_rtx_REG (Pmode, tmp_regno));
+
       if (!sibcall_insn_operand (fnaddr, word_mode))
        {
          tmp = gen_rtx_REG (word_mode, tmp_regno);
--cut here--

With this patch, we get:

        .size   _ZN1D4foo2Ev, .-_ZN1D4foo2Ev
        .set    .LTHUNK0,_ZN1D4foo2Ev
        .p2align 4,,15
        .globl  _ZThn16_N1D4foo2Ev
        .type   _ZThn16_N1D4foo2Ev, @function
_ZThn16_N1D4foo2Ev:
.LFB15:
        .cfi_startproc
        subq    $16, %rdi
        movabsq $.LTHUNK0@GOTOFF, %r10
        addq    %rbx, %r10
        jmp     *%r10
        .cfi_endproc
.LFE15:
        .size   _ZThn16_N1D4foo2Ev, .-_ZThn16_N1D4foo2Ev

So, load off GOTOFF table, which works as well.
Comment 6 Uroš Bizjak 2012-07-06 10:02:38 UTC
Author: uros
Date: Fri Jul  6 10:00:11 2012
New Revision: 189315

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=189315
Log:
    PR target/53853
    * config/i386/i386.c (x86_output_mi_thunk): For CM_LARGE_PIC model,
    emit PIC sequence for fnaddr symbol reference in advance.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/i386/i386.c
Comment 7 uros 2012-07-10 17:53:56 UTC
Author: uros
Date: Tue Jul 10 17:53:48 2012
New Revision: 189412

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=189412
Log:
	Backport from mainline
	2012-07-03  Uros Bizjak  <ubizjak@gmail.com>

	PR target/53811
	* config/i386/i386.c (x86_output_mi_thunk): Check if fnaddr satisfies
	sibcall_insn_operand.  Move it to a temporary register if not.

	2012-07-06  Uros Bizjak  <ubizjak@gmail.com>

	PR target/53853
	* config/i386/i386.c (x86_output_mi_thunk): For CM_LARGE_PIC model,
	emit PIC sequence for fnaddr symbol reference in advance.

testsuite/ChangeLog:

	Backport from mainline
	2012-07-03  Uros Bizjak  <ubizjak@gmail.com>

	PR target/53811
	* g++.dg/other/pr53811.C: New test.


Added:
    branches/gcc-4_7-branch/gcc/testsuite/g++.dg/other/pr53811.C
Modified:
    branches/gcc-4_7-branch/gcc/ChangeLog
    branches/gcc-4_7-branch/gcc/config/i386/i386.c
    branches/gcc-4_7-branch/gcc/testsuite/ChangeLog
Comment 8 Uroš Bizjak 2012-07-10 17:56:32 UTC
Fixed.