Add various fixes from CentOS Stream 9

This commit is contained in:
Omair Majid 2023-12-08 08:55:44 -05:00
parent 626897d40e
commit 725355e8cb
9 changed files with 703 additions and 9 deletions

View File

@ -54,7 +54,7 @@
Name: dotnet%{dotnetver} Name: dotnet%{dotnetver}
Version: %{sdk_rpm_version} Version: %{sdk_rpm_version}
Release: 0%{?dist}.1 Release: 0%{?dist}.2
Summary: .NET Runtime and SDK Summary: .NET Runtime and SDK
License: 0BSD AND Apache-2.0 AND (Apache-2.0 WITH LLVM-exception) AND APSL-2.0 AND BSD-2-Clause AND BSD-3-Clause AND BSD-4-Clause AND BSL-1.0 AND bzip2-1.0.6 AND CC0-1.0 AND CC-BY-3.0 AND CC-BY-4.0 AND CC-PDDC AND CNRI-Python AND EPL-1.0 AND GPL-2.0-only AND (GPL-2.0-only WITH GCC-exception-2.0) AND GPL-2.0-or-later AND GPL-3.0-only AND ICU AND ISC AND LGPL-2.1-only AND LGPL-2.1-or-later AND LicenseRef-Fedora-Public-Domain AND LicenseRef-ISO-8879 AND MIT AND MIT-Wu AND MS-PL AND MS-RL AND NCSA AND OFL-1.1 AND OpenSSL AND Unicode-DFS-2015 AND Unicode-DFS-2016 AND W3C-19980720 AND X11 AND Zlib License: 0BSD AND Apache-2.0 AND (Apache-2.0 WITH LLVM-exception) AND APSL-2.0 AND BSD-2-Clause AND BSD-3-Clause AND BSD-4-Clause AND BSL-1.0 AND bzip2-1.0.6 AND CC0-1.0 AND CC-BY-3.0 AND CC-BY-4.0 AND CC-PDDC AND CNRI-Python AND EPL-1.0 AND GPL-2.0-only AND (GPL-2.0-only WITH GCC-exception-2.0) AND GPL-2.0-or-later AND GPL-3.0-only AND ICU AND ISC AND LGPL-2.1-only AND LGPL-2.1-or-later AND LicenseRef-Fedora-Public-Domain AND LicenseRef-ISO-8879 AND MIT AND MIT-Wu AND MS-PL AND MS-RL AND NCSA AND OFL-1.1 AND OpenSSL AND Unicode-DFS-2015 AND Unicode-DFS-2016 AND W3C-19980720 AND X11 AND Zlib
@ -90,6 +90,19 @@ Source21: dotnet.sh.in
Patch1: roslyn-analyzers-ppc64le-apphost.patch Patch1: roslyn-analyzers-ppc64le-apphost.patch
# https://github.com/dotnet/source-build/discussions/3481 # https://github.com/dotnet/source-build/discussions/3481
Patch2: vstest-intent-net8.0.patch Patch2: vstest-intent-net8.0.patch
# https://github.com/dotnet/source-build/issues/3571
Patch3: fix-mono-typeloadexception.patch
# https://github.com/dotnet/runtime/pull/91008
Patch4: runtime-91008-mono-var-opcode-OP_REGOFFSET.patch
# https://github.com/dotnet/runtime/pull/91865
Patch5: runtime-91865-arm64-page-size.patch
# https://github.com/dotnet/runtime/pull/92274
Patch6: runtime-92274-webcil-s390x.patch
# https://github.com/dotnet/runtime/pull/92441
Patch7: runtime-92441-s390x-host-le.patch
# https://github.com/dotnet/sdk/pull/35600
Patch8: sdk-35600-skip-windows-gui.patch
ExclusiveArch: aarch64 ppc64le s390x x86_64 ExclusiveArch: aarch64 ppc64le s390x x86_64
@ -508,7 +521,14 @@ sed -e 's|[@]LIBDIR[@]|%{_libdir}|g' %{SOURCE21} > dotnet.sh
%install %install
install -dm 0755 %{buildroot}%{_libdir}/dotnet install -dm 0755 %{buildroot}%{_libdir}/dotnet
ls artifacts/%{runtime_arch}/Release ls artifacts/%{runtime_arch}/Release
tar xf artifacts/%{runtime_arch}/Release/dotnet-sdk-%{sdk_version}-%{runtime_id}.tar.gz -C %{buildroot}%{_libdir}/dotnet/ mkdir -p built-sdk
tar xf artifacts/%{runtime_arch}/Release/dotnet-sdk-%{sdk_version}-%{runtime_id}.tar.gz -C built-sdk/
# Convert hardlinks to actual copies. This takes up quite a bit of
# extra disk space, but works around RHEL issues in post-rpmbuild tools
# when they encounter hardlinks.
cp -r --preserve=mode,ownership,timestamps built-sdk/* %{buildroot}%{_libdir}/dotnet/
ls %{buildroot}%{_libdir}/dotnet
# Delete bundled certificates: we want to use the system store only, # Delete bundled certificates: we want to use the system store only,
# except for when we have no other choice and ca-certificates doesn't # except for when we have no other choice and ca-certificates doesn't
@ -525,12 +545,8 @@ fi
tar xf artifacts/%{runtime_arch}/Release/dotnet-runtime-symbols-%{runtime_id}-%{runtime_version}.tar.gz \ tar xf artifacts/%{runtime_arch}/Release/dotnet-runtime-symbols-%{runtime_id}-%{runtime_version}.tar.gz \
-C %{buildroot}%{_libdir}/dotnet/shared/Microsoft.NETCore.App/%{runtime_version}/ -C %{buildroot}%{_libdir}/dotnet/shared/Microsoft.NETCore.App/%{runtime_version}/
# Remove static files
find %{buildroot}%{_libdir}/dotnet/ -type f -name 'libmono-*.a' -exec rm {} \;
# Fix executable permissions on files # Fix executable permissions on files
find %{buildroot}%{_libdir}/dotnet/ -type f -name 'apphost' -exec chmod +x {} \; find %{buildroot}%{_libdir}/dotnet/ -type f -name 'apphost' -exec chmod +x {} \;
#find %{buildroot}%{_libdir}/dotnet/ -type f -name 'containerize' -exec chmod +x {} \;
find %{buildroot}%{_libdir}/dotnet/ -type f -name 'singlefilehost' -exec chmod +x {} \; find %{buildroot}%{_libdir}/dotnet/ -type f -name 'singlefilehost' -exec chmod +x {} \;
find %{buildroot}%{_libdir}/dotnet/ -type f -name 'lib*so' -exec chmod +x {} \; find %{buildroot}%{_libdir}/dotnet/ -type f -name 'lib*so' -exec chmod +x {} \;
find %{buildroot}%{_libdir}/dotnet/ -type f -name '*.a' -exec chmod -x {} \; find %{buildroot}%{_libdir}/dotnet/ -type f -name '*.a' -exec chmod -x {} \;
@ -649,6 +665,9 @@ export COMPlus_LTTng=0
%changelog %changelog
* Fri Dec 08 2023 Omair Majid <omajid@redhat.com> - 8.0.100~rc.1-0.2
- Add various fixes from CentOS Stream 9
* Fri Sep 15 2023 Omair Majid <omajid@redhat.com> - 8.0.100~rc.1-0.1 * Fri Sep 15 2023 Omair Majid <omajid@redhat.com> - 8.0.100~rc.1-0.1
- Update to .NET SDK 8.0.100 RC 1 and Runtime 8.0.0 RC 1 - Update to .NET SDK 8.0.100 RC 1 and Runtime 8.0.0 RC 1

View File

@ -0,0 +1,23 @@
From 02f6303d86672997ec2e6b79b16d5ddbf52118a0 Mon Sep 17 00:00:00 2001
From: Tom Deseyn <tom.deseyn@gmail.com>
Date: Tue, 22 Aug 2023 14:52:36 +0200
Subject: [PATCH] Avoid loading System.Security.Permissions.
source-built Mono fails to load types from this assembly.
---
src/msbuild/src/Shared/ExceptionHandling.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/msbuild/src/Shared/ExceptionHandling.cs b/src/msbuild/src/Shared/ExceptionHandling.cs
index a7ef74e873..3dce645df1 100644
--- a/src/msbuild/src/Shared/ExceptionHandling.cs
+++ b/src/msbuild/src/Shared/ExceptionHandling.cs
@@ -167,7 +167,7 @@ internal static bool IsIoRelatedException(Exception e)
internal static bool IsXmlException(Exception e)
{
return e is XmlException
- || e is XmlSyntaxException
+ // || e is XmlSyntaxException
|| e is XmlSchemaException
|| e is UriFormatException; // XmlTextReader for example uses this under the covers
}

View File

@ -11,6 +11,8 @@ badfuncs:
# libSystem*so. # libSystem*so.
/usr/lib64/dotnet/shared/Microsoft.NETCore.App/*/libcoreclr.so: /usr/lib64/dotnet/shared/Microsoft.NETCore.App/*/libcoreclr.so:
- inet_addr - inet_addr
/usr/lib64/dotnet/packs/Microsoft.NETCore.App.Runtime.*/*/runtimes/*/native/libcoreclr.so:
- inet_addr
runpath: runpath:
# Upstream explicitly sets $ORIGIN/netcoredeps as an RPATH # Upstream explicitly sets $ORIGIN/netcoredeps as an RPATH
# See https://github.com/dotnet/core/blob/main/Documentation/self-contained-linux-apps.md # See https://github.com/dotnet/core/blob/main/Documentation/self-contained-linux-apps.md

View File

@ -0,0 +1,29 @@
From a73b8bacfcc5819926bc05173ab2f7850eb00da3 Mon Sep 17 00:00:00 2001
From: Ulrich Weigand <ulrich.weigand@de.ibm.com>
Date: Wed, 23 Aug 2023 21:11:37 +0200
Subject: [PATCH] [mono] Handle enum return type when inlining CreateInstance
Use underlying base type when deciding how to inline a
CreateInstance invocation in mini_emit_inst_for_method.
Fixes https://github.com/dotnet/runtime/issues/90292
(Mono abort causing .NET 8 msbuild regression).
---
src/mono/mono/mini/intrinsics.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/runtime/src/mono/mono/mini/intrinsics.c b/src/runtime/src/mono/mono/mini/intrinsics.c
index b1e5e76723147..ef77b7dc89f2e 100644
--- a/src/runtime/src/mono/mono/mini/intrinsics.c
+++ b//src/runtimesrc/mono/mono/mini/intrinsics.c
@@ -2079,7 +2079,9 @@ mini_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSign
MonoType *t = method_context->method_inst->type_argv [0];
MonoClass *arg0 = mono_class_from_mono_type_internal (t);
if (m_class_is_valuetype (arg0) && !mono_class_has_default_constructor (arg0, FALSE)) {
- if (m_class_is_primitive (arg0)) {
+ if (m_class_is_primitive (arg0) || m_class_is_enumtype (arg0)) {
+ if (m_class_is_enumtype (arg0))
+ t = mono_class_enum_basetype_internal (arg0);
int dreg = alloc_dreg (cfg, mini_type_to_stack_type (cfg, t));
mini_emit_init_rvar (cfg, dreg, t);
ins = cfg->cbb->last_ins;

View File

@ -0,0 +1,39 @@
From 7d3b041c09aa1d6cf532e64d24b75a7e5bd4d106 Mon Sep 17 00:00:00 2001
From: Tom Deseyn <tom.deseyn@gmail.com>
Date: Tue, 12 Sep 2023 07:43:45 +0200
Subject: [PATCH] Limit special diagnostics size region to 4KiB.
This fixes out-of-bounds access when trying to write the
diagnostics info on platforms where the PAGE_SIZE is larger
than the DumpWriter's 16KiB m_tempBuffer.
---
src/coreclr/debug/createdump/crashinfo.cpp | 2 +-
src/coreclr/debug/createdump/specialdiaginfo.h | 2 ++
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/runtime/src/coreclr/debug/createdump/crashinfo.cpp b/src/runtime/src/coreclr/debug/createdump/crashinfo.cpp
index ef903767ba027..8af6ec4a54f5b 100644
--- a/src/runtime/src/coreclr/debug/createdump/crashinfo.cpp
+++ b/src/runtime/src/coreclr/debug/createdump/crashinfo.cpp
@@ -195,7 +195,7 @@ CrashInfo::GatherCrashInfo(DumpType dumpType)
return false;
}
// Add the special (fake) memory region for the special diagnostics info
- MemoryRegion special(PF_R, SpecialDiagInfoAddress, SpecialDiagInfoAddress + PAGE_SIZE);
+ MemoryRegion special(PF_R, SpecialDiagInfoAddress, SpecialDiagInfoAddress + SpecialDiagInfoSize);
m_memoryRegions.insert(special);
#ifdef __APPLE__
InitializeOtherMappings();
diff --git a/src/runtime/src/coreclr/debug/createdump/specialdiaginfo.h b/src/runtime/src/coreclr/debug/createdump/specialdiaginfo.h
index 3a04a9f551e6d..a857129c9c91f 100644
--- a/src/runtime/src/coreclr/debug/createdump/specialdiaginfo.h
+++ b/src/runtime/src/coreclr/debug/createdump/specialdiaginfo.h
@@ -24,6 +24,8 @@ const uint64_t SpecialDiagInfoAddress = 0x7fff1000;
#endif
#endif
+const uint64_t SpecialDiagInfoSize = 0x1000;
+
struct SpecialDiagInfoHeader
{
char Signature[16];

View File

@ -0,0 +1,260 @@
From 72f310a6c3dccbabf9edc29677b51ed78c87cc67 Mon Sep 17 00:00:00 2001
From: Sanjam Panda <sanjam.panda@ibm.com>
Date: Tue, 19 Sep 2023 15:16:02 +0200
Subject: [PATCH 1/3] [wasm] Endian fix for Webcil
'dotnet new blazorwasm' command failed on s390x and was throwing a not implemented exception
The issue was with with the WebCil writer and reader, specific endianness conversions relating to the webcil payload were not implemented for big endian machines.
We considered fixing the generic implementation, but there were only two structures in use: WebcilHeader and WebcilSectionHeader, so it was easier to handle them explicitly.
---
.../Microsoft.NET.WebAssembly.Webcil.csproj | 1 +
.../WebcilConverter.cs | 35 +++++++++++++-----
.../WebcilReader.cs | 37 +++++++++++++++----
3 files changed, 57 insertions(+), 16 deletions(-)
diff --git a/src/runtime/src/tasks/Microsoft.NET.WebAssembly.Webcil/Microsoft.NET.WebAssembly.Webcil.csproj b/src/runtime/src/tasks/Microsoft.NET.WebAssembly.Webcil/Microsoft.NET.WebAssembly.Webcil.csproj
index c35eb57e80686..d09ae4a569a59 100644
--- a/src/runtime/src/tasks/Microsoft.NET.WebAssembly.Webcil/Microsoft.NET.WebAssembly.Webcil.csproj
+++ b/src/runtime/src/tasks/Microsoft.NET.WebAssembly.Webcil/Microsoft.NET.WebAssembly.Webcil.csproj
@@ -16,6 +16,7 @@
<ItemGroup>
<!-- we need to keep the version of System.Reflection.Metadata in sync with dotnet/msbuild and dotnet/sdk -->
+ <PackageReference Include="System.Memory" Version="$(SystemMemoryVersion)" />
<PackageReference Include="System.Reflection.Metadata" Version="$(SystemReflectionMetadataVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="$(SystemCollectionsImmutableVersion)" />
</ItemGroup>
diff --git a/src/runtime/src/tasks/Microsoft.NET.WebAssembly.Webcil/WebcilConverter.cs b/src/runtime/src/tasks/Microsoft.NET.WebAssembly.Webcil/WebcilConverter.cs
index a38af7270a2da..7b882c42d579e 100644
--- a/src/runtime/src/tasks/Microsoft.NET.WebAssembly.Webcil/WebcilConverter.cs
+++ b/src/runtime/src/tasks/Microsoft.NET.WebAssembly.Webcil/WebcilConverter.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System;
+using System.Buffers.Binary;
using System.IO;
using System.Collections.Immutable;
using System.Reflection.PortableExecutable;
@@ -181,9 +182,6 @@ private static void WriteHeader(Stream s, WebcilHeader header)
private static void WriteSectionHeaders(Stream s, ImmutableArray<WebcilSectionHeader> sectionsHeaders)
{
- // FIXME: fixup endianness
- if (!BitConverter.IsLittleEndian)
- throw new NotImplementedException();
foreach (var sectionHeader in sectionsHeaders)
{
WriteSectionHeader(s, sectionHeader);
@@ -192,16 +190,38 @@ private static void WriteSectionHeaders(Stream s, ImmutableArray<WebcilSectionHe
private static void WriteSectionHeader(Stream s, WebcilSectionHeader sectionHeader)
{
+ if (!BitConverter.IsLittleEndian)
+ {
+ sectionHeader = new WebcilSectionHeader
+ (
+ virtualSize: BinaryPrimitives.ReverseEndianness(sectionHeader.VirtualSize),
+ virtualAddress: BinaryPrimitives.ReverseEndianness(sectionHeader.VirtualAddress),
+ sizeOfRawData: BinaryPrimitives.ReverseEndianness(sectionHeader.SizeOfRawData),
+ pointerToRawData: BinaryPrimitives.ReverseEndianness(sectionHeader.PointerToRawData)
+ );
+ }
WriteStructure(s, sectionHeader);
}
+ private static void WriteStructure(Stream s, WebcilHeader webcilHeader)
+ {
+ if (!BitConverter.IsLittleEndian)
+ {
+ webcilHeader.version_major = BinaryPrimitives.ReverseEndianness(webcilHeader.version_major);
+ webcilHeader.version_minor = BinaryPrimitives.ReverseEndianness(webcilHeader.version_minor);
+ webcilHeader.coff_sections = BinaryPrimitives.ReverseEndianness(webcilHeader.coff_sections);
+ webcilHeader.pe_cli_header_rva = BinaryPrimitives.ReverseEndianness(webcilHeader.pe_cli_header_rva);
+ webcilHeader.pe_cli_header_size = BinaryPrimitives.ReverseEndianness(webcilHeader.pe_cli_header_size);
+ webcilHeader.pe_debug_rva = BinaryPrimitives.ReverseEndianness(webcilHeader.pe_debug_rva);
+ webcilHeader.pe_debug_size = BinaryPrimitives.ReverseEndianness(webcilHeader.pe_debug_size);
+ }
+ WriteStructure(s, webcilHeader);
+ }
+
#if NETCOREAPP2_1_OR_GREATER
private static void WriteStructure<T>(Stream s, T structure)
where T : unmanaged
{
- // FIXME: fixup endianness
- if (!BitConverter.IsLittleEndian)
- throw new NotImplementedException();
unsafe
{
byte* p = (byte*)&structure;
@@ -212,9 +232,6 @@ private static void WriteStructure<T>(Stream s, T structure)
private static void WriteStructure<T>(Stream s, T structure)
where T : unmanaged
{
- // FIXME: fixup endianness
- if (!BitConverter.IsLittleEndian)
- throw new NotImplementedException();
int size = Marshal.SizeOf<T>();
byte[] buffer = new byte[size];
IntPtr ptr = IntPtr.Zero;
diff --git a/src/runtime/src/tasks/Microsoft.NET.WebAssembly.Webcil/WebcilReader.cs b/src/runtime/src/tasks/Microsoft.NET.WebAssembly.Webcil/WebcilReader.cs
index 4f42f82798664..ac4f9d86095a9 100644
--- a/src/runtime/src/tasks/Microsoft.NET.WebAssembly.Webcil/WebcilReader.cs
+++ b/src/runtime/src/tasks/Microsoft.NET.WebAssembly.Webcil/WebcilReader.cs
@@ -6,7 +6,7 @@
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
-
+using System.Buffers.Binary;
using System.Reflection.Metadata;
using System.Reflection.PortableExecutable;
@@ -63,14 +63,20 @@ private unsafe bool ReadHeader()
{
return false;
}
- if (!BitConverter.IsLittleEndian)
- {
- throw new NotImplementedException("TODO: implement big endian support");
- }
fixed (byte* p = buffer)
{
header = *(WebcilHeader*)p;
}
+ if (!BitConverter.IsLittleEndian)
+ {
+ header.version_major = BinaryPrimitives.ReverseEndianness(header.version_major);
+ header.version_minor = BinaryPrimitives.ReverseEndianness(header.version_minor);
+ header.coff_sections = BinaryPrimitives.ReverseEndianness(header.coff_sections);
+ header.pe_cli_header_rva = BinaryPrimitives.ReverseEndianness(header.pe_cli_header_rva);
+ header.pe_cli_header_size = BinaryPrimitives.ReverseEndianness(header.pe_cli_header_size);
+ header.pe_debug_rva = BinaryPrimitives.ReverseEndianness(header.pe_debug_rva);
+ header.pe_debug_rva = BinaryPrimitives.ReverseEndianness(header.pe_debug_size);
+ }
if (header.id[0] != 'W' || header.id[1] != 'b'
|| header.id[2] != 'I' || header.id[3] != 'L'
|| header.version_major != Internal.Constants.WC_VERSION_MAJOR
@@ -346,6 +352,7 @@ private long TranslateRVA(uint rva)
private unsafe ImmutableArray<WebcilSectionHeader> ReadSections()
{
+ WebcilSectionHeader secheader;
var sections = ImmutableArray.CreateBuilder<WebcilSectionHeader>(_header.coff_sections);
var buffer = new byte[Marshal.SizeOf<WebcilSectionHeader>()];
_stream.Seek(SectionDirectoryOffset + _webcilInWasmOffset, SeekOrigin.Begin);
@@ -357,8 +364,24 @@ private unsafe ImmutableArray<WebcilSectionHeader> ReadSections()
}
fixed (byte* p = buffer)
{
- // FIXME endianness
- sections.Add(*(WebcilSectionHeader*)p);
+ secheader = (*(WebcilSectionHeader*)p);
+ }
+ if (!BitConverter.IsLittleEndian)
+ {
+ sections.Add
+ (
+ new WebcilSectionHeader
+ (
+ virtualSize: BinaryPrimitives.ReverseEndianness(secheader.VirtualSize),
+ virtualAddress: BinaryPrimitives.ReverseEndianness(secheader.VirtualAddress),
+ sizeOfRawData: BinaryPrimitives.ReverseEndianness(secheader.SizeOfRawData),
+ pointerToRawData: BinaryPrimitives.ReverseEndianness(secheader.PointerToRawData)
+ )
+ );
+ }
+ else
+ {
+ sections.Add(secheader);
}
}
return sections.MoveToImmutable();
From 0c78184347335db183a38cf6bd26e2fe69160931 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Aleksey=20Kliger=20=28=CE=BBgeek=29?= <alklig@microsoft.com>
Date: Thu, 21 Sep 2023 14:31:12 -0400
Subject: [PATCH 2/3] Fix infinite recursion
---
.../WebcilConverter.cs | 25 ++++++++-----------
1 file changed, 10 insertions(+), 15 deletions(-)
diff --git a/src/runtime/src/tasks/Microsoft.NET.WebAssembly.Webcil/WebcilConverter.cs b/src/runtime/src/tasks/Microsoft.NET.WebAssembly.Webcil/WebcilConverter.cs
index 7b882c42d579e..fc95eded5bc33 100644
--- a/src/runtime/src/tasks/Microsoft.NET.WebAssembly.Webcil/WebcilConverter.cs
+++ b/src/runtime/src/tasks/Microsoft.NET.WebAssembly.Webcil/WebcilConverter.cs
@@ -177,6 +177,16 @@ public unsafe void GatherInfo(PEReader peReader, out WCFileInfo wcInfo, out PEFi
private static void WriteHeader(Stream s, WebcilHeader header)
{
+ if (!BitConverter.IsLittleEndian)
+ {
+ webcilHeader.version_major = BinaryPrimitives.ReverseEndianness(webcilHeader.version_major);
+ webcilHeader.version_minor = BinaryPrimitives.ReverseEndianness(webcilHeader.version_minor);
+ webcilHeader.coff_sections = BinaryPrimitives.ReverseEndianness(webcilHeader.coff_sections);
+ webcilHeader.pe_cli_header_rva = BinaryPrimitives.ReverseEndianness(webcilHeader.pe_cli_header_rva);
+ webcilHeader.pe_cli_header_size = BinaryPrimitives.ReverseEndianness(webcilHeader.pe_cli_header_size);
+ webcilHeader.pe_debug_rva = BinaryPrimitives.ReverseEndianness(webcilHeader.pe_debug_rva);
+ webcilHeader.pe_debug_size = BinaryPrimitives.ReverseEndianness(webcilHeader.pe_debug_size);
+ }
WriteStructure(s, header);
}
@@ -203,21 +213,6 @@ private static void WriteSectionHeader(Stream s, WebcilSectionHeader sectionHead
WriteStructure(s, sectionHeader);
}
- private static void WriteStructure(Stream s, WebcilHeader webcilHeader)
- {
- if (!BitConverter.IsLittleEndian)
- {
- webcilHeader.version_major = BinaryPrimitives.ReverseEndianness(webcilHeader.version_major);
- webcilHeader.version_minor = BinaryPrimitives.ReverseEndianness(webcilHeader.version_minor);
- webcilHeader.coff_sections = BinaryPrimitives.ReverseEndianness(webcilHeader.coff_sections);
- webcilHeader.pe_cli_header_rva = BinaryPrimitives.ReverseEndianness(webcilHeader.pe_cli_header_rva);
- webcilHeader.pe_cli_header_size = BinaryPrimitives.ReverseEndianness(webcilHeader.pe_cli_header_size);
- webcilHeader.pe_debug_rva = BinaryPrimitives.ReverseEndianness(webcilHeader.pe_debug_rva);
- webcilHeader.pe_debug_size = BinaryPrimitives.ReverseEndianness(webcilHeader.pe_debug_size);
- }
- WriteStructure(s, webcilHeader);
- }
-
#if NETCOREAPP2_1_OR_GREATER
private static void WriteStructure<T>(Stream s, T structure)
where T : unmanaged
From cecf4f09f0c52340c753811098f0f2d9593049aa Mon Sep 17 00:00:00 2001
From: Aleksey Kliger <alklig@microsoft.com>
Date: Thu, 21 Sep 2023 14:36:20 -0400
Subject: [PATCH 3/3] rename var
---
src/tasks/Microsoft.NET.WebAssembly.Webcil/WebcilConverter.cs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/runtime/src/tasks/Microsoft.NET.WebAssembly.Webcil/WebcilConverter.cs b/src/runtime/src/tasks/Microsoft.NET.WebAssembly.Webcil/WebcilConverter.cs
index fc95eded5bc33..13c34bde4b8ea 100644
--- a/src/runtime/src/tasks/Microsoft.NET.WebAssembly.Webcil/WebcilConverter.cs
+++ b/src/runtime/src/tasks/Microsoft.NET.WebAssembly.Webcil/WebcilConverter.cs
@@ -175,7 +175,7 @@ public unsafe void GatherInfo(PEReader peReader, out WCFileInfo wcInfo, out PEFi
SectionStart: firstWCSection);
}
- private static void WriteHeader(Stream s, WebcilHeader header)
+ private static void WriteHeader(Stream s, WebcilHeader webcilHeader)
{
if (!BitConverter.IsLittleEndian)
{
@@ -187,7 +187,7 @@ private static void WriteHeader(Stream s, WebcilHeader header)
webcilHeader.pe_debug_rva = BinaryPrimitives.ReverseEndianness(webcilHeader.pe_debug_rva);
webcilHeader.pe_debug_size = BinaryPrimitives.ReverseEndianness(webcilHeader.pe_debug_size);
}
- WriteStructure(s, header);
+ WriteStructure(s, webcilHeader);
}
private static void WriteSectionHeaders(Stream s, ImmutableArray<WebcilSectionHeader> sectionsHeaders)

View File

@ -0,0 +1,290 @@
From 0566e7dd9a7a8e5dec119d0ba715623beeba4c90 Mon Sep 17 00:00:00 2001
From: Elinor Fung <elfung@microsoft.com>
Date: Wed, 20 Sep 2023 17:27:40 -0700
Subject: [PATCH 1/2] Make HostModel PEUtils always read/write little endian
---
.../AppHost/PEUtils.cs | 26 ++++++++++++-------
1 file changed, 16 insertions(+), 10 deletions(-)
diff --git a/src/runtime/src/installer/managed/Microsoft.NET.HostModel/AppHost/PEUtils.cs b/src/runtime/src/installer/managed/Microsoft.NET.HostModel/AppHost/PEUtils.cs
index 0d0b33ed55569..e6142aba26e3e 100644
--- a/src/runtime/src/installer/managed/Microsoft.NET.HostModel/AppHost/PEUtils.cs
+++ b/src/runtime/src/installer/managed/Microsoft.NET.HostModel/AppHost/PEUtils.cs
@@ -1,6 +1,8 @@
// 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.Buffers.Binary;
using System.IO;
using System.IO.MemoryMappedFiles;
@@ -24,7 +26,9 @@ internal static unsafe bool IsPEImage(MemoryMappedViewAccessor accessor)
// https://en.wikipedia.org/wiki/Portable_Executable
// Validate that we're looking at Windows PE file
- if (((ushort*)bytes)[0] != PEOffsets.DosImageSignature
+ ReadOnlySpan<byte> signatureBytes = new(bytes, sizeof(ushort));
+ ushort signature = BinaryPrimitives.ReadUInt16LittleEndian(signatureBytes);
+ if (signature != PEOffsets.DosImageSignature
|| accessor.Capacity < PEOffsets.DosStub.PESignatureOffset + sizeof(uint))
{
return false;
@@ -68,24 +72,26 @@ internal static unsafe void SetWindowsGraphicalUserInterfaceBit(MemoryMappedView
byte* bytes = pointer + accessor.PointerOffset;
// https://en.wikipedia.org/wiki/Portable_Executable
- uint peHeaderOffset = ((uint*)(bytes + PEOffsets.DosStub.PESignatureOffset))[0];
+ ReadOnlySpan<byte> peHeaderOffsetBytes = new(bytes + PEOffsets.DosStub.PESignatureOffset, sizeof(uint));
+ uint peHeaderOffset = BinaryPrimitives.ReadUInt32LittleEndian(peHeaderOffsetBytes);
if (accessor.Capacity < peHeaderOffset + PEOffsets.PEHeader.Subsystem + sizeof(ushort))
{
throw new AppHostNotPEFileException("Subsystem offset out of file range.");
}
- ushort* subsystem = ((ushort*)(bytes + peHeaderOffset + PEOffsets.PEHeader.Subsystem));
+ Span<byte> subsystemBytes = new(bytes + peHeaderOffset + PEOffsets.PEHeader.Subsystem, sizeof(ushort));
+ ushort subsystem = BinaryPrimitives.ReadUInt16LittleEndian(subsystemBytes);
// https://docs.microsoft.com/en-us/windows/desktop/Debug/pe-format#windows-subsystem
// The subsystem of the prebuilt apphost should be set to CUI
- if (subsystem[0] != (ushort)PEOffsets.Subsystem.WindowsCui)
+ if (subsystem != (ushort)PEOffsets.Subsystem.WindowsCui)
{
- throw new AppHostNotCUIException(subsystem[0]);
+ throw new AppHostNotCUIException(subsystem);
}
// Set the subsystem to GUI
- subsystem[0] = (ushort)PEOffsets.Subsystem.WindowsGui;
+ BinaryPrimitives.WriteUInt16LittleEndian(subsystemBytes, (ushort)PEOffsets.Subsystem.WindowsGui);
}
finally
{
@@ -121,16 +127,16 @@ internal static unsafe ushort GetWindowsGraphicalUserInterfaceBit(MemoryMappedVi
byte* bytes = pointer + accessor.PointerOffset;
// https://en.wikipedia.org/wiki/Portable_Executable
- uint peHeaderOffset = ((uint*)(bytes + PEOffsets.DosStub.PESignatureOffset))[0];
+ ReadOnlySpan<byte> peHeaderOffsetBytes = new(bytes + PEOffsets.DosStub.PESignatureOffset, sizeof(uint));
+ uint peHeaderOffset = BinaryPrimitives.ReadUInt32LittleEndian(peHeaderOffsetBytes);
if (accessor.Capacity < peHeaderOffset + PEOffsets.PEHeader.Subsystem + sizeof(ushort))
{
throw new AppHostNotPEFileException("Subsystem offset out of file range.");
}
- ushort* subsystem = ((ushort*)(bytes + peHeaderOffset + PEOffsets.PEHeader.Subsystem));
-
- return subsystem[0];
+ ReadOnlySpan<byte> subsystemBytes = new(bytes + peHeaderOffset + PEOffsets.PEHeader.Subsystem, sizeof(ushort));
+ return BinaryPrimitives.ReadUInt16LittleEndian(subsystemBytes);
}
finally
{
From d39f18ecd6671748cc6baf57f141f94668cb5f9e Mon Sep 17 00:00:00 2001
From: Elinor Fung <elfung@microsoft.com>
Date: Thu, 21 Sep 2023 10:45:36 -0700
Subject: [PATCH 2/2] PR feeback - helper methods
---
.../AppHost/PEUtils.cs | 123 ++++++------------
.../AppHostUpdateTests.cs | 6 +-
2 files changed, 42 insertions(+), 87 deletions(-)
diff --git a/src/runtime/src/installer/managed/Microsoft.NET.HostModel/AppHost/PEUtils.cs b/src/runtime/src/installer/managed/Microsoft.NET.HostModel/AppHost/PEUtils.cs
index e6142aba26e3e..1bfc80fcfca49 100644
--- a/src/runtime/src/installer/managed/Microsoft.NET.HostModel/AppHost/PEUtils.cs
+++ b/src/runtime/src/installer/managed/Microsoft.NET.HostModel/AppHost/PEUtils.cs
@@ -5,6 +5,7 @@
using System.Buffers.Binary;
using System.IO;
using System.IO.MemoryMappedFiles;
+using System.Reflection.PortableExecutable;
namespace Microsoft.NET.HostModel.AppHost
{
@@ -17,31 +18,13 @@ public static class PEUtils
/// <returns>true if the accessor represents a PE image, false otherwise.</returns>
internal static unsafe bool IsPEImage(MemoryMappedViewAccessor accessor)
{
- byte* pointer = null;
+ if (accessor.Capacity < PEOffsets.DosStub.PESignatureOffset + sizeof(uint))
+ return false;
- try
- {
- accessor.SafeMemoryMappedViewHandle.AcquirePointer(ref pointer);
- byte* bytes = pointer + accessor.PointerOffset;
-
- // https://en.wikipedia.org/wiki/Portable_Executable
- // Validate that we're looking at Windows PE file
- ReadOnlySpan<byte> signatureBytes = new(bytes, sizeof(ushort));
- ushort signature = BinaryPrimitives.ReadUInt16LittleEndian(signatureBytes);
- if (signature != PEOffsets.DosImageSignature
- || accessor.Capacity < PEOffsets.DosStub.PESignatureOffset + sizeof(uint))
- {
- return false;
- }
- return true;
- }
- finally
- {
- if (pointer != null)
- {
- accessor.SafeMemoryMappedViewHandle.ReleasePointer();
- }
- }
+ // https://en.wikipedia.org/wiki/Portable_Executable
+ // Validate that we're looking at Windows PE file
+ ushort signature = AsLittleEndian(accessor.ReadUInt16(0));
+ return signature == PEOffsets.DosImageSignature;
}
public static bool IsPEImage(string filePath)
@@ -64,42 +47,15 @@ public static bool IsPEImage(string filePath)
/// <param name="accessor">The memory accessor which has the apphost file opened.</param>
internal static unsafe void SetWindowsGraphicalUserInterfaceBit(MemoryMappedViewAccessor accessor)
{
- byte* pointer = null;
-
- try
- {
- accessor.SafeMemoryMappedViewHandle.AcquirePointer(ref pointer);
- byte* bytes = pointer + accessor.PointerOffset;
-
- // https://en.wikipedia.org/wiki/Portable_Executable
- ReadOnlySpan<byte> peHeaderOffsetBytes = new(bytes + PEOffsets.DosStub.PESignatureOffset, sizeof(uint));
- uint peHeaderOffset = BinaryPrimitives.ReadUInt32LittleEndian(peHeaderOffsetBytes);
-
- if (accessor.Capacity < peHeaderOffset + PEOffsets.PEHeader.Subsystem + sizeof(ushort))
- {
- throw new AppHostNotPEFileException("Subsystem offset out of file range.");
- }
-
- Span<byte> subsystemBytes = new(bytes + peHeaderOffset + PEOffsets.PEHeader.Subsystem, sizeof(ushort));
- ushort subsystem = BinaryPrimitives.ReadUInt16LittleEndian(subsystemBytes);
-
- // https://docs.microsoft.com/en-us/windows/desktop/Debug/pe-format#windows-subsystem
- // The subsystem of the prebuilt apphost should be set to CUI
- if (subsystem != (ushort)PEOffsets.Subsystem.WindowsCui)
- {
- throw new AppHostNotCUIException(subsystem);
- }
-
- // Set the subsystem to GUI
- BinaryPrimitives.WriteUInt16LittleEndian(subsystemBytes, (ushort)PEOffsets.Subsystem.WindowsGui);
- }
- finally
- {
- if (pointer != null)
- {
- accessor.SafeMemoryMappedViewHandle.ReleasePointer();
- }
- }
+ // https://learn.microsoft.com/windows/win32/debug/pe-format#windows-subsystem
+ // The subsystem of the prebuilt apphost should be set to CUI
+ uint peHeaderOffset;
+ ushort subsystem = GetWindowsSubsystem(accessor, out peHeaderOffset);
+ if (subsystem != (ushort)Subsystem.WindowsCui)
+ throw new AppHostNotCUIException(subsystem);
+
+ // Set the subsystem to GUI
+ accessor.Write(peHeaderOffset + PEOffsets.PEHeader.Subsystem, AsLittleEndian((ushort)Subsystem.WindowsGui));
}
public static unsafe void SetWindowsGraphicalUserInterfaceBit(string filePath)
@@ -119,32 +75,7 @@ public static unsafe void SetWindowsGraphicalUserInterfaceBit(string filePath)
/// <param name="accessor">The memory accessor which has the apphost file opened.</param>
internal static unsafe ushort GetWindowsGraphicalUserInterfaceBit(MemoryMappedViewAccessor accessor)
{
- byte* pointer = null;
-
- try
- {
- accessor.SafeMemoryMappedViewHandle.AcquirePointer(ref pointer);
- byte* bytes = pointer + accessor.PointerOffset;
-
- // https://en.wikipedia.org/wiki/Portable_Executable
- ReadOnlySpan<byte> peHeaderOffsetBytes = new(bytes + PEOffsets.DosStub.PESignatureOffset, sizeof(uint));
- uint peHeaderOffset = BinaryPrimitives.ReadUInt32LittleEndian(peHeaderOffsetBytes);
-
- if (accessor.Capacity < peHeaderOffset + PEOffsets.PEHeader.Subsystem + sizeof(ushort))
- {
- throw new AppHostNotPEFileException("Subsystem offset out of file range.");
- }
-
- ReadOnlySpan<byte> subsystemBytes = new(bytes + peHeaderOffset + PEOffsets.PEHeader.Subsystem, sizeof(ushort));
- return BinaryPrimitives.ReadUInt16LittleEndian(subsystemBytes);
- }
- finally
- {
- if (pointer != null)
- {
- accessor.SafeMemoryMappedViewHandle.ReleasePointer();
- }
- }
+ return GetWindowsSubsystem(accessor, out _);
}
public static unsafe ushort GetWindowsGraphicalUserInterfaceBit(string filePath)
@@ -157,5 +88,25 @@ public static unsafe ushort GetWindowsGraphicalUserInterfaceBit(string filePath)
}
}
}
+
+ private static ushort GetWindowsSubsystem(MemoryMappedViewAccessor accessor, out uint peHeaderOffset)
+ {
+ // https://en.wikipedia.org/wiki/Portable_Executable
+ if (accessor.Capacity < PEOffsets.DosStub.PESignatureOffset + sizeof(uint))
+ throw new AppHostNotPEFileException("PESignature offset out of file range.");
+
+ peHeaderOffset = AsLittleEndian(accessor.ReadUInt32(PEOffsets.DosStub.PESignatureOffset));
+ if (accessor.Capacity < peHeaderOffset + PEOffsets.PEHeader.Subsystem + sizeof(ushort))
+ throw new AppHostNotPEFileException("Subsystem offset out of file range.");
+
+ // https://learn.microsoft.com/windows/win32/debug/pe-format#windows-subsystem
+ return AsLittleEndian(accessor.ReadUInt16(peHeaderOffset + PEOffsets.PEHeader.Subsystem));
+ }
+
+ private static ushort AsLittleEndian(ushort value)
+ => BitConverter.IsLittleEndian ? value : BinaryPrimitives.ReverseEndianness(value);
+
+ private static uint AsLittleEndian(uint value)
+ => BitConverter.IsLittleEndian ? value : BinaryPrimitives.ReverseEndianness(value);
}
}
diff --git a/src/runtime/src/installer/tests/Microsoft.NET.HostModel.Tests/Microsoft.NET.HostModel.AppHost.Tests/AppHostUpdateTests.cs b/src/runtime/src/installer/tests/Microsoft.NET.HostModel.Tests/Microsoft.NET.HostModel.AppHost.Tests/AppHostUpdateTests.cs
index 232410be8f259..b4d038b99b5ce 100644
--- a/src/runtime/src/installer/tests/Microsoft.NET.HostModel.Tests/Microsoft.NET.HostModel.AppHost.Tests/AppHostUpdateTests.cs
+++ b/src/runtime/src/installer/tests/Microsoft.NET.HostModel.Tests/Microsoft.NET.HostModel.AppHost.Tests/AppHostUpdateTests.cs
@@ -11,6 +11,7 @@
using Microsoft.NET.HostModel.AppHost;
using Microsoft.DotNet.CoreSetup.Test;
using System.Diagnostics;
+using System.Reflection.PortableExecutable;
namespace Microsoft.NET.HostModel.Tests
{
@@ -111,7 +112,9 @@ public void ItCanSetWindowsGUISubsystem()
BitConverter
.ToUInt16(File.ReadAllBytes(destinationFilePath), SubsystemOffset)
.Should()
- .Be(2);
+ .Be((ushort)Subsystem.WindowsGui);
+
+ Assert.Equal((ushort)Subsystem.WindowsGui, PEUtils.GetWindowsGraphicalUserInterfaceBit(destinationFilePath));
}
}
@@ -153,6 +156,7 @@ public void ItFailsToSetGUISubsystemWithWrongDefault()
string destinationFilePath = Path.Combine(testDirectory.Path, "DestinationAppHost.exe.mock");
string appBinaryFilePath = "Test/App/Binary/Path.dll";
+ Assert.Equal(42, PEUtils.GetWindowsGraphicalUserInterfaceBit(sourceAppHostMock));
Assert.Throws<AppHostNotCUIException>(() =>
HostWriter.CreateAppHost(
sourceAppHostMock,

View File

@ -0,0 +1,32 @@
From eaa9d8ebefb59cb289e147223b242d77e69f0861 Mon Sep 17 00:00:00 2001
From: Elinor Fung <elfung@microsoft.com>
Date: Wed, 20 Sep 2023 15:55:32 -0700
Subject: [PATCH] Skip getting Windows GUI bit on non-Windows in
AppHostShellShimMaker
---
src/Cli/dotnet/ShellShim/AppHostShimMaker.cs | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/sdk/src/Cli/dotnet/ShellShim/AppHostShimMaker.cs b/src/sdk/src/Cli/dotnet/ShellShim/AppHostShimMaker.cs
index eb9a1332299..7240150e06d 100644
--- a/src/sdk/src/Cli/dotnet/ShellShim/AppHostShimMaker.cs
+++ b/src/sdk/src/Cli/dotnet/ShellShim/AppHostShimMaker.cs
@@ -40,14 +40,14 @@ public void CreateApphostShellShim(FilePath entryPoint, FilePath shimPath)
string entryPointFullPath = Path.GetFullPath(entryPoint.Value);
var appBinaryFilePath = Path.GetRelativePath(Path.GetDirectoryName(appHostDestinationFilePath), entryPointFullPath);
-
if (ResourceUpdater.IsSupportedOS())
{
- var windowsGraphicalUserInterfaceBit = PEUtils.GetWindowsGraphicalUserInterfaceBit(entryPointFullPath);
+ bool windowsGraphicalUserInterface = OperatingSystem.IsWindows()
+ && PEUtils.GetWindowsGraphicalUserInterfaceBit(entryPointFullPath) == WindowsGUISubsystem;
HostWriter.CreateAppHost(appHostSourceFilePath: appHostSourcePath,
appHostDestinationFilePath: appHostDestinationFilePath,
appBinaryFilePath: appBinaryFilePath,
- windowsGraphicalUserInterface: (windowsGraphicalUserInterfaceBit == WindowsGUISubsystem) && OperatingSystem.IsWindows(),
+ windowsGraphicalUserInterface: windowsGraphicalUserInterface,
assemblyToCopyResourcesFrom: entryPointFullPath,
enableMacOSCodeSign: OperatingSystem.IsMacOS());
}

View File

@ -5,13 +5,13 @@ provision:
prepare: prepare:
how: install how: install
package: package:
- aspnetcore-runtime-7.0 - aspnetcore-runtime-8.0
- babeltrace - babeltrace
- bash-completion - bash-completion
- bc - bc
- binutils - binutils
- dotnet-runtime-7.0 - dotnet-runtime-8.0
- dotnet-sdk-7.0 - dotnet-sdk-8.0
- expect - expect
- file - file
- findutils - findutils