Skip to content

Commit 293ff12

Browse files
committed
[GR-66764] Enforce base layer image name conventions early.
Check the image name requirements early so that we cannot even build a base-layer that would be unusable due to its image name.
1 parent 41c2564 commit 293ff12

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/imagelayer/HostedImageLayerBuildingSupport.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
import com.oracle.svm.core.option.SubstrateOptionsParser;
4949
import com.oracle.svm.core.util.ArchiveSupport;
5050
import com.oracle.svm.core.util.UserError;
51-
import com.oracle.svm.core.util.VMError;
5251
import com.oracle.svm.hosted.ImageClassLoader;
5352
import com.oracle.svm.hosted.NativeImageClassLoaderSupport;
5453
import com.oracle.svm.hosted.c.NativeLibraries;
@@ -337,15 +336,9 @@ public static Map<String, OptionLayerVerificationRequests> collectLayerVerificat
337336

338337
@SuppressFBWarnings(value = "NP", justification = "FB reports null pointer dereferencing because it doesn't see through UserError.guarantee.")
339338
public static void setupSharedLayerLibrary(NativeLibraries nativeLibs) {
340-
Path sharedLibPath = HostedImageLayerBuildingSupport.singleton().getLoadLayerArchiveSupport().getSharedLibraryPath();
341-
Path parent = sharedLibPath.getParent();
342-
VMError.guarantee(parent != null, "Shared layer library path doesn't have a parent.");
343-
nativeLibs.getLibraryPaths().add(parent.toString());
344-
Path fileName = sharedLibPath.getFileName();
345-
VMError.guarantee(fileName != null, "Cannot determine shared layer library file name.");
346-
String fullLibName = fileName.toString();
347-
VMError.guarantee(fullLibName.startsWith("lib") && fullLibName.endsWith(".so"), "Expecting that shared layer library file starts with lib and ends with .so. Found: %s", fullLibName);
348-
String libName = fullLibName.substring("lib".length(), fullLibName.length() - ".so".length());
339+
LoadLayerArchiveSupport archiveSupport = HostedImageLayerBuildingSupport.singleton().getLoadLayerArchiveSupport();
340+
nativeLibs.getLibraryPaths().add(archiveSupport.getSharedLibraryPath().toString());
341+
String libName = archiveSupport.getSharedLibraryBaseName();
349342
HostedDynamicLayerInfo.singleton().registerLibName(libName);
350343
nativeLibs.addDynamicNonJniLibrary(libName);
351344
}

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/imagelayer/LayerArchiveSupport.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public class LayerArchiveSupport {
5353
private static final String SNAPSHOT_GRAPHS_FILE_NAME = "layer-snapshot-graphs.big";
5454
private static final String LAYER_INFO_MESSAGE_PREFIX = "Native Image Layers";
5555
protected static final String LAYER_TEMP_DIR_PREFIX = "layerRoot_";
56+
protected static final String SHARED_LIB_NAME_PREFIX = "lib";
5657

5758
public static final String LAYER_FILE_EXTENSION = ".nil";
5859

@@ -103,7 +104,11 @@ public Path getSnapshotGraphsPath() {
103104
}
104105

105106
public Path getSharedLibraryPath() {
106-
return layerDir.resolve(layerProperties.layerName() + ".so");
107+
return layerDir;
108+
}
109+
110+
public String getSharedLibraryBaseName() {
111+
return layerProperties.layerName().substring(SHARED_LIB_NAME_PREFIX.length());
107112
}
108113

109114
private static final Path layerPropertiesFileName = Path.of("META-INF/nilayer.properties");

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/imagelayer/WriteLayerArchiveSupport.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
import com.oracle.svm.core.BuildArtifacts;
3333
import com.oracle.svm.core.BuildArtifacts.ArtifactType;
34+
import com.oracle.svm.core.SubstrateOptions;
35+
import com.oracle.svm.core.option.SubstrateOptionsParser;
3436
import com.oracle.svm.core.util.ArchiveSupport;
3537
import com.oracle.svm.core.util.UserError;
3638
import com.oracle.svm.hosted.NativeImageClassLoaderSupport;
@@ -41,6 +43,11 @@ public class WriteLayerArchiveSupport extends LayerArchiveSupport {
4143

4244
public WriteLayerArchiveSupport(String layerName, NativeImageClassLoaderSupport classLoaderSupport, Path tempDir, ArchiveSupport archiveSupport) {
4345
super(layerName, classLoaderSupport.getLayerFile(), tempDir.resolve(LAYER_TEMP_DIR_PREFIX + "write"), archiveSupport);
46+
if (!layerName.startsWith(SHARED_LIB_NAME_PREFIX)) {
47+
throw UserError.abort("Shared layer library image name given with '" +
48+
SubstrateOptionsParser.commandArgument(SubstrateOptions.Name, layerName) +
49+
"' needs to start with '" + SHARED_LIB_NAME_PREFIX + "'");
50+
}
4451
builderArguments.addAll(classLoaderSupport.getHostedOptionParser().getArguments());
4552
}
4653

0 commit comments

Comments
 (0)