graal
graal copied to clipboard
Exception when using @CFunction on Windows
Describe the issue
There is a problem with calling native code corresponing the java functuion annotated @CFunction on Windows platform.
Accrording to CInterfaceTutorial.java and the cinterfecetutorail.c
@CContext(NativeTest.CApiDirectives.class)
public class NativeTest {
static class CApiDirectives implements CContext.Directives { ...}
@CFunction
public native static int testC();
}
extern "C" int testC();
int main() {
testC(); // crashes with exception on Windows
}
Steps to reproduce the issue Please include both build steps as well as run steps
- Use GraalVM CE Build v22.1.0 on Apr 26
- git clone https://github.com/Montura/graal-native-test
- https://github.com/Montura/graal-native-test#steps-to-reproduce
Describe GraalVM and your environment:
- GraalVM version release v22.1.0
- JDK major version: 11
- OS and arch:
- os: Windows 10 Pro 19044.1826, arch: x64 (Intel Core i3-8100)
- os: Linux Ubuntu 20.04.4 LTS, arch: x64 (Intel Core i5-2410M)
- os: Mac OS Big Sur Version 11.5.2, arch: x64 (Intel Core i9)
More details
- on Linux and Mac Os works fine:
Expected output (digits are not valuable):
OS name: mac os
JNI time = 20
C time = 6
dummy time = 6
native time = 1
- on Windows
Actual output (digits are not valuable):
OS name: windows 10
JNI time = 20
"Exception thrown at 0x00007FFA0F6F0000 (GraalSample.dll) in native.exe: 0xC0000005: Access violation executing location 0x00007FFA0F6F0000."
Possible cause
- I dumped symbols from shared library for Mac, Linux and Windows:
- Mac and Linux are export undefined symbol testC: symbols_mac and symbols_linux
-
Windows can't export undefined symbol testC : symbols_windows
- I used "/FORCE:UNRESOLVED" linker option to build shared lib for Windows (so the symbol testC isn't imported)
- I tried "/OPT:NOREF" and "/INCLUDE:testC", but it doens't help me at all.
- GetProcAddress and dlsym proved my assumption: load_functions.cpp
Thank you for reporting this, we will take a look into it and get back to you
@oubidar-Abderrahim, hello. Do you have any updates?
I apologize for the super late response, the issue got buried under many others. Could you please verify if this issue is still present in our latest build of 22.3.0?
If this issue is still relevant in the latest GraalVM versions, please create a new issue for it and follow the template provided. Thank you
If this issue is still relevant in the latest GraalVM versions, please create a new issue for it and follow the template provided. Thank you
It's irrelevant, there is an issue with shared library linkage on Windows. dll export undefined symbols with "/FORCE:UNRESOLVED" is ignored if the entry point symbol is unresolved.