public void CheckCOFFAndPEOptionalHeaders64Exe() { string source = @" class C { public static void Main() { } }"; var compilation = CreateCompilationWithMscorlib(source, compOptions: TestOptions.Exe.WithPlatform(Platform.X64)); var peHeaders = new PEHeaders(compilation.EmitToStream()); //interesting COFF bits Assert.True(peHeaders.Requires64Bits()); Assert.True(peHeaders.IsExe); Assert.False(peHeaders.IsDll); //interesting Optional PE header bits //We will use a range beginning with 0x30 to identify the Roslyn compiler family. Assert.Equal(0x30, peHeaders.PEHeader.MajorLinkerVersion); Assert.Equal(0, peHeaders.PEHeader.MinorLinkerVersion); Assert.Equal(0x0000000140000000ul, peHeaders.PEHeader.ImageBase); Assert.Equal(0x200, peHeaders.PEHeader.FileAlignment); //doesn't change based on architecture Assert.True(peHeaders.IsConsoleApplication); //should change if this is a windows app. Assert.Equal(0x8540u, (ushort)peHeaders.PEHeader.DllCharacteristics); //DYNAMIC_BASE | NX_COMPAT | NO_SEH | TERMINAL_SERVER_AWARE Assert.Equal(0x00400000u, peHeaders.PEHeader.SizeOfStackReserve); Assert.Equal(0x4000u, peHeaders.PEHeader.SizeOfStackCommit); Assert.Equal(0x00100000u, peHeaders.PEHeader.SizeOfHeapReserve); //no sure why we don't bump this up relative to 32bit as well. Assert.Equal(0x2000u, peHeaders.PEHeader.SizeOfHeapCommit); }
public void CheckCOFFAndPEOptionalHeaders32Exe() { string source = @" class C { public static void Main() { } }"; var compilation = CreateCompilationWithMscorlib(source, compOptions: TestOptions.Exe.WithPlatform(Platform.AnyCpu)); var peHeaders = new PEHeaders(compilation.EmitToStream()); //interesting COFF bits Assert.False(peHeaders.Requires64Bits()); Assert.True(peHeaders.IsExe); Assert.False(peHeaders.IsDll); //interesting Optional PE header bits //We will use a range beginning with 0x30 to identify the Roslyn compiler family. Assert.Equal(0x30, peHeaders.PEHeader.MajorLinkerVersion); Assert.Equal(0, peHeaders.PEHeader.MinorLinkerVersion); Assert.Equal(0x00400000ul, peHeaders.PEHeader.ImageBase); Assert.Equal(0x00000200, peHeaders.PEHeader.FileAlignment); Assert.True(peHeaders.IsConsoleApplication); //should change if this is a windows app. Assert.Equal(0x8540u, (ushort)peHeaders.PEHeader.DllCharacteristics); //DYNAMIC_BASE | NX_COMPAT | NO_SEH | TERMINAL_SERVER_AWARE Assert.Equal(0x00100000u, peHeaders.PEHeader.SizeOfStackReserve); Assert.Equal(0x1000u, peHeaders.PEHeader.SizeOfStackCommit); Assert.Equal(0x00100000u, peHeaders.PEHeader.SizeOfHeapReserve); Assert.Equal(0x1000u, peHeaders.PEHeader.SizeOfHeapCommit); //The following ensure that the runtime startup stub was emitted. It is not needed on modern operating systems. Assert.NotEqual(0, peHeaders.PEHeader.ImportAddressTableDirectory.RelativeVirtualAddress); Assert.NotEqual(0, peHeaders.PEHeader.ImportAddressTableDirectory.Size); Assert.NotEqual(0, peHeaders.PEHeader.ImportTableDirectory.RelativeVirtualAddress); Assert.NotEqual(0, peHeaders.PEHeader.ImportTableDirectory.Size); Assert.NotEqual(0, peHeaders.PEHeader.BaseRelocationTableDirectory.RelativeVirtualAddress); Assert.NotEqual(0, peHeaders.PEHeader.BaseRelocationTableDirectory.Size); }
public void CheckCOFFAndPEOptionalHeadersARM() { string source = @" class C { public static void Main() { } }"; var compilation = CreateCompilationWithMscorlib(source, compOptions: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary).WithPlatform(Platform.Arm)); var peHeaders = new PEHeaders(compilation.EmitToStream()); //interesting COFF bits Assert.False(peHeaders.Requires64Bits()); Assert.True(peHeaders.IsDll); Assert.False(peHeaders.IsExe); //interesting Optional PE header bits //We will use a range beginning with 0x30 to identify the Roslyn compiler family. Assert.Equal(0x30, peHeaders.PEHeader.MajorLinkerVersion); Assert.Equal(0, peHeaders.PEHeader.MinorLinkerVersion); // the default value is the same as the 32 bit default value Assert.Equal(0x10000000u, peHeaders.PEHeader.ImageBase); Assert.Equal(0x200, peHeaders.PEHeader.FileAlignment); Assert.Equal(0x8540u, (ushort)peHeaders.PEHeader.DllCharacteristics); //DYNAMIC_BASE | NX_COMPAT | NO_SEH | TERMINAL_SERVER_AWARE Assert.Equal(0x01c4, (ushort)peHeaders.CoffHeader.Machine); Assert.Equal(6, peHeaders.PEHeader.MajorSubsystemVersion); //Arm targets only run on 6.2 and above Assert.Equal(2, peHeaders.PEHeader.MinorSubsystemVersion); //The following ensure that the runtime startup stub was not emitted. It is not needed on modern operating systems. Assert.Equal(0, peHeaders.PEHeader.ImportAddressTableDirectory.RelativeVirtualAddress); Assert.Equal(0, peHeaders.PEHeader.ImportAddressTableDirectory.Size); Assert.Equal(0, peHeaders.PEHeader.ImportTableDirectory.RelativeVirtualAddress); Assert.Equal(0, peHeaders.PEHeader.ImportTableDirectory.Size); Assert.Equal(0, peHeaders.PEHeader.BaseRelocationTableDirectory.RelativeVirtualAddress); Assert.Equal(0, peHeaders.PEHeader.BaseRelocationTableDirectory.Size); }
public void CheckCOFFAndPEOptionalHeaders64() { string source = @" class C { public static void Main() { } }"; var compilation = CreateCompilationWithMscorlib(source, compOptions: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary).WithPlatform(Platform.X64)); var peHeaders = new PEHeaders(compilation.EmitToStream()); //interesting COFF bits Assert.True(peHeaders.Requires64Bits()); Assert.True(peHeaders.IsDll); Assert.False(peHeaders.IsExe); //interesting Optional PE header bits //We will use a range beginning with 0x30 to identify the Roslyn compiler family. Assert.Equal(0x30, peHeaders.PEHeader.MajorLinkerVersion); Assert.Equal(0, peHeaders.PEHeader.MinorLinkerVersion); // the default value is the same as the 32 bit default value Assert.Equal(0x0000000180000000u, peHeaders.PEHeader.ImageBase); Assert.Equal(0x00000200, peHeaders.PEHeader.FileAlignment); //doesn't change based on architecture. Assert.Equal(0x8540u, (ushort)peHeaders.PEHeader.DllCharacteristics); //DYNAMIC_BASE | NX_COMPAT | NO_SEH | TERMINAL_SERVER_AWARE //Verify additional items Assert.Equal(0x00400000u, peHeaders.PEHeader.SizeOfStackReserve); Assert.Equal(0x4000u, peHeaders.PEHeader.SizeOfStackCommit); Assert.Equal(0x00100000u, peHeaders.PEHeader.SizeOfHeapReserve); Assert.Equal(0x2000u, peHeaders.PEHeader.SizeOfHeapCommit); Assert.Equal(0x8664, (ushort)peHeaders.CoffHeader.Machine); //AMD64 (K8) //default for non-arm, non-appcontainer outputs. EDMAURER: This is an intentional change from Dev11. //Should we find that it is too disruptive. We will consider rolling back. //It turns out to be too disruptive. Rolling back to 4.0 Assert.Equal(4, peHeaders.PEHeader.MajorSubsystemVersion); Assert.Equal(0, peHeaders.PEHeader.MinorSubsystemVersion); //The following ensure that the runtime startup stub was not emitted. It is not needed on modern operating systems. Assert.Equal(0, peHeaders.PEHeader.ImportAddressTableDirectory.RelativeVirtualAddress); Assert.Equal(0, peHeaders.PEHeader.ImportAddressTableDirectory.Size); Assert.Equal(0, peHeaders.PEHeader.ImportTableDirectory.RelativeVirtualAddress); Assert.Equal(0, peHeaders.PEHeader.ImportTableDirectory.Size); Assert.Equal(0, peHeaders.PEHeader.BaseRelocationTableDirectory.RelativeVirtualAddress); Assert.Equal(0, peHeaders.PEHeader.BaseRelocationTableDirectory.Size); }
public void CheckCOFFAndPEOptionalHeaders32() { string source = @" class C { public static void Main() { } }"; var compilation = CreateCompilationWithMscorlib(source, compOptions: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); var peHeaders = new PEHeaders(compilation.EmitToStream()); //interesting COFF bits Assert.False(peHeaders.Requires64Bits()); Assert.True(peHeaders.IsDll); Assert.False(peHeaders.IsExe); //interesting Optional PE header bits //We will use a range beginning with 0x30 to identify the Roslyn compiler family. Assert.Equal(0x30, peHeaders.PEHeader.MajorLinkerVersion); Assert.Equal(0, peHeaders.PEHeader.MinorLinkerVersion); Assert.Equal(0x10000000u, peHeaders.PEHeader.ImageBase); Assert.Equal(0x200, peHeaders.PEHeader.FileAlignment); Assert.Equal(0x8540u, (ushort)peHeaders.PEHeader.DllCharacteristics); //DYNAMIC_BASE | NX_COMPAT | NO_SEH | TERMINAL_SERVER_AWARE //Verify additional items Assert.Equal(0x00100000u, peHeaders.PEHeader.SizeOfStackReserve); Assert.Equal(0x1000u, peHeaders.PEHeader.SizeOfStackCommit); Assert.Equal(0x00100000u, peHeaders.PEHeader.SizeOfHeapReserve); Assert.Equal(0x1000u, peHeaders.PEHeader.SizeOfHeapCommit); }
public void CheckCorflags() { string source = @" class C { public static void Main() { } }"; PEHeaders peHeaders; var compilation = CreateCompilationWithMscorlib(source, compOptions: TestOptions.Exe.WithPlatform(Platform.AnyCpu)); peHeaders = new PEHeaders(compilation.EmitToStream()); Assert.Equal(CorFlags.ILOnly, peHeaders.CorHeader.Flags); compilation = CreateCompilationWithMscorlib(source, compOptions: TestOptions.Exe.WithPlatform(Platform.X86)); peHeaders = new PEHeaders(compilation.EmitToStream()); Assert.Equal(CorFlags.ILOnly | CorFlags.Requires32Bit, peHeaders.CorHeader.Flags); compilation = CreateCompilationWithMscorlib(source, compOptions: TestOptions.Exe.WithPlatform(Platform.X64)); peHeaders = new PEHeaders(compilation.EmitToStream()); Assert.Equal(CorFlags.ILOnly, peHeaders.CorHeader.Flags); Assert.True(peHeaders.Requires64Bits()); Assert.True(peHeaders.RequiresAmdInstructionSet()); compilation = CreateCompilationWithMscorlib(source, compOptions: TestOptions.Exe.WithPlatform(Platform.AnyCpu32BitPreferred)); peHeaders = new PEHeaders(compilation.EmitToStream()); Assert.False(peHeaders.Requires64Bits()); Assert.False(peHeaders.RequiresAmdInstructionSet()); Assert.Equal(CorFlags.ILOnly | CorFlags.Requires32Bit | CorFlags.Prefers32Bit, peHeaders.CorHeader.Flags); compilation = CreateCompilationWithMscorlib(source, compOptions: TestOptions.Exe.WithPlatform(Platform.Arm)); peHeaders = new PEHeaders(compilation.EmitToStream()); Assert.False(peHeaders.Requires64Bits()); Assert.False(peHeaders.RequiresAmdInstructionSet()); Assert.Equal(CorFlags.ILOnly, peHeaders.CorHeader.Flags); }