diff options
-rwxr-xr-x | emcc | 30 | ||||
-rw-r--r-- | src/library.js | 49 | ||||
-rw-r--r-- | system/lib/libc.symbols | 5 | ||||
-rw-r--r-- | system/lib/libc/musl/COPYRIGHT | 92 | ||||
-rw-r--r-- | system/lib/libc/musl/memcpy.c | 29 |
5 files changed, 149 insertions, 56 deletions
@@ -937,12 +937,22 @@ try: # libc def create_libc(): if DEBUG: print >> sys.stderr, 'emcc: building libc for cache' - execute([shared.PYTHON, shared.EMCC, shared.path_from_root('system', 'lib', 'dlmalloc.c'), '-g', '-o', in_temp('dlmalloc.o')], stdout=stdout, stderr=stderr) - # we include the libc++ new stuff here, so that the common case of using just new/delete is quick to link - execute([shared.PYTHON, shared.EMXX, shared.path_from_root('system', 'lib', 'libcxx', 'new.cpp'), '-g', '-o', in_temp('new.o')], stdout=stdout, stderr=stderr) - shared.Building.link([in_temp('dlmalloc.o'), in_temp('new.o')], in_temp('libc.o')) - return in_temp('libc.o') - def fix_libc(): + o_s = [] + for src in ['dlmalloc.c', os.path.join('libc', 'musl', 'memcpy.c'), os.path.join('libcxx', 'new.cpp')]: + o = in_temp(os.path.basename(src) + '.o') + execute([shared.PYTHON, shared.EMCC, shared.path_from_root('system', 'lib', src), '-o', o], stdout=stdout, stderr=stderr) + o_s.append(o) + shared.Building.link(o_s, in_temp('libc.bc')) + return in_temp('libc.bc') + + def fix_libc(need): + # If an intrinsic alias of memcpy is used, we need memcpy + for memcpy_alias in ['llvm.memcpy.i32', 'llvm.memcpy.i64', 'llvm.memcpy.p0i8.p0i8.i32', 'llvm.memcpy.p0i8.p0i8.i64']: + if memcpy_alias in need: + if '_memcpy' not in shared.Settings.EXPORTED_FUNCTIONS: + shared.Settings.EXPORTED_FUNCTIONS.append('_memcpy') + break + # 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') @@ -966,7 +976,7 @@ try: os.append(o) shared.Building.link(os, in_temp('libcxx.bc')) return in_temp('libcxx.bc') - def fix_libcxx(): + def fix_libcxx(need): assert shared.Settings.QUANTUM_SIZE == 4, 'We do not support libc++ with QUANTUM_SIZE == 1' # libcxx might need corrections, so turn them all on. TODO: check which are actually needed shared.Settings.CORRECT_SIGNS = shared.Settings.CORRECT_OVERFLOWS = shared.Settings.CORRECT_ROUNDINGS = 1 @@ -985,7 +995,7 @@ try: os.append(o) shared.Building.link(os, in_temp('libcxxabi.bc')) return in_temp('libcxxabi.bc') - def fix_libcxxabi(): + def fix_libcxxabi(need): assert shared.Settings.QUANTUM_SIZE == 4, 'We do not support libc++abi with QUANTUM_SIZE == 1' #print >> sys.stderr, 'emcc: info: using libcxxabi, this may need CORRECT_* options' #shared.Settings.CORRECT_SIGNS = shared.Settings.CORRECT_OVERFLOWS = shared.Settings.CORRECT_ROUNDINGS = 1 @@ -997,7 +1007,7 @@ try: for name, create, fix, library_symbols in [('libcxx', create_libcxx, fix_libcxx, libcxx_symbols), ('libcxxabi', create_libcxxabi, fix_libcxxabi, libcxxabi_symbols), - ('libc', create_libc, fix_libc, libc_symbols)]: + ('libc', create_libc, fix_libc, libc_symbols)]: need = set() has = set() for temp_file in temp_files: @@ -1026,7 +1036,7 @@ try: extra_files_to_link.append(libfile) force = True if fix: - fix() + fix(need) # First, combine the bitcode files if there are several. We must also link if we have a singleton .a if len(input_files) + len(extra_files_to_link) > 1 or \ diff --git a/src/library.js b/src/library.js index 82e42a28..bc7a4d0a 100644 --- a/src/library.js +++ b/src/library.js @@ -4199,51 +4199,8 @@ LibraryManager.library = { ret += makeCopyValues(dest, src, num, 'null', null, align); return ret; }, - memcpy: function (dest, src, num, align) { -#if ASSERTIONS - assert(num % 1 === 0); //, 'memcpy given ' + num + ' bytes to copy. Problem with quantum=1 corrections perhaps?'); -#endif -#if USE_TYPED_ARRAYS == 2 - if (num >= {{{ SEEK_OPTIMAL_ALIGN_MIN }}} && src % 2 == dest % 2) { - // This is unaligned, but quite large, and potentially alignable, so work hard to get to aligned settings - if (src % 4 == dest % 4) { - var stop = src + num; - while (src % 4) { // no need to check for stop, since we have large num - HEAP8[dest++] = HEAP8[src++]; - } - var src4 = src >> 2, dest4 = dest >> 2, stop4 = stop >> 2; - while (src4 < stop4) { - HEAP32[dest4++] = HEAP32[src4++]; - } - src = src4 << 2; - dest = dest4 << 2; - while (src < stop) { - HEAP8[dest++] = HEAP8[src++]; - } - } else { - var stop = src + num; - if (src % 2) { // no need to check for stop, since we have large num - HEAP8[dest++] = HEAP8[src++]; - } - var src2 = src >> 1, dest2 = dest >> 1, stop2 = stop >> 1; - while (src2 < stop2) { - HEAP16[dest2++] = HEAP16[src2++]; - } - src = src2 << 1; - dest = dest2 << 1; - if (src < stop) { - HEAP8[dest++] = HEAP8[src++]; - } - } - } else { - while (num--) { - HEAP8[dest++] = HEAP8[src++]; - } - } -#else - {{{ makeCopyValues('dest', 'src', 'num', 'null', null, 'align') }}}; -#endif - }, + + memcpy: function(){ throw 'memcpy should be included from libc' }, llvm_memcpy_i32: 'memcpy', llvm_memcpy_i64: 'memcpy', @@ -4262,7 +4219,7 @@ LibraryManager.library = { {{{ makeCopyValues('dest', 'src', 1, 'null', null, 1) }}}; } } else { - _memcpy(dest, src, num, align); + _memcpy(dest, src, num); } }, llvm_memmove_i32: 'memmove', diff --git a/system/lib/libc.symbols b/system/lib/libc.symbols index d41f4140..b98a79e4 100644 --- a/system/lib/libc.symbols +++ b/system/lib/libc.symbols @@ -48,3 +48,8 @@ _ZNSt20bad_array_new_lengthC2Ev _ZNSt20bad_array_new_lengthD0Ev _ZNSt20bad_array_new_lengthD1Ev _ZNSt20bad_array_new_lengthD2Ev +memcpy +llvm.memcpy.i32 +llvm.memcpy.i64 +llvm.memcpy.p0i8.p0i8.i32 +llvm.memcpy.p0i8.p0i8.i64 diff --git a/system/lib/libc/musl/COPYRIGHT b/system/lib/libc/musl/COPYRIGHT new file mode 100644 index 00000000..c0817619 --- /dev/null +++ b/system/lib/libc/musl/COPYRIGHT @@ -0,0 +1,92 @@ +musl as a whole is licensed under the following standard MIT license: + +Copyright © 2005-2012 Rich Felker + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +Portions of this software are contributed or derived from software +authored by third parties. Complete details on the copyright status of +all code included in musl follows below: + + +The TRE regular expression implementation (src/regex/reg* and +src/regex/tre*) is Copyright © 2001-2008 Ville Laurikari and licensed +under a 2-clause BSD license (license text in the source files). The +included version has been heavily modified by Rich Felker in 2012, in +the interests of size, simplicity, and namespace cleanliness. + +Most of the math library code (src/math/* and src/complex/*) is +Copyright © 1993,2004 Sun Microsystems or +Copyright © 2003-2011 David Schultz or +Copyright © 2003-2009 Steven G. Kargl or +Copyright © 2003-2009 Bruce D. Evans or +Copyright © 2008 Stephen L. Moshier +and labelled as such. All have been licensed under extremely +permissive terms. See the comments in the individual files for +details. + +The implementation of DES for crypt (src/misc/crypt_des.c) is +Copyright © 1994 David Burren. It is licensed under a BSD license. + +The implementation of blowfish crypt (src/misc/crypt_blowfish.c) was +originally written by Solar Designer and placed into the public +domain. The code also comes with a fallback permissive license for use +in jurisdictions that may not recognize the public domain. + +The smoothsort implementation (src/stdlib/qsort.c) is Copyright © 2011 +Valentin Ochs and is licensed under an MIT-style license. + +The BSD PRNG implementation (src/prng/random.c) and XSI search API +(src/search/*.c) functions are Copyright © 2011 Szabolcs Nagy and +licensed under following terms: "Permission to use, copy, modify, +and/or distribute this code for any purpose with or without fee is +hereby granted. There is no warranty." + +The x86_64 port was written by Nicholas J. Kain. Several files (crt) +were released into the public domain; others are licensed under the +standard MIT license terms at the top of this file. See individual +files for their copyright status. + +The mips and microblaze ports were originally written by Richard +Pennington for use in the ellcc project. The original code was adapted +by Rich Felker for build system and code conventions during upstream +integration. It is licensed under the standard MIT terms. + +The powerpc port was also originally written by Richard Pennington, +and later supplemented and integrated by John Spencer. It is licensed +under the standard MIT terms. + +All other files which have no copyright comments are original works +Copyright © 2005-2012 Rich Felker, the main author of this library. +The decision to exclude such comments is intentional, as it should be +possible to carry around the complete source code on tiny storage +media. All public header files (include/*) should be treated as Public +Domain as they intentionally contain no content which can be covered +by copyright. Some source modules may fall in this category as well. +If you believe that a file is so trivial that it should be in the +Public Domain, please contact me and, if I agree, I will explicitly +release it from copyright. + +The following files are trivial, in my opinion not copyrightable in +the first place, and hereby explicitly released to the Public Domain: + +All public headers: include/* +Startup files: crt/* diff --git a/system/lib/libc/musl/memcpy.c b/system/lib/libc/musl/memcpy.c new file mode 100644 index 00000000..8e98302f --- /dev/null +++ b/system/lib/libc/musl/memcpy.c @@ -0,0 +1,29 @@ +#include <string.h> +#include <stdlib.h> +#include <stdint.h> + +#define SS (sizeof(size_t)) +#define ALIGN (sizeof(size_t)-1) +#define ONES ((size_t)-1/UCHAR_MAX) + +void *memcpy(void *restrict dest, const void *restrict src, size_t n) +{ + unsigned char *d = dest; + const unsigned char *s = src; + + if (((uintptr_t)d & ALIGN) != ((uintptr_t)s & ALIGN)) + goto misaligned; + + for (; ((uintptr_t)d & ALIGN) && n; n--) *d++ = *s++; + if (n) { + size_t *wd = (void *)d; + const size_t *ws = (const void *)s; + + for (; n>=SS; n-=SS) *wd++ = *ws++; + d = (void *)wd; + s = (const void *)ws; +misaligned: + for (; n; n--) *d++ = *s++; + } + return dest; +} |