Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/mx.compiler/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@
"jdk.graal.compiler.util to org.graalvm.nativeimage.agent.tracing,org.graalvm.nativeimage.configure",
"jdk.graal.compiler.core.common to org.graalvm.nativeimage.agent.tracing,org.graalvm.nativeimage.objectfile",
"jdk.graal.compiler.debug to org.graalvm.nativeimage.objectfile",
"jdk.graal.compiler.nodes.graphbuilderconf to org.graalvm.nativeimage.driver,org.graalvm.nativeimage.librarysupport",
"jdk.graal.compiler.nodes.graphbuilderconf to org.graalvm.nativeimage.driver,org.graalvm.nativeimage.librarysupport,org.graalvm.nativeimage.svm.niutils",
"jdk.graal.compiler.phases.common to org.graalvm.nativeimage.agent.tracing,org.graalvm.nativeimage.configure",
"jdk.graal.compiler.serviceprovider to org.graalvm.nativeimage.driver,org.graalvm.nativeimage.agent.jvmtibase,org.graalvm.nativeimage.agent.diagnostics,org.graalvm.nativeimage.objectfile",
"jdk.graal.compiler.util.json to org.graalvm.nativeimage.librarysupport,org.graalvm.nativeimage.agent.tracing,org.graalvm.nativeimage.configure,org.graalvm.nativeimage.driver",
Expand Down
12 changes: 12 additions & 0 deletions substratevm/mx.substratevm/mx_substratevm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1792,6 +1792,18 @@ def _native_image_launcher_extra_jvm_args():
extra_jvm_args=_native_image_launcher_extra_jvm_args(),
home_finder=False,
),
mx_sdk_vm.LauncherConfig(
use_modules='image',
main_module="org.graalvm.nativeimage.svm.niutils",
destination="bin/<exe:native-image-utils>",
jar_distributions=["substratevm:SVM_SBOM_EXTRACT"],
main_class="com.oracle.svm.niutils.NativeImageUtils",
build_args=driver_build_args + svm_experimental_options([
'-H:+UseLibExtractSbom',
'-H:NativeLinkerOption=-lelf',
]),
home_finder=False,
),
],
library_configs=[
mx_sdk_vm.LibraryConfig(
Expand Down
86 changes: 86 additions & 0 deletions substratevm/mx.substratevm/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,28 @@
"jacoco" : "exclude",
},

"com.oracle.svm.native.extractsbom": {
"subDir": "src",
"native": "static_lib",
"deliverable" : "extract_sbom",
"os_arch": {
"linux": {
"<others>": {
"cflags": ["-g", "-Wall" ],
},
},
"<others>": {
"<others>": {
"ignore": "only supported on linux",
},
},
},
"multitarget": {
"libc": ["glibc", "default"],
},
"jacoco" : "exclude",
},

"com.oracle.svm.native.reporterchelper": {
"subDir": "src",
"native": "shared_lib",
Expand Down Expand Up @@ -1724,6 +1746,32 @@
"jacoco" : "exclude",
},

"com.oracle.svm.native-image-utils-shim": {
"subDir": "src",
"sourceDirs": [
"src",
"resources"
],
"dependencies": [
"com.oracle.svm.configure",
"com.oracle.svm.driver",
],
"requiresConcealed" : {
"jdk.internal.vm.ci": [
"jdk.vm.ci.meta",
]
},
"checkstyle": "com.oracle.svm.hosted",
"workingSets": "SVM",
"annotationProcessors": [
"compiler:GRAAL_PROCESSOR",
"SVM_PROCESSOR",
],
"javaCompliance" : "24+",
"spotbugs": "false",
"jacoco" : "exclude",
},

"com.oracle.svm.truffle.tck" : {
"subDir": "src",
"sourceDirs": ["src"],
Expand Down Expand Up @@ -1951,6 +1999,7 @@
com.oracle.svm.svm_enterprise,
com.oracle.svm.svm_enterprise.llvm,
com.oracle.svm_enterprise.ml_dataset,
org.graalvm.nativeimage.svm.niutils,
org.graalvm.extraimage.builder,
org.graalvm.extraimage.librarysupport,
com.oracle.svm.extraimage_enterprise,
Expand Down Expand Up @@ -2078,6 +2127,7 @@
org.graalvm.nativeimage.guest.staging,
org.graalvm.nativeimage.junitsupport,
org.graalvm.nativeimage.pointsto,
org.graalvm.nativeimage.svm.niutils,
org.graalvm.truffle.runtime.svm""",
],
"opens" : [],
Expand Down Expand Up @@ -2395,6 +2445,7 @@
"dependency:com.oracle.svm.native.libchelper/*",
"dependency:com.oracle.svm.native.jvm.posix/*",
"dependency:com.oracle.svm.native.libcontainer/*",
"dependency:com.oracle.svm.native.extractsbom/*",
"file:debug/include",
"file:src/com.oracle.svm.core/src/com/oracle/svm/core/gc/shared/include",
],
Expand Down Expand Up @@ -2518,6 +2569,41 @@
"maven": False,
},

"SVM_SBOM_EXTRACT": {
"subDir": "src",
"description" : "Native image utility for SBOM extraction",
"mainClass": "com.oracle.svm.niutils.NativeImageUtils",
"dependencies": [
"com.oracle.svm.native-image-utils-shim",
],
"distDependencies": [
"LIBRARY_SUPPORT",
"SVM_DRIVER",
"compiler:GRAAL",
"sdk:NATIVEIMAGE",
"sdk:COLLECTIONS",
],
"moduleInfo" : {
"name" : "org.graalvm.nativeimage.svm.niutils",
"exports" : [
"com.oracle.svm.niutils",
],
"requires": [
"jdk.graal.compiler",
"org.graalvm.collections",
"org.graalvm.nativeimage.builder",
"org.graalvm.nativeimage.configure",
],
"requiresConcealed" : {
"jdk.internal.vm.ci" : [
"jdk.vm.ci.meta",
],
},
},
# vm: included as binary, tool descriptor intentionally not copied
"maven": False,
},

"SVM_CONFIGURE": {
"subDir": "src",
"description" : "SubstrateVM native-image configuration tool",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,10 @@ protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, Boolean o
@Option(help = "Enable detection and runtime container configuration support.")//
public static final HostedOptionKey<Boolean> UseContainerSupport = new HostedOptionKey<>(true);

@LayerVerifiedOption(kind = Kind.Changed, severity = Severity.Error)//
@Option(help = "Enable linking with libextract_sbom.a")//
public static final HostedOptionKey<Boolean> UseLibExtractSbom = new HostedOptionKey<>(false);

@Option(help = "The size of each thread stack at run-time, in bytes.", type = OptionType.User)//
public static final RuntimeOptionKey<Long> StackSize = new RuntimeOptionKey<>(0L);

Expand Down
17 changes: 17 additions & 0 deletions substratevm/src/com.oracle.svm.native-image-utils-shim/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Debugging native-image-utils with GDB

The native-image-utils binary allows for extraction of compressed SBOM bytes
from another native image.

Debugging native-image-utils requires building it with debug symbols. To do
that, execute:

```bash
$ native-image -g --macro:native-image-utils-launcher
```

Then you can debug `native-image-utils` with GDB:

```bash
$ gdb --args native-image-utils extract-sbom --image-path=/path/to/native-image-with-sbom-embedded
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.svm.niutils;

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;

public class NativeImageUtils {

private static String NAME = "native-image-utils";
private static String EXTRACT_CMD = "extract-sbom";
private static String EXECUTABLE_IMAGE_OPT = "image-path";

private static void usageAndExit() {
System.err.printf("Usage: %s %s --%s=<path/to/image%n", NAME, EXTRACT_CMD, EXECUTABLE_IMAGE_OPT);
System.exit(1);
}

// Simple double dash '--' options parsing with required value, specified via '=' assignment
private static Map<String, String> parseOptions(String[] args) throws OptionParsingException {
Map<String, String> options = new HashMap<>();
for (String arg : args) {
if (arg.startsWith("--")) {
String optionVal = arg.substring(2);
int equalsIdx = optionVal.indexOf('=');
if (equalsIdx == -1) {
throw new OptionParsingException("Illegal value for option " + arg);
} else {
String opt = String.format("--%s", optionVal.substring(0, equalsIdx));
String optVal = optionVal.substring(equalsIdx + 1);
options.put(opt, optVal);
}
}
// Skip any non-option arguments
}
return options;
}

public static void main(String[] args) {
if (args.length != 2) {
usageAndExit();
}
Path exe = null;
try {
Map<String, String> opts = parseOptions(args);
String imagePath = opts.get(String.format("--%s", EXECUTABLE_IMAGE_OPT));
if (imagePath == null) {
System.err.printf("--%s option missing", EXECUTABLE_IMAGE_OPT);
usageAndExit();
}
exe = Path.of(imagePath);
if (!Files.exists(exe)) {
System.err.println("Image path does not exist or is not readable: " + exe);
usageAndExit();
}
} catch (OptionParsingException e) {
System.err.println(e.getMessage());
usageAndExit();
}
System.exit(SbomExtractLibrary.extractSbom(exe));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.svm.niutils;

@SuppressWarnings("serial")
public class OptionParsingException extends Exception {

public OptionParsingException(String msg) {
super(msg);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright (c) 2026, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.svm.niutils;

import java.nio.file.Path;

import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;
import org.graalvm.nativeimage.c.CContext;
import org.graalvm.nativeimage.c.function.CFunction;
import org.graalvm.nativeimage.c.function.CFunction.Transition;
import org.graalvm.nativeimage.c.function.CLibrary;
import org.graalvm.nativeimage.c.type.CCharPointer;
import org.graalvm.nativeimage.c.type.CTypeConversion;
import org.graalvm.nativeimage.c.type.CTypeConversion.CCharPointerHolder;

import com.oracle.svm.core.SubstrateOptions;

/**
* Provides Java-level access to the native {@code libextract_sbom} implementation.
*/
@CContext(SbomExtractLibraryDirectives.class)
@CLibrary(value = "extract_sbom", requireStatic = true)
public class SbomExtractLibrary {

public static int extractSbom(Path executable) {
CCharPointerHolder exe = CTypeConversion.toCString(executable.toAbsolutePath().toString());
return extractSbomNative(exe.get());
}

@CFunction(value = "extract_sbom", transition = Transition.NO_TRANSITION)
private static native int extractSbomNative(CCharPointer executable);

}

@Platforms(Platform.HOSTED_ONLY.class)
class SbomExtractLibraryDirectives implements CContext.Directives {
/**
* True if {@link SbomExtractLibrary} should be linked.
*/
@Override
public boolean isInConfiguration() {
return Platform.includedIn(Platform.LINUX.class) && SubstrateOptions.UseLibExtractSbom.getValue();
}
}
Loading
Loading