[PATCH] D20677: Make it possible to build a -fno-exceptions libc++abi variant.

Asiri Rathnayake via cfe-commits cfe-commits at lists.llvm.org
Fri May 27 14:53:00 PDT 2016


rmaprath added a comment.

In http://reviews.llvm.org/D20677#442713, @EricWF wrote:

> In http://reviews.llvm.org/D20677#442687, @rmaprath wrote:
>
> > In http://reviews.llvm.org/D20677#442559, @EricWF wrote:
> >
> > > I have an issue with this change since it allows a libc++abi built without exceptions to be used in a program compiled with them. I assert that this should not be supported in any way.
> > >
> > > My personal preference would be to remove as much of the exception API from the library when it's built without exceptions. This should cause link errors if a program contains any code that throws. If this is not done it creates bugs within code like `__terminate` as mentioned in an inline comment.
> > >
> > > I would like to see another revision of this patch that removes as much of the exception API as possible. Looking at the symbols defined in `cxxabi.h` I would say ever symbol in sections 2.4 and 2.5 should not longer be defined in the library.
> >
> >
> > That sounds generally OK to me. The toolchain I'm working on (ARM Compiler 6) has an elaborate mechanism (based on build attributes) to select the correct variant of libraries. In other words, if any of your objects are compiled with exceptions, you are guaranteed to no select any of the no-exceptions library variants. This avoids the problem you mentioned altogether.
>
>
> Note that that behavior will cause different issues in some cases. If you  link an executable  to two libraries, `libfoo.so` and `libbar.so`, where one was compiled with exceptions and the other without you'll get two copies of libc++abi in the program. Now you have two copies of the global terminate handler and two copies of `__terminate` for the linker to select from.
>  If it selects the nothrow `__terminate` and the terminate handler throws an exception your in trouble.


In this case, I expect the linker to only select one variant of libc++abi (the one with exceptions). The idea behind build-attributes is to capture user intentions, if the user links his program with `libbar.a` and `libfoo.a` user libraries (with and without exceptions), the linker would assume that the user meant to use exceptions rather than not, and hence select the with-exceptions libc++abi variant. The theory behind build-attributes is bit more complicated that that though, I'm not the best person to go on about this.

In any case, I agree that getting the linker to produce an error (when linking with-exceptions objects with a no-exceptions libc++abi) is much more clearer.

I have a small concern about how difficult this would make things for us though - our toolchain setup uses `-ffunction-sections` and `-fdata-sections` along with linker's unused-section elimination to get rid of most of the stuff not necessary for the final image, but I can't remember if unused-section elimination happens before or after checking for missing symbols. If it is the latter, then we might be in trouble with this approach. I will have a look into this when I get back to work.

Cheers,

/ Asiri


http://reviews.llvm.org/D20677





More information about the cfe-commits mailing list