Skip to content

Cleanup deps_info.py. NFC. #12824

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -2103,7 +2103,7 @@ LibraryManager.library = {
_inet_ntop4_raw: function(addr) {
return (addr & 0xff) + '.' + ((addr >> 8) & 0xff) + '.' + ((addr >> 16) & 0xff) + '.' + ((addr >> 24) & 0xff)
},
_inet_pton6_raw__deps: ['htons', 'ntohs', '$jstoi_q'],
_inet_pton6_raw__deps: ['htons', '$jstoi_q'],
_inet_pton6_raw: function(str) {
var words;
var w, offset, z, i;
Expand Down Expand Up @@ -2170,7 +2170,7 @@ LibraryManager.library = {
}
return 1;
},
_inet_ntop6_raw__deps: ['_inet_ntop4_raw'],
_inet_ntop6_raw__deps: ['_inet_ntop4_raw', 'ntohs'],
_inet_ntop6_raw: function(ints) {
// ref: http://www.ietf.org/rfc/rfc2373.txt - section 2.5.4
// Format for IPv4 compatible and mapped 128-bit IPv6 Addresses
Expand Down
1 change: 0 additions & 1 deletion tests/other/metadce/hello_libcxx_O2_fexceptions.exports
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
_ZSt18uncaught_exceptionv
__cxa_can_catch
__cxa_is_pointer_type
__errno_location
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
_ZSt18uncaught_exceptionv
__cxa_can_catch
__cxa_demangle
__cxa_is_pointer_type
Expand Down
55 changes: 54 additions & 1 deletion tests/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from runner import RunnerCore, path_from_root, is_slow_test, ensure_dir, disabled, make_executable
from runner import env_modify, no_mac, no_windows, requires_native_clang, with_env_modify
from runner import create_test_file, parameterized, NON_ZERO, node_pthreads
from tools import shared, building, utils
from tools import shared, building, utils, deps_info
import jsrun
import clang_native
from tools import line_endings
Expand Down Expand Up @@ -9950,3 +9950,56 @@ def test_relocatable_limited_exports(self):
self.assertGreater(len(exports_linkable), 1000)
self.assertIn('sendmsg', exports_linkable)
self.assertNotIn('sendmsg', exports)

@is_slow_test
def test_deps_info(self):
# Verify that for each symbol listed in deps_info all the reverse
# dependencies are indeed valid.
# To do this we compile a tiny test program that depend on the address
# of each function. Once compiled the resulting JavaScript code should
# contain a reference to each of the dependencies.
start_at = None
assert not start_at or start_at in deps_info.deps_info
for function, deps in deps_info.deps_info.items():
if start_at:
if function == start_at:
start_at = None
else:
print(f'skipping {function}')
continue
create_test_file(function + '.c', '''
void %s();
int main() {
return (int)&%s;
}
''' % (function, function))
cmd = [EMCC, function + '.c', '--profiling-funcs', '-Wno-incompatible-library-redeclaration']
print(f'compiling test program for: {function}')
print(shared.shlex_join(cmd))
if 'embind' in function:
cmd.append('--bind')
if 'fetch' in function:
cmd.append('-sFETCH')
if 'websocket' in function:
cmd += ['-sPROXY_POSIX_SOCKETS', '-lwebsocket.js']
if function == 'Mix_LoadWAV_RW':
cmd += ['-sUSE_SDL=2']
if 'thread' in function:
cmd.append('-sUSE_PTHREADS')
if 'glGetStringi' in function:
cmd.append('-sUSE_WEBGL2')
if 'glMapBufferRange' in function:
cmd.append('-sFULL_ES3')
if function == 'wgpuDeviceCreateBuffer':
cmd.append('-sUSE_WEBGPU')
if function == 'setjmp':
continue
self.run_process(cmd)
js = open('a.out.js').read()
for dep in deps:
direct = '_' + dep + '('
via_module = "_" + dep + "']("
assignment = ' = _' + dep
print(f' checking for: {dep}')
if direct not in js and via_module not in js and assignment not in js:
self.fail(f'use of declared dependency {dep} not found in JS output for {function}')
50 changes: 22 additions & 28 deletions tools/deps_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,12 @@
'SDL_OpenAudio': ['malloc', 'free'],
'SDL_PushEvent': ['malloc', 'free'],
'SDL_free': ['free'],
'SDL_getenv': ['malloc', 'free'],
'SDL_malloc': ['malloc', 'free'],
'__ctype_b_loc': ['malloc', 'free'],
'__ctype_tolower_loc': ['malloc', 'free'],
'__ctype_toupper_loc': ['malloc', 'free'],
'__cxa_allocate_exception': ['malloc', 'free', 'setThrew'],
'__cxa_begin_catch': ['_ZSt18uncaught_exceptionv', 'setThrew'],
'__cxa_end_catch': ['free'],
'__cxa_allocate_exception': ['malloc'],
'__cxa_end_catch': ['setThrew', 'free'],
'__cxa_find_matching_catch': ['__cxa_is_pointer_type', '__cxa_can_catch'],
'__cxa_find_matching_catch_0': ['__cxa_is_pointer_type', '__cxa_can_catch'],
'__cxa_find_matching_catch_1': ['__cxa_is_pointer_type', '__cxa_can_catch'],
Expand All @@ -77,8 +75,6 @@
'__cxa_find_matching_catch_8': ['__cxa_is_pointer_type', '__cxa_can_catch'],
'__cxa_find_matching_catch_9': ['__cxa_is_pointer_type', '__cxa_can_catch'],
'__cxa_free_exception': ['free'],
'__cxa_throw': ['setThrew'],
'__gxx_personality_v0': ['_ZSt18uncaught_exceptionv', '__cxa_find_matching_catch'],
'_embind_register_class': ['free'],
'_embind_register_enum_value': ['free'],
'_embind_register_function': ['free'],
Expand All @@ -89,18 +85,18 @@
'alGetString': ['malloc', 'free'],
'alcGetProcAddress': ['emscripten_GetAlcProcAddress'],
'alcGetString': ['malloc', 'free'],
'bind': ['htonl', 'htons', 'ntohs'],
'bind': ['ntohs'],
'calloc': ['malloc', 'free'],
'connect': ['htonl', 'htons', 'ntohs'],
'connect': ['ntohs'],
'ctime': ['_get_tzname', '_get_daylight', '_get_timezone', 'malloc', 'free'],
'ctime_r': ['_get_tzname', '_get_daylight', '_get_timezone', 'malloc', 'free'],
'dladdr': ['malloc', 'free'],
'dlerror': ['malloc', 'free'],
'eglGetProcAddress': ['emscripten_GetProcAddress'],
'eglQueryString': ['malloc', 'free'],
'emscripten_GetAlProcAddress': ['strcmp'],
'emscripten_GetAlcProcAddress': ['strcmp'],
'emscripten_GetProcAddress': ['malloc', 'strstr'],
'emscripten_GetProcAddress': ['malloc'],
'emscripten_GetAlProcAddress': ['emscripten_GetAlProcAddress'],
'emscripten_GetAlcProcAddress': ['emscripten_GetAlcProcAddress'],
'emscripten_SDL_SetEventHandler': ['malloc', 'free'],
'emscripten_alcGetStringiSOFT': ['malloc', 'free'],
'emscripten_async_wget2_data': ['malloc', 'free'],
Expand All @@ -115,9 +111,9 @@
'emscripten_idb_load': ['malloc', 'free'],
'emscripten_init_websocket_to_posix_socket_bridge': ['malloc', 'free'],
'emscripten_log': ['strlen'],
'emscripten_longjmp': ['setThrew', 'realloc', 'testSetjmp', 'saveSetjmp'],
'emscripten_pc_get_file': ['malloc', 'free'],
'emscripten_pc_get_function': ['malloc', 'free'],
'emscripten_longjmp': ['setThrew'],
'emscripten_pc_get_file': ['emscripten_builtin_malloc', 'emscripten_builtin_free', 'emscripten_builtin_memalign', 'malloc', 'free'],
'emscripten_pc_get_function': ['emscripten_builtin_malloc', 'emscripten_builtin_free', 'emscripten_builtin_memalign', 'malloc', 'free'],
'emscripten_run_preload_plugins_data': ['malloc', 'free'],
'emscripten_run_script_string': ['malloc', 'free'],
'emscripten_set_batterychargingchange_callback_on_thread': ['malloc', 'free'],
Expand Down Expand Up @@ -178,11 +174,12 @@
'gai_strerror': ['malloc', 'free'],
'getaddrinfo': ['malloc', 'free', 'htonl', 'htons', 'ntohs'],
'getenv': ['malloc', 'free'],
'gethostbyname': ['malloc', 'free', 'htons', 'ntohs', 'memcpy'],
'gethostbyname_r': ['malloc', 'free', 'htons', 'ntohs', 'memcpy'],
'gethostbyname': ['malloc', 'free', 'htons'],
'gethostbyname_r': ['malloc', 'free', 'htons', 'memcpy'],
'getlogin': ['malloc', 'free'],
'getnameinfo': ['htons', 'ntohs'],
'getpeername': ['htons', 'ntohs'],
'getpeername': ['htons'],
'getsockname': ['htons'],
'getrusage': ['memset'],
'glBegin': ['malloc', 'free'],
'glGetString': ['malloc', 'free'],
Expand All @@ -197,33 +194,30 @@
'inet_ntoa': ['malloc', 'free'],
'localtime': ['_get_tzname', '_get_daylight', '_get_timezone', 'malloc', 'free'],
'localtime_r': ['_get_tzname', '_get_daylight', '_get_timezone', 'malloc', 'free'],
'longjmp': ['setThrew', 'realloc', 'testSetjmp', 'saveSetjmp'],
'longjmp': ['setThrew'],
'mktime': ['_get_tzname', '_get_daylight', '_get_timezone', 'malloc', 'free'],
'mmap': ['memalign', 'memset', 'malloc', 'free'],
'munmap': ['memalign', 'memset', 'malloc', 'free'],
'munmap': ['malloc', 'free'],
'newlocale': ['malloc', 'free'],
'nl_langinfo': ['malloc', 'free'],
'pthread_create': ['malloc', 'free', 'emscripten_main_thread_process_queued_calls'],
'readdir': ['malloc', 'free'],
'realloc': ['malloc', 'free'],
'realpath': ['malloc', 'free'],
'recv': ['htons', 'ntohs'],
'send': ['htons', 'ntohs'],
'setjmp': ['setThrew', 'realloc', 'testSetjmp', 'saveSetjmp'],
'recv': ['htons'],
'send': ['ntohs'],
'setjmp': ['saveSetjmp'],
'setprotoent': ['malloc', 'free'],
'siglongjmp': ['setThrew', 'realloc', 'testSetjmp', 'saveSetjmp'],
'sleep': ['usleep'],
'socket': ['htonl', 'htons', 'ntohs'],
'socketpair': ['htons', 'ntohs'],
'siglongjmp': ['setThrew'],
'strerror': ['malloc', 'free'],
'syslog': ['malloc', 'htons', 'ntohs'],
'syslog': ['malloc', 'ntohs'],
'timegm': ['_get_tzname', '_get_daylight', '_get_timezone', 'malloc', 'free'],
'times': ['memset'],
'tmpnam': ['malloc', 'free'],
'ttyname': ['malloc', 'free'],
'tzset': ['_get_tzname', '_get_daylight', '_get_timezone', 'malloc', 'free'],
'uuid_clear': ['memset'],
'uuid_compare': ['memcmp', 'memcpy', 'memset'],
'uuid_compare': ['memcmp'],
'uuid_copy': ['memcpy'],
'wgpuDeviceCreateBuffer': ['malloc', 'free'],
'emscripten_glGetString': ['malloc'],
Expand Down