From: Matt Corallo Date: Sat, 8 Jan 2022 19:44:08 +0000 (+0000) Subject: [TS] Use export_/import_name to filter exposed symbols X-Git-Tag: v0.0.104.1^2~16 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=caf86199f09538269930ee679d2852a73671d46f;p=ldk-java [TS] Use export_/import_name to filter exposed symbols --- diff --git a/genbindings.sh b/genbindings.sh index 77c936d9..bb14f62f 100755 --- a/genbindings.sh +++ b/genbindings.sh @@ -199,7 +199,7 @@ else cat ts/bindings.c.body >> ts/bindings.c echo "Building TS bindings..." - COMPILE="$COMMON_COMPILE -flto -Wl,--no-entry -Wl,--export-dynamic -Wl,-allow-undefined -nostdlib --target=wasm32-wasi" + COMPILE="$COMMON_COMPILE -flto -Wl,--no-entry -nostdlib --target=wasm32-wasi" # We only need malloc and assert/abort, but for now just use WASI for those: #EXTRA_LINK=/usr/lib/wasm32-wasi/libc.a EXTRA_LINK= diff --git a/ts/js-wasm.h b/ts/js-wasm.h index 886c4e85..abcb5b30 100644 --- a/ts/js-wasm.h +++ b/ts/js-wasm.h @@ -2,14 +2,10 @@ #include #include -static inline size_t strlen(const char *str) { - const char *s; - for (s = str; *s; ++s) ; - return (s - str); -} +extern size_t strlen(const char *s); typedef uint32_t JSValue; -extern JSValue js_invoke_function(JSValue,JSValue,JSValue,JSValue,JSValue,JSValue,JSValue,JSValue,JSValue,JSValue,JSValue,JSValue); +extern JSValue js_invoke_function(JSValue,JSValue,JSValue,JSValue,JSValue,JSValue,JSValue,JSValue,JSValue,JSValue,JSValue,JSValue) __attribute__((import_name("js_invoke_function"))); static inline JSValue js_invoke_function_0(JSValue obj, JSValue fn){ return js_invoke_function(obj,fn,0,0,0,0,0,0,0,0,0,0); diff --git a/typescript_strings.py b/typescript_strings.py index a24faea7..0453a79a 100644 --- a/typescript_strings.py +++ b/typescript_strings.py @@ -103,12 +103,12 @@ void *memset(void *s, int c, size_t n); void *memcpy(void *dest, const void *src, size_t n); int memcmp(const void *s1, const void *s2, size_t n); -void __attribute__((noreturn)) abort(void); +extern void __attribute__((noreturn)) abort(void); static inline void assert(bool expression) { if (!expression) { abort(); } } -uint32_t __attribute__((visibility("default"))) test_bigint_pass_deadbeef0badf00d(uint64_t val) { +uint32_t __attribute__((export_name("test_bigint_pass_deadbeef0badf00d"))) test_bigint_pass_deadbeef0badf00d(uint64_t val) { return val == 0xdeadbeef0badf00dULL; } @@ -279,10 +279,10 @@ static inline LDKStr str_ref_to_owned_c(const jstring str) { typedef bool jboolean; -uint32_t __attribute__((visibility("default"))) TS_malloc(uint32_t size) { +uint32_t __attribute__((export_name("TS_malloc"))) TS_malloc(uint32_t size) { return (uint32_t)MALLOC(size, "JS-Called malloc"); } -void __attribute__((visibility("default"))) TS_free(uint32_t ptr) { +void __attribute__((export_name("TS_free"))) TS_free(uint32_t ptr) { FREE((void*)ptr); } """ @@ -355,7 +355,7 @@ import * as InternalUtils from '../InternalUtils.mjs' return "str_ref_to_owned_c(" + var_name + ")" def c_fn_name_define_pfx(self, fn_name, have_args): - return " __attribute__((visibility(\"default\"))) TS_" + fn_name + "(" + return " __attribute__((export_name(\"TS_" + fn_name + "\"))) TS_" + fn_name + "(" def wasm_import_header(self, target): res = """ @@ -364,9 +364,6 @@ imports.env = {}; var js_objs: Array> = []; var js_invoke: Function; -imports.env["abort"] = function () { - console.error("ABORT"); -}; imports.wasi_snapshot_preview1 = { "fd_write" : () => {