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

UnsatisfiedLinkError: Error looking up function 'strlen' #21

Closed
bhelx opened this issue Apr 1, 2024 · 10 comments · Fixed by #22
Closed

UnsatisfiedLinkError: Error looking up function 'strlen' #21

bhelx opened this issue Apr 1, 2024 · 10 comments · Fixed by #22

Comments

@bhelx
Copy link
Contributor

bhelx commented Apr 1, 2024

A report from a user. They got this error when trying to load a plugin but it failed:

at com.sun.jna.Function.<init> (Function.java:252)
    at com.sun.jna.NativeLibrary.getFunction (NativeLibrary.java:604)
    at com.sun.jna.NativeLibrary.getFunction (NativeLibrary.java:580)
    at com.sun.jna.NativeLibrary.getFunction (NativeLibrary.java:566)
    at com.sun.jna.Library$Handler.invoke (Library.java:243)
    at jdk.proxy3.$Proxy28.strlen (Unknown Source)
    at org.extism.sdk.Plugin.<init> (Plugin.java:49)
    at org.extism.sdk.Plugin.<init> (Plugin.java:61)
    at org.spirefy.engine.PluginEngine.load (PluginEngine.java:28)
    at org.spirefy.example.Example.main (Example.java:12)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:254)
    at java.lang.Thread.run (Thread.java:1570)
java.lang.UnsatisfiedLinkError: Error looking up function 'strlen': The specified procedure could not be found.

Looks to me like this code is not correct:

int errlen = LibExtism.INSTANCE.strlen(errormsg[0]);

we don't expose have a strlen function in libextism.

@bhelx bhelx changed the title Unsatisfied Link Error Unsatisfied Link Error: Error looking up function 'strlen' Apr 1, 2024
@bhelx bhelx changed the title Unsatisfied Link Error: Error looking up function 'strlen' UnsatisfiedLinkError: Error looking up function 'strlen' Apr 1, 2024
@apisorbust
Copy link

I am puzzled by this. The example URL code works fine from Java host. But trying to load a local wasm module it seems like it isn't even getting to my module.. e.g. the extism.sdk.Plugin.init call is looking for that strlen func for some reason? Which is odd that it would be since there is a length function in Java anyway. I feel like this is one of those "oh.. it's this other thing unrelated that is somehow causing this issue to rear up".

@apisorbust
Copy link

Just another thought on this.. it seems like the strlen() call is because the p is null (prior to it in the Plugin.java call). So my assumption is p being null means it did not find/load my plugin.. The code:

Pointer p = LibExtism.INSTANCE.extism_plugin_new(manifestBytes, manifestBytes.length, ptrArr, functions == null ? 0 : functions.length, withWASI, errormsg); if (p == null) { if (functions != null) for (int i = 0; i < functions.length; i++) { LibExtism.INSTANCE.extism_function_free(functions[i].pointer); } int errlen = LibExtism.INSTANCE.strlen(errormsg[0]); byte[] msg = new byte[errlen]; errormsg[0].read(0, msg, 0, errlen); LibExtism.INSTANCE.extism_plugin_new_error_free(errormsg[0]); throw new ExtismException(new String(msg)); }

I assume above that Pointer P using LibExtism.INSTNACE.extism_plugin_new() is trying to load/create the plugin, but that it returns null and this the if (p == null) bit runs, which is where this strlen function not found is happening.

I'd be interested if whoever owns/knows the code might explain the issue with INSTANCE.strlen().

@bhelx
Copy link
Contributor Author

bhelx commented Apr 4, 2024

I think perhaps @thomasdarimont or @Zwiterrion may have written that piece. I believe it's a mistake, maybe the testing plugin had that export but it's not part of Extism so it's not gonna be present normally. I think we should remove it and instead use extism_plugin_error:

String extism_plugin_error(Pointer pluginPointer);

Also perhaps @zshipko has an idea of the correct behavior here.

@bhelx
Copy link
Contributor Author

bhelx commented Apr 4, 2024

I'd be happy to fix it but I can't reproduce the problem yet.

@thomasdarimont
Copy link
Contributor

@bhelx I'll take a look now.

@thomasdarimont
Copy link
Contributor

thomasdarimont commented Apr 4, 2024

I cannot reproduce the problem either, as the code is correctly executed.
image

The strlen function is exposed by the glibc

$ readelf -Ws --dyn-syms /usr/local/lib/libextism.so | grep strlen
    53: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND strlen@GLIBC_2.2.5 (3)
 43603: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND strlen@@GLIBC_2.2.5

Tested this with

$ extism lib check
1.2.0

@Zwiterrion
Copy link

Zwiterrion commented Apr 4, 2024

I checked on arm64, and i got the strlen function.

@apisorbust can you give us your os ? You may be on windows and we tested on Mac and Linux

@bhelx
Copy link
Contributor Author

bhelx commented Apr 4, 2024

The strlen function is exposed by the glibc

Ohhh I see. Yeah, we can't assume that is there. We should be able to not rely on it. Idk what OS he was on, he didn't say, but his paths suggested windows

thomasdarimont added a commit to thomasdarimont/extism-java-sdk that referenced this issue Apr 4, 2024
Signed-off-by: Thomas Darimont <thomas.darimont@googlemail.com>
@thomasdarimont
Copy link
Contributor

@bhelx I found a way to get rid of the strlen function... see #22

@bhelx bhelx closed this as completed in #22 Apr 4, 2024
bhelx pushed a commit that referenced this issue Apr 4, 2024
Fixes #21 and enables the extism java sdk to be used on windows.

Signed-off-by: Thomas Darimont <thomas.darimont@googlemail.com>
@apisorbust
Copy link

Sorry.. didn't see this update thread. Yah.. windows 64.. but ya'll figured it out already. Just waiting on maven push for my app to pull down the fix and get cracking. Thank you again for jumping in on this and fixing it.

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 a pull request may close this issue.

4 participants