From owner-freebsd-hackers Wed Apr 23 16:31:43 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.5/8.8.5) id QAA00326 for hackers-outgoing; Wed, 23 Apr 1997 16:31:43 -0700 (PDT) Received: from phaeton.artisoft.com (phaeton.Artisoft.COM [198.17.250.50]) by hub.freebsd.org (8.8.5/8.8.5) with SMTP id QAA00320 for ; Wed, 23 Apr 1997 16:31:40 -0700 (PDT) Received: (from terry@localhost) by phaeton.artisoft.com (8.6.11/8.6.9) id QAA29868; Wed, 23 Apr 1997 16:28:46 -0700 From: Terry Lambert Message-Id: <199704232328.QAA29868@phaeton.artisoft.com> Subject: Re: Any compiler guru? (Was: 2 questions about C++ support in 2.2) To: nw1@cs.wustl.edu (Nanbor Wang) Date: Wed, 23 Apr 1997 16:28:46 -0700 (MST) Cc: hackers@freebsd.org In-Reply-To: <199704231911.OAA17121@siesta.cs.wustl.edu> from "Nanbor Wang" at Apr 23, 97 02:11:43 pm X-Mailer: ELM [version 2.4 PL24] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk > I have been working on porting ACE to FreeBSD platform on and off for > quite some time. Fortunately, I have solved most of the problem for a > non-thread version of ACE and will ask the author of ACE to commit the > changes into his lastest version very soon. > > However, I got caught by a possibly buggy behavior of g++ on FreeBSD. > ACE uses a lot of (advanced?) features of C++ and it seems to me that > we don't have a very good C++ support on our platform. I've seen this > issue being raised several times but never recalled to see an answer > or solution or fix to it. ;( [ ... ] > /var/tmp/cc022478.s:16783: Warning: GOT relocation burb: `__vt$15ACE_Local_Mutex > ' should be global [ ... ] > p.s. I hate to say this but Linux handles this code without a glitch > which makes me very uncomfortable. This was covered a few months back on the -current list by Warner Losh, the resident C++ guru. Linux is running ELF. ELF can emit a seperate section for duplicate instances of a particular template class (it's instantiated when it is used). For instance, TQueue.h: -------- template struct QueueElement { private: const Type *pItem; QueueElement *pNext; }; foo.cc -------- QueueElement *vnode_free; fum.cc -------- QueueElement *vnode_allocated; Would create two instances of the vnode QueueElement class, one in foo.o and one in fum.o. In FreeBSD, these are static because a.out format does not support generating the code in a seperate section (which the linker would then discard, based on it being a duplicate of an existing section). Linux generates the code in ELF format, and puts the code in a seperate section, and the ELF linker only includes one instance of the code. Linux executables can be much, much smaller because of this. Typically, when you do this with templates, you turn off the code generation for the inline (static, locally scoped to a single object file) code, and seperately compile the class instance in it's own .cc file, without the flags to turn off the code generation and with flags to make it globally scoped. Then you have a single instance of the class member functions. Most likely, in the FreeBSD case, this hybrid compilation which results in the warnings you are getting is resulting in the constructor for the virtual base class not getting called. In the static library case, the constructor is added to the linker set at link time, and called on program startup. So turn off that "optimization" for ACE on FreeBSD and live with the (much) bigger objects that get produced. Regards, Terry Lambert terry@lambert.org --- Any opinions in this posting are my own and not those of my present or previous employers.