Skip to content
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

Link libc++ statically to reduce runtime dependency of wamrc #3331

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions build-scripts/build_llvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def build_llvm(llvm_dir, platform, backends, projects, use_clang=False, extra_fl
"-DLLVM_INCLUDE_UTILS:BOOL=OFF",
"-DLLVM_INCLUDE_TESTS:BOOL=OFF",
"-DLLVM_OPTIMIZED_TABLEGEN:BOOL=ON",
"-DLLVM_STATIC_LINK_CXX_STDLIB=ON",
]

# ccache is not available on Windows
Expand Down
6 changes: 6 additions & 0 deletions wamr-compiler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,12 @@ if (NOT MSVC)
target_link_libraries (wamrc ssp.a ws2_32)
else()
target_link_libraries (wamrc -ldl)
# Link libc++ statically to reduce the runtime dependency
target_link_libraries (wamrc -static-libstdc++)
# If not on macOS, link libgcc statically
if (NOT APPLE)
target_link_libraries (wamrc -static-libgcc)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this configurable?
I think static link such libraries is not a very common requirement.

endif()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which instance of these libraries are used by shared libraries loaded by --native-lib?
is it ok to have multiple copies of these libraries in a process?

Copy link
Collaborator Author

@no1wudi no1wudi Apr 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure which copy will be used in the native lib, but it seems OK since I have used a cxx based custom compiler plugin with prebuilt wasi-sdk, it works fine without special action, please refer to: https://clang.llvm.org/docs/ClangPlugins.html

I guess it use the dynamic libc++ from system instead of the static version in the clang/wamrc

endif()
else()
target_link_libraries (wamrc aotclib vmlib ${lib_lldb} ${WAMRC_LINK_LLVM_LIBS} ${lib_ubsan}
Expand Down
Loading