Skip to content

[GR-49642] Support to export custom symbols when building a native image #7618

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

Open
wkgcass opened this issue Oct 14, 2023 · 3 comments
Open

Comments

@wkgcass
Copy link

wkgcass commented Oct 14, 2023

Feature request

Is your feature request related to a problem? Please describe.

I am using Panama FFI to call the DPDK library. Normally the compilation result of dpdk is a static archive and should be statically linked to a user program.
When trying to statically linking a library to the native-image, I find it's pretty easy to link, simply by adding the following options:

-H:NativeLinkerOption='-Wl,--no-as-needed' \
-H:NativeLinkerOption='-Wl,path/to/libxxx.a' \
-H:NativeLinkerOption='-Wl,--as-needed'

However the symbols of the library are not exported because during the linking phase the native-image generator adds a version script to control the visibility of the symbols.

Since the symbols are not exported, the lookup operation of Panama FFI cannot find the requested function.

Describe the solution you'd like.

So I'm wondering whether we could add an option to let users define their own symbols.
For example, adding an option: -H:AdditionalExportedSymbols=<file-path>, and directly concat the file content below global: and above local:. Similar operation could be added for MacOS as well.

I looked into the source code and I found this is not hard to implement, but I'm wondering whether this should be officially supported.

Describe who do you think will benefit the most.

GraalVM users, developers of libraries and frameworks which depend on GraalVM

Describe alternatives you've considered.

I currently modified the native-image source code (not directly, but with a javaagent) to achieve my requirements.

Express whether you'd like to help contributing this feature

If this feature is desired to be officially supported, I would like to contribute.

@kassifar
Copy link
Member

Hello @wkgcass,

Thank you for your suggestion, we'll take a look at it.

@kassifar kassifar self-assigned this Jan 10, 2024
@wirthi wirthi changed the title Support to export custom symbols when building a native image [GR-49642] Support to export custom symbols when building a native image Apr 24, 2024
@iseki0
Copy link

iseki0 commented Dec 8, 2024

Are there any updates? Since the native-image provides nearly static linked build of Java application, keep all native libraries static linked is useful. But there're no public way to custom the symbols import from the static linked libraries.
@wirthi

@fangerer
Copy link
Member

@wkgcass Could you try to use -H:NativeLinkerOption='-Wl,--export-dynamic-symbol=...' and see if that works.

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

5 participants