On Thu, May 12, 2016 at 4:19 PM, H.J. Lu <hjl.to...@gmail.com> wrote:
> On Thu, May 12, 2016 at 3:02 PM, Uros Bizjak <ubiz...@gmail.com> wrote:
>> Hello!
>>
>> testsuite/gcc.target/i386/pr61599-{1,2}.c testcases expose a failure
>> with -mcmodel -fpic, where:
>>
>> /tmp/ccfpoxHY.o: In function `bar':
>> pr61599-2.c:(.text+0xe): relocation truncated to fit: R_X86_64_PC32
>> against symbol `a' defined in LARGE_COMMON section in /tmp/ccKTKST2.o
>> collect2: error: ld returned 1 exit status
>> compiler exited with status 1
>>
>> CM_MEDIUM_PIC code model assumes that code+got/plt fits in a 31 bit
>> region, data is unlimited. Based on these assumptions, code should be
>> accessed via R_X86_64_GOT64.
>>
>> Attached patch uses UNSPEC_GOT instead of UNSPEC_GOTPCREL also for
>> CM_MEDIUM_PIC.
>>
>> 2016-05-12  Uros Bizjak  <ubiz...@gmail.com>
>>
>>     PR target/61599
>>     * config/i386/i386.c (legitimize_pic_address): Do not use
>>     UNSPEC_GOTPCREL for CM_MEDIUM_PIC code model.
>>
>> Patch was bootstrapped on x86_64-linux-gnu and regression tested with
>> -mcmodel=medium -fpic.
>>
>> Jakub, H.J., do you have any comments on the patch?
>
>
> I prefer this patch.
>

Oops wrong one.  Here is the right one.


-- 
H.J.
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 8157f9d..a864868 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -15478,7 +15478,9 @@ legitimize_pic_address (rtx orig, rtx reg)
 	  new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_PCREL);
 	  new_rtx = gen_rtx_CONST (Pmode, new_rtx);
 	}
-      else if (TARGET_64BIT && ix86_cmodel != CM_LARGE_PIC)
+      else if (TARGET_64BIT
+	       && ix86_cmodel != CM_LARGE_PIC
+	       && !ix86_in_large_data_p (SYMBOL_REF_DECL (addr)))
 	{
 	  new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr),
 				    UNSPEC_GOTPCREL);

Reply via email to