public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH, i386]: Additional fix for PR62599 with -mcmodel=medium -fpic
@ 2016-05-12 22:03 Uros Bizjak
  2016-05-12 23:19 ` H.J. Lu
  0 siblings, 1 reply; 8+ messages in thread
From: Uros Bizjak @ 2016-05-12 22:03 UTC (permalink / raw)
  To: gcc-patches; +Cc: H.J. Lu, Jakub Jelinek

[-- Attachment #1: Type: text/plain, Size: 937 bytes --]

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  <ubizjak@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?

Uros.

[-- Attachment #2: p.diff.txt --]
[-- Type: text/plain, Size: 574 bytes --]

Index: config/i386/i386.c
===================================================================
--- config/i386/i386.c	(revision 236182)
+++ config/i386/i386.c	(working copy)
@@ -15475,7 +15475,7 @@ 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_SMALL_PIC)
 	{
 	  new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr),
 				    UNSPEC_GOTPCREL);

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH, i386]: Additional fix for PR62599 with -mcmodel=medium -fpic
  2016-05-12 22:03 [PATCH, i386]: Additional fix for PR62599 with -mcmodel=medium -fpic Uros Bizjak
@ 2016-05-12 23:19 ` H.J. Lu
  2016-05-12 23:20   ` H.J. Lu
  0 siblings, 1 reply; 8+ messages in thread
From: H.J. Lu @ 2016-05-12 23:19 UTC (permalink / raw)
  To: Uros Bizjak; +Cc: gcc-patches, Jakub Jelinek

[-- Attachment #1: Type: text/plain, Size: 1084 bytes --]

On Thu, May 12, 2016 at 3:02 PM, Uros Bizjak <ubizjak@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  <ubizjak@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.


-- 
H.J.

[-- Attachment #2: pr20070.patch --]
[-- Type: text/x-patch, Size: 676 bytes --]

diff --git a/ld/plugin.c b/ld/plugin.c
index bf66f52..01d76dd 100644
--- a/ld/plugin.c
+++ b/ld/plugin.c
@@ -674,7 +674,21 @@ get_symbols (const void *handle, int nsyms, struct ld_plugin_symbol *syms,
 					     syms[n].name, FALSE, FALSE, TRUE);
       if (!blhe)
 	{
-	  res = LDPR_UNKNOWN;
+	  /* This symbol is defined and referenced only in IR.  */
+	  switch (syms[n].def)
+	    {
+	    default:
+	      abort ();
+	    case LDPK_UNDEF:
+	    case LDPK_WEAKUNDEF:
+	      res = LDPR_UNDEF;
+	      break;
+	    case LDPK_DEF:
+	    case LDPK_WEAKDEF:
+	    case LDPK_COMMON:
+	      res = LDPR_PREVAILING_DEF_IRONLY;
+	      break;
+	    }
 	  goto report_symbol;
 	}
 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH, i386]: Additional fix for PR62599 with -mcmodel=medium -fpic
  2016-05-12 23:19 ` H.J. Lu
@ 2016-05-12 23:20   ` H.J. Lu
  2016-05-13  7:07     ` Uros Bizjak
  0 siblings, 1 reply; 8+ messages in thread
From: H.J. Lu @ 2016-05-12 23:20 UTC (permalink / raw)
  To: Uros Bizjak; +Cc: gcc-patches, Jakub Jelinek

[-- Attachment #1: Type: text/plain, Size: 1231 bytes --]

On Thu, May 12, 2016 at 4:19 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Thu, May 12, 2016 at 3:02 PM, Uros Bizjak <ubizjak@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  <ubizjak@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.

[-- Attachment #2: large.patch --]
[-- Type: text/x-patch, Size: 618 bytes --]

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);

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH, i386]: Additional fix for PR62599 with -mcmodel=medium -fpic
  2016-05-12 23:20   ` H.J. Lu
@ 2016-05-13  7:07     ` Uros Bizjak
  2016-05-13 16:51       ` Uros Bizjak
  0 siblings, 1 reply; 8+ messages in thread
From: Uros Bizjak @ 2016-05-13  7:07 UTC (permalink / raw)
  To: H.J. Lu; +Cc: gcc-patches, Jakub Jelinek

On Fri, May 13, 2016 at 1:20 AM, H.J. Lu <hjl.tools@gmail.com> wrote:

>>> 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  <ubizjak@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.

Yes, your patch is more precise.

Thanks,
Uros.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH, i386]: Additional fix for PR62599 with -mcmodel=medium -fpic
  2016-05-13  7:07     ` Uros Bizjak
@ 2016-05-13 16:51       ` Uros Bizjak
  2016-05-13 17:03         ` Uros Bizjak
  2016-05-13 17:21         ` H.J. Lu
  0 siblings, 2 replies; 8+ messages in thread
From: Uros Bizjak @ 2016-05-13 16:51 UTC (permalink / raw)
  To: H.J. Lu; +Cc: gcc-patches, Jakub Jelinek

On Fri, May 13, 2016 at 9:07 AM, Uros Bizjak <ubizjak@gmail.com> wrote:
> On Fri, May 13, 2016 at 1:20 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>
>>>> 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  <ubizjak@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.

> Yes, your patch is more precise.

OTOH, are we sure there is no linker bug here? We have:

$ objdump -dr pr61599-1a.o

pr61599-1a.o:     file format elf64-x86-64


Disassembly of section .text:

0000000000000000 <main>:
   0:   55                      push   %rbp
   1:   48 89 e5                mov    %rsp,%rbp
   4:   48 8d 05 00 00 00 00    lea    0x0(%rip),%rax        # b <main+0xb>
                        7: R_X86_64_GOTPC32     _GLOBAL_OFFSET_TABLE_-0x4
   b:   b8 00 00 00 00          mov    $0x0,%eax
  10:   e8 00 00 00 00          callq  15 <main+0x15>
                        11: R_X86_64_PLT32      bar-0x4
  15:   89 c2                   mov    %eax,%edx
  17:   48 8b 05 00 00 00 00    mov    0x0(%rip),%rax        # 1e <main+0x1e>
                        1a: R_X86_64_GOTPCREL   c-0x4
  1e:   0f b6 80 e1 00 00 00    movzbl 0xe1(%rax),%eax
  25:   0f be c0                movsbl %al,%eax
  28:   01 d0                   add    %edx,%eax
  2a:   5d                      pop    %rbp
  2b:   c3                      retq

$ objdump -dr pr61599-2a.o

pr61599-2a.o:     file format elf64-x86-64


Disassembly of section .text:

0000000000000000 <bar>:
   0:   55                      push   %rbp
   1:   48 89 e5                mov    %rsp,%rbp
   4:   48 8d 05 00 00 00 00    lea    0x0(%rip),%rax        # b <bar+0xb>
                        7: R_X86_64_GOTPC32     _GLOBAL_OFFSET_TABLE_-0x4
   b:   48 8b 05 00 00 00 00    mov    0x0(%rip),%rax        # 12 <bar+0x12>
                        e: R_X86_64_GOTPCREL    a-0x4
  12:   0f b6 40 02             movzbl 0x2(%rax),%eax
  16:   0f be d0                movsbl %al,%edx
  19:   48 8b 05 00 00 00 00    mov    0x0(%rip),%rax        # 20 <bar+0x20>
                        1c: R_X86_64_GOTPCREL   b-0x4
  20:   0f b6 40 10             movzbl 0x10(%rax),%eax
  24:   0f be c0                movsbl %al,%eax
  27:   01 c2                   add    %eax,%edx
  29:   48 8b 05 00 00 00 00    mov    0x0(%rip),%rax        # 30 <bar+0x30>
                        2c: R_X86_64_GOTPCREL   c-0x4
  30:   0f b6 80 00 01 00 00    movzbl 0x100(%rax),%eax
  37:   0f be c0                movsbl %al,%eax
  3a:   01 d0                   add    %edx,%eax
  3c:   5d                      pop    %rbp
  3d:   c3                      retq

$ gcc pr61599-2a.o pr61599-1a.o
pr61599-2a.o: In function `bar':
pr61599-2a.c:(.text+0xe): relocation truncated to fit: R_X86_64_PC32
against symbol `a' defined in LARGE_COMMON section in pr61599-1a.o
collect2: error: ld returned 1 exit status

There is no R_X86_64_PC32 in pr61599-2a.o, only X86_64_GOTPCREL, which
according to assumptions, would reach all entries in the GOT table.

Uros.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH, i386]: Additional fix for PR62599 with -mcmodel=medium -fpic
  2016-05-13 16:51       ` Uros Bizjak
@ 2016-05-13 17:03         ` Uros Bizjak
  2016-05-13 17:21         ` H.J. Lu
  1 sibling, 0 replies; 8+ messages in thread
From: Uros Bizjak @ 2016-05-13 17:03 UTC (permalink / raw)
  To: H.J. Lu; +Cc: gcc-patches, Jakub Jelinek

On Fri, May 13, 2016 at 6:51 PM, Uros Bizjak <ubizjak@gmail.com> wrote:
> On Fri, May 13, 2016 at 9:07 AM, Uros Bizjak <ubizjak@gmail.com> wrote:
>> On Fri, May 13, 2016 at 1:20 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>
>>>>> 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  <ubizjak@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.
>
>> Yes, your patch is more precise.
>
> OTOH, are we sure there is no linker bug here? We have:
>
> $ objdump -dr pr61599-1a.o
>
> pr61599-1a.o:     file format elf64-x86-64
>
>
> Disassembly of section .text:
>
> 0000000000000000 <main>:
>    0:   55                      push   %rbp
>    1:   48 89 e5                mov    %rsp,%rbp
>    4:   48 8d 05 00 00 00 00    lea    0x0(%rip),%rax        # b <main+0xb>
>                         7: R_X86_64_GOTPC32     _GLOBAL_OFFSET_TABLE_-0x4
>    b:   b8 00 00 00 00          mov    $0x0,%eax
>   10:   e8 00 00 00 00          callq  15 <main+0x15>
>                         11: R_X86_64_PLT32      bar-0x4
>   15:   89 c2                   mov    %eax,%edx
>   17:   48 8b 05 00 00 00 00    mov    0x0(%rip),%rax        # 1e <main+0x1e>
>                         1a: R_X86_64_GOTPCREL   c-0x4
>   1e:   0f b6 80 e1 00 00 00    movzbl 0xe1(%rax),%eax
>   25:   0f be c0                movsbl %al,%eax
>   28:   01 d0                   add    %edx,%eax
>   2a:   5d                      pop    %rbp
>   2b:   c3                      retq
>
> $ objdump -dr pr61599-2a.o
>
> pr61599-2a.o:     file format elf64-x86-64
>
>
> Disassembly of section .text:
>
> 0000000000000000 <bar>:
>    0:   55                      push   %rbp
>    1:   48 89 e5                mov    %rsp,%rbp
>    4:   48 8d 05 00 00 00 00    lea    0x0(%rip),%rax        # b <bar+0xb>
>                         7: R_X86_64_GOTPC32     _GLOBAL_OFFSET_TABLE_-0x4
>    b:   48 8b 05 00 00 00 00    mov    0x0(%rip),%rax        # 12 <bar+0x12>
>                         e: R_X86_64_GOTPCREL    a-0x4
>   12:   0f b6 40 02             movzbl 0x2(%rax),%eax
>   16:   0f be d0                movsbl %al,%edx
>   19:   48 8b 05 00 00 00 00    mov    0x0(%rip),%rax        # 20 <bar+0x20>
>                         1c: R_X86_64_GOTPCREL   b-0x4
>   20:   0f b6 40 10             movzbl 0x10(%rax),%eax
>   24:   0f be c0                movsbl %al,%eax
>   27:   01 c2                   add    %eax,%edx
>   29:   48 8b 05 00 00 00 00    mov    0x0(%rip),%rax        # 30 <bar+0x30>
>                         2c: R_X86_64_GOTPCREL   c-0x4
>   30:   0f b6 80 00 01 00 00    movzbl 0x100(%rax),%eax
>   37:   0f be c0                movsbl %al,%eax
>   3a:   01 d0                   add    %edx,%eax
>   3c:   5d                      pop    %rbp
>   3d:   c3                      retq
>
> $ gcc pr61599-2a.o pr61599-1a.o
> pr61599-2a.o: In function `bar':
> pr61599-2a.c:(.text+0xe): relocation truncated to fit: R_X86_64_PC32
> against symbol `a' defined in LARGE_COMMON section in pr61599-1a.o
> collect2: error: ld returned 1 exit status
>
> There is no R_X86_64_PC32 in pr61599-2a.o, only X86_64_GOTPCREL, which
> according to assumptions, would reach all entries in the GOT table.

It is a bug in GNU linker:

$ gcc -fuse-ld=gold pr61599-2a.o pr61599-1a.o
$ ./a.out

Uros.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH, i386]: Additional fix for PR62599 with -mcmodel=medium -fpic
  2016-05-13 16:51       ` Uros Bizjak
  2016-05-13 17:03         ` Uros Bizjak
@ 2016-05-13 17:21         ` H.J. Lu
  2016-05-13 17:22           ` Uros Bizjak
  1 sibling, 1 reply; 8+ messages in thread
From: H.J. Lu @ 2016-05-13 17:21 UTC (permalink / raw)
  To: Uros Bizjak; +Cc: gcc-patches, Jakub Jelinek

On Fri, May 13, 2016 at 9:51 AM, Uros Bizjak <ubizjak@gmail.com> wrote:
> On Fri, May 13, 2016 at 9:07 AM, Uros Bizjak <ubizjak@gmail.com> wrote:
>> On Fri, May 13, 2016 at 1:20 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>
>>>>> 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  <ubizjak@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.
>
>> Yes, your patch is more precise.
>
> OTOH, are we sure there is no linker bug here? We have:
>
> $ objdump -dr pr61599-1a.o
>
> pr61599-1a.o:     file format elf64-x86-64
>
>
> Disassembly of section .text:
>
> 0000000000000000 <main>:
>    0:   55                      push   %rbp
>    1:   48 89 e5                mov    %rsp,%rbp
>    4:   48 8d 05 00 00 00 00    lea    0x0(%rip),%rax        # b <main+0xb>
>                         7: R_X86_64_GOTPC32     _GLOBAL_OFFSET_TABLE_-0x4
>    b:   b8 00 00 00 00          mov    $0x0,%eax
>   10:   e8 00 00 00 00          callq  15 <main+0x15>
>                         11: R_X86_64_PLT32      bar-0x4
>   15:   89 c2                   mov    %eax,%edx
>   17:   48 8b 05 00 00 00 00    mov    0x0(%rip),%rax        # 1e <main+0x1e>
>                         1a: R_X86_64_GOTPCREL   c-0x4
>   1e:   0f b6 80 e1 00 00 00    movzbl 0xe1(%rax),%eax
>   25:   0f be c0                movsbl %al,%eax
>   28:   01 d0                   add    %edx,%eax
>   2a:   5d                      pop    %rbp
>   2b:   c3                      retq
>
> $ objdump -dr pr61599-2a.o
>
> pr61599-2a.o:     file format elf64-x86-64
>
>
> Disassembly of section .text:
>
> 0000000000000000 <bar>:
>    0:   55                      push   %rbp
>    1:   48 89 e5                mov    %rsp,%rbp
>    4:   48 8d 05 00 00 00 00    lea    0x0(%rip),%rax        # b <bar+0xb>
>                         7: R_X86_64_GOTPC32     _GLOBAL_OFFSET_TABLE_-0x4
>    b:   48 8b 05 00 00 00 00    mov    0x0(%rip),%rax        # 12 <bar+0x12>
>                         e: R_X86_64_GOTPCREL    a-0x4
>   12:   0f b6 40 02             movzbl 0x2(%rax),%eax
>   16:   0f be d0                movsbl %al,%edx
>   19:   48 8b 05 00 00 00 00    mov    0x0(%rip),%rax        # 20 <bar+0x20>
>                         1c: R_X86_64_GOTPCREL   b-0x4
>   20:   0f b6 40 10             movzbl 0x10(%rax),%eax
>   24:   0f be c0                movsbl %al,%eax
>   27:   01 c2                   add    %eax,%edx
>   29:   48 8b 05 00 00 00 00    mov    0x0(%rip),%rax        # 30 <bar+0x30>
>                         2c: R_X86_64_GOTPCREL   c-0x4
>   30:   0f b6 80 00 01 00 00    movzbl 0x100(%rax),%eax
>   37:   0f be c0                movsbl %al,%eax
>   3a:   01 d0                   add    %edx,%eax
>   3c:   5d                      pop    %rbp
>   3d:   c3                      retq
>
> $ gcc pr61599-2a.o pr61599-1a.o
> pr61599-2a.o: In function `bar':
> pr61599-2a.c:(.text+0xe): relocation truncated to fit: R_X86_64_PC32
> against symbol `a' defined in LARGE_COMMON section in pr61599-1a.o
> collect2: error: ld returned 1 exit status
>
> There is no R_X86_64_PC32 in pr61599-2a.o, only X86_64_GOTPCREL, which
> according to assumptions, would reach all entries in the GOT table.

I opened:

https://sourceware.org/bugzilla/show_bug.cgi?id=20093

-- 
H.J.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH, i386]: Additional fix for PR62599 with -mcmodel=medium -fpic
  2016-05-13 17:21         ` H.J. Lu
@ 2016-05-13 17:22           ` Uros Bizjak
  0 siblings, 0 replies; 8+ messages in thread
From: Uros Bizjak @ 2016-05-13 17:22 UTC (permalink / raw)
  To: H.J. Lu; +Cc: gcc-patches, Jakub Jelinek

On Fri, May 13, 2016 at 7:20 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Fri, May 13, 2016 at 9:51 AM, Uros Bizjak <ubizjak@gmail.com> wrote:
>> On Fri, May 13, 2016 at 9:07 AM, Uros Bizjak <ubizjak@gmail.com> wrote:
>>> On Fri, May 13, 2016 at 1:20 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>
>>>>>> 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  <ubizjak@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.
>>
>>> Yes, your patch is more precise.
>>
>> OTOH, are we sure there is no linker bug here? We have:
>>
>> $ objdump -dr pr61599-1a.o
>>
>> pr61599-1a.o:     file format elf64-x86-64
>>
>>
>> Disassembly of section .text:
>>
>> 0000000000000000 <main>:
>>    0:   55                      push   %rbp
>>    1:   48 89 e5                mov    %rsp,%rbp
>>    4:   48 8d 05 00 00 00 00    lea    0x0(%rip),%rax        # b <main+0xb>
>>                         7: R_X86_64_GOTPC32     _GLOBAL_OFFSET_TABLE_-0x4
>>    b:   b8 00 00 00 00          mov    $0x0,%eax
>>   10:   e8 00 00 00 00          callq  15 <main+0x15>
>>                         11: R_X86_64_PLT32      bar-0x4
>>   15:   89 c2                   mov    %eax,%edx
>>   17:   48 8b 05 00 00 00 00    mov    0x0(%rip),%rax        # 1e <main+0x1e>
>>                         1a: R_X86_64_GOTPCREL   c-0x4
>>   1e:   0f b6 80 e1 00 00 00    movzbl 0xe1(%rax),%eax
>>   25:   0f be c0                movsbl %al,%eax
>>   28:   01 d0                   add    %edx,%eax
>>   2a:   5d                      pop    %rbp
>>   2b:   c3                      retq
>>
>> $ objdump -dr pr61599-2a.o
>>
>> pr61599-2a.o:     file format elf64-x86-64
>>
>>
>> Disassembly of section .text:
>>
>> 0000000000000000 <bar>:
>>    0:   55                      push   %rbp
>>    1:   48 89 e5                mov    %rsp,%rbp
>>    4:   48 8d 05 00 00 00 00    lea    0x0(%rip),%rax        # b <bar+0xb>
>>                         7: R_X86_64_GOTPC32     _GLOBAL_OFFSET_TABLE_-0x4
>>    b:   48 8b 05 00 00 00 00    mov    0x0(%rip),%rax        # 12 <bar+0x12>
>>                         e: R_X86_64_GOTPCREL    a-0x4
>>   12:   0f b6 40 02             movzbl 0x2(%rax),%eax
>>   16:   0f be d0                movsbl %al,%edx
>>   19:   48 8b 05 00 00 00 00    mov    0x0(%rip),%rax        # 20 <bar+0x20>
>>                         1c: R_X86_64_GOTPCREL   b-0x4
>>   20:   0f b6 40 10             movzbl 0x10(%rax),%eax
>>   24:   0f be c0                movsbl %al,%eax
>>   27:   01 c2                   add    %eax,%edx
>>   29:   48 8b 05 00 00 00 00    mov    0x0(%rip),%rax        # 30 <bar+0x30>
>>                         2c: R_X86_64_GOTPCREL   c-0x4
>>   30:   0f b6 80 00 01 00 00    movzbl 0x100(%rax),%eax
>>   37:   0f be c0                movsbl %al,%eax
>>   3a:   01 d0                   add    %edx,%eax
>>   3c:   5d                      pop    %rbp
>>   3d:   c3                      retq
>>
>> $ gcc pr61599-2a.o pr61599-1a.o
>> pr61599-2a.o: In function `bar':
>> pr61599-2a.c:(.text+0xe): relocation truncated to fit: R_X86_64_PC32
>> against symbol `a' defined in LARGE_COMMON section in pr61599-1a.o
>> collect2: error: ld returned 1 exit status
>>
>> There is no R_X86_64_PC32 in pr61599-2a.o, only X86_64_GOTPCREL, which
>> according to assumptions, would reach all entries in the GOT table.
>
> I opened:
>
> https://sourceware.org/bugzilla/show_bug.cgi?id=20093

I  also reported

https://sourceware.org/bugzilla/show_bug.cgi?id=20092

Thanks,
Uros.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-05-13 17:22 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-12 22:03 [PATCH, i386]: Additional fix for PR62599 with -mcmodel=medium -fpic Uros Bizjak
2016-05-12 23:19 ` H.J. Lu
2016-05-12 23:20   ` H.J. Lu
2016-05-13  7:07     ` Uros Bizjak
2016-05-13 16:51       ` Uros Bizjak
2016-05-13 17:03         ` Uros Bizjak
2016-05-13 17:21         ` H.J. Lu
2016-05-13 17:22           ` Uros Bizjak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).