From 4dad7a3f74b37e1db0aff2c904df17aba85d6789 Mon Sep 17 00:00:00 2001 From: Vlad Brezae Date: Thu, 19 Feb 2026 22:50:05 +0200 Subject: [PATCH] [r2r] Fix verbose logging `ProgressReporter` receives the total number of steps in the ctor and `LogProgress` is expected to be called this number of times, logging the progress in steps. Doing a composite r2r with --verbose is always crashing because logging fails when `total < Steps` due to division by 0 `_increment` (some assemblies being very small). Also, for other small `total` values, percentages over 100 were being logged. This commit fixes the crash and also this incorrect logging. --- .../Common/Compiler/ObjectWriter/ObjectWriter.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/coreclr/tools/Common/Compiler/ObjectWriter/ObjectWriter.cs b/src/coreclr/tools/Common/Compiler/ObjectWriter/ObjectWriter.cs index 9fe0dc6e7605c3..d7dcb15a7a2fe3 100644 --- a/src/coreclr/tools/Common/Compiler/ObjectWriter/ObjectWriter.cs +++ b/src/coreclr/tools/Common/Compiler/ObjectWriter/ObjectWriter.cs @@ -757,8 +757,9 @@ protected static ReadOnlySpan FormatUtf8Int(Span buffer, int number) private struct ProgressReporter { private readonly Logger _logger; - private readonly int _increment; + private readonly int _total; private int _current; + private int _lastReportedStep; // Will report progress every (100 / 10) = 10% private const int Steps = 10; @@ -766,18 +767,20 @@ private struct ProgressReporter public ProgressReporter(Logger logger, int total) { _logger = logger; - _increment = total / Steps; + _total = total; _current = 0; + _lastReportedStep = 0; } public void LogProgress() { _current++; - int adjusted = _current + Steps - 1; - if ((adjusted % _increment) == 0) + int step = (_current * Steps) / _total; + if (step > _lastReportedStep) { - _logger.LogMessage($"{(adjusted / _increment) * (100 / Steps)}%..."); + _logger.LogMessage($"{step * (100 / Steps)}%..."); + _lastReportedStep = step; } } }