oracle / graal

GraalVM compiles Java applications into native executables that start instantly, scale fast, and use fewer compute resources 🚀
https://www.graalvm.org
Other
20.41k stars 1.64k forks source link

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

Open wkgcass opened 1 year ago

wkgcass commented 1 year ago

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 commented 1 year ago

Hello @wkgcass,

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