Placement of vtables, inlines and such

Daveed Vandevoorde daveed at edg.com
Fri Jun 25 06:04:38 UTC 1999


Jason Merrill wrote:
[...]
> No.  gc works by sweeping from main, finding all the referenced symbols;
> any sections that haven't provided any symbols are discarded.  If we use
> weak symbols for vtables and put them in separate sections, gc will keep at
> most one copy, as needed.  There is no notion of a special symbol.

How does this work in shared libraries? Is GC done at load time?

> gc is a more general solution, as it also can discard normal code that
> isn't actually needed.  It also allows us to discard all copies in cases
> where that is appropriate, such as when we can get the vtable from one of
> our shared libs. 

I guess that means the answer to the above is "yes"?

[...]
> This does bring up another issue; handling initialization.  g++ handles
> initialization of a weak/COMDAT object by emitting a sentry along with it,
> which gets set when the object has been initialized.

Do you thread-protect it? (just curious)

[...]
> Aha.  I guess there's no point in trying to avoid dealing with local
> statics then.

I'm afraid so. An idiom to protect against initialization order
dependencies is:
	inline X& x() {
		static X lx;
		return lx;
	}

(and use x() instead of a global x everywhere.)

I've seen increased usage of this and it would be nice if it could be
inlined.

	Daveed




More information about the cxx-abi-dev mailing list