Граф коммитов

8801 Коммитов

Автор SHA1 Сообщение Дата
Sam Clegg b42b59020e
Reduce minmal pthread dependencies (#13048)
Explictly depend on the internal thread functions that we need, and
allow unused ones to be DCE'd.

The biggest win here was removing the forced dependency on vsnprintf
which was being pulled in via
`emscripten_sync_run_in_main_thread_xprintf_varargs`.  Interestingly
this function doesn't seem to have any callers at all but I assume
it has some use so leaving it in the code for now.
2020-12-16 15:50:57 -08:00
Sam Clegg 097cfb8726
Add metadce test for minimal threaded program (#13047)
This sets up a baseline for the size of mutli-threads
program which we can then work to improve on and also
prevents regressions.
2020-12-15 10:09:58 -08:00
Sam Clegg 0f298808fc
Followup on proxy_main cleanup (#13034)
We had a single browser test set OFFSCREENCANVAS_SUPPORT=1 but
wasn't decorated with @requires_offscreen_canvas.

This test was relying on the bahaviour emscripten_proxy_main where
it would end up running main directly if pthread_create failed.
In thie case pthread_create fails because its tries to setup the
offscreen canvas.

This change avoids running that test when it offscree canvas is
not available and removes the fallback from emscripten_proxy_main.
2020-12-15 08:59:17 -08:00
Sam Clegg a2eb73f500
Fix null pointer read in realpath (#13032)
Calling realpath with SAFE_HEAP enabled was causing a read of
address zero because realpath calls sys_open with a third argument
and therefor without any varargs at all

Fixes: #12999
2020-12-14 11:32:47 -08:00
Aleksey Kliger (λgeek) 3a412796da
pthread_key_create: Allocate enough memory per entry (#13015)
When calling realloc, double the amount of allocated space.
2020-12-14 11:16:29 -08:00
Sam Clegg 8e11952d8e
Re-enable test (#13023) 2020-12-12 09:13:59 -08:00
Sam Clegg 0db0971de3
Remove bug workaround in async_longjmp.cpp (#13019)
Seems like this was fixed.
2020-12-11 18:32:27 -08:00
Sam Clegg 6069e85bca
Update posixtestsuite submodule (#13013)
This repo is now part of the emscripten org.
2020-12-11 13:24:29 -08:00
Sam Clegg b8328b9531
Temporarily disable test_metadce_hello_main_module_2 (#13010)
This test needs to be disaled so that a recent llvm change
can roll: https://reviews.llvm.org/D93066

It causes the following diff/failure:

```
AssertionError: Unexpected difference:
--- /b/s/w/ir/k/install/emscripten/tests/other/metadce/hello_world_O3_MAIN_MODULE_2.funcs
+++ /b/s/w/ir/k/install/emscripten/tests/other/metadce/hello_world_O3_MAIN_MODULE_2.funcs.new
@@ -4,7 +4,8 @@
 $__overflow
 $__stdio_write
 $__towrite
-$__wasm_apply_relocs
+$__wasm_apply_data_relocs
+$__wasm_apply_global_relocs
 $__wasm_call_ctors
 $dlmalloc
 $fwrite
```
2020-12-11 09:54:07 -08:00
Sam Clegg 3500c14562
Convert sample batch of browser tests to avoid REPORT_RESULT (#12977)
For simple browser tests we can just rely on the process
exit code being reported.  I've added a new btest_exit
method so that tests can opt into this new behavior.

This allows test code to be identical whether running
in the browser or outside.
2020-12-10 18:13:35 -08:00
Milek7 d42c1f98b7
Properly set addrlen in socket syscalls (#12997)
We also don't need to return JS object from __write_sockaddr, change it to returning just errno.

Fixes: #12996
2020-12-10 08:24:15 -08:00
juj fa37c450ee
Implement missing WebSockets functionality around socket protocols and extensions fields. Fix emscripten_websocket_delete() and emscripten_websocket_deinitialize() to work properly. (#12991) 2020-12-10 11:33:27 +02:00
Sam Clegg 6a71998ad4
Fix bad merge from #12967 (#12993) 2020-12-08 21:48:32 -08:00
Sam Clegg ceecfdc844
Fix warning in test_core tests and remove flags. NFC. (#12979) 2020-12-08 18:00:12 -08:00
Sam Clegg d01730f674
tests: avoid modifying global JS_ENGINES (#12967)
Modifying this global state seems wrong. Its probably safe because when
we run tests in parallel we use seperate processes, but it wouldn't work
if we switched to using threads.

Instead maintain test-local list of JS engines, and also a seperate list
of extra arguments for node and/v8.
2020-12-08 17:52:20 -08:00
Basil Fierz f263265074
[GLFW] Respect GLFW_NO_API flag (#12907)
In order to support the combined use of GLFW and WebGPU, GLFW
should not assign anything to the Emscripten modules context variable.
GLFW supports not creating any OpenGL context using the windows
attribute GLFW_CLIENT_API.
2020-12-07 14:04:14 -08:00
Sam Clegg 96b14d38f5
Move cubegeom tests to tests/third_party. NFC (#12982)
See #12980
2020-12-07 08:42:08 -08:00
Sam Clegg 3b672f5ca6
Honor test fixture compiler flags in browser tests. NFC (#12975)
Also fix all warnings resulting in `-Werror` being added.
2020-12-06 13:00:28 -08:00
Sam Clegg f388f6f1da
Prefer mb/gb when specifying memory settings. NFC. (#12965)
This didn't used to be supported by set_settings but it is
since #9243.
2020-12-04 13:07:09 -08:00
Sam Clegg 8e01def089
Check for file existence while parsing arguments (#12953)
This prevents the user from seeing backtraces like:

```
Traceback (most recent call last):
  File "./emcc.py", line 3310, in <module>
    sys.exit(main(sys.argv))
  File "./emcc.py", line 3303, in main
    ret = run(args)
  File "./emcc.py", line 916, in run
    options, settings_changes, user_js_defines, newargs = parse_args(newargs)
  File "./emcc.py", line 2446, in parse_args
    options.pre_js += open(consume_arg_file()).read() + '\n'
FileNotFoundError: [Errno 2] No such file or directory: 'foo.js'
```
2020-12-04 09:15:52 -08:00
Derek Schuff 28b1af7675
Disable testing with native exception handling (#12960)
V8 has begun work supporting the updated EH proposal, so it's no longer
compatible with LLVM. We can re-enable these tests on CI when V8 and
LLVM converge again.
2020-12-03 16:08:18 -08:00
Derek Schuff 3a302c15e4
Remove existing file in test_split_module before renaming over it (#12959)
This behavior seems to be failing tests on Windows.
2020-12-03 15:08:32 -08:00
Sam Clegg 11da087802
Use file_packager launcher script. NFC. (#12956)
Just like emcc and other tools we don't need to know internally
that this is python tool.  Plus using the launcher script means
we are testing whata our users will run.
2020-12-03 14:07:03 -08:00
Sam Clegg ed3976e2fa
Initial framework for SPLIT_MODULE option (#12939)
This option uses the new wasm-split tool in binaryen to generate profile
data and then split a module into a primary and secondary component
modules that can be linked together at runtime.
2020-12-03 10:21:30 -08:00
Sam Clegg 292a0ae285
Improve SYSCALL_DEBUG to include arguments (#12948) 2020-12-03 10:20:09 -08:00
Sam Clegg a44cb41913
Run dylink_test with MAIN_MODULE=2 where possible. NFC. (#12947)
Using this mode where we can speeds up the tests and makes
them easier to debug (because `MAIN_MODULE=1` produces
enormous wasm files).
2020-12-03 09:54:24 -08:00
Sam Clegg 00d2c8da1a
Integrate posixtestsuite for pthread testing (#12923)
This change adds posixtestsuite as a git submodule (in tests/third_party).

It also adds a new test suite that auto-populates based on the files
in `posixtestsuite/conformance/interfaces/pthread_*`

The submodule is optional in that the testsuite simply remains empty
if it is not found.
2020-12-02 22:25:23 -08:00
Sam Clegg 3c48bfee05
Build C11 thread API function in libpthread (#9243)
This change doesn't do much other than compile in the relevant parts of
musl.

For all functions exception thrd_detach we simply sompile the musl code.
For thrd_detach musl normally aliases this to pthread_detech in the
pthread_detach.c but we implement pthread_detech so add the alias there.

Fixes #9242
2020-12-02 18:15:51 -08:00
Sam Clegg e94989ddd5
Automatically report exit status in browser tests (#12928)
This means that tests don't necessarily need to call REPORT_RESULT.

I'm going to be taking advantage of this in #12923.

Also, don't initialize EXIT_STATUS to zero, but leave it as undefined.
It seems useful to be able to tell the diference between a program that
exits with a zero status and one that has not in fact exited yet.
2020-12-02 15:20:25 -08:00
Sam Clegg f28260bdc2
Handle exit() from pthread by posting exitProcess back to main thread (#12933) 2020-12-02 14:08:01 -08:00
Alon Zakai 68af137b91
Fix JS pthreads proxying + WASM_BIGINT (#12935)
The proxying of JS methods has no type info. It used to just use a JS
Number (a double) for everything, which works, except with BigInts
that's no longer enough.

We have to serialize type info in this case. This does a simple thing of
prefixing each argument with a non-zero value if it is a bigint. This is
not very compact, but is maybe good enough for now.

Also add a HEAP64 global array which is useful here (and will be
with wasm64 too).

Fixes #12079
2020-12-02 10:55:52 -08:00
Sam Clegg 002625bc26
Remove excess headers from report_result.h (#12929)
Because this header is force-included into all browser tests it should
be as un-intrusive as possible.

This also involved adding includes to a few tests that were indirectly
relying on these includes.  Better to IWYN.

Split out from #12928
2020-12-01 10:38:16 -08:00
Sam Clegg 8ac2436f43
Improve test_math. NFC. (#12922)
- Convert to C
- Split output into multiple lines.
- Add additional check for ldexp family.

See: #12893
2020-11-30 17:45:22 -08:00
Sam Clegg e15dc28746
Remove `with_report_result` helper from test code (#12906)
Rather than use `with_report_result` to create modified versions
of the original sources we can instead just compile them with
`compile_btest` which takes care of adding `report_result.c` and
including `report_result.h`.
2020-11-30 16:23:23 -08:00
Alon Zakai 6af99354de
Make ASYNCIFY_LAZY_LOAD_CODE automatically enable ASYNCIFY. (#12925) 2020-11-30 13:23:54 -08:00
Alon Zakai 16e93a3436
Ignore part of test_dwarf in unoptimized builds (#12924)
LLVM now emits larger code in unoptimized builds, with some extra local
assignments, instead of the simple pattern the test expected, which is to
set the local to the constant value and then do the call. Instead, it sets
the constants earlier on and then does some copying of those locals. I
can't see a simple way to parse that pattern in a useful way, so skip part
of the test in unoptimized builds. (If we think it's useful to test this kind of
thing, we'd need a different way entirely, probably, that isn't sensitive to
LLVM changes like this.)

Fixes #12903
2020-11-30 12:55:35 -08:00
Sam Clegg c178575c8b
tests: remove unused btest argument (#12912)
Technically this extra outfile argument had a single user
but it wasn't serving any useful purpose.
2020-11-30 12:29:47 -08:00
Sam Clegg 1216d230ea
Fix `-s` handling when the following argument is uppercase (#12913)
For example `-s -DFOO` should not be treated as a setting
because `-DFOO` is not a syntactically valid setting name.

Fixes: #12911
2020-11-30 11:33:17 -08:00
Sam Clegg 565634dcbf
Temporarily disable wasm0.test_dwarf. NFC. (#12904)
See #12903
2020-11-28 12:11:16 -08:00
Alon Zakai 251e842ebb
Ignore for now a mac test failure on test_dwarf which LLVM has broken (#12892) 2020-11-26 12:30:36 -08:00
Sam Clegg 5dc1e7c36e
Merge pthreads library into libc (#12880)
This is how musl does it and there is no reason we shouldn't
follow suite.
2020-11-25 18:57:34 -08:00
Sam Clegg 1765ab5dbc
Fix UAF in test_pthread_run_on_main_thread_flood (#12888)
This test was trying to free queued tasks before waiting on them which
is not (according to the header) allowed.

Fixes: #12885
2020-11-25 18:12:08 -08:00
Sam Clegg 8c885a45f3
Improve test_pthread_run_on_main_thread_flood. NFC. (#12886)
This test is failing intermittently but is currently going
unnoticed since we were not checking the thread exit code.

This change should make it easier for somebody to pick up
this bug and fix it.

See: #12885
2020-11-25 17:07:39 -08:00
Sam Clegg d5de3ab92f
Fix other.test_system_include_paths on windows (#12877)
Normalize paths before comparing them.
2020-11-24 13:16:08 -08:00
Sam Clegg 72b0caf40c
Paraeterize browser.test_html5 (#12851)
Also rename to test_html5_core so that running test_html5_core*
can be used to run all the variants without matching other tests
that exist with that prefix.
2020-11-24 08:42:15 -08:00
Sam Clegg d772153387
Run clang with `--sysroot`. NFC (#12863)
This means we don't need to pass -nostdsysteminc and also means we can
use shorter sysroot-relative paths when specifying include directories.

This is a step toawrds a real emscripten sysroot which is alos needed
for goma integration (IIUC).

See: #9353
2020-11-23 21:08:51 -08:00
Sam Clegg cb8027fac3
Use musl's pthhread_self.c. NFC. (#12856)
This change make emscripten more like other platorms in that
`__pthread_self` is implementd in the header file with inline asm and
the public `pthread_self` function comes from pthread_self.c

Previously we had it kind of backwards where the low level
`__pthread_self` was calling into the higher level `pthread_self`.

This is also the first use of inline asm we have in emscripten
and its good to know that it works.
2020-11-22 17:38:03 -08:00
Sam Clegg 923ea43df4
Add simple syslog test. (#12846)
This doesn't actaully work right now because musl's syslog
depends on all kinds of things like sockets and being
able to open "/dev/console".

So this is really just a compile and link test.

The indirect dependency on malloc comes from that fact
that it calls gmtime_r which can allocate in JS.
2020-11-21 18:24:35 -08:00
Sam Clegg 3ff744bca8
Improve test_extern_weak. NFC. (#12835)
Split the test into two, but leave the dynamic version
disabled until we can fix #12819

Also, add weak data symbols to the test.
2020-11-19 19:16:44 -08:00
Sam Clegg b2f1f607b5
Limit line length of JS ouptut in test code (#12823)
When minified JS tests fail the resulting error messages from node
normally contain the entire program (since its all on the same line).
This didn't used to be the case with older versions of node IIRC.

This change used the exiting `limit_size` function when displaying JS
output and also limits the size of any give line to avoid flodding the
terminal with a million chars on a single line.

If folks find this annoying, or were relying on this output when running
tests we add options.  For example we could limit this behaviour to only
apply run running in a terminal.
2020-11-18 18:06:41 -08:00
Sam Clegg a597fba1eb
Remove more __asmjs__-only code. NFC. (#12822) 2020-11-18 14:38:19 -08:00
Sam Clegg 4a8b0c3169
Fix path to llvm-dwarfdump used in test code. NFC. (#12817)
Fixes: #12799
2020-11-18 12:09:26 -08:00
Sam Clegg 06692ff55a
Check full JS output for hello world (#12806)
For the smallest hello world test, don't just check the output size
but check the full JS output matches the expectations.
That means that any change that touches those core lines of output
will need to rebaseline this test.  However:

a) such changes deserve extra scrutiny
b) such changes should be few and far between
c) rebaselining is trivial (just run with EMTEST_REBASELINE=1)

Note that we do not compare the full wasm output since that is even
more fragile and can change with LLVM updates.
2020-11-18 11:40:25 -08:00
Sam Clegg d4b99512f3
Remove `no_wasm_backend` usage from test_core.py (#12807)
The only remaining usage is in test_browser.py.
2020-11-18 11:15:30 -08:00
Sam Clegg c2462cdb94
Create memory in wasm binaryn by default (#12790)
There are some cases where we want to create the memory in JS but for
most programs exporting the memory from wasm makes more sense and is
more compact and reliable.

The new EXTERNAL_MEMORY setting can be used to override this behaviour.
2020-11-17 19:06:01 -08:00
Sam Clegg 5b3cbfe20c
Move tests/cube2hash -> tests/third_party/cube2hash (#12797)
Also, update tools/add_license.py removing directories that
not longer exist.

See #12737
2020-11-17 10:51:03 -08:00
Sam Clegg 574bce3a92
Move pngtest to tests/third_party/libpng/ (#12798)
These two files come directly the libpng distribution and
so belong in third_party.  I removed the local mod we had
done in favor of checking the existing output of the
upstream test code.

Fixes: #12795
2020-11-17 08:11:41 -08:00
Sam Clegg 72f49adb9f
Paramaterize minimal runtime codesize test. NFC. (#12792)
This has several advantages:

1. Its easy to re-run just one of them when debugging.
2. Running all of them is way faster because the run in parallel
3. When they fail the name of the failing test gives more information
2020-11-17 08:11:12 -08:00
Wouter van Oortmerssen 528a6ab880
[WiP] Initial changes to support wasm64 in emcc (#12658) 2020-11-16 17:41:52 -08:00
Sam Clegg fa5530de31
Rebaseline test_minimal_runtime_code_size. NFC. (#12788)
These are call codesize wins!
2020-11-15 10:19:58 -08:00
Sam Clegg c92bbd565a
Remove references to __asmjs__ macro (#12775) 2020-11-13 13:48:37 -08:00
Sam Clegg dc4a8ef1b0
Fix test configurations used in test_minimal_runtime_hello_pthread (#12774)
I believe this tests is always supposed to run with
MINIMAL_RUNTIME.  Without this change the half of the
innter test runs just run with pthreads which is
redundant.
2020-11-13 12:49:02 -08:00
Sam Clegg a14e861db1
Enable WASM2JS + STANDALONE (#12766)
Now that wasm2js supports memories defined on the wasm side
this seems to just work.

See: https://github.com/WebAssembly/binaryen/pull/3323
2020-11-12 19:16:49 -08:00
Sam Clegg e771de2999
Rebaseline test_minimal_runtime_code_size test results. NFC (#12762)
This captures some minor code size win from (I belive)
https://github.com/WebAssembly/binaryen/pull/3323
2020-11-12 14:26:31 -08:00
Sam Clegg c3e788c8f9
Check full function name when reporting undefined library symbols. (#12747) 2020-11-11 16:28:52 -08:00
Sam Clegg 781b3fd0d0
Mark some slow tests. NFC. (#12761)
Most of these take well over 30 seconds on my 56 thread machine.
2020-11-11 14:43:12 -08:00
juj 50fc8c15be
Fix regression that broke calls to makeDynCall in JS library code. (#12732)
* Fix regression that broke calls to makeDynCall in JS library code. Old syntax is {{{ makeDynCall('sig') }}}(funcPtr, arg1, arg2);. New syntax is {{{ makeDynCall('sig', 'funcPtr') }}}(arg1, arg2). With this change, both old and new syntax work, with a compile time warning issued for old syntax to migrate to new one. Add ChangeLog entry about broken static dynCall invocation outside JS library files.

* Address review
2020-11-11 09:32:57 +02:00
Sam Clegg 412bf20477
Report undefined symbols when only producing a wasm file (#12729)
When building direclty to wasm (e.g. with `-o <out>.wasm`
or with `--oformat=wasm`) we were not reporting undefined
symbols since we were not running the js compiler at all.

Fixed: #12725
2020-11-09 21:53:21 -08:00
Sam Clegg 801e59e48e
Rebaseline test_minimal_runtime_code_size (#12735) 2020-11-09 11:07:35 -08:00
Sam Clegg af049b0dfa
Move cubescript test to third_party (#12738)
Also remove the copyright message that was added by mistake.

Fixes: #12737
2020-11-09 08:07:29 -08:00
Sam Clegg 13535ca57a
Split config file handling out of shared.py. NFC. (#12699)
Move config file handling into its own file.  Also, move a few small
utilities into `utils.py` to avoid circular dependencies.

For a while now shared.py has been way too big and this is step towards
breaking it up and breaking the existing circular dependencies between
python modules that use and also also used by shared.py (cache.py for
example).
2020-11-09 08:06:33 -08:00
juj 980c0771ac
Fix closure error messages (#12726)
* Fix Closure to print clear readable error messages, instead of a single wall of minified text.

* Fix --cpuprofiler and --memoryprofiler to work with --closure 1, and add testing for --cpuprofiler, --memoryprofiler and --threadprofiler with Closure.

* Flake

* Address review.

* Address review
2020-11-09 18:00:48 +02:00
Sam Clegg b2191bd675
Re-enable code size tests after wasm2js change (#12719)
This gets us some nice code size improvements.

See: https://github.com/WebAssembly/binaryen/pull/3325
2020-11-08 09:04:10 -08:00
Sam Clegg 96c6cb790b
Avoid temp files in compile-only mode (#12710)
In compile-only mode we can write all object files directly to their
final locations completely avoid the need for temp files or for
renaming. Also avoid the `.d` file modification that we had in there.

This is a really nice simplification that has become possible as we have
made the emscripten code more precise about exactly which mode it is
running in.

Fixes: #12709
2020-11-05 16:09:42 -08:00
Sam Clegg bb1f4b8bb3
Temporarily disable wasm2js code size test (#12715)
This is needed to allow a binaryen change to roll in
which gives a nice code size reduction:
 https://github.com/WebAssembly/binaryen/pull/3325

Also relax the pattern matching used in another test
to as not to be sensitive the this change.
2020-11-05 15:25:17 -08:00
Sam Clegg 8edff9b6fc
Fix parsing of JS library pre-processor directives (#12702)
Because we were only checking for `#if` at the start of the
line we were accidenatlly also accepting `#ifdef` and also
`#ifanything`.

For backwards compatibility continue to accept `#ifdef` in
case people are using it in the wild but issue warning.

As a side effect of this refactor we not allow support
preprocessor directives that are not in column 0.
2020-11-05 13:31:57 -08:00
Sam Clegg 0b6f01cd7c
WASM2JS is currently not compatible with STANDALONE_WASM (#12713)
wasm2js doesn't yet support memories exported from the wasm module.
I'm working fixed that but for now add an error message.
2020-11-05 11:21:48 -08:00
Sam Clegg dcd3854337
Remove emscripten copyright from third_party headers (#12712)
Its seems we painted with too broad a brush in #7116.

This change was generated programmatically using this type of thing:

for f in `git grep --name-only "//.*The Emscripten Authors" tests/third_party`; do tail -n +6 $f > tmp && /bin/mv tmp $f; done

Fixes: #12711
2020-11-05 10:55:29 -08:00
Sam Clegg cc8a324fd5
Initial support for --post-link on output of wasi-sdk (#12694)
This is an initial PR that only supports the most basic of
wasi-sdk-produced programs.  Most ones that just use stdout and argv.

Adds a simple test which uses the official wasi-sdk sysroot
to build the wasm binary and then uses emscripten to post-process
this to turn this into a runnable JS file.

See #12341
2020-11-04 18:06:11 -08:00
Sam Clegg 7547f68f1f
Allow `-Wl,--print-map` now that wasm-ld supports it (#12697) 2020-11-04 13:01:28 -08:00
Kai Ninomiya 1f678eb3a0
library_webgpu.js: Fix syntax (#12689)
This file accidentally used some modern JS syntax; this fixes it.

Fixes #12621
2020-11-03 17:16:23 -08:00
Sam Clegg 9d37058ced
Minor test code cleanup. NFC. (#12690) 2020-11-03 11:41:26 -08:00
Sam Clegg cbf59196ca
Split out post-link code in emcc and make it independently runnable (#12640)
This change introduces a new output format (--oformat) called
`bare`.  In `bare` mode emscripten will stop after running wasm-ld
and output just the bare wasm module.

It also introduces a new command line argument `--post-link` which
take as input a raw wasm module and run all the post link phases
on it (e.g. wasm-emscripten-finalize, jsifier, etc).

The precise command line UI for this feature is still in the
design phase so I've added a warning so that any users of this
command line UI know that it is experiment.
2020-11-03 11:36:02 -08:00
Sam Clegg a516755858
Error on bad JS library elements (#12673)
For libary config element such as `foo__sig` error out if
the corresponding library member is not found (in this
case if `foo` is not in the library.

This found `memcpy__inline` which can be removed since
memcpy is no longer part of the JS library.

Also remove `__inline` completely since this was the last
use of it, and its asmjs specific.
2020-11-02 09:03:40 -08:00
Sam Clegg 505f406663
Include only needed library methods in tests. NFC. (#12675)
INCLUDE_FULL_LIBRARY is (a) wasteful, and (b) currently
requires NO_ERROR_ON_UNDEFINED_SYMBOLS because reasons.
2020-11-02 08:47:09 -08:00
Sam Clegg 5a7df0592c
Remove setErrNo dependency from library_fs.js. NFC. (#12668)
The filesystem library generally reports errors by throwing
`FS.ErrnoError` exceptions so it should not need ever need
to set errno directly.

Errno gets set in library_syscalls were each syscall is
is wrapped in a try/catch that returns errno back to libs.

In order to remove this dependency I had to remove the three
different uses of `setErrNo` in library_fs.js:

1. handleFSError.  This only had two caller, both in
   library.js so moved this there and added a seperate
   dependency on setErrNo.

2. findObject: Only has a single caller in src/library_dylink.js
   which only cared about a binary result and certainly
   doesn't check the errno location.

3. forceLoadFile: Had exactly two internal callers that both
   turned the error into an exception anyway, so just throw
   the exception directly.
2020-10-31 16:19:21 -07:00
Sam Clegg 693c656732
Add --compiler-wrapper command line flag (#12662)
This works just like the COMPILER_WRAPPER config settings
but works from the command line.

Fixes: #12340
2020-10-30 21:02:46 -07:00
Alon Zakai 699996cf7c
Fix MODULARIZE with sync compilation (#12650)
MODULARIZE + WASM_ASYNC_COMPILATION=0, that is, modularize mode but with
async compilation turned off, so that startup is synchronous, should return the
Module object from the factory function (as it would not make sense to return
a Promise without async startup).

Fixes #12647
2020-10-30 13:17:21 -07:00
Sam Clegg 17fc2da2db
Move setup_runtimelink_test test method into its only caller. NFC. (#12660)
This code is pretty specific and has just one caller. I can't
imagine other tests wanting to share this exact code.
2020-10-30 13:03:49 -07:00
Alon Zakai 7858fcc10e
Allow linking with -lSDL2_mixer to work properly (#12633)
This did not just work because we build libSDL2_mixer_ogg etc., with a suffix
for the codecs we build in. This PR adds an explicit mapping to handle such
cases.

Also improve the test to check this, and add a lot more checks there, like that
we don't use SDL1 somehow (which can happen with files like this where the
SDL1 and SDL2 APIs agree, and so SDL2 does not need to be linked in to
get a running executable).

Fixes #12589
2020-10-30 11:56:08 -07:00
Sam Clegg b0fabfce47
Flush standard streams before running sub-process (#12657)
Without this, the subprocess output (which will be flushed
on sub-process exit) may appear in the output before message
that we have written.

This particular effects python3 which changed the default
buffering of std streams when in non-interative mode:
https://stackoverflow.com/questions/22471023/python-sys-stderr-flush-frequency

Fixes: #12654
2020-10-30 11:49:18 -07:00
Alon Zakai 437266ac3d
Rename INITIAL_INITIAL_MEMORY to INITIAL_MEMORY in preamble.js (#12659)
I think this was a typo.

This should have no observable effects, as it's just an internal variable.
2020-10-30 10:22:43 -07:00
Sam Clegg 60de0b2615
test_minimal_runtime_code_size.: Don't use slop in EMTEST_REBASELINE mode (#12655)
This was leading to some odd results in the expectations files there the
totals didn't add up.  As pointed out by @tlively in #12646.
2020-10-30 09:49:39 -07:00
Sam Clegg 76b86e0045
Stop exporting `__data_end` by default (#12646)
Since https://github.com/WebAssembly/binaryen/pull/3300
wasm-emscripten-finalize no longer needs this.
2020-10-30 08:26:26 -07:00
Sam Clegg f435aa885a
Revive parts of test_emcc_4. NFC. (#12635)
The WASM=0 parts of this test has been disabled and
certainly parts had bit-rotted.
2020-10-29 19:22:15 -07:00
Sam Clegg c88c779c1c
Avoid `.bc` extension in cube2hash test. NFC. (#12645) 2020-10-29 19:12:57 -07:00
sam142 25c04d33bf
Fix an off-by-one error when converting UTF16 strings to JavaScript strings (#12631)
When strings are converted without using TextDecoder, an off-by-on error
causes an out-of-bounds memory read. Fix this by turning the while loop
into a for loop with an appropriate bounds check.

Test the marshalling with null-terminated and non-null-terminated
strings. The code is based on the test for UTF32.
2020-10-29 19:05:34 -07:00
jkae 8ee479e236
Update mktime to match C expected behavior (#12320)
Write out the date fields.

Resolves #12241
2020-10-29 15:34:29 -07:00
Riccardo Magliocchetti 538a4f677c
Give a friendlier error when misusing tools/file_packager.py (#12600)
Catch the case when you are using the very same path as target and
js output.

Fixes #12326
2020-10-29 10:39:10 -07:00
Sam Clegg 16d018704d
Switch to llvm's PIC ABI for relocatable code (#12461)
This change replaces the current PIC ABI (where function and data
addresses are resolved via `fp$` and `g$` function calls with the PIC
ABI use by llvm which involved importing `GOT.func` and `GOT.mem`
mutable wasm globals.

This allows us to pass `--new-pic-abi` to wasm-emscripten-finalize
which disabled the PIC ABI transformation normally done by binaryen.

As part of this change we now store the `__sig` of each JavaScript
function on the function so it is available at runtime.  This
runtime signature is needed when a dynamically linked module
imports a JavaScript function by address.  In this case the function
must be added to the table, and for that to succeed we need to know
its signature.
2020-10-28 23:08:24 -07:00
Sam Clegg 9608511c6f
Split emrun tests out of `browser` (#12594)
Unlike the other browser tests they don't use the test
runner harness and instead launch their own browser.

I was finding that running the test locally in isolation
that browser test harness would interfere with the
browser that emrun was starting.. since they both honor
EMTEST_BROWSER.
2020-10-28 21:06:38 -07:00
Sam Clegg 3f7d8eeac3
Move emscripten_stack_get_base/end into native code (#12615)
With this change, we no longer need any JavaScript variables to track the
state of the stack.   The base and max as well as the current stack
pointer are all managed in native code.

The following JavaScript variable a no longer present in the library
code:
 STACK_BASE -> emscripten_stack_get_base()
 STACK_MAX -> emscripten_stack_get_end()
 STACKTOP -> emscripten_stack_get_current()
 TOTAL_STACK -> emscripten_stack_get_base() - emscripten_stack_get_end()
2020-10-28 20:13:45 -07:00
Sam Clegg 23cda910f5
Fix `-s EMSCRIPTEN_METADATA` in standalone mode (#12632)
The problem is that apply_memory is only called in modes where
JS is being generated.

Fixes: #12552
2020-10-28 17:20:33 -07:00
Sam Clegg 7c2d0936d0
Remove python2 support. NFC. (#12610)
We have been error'ing out python3 usage for a while now.
This change finally removes the python2 support so there
is no way back.

And to show we mean it, include an f-string in there
for good measure.

Fixes: #7198
2020-10-28 15:32:49 -07:00
Sam Clegg f450c1cdfb
Remove old asmjs-specific test. NFC. (#12619) 2020-10-28 13:08:54 -07:00
Sam Clegg f1c87feda8
Convert more tests to compile directly from file. NFC. (#12617)
This makes debugging tests a lot easier.
2020-10-28 13:08:28 -07:00
Sam Clegg 1d73f9f410
Allow dlsym() to looking JavaScript symbols in RTLD_DEFAULT mode (#12609)
In this mode dlsym is supposed to be able to looking all symbols
in default library search path which should include JS symbols.

Unfortunately if the symbol being looked up is not already in the
table then its signature needs to be known at this point.  To
handle this case we keep the signatures around at runtime by
attaching them to the JS library functions.  This a small extra
overhead that only applies to dynamic linking.

This change is needed for and split out from #12461
2020-10-28 13:07:26 -07:00
Sam Clegg 960eb0657e
Fix duplicate `dylink` section in side modules (#12624)
We were adding a second dylink section before the first
which is relatively harmless but certainly wrong.
2020-10-28 13:06:32 -07:00
Sam Clegg 113b74891a
Remove unused ASM_PRIMITIVE_VARS settings. NFC. (#12614) 2020-10-28 12:42:17 -07:00
Sam Clegg 15dc46a06b
Force use of Ninja generator in test_cmake_with_embind_cpp11_mode (#12613)
This change includes a bunch of cleanups but the main change
here is to force the use of the Ninja generator.  Without
this this test will try to VS or nmake on windows which fails
in various ways.

This change is needed since we stopped forcing the default
generator on windows in #12595 landed.
2020-10-27 13:56:38 -07:00
Sam Clegg 72364b6a02
Remove some of the magic from emcmake (#12595)
emcmake should be a tools that simply wraps cmake.  We should not be
opinionated about the generator that a user might want to use of
try to work around MinGW issues on behalf of the user.
2020-10-27 07:35:22 -07:00
Sam Clegg a54a3a63dd
Add `--oformat` flag to explictly control output format (#12598)
Without this flag the output format is determined by the name of the
output file.

With this flag the name of the output file is ignored and the format is
determined solely by this flag.

This can be useful in various situation but the motivation for doing
it now that it provides a place to specify a new output format which
will be the raw linker output, which can then be fed into that new
post-link-only mode that we are planning.
2020-10-27 06:01:16 -07:00
Sam Clegg 50cfc37e26
Remove workaround for windows popen bug (#12603)
This workaround was inadvertantly disabled completely back in #9177.  As
part of this change it became impossible to set the global variable
EM_POPEN_WORKAROUND which enables this workaround.  After this change
the environment variable `EM_POPEN_WORKAROUND` and the config setting
`POPEN_WORKAROUND` both control the global variable calles
`POPEN_WORKAROUND` but its the global variable called
`EM_POPEN_WORKAROUND` that continues to enable this workaround.

Since that change landed over a year ago and nobody has complained
about this workaround not working I can only assume that we don't
have any Windows 7 users who I believe are the only ones effected
by this python bug.
2020-10-26 16:12:03 -07:00
Sam Clegg 845498c53a
Update test_minimal_runtime_code_size expectations (#12606)
A binaryen change (https://github.com/WebAssembly/binaryen/pull/3275)
seems to have given us some code size improvements here.
2020-10-26 10:55:03 -07:00
algestam bda996b3bb
Imply MODULARIZE when EXPORT_ES6 is set (#12530)
* Exit if modularize explicitly set to false with EXPORT_ES6

* Add tests that verifies MODULARIZE behaviour when used with EXPORT_ES6
2020-10-26 09:32:09 -07:00
Sam Clegg f9d491b575
Verify dlopen flags (#12591) 2020-10-24 13:43:46 -07:00
Sam Clegg d059fd603d
emrun: use argparse in more conventional way (#12520)
* emrun: use argparse in more conventional way

This is not quite NFC since passing command line arguments
to the page that start with `-` now requires a separator.

This used to work:

./emrun filename.html --foo --bar

Where as now one needs to add `--` to signal the end of emrun's
argument parsing.

So either:

./emrun filename.html -- --foo --bar

or:

./emrun -- filename.html --foo --bar

* error_check
2020-10-23 16:08:12 -07:00
Sam Clegg f93a4a957a
Use the same test layout in test_other that we do in test_core. NFC. (#12588)
This also allows us to use the same `run_in_out_file_test` method
in both places.
2020-10-23 16:07:09 -07:00
Sam Clegg 56c5062c80
Fix dlsym for 64-bit functions (#12586)
This basically involved looking the `orig$` functions whenever we
want a native WebAssembly function.

Regarding test_dlfcn_i64: It seems that this test wasn't actually
testing functions that have i64 in thier signature but some kind of i64
handling from back in the asm.js days.  See  #2060.  This change
repurposes it to and makes it more useful.
2020-10-23 11:49:07 -07:00
Sam Clegg d62987bbce
Cleanup format in test sources. NFC. (#12587) 2020-10-23 11:41:19 -07:00
Alon Zakai dab23338a2
Make ASSERTIONS=2 imply STACK_OVERFLOW_CHECK=2 (#12579)
This is in addition to the existing 1 implying 1.

The goal is to make it easier to use -s ASSERTIONS=2 and have it check
as many things as possible.
2020-10-23 11:34:53 -07:00
Sam Clegg a51335751c
Re-enable browser.test_dylink_dso_needed tests (#12585)
This was fixed back in #11028

Fixes: #8753
2020-10-23 11:23:37 -07:00
Sam Clegg 45c49faaf0
Add support for RTLD_DEFAULT in dlsym (#12583)
This implicitly-open handle looks up symbols in the same way that they
are looked up when loading shared libraries. i.e. it searches all
symbols in the main module + any shared libraries loaded with
RTLD_GLOBAL.
2020-10-23 08:30:55 -07:00
Alon Zakai 1a4903111b
Add a strict mode test for dynamic linking (#12584) 2020-10-22 17:33:33 -07:00
Alon Zakai 071ba773e3
Emit a relative path in -gseparate-dwarf (#12549)
This way the side file  can be found relative to the main one.

Fixes #12526
2020-10-22 12:57:18 -07:00
Sam Gao 0caed62db3
Re-increment uncaught exception count on rethrow (#12535)
In https://github.com/emscripten-core/emscripten/blob/master/src/library_exceptions.js,
the uncaught exception count is incremented and decremented exactly once during
__cxa_throw and __cxa_begin_catch respectively (as the ABI says it should be). This
however doesn't get re-incremented in the event of a rethrow, so anything that happens
between the first catch and the second catch (eg. destructors) receive the decremented
value.

In LLVM the count is incremented again in __cxa_rethrow, which curiously the ABI does
not ask us to do, but seems to be the behaviour we expect. Perhaps the ABI assumes
that rethrow calls throw under the hood. This PR brings us closer to that, and in alignment
with LLVM.

The testcase added here now emits the same correct output as a native build, which
it did not before this PR.
2020-10-22 11:32:26 -07:00
Sam Clegg e3882c9c5b
Fix mis-reporting of `undefined exported functions` on data symbols (#12573)
We can already use EXPORT_FUNCTIONS to export data symbols but
the symbol check was only looking at function exports.

This was leading to erroneous error message for users who were
doing `-s EXPORTED_FUNCTIONS=[data_symbol]`.

See: #12558
2020-10-21 15:49:40 -07:00
Sam Clegg 244498370a
Error out if wasm2js and dynamic linking are used together (#12564)
This combination has never been allowed by we didn't show
a clear error before.
2020-10-21 08:29:11 -07:00
Sam Clegg 13da6c1dd0
Remove TODO in test code. NFC. (#12565)
This test seems to pass now with the wasm backend
2020-10-21 08:28:57 -07:00
Stephan Reiter 416f76a1f3
If async preparing wasm fails with MODULARIZE=1, reject the module ready promise (#12408)
For example, if a global constructor performs an invalid memory access,
an exception will be thrown that bubbles up to receiveInstantiatedSource.
That causes a rejection of the promise returned from instantiateAsync,
and we should forward that to the module consumer via the module ready promise.
By handling that rejection we also avoid an unhandled-promise-rejection
error in browsers.

Fixes #12396
2020-10-20 13:02:08 -07:00
Beuc 37b5cfa8fd
sdl2-config: bump version (#12538)
Third-party SDL modules query require a recent-ish version of SDL2 (e.g.
standard SDL2_image requires SDL2 >= 2.0.8). Emscripten currently
ships SDL2 tag version_22, that is 2.0.10.
2020-10-19 14:19:29 -07:00
Sam Clegg 13493fd0a2
Use a mutable global as __stack_pointer in dynamic linking (#12536)
Without this change we were using a normal Number and then
`wasm-emscripten-finalize` would use that value to set an
internal mutable global.

This change means that users emscripten's dynamic linking
now depends on the mutable globals proposal.  However this
is already available in all major browsers:

  https://webassembly.org/roadmap/

This is small step towards #12461 which can be landing
in isolation without otherwise changing the ABI.

Once this lands we can remove `internalizeStackPointerGlobal`
from `wasm-emscripten-finalize`.
2020-10-16 10:58:56 -07:00
Sam Clegg 31df03a539
Some minor cleanups split out from #12461 (#12532)
- Use C over C++ in test_dlfcn_longjmp since the test
  doesn't use C++ and it makes debugging simpler.
- Add/improve a couple of assertions
- Remove duplicate `var` in declaration wasmTable.
2020-10-15 15:46:06 -07:00
Sam Clegg 04e5f3df56
Cleanup test_zzz_emrun. NFC. (#12522) 2020-10-15 11:14:28 -07:00
Sam Clegg 034b67c5b6
Remove unused removeFunctionWasm helper. NFC (#12507)
And extract getEmptyTableSlot helper.
2020-10-14 09:28:39 -07:00
Sam Clegg 72cd886b5b
Allow --argument=foo as well as --argument foo (#12512)
This is useful in general but specifically for cmake
which links to re-order compiler flags.
2020-10-14 09:02:11 -07:00
Alon Zakai eb05ac60bd
Use env_modify in test_openjpeg (#12511) 2020-10-13 14:40:30 -07:00
Sam Clegg 1046cd3202
Fix and reenable test_unistd_truncate_noderawfs (#12510) 2020-10-13 13:21:12 -07:00
Alon Zakai a3bc227e21
C environ constructor cleanup (#12509)
We had a redundant check there.

Also improve the test to handle the case where malloc failed in the constructor. This
might help debug the asan failure on the bot on this test (which does not fail locally
for me).
2020-10-13 11:21:32 -07:00
Alon Zakai b814fe4ba3
ASan testing fixes (#12508)
This should fix all current errors on the waterfall for asan, except for
the one I can't reproduce locally (environ).
2020-10-13 11:21:03 -07:00
Sam Clegg 6e3d03dc2f
Re-enable metadce test after https://reviews.llvm.org/D89152 (#12503) 2020-10-13 08:13:23 -07:00
Sam Clegg 88dad4c3a3
Temporarily disable test_metadce_hello_main_module_2 (#12500)
So that https://reviews.llvm.org/D89152 can roll
2020-10-12 20:49:09 -07:00
Sam Clegg c5fdb4d5e7
Don't allow libraries to clobber global library iterator variable (#12498) 2020-10-12 16:25:25 -07:00
algestam c13a3c515a
Add O_NOCTTY flag to nodefs flags (#12492) 2020-10-11 18:32:31 -07:00
Heejin Ahn beac72fcf3
Ensure EH does not change code after linking (#12493)
We used to require Binaryen postprocessing for EH and have a `fail`
requirement for it in `other.test_immutable_after_link`. I deleted the
requirement in #12399, but it could have been better if I didn't just
delete it but changed it to an `ok` requirement. This PR adds that.
2020-10-11 16:43:24 -07:00
Heejin Ahn e179b57d11
Don't run binaryen postprocessing for Emscripten EH/SjLj (#12399)
Now that we are renaming invoke wrappers and `emscripten_longjmp_jmpbuf`
in the wasm backend, using Emscripten EH or SjLj does not need
Binaryen's postprocessing. This makes Emscripten not enable Binaryen
postprocessing using wasm-emscripten-finalize when we are using them,
and deletes all special handling for `emscripten_longjmp_jmpbuf`, given
that Emscripten will not see it.

Addresses:
WebAssembly/binaryen#3043
WebAssembly/binaryen#3081

Companions:
https://reviews.llvm.org/D88697
WebAssembly/binaryen#3191
2020-10-11 02:51:11 -07:00
Sam Clegg 3f3d3001a1
Rebaseline codesize tests after recent llvm roll (#12479) 2020-10-09 13:52:13 -07:00
Heejin Ahn 5e5c875aa3
Disable other.test_minimal_runtime_code_size on Mac (#12474)
After #12464, small code size regression also happened on Mac. Not sure
what the exact reason is, but this just disables it to make the
autoroller work again.

Failure log: https://logs.chromium.org/logs/emscripten-releases/buildbucket/cr-buildbucket.appspot.com/8866979228011064752/+/steps/Emscripten_testsuite__upstream__other_/0/stdout
2020-10-09 00:15:57 -07:00
Doug Conmy 3cf806d250
Fix timezone returning wrong values during DST (#12330)
Calculate the non-DST-adjusted time properly.

fixes #11572

Co-authored-by: Tristan Griffin <tristan.griffin@pnp-hcl.com>
Co-authored-by: Tristan Griffin <tristangriffin@icloud.com>
2020-10-08 12:39:43 -07:00
Sam Clegg ef4d1e9ec6
Remove EM_LOG_DEMANGLE (#12470)
When displaying a callstack from a wasm module names will either
not appear at all or they will be populated from the wasm names
section which never contains managled names.

As far as I can tell mangled names no longer appear be backtraces
so demanagling is no longer a useful features.
2020-10-08 10:47:34 -07:00