I am trying to execute a rust function in java using GraalVMs polyglot llvm features, however It is throwing a buffer overflow exception.
I compiled a rust library into a llvm bytecode file for use with GraalVM Java. However, when I try evaluating this file using Graalvms polyglot features, it returns a Overflow exception during evaluation of this file. I want to be able to execute any function from this llvm source file.
Here is my process:
Compiling the rust project -
cargo rustc --release -- --emit=llvm-bc (crate type cdylib, includes 6 dependencies)
The java function utilizing the rust llvm code:
/* imports and class declaration not shown */
void runFunctionFromLLVM() {
try {
Context polyglot = Context.newBuilder().allowNativeAccess(true).build();
// accesses the rust llvm library
File file = new File("(projectpath)/src/backend/target/release/deps/backend.bc");
Source source = Source.newBuilder("llvm", file).build();
// Buffer overflow traced to this function
Value cpart = polyglot.eval(source);
// attempts to access a function, but cannot due to the previous buffer overflow
System.out.println(cpart.getMember("logTest").canExecute());
} catch (Exception e) {
System.out.println("[ERROR]: LLVM failed to execute with error " + e.toString());
}
}
When testing this function it outputs this exception:
LLVM failed to execute with error org.graalvm.polyglot.PolyglotException: java.nio.BufferOverflowException
Java version graalvm-ce-11
OS Linux Mint 21.2 Cinnamon
My llvm-bc file is 87.8 KB large (is it simply too large for the evaluation process?).
Any help or suggestions are appreciated :).