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

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