mirror of
https://github.com/fluencelabs/musl
synced 2025-06-20 10:16:47 +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)
|
#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 __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 __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);
|
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'),
|
__lttf2: NYI('__lttf2'),
|
||||||
__multf3: NYI('__multf3'),
|
__multf3: NYI('__multf3'),
|
||||||
__multi3: NYI('__multi3'),
|
__multi3: NYI('__multi3'),
|
||||||
|
__muldc3: NYI('__muldc3'),
|
||||||
|
__mulsc3: NYI('__mulsc3'),
|
||||||
|
__multc3: NYI('__multc3'),
|
||||||
__netf2: NYI('__netf2'),
|
__netf2: NYI('__netf2'),
|
||||||
__subtf3: NYI('__subtf3'),
|
__subtf3: NYI('__subtf3'),
|
||||||
__divsc3: NYI('__divsc3')
|
__divsc3: NYI('__divsc3'),
|
||||||
|
__unordtf2: NYI('__unordtf2')
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
@ -821,66 +825,70 @@ var musl_hack = (function() {
|
|||||||
return {
|
return {
|
||||||
abort: NYI('abort'),
|
abort: NYI('abort'),
|
||||||
__addtf3: NYI('__addtf3'),
|
__addtf3: NYI('__addtf3'),
|
||||||
__block_all_sigs: NYI('__block_all_sigs'),
|
__clone: NYI('__clone'),
|
||||||
__divtf3: NYI('__divtf3'),
|
__divtf3: NYI('__divtf3'),
|
||||||
__dl_invalid_handle: NYI('__dl_invalid_handle'),
|
__eqtf2: NYI('__eqtf2'),
|
||||||
__dl_seterr: NYI('__dl_seterr'),
|
exit: NYI('exit'),
|
||||||
_Exit: NYI('_Exit'),
|
_Exit: NYI('_Exit'),
|
||||||
__extenddftf2: NYI('__extenddftf2'),
|
__extenddftf2: NYI('__extenddftf2'),
|
||||||
__extendsftf2: NYI('__extendsftf2'),
|
__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'),
|
__fixtfdi: NYI('__fixtfdi'),
|
||||||
__fixtfsi: NYI('__fixtfsi'),
|
__fixtfsi: NYI('__fixtfsi'),
|
||||||
__floatscan: NYI('__floatscan'),
|
__fixunstfsi: NYI('__fixunstfsi'),
|
||||||
__floatsitf: NYI('__floatsitf'),
|
__floatsitf: NYI('__floatsitf'),
|
||||||
fprintf: NYI('fprintf'),
|
__floatunsitf: NYI('__floatunsitf'),
|
||||||
iswctype: NYI('iswctype'),
|
__getf2: NYI('__getf2'),
|
||||||
iswspace: NYI('iswspace'),
|
getrlimit: NYI('getrlimit'),
|
||||||
__lctrans: NYI('__lctrans'),
|
__gttf2: NYI('__gttf2'),
|
||||||
__lctrans_cur: NYI('__lctrans_cur'),
|
ioctl: NYI('ioctl'),
|
||||||
|
__letf2: NYI('__letf2'),
|
||||||
__lock: NYI('__lock'),
|
__lock: NYI('__lock'),
|
||||||
__lockfile: NYI('__lockfile'),
|
longjmp: NYI('longjmp'),
|
||||||
__lttf2: NYI('__lttf2'),
|
__lttf2: NYI('__lttf2'),
|
||||||
__madvise: NYI('__madvise'),
|
__muldc3: NYI('__muldc3'),
|
||||||
mbtowc: NYI('mbtowc'),
|
__mulsc3: NYI('__mulsc3'),
|
||||||
__mmap: NYI('__mmap'),
|
__multc3: NYI('__multc3'),
|
||||||
__mremap: NYI('__mremap'),
|
|
||||||
__multf3: NYI('__multf3'),
|
__multf3: NYI('__multf3'),
|
||||||
__munmap: NYI('__munmap'),
|
|
||||||
nanosleep: NYI('nanosleep'),
|
|
||||||
__netf2: NYI('__netf2'),
|
__netf2: NYI('__netf2'),
|
||||||
posix_spawn: NYI('posix_spawn'),
|
nftw: NYI('nftw'),
|
||||||
posix_spawn_file_actions_adddup2: NYI('posix_spawn_file_actions_adddup2'),
|
pthread_attr_init: NYI('pthread_attr_init'),
|
||||||
posix_spawn_file_actions_destroy: NYI('posix_spawn_file_actions_destroy'),
|
pthread_attr_setdetachstate: NYI('pthread_attr_setdetachstate'),
|
||||||
posix_spawn_file_actions_init: NYI('posix_spawn_file_actions_init'),
|
pthread_attr_setguardsize: NYI('pthread_attr_setguardsize'),
|
||||||
pthread_self: NYI('pthread_self'),
|
pthread_attr_setstacksize: NYI('pthread_attr_setstacksize'),
|
||||||
__randname: NYI('__randname'),
|
pthread_barrier_destroy: NYI('pthread_barrier_destroy'),
|
||||||
__rem_pio2_large: NYI('__rem_pio2_large'),
|
pthread_barrier_init: NYI('pthread_barrier_init'),
|
||||||
setitimer: NYI('setitimer'),
|
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'),
|
__set_thread_area: NYI('__set_thread_area'),
|
||||||
snprintf: NYI('snprintf'),
|
__subtf3: NYI('__subtf3'),
|
||||||
sprintf: NYI('sprintf'),
|
|
||||||
__stdio_write: NYI('__stdio_write'),
|
|
||||||
__stdout_write: NYI('__stdout_write'),
|
|
||||||
__synccall: NYI('__synccall'),
|
__synccall: NYI('__synccall'),
|
||||||
towlower: NYI('towlower'),
|
__timedwait_cp: NYI('__timedwait_cp'),
|
||||||
towupper: NYI('towupper'),
|
|
||||||
__trunctfdf2: NYI('__trunctfdf2'),
|
__trunctfdf2: NYI('__trunctfdf2'),
|
||||||
__trunctfsf2: NYI('__trunctfsf2'),
|
__trunctfsf2: NYI('__trunctfsf2'),
|
||||||
uname: NYI('uname'),
|
uname: NYI('uname'),
|
||||||
__unlock: NYI('__unlock'),
|
__unlock: NYI('__unlock'),
|
||||||
__unlockfile: NYI('__unlockfile'),
|
__unordtf2: NYI('__unordtf2'),
|
||||||
vfprintf: NYI('vfprintf'),
|
__wait: NYI('__wait'),
|
||||||
vfscanf: NYI('vfscanf'),
|
|
||||||
vsnprintf: NYI('vsnprintf'),
|
|
||||||
wctype: NYI('wctype')
|
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
@ -889,6 +897,9 @@ var musl_hack = (function() {
|
|||||||
var syscall = (function() {
|
var syscall = (function() {
|
||||||
// TODO auto-generate syscall number from the header.
|
// TODO auto-generate syscall number from the header.
|
||||||
return {
|
return {
|
||||||
|
__syscall: function(n, args) {
|
||||||
|
print('syscall(' + n + ', ' + args + ')');
|
||||||
|
return -1; },
|
||||||
__syscall0: function(n) { print('syscall(' + n + ')'); return -1; },
|
__syscall0: function(n) { print('syscall(' + n + ')'); return -1; },
|
||||||
__syscall1: function(n, a) {
|
__syscall1: function(n, a) {
|
||||||
print('syscall(' + n + ', ' + a + ')');
|
print('syscall(' + n + ', ' + a + ')');
|
||||||
|
75
libc.py
75
libc.py
@ -27,50 +27,30 @@ import tempfile
|
|||||||
|
|
||||||
verbose = False
|
verbose = False
|
||||||
|
|
||||||
# TODO add 'time'.
|
DIR_BLACKLIST = ['misc', 'thread']
|
||||||
SRC_DIRS = [
|
|
||||||
'ctype', 'env', 'errno', 'exit', 'internal', 'ldso', 'malloc', 'math',
|
|
||||||
'prng', 'regex', 'stdio', 'string', 'stdlib', 'unistd']
|
|
||||||
BLACKLIST = [
|
BLACKLIST = [
|
||||||
'puts.c', # The JS version is nicer for now.
|
'puts.c', # Prefer the JS version for now
|
||||||
'strsignal.c', '__ctype_get_mb_cur_max.c',
|
'abort.c', # Perfer the JS version for now
|
||||||
'printf.c', 'fprintf.c', 'fscanf.c', 'vfprintf.c', 'asprintf.c',
|
'_Exit.c', # Perfer the JS version for now
|
||||||
'dprintf.c', 'scanf.c', 'sprintf.c', 'snprintf.c', 'sscanf.c',
|
'exit.c', # Contains a weak reference which is not suppoered by s2wasm
|
||||||
'vfscanf.c', 'vsnprintf.c',
|
'__libc_start_main.c', # Contains a weak reference which is not suppoered by s2wasm
|
||||||
'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'
|
|
||||||
]
|
]
|
||||||
WARNINGS = ['-Wno-incompatible-library-redeclaration',
|
CFLAGS = ['-std=c99',
|
||||||
|
'-D_XOPEN_SOURCE=700',
|
||||||
|
'-Werror',
|
||||||
|
'-Wno-incompatible-library-redeclaration',
|
||||||
'-Wno-shift-op-parentheses',
|
'-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-ignored-attributes',
|
||||||
|
'-Wno-format',
|
||||||
'-Wno-bitwise-op-parentheses',
|
'-Wno-bitwise-op-parentheses',
|
||||||
|
'-Wno-logical-op-parentheses',
|
||||||
|
'-Wno-string-plus-int',
|
||||||
'-Wno-pointer-sign',
|
'-Wno-pointer-sign',
|
||||||
|
'-Wno-dangling-else',
|
||||||
|
'-Wno-absolute-value',
|
||||||
'-Wno-unknown-pragmas']
|
'-Wno-unknown-pragmas']
|
||||||
|
|
||||||
|
|
||||||
@ -107,21 +87,24 @@ def build_alltypes(musl, arch):
|
|||||||
def musl_sources(musl_root):
|
def musl_sources(musl_root):
|
||||||
"""musl sources to be built."""
|
"""musl sources to be built."""
|
||||||
sources = []
|
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)
|
base = os.path.join(musl_root, 'src', d)
|
||||||
pattern = os.path.join(base, '*.c')
|
pattern = os.path.join(base, '*.c')
|
||||||
for f in glob.glob(pattern):
|
for f in glob.glob(pattern):
|
||||||
if os.path.basename(f) in BLACKLIST:
|
if os.path.basename(f) in BLACKLIST:
|
||||||
continue
|
continue
|
||||||
sources.append(os.path.join(base, f))
|
sources.append(f)
|
||||||
return sorted(sources)
|
return sorted(sources)
|
||||||
|
|
||||||
|
|
||||||
def includes(musl, arch):
|
def includes(musl, arch):
|
||||||
"""Include path."""
|
"""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, 'src', 'internal'),
|
||||||
os.path.join(musl, 'arch', arch)]
|
os.path.join(musl, 'include')]
|
||||||
return list(itertools.chain(*zip(['-I'] * len(includes), includes)))
|
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,
|
compile_cmd = [os.path.join(self.clang_dir, 'clang'), '-target', target,
|
||||||
'-Os', '-c', '-nostdinc']
|
'-Os', '-c', '-nostdinc']
|
||||||
compile_cmd += includes(self.musl, self.arch)
|
compile_cmd += includes(self.musl, self.arch)
|
||||||
compile_cmd += WARNINGS
|
compile_cmd += CFLAGS
|
||||||
check_output(compile_cmd + [src], cwd=self.tmpdir)
|
check_output(compile_cmd + [src], cwd=self.tmpdir)
|
||||||
return os.path.basename(src)[:-1] + 'o' # .c -> .o
|
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,
|
compile_cmd = [os.path.join(self.clang_dir, 'clang'), '-target', target,
|
||||||
'-Os', '-emit-llvm', '-S', '-nostdinc']
|
'-Os', '-emit-llvm', '-S', '-nostdinc']
|
||||||
compile_cmd += includes(self.musl, self.arch)
|
compile_cmd += includes(self.musl, self.arch)
|
||||||
compile_cmd += WARNINGS
|
compile_cmd += CFLAGS
|
||||||
check_output(compile_cmd + [src], cwd=self.tmpdir)
|
check_output(compile_cmd + [src], cwd=self.tmpdir)
|
||||||
return os.path.basename(src)[:-1] + 'll' # .c -> .ll
|
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)
|
sexpr_wasm)
|
||||||
compiler.compile(sources)
|
compiler.compile(sources)
|
||||||
compiler.binary()
|
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:
|
finally:
|
||||||
if not save_temps:
|
if not save_temps:
|
||||||
shutil.rmtree(tmpdir)
|
shutil.rmtree(tmpdir)
|
||||||
|
Reference in New Issue
Block a user