diff --git a/src/tests/nativeaot/SmokeTests/HardwareIntrinsics/Program.cs b/src/tests/nativeaot/SmokeTests/HardwareIntrinsics/Program.cs
index c29e55cd27f8d..58a4de298e974 100644
--- a/src/tests/nativeaot/SmokeTests/HardwareIntrinsics/Program.cs
+++ b/src/tests/nativeaot/SmokeTests/HardwareIntrinsics/Program.cs
@@ -1,8 +1,9 @@
-// Licensed to the .NET Foundation under one or more agreements.
+// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Numerics;
+using System.Runtime.InteropServices;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;
@@ -12,6 +13,36 @@ static int Main()
{
s_success = true;
+#if !DEBUG
+ Console.WriteLine("****************************************************");
+ Console.WriteLine("* Size test *");
+ long fileSize = new System.IO.FileInfo(Environment.ProcessPath).Length;
+ Console.WriteLine($"* Size of the executable is {fileSize / 1024,7:n0} kB *");
+ Console.WriteLine("****************************************************");
+
+ const int Meg = 1024 * 1024;
+ const int HalfMeg = Meg / 2;
+ long lowerBound, upperBound;
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+ {
+ lowerBound = 2 * Meg; // 2 MB
+ upperBound = 4 * Meg; // 4 MB
+ }
+ else
+ {
+ lowerBound = Meg + HalfMeg; // 1.5 MB
+ upperBound = 2 * Meg; // 2 MB
+ }
+
+ if (fileSize < lowerBound || fileSize > upperBound)
+ {
+ Console.WriteLine("BUG: File size is not in the expected range. Did a libraries change regress size of Hello World?");
+ return 1;
+ }
+
+ Console.WriteLine();
+#endif
+
// We expect the AOT compiler generated HW intrinsics with the following characteristics:
//
// * TRUE = IsSupported assumed to be true, no runtime check
diff --git a/src/tests/nativeaot/SmokeTests/HardwareIntrinsics/X64Baseline.csproj b/src/tests/nativeaot/SmokeTests/HardwareIntrinsics/X64Baseline.csproj
index e49eb84629044..28fc56a41439c 100644
--- a/src/tests/nativeaot/SmokeTests/HardwareIntrinsics/X64Baseline.csproj
+++ b/src/tests/nativeaot/SmokeTests/HardwareIntrinsics/X64Baseline.csproj
@@ -6,6 +6,10 @@
true
true
$(DefineConstants);BASELINE_INTRINSICS
+ true
+
+
+ objcopy
diff --git a/src/tests/nativeaot/SmokeTests/HardwareIntrinsics/x64NonVex.csproj b/src/tests/nativeaot/SmokeTests/HardwareIntrinsics/x64NonVex.csproj
index 5e8d35d67bf3d..c00af0ea752e4 100644
--- a/src/tests/nativeaot/SmokeTests/HardwareIntrinsics/x64NonVex.csproj
+++ b/src/tests/nativeaot/SmokeTests/HardwareIntrinsics/x64NonVex.csproj
@@ -6,6 +6,10 @@
true
true
$(DefineConstants);NON_VEX_INTRINSICS
+ true
+
+
+ objcopy
diff --git a/src/tests/nativeaot/SmokeTests/HardwareIntrinsics/x64Vex.csproj b/src/tests/nativeaot/SmokeTests/HardwareIntrinsics/x64Vex.csproj
index 983436eab7d79..92ad863899305 100644
--- a/src/tests/nativeaot/SmokeTests/HardwareIntrinsics/x64Vex.csproj
+++ b/src/tests/nativeaot/SmokeTests/HardwareIntrinsics/x64Vex.csproj
@@ -6,6 +6,10 @@
true
true
$(DefineConstants);VEX_INTRINSICS
+ true
+
+
+ objcopy