This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/14346] New: With -fpic/-fPIC, thunks jump through PLT, not directly to thunked function
- From: "hp at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 29 Feb 2004 16:12:36 -0000
- Subject: [Bug target/14346] New: With -fpic/-fPIC, thunks jump through PLT, not directly to thunked function
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
As in summary. Because thunks do not set up the PIC register, going through the
PLT causes a SEGV in best case. Another PIC construct than for normal calls
must be used, but unfortunately the only (currently) available PC-relative PIC
reloc for cris-axis-linux-gnu requests a PLT. The thunked function is global.
Using a local symbol makes the linker omit the redirection through the PLT and
the jump goes directly to the right place.
On trunk and 3.4 branch, the thunk uses a local symbol (equated to the thunked
function, generated by generic code), so TRT happens.
See <URL:http://gcc.gnu.org/ml/gcc-patches/2003-06/msg02603.html> for
the first of the patch where the generic local-thunk was implemented (needed
follow-up patches for correctness). I'll go with a target-local patch.
Testcase:
-------------- th1.h
class B
{
int bb1;
int bb2;
public:
virtual void b();
};
extern class B* mka();
-------------- th1.cc (compile and link with -fpic -shared -o libth1.so)
#include "th1.h"
class A
{
int aa;
public:
virtual void a() = 0;
};
class C : public A, public B
{
int cc;
public:
virtual void b();
virtual void a();
};
extern "C" void abort (void);
extern "C" void exit (int);
class B* mka (void)
{
return new C;
}
void C::b(void)
{
exit (0);
}
void B::b(void)
{
abort ();
}
void C::a(void)
{
abort ();
}
-------------- m.cc (compile and link with -L. -lth1, expect normal exit)
#include "th1.h"
extern "C" void abort (void);
int ii[10];
int main(void)
{
register int picreg
#if defined (__CRIS__) && !defined (__PIC__) && !defined (__pic__)
__asm__ ("r0")
#endif
= -1;
class B *bb = mka();
bb->b();
// Make sure picreg is alive and used after bb->b() above.
asm ("" : : "r" (picreg));
abort ();
}
--
Summary: With -fpic/-fPIC, thunks jump through PLT, not directly
to thunked function
Product: gcc
Version: unknown
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P1
Component: target
AssignedTo: hp at gcc dot gnu dot org
ReportedBy: hp at gcc dot gnu dot org
CC: gcc-bugs at gcc dot gnu dot org
GCC target triplet: cris-axis-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14346