@@ -340,13 +340,18 @@ protected void setOutputKind(List<String> cmd) {
340
340
@ Override
341
341
protected List <String > getLibrariesCommand () {
342
342
List <String > cmd = new ArrayList <>();
343
+ String pushState = "-Wl,--push-state" ;
344
+ String popState = "-Wl,--pop-state" ;
343
345
if (customStaticLibs ) {
344
- cmd .add ("-Wl,--push-state" );
346
+ cmd .add (pushState );
345
347
}
348
+ String previousLayerLib = null ;
346
349
for (String lib : libs ) {
347
350
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 ;
350
355
} else if (dynamicLibC ) {
351
356
linkingMode = LIB_C_NAMES .contains (lib ) ? "dynamic" : "static" ;
352
357
} else if (staticLibCpp ) {
@@ -358,7 +363,14 @@ protected List<String> getLibrariesCommand() {
358
363
cmd .add ("-l" + lib );
359
364
}
360
365
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 );
362
374
}
363
375
364
376
// Make sure libgcc gets statically linked
0 commit comments