diff options
author | Bruce Mitchener <bruce.mitchener@gmail.com> | 2013-04-22 17:38:22 +0700 |
---|---|---|
committer | Bruce Mitchener <bruce.mitchener@gmail.com> | 2013-04-22 18:51:43 +0700 |
commit | 654b36699e487b3d12a1827603f5f97414ee8d13 (patch) | |
tree | 497238a565fd39a1c0866a030e0f5ed98d4a9c22 | |
parent | 7cacf252e7f99fc2c98b969f8076011cfb6854d1 (diff) |
Move wchar,mb stuff to libcextra.
-rwxr-xr-x | emcc | 66 | ||||
-rw-r--r-- | system/lib/libcextra.symbols | 48 | ||||
-rwxr-xr-x | tests/runner.py | 16 |
3 files changed, 112 insertions, 18 deletions
@@ -1127,6 +1127,44 @@ try: os.path.join('libc', 'stdlib', 'strtod.c'), ]; + musl_files = [] + + for directory, sources in musl_files: + libc_files += [os.path.join('libc', 'musl', 'src', directory, source) for source in sources] + + prev_cxx = os.environ.get('EMMAKEN_CXX') + if prev_cxx: os.environ['EMMAKEN_CXX'] = '' + musl_internal_includes = shared.path_from_root('system', 'lib', 'libc', 'musl', 'src', 'internal') + for src in libc_files: + o = in_temp(os.path.basename(src) + '.o') + execute([shared.PYTHON, shared.EMCC, shared.path_from_root('system', 'lib', src), '-o', o, '-I', musl_internal_includes], stdout=stdout, stderr=stderr) + o_s.append(o) + if prev_cxx: os.environ['EMMAKEN_CXX'] = prev_cxx + + shared.Building.link(o_s, in_temp('libc.bc')) + return in_temp('libc.bc') + + def fix_libc(need): + # libc needs some sign correction. # If we are in mode 0, switch to 2. We will add our lines + try: + if shared.Settings.CORRECT_SIGNS == 0: raise Exception('we need to change to 2') + except: # we fail if equal to 0 - so we need to switch to 2 - or if CORRECT_SIGNS is not even in Settings + shared.Settings.CORRECT_SIGNS = 2 + if shared.Settings.CORRECT_SIGNS == 2: + shared.Settings.CORRECT_SIGNS_LINES = [shared.path_from_root('src', 'dlmalloc.c') + ':' + str(i+4) for i in [4816, 4191, 4246, 4199, 4205, 4235, 4227]] + # If we are in mode 1, we are correcting everything anyhow. If we are in mode 3, we will be corrected + # so all is well anyhow too. + # XXX We also need to add libc symbols that use malloc, for example strdup. It's very rare to use just them and not + # a normal malloc symbol (like free, after calling strdup), so we haven't hit this yet, but it is possible. + libc_symbols = map(lambda line: line.strip().split(' ')[1], open(shared.path_from_root('system', 'lib', 'libc.symbols')).readlines()) + libc_symbols = set(libc_symbols) + + # libcextra + def create_libcextra(): + if DEBUG: print >> sys.stderr, 'emcc: building libcextra for cache' + o_s = [] + libcextra_files = [] + musl_files = [ ['multibyte', [ 'btowc.c', @@ -1177,35 +1215,26 @@ try: ]] ] + libcextra_files = [] for directory, sources in musl_files: - libc_files += [os.path.join('libc', 'musl', 'src', directory, source) for source in sources] + libcextra_files += [os.path.join('libc', 'musl', 'src', directory, source) for source in sources] prev_cxx = os.environ.get('EMMAKEN_CXX') if prev_cxx: os.environ['EMMAKEN_CXX'] = '' musl_internal_includes = shared.path_from_root('system', 'lib', 'libc', 'musl', 'src', 'internal') - for src in libc_files: + for src in libcextra_files: o = in_temp(os.path.basename(src) + '.o') execute([shared.PYTHON, shared.EMCC, shared.path_from_root('system', 'lib', src), '-o', o, '-I', musl_internal_includes], stdout=stdout, stderr=stderr) o_s.append(o) if prev_cxx: os.environ['EMMAKEN_CXX'] = prev_cxx - shared.Building.link(o_s, in_temp('libc.bc')) - return in_temp('libc.bc') + shared.Building.link(o_s, in_temp('libcextra.bc')) + return in_temp('libcextra.bc') - def fix_libc(need): - # libc needs some sign correction. # If we are in mode 0, switch to 2. We will add our lines - try: - if shared.Settings.CORRECT_SIGNS == 0: raise Exception('we need to change to 2') - except: # we fail if equal to 0 - so we need to switch to 2 - or if CORRECT_SIGNS is not even in Settings - shared.Settings.CORRECT_SIGNS = 2 - if shared.Settings.CORRECT_SIGNS == 2: - shared.Settings.CORRECT_SIGNS_LINES = [shared.path_from_root('src', 'dlmalloc.c') + ':' + str(i+4) for i in [4816, 4191, 4246, 4199, 4205, 4235, 4227]] - # If we are in mode 1, we are correcting everything anyhow. If we are in mode 3, we will be corrected - # so all is well anyhow too. - # XXX We also need to add libc symbols that use malloc, for example strdup. It's very rare to use just them and not - # a normal malloc symbol (like free, after calling strdup), so we haven't hit this yet, but it is possible. - libc_symbols = map(lambda line: line.strip().split(' ')[1], open(shared.path_from_root('system', 'lib', 'libc.symbols')).readlines()) - libc_symbols = set(libc_symbols) + def fix_libcextra(need): + pass + libcextra_symbols = map(lambda line: line.strip().split(' ')[1], open(shared.path_from_root('system', 'lib', 'libcextra.symbols')).readlines()) + libcextra_symbols = set(libcextra_symbols) # libcxx def create_libcxx(): @@ -1279,6 +1308,7 @@ try: force = os.environ.get('EMCC_FORCE_STDLIBS') has = need = None for name, create, fix, library_symbols in [('libcxx', create_libcxx, fix_libcxx, libcxx_symbols), + ('libcextra', create_libcextra, fix_libcextra, libcextra_symbols), ('libcxxabi', create_libcxxabi, fix_libcxxabi, libcxxabi_symbols), ('libc', create_libc, fix_libc, libc_symbols)]: if not force: diff --git a/system/lib/libcextra.symbols b/system/lib/libcextra.symbols new file mode 100644 index 00000000..97805c96 --- /dev/null +++ b/system/lib/libcextra.symbols @@ -0,0 +1,48 @@ + U __errno + U __fsmu8 + T btowc + U malloc + T mblen + T mbrlen + d mbrlen.internal + T mbrtowc + d mbrtowc.internal_state + T mbsinit + T mbsnrtowcs + T mbsrtowcs + T mbstowcs + T mbtowc + U towlower + t twoway_wcsstr + T wcpcpy + T wcpncpy + T wcrtomb + T wcscasecmp + T wcscat + T wcschr + T wcscmp + T wcscpy + T wcscspn + T wcsdup + T wcslen + T wcsncasecmp + T wcsncat + T wcsncmp + T wcsncpy + T wcsnlen + T wcsnrtombs + T wcspbrk + T wcsrchr + T wcsrtombs + T wcsspn + T wcsstr + T wcstok + T wcstombs + T wcswcs + T wctob + T wctomb + T wmemchr + T wmemcmp + T wmemcpy + T wmemmove + T wmemset diff --git a/tests/runner.py b/tests/runner.py index 99f24fc9..00426b0c 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -2309,6 +2309,22 @@ cat |umber one top notchfi FI FO FUM WHEN WHERE WHY HOW WHO|''', ['wowie', 'too' ''' self.do_run(src, 'Assertion failed: 1 == false') + def test_libcextra(self): + src = r''' + #include <stdio.h> + #include <wchar.h> + + int main() + { + const wchar_t* wstr = L"Hello"; + + printf("wcslen: %d\n", wcslen(wstr)); + + return 0; + } + ''' + self.do_run(src, 'wcslen: 5') + def test_longjmp(self): src = r''' #include <stdio.h> |