This commit is contained in:
Copilot 2025-07-30 06:56:42 -07:00 committed by GitHub
commit f47c2fdb36
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 51 additions and 0 deletions

View File

@ -0,0 +1,24 @@
using Mono.Linker.Tests.Cases.Expectations.Assertions;
using Mono.Linker.Tests.Cases.Expectations.Metadata;
namespace Mono.Linker.Tests.Cases.CommandLine
{
/// <summary>
/// This test case verifies that the NoSEH flag is set in the PE header
/// when running ILLink on a sample application that has been R2R-stripped.
/// </summary>
public class NoSEHFlagIsSet
{
public static void Main()
{
// Simple test case - just call a method
TestMethod();
}
[Kept]
static void TestMethod()
{
// Simple implementation
}
}
}

View File

@ -8,6 +8,7 @@ using System.Linq;
using System.Runtime.Serialization.Json;
using System.Xml;
using Mono.Cecil;
using Mono.Linker.Tests.Cases.CommandLine;
using Mono.Linker.Tests.Cases.CommandLine.Mvid;
using Mono.Linker.Tests.Cases.Interop.PInvoke.Individual;
using Mono.Linker.Tests.Cases.References.Individual;
@ -269,5 +270,31 @@ namespace Mono.Linker.Tests.TestCases
runner = new TestRunner(new ObjectFactory());
return runner.Run(testCase);
}
[Test]
public void NoSEHFlagIsSetInPEHeader()
{
var testcase = CreateIndividualCase(typeof(NoSEHFlagIsSet));
var result = Run(testcase);
var outputPath = result.OutputAssemblyPath;
if (!outputPath.Exists())
Assert.Fail($"The linked assembly is missing. Expected it to exist at {outputPath}");
// Check PE header for NoSEH flag
using (var fileStream = new FileStream(outputPath, FileMode.Open, FileAccess.Read))
using (var peReader = new System.Reflection.PortableExecutable.PEReader(fileStream))
{
var peHeaders = peReader.PEHeaders;
var characteristics = peHeaders.CoffHeader.Characteristics;
var dllCharacteristics = peHeaders.PEHeader!.DllCharacteristics;
// IMAGE_DLLCHARACTERISTICS_NO_SEH = 0x0400
const System.Reflection.PortableExecutable.DllCharacteristics NoSEH = (System.Reflection.PortableExecutable.DllCharacteristics)0x0400;
Assert.That(dllCharacteristics & NoSEH, Is.EqualTo(NoSEH),
$"NoSEH flag (0x0400) is not set in PE header. DllCharacteristics: 0x{dllCharacteristics:X}");
}
}
}
}