From 207fa953d8957c717e2025c9eb59cef224e426e1 Mon Sep 17 00:00:00 2001
From: Omair Majid <omajid@redhat.com>
Date: Tue, 19 Sep 2023 11:01:35 -0400
Subject: [PATCH] Fix issues found in CI

- Add patches to fix mono and arm64 issues
- Include libmono-*.a files in the SDK
- Fix CI configuration

Related: RHEL-2958
---
 copr-build                                    |  2 +-
 dotnet8.0.spec                                | 16 ++++++--
 ...e-91008-mono-var-opcode-OP_REGOFFSET.patch | 29 ++++++++++++++
 runtime-91865-arm64-page-size.patch           | 39 +++++++++++++++++++
 tests/ci.fmf                                  |  1 +
 5 files changed, 82 insertions(+), 5 deletions(-)
 create mode 100644 runtime-91008-mono-var-opcode-OP_REGOFFSET.patch
 create mode 100644 runtime-91865-arm64-page-size.patch

diff --git a/copr-build b/copr-build
index 9d7da01..2ee2805 100755
--- a/copr-build
+++ b/copr-build
@@ -10,4 +10,4 @@ srpm_name=$(grep 'Wrote: ' fedpkg.output | cut -d' ' -f 2)
 
 ls -alh "${srpm_name}"
 
-copr-cli --debug build @dotnet-sig/dotnet-preview "${srpm_name}"
+copr-cli --debug build @dotnet-sig/dotnet-preview "${srpm_name}" --timeout 36000
diff --git a/dotnet8.0.spec b/dotnet8.0.spec
index 1e88f0a..9b629d9 100644
--- a/dotnet8.0.spec
+++ b/dotnet8.0.spec
@@ -54,7 +54,7 @@
 
 Name:           dotnet%{dotnetver}
 Version:        %{sdk_rpm_version}
-Release:        0.2%{?dist}
+Release:        0.3%{?dist}
 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
 
@@ -92,6 +92,11 @@ Patch1:         roslyn-analyzers-ppc64le-apphost.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
+
 
 %if 0%{?fedora} || 0%{?rhel} >= 8
 ExclusiveArch:  aarch64 ppc64le s390x x86_64
@@ -540,9 +545,6 @@ fi
 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}/
 
-# Remove static files
-find %{buildroot}%{_libdir}/dotnet/ -type f -name 'libmono-*.a' -exec rm {} \;
-
 # Fix executable permissions on files
 find %{buildroot}%{_libdir}/dotnet/ -type f -name 'apphost' -exec chmod +x {} \;
 find %{buildroot}%{_libdir}/dotnet/ -type f -name 'singlefilehost' -exec chmod +x {} \;
@@ -663,6 +665,12 @@ export COMPlus_LTTng=0
 
 
 %changelog
+* Tue Sep 19 2023 Omair Majid <omajid@redhat.com> - 8.0.100~rc.1-0.3
+- Add patches to fix mono and arm64 issues
+- Include libmono-*.a files in the SDK
+- Fix CI configuration
+- Related: RHEL-2958
+
 * 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
 - Related: RHEL-2958
diff --git a/runtime-91008-mono-var-opcode-OP_REGOFFSET.patch b/runtime-91008-mono-var-opcode-OP_REGOFFSET.patch
new file mode 100644
index 0000000..ac6eb6b
--- /dev/null
+++ b/runtime-91008-mono-var-opcode-OP_REGOFFSET.patch
@@ -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;
diff --git a/runtime-91865-arm64-page-size.patch b/runtime-91865-arm64-page-size.patch
new file mode 100644
index 0000000..11b86b8
--- /dev/null
+++ b/runtime-91865-arm64-page-size.patch
@@ -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];
diff --git a/tests/ci.fmf b/tests/ci.fmf
index beb95c0..2550a34 100644
--- a/tests/ci.fmf
+++ b/tests/ci.fmf
@@ -20,6 +20,7 @@ prepare:
         - jq
         - libstdc++-devel
         - lldb
+        - lttng-ust
         - npm
         - postgresql-odbc
         - postgresql-server