Skip to content

Commit 3135805

Browse files
committed
Fix all crashing tests for emscripten build
1 parent b602c32 commit 3135805

File tree

9 files changed

+57
-54
lines changed

9 files changed

+57
-54
lines changed

include/clang/Interpreter/CppInterOp.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,12 @@ 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, void* self) const;
131131

132132
/// This function is used for debugging, it reports when the function was
133133
/// called.
134-
void ReportInvokeStart(void* result, ArgList args, void* self) const;
135-
void ReportInvokeStart(void* object, unsigned long nary,
134+
CPPINTEROP_API void ReportInvokeStart(void* result, ArgList args, void* self) const;
135+
CPPINTEROP_API void ReportInvokeStart(void* object, unsigned long nary,
136136
int withFree) const;
137137
void ReportInvokeEnd() const;
138138
public:

lib/Interpreter/CMakeLists.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,15 @@ if(EMSCRIPTEN)
129129
#FIXME: A patch is needed to llvm to remove -Wl,-z,defs since it is now recognised on emscripten. What needs to be removed is here
130130
# https://github.com/llvm/llvm-project/blob/128e2e446e90c3b1827cfc7d4d19e3c0976beff3/llvm/cmake/modules/HandleLLVMOptions.cmake#L318 . The PR to do try to do this is here
131131
# https://github.com/llvm/llvm-project/pull/123396
132-
set_target_properties(clangCppInterOp PROPERTIES
133-
NO_SONAME 1
134-
LINK_FLAGS "-s WASM_BIGINT -s SIDE_MODULE=1 ${SYMBOLS_LIST}"
132+
set_target_properties(clangCppInterOp
133+
PROPERTIES NO_SONAME 1
135134
)
135+
target_link_options(clangCppInterOp
136+
PRIVATE "SHELL: -s WASM_BIGINT"
137+
PRIVATE "SHELL: -s SIDE_MODULE=1"
138+
PRIVATE "SHELL: ${SYMBOLS_LIST}"
139+
)
140+
136141
if (CPPINTEROP_ENABLE_TESTING)
137142
# When compiling Emscripten tests the shared library it links to is expected to be in the same folder as the compiled Javascript
138143
add_custom_command(TARGET clangCppInterOp POST_BUILD

lib/Interpreter/CppInterOp.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ namespace Cpp {
100100
static clang::ASTContext& getASTContext() { return getSema().getASTContext(); }
101101

102102
#define DEBUG_TYPE "jitcall"
103-
bool JitCall::AreArgumentsValid(void* result, ArgList args,
103+
CPPINTEROP_API bool JitCall::AreArgumentsValid(void* result, ArgList args,
104104
void* self) const {
105105
bool Valid = true;
106106
if (Cpp::IsConstructor(m_FD)) {
@@ -130,7 +130,7 @@ namespace Cpp {
130130
return Valid;
131131
}
132132

133-
void JitCall::ReportInvokeStart(void* result, ArgList args, void* self) const{
133+
CPPINTEROP_API void JitCall::ReportInvokeStart(void* result, ArgList args, void* self) const{
134134
std::string Name;
135135
llvm::raw_string_ostream OS(Name);
136136
auto FD = (const FunctionDecl*) m_FD;
@@ -145,7 +145,7 @@ namespace Cpp {
145145
);
146146
}
147147

148-
void JitCall::ReportInvokeStart(void* object, unsigned long nary,
148+
CPPINTEROP_API void JitCall::ReportInvokeStart(void* object, unsigned long nary,
149149
int withFree) const {
150150
std::string Name;
151151
llvm::raw_string_ostream OS(Name);

lib/Interpreter/exports.ld

Lines changed: 9 additions & 0 deletions
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

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,21 @@ 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+
target_compile_options(CppInterOpTests
29+
PUBLIC "SHELL: -fexceptions"
30+
)
31+
32+
target_link_options(CppInterOpTests
33+
PUBLIC "SHELL: -fexceptions"
34+
PUBLIC "SHELL: -s MAIN_MODULE=1"
35+
PUBLIC "SHELL: -s WASM=1"
36+
PUBLIC "SHELL: -s WASM_BIGINT"
37+
PUBLIC "SHELL: -s ASSERTIONS=0"
38+
PUBLIC "SHELL: -s ALLOW_MEMORY_GROWTH=1"
39+
PUBLIC "SHELL: -s EXIT_RUNTIME=1"
40+
PUBLIC "SHELL: -s STACK_SIZE=32mb"
41+
PUBLIC "SHELL: -s INITIAL_MEMORY=128mb"
42+
PUBLIC "SHELL: --preload-file ${SYSROOT_PATH}/include@/include"
3843
)
3944
endif()
4045

@@ -69,16 +74,21 @@ target_link_libraries(DynamicLibraryManagerTests
6974
)
7075

7176
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"
77+
target_compile_options(DynamicLibraryManagerTests
78+
PUBLIC "SHELL: -fexceptions"
79+
)
80+
81+
target_link_options(DynamicLibraryManagerTests
82+
PUBLIC "SHELL: -fexceptions"
83+
PUBLIC "SHELL: -s MAIN_MODULE=1"
84+
PUBLIC "SHELL: -s WASM=1"
85+
PUBLIC "SHELL: -s WASM_BIGINT"
86+
PUBLIC "SHELL: -s ASSERTIONS=0"
87+
PUBLIC "SHELL: -s ALLOW_MEMORY_GROWTH=1"
88+
PUBLIC "SHELL: -s EXIT_RUNTIME=1"
89+
PUBLIC "SHELL: -s STACK_SIZE=32mb"
90+
PUBLIC "SHELL: -s INITIAL_MEMORY=128mb"
91+
PUBLIC "SHELL: --preload-file ${SYSROOT_PATH}/include@/include"
8292
)
8393
endif()
8494

unittests/CppInterOp/FunctionReflectionTest.cpp

Lines changed: 3 additions & 6 deletions
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

Lines changed: 0 additions & 12 deletions
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

Lines changed: 0 additions & 3 deletions
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

Lines changed: 1 addition & 4 deletions
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)