Commit 721c9332 authored by Kirill Smelkov's avatar Kirill Smelkov

__attribute__(constructor) actually works

wasm@deco:~/trydynlib$ make -B
emcc -s WASM=0 -s SIDE_MODULE=1 -DLIBF_COMPILE -o libf_so.js libf.c
emcc -s WASM=0 -s SIDE_MODULE=1 -s RUNTIME_LINKED_LIBS="['libf_so.js']" -DLIBK_COMPILE -o libk_so.js libk.c
warning: unexpected number of arguments 0 in call to 'ffunc1', should be 1
emcc -s WASM=0 -s MAIN_MODULE=1 -s RUNTIME_LINKED_LIBS="['libk_so.js']" -o prog.js prog.c
warning: unexpected number of arguments 0 in call to 'kfunc1', should be 1

wasm@deco:~/trydynlib$ node prog.js
prog!
libf.ffunc1
libk.kfunc1 -> 12
parent 3bdad7bf
......@@ -17,7 +17,7 @@ all : prog.js
libf_so.$(SO) : libf.c
$(CC) -s SIDE_MODULE=1 -DLIBF_COMPILE -o $@ $<
libk_so.$(SO) : libk.cpp libf.h libf_so.$(SO)
libk_so.$(SO) : libk.c libf.h libf_so.$(SO)
$(CC) -s SIDE_MODULE=1 -s RUNTIME_LINKED_LIBS="['libf_so.$(SO)']" -DLIBK_COMPILE -o $@ $<
......
......@@ -5,26 +5,12 @@
// XXX should be in make, but currently emscripten cannot do this
#if 1
__attribute__((constructor)) // FIXME does not work (in C) ?
__attribute__((constructor))
static void init_ctor() {
EM_ASM({
loadDynamicLibrary('libf_so.js');
});
}
#endif
#if 0
class init {
init() {
EM_ASM({
loadDynamicLibrary('libf_so.js');
});
}
};
static init _();
#endif
LIBKAPI
int kfunc1() {
......
......@@ -45,7 +45,7 @@ gb = alignMemory(getMemory(48 + 1), 1 || 1);
for (var i = gb; i < gb + 48; ++i) HEAP8[i] = 0;
// STATICTOP = STATIC_BASE + 48;
/* global initializers */ __ATINIT__.push({ func: function() { __ZL9init_ctorv() } });
/* global initializers */ __ATINIT__.push({ func: function() { _init_ctor() } });
/* memory initializer */ allocate([123,32,108,111,97,100,68,121,110,97,109,105,99,76,105,98,114,97,114,121,40,39,108,105,98,102,95,115,111,46,106,115,39,41,59,32,125,0], "i8", ALLOC_NONE, gb);
......@@ -194,7 +194,7 @@ function setThrew(threw, value) {
}
}
function __ZL9init_ctorv() {
function _init_ctor() {
var $0 = 0, label = 0, sp = 0;
sp = STACKTOP;
$0 = _emscripten_asm_const_i(0)|0;
......@@ -216,15 +216,15 @@ function runPostSets() {
// EMSCRIPTEN_END_FUNCS
return { __ZL9init_ctorv: __ZL9init_ctorv, _kfunc1: _kfunc1, establishStackSpace: establishStackSpace, runPostSets: runPostSets, setThrew: setThrew, stackAlloc: stackAlloc, stackRestore: stackRestore, stackSave: stackSave };
return { _init_ctor: _init_ctor, _kfunc1: _kfunc1, establishStackSpace: establishStackSpace, runPostSets: runPostSets, setThrew: setThrew, stackAlloc: stackAlloc, stackRestore: stackRestore, stackSave: stackSave };
})
// EMSCRIPTEN_END_ASM
(Module.asmGlobalArg, Module.asmLibraryArg, buffer);
var real___ZL9init_ctorv = asm["__ZL9init_ctorv"]; asm["__ZL9init_ctorv"] = function() {
var real__init_ctor = asm["_init_ctor"]; asm["_init_ctor"] = function() {
assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)');
assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
return real___ZL9init_ctorv.apply(null, arguments);
return real__init_ctor.apply(null, arguments);
};
var real__kfunc1 = asm["_kfunc1"]; asm["_kfunc1"] = function() {
......@@ -238,7 +238,7 @@ var real_setThrew = asm["setThrew"]; asm["setThrew"] = function() {
assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)');
return real_setThrew.apply(null, arguments);
};
var __ZL9init_ctorv = Module["__ZL9init_ctorv"] = asm["__ZL9init_ctorv"];
var _init_ctor = Module["_init_ctor"] = asm["_init_ctor"];
var _kfunc1 = Module["_kfunc1"] = asm["_kfunc1"];
var runPostSets = Module["runPostSets"] = asm["runPostSets"];
var setThrew = Module["setThrew"] = asm["setThrew"];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment