Commit 462cb27f authored by Kirill Smelkov's avatar Kirill Smelkov

libk calls -> libf but for libf is linked by main (for now?)

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 -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', 'libf_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 a63a840f
......@@ -14,12 +14,16 @@ endif
all : prog.js
libk_so.$(SO) : libk.c
libf_so.$(SO) : libf.c
$(CC) -s SIDE_MODULE=1 -DLIBF_COMPILE -o $@ $<
libk_so.$(SO) : libk.c libf.h libf_so.$(SO)
$(CC) -s SIDE_MODULE=1 -DLIBK_COMPILE -o $@ $<
# FIXME link in libf_so in libk_so
prog.js : prog.c libk_so.$(SO)
$(CC) -s MAIN_MODULE=1 -s RUNTIME_LINKED_LIBS="['libk_so.$(SO)']" -o $@ prog.c
$(CC) -s MAIN_MODULE=1 -s RUNTIME_LINKED_LIBS="['libk_so.$(SO)', 'libf_so.$(SO)']" -o $@ prog.c
.PHONY : FORCE
......
#include "libf.h"
#include <stdio.h>
LIBFAPI
void ffunc1() {
printf("libf.ffunc1\n");
}
#ifndef _LIBF_H
#define _LIBF_H
#include "dso.h"
#ifdef LIBF_COMPILE
# define LIBFAPI DSO_EXPORT
#else
# define LIBFAPI DSO_IMPORT
#endif
LIBFAPI void ffunc1();
#endif
// Copyright 2011 The Emscripten Authors. All rights reserved.
// Emscripten is available under two separate licenses, the MIT license and the
// University of Illinois/NCSA Open Source License. Both these licenses can be
// found in the LICENSE file.
// Capture the output of this into a variable, if you want
(function(fb, parentModule) {
var Module = {};
var args = [];
Module.arguments = [];
Module.cleanups = [];
var gb = 0;
// Each module has its own stack
var STACKTOP = getMemory(TOTAL_STACK);
assert(STACKTOP % 8 == 0);
var STACK_MAX = STACKTOP + TOTAL_STACK;
Module.cleanups.push(function() {
parentModule['_free'](STACKTOP); // XXX ensure exported, and that it was actually malloc'ed and not static memory FIXME
parentModule['_free'](gb);
});
// === Auto-generated preamble library stuff ===
//========================================
// Runtime essentials
//========================================
// === Body ===
var ASM_CONSTS = [];
gb = alignMemory(getMemory(16 + 4), 4 || 1);
for (var i = gb; i < gb + 16; ++i) HEAP8[i] = 0;
// STATICTOP = STATIC_BASE + 16;
/* global initializers */ __ATINIT__.push();
/* memory initializer */ allocate([108,105,98,102,46,102,102,117,110,99,49,10,0], "i8", ALLOC_NONE, gb);
/* no memory initializer */
// {{PRE_LIBRARY}}
function _printf() {
if (!parentModule['_printf']) abort("external function 'printf' 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['_printf'].apply(null, arguments);
}
var ASSERTIONS = true;
// Copyright 2017 The Emscripten Authors. All rights reserved.
// Emscripten is available under two separate licenses, the MIT license and the
// University of Illinois/NCSA Open Source License. Both these licenses can be
// found in the LICENSE file.
/** @type {function(string, boolean=, number=)} */
function intArrayFromString(stringy, dontAddNull, length) {
var len = length > 0 ? length : lengthBytesUTF8(stringy)+1;
var u8array = new Array(len);
var numBytesWritten = stringToUTF8Array(stringy, u8array, 0, u8array.length);
if (dontAddNull) u8array.length = numBytesWritten;
return u8array;
}
function intArrayToString(array) {
var ret = [];
for (var i = 0; i < array.length; i++) {
var chr = array[i];
if (chr > 0xFF) {
if (ASSERTIONS) {
assert(false, 'Character code ' + chr + ' (' + String.fromCharCode(chr) + ') at offset ' + i + ' not in 0x00-0xFF.');
}
chr &= 0xFF;
}
ret.push(String.fromCharCode(chr));
}
return ret.join('');
}
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, "_printf": _printf, "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';
var HEAP8 = new global.Int8Array(buffer);
var HEAP16 = new global.Int16Array(buffer);
var HEAP32 = new global.Int32Array(buffer);
var HEAPU8 = new global.Uint8Array(buffer);
var HEAPU16 = new global.Uint16Array(buffer);
var HEAPU32 = new global.Uint32Array(buffer);
var HEAPF32 = new global.Float32Array(buffer);
var HEAPF64 = new global.Float64Array(buffer);
var DYNAMICTOP_PTR=env.DYNAMICTOP_PTR|0;
var tempDoublePtr=env.tempDoublePtr|0;
var STACKTOP=env.STACKTOP|0;
var STACK_MAX=env.STACK_MAX|0;
var gb=env.gb|0;
var fb=env.fb|0;
var __THREW__ = 0;
var threwValue = 0;
var setjmpId = 0;
var undef = 0;
var nan = global.NaN, inf = global.Infinity;
var tempInt = 0, tempBigInt = 0, tempBigIntS = 0, tempValue = 0, tempDouble = 0.0;
var Math_floor=global.Math.floor;
var Math_abs=global.Math.abs;
var Math_sqrt=global.Math.sqrt;
var Math_pow=global.Math.pow;
var Math_cos=global.Math.cos;
var Math_sin=global.Math.sin;
var Math_tan=global.Math.tan;
var Math_acos=global.Math.acos;
var Math_asin=global.Math.asin;
var Math_atan=global.Math.atan;
var Math_atan2=global.Math.atan2;
var Math_exp=global.Math.exp;
var Math_log=global.Math.log;
var Math_ceil=global.Math.ceil;
var Math_imul=global.Math.imul;
var Math_min=global.Math.min;
var Math_max=global.Math.max;
var Math_clz32=global.Math.clz32;
var abort=env.abort;
var assert=env.assert;
var enlargeMemory=env.enlargeMemory;
var getTotalMemory=env.getTotalMemory;
var abortOnCannotGrowMemory=env.abortOnCannotGrowMemory;
var abortStackOverflow=env.abortStackOverflow;
var setTempRet0=env.setTempRet0;
var getTempRet0=env.getTempRet0;
var _printf=env._printf;
var tempFloat = 0.0;
// EMSCRIPTEN_START_FUNCS
function stackAlloc(size) {
size = size|0;
var ret = 0;
ret = STACKTOP;
STACKTOP = (STACKTOP + size)|0;
STACKTOP = (STACKTOP + 15)&-16;
if ((STACKTOP|0) >= (STACK_MAX|0)) abortStackOverflow(size|0);
return ret|0;
}
function stackSave() {
return STACKTOP|0;
}
function stackRestore(top) {
top = top|0;
STACKTOP = top;
}
function establishStackSpace(stackBase, stackMax) {
stackBase = stackBase|0;
stackMax = stackMax|0;
STACKTOP = stackBase;
STACK_MAX = stackMax;
}
function setThrew(threw, value) {
threw = threw|0;
value = value|0;
if ((__THREW__|0) == 0) {
__THREW__ = threw;
threwValue = value;
}
}
function _ffunc1() {
var $vararg_buffer = 0, label = 0, sp = 0;
sp = STACKTOP;
STACKTOP = STACKTOP + 16|0; if ((STACKTOP|0) >= (STACK_MAX|0)) abortStackOverflow(16|0);
$vararg_buffer = sp;
(_printf(((gb + (0) | 0)|0),($vararg_buffer|0))|0);
STACKTOP = sp;return;
}
function runPostSets() {
var temp = 0;
}
// EMSCRIPTEN_END_FUNCS
return { _ffunc1: _ffunc1, establishStackSpace: establishStackSpace, runPostSets: runPostSets, setThrew: setThrew, stackAlloc: stackAlloc, stackRestore: stackRestore, stackSave: stackSave };
})
// EMSCRIPTEN_END_ASM
(Module.asmGlobalArg, Module.asmLibraryArg, buffer);
var real__ffunc1 = asm["_ffunc1"]; asm["_ffunc1"] = 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__ffunc1.apply(null, arguments);
};
var real_setThrew = asm["setThrew"]; asm["setThrew"] = 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_setThrew.apply(null, arguments);
};
var _ffunc1 = Module["_ffunc1"] = asm["_ffunc1"];
var runPostSets = Module["runPostSets"] = asm["runPostSets"];
var setThrew = Module["setThrew"] = asm["setThrew"];
var NAMED_GLOBALS = { };
for (var named in NAMED_GLOBALS) {
Module['_' + named] = gb + NAMED_GLOBALS[named];
}
Module['NAMED_GLOBALS'] = NAMED_GLOBALS;
;
parentModule['registerFunctions']([], Module);
// === Auto-generated postamble setup entry stuff ===
__ATPRERUN__.push(runPostSets);
if (runtimeInitialized) {
// dlopen case: we are being loaded after the system is fully initialized, so just run our prerun and atinit stuff now
callRuntimeCallbacks(__ATPRERUN__);
callRuntimeCallbacks(__ATINIT__);
} // otherwise, general dynamic linking case: stuff we added to prerun and init will be executed with the rest of the system as it loads
// {{MODULE_ADDITIONS}}
return Module;
});
#include "libk.h"
#include "libf.h"
LIBKAPI
int kfunc1() {
ffunc1();
return 12;
}
......@@ -54,6 +54,9 @@ for (var i = gb; i < gb + 0; ++i) HEAP8[i] = 0;
/* no memory initializer */
// {{PRE_LIBRARY}}
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);
}
var ASSERTIONS = true;
// Copyright 2017 The Emscripten Authors. All rights reserved.
......@@ -91,7 +94,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, "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, "_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';
......@@ -146,6 +149,7 @@ var asm = (/** @suppress {uselessCode} */ function(global, env, buffer) {
var abortStackOverflow=env.abortStackOverflow;
var setTempRet0=env.setTempRet0;
var getTempRet0=env.getTempRet0;
var _ffunc1=env._ffunc1;
var tempFloat = 0.0;
// EMSCRIPTEN_START_FUNCS
......@@ -185,6 +189,7 @@ function setThrew(threw, value) {
function _kfunc1() {
var label = 0, sp = 0;
sp = STACKTOP;
_ffunc1();
return 12;
}
function runPostSets() {
......
......@@ -1533,7 +1533,7 @@ Module["preloadedAudios"] = {}; // maps url to audio data
if (!Module['dynamicLibraries']) Module['dynamicLibraries'] = [];
Module['dynamicLibraries'] = ["libk_so.js"].concat(Module['dynamicLibraries']);
Module['dynamicLibraries'] = ["libk_so.js","libf_so.js"].concat(Module['dynamicLibraries']);
addOnPreRun(function() {
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