This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/16665] New: [3.4.1] SH: wrong thunk
- From: "sugioka at itonet dot co dot jp" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 22 Jul 2004 01:31:14 -0000
- Subject: [Bug target/16665] New: [3.4.1] SH: wrong thunk
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
On sh*-linux, thunk code generated by g++-3.4.1 seems incorrect.
Attached code generates following thunk code.
In this case, '_ZThn4_N7Derived1vEv' is an entry point of virtual function
v() and exported from shared library through vtable.
When this function is called from main(), r12 has invalid value,
and jumps to wrong place.
------------------------------------
.set .LTHUNK1,_ZN7Derived1vEv
.section .gnu.linkonce.t._ZThn4_N7Derived1vEv,"ax",@progbits
.align 1
.weak _ZThn4_N7Derived1vEv
.type _ZThn4_N7Derived1vEv, @function
_ZThn4_N7Derived1vEv:
.LFB6:
.loc 2 13 0
add #-4,r4
mov.l .L5,r3
add r12,r3 <==== r12 has invalid value
jmp @r3 <==== jump to wrong place
nop
.L6:
.align 2
.L5:
.long .LTHUNK1@GOTOFF
.LFE6:
.size _ZThn4_N7Derived1vEv, .-_ZThn4_N7Derived1vEv
------------------------------------
////////////////////////////////////////////////////////////
build and execute as follows.
$ g++ -O -g -fPIC -c lib.cxx
$ g++ -shared -o libApp.so lib.o
$ g++ -O -g -o main -L. main.cxx -lApp
$ LD_LIBRARY_PATH=. ./main
Segmentation fault
////////////////////////////////////////////////////////////
// lib.h
class Base {
public: virtual void v() = 0;
};
class Base2 {
public: virtual void v2();
};
class Intermediate : public Base2, public Base {
public: virtual void v();
};
class Derived : public Intermediate {
public: virtual void v();
};
////////////////////////////////////////////////////////////
// lib.cxx
#include "lib.h"
void Base2::v2() {}
void Intermediate::v() {}
void Derived::v() {}
////////////////////////////////////////////////////////////
// main.cxx
#include "lib.h"
int main()
{
Derived obj;
Base *p = &obj;
p->v();
}
--
Summary: [3.4.1] SH: wrong thunk
Product: gcc
Version: 3.4.1
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: target
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: sugioka at itonet dot co dot jp
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: sh4-unknown-linux-gnu
GCC host triplet: sh4-unknown-linux-gnu
GCC target triplet: sh4-unknown-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16665