libcxx on Linux: symbols used but not defined

Alexey Samsonov samsonov at google.com
Fri Feb 15 07:38:46 PST 2013


On Thu, Feb 14, 2013 at 7:44 PM, Michael van der Westhuizen <
r1mikey at gmail.com> wrote:

>
>
> On 14 Feb 2013, at 5:25 PM, Saleem Abdulrasool <compnerd at compnerd.org>
> wrote:
>
>
> On Feb 14, 2013 6:39 AM, "Alexey Samsonov" <samsonov at google.com> wrote:
> >
> >
> > On Thu, Feb 7, 2013 at 7:47 PM, Howard Hinnant <hhinnant at apple.com>
> wrote:
> >>
> >> On Feb 7, 2013, at 6:17 AM, Alexey Samsonov <samsonov at google.com>
> wrote:
> >>
> >> > Hi!
> >> >
> >> > I'm trying to build libcxx on Linux (Ubuntu Precise) using the
> following command:
> >> >
> >> > cmake -DLIBCXX_CXX_ABI=libsupc++
> '-DLIBCXX_LIBSUPCXX_INCLUDE_PATHS=/usr/include/c++/4.6;/usr/include/c++/4.6/x86_64-linux-gnu/.;'
> -DLIBCXX_ENABLE_EXCEPTIONS=OFF -DLIBCXX_ENABLE_SHARED=OFF
> -DLIBCXX_ENABLE_RTTI=OFF -DCMAKE_BUILD_TYPE=Release
> -DCMAKE_INSTALL_PREFIX=/tmp/tmp.boBpS5zFqt/libcxx_inst
> /tmp/tmp.boBpS5zFqt/libcxx
> >> >
> >> > and I want the result to be "hermetic" in the sense that resulting
> static library libc++.a doesn't reference undefined symbols from std::
> >> > However, I see the following problems:
> >> >
> >> > (libc++.a.new.cpp.o):/tmp/tmp.boBpS5zFqt/libcxx/src/new.cpp:function
> std::bad_alloc::~bad_alloc(): error: undefined reference to
> 'std::exception::~exception()'
> >> > (libc++.a.new.cpp.o):/tmp/tmp.boBpS5zFqt/libcxx/src/new.cpp:function
> std::bad_array_new_length::~bad_array_new_length(): error: undefined
> reference to 'std::exception::~exception()'
> >> > (libc++.a.new.cpp.o):/tmp/tmp.boBpS5zFqt/libcxx/src/new.cpp:function
> std::bad_array_new_length::~bad_array_new_length(): error: undefined
> reference to 'std::exception::~exception()'
> >> > (libc++.a.ios.cpp.o):/tmp/tmp.boBpS5zFqt/libcxx/src/ios.cpp:function
> std::__1::basic_ostream<char, std::__1::char_traits<char> >::flush():
> error: undefined reference to 'std::uncaught_exception()'
> >> > (libc++.a.ios.cpp.o):/tmp/tmp.boBpS5zFqt/libcxx/src/ios.cpp:function
> std::__1::basic_ostream<wchar_t, std::__1::char_traits<wchar_t> >::flush():
> error: undefined reference to 'std::uncaught_exception()'
> >> > (libc++.a.ios.cpp.o):/tmp/tmp.boBpS5zFqt/libcxx/src/ios.cpp:function
> std::__1::basic_ostream<char, std::__1::char_traits<char>
> >::sentry::~sentry(): error: undefined reference to
> 'std::uncaught_exception()'
> >> > (libc++.a.ios.cpp.o):/tmp/tmp.boBpS5zFqt/libcxx/src/ios.cpp:function
> std::__1::basic_ostream<char, std::__1::char_traits<char>
> >::sentry::~sentry(): error: undefined reference to
> 'std::uncaught_exception()'
> >> >
> (libc++.a.memory.cpp.o):/tmp/tmp.boBpS5zFqt/libcxx/src/memory.cpp:function
> std::__1::bad_weak_ptr::~bad_weak_ptr(): error: undefined reference to
> 'std::exception::~exception()'
> >> >
> (libc++.a.memory.cpp.o):/tmp/tmp.boBpS5zFqt/libcxx/src/memory.cpp:function
> vtable for std::__1::__shared_weak_count: error: undefined reference to
> 'std::__1::__shared_weak_count::__get_deleter(std::type_info const&) const'
> >> >
> (libc++.a.thread.cpp.o):/tmp/tmp.boBpS5zFqt/libcxx/src/thread.cpp:function
> std::__1::thread::~thread(): error: undefined reference to
> 'std::terminate()'
> >> >
> >> > What is the correct way to for that? I have the patch (attached) that
> works for me, but I'm not really sure it's correct
> >> > (especially the first part).
> >>
> >> Yeah, we tried this once:
> >>
> >> > --- include/memory    (revision 173248)
> >> > +++ include/memory    (working copy)
> >> > @@ -3629,10 +3629,9 @@
> >> >      long use_count() const _NOEXCEPT {return
> __shared_count::use_count();}
> >> >      __shared_weak_count* lock() _NOEXCEPT;
> >> >
> >> > -    // purposefully not protected with #ifndef _LIBCPP_NO_RTTI
> because doing so
> >> > -    //  breaks ABI for those clients who need to compile their
> projects with
> >> > -    //    -fno-rtti and yet link against a libc++.dylib compiled
> without -fno-rtti.
> >> > +#ifndef _LIBCPP_NO_RTTI
> >> >      virtual const void* __get_deleter(const type_info&) const
> _NOEXCEPT;
> >> > +#endif _LIBCPP_NO_RTTI
> >>
> >> and as the comments indicate, got bitten by it, at least on Apple
> platforms.
> >>
> >> Way forward:  Perhaps you could #ifdef it a little more in such a way
> that it isn't going to trigger except for someone trying to do exactly what
> you are doing:  Build a static lib on linux with rtti and exceptions off.
>  Or perhaps slightly more general:  Build a static lib with rtti and
> exceptions off.
> >
> >
> > Yes, I can add some #ifdefs here. But I also wonder about the second
> part of the patch:
> > I have __GLIBCXX__ defined because of commit:
> >
> > r173164 Saleem Abdulrasool: Ensure that __GLIBCXX__ is defined when
> building with libsupc++.
> >
> > and, as a result, I don't get definitions of terminate(),
> uncaught_exception(), exception>::~exception() and exception::what() in the
> resulting libc++ library,
> > yet these functions are referenced from it.
>
> Those functions are provided by libsupc++, and redefining them results in
> conflicts.  If you are building a static libc++, you would still need to
> link against the low level provider, or you need to merge a static copy of
> libsupc++ into your resulting libc++.a.
>
> You should also bear in mind that libsupc++ does not implement the
> dependent EH API, which is an extension that libc++ needs (due to the API
> for the ABI library not encapsulating sufficient functionality to be able
> to properly share a runtime library between standard libraries).  For now
> you'd probably be better off with libc++abi or libcxxrt if you want to use
> anything that requires exception_ptr, uncaught_exception or global
> terminate handlers.
>

Thanks for clarifications! I'll try to get the necessary parts from abi
libraries.

Howard, can you take a look at the attached patch that removes undefined
rtti-related function for the case when we build static library w/o RTTI?


>  > --
> > Alexey Samsonov, MSK
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
>


-- 
Alexey Samsonov, MSK
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130215/61f7b2e2/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: zdiff.patch_static
Type: application/octet-stream
Size: 1472 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130215/61f7b2e2/attachment.obj>


More information about the cfe-commits mailing list