@@ -381,7 +381,7 @@ def __init__(self, vm: NativeImageVM, bm_suite: BenchmarkSuite | NativeImageBenc
381
381
382
382
if vm .is_quickbuild :
383
383
base_image_build_args += ['-Ob' ]
384
- if vm .graalos :
384
+ if vm .graalos or vm . graalhost_graalos :
385
385
base_image_build_args += ['-H:+GraalOS' ]
386
386
if vm .use_string_inlining :
387
387
base_image_build_args += ['-H:+UseStringInlining' ]
@@ -717,8 +717,10 @@ def __init__(self, name, config_name, extra_java_args=None, extra_launcher_args=
717
717
self .pgo_sampler_only = False
718
718
self .is_gate = False
719
719
self .is_quickbuild = False
720
- self .layered = False
721
720
self .graalos = False
721
+ self .graalhost_graalos = False
722
+ self .pie = False
723
+ self .layered = False
722
724
self .use_string_inlining = False
723
725
self .is_llvm = False
724
726
self .gc = None
@@ -774,6 +776,14 @@ def config_name(self):
774
776
config += ["preserve-all" ]
775
777
if self .preserve_classpath is True :
776
778
config += ["preserve-classpath" ]
779
+ if self .graalos is True :
780
+ config += ["graalos" ]
781
+ if self .graalhost_graalos is True :
782
+ config += ["graalhost-graalos" ]
783
+ if self .pie is True :
784
+ config += ["pie" ]
785
+ if self .layered is True :
786
+ config += ["layered" ]
777
787
if self .future_defaults_all is True :
778
788
config += ["future-defaults-all" ]
779
789
if self .is_gate is True :
@@ -782,10 +792,6 @@ def config_name(self):
782
792
config += ["upx" ]
783
793
if self .is_quickbuild is True :
784
794
config += ["quickbuild" ]
785
- if self .layered is True :
786
- config += ["layered" ]
787
- if self .graalos is True :
788
- config += ["graalos" ]
789
795
if self .gc == "G1" :
790
796
config += ["g1gc" ]
791
797
if self .is_llvm is True :
@@ -847,7 +853,8 @@ def _configure_from_name(self, config_name):
847
853
# This defines the allowed config names for NativeImageVM. The ones registered will be available via --jvm-config
848
854
# Note: the order of entries here must match the order of statements in NativeImageVM.config_name()
849
855
rule = r'^(?P<native_architecture>native-architecture-)?(?P<string_inlining>string-inlining-)?(?P<otw>otw-)?(?P<compacting_gc>compacting-gc-)?(?P<preserve_all>preserve-all-)?(?P<preserve_classpath>preserve-classpath-)?' \
850
- r'(?P<future_defaults_all>future-defaults-all-)?(?P<gate>gate-)?(?P<upx>upx-)?(?P<quickbuild>quickbuild-)?(?P<layered>layered-)?(?P<graalos>graalos-)?(?P<gc>g1gc-)?' \
856
+ r'(?P<graalos>graalos-)?(?P<graalhost_graalos>graalhost-graalos-)?(?P<pie>pie-)?(?P<layered>layered-)?' \
857
+ r'(?P<future_defaults_all>future-defaults-all-)?(?P<gate>gate-)?(?P<upx>upx-)?(?P<quickbuild>quickbuild-)?(?P<gc>g1gc-)?' \
851
858
r'(?P<llvm>llvm-)?(?P<pgo>pgo-|pgo-sampler-)?(?P<inliner>inline-)?' \
852
859
r'(?P<analysis_context_sensitivity>insens-|allocsens-|1obj-|2obj1h-|3obj2h-|4obj3h-)?(?P<jdk_profiles>jdk-profiles-collect-|adopted-jdk-pgo-)?' \
853
860
r'(?P<profile_inference>profile-inference-feature-extraction-|profile-inference-call-count-|profile-inference-pgo-|profile-inference-debug-)?(?P<sampler>safepoint-sampler-|async-sampler-)?(?P<optimization_level>O0-|O1-|O2-|O3-|Os-)?(default-)?(?P<edition>ce-|ee-)?$'
@@ -870,6 +877,22 @@ def _configure_from_name(self, config_name):
870
877
mx .logv (f"'preserve-classpath' is enabled for { config_name } " )
871
878
self .preserve_classpath = True
872
879
880
+ if matching .group ("graalos" ) is not None :
881
+ mx .logv (f"'graalos' is enabled for { config_name } " )
882
+ self .graalos = True
883
+
884
+ if matching .group ("graalhost_graalos" ) is not None :
885
+ mx .logv (f"'graalhost-graalos' is enabled for { config_name } " )
886
+ self .graalhost_graalos = True
887
+
888
+ if matching .group ("pie" ) is not None :
889
+ mx .logv (f"'pie' is enabled for { config_name } " )
890
+ self .pie = True
891
+
892
+ if matching .group ("layered" ) is not None :
893
+ mx .logv (f"'layered' is enabled for { config_name } " )
894
+ self .layered = True
895
+
873
896
if matching .group ("future_defaults_all" ) is not None :
874
897
mx .logv (f"'future-defaults-all' is enabled for { config_name } " )
875
898
self .future_defaults_all = True
@@ -898,14 +921,6 @@ def _configure_from_name(self, config_name):
898
921
mx .logv (f"'quickbuild' is enabled for { config_name } " )
899
922
self .is_quickbuild = True
900
923
901
- if matching .group ("layered" ) is not None :
902
- mx .logv (f"'layered' is enabled for { config_name } " )
903
- self .layered = True
904
-
905
- if matching .group ("graalos" ) is not None :
906
- mx .logv (f"'graalos' is enabled for { config_name } " )
907
- self .graalos = True
908
-
909
924
if matching .group ("gc" ) is not None :
910
925
gc = matching .group ("gc" )[:- 1 ]
911
926
if gc == "g1gc" :
@@ -1503,42 +1518,45 @@ def run_stage_instrument_run(self):
1503
1518
print (
1504
1519
f"Profile file { self .config .profile_path } not dumped. Instrument run failed with exit code { exit_code } " )
1505
1520
1506
- def get_layered_build_args (self ) -> List [str ]:
1507
- """Return extra options that are necessary when building a layered image ."""
1521
+ def get_layer_aware_build_args (self ) -> List [str ]:
1522
+ """Return extra build options that are dependent on layer information ."""
1508
1523
current_stage = self .stages_info .current_stage
1509
- if not self .layered or current_stage .layer_info .is_shared_library :
1510
- # No extra options are necessary if we are not building a layered image
1511
- # No extra options are necessary when building shared layers
1512
- return []
1513
-
1514
- # Set LinkerRPath to point to the directories containing the shared objects of underlying layers
1515
- shared_library_stages = [stage for stage in self .stages_info .complete_stage_list
1516
- if current_stage .stage_name == stage .stage_name and stage .is_layered () and stage .layer_info .is_shared_library ]
1517
- if len (shared_library_stages ) == 0 :
1518
- mx .abort ("Failed to find any shared library layer image stages!" )
1519
- layer_output_dirs = []
1520
- for stage in shared_library_stages :
1521
- _ , stage_output_dir = self .config .get_executable_name_and_output_dir_for_stage (stage , self )
1522
- layer_output_dirs .append (stage_output_dir .absolute ().as_posix ())
1523
- linker_r_path = "," .join (layer_output_dirs )
1524
- layer_build_args = [f"-H:LinkerRPath={ linker_r_path } " ]
1525
-
1526
- # Set LayerUse to point to the .nil archive of the preceeding layer
1527
- last_shared_library_stage_output_dir = Path (layer_output_dirs [- 1 ])
1528
- nil_archives = list (last_shared_library_stage_output_dir .glob ("*.nil" ))
1529
- if len (nil_archives ) == 0 :
1530
- mx .abort (
1531
- f"Could not determine the .nil archive of the preceding shared library layer!"
1532
- f" No .nil archives located in '{ last_shared_library_stage_output_dir } ' directory!"
1533
- )
1534
- if len (nil_archives ) > 1 :
1535
- mx .abort (
1536
- f"Could not determine the .nil archive of the preceding shared library layer!"
1537
- f" Multiple files found: { nil_archives } "
1538
- )
1539
- layer_build_args .append (f"-H:LayerUse={ nil_archives [0 ]} " )
1524
+ layer_aware_build_args = []
1525
+
1526
+ if self .pie and (not self .layered or not current_stage .layer_info .is_shared_library ):
1527
+ # This option should not be applied to base layers
1528
+ layer_aware_build_args += ["-H:NativeLinkerOption=-pie" ]
1529
+
1530
+ if self .layered and not current_stage .layer_info .is_shared_library :
1531
+ # Set LinkerRPath to point to the directories containing the shared objects of underlying layers
1532
+ shared_library_stages = [stage for stage in self .stages_info .complete_stage_list
1533
+ if current_stage .stage_name == stage .stage_name and stage .is_layered () and stage .layer_info .is_shared_library ]
1534
+ if len (shared_library_stages ) == 0 :
1535
+ mx .abort ("Failed to find any shared library layer image stages!" )
1536
+ layer_output_dirs = []
1537
+ for stage in shared_library_stages :
1538
+ _ , stage_output_dir = self .config .get_executable_name_and_output_dir_for_stage (stage , self )
1539
+ layer_output_dirs .append (stage_output_dir .absolute ().as_posix ())
1540
+ linker_r_path = "," .join (layer_output_dirs )
1541
+ app_layer_build_args = [f"-H:LinkerRPath={ linker_r_path } " ]
1542
+
1543
+ # Set LayerUse to point to the .nil archive of the preceeding layer
1544
+ last_shared_library_stage_output_dir = Path (layer_output_dirs [- 1 ])
1545
+ nil_archives = list (last_shared_library_stage_output_dir .glob ("*.nil" ))
1546
+ if len (nil_archives ) == 0 :
1547
+ mx .abort (
1548
+ f"Could not determine the .nil archive of the preceding shared library layer!"
1549
+ f" No .nil archives located in '{ last_shared_library_stage_output_dir } ' directory!"
1550
+ )
1551
+ if len (nil_archives ) > 1 :
1552
+ mx .abort (
1553
+ f"Could not determine the .nil archive of the preceding shared library layer!"
1554
+ f" Multiple files found: { nil_archives } "
1555
+ )
1556
+ app_layer_build_args .append (f"-H:LayerUse={ nil_archives [0 ]} " )
1557
+ layer_aware_build_args += app_layer_build_args
1540
1558
1541
- return layer_build_args
1559
+ return layer_aware_build_args
1542
1560
1543
1561
def run_stage_image (self ):
1544
1562
executable_name_args = ['-o' , self .config .final_image_name ]
@@ -1578,7 +1596,7 @@ def run_stage_image(self):
1578
1596
[f"-H:BuildOutputJSONFile={ self .config .get_build_output_json_file (StageName .IMAGE )} " ])
1579
1597
final_image_command = (self .config .base_image_build_args + executable_name_args
1580
1598
+ (pgo_args if self .pgo_instrumentation else []) + jdk_profiles_args + ml_args + ml_debug_args
1581
- + collection_args + self .get_layered_build_args ())
1599
+ + collection_args + self .get_layer_aware_build_args ())
1582
1600
with self .get_stage_runner () as s :
1583
1601
exit_code = s .execute_command (self , final_image_command )
1584
1602
NativeImageVM .move_bundle_output (self .config , self .config .image_path )
0 commit comments