On Tue, 4 Nov 2025 16:49:06 GMT, Matthias Baesken <[email protected]> wrote:
>> We currently have support for LTO (link time optimization) for >> Hotspot/libjvm, that can be enabled as a JVM feature. >> But for other JDK native libs, we do not have support for this feature. >> LTO and sometimes lead to faster and also in some cases smaller binaries, so >> support for this might be interesting also for other libs and not only >> libjvm. > > Matthias Baesken has updated the pull request incrementally with one > additional commit since the last revision: > > Use lto configure flags in hs build make/autoconf/flags-cflags.m4 line 285: > 283: C_O_FLAG_NONE="-O0" > 284: > 285: # link time optimization can be additionally enabled on lib level I don't think this comment makes much sense in this context. make/common/native/Flags.gmk line 69: > 67: $1_OPT_CFLAGS += $(C_O_FLAG_LTO) > 68: $1_OPT_CXXFLAGS += $(CXX_O_FLAG_LTO) > 69: endif I don't think adding the LTO flags to the OPT flags is the right move, but if we are going with that, then this addition of LTO flags should only be done if `$$($1_OPTIMIZATION)` is set, as otherwise, those flags are already added through `$$($2_OPT_CFLAGS)`. That means, this block should be moved into the else block above, before the endif on line 64. However, the OPT flags are treated separately through SetupCompilerFlags and SetupCompileFileFlags because it should be possible to override the optimization level on a per file basis. The LTO flags on the other hand, are not possible to override on a per file basis, so we should not be tinkering with those in the SetupCompileFileFlags macro at all. So mixing in the LTO flags with the OPT flags is the wrong move. make/common/native/Flags.gmk line 242: > 240: ifeq ($$($1_LINK_TIME_OPTIMIZATION), true) > 241: $1_EXTRA_LDFLAGS += $(LDFLAGS_LTO) > 242: endif For flag ordering, I think this being a link unit global setting should be appended before the OS and TOOLCHAIN specific flags above. make/hotspot/lib/JvmFeatures.gmk line 186: > 184: else ifeq ($(call isCompiler, microsoft), true) > 185: JVM_CFLAGS_FEATURES += $(CXX_O_FLAG_LTO) > 186: JVM_LDFLAGS_FEATURES += $(LDFLAGS_LTO) Now that we have variables for LTO flags, we shouldn't need compiler type checks for adding them. We can keep the conditionals for the other flags, but adding LTO flags looks compiler agnostic. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/27976#discussion_r2495462638 PR Review Comment: https://git.openjdk.org/jdk/pull/27976#discussion_r2495525800 PR Review Comment: https://git.openjdk.org/jdk/pull/27976#discussion_r2495534912 PR Review Comment: https://git.openjdk.org/jdk/pull/27976#discussion_r2495546178
