Date: Tue, 10 Sep 2002 16:04:14 +0200 From: Bernd Walter <ticso@cicely5.cicely.de> To: Andrew Gallatin <gallatin@cs.duke.edu> Cc: Joe Marcus Clarke <marcus@marcuscom.com>, obrien@FreeBSD.ORG, alpha@FreeBSD.ORG Subject: Re: getting closer (was Re: mozilla failure on 4.6.2) Message-ID: <20020910140414.GC5057@cicely5.cicely.de> In-Reply-To: <15741.61382.872535.426732@grasshopper.cs.duke.edu> References: <1031329151.342.9.camel@gyros.marcuscom.com> <20020906194732.GA2244@dragon.nuxi.com> <15737.2550.488154.4401@grasshopper.cs.duke.edu> <20020907000825.GA4091@dragon.nuxi.com> <15739.43883.152090.936327@grasshopper.cs.duke.edu> <15741.2822.526047.253409@grasshopper.cs.duke.edu> <1031605410.351.90.camel@gyros.marcuscom.com> <15741.17468.701009.998323@grasshopper.cs.duke.edu> <1031635953.342.133.camel@gyros.marcuscom.com> <15741.61382.872535.426732@grasshopper.cs.duke.edu>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Sep 10, 2002 at 09:12:38AM -0400, Andrew Gallatin wrote: > > Joe Marcus Clarke writes: > > Add 8 to the stack pointer ("this", right), and store it in $16. > > I wish it were that simple :-( > > The problem seems to be that the application code is passing the > "wrong" value in and somehow the c++ calling standard corrects it, and > we must correct it too: > > impl == 0x12001c080 > foo == 0x12001c080 > bar == 0x12001c088 I have no idea how the class declaration for you example looks like. Possible because I don't know the mozilla code you are talking about. What is the difference in direct and invoke calling? Lets asume foo is a virtual function of class x which is based on class y defining the virtual function bar. From what I know about C++ (which might be outdated) we have the following situation when using an object of class x. Call of function bar means the caller knows the offset to the function pointer, because it's using a pointer of type x. The function bar expects a this pointer of type y so it gets the this pointer of the embedded y object which may be numericaly different. Now asume class x reimplement the virtual function bar. The newly bar function has to share the calling conventions that were declared by class y. If we call function bar using a type y pointer we submit a this pointer of type y. But the function is designed to have a this pointer of type x. Now the function must recalculate the supplied y pointer into an x pointer. If we call funtcion bar using a type x pointer we still have to convert the x pointer into an y pointer because the function still expects an y pointer. > Notice how "bar" = (char *)impl + 8 ? > > Somehow, when doing a "direct" call, the "this" pointer ends up as the > impl pointer, not as the "bar" pointer, even if "bar" is used in the > call. > > However, in the "invoke" code, we get literally what we asked for -- > the "this" pointer == the "bar" pointer. > > We need to somehow be able to tell that its a case like this and make > the this pointer be the impl pointer. > > Appended is sample output, with some of the methods modified to print out > the this pointer. > > Drew > > calling direct: > 1 + 1 = 2 > 1L + 1L = 2 > 2 * 2 = 4 > 2L * 2L = 4 > 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = 55 > 1 + 2 = 3.000000f > 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = 55.000000 > 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = 55.000000f > 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 +1 15 + 16 + 17 + 18 + 19 + 20 = 210.000000f > moo cow = milk > calling via invoke: > 1 + 1 = 2 > 1L + 1L = 2 > 2 * 2 = 4 > 2L * 2L = 4 > 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = 55 > 1 + 2 = 3.000000f > 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = 55.000000 > 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = 55.000000f > 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 = 210.000000f > moo cow = milk > > impl == 0x1200160c0 > foo == 0x1200160c0 > bar == 0x1200160d8 > Calling Foo... > direct calls: > this = 0x1200160c0 > FooImpl::FooMethod1 called with i == 1, FooImpl part of a FooBarImpl > this = 0x1200160c0 > FooImpl::FooMethod2 called with i == 2, FooImpl part of a FooBarImpl > invoke calls: > this = 0x1200160c0 > FooImpl::FooMethod1 called with i == 1, FooImpl part of a FooBarImpl > this = 0x1200160c0 > FooImpl::FooMethod2 called with i == 2, FooImpl part of a FooBarImpl > > Calling Bar... > direct calls: > this = 0x1200160d8 > BarImpl::BarMethod1 called with i == 1, BarImpl part of a FooBarImpl > this = 0x1200160d8 > BarImpl::BarMethod2 called with i == 2, BarImpl part of a FooBarImpl > invoke calls: > this = 0x1200160d8 > BarImpl::BarMethod1 called with i == 1, BarImpl part of a FooBarImpl > this = 0x1200160d8 > BarImpl::BarMethod2 called with i == 2, BarImpl part of a FooBarImpl > > > impl == 0x12001c080 > foo == 0x12001c080 > bar == 0x12001c088 > Calling Foo... > direct calls: > this = 0x12001c080 > FooBarImpl2::FooMethod1 called with i == 1, local value = 12345678 > this = 0x12001c080 > FooBarImpl2::FooMethod2 called with i == 2, local value = 12345678 > invoke calls: > this = 0x12001c080 > FooBarImpl2::FooMethod1 called with i == 1, local value = 12345678 > this = 0x12001c080 > FooBarImpl2::FooMethod2 called with i == 2, local value = 12345678 > > Calling Bar... > direct calls: > this = 0x12001c080 > FooBarImpl2::BarMethod1 called with i == 1, local value = 12345678 > this = 0x12001c080 > FooBarImpl2::BarMethod2 called with i == 2, local value = 12345678 > invoke calls: > this = 0x12001c088 > FooBarImpl2::BarMethod1 called with i == 1, local value = 0 > this = 0x12001c088 > FooBarImpl2::BarMethod2 called with i == 2, local value = 0 > > > > > > > To Unsubscribe: send mail to majordomo@FreeBSD.org > with "unsubscribe freebsd-alpha" in the body of the message -- B.Walter BWCT http://www.bwct.de ticso@bwct.de info@bwct.de B.Walter COSMO-Project http://www.cosmo-project.de ticso@cicely.de Usergroup info@cosmo-project.de To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-alpha" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020910140414.GC5057>