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

Kafkactl cannot be executed in a Alpine Docker image #129

Open
nil-malh opened this issue May 16, 2024 · 0 comments
Open

Kafkactl cannot be executed in a Alpine Docker image #129

nil-malh opened this issue May 16, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@nil-malh
Copy link

Describe the bug

Kafkactl will produce a segmentation fault when running the native-image in a Alpine Docker image

/# kafkactl
Error relocating /usr/local/bin/kafkactl: __strdup: symbol not found
Error relocating /usr/local/bin/kafkactl: __strtok_r: symbol not found
Error relocating /usr/local/bin/kafkactl: __isnan: symbol not found
Error relocating /usr/local/bin/kafkactl: __isnanf: symbol not found
Segmentation fault

To Reproduce

  • Create a Alpine docker image, download kafkactl from the release and add it to the PATH
  • Execute kafkactl

Expected behavior

Should work as expected without the segmentation fault

Environment (please complete the following information):

  • Kafkactl distribution and version [Native Image, v1.14.0]

Steps taken to try and solve the problem

The issue is mainly due to Alpine not using glibc but musl, and so some symbols are missings when running the native-image.

The easiest way to fix this issue is to use GraalVM Static Native Executable see here

As explained in the documentation :

A static native executable is a statically linked binary that can be used without any additional library dependencies. A static native executable is easy to distribute and deploy on a slim or distroless container (a scratch container). You can create a static native executable by statically linking it against musl-libc, a lightweight, fast and simple libc implementation.

In order to apply this to kafkactl some tinkering is required :

  • Edit the build.gradle to add the --static --libc=musl :

    graalvmNative {
       binaries {
          main {
             imageName.set("kafkactl-" + version)
             buildArgs.add("--static")
             buildArgs.add("--libc=musl")// Static linking
             ...
     }

    The CI/CD needs some changes as well, as it requires the musl libc compiler in order to link it into the native image.
    We can refer to this

    How ever small caveat the documentation provides the url for the latest version of musl however it's not compatible with the native image as mentioned in the issue #4076 from oracle/graal

Hey everyone :)
As @ dainiusjocas mentioned, this problem started happening due to a change in the gcc musl toolchain build process that started treating relocations in a read-only section at runtime as an error rather than a compile time warning.
I don't think we can report this issue to the musl toolchain developers - this was probably an intended change from their side.

The reason why it fails with native-image is because a read only section that gets placed in a read only segment at runtime, .svm_heap, has relocations that can only be resolved at program startup.

I don't see a trivial way to get rid of these relocations (I assume most of them come from method address relocations, for e.g. for the vtables).

As a workaround, it's probably best to use GCC 10.2.1 for cross-compiling to musl. Alternatively, there may be a ld option that can prevent the linker from failing due to these relocations, but I'm not sure which one it is exactly :/

Tracked internally by GR-24601

Originally posted by @gradinac in oracle/graal#4076 (comment)

The latest functional version is https://more.musl.cc/10.2.1/x86_64-linux-musl/x86_64-linux-musl-native.tgz

@nil-malh nil-malh added the bug Something isn't working label May 16, 2024
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

1 participant