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

libunwind warning when compiling a wasmtime project against musl #8897

Closed
pimeys opened this issue Jul 3, 2024 · 9 comments · Fixed by #9479
Closed

libunwind warning when compiling a wasmtime project against musl #8897

pimeys opened this issue Jul 3, 2024 · 9 comments · Fixed by #9479
Labels
bug Incorrect behavior in the current implementation that needs fixing

Comments

@pimeys
Copy link

pimeys commented Jul 3, 2024

Test Case

Load any wasm component (wasip2) with wasmtime 21.0.1, if you compile the rust host against musl, a warning is printed to the terminal:

libunwind: __unw_add_dynamic_fde: bad fde: FDE is really a CIE

The component and the whole system works correctly, but the log is confusing and there's no way to tell if something is actually broken.

Expected Results

It should work as with builds against glibc, or builds on macos with no libunwind warning printed to the terminal.

Actual Results

I can't seem to find anything being broken really...

Versions and Environment

Wasmtime version or commit: 21.0.1

Operating system: nixos linux unstable

Architecture: x86_64-unknown-linux-musl for the host and wasm32-wasip1 for the guest.

Extra Info

I found issues from the past, such as

wasmerio/wasmer#2150
#1904

But nothing more recent...

@pimeys pimeys added the bug Incorrect behavior in the current implementation that needs fixing label Jul 3, 2024
@fitzgen
Copy link
Member

fitzgen commented Jul 3, 2024

Seems like a regression of #1904 and #1914.

FWIW, we do not rely on the system's libunwind for correctness, we only emit .eh_frame and call __register_frame for the benefit of tools like profilers. You can also turn this off via https://docs.rs/wasmtime/latest/wasmtime/struct.Config.html#method.native_unwind_info

IIRC, different libc implementations have different signatures for __register_frame, and this might be what we are running into here. If so, that isn't really something we can fix...

@fitzgen
Copy link
Member

fitzgen commented Jul 3, 2024

IIRC, different libc implementations have different signatures for __register_frame, and this might be what we are running into here. If so, that isn't really something we can fix...

Context:

/// There are two primary unwinders on Unix platforms: libunwind and libgcc.
///
/// Unfortunately their interface to `__register_frame` is different. The
/// libunwind library takes a pointer to an individual FDE while libgcc takes a
/// null-terminated list of FDEs. This means we need to know what unwinder
/// is being used at runtime.
///
/// This detection is done currently by looking for a libunwind-specific symbol.
/// This specific symbol was somewhat recommended by LLVM's
/// "RTDyldMemoryManager.cpp" file which says:
///
/// > We use the presence of __unw_add_dynamic_fde to detect libunwind.
///
/// I'll note that there's also a different libunwind project at
/// https://www.nongnu.org/libunwind/ but that doesn't appear to have
/// `__register_frame` so I don't think that interacts with this.

@pimeys
Copy link
Author

pimeys commented Jul 3, 2024

Is there any way to hide this message or will it break any functionality?

@fitzgen
Copy link
Member

fitzgen commented Jul 3, 2024

I believe it is the libunwind implementation printing the message, not Wasmtime.

You can turn off Wasmtime's generation of unwind info via https://docs.rs/wasmtime/latest/wasmtime/struct.Config.html#method.native_unwind_info which should make it so that the message stops printing.

@pimeys
Copy link
Author

pimeys commented Jul 4, 2024

Yeah, this solved it for us. I don't really know should I close this issue or not. It's kind of still an issue if wanting to use the native unwind info, but also wanting to target musl.

@alexcrichton
Copy link
Member

This cropping up again is a consequence of #8028 and how dlsym looks like it always returns NULL in a static build. This means that if you build a static binary, which I believe you're doing here, then it'll always think it's using libgcc which is incorrect.

So effectively this boils down to the mechanism used to detect libgcc-vs-libunwind. Another possible option is to use weak symbols but that's not possible in stable Rust so would require some C trickery to do that. I don't know of other options myself.

@bjorn3
Copy link
Contributor

bjorn3 commented Jul 8, 2024

You can use weak symbols from inline asm, right? Would require a separate implementation for each architecture though.

@alexcrichton
Copy link
Member

Oh? I had no idea! If that works that might be a reasonable way to go here

@kate-goldenring
Copy link

We are encountering this in Spin with Wasmtime v25.0.0: fermyon/spin#2889

alexcrichton added a commit to alexcrichton/wasmtime that referenced this issue Oct 16, 2024
github-merge-queue bot pushed a commit that referenced this issue Oct 22, 2024
* Switch libunwind detection to using weak symbols

This is an attempt to resolve #8897.

* Fix warnings

* Run clang-format
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Incorrect behavior in the current implementation that needs fixing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants