<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Sep 21, 2013 at 9:40 AM, Howard Hinnant <span dir="ltr"><<a href="mailto:hhinnant@apple.com" target="_blank">hhinnant@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Thank you for your efforts to port libc++ to musl-libc.<br></blockquote><div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Unfortunately your patch below breaks other platforms. You will need to isolate your changes such that they only impact your platform.<br></blockquote><br>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.<br>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Howard<br>
<div><div class="h5"><br>
On Sep 17, 2013, at 2:25 AM, 邓尧 <<a href="mailto:torshie@gmail.com">torshie@gmail.com</a>> wrote:<br>
<br>
> Hi,<br>
> I'm trying to build libc++ against musl-libc ( <a href="http://www.musl-libc.org" target="_blank">www.musl-libc.org</a> ), 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.<br>
><br>
> the following code would throw a bad_cast exception:<br>
><br>
> #include <locale><br>
> #include <iostream><br>
> #include <cstdio><br>
><br>
> using namespace std;<br>
><br>
> int main() {<br>
> locale loc("C");<br>
> //cout.imbue(loc); // If this line is added, the whole program runs well.<br>
> cout << "hello" << endl;<br>
> return 0;<br>
> }<br>
><br>
> This is the call stack of the thrown exception:<br>
> #6 0x00000000004ce2d9 in __cxa_throw ()<br>
> #7 0x0000000000422a40 in std::__1::locale::__imp::use_facet(long) const ()<br>
> at /home/hoolala/workspace/bootcxx/out/libcxx/src/locale.cpp:439<br>
> #8 0x0000000000423379 in std::__1::locale::use_facet(std::__1::locale::id&) const ()<br>
> at /home/hoolala/workspace/bootcxx/out/libcxx/src/locale.cpp:581<br>
> #9 0x00000000004005ad in std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::operator<< <std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*) ()<br>
> at /home/hoolala/workspace/bootcxx/out/sysroot/usr/include/c++/v1/__locale:174<br>
> #10 0x000000000040035a in main () at loc.cpp:12<br>
><br>
> I applied a simple patch to the original libc++ code:<br>
><br>
> Index: include/__locale<br>
> ===================================================================<br>
> --- include/__locale (revision 190843)<br>
> +++ include/__locale (working copy)<br>
> @@ -376,7 +376,7 @@<br>
> static const mask xdigit = _ISXDIGIT;<br>
> static const mask blank = _ISBLANK;<br>
> #else // __GLIBC__ || _WIN32 || __APPLE__ || __FreeBSD__ || EMSCRIPTEN || __sun__<br>
> - typedef unsigned long mask;<br>
> + typedef unsigned short mask;<br>
> static const mask space = 1<<0;<br>
> static const mask print = 1<<1;<br>
> static const mask cntrl = 1<<2;<br>
> Index: include/locale<br>
> ===================================================================<br>
> --- include/locale (revision 190843)<br>
> +++ include/locale (working copy)<br>
> @@ -829,7 +829,7 @@<br>
> typename remove_reference<decltype(errno)>::type __save_errno = errno;<br>
> errno = 0;<br>
> char *__p2;<br>
> - long long __ll = strtoll_l(__a, &__p2, __base, _LIBCPP_GET_C_LOCALE);<br>
> + long long __ll = strtoll(__a, &__p2, __base);<br>
> typename remove_reference<decltype(errno)>::type __current_errno = errno;<br>
> if (__current_errno == 0)<br>
> errno = __save_errno;<br>
> @@ -869,7 +869,7 @@<br>
> typename remove_reference<decltype(errno)>::type __save_errno = errno;<br>
> errno = 0;<br>
> char *__p2;<br>
> - unsigned long long __ll = strtoull_l(__a, &__p2, __base, _LIBCPP_GET_C_LOCALE);<br>
> + unsigned long long __ll = strtoull(__a, &__p2, __base);<br>
> typename remove_reference<decltype(errno)>::type __current_errno = errno;<br>
> if (__current_errno == 0)<br>
> errno = __save_errno;<br>
> @@ -899,7 +899,7 @@<br>
> typename remove_reference<decltype(errno)>::type __save_errno = errno;<br>
> errno = 0;<br>
> char *__p2;<br>
> - long double __ld = strtold_l(__a, &__p2, _LIBCPP_GET_C_LOCALE);<br>
> + long double __ld = strtold(__a, &__p2);<br>
> typename remove_reference<decltype(errno)>::type __current_errno = errno;<br>
> if (__current_errno == 0)<br>
> errno = __save_errno;<br>
> Index: src/locale.cpp<br>
> ===================================================================<br>
> --- src/locale.cpp (revision 190843)<br>
> +++ src/locale.cpp (working copy)<br>
> @@ -1005,6 +1005,8 @@<br>
> extern "C" const int ** __ctype_toupper_loc();<br>
> #endif<br>
><br>
> +extern "C" const unsigned short ** __ctype_b_loc();<br>
> +<br>
> const ctype<char>::mask*<br>
> ctype<char>::classic_table() _NOEXCEPT<br>
> {<br>
> @@ -1027,10 +1029,11 @@<br>
> #else<br>
> // Platform not supported: abort so the person doing the port knows what to<br>
> // fix<br>
> -# warning ctype<char>::classic_table() is not implemented<br>
> - printf("ctype<char>::classic_table() is not implemented\n");<br>
> - abort();<br>
> - return NULL;<br>
> +//# warning ctype<char>::classic_table() is not implemented<br>
> + //printf("ctype<char>::classic_table() is not implemented\n");<br>
> + //abort();<br>
> + //return NULL;<br>
> + return *__ctype_b_loc();<br>
> #endif<br>
> }<br>
><br>
> Did I miss anything in the patch ?<br>
><br>
> Thanks<br>
> Yao<br>
><br>
</div></div>> _______________________________________________<br>
> cfe-dev mailing list<br>
> <a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br>
</blockquote></div><br></div></div>