-
Notifications
You must be signed in to change notification settings - Fork 627
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
Set compile symbol visibility to hidden in cmake #3655
Set compile symbol visibility to hidden in cmake #3655
Conversation
@bnason-nf @wenyongh It will fail $ cmake -S . -B build-shared -DWAMR_BUILD_SHARED=1
$ cmake --build build-shared
/usr/bin/ld: CMakeFiles/iwasm.dir/main.c.o: in function `libc_wasi_init':
main.c:(.text.libc_wasi_init+0x32): undefined reference to `wasm_runtime_set_wasi_args'
/usr/bin/ld: main.c:(.text.libc_wasi_init+0x4b): undefined reference to `wasm_runtime_set_wasi_addr_pool'
/usr/bin/ld: main.c:(.text.libc_wasi_init+0x66): undefined reference to `wasm_runtime_set_wasi_ns_lookup_pool'
/usr/bin/ld: CMakeFiles/iwasm.dir/main.c.o: in function `load_native_lib':
main.c:(.text.load_native_lib+0x10): undefined reference to `wasm_runtime_malloc'
/usr/bin/ld: main.c:(.text.load_native_lib+0xe2): undefined reference to `wasm_runtime_register_natives'
/usr/bin/ld: main.c:(.text.load_native_lib+0x10e): undefined reference to `bh_log'
/usr/bin/ld: main.c:(.text.load_native_lib+0x133): undefined reference to `wasm_runtime_free'
/usr/bin/ld: main.c:(.text.load_native_lib+0x183): undefined reference to `bh_log'
/usr/bin/ld: main.c:(.text.load_native_lib+0x1a9): undefined reference to `bh_log'
/usr/bin/ld: main.c:(.text.load_native_lib+0x1ce): undefined reference to `bh_log'
/usr/bin/ld: main.c:(.text.load_native_lib+0x1f4): undefined reference to `bh_log'
/usr/bin/ld: CMakeFiles/iwasm.dir/main.c.o: in function `main':
main.c:(.text.startup.main+0x186): undefined reference to `wasm_runtime_full_init'
/usr/bin/ld: main.c:(.text.startup.main+0x197): undefined reference to `bh_log_set_verbose_level'
/usr/bin/ld: main.c:(.text.startup.main+0x203): undefined reference to `wasm_runtime_is_xip_file'
/usr/bin/ld: main.c:(.text.startup.main+0x22c): undefined reference to `wasm_runtime_load'
/usr/bin/ld: main.c:(.text.startup.main+0x26a): undefined reference to `wasm_runtime_instantiate'
/usr/bin/ld: main.c:(.text.startup.main+0x2b0): undefined reference to `wasm_application_execute_func'
/usr/bin/ld: main.c:(.text.startup.main+0x2b8): undefined reference to `wasm_runtime_get_exception'
/usr/bin/ld: main.c:(.text.startup.main+0x2d9): undefined reference to `wasm_runtime_deinstantiate'
/usr/bin/ld: main.c:(.text.startup.main+0x2e3): undefined reference to `wasm_runtime_unload'
/usr/bin/ld: main.c:(.text.startup.main+0x2f7): undefined reference to `wasm_runtime_free'
/usr/bin/ld: main.c:(.text.startup.main+0x33c): undefined reference to `wasm_runtime_free'
/usr/bin/ld: main.c:(.text.startup.main+0x351): undefined reference to `wasm_runtime_unregister_natives'
/usr/bin/ld: main.c:(.text.startup.main+0x36e): undefined reference to `bh_log'
/usr/bin/ld: main.c:(.text.startup.main+0x378): undefined reference to `wasm_runtime_destroy'
/usr/bin/ld: main.c:(.text.startup.main+0x53d): undefined reference to `os_mmap'
/usr/bin/ld: main.c:(.text.startup.main+0x55e): undefined reference to `b_memcpy_s'
/usr/bin/ld: main.c:(.text.startup.main+0x566): undefined reference to `wasm_runtime_free'
/usr/bin/ld: main.c:(.text.startup.main+0x6d5): undefined reference to `wasm_application_execute_func'
/usr/bin/ld: main.c:(.text.startup.main+0x6dd): undefined reference to `wasm_runtime_get_exception'
/usr/bin/ld: main.c:(.text.startup.main+0x6f9): undefined reference to `os_munmap'
/usr/bin/ld: main.c:(.text.startup.main+0x75c): undefined reference to `wasm_runtime_get_wasi_exit_code'
/usr/bin/ld: main.c:(.text.startup.main+0x7ef): undefined reference to `wasm_application_execute_main'
/usr/bin/ld: main.c:(.text.startup.main+0x80d): undefined reference to `wasm_runtime_free'
/usr/bin/ld: main.c:(.text.startup.main+0x84d): undefined reference to `bh_log'
/usr/bin/ld: main.c:(.text.startup.main+0x884): undefined reference to `wasm_runtime_get_version'
/usr/bin/ld: CMakeFiles/iwasm.dir/workspaces/wasm-micro-runtime/core/shared/utils/uncommon/bh_read_file.c.o: in function `bh_read_file_to_buffer':
bh_read_file.c:(.text.bh_read_file_to_buffer+0x62): undefined reference to `wasm_runtime_malloc'
/usr/bin/ld: bh_read_file.c:(.text.bh_read_file_to_buffer+0x113): undefined reference to `wasm_runtime_free'
collect2: error: ld returned 1 exit status
gmake[2]: *** [CMakeFiles/iwasm.dir/build.make:134: iwasm] Error 1
gmake[2]: Leaving directory '/workspaces/wasm-micro-runtime/product-mini/platforms/linux/build-shared'
gmake[1]: *** [CMakeFiles/Makefile2:99: CMakeFiles/iwasm.dir/all] Error 2
gmake[1]: Leaving directory '/workspaces/wasm-micro-runtime/product-mini/platforms/linux/build-shared'
gmake: *** [Makefile:149: all] Error 2 |
i guess you need attribute((visibility("default"))) for WASM_RUNTIME_API_EXTERN. @bnason-nf have you tested your change at all? |
Hi @yamt, thanks for finding this, I wasn't aware of it because I almost exclusively use WAMR in static build mode. It looks like the fix might be pretty simple:
However, that still leaves these functions undefined: |
why do you care the visibility setting then?
i don't have an answer. |
The situation I encountered where this mattered was when linking wamr into a shared library. This shared library had default visibility, which then exposed all of the wamr functions to users of the shared library. In this particular application, there was another shared library that was also exposing some of the same functions that wamr was exposing, such as |
I guess there are two cases need to handle differently.
174 │ target_link_libraries(iwasm
175 ~ │ PRIVATE
176 ~ │ $<$<BOOL:${WAMR_BUILD_SHARED}>:libiwasm> $<$<NOT:$<BOOL:${WAMR_BUILD_SHARED}>>:vmlib>
177 ~ │ ${LLVM_AVAILABLE_LIBS}
178 ~ │ ${UV_A_LIBS}
179 ~ │ -lm
180 ~ │ -ldl
181 ~ │ -lpthread
182 │ )
Therefore, a suggestion is: keep the change in CMakeLists.txt at the root, but revert the change in product-mini/platforms/linux/CMakeLists.txt. And suggest people to use CMakeLists.txt at the root to integrate WAMR. |
I'm fine with that. @wenyongh are you ok with that suggestion? You requested the product-mini change: |
The main.c of windows also calls these APIs. I think they are part of APIs in the core/shared/platform/utils and core/shared/platform/include. We haven't discussed whether to expose these APIs in the shared lib before. It is difficult to avoid calling these APIs in product-mini's main.c, maybe we can also expose part of these APIs e.g., in wasm_export.h or another header file, for easier integration? But per @lum1n0us's suggestion, we had better revert CMakeLists.txt in product-mini first. |
Agree, let's revert CMakeLists.txt in product-mini first. |
Reverts commit 6d8d60d: "Set linux iwasm default visibility to hidden also" Addresses comments for pull request bytecodealliance#3655.
Thanks, the pull request for this is #3691. |
how does it work w/o dllexport on windows? |
The windows product-mini's iwasm links libvmlib.a instead of libiwasm.dll. The APIs in core/shared are not exported in libiwasm.dll, I used |
ok. thank you for explanation. |
This was originally fixed in bytecodealliance#3655, but regressed in bytecodealliance#3762 which removed the -fvisibility=hidden flag from the CMakeLists.txt file. This also removes extraneous ending whitespace from the file.
No description provided.