[PATCH] D12512: [libcxxabi] Manually align pointers in __cxa_allocate_exception - Fixes PR24604

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 31 19:25:36 PDT 2015


EricWF added a comment.

In http://reviews.llvm.org/D12512#236988, @majnemer wrote:

> In http://reviews.llvm.org/D12512#236987, @EricWF wrote:
>
> > In http://reviews.llvm.org/D12512#236984, @majnemer wrote:
> >
> > > Wouldn't this change be problematic if you threw to code which was statically linked with a prior version of libcxxabi?
> >
> >
> > How do you mean? As in you have two different versions of libc++abi linked into one executable? If so your already in bad shape.
>
>
> Say you have two binaries, foo.exe and bar.so.  Foo.exe statically links against an older libc++abi and bar.so links against a newer libc++abi.  In this instance, our program has two copies of libc++abi statically linked with no ill effects and such a scenario was supported before this patch (at least AFAICT).
>
> However, we might have problems after this patch if foo.exe is linked against a newer static library than bar.so


If foo.exe is already getting `__cxa_allocate_exception(...)` from one libc++abi version and `__cxa_free_exception` from another then they are already in trouble because `__cxa_free_exception(ptr)` checks to see if `ptr` has been allocated from a builtin buffer.  This only happens when malloc is out of memory but it would still be an existing problem in the scenario you describe.

Furthermore the new code is only executed in cases where we already have undefined behavior.  We don't add any extra padding to the pointers returned from malloc unless not doing so would lead to UB.

I know if multiple instances of libc++abi in one executable is not supported on OS X (see FAQ at the bottom of libcxxabi.llvm.org). I don't know if thats supported on linux though. People really shouldn't be using a static libc++abi. In order for the exception handling globals to work there should only be one copy of the in the entire program.

Hopefully this change isn't too problematic and thanks for looking at it.


http://reviews.llvm.org/D12512





More information about the cfe-commits mailing list