Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,7 @@ protected NativeLibraries setupNativeLibraries(HostedProviders providers, CEnumC
throw new InterruptImageBuilding("Exiting image generation because of " + SubstrateOptionsParser.commandArgument(CAnnotationProcessorCache.Options.ExitAfterCAPCache, "+"));
}
if (ImageLayerBuildingSupport.buildingExtensionLayer()) {
HostedImageLayerBuildingSupport.setupSharedLayerLibrary(nativeLibs);
HostedImageLayerBuildingSupport.singleton().setupSharedLayerLibrary(nativeLibs);
}
return nativeLibs;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import com.oracle.svm.core.SubstrateOptions;
import com.oracle.svm.core.c.libc.BionicLibC;
import com.oracle.svm.core.c.libc.LibCBase;
import com.oracle.svm.core.imagelayer.ImageLayerBuildingSupport;
import com.oracle.svm.core.option.AccumulatingLocatableMultiOptionValue;
import com.oracle.svm.core.option.HostedOptionKey;
import com.oracle.svm.core.util.UserError;
Expand All @@ -56,6 +57,7 @@
import com.oracle.svm.hosted.c.NativeLibraries;
import com.oracle.svm.hosted.c.codegen.CCompilerInvoker;
import com.oracle.svm.hosted.c.libc.HostedLibCBase;
import com.oracle.svm.hosted.imagelayer.HostedDynamicLayerInfo;
import com.oracle.svm.hosted.jdk.JNIRegistrationSupport;

import jdk.graal.compiler.options.Option;
Expand Down Expand Up @@ -343,7 +345,9 @@ protected List<String> getLibrariesCommand() {
}
for (String lib : libs) {
String linkingMode = null;
if (dynamicLibC) {
if (ImageLayerBuildingSupport.buildingImageLayer() && HostedDynamicLayerInfo.singleton().isImageLayerLib(lib)) {
linkingMode = "dynamic";
} else if (dynamicLibC) {
linkingMode = LIB_C_NAMES.contains(lib) ? "dynamic" : "static";
} else if (staticLibCpp) {
linkingMode = lib.equals("stdc++") ? "static" : "dynamic";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,23 @@ public class HostedDynamicLayerInfo extends DynamicImageLayerInfo implements Lay
private final ConcurrentHashMap<Integer, MethodNameInfo> methodIdToNameInfoMap;
private final CGlobalData<PointerBase> cGlobalData;
private final Set<String> priorLayerMethodSymbols = new HashSet<>();
private final List<String> libNames;
private boolean persisted = false;

HostedDynamicLayerInfo() {
this(0, null, new HashMap<>(), new ConcurrentHashMap<>());
this(0, null, new HashMap<>(), new ConcurrentHashMap<>(), new ArrayList<>());
}

public static HostedDynamicLayerInfo singleton() {
return (HostedDynamicLayerInfo) ImageSingletons.lookup(DynamicImageLayerInfo.class);
}

private HostedDynamicLayerInfo(int layerNumber, String codeSectionStartSymbol, Map<Integer, Integer> methodIdToOffsetMap, ConcurrentHashMap<Integer, MethodNameInfo> methodIdToNameInfoMap) {
private HostedDynamicLayerInfo(int layerNumber, String codeSectionStartSymbol, Map<Integer, Integer> methodIdToOffsetMap, ConcurrentHashMap<Integer, MethodNameInfo> methodIdToNameInfoMap,
List<String> libNames) {
super(layerNumber);
this.methodIdToOffsetMap = methodIdToOffsetMap;
this.methodIdToNameInfoMap = methodIdToNameInfoMap;
this.libNames = libNames;
cGlobalData = codeSectionStartSymbol == null ? null : CGlobalDataFactory.forSymbol(codeSectionStartSymbol);
}

Expand Down Expand Up @@ -141,6 +144,14 @@ public void defineSymbolsForPriorLayerMethods(ObjectFile objectFile) {
priorLayerMethodSymbols.forEach(symbol -> objectFile.createUndefinedSymbol(symbol, 0, true));
}

public void registerLibName(String lib) {
libNames.add(lib);
}

public boolean isImageLayerLib(String lib) {
return libNames.contains(lib);
}

@Override
public EnumSet<LayeredImageSingletonBuilderFlags> getImageBuilderFlags() {
return LayeredImageSingletonBuilderFlags.BUILDTIME_ACCESS_ONLY;
Expand Down Expand Up @@ -207,6 +218,8 @@ public PersistFlags preparePersist(ImageSingletonWriter writer) {
writer.writeIntList("methodNameIDs", methodNameIds);
writer.writeStringList("names", names);

writer.writeStringList("libNames", libNames);

return PersistFlags.CREATE;
}

Expand Down Expand Up @@ -248,7 +261,9 @@ public static Object createFromLoader(ImageSingletonLoader loader) {
assert prev == null;
}

return new HostedDynamicLayerInfo(layerNumber, codeSectionStartSymbol, initialMethodIdToOffsetMap, initialMethodIdToMethodNameMap);
var libNames = loader.readStringList("libNames");

return new HostedDynamicLayerInfo(layerNumber, codeSectionStartSymbol, initialMethodIdToOffsetMap, initialMethodIdToMethodNameMap, libNames);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,18 @@ public static HostedImageLayerBuildingSupport initialize(HostedOptionValues valu
}

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

public static void setupImageLayerArtifacts(String imageName) {
Expand Down
Loading