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

aarch64 native library is tried to be loaded when using a 32-bit JVM #1127

Closed
tyilo opened this issue Jun 14, 2024 · 4 comments · Fixed by #1128
Closed

aarch64 native library is tried to be loaded when using a 32-bit JVM #1127

tyilo opened this issue Jun 14, 2024 · 4 comments · Fixed by #1128
Labels
released Issue has been released troubleshooting

Comments

@tyilo
Copy link
Contributor

tyilo commented Jun 14, 2024

Describe the bug
When running inside a 32-bit JVM on a aarch64 processor, sqlite-jdbc tries to load the aarch64 native library. This of course fails.

To Reproduce

package org.example;

import java.sql.DriverManager;

public class Main {
  public static void main(String[] args) throws Exception {
    System.out.println("Arch: " + System.getProperty("sun.arch.data.model"));

    try (var connection = DriverManager.getConnection("jdbc:sqlite:/tmp/test.db");
      var statement = connection.createStatement();
      var result = statement.executeQuery("SELECT RANDOM();")) {
      while (result.next()) {
        System.out.println("Output: " + result.getLong(1));
      }
    }
  }
}

Expected behavior
As the code is running inside a 32-bit JVM, the arm, armv6 or armv7 native library should be loaded.

Logs
Output:

Arch: 32
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
OpenJDK Client VM warning: You have loaded library /tmp/sqlite-3.46.0.0-51c6d6c2-c417-498d-9da6-fb79c3df716a-libsqlitejdbc.so which might have disabled stack guard. The VM will try to fix the stack guard now.
It's highly recommended that you fix the library with 'execstack -c <libfile>', or link it with '-z noexecstack'.
Exception in thread "main" java.sql.SQLException: Error opening connection
	at org.sqlite.SQLiteConnection.open(SQLiteConnection.java:283)
	at org.sqlite.SQLiteConnection.<init>(SQLiteConnection.java:67)
	at org.sqlite.jdbc3.JDBC3Connection.<init>(JDBC3Connection.java:28)
	at org.sqlite.jdbc4.JDBC4Connection.<init>(JDBC4Connection.java:19)
	at org.sqlite.JDBC.createConnection(JDBC.java:106)
	at org.sqlite.JDBC.connect(JDBC.java:79)
	at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:681)
	at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:252)
	at org.example.Main.main(Main.java:9)
Caused by: org.sqlite.NativeLibraryNotFoundException: No native library found for os.name=Linux, os.arch=aarch64, paths=[/org/sqlite/native/Linux/aarch64:/usr/java/packages/lib:/usr/lib/arm-linux-gnueabihf/jni:/lib/arm-linux-gnueabihf:/usr/lib/arm-linux-gnueabihf:/usr/lib/jni:/lib:/usr/lib]
	at org.sqlite.SQLiteJDBCLoader.loadSQLiteNativeLibrary(SQLiteJDBCLoader.java:361)
	at org.sqlite.SQLiteJDBCLoader.initialize(SQLiteJDBCLoader.java:75)
	at org.sqlite.core.NativeDB.load(NativeDB.java:69)
	at org.sqlite.SQLiteConnection.open(SQLiteConnection.java:280)
	... 8 more

Environment (please complete the following information):

  • OS: Raspberry Pi OS
  • CPU architecture: aarch64
  • sqlite-jdbc version: 3.46.0.0

Additional context

@tyilo tyilo added the triage label Jun 14, 2024
@gotson
Copy link
Collaborator

gotson commented Jun 14, 2024

Probably because your Raspberry used to be 32bit and was incorrectly migrated to 64bit. Pretty sure there's existing issues about that.

You can force the detection: https://github.com/xerial/sqlite-jdbc/blob/master/USAGE.md#override-detected-architecture

@tyilo
Copy link
Contributor Author

tyilo commented Jun 14, 2024

Sure I can try that to fix my issue, but this is still a bug in sqlite-jdbc.

A 64-bit native library should never be tried to be loaded into a 32-bit JVM.

@gotson
Copy link
Collaborator

gotson commented Jun 14, 2024

It's more of a problem in the Raspberry OS that gets in a weird state it shouldn't be in.

Anyhow, if you think you can fix this behaviour, feel free to send a PR.

Copy link
Contributor

🎉 This issue has been resolved in 3.46.0.1 (Release Notes)

@github-actions github-actions bot added the released Issue has been released label Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released Issue has been released troubleshooting
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants