square / jna-gmp

A Java JNA wrapper around the GNU Multiple Precision Arithmetic Library.
Apache License 2.0
62 stars 24 forks source link

Not using the embedded library #25

Closed JakeWharton closed 6 years ago

JakeWharton commented 7 years ago

We saw this internally when deploying.

2017-05-19T13:48:53,422  WARN [main] module.NativeRSAModule - Could not load native library for NativeRSAEngine, falling back to RSAEn
gine
java.lang.UnsatisfiedLinkError: Error looking up function '__gmpz_powm_sec': /usr/lib64/libgmp.so.3.5.0: undefined symbol: __gmpz_powm
_sec
        at com.sun.jna.Function.<init>(Function.java:208)
        at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:536)
        at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:513)
        at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:499)
        at com.sun.jna.Native.register(Native.java:1509)
        at com.squareup.jnagmp.LibGmp.load(LibGmp.java:70)
        at com.squareup.jnagmp.LibGmp.loadLibGmp(LibGmp.java:65)
        at com.squareup.jnagmp.LibGmp.<clinit>(LibGmp.java:52)
        at com.squareup.jnagmp.Gmp.<clinit>(Gmp.java:49)
kevinconaway commented 6 years ago

@JakeWharton we're seeing this as well after upgrading to 2.0.0 It looks like the shared library thats being distributed requires GLIBC 2.14 but our system has 2.12:

Exception in thread "main" java.lang.UnsatisfiedLinkError: /tmp/jna--1159748624/jna6403537542271234011.tmp: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by /tmp/jna--1159748624/jna6403537542271234011.tmp)
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1929)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1814)
    at java.lang.Runtime.load0(Runtime.java:809)
    at java.lang.System.load(System.java:1083)
    at Test.main(Test.java:10)

Dependencies for the 2.0.0 library:

ldd -r -v  /tmp/jna--1159748624/jna6403537542271234011.tmp
ldd: warning: you do not have execution permission for `/tmp/jna--1159748624/jna6403537542271234011.tmp'
/tmp/jna--1159748624/jna6403537542271234011.tmp: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by /tmp/jna--1159748624/jna6403537542271234011.tmp)
    linux-vdso.so.1 =>  (0x00007fffdece7000)
    libc.so.6 => /lib64/libc.so.6 (0x00007ffac21ec000)
    /lib64/ld-linux-x86-64.so.2 (0x0000003b93800000)
symbol memcpy, version GLIBC_2.14 not defined in file libc.so.6 with link time reference    (/tmp/jna--1159748624/jna6403537542271234011.tmp)

    Version information:
    /tmp/jna--1159748624/jna6403537542271234011.tmp:
        libc.so.6 (GLIBC_2.3) => /lib64/libc.so.6
        libc.so.6 (GLIBC_2.14) => not found
        libc.so.6 (GLIBC_2.7) => /lib64/libc.so.6
        libc.so.6 (GLIBC_2.2.5) => /lib64/libc.so.6
    /lib64/libc.so.6:
        ld-linux-x86-64.so.2 (GLIBC_PRIVATE) => /lib64/ld-linux-x86-64.so.2
        ld-linux-x86-64.so.2 (GLIBC_2.3) => /lib64/ld-linux-x86-64.so.2

Looking at the 1.x version:

ldd -r -v libgmp.so
ldd: warning: you do not have execution permission for `./libgmp.so'
    linux-vdso.so.1 =>  (0x00007ffcc07dc000)
    libc.so.6 => /lib64/libc.so.6 (0x00007f0994678000)
    /lib64/ld-linux-x86-64.so.2 (0x000000383e800000)

    Version information:
    ./libgmp.so:
        libc.so.6 (GLIBC_2.3) => /lib64/libc.so.6
        libc.so.6 (GLIBC_2.2.5) => /lib64/libc.so.6
    /lib64/libc.so.6:
        ld-linux-x86-64.so.2 (GLIBC_PRIVATE) => /lib64/ld-linux-x86-64.so.2
        ld-linux-x86-64.so.2 (GLIBC_2.3) => /lib64/ld-linux-x86-64.so.2

@dragonsinth Is this just a matter of recompiling libgmp on a machine that doesn't have glibc 2.14?

dragonsinth commented 6 years ago

I'm definitely at the limits of my knowledge when it comes to effectively building linux binaries. :( Especially all the nuances about building against particular library versions.

Googling "how do i create an lsb compatible binary gcc" turns up stuff that's like 7 years old and contains broken links. :/

I'd definitely welcome any expertise on this.

dragonsinth commented 6 years ago

@kevinconaway I would definitely suggest tho, if you recompile libgmp on the system you're trying to run on, it should work.

dragonsinth commented 6 years ago

BTW @JakeWharton I assume you got past the original issue reported? I'm realizing that you and @kevinconaway are reporting two different issues here.

kevinconaway commented 6 years ago

I would definitely suggest tho, if you recompile libgmp on the system you're trying to run on, it should work.

I did do that and it did work but, much like you, I'm not really knowledgeable beyond the standard ./configure && make incantation. We run on a number of different platforms so ideally I'd like to build a version that targets the lowest common denominator but I'm not sure of the best way to do that.

kevinconaway commented 6 years ago

I'm realizing that you and @kevinconaway are reporting two different issues here.

I believe its the same issue. The issue originally presented itself to us with the exact same stack trace that Jake posted. Its just that LibGmp or perhaps NativeLibrary swallows the original linker error. I pulled out the shared library file and tried to load it directly on my target system and thats where the error I posted came from.

JakeWharton commented 6 years ago

@dragonsinth It wasn't me. Was someone else. I just moved the report here.

dragonsinth commented 6 years ago

I'm interested in the outcome but I can't really spend the time to research the best way to build compatible binaries (past the half hour I already spend). But if someone can come up with a reasonable plan (like, use this docker image that contains an older distro) I'm happy to help execute and submit a new prebuilt binary.

kevinconaway commented 6 years ago

Sure. I'll spend some time and come up with a recommendation.

Thanks for your help so far

kevinconaway commented 6 years ago

JNA had this issue as well https://github.com/java-native-access/jna/issues/853

dragonsinth commented 6 years ago

Looks like they solved it with "The native libraries were rebuild in a debian squeeze chroot, which results in support for GLIBC version down to 2.7.". I'm not entirely sure what that means or how to set that up.

dragonsinth commented 6 years ago
$ ldd -r -v libgmp.so 
    linux-vdso.so.1 (0x00007ffebd945000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fdc93e01000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fdc9443b000)

    Version information:
    ./libgmp.so:
        libc.so.6 (GLIBC_2.3) => /lib/x86_64-linux-gnu/libc.so.6
        libc.so.6 (GLIBC_2.7) => /lib/x86_64-linux-gnu/libc.so.6
        libc.so.6 (GLIBC_2.2.5) => /lib/x86_64-linux-gnu/libc.so.6
    /lib/x86_64-linux-gnu/libc.so.6:
        ld-linux-x86-64.so.2 (GLIBC_2.3) => /lib64/ld-linux-x86-64.so.2

Merged! Thanks so much for making this happen!

kevinconaway commented 6 years ago

Thanks so much for your prompt help on this @dragonsinth.

Will you be able to create a new release with this change?

dragonsinth commented 6 years ago

@JakeWharton usually does releases, I don't think I have access to publish artifacts anyway.

dragonsinth commented 6 years ago

I did just update the CHANGELOG.md so it should be fairly ready to go.

JakeWharton commented 6 years ago

I can try to get out a release this weekend or next week.

On Wed, Feb 28, 2018 at 2:44 PM Scott Blum notifications@github.com wrote:

I did just update the CHANGELOG.md so it should be fairly ready to go.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/square/jna-gmp/issues/25#issuecomment-369359346, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEEEeLrAi2Swe1G3q9WNUQXjtiu2Pldks5tZayNgaJpZM4NlXbJ .

kevinconaway commented 6 years ago

Thank you!

kevinconaway commented 6 years ago

Hi @JakeWharton, will you have time to create a release this week?

Thanks.

JakeWharton commented 6 years ago

I will try today since I'm making other releases.

On Wed, Mar 7, 2018 at 8:42 AM Kevin Conaway notifications@github.com wrote:

Hi @JakeWharton https://github.com/jakewharton, will you have time to create a release this week?

Thanks.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/square/jna-gmp/issues/25#issuecomment-371136820, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEEEdcHbQ-XqJW5t1jmFLya3ofXoOLXks5tb9_-gaJpZM4NlXbJ .

kevinconaway commented 6 years ago

@JakeWharton Will you have time to create a release with this issue?

If its OK with you, I'll continue to write one comment a week a la Andy Dufresne. We'd like to use some of the enhancements in 2.x but we can't without this patch.

Thanks!

JakeWharton commented 6 years ago

Released 2.1.0. Will take 20m to show up on Maven central.

On Wed, Mar 14, 2018 at 10:54 AM Kevin Conaway notifications@github.com wrote:

@JakeWharton https://github.com/jakewharton Will you have time to create a release with this issue?

If its OK with you, I'll continue to write one comment a week a la Andy Dufresne. We'd like to use some of the enhancements in 2.x but we can't without this patch.

Thanks!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/square/jna-gmp/issues/25#issuecomment-373050105, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEEEbwTW4XQZbXrfGeSttuJg9FIkbDOks5teS8egaJpZM4NlXbJ .

kevinconaway commented 6 years ago

Got it, thank you!