[PATCH] Make libc++ compile on linux (issue1164043)

Reviewers: cfe-dev_cs.uiuc.edu,

Message:
Let me know what you think.

Description:
I'm working on Ubuntu Hardy. Your mileage may vary on other platforms.
:slight_smile:

Everything compiles with this patch. The link currently fails with:

+ g++ algorithm.o bind.o chrono.o condition_variable.o exception.o
hash.o ios.o iostream.o locale.o memory.o mutex.o new.o random.o
stdexcept.o strstream.o system_error.o thread.o typeinfo.o utility.o
valarray.o -fPIC -o libc++.so.1.0 -shared -nodefaultlibs
-Wl,-soname,libc++.so.1 -lstdc++ -lc
exception.o:(.data.rel.ro._ZTISt13bad_exception[typeinfo for
std::bad_exception]+0x0): undefined reference to `vtable for
__cxxabiv1::__si_class_type_info'
ios.o:(.data.rel.ro._ZTINSt3__119__iostream_categoryE[typeinfo for
std::__1::__iostream_category]+0x0): undefined reference to `vtable for
__cxxabiv1::__si_class_type_info'
ios.o:(.data.rel.ro._ZTINSt3__19basic_iosIwNS_11char_traitsIwEEEE[typeinfo
for std::__1::basic_ios<wchar_t, std::__1::char_traits<wchar_t> >]+0x0):
undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
ios.o:(.data.rel.ro._ZTINSt3__19basic_iosIcNS_11char_traitsIcEEEE[typeinfo
for std::__1::basic_ios<char, std::__1::char_traits<char> >]+0x0):
undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
ios.o:(.data.rel.ro._ZTINSt3__18ios_base7failureE[typeinfo for
std::__1::ios_base::failure]+0x0): undefined reference to `vtable for
__cxxabiv1::__si_class_type_info'
iostream.o:(.data.rel.ro._ZTINSt3__110__stdinbufIcEE[typeinfo for
std::__1::__stdinbuf<char>]+0x0): more undefined references to `vtable
for __cxxabiv1::__si_class_type_info' follow
/usr/bin/ld: libc++.so.1.0: hidden symbol `vtable for
__cxxabiv1::__si_class_type_info' isn't defined
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: ld returned 1 exit status

None of the tests have been tested.

Please review this at http://codereview.appspot.com/1164043/show

Affected files:
   A include/__atomic_hack
   M include/__config
   M include/__locale
   M include/algorithm
   M include/cstddef
   M include/iosfwd
   M include/locale
   M include/string
   M include/thread
   M lib/buildit
   M src/chrono.cpp
   M src/exception.cpp
   M src/ios.cpp
   M src/locale.cpp
   M src/memory.cpp
   M src/mutex.cpp
   M src/new.cpp
   M src/stdexcept.cpp
   M src/system_error.cpp
   M src/thread.cpp

Reviewers: cfe-dev_cs.uiuc.edu,

Message:
Let me know what you think.

For the atomics, would it be possible to use the builtins for them instead of the OSAtomic* and inline asm.

-Chris

I just wanted to let you know that it is going to be several days before I have a chance to review your patch. Thanks for contributing it!

-Howard

Done.

Thanks much Jeffrey. This is checked in now. I did a little bit of modification with the <locale> __nolocale_* functions.

-Howard

What's the building option for libc++ on ubuntu.
I was using such options
export CXX="g++ -std=c++0x"

And the build result is

./buildit
./buildit: line 15: [: g++: binary operator expected
+ for FILE in '../src/*.cpp'
+ g++ -std=c++0x -c -g -Os -fPIC -nostdinc++ -I../include ../src/algorithm.cpp
+ for FILE in '../src/*.cpp'
+ g++ -std=c++0x -c -g -Os -fPIC -nostdinc++ -I../include ../src/bind.cpp
+ for FILE in '../src/*.cpp'
+ g++ -std=c++0x -c -g -Os -fPIC -nostdinc++ -I../include ../src/chrono.cpp
+ for FILE in '../src/*.cpp'
+ g++ -std=c++0x -c -g -Os -fPIC -nostdinc++ -I../include
../src/condition_variable.cpp
In file included from ../src/condition_variable.cpp:11:
../include/thread: In member function ‘std::__1::thread&
std::__1::thread::operator=(std::__1::thread&&)’:
../include/thread:268: error: no match for ‘operator!=’ in
‘((std::__1::thread*)this)->std::__1::thread::__t_ !=
std::__1::__get_nullptr_t()’
../include/system_error:569: note: candidates are: bool
std::__1::operator!=(const std::__1::error_condition&, const
std::__1::error_condition&)
../include/system_error:565: note: bool
std::__1::operator!=(const std::__1::error_condition&, const
std::__1::error_code&)
../include/system_error:561: note: bool
std::__1::operator!=(const std::__1::error_code&, const
std::__1::error_condition&)
../include/system_error:557: note: bool
std::__1::operator!=(const std::__1::error_code&, const
std::__1::error_code&)
../include/cstddef:73: note: bool
std::__1::operator!=(std::__1::nullptr_t, std::__1::nullptr_t)
../include/thread:271: error: cannot convert ‘std::__1::nullptr_t’ to
‘pthread_t’ in assignment
[3]+ Done gedit ./buildit

Also there is a patch for buildit
dreamkxd@lyg-laptop:~/workspace/libcxx/lib$ svn diff
Index: buildit

g++ -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
4.4.3-4ubuntu5'
--with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr
--enable-shared --enable-multiarch --enable-linker-build-id
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4
--program-suffix=-4.4 --enable-nls --enable-clocale=gnu
--enable-libstdcxx-debug --enable-plugin --enable-objc-gc
--enable-targets=all --disable-werror --with-arch-32=i486
--with-tune=generic --enable-checking=release --build=i486-linux-gnu
--host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5)

What's the building option for libc++ on ubuntu.
I was using such options
export CXX="g++ -std=c++0x"

And the build result is

./buildit
./buildit: line 15: [: g++: binary operator expected
+ for FILE in '../src/*.cpp'
+ g++ -std=c++0x -c -g -Os -fPIC -nostdinc++ -I../include ../src/algorithm.cpp
+ for FILE in '../src/*.cpp'
+ g++ -std=c++0x -c -g -Os -fPIC -nostdinc++ -I../include ../src/bind.cpp
+ for FILE in '../src/*.cpp'
+ g++ -std=c++0x -c -g -Os -fPIC -nostdinc++ -I../include ../src/chrono.cpp
+ for FILE in '../src/*.cpp'
+ g++ -std=c++0x -c -g -Os -fPIC -nostdinc++ -I../include
../src/condition_variable.cpp
In file included from ../src/condition_variable.cpp:11:
../include/thread: In member function ‘std::__1::thread&
std::__1::thread::operator=(std::__1::thread&&)’:
../include/thread:268: error: no match for ‘operator!=’ in
‘((std::__1::thread*)this)->std::__1::thread::__t_ !=
std::__1::__get_nullptr_t()’
../include/system_error:569: note: candidates are: bool
std::__1::operator!=(const std::__1::error_condition&, const
std::__1::error_condition&)
../include/system_error:565: note: bool
std::__1::operator!=(const std::__1::error_condition&, const
std::__1::error_code&)
../include/system_error:561: note: bool
std::__1::operator!=(const std::__1::error_code&, const
std::__1::error_condition&)
../include/system_error:557: note: bool
std::__1::operator!=(const std::__1::error_code&, const
std::__1::error_code&)
../include/cstddef:73: note: bool
std::__1::operator!=(std::__1::nullptr_t, std::__1::nullptr_t)
../include/thread:271: error: cannot convert ‘std::__1::nullptr_t’ to
‘pthread_t’ in assignment
[3]+ Done gedit ./buildit

On Mac OS, this code takes advantage of the fact that pthread_t is a pointer. Other arrangements will have to be made for when this is not the case. One important fact to remember in porting this code is that the pthread_t must have a state that represents "no thread". On Mac OS that state is the null pointer. Alternatively one could add an extra bool member to std::thread to indicate when the pthread_t does not represent a joinable thread.

Also there is a patch for buildit
dreamkxd@lyg-laptop:~/workspace/libcxx/lib$ svn diff
Index: buildit

--- buildit (revision 105318)
+++ buildit (working copy)
@@ -12,7 +12,7 @@
  exit 1
fi

-if [ -z $CXX ]
+if [ -z "$CXX" ]
then
  CXX=g++
fi

Thanks, I'll make this change next time I check in.

-Howard