@@ -388,7 +388,7 @@ def __init__(self, vm: NativeImageVM, bm_suite: BenchmarkSuite | NativeImageBenc
388388
389389 if vm .is_quickbuild :
390390 base_image_build_args += ['-Ob' ]
391- if vm .graalos :
391+ if vm .graalos or vm . graalhost_graalos :
392392 base_image_build_args += ['-H:+GraalOS' ]
393393 if vm .use_string_inlining :
394394 base_image_build_args += ['-H:+UseStringInlining' ]
@@ -728,8 +728,10 @@ def __init__(self, name, config_name, extra_java_args=None, extra_launcher_args=
728728 self .pgo_perf_invoke_profile_collection_strategy : Optional [PerfInvokeProfileCollectionStrategy ] = None
729729 self .is_gate = False
730730 self .is_quickbuild = False
731- self .layered = False
732731 self .graalos = False
732+ self .graalhost_graalos = False
733+ self .pie = False
734+ self .layered = False
733735 self .use_string_inlining = False
734736 self .is_llvm = False
735737 self .gc = None
@@ -785,6 +787,14 @@ def config_name(self):
785787 config += ["preserve-all" ]
786788 if self .preserve_classpath is True :
787789 config += ["preserve-classpath" ]
790+ if self .graalos is True :
791+ config += ["graalos" ]
792+ if self .graalhost_graalos is True :
793+ config += ["graalhost-graalos" ]
794+ if self .pie is True :
795+ config += ["pie" ]
796+ if self .layered is True :
797+ config += ["layered" ]
788798 if self .future_defaults_all is True :
789799 config += ["future-defaults-all" ]
790800 if self .is_gate is True :
@@ -793,10 +803,6 @@ def config_name(self):
793803 config += ["upx" ]
794804 if self .is_quickbuild is True :
795805 config += ["quickbuild" ]
796- if self .layered is True :
797- config += ["layered" ]
798- if self .graalos is True :
799- config += ["graalos" ]
800806 if self .gc == "G1" :
801807 config += ["g1gc" ]
802808 if self .is_llvm is True :
@@ -862,7 +868,8 @@ def _configure_from_name(self, config_name):
862868 # This defines the allowed config names for NativeImageVM. The ones registered will be available via --jvm-config
863869 # Note: the order of entries here must match the order of statements in NativeImageVM.config_name()
864870 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-)?' \
865- 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-)?' \
871+ r'(?P<graalos>graalos-)?(?P<graalhost_graalos>graalhost-graalos-)?(?P<pie>pie-)?(?P<layered>layered-)?' \
872+ r'(?P<future_defaults_all>future-defaults-all-)?(?P<gate>gate-)?(?P<upx>upx-)?(?P<quickbuild>quickbuild-)?(?P<gc>g1gc-)?' \
866873 r'(?P<llvm>llvm-)?(?P<pgo>pgo-|pgo-sampler-|pgo-perf-sampler-invoke-multiple-|pgo-perf-sampler-invoke-|pgo-perf-sampler-)?(?P<inliner>inline-)?' \
867874 r'(?P<analysis_context_sensitivity>insens-|allocsens-|1obj-|2obj1h-|3obj2h-|4obj3h-)?(?P<jdk_profiles>jdk-profiles-collect-|adopted-jdk-pgo-)?' \
868875 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-)?$'
@@ -885,6 +892,22 @@ def _configure_from_name(self, config_name):
885892 mx .logv (f"'preserve-classpath' is enabled for { config_name } " )
886893 self .preserve_classpath = True
887894
895+ if matching .group ("graalos" ) is not None :
896+ mx .logv (f"'graalos' is enabled for { config_name } " )
897+ self .graalos = True
898+
899+ if matching .group ("graalhost_graalos" ) is not None :
900+ mx .logv (f"'graalhost-graalos' is enabled for { config_name } " )
901+ self .graalhost_graalos = True
902+
903+ if matching .group ("pie" ) is not None :
904+ mx .logv (f"'pie' is enabled for { config_name } " )
905+ self .pie = True
906+
907+ if matching .group ("layered" ) is not None :
908+ mx .logv (f"'layered' is enabled for { config_name } " )
909+ self .layered = True
910+
888911 if matching .group ("future_defaults_all" ) is not None :
889912 mx .logv (f"'future-defaults-all' is enabled for { config_name } " )
890913 self .future_defaults_all = True
@@ -913,14 +936,6 @@ def _configure_from_name(self, config_name):
913936 mx .logv (f"'quickbuild' is enabled for { config_name } " )
914937 self .is_quickbuild = True
915938
916- if matching .group ("layered" ) is not None :
917- mx .logv (f"'layered' is enabled for { config_name } " )
918- self .layered = True
919-
920- if matching .group ("graalos" ) is not None :
921- mx .logv (f"'graalos' is enabled for { config_name } " )
922- self .graalos = True
923-
924939 if matching .group ("gc" ) is not None :
925940 gc = matching .group ("gc" )[:- 1 ]
926941 if gc == "g1gc" :
@@ -1571,42 +1586,45 @@ def run_stage_instrument_run(self):
15711586 print (
15721587 f"Profile file { self .config .profile_path } not dumped. Instrument run failed with exit code { exit_code } " )
15731588
1574- def get_layered_build_args (self ) -> List [str ]:
1575- """Return extra options that are necessary when building a layered image ."""
1589+ def get_layer_aware_build_args (self ) -> List [str ]:
1590+ """Return extra build options that are dependent on layer information ."""
15761591 current_stage = self .stages_info .current_stage
1577- if not self .layered or current_stage .layer_info .is_shared_library :
1578- # No extra options are necessary if we are not building a layered image
1579- # No extra options are necessary when building shared layers
1580- return []
1581-
1582- # Set LinkerRPath to point to the directories containing the shared objects of underlying layers
1583- shared_library_stages = [stage for stage in self .stages_info .complete_stage_list
1584- if current_stage .stage_name == stage .stage_name and stage .is_layered () and stage .layer_info .is_shared_library ]
1585- if len (shared_library_stages ) == 0 :
1586- mx .abort ("Failed to find any shared library layer image stages!" )
1587- layer_output_dirs = []
1588- for stage in shared_library_stages :
1589- _ , stage_output_dir = self .config .get_executable_name_and_output_dir_for_stage (stage , self )
1590- layer_output_dirs .append (stage_output_dir .absolute ().as_posix ())
1591- linker_r_path = "," .join (layer_output_dirs )
1592- layer_build_args = [f"-H:LinkerRPath={ linker_r_path } " ]
1593-
1594- # Set LayerUse to point to the .nil archive of the preceeding layer
1595- last_shared_library_stage_output_dir = Path (layer_output_dirs [- 1 ])
1596- nil_archives = list (last_shared_library_stage_output_dir .glob ("*.nil" ))
1597- if len (nil_archives ) == 0 :
1598- mx .abort (
1599- f"Could not determine the .nil archive of the preceding shared library layer!"
1600- f" No .nil archives located in '{ last_shared_library_stage_output_dir } ' directory!"
1601- )
1602- if len (nil_archives ) > 1 :
1603- mx .abort (
1604- f"Could not determine the .nil archive of the preceding shared library layer!"
1605- f" Multiple files found: { nil_archives } "
1606- )
1607- layer_build_args .append (f"-H:LayerUse={ nil_archives [0 ]} " )
1592+ layer_aware_build_args = []
1593+
1594+ if self .pie and (not self .layered or not current_stage .layer_info .is_shared_library ):
1595+ # This option should not be applied to base layers
1596+ layer_aware_build_args += ["-H:NativeLinkerOption=-pie" ]
1597+
1598+ if self .layered and not current_stage .layer_info .is_shared_library :
1599+ # Set LinkerRPath to point to the directories containing the shared objects of underlying layers
1600+ shared_library_stages = [stage for stage in self .stages_info .complete_stage_list
1601+ if current_stage .stage_name == stage .stage_name and stage .is_layered () and stage .layer_info .is_shared_library ]
1602+ if len (shared_library_stages ) == 0 :
1603+ mx .abort ("Failed to find any shared library layer image stages!" )
1604+ layer_output_dirs = []
1605+ for stage in shared_library_stages :
1606+ _ , stage_output_dir = self .config .get_executable_name_and_output_dir_for_stage (stage , self )
1607+ layer_output_dirs .append (stage_output_dir .absolute ().as_posix ())
1608+ linker_r_path = "," .join (layer_output_dirs )
1609+ app_layer_build_args = [f"-H:LinkerRPath={ linker_r_path } " ]
1610+
1611+ # Set LayerUse to point to the .nil archive of the preceeding layer
1612+ last_shared_library_stage_output_dir = Path (layer_output_dirs [- 1 ])
1613+ nil_archives = list (last_shared_library_stage_output_dir .glob ("*.nil" ))
1614+ if len (nil_archives ) == 0 :
1615+ mx .abort (
1616+ f"Could not determine the .nil archive of the preceding shared library layer!"
1617+ f" No .nil archives located in '{ last_shared_library_stage_output_dir } ' directory!"
1618+ )
1619+ if len (nil_archives ) > 1 :
1620+ mx .abort (
1621+ f"Could not determine the .nil archive of the preceding shared library layer!"
1622+ f" Multiple files found: { nil_archives } "
1623+ )
1624+ app_layer_build_args .append (f"-H:LayerUse={ nil_archives [0 ]} " )
1625+ layer_aware_build_args += app_layer_build_args
16081626
1609- return layer_build_args
1627+ return layer_aware_build_args
16101628
16111629 def run_stage_image (self ):
16121630 executable_name_args = ['-o' , self .config .final_image_name ]
@@ -1653,7 +1671,7 @@ def run_stage_image(self):
16531671 [f"-H:BuildOutputJSONFile={ self .config .get_build_output_json_file (StageName .IMAGE )} " ])
16541672 final_image_command = (self .config .base_image_build_args + executable_name_args
16551673 + (pgo_args if self .pgo_instrumentation else []) + jdk_profiles_args + ml_args + ml_debug_args
1656- + collection_args + self .get_layered_build_args ())
1674+ + collection_args + self .get_layer_aware_build_args ())
16571675 with self .get_stage_runner () as s :
16581676 exit_code = s .execute_command (self , final_image_command )
16591677 NativeImageVM .move_bundle_output (self .config , self .config .image_path )
0 commit comments