> On 9 Mar 2026, at 10:20, Jan Beulich <[email protected]> wrote:
> 
> On 09.03.2026 10:49, Edwin Torok wrote:
>>> On 9 Mar 2026, at 07:47, Jan Beulich <[email protected]> wrote:
>>> There's
>>> one other question though: Isn't -O0 the default? Where would any other
>>> optimization setting come from in HOSTCFLAGS? Ah, I see ./Config.mk does
>>> this, for an unclear to me reason.
>> 
>> One possible reason I’d enable optimisations (even for non-performance 
>> critical code) is to get better warnings.
>> I looked this up, and I see it is actually documented in the GCC manual:
>> "The effectiveness of some warnings depends on optimizations also being 
>> enabled.
>> For example, -Wsuggest-final-types is more effective with link-time 
>> optimization. 
>> Some other warnings may not be issued at all unless optimization is enabled.
>> While optimization in general improves the efficacy of warnings about 
>> control and data-flow problems,
>> in some cases it may also cause false positives.”
>> 
>> In fact warnings rely on optimisations even more than I thought, didn’t know 
>> about link time optimisations having an effect
>> (from the example that warning is only relevant for C++ for now)
>> 
>> I can see why in general a compiler would decide to implement it that way 
>> (if you run an analysis to get more accurate
>> information for showing warnings then you might as well use it to emit 
>> better code), but I wish that wasn’t the case. 
>> E.g. you may want to use a low optimisation level to get better debugging, 
>> without giving up on the better warnings.
>> The only way to do that currently is to build it twice (or rely on a CI that 
>> builds with different flags).
>> 
>> If you want to change it I’d suggest setting it at least to -Og, which is 
>> recommended over O0:
>> "In contrast to -O0, this enables -fvar-tracking-assignments and 
>> -fvar-tracking which handle debug information in the prologue and epilogue 
>> of functions better than -O0."
> 
> And did you check that -Og works for the purposes here? I'd indeed prefer to
> use that, if we can.


It avoids the duplicate symbol error with version of Clang that I have, so I 
have sent a V4 that uses -Og and the updated comments.
Was a bit worried this might not work with old GCCs, but AFAICT Og is supported 
since 4.8, and the minimum is 5.1.

Best regards,
—Edwin

> 
>>> Perhaps that would want mentioning
>>> here then as well.
>> 
>> How about:
>> 
>> # The default HOSTCFLAGS from $(XEN_ROOT)/Config.mk would set
>> # a non-zero optimisation level
>> 
>> I’d avoid mentioning -O2, in case that changes.
> 
> Of course.
> 
> Jan

Reply via email to