diff --git a/src/lib/libdylink.js b/src/lib/libdylink.js index 84ebaf1e01374..6ecad00410d22 100644 --- a/src/lib/libdylink.js +++ b/src/lib/libdylink.js @@ -213,6 +213,8 @@ var LibraryDylink = { '__stop_em_asm', '__start_em_js', '__stop_em_js', + '__rodata_end', + '__rodata_start', ].includes(symName) || symName.startsWith('__em_js__') #if SPLIT_MODULE // Exports synthesized by wasm-split should be prefixed with '%' diff --git a/src/lib/libstrings.js b/src/lib/libstrings.js index 82152e2c89438..89d6d52595bee 100644 --- a/src/lib/libstrings.js +++ b/src/lib/libstrings.js @@ -92,6 +92,11 @@ addToLibrary({ #endif // TEXTDECODER == 2 }, +#if SHRINK_LEVEL == 0 + $UTF8ToString_cache__internal: true, + $UTF8ToString_cache: {}, +#endif + $UTF8ToString__docs: ` /** * Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the @@ -106,11 +111,19 @@ addToLibrary({ * @param {boolean=} ignoreNul - If true, the function will not stop on a NUL character. * @return {string} */`, + $UTF8ToString__deps: [ +#if SHRINK_LEVEL == 0 + '$UTF8ToString_cache', + // These deps don't currently work due to https://github.com/llvm/llvm-project/issues/180632 + //'__rodata_end', + //'__rodata_start', +#endif #if TEXTDECODER == 2 - $UTF8ToString__deps: ['$UTF8Decoder', '$findStringEnd'], + '$UTF8Decoder', '$findStringEnd', #else - $UTF8ToString__deps: ['$UTF8ArrayToString'], + '$UTF8ArrayToString', #endif + ], $UTF8ToString: (ptr, maxBytesToRead, ignoreNul) => { #if ASSERTIONS assert(typeof ptr == 'number', `UTF8ToString expects a number (got ${typeof ptr})`); @@ -118,13 +131,33 @@ addToLibrary({ #if CAN_ADDRESS_2GB ptr >>>= 0; #endif + +#if SHRINK_LEVEL == 0 + var useCache = !maxBytesToRead && ptr >= ___rodata_start && ptr < ___rodata_end; + if (useCache) { + var rtn = UTF8ToString_cache[ptr]; + if (rtn) { + return rtn; + } + } +#endif + #if TEXTDECODER == 2 if (!ptr) return ''; var end = findStringEnd(HEAPU8, ptr, maxBytesToRead, ignoreNul); - return UTF8Decoder.decode({{{ getUnsharedTextDecoderView('HEAPU8', 'ptr', 'end') }}}); + var rtn = UTF8Decoder.decode({{{ getUnsharedTextDecoderView('HEAPU8', 'ptr', 'end') }}}); #else - return ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead, ignoreNul) : ''; + var rtn = ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead, ignoreNul) : ''; #endif + +#if SHRINK_LEVEL == 0 + if (useCache) { + UTF8ToString_cache[ptr] = rtn; + } +#endif + + return rtn; + }, /** diff --git a/test/codesize/test_codesize_cxx_ctors1.json b/test/codesize/test_codesize_cxx_ctors1.json index e63fad8fa97f1..f4b49bb1450b4 100644 --- a/test/codesize/test_codesize_cxx_ctors1.json +++ b/test/codesize/test_codesize_cxx_ctors1.json @@ -1,10 +1,10 @@ { "a.out.js": 19555, "a.out.js.gz": 8102, - "a.out.nodebug.wasm": 132828, - "a.out.nodebug.wasm.gz": 49874, - "total": 152383, - "total_gz": 57976, + "a.out.nodebug.wasm": 132873, + "a.out.nodebug.wasm.gz": 49908, + "total": 152428, + "total_gz": 58010, "sent": [ "__cxa_throw", "_abort_js", @@ -31,6 +31,8 @@ ], "exports": [ "__indirect_function_table", + "__rodata_end", + "__rodata_start", "__wasm_call_ctors", "_emscripten_stack_alloc", "_emscripten_stack_restore", diff --git a/test/codesize/test_codesize_cxx_ctors2.json b/test/codesize/test_codesize_cxx_ctors2.json index 2d2575871e287..31ba1ecebb19a 100644 --- a/test/codesize/test_codesize_cxx_ctors2.json +++ b/test/codesize/test_codesize_cxx_ctors2.json @@ -1,10 +1,10 @@ { "a.out.js": 19532, "a.out.js.gz": 8087, - "a.out.nodebug.wasm": 132248, - "a.out.nodebug.wasm.gz": 49531, - "total": 151780, - "total_gz": 57618, + "a.out.nodebug.wasm": 132293, + "a.out.nodebug.wasm.gz": 49567, + "total": 151825, + "total_gz": 57654, "sent": [ "__cxa_throw", "_abort_js", @@ -28,6 +28,8 @@ ], "exports": [ "__indirect_function_table", + "__rodata_end", + "__rodata_start", "_emscripten_stack_alloc", "_emscripten_stack_restore", "emscripten_stack_get_current", diff --git a/test/codesize/test_codesize_cxx_except.json b/test/codesize/test_codesize_cxx_except.json index c3e7a0ff4dc6c..f523edba0d416 100644 --- a/test/codesize/test_codesize_cxx_except.json +++ b/test/codesize/test_codesize_cxx_except.json @@ -1,10 +1,10 @@ { "a.out.js": 23216, "a.out.js.gz": 9081, - "a.out.nodebug.wasm": 172758, - "a.out.nodebug.wasm.gz": 57395, - "total": 195974, - "total_gz": 66476, + "a.out.nodebug.wasm": 172803, + "a.out.nodebug.wasm.gz": 57433, + "total": 196019, + "total_gz": 66514, "sent": [ "__cxa_begin_catch", "__cxa_end_catch", @@ -91,6 +91,8 @@ "__cxa_get_exception_ptr", "__cxa_increment_exception_refcount", "__indirect_function_table", + "__rodata_end", + "__rodata_start", "__wasm_call_ctors", "_emscripten_stack_alloc", "_emscripten_stack_restore", diff --git a/test/codesize/test_codesize_cxx_except_wasm.json b/test/codesize/test_codesize_cxx_except_wasm.json index fcc8b1204617a..326dbe72f909d 100644 --- a/test/codesize/test_codesize_cxx_except_wasm.json +++ b/test/codesize/test_codesize_cxx_except_wasm.json @@ -1,10 +1,10 @@ { "a.out.js": 19366, "a.out.js.gz": 8022, - "a.out.nodebug.wasm": 148153, - "a.out.nodebug.wasm.gz": 55275, - "total": 167519, - "total_gz": 63297, + "a.out.nodebug.wasm": 148199, + "a.out.nodebug.wasm.gz": 55309, + "total": 167565, + "total_gz": 63331, "sent": [ "_abort_js", "_tzset_js", @@ -29,6 +29,8 @@ ], "exports": [ "__indirect_function_table", + "__rodata_end", + "__rodata_start", "__trap", "__wasm_call_ctors", "_emscripten_stack_alloc", diff --git a/test/codesize/test_codesize_cxx_except_wasm_legacy.json b/test/codesize/test_codesize_cxx_except_wasm_legacy.json index 2b80270d360e4..ae96f245087b9 100644 --- a/test/codesize/test_codesize_cxx_except_wasm_legacy.json +++ b/test/codesize/test_codesize_cxx_except_wasm_legacy.json @@ -1,10 +1,10 @@ { "a.out.js": 19440, "a.out.js.gz": 8042, - "a.out.nodebug.wasm": 145959, - "a.out.nodebug.wasm.gz": 54906, - "total": 165399, - "total_gz": 62948, + "a.out.nodebug.wasm": 146005, + "a.out.nodebug.wasm.gz": 54943, + "total": 165445, + "total_gz": 62985, "sent": [ "_abort_js", "_tzset_js", @@ -29,6 +29,8 @@ ], "exports": [ "__indirect_function_table", + "__rodata_end", + "__rodata_start", "__trap", "__wasm_call_ctors", "_emscripten_stack_alloc", diff --git a/test/codesize/test_codesize_cxx_mangle.json b/test/codesize/test_codesize_cxx_mangle.json index 5f386c71f840d..b8e9a4365633c 100644 --- a/test/codesize/test_codesize_cxx_mangle.json +++ b/test/codesize/test_codesize_cxx_mangle.json @@ -1,10 +1,10 @@ { "a.out.js": 23266, "a.out.js.gz": 9101, - "a.out.nodebug.wasm": 239192, - "a.out.nodebug.wasm.gz": 79781, - "total": 262458, - "total_gz": 88882, + "a.out.nodebug.wasm": 239237, + "a.out.nodebug.wasm.gz": 79811, + "total": 262503, + "total_gz": 88912, "sent": [ "__cxa_begin_catch", "__cxa_end_catch", @@ -92,6 +92,8 @@ "__cxa_get_exception_ptr", "__cxa_increment_exception_refcount", "__indirect_function_table", + "__rodata_end", + "__rodata_start", "__wasm_call_ctors", "_emscripten_stack_alloc", "_emscripten_stack_restore", diff --git a/test/codesize/test_codesize_cxx_noexcept.json b/test/codesize/test_codesize_cxx_noexcept.json index 310ac1a386de9..f6c222cfedfba 100644 --- a/test/codesize/test_codesize_cxx_noexcept.json +++ b/test/codesize/test_codesize_cxx_noexcept.json @@ -1,10 +1,10 @@ { "a.out.js": 19555, "a.out.js.gz": 8102, - "a.out.nodebug.wasm": 134835, - "a.out.nodebug.wasm.gz": 50701, - "total": 154390, - "total_gz": 58803, + "a.out.nodebug.wasm": 134880, + "a.out.nodebug.wasm.gz": 50737, + "total": 154435, + "total_gz": 58839, "sent": [ "__cxa_throw", "_abort_js", @@ -31,6 +31,8 @@ ], "exports": [ "__indirect_function_table", + "__rodata_end", + "__rodata_start", "__wasm_call_ctors", "_emscripten_stack_alloc", "_emscripten_stack_restore", diff --git a/test/codesize/test_codesize_cxx_wasmfs.json b/test/codesize/test_codesize_cxx_wasmfs.json index d9b9ec90b92c0..55fb01e54155a 100644 --- a/test/codesize/test_codesize_cxx_wasmfs.json +++ b/test/codesize/test_codesize_cxx_wasmfs.json @@ -1,10 +1,10 @@ { - "a.out.js": 7053, - "a.out.js.gz": 3325, - "a.out.nodebug.wasm": 172904, - "a.out.nodebug.wasm.gz": 63288, - "total": 179957, - "total_gz": 66613, + "a.out.js": 7198, + "a.out.js.gz": 3394, + "a.out.nodebug.wasm": 172949, + "a.out.nodebug.wasm.gz": 63318, + "total": 180147, + "total_gz": 66712, "sent": [ "__cxa_throw", "_abort_js", @@ -49,6 +49,8 @@ ], "exports": [ "__indirect_function_table", + "__rodata_end", + "__rodata_start", "__wasm_call_ctors", "_emscripten_stack_alloc", "_emscripten_stack_restore", diff --git a/test/codesize/test_codesize_file_preload.expected.js b/test/codesize/test_codesize_file_preload.expected.js index 089058d9e9f84..a56e34732be12 100644 --- a/test/codesize/test_codesize_file_preload.expected.js +++ b/test/codesize/test_codesize_file_preload.expected.js @@ -2982,6 +2982,8 @@ var FS = { } }; +var UTF8ToString_cache = {}; + /** * Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the * emscripten HEAP, returns a copy of that string as a Javascript String object. @@ -2994,7 +2996,20 @@ var FS = { * string will cut short at that byte index. * @param {boolean=} ignoreNul - If true, the function will not stop on a NUL character. * @return {string} - */ var UTF8ToString = (ptr, maxBytesToRead, ignoreNul) => ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead, ignoreNul) : ""; + */ var UTF8ToString = (ptr, maxBytesToRead, ignoreNul) => { + var useCache = !maxBytesToRead && ptr >= ___rodata_start && ptr < ___rodata_end; + if (useCache) { + var rtn = UTF8ToString_cache[ptr]; + if (rtn) { + return rtn; + } + } + var rtn = ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead, ignoreNul) : ""; + if (useCache) { + UTF8ToString_cache[ptr] = rtn; + } + return rtn; +}; var SYSCALLS = { calculateAt(dirfd, path, allowEmpty) { @@ -3155,12 +3170,14 @@ Module["FS_createLazyFile"] = FS_createLazyFile; // End JS library exports // end include: postlibrary.js // Imports from the Wasm binary. -var _main, memory, __indirect_function_table, wasmMemory; +var _main, memory, __indirect_function_table, ___rodata_start, ___rodata_end, wasmMemory; function assignWasmExports(wasmExports) { _main = Module["_main"] = wasmExports["d"]; memory = wasmMemory = wasmExports["b"]; __indirect_function_table = wasmExports["__indirect_function_table"]; + ___rodata_start = wasmExports["e"].value; + ___rodata_end = wasmExports["f"].value; } var wasmImports = { diff --git a/test/codesize/test_codesize_file_preload.json b/test/codesize/test_codesize_file_preload.json index 63eb5b217a6c2..7e67fb9c0e184 100644 --- a/test/codesize/test_codesize_file_preload.json +++ b/test/codesize/test_codesize_file_preload.json @@ -1,10 +1,10 @@ { "a.out.js": 22509, "a.out.js.gz": 9332, - "a.out.nodebug.wasm": 1681, - "a.out.nodebug.wasm.gz": 960, - "total": 24190, - "total_gz": 10292, + "a.out.nodebug.wasm": 1701, + "a.out.nodebug.wasm.gz": 973, + "total": 24210, + "total_gz": 10305, "sent": [ "a (fd_write)" ], @@ -14,7 +14,9 @@ "exports": [ "b (memory)", "c (__wasm_call_ctors)", - "d (main)" + "d (main)", + "e (__rodata_start)", + "f (__rodata_end)" ], "funcs": [ "$__emscripten_stdout_close", diff --git a/test/codesize/test_codesize_files_js_fs.json b/test/codesize/test_codesize_files_js_fs.json index 5f456e69a275d..b0ab5b4851e3e 100644 --- a/test/codesize/test_codesize_files_js_fs.json +++ b/test/codesize/test_codesize_files_js_fs.json @@ -1,10 +1,10 @@ { - "a.out.js": 18174, - "a.out.js.gz": 7430, - "a.out.nodebug.wasm": 381, - "a.out.nodebug.wasm.gz": 260, - "total": 18555, - "total_gz": 7690, + "a.out.js": 18289, + "a.out.js.gz": 7483, + "a.out.nodebug.wasm": 401, + "a.out.nodebug.wasm.gz": 271, + "total": 18690, + "total_gz": 7754, "sent": [ "a (fd_write)", "b (fd_read)", @@ -20,7 +20,9 @@ "exports": [ "e (memory)", "f (__wasm_call_ctors)", - "g (main)" + "g (main)", + "h (__rodata_start)", + "i (__rodata_end)" ], "funcs": [ "$__wasm_call_ctors", diff --git a/test/codesize/test_codesize_files_wasmfs.json b/test/codesize/test_codesize_files_wasmfs.json index c0a9f4d8de935..711f47b516e4e 100644 --- a/test/codesize/test_codesize_files_wasmfs.json +++ b/test/codesize/test_codesize_files_wasmfs.json @@ -1,10 +1,10 @@ { - "a.out.js": 5475, - "a.out.js.gz": 2578, - "a.out.nodebug.wasm": 58468, - "a.out.nodebug.wasm.gz": 18081, - "total": 63943, - "total_gz": 20659, + "a.out.js": 5594, + "a.out.js.gz": 2642, + "a.out.nodebug.wasm": 58488, + "a.out.nodebug.wasm.gz": 18096, + "total": 64082, + "total_gz": 20738, "sent": [ "a (emscripten_date_now)", "b (emscripten_err)", @@ -42,7 +42,9 @@ "exports": [ "p (memory)", "q (__wasm_call_ctors)", - "r (main)" + "r (main)", + "s (__rodata_start)", + "t (__rodata_end)" ], "funcs": [ "$__cxa_pure_virtual", diff --git a/test/codesize/test_codesize_hello_O0.json b/test/codesize/test_codesize_hello_O0.json index c88041660275d..7ec7f329343f9 100644 --- a/test/codesize/test_codesize_hello_O0.json +++ b/test/codesize/test_codesize_hello_O0.json @@ -1,10 +1,10 @@ { - "a.out.js": 24268, - "a.out.js.gz": 8718, - "a.out.nodebug.wasm": 15138, - "a.out.nodebug.wasm.gz": 7455, - "total": 39406, - "total_gz": 16173, + "a.out.js": 24436, + "a.out.js.gz": 8745, + "a.out.nodebug.wasm": 15184, + "a.out.nodebug.wasm.gz": 7478, + "total": 39620, + "total_gz": 16223, "sent": [ "fd_write" ], @@ -13,6 +13,8 @@ ], "exports": [ "__indirect_function_table", + "__rodata_end", + "__rodata_start", "__wasm_call_ctors", "_emscripten_stack_alloc", "_emscripten_stack_restore", diff --git a/test/codesize/test_codesize_hello_O1.json b/test/codesize/test_codesize_hello_O1.json index 9c4d7260067b2..9c64ba49b7915 100644 --- a/test/codesize/test_codesize_hello_O1.json +++ b/test/codesize/test_codesize_hello_O1.json @@ -1,10 +1,10 @@ { "a.out.js": 6350, "a.out.js.gz": 2462, - "a.out.nodebug.wasm": 2675, - "a.out.nodebug.wasm.gz": 1491, - "total": 9025, - "total_gz": 3953, + "a.out.nodebug.wasm": 2719, + "a.out.nodebug.wasm.gz": 1516, + "total": 9069, + "total_gz": 3978, "sent": [ "fd_write" ], @@ -13,6 +13,8 @@ ], "exports": [ "__indirect_function_table", + "__rodata_end", + "__rodata_start", "__wasm_call_ctors", "_emscripten_stack_alloc", "_emscripten_stack_restore", diff --git a/test/codesize/test_codesize_hello_O2.json b/test/codesize/test_codesize_hello_O2.json index c22ad426dd9a4..0e70d6dc00175 100644 --- a/test/codesize/test_codesize_hello_O2.json +++ b/test/codesize/test_codesize_hello_O2.json @@ -1,10 +1,10 @@ { "a.out.js": 4324, "a.out.js.gz": 2134, - "a.out.nodebug.wasm": 1927, - "a.out.nodebug.wasm.gz": 1138, - "total": 6251, - "total_gz": 3272, + "a.out.nodebug.wasm": 1971, + "a.out.nodebug.wasm.gz": 1164, + "total": 6295, + "total_gz": 3298, "sent": [ "fd_write" ], @@ -13,6 +13,8 @@ ], "exports": [ "__indirect_function_table", + "__rodata_end", + "__rodata_start", "__wasm_call_ctors", "_emscripten_stack_alloc", "_emscripten_stack_restore", diff --git a/test/codesize/test_codesize_hello_O3.json b/test/codesize/test_codesize_hello_O3.json index 29437d2ab4ab1..82e3d8a160817 100644 --- a/test/codesize/test_codesize_hello_O3.json +++ b/test/codesize/test_codesize_hello_O3.json @@ -1,10 +1,10 @@ { "a.out.js": 4266, "a.out.js.gz": 2093, - "a.out.nodebug.wasm": 1681, - "a.out.nodebug.wasm.gz": 960, - "total": 5947, - "total_gz": 3053, + "a.out.nodebug.wasm": 1701, + "a.out.nodebug.wasm.gz": 973, + "total": 5967, + "total_gz": 3066, "sent": [ "a (fd_write)" ], @@ -14,7 +14,9 @@ "exports": [ "b (memory)", "c (__wasm_call_ctors)", - "d (main)" + "d (main)", + "e (__rodata_start)", + "f (__rodata_end)" ], "funcs": [ "$__emscripten_stdout_close", diff --git a/test/codesize/test_codesize_hello_dylink.json b/test/codesize/test_codesize_hello_dylink.json index cbd43f6d97db7..3d29250b742ed 100644 --- a/test/codesize/test_codesize_hello_dylink.json +++ b/test/codesize/test_codesize_hello_dylink.json @@ -1,10 +1,10 @@ { - "a.out.js": 26596, - "a.out.js.gz": 11356, - "a.out.nodebug.wasm": 17730, - "a.out.nodebug.wasm.gz": 8957, - "total": 44326, - "total_gz": 20313, + "a.out.js": 26756, + "a.out.js.gz": 11420, + "a.out.nodebug.wasm": 17774, + "a.out.nodebug.wasm.gz": 8987, + "total": 44530, + "total_gz": 20407, "sent": [ "__syscall_stat64", "emscripten_resize_heap", @@ -22,6 +22,8 @@ "exports": [ "__heap_base", "__indirect_function_table", + "__rodata_end", + "__rodata_start", "__wasm_call_ctors", "_emscripten_find_dylib", "_emscripten_stack_alloc", diff --git a/test/codesize/test_codesize_hello_dylink_all.json b/test/codesize/test_codesize_hello_dylink_all.json index 905c54ed8db4b..efaade179962d 100644 --- a/test/codesize/test_codesize_hello_dylink_all.json +++ b/test/codesize/test_codesize_hello_dylink_all.json @@ -1,7 +1,7 @@ { - "a.out.js": 244700, - "a.out.nodebug.wasm": 577696, - "total": 822396, + "a.out.js": 244170, + "a.out.nodebug.wasm": 577743, + "total": 821913, "sent": [ "IMG_Init", "IMG_Load", @@ -1825,6 +1825,8 @@ "__pthread_detach", "__res_msend", "__res_state", + "__rodata_end", + "__rodata_start", "__set_temp_ret", "__sig_actions", "__sig_is_blocked", diff --git a/test/codesize/test_codesize_hello_single_file.json b/test/codesize/test_codesize_hello_single_file.json index 531826ef78b44..cf6d9e3f765be 100644 --- a/test/codesize/test_codesize_hello_single_file.json +++ b/test/codesize/test_codesize_hello_single_file.json @@ -1,6 +1,6 @@ { - "a.out.js": 5371, - "a.out.js.gz": 2984, + "a.out.js": 5392, + "a.out.js.gz": 2999, "sent": [ "a (fd_write)" ] diff --git a/test/codesize/test_codesize_hello_wasmfs.json b/test/codesize/test_codesize_hello_wasmfs.json index 29437d2ab4ab1..82e3d8a160817 100644 --- a/test/codesize/test_codesize_hello_wasmfs.json +++ b/test/codesize/test_codesize_hello_wasmfs.json @@ -1,10 +1,10 @@ { "a.out.js": 4266, "a.out.js.gz": 2093, - "a.out.nodebug.wasm": 1681, - "a.out.nodebug.wasm.gz": 960, - "total": 5947, - "total_gz": 3053, + "a.out.nodebug.wasm": 1701, + "a.out.nodebug.wasm.gz": 973, + "total": 5967, + "total_gz": 3066, "sent": [ "a (fd_write)" ], @@ -14,7 +14,9 @@ "exports": [ "b (memory)", "c (__wasm_call_ctors)", - "d (main)" + "d (main)", + "e (__rodata_start)", + "f (__rodata_end)" ], "funcs": [ "$__emscripten_stdout_close", diff --git a/test/codesize/test_codesize_libcxxabi_message_O3.json b/test/codesize/test_codesize_libcxxabi_message_O3.json index bb31d9d714f0f..0462d9656757f 100644 --- a/test/codesize/test_codesize_libcxxabi_message_O3.json +++ b/test/codesize/test_codesize_libcxxabi_message_O3.json @@ -1,16 +1,18 @@ { "a.out.js": 3528, "a.out.js.gz": 1668, - "a.out.nodebug.wasm": 89, - "a.out.nodebug.wasm.gz": 98, - "total": 3617, - "total_gz": 1766, + "a.out.nodebug.wasm": 110, + "a.out.nodebug.wasm.gz": 111, + "total": 3638, + "total_gz": 1779, "sent": [], "imports": [], "exports": [ "a (memory)", "b (__wasm_call_ctors)", - "c (main)" + "c (main)", + "d (__rodata_start)", + "e (__rodata_end)" ], "funcs": [ "$__wasm_call_ctors", diff --git a/test/codesize/test_codesize_mem_O3.json b/test/codesize/test_codesize_mem_O3.json index 9624d708670c0..897a2bf6250a4 100644 --- a/test/codesize/test_codesize_mem_O3.json +++ b/test/codesize/test_codesize_mem_O3.json @@ -1,10 +1,10 @@ { "a.out.js": 4355, "a.out.js.gz": 2096, - "a.out.nodebug.wasm": 5260, - "a.out.nodebug.wasm.gz": 2419, - "total": 9615, - "total_gz": 4515, + "a.out.nodebug.wasm": 5278, + "a.out.nodebug.wasm.gz": 2431, + "total": 9633, + "total_gz": 4527, "sent": [ "a (emscripten_resize_heap)" ], @@ -15,7 +15,9 @@ "b (memory)", "c (__wasm_call_ctors)", "d (__main_argc_argv)", - "e (_emscripten_stack_alloc)" + "e (_emscripten_stack_alloc)", + "f (__rodata_start)", + "g (__rodata_end)" ], "funcs": [ "$__wasm_call_ctors", diff --git a/test/codesize/test_codesize_mem_O3_grow.json b/test/codesize/test_codesize_mem_O3_grow.json index ad537a5e34f18..4af6d6daf7e1e 100644 --- a/test/codesize/test_codesize_mem_O3_grow.json +++ b/test/codesize/test_codesize_mem_O3_grow.json @@ -1,10 +1,10 @@ { "a.out.js": 4640, "a.out.js.gz": 2246, - "a.out.nodebug.wasm": 5261, - "a.out.nodebug.wasm.gz": 2419, - "total": 9901, - "total_gz": 4665, + "a.out.nodebug.wasm": 5279, + "a.out.nodebug.wasm.gz": 2431, + "total": 9919, + "total_gz": 4677, "sent": [ "a (emscripten_resize_heap)" ], @@ -15,7 +15,9 @@ "b (memory)", "c (__wasm_call_ctors)", "d (__main_argc_argv)", - "e (_emscripten_stack_alloc)" + "e (_emscripten_stack_alloc)", + "f (__rodata_start)", + "g (__rodata_end)" ], "funcs": [ "$__wasm_call_ctors", diff --git a/test/codesize/test_codesize_minimal_O0.expected.js b/test/codesize/test_codesize_minimal_O0.expected.js index 687f2a57de237..f12189e9f78af 100644 --- a/test/codesize/test_codesize_minimal_O0.expected.js +++ b/test/codesize/test_codesize_minimal_O0.expected.js @@ -1324,6 +1324,8 @@ var _emscripten_stack_get_current = makeInvalidEarlyAccess('_emscripten_stack_ge var memory = makeInvalidEarlyAccess('memory'); var _global_val = Module['_global_val'] = makeInvalidEarlyAccess('_global_val'); var __indirect_function_table = makeInvalidEarlyAccess('__indirect_function_table'); +var ___rodata_start = makeInvalidEarlyAccess('___rodata_start'); +var ___rodata_end = makeInvalidEarlyAccess('___rodata_end'); var wasmMemory = makeInvalidEarlyAccess('wasmMemory'); function assignWasmExports(wasmExports) { @@ -1339,6 +1341,8 @@ function assignWasmExports(wasmExports) { assert(typeof wasmExports['memory'] != 'undefined', 'missing Wasm export: memory'); assert(typeof wasmExports['global_val'] != 'undefined', 'missing Wasm export: global_val'); assert(typeof wasmExports['__indirect_function_table'] != 'undefined', 'missing Wasm export: __indirect_function_table'); + assert(typeof wasmExports['__rodata_start'] != 'undefined', 'missing Wasm export: __rodata_start'); + assert(typeof wasmExports['__rodata_end'] != 'undefined', 'missing Wasm export: __rodata_end'); _add = Module['_add'] = createExportWrapper('add', 2); _fflush = createExportWrapper('fflush', 1); _emscripten_stack_init = wasmExports['emscripten_stack_init']; @@ -1351,6 +1355,8 @@ function assignWasmExports(wasmExports) { memory = wasmMemory = wasmExports['memory']; _global_val = Module['_global_val'] = wasmExports['global_val'].value; __indirect_function_table = wasmExports['__indirect_function_table']; + ___rodata_start = wasmExports['__rodata_start'].value; + ___rodata_end = wasmExports['__rodata_end'].value; } var wasmImports = { diff --git a/test/codesize/test_codesize_minimal_O0.json b/test/codesize/test_codesize_minimal_O0.json index 64dd7944fbd5b..fdbdfa47c649e 100644 --- a/test/codesize/test_codesize_minimal_O0.json +++ b/test/codesize/test_codesize_minimal_O0.json @@ -1,14 +1,16 @@ { - "a.out.js": 19498, - "a.out.js.gz": 7013, - "a.out.nodebug.wasm": 1136, - "a.out.nodebug.wasm.gz": 656, - "total": 20634, - "total_gz": 7669, + "a.out.js": 19662, + "a.out.js.gz": 7034, + "a.out.nodebug.wasm": 1178, + "a.out.nodebug.wasm.gz": 678, + "total": 20840, + "total_gz": 7712, "sent": [], "imports": [], "exports": [ "__indirect_function_table", + "__rodata_end", + "__rodata_start", "__wasm_call_ctors", "_emscripten_stack_alloc", "_emscripten_stack_restore", diff --git a/test/codesize/test_codesize_minimal_O1.json b/test/codesize/test_codesize_minimal_O1.json index 1ee812afcbccf..beb68729157b3 100644 --- a/test/codesize/test_codesize_minimal_O1.json +++ b/test/codesize/test_codesize_minimal_O1.json @@ -1,14 +1,16 @@ { "a.out.js": 3066, "a.out.js.gz": 1302, - "a.out.nodebug.wasm": 449, - "a.out.nodebug.wasm.gz": 337, - "total": 3515, - "total_gz": 1639, + "a.out.nodebug.wasm": 491, + "a.out.nodebug.wasm.gz": 357, + "total": 3557, + "total_gz": 1659, "sent": [], "imports": [], "exports": [ "__indirect_function_table", + "__rodata_end", + "__rodata_start", "__wasm_call_ctors", "_emscripten_stack_alloc", "_emscripten_stack_restore", diff --git a/test/codesize/test_codesize_minimal_O2.json b/test/codesize/test_codesize_minimal_O2.json index ab0eb13fd26e5..42e0b7efb0e65 100644 --- a/test/codesize/test_codesize_minimal_O2.json +++ b/test/codesize/test_codesize_minimal_O2.json @@ -1,14 +1,16 @@ { "a.out.js": 2357, "a.out.js.gz": 1175, - "a.out.nodebug.wasm": 280, - "a.out.nodebug.wasm.gz": 226, - "total": 2637, - "total_gz": 1401, + "a.out.nodebug.wasm": 322, + "a.out.nodebug.wasm.gz": 249, + "total": 2679, + "total_gz": 1424, "sent": [], "imports": [], "exports": [ "__indirect_function_table", + "__rodata_end", + "__rodata_start", "__wasm_call_ctors", "_emscripten_stack_alloc", "_emscripten_stack_restore", diff --git a/test/codesize/test_codesize_minimal_O3.json b/test/codesize/test_codesize_minimal_O3.json index 2bc3eca6c115a..4690b491f8d7c 100644 --- a/test/codesize/test_codesize_minimal_O3.json +++ b/test/codesize/test_codesize_minimal_O3.json @@ -1,17 +1,19 @@ { "a.out.js": 2298, "a.out.js.gz": 1140, - "a.out.nodebug.wasm": 75, - "a.out.nodebug.wasm.gz": 87, - "total": 2373, - "total_gz": 1227, + "a.out.nodebug.wasm": 93, + "a.out.nodebug.wasm.gz": 98, + "total": 2391, + "total_gz": 1238, "sent": [], "imports": [], "exports": [ "a (memory)", "b (__wasm_call_ctors)", "c (add)", - "d (global_val)" + "d (global_val)", + "e (__rodata_start)", + "f (__rodata_end)" ], "funcs": [ "$__wasm_call_ctors", diff --git a/test/codesize/test_unoptimized_code_size.json b/test/codesize/test_unoptimized_code_size.json index 27350191fb96c..9ed68506da86e 100644 --- a/test/codesize/test_unoptimized_code_size.json +++ b/test/codesize/test_unoptimized_code_size.json @@ -1,16 +1,16 @@ { - "hello_world.js": 56965, - "hello_world.js.gz": 17729, - "hello_world.wasm": 15138, - "hello_world.wasm.gz": 7455, - "no_asserts.js": 26576, - "no_asserts.js.gz": 8881, - "no_asserts.wasm": 12187, - "no_asserts.wasm.gz": 5984, - "strict.js": 54881, - "strict.js.gz": 17045, - "strict.wasm": 15138, - "strict.wasm.gz": 7450, - "total": 180885, - "total_gz": 64544 + "hello_world.js": 57754, + "hello_world.js.gz": 17884, + "hello_world.wasm": 15184, + "hello_world.wasm.gz": 7478, + "no_asserts.js": 27075, + "no_asserts.js.gz": 9003, + "no_asserts.wasm": 12233, + "no_asserts.wasm.gz": 6011, + "strict.js": 55670, + "strict.js.gz": 17199, + "strict.wasm": 15184, + "strict.wasm.gz": 7473, + "total": 183100, + "total_gz": 65048 } diff --git a/test/core/test_dlfcn_self.exports b/test/core/test_dlfcn_self.exports index 0bb3488384e51..95087c6e25a12 100644 --- a/test/core/test_dlfcn_self.exports +++ b/test/core/test_dlfcn_self.exports @@ -7,6 +7,8 @@ __optpos __optreset __progname __progname_full +__rodata_end +__rodata_start __sig_actions __sig_pending __signgam diff --git a/tools/link.py b/tools/link.py index 03be0d432ed06..a08a5a29ac0b8 100644 --- a/tools/link.py +++ b/tools/link.py @@ -1257,6 +1257,10 @@ def limit_incoming_module_api(): if not settings.RELOCATABLE: settings.REQUIRED_EXPORTS += ['__stack_pointer'] + if settings.SHRINK_LEVEL == 0 and not settings.STANDALONE_WASM: + # Remove once we fix https://github.com/llvm/llvm-project/issues/180632 + settings.REQUIRED_EXPORTS += ['__rodata_start', '__rodata_end'] + if settings.MAIN_MODULE == 1 or settings.SIDE_MODULE == 1: settings.LINKABLE = 1