Skip to content

Commit a97b28e

Browse files
RakeshwarKRakeshwar Reddy Kambaiahgari
authored andcommitted
Fix SPEC CPU build failure on GCC 15 (microsoft#688)
* Gcc15Workaround * up version * added tests * upversion --------- Signed-off-by: Rakesh <153008248+RakeshwarK@users.noreply.github.com> Co-authored-by: Rakeshwar Reddy Kambaiahgari <rkambaiahgar@microsoft.com>
1 parent d92608f commit a97b28e

8 files changed

Lines changed: 121 additions & 2 deletions

File tree

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.2.0
1+
3.2.1

src/VirtualClient/VirtualClient.Actions.UnitTests/SPEC/SpecCpuExecutorTests.cs

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,96 @@ public async Task SpecCpuExecutorExecutesTheCorrectCommandsWithDifferentProfiles
427427
Assert.IsTrue(commandCalled);
428428
}
429429

430+
[Test]
431+
public async Task SpecCpuExecutorAppliesGcc15WorkaroundWhenGccVersionIs15OrGreaterOnLinux()
432+
{
433+
this.SetupLinux();
434+
435+
string writtenConfigText = null;
436+
this.mockFixture.File.Setup(f => f.WriteAllTextAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
437+
.Callback<string, string, CancellationToken>((path, content, token) => writtenConfigText = content)
438+
.Returns(Task.CompletedTask);
439+
440+
this.mockFixture.ProcessManager.OnCreateProcess = (exe, arguments, workingDir) =>
441+
{
442+
if (exe == "sudo" && arguments == "gcc -dumpversion")
443+
{
444+
return new InMemoryProcess
445+
{
446+
StartInfo = new ProcessStartInfo { FileName = exe, Arguments = arguments },
447+
StandardOutput = new ConcurrentBuffer(new StringBuilder("15")),
448+
ExitCode = 0,
449+
OnStart = () => true,
450+
OnHasExited = () => true
451+
};
452+
}
453+
454+
return new InMemoryProcess
455+
{
456+
StartInfo = new ProcessStartInfo { FileName = exe, Arguments = arguments },
457+
ExitCode = 0,
458+
OnStart = () => true,
459+
OnHasExited = () => true
460+
};
461+
};
462+
463+
using (TestSpecCpuExecutor specCpuExecutor = new TestSpecCpuExecutor(this.mockFixture.Dependencies, this.mockFixture.Parameters))
464+
{
465+
await specCpuExecutor.ExecuteAsync(CancellationToken.None).ConfigureAwait(false);
466+
}
467+
468+
Assert.IsNotNull(writtenConfigText);
469+
Assert.IsTrue(writtenConfigText.Contains("%define GCCge15"), "Config should contain '%define GCCge15' when GCC version is 15 or greater.");
470+
Assert.IsTrue(writtenConfigText.Contains("%define GCCge10"), "Config should also contain '%define GCCge10' when GCC version is 15 or greater.");
471+
Assert.IsFalse(writtenConfigText.Contains("$Gcc15Workaround$"), "Placeholder '$Gcc15Workaround$' should be replaced.");
472+
Assert.IsFalse(writtenConfigText.Contains("$Gcc10Workaround$"), "Placeholder '$Gcc10Workaround$' should be replaced.");
473+
}
474+
475+
[Test]
476+
public async Task SpecCpuExecutorDoesNotApplyGcc15WorkaroundWhenGccVersionIsLessThan15OnLinux()
477+
{
478+
this.SetupLinux();
479+
480+
string writtenConfigText = null;
481+
this.mockFixture.File.Setup(f => f.WriteAllTextAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
482+
.Callback<string, string, CancellationToken>((path, content, token) => writtenConfigText = content)
483+
.Returns(Task.CompletedTask);
484+
485+
this.mockFixture.ProcessManager.OnCreateProcess = (exe, arguments, workingDir) =>
486+
{
487+
if (exe == "sudo" && arguments == "gcc -dumpversion")
488+
{
489+
return new InMemoryProcess
490+
{
491+
StartInfo = new ProcessStartInfo { FileName = exe, Arguments = arguments },
492+
StandardOutput = new ConcurrentBuffer(new StringBuilder("10")),
493+
ExitCode = 0,
494+
OnStart = () => true,
495+
OnHasExited = () => true
496+
};
497+
}
498+
499+
return new InMemoryProcess
500+
{
501+
StartInfo = new ProcessStartInfo { FileName = exe, Arguments = arguments },
502+
ExitCode = 0,
503+
OnStart = () => true,
504+
OnHasExited = () => true
505+
};
506+
};
507+
508+
using (TestSpecCpuExecutor specCpuExecutor = new TestSpecCpuExecutor(this.mockFixture.Dependencies, this.mockFixture.Parameters))
509+
{
510+
await specCpuExecutor.ExecuteAsync(CancellationToken.None).ConfigureAwait(false);
511+
}
512+
513+
Assert.IsNotNull(writtenConfigText);
514+
Assert.IsFalse(writtenConfigText.Contains("%define GCCge15"), "Config should NOT contain '%define GCCge15' when GCC version is less than 15.");
515+
Assert.IsTrue(writtenConfigText.Contains("%define GCCge10"), "Config should contain '%define GCCge10' when GCC version is 10.");
516+
Assert.IsFalse(writtenConfigText.Contains("$Gcc15Workaround$"), "Placeholder '$Gcc15Workaround$' should be replaced.");
517+
Assert.IsFalse(writtenConfigText.Contains("$Gcc10Workaround$"), "Placeholder '$Gcc10Workaround$' should be replaced.");
518+
}
519+
430520
private void SetupLinux()
431521
{
432522
this.mockFixture = new MockFixture();

src/VirtualClient/VirtualClient.Actions.UnitTests/SPEC/mockspeccpu.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ default:
158158
# line to avoid compile errors for several FP benchmarks
159159
#
160160
$Gcc10Workaround$ # EDIT: remove the '#' from column 1 if using GCC 10 or later
161+
$Gcc15Workaround$ # workaround for GCC v15 (and presumably later)
161162

162163
# EDIT if needed: the preENV line adds library directories to the runtime
163164
# path. You can adjust it, or add lines for other environment variables.

src/VirtualClient/VirtualClient.Actions/SPECcpu/SpecCpuExecutor.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,11 @@ private async Task WriteSpecCpuConfigAsync(CancellationToken cancellationToken)
489489
SpecCpuConfigPlaceHolder.Gcc10Workaround,
490490
Convert.ToInt32(compilerVersion) >= 10 ? SpecCpuConfigPlaceHolder.Gcc10WorkaroundContent : string.Empty,
491491
StringComparison.OrdinalIgnoreCase);
492+
493+
templateText = templateText.Replace(
494+
SpecCpuConfigPlaceHolder.Gcc15Workaround,
495+
Convert.ToInt32(compilerVersion) >= 15 ? SpecCpuConfigPlaceHolder.Gcc15WorkaroundContent : string.Empty,
496+
StringComparison.OrdinalIgnoreCase);
492497
}
493498
else
494499
{
@@ -501,6 +506,11 @@ private async Task WriteSpecCpuConfigAsync(CancellationToken cancellationToken)
501506
SpecCpuConfigPlaceHolder.Gcc10Workaround,
502507
SpecCpuConfigPlaceHolder.Gcc10WorkaroundContent,
503508
StringComparison.OrdinalIgnoreCase);
509+
510+
templateText = templateText.Replace(
511+
SpecCpuConfigPlaceHolder.Gcc15Workaround,
512+
SpecCpuConfigPlaceHolder.Gcc15WorkaroundContent,
513+
StringComparison.OrdinalIgnoreCase);
504514
}
505515

506516
templateText = templateText.Replace(
@@ -572,6 +582,8 @@ private static class SpecCpuConfigPlaceHolder
572582
public const string PeakOptimizingFlags = "$PeakOptimizingFlags$";
573583
public const string Gcc10Workaround = "$Gcc10Workaround$";
574584
public const string Gcc10WorkaroundContent = "%define GCCge10";
585+
public const string Gcc15Workaround = "$Gcc15Workaround$";
586+
public const string Gcc15WorkaroundContent = "%define GCCge15";
575587
}
576588
}
577589
}

src/VirtualClient/VirtualClient.Actions/SPECcpu/vc-linux-arm64-jemalloc.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ default:
164164
# line to avoid compile errors for several FP benchmarks
165165
#
166166
%define GCCge10 # EDIT: remove the '#' from column 1 if using GCC 10 or later
167+
%define GCCge15 # EDIT: remove the '#' from column 1 if using GCC 15 or later
167168

168169
# EDIT if needed: the preENV line adds library directories to the runtime
169170
# path. You can adjust it, or add lines for other environment variables.
@@ -318,6 +319,9 @@ default: # data model applies to all benchmarks
318319
#
319320
default=base: # flags for all base
320321
OPTIMIZE = -g -O3 -mcpu=native
322+
% ifdef %{GCCge15} # workaround for GCC v15 (and presumably later)
323+
EXTRA_CXXFLAGS = -Wno-error=template-body
324+
% endif
321325

322326

323327
#-------- Peak Tuning Flags ----------------------------------------------

src/VirtualClient/VirtualClient.Actions/SPECcpu/vc-linux-arm64.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ default:
164164
# line to avoid compile errors for several FP benchmarks
165165
#
166166
$Gcc10Workaround$ # EDIT: remove the '#' from column 1 if using GCC 10 or later
167+
$Gcc15Workaround$ # workaround for GCC v15 (and presumably later)
167168

168169
# EDIT if needed: the preENV line adds library directories to the runtime
169170
# path. You can adjust it, or add lines for other environment variables.
@@ -314,6 +315,9 @@ default: # data model applies to all benchmarks
314315
#
315316
default=base: # flags for all base
316317
OPTIMIZE = $BaseOptimizingFlags$
318+
% ifdef %{GCCge15} # workaround for GCC v15 (and presumably later)
319+
EXTRA_CXXFLAGS = -Wno-error=template-body
320+
% endif
317321

318322

319323
#-------- Peak Tuning Flags ----------------------------------------------

src/VirtualClient/VirtualClient.Actions/SPECcpu/vc-linux-x64-jemalloc.cfg

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ default:
158158
# line to avoid compile errors for several FP benchmarks
159159
#
160160
%define GCCge10 # EDIT: remove the '#' from column 1 if using GCC 10 or later
161+
%define GCCge15 # EDIT: remove the '#' from column 1 if using GCC 15 or later
161162

162163
# EDIT if needed: the preENV line adds library directories to the runtime
163164
# path. You can adjust it, or add lines for other environment variables.
@@ -300,7 +301,10 @@ fpspeed:
300301
# the -march=native. See topic "Older GCC" above.
301302
#
302303
default=base: # flags for all base
303-
OPTIMIZE = -g -O3 -march=native
304+
OPTIMIZE = -g -O3 -march=native
305+
% ifdef %{GCCge15} # workaround for GCC v15 (and presumably later)
306+
EXTRA_CXXFLAGS = -Wno-error=template-body
307+
% endif
304308

305309

306310
#-------- Peak Tuning Flags ----------------------------------------------

src/VirtualClient/VirtualClient.Actions/SPECcpu/vc-linux-x64.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ default:
158158
# line to avoid compile errors for several FP benchmarks
159159
#
160160
$Gcc10Workaround$ # EDIT: remove the '#' from column 1 if using GCC 10 or later
161+
$Gcc15Workaround$ # workaround for GCC v15 (and presumably later)
161162

162163
# EDIT if needed: the preENV line adds library directories to the runtime
163164
# path. You can adjust it, or add lines for other environment variables.
@@ -297,6 +298,9 @@ fpspeed:
297298
#
298299
default=base: # flags for all base
299300
OPTIMIZE = $BaseOptimizingFlags$
301+
% ifdef %{GCCge15} # workaround for GCC v15 (and presumably later)
302+
EXTRA_CXXFLAGS = -Wno-error=template-body
303+
% endif
300304

301305

302306
#-------- Peak Tuning Flags ----------------------------------------------

0 commit comments

Comments
 (0)