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

Conversation

no1wudi
Copy link
Collaborator

@no1wudi no1wudi commented Apr 18, 2024

No description provided.

@no1wudi no1wudi requested a review from wenyongh April 18, 2024 01:43
@no1wudi no1wudi force-pushed the wamrc branch 2 times, most recently from cb7047d to a2528d0 Compare April 18, 2024 02:06
# If not on macOS, link libgcc statically
if (NOT APPLE)
target_link_libraries (wamrc -static-libgcc)
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

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.

@no1wudi
Copy link
Collaborator Author

no1wudi commented Apr 18, 2024

@xujuntwt95329 @yamt I'm trying to make wamrc compatible with different linux distributions like https://github.com/WebAssembly/wasi-sdk/releases.

I thinks it's useful since we also provide prebuilt binary for wamrc.

@wenyongh
Copy link
Contributor

@xujuntwt95329 @yamt I'm trying to make wamrc compatible with different linux distributions like https://github.com/WebAssembly/wasi-sdk/releases.

I thinks it's useful since we also provide prebuilt binary for wamrc.

@no1wudi it sounds good to me, but it increases the wamrc binary size. Could we link the static gcc/g++ lib only for the CI prebuilt binaries and keep it unchanged for normal compilation? Not sure whether it is easy to achieve that?

@lum1n0us
Copy link
Collaborator

I guess libc++ is a basement for every platform. If there are compatible issues with a dynamic libc++ library, it highly likely suggests there is a real compatible issue with the platform(via libc++). Using a static library may let wamrc run, but also covers some real problems, I am afraid.

@no1wudi
Copy link
Collaborator Author

no1wudi commented Apr 19, 2024

Please refer to widely used wasi-sdk and llvm does if you have any concerns:
https://github.com/llvm/llvm-project/blob/de3e4a9dfe89dfc0a4d6d5e0891c542f6c82ca57/llvm/cmake/modules/HandleLLVMStdlib.cmake#L35

https://github.com/WebAssembly/wasi-sdk/blob/99abb024209dc7a9a8d8f3eb6d03908a18bb0594/Makefile#L84

Static link stdc++ should be except increase the binary size, the real problem is glibc, it's can not be linked statically.

The wasi-sdk build the toolchain on older version system (glibc, Ubuntu-18), so if glibc version in your system higher than it then you can run it.

@yamt
Copy link
Collaborator

yamt commented Apr 19, 2024

Please refer to widely used wasi-sdk and llvm does if you have any concerns: https://github.com/llvm/llvm-project/blob/de3e4a9dfe89dfc0a4d6d5e0891c542f6c82ca57/llvm/cmake/modules/HandleLLVMStdlib.cmake#L35

https://github.com/WebAssembly/wasi-sdk/blob/99abb024209dc7a9a8d8f3eb6d03908a18bb0594/Makefile#L84

Static link stdc++ should be except increase the binary size, the real problem is glibc, it's can not be linked statically.

The wasi-sdk build the toolchain on older version system (glibc, Ubuntu-18), so if glibc version in your system higher than it then you can run it.

i can understand about libstdc++.
but do you have any specific concerns about libgcc?

also, can you answer this question? #3331 (comment)

@no1wudi
Copy link
Collaborator Author

no1wudi commented Apr 19, 2024

Please refer to widely used wasi-sdk and llvm does if you have any concerns: https://github.com/llvm/llvm-project/blob/de3e4a9dfe89dfc0a4d6d5e0891c542f6c82ca57/llvm/cmake/modules/HandleLLVMStdlib.cmake#L35
https://github.com/WebAssembly/wasi-sdk/blob/99abb024209dc7a9a8d8f3eb6d03908a18bb0594/Makefile#L84
Static link stdc++ should be except increase the binary size, the real problem is glibc, it's can not be linked statically.
The wasi-sdk build the toolchain on older version system (glibc, Ubuntu-18), so if glibc version in your system higher than it then you can run it.

i can understand about libstdc++. but do you have any specific concerns about libgcc?

also, can you answer this question? #3331 (comment)

Maybe libgcc is not a problem for this case, but I'm not sure will it lead to compatibility issue in early test so it static linked here, we can remove it after more test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants