Build libc++ against musl-libc.

Hi,

I’m trying to build libc++ against musl-libc ( www.musl-libc.org ), another linux C library. I have successfully built a musl-libc based C toolchain, a freestanding C++ compiler, and some C++ runtime libraries like libcxxrt, libunwind, I even succeeded in building libc++ against musl-libc, but a simple hello-world program won’t run.

the following code would throw a bad_cast exception:

#include
#include
#include

using namespace std;

int main() {
locale loc(“C”);
//cout.imbue(loc); // If this line is added, the whole program runs well.
cout << “hello” << endl;
return 0;
}

This is the call stack of the thrown exception:
#6 0x00000000004ce2d9 in __cxa_throw ()
#7 0x0000000000422a40 in std::__1::locale::__imp::use_facet(long) const ()
at /home/hoolala/workspace/bootcxx/out/libcxx/src/locale.cpp:439
#8 0x0000000000423379 in std::__1::locale::use_facet(std::__1::locale::id&) const ()
at /home/hoolala/workspace/bootcxx/out/libcxx/src/locale.cpp:581
#9 0x00000000004005ad in std::__1::basic_ostream<char, std::__1::char_traits >& std::__1::operator<< <std::__1::char_traits >(std::__1::basic_ostream<char, std::__1::char_traits >&, char const*) ()
at /home/hoolala/workspace/bootcxx/out/sysroot/usr/include/c++/v1/__locale:174
#10 0x000000000040035a in main () at loc.cpp:12

I applied a simple patch to the original libc++ code:

Index: include/__locale

Thank you for your efforts to port libc++ to musl-libc.

Unfortunately your patch below breaks other platforms. You will need to isolate your changes such that they only impact your platform.

Howard

Thank you for your efforts to port libc++ to musl-libc.

Unfortunately your patch below breaks other platforms. You will need to
isolate your changes such that they only impact your platform.

This patch is just a proof of concept. When I get most of the test cases
passed, I'll rewrite the whole patch, and do necessary isolation.