Skip to content

Commit 44ec746

Browse files
committed
Fix base layer shared object linking.
1 parent 54146ef commit 44ec746

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/CCLinkerInvocation.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,13 +340,18 @@ protected void setOutputKind(List<String> cmd) {
340340
@Override
341341
protected List<String> getLibrariesCommand() {
342342
List<String> cmd = new ArrayList<>();
343+
String pushState = "-Wl,--push-state";
344+
String popState = "-Wl,--pop-state";
343345
if (customStaticLibs) {
344-
cmd.add("-Wl,--push-state");
346+
cmd.add(pushState);
345347
}
348+
String previousLayerLib = null;
346349
for (String lib : libs) {
347350
String linkingMode = null;
348-
if (ImageLayerBuildingSupport.buildingImageLayer() && HostedDynamicLayerInfo.singleton().isImageLayerLib(lib)) {
349-
linkingMode = "dynamic";
351+
if (ImageLayerBuildingSupport.buildingExtensionLayer() && HostedDynamicLayerInfo.singleton().isImageLayerLib(lib)) {
352+
VMError.guarantee(!lib.isEmpty());
353+
VMError.guarantee(previousLayerLib == null, "We currently only support one previous layer."); // GR-58631
354+
previousLayerLib = lib;
350355
} else if (dynamicLibC) {
351356
linkingMode = LIB_C_NAMES.contains(lib) ? "dynamic" : "static";
352357
} else if (staticLibCpp) {
@@ -358,7 +363,14 @@ protected List<String> getLibrariesCommand() {
358363
cmd.add("-l" + lib);
359364
}
360365
if (customStaticLibs) {
361-
cmd.add("-Wl,--pop-state");
366+
cmd.add(popState);
367+
}
368+
369+
if (previousLayerLib != null) {
370+
cmd.add(pushState);
371+
cmd.add("-Wl,-Bdynamic");
372+
cmd.add("-l" + previousLayerLib);
373+
cmd.add(popState);
362374
}
363375

364376
// Make sure libgcc gets statically linked

0 commit comments

Comments
 (0)