mirror of
https://github.com/fluencelabs/musl
synced 2025-06-13 23:11:51 +00:00
[WebAssembly] Exclude less in libc.py
This commit is contained in:
@ -0,0 +1,8 @@
|
||||
#ifndef SHARED
|
||||
void _start_c(long *p);
|
||||
|
||||
void _start(void) {
|
||||
long p = 0;
|
||||
_start_c(&p);
|
||||
}
|
||||
#endif
|
||||
|
@ -1,4 +1,6 @@
|
||||
static inline struct pthread *__pthread_self(void) { return pthread_self(); }
|
||||
static inline struct pthread *__pthread_self(void) {
|
||||
return (struct pthread *)UINTPTR_MAX;
|
||||
}
|
||||
|
||||
#define TP_ADJ(p) (p)
|
||||
|
||||
|
@ -31,6 +31,3 @@ long __syscall3(long n, long a, long b, long c);
|
||||
long __syscall4(long n, long a, long b, long c, long d);
|
||||
long __syscall5(long n, long a, long b, long c, long d, long e);
|
||||
long __syscall6(long n, long a, long b, long c, long d, long e, long f);
|
||||
|
||||
// HACK other architectures don't do this.
|
||||
#include "../../src/internal/syscall.h"
|
||||
|
@ -269,9 +269,13 @@ var runtime = (function() {
|
||||
__lttf2: NYI('__lttf2'),
|
||||
__multf3: NYI('__multf3'),
|
||||
__multi3: NYI('__multi3'),
|
||||
__muldc3: NYI('__muldc3'),
|
||||
__mulsc3: NYI('__mulsc3'),
|
||||
__multc3: NYI('__multc3'),
|
||||
__netf2: NYI('__netf2'),
|
||||
__subtf3: NYI('__subtf3'),
|
||||
__divsc3: NYI('__divsc3')
|
||||
__divsc3: NYI('__divsc3'),
|
||||
__unordtf2: NYI('__unordtf2')
|
||||
};
|
||||
})();
|
||||
|
||||
@ -821,66 +825,70 @@ var musl_hack = (function() {
|
||||
return {
|
||||
abort: NYI('abort'),
|
||||
__addtf3: NYI('__addtf3'),
|
||||
__block_all_sigs: NYI('__block_all_sigs'),
|
||||
__clone: NYI('__clone'),
|
||||
__divtf3: NYI('__divtf3'),
|
||||
__dl_invalid_handle: NYI('__dl_invalid_handle'),
|
||||
__dl_seterr: NYI('__dl_seterr'),
|
||||
__eqtf2: NYI('__eqtf2'),
|
||||
exit: NYI('exit'),
|
||||
_Exit: NYI('_Exit'),
|
||||
__extenddftf2: NYI('__extenddftf2'),
|
||||
__extendsftf2: NYI('__extendsftf2'),
|
||||
fcntl: NYI('fcntl'),
|
||||
fdopen: NYI('fdopen'),
|
||||
__fdopen: NYI('__fdopen'),
|
||||
feclearexcept: NYI('feclearexcept'),
|
||||
fegetround: NYI('fegetround'),
|
||||
feraiseexcept: NYI('feraiseexcept'),
|
||||
fesetround: NYI('fesetround'),
|
||||
fetestexcept: NYI('fetestexcept'),
|
||||
__fixtfdi: NYI('__fixtfdi'),
|
||||
__fixtfsi: NYI('__fixtfsi'),
|
||||
__floatscan: NYI('__floatscan'),
|
||||
__fixunstfsi: NYI('__fixunstfsi'),
|
||||
__floatsitf: NYI('__floatsitf'),
|
||||
fprintf: NYI('fprintf'),
|
||||
iswctype: NYI('iswctype'),
|
||||
iswspace: NYI('iswspace'),
|
||||
__lctrans: NYI('__lctrans'),
|
||||
__lctrans_cur: NYI('__lctrans_cur'),
|
||||
__floatunsitf: NYI('__floatunsitf'),
|
||||
__getf2: NYI('__getf2'),
|
||||
getrlimit: NYI('getrlimit'),
|
||||
__gttf2: NYI('__gttf2'),
|
||||
ioctl: NYI('ioctl'),
|
||||
__letf2: NYI('__letf2'),
|
||||
__lock: NYI('__lock'),
|
||||
__lockfile: NYI('__lockfile'),
|
||||
longjmp: NYI('longjmp'),
|
||||
__lttf2: NYI('__lttf2'),
|
||||
__madvise: NYI('__madvise'),
|
||||
mbtowc: NYI('mbtowc'),
|
||||
__mmap: NYI('__mmap'),
|
||||
__mremap: NYI('__mremap'),
|
||||
__muldc3: NYI('__muldc3'),
|
||||
__mulsc3: NYI('__mulsc3'),
|
||||
__multc3: NYI('__multc3'),
|
||||
__multf3: NYI('__multf3'),
|
||||
__munmap: NYI('__munmap'),
|
||||
nanosleep: NYI('nanosleep'),
|
||||
__netf2: NYI('__netf2'),
|
||||
posix_spawn: NYI('posix_spawn'),
|
||||
posix_spawn_file_actions_adddup2: NYI('posix_spawn_file_actions_adddup2'),
|
||||
posix_spawn_file_actions_destroy: NYI('posix_spawn_file_actions_destroy'),
|
||||
posix_spawn_file_actions_init: NYI('posix_spawn_file_actions_init'),
|
||||
pthread_self: NYI('pthread_self'),
|
||||
__randname: NYI('__randname'),
|
||||
__rem_pio2_large: NYI('__rem_pio2_large'),
|
||||
setitimer: NYI('setitimer'),
|
||||
nftw: NYI('nftw'),
|
||||
pthread_attr_init: NYI('pthread_attr_init'),
|
||||
pthread_attr_setdetachstate: NYI('pthread_attr_setdetachstate'),
|
||||
pthread_attr_setguardsize: NYI('pthread_attr_setguardsize'),
|
||||
pthread_attr_setstacksize: NYI('pthread_attr_setstacksize'),
|
||||
pthread_barrier_destroy: NYI('pthread_barrier_destroy'),
|
||||
pthread_barrier_init: NYI('pthread_barrier_init'),
|
||||
pthread_barrier_wait: NYI('pthread_barrier_wait'),
|
||||
pthread_cancel: NYI('pthread_cancel'),
|
||||
_pthread_cleanup_pop: NYI('_pthread_cleanup_pop'),
|
||||
_pthread_cleanup_push: NYI('_pthread_cleanup_push'),
|
||||
pthread_cond_init: NYI('pthread_cond_init'),
|
||||
pthread_cond_wait: NYI('pthread_cond_wait'),
|
||||
pthread_create: NYI('pthread_create'),
|
||||
pthread_mutex_init: NYI('pthread_mutex_init'),
|
||||
pthread_mutex_lock: NYI('pthread_mutex_lock'),
|
||||
pthread_mutex_unlock: NYI('pthread_mutex_unlock'),
|
||||
pthread_once: NYI('pthread_once'),
|
||||
pthread_rwlock_rdlock: NYI('pthread_rwlock_rdlock'),
|
||||
pthread_rwlock_unlock: NYI('pthread_rwlock_unlock'),
|
||||
pthread_rwlock_wrlock: NYI('pthread_rwlock_wrlock'),
|
||||
pthread_setcancelstate: NYI('pthread_setcancelstate'),
|
||||
pthread_sigmask: NYI('pthread_sigmask'),
|
||||
pthread_testcancel: NYI('pthread_testcancel'),
|
||||
sem_init: NYI('sem_init'),
|
||||
sem_post: NYI('sem_post'),
|
||||
sem_wait: NYI('sem_wait'),
|
||||
setjmp: NYI('setjmp'),
|
||||
setrlimit: NYI('setrlimit'),
|
||||
__set_thread_area: NYI('__set_thread_area'),
|
||||
snprintf: NYI('snprintf'),
|
||||
sprintf: NYI('sprintf'),
|
||||
__stdio_write: NYI('__stdio_write'),
|
||||
__stdout_write: NYI('__stdout_write'),
|
||||
__subtf3: NYI('__subtf3'),
|
||||
__synccall: NYI('__synccall'),
|
||||
towlower: NYI('towlower'),
|
||||
towupper: NYI('towupper'),
|
||||
__timedwait_cp: NYI('__timedwait_cp'),
|
||||
__trunctfdf2: NYI('__trunctfdf2'),
|
||||
__trunctfsf2: NYI('__trunctfsf2'),
|
||||
uname: NYI('uname'),
|
||||
__unlock: NYI('__unlock'),
|
||||
__unlockfile: NYI('__unlockfile'),
|
||||
vfprintf: NYI('vfprintf'),
|
||||
vfscanf: NYI('vfscanf'),
|
||||
vsnprintf: NYI('vsnprintf'),
|
||||
wctype: NYI('wctype')
|
||||
__unordtf2: NYI('__unordtf2'),
|
||||
__wait: NYI('__wait'),
|
||||
};
|
||||
})();
|
||||
|
||||
@ -889,6 +897,9 @@ var musl_hack = (function() {
|
||||
var syscall = (function() {
|
||||
// TODO auto-generate syscall number from the header.
|
||||
return {
|
||||
__syscall: function(n, args) {
|
||||
print('syscall(' + n + ', ' + args + ')');
|
||||
return -1; },
|
||||
__syscall0: function(n) { print('syscall(' + n + ')'); return -1; },
|
||||
__syscall1: function(n, a) {
|
||||
print('syscall(' + n + ', ' + a + ')');
|
||||
|
75
libc.py
75
libc.py
@ -27,50 +27,30 @@ import tempfile
|
||||
|
||||
verbose = False
|
||||
|
||||
# TODO add 'time'.
|
||||
SRC_DIRS = [
|
||||
'ctype', 'env', 'errno', 'exit', 'internal', 'ldso', 'malloc', 'math',
|
||||
'prng', 'regex', 'stdio', 'string', 'stdlib', 'unistd']
|
||||
DIR_BLACKLIST = ['misc', 'thread']
|
||||
BLACKLIST = [
|
||||
'puts.c', # The JS version is nicer for now.
|
||||
'strsignal.c', '__ctype_get_mb_cur_max.c',
|
||||
'printf.c', 'fprintf.c', 'fscanf.c', 'vfprintf.c', 'asprintf.c',
|
||||
'dprintf.c', 'scanf.c', 'sprintf.c', 'snprintf.c', 'sscanf.c',
|
||||
'vfscanf.c', 'vsnprintf.c',
|
||||
'qsort.c', 'regexec.c', 'regcomp.c', 'strftime.c', 'strptime.c',
|
||||
'faccessat.c', 'floatscan.c', 'getcwd.c', 'glob.c', 'pclose.c',
|
||||
'__tz.c', 'pwrite.c', 'pread.c', '__fdopen.c', '__fopen_rb_ca.c',
|
||||
'__rem_pio2_large.c', '__stdio_write.c',
|
||||
'__stdout_write.c', 'vdprintf.c',
|
||||
'__year_to_secs.c', 'tcgetpgrp.c', 'tcsetpgrp.c', 'timer_create.c',
|
||||
'tmpfile.c', 'utime.c', 'wcsftime.c',
|
||||
'dlerror.c', 'exit.c', 'abort.c', '_Exit.c', '__libc_start_main.c',
|
||||
# Wide characters.
|
||||
'fgetwc.c', 'getw.c', 'vfwprintf.c',
|
||||
'fgetws.c', 'getwc.c', 'vfwscanf.c',
|
||||
'fputwc.c', 'getwchar.c', 'vswprintf.c',
|
||||
'fputws.c', 'swprintf.c', 'vswscanf.c',
|
||||
'swscanf.c', 'vwprintf.c',
|
||||
'fwprintf.c', 'putw.c', 'vwscanf.c', 'fwscanf.c',
|
||||
'putwc.c', 'wprintf.c', 'open_wmemstream.c',
|
||||
'fwscanf.c', 'putwchar.c', 'ungetwc.c', 'wscanf.c', 'fwide.c',
|
||||
'iswctype.c', 'iswupper.c', 'towctrans.c', 'wctrans.c', 'iswgraph.c',
|
||||
'iswblank.c', 'iswpunct.c', 'wcwidth.c', 'iswspace.c', 'iswxdigit.c',
|
||||
'wcswidth.c', 'iswcntrl.c', 'iswalnum.c', 'iswalpha.c', 'iswlower.c',
|
||||
'iswprint.c', 'iswdigit.c', 'wcsdup.c', 'wcsncmp.c', 'wcscpy.c',
|
||||
'wcstok.c', 'wcpncpy.c', 'wcsrchr.c', 'wmemchr.c', 'wcsspn.c',
|
||||
'wmemcpy.c', 'wcscspn.c', 'wcscasecmp_l.c', 'wcsncat.c', 'wcsncasecmp_l.c',
|
||||
'wmemmove.c', 'wcscasecmp.c', 'wcspbrk.c', 'wcschr.c', 'wmemcmp.c',
|
||||
'wcpcpy.c', 'wcsnlen.c', 'wcsstr.c', 'wmemset.c', 'wcscmp.c', 'wcsncpy.c',
|
||||
'wcswcs.c', 'wcscat.c', 'wcslen.c', 'wcsncasecmp.c',
|
||||
# stdio file lock.
|
||||
'flockfile.c', 'ftrylockfile.c', 'funlockfile.c', '__lockfile.c'
|
||||
'puts.c', # Prefer the JS version for now
|
||||
'abort.c', # Perfer the JS version for now
|
||||
'_Exit.c', # Perfer the JS version for now
|
||||
'exit.c', # Contains a weak reference which is not suppoered by s2wasm
|
||||
'__libc_start_main.c', # Contains a weak reference which is not suppoered by s2wasm
|
||||
]
|
||||
WARNINGS = ['-Wno-incompatible-library-redeclaration',
|
||||
CFLAGS = ['-std=c99',
|
||||
'-D_XOPEN_SOURCE=700',
|
||||
'-Werror',
|
||||
'-Wno-incompatible-library-redeclaration',
|
||||
'-Wno-shift-op-parentheses',
|
||||
'-Wno-tautological-unsigned-zero-compare',
|
||||
'-Wno-tautological-constant-out-of-range-compare',
|
||||
'-Wno-tautological-unsigned-enum-zero-compare',
|
||||
'-Wno-ignored-attributes',
|
||||
'-Wno-format',
|
||||
'-Wno-bitwise-op-parentheses',
|
||||
'-Wno-logical-op-parentheses',
|
||||
'-Wno-string-plus-int',
|
||||
'-Wno-pointer-sign',
|
||||
'-Wno-dangling-else',
|
||||
'-Wno-absolute-value',
|
||||
'-Wno-unknown-pragmas']
|
||||
|
||||
|
||||
@ -107,21 +87,24 @@ def build_alltypes(musl, arch):
|
||||
def musl_sources(musl_root):
|
||||
"""musl sources to be built."""
|
||||
sources = []
|
||||
for d in SRC_DIRS:
|
||||
for d in os.listdir(os.path.join(musl_root, 'src')):
|
||||
if d in DIR_BLACKLIST:
|
||||
continue
|
||||
base = os.path.join(musl_root, 'src', d)
|
||||
pattern = os.path.join(base, '*.c')
|
||||
for f in glob.glob(pattern):
|
||||
if os.path.basename(f) in BLACKLIST:
|
||||
continue
|
||||
sources.append(os.path.join(base, f))
|
||||
sources.append(f)
|
||||
return sorted(sources)
|
||||
|
||||
|
||||
def includes(musl, arch):
|
||||
"""Include path."""
|
||||
includes = [os.path.join(musl, 'include'),
|
||||
includes = [
|
||||
os.path.join(musl, 'arch', arch),
|
||||
os.path.join(musl, 'src', 'internal'),
|
||||
os.path.join(musl, 'arch', arch)]
|
||||
os.path.join(musl, 'include')]
|
||||
return list(itertools.chain(*zip(['-I'] * len(includes), includes)))
|
||||
|
||||
|
||||
@ -155,7 +138,7 @@ class ObjCompiler(Compiler):
|
||||
compile_cmd = [os.path.join(self.clang_dir, 'clang'), '-target', target,
|
||||
'-Os', '-c', '-nostdinc']
|
||||
compile_cmd += includes(self.musl, self.arch)
|
||||
compile_cmd += WARNINGS
|
||||
compile_cmd += CFLAGS
|
||||
check_output(compile_cmd + [src], cwd=self.tmpdir)
|
||||
return os.path.basename(src)[:-1] + 'o' # .c -> .o
|
||||
|
||||
@ -178,7 +161,7 @@ class AsmCompiler(Compiler):
|
||||
compile_cmd = [os.path.join(self.clang_dir, 'clang'), '-target', target,
|
||||
'-Os', '-emit-llvm', '-S', '-nostdinc']
|
||||
compile_cmd += includes(self.musl, self.arch)
|
||||
compile_cmd += WARNINGS
|
||||
compile_cmd += CFLAGS
|
||||
check_output(compile_cmd + [src], cwd=self.tmpdir)
|
||||
return os.path.basename(src)[:-1] + 'll' # .c -> .ll
|
||||
|
||||
@ -222,6 +205,10 @@ def run(clang_dir, binaryen_dir, sexpr_wasm, musl, arch, out, save_temps,
|
||||
sexpr_wasm)
|
||||
compiler.compile(sources)
|
||||
compiler.binary()
|
||||
if compile_to_wasm:
|
||||
compiler.compile([os.path.join(musl, 'crt', 'crt1.c')])
|
||||
shutil.copy(os.path.join(tmpdir, compiler.compiled[0]),
|
||||
os.path.dirname(out))
|
||||
finally:
|
||||
if not save_temps:
|
||||
shutil.rmtree(tmpdir)
|
||||
|
Reference in New Issue
Block a user