Skip to content

Build native image with option -march=compatibility

Current problem

Since version versin 1.5 of these services, which were included in all-in-one:2023-12 and squash-orchestrator:4.8.0, we use Java 17 to compile classes and GraalVM for JDK 17 to compile native images.

Unfortunately since GraalVM for JDK 17, default compilation targets x86-64-v3 on AMD64 architecure. The consequence is we have users which cannot start their orchestrator because the CPU lacks some features. Error message is the following:

The current machine does not support all of the following CPU features that are required by the image: [CX8, CMOV, FXSR, MMX, SSE, SSE2, SSE3, SSSE3, SSE4_1, SSE4_2, POPCNT, LZCNT, AVX, AVX2, BMI1, BMI2, FMA]. Please rebuild the executable with an appropriate setting of the -march option.The current machine does not support all of the following CPU features that are required by the image: [CX8, CMOV, FXSR, MMX, SSE, SSE2, SSE3, SSSE3, SSE4_1, SSE4_2, POPCNT, LZCNT, AVX, AVX2, BMI1, BMI2, FMA].

It is written in GraalVM for JDK 17 documentation:

The targeted machine type can be selected with the -march option and defaults to x86-64-v3 on AMD64 and armv8-a on AArch64.

Searching in GraalVM repositories, we learn that in previous versions of GraalVM, the targeted machine was x86-64 by default. Which equals to value compatibility of option -march in GraalVM for JDK 17.

Expected behaviour

We need to build our native images targetting x86-64 so it becomes compatible with all machines again.

This will be done adding compile option -march=compatibility.

It is possible to verify the actual compilation option in any pipeline building a native image, the option is displayed in phase 1 (initializing):

[1/8] Initializing...                                                                                   (14.6s @ 0.27GB)
 Java version: 17.0.7+7, vendor version: GraalVM CE 17.0.7+7.1
 Graal compiler: optimization level: 2, target machine: x86-64-v3
Edited by Johan Lor