[cfe-commits] patch: libcxxabi cxa_*_virtual and cxa_guard_* methods

John McCall rjmccall at apple.com
Sun May 22 14:00:59 PDT 2011

On May 22, 2011, at 1:55 PM, Nick Lewycky wrote:
> On 22 May 2011 13:52, John McCall <rjmccall at apple.com> wrote:
> On May 22, 2011, at 1:45 PM, Nick Lewycky wrote:
>> Back when I thought that we needed to support self-recursive initialization, I came up with a way to do this. The fundamental problem with pthread_self() is that it returns an 8-byte opaque object (ie., they aren't guaranteed to be dense), and C++11's thread library is worse. (Linux supports "gettid()" which returns a 4-byte ID which would fit neatly in the guard variable, but let's leave that aside for the moment.) We can construct our own thread ID by creating a thread_local variable, and we can make it use only 7 bytes by giving it 256 byte alignment. The recursion depth counter would then be kept on the initialization byte (supporting 254 levels of recursion depth with values 0 and 1 reserved for an unlocked guard variable).
> This won't work;  the initialization byte has to stay zero until initialization is complete.
> My mistake, of course the ABI document states that the first byte must not be modified by __cxa_guard_acquire.
> (By the way, unless I missed it, the ABI document never says that the guard variable is initialized to zero. It seems to me that it has to be though...)

I think you can read in a requirement that the first byte be statically initialized to zero, but yeah, I agree that the compiler really must zero-initialize the whole thing.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110522/c71975bf/attachment.html>

More information about the cfe-commits mailing list