public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/67215] New: -fno-plt needs improvements for x86
@ 2015-08-14 12:37 andrew.n.senkevich at gmail dot com
  2015-08-14 12:45 ` [Bug target/67215] " hjl.tools at gmail dot com
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: andrew.n.senkevich at gmail dot com @ 2015-08-14 12:37 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 67215
           Summary: -fno-plt needs improvements for x86
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: andrew.n.senkevich at gmail dot com
                CC: hjl.tools at gmail dot com
  Target Milestone: ---

We shouldn't turn

call foo@plt

into

load foo@plt into %eax
call *%eax

We should keep

call/jmp *foo@GOT


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

* [Bug target/67215] -fno-plt needs improvements for x86
  2015-08-14 12:37 [Bug target/67215] New: -fno-plt needs improvements for x86 andrew.n.senkevich at gmail dot com
@ 2015-08-14 12:45 ` hjl.tools at gmail dot com
  2015-08-14 13:00 ` andrew.n.senkevich at gmail dot com
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: hjl.tools at gmail dot com @ 2015-08-14 12:45 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
   Last reconfirmed|                            |2015-08-14
   Target Milestone|---                         |6.0
     Ever confirmed|0                           |1

--- Comment #1 from H.J. Lu <hjl.tools at gmail dot com> ---
Please provide a testcase.


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

* [Bug target/67215] -fno-plt needs improvements for x86
  2015-08-14 12:37 [Bug target/67215] New: -fno-plt needs improvements for x86 andrew.n.senkevich at gmail dot com
  2015-08-14 12:45 ` [Bug target/67215] " hjl.tools at gmail dot com
@ 2015-08-14 13:00 ` andrew.n.senkevich at gmail dot com
  2015-08-14 13:07 ` hjl.tools at gmail dot com
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: andrew.n.senkevich at gmail dot com @ 2015-08-14 13:00 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Senkevich <andrew.n.senkevich at gmail dot com> ---
-bash-4.2$ cat test.c
extern int proc2(int);

int proc( void)
{
  int i = proc2( 3);

  return i;
}

gcc test.c -S -pie -fpie -o test.1.S
gcc test.c -S -pie -fpie -fno-plt -o test.2.S

-bash-4.2$ cat test.1.S
        .file   "test.c"
        .text
        .globl  proc
        .type   proc, @function
proc:
.LFB0:
        .cfi_startproc
        pushq   %rbp
        .cfi_def_cfa_offset 16
        .cfi_offset 6, -16
        movq    %rsp, %rbp
        .cfi_def_cfa_register 6
        subq    $16, %rsp
        movl    $3, %edi
        call    proc2@PLT
        movl    %eax, -4(%rbp)
        movl    -4(%rbp), %eax
        leave
        .cfi_def_cfa 7, 8
        ret
        .cfi_endproc
.LFE0:
        .size   proc, .-proc
        .ident  "GCC: (GNU) 6.0.0 20150812 (experimental)"
        .section        .note.GNU-stack,"",@progbits

-bash-4.2$ cat test.2.S
        .file   "test.c"
        .text
        .globl  proc
        .type   proc, @function
proc:
.LFB0:
        .cfi_startproc
        pushq   %rbp
        .cfi_def_cfa_offset 16
        .cfi_offset 6, -16
        movq    %rsp, %rbp
        .cfi_def_cfa_register 6
        subq    $16, %rsp
        movq    proc2@GOTPCREL(%rip), %rax
        movl    $3, %edi
        call    *%rax
        movl    %eax, -4(%rbp)
        movl    -4(%rbp), %eax
        leave
        .cfi_def_cfa 7, 8
        ret
        .cfi_endproc
.LFE0:
        .size   proc, .-proc
        .ident  "GCC: (GNU) 6.0.0 20150812 (experimental)"
        .section        .note.GNU-stack,"",@progbits


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

* [Bug target/67215] -fno-plt needs improvements for x86
  2015-08-14 12:37 [Bug target/67215] New: -fno-plt needs improvements for x86 andrew.n.senkevich at gmail dot com
  2015-08-14 12:45 ` [Bug target/67215] " hjl.tools at gmail dot com
  2015-08-14 13:00 ` andrew.n.senkevich at gmail dot com
@ 2015-08-14 13:07 ` hjl.tools at gmail dot com
  2015-08-14 15:25 ` andrew.n.senkevich at gmail dot com
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: hjl.tools at gmail dot com @ 2015-08-14 13:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from H.J. Lu <hjl.tools at gmail dot com> ---
(In reply to Andrew Senkevich from comment #2)
> -bash-4.2$ cat test.c
> extern int proc2(int);
> 
> int proc( void)
> {
>   int i = proc2( 3);
> 
>   return i;
> }
> 
> gcc test.c -S -pie -fpie -o test.1.S
> gcc test.c -S -pie -fpie -fno-plt -o test.2.S

Please provide a tectcase which shows the problem with -O1 and above
for both ia32 and x86-64.


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

* [Bug target/67215] -fno-plt needs improvements for x86
  2015-08-14 12:37 [Bug target/67215] New: -fno-plt needs improvements for x86 andrew.n.senkevich at gmail dot com
                   ` (2 preceding siblings ...)
  2015-08-14 13:07 ` hjl.tools at gmail dot com
@ 2015-08-14 15:25 ` andrew.n.senkevich at gmail dot com
  2015-08-14 15:34 ` hjl.tools at gmail dot com
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: andrew.n.senkevich at gmail dot com @ 2015-08-14 15:25 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Senkevich <andrew.n.senkevich at gmail dot com> ---
-bash-4.2$ cat test.c
extern char* mem(int);
char* arr[32];

void proc(void)
{
  int i;

  for (i=0;i<32;i++)
    arr[i] = mem(128);
}

gcc -pie -fpie -fno-plt -O2  -S test.c -o test_32.S -m32
gcc -pie -fpie -fno-plt -O2  -S test.c -o test_64.S

-bash-4.2$ cat test_32.S
. . .
proc:
.LFB0:
        .cfi_startproc
        call    __x86.get_pc_thunk.ax
        addl    $_GLOBAL_OFFSET_TABLE_, %eax
        pushl   %edi
        .cfi_def_cfa_offset 8
        .cfi_offset 7, -8
        pushl   %esi
        .cfi_def_cfa_offset 12
        .cfi_offset 6, -12
        pushl   %ebx
        .cfi_def_cfa_offset 16
        .cfi_offset 3, -16
        movl    arr@GOT(%eax), %ebx
        movl    mem@GOT(%eax), %esi
        leal    128(%ebx), %edi
        .p2align 4,,10
        .p2align 3
.L2:
        subl    $12, %esp
        .cfi_def_cfa_offset 28
        addl    $4, %ebx
        pushl   $128
        .cfi_def_cfa_offset 32
        call    *%esi
        movl    %eax, -4(%ebx)
        addl    $16, %esp
        .cfi_def_cfa_offset 16
        cmpl    %edi, %ebx
        jne     .L2
        popl    %ebx
        .cfi_restore 3
        .cfi_def_cfa_offset 12
        popl    %esi
        .cfi_restore 6
        .cfi_def_cfa_offset 8
        popl    %edi
        .cfi_restore 7
        .cfi_def_cfa_offset 4
        ret
        .cfi_endproc
.LFE0:
        .size   proc, .-proc
. . .

-bash-4.2$ cat test_64.S
. . .
proc:
.LFB0:
        .cfi_startproc
        pushq   %r12
        .cfi_def_cfa_offset 16
        .cfi_offset 12, -16
        pushq   %rbp
        .cfi_def_cfa_offset 24
        .cfi_offset 6, -24
        pushq   %rbx
        .cfi_def_cfa_offset 32
        .cfi_offset 3, -32
        movq    arr@GOTPCREL(%rip), %rbx
        movq    mem@GOTPCREL(%rip), %rbp
        leaq    256(%rbx), %r12
        .p2align 4,,10
        .p2align 3
.L2:
        movl    $128, %edi
        addq    $8, %rbx
        call    *%rbp
        movq    %rax, -8(%rbx)
        cmpq    %r12, %rbx
        jne     .L2
        popq    %rbx
        .cfi_def_cfa_offset 24
        popq    %rbp
        .cfi_def_cfa_offset 16
        popq    %r12
        .cfi_def_cfa_offset 8
        ret
        .cfi_endproc
.LFE0:
        .size   proc, .-proc
. . .


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

* [Bug target/67215] -fno-plt needs improvements for x86
  2015-08-14 12:37 [Bug target/67215] New: -fno-plt needs improvements for x86 andrew.n.senkevich at gmail dot com
                   ` (3 preceding siblings ...)
  2015-08-14 15:25 ` andrew.n.senkevich at gmail dot com
@ 2015-08-14 15:34 ` hjl.tools at gmail dot com
  2015-08-16  1:08 ` hjl.tools at gmail dot com
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: hjl.tools at gmail dot com @ 2015-08-14 15:34 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |NEW
                 CC|                            |izamyatin at gmail dot com,
                   |                            |kirill.yukhin at intel dot com


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

* [Bug target/67215] -fno-plt needs improvements for x86
  2015-08-14 12:37 [Bug target/67215] New: -fno-plt needs improvements for x86 andrew.n.senkevich at gmail dot com
                   ` (4 preceding siblings ...)
  2015-08-14 15:34 ` hjl.tools at gmail dot com
@ 2015-08-16  1:08 ` hjl.tools at gmail dot com
  2015-09-06 10:59 ` LpSolit at netscape dot net
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: hjl.tools at gmail dot com @ 2015-08-16  1:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from H.J. Lu <hjl.tools at gmail dot com> ---
Created attachment 36190
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36190&action=edit
A patch

For x86, -fno-plt should be handled by ix86_expand_call to
generate indirect call via GOT, not by forcing the function
address into a register in prepare_call_address.


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

* [Bug target/67215] -fno-plt needs improvements for x86
  2015-08-14 12:37 [Bug target/67215] New: -fno-plt needs improvements for x86 andrew.n.senkevich at gmail dot com
                   ` (5 preceding siblings ...)
  2015-08-16  1:08 ` hjl.tools at gmail dot com
@ 2015-09-06 10:59 ` LpSolit at netscape dot net
  2015-10-27 14:30 ` hjl.tools at gmail dot com
  2015-10-27 14:30 ` hjl at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: LpSolit at netscape dot net @ 2015-09-06 10:59 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from H.J. Lu <hjl.tools at gmail dot com> ---
(In reply to H.J. Lu from comment #5)
> Created attachment 36190 [details]
> A patch
> 
> For x86, -fno-plt should be handled by ix86_expand_call to
> generate indirect call via GOT, not by forcing the function
> address into a register in prepare_call_address.

We can avoid adding targetm.calls.call_via_reg_without_plt by
hijacking flag_plt:

if (!flag_plt)
{
  flag_x86_plt = 1;
  flag_plt = 0;
}


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

* [Bug target/67215] -fno-plt needs improvements for x86
  2015-08-14 12:37 [Bug target/67215] New: -fno-plt needs improvements for x86 andrew.n.senkevich at gmail dot com
                   ` (7 preceding siblings ...)
  2015-10-27 14:30 ` hjl.tools at gmail dot com
@ 2015-10-27 14:30 ` hjl at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: hjl at gcc dot gnu.org @ 2015-10-27 14:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from hjl at gcc dot gnu.org <hjl at gcc dot gnu.org> ---
Author: hjl
Date: Tue Oct 27 14:29:31 2015
New Revision: 229444

URL: https://gcc.gnu.org/viewcvs?rev=229444&root=gcc&view=rev
Log:
Properly handle -fno-plt in ix86_expand_call

prepare_call_address in calls.c is the wrong place to handle -fno-plt.
We shoudn't force function address into register and hope that load
function address via GOT and indirect call via register will be folded
into indirect call via GOT, which doesn't always happen.  Also non-PIC
case can only be handled in backend.  Instead, backend should expand
external function call into indirect call via GOT for -fno-plt.

This patch reverts -fno-plt in prepare_call_address and handles it in
ix86_expand_call.  Other backends may need similar changes to support
-fno-plt.  Alternately, we can introduce a target hook to indicate
whether an external function should be called via register for -fno-plt
so that i386 backend can disable it in prepare_call_address.

gcc/

        PR target/67215
        * calls.c (prepare_call_address): Don't handle -fno-plt here.
        * config/i386/i386.c (ix86_expand_call): Generate indirect call
        via GOT for -fno-plt.  Support indirect call via GOT for x32.
        * config/i386/predicates.md (sibcall_memory_operand): Allow
        GOT memory operand.

gcc/testsuite/

        PR target/67215
        * gcc.target/i386/pr67215-1.c: New test.
        * gcc.target/i386/pr67215-2.c: Likewise.
        * gcc.target/i386/pr67215-3.c: Likewise.

Added:
    trunk/gcc/testsuite/gcc.target/i386/pr67215-1.c
    trunk/gcc/testsuite/gcc.target/i386/pr67215-2.c
    trunk/gcc/testsuite/gcc.target/i386/pr67215-3.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/calls.c
    trunk/gcc/config/i386/i386.c
    trunk/gcc/config/i386/predicates.md
    trunk/gcc/testsuite/ChangeLog


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

* [Bug target/67215] -fno-plt needs improvements for x86
  2015-08-14 12:37 [Bug target/67215] New: -fno-plt needs improvements for x86 andrew.n.senkevich at gmail dot com
                   ` (6 preceding siblings ...)
  2015-09-06 10:59 ` LpSolit at netscape dot net
@ 2015-10-27 14:30 ` hjl.tools at gmail dot com
  2015-10-27 14:30 ` hjl at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: hjl.tools at gmail dot com @ 2015-10-27 14:30 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

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


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

end of thread, other threads:[~2015-10-27 14:30 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-14 12:37 [Bug target/67215] New: -fno-plt needs improvements for x86 andrew.n.senkevich at gmail dot com
2015-08-14 12:45 ` [Bug target/67215] " hjl.tools at gmail dot com
2015-08-14 13:00 ` andrew.n.senkevich at gmail dot com
2015-08-14 13:07 ` hjl.tools at gmail dot com
2015-08-14 15:25 ` andrew.n.senkevich at gmail dot com
2015-08-14 15:34 ` hjl.tools at gmail dot com
2015-08-16  1:08 ` hjl.tools at gmail dot com
2015-09-06 10:59 ` LpSolit at netscape dot net
2015-10-27 14:30 ` hjl.tools at gmail dot com
2015-10-27 14:30 ` hjl at gcc dot gnu.org

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