Skip to content

Commit 90338c6

Browse files
Get things working with the new libcxx / libcxxabi.
1 parent 1a0bccc commit 90338c6

File tree

11 files changed

+816
-474
lines changed

11 files changed

+816
-474
lines changed

emcc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,6 @@ try:
11021102
o_s = []
11031103
libc_files = [
11041104
'dlmalloc.c',
1105-
os.path.join('libcxx', 'new.cpp'),
11061105
os.path.join('libc', 'stdlib', 'getopt_long.c'),
11071106
os.path.join('libc', 'gen', 'err.c'),
11081107
os.path.join('libc', 'gen', 'errx.c'),
@@ -1166,7 +1165,8 @@ try:
11661165
'ios.cpp',
11671166
'locale.cpp',
11681167
'regex.cpp',
1169-
'strstream.cpp'
1168+
'strstream.cpp',
1169+
'typeinfo.cpp'
11701170
]
11711171
for src in libcxx_files:
11721172
o = in_temp(src + '.o')
@@ -1189,8 +1189,14 @@ try:
11891189
if DEBUG: print >> sys.stderr, 'emcc: building libcxxabi for cache'
11901190
os = []
11911191
libcxxabi_files = [
1192+
'abort_message.cpp',
11921193
'private_typeinfo.cpp',
1193-
'typeinfo.cpp'
1194+
'typeinfo.cpp',
1195+
'cxa_new_delete.cpp',
1196+
'cxa_handlers.cpp',
1197+
'stdexcept.cpp',
1198+
'exception.cpp',
1199+
'cxa_exception_storage.cpp']:
11941200
]
11951201
for src in libcxxabi_files:
11961202
o = in_temp(src + '.o')

src/library.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5082,6 +5082,10 @@ LibraryManager.library = {
50825082
_ZSt18uncaught_exceptionv: function() { // std::uncaught_exception()
50835083
return !!__ZSt18uncaught_exceptionv.uncaught_exception;
50845084
},
5085+
__cxa_uncaught_exception__deps: ['_Zst18uncaught_exceptionv'],
5086+
__cxa_uncaught_exception: function() {
5087+
return !!__ZSt18uncaught_exceptionv.uncaught_exception;
5088+
},
50855089

50865090
__cxa_call_unexpected: function(exception) {
50875091
Module.printErr('Unexpected exception thrown, this is not properly supported - aborting');

system/include/libcxx/__locale

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
#include <locale.h>
2222
#if _WIN32
2323
# include <support/win32/locale_win32.h>
24-
#elif (__GLIBC__ || __APPLE__ || __FreeBSD__ || __sun__)
24+
#elif (__GLIBC__ || __APPLE__ || __FreeBSD__ || __sun__ || EMSCRIPTEN)
2525
# include <xlocale.h>
26-
#endif // _WIN32 || __GLIBC__ || __APPLE__ || __FreeBSD_
26+
#endif // _WIN32 || __GLIBC__ || __APPLE__ || __FreeBSD__ || EMSCRIPTEN
2727

2828
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2929
#pragma GCC system_header
@@ -339,11 +339,13 @@ public:
339339
static const mask punct = _PUNCT;
340340
static const mask xdigit = _HEX;
341341
static const mask blank = _BLANK;
342-
#elif (__APPLE__ || __FreeBSD__)
342+
#elif (__APPLE__ || __FreeBSD__ || EMSCRIPTEN)
343343
#if __APPLE__
344344
typedef __uint32_t mask;
345345
#elif __FreeBSD__
346346
typedef unsigned long mask;
347+
#elif EMSCRIPTEN
348+
typedef unsigned short mask;
347349
#endif
348350
static const mask space = _CTYPE_S;
349351
static const mask print = _CTYPE_R;
@@ -367,7 +369,7 @@ public:
367369
static const mask punct = _ISPUNCT;
368370
static const mask xdigit = _ISXDIGIT;
369371
static const mask blank = _ISBLANK;
370-
#else // __GLIBC__ || _WIN32 || __APPLE__ || __FreeBSD__ || __sun__
372+
#else // __GLIBC__ || _WIN32 || __APPLE__ || __FreeBSD__ || EMSCRIPTEN || __sun__
371373
typedef unsigned long mask;
372374
static const mask space = 1<<0;
373375
static const mask print = 1<<1;
@@ -590,7 +592,7 @@ public:
590592
#endif
591593
_LIBCPP_ALWAYS_INLINE const mask* table() const _NOEXCEPT {return __tab_;}
592594
static const mask* classic_table() _NOEXCEPT;
593-
#if defined(__GLIBC__)
595+
#if defined(__GLIBC__) || defined(EMSCRIPTEN)
594596
static const int* __classic_upper_table() _NOEXCEPT;
595597
static const int* __classic_lower_table() _NOEXCEPT;
596598
#endif

system/include/libcxx/locale

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ typedef _VSTD::unique_ptr<__locale_struct, decltype(&uselocale)> __locale_raii;
222222
// OSX has nice foo_l() functions that let you turn off use of the global
223223
// locale. Linux, not so much. The following functions avoid the locale when
224224
// that's possible and otherwise do the wrong thing. FIXME.
225-
#ifdef __linux__
225+
#if defined(__linux__) || defined(EMSCRIPTEN)
226226

227227
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
228228
decltype(MB_CUR_MAX_L(_VSTD::declval<locale_t>()))

system/lib/libc.symbols

Lines changed: 42 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,51 @@
1+
_err
2+
_errx
3+
_verr
4+
_verrx
5+
_vwarn
6+
_vwarnx
7+
_warn
8+
_warnx
9+
atof
10+
bulk_free
11+
calloc
12+
err
13+
errx
14+
free
115
getopt
216
getopt_long
317
getopt_long_only
4-
malloc
5-
free
6-
calloc
7-
memalign
8-
realloc
9-
valloc
10-
pvalloc
18+
independent_calloc
19+
independent_comalloc
1120
mallinfo
12-
mallopt
13-
malloc_trim
14-
malloc_stats
15-
malloc_usable_size
21+
malloc
1622
malloc_footprint
23+
malloc_footprint_limit
1724
malloc_max_footprint
18-
independent_calloc
19-
independent_comalloc
20-
_Znwj
21-
_Znaj
22-
_Znam
23-
_Znwm
24-
_ZdaPv
25-
_ZdaPvRKSt9nothrow_t
26-
_ZdlPv
27-
_ZdlPvRKSt9nothrow_t
28-
_Znaj
29-
_ZnajRKSt9nothrow_t
30-
_Znwj
31-
_ZnwjRKSt9nothrow_t
32-
_ZL13__new_handler
33-
_ZSt15get_new_handlerv
34-
_ZSt15set_new_handlerPFvvE
35-
_ZTVSt9bad_alloc
36-
_ZTSSt9bad_alloc
37-
_ZNKSt9bad_alloc4whatEv
38-
_ZNSt9bad_allocC1Ev
39-
_ZNSt9bad_allocC2Ev
40-
_ZNSt9bad_allocD0Ev
41-
_ZNSt9bad_allocD1Ev
42-
_ZNSt9bad_allocD2Ev
43-
_ZSt17__throw_bad_allocv
44-
_ZTISt9bad_alloc
45-
_ZTVSt20bad_array_new_length
46-
_ZTSSt20bad_array_new_length
47-
_ZTISt20bad_array_new_length
48-
_ZNKSt20bad_array_new_length4whatEv
49-
_ZNSt20bad_array_new_lengthC1Ev
50-
_ZNSt20bad_array_new_lengthC2Ev
51-
_ZNSt20bad_array_new_lengthD0Ev
52-
_ZNSt20bad_array_new_lengthD1Ev
53-
_ZNSt20bad_array_new_lengthD2Ev
54-
warn
55-
warnx
56-
err
57-
errx
58-
_warn
59-
_warnx
60-
_err
61-
_errx
62-
vwarn
63-
vwarnx
64-
verr
65-
verrx
66-
_vwarn
67-
_vwarnx
68-
_verr
69-
_verrx
25+
malloc_set_footprint_limit
26+
malloc_stats
27+
malloc_trim
28+
malloc_usable_size
29+
mallopt
30+
memalign
31+
optarg
32+
opterr
33+
optind
34+
optopt
35+
optreset
36+
posix_memalign
37+
pvalloc
38+
realloc
39+
realloc_in_place
7040
strtod
71-
strtold
72-
strtof
7341
strtod_l
42+
strtof
43+
strtold
7444
strtold_l
75-
atof
45+
valloc
46+
verr
47+
verrx
48+
vwarn
49+
vwarnx
50+
warn1
51+
warnx

system/lib/libcxx/locale.cpp

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ ctype<wchar_t>::do_toupper(char_type c) const
786786
{
787787
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
788788
return isascii(c) ? _DefaultRuneLocale.__mapupper[c] : c;
789-
#elif defined(__GLIBC__)
789+
#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
790790
return isascii(c) ? ctype<char>::__classic_upper_table()[c] : c;
791791
#else
792792
return (isascii(c) && iswlower_l(c, __cloc())) ? c-L'a'+L'A' : c;
@@ -799,7 +799,7 @@ ctype<wchar_t>::do_toupper(char_type* low, const char_type* high) const
799799
for (; low != high; ++low)
800800
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
801801
*low = isascii(*low) ? _DefaultRuneLocale.__mapupper[*low] : *low;
802-
#elif defined(__GLIBC__)
802+
#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
803803
*low = isascii(*low) ? ctype<char>::__classic_upper_table()[*low]
804804
: *low;
805805
#else
@@ -813,7 +813,7 @@ ctype<wchar_t>::do_tolower(char_type c) const
813813
{
814814
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
815815
return isascii(c) ? _DefaultRuneLocale.__maplower[c] : c;
816-
#elif defined(__GLIBC__)
816+
#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
817817
return isascii(c) ? ctype<char>::__classic_lower_table()[c] : c;
818818
#else
819819
return (isascii(c) && isupper_l(c, __cloc())) ? c-L'A'+'a' : c;
@@ -826,7 +826,7 @@ ctype<wchar_t>::do_tolower(char_type* low, const char_type* high) const
826826
for (; low != high; ++low)
827827
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
828828
*low = isascii(*low) ? _DefaultRuneLocale.__maplower[*low] : *low;
829-
#elif defined(__GLIBC__)
829+
#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
830830
*low = isascii(*low) ? ctype<char>::__classic_lower_table()[*low]
831831
: *low;
832832
#else
@@ -893,7 +893,7 @@ ctype<char>::do_toupper(char_type c) const
893893
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
894894
return isascii(c) ?
895895
static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(c)]) : c;
896-
#elif defined(__GLIBC__)
896+
#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
897897
return isascii(c) ?
898898
static_cast<char>(__classic_upper_table()[static_cast<size_t>(c)]) : c;
899899
#else
@@ -908,7 +908,7 @@ ctype<char>::do_toupper(char_type* low, const char_type* high) const
908908
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
909909
*low = isascii(*low) ?
910910
static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(*low)]) : *low;
911-
#elif defined(__GLIBC__)
911+
#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
912912
*low = isascii(*low) ?
913913
static_cast<char>(__classic_upper_table()[static_cast<size_t>(*low)]) : *low;
914914
#else
@@ -923,7 +923,7 @@ ctype<char>::do_tolower(char_type c) const
923923
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
924924
return isascii(c) ?
925925
static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(c)]) : c;
926-
#elif defined(__GLIBC__)
926+
#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
927927
return isascii(c) ?
928928
static_cast<char>(__classic_lower_table()[static_cast<size_t>(c)]) : c;
929929
#else
@@ -937,7 +937,7 @@ ctype<char>::do_tolower(char_type* low, const char_type* high) const
937937
for (; low != high; ++low)
938938
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
939939
*low = isascii(*low) ? static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(*low)]) : *low;
940-
#elif defined(__GLIBC__)
940+
#elif defined(__GLIBC__) || defined(EMSCRIPTEN)
941941
*low = isascii(*low) ? static_cast<char>(__classic_lower_table()[static_cast<size_t>(*low)]) : *low;
942942
#else
943943
*low = (isascii(*low) && isupper_l(*low, __cloc())) ? *low-'A'+'a' : *low;
@@ -978,6 +978,12 @@ ctype<char>::do_narrow(const char_type* low, const char_type* high, char dfault,
978978
return low;
979979
}
980980

981+
#ifdef EMSCRIPTEN
982+
extern "C" const unsigned short ** __ctype_b_loc();
983+
extern "C" const int ** __ctype_tolower_loc();
984+
extern "C" const int ** __ctype_toupper_loc();
985+
#endif
986+
981987
const ctype<char>::mask*
982988
ctype<char>::classic_table() _NOEXCEPT
983989
{
@@ -991,6 +997,8 @@ ctype<char>::classic_table() _NOEXCEPT
991997
return _ctype+1; // internal ctype mask table defined in msvcrt.dll
992998
// This is assumed to be safe, which is a nonsense assumption because we're
993999
// going to end up dereferencing it later...
1000+
#elif EMSCRIPTEN
1001+
return *__ctype_b_loc();
9941002
#else
9951003
// Platform not supported: abort so the person doing the port knows what to
9961004
// fix
@@ -1014,6 +1022,20 @@ ctype<char>::__classic_upper_table() _NOEXCEPT
10141022
}
10151023
#endif // __GLIBC__
10161024

1025+
#if defined(EMSCRIPTEN)
1026+
const int*
1027+
ctype<char>::__classic_lower_table() _NOEXCEPT
1028+
{
1029+
return *__ctype_tolower_loc();
1030+
}
1031+
1032+
const int*
1033+
ctype<char>::__classic_upper_table() _NOEXCEPT
1034+
{
1035+
return *__ctype_toupper_loc();
1036+
}
1037+
#endif // EMSCRIPTEN
1038+
10171039
// template <> class ctype_byname<char>
10181040

10191041
ctype_byname<char>::ctype_byname(const char* name, size_t refs)

0 commit comments

Comments
 (0)