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
4 changes: 3 additions & 1 deletion system/lib/libc/musl/src/errno/__strerror.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
* with these messages, and then to define a lookup table translating
* error codes to offsets of corresponding fields in the structure. */
#if defined(__EMSCRIPTEN__)
// This is intended to match the errno in llvm-libc.
/* Error handling is introduced to match the behavior in llvm-libc.
* When invalid errno is specified, Unknown error: errno_code is emitted.
*/
E(0, "Success")
#else
E(0, "No error information")
Expand Down
8 changes: 6 additions & 2 deletions system/lib/libc/musl/src/errno/strerror.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,19 @@ char *__strerror_l(int e, locale_t loc)
if (e==EDQUOT) e=0;
else if (e==EDQUOT_ORIG) e=EDQUOT;
#endif
if (e >= sizeof errmsgidx / sizeof *errmsgidx) e = 0;
s = (char *)&errmsgstr + errmsgidx[e];
#ifdef __EMSCRIPTEN__
if (e < 0 || e >= sizeof errmsgidx / sizeof *errmsgidx || (e != 0 && !errmsgidx[e])) {
return "Unknown error";
}
s = (char *)&errmsgstr + errmsgidx[e];
// strerror is a (debug) dependency of many emscripten syscalls which mean it
// must be excluded from LTO, along with all of its dependencies.
// In order to limit the transitive dependencies we disable localization of
// rrno messages here.
return (char *)s;
#else
if (e >= sizeof errmsgidx / sizeof *errmsgidx) e = 0;
s = (char *)&errmsgstr + errmsgidx[e];
return (char *)LCTRANS(s, LC_MESSAGES, loc);
#endif
}
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_except.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 23325,
"a.out.js.gz": 9128,
"a.out.nodebug.wasm": 171265,
"a.out.nodebug.wasm.gz": 57337,
"total": 194590,
"total_gz": 66465,
"a.out.nodebug.wasm": 171311,
"a.out.nodebug.wasm.gz": 57348,
"total": 194636,
"total_gz": 66476,
"sent": [
"__cxa_begin_catch",
"__cxa_end_catch",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_except_wasm.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 19486,
"a.out.js.gz": 8077,
"a.out.nodebug.wasm": 144620,
"a.out.nodebug.wasm.gz": 54891,
"total": 164106,
"total_gz": 62968,
"a.out.nodebug.wasm": 144667,
"a.out.nodebug.wasm.gz": 54907,
"total": 164153,
"total_gz": 62984,
"sent": [
"_abort_js",
"_tzset_js",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_except_wasm_legacy.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 19555,
"a.out.js.gz": 8099,
"a.out.nodebug.wasm": 142209,
"a.out.nodebug.wasm.gz": 54350,
"total": 161764,
"total_gz": 62449,
"a.out.nodebug.wasm": 142256,
"a.out.nodebug.wasm.gz": 54366,
"total": 161811,
"total_gz": 62465,
"sent": [
"_abort_js",
"_tzset_js",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_mangle.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 23375,
"a.out.js.gz": 9148,
"a.out.nodebug.wasm": 235299,
"a.out.nodebug.wasm.gz": 78928,
"total": 258674,
"total_gz": 88076,
"a.out.nodebug.wasm": 235343,
"a.out.nodebug.wasm.gz": 78952,
"total": 258718,
"total_gz": 88100,
"sent": [
"__cxa_begin_catch",
"__cxa_end_catch",
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_hello_O0.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.out.js": 24194,
"a.out.js.gz": 8694,
"a.out.nodebug.wasm": 15117,
"a.out.nodebug.wasm.gz": 7456,
"total": 39311,
"total_gz": 16150,
"a.out.nodebug.wasm": 15168,
"a.out.nodebug.wasm.gz": 7488,
"total": 39362,
"total_gz": 16182,
"sent": [
"fd_write"
],
Expand Down
4 changes: 2 additions & 2 deletions test/codesize/test_codesize_hello_dylink_all.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"a.out.js": 245483,
"a.out.nodebug.wasm": 574056,
"total": 819539,
"a.out.nodebug.wasm": 573907,
Copy link
Collaborator

Choose a reason for hiding this comment

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

How did this one get smaller?? Strange.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

possibly heavy optimization takes the return "Unknown error" branch and avoids the more complicated
s = (char *)&errmsgstr + errmsgidx[e];?

"total": 819390,
"sent": [
"IMG_Init",
"IMG_Load",
Expand Down
12 changes: 6 additions & 6 deletions test/codesize/test_unoptimized_code_size.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"hello_world.js": 56928,
"hello_world.js.gz": 17700,
"hello_world.wasm": 15117,
"hello_world.wasm.gz": 7456,
"hello_world.wasm": 15168,
"hello_world.wasm.gz": 7488,
"no_asserts.js": 26632,
"no_asserts.js.gz": 8884,
"no_asserts.wasm": 12217,
"no_asserts.wasm.gz": 6015,
"strict.js": 54943,
"strict.js.gz": 17045,
"strict.wasm": 15117,
"strict.wasm.gz": 7451,
"total": 180954,
"total_gz": 64551
"strict.wasm": 15168,
"strict.wasm.gz": 7482,
"total": 181056,
"total_gz": 64614
}
3 changes: 3 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -13124,6 +13124,9 @@ def test_wasmfs_before_preload(self):
def test_hello_world_above_2gb(self):
self.do_run_in_out_file_test('hello_world.c', cflags=['-sGLOBAL_BASE=2GB', '-sINITIAL_MEMORY=3GB'])

def test_unistd_strerror(self):
self.do_run_in_out_file_test('unistd/strerror.c')

def test_hello_function(self):
# hello_function.cpp is referenced/used in the docs. This test ensures that it
# at least compiles.
Expand Down
13 changes: 13 additions & 0 deletions test/unistd/strerror.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright 2025 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.
*/

#include <stdio.h>
#include <string.h>

int main() {
printf("errno: %s\n", strerror(-1));
}
1 change: 1 addition & 0 deletions test/unistd/strerror.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
errno: Unknown error