Commit c739465b authored by Kirill Smelkov's avatar Kirill Smelkov

__attribute__(constructor) did not work

init() is not called on libk load.
parent 76b7f605
#include "libk.h"
#include "libf.h"
#include <emscripten.h>
// XXX should be in make, but currently emscripten cannot do this
#if 1
__attribute__((constructor)) // FIXME does not work
static void init() {
EM_ASM({
Runtime.loadDynamicLibrary('libf.js');
});
}
#endif
LIBKAPI
int kfunc1() {
ffunc1();
......
......@@ -30,22 +30,25 @@
// === Body ===
var ASM_CONSTS = [];
var ASM_CONSTS = [function() { Runtime.loadDynamicLibrary('libf.js'); }];
function _emscripten_asm_const_i(code) {
return ASM_CONSTS[code]();
}
gb = alignMemory(getMemory(0 + 4), 4 || 1);
gb = alignMemory(getMemory(48 + 1), 1 || 1);
for (var i = gb; i < gb + 0; ++i) HEAP8[i] = 0;
for (var i = gb; i < gb + 48; ++i) HEAP8[i] = 0;
// STATICTOP = STATIC_BASE + 0;
/* global initializers */ __ATINIT__.push();
// STATICTOP = STATIC_BASE + 48;
/* global initializers */ __ATINIT__.push({ func: function() { _init() } });
/* memory initializer */ allocate([], "i8", ALLOC_NONE, gb);
/* memory initializer */ allocate([123,32,82,117,110,116,105,109,101,46,108,111,97,100,68,121,110,97,109,105,99,76,105,98,114,97,114,121,40,39,108,105,98,102,46,106,115,39,41,59,32,125,0], "i8", ALLOC_NONE, gb);
......@@ -54,6 +57,9 @@ for (var i = gb; i < gb + 0; ++i) HEAP8[i] = 0;
/* no memory initializer */
// {{PRE_LIBRARY}}
function _emscripten_asm_const_int() {
if (!parentModule['_emscripten_asm_const_int']) abort("external function 'emscripten_asm_const_int' is missing. perhaps a side module was not linked in? if this function was expected to arrive from a system library, try to build the MAIN_MODULE with EMCC_FORCE_STDLIBS=1 in the environment");return parentModule['_emscripten_asm_const_int'].apply(null, arguments);
}
function _ffunc1() {
if (!parentModule['_ffunc1']) abort("external function 'ffunc1' is missing. perhaps a side module was not linked in? if this function was expected to arrive from a system library, try to build the MAIN_MODULE with EMCC_FORCE_STDLIBS=1 in the environment");return parentModule['_ffunc1'].apply(null, arguments);
}
......@@ -94,7 +100,7 @@ function intArrayToString(array) {
Module.asmGlobalArg = { "Math": Math, "Int8Array": Int8Array, "Int16Array": Int16Array, "Int32Array": Int32Array, "Uint8Array": Uint8Array, "Uint16Array": Uint16Array, "Uint32Array": Uint32Array, "Float32Array": Float32Array, "Float64Array": Float64Array, "NaN": NaN, "Infinity": Infinity };
Module.asmLibraryArg = { "abort": abort, "assert": assert, "enlargeMemory": enlargeMemory, "getTotalMemory": getTotalMemory, "abortOnCannotGrowMemory": abortOnCannotGrowMemory, "abortStackOverflow": abortStackOverflow, "setTempRet0": setTempRet0, "getTempRet0": getTempRet0, "_ffunc1": _ffunc1, "DYNAMICTOP_PTR": DYNAMICTOP_PTR, "tempDoublePtr": tempDoublePtr, "STACKTOP": STACKTOP, "STACK_MAX": STACK_MAX, "gb": gb, "fb": fb };
Module.asmLibraryArg = { "abort": abort, "assert": assert, "enlargeMemory": enlargeMemory, "getTotalMemory": getTotalMemory, "abortOnCannotGrowMemory": abortOnCannotGrowMemory, "abortStackOverflow": abortStackOverflow, "setTempRet0": setTempRet0, "getTempRet0": getTempRet0, "_emscripten_asm_const_i": _emscripten_asm_const_i, "_emscripten_asm_const_int": _emscripten_asm_const_int, "_ffunc1": _ffunc1, "DYNAMICTOP_PTR": DYNAMICTOP_PTR, "tempDoublePtr": tempDoublePtr, "STACKTOP": STACKTOP, "STACK_MAX": STACK_MAX, "gb": gb, "fb": fb };
// EMSCRIPTEN_START_ASM
var asm = (/** @suppress {uselessCode} */ function(global, env, buffer) {
'almost asm';
......@@ -149,6 +155,8 @@ var asm = (/** @suppress {uselessCode} */ function(global, env, buffer) {
var abortStackOverflow=env.abortStackOverflow;
var setTempRet0=env.setTempRet0;
var getTempRet0=env.getTempRet0;
var _emscripten_asm_const_i=env._emscripten_asm_const_i;
var _emscripten_asm_const_int=env._emscripten_asm_const_int;
var _ffunc1=env._ffunc1;
var tempFloat = 0.0;
......@@ -186,6 +194,12 @@ function setThrew(threw, value) {
}
}
function _init() {
var $0 = 0, label = 0, sp = 0;
sp = STACKTOP;
$0 = _emscripten_asm_const_i(0)|0;
return;
}
function _kfunc1() {
var label = 0, sp = 0;
sp = STACKTOP;
......@@ -202,11 +216,17 @@ function runPostSets() {
// EMSCRIPTEN_END_FUNCS
return { _kfunc1: _kfunc1, establishStackSpace: establishStackSpace, runPostSets: runPostSets, setThrew: setThrew, stackAlloc: stackAlloc, stackRestore: stackRestore, stackSave: stackSave };
return { _init: _init, _kfunc1: _kfunc1, establishStackSpace: establishStackSpace, runPostSets: runPostSets, setThrew: setThrew, stackAlloc: stackAlloc, stackRestore: stackRestore, stackSave: stackSave };
})
// EMSCRIPTEN_END_ASM
(Module.asmGlobalArg, Module.asmLibraryArg, buffer);
var real__init = asm["_init"]; asm["_init"] = 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__init.apply(null, arguments);
};
var real__kfunc1 = asm["_kfunc1"]; asm["_kfunc1"] = 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)');
......@@ -218,6 +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 _init = Module["_init"] = asm["_init"];
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