public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/63842] New: x86-64 large PIC model may load the GOT base into the wrong register
@ 2014-11-12 23:34 hjl.tools at gmail dot com
  2014-11-12 23:41 ` [Bug target/63842] " hjl.tools at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: hjl.tools at gmail dot com @ 2014-11-12 23:34 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63842

            Bug ID: 63842
           Summary: x86-64 large PIC model may load the GOT base into the
                    wrong register
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hjl.tools at gmail dot com
                CC: ubizjak at gmail dot com
            Target: x86-64

According to x86-64 psABI, when PLT is more 2GB from GOT, linker must use
large model PLT layout:

PLT0: pushq 8(%r15)   # GOT[1]
      jmpq  *16(%r15) # GOT[2]

That is fpr large PIC mode,  if a function calls another function via PLT,
it must load GOT base into %r15 before making function call. However,
GCC generates:

[hjl@gnu-6 pr17592]$ cat foo.c
#include <stdio.h>

void
foo (void)
{
  printf ("hello\n");
}
[hjl@gnu-6 pr17592]$ make foo.s
gcc -O2  -mcmodel=large -fpic -S foo.c
[hjl@gnu-6 pr17592]$ cat foo.s
    .file    "foo.c"
    .section    .rodata.str1.1,"aMS",@progbits,1
.LC0:
    .string    "hello"
    .text
    .p2align 4,,15
    .globl    foo
    .type    foo, @function
foo:
.LFB11:
    .cfi_startproc
.L2:
    leaq    .L2(%rip), %rcx
    movabsq    $_GLOBAL_OFFSET_TABLE_-.L2, %r11
    movabsq    $.LC0@GOTOFF, %rax
    addq    %r11, %rcx
    leaq    (%rcx,%rax), %rdi
    movabsq    $puts@PLTOFF, %rax
    addq    %rcx, %rax
    jmp    *%rax
    .cfi_endproc
.LFE11:
    .size    foo, .-foo
    .ident    "GCC: (GNU) 4.8.3 20140911 (Red Hat 4.8.3-7)"
    .section    .note.GNU-stack,"",@progbits
[hjl@gnu-6 pr17592]$ 

It works fine as long as large PLT layout isn't used.  But it fails
when large PLT layout is used.  Since puts is called via PLT, GCC
must load GOT base into %r15, instead of %r11.


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

* [Bug target/63842] x86-64 large PIC model may load the GOT base into the wrong register
  2014-11-12 23:34 [Bug target/63842] New: x86-64 large PIC model may load the GOT base into the wrong register hjl.tools at gmail dot com
@ 2014-11-12 23:41 ` hjl.tools at gmail dot com
  2014-11-27 21:30 ` hjl.tools at gmail dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: hjl.tools at gmail dot com @ 2014-11-12 23:41 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63842

--- Comment #1 from H.J. Lu <hjl.tools at gmail dot com> ---
The proper code sequence should be

pushq %r15
load GOT base into %r15
load address of puts PLT entry into %rdx
call *(%rdx)
popq %r15

That is similar to 32-bit.


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

* [Bug target/63842] x86-64 large PIC model may load the GOT base into the wrong register
  2014-11-12 23:34 [Bug target/63842] New: x86-64 large PIC model may load the GOT base into the wrong register hjl.tools at gmail dot com
  2014-11-12 23:41 ` [Bug target/63842] " hjl.tools at gmail dot com
@ 2014-11-27 21:30 ` hjl.tools at gmail dot com
  2021-08-09  7:33 ` pinskia at gcc dot gnu.org
  2021-08-09 12:40 ` hjl.tools at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: hjl.tools at gmail dot com @ 2014-11-27 21:30 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63842

H.J. Lu <hjl.tools at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-11-27
     Ever confirmed|0                           |1

--- Comment #2 from H.J. Lu <hjl.tools at gmail dot com> ---
r218132 generates:

main:
.LFB11:
    .cfi_startproc
.L2:
    leaq    .L2(%rip), %rax
    movabsq    $_GLOBAL_OFFSET_TABLE_-.L2, %r11
    movabsq    $.LC0@GOTOFF, %rdx
    pushq    %r15
    .cfi_def_cfa_offset 16
    .cfi_offset 15, -16
    addq    %r11, %rax
    leaq    (%rax,%rdx), %rdi
    movabsq    $puts@PLTOFF, %rdx
    movq    %rax, %r15
    addq    %rax, %rdx
    call    *%rdx
    xorl    %eax, %eax
    popq    %r15
    .cfi_def_cfa_offset 8
    ret
    .cfi_endproc
.LFE11:

It looks OK.  But it is hard to test without a linker supporting large
model PLT.  I will leave it open until I finish large model PLT support
in binutils so that I can verify it.


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

* [Bug target/63842] x86-64 large PIC model may load the GOT base into the wrong register
  2014-11-12 23:34 [Bug target/63842] New: x86-64 large PIC model may load the GOT base into the wrong register hjl.tools at gmail dot com
  2014-11-12 23:41 ` [Bug target/63842] " hjl.tools at gmail dot com
  2014-11-27 21:30 ` hjl.tools at gmail dot com
@ 2021-08-09  7:33 ` pinskia at gcc dot gnu.org
  2021-08-09 12:40 ` hjl.tools at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-09  7:33 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63842

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
   Target Milestone|---                         |5.0
             Status|NEW                         |RESOLVED

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed.

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

* [Bug target/63842] x86-64 large PIC model may load the GOT base into the wrong register
  2014-11-12 23:34 [Bug target/63842] New: x86-64 large PIC model may load the GOT base into the wrong register hjl.tools at gmail dot com
                   ` (2 preceding siblings ...)
  2021-08-09  7:33 ` pinskia at gcc dot gnu.org
@ 2021-08-09 12:40 ` hjl.tools at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: hjl.tools at gmail dot com @ 2021-08-09 12:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63842

H.J. Lu <hjl.tools at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|FIXED                       |DUPLICATE

--- Comment #4 from H.J. Lu <hjl.tools at gmail dot com> ---
Dup.

*** This bug has been marked as a duplicate of bug 63833 ***

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

end of thread, other threads:[~2021-08-09 12:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-12 23:34 [Bug target/63842] New: x86-64 large PIC model may load the GOT base into the wrong register hjl.tools at gmail dot com
2014-11-12 23:41 ` [Bug target/63842] " hjl.tools at gmail dot com
2014-11-27 21:30 ` hjl.tools at gmail dot com
2021-08-09  7:33 ` pinskia at gcc dot gnu.org
2021-08-09 12:40 ` hjl.tools at gmail dot com

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