-
Notifications
You must be signed in to change notification settings - Fork 103
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
Upgrade Rust to >= 1.56.0 #277
Comments
Turns out there are two test modes (see The linkage error in Rust >= 1.56.0 (LLVM 13) only occurs for the package list mode. If we change the test mode, we seem to be fine. |
Weird. |
What I figured out along the way:
So overall I would not bet money on the existence of a functional CosmWasm static library and an Alpine build. |
Yea, what I am actually thinking - in general the fact that .a file works is very dependent on mangling. If you have same compiler it works. But it may not work for C++/C++ - basically you cannot use mingw compiled libraries in msvc, it wont link (ant it is not matter of luck - it would never work, those two have fundamentally different mangling - or at least historically had). Otherwise it is matter of knowledge of one compiler about how the other mangles. In particular - if you use bindgen to bridge Rust with C++, it basically knows how gcc and msvc mangles. I am not sure how does it work for marrying Rust with Go, I don't have such experience. But there is one ABI which is very much stable and well defined for static libraries, and it is C. There is a reason, why bindings to tensorflow are used using its C interfaces instead of native C++ - because C ABI is stable and it just works. I am pretty sure that there is notion of exporting Go functions/structures as C does, and use C functions/structures in go. Using such C interfaces as bridge is tedious, but it would probably solve any linkage level problems. I have a little experience with that bridging C++ with Rust, but no experience with Go at all. |
We use a C interface and all exported functions are non-mangeled like this one: Lines 27 to 34 in 36b28ed
|
I am running into the next problem. When I use the current builders (Rust 1.55.0), I get a static binary for the demo build here. When I upgrade to the new builders (locally), this binary becomes dynamically linked and requires libgcc at runtime on Alpine, which is not installed by default. Not sure why
and
|
You can install |
I debugged all the internal build and link commands that
I wonder if we can find out where the |
For symbols, Libgcc should be around, but .a files / static linking will require a static version of it as well, AFAIK. |
Do you want to generate a static or dynamic version of wasmvm? |
I recall passing |
I just found this in the GCC link options:
But I think it's super strange if the default value changed by a Rust update. Maybe the gcc version is different because of a new build of the image. |
Maybe you are using a different (non-GNU) linker now (for whatever reason)? |
I tested various configurations now with golang:1.17.5-alpine and golang:1.17.6-alpine. The linker is I can get libgcc statically linked with Turns out it is very hard to get a fully statically linked binary in Go. No idea why this just works automatically as long as Rust 1.55.0 is used. |
Maybe we should stop thinking about this as a static build but as a muslc build and there is no real reason why this needs to be static as long as it runs on Alpine machines. |
Note to myself: https://dubo-dubon-duponey.medium.com/a-beginners-guide-to-cross-compiling-static-cgo-pie-binaries-golang-1-16-792eea92d5aa discusses the topic and contains a bunch of go build option combinations I can try. |
I got the static build to work with # See "2. If you really need CGO, but not netcgo" in https://dubo-dubon-duponey.medium.com/a-beginners-guide-to-cross-compiling-static-cgo-pie-binaries-golang-1-16-792eea92d5aa
# See also https://github.com/rust-lang/rust/issues/78919 for why we need -Wl,-z,muldefs
go build -x -ldflags "-linkmode=external -extldflags '-Wl,-z,muldefs -static'" -tags muslc \
-o demo ./cmd Looking at this now it is really a surprise how we got static builds before without telling the linker. Unfortunately the node builders will have to juggle with those explicit flags from now on in order to produce static builds. |
Also interesting for advanced Go binary builds: https://wiki.archlinux.org/title/Go_package_guidelines |
When upgrading Rust to 1.56.0 or 1.57.0 in the builder images, we get linkage errors when trying to link the static library (.a) to a Go project (
go build
andgo test
) on Alpine Linux. The error message indicates problems regarding position independent code.I don't understand the problem. It might be caused by the LLVM 13 upgrade that is part of Rust 1.56. At least I did not find anything else.
Using Rust 1.55.0 for now.
The text was updated successfully, but these errors were encountered: