This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/36634] New: -msecure-plt combine gives invalid call insn
- From: "amodra at bigpond dot net dot au" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 25 Jun 2008 21:29:30 -0000
- Subject: [Bug target/36634] New: -msecure-plt combine gives invalid call insn
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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