diff --git a/system/include/emscripten/val.h b/system/include/emscripten/val.h index 0e0e511cb64df..a63283912aac2 100644 --- a/system/include/emscripten/val.h +++ b/system/include/emscripten/val.h @@ -285,7 +285,7 @@ struct WireTypePack { static const char name##_symbol[] = #name; \ static const ::emscripten::internal::symbol_registrar name##_registrar -class val { +class EMBIND_VISIBILITY_DEFAULT val { public: // missing operators: // * ~ - + ++ -- diff --git a/system/include/emscripten/wire.h b/system/include/emscripten/wire.h index 379aae8799103..ebb5558ff6f35 100644 --- a/system/include/emscripten/wire.h +++ b/system/include/emscripten/wire.h @@ -24,6 +24,7 @@ #include #define EMSCRIPTEN_ALWAYS_INLINE __attribute__((always_inline)) +#define EMBIND_VISIBILITY_DEFAULT __attribute__((visibility("default"))) #ifndef EMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES #define EMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES 1 @@ -430,7 +431,7 @@ constexpr bool typeSupportsMemoryView() { } // namespace internal template -struct memory_view { +struct EMBIND_VISIBILITY_DEFAULT memory_view { memory_view() = delete; explicit memory_view(size_t size, const ElementType* data) : size(size) diff --git a/test/test_core.py b/test/test_core.py index f01332a4b53e9..5d0574bfa40f6 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -7718,6 +7718,36 @@ def test_source_map(self, args): else: self.assertTrue(seen_lines.issuperset([6, 7, 11, 12]), seen_lines) + @needs_dylink + def test_embind_dylink_visibility_hidden(self): + # Check that embind is usable from a library built with "-fvisibility=hidden" + + create_file('liblib.cpp', r''' + #include + #define EXPORT __attribute__((visibility("default"))) + using namespace emscripten; + EXPORT void liba_fun() { + unsigned char buffer[1]; + val view(typed_memory_view(1, buffer)); + } + ''') + self.build_dlfcn_lib('liblib.cpp', emcc_args=['-fvisibility=hidden']) + + self.prep_dlfcn_main() + self.clear_setting('NO_AUTOLOAD_DYLIBS') + create_file('main.cpp', r''' + #include + #include + using namespace emscripten; + void liba_fun(); + int main() { + liba_fun(); + printf("done\n"); + return 0; + } + ''') + self.do_runf('main.cpp', 'done\n', emcc_args=['--bind']) + @no_wasm2js('TODO: source maps in wasm2js') def test_dwarf(self): self.emcc_args.append('-g')