Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 23 Apr 1997 16:28:46 -0700 (MST)
From:      Terry Lambert <terry@lambert.org>
To:        nw1@cs.wustl.edu (Nanbor Wang)
Cc:        hackers@freebsd.org
Subject:   Re: Any compiler guru? (Was: 2 questions about C++ support in 2.2)
Message-ID:  <199704232328.QAA29868@phaeton.artisoft.com>
In-Reply-To: <199704231911.OAA17121@siesta.cs.wustl.edu> from "Nanbor Wang" at Apr 23, 97 02:11:43 pm

next in thread | previous in thread | raw e-mail | index | archive | help
> 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 <class Type>
struct QueueElement {
private:
	const Type              *pItem;
	QueueElement<Type>      *pNext;
};

foo.cc
--------

QueueElement<vnode>	*vnode_free;

fum.cc
--------
QueueElement<vnode>	*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.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199704232328.QAA29868>