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

Support static linking of JNI libs #827

Closed
FroMage opened this issue Nov 28, 2018 · 11 comments
Closed

Support static linking of JNI libs #827

FroMage opened this issue Nov 28, 2018 · 11 comments

Comments

@FroMage
Copy link

FroMage commented Nov 28, 2018

ATM when using SSL we must run with -Djava.library.path=$GRAALVM_HOME/jre/lib/amd64 to get the libsunec.so, but that's asymmetrical to the rest of the JDK which is statically linked in the executable. Could we get an option to statically link specified JNI libs into the executable to avoid that external runtime dependency?

@cstancu cstancu assigned cstancu and olpaw and unassigned ansalond Nov 29, 2018
@cstancu
Copy link
Member

cstancu commented Nov 29, 2018

@FroMage this improvement is on our TODO list. Thanks for the report!

@neomatrix369
Copy link
Contributor

I think you now do this already via the --static option?

@lvh
Copy link

lvh commented Aug 10, 2019

That statically links libc and zlib specifically, but not anyhting else, IIUC.

@lvh
Copy link

lvh commented Aug 10, 2019

FWIW I think resolving this would also resolve #1336.

@neomatrix369
Copy link
Contributor

@lvh thanks for the response, I'll update the docs via a PR to express this next to the --static option

@neomatrix369
Copy link
Contributor

@lvh FYI: just raised a PR #1602

@lvh
Copy link

lvh commented Nov 24, 2019

FWIW 19.3.0 at least fixes the libsunec case and I think maybe it just lets you link anything now?

@olpaw
Copy link
Member

olpaw commented Nov 25, 2019

Closing issue since 19.3. we depend on static linking of JNI libs of the JDK.

If there are issues with specific JNI libs that cause problems please open individual issues for them.

@olpaw olpaw closed this as completed Nov 25, 2019
@lvh
Copy link

lvh commented Nov 27, 2019

@olpaw is there any documentation on how to use that feature? There's a JNI doc in the repo but it's pretty outdated (still mentions SubstrateVM, for one) :)

concretely: let's say I have a JNI library (ideally the JNI library is actually jnr-ffi), how do I build a native image that uses it?

@manuel-alvarez-alvarez
Copy link

@lvh did you manage to use a static library with a statically built native image?

I'm trying to add support for Brotli4j, so far by using -H:NativeLinkerOption I'm able to link using a static libbrotli.a so the resulting executable appears to be properly built:

/project/target # readelf -Ws application | grep brotli
 37260: 0000000001bcea40    72 FUNC    GLOBAL DEFAULT    2 Java_com_aayushatharva_brotli4j_decoder_DecoderJNI_nativeDestroy
 37262: 0000000001bcea90   327 FUNC    GLOBAL DEFAULT    2 Java_com_aayushatharva_brotli4j_encoder_EncoderJNI_nativeCreate
 37379: 0000000001bcee20    72 FUNC    GLOBAL DEFAULT    2 Java_com_aayushatharva_brotli4j_encoder_EncoderJNI_nativeDestroy
 37661: 0000000001bce950   235 FUNC    GLOBAL DEFAULT    2 Java_com_aayushatharva_brotli4j_decoder_DecoderJNI_nativePull
 37908: 0000000001bce7e0   354 FUNC    GLOBAL DEFAULT    2 Java_com_aayushatharva_brotli4j_decoder_DecoderJNI_nativePush
 38116: 0000000001bce5c4    38 FUNC    GLOBAL DEFAULT    2 JNI_OnLoad_brotli
 38290: 0000000001bcebe0   365 FUNC    GLOBAL DEFAULT    2 Java_com_aayushatharva_brotli4j_encoder_EncoderJNI_nativePush
 38375: 0000000001bced50   201 FUNC    GLOBAL DEFAULT    2 Java_com_aayushatharva_brotli4j_encoder_EncoderJNI_nativePull
 38523: 0000000001bce5ea    34 FUNC    GLOBAL DEFAULT    2 JNI_OnUnload_brotli
 38535: 0000000001bce6d0   263 FUNC    GLOBAL DEFAULT    2 Java_com_aayushatharva_brotli4j_decoder_DecoderJNI_nativeCreate
 38773: 0000000001bce610   177 FUNC    GLOBAL DEFAULT    2 Java_com_aayushatharva_brotli4j_common_CommonJNI_nativeSetDictionaryData

But all attempts to load the library with System.loadLibrary("brotli") yield an java.lang.UnsatisfiedLinkError: no brotli in java.library.path exception.

Thanks in advance for any suggestions / help

@lvh
Copy link

lvh commented May 5, 2021

Nope, sorry.

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

No branches or pull requests

8 participants