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

Binary Compatibility and dynamically linked libraries #537

Closed
lkiesow opened this issue Aug 31, 2022 · 8 comments
Closed

Binary Compatibility and dynamically linked libraries #537

lkiesow opened this issue Aug 31, 2022 · 8 comments
Labels
area:backend Everything backend related area:build-system Related to building Tobira kind:improvement

Comments

@lkiesow
Copy link
Contributor

lkiesow commented Aug 31, 2022

We should probably investigate why this doesn't work. This could cause a few headaches:

Lars Kiesow

[…] since [Tobira] is a static binary + a few systemd unit files

geichelberger

It’s not entirely static. Some libs have dynamic dependencies. Compile it on CentOS8 and it’s not working on CentOS9.

@LukasKalbertodt
Copy link
Member

The problem with CentOS seems to be libssl. All dynamically linked libraries:

$ ldd tobira1.1
	linux-vdso.so.1 (0x00007ffdcfdde000)
	libssl.so.1.1 => /lib/x86_64-linux-gnu/libssl.so.1.1 (0x00007f640a354000)
	libcrypto.so.1.1 => /lib/x86_64-linux-gnu/libcrypto.so.1.1 (0x00007f640a07e000)
	libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f640a062000)
	libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f640a047000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f640a024000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f6409ed5000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f6409ecd000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f6409cdb000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f640b17b000)

I guess in the Linux world it's a religious question whether dynamic or static linking is preferred, but for ease of deployment, I would like to reduce the number of dynamically linked libraries as much as possible.

We could even get rid of libc (and friends) by using musl. It's super easy to compile a Rust project against/with musl, so that's not a problem. However, musl has a few things to keep in mind. If my memory serves me right, something about performance and DNS lookups.

@LukasKalbertodt LukasKalbertodt changed the title Binary Compatibility Binary Compatibility and dynamically linked libraries Aug 31, 2022
@LukasKalbertodt LukasKalbertodt added area:backend Everything backend related kind:improvement area:build-system Related to building Tobira labels Aug 31, 2022
@geichelberger
Copy link
Contributor

musl has performance issues:
https://www.linkedin.com/pulse/testing-alternative-c-memory-allocators-pt-2-musl-mystery-gomes

Dynamically linked libraries have benefits, e.g., you get security updates for free.

@ziegenberg
Copy link
Contributor

Disadvantages of statically linked libraries:

  • If the library needs to be updated, your application needs to be rebuilt and distributed.
  • For every used library you are now responsible for keeping an eye on relevant security updates. And with every update, you need to create a release in a timely manner.

@ziegenberg
Copy link
Contributor

Question is: why do you need libssl when I see rustls all over the place in the Cargo.toml?

@ziegenberg
Copy link
Contributor

Looks like meilisearch-sdk uses isahc which says:

Rustls support: We hope to support rustls as a TLS backend someday, it is not currently supported directly. If for some reason rustls is a hard requirement for you, you'll need to use a different HTTP client for now.

@LukasKalbertodt
Copy link
Member

LukasKalbertodt commented Sep 5, 2022

Oh hey, thanks for investigating. I had no time looking at this before. And yeah, looks like libssl is only required due to isahc due to meilisearch-sdk. However, isahc seems to almost work with rustls already: sagebind/isahc#199 They said they would release this support with 2.0, which is planned to release "soon".

Unfortunately, that doesn't really help as meilisearch_sdk would have to update their isahc version then first. The situation isn't great anyway: we already have an HTTP library in the binary, no need to also pull in isahc with curl. I am also not super happy with meilisearch-sdk anyway.
So ehm... a few different paths forward, but none is really great. The easiest is probably preparing a patch for meilisearch_sdk adding support for a different HTTP client instead of isahc.


Oh and for reference:

[libz-sys 1.1.8] cargo:rustc-link-lib=z
[openssl-sys 0.9.75] cargo:rustc-link-lib=ssl
[openssl-sys 0.9.75] cargo:rustc-link-lib=crypto

Seems like all other dynamically linked libaries are not "caused" by any dependencies, but are standard links for x86_64-unknown-linux-gnu.

@ziegenberg
Copy link
Contributor

Or just build different binaries for different platforms. That's probably the easiest and also fastest way forward.
For releases we could use the GitHub actions matrix build feature.

JulianKniephoff added a commit that referenced this issue Sep 8, 2022
CC #537 

See first commit for reasoning. This leaves Tobira only linking to
"libstd libraries" basically.
@LukasKalbertodt
Copy link
Member

With #546 I found an easy way to statically link libssl, libcrypto and libz. With that, only "std libs" are dynamically linked. These we can only get rid off by using musl and that's tracked by #116. So I'll close this issue.

@LukasKalbertodt LukasKalbertodt moved this to Done ✔️ in Tobira Sep 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:backend Everything backend related area:build-system Related to building Tobira kind:improvement
Projects
Status: Done ✔️
Development

No branches or pull requests

4 participants