Skip to content

Export std hash template specializations from dylibs #7618

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 23, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ if(BYN_ENABLE_LTO)
set(CMAKE_JOB_POOL_LINK link_job_pool)
add_compile_flag("-flto=thin")
endif()
#add_link_flag("-Wl,--export-dynamic")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Bsymbolic -Wl,--export-dynamic")

if(MSVC)
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
Expand Down
16 changes: 16 additions & 0 deletions src/compiler-support.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,20 @@
#define WASM_BUILTIN_UNREACHABLE __assume(false)
#endif

// Forces symbols to be exported from libbinaryen dynamic library. Currently
// we are just using the default flags, causing most of our symbols to have
// "default" visibility, meaning they can all be used from the tool sources.
// However a recent libc++ change caused functions declared in namespace std
// (e.g. hash template specializations) to have hidden visibility. So this
// macro forces them to be exported. In the future if we want to compile
// libbinaryen with -fvisibility-hidden or use a DLL on Windows, we'll need
// to explicitly annotate everything we want to export. But that's probably
// only useful if we want external users to link against libbinaryen.so
// (currently we don't; it's only used to reduce our install size).
#if defined(__ELF__) || defined(__MACH__)
#define DLLEXPORT [[gnu::visibility("default")]]
#else
#define DLLEXPORT
#endif

#endif // wasm_compiler_support_h
3 changes: 2 additions & 1 deletion src/wasm-type-shape.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <functional>
#include <vector>

#include "compiler-support.h"
#include "wasm-features.h"
#include "wasm-type.h"

Expand Down Expand Up @@ -74,7 +75,7 @@ namespace std {

template<> class hash<wasm::RecGroupShape> {
public:
size_t operator()(const wasm::RecGroupShape& shape) const;
DLLEXPORT size_t operator()(const wasm::RecGroupShape& shape) const;
};

} // namespace std
Expand Down
17 changes: 9 additions & 8 deletions src/wasm-type.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <variant>
#include <vector>

#include "compiler-support.h"
#include "support/index.h"
#include "support/name.h"
#include "support/parent_index_iterator.h"
Expand Down Expand Up @@ -1005,35 +1006,35 @@ namespace std {

template<> class hash<wasm::Type> {
public:
size_t operator()(const wasm::Type&) const;
DLLEXPORT size_t operator()(const wasm::Type&) const;
};
template<> class hash<wasm::Signature> {
public:
size_t operator()(const wasm::Signature&) const;
DLLEXPORT size_t operator()(const wasm::Signature&) const;
};
template<> class hash<wasm::Continuation> {
public:
size_t operator()(const wasm::Continuation&) const;
DLLEXPORT size_t operator()(const wasm::Continuation&) const;
};
template<> class hash<wasm::Field> {
public:
size_t operator()(const wasm::Field&) const;
DLLEXPORT size_t operator()(const wasm::Field&) const;
};
template<> class hash<wasm::Struct> {
public:
size_t operator()(const wasm::Struct&) const;
DLLEXPORT size_t operator()(const wasm::Struct&) const;
};
template<> class hash<wasm::Array> {
public:
size_t operator()(const wasm::Array&) const;
DLLEXPORT size_t operator()(const wasm::Array&) const;
};
template<> class hash<wasm::HeapType> {
public:
size_t operator()(const wasm::HeapType&) const;
DLLEXPORT size_t operator()(const wasm::HeapType&) const;
};
template<> class hash<wasm::RecGroup> {
public:
size_t operator()(const wasm::RecGroup&) const;
DLLEXPORT size_t operator()(const wasm::RecGroup&) const;
};

} // namespace std
Expand Down
Loading