8000 [GR-64789] [Native Image] FFI Bug · Issue #11109 · oracle/graal · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[GR-64789] [Native Image] FFI Bug #11109

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
2 tasks done
akashKarmakar02 opened this issue Apr 30, 2025 · 4 comments
Open
2 tasks done

[GR-64789] [Native Image] FFI Bug #11109

akashKarmakar02 opened this issue Apr 30, 2025 · 4 comments
Assignees

Comments

@akashKarmakar02
Copy link
akashKarmakar02 commented Apr 30, 2025

Describe the Issue

When i pass a struct to c function @cstruct annotated interface it's values are garbage

Using the latest version of GraalVM can resolve many issues.

GraalVM Version

java version "24" 2025-03-18
Java(TM) SE Runtime Environment Oracle GraalVM 24+36.1 (build 24+36-jvmci-b01)
Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 24+36.1 (build 24+36-jvmci-b01, mixed mode, sharing)

Operating System and Version

Linux fedora 6.14.3-300.fc42.x86_64 #1 SMP PREEMPT_DYNAMIC Sun Apr 20 16:08:39 UTC 2025 x86_64 GNU/Linux

Troubleshooting Confirmation

Run Command

native-image -cp . -H:CLibraryPath=$(pwd) -H:IncludeResources=add.h --native-compiler-options="-I$(pwd)" -Ob -jar Main.jar

Expected Behavior

5
Age: 5

Actual Behavior

5
Age: -678812048

Steps to Reproduce

1.create a c function which takes a struct as param
2. pass the struct obj from java
3. print the properties in c and java

Additional Context

java code:

import org.graalvm.nativeimage.c.CContext;
import org.graalvm.nativeimage.c.struct.CField;
import org.graalvm.nativeimage.c.struct.CStruct;
import org.graalvm.word.PointerBase;

@CStruct("User")
@CContext(Main.Directives.class)
public interface User extends PointerBase {

    @CField("age")
    int age();

    @CField("age")
    void age(int age);

}
 User u = StackValue.get(User.class);

u.age(5);
System.out.println(u.age());

print_user(u);

C code:

void print_user(User u) {
    printf("Age: %d", u.age);
}

Run-Time Log Output and Error Messages

No response

@selhagani
Copy link
Member

Hi @akashKarmakar02,

Thank you for reaching out to us.

To be able to reproduce this reliably on my end, could you please provide a more complete reproducer with all the code you used? You could also share all the code in a github repository alongside the steps/commands needed to reproduce the issue you're encountering.
This will help speed up the process on our end. Thank you.

@akashKarmakar02
Copy link
Author

https://github.com/akashKarmakar02/graalnative

just run sh build.sh and LD_LIBRARY_PATH=. ./Main

@selhagani selhagani changed the title [Native Image] FFI Bug [GR-64789] [Native Image] FFI Bug May 6, 2025
@selhagani
Copy link
Member

Thank you for sharing the reproducer. I was able to reproduce the issue on my end. We will take a closer look into this and I'll make sure to keep you updated.

@akashKarmakar02
Copy link
Author

@selhagani Hey, i made some progress if a receive User *user in c then it works. but how can i send normal structs from java.

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

2 participants
0