Skip to content

Conversation

@sidepelican
Copy link
Contributor

In release builds (JNI mode), Java-linked Swift functions were being stripped from the dynamic library, It might be because of dead code elimination.

I have added the public modifier to these functions to match the behavior of FFM mode and ensure they are properly exported.

  • before(In Samples/SwiftJavaExtractJNISampleApp)
❯ swiftly run +swift-6.3-DEVELOPMENT-SNAPSHOT-2026-01-03-a swift build -c release --swift-sdk aarch64-unknown-linux-android28
❯ nm -D .build/aarch64-unknown-linux-android28/release/libMySwiftLibrary.so | grep Java_
(no output)
  • after
❯ swiftly run +swift-6.3-DEVELOPMENT-SNAPSHOT-2026-01-03-a swift build -c release --swift-sdk aarch64-unknown-linux-android28
❯ nm -D .build/aarch64-unknown-linux-android28/release/libMySwiftLibrary.so | grep Java_
00000000000bb544 T $s14MySwiftLibrary023Java_com_example_swift_aB18Class__00024init__11environment04thisH0s5Int64VSpySPySo18JNINativeInterfaceVGSgGSg_SvtF
00000000000bb600 T $s14MySwiftLibrary023Java_com_example_swift_aB18Class__00024sum__J11environment04thisH04selfs5Int64VSpySPySo18JNINativeInterfaceVGSgGSg_SvAGtF
00000000000bb650 T $s14MySwiftLibrary023Java_com_example_swift_aB19Class__00024copy__J11environment04thisH04selfs5Int64VSpy
...

@sidepelican sidepelican requested a review from ktoso as a code owner January 15, 2026 02:45
Copy link
Collaborator

@ktoso ktoso left a comment

Choose a reason for hiding this comment

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

Yeah, the missing public would be able to cause such a thing. Thanks for the pull request!

@sidepelican
Copy link
Contributor Author

My very tiny library worked fine with this,
but it might be public necessary here too?

func SwiftJava_JNI_OnLoad(javaVM: JavaVMPointer, reserved: UnsafeMutableRawPointer) -> jint {

@ktoso
Copy link
Collaborator

ktoso commented Jan 15, 2026

I would not mind making it public in abundance if caution.

@sidepelican
Copy link
Contributor Author

Now JNI_OnLoad is also included.

  • before
❯ nm -D .build/aarch64-unknown-linux-android28/release/libSwiftJava.so | grep JNI_OnLoad 
(no output)
  • after
❯ nm -D .build/aarch64-unknown-linux-android28/release/libSwiftJava.so | grep JNI_OnLoad
00000000000c6060 T $s9SwiftJava0aB11_JNI_OnLoad6javaVM8reserveds5Int32VSpySPySo18JNIInvokeInterfaceVGSgG_SvtF
00000000000c605c T JNI_OnLoad

@ktoso ktoso merged commit b5b5dec into swiftlang:main Jan 15, 2026
49 checks passed
@ktoso
Copy link
Collaborator

ktoso commented Jan 15, 2026

Thank you!

this did make me think that it likely was necessaey to begin with. Thank you!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants