Skip to content

Commit b1d2d39

Browse files
authored
Use _Exit and _exit from musl source. NFC (#14464)
This is part 1 of a change I'm working on to use musl's exit code. This is NFC because we endup calling proc_exit which calls exit in any case.
1 parent a88a0bf commit b1d2d39

File tree

4 files changed

+31
-16
lines changed

4 files changed

+31
-16
lines changed

src/library.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,6 @@ LibraryManager.library = {
163163
#endif
164164
},
165165

166-
_exit__sig: 'vi',
167-
_exit: 'exit',
168-
169-
_Exit__sig: 'vi',
170-
_Exit: 'exit',
171-
172166
#if MINIMAL_RUNTIME
173167
$exit: function(status) {
174168
throw 'exit(' + status + ')';

system/lib/libc/musl/src/exit/_Exit.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
_Noreturn void _Exit(int ec)
55
{
6+
#ifdef __EMSCRIPTEN__
7+
__wasi_proc_exit(ec);
8+
#else
69
__syscall(SYS_exit_group, ec);
710
for (;;) __syscall(SYS_exit, ec);
11+
#endif
812
}

system/lib/standalone/standalone.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@
2525

2626
// libc
2727

28-
void _Exit(int status) {
29-
__wasi_proc_exit(status);
30-
__builtin_unreachable();
31-
}
32-
3328
void abort() {
3429
_Exit(1);
3530
}

tools/system_libs.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,14 @@ def get_wasm_libc_rt_files():
151151
return math_files + other_files + iprintf_files
152152

153153

154+
def is_case_insensitive(path):
155+
"""Returns True if the filesystem at `path` is case insensitive."""
156+
shared.write_file(os.path.join(path, 'test_file'), '')
157+
case_insensitive = os.path.exists(os.path.join(path, 'TEST_FILE'))
158+
os.remove(os.path.join(path, 'test_file'))
159+
return case_insensitive
160+
161+
154162
class Library:
155163
"""
156164
`Library` is the base class of all system libraries.
@@ -343,8 +351,20 @@ def build_objects(self, build_dir):
343351
objects = []
344352
cflags = self.get_cflags()
345353
base_flags = get_base_cflags()
354+
case_insensitive = is_case_insensitive(build_dir)
346355
for src in self.get_files():
347-
o = os.path.join(build_dir, shared.unsuffixed_basename(src) + '.o')
356+
object_basename = shared.unsuffixed_basename(src)
357+
# Resolve duplicates by appending unique.
358+
# This is needed on case insensitve filesystem to handle,
359+
# for example, _exit.o and _Exit.o.
360+
if case_insensitive:
361+
object_basename = object_basename.lower()
362+
o = os.path.join(build_dir, object_basename + '.o')
363+
object_uuid = 0
364+
# Find a unique basename
365+
while o in objects:
366+
object_uuid += 1
367+
o = os.path.join(build_dir, f'{object_basename}__{object_uuid}.o')
348368
ext = shared.suffix(src)
349369
if ext in ('.s', '.S', '.c'):
350370
cmd = [shared.EMCC]
@@ -704,7 +724,7 @@ def get_files(self):
704724
'res_query.c', 'res_querydomain.c', 'gai_strerror.c',
705725
'proto.c', 'gethostbyaddr.c', 'gethostbyaddr_r.c', 'gethostbyname.c',
706726
'gethostbyname2_r.c', 'gethostbyname_r.c', 'gethostbyname2.c',
707-
'alarm.c', 'syscall.c', '_exit.c', 'popen.c',
727+
'alarm.c', 'syscall.c', 'popen.c',
708728
'getgrouplist.c', 'initgroups.c', 'wordexp.c', 'timer_create.c',
709729
'faccessat.c',
710730
# 'process' exclusion
@@ -825,6 +845,10 @@ def get_files(self):
825845
path_components=['system', 'lib', 'libc', 'musl', 'src', 'sched'],
826846
filenames=['sched_yield.c'])
827847

848+
libc_files += files_in_path(
849+
path_components=['system', 'lib', 'libc', 'musl', 'src', 'exit'],
850+
filenames=['_Exit.c'])
851+
828852
libc_files += files_in_path(
829853
path_components=['system', 'lib', 'libc'],
830854
filenames=[
@@ -1390,9 +1414,7 @@ def get_files(self):
13901414
# including fprintf etc.
13911415
exit_files = files_in_path(
13921416
path_components=['system', 'lib', 'libc', 'musl', 'src', 'exit'],
1393-
filenames=['assert.c', 'atexit.c', 'exit.c']) + files_in_path(
1394-
path_components=['system', 'lib', 'libc', 'musl', 'src', 'unistd'],
1395-
filenames=['_exit.c'])
1417+
filenames=['assert.c', 'atexit.c', 'exit.c'])
13961418
return base_files + time_files + exit_files
13971419

13981420

0 commit comments

Comments
 (0)