Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,10 @@ def get_last_setting_change(setting):
if 'WARN_ON_UNDEFINED_SYMBOLS=0' in settings_changes:
shared.Settings.ERROR_ON_UNDEFINED_SYMBOLS = 0

if shared.Settings.MINIMAL_RUNTIME or 'MINIMAL_RUNTIME=1' in settings_changes or 'MINIMAL_RUNTIME=2' in settings_changes:
# Remove the default exported functions 'malloc', 'free', etc. those should only be linked in if used
shared.Settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about erroring if DEFAULT_LIBRARY_FUNCS_TO_INCLUDE is in settings_changes? (That is, error if the user tries to add stuff which are otherwise removed silently here.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intent is to enable user to pass stuff explicitly from command line. I.e. if user wants to do -s DEFAULT_LIBRARY_FUNCS_TO_INCLUDE =[malloc] in MINIMAL_RUNTIME, then we should include malloc.


# Set ASM_JS default here so that we can override it from the command line.
shared.Settings.ASM_JS = 1 if options.opt_level > 0 else 2

Expand Down Expand Up @@ -1249,10 +1253,6 @@ def is_supported_link_flag(f):

link_flags = [f for f in link_flags if is_supported_link_flag(f[1])]

if shared.Settings.MINIMAL_RUNTIME:
# Remove the default exported functions 'memcpy', 'memset', 'malloc', 'free', etc. - those should only be linked in if used
shared.Settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE = []

if shared.Settings.STACK_OVERFLOW_CHECK:
if shared.Settings.MINIMAL_RUNTIME:
shared.Settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$abortStackOverflow']
Expand Down
2 changes: 2 additions & 0 deletions src/Fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,9 @@ function __emscripten_fetch_xhr(fetch, onsuccess, onerror, onprogress, onreadyst
xhr.open(requestMethod, url_, !fetchAttrSynchronous, userNameStr, passwordStr);
if (!fetchAttrSynchronous) xhr.timeout = timeoutMsecs; // XHR timeout field is only accessible in async XHRs, and must be set after .open() but before .send().
xhr.url_ = url_; // Save the url for debugging purposes (and for comparing to the responseURL that server side advertised)
#if ASSERTIONS
assert(!fetchAttrStreamData, 'streaming uses moz-chunked-arraybuffer which is no longer supported; TODO: rewrite using fetch()');
#endif
xhr.responseType = 'arraybuffer';

if (overriddenMimeType) {
Expand Down
14 changes: 7 additions & 7 deletions src/deps_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@
"sleep": ["usleep"],
"recv": ["htons"],
"send": ["htons"],
"ctime": ["_get_tzname", "_get_daylight", "_get_timezone"],
"ctime_r": ["_get_tzname", "_get_daylight", "_get_timezone"],
"localtime": ["_get_tzname", "_get_daylight", "_get_timezone"],
"localtime_r": ["_get_tzname", "_get_daylight", "_get_timezone"],
"mktime": ["_get_tzname", "_get_daylight", "_get_timezone"],
"timegm": ["_get_tzname", "_get_daylight", "_get_timezone"],
"tzset": ["_get_tzname", "_get_daylight", "_get_timezone"],
"ctime": ["_get_tzname", "_get_daylight", "_get_timezone", "malloc"],
"ctime_r": ["_get_tzname", "_get_daylight", "_get_timezone", "malloc"],
"localtime": ["_get_tzname", "_get_daylight", "_get_timezone", "malloc"],
"localtime_r": ["_get_tzname", "_get_daylight", "_get_timezone", "malloc"],
"mktime": ["_get_tzname", "_get_daylight", "_get_timezone", "malloc"],
"timegm": ["_get_tzname", "_get_daylight", "_get_timezone", "malloc"],
"tzset": ["_get_tzname", "_get_daylight", "_get_timezone", "malloc"],
"emscripten_set_canvas_element_size_calling_thread": ["emscripten_async_queue_on_thread_"],
"emscripten_webgl_destroy_context": ["emscripten_webgl_make_context_current", "emscripten_webgl_get_current_context"],
"emscripten_webgl_create_context": ["malloc", "free"],
Expand Down
44 changes: 34 additions & 10 deletions src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ LibraryManager.library = {
},

emscripten_get_heap_size: function() {
return HEAP8.length;
return HEAPU8.length;
},

emscripten_get_sbrk_ptr__asm: true,
Expand Down Expand Up @@ -703,7 +703,7 @@ LibraryManager.library = {
_exit(-1234);
},

#if MINIMAL_RUNTIME
#if MINIMAL_RUNTIME && !EXIT_RUNTIME
atexit: function(){},
__cxa_atexit: function(){},
__cxa_thread_atexit: function(){},
Expand Down Expand Up @@ -746,7 +746,7 @@ LibraryManager.library = {
// to limitations in the system libraries (we can't easily add a global
// ctor to create the environment without it always being linked in with
// libc).
__buildEnvironment__deps: ['$ENV'],
__buildEnvironment__deps: ['$ENV', '_getExecutableName'],
__buildEnvironment: function(environ) {
// WARNING: Arbitrary limit!
var MAX_ENV_VALUES = 64;
Expand All @@ -765,7 +765,7 @@ LibraryManager.library = {
ENV['HOME'] = '/home/web_user';
// Browser language detection #8751
ENV['LANG'] = ((typeof navigator === 'object' && navigator.languages && navigator.languages[0]) || 'C').replace('-', '_') + '.UTF-8';
ENV['_'] = thisProgram;
ENV['_'] = __getExecutableName();
// Allocate memory.
#if !MINIMAL_RUNTIME // TODO: environment support in MINIMAL_RUNTIME
poolPtr = getMemory(TOTAL_ENV_SIZE);
Expand Down Expand Up @@ -1844,12 +1844,12 @@ LibraryManager.library = {
}
},

dladdr__deps: ['$stringToNewUTF8'],
dladdr__deps: ['$stringToNewUTF8', '_getExecutableName'],
dladdr__proxy: 'sync',
dladdr__sig: 'iii',
dladdr: function(addr, info) {
// report all function pointers as coming from this program itself XXX not really correct in any way
var fname = stringToNewUTF8(thisProgram || './this.program'); // XXX leak
var fname = stringToNewUTF8(__getExecutableName()); // XXX leak
{{{ makeSetValue('info', 0, 'fname', 'i32') }}};
{{{ makeSetValue('info', Runtime.QUANTUM_SIZE, '0', 'i32') }}};
{{{ makeSetValue('info', Runtime.QUANTUM_SIZE*2, '0', 'i32') }}};
Expand Down Expand Up @@ -2068,6 +2068,9 @@ LibraryManager.library = {
// Note: glibc has one fewer underscore for all of these. Also used in other related functions (timegm)
tzset__proxy: 'sync',
tzset__sig: 'v',
#if MINIMAL_RUNTIME
tzset__deps: ['$allocateUTF8'],
#endif
tzset: function() {
// TODO: Use (malleable) environment variables instead of system settings.
if (_tzset.called) return;
Expand All @@ -2091,8 +2094,8 @@ LibraryManager.library = {
};
var winterName = extractZone(winter);
var summerName = extractZone(summer);
var winterNamePtr = allocate(intArrayFromString(winterName), 'i8', ALLOC_NORMAL);
var summerNamePtr = allocate(intArrayFromString(summerName), 'i8', ALLOC_NORMAL);
var winterNamePtr = allocateUTF8(winterName);
var summerNamePtr = allocateUTF8(summerName);
if (summer.getTimezoneOffset() < winter.getTimezoneOffset()) {
// Northern hemisphere
{{{ makeSetValue('__get_tzname()', '0', 'winterNamePtr', 'i32') }}};
Expand Down Expand Up @@ -2158,7 +2161,11 @@ LibraryManager.library = {

// Note: this is not used in STANDALONE_WASM mode, because it is more
// compact to do it in JS.
strftime__deps: ['_isLeapYear', '_arraySum', '_addDays', '_MONTH_DAYS_REGULAR', '_MONTH_DAYS_LEAP'],
strftime__deps: ['_isLeapYear', '_arraySum', '_addDays', '_MONTH_DAYS_REGULAR', '_MONTH_DAYS_LEAP'
#if MINIMAL_RUNTIME
, '$intArrayFromString', '$writeArrayToMemory'
#endif
],
strftime: function(s, maxsize, format, tm) {
// size_t strftime(char *restrict s, size_t maxsize, const char *restrict format, const struct tm *restrict timeptr);
// http://pubs.opengroup.org/onlinepubs/009695399/functions/strftime.html
Expand Down Expand Up @@ -2481,7 +2488,11 @@ LibraryManager.library = {
return _strftime(s, maxsize, format, tm); // no locale support yet
},

strptime__deps: ['_isLeapYear', '_arraySum', '_addDays', '_MONTH_DAYS_REGULAR', '_MONTH_DAYS_LEAP'],
strptime__deps: ['_isLeapYear', '_arraySum', '_addDays', '_MONTH_DAYS_REGULAR', '_MONTH_DAYS_LEAP'
#if MINIMAL_RUNTIME
, '$intArrayFromString'
#endif
],
strptime: function(buf, format, tm) {
// char *strptime(const char *restrict buf, const char *restrict format, struct tm *restrict tm);
// http://pubs.opengroup.org/onlinepubs/009695399/functions/strptime.html
Expand Down Expand Up @@ -5149,6 +5160,19 @@ LibraryManager.library = {
__handle_stack_overflow: function() {
abort('stack overflow')
},

_getExecutableName: function() {
#if MINIMAL_RUNTIME // MINIMAL_RUNTIME does not have a global runtime variable thisProgram
#if ENVIRONMENT_MAY_BE_NODE
if (ENVIRONMENT_IS_NODE && process['argv'].length > 1) {
return process['argv'][1].replace(/\\/g, '/');
}
#endif
return "./this.program";
#else
return thisProgram || './this.program';
#endif
},
};

function autoAddDeps(object, name) {
Expand Down
14 changes: 13 additions & 1 deletion src/library_formatString.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ mergeInto(LibraryManager.library, {
// Returns the resulting string string as a character array.
_formatString__deps: ['_reallyNegative'],
_formatString: function(format, varargs) {
#if ASSERTIONS
assert((varargs & 3) === 0);
#endif
var textIndex = format;
var argIndex = varargs;
// This must be called before reading a double or i64 vararg. It will bump the pointer properly.
Expand All @@ -19,11 +21,15 @@ mergeInto(LibraryManager.library, {
if (type === 'double' || type === 'i64') {
// move so the load is aligned
if (ptr & 7) {
#if ASSERTIONS
assert((ptr & 7) === 4);
#endif
ptr += 4;
}
} else {
#if ASSERTIONS
assert((ptr & 3) === 0);
#endif
}
return ptr;
}
Expand All @@ -40,7 +46,9 @@ mergeInto(LibraryManager.library, {
{{{ makeGetValue('argIndex', 4, 'i32', undefined, undefined, true, 4) }}}];
argIndex += 8;
} else {
#if ASSERTIONS
assert((argIndex & 3) === 0);
#endif
type = 'i32'; // varargs are always i32, i64, or double
ret = {{{ makeGetValue('argIndex', 0, 'i32', undefined, undefined, true) }}};
argIndex += 4;
Expand Down Expand Up @@ -418,7 +426,11 @@ mergeInto(LibraryManager.library, {
},

// printf/puts implementations for when musl is not pulled in - very partial. useful for tests, and when bootstrapping structInfo
printf__deps: ['_formatString'],
printf__deps: ['_formatString'
#if MINIMAL_RUNTIME
, '$intArrayToString'
#endif
],
printf: function(format, varargs) {
// int printf(const char *restrict format, ...);
// http://pubs.opengroup.org/onlinepubs/000095399/functions/printf.html
Expand Down
10 changes: 5 additions & 5 deletions src/library_html5.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var LibraryJSEvents = {
#endif
},

#if !MINIMAL_RUNTIME // In minimal runtime, there is no concept of the page running vs being closed, and hence __ATEXIT__ is not present
#if !MINIMAL_RUNTIME || EXIT_RUNTIME // In minimal runtime, there is no concept of the page running vs being closed, and hence __ATEXIT__ is not present
registerRemoveEventListeners: function() {
if (!JSEvents.removeEventListenersRegistered) {
__ATEXIT__.push(JSEvents.removeAllEventListeners);
Expand Down Expand Up @@ -175,7 +175,7 @@ var LibraryJSEvents = {
},

#if USE_PTHREADS
#if MINIMAL_RUNTIME
#if MINIMAL_RUNTIME && !WASM_BACKEND
queueEventHandlerOnThread_iiii__deps: ['$stackSave', '$stackAlloc', '$stackRestore'],
#endif
queueEventHandlerOnThread_iiii: function(targetThread, eventHandlerFunc, eventTypeId, eventData, userData) {
Expand Down Expand Up @@ -2824,7 +2824,7 @@ var LibraryJSEvents = {
},

emscripten_set_offscreencanvas_size_on_target_thread_js__deps: ['$stringToNewUTF8'
#if MINIMAL_RUNTIME
#if MINIMAL_RUNTIME && !WASM_BACKEND
, '$stackSave', '$stackAlloc', '$stackRestore'
#endif
],
Expand Down Expand Up @@ -2887,7 +2887,7 @@ var LibraryJSEvents = {
#endif

_set_canvas_element_size__deps: ['emscripten_set_canvas_element_size'
#if MINIMAL_RUNTIME
#if MINIMAL_RUNTIME && !WASM_BACKEND
, '$stackSave', '$stackAlloc', '$stackRestore'
#endif
],
Expand Down Expand Up @@ -2964,7 +2964,7 @@ var LibraryJSEvents = {

// JavaScript-friendly API, returns pair [width, height]
_get_canvas_element_size__deps: ['emscripten_get_canvas_element_size'
#if MINIMAL_RUNTIME
#if MINIMAL_RUNTIME && !WASM_BACKEND
, '$stackSave', '$stackAlloc', '$stackRestore'
#endif
],
Expand Down
4 changes: 4 additions & 0 deletions src/library_nodefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@ mergeInto(LibraryManager.library, {
},
convertNodeCode: function(e) {
var code = e.code;
#if ASSERTIONS
assert(code in ERRNO_CODES);
#endif
return ERRNO_CODES[code];
},
mount: function (mount) {
#if ASSERTIONS
assert(ENVIRONMENT_IS_NODE);
#endif
return NODEFS.createNode(null, '/', NODEFS.getMode(mount.opts.root), 0);
},
createNode: function (parent, name, mode, dev) {
Expand Down
16 changes: 4 additions & 12 deletions src/library_pthread_stub.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,23 +163,15 @@ var LibraryPThreadStub = {
emscripten_main_browser_thread_id: function() { return _pthread_self(); },

// When pthreads is not enabled, we can't use the Atomics futex api to do proper sleeps, so simulate a busy spin wait loop instead.
usleep__deps: ['emscripten_get_now'],
usleep: function(useconds) {
// int usleep(useconds_t useconds);
// http://pubs.opengroup.org/onlinepubs/000095399/functions/usleep.html
// We're single-threaded, so use a busy loop. Super-ugly.
var msec = useconds / 1000;
if ((ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) && self['performance'] && self['performance']['now']) {
var start = self['performance']['now']();
while (self['performance']['now']() - start < msec) {
// Do nothing.
}
} else {
var start = Date.now();
while (Date.now() - start < msec) {
// Do nothing.
}
var start = _emscripten_get_now();
while (_emscripten_get_now() - start < useconds / 1000) {
// Do nothing.
}
return 0;
},

nanosleep__deps: ['usleep', '__setErrNo'],
Expand Down
2 changes: 1 addition & 1 deletion src/library_stack_trace.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var LibraryStackTrace = {

$demangle__deps: [
#if MINIMAL_RUNTIME
#if MINIMAL_RUNTIME && !WASM_BACKEND
'$stackSave', '$stackAlloc', '$stackRestore'
#if ASSERTIONS
, '$warnOnce'
Expand Down
5 changes: 4 additions & 1 deletion src/library_strings.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#if MINIMAL_RUNTIME

#include "runtime_strings_extra.js"
#include "arrayUtils.js"

mergeInto(LibraryManager.library, {
$AsciiToString: AsciiToString,
Expand All @@ -15,7 +16,9 @@ mergeInto(LibraryManager.library, {
$allocateUTF8OnStack: allocateUTF8OnStack,
$writeStringToMemory: writeStringToMemory,
$writeArrayToMemory: writeArrayToMemory,
$writeAsciiToMemory: writeAsciiToMemory
$writeAsciiToMemory: writeAsciiToMemory,
$intArrayFromString: intArrayFromString,
$intArrayToString: intArrayToString
});

#endif
10 changes: 6 additions & 4 deletions src/library_syscall.js
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,9 @@ var SyscallsLibrary = {
__syscall121: function(which, varargs) { // setdomainname
return -{{{ cDefine('EPERM') }}};
},
#if MINIMAL_RUNTIME
__syscall122__deps: ['$writeAsciiToMemory'],
#endif
__syscall122: function(which, varargs) { // uname
var buf = SYSCALLS.get();
if (!buf) return -{{{ cDefine('EFAULT') }}}
Expand Down Expand Up @@ -1357,17 +1360,16 @@ var SyscallsLibrary = {
// This is the set of syscalls that use the FS etc. APIs. The rest is in
// library_wasi.js.

#if SYSCALLS_REQUIRE_FILESYSTEM == 0
#if SYSCALLS_REQUIRE_FILESYSTEM == 0 && (!MINIMAL_RUNTIME || EXIT_RUNTIME)
$flush_NO_FILESYSTEM: function() {
// flush anything remaining in the buffers during shutdown
var fflush = Module["_fflush"];
if (fflush) fflush(0);
if (typeof _fflush !== 'undefined') _fflush(0);
var buffers = SYSCALLS.buffers;
if (buffers[1].length) SYSCALLS.printChar(1, {{{ charCode("\n") }}});
if (buffers[2].length) SYSCALLS.printChar(2, {{{ charCode("\n") }}});
},
fd_write__deps: ['$flush_NO_FILESYSTEM'],
#if EXIT_RUNTIME == 1 && !MINIMAL_RUNTIME // MINIMAL_RUNTIME does not have __ATEXIT__ (so it does not get flushed stdout at program exit - programs in MINIMAL_RUNTIME do not have a concept of exiting)
#if EXIT_RUNTIME == 1
fd_write__postset: '__ATEXIT__.push(flush_NO_FILESYSTEM);',
#endif
#endif
Expand Down
10 changes: 7 additions & 3 deletions src/library_wasi.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var WasiLibrary = {
return _exit(code);
},

emscripten_get_environ__deps: ['$ENV'],
emscripten_get_environ__deps: ['$ENV', '_getExecutableName'],
emscripten_get_environ: function() {
if (!_emscripten_get_environ.strings) {
// Default values.
Expand All @@ -23,7 +23,7 @@ var WasiLibrary = {
'HOME': '/home/web_user',
// Browser language detection #8751
'LANG': ((typeof navigator === 'object' && navigator.languages && navigator.languages[0]) || 'C').replace('-', '_') + '.UTF-8',
'_': thisProgram
'_': __getExecutableName()
};
// Apply the user-provided values, if any.
for (var x in ENV) {
Expand All @@ -50,7 +50,11 @@ var WasiLibrary = {
return 0;
},

environ_get__deps: ['emscripten_get_environ'],
environ_get__deps: ['emscripten_get_environ'
#if MINIMAL_RUNTIME
, '$writeAsciiToMemory'
#endif
],
environ_get: function(__environ, environ_buf) {
var strings = _emscripten_get_environ();
var bufSize = 0;
Expand Down
Loading