For reasons that are a bit beyond me, `--host` and `PLATFORM_TRIPLET`
seem to be independent, in particular we've had an empty
`PLATFORM_TRIPLET`. This is unfortunate because `PLATFORM_TRIPLET`
is used to generate the SOABI config variable which in turn is used
to decide whether a .so file is a good match for loading. We'd like
for linux Pythons not to try to import emscripten .so files (it
raises `ImportError: some_file.so: invalid ELF header`). Similarly,
we'd like to avoid attempting to load linux .so files in wasm. These
platform tags are our friends.

Anyways, this PR sets `PLATFORM_TRIPLET` and ensures that .so files
built by pywasmcross are tagged with our SOABI tag.

I moved the .so file renaming from pywasmcross to buildpkg just
before running the post script. That is a better place to put it in
case the package wants to look at the .so file after linking it. It
might be surprised that we moved it.

I also improved the error message if we try to `loadWebAssemblyModule`
something that is actually say a Linux .so file and updated get_dynlibs
to filter out .so files that have an incompatible abi tag.
Set PLATFORM_TRIPLET, include platform in so names, only load compatible so files. For reasons that are a bit beyond me, `--host` and `PLATFORM_TRIPLET`
seem to be independent, in particular we've had an empty
`PLATFORM_TRIPLET`. This is unfortunate because `PLATFORM_TRIPLET`
is used to generate the SOABI config variable which in turn is used
to decide whether a .so file is a good match for loading. We'd like
for linux Pythons not to try to import emscripten .so files (it
raises `ImportError: some_file.so: invalid ELF header`). Similarly,
we'd like to avoid attempting to load linux .so files in wasm. These
platform tags are our friends.

Anyways, this PR sets `PLATFORM_TRIPLET` and ensures that .so files
built by pywasmcross are tagged with our SOABI tag.

I moved the .so file renaming from pywasmcross to buildpkg just
before running the post script. That is a better place to put it in
case the package wants to look at the .so file after linking it. It
might be surprised that we moved it.

I also improved the error message if we try to `loadWebAssemblyModule`
something that is actually say a Linux .so file and updated get_dynlibs
to filter out .so files that have an incompatible abi tag.
From 73b89ee1b5a57c65824baf91b547be32b69decbd Mon Sep 17 00:00:00 2001
From: Hood Chatham <roberthoodchatham@gmail.com>
Date: Tue, 15 Feb 2022 23:27:03 -0500
Subject: [PATCH 3/4] Fix side module exception handling

See https://github.com/emscripten-core/emscripten/pull/16309

Apparently compiled C++ code tries to call a bunch of functions with names like
`__cxa_find_matching_catch_##` which all mean the same function. Emscripten
statically defines the set of these that are used in the main module, but it is
possible that a side module will need extra ones. This fixes the problem by updating
`resolveGlobalSymbol` so that every `__cxa_find_matching_catch_##` will resolve to
`__cxa_find_matching_catch`.
---
 src/library_dylink.js | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/library_dylink.js b/src/library_dylink.js
index 54a6f190c..1d1613eef 100644
--- a/src/library_dylink.js
+++ b/src/library_dylink.js
@@ -32,6 +32,9 @@ var LibraryDylink = {
       sym = createInvokeFunction(symName.split('_')[1]);
     }
 
+    if(!sym && symName.startsWith("__cxa_find_matching_catch")){
+      sym = Module.___cxa_find_matching_catch;
+    }
     return sym;
   },
 
-- 
2.25.1


From 73b89ee1b5a57c65824baf91b547be32b69decbd Mon Sep 17 00:00:00 2001
From: Hood Chatham <roberthoodchatham@gmail.com>
Date: Tue, 15 Feb 2022 23:27:03 -0500
Subject: [PATCH 3/4] Fix side module exception handling

See https://github.com/emscripten-core/emscripten/pull/16309

Apparently compiled C++ code tries to call a bunch of functions with names like
`__cxa_find_matching_catch_##` which all mean the same function. Emscripten
statically defines the set of these that are used in the main module, but it is
possible that a side module will need extra ones. This fixes the problem by updating
`resolveGlobalSymbol` so that every `__cxa_find_matching_catch_##` will resolve to
`__cxa_find_matching_catch`.
---
 src/library_dylink.js | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/library_dylink.js b/src/library_dylink.js
index 54a6f190c..1d1613eef 100644
--- a/src/library_dylink.js
+++ b/src/library_dylink.js
@@ -32,6 +32,9 @@ var LibraryDylink = {
       sym = createInvokeFunction(symName.split('_')[1]);
     }
 
+    if(!sym && symName.startsWith("__cxa_find_matching_catch")){
+      sym = Module.___cxa_find_matching_catch;
+    }
     return sym;
   },
 
-- 
2.25.1

