public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/36634]  New: -msecure-plt combine gives invalid call insn
@ 2008-06-25 21:30 amodra at bigpond dot net dot au
  2008-06-25 21:31 ` [Bug target/36634] " amodra at bigpond dot net dot au
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: amodra at bigpond dot net dot au @ 2008-06-25 21:30 UTC (permalink / raw)
  To: gcc-bugs

The -msecure-plt ABI requires that -fpic/-fPIC calls via the PLT have the GOT
pointer register valid.  gcc accomplishes this by adding pic_offset_table_rtx
to CALL_INSN_FUNCTION_USAGE for such calls at rtl expansion time.  See
rs6000.md define_expand "call".  Now, indirect calls do *not* need a GOT
pointer since they don't go via the PLT, and we wouldn't want indirect calls to
cause unnecessary code in a function prologue to set up the GOT pointer.  This
is a lurking problem for the RTL combiner if it should happen to see an
opportunity to combine an instruction loading a function pointer followed by an
indirect call, since it will combine them to a PLT call that lacks a use of
pic_offset_table_rtx.

$ cat pr44759.c
#include <stdio.h>
#include <stdlib.h>

extern void first_call (void);

int main (void)
{
  first_call ();
  printf ("All finished\n");
}
$ cat pr44759-1.c
#include <stdio.h>
#include <stdlib.h>

typedef void (*simple) (signed int);
void myprint (unsigned int i)
{
  printf("I am printing\n");
}

static inline void lets_inline (void (*p)(signed int), int v)
{
  (*p)(v);
}

void first_call (void)
{
  lets_inline ((simple)myprint, 0);
}
$ gcc -c pr44759.c -fPIC -O2 -msecure-plt
$ gcc -c pr44759-1.c -fPIC -O2 -msecure-plt
$ gcc -o libpr44759.so pr44759-1.o -fPIC -shared -msecure-plt
$ gcc -o pr44759 pr44759.o libpr44759.so
$ LD_LIBRARY_PATH=. ./pr44759
Segmentation fault

Note that the testcase does not fail on mainline or gcc-4.3, presumably because
combining happens at the tree level there.  I'm also not sure whether the
testcase is completely valid code, but even if not, there may be other ways to
expose the rtl combine error.


-- 
           Summary: -msecure-plt combine gives invalid call insn
           Product: gcc
           Version: 4.1.3
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: amodra at bigpond dot net dot au
GCC target triplet: powerpc-*-*


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36634


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

* [Bug target/36634] -msecure-plt combine gives invalid call insn
  2008-06-25 21:30 [Bug target/36634] New: -msecure-plt combine gives invalid call insn amodra at bigpond dot net dot au
@ 2008-06-25 21:31 ` amodra at bigpond dot net dot au
  2008-06-27  1:52 ` amodra at bigpond dot net dot au
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: amodra at bigpond dot net dot au @ 2008-06-25 21:31 UTC (permalink / raw)
  To: gcc-bugs



-- 

amodra at bigpond dot net dot au changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |amodra at bigpond dot net
                   |dot org                     |dot au
             Status|UNCONFIRMED                 |ASSIGNED
     Ever Confirmed|0                           |1
      Known to fail|                            |4.1.3 4.2.5
   Last reconfirmed|0000-00-00 00:00:00         |2008-06-25 21:30:58
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36634


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

* [Bug target/36634] -msecure-plt combine gives invalid call insn
  2008-06-25 21:30 [Bug target/36634] New: -msecure-plt combine gives invalid call insn amodra at bigpond dot net dot au
  2008-06-25 21:31 ` [Bug target/36634] " amodra at bigpond dot net dot au
@ 2008-06-27  1:52 ` amodra at bigpond dot net dot au
  2008-07-04  2:33 ` amodra at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: amodra at bigpond dot net dot au @ 2008-06-27  1:52 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from amodra at bigpond dot net dot au  2008-06-27 01:52 -------
(insn 9 8 11 1 (set (reg/v/f:SI 119 [ p ])
        (mem/u/c:SI (plus:SI (reg:SI 30 30)
                (const:SI (minus:SI (symbol_ref/u:SI ("*.LC2") [flags 0x2])
                        (symbol_ref:SI ("*.LCTOC1"))))) [5 S4 A8])) -1 (nil)
    (expr_list:REG_EQUAL (symbol_ref:SI ("myprint") [flags 0x1] <function_decl
0x40164300 myprint>)
        (nil)))

[snip]

(call_insn 12 11 13 1 (parallel [
            (call (mem:SI (reg/v/f:SI 119 [ p ]) [0 S4 A8])
                (const_int 0 [0x0]))
            (use (const_int 0 [0x0]))
            (clobber (scratch:SI))
        ]) -1 (nil)
    (nil)
    (expr_list:REG_DEP_TRUE (use (reg:SI 3 3))
        (nil)))

The first instruction is a GOT load of the function address, the second an
indirect call.  No problem there.  Indirect calls for -msecure-plt don't need
the GOT pointer to be valid.

The trouble occurrs when combine substitutes the first insn into the second to
get:

(call_insn 12 11 13 0 (parallel [
            (call (mem:SI (symbol_ref:SI ("myprint") [flags 0x1] <function_decl
0x40164300 myprint>) [0 S4 A8])
                (const_int 0 [0x0]))
            (use (const_int 0 [0x0]))
            (clobber (scratch:SI))
        ]) 402 {*call_nonlocal_sysv} (insn_list:REG_DEP_TRUE 11 (nil))
    (expr_list:REG_UNUSED (scratch:SI)
        (expr_list:REG_DEAD (reg:SI 3 3)
            (nil)))
    (expr_list:REG_DEP_TRUE (use (reg:SI 3 3))
        (nil)))

Note that lack of anything marking r30 as used.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36634


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

* [Bug target/36634] -msecure-plt combine gives invalid call insn
  2008-06-25 21:30 [Bug target/36634] New: -msecure-plt combine gives invalid call insn amodra at bigpond dot net dot au
                   ` (2 preceding siblings ...)
  2008-07-04  2:33 ` amodra at gcc dot gnu dot org
@ 2008-07-04  2:33 ` amodra at gcc dot gnu dot org
  2008-07-04  2:34 ` amodra at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: amodra at gcc dot gnu dot org @ 2008-07-04  2:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from amodra at gcc dot gnu dot org  2008-07-04 02:32 -------
Subject: Bug 36634

Author: amodra
Date: Fri Jul  4 02:32:01 2008
New Revision: 137447

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=137447
Log:
        PR target/36634
        * config/rs6000/rs6000.md (call, call_value): Don't arrange for
        pic_offset_table_rtx to be marked as used here.
        (call_nonlocal_sysv, call_value_nonlocal_sysv): Add split for
        TARGET_SECURE_PLT to "use" pic_offset_table_rtx.
        (call_nonlocal_sysv_secure, call_value_nonlocal_sysv_secure): New insn.
        (sibcall_nonlocal_sysv, sibcall_value_nonlocal_sysv): Assert
        !TARGET_SECURE_PLT.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/rs6000/rs6000.md


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36634


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

* [Bug target/36634] -msecure-plt combine gives invalid call insn
  2008-06-25 21:30 [Bug target/36634] New: -msecure-plt combine gives invalid call insn amodra at bigpond dot net dot au
  2008-06-25 21:31 ` [Bug target/36634] " amodra at bigpond dot net dot au
  2008-06-27  1:52 ` amodra at bigpond dot net dot au
@ 2008-07-04  2:33 ` amodra at gcc dot gnu dot org
  2008-07-04  2:33 ` amodra at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: amodra at gcc dot gnu dot org @ 2008-07-04  2:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from amodra at gcc dot gnu dot org  2008-07-04 02:33 -------
Subject: Bug 36634

Author: amodra
Date: Fri Jul  4 02:32:23 2008
New Revision: 137448

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=137448
Log:
        PR target/36634
        * config/rs6000/rs6000.md (call, call_value): Don't arrange for
        pic_offset_table_rtx to be marked as used here.
        (call_nonlocal_sysv, call_value_nonlocal_sysv): Add split for
        TARGET_SECURE_PLT to "use" pic_offset_table_rtx.
        (call_nonlocal_sysv_secure, call_value_nonlocal_sysv_secure): New insn.
        (sibcall_nonlocal_sysv, sibcall_value_nonlocal_sysv): Assert
        !TARGET_SECURE_PLT.


Modified:
    branches/gcc-4_3-branch/gcc/ChangeLog
    branches/gcc-4_3-branch/gcc/config/rs6000/rs6000.md


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36634


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

* [Bug target/36634] -msecure-plt combine gives invalid call insn
  2008-06-25 21:30 [Bug target/36634] New: -msecure-plt combine gives invalid call insn amodra at bigpond dot net dot au
                   ` (3 preceding siblings ...)
  2008-07-04  2:33 ` amodra at gcc dot gnu dot org
@ 2008-07-04  2:34 ` amodra at gcc dot gnu dot org
  2008-07-04  2:54 ` amodra at bigpond dot net dot au
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: amodra at gcc dot gnu dot org @ 2008-07-04  2:34 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from amodra at gcc dot gnu dot org  2008-07-04 02:34 -------
Subject: Bug 36634

Author: amodra
Date: Fri Jul  4 02:33:29 2008
New Revision: 137449

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=137449
Log:
        PR target/36634
        * config/rs6000/rs6000.md (call, call_value): Don't arrange for
        pic_offset_table_rtx to be marked as used here.
        (call_nonlocal_sysv, call_value_nonlocal_sysv): Add split for
        TARGET_SECURE_PLT to "use" pic_offset_table_rtx.
        (call_nonlocal_sysv_secure, call_value_nonlocal_sysv_secure): New insn.
        (sibcall_nonlocal_sysv, sibcall_value_nonlocal_sysv): Assert
        !TARGET_SECURE_PLT.


Modified:
    branches/gcc-4_2-branch/gcc/ChangeLog
    branches/gcc-4_2-branch/gcc/config/rs6000/rs6000.md


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36634


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

* [Bug target/36634] -msecure-plt combine gives invalid call insn
  2008-06-25 21:30 [Bug target/36634] New: -msecure-plt combine gives invalid call insn amodra at bigpond dot net dot au
                   ` (5 preceding siblings ...)
  2008-07-04  2:54 ` amodra at bigpond dot net dot au
@ 2008-07-04  2:54 ` amodra at bigpond dot net dot au
  2009-04-29 15:15 ` pinskia at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: amodra at bigpond dot net dot au @ 2008-07-04  2:54 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from amodra at bigpond dot net dot au  2008-07-04 02:53 -------
Fixed all active branches


-- 

amodra at bigpond dot net dot au changed:

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


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36634


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

* [Bug target/36634] -msecure-plt combine gives invalid call insn
  2008-06-25 21:30 [Bug target/36634] New: -msecure-plt combine gives invalid call insn amodra at bigpond dot net dot au
                   ` (4 preceding siblings ...)
  2008-07-04  2:34 ` amodra at gcc dot gnu dot org
@ 2008-07-04  2:54 ` amodra at bigpond dot net dot au
  2008-07-04  2:54 ` amodra at bigpond dot net dot au
  2009-04-29 15:15 ` pinskia at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: amodra at bigpond dot net dot au @ 2008-07-04  2:54 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from amodra at bigpond dot net dot au  2008-07-04 02:53 -------
Created an attachment (id=15850)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=15850&action=view)
patch for 4.1

Since there will be no more releases from 4.1 branch, I won't be applying the
patch to that branch.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36634


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

* [Bug target/36634] -msecure-plt combine gives invalid call insn
  2008-06-25 21:30 [Bug target/36634] New: -msecure-plt combine gives invalid call insn amodra at bigpond dot net dot au
                   ` (6 preceding siblings ...)
  2008-07-04  2:54 ` amodra at bigpond dot net dot au
@ 2009-04-29 15:15 ` pinskia at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-04-29 15:15 UTC (permalink / raw)
  To: gcc-bugs



-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |4.3.2


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36634


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

end of thread, other threads:[~2009-04-29 15:15 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-06-25 21:30 [Bug target/36634] New: -msecure-plt combine gives invalid call insn amodra at bigpond dot net dot au
2008-06-25 21:31 ` [Bug target/36634] " amodra at bigpond dot net dot au
2008-06-27  1:52 ` amodra at bigpond dot net dot au
2008-07-04  2:33 ` amodra at gcc dot gnu dot org
2008-07-04  2:33 ` amodra at gcc dot gnu dot org
2008-07-04  2:34 ` amodra at gcc dot gnu dot org
2008-07-04  2:54 ` amodra at bigpond dot net dot au
2008-07-04  2:54 ` amodra at bigpond dot net dot au
2009-04-29 15:15 ` pinskia at gcc dot gnu dot 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).