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

Dynamic linking zlib for Linux #118

Open
rgithubli opened this issue Apr 27, 2023 · 7 comments
Open

Dynamic linking zlib for Linux #118

rgithubli opened this issue Apr 27, 2023 · 7 comments
Assignees

Comments

@rgithubli
Copy link
Contributor

rgithubli commented Apr 27, 2023

Seeking for feedback

Let us know if you have concerns on this change and how we can improve.

Changes

Corretto now uses system zlib rather than bundled zlib.

In the past, Corretto would bundle zlib (use libz.so built from the zlib bundled in JDK source), for linux except for AL, code. Howver, OpenJDK uses system (use libz.so installed in system or passed in LD_LIBRARY_PATH) for linux by default. code. We made zlib in Corretto as bundled only for historical reason. In order to have the parity, we should make it dynamic linking for all linux platforms.

Keep bundled for Windows as Windows doesn't have zlib out of box. Also keep mac as bundled for https://bugs.openjdk.org/browse/JDK-8286623.

User experience

Users are not expected to make any code change or observe behavior differences. Under the hood, instead of using the libz.so built from Corretto source, now Corretto will rely on libz.so on the system or in the LD_LIBRARY_PATH if it is set. libz.so is a low level library that majority of the systems have out of box (CentOS, Ubuntu, alpine etc.)

With this change, you can use a different libz.so rather than stick with the bundled zlib. You can pass the library location to LD_LIBRARY_PATH: export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<libz.so path>. You can then verify if the path set successfully via ldconfig -p | grep libz.

Target Release Date

The code enabling zlib dynamic linking has already been pushed to Corretto source. It will be published in our next quarterly release (2023-07-18).

In the meantime, you can download our latest nightly builds to try it out: https://downloads.corretto.aws/#/downloads?build=nightly

@navyxliu
Copy link

'--with-zlib' is an option for configure. the term bundle here means the building system will pick up the libraries bundled with the repository. Alternatively, it could choose the libraries provided from the system or even find one from a custom location.

https://github.com/corretto/corretto-17/blob/develop/make/autoconf/lib-bundled.m4

How to link zlib is not determine by configure. it's up by LDFLAGS, or the flags pass to your linker. We are supposed to link shared libraries dynamically. LDFLAGS usually is as simple as -labc. it denotes that we want to dynamically link libabc.so. if you really want to statically link a library, you need to find the archive file and link it explicitly for instance libabc.a

@rgithubli
Copy link
Contributor Author

#125 merged. Closing.

@rgithubli
Copy link
Contributor Author

Reopening this issue for gathering feedback.

@SentryMan
Copy link

I'm getting missing libz.so.1 errors all of a sudden, is this the cause?

@benty-amzn
Copy link
Contributor

Depending on how you're installing corretto it's certainly possible. This change is linux only, to start with, so if you're on another platform you can stop reading, it's something else.

The installer packages (deb, rpm, apk) were updated to depend on zlib, so it should have been installed if missing. However if you're using the .tar.gz bundles there's no automated dependency installation, so if your environment does not have zlib present it could cause that error.

It should be fairly straightforward to test, if you can install packages in your environment - just install the package that provides libz.so.1 for your distro and see if the error goes away.

@SentryMan
Copy link

SentryMan commented Aug 19, 2023

I also use distroless, and recently updated from an older version.

@SentryMan
Copy link

well, I can do the workaround mentioned in that other issue, but it is slightly inconvenient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants