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

C API: dylib on macOS has ID with rpath #1297

Open
turbolent opened this issue Nov 7, 2024 · 3 comments
Open

C API: dylib on macOS has ID with rpath #1297

turbolent opened this issue Nov 7, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@turbolent
Copy link
Contributor

turbolent commented Nov 7, 2024

Describe the bug

Similar to bytecodealliance/wasmtime#984:

On macOS, the built dylib has an ID with a relative path, @rpath:

$ otool -L wasmi/lib/libwasmi.dylib
wasmi/lib/libwasmi.dylib:
	@rpath/libwasmi.dylib (compatibility version 0.0.0, current version 0.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1351.0.0

Loading the dynamic library then results in

Library not loaded: @rpath/libwasmi.dylib

Reason: no LC_RPATH's found

Expected behavior

Loading the built dynamic library should work.

To Reproduce

  1. What Wasmi version was used?

68205d4

  1. Bug occurs on Wasmi CLI or Wasmi library?

Wasmi C library

  1. Ideally please provide minified Wasm (.wasm) or Wat (.wat) file to reproduce.

N/A

  1. Follow steps in https://lib.rs/crates/wasmi_c_api_impl

  2. Link against the dylib and run the binary

@turbolent turbolent added the bug Something isn't working label Nov 7, 2024
@turbolent
Copy link
Contributor Author

I've solved this for now by post-processing the library manually with e.g.

$ install_name_tool -id libwasmi.dylib libwasmi.dylib

wasmtime has a build step to do this automatically, this could be maybe adopted here:
https://github.com/bytecodealliance/wasmtime/blob/06377eb08a649619cc8ac9a934cb3f119017f3ef/crates/c-api/CMakeLists.txt#L108-L114

@Robbepop
Copy link
Member

Robbepop commented Nov 7, 2024

@turbolent Thanks a lot for the issue report! Since you already know what needs to be done (e.g. Wasmtime's solution), would you be willing to open a PR? :)

@turbolent
Copy link
Contributor Author

It looks like wasmi's CMake configuration already has code for this:

if(WASMI_TARGET MATCHES "darwin")
set(INSTALLED_LIB "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/libwasmi.dylib")
install(
FILES "${INSTALLED_LIB}"
DESTINATION "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}"
COMPONENT Runtime
)
if(NOT CMAKE_INSTALL_NAME_TOOL)
message(WARNING "CMAKE_INSTALL_NAME_TOOL is not set. LC_ID_DYLIB for libwasmi.dylib will not be set.")
else()
set(install_name_tool_cmd
"${CMAKE_INSTALL_NAME_TOOL}"
"-id"
"@rpath/libwasmi.dylib"
"${INSTALLED_LIB}"
)
install(CODE "execute_process(COMMAND ${install_name_tool_cmd})")
endif()
endif()

I'm not familiar enough with the macOS linker to say what the behaviour should be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants