Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

@samyuh
Copy link
Contributor

@samyuh samyuh commented Jan 16, 2025

Problem

When importing a data source of a file that was previously compressed using the snappy compression algorithm, the compression fails with the following exception:

Error loading shared library ld-linux-x86-64.so.2: No such file or directory.

This problem occurs since the dockerimage does not containg the ld-linux-x86-64.so.2 lib, which is from glibc. Alpine images use musl making this incompatible.

Having this dependency being linked dynamically can mess things up. Ideally, we would like to have snappy being compiled against a MUSL image.

Snappy removed pure-java mode 1.1.9.0 (https://github.com/xerial/snappy-java/pull/381/files), which could be used to run snappy in non-supported systems with the use of one flag. We could force an older version but it was removed due to some problems (such as data corruption) and older versions than 1.1.9.0 contain critical CVEs (https://mvnrepository.com/artifact/org.xerial.snappy/snappy-java).

Workaround

Alpine images also have some packages that allow us to run binaries precompiled against glibc libraries (they don't allow us to compile against it), such as gcompat. In our case, libc6-compat provides /lib64/ld-linux-x86-64.so.2 compatible lib. Turns out that /lib64/ld-linux-x86-64.so.2 is a symlink to /lib/libc.musl-x86_64.so.1. Adding a /lib/ld-linux-x86-64.so.2 linked to /lib/ld-musl-x86_64.so.1 solves the issue since that is the place snappy is searching for the dependency.

This is the same solution employed by https://stackoverflow.com/a/55568352.

Fix

The library now includes native binaries compiled specifically for musl environments, eliminating the need for workarounds like installing gcompat or libc6-compat packages in Alpine containers.

This improvement means:

  • Direct compatibility with Alpine Linux
  • No need for additional compatibility packages
  • Better performance by using native musl binaries instead of compatibility layers
  • Simplified deployment in Alpine-based containers

Closes #616
Closes #239

@samyuh samyuh changed the title draft: feat: add musl support feat: add musl support Jan 17, 2025
@samyuh samyuh changed the title feat: add musl support feat: create musl compatible image Jan 17, 2025
@samyuh samyuh marked this pull request as draft January 17, 2025 17:09
@samyuh samyuh marked this pull request as ready for review January 18, 2025 01:00
@samyuh
Copy link
Contributor Author

samyuh commented Jan 18, 2025

Hey @xerial! This is a pull request that gives compatibility with systems using musl. Can you please take a look at this? Thanks!

@samyuh samyuh changed the title feat: create musl compatible image feat: create an alpine compatible image Jan 18, 2025
Makefile Outdated Show resolved Hide resolved
@xerial
Copy link
Owner

xerial commented Feb 4, 2025

@samyuh It seems building a native library for Alipine is failing on CI. https://github.com/xerial/snappy-java/actions/runs/12839320244/job/36630155639?pr=632

@samyuh
Copy link
Contributor Author

samyuh commented Feb 4, 2025

Hey @xerial thanks for the feedback! I will try to make time to look into this later today :)

@samyuh
Copy link
Contributor Author

samyuh commented Feb 4, 2025

@samyuh It seems building a native library for Alipine is failing on CI. https://github.com/xerial/snappy-java/actions/runs/12839320244/job/36630155639?pr=632

Pipelines should pass now, I just renamed one file and forgot to change it on Makefile

@samyuh samyuh requested a review from xerial February 5, 2025 09:53
src/main/java/org/xerial/snappy/OSInfo.java Outdated Show resolved Hide resolved
@samyuh samyuh requested a review from xerial February 5, 2025 23:32
src/main/java/org/xerial/snappy/OSInfo.java Outdated Show resolved Hide resolved
src/main/java/org/xerial/snappy/OSInfo.java Show resolved Hide resolved
@samyuh samyuh requested a review from xerial February 6, 2025 09:52
@samyuh samyuh changed the title feat: create an alpine compatible image feat: add support to x64 systems using musl Feb 7, 2025
@samyuh
Copy link
Contributor Author

samyuh commented Feb 10, 2025

Hey @xerial
Anything else missing? (feel free to add any new commit if you want btw)
Thanks :)

@xerial
Copy link
Owner

xerial commented Jul 19, 2025

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for musl-based x64 systems. The changes include updates to the build system and runtime detection logic in Java. The review focuses on improving maintainability of the build scripts, ensuring the correctness of the OSGi configuration, and enhancing the robustness of the Java code.

build.sbt Outdated
"org/xerial/snappy/native/Linux/ppc64/libsnappyjava.so;osname=linux;processor=ppc64le",
"org/xerial/snappy/native/Linux/s390x/libsnappyjava.so;osname=linux;processor=s390x",
"org/xerial/snappy/native/Linux/loongarch64/libsnappyjava.so;osname=linux;processor=loongarch64",
"org/xerial/snappy/native/Linux/x86_64-musl/libsnappyjava.so;osname=Linux;processor=x86-64-musl",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The processor value x86-64-musl in the OSGi Bundle-NativeCode entry is not a standard processor architecture that an OSGi framework would recognize. On an Alpine x86-64 system, the os.arch property is typically x86_64, which the OSGi framework maps to processor aliases like x86-64 or amd64. It's unlikely to match x86-64-musl. This could result in the OSGi framework either not extracting any native library or extracting the glibc-based one, which would fail to load. This could break functionality in OSGi environments on Alpine.

Comment on lines +105 to +114
Linux-x86_64-musl_CXX := $(CROSS_PREFIX)g++
Linux-x86_64-musl_STRIP := $(CROSS_PREFIX)strip
ifeq ($(IBM_JDK_7),)
Linux-x86_64-musl_CXXFLAGS := -Ilib/inc_linux -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden -m64 -std=c++11
else
Linux-x86_64-musl_CXXFLAGS := -include $(IBM_JDK_LIB)/jni_md.h -include $(IBM_JDK_LIB)/jniport.h -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden -m64 -std=c++11
endif
Linux-x86_64-musl_LINKFLAGS := -shared -static-libgcc -static-libstdc++
Linux-x86_64-musl_LIBNAME := libsnappyjava.so
Linux-x86_64-musl_SNAPPY_FLAGS :=
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The build configuration for Linux-x86_64-musl is very similar to the existing Linux-x86_64 configuration. This duplication can make future maintenance more difficult, as changes would need to be applied in two places. Consider refactoring the common settings into a reusable block to reduce redundancy.

src/main/java/org/xerial/snappy/OSInfo.java Outdated Show resolved Hide resolved
xerial and others added 3 commits July 19, 2025 11:50
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Changed processor=x86-64-musl to processor=x86-64 in Bundle-NativeCode
as x86-64-musl is not a valid OSGi processor value. The OSGi spec only
recognizes x86-64 (and aliases: amd64, em64t, x86_64) for 64-bit x86.

Also fixed osname=Linux to osname=linux for consistency with other entries.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Fixed improper indentation of catch statement at line 237

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@xerial xerial merged commit ded9f16 into xerial:master Jul 19, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using snappy with MUSL Linux x86_64 builds for musl libc

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.