Skip to content

Commit 993550c

Browse files
anutosh491mcbarton
andauthored
Fix all crashing tests for emscripten build (#523)
Co-authored-by: mcbarton <[email protected]>
1 parent 4fd5386 commit 993550c

File tree

7 files changed

+54
-49
lines changed

7 files changed

+54
-49
lines changed

include/clang/Interpreter/CppInterOp.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,15 @@ namespace Cpp {
127127
: m_Kind(K), m_DestructorCall(C), m_FD(Dtor) {}
128128

129129
/// Checks if the passed arguments are valid for the given function.
130-
bool AreArgumentsValid(void* result, ArgList args, void* self) const;
130+
CPPINTEROP_API bool AreArgumentsValid(void* result, ArgList args,
131+
void* self) const;
131132

132133
/// This function is used for debugging, it reports when the function was
133134
/// called.
134-
void ReportInvokeStart(void* result, ArgList args, void* self) const;
135-
void ReportInvokeStart(void* object, unsigned long nary,
136-
int withFree) const;
135+
CPPINTEROP_API void ReportInvokeStart(void* result, ArgList args,
136+
void* self) const;
137+
CPPINTEROP_API void ReportInvokeStart(void* object, unsigned long nary,
138+
int withFree) const;
137139
void ReportInvokeEnd() const;
138140
public:
139141
Kind getKind() const { return m_Kind; }

lib/Interpreter/exports.ld

+9
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,12 @@
3737
-Wl,--export=_ZNK5clang7TagType7getDeclEv
3838
-Wl,--export=_ZNK5clang7VarDecl28isThisDeclarationADefinitionERNS_10ASTContextE
3939
-Wl,--export=_ZTVN4llvm18raw_string_ostreamE
40+
-Wl,--export=_ZN4llvm13StringMapImpl11RehashTableEj
41+
-Wl,--export=_ZN4llvm13StringMapImpl15LookupBucketForENS_9StringRefEj
42+
-Wl,--export=_ZN4llvm13StringMapImpl4hashENS_9StringRefE
43+
-Wl,--export=_ZNK5clang10ASTContext14getComplexTypeENS_8QualTypeE
44+
-Wl,--export=_ZNK5clang10ASTContext19getTypeDeclTypeSlowEPKNS_8TypeDeclE
45+
-Wl,--export=_ZNK5clang10RecordDecl19isInjectedClassNameEv
46+
-Wl,--export=_ZNK5clang11DeclContext6lookupENS_15DeclarationNameE
47+
-Wl,--export=_ZNK5clang17ClassTemplateDecl18getSpecializationsEv
48+
-Wl,--export=_ZNK5clang4Sema15getStdNamespaceEv

unittests/CppInterOp/CMakeLists.txt

+35-20
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,33 @@ add_cppinterop_unittest(CppInterOpTests
2525
)
2626

2727
if(EMSCRIPTEN)
28-
# Explaination of compile and link flags
29-
# To dynamically link to a shared library for Emscripten builds you must use the MAIN_MODULE flag (see both https://github.com/emscripten-core/emscripten/issues/23543#issuecomment-2625334414
30-
# and https://emscripten.org/docs/compiling/Dynamic-Linking.html)
31-
# Without WASM_BIGINT flag then you get fatal errors when trying to run compiled Javascript about trying to convert between BigInt and non BigInt types
32-
# EXPORTED_RUNTIME_METHODS='[\"FS\",\"PATH\",\"LDSO\",\"loadDynamicLibrary\",\"ERRNO_CODES\"]' and --preload-file ${SYSROOT_PATH}/include@/include are not allow the Javascript that is
33-
# compiled to have access to the standard library headers (approach taken from xeus-cpp)
34-
# Without ALLOW_MEMORY_GROWTH=1 tests will fail with aborted(OOM). Approach to fix taken from answers to
35-
# https://stackoverflow.com/questions/67222200/runtimeerror-abortoom-build-with-s-assertions-1-for-more-info
36-
set_target_properties(CppInterOpTests PROPERTIES
37-
LINK_FLAGS "-s MAIN_MODULE=1 -s WASM_BIGINT -s EXPORTED_RUNTIME_METHODS='[\"FS\",\"PATH\",\"LDSO\",\"loadDynamicLibrary\",\"ERRNO_CODES\"]' --preload-file ${SYSROOT_PATH}/include@/include -s ALLOW_MEMORY_GROWTH=1"
28+
# Explanation of Emscripten-specific link flags for CppInterOpTests:
29+
#
30+
# MAIN_MODULE=1:
31+
# Enables building CppInterOpTests.js as the main WebAssembly module, allowing dynamic linking of side modules.
32+
#
33+
# WASM_BIGINT:
34+
# Ensures support for 64-bit integer types by enabling JavaScript BigInt integration in WASM.
35+
#
36+
# ALLOW_MEMORY_GROWTH=1:
37+
# Allows the WebAssembly memory to grow dynamically at runtime to accommodate increasing memory needs.
38+
# Would lead to an abortOnCannotGrowMemory error if memory cannot be grown while running the tests.
39+
#
40+
# STACK_SIZE=32mb: Allocates 32MB of stack space to handle deep recursion or large stack-allocated objects safely.
41+
# INITIAL_MEMORY=128mb: Sets the initial linear memory size to 128MB to reduce the likelihood of early memory expansion and improve performance.
42+
# The STACK_SIZE and INITIAL_MEMORY values are chosen based on what has been put to use for running xeus-cpp-lite.
43+
# Check https://github.com/jupyter-xeus/xeus/blob/main/cmake/WasmBuildOptions.cmake#L35-L36 for more details.
44+
# Not setting these flags would lead to a memory access out of bounds error while running the tests.
45+
#
46+
# --preload-file ${SYSROOT_PATH}/include@/include:
47+
# Preloads the system include directory into the Emscripten virtual filesystem to make headers accessible at runtime.
48+
target_link_options(CppInterOpTests
49+
PUBLIC "SHELL: -s MAIN_MODULE=1"
50+
PUBLIC "SHELL: -s WASM_BIGINT"
51+
PUBLIC "SHELL: -s ALLOW_MEMORY_GROWTH=1"
52+
PUBLIC "SHELL: -s STACK_SIZE=32mb"
53+
PUBLIC "SHELL: -s INITIAL_MEMORY=128mb"
54+
PUBLIC "SHELL: --preload-file ${SYSROOT_PATH}/include@/include"
3855
)
3956
endif()
4057

@@ -69,16 +86,14 @@ target_link_libraries(DynamicLibraryManagerTests
6986
)
7087

7188
if(EMSCRIPTEN)
72-
# Explaination of compile and link flags
73-
# To dynamically link to a shared library for Emscripten builds you must use the MAIN_MODULE flag (see both https://github.com/emscripten-core/emscripten/issues/23543#issuecomment-2625334414
74-
# and https://emscripten.org/docs/compiling/Dynamic-Linking.html)
75-
# Without WASM_BIGINT flag then you get fatal errors when trying to run compiled Javascript about trying to convert between BigInt and non BigInt types
76-
# EXPORTED_RUNTIME_METHODS='[\"FS\",\"PATH\",\"LDSO\",\"loadDynamicLibrary\",\"ERRNO_CODES\"]' and --preload-file ${SYSROOT_PATH}/include@/include are not allow the Javascript that is
77-
# compiled to have access to the standard library headers (approach taken from xeus-cpp)
78-
# Without ALLOW_MEMORY_GROWTH=1 tests will fail with aborted(OOM). Approach to fix taken from answers to
79-
# https://stackoverflow.com/questions/67222200/runtimeerror-abortoom-build-with-s-assertions-1-for-more-info
80-
set_target_properties(DynamicLibraryManagerTests PROPERTIES
81-
LINK_FLAGS "-s MAIN_MODULE=1 -s WASM_BIGINT -s EXPORTED_RUNTIME_METHODS='[\"FS\",\"PATH\",\"LDSO\",\"loadDynamicLibrary\",\"ERRNO_CODES\"]' --preload-file ${SYSROOT_PATH}/include@/include -s ALLOW_MEMORY_GROWTH=1"
89+
# Check explanation of Emscripten-specific link flags for CppInterOpTests above for DynamicLibraryManagerTests as well.
90+
target_link_options(DynamicLibraryManagerTests
91+
PUBLIC "SHELL: -s MAIN_MODULE=1"
92+
PUBLIC "SHELL: -s WASM_BIGINT"
93+
PUBLIC "SHELL: -s ALLOW_MEMORY_GROWTH=1"
94+
PUBLIC "SHELL: -s STACK_SIZE=32mb"
95+
PUBLIC "SHELL: -s INITIAL_MEMORY=128mb"
96+
PUBLIC "SHELL: --preload-file ${SYSROOT_PATH}/include@/include"
8297
)
8398
endif()
8499

unittests/CppInterOp/FunctionReflectionTest.cpp

+3-6
Original file line numberDiff line numberDiff line change
@@ -547,9 +547,6 @@ TEST(FunctionReflectionTest, ExistsFunctionTemplate) {
547547
}
548548

549549
TEST(FunctionReflectionTest, InstantiateTemplateFunctionFromString) {
550-
#ifdef EMSCRIPTEN
551-
GTEST_SKIP() << "Test crashes gtest on Emscipten";
552-
#endif
553550
if (llvm::sys::RunningOnValgrind())
554551
GTEST_SKIP() << "XFAIL due to Valgrind report";
555552
Cpp::CreateInterpreter();
@@ -1053,7 +1050,7 @@ TEST(FunctionReflectionTest, IsStaticMethod) {
10531050

10541051
TEST(FunctionReflectionTest, GetFunctionAddress) {
10551052
#ifdef EMSCRIPTEN
1056-
GTEST_SKIP() << "Test crashes gtest on Emscipten";
1053+
GTEST_SKIP() << "Test fails for Emscipten builds";
10571054
#endif
10581055
if (llvm::sys::RunningOnValgrind())
10591056
GTEST_SKIP() << "XFAIL due to Valgrind report";
@@ -1100,7 +1097,7 @@ TEST(FunctionReflectionTest, IsVirtualMethod) {
11001097

11011098
TEST(FunctionReflectionTest, JitCallAdvanced) {
11021099
#ifdef EMSCRIPTEN
1103-
GTEST_SKIP() << "Test crashes gtest on Emscipten";
1100+
GTEST_SKIP() << "Test fails for Emscipten builds";
11041101
#endif
11051102
if (llvm::sys::RunningOnValgrind())
11061103
GTEST_SKIP() << "XFAIL due to Valgrind report";
@@ -1127,7 +1124,7 @@ TEST(FunctionReflectionTest, JitCallAdvanced) {
11271124

11281125
TEST(FunctionReflectionTest, GetFunctionCallWrapper) {
11291126
#ifdef EMSCRIPTEN
1130-
GTEST_SKIP() << "Test crashes gtest on Emscipten";
1127+
GTEST_SKIP() << "Test fails for Emscipten builds";
11311128
#endif
11321129
if (llvm::sys::RunningOnValgrind())
11331130
GTEST_SKIP() << "XFAIL due to Valgrind report";

unittests/CppInterOp/ScopeReflectionTest.cpp

-12
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,6 @@ TEST(ScopeReflectionTest, SizeOf) {
161161

162162

163163
TEST(ScopeReflectionTest, IsBuiltin) {
164-
#ifdef EMSCRIPTEN
165-
GTEST_SKIP() << "Test crashes gtest on Emscipten";
166-
#endif
167164
// static std::set<std::string> g_builtins =
168165
// {"bool", "char", "signed char", "unsigned char", "wchar_t", "short", "unsigned short",
169166
// "int", "unsigned int", "long", "unsigned long", "long long", "unsigned long long",
@@ -494,9 +491,6 @@ TEST(ScopeReflectionTest, GetScopefromCompleteName) {
494491
}
495492

496493
TEST(ScopeReflectionTest, GetNamed) {
497-
#ifdef EMSCRIPTEN
498-
GTEST_SKIP() << "Test crashes gtest on Emscipten";
499-
#endif
500494
std::string code = R"(namespace N1 {
501495
namespace N2 {
502496
class C {
@@ -882,9 +876,6 @@ template<typename T> T TrivialFnTemplate() { return T(); }
882876
}
883877

884878
TEST(ScopeReflectionTest, InstantiateTemplateFunctionFromString) {
885-
#ifdef EMSCRIPTEN
886-
GTEST_SKIP() << "Test crashes gtest on Emscipten";
887-
#endif
888879
if (llvm::sys::RunningOnValgrind())
889880
GTEST_SKIP() << "XFAIL due to Valgrind report";
890881
Cpp::CreateInterpreter();
@@ -1025,9 +1016,6 @@ TEST(ScopeReflectionTest, GetClassTemplateInstantiationArgs) {
10251016

10261017

10271018
TEST(ScopeReflectionTest, IncludeVector) {
1028-
#ifdef EMSCRIPTEN
1029-
GTEST_SKIP() << "Test crashes gtest on Emscipten";
1030-
#endif
10311019
if (llvm::sys::RunningOnValgrind())
10321020
GTEST_SKIP() << "XFAIL due to Valgrind report";
10331021
std::string code = R"(

unittests/CppInterOp/TypeReflectionTest.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -546,9 +546,6 @@ TEST(TypeReflectionTest, IsPODType) {
546546
}
547547

548548
TEST(TypeReflectionTest, IsSmartPtrType) {
549-
#ifdef EMSCRIPTEN
550-
GTEST_SKIP() << "Test crashes gtest on Emscipten";
551-
#endif
552549
if (llvm::sys::RunningOnValgrind())
553550
GTEST_SKIP() << "XFAIL due to Valgrind report";
554551
Cpp::CreateInterpreter();

unittests/CppInterOp/VariableReflectionTest.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ CODE
264264

265265
TEST(VariableReflectionTest, GetVariableOffset) {
266266
#ifdef EMSCRIPTEN
267-
GTEST_SKIP() << "Test crashes gtest on Emscipten";
267+
GTEST_SKIP() << "Test fails for Emscipten builds";
268268
#endif
269269
std::vector<Decl *> Decls;
270270
#define Stringify(s) Stringifyx(s)
@@ -331,9 +331,6 @@ TEST(VariableReflectionTest, GetVariableOffset) {
331331
CODE
332332

333333
TEST(VariableReflectionTest, VariableOffsetsWithInheritance) {
334-
#ifdef EMSCRIPTEN
335-
GTEST_SKIP() << "Test crashes gtest on Emscipten";
336-
#endif
337334
if (llvm::sys::RunningOnValgrind())
338335
GTEST_SKIP() << "XFAIL due to Valgrind report";
339336

0 commit comments

Comments
 (0)