Skip to content

Commit 2d81085

Browse files
committed
Remove remaining uses of setErrNo and deprecate ERRNO_SUPPORT setting
Aside from the `setErrNo` library function `ERRNO_SUPPORT` also controlled the building the malloc and sbrk. However, just setting errno to ENOMEM didn't seem to have any effect on the code size for any of our micro benchmarks. This may be because LTO can completely eliminate the write to `errno` when there are no readers, or it could be that errno usage exists in in even the smallest program already so removing from malloc alone makes no difference.
1 parent 63036a7 commit 2d81085

18 files changed

+56
-50
lines changed

ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ See docs/process.md for more on how version tagging works.
2020

2121
3.1.52 (in development)
2222
-----------------------
23+
- The `ERRNO_SUPPORT` setting is now deprecated since the `setErrNo` function
24+
that it controls is no longer used by emscripten.
2325
- Building with `pthreads+EXPORT_ES6` will now emit the worker file as
2426
`NAME.worker.mjs` rather than `.js`. This is a necessary breaking change to
2527
resolve other `pthreads+EXPORT_ES6` issues in Node.js (because Node.js is

embuilder.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
'libc++-noexcept',
4747
'libal',
4848
'libdlmalloc',
49-
'libdlmalloc-noerrno',
5049
'libdlmalloc-tracing',
5150
'libdlmalloc-debug',
5251
'libembind',

site/source/docs/tools_reference/settings_reference.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,8 @@ options: 'quiet', 'warn', 'error'. If set to 'warn', Closure warnings are
315315
printed out to console. If set to 'error', Closure warnings are treated like
316316
errors, similar to -Werror compiler flag.
317317

318+
.. note:: This setting is deprecated
319+
318320
.. _ignore_closure_compiler_errors:
319321

320322
IGNORE_CLOSURE_COMPILER_ERRORS
@@ -1177,6 +1179,8 @@ EXTRA_EXPORTED_RUNTIME_METHODS
11771179

11781180
Deprecated, use EXPORTED_RUNTIME_METHODS instead.
11791181

1182+
.. note:: This setting is deprecated
1183+
11801184
.. _incoming_module_js_api:
11811185

11821186
INCOMING_MODULE_JS_API
@@ -2454,6 +2458,8 @@ POSIX errno variable. Setting this to 0 also requires using --closure
24542458
for effective code size optimizations to take place.
24552459
In MINIMAL_RUNTIME builds, this option defaults to 0.
24562460

2461+
.. note:: This setting is deprecated
2462+
24572463
.. _minimal_runtime:
24582464

24592465
MINIMAL_RUNTIME

src/library.js

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,8 @@ addToLibrary({
328328
updateMemoryViews();
329329
},
330330

331-
system__deps: ['$setErrNo'],
332-
system: (command) => {
331+
_emscripten_system__deps: ['$setErrNo'],
332+
_emscripten_system: (command) => {
333333
#if ENVIRONMENT_MAY_BE_NODE
334334
if (ENVIRONMENT_IS_NODE) {
335335
if (!command) return 1; // shell is available
@@ -368,8 +368,7 @@ addToLibrary({
368368
// http://pubs.opengroup.org/onlinepubs/000095399/functions/system.html
369369
// Can't call external programs.
370370
if (!command) return 0; // no shell available
371-
setErrNo({{{ cDefs.ENOSYS }}});
372-
return -1;
371+
return -{{{ cDefs.ENOSYS }}};
373372
},
374373

375374
// ==========================================================================
@@ -1521,20 +1520,6 @@ addToLibrary({
15211520
{{{ cDefs.EOWNERDEAD }}}: 'Previous owner died',
15221521
{{{ cDefs.ESTRPIPE }}}: 'Streams pipe error',
15231522
},
1524-
#if SUPPORT_ERRNO
1525-
$setErrNo__deps: ['__errno_location'],
1526-
$setErrNo: (value) => {
1527-
{{{makeSetValue("___errno_location()", 0, 'value', 'i32') }}};
1528-
return value;
1529-
},
1530-
#else
1531-
$setErrNo: (value) => {
1532-
#if ASSERTIONS
1533-
err('failed to set errno from JS');
1534-
#endif
1535-
return 0;
1536-
},
1537-
#endif
15381523

15391524
#if PROXY_POSIX_SOCKETS == 0
15401525
// ==========================================================================
@@ -2137,11 +2122,10 @@ addToLibrary({
21372122
// nonblocking
21382123
// ==========================================================================
21392124
#if SOCKET_WEBRTC
2140-
$Sockets__deps: ['$setErrNo',
2125+
$Sockets__deps: [
21412126
() => 'var SocketIO = ' + read('../third_party/socket.io.js') + ';\n',
2142-
() => 'var Peer = ' + read('../third_party/wrtcp.js') + ';\n'],
2143-
#else
2144-
$Sockets__deps: ['$setErrNo'],
2127+
() => 'var Peer = ' + read('../third_party/wrtcp.js') + ';\n'
2128+
],
21452129
#endif
21462130
$Sockets: {
21472131
BUFFER_SIZE: 10*1024, // initial size

src/library_legacy.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,19 @@ addToLibrary({
7575

7676
$allocateUTF8: '$stringToNewUTF8',
7777
$allocateUTF8OnStack: '$stringToUTF8OnStack',
78+
79+
#if SUPPORT_ERRNO
80+
$setErrNo__deps: ['__errno_location'],
81+
$setErrNo: (value) => {
82+
{{{makeSetValue("___errno_location()", 0, 'value', 'i32') }}};
83+
return value;
84+
},
85+
#else
86+
$setErrNo: (value) => {
87+
#if ASSERTIONS
88+
err('failed to set errno from JS');
89+
#endif
90+
return 0;
91+
},
92+
#endif
7893
});

src/library_sigs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ sigs = {
330330
_emscripten_receive_on_main_thread_js__sig: 'dipip',
331331
_emscripten_runtime_keepalive_clear__sig: 'v',
332332
_emscripten_set_offscreencanvas_size__sig: 'ipii',
333+
_emscripten_system__sig: 'ip',
333334
_emscripten_thread_exit_joinable__sig: 'vp',
334335
_emscripten_thread_mailbox_await__sig: 'vp',
335336
_emscripten_thread_set_strongref__sig: 'vp',
@@ -1540,7 +1541,6 @@ sigs = {
15401541
strftime_l__sig: 'pppppp',
15411542
strptime__sig: 'pppp',
15421543
strptime_l__sig: 'ppppp',
1543-
system__sig: 'ip',
15441544
uuid_clear__sig: 'vp',
15451545
uuid_compare__sig: 'ipp',
15461546
uuid_copy__sig: 'vpp',

src/settings.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ var USE_CLOSURE_COMPILER = false;
274274
// printed out to console. If set to 'error', Closure warnings are treated like
275275
// errors, similar to -Werror compiler flag.
276276
// [link]
277+
// [deprecated]
277278
var CLOSURE_WARNINGS = 'quiet';
278279

279280
// Ignore closure warnings and errors (like on duplicate definitions)
@@ -922,6 +923,7 @@ var ASYNCIFY_EXPORTS = [];
922923
var EXPORTED_RUNTIME_METHODS = [];
923924

924925
// Deprecated, use EXPORTED_RUNTIME_METHODS instead.
926+
// [deprecated]
925927
var EXTRA_EXPORTED_RUNTIME_METHODS = [];
926928

927929
// A list of incoming values on the Module object in JS that we care about. If
@@ -1846,6 +1848,7 @@ var MIN_NODE_VERSION = 160000;
18461848
// for effective code size optimizations to take place.
18471849
// In MINIMAL_RUNTIME builds, this option defaults to 0.
18481850
// [link]
1851+
// [deprecated]
18491852
var SUPPORT_ERRNO = true;
18501853

18511854
// If true, uses minimal sized runtime without POSIX features, Module,

system/lib/libc/emscripten_internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ void llvm_eh_typeid_for(void* exn);
148148

149149
uint32_t _emscripten_lookup_name(const char *name);
150150

151+
int _emscripten_system(const char *command);
152+
151153
#ifdef __cplusplus
152154
}
153155
#endif

system/lib/libc/sbrk.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
#define __NEED_max_align_t
1313
#endif
1414

15-
#ifndef EMSCRIPTEN_NO_ERRNO
1615
#include <errno.h>
17-
#endif
1816
#include <limits.h>
1917
#include <stddef.h>
2018
#include <stdint.h>
@@ -31,12 +29,6 @@ void emscripten_memprof_sbrk_grow(intptr_t old, intptr_t new);
3129

3230
#include <emscripten/heap.h>
3331

34-
#ifndef EMSCRIPTEN_NO_ERRNO
35-
#define SET_ERRNO() { errno = ENOMEM; }
36-
#else
37-
#define SET_ERRNO()
38-
#endif
39-
4032
extern size_t __heap_base;
4133

4234
static uintptr_t sbrk_val = (uintptr_t)&__heap_base;
@@ -79,7 +71,7 @@ void *sbrk(intptr_t increment_) {
7971
// increase the WebAssembly Memory size, and abort if that fails.
8072
if ((increment > 0 && new_brk <= old_brk)
8173
|| (new_brk > emscripten_get_heap_size() && !emscripten_resize_heap(new_brk))) {
82-
SET_ERRNO();
74+
errno = ENOMEM;
8375
return (void*)-1;
8476
}
8577
#ifdef __EMSCRIPTEN_SHARED_MEMORY__

system/lib/libc/system.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <unistd.h>
2+
#include <stdlib.h>
3+
#include <errno.h>
4+
#include "pthread_impl.h"
5+
#include "emscripten_internal.h"
6+
7+
int system(const char *cmd)
8+
{
9+
return __syscall_ret(_emscripten_system(cmd));
10+
}

test/minimal_webgl/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@ if (EMSCRIPTEN)
7171
# Optimization flag to optimize aggressively for size. (other options -Os, -O3, -O2, -O1, -O0)
7272
append_linker_flags("-Oz")
7373

74-
# Reduce code size: We do not need libc errno field support in our build output.
75-
append_linker_flags("-sSUPPORT_ERRNO=0")
76-
7774
# Reduce code size: We do not need native POSIX filesystem emulation support (Emscripten FS/MEMFS)
7875
append_linker_flags("-sFILESYSTEM=0")
7976
endif()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8422
1+
8420
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7251
1+
7250
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
57121
1+
57107

test/test_other.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10593,7 +10593,6 @@ def test_minimal_runtime_code_size(self, test_name, js, compare_js_output=False)
1059310593
'-sTEXTDECODER=2',
1059410594
'-sABORTING_MALLOC=0',
1059510595
'-sALLOW_MEMORY_GROWTH=0',
10596-
'-sSUPPORT_ERRNO=0',
1059710596
'-sDECLARE_ASM_MODULE_EXPORTS',
1059810597
'-sMALLOC=emmalloc',
1059910598
'-sGL_EMULATE_GLES_VERSION_STRING_FORMAT=0',
@@ -11918,7 +11917,7 @@ def test_default_to_cxx(self):
1191811917
'minimal': (['-sMINIMAL_RUNTIME', '-sSUPPORT_ERRNO'],),
1191911918
})
1192011919
def test_support_errno(self, args):
11921-
self.emcc_args += args + ['-sEXPORTED_FUNCTIONS=_main,___errno_location']
11920+
self.emcc_args += args + ['-sEXPORTED_FUNCTIONS=_main,___errno_location', '-Wno-deprecated']
1192211921

1192311922
self.do_other_test('test_support_errno.c')
1192411923
size_default = os.path.getsize('test_support_errno.js')

tools/link.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,9 @@ def phase_linker_setup(options, state, newargs):
729729

730730
final_suffix = get_file_suffix(target)
731731

732+
if 'SUPPORT_ERRNO' in user_settings:
733+
diagnostics.warning('deprecated', 'SUPPORT_ERRNO is deprecated since emscripten no longer uses the setErrNo library function')
734+
732735
if settings.EXTRA_EXPORTED_RUNTIME_METHODS:
733736
diagnostics.warning('deprecated', 'EXTRA_EXPORTED_RUNTIME_METHODS is deprecated, please use EXPORTED_RUNTIME_METHODS instead')
734737
settings.EXPORTED_RUNTIME_METHODS += settings.EXTRA_EXPORTED_RUNTIME_METHODS
@@ -879,7 +882,6 @@ def phase_linker_setup(options, state, newargs):
879882
# It is unlikely that developers targeting "native web" APIs with MINIMAL_RUNTIME need
880883
# errno support by default.
881884
if settings.MINIMAL_RUNTIME:
882-
default_setting('SUPPORT_ERRNO', 0)
883885
# Require explicit -lfoo.js flags to link with JS libraries.
884886
default_setting('AUTO_JS_LIBRARIES', 0)
885887
# When using MINIMAL_RUNTIME, symbols should only be exported if requested.

tools/maint/update_settings_docs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
'compile+link': 'Applicable during both linking and compilation',
5151
'compile': 'Only applicable during compilation',
5252
'experimental': 'This is an experimental setting',
53+
'deprecated': 'This setting is deprecated',
5354
}
5455

5556
output_file = path_from_root('site/source/docs/tools_reference/settings_reference.rst')

tools/system_libs.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,6 +1267,7 @@ def get_files(self):
12671267
'sigtimedwait.c',
12681268
'wasi-helpers.c',
12691269
'sbrk.c',
1270+
'system.c',
12701271
])
12711272

12721273
if settings.RELOCATABLE:
@@ -1666,7 +1667,6 @@ def __init__(self, **kwargs):
16661667
if self.malloc not in ('dlmalloc', 'emmalloc', 'emmalloc-debug', 'emmalloc-memvalidate', 'emmalloc-verbose', 'emmalloc-memvalidate-verbose', 'mimalloc', 'none'):
16671668
raise Exception('malloc must be one of "emmalloc[-debug|-memvalidate][-verbose]", "dlmalloc" or "none", see settings.js')
16681669

1669-
self.use_errno = kwargs.pop('use_errno')
16701670
self.is_tracing = kwargs.pop('is_tracing')
16711671
self.memvalidate = kwargs.pop('memvalidate')
16721672
self.verbose = kwargs.pop('verbose')
@@ -1691,8 +1691,6 @@ def get_cflags(self):
16911691
cflags += ['-UNDEBUG', '-DDLMALLOC_DEBUG']
16921692
else:
16931693
cflags += ['-DNDEBUG']
1694-
if not self.use_errno:
1695-
cflags += ['-DMALLOC_FAILURE_ACTION=', '-DEMSCRIPTEN_NO_ERRNO']
16961694
if self.is_tracing:
16971695
cflags += ['--tracing']
16981696
return cflags
@@ -1704,9 +1702,6 @@ def get_base_name(self):
17041702
name = super().get_base_name()
17051703
if self.is_debug and not self.memvalidate and not self.verbose:
17061704
name += '-debug'
1707-
if not self.use_errno:
1708-
# emmalloc doesn't actually use errno, but it's easier to build it again
1709-
name += '-noerrno'
17101705
if self.is_tracing:
17111706
name += '-tracing'
17121707
return name
@@ -1716,14 +1711,13 @@ def can_use(self):
17161711

17171712
@classmethod
17181713
def vary_on(cls):
1719-
return super().vary_on() + ['is_debug', 'use_errno', 'is_tracing', 'memvalidate', 'verbose']
1714+
return super().vary_on() + ['is_debug', 'is_tracing', 'memvalidate', 'verbose']
17201715

17211716
@classmethod
17221717
def get_default_variation(cls, **kwargs):
17231718
return super().get_default_variation(
17241719
malloc=settings.MALLOC,
17251720
is_debug=settings.ASSERTIONS >= 2,
1726-
use_errno=settings.SUPPORT_ERRNO,
17271721
is_tracing=settings.EMSCRIPTEN_TRACING,
17281722
memvalidate='memvalidate' in settings.MALLOC,
17291723
verbose='verbose' in settings.MALLOC,

0 commit comments

Comments
 (0)