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 (); }
Subject: Bug 14346 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_3-branch Changes by: hp@gcc.gnu.org 2004-02-29 21:46:29 Modified files: gcc : ChangeLog gcc/config/cris: cris.c Log message: PR target/14346 * config/cris/cris.c (cris_asm_output_mi_thunk): For PIC, prepend TAB to jumping "add.d" insn. Avoid PLT indirection by equating a local symbol and jumping through it. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.16114.2.913&r2=1.16114.2.914 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/cris/cris.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.32.4.2&r2=1.32.4.3
See <URL:http://gcc.gnu.org/ml/gcc-patches/2004-02/msg02798.html>.