mirror of
https://github.com/fluencelabs/musl
synced 2025-04-29 00:52:15 +00:00
[WebAssembly] Use hardcoded list expected undefined symbols (#21)
Rather than generate wasm.syms from wasm.js (which includes a huge superset of the number of symbols actaully expected to be undefined at link time) simply hardcode that list as a test file, which lld can read.
This commit is contained in:
parent
8116ebcd0c
commit
c185c68dd0
@ -951,11 +951,7 @@ var ffi = (function() {
|
|||||||
if (arguments.length < 1)
|
if (arguments.length < 1)
|
||||||
throw new Error('Expected at least one wasm module to load.');
|
throw new Error('Expected at least one wasm module to load.');
|
||||||
|
|
||||||
if (arguments[0] == '--dump-ffi-symbols') {
|
function load_wasm(file_path) {
|
||||||
for (var name in ffi["env"])
|
|
||||||
print(name)
|
|
||||||
} else {
|
|
||||||
function load_wasm(file_path) {
|
|
||||||
// TODO this should be split up in load, check dependencies, and then resolve
|
// TODO this should be split up in load, check dependencies, and then resolve
|
||||||
// dependencies. That would make it easier to do lazy loading. We could do
|
// dependencies. That would make it easier to do lazy loading. We could do
|
||||||
// this by catching load exceptions + adding to ffi and trying again, but
|
// this by catching load exceptions + adding to ffi and trying again, but
|
||||||
@ -973,14 +969,14 @@ if (arguments[0] == '--dump-ffi-symbols') {
|
|||||||
heap_size_bytes = heap.byteLength;
|
heap_size_bytes = heap.byteLength;
|
||||||
}
|
}
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load modules in reverse, adding their exports to the ffi object.
|
// Load modules in reverse, adding their exports to the ffi object.
|
||||||
// This is analogous to how the linker resolves symbols: the later modules
|
// This is analogous to how the linker resolves symbols: the later modules
|
||||||
// export symbols used by the earlier modules, and allow shadowing.
|
// export symbols used by the earlier modules, and allow shadowing.
|
||||||
// Note that all modules, as well as the main module, share a heap.
|
// Note that all modules, as well as the main module, share a heap.
|
||||||
var modules = {};
|
var modules = {};
|
||||||
for (var i = arguments.length - 1; i > 0; --i) {
|
for (var i = arguments.length - 1; i > 0; --i) {
|
||||||
var path = arguments[i];
|
var path = arguments[i];
|
||||||
modules[i] = load_wasm(path);
|
modules[i] = load_wasm(path);
|
||||||
for (var f in modules[i].exports) {
|
for (var f in modules[i].exports) {
|
||||||
@ -991,21 +987,21 @@ if (arguments[0] == '--dump-ffi-symbols') {
|
|||||||
if (modules[i].exports[f] instanceof Function)
|
if (modules[i].exports[f] instanceof Function)
|
||||||
ffi['env'][f] = modules[i].exports[f];
|
ffi['env'][f] = modules[i].exports[f];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the main module once the ffi object has been fully populated.
|
// Load the main module once the ffi object has been fully populated.
|
||||||
var main_module = arguments[0];
|
var main_module = arguments[0];
|
||||||
modules[0] = load_wasm(main_module);
|
modules[0] = load_wasm(main_module);
|
||||||
|
|
||||||
// TODO check that `main` exists in modules[0].exports and error out if not.
|
// TODO check that `main` exists in modules[0].exports and error out if not.
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var ret = modules[0].exports.main();
|
var ret = modules[0].exports.main();
|
||||||
stdio.__flush_stdout();
|
stdio.__flush_stdout();
|
||||||
print(main_module + '::main() returned ' + ret);
|
print(main_module + '::main() returned ' + ret);
|
||||||
if (ret != stdlib.EXIT_SUCCESS)
|
if (ret != stdlib.EXIT_SUCCESS)
|
||||||
throw new Error('main reported failure');
|
throw new Error('main reported failure');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
stdio.__flush_stdout();
|
stdio.__flush_stdout();
|
||||||
if (e instanceof TerminateWasmException) {
|
if (e instanceof TerminateWasmException) {
|
||||||
print('Program terminated with: ' + e);
|
print('Program terminated with: ' + e);
|
||||||
@ -1034,5 +1030,4 @@ if (arguments[0] == '--dump-ffi-symbols') {
|
|||||||
('Unknown exception of type `' + typeof(e) + '`: ' + e));
|
('Unknown exception of type `' + typeof(e) + '`: ' + e));
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
34
arch/wasm32/wasm.syms
Normal file
34
arch/wasm32/wasm.syms
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
# Symbols we want wasm.js to define at runtime
|
||||||
|
_Exit
|
||||||
|
abort
|
||||||
|
puts
|
||||||
|
|
||||||
|
# Musl syscall interface, provided by wasm.js
|
||||||
|
__syscall
|
||||||
|
__syscall0
|
||||||
|
__syscall1
|
||||||
|
__syscall2
|
||||||
|
__syscall3
|
||||||
|
__syscall4
|
||||||
|
__syscall5
|
||||||
|
__syscall6
|
||||||
|
__syscall_cp
|
||||||
|
|
||||||
|
# Symbols not supported by clang but currently expected to work on the
|
||||||
|
# wasm waterfall
|
||||||
|
# TODO(sbc): remove these
|
||||||
|
__builtin_isinff
|
||||||
|
__builtin_isinfl
|
||||||
|
__builtin_clrsb
|
||||||
|
__builtin_clrsbl
|
||||||
|
__builtin_clrsbll
|
||||||
|
__builtin_apply
|
||||||
|
__builtin_apply_args
|
||||||
|
__builtin_malloc
|
||||||
|
|
||||||
|
# Part of musl we still don't compile for wasm
|
||||||
|
__lock
|
||||||
|
__unlock
|
||||||
|
__set_thread_area
|
||||||
|
setjmp
|
||||||
|
longjmp
|
Loading…
x
Reference in New Issue
Block a user