diff --git a/src/library.js b/src/library.js index 6da189097bd17..c11c7a2fa1a17 100644 --- a/src/library.js +++ b/src/library.js @@ -163,12 +163,6 @@ LibraryManager.library = { #endif }, - _exit__sig: 'vi', - _exit: 'exit', - - _Exit__sig: 'vi', - _Exit: 'exit', - #if MINIMAL_RUNTIME $exit: function(status) { throw 'exit(' + status + ')'; diff --git a/system/lib/libc/musl/src/exit/_Exit.c b/system/lib/libc/musl/src/exit/_Exit.c index 7a6115c7bbc71..9d06aac1d89ef 100644 --- a/system/lib/libc/musl/src/exit/_Exit.c +++ b/system/lib/libc/musl/src/exit/_Exit.c @@ -3,6 +3,10 @@ _Noreturn void _Exit(int ec) { +#ifdef __EMSCRIPTEN__ + __wasi_proc_exit(ec); +#else __syscall(SYS_exit_group, ec); for (;;) __syscall(SYS_exit, ec); +#endif } diff --git a/system/lib/standalone/standalone.c b/system/lib/standalone/standalone.c index 645abfe199b83..9daaa1737ce5e 100644 --- a/system/lib/standalone/standalone.c +++ b/system/lib/standalone/standalone.c @@ -25,11 +25,6 @@ // libc -void _Exit(int status) { - __wasi_proc_exit(status); - __builtin_unreachable(); -} - void abort() { _Exit(1); } diff --git a/tools/system_libs.py b/tools/system_libs.py index 670e04c2f401c..65609fbb6f42b 100644 --- a/tools/system_libs.py +++ b/tools/system_libs.py @@ -151,6 +151,14 @@ def get_wasm_libc_rt_files(): return math_files + other_files + iprintf_files +def is_case_insensitive(path): + """Returns True if the filesystem at `path` is case insensitive.""" + shared.write_file(os.path.join(path, 'test_file'), '') + case_insensitive = os.path.exists(os.path.join(path, 'TEST_FILE')) + os.remove(os.path.join(path, 'test_file')) + return case_insensitive + + class Library: """ `Library` is the base class of all system libraries. @@ -343,8 +351,20 @@ def build_objects(self, build_dir): objects = [] cflags = self.get_cflags() base_flags = get_base_cflags() + case_insensitive = is_case_insensitive(build_dir) for src in self.get_files(): - o = os.path.join(build_dir, shared.unsuffixed_basename(src) + '.o') + object_basename = shared.unsuffixed_basename(src) + # Resolve duplicates by appending unique. + # This is needed on case insensitve filesystem to handle, + # for example, _exit.o and _Exit.o. + if case_insensitive: + object_basename = object_basename.lower() + o = os.path.join(build_dir, object_basename + '.o') + object_uuid = 0 + # Find a unique basename + while o in objects: + object_uuid += 1 + o = os.path.join(build_dir, f'{object_basename}__{object_uuid}.o') ext = shared.suffix(src) if ext in ('.s', '.S', '.c'): cmd = [shared.EMCC] @@ -704,7 +724,7 @@ def get_files(self): 'res_query.c', 'res_querydomain.c', 'gai_strerror.c', 'proto.c', 'gethostbyaddr.c', 'gethostbyaddr_r.c', 'gethostbyname.c', 'gethostbyname2_r.c', 'gethostbyname_r.c', 'gethostbyname2.c', - 'alarm.c', 'syscall.c', '_exit.c', 'popen.c', + 'alarm.c', 'syscall.c', 'popen.c', 'getgrouplist.c', 'initgroups.c', 'wordexp.c', 'timer_create.c', 'faccessat.c', # 'process' exclusion @@ -825,6 +845,10 @@ def get_files(self): path_components=['system', 'lib', 'libc', 'musl', 'src', 'sched'], filenames=['sched_yield.c']) + libc_files += files_in_path( + path_components=['system', 'lib', 'libc', 'musl', 'src', 'exit'], + filenames=['_Exit.c']) + libc_files += files_in_path( path_components=['system', 'lib', 'libc'], filenames=[ @@ -1390,9 +1414,7 @@ def get_files(self): # including fprintf etc. exit_files = files_in_path( path_components=['system', 'lib', 'libc', 'musl', 'src', 'exit'], - filenames=['assert.c', 'atexit.c', 'exit.c']) + files_in_path( - path_components=['system', 'lib', 'libc', 'musl', 'src', 'unistd'], - filenames=['_exit.c']) + filenames=['assert.c', 'atexit.c', 'exit.c']) return base_files + time_files + exit_files