Skip to content

Commit 40e0d54

Browse files
authored
Try to use a linker script to export symbols from shared library
1 parent 276052a commit 40e0d54

File tree

4 files changed

+73
-69
lines changed

4 files changed

+73
-69
lines changed

.github/workflows/MacOS.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,7 @@ jobs:
389389
-DLLVM_ENABLE_WERROR=On \
390390
../
391391
fi
392-
cmake --build . --target check-cppinterop --parallel ${{ env.ncpus }} || true
393-
cat /Users/runner/work/CppInterOp/CppInterOp/build/unittests/googletest-prefix/src/googletest-stamp/googletest-build-*.log
392+
cmake --build . --target check-cppinterop --parallel ${{ env.ncpus }}
394393
cd ..
395394
# We need CB_PYTHON_DIR later
396395
echo "CB_PYTHON_DIR=$CB_PYTHON_DIR" >> $GITHUB_ENV

lib/Interpreter/CMakeLists.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,9 @@ endif()
115115
)
116116

117117
if(EMSCRIPTEN)
118-
# Read the undefined symbols from the text file
119-
file(READ "${CMAKE_SOURCE_DIR}/lib/Interpreter/undefined_symbols.txt" SYMBOLS_LIST)
118+
# Specify the path to your linker script
119+
set(LINKER_SCRIPT_PATH "${CMAKE_SOURCE_DIR}/lib/Interpreter/exports.ld")
120120

121-
# Replace newlines with spaces
122-
string(REPLACE "\n" " " SYMBOLS_LIST "${SYMBOLS_LIST}")
123121
#FIXME: Setting no_soname=1 is needed until https://github.com/emscripten-core/emscripten/blob/ac676d5e437525d15df5fd46bc2c208ec6d376a3/cmake/Modules/Platform/Emscripten.cmake#L36
124122
# is patched out of emsdk, as --soname is not recognised by emscripten. A PR to do this has been done here https://github.com/emscripten-core/emscripten/pull/23453
125123
#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
@@ -128,10 +126,14 @@ if(EMSCRIPTEN)
128126
set_target_properties(clangCppInterOp PROPERTIES
129127
NO_SONAME 1
130128
COMPILE_FLAGS "-s SIDE_MODULE=1"
131-
LINK_FLAGS "-s WASM_BIGINT -s SIDE_MODULE=1 ${SYMBOLS_LIST}"
129+
LINK_FLAGS "-s WASM_BIGINT -s SIDE_MODULE=1"
132130
SUFFIX ".wasm"
133131
)
134132

133+
target_link_options(clangCppInterOp PRIVATE
134+
-T${LINKER_SCRIPT_PATH}
135+
)
136+
135137
add_custom_command(TARGET clangCppInterOp POST_BUILD
136138
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:clangCppInterOp> ${CMAKE_BINARY_DIR}/unittests/CppInterOp/
137139
)

lib/Interpreter/exports.ld

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
EXPORTS
2+
{
3+
_ZN4llvm3sys2fs17getMainExecutableEPKcPv;
4+
_ZN4llvm3sys4path11parent_pathENS_9StringRefENS1_5StyleE;
5+
_ZN3Cpp11GetOperatorEPvNS_8OperatorERNSt3__26vectorIS0_NS2_9allocatorIS0_EEEENS_13OperatorArityE;
6+
_ZN4llvm11raw_ostream14flush_nonemptyEv;
7+
_ZN4llvm11raw_ostream16SetBufferAndModeEPcmNS0_10BufferKindE;
8+
_ZN4llvm11raw_ostream5writeEPKcm;
9+
_ZN4llvm11raw_ostreamD2Ev;
10+
_ZN4llvm13StringMapImpl11RehashTableEj;
11+
_ZN4llvm13StringMapImpl15LookupBucketForENS_9StringRefEj;
12+
_ZN4llvm13StringMapImpl4hashENS_9StringRefE;
13+
_ZN4llvm15SmallVectorBaseIjE8grow_podEPvmm;
14+
_ZN4llvm15allocate_bufferEmm;
15+
_ZN4llvm21logAllUnhandledErrorsENS_5ErrorERNS_11raw_ostreamENS_5TwineE;
16+
_ZN4llvm25llvm_unreachable_internalEPKcS1_j;
17+
_ZN4llvm3sys17RunningOnValgrindEv;
18+
_ZN4llvm3sys4path6appendERNS_15SmallVectorImplIcEERKNS_5TwineES7_S7_S7_;
19+
_ZN4llvm4dbgsEv;
20+
_ZN4llvm4errsEv;
21+
_ZN4llvm5APIntC1EjNS_8ArrayRefIyEE;
22+
_ZN5clang10ASTContext19createMangleContextEPKNS_10TargetInfoE;
23+
_ZN5clang11DeclContext7classofEPKNS_4DeclE;
24+
_ZN5clang11Interpreter19getCompilerInstanceEv;
25+
_ZN5clang11Interpreter5ParseEN4llvm9StringRefE;
26+
_ZN5clang11Interpreter6createENSt3__210unique_ptrINS_16CompilerInstanceENS1_14default_deleteIS3_EEEE;
27+
_ZN5clang11Interpreter7ExecuteERNS_22PartialTranslationUnitE;
28+
_ZNK5clang4Sema15getStdNamespaceEv;
29+
_ZNK5clang4Type27getUnqualifiedDesugaredTypeEv;
30+
_ZNK5clang7TagType7getDeclEv;
31+
_ZNK5clang7VarDecl28isThisDeclarationADefinitionERNS_10ASTContextE;
32+
_ZTVN4llvm18raw_string_ostreamE;
33+
clang_Interpreter_dispose;
34+
clang_Interpreter_getClangInterpreter;
35+
clang_Interpreter_takeInterpreterAsPtr;
36+
clang_createInterpreterFromRawPtr;
37+
clang_getComplexType;
38+
clang_getTypeAsString;
39+
clang_instantiateTemplate;
40+
_ZN5clang13MangleContext10mangleNameENS_10GlobalDeclERN4llvm11raw_ostreamE;
41+
_ZN5clang13MangleContext20shouldMangleDeclNameEPKNS_9NamedDeclE;
42+
_ZN5clang26IncrementalCompilerBuilder9CreateCppEv;
43+
_ZN5clang4Decl17castToDeclContextEPKS0_;
44+
_ZNK3Cpp7JitCall17AreArgumentsValidEPvNS0_7ArgListES1_;
45+
_ZNK3Cpp7JitCall17ReportInvokeStartEPvNS0_7ArgListES1_;
46+
_ZNK3Cpp7JitCall17ReportInvokeStartEPvmi;
47+
_ZNK4llvm5APInt13compareSignedERKS0_;
48+
_ZNK4llvm5APInt4sextEj;
49+
_ZNK4llvm5APInt4zextEj;
50+
_ZNK4llvm5APInt7compareERKS0_;
51+
_ZNK4llvm5Error19fatalUncheckedErrorEv;
52+
_ZNK5clang10ASTContext14getComplexTypeENS_8QualTypeE;
53+
_ZNK5clang10ASTContext19getTypeDeclTypeSlowEPKNS_8TypeDeclE;
54+
_ZNK5clang10RecordDecl19isInjectedClassNameEv;
55+
_ZNK5clang11DeclContext11decls_beginEv;
56+
_ZNK5clang11DeclContext6lookupENS_15DeclarationNameE;
57+
_ZNK5clang12FunctionDecl29getTemplateSpecializationArgsEv;
58+
_ZNK5clang12FunctionDecl31getTemplateInstantiationPatternEb;
59+
_ZNK5clang17ClassTemplateDecl18getSpecializationsEv;
60+
_ZNK5clang29VarTemplateSpecializationDecl22getSpecializedTemplateEv;
61+
_ZNK5clang4Decl13getASTContextEv;
62+
_ZNK5clang4Decl15hasDefiningAttrEv;
63+
_ZNK5clang4Decl8getAttrsEv;
64+
_ZN4llvm3sys2fs6accessERKNS_5TwineENS1_10AccessModeE;
65+
}

lib/Interpreter/undefined_symbols.txt

Lines changed: 0 additions & 62 deletions
This file was deleted.

0 commit comments

Comments
 (0)