From owner-freebsd-alpha Tue Sep 10 7: 4:52 2002 Delivered-To: freebsd-alpha@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 70CAA37B400; Tue, 10 Sep 2002 07:04:42 -0700 (PDT) Received: from srv1.cosmo-project.de (srv1.cosmo-project.de [213.83.6.106]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4DDA143E6A; Tue, 10 Sep 2002 07:04:41 -0700 (PDT) (envelope-from ticso@cicely5.cicely.de) Received: from cicely5.cicely.de (cicely5.cicely.de [IPv6:3ffe:400:8d0:301:200:92ff:fe9b:20e7]) by srv1.cosmo-project.de (8.12.5/8.12.5) with ESMTP id g8AE4J6K035027 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=OK); Tue, 10 Sep 2002 16:04:32 +0200 (CEST) (envelope-from ticso@cicely5.cicely.de) Received: from cicely5.cicely.de (localhost [IPv6:::1]) by cicely5.cicely.de (8.12.6/8.12.6) with ESMTP id g8AE4FZr005632 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO); Tue, 10 Sep 2002 16:04:15 +0200 (CEST) (envelope-from ticso@cicely5.cicely.de) Received: (from ticso@localhost) by cicely5.cicely.de (8.12.6/8.12.6/Submit) id g8AE4FxI005631; Tue, 10 Sep 2002 16:04:15 +0200 (CEST) (envelope-from ticso) Date: Tue, 10 Sep 2002 16:04:14 +0200 From: Bernd Walter To: Andrew Gallatin Cc: Joe Marcus Clarke , 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> Reply-To: ticso@cicely.de 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> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <15741.61382.872535.426732@grasshopper.cs.duke.edu> X-Operating-System: FreeBSD cicely5.cicely.de 5.0-CURRENT i386 User-Agent: Mutt/1.5.1i Sender: owner-freebsd-alpha@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org 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