I encountered an issue while running a simple Java program after compiling it with GraalVM and generating a native image. The original Java file is named Hello.java and contains the following code:
public class Hello {
public static void main(String[] args) {
System.out.println("Hello");
}
}
To compile the code, I used GraalVM, which resulted in the generation of the Hello.class file. Subsequently, I created a native image for this class using the command native-image Hello
. However, when attempting to execute the program with the ./hello command, I encountered the following error:
zsh: segmentation fault ./hello`
Despite searching for solutions on Stack Overflow, I have been unable to find a suitable resolution.
Here are the system and GraalVM installation details:
OS: MacOS Ventura
Processor: 2.6 GHz 6-Core Intel Core i7
GraalVM: graalvm-jdk-17.0.7+8.1
(Dowloaded it from https://www.graalvm.org/downloads with Java 17 and macOS(x64))
Below is the output forjava -version
java version "17.0.7" 2023-04-18 LTS
Java(TM) SE Runtime Environment Oracle GraalVM 17.0.7+8.1 (build 17.0.7+8-LTS-jvmci-23.0-b12)
Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 17.0.7+8.1 (build 17.0.7+8-LTS-jvmci-23.0-b12, mixed mode, sharing)
Looks like it is a known issue for GraalVM. https://github.com/oracle/graal/issues/5778
As per the issue on Github, I was able to resolve the zsh: segmentation fault ./hello
problem using below workaround:
Obtain an older version of Xcode. https://developer.apple.com/download/all/?q=Xcode%2012.5.1 This requires an Apple ID. (If you are not comfortable clicking the link, just sign in to Apple Developer account and search for "Xcode 12.5.1")
Unpack it via finder
Open a terminal and run following commands
$ mv ~/Downloads/Xcode.app /Applications/Xcode12.5.1.app/
$ sudo xcode-select -s /Applications/Xcode12.5.1.app/Contents/Developer
$ # verify with
$ xcodebuild -version