RFR: 8370438: Offer link time optimization support on library level [v5]

Erik Joelsson erikj at openjdk.org
Thu Nov 6 14:01:54 UTC 2025


On Thu, 6 Nov 2025 12:32:14 GMT, Matthias Baesken <mbaesken at openjdk.org> wrote:

>> 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.
>
>> I don't think adding the LTO flags to the OPT flags is the right move
> 
> So where should I move it? After all it is link time *optimization* so it is an optimization related tool feature. 
> But should I remove it completely from SetupCompileFileFlags because having it in  SetupCompilerFlags is sufficient for out task ?

Again, the optimization flags aren't handled as a separate set of variables because they are of the category "optimization". It's because optimization flags are handled on a higher level with an abstraction of "low", "medium", "high" etc, and that abstraction allows for specific file overrides. That's what the `*_OPT_C*FLAGS` are there to handle. Since the LTO flags are not related to this abstraction, they should not be mixed into these variables, that is just confusing and adding unnecessary complexity.

The LTO flags should just be stacked on to the `$1_EXTRA_*` flags like any other.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/27976#discussion_r2499047995


More information about the client-libs-dev mailing list