platform/upstream/dotnet/runtime.git
2 years agoTag myself on area-CodeGen-coreclr issues (#70142)
Jakob Botsch Nielsen [Thu, 2 Jun 2022 20:22:20 +0000 (22:22 +0200)]
Tag myself on area-CodeGen-coreclr issues (#70142)

2 years agoJIT: Fix checked/release diff (#70144)
Jakob Botsch Nielsen [Thu, 2 Jun 2022 19:50:07 +0000 (21:50 +0200)]
JIT: Fix checked/release diff (#70144)

Fix #70143 introduced by #68869

2 years agoDelete an old quirk in "gtSetEvalOrder" (#69894)
SingleAccretion [Thu, 2 Jun 2022 19:08:45 +0000 (22:08 +0300)]
Delete an old quirk in "gtSetEvalOrder" (#69894)

The quirk prevented us from marking address modes for SIMD types as
NO_CSE, which in most cases is not good for CQ.

Thus, deleting the quirk yields mostly positive diffs, with some small
regressions in ARM64 where "genCreateAddrMode" is not perfect in its
understanding of which address modes are legal.

2 years agoEnable test that already fixed (#70065)
Buyaa Namnan [Thu, 2 Jun 2022 19:01:57 +0000 (12:01 -0700)]
Enable test that already fixed (#70065)

2 years agoSkip HostAbortedExceptionTests when BinaryFormatter isn't supported (#70151)
Eric Erhardt [Thu, 2 Jun 2022 17:58:32 +0000 (11:58 -0600)]
Skip HostAbortedExceptionTests when BinaryFormatter isn't supported (#70151)

Fix #70132

2 years agoEnable Expression tests for NativeAOT (#69945)
Lakshan Fernando [Thu, 2 Jun 2022 17:13:41 +0000 (10:13 -0700)]
Enable Expression tests for NativeAOT (#69945)

* Enable Expression tests for NativeAOT

* Add debug info

* FB

* FB2

* FB4

2 years agoMove TypeReference.ToObject to managed (CoreCLR) (#70055)
Sergio Pedri [Thu, 2 Jun 2022 15:09:29 +0000 (17:09 +0200)]
Move TypeReference.ToObject to managed (CoreCLR) (#70055)

* Initial partial TypedReference.ToObject managed port

* Port rest of mamaged TypeDesc method table logic

* Add RuntimeTypeHandle.GetElementTypeMethodTable FCall

* Remove TypedReference.InternalToObject FCall

* Remove throwing path, add an assert

* Remove unnecessary TypeDesc paths

* Remove ParamTypeDesc::m_TemplateMT and related code

* Fix TypeDesc::GetMethodTable

* Reuse RuntimeTypeHandle.GetValueInternal to drop an FCall

* Add unit tests for TypedReference.ToObject and type desc

* Move ifdef methods to TypedReference.Mono file

* Skip new TypedReference tests on Mono

* Use [ActiveIssue] instead of [SkipOnMono]

* Commented tests out to skip Mono AOT failure

2 years agoUse key properties to determine ECC key size for Apple
Kevin Jones [Thu, 2 Jun 2022 14:56:13 +0000 (10:56 -0400)]
Use key properties to determine ECC key size for Apple

Remove previous workarounds for determining ECC key sizes since those workarounds only apply to unsupported macOS versions now.

2 years agoImprove DisplayNameHelpers for NativeAOT (#70084)
Vitek Karas [Thu, 2 Jun 2022 14:22:06 +0000 (07:22 -0700)]
Improve DisplayNameHelpers for NativeAOT (#70084)

These helpers are used to report names of things in warnings. The functional changes are:
* For method parameters, use the parameter name if available (and only if not fallback to the #1 notation)
* For property accessor methods, use the C# naming scheme, so for example Type.Property.get instead of Type.get_Property.

Both of these changes are in preparation to bring NativeAOT closer in behavior to ILLink and the trim analyzers.

For this I moved some of the helpers to the common shared code.

Some unrelated code cleanup as well.

Co-authored-by: Michal Strehovský <MichalStrehovsky@users.noreply.github.com>
2 years ago[QUIC] Latest msquic interop (#69876)
Marie Píchová [Thu, 2 Jun 2022 12:47:14 +0000 (14:47 +0200)]
[QUIC] Latest msquic interop (#69876)

* Latest msquic interop

* Update src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/MsQuic/Interop/msquic_extensions.cs

* No polyfill for runtime repo

* Feedback

2 years agoDisable flaky DNS cancellation tests during jitstress (#70089)
Radek Zikmund [Thu, 2 Jun 2022 10:01:42 +0000 (12:01 +0200)]
Disable flaky DNS cancellation tests during jitstress (#70089)

* Revert "Reenable GetHostAddressesTest_Cancellation on Unix (#70009)"

This reverts commit e8b95926ed9880156071ee8575a7c22f13675081.

* Revert "Fix flakyness of DnsGetHostAddresses_PostCancelledToken_Throws (#70044)"

This reverts commit a466063cd273e88276abe9d84eb28dccaf50d633.

* Disable flaky tests on jitstress

* fixup! Disable flaky tests on jitstress

2 years agoExempt MemberNotNullWhen from genapi ref assembly requirements (#70113)
Stephen Toub [Thu, 2 Jun 2022 07:10:11 +0000 (03:10 -0400)]
Exempt MemberNotNullWhen from genapi ref assembly requirements (#70113)

As with MemberNotNull, MemberNotNullWhen is an implementation detail when it refers to a private member (even when attributed on a public API).  The tooling shouldn't require it in reference assemblies, as in such situations it a) isn't meaningful to a consumer and b) leaks implementation details.

2 years agoFix build issues after enabling TRACE_GC (#69766)
Andrew Au [Thu, 2 Jun 2022 06:46:26 +0000 (23:46 -0700)]
Fix build issues after enabling TRACE_GC (#69766)

2 years agoMore lib testing with native AOT (#69132)
Lakshan Fernando [Thu, 2 Jun 2022 05:13:37 +0000 (22:13 -0700)]
More lib testing with native AOT (#69132)

2 years agoResumbmit tar feedback changes, include Android build fix (#69469)
Carlos Sanchez [Thu, 2 Jun 2022 03:41:19 +0000 (20:41 -0700)]
Resumbmit tar feedback changes, include Android build fix (#69469)

* Address some System.Formats.Tar TODOs (infra and syscalls) (#69107)

Re-submitting the changes approved in PR: https://github.com/dotnet/runtime/pull/69107

Addresses: https://github.com/dotnet/runtime/issues/68230

Includes an extra change to prevent the android build failure with the addition of the new native call to getgrgid_r.

Co-authored-by: carlossanlop <carlossanlop@users.noreply.github.com>
Co-authored-by: Adam Sitnik <adam.sitnik@gmail.com>
2 years agoUpdate Roslyn to pick up recent features / bug fixes / design changes (#70087)
Stephen Toub [Thu, 2 Jun 2022 02:43:34 +0000 (22:43 -0400)]
Update Roslyn to pick up recent features / bug fixes / design changes (#70087)

* Update Roslyn to pick up recent features

* Replace a straggling !!

* Fix now erroneous use of u8

* Disable several generic math tests

2 years ago[wasm] Add support for symbolicating traces via XHarness (#66226)
Ankit Jain [Thu, 2 Jun 2022 01:59:28 +0000 (21:59 -0400)]
[wasm] Add support for symbolicating traces via XHarness (#66226)

* [wasm] Add `WasmSymbolicator` project

- this can be used to symbolicate traces using patterns from
  `src/mono/wasm/data/wasm-symbol-patterns.txt`.
- Includes a wrapper that can be passed to xharness for symbolicating
  traces in the output.

- This can be used as a command line tool also:

`dotnet run /path/to/dotnet.js.symbols /path/to/traces`

If `-` is passed instead of the last argument, then it reads the
messages from stdin.

* [wasm] Enable xharness+symbolicator for library tests

* [wasm ] startup.ts: improve printing errors

* [wasm] test-main.js: print 'WASM EXIT' message even for non-browser cases

* [wasm] Enable symbols file generation for samples in Release config

* [wasm] Fix file check

* Fix build

* fix dotnet-linker-tests build

* Update condition for using wasmsymbolicator with xharness

* Update build-commons.sh

Revert unnecessary change

* Update gen-buildsys.sh

Revert unnecessary change

* Update build.sh

Revert unnecessary change

2 years agoUpdate test to stop expecting removed diagnostics (#70106)
Elinor Fung [Thu, 2 Jun 2022 01:01:27 +0000 (18:01 -0700)]
Update test to stop expecting removed diagnostics (#70106)

2 years agoSupport more primitive type converters (#70057)
Tarek Mahmoud Sayed [Thu, 2 Jun 2022 00:41:31 +0000 (17:41 -0700)]
Support more primitive type converters (#70057)

2 years agoCoreCLR support for default interface implementation of static virtual methods (...
Tomáš Rylek [Wed, 1 Jun 2022 23:45:43 +0000 (01:45 +0200)]
CoreCLR support for default interface implementation of static virtual methods (#66887)

* Move the diamondshape test under StaticVirtualMethods

* Modify the test to exercise static virtual methods

* Fixes to svm_diamondshape to make it build; initial runtime changes

* Partial change for default interface implementations of SVMs

* Additional JIT changes to make default impl's of SVM resolve properly

* Add struct variants for the svm_diamondshape tests

* Add struct and ldftn testing per David's PR feedback

* Remove 'final' check; add reabstraction test cases

* Relax flag checking for reabstracted SVMs; runtime resolution test

2 years ago[wasm-ep] Implement EventSource counters support; add an EventPipeSessionOptions...
Aleksey Kliger (λgeek) [Wed, 1 Jun 2022 23:31:06 +0000 (19:31 -0400)]
[wasm-ep] Implement EventSource counters support; add an EventPipeSessionOptions builder to TS (#69567)

1. Implements support for creating event counters in WebAssembly apps.
   **Important change** adds `Thread.IsInternalThreadStartSupported` and `Thread.InternalUnsafeStart()` to `System.Threading.Thread` that can be used by System.Private.CoreLib to start threads on a runtime where `Thread.IsThreadStartSupported` is false.
   This is used to create the event counters polling thread.
   This is in addition to the native runtime being able to create threads using `mono_thread_create_internal`
2. Coop thread suspend: STW calls `mono_threads_platform_stw_defer_initial_suspend` which postpones suspending a thread until the next GC suspend phase.  Doesn't do anything on most platforms.  On WASM, suspend the main browser thread after all the other threads are suspended. This helps prevent deadlocks where the main thread is suspended while another thread is doing a call that is proxied to the main thread and cannot complete.  By suspending the main thread last, we give it a chance to service the other threads' requests.
2. Adds a `MONO.diagnostics.SessionOptionsBuilder` class that can be used to create an `EventPipeSessionOptions` instance and populate the provider string for an event pipe session.
3. Updated the `browser-eventpipe` sample to create an EventSource and some counters.  The sample is now interactive so you have to click "Start Work" in a browser for things to happen.

There's an outstanding issue https://github.com/dotnet/runtime/issues/69568 that will be investigated in a follow-up PR

* Add custom EventSource and counter

   - Added a method for coop GC to suspend the main browser thread in the second phase (so that other threads are less likely to deadlock if they delegate work to it)

   - Added an event provider builder

   - Added a Thread.InternalUnsafeStart() method and a IsInternalThreadStartSupported property.  This allows EventSource to start a thread to poll the counter values.

   - The sample with counters can now record counter values.  But not at the same time as the default configuration (runtime, runtime private, sample profiler).  Not sure if it's a wasm issue or a limitation of EventPipe.

* Change ProvidersConfigBuilder to SessionOptionsBuilder

   it creates an entire EventPipeSessionOptions object, not just the providers config

* checkout interactive demo

* Add docs; fix whitespace

* more whitespace fixes

* add default arg value to ThrowIfNoThreadStart

* fix build

* Review feedback

2 years agoAvoid tailcall optimization in invoke test (#70108)
Steve Harter [Wed, 1 Jun 2022 22:22:24 +0000 (17:22 -0500)]
Avoid tailcall optimization in invoke test (#70108)

2 years agoMove comments about different form factors to the top (#70102)
Andy Gocke [Wed, 1 Jun 2022 22:04:48 +0000 (15:04 -0700)]
Move comments about different form factors to the top (#70102)

2 years agoRemove more uses of StringBuilderCache (#69683)
Stephen Toub [Wed, 1 Jun 2022 21:24:10 +0000 (17:24 -0400)]
Remove more uses of StringBuilderCache (#69683)

* Remove more uses of StringBuilderCache

* Address PR feedback

* Fix missing colon in TimeZone formatting

2 years agoFix state reference of reflection-only loader context (#70094)
Jan Kotas [Wed, 1 Jun 2022 19:59:43 +0000 (12:59 -0700)]
Fix state reference of reflection-only loader context (#70094)

Also delete unused winmd related error message

Fix #70074

2 years ago[wasm] Fix runtime test failing due to the app running in debug mode (#70050)
Ankit Jain [Wed, 1 Jun 2022 19:05:13 +0000 (15:05 -0400)]
[wasm] Fix runtime test failing due to the app running in debug mode (#70050)

* [wasm] Fix runtime test failing due to the app running in debug mode

Fixes https://github.com/dotnet/runtime/issues/69517

- Recent [wasm-app-host commit](6b3ea401ca20c26dbb5497b0fbbf77b3afc73374) changed `WasmApp.targets` so
  `WasmDebugLevel` would be set to enable debugging if
  `Configuration==Debug`.
    - this broke some runtime tests which depend on tail call
    optimizations, which get disabled when debugging is enabled in the
    runtime.

- And the wasm apps for the runtime tests are being built with no
  configuration set, which defaults to `Debug`. Instead, propogate the
  config for the build to the wasm proxy (`WasmTestRunner`) projects too.

Fixes https://github.com/dotnet/runtime/issues/69517 .

* Revert "[wasm] Disable runtime test failing due to stack overflow (#69863)"

This reverts commit 61441fae579149181dc973ae4e58eccd4beef728.

2 years agoFix VTableCallHolder writeable mapping size with W^X (#70093)
Jan Vorlicek [Wed, 1 Jun 2022 18:40:18 +0000 (20:40 +0200)]
Fix VTableCallHolder writeable mapping size with W^X (#70093)

The size of this holder is dynamic, but when we are creating the writeable
mapping of this holder to initialize its code, we don't take that into account.
So in case the holder is located at the end of a memory page and crosses its
boundary, the writeable mapping covers only the beginning of the holder and
so we either crash during the initialization if the following memory page is
not mapped or read only, or we corrupt a completely unrelated memory page
in case it is mapped and writeable.

The fix is to use the real size of the holder instead of sizeof(...).

2 years agoCreating comma temps differently for SubMulDiv morph (#69770)
Will Smith [Wed, 1 Jun 2022 18:23:50 +0000 (11:23 -0700)]
Creating comma temps differently for SubMulDiv morph (#69770)

* Creating comma temps differently for SubMulDiv morph

* Fixing some formatting. Added comments. Renamed fgMustMakeTemp to fgIsCloneableInvariantOrLocal

* Renaming

* Putting back in a check

* Formatting

* Adding comments

* Formatting

2 years ago[wasm][debugging] Adding instructions for native debugging (#69873)
Thays Grazia [Wed, 1 Jun 2022 17:53:30 +0000 (14:53 -0300)]
[wasm][debugging] Adding instructions for native debugging  (#69873)

* Adding support to native debugging.

* Remove console.writeline commited by mistake

* Update debugger.md

* Update src/mono/wasm/debugger/debugger.md

Co-authored-by: Aaron Robinson <arobins@microsoft.com>
* Update src/mono/wasm/debugger/debugger.md

Co-authored-by: Larry Ewing <lewing@microsoft.com>
* Update debugger.md

* addressing comments in the PR

* Update WasmApp.Native.targets

* Update WasmApp.Native.targets

* Apply suggestions from code review

Co-authored-by: Ankit Jain <radical@gmail.com>
* Update debugger.md

* Update debugger.md

* Update debugger.md

* Update WasmApp.Native.targets

Co-authored-by: Aaron Robinson <arobins@microsoft.com>
Co-authored-by: Larry Ewing <lewing@microsoft.com>
Co-authored-by: Ankit Jain <radical@gmail.com>
2 years agoAggressive GC (#69695)
Andrew Au [Wed, 1 Jun 2022 16:22:41 +0000 (09:22 -0700)]
Aggressive GC (#69695)

2 years ago[mono] Support array parameter types of custom attributes in Mono AOT compiler (...
Ivan Povazan [Wed, 1 Jun 2022 16:09:22 +0000 (18:09 +0200)]
[mono] Support array parameter types of custom attributes in Mono AOT compiler (#69759)

- mono_reflection_create_custom_attr_data_args_noalloc now supports decoding array type parameters of custom attributes
- mono_reflection_create_custom_attr_data_args_noalloc is refactored to use MonoDecodeCustomAttr
- MonoDecodeCustomAttr encapsulates all the information of the decoded custom attribute parameters
- initial support for UnmanagedCallConvAttribute: native-to-managed wrapper generation now takes into account applied custom attributes by updating the method's signature

Fixes [#52977](https://github.com/dotnet/runtime/issues/52977)

2 years ago[API Implementation]: Expose `StopTheHostException` (#69404)
Robin Lindner [Wed, 1 Jun 2022 15:45:50 +0000 (17:45 +0200)]
[API Implementation]: Expose `StopTheHostException` (#69404)

* Implement `HostAbortedException` proposal

* Apply suggestions

* Add solution file

Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
2 years agoEnable mandelbrot-7 (#69915)
Fan Yang [Wed, 1 Jun 2022 15:16:04 +0000 (11:16 -0400)]
Enable mandelbrot-7 (#69915)

2 years agoEnsure we do not corrupt RAX for CFG dispatcher on x64 (#70016)
Jakob Botsch Nielsen [Wed, 1 Jun 2022 09:42:28 +0000 (11:42 +0200)]
Ensure we do not corrupt RAX for CFG dispatcher on x64 (#70016)

The jump stubs used on x64 will clutter rax which is used for the target
address in the CFG dispatcher. When this happened for the CFG dispatcher
it would result in an infinite loop.

The same problem is already handled for some other helpers as pointed
out by @jkotas, so simply add the CFG dispatcher to that set.

2 years agoFix fgCanTailCallViaJitHelper (#70033)
Jakob Botsch Nielsen [Wed, 1 Jun 2022 09:15:51 +0000 (11:15 +0200)]
Fix fgCanTailCallViaJitHelper (#70033)

FEATURE_READYTORUN is always defined except for single-file JIT. The
right check here is Compiler::Options::IsReadyToRun().

Fix #70013

2 years agoFix incorrect docker tack for fedora 34 helix image (#70011)
Radek Zikmund [Wed, 1 Jun 2022 08:46:22 +0000 (10:46 +0200)]
Fix incorrect docker tack for fedora 34 helix image (#70011)

2 years agoAdd ILogWriter interface to ilc (#69609)
Vitek Karas [Wed, 1 Jun 2022 08:30:03 +0000 (01:30 -0700)]
Add ILogWriter interface to ilc (#69609)

This will allow test infra to capture full detail of reported diagnostics (not just text, but the actual type system objects).

Part of the work to bring linker tests over to Native AOT.

Note: the products don't use this in any way. The plan is for the tests to have a project reference to ILCompiler and use test-specific log writer through the APIs there.

In other changes where I'm tryhing to share more code with the linker and NativeAOT the idea of sharing the logger between crossgen and ilc becomes really problematic (the MessageOrigin and related classes become even more coupled with the ilc/linker code).
So I decided to split the two loggers completely, the ilc is really the only one using the MessageOrigin and related functionality, while crossgen uses the very simple string based methods only.

So I moved all of the ilc specific classes into the ilc directories along with the logger.
I then introduced a very simple logger class just for crossgen which implements only the necessary functionality for that tool.

If there's a will to share more in the future (no reason right now I'm aware of) we should design a better abstraction for the two tools to share.

2 years agoFix flakyness of DnsGetHostAddresses_PostCancelledToken_Throws (#70044)
Radek Zikmund [Wed, 1 Jun 2022 08:26:02 +0000 (10:26 +0200)]
Fix flakyness of DnsGetHostAddresses_PostCancelledToken_Throws (#70044)

* Fix flakyness of DnsGetHostAddresses_PostCancelledToken_Throws

* fixup! Fix flakyness of DnsGetHostAddresses_PostCancelledToken_Throws

2 years agoFix STAThreadAttribute/MTAThreadAttribute on main entry point not respected by Native...
ThomasGoulet73 [Wed, 1 Jun 2022 08:19:37 +0000 (04:19 -0400)]
Fix STAThreadAttribute/MTAThreadAttribute on main entry point not respected by NativeAOT (#70067)

Fixes dotnet/runtime#70066

2 years agoAdd NativeAOT info to dump debugging template (#70070)
Michal Strehovský [Wed, 1 Jun 2022 07:31:07 +0000 (16:31 +0900)]
Add NativeAOT info to dump debugging template (#70070)

2 years agoFix compilation error in VS 17.3.1 (#69994)
Andrii Kurdiumov [Wed, 1 Jun 2022 07:21:14 +0000 (13:21 +0600)]
Fix compilation error in VS 17.3.1 (#69994)

I believe this is related to latest changes in Roslyn.
Similar to https://github.com/dotnet/winforms/pull/7220

2 years agoMake gcunsafe for cpblk if it has gc pointers (#70053)
Kunal Pathak [Wed, 1 Jun 2022 05:28:53 +0000 (22:28 -0700)]
Make gcunsafe for cpblk if it has gc pointers (#70053)

2 years agoUse void* for array pinning (#70048)
Elinor Fung [Wed, 1 Jun 2022 04:15:07 +0000 (21:15 -0700)]
Use void* for array pinning (#70048)

2 years agoExclude GetTotalPauseDuration from GCStress (#70037)
Andrew Au [Wed, 1 Jun 2022 02:58:46 +0000 (19:58 -0700)]
Exclude GetTotalPauseDuration from GCStress (#70037)

2 years agoAdd special Comparer/EqualityComparer for Nullable<Enum> (#68077)
Egor Bogatov [Tue, 31 May 2022 23:22:59 +0000 (02:22 +0300)]
Add special Comparer/EqualityComparer for Nullable<Enum> (#68077)

2 years agoTemporarily disable tailcall_d / do on Windows arm with #70042 (#70043)
Tomáš Rylek [Tue, 31 May 2022 23:16:49 +0000 (01:16 +0200)]
Temporarily disable tailcall_d / do on Windows arm with #70042 (#70043)

2 years agoRemove more wprintf usages (#69912)
Aaron Robinson [Tue, 31 May 2022 22:59:00 +0000 (15:59 -0700)]
Remove more wprintf usages (#69912)

* Remove wprintf from eventpipe.

* Remove messagebox logic from utils and place its single usage
  under debug/.

* Convert Profiler GUID logging to use UTF-8

2 years agoKeep native order of get members call from Type (#69506)
Buyaa Namnan [Tue, 31 May 2022 22:14:36 +0000 (15:14 -0700)]
Keep native order of get members call from Type  (#69506)

Co-authored-by: Jan Kotas <jkotas@microsoft.com>
2 years agoAdding support for vector constants via GenTreeVecCon (#68874)
Tanner Gooding [Tue, 31 May 2022 21:21:33 +0000 (14:21 -0700)]
Adding support for vector constants via GenTreeVecCon (#68874)

* Adding support for vector constants via GenTreeVecCon

* Responding to PR feedback

* Support tracking the underlying simdBaseJitType for GenTreeVecCon

* Applying formatting patch

* Handle the scenario where TYP_SIMD8 is retyped to TYP_LONG or TYP_DOUBLE

* Ensure GenTreeVecCon tracks the simdSize so that TYP_SIMD8 ABI retyping still works

* Ensure the create call and not the cloned local is lowered

* Resolving PR feedback

* Ensure morph and rationalize check `OBJ(ADDR(CNS_VEC))`

* Update src/coreclr/jit/gentree.cpp

Co-authored-by: SingleAccretion <62474226+SingleAccretion@users.noreply.github.com>
Co-authored-by: SingleAccretion <62474226+SingleAccretion@users.noreply.github.com>
2 years agoFix address adjustment in bundle unmap for macos universal binaries (#69687)
Vladimir Sadov [Tue, 31 May 2022 21:03:27 +0000 (14:03 -0700)]
Fix address adjustment in bundle unmap for macos universal binaries (#69687)

2 years agoChange some delegate FCalls to managed (#70000)
Huo Yaoyuan [Tue, 31 May 2022 20:57:30 +0000 (04:57 +0800)]
Change some delegate FCalls to managed (#70000)

* Convert CompareUnmanagedFunctionPtrs to managed

* Move simple type match to managed

* Add more check in managed portion

* Rename method for FCall

* Change FCall to directly call IsEquivalentTo

* Add helper method frame

* Fix uninitialized result variable

* Change to QCall for type equivalence

2 years agoOptimize Array.GetFlattenedIndex (all runtimes) and InternalGetValue (CoreCLR) (...
Sergio Pedri [Tue, 31 May 2022 19:53:07 +0000 (21:53 +0200)]
Optimize Array.GetFlattenedIndex (all runtimes) and InternalGetValue (CoreCLR) (#69940)

* Add managed fast path for SZ Array.GetValue(int)

This is only used when the element type is a reference type

* Move faster GetValue(int) to CoreCLR-specific file

* Add Array.GetFlattenedIndex(int) overload

* Add managed stub for InternalGetValue in CoreCLR

This is used whenever the element type is a class

* Initial (partial) port of ArrayNative::GetValue to C#

* Simplify TypeDesc checks in managed Array.GetValue

* Remove Array.InternalGetValue CoreCLR FCall

* Add RuntimeHelpers.Box FCall on CoreCLR

* Implement value type support for managed Array.InternalGetValue

* Remove leftover MethodTable.IsElementTypeClass property

* Minor API tweaks, add XML docs

* Fix some typos and oversights

* Remove managed TypeDesc type (not needed anymore)

* Revert name change for MethodTable.ElementType field

* Simplify Array.GetFlattenedIndex (CoreCLR/NativeAOT)

* Apply suggestions from code review

* Move FCIMPL to comutilnative.cpp
* Remove ExplicitLayout from TypeHandle
* Tweak comment on unsupported path for Array.GetValue
* Use MemoryMarshal.GetArrayDataReference instead of manual addressing
* Add HELPER_METHOD_FRAME to FCall implementation

* Move MethodTable FCall decl to comutilnative.h

* Simplify legacy behavior check in ArrayNative::SetValue

* Change RuntimeHelpers.Box to just call JIT_Box

* Simplify GetArrayElementTypeHandle(), add an assert

2 years agoSplit out and generalize tailcall IR validation/tailcall profile adjustments (#69941)
Jakob Botsch Nielsen [Tue, 31 May 2022 18:57:10 +0000 (20:57 +0200)]
Split out and generalize tailcall IR validation/tailcall profile adjustments (#69941)

* Split the IR validation after tailcalls into a separate function.
  Previously it was intertwined with updating of profile weights for
  follow-up blocks.
* Generalize the validation to use a tree walk and handle more cases.
  This fixes an assertion failure seen in some PGO runs.
* Generalize the updating of profile weights for follow-up blocks.
  Previously this was only updating profile weights for one follow up
  blocks, but there can be an arbitrary number of successor blocks due
  to inlining.

Fix #69939

2 years agoClean up emitOutputNOP (#69989)
Bruce Forstall [Tue, 31 May 2022 18:06:22 +0000 (11:06 -0700)]
Clean up emitOutputNOP (#69989)

Change it to take a dst, not a writeable dst, pointer.

2 years agoImprove regex tests for offset start cases (#69959)
Dan Moseley [Tue, 31 May 2022 17:02:26 +0000 (11:02 -0600)]
Improve regex tests for offset start cases (#69959)

* Improve tests for offset start

* improve

* comment

2 years agoDisable TarWriter_WriteEntry_File_Tests.Add_File in Linux (#69997)
Carlos Sanchez [Tue, 31 May 2022 16:54:40 +0000 (09:54 -0700)]
Disable TarWriter_WriteEntry_File_Tests.Add_File in Linux (#69997)

2 years agoCryptography.Xml.Tests: Make tests account for RHEL9 RSA+SHA1 deprecation
Tom Deseyn [Tue, 31 May 2022 16:42:44 +0000 (18:42 +0200)]
Cryptography.Xml.Tests: Make tests account for RHEL9 RSA+SHA1 deprecation

Co-authored-by: Kevin Jones <vcsjones@github.com>
2 years agoMove off preview onto regular Windows 11 client images (#69871)
Matt Galbraith [Tue, 31 May 2022 16:36:21 +0000 (09:36 -0700)]
Move off preview onto regular Windows 11 client images (#69871)

2 years ago[Mono] Pass Vector128 in SIMD registers, when LLVM is enabled (#68991)
Fan Yang [Tue, 31 May 2022 16:35:49 +0000 (12:35 -0400)]
[Mono] Pass Vector128 in SIMD registers, when LLVM is enabled (#68991)

* Add a new LLVMArgStorage type

* Fix llvm signature

* Fix emit_call

* Enable passing SIMD register on arm64 and clean up debugging stuff

* Clean up unnecessary format change

* Update code after rebase

* Only use SIMD register when element type is primitive type

* Disable SIMD intrinsics for generic sharing, since it doesn't work at all.

* Check if element type is primitive on arm64

* Not using SIMD register when it is full aot

* Address review feedbacks

2 years agoReenable GetHostAddressesTest_Cancellation on Unix (#70009)
Radek Zikmund [Tue, 31 May 2022 16:32:10 +0000 (18:32 +0200)]
Reenable GetHostAddressesTest_Cancellation on Unix (#70009)

2 years ago[mono] Fix diamond pattern encountered with static virtual interface methods (#69738)
Vlad Brezae [Tue, 31 May 2022 16:22:11 +0000 (19:22 +0300)]
[mono] Fix diamond pattern encountered with static virtual interface methods (#69738)

* [mono][mini] Throw exception if we have conflicts with static virtual interface call

Small refactoring to avoid duplicated code

* [mono][interp] Throw exception if we have conflicts with static virtual interface call

* [mono][mini] Fix method access check during ldftn

From IL, it is possible to change the access modifier when overriding a method. In such case we need to check the accessibility of the IL method and not the one that we resolve from the constrained class.

2 years ago[Mono] Fix 4244 warnings. (#69236)
Johan Lorensson [Tue, 31 May 2022 16:03:52 +0000 (18:03 +0200)]
[Mono] Fix 4244 warnings. (#69236)

* Fixes all 4244 warnings on Mono runtime x86/x64 Windows build,
aligning with SDL requirements (#66154).

There will be additional warnings in the cross compilers that needs
to be fixed separately, but this should fix the major bulk of
4244 warnings.

All changes done in this PR are mitigating compiler issued data type
truncation 4244 warnings:

'conversion' conversion from 'type1' to 'type2', possible loss of data

and PR will align to the same type as the compiler issued in the warning.

PR introduce a new set of macros to cast between types following patter
of existing GPOINTER_TO_INT, GPOINTER_TO_UINT, GTYPE1_TO_TYPE2.

The idea of use these macros is that it will be clear where casts are done,
and we will have ability to intercept and add validation logic in
specialized builds to catch truncation errors. The PR also introduce
the needed inline functions under ENABLE_CHECKED_CASTS that could be
used for extended validation when using the macros. Failure actions
in these inline functions are not currently fully implemented,
since that will be different from case to case,
but can be added when needed since all infrastructure is prepared.

If it is possible to change types used in code to mitigate the warnings,
that will be the initial strategy used by this PR, if that however would
cause ripple effects through the source code (unfortunately quite common),
we will fallback using the GTYPE1_TO_TYPE2 macros to clearly show the
intent, keep trackability of the change as well as adding ability to do
additional validation of casts in the future.

2 years ago[Android] Add UnmanagedCallersOnly attribute to SafeDeleteSslContext.ReadFromConnecti...
Simon Rozsival [Tue, 31 May 2022 14:22:18 +0000 (16:22 +0200)]
[Android] Add UnmanagedCallersOnly attribute to SafeDeleteSslContext.ReadFromConnection/WriteToConnection methods (#69507)

2 years ago[mono][doc] Update Android NDK version to r23c (#69913)
Fan Yang [Tue, 31 May 2022 13:39:51 +0000 (09:39 -0400)]
[mono][doc] Update Android NDK version to r23c (#69913)

2 years agoUse `Random.XoshiroImpl` in the thread pool's hill climbing RNG. (#69987)
Theodore Tsirpanis [Tue, 31 May 2022 13:37:05 +0000 (16:37 +0300)]
Use `Random.XoshiroImpl` in the thread pool's hill climbing RNG. (#69987)

2 years agoAdd MetadataUpdateOriginalTypeAttribute (#69751)
Aleksey Kliger (λgeek) [Tue, 31 May 2022 13:18:09 +0000 (09:18 -0400)]
Add MetadataUpdateOriginalTypeAttribute (#69751)

Fixes https://github.com/dotnet/runtime/issues/66222

2 years agoFix `--fulllog` in ILC/crossgen2 (#69996)
Michal Strehovský [Tue, 31 May 2022 13:11:17 +0000 (22:11 +0900)]
Fix `--fulllog` in ILC/crossgen2 (#69996)

Fixes issue reported in https://github.com/dotnet/runtime/issues/66716#issuecomment-1069310326.

We create a hashset for the purpose of avoiding this problem, check it, but never add to it.

2 years agoDelete CallingConventions.cs (#70001)
Michal Strehovský [Tue, 31 May 2022 12:48:42 +0000 (21:48 +0900)]
Delete CallingConventions.cs (#70001)

This file was added for universal shared code. We can restore it again if it's needed, but we don't need it now.

On NativeAOT we could leverage the CCC for reflection invoke, but this code was never updated to work outside Windows. It's safer to delete it.

2 years agoCI fix for native aot tests (#69571)
Lakshan Fernando [Tue, 31 May 2022 10:47:41 +0000 (03:47 -0700)]
CI fix for native aot tests (#69571)

* CI fix for native aot tests

* parse notrait commandline args

* try a different platform

* FB

* Remove unnecessary whitespace change

These make `git blame` harder to follow. Plus the consistent thing in this file is no extra newline here.

Co-authored-by: Michal Strehovský <MichalStrehovsky@users.noreply.github.com>
2 years agoChange wording of exception (#69957)
Steve Dunn [Tue, 31 May 2022 10:30:43 +0000 (11:30 +0100)]
Change wording of exception (#69957)

* Change wording of exception

* Update src/libraries/System.Text.Json/src/Resources/Strings.resx

Co-authored-by: Eirik Tsarpalis <eirik.tsarpalis@gmail.com>
* Update wording. Revert whitespace changes from before.

* Really fix whitespace diffs

Co-authored-by: Eirik Tsarpalis <eirik.tsarpalis@gmail.com>
2 years agoStore actual signature types in CallArg and normalize to that type (#69969)
Jakob Botsch Nielsen [Tue, 31 May 2022 08:51:40 +0000 (10:51 +0200)]
Store actual signature types in CallArg and normalize to that type (#69969)

Previously, for struct args, we would use the class handle of the
argument (from the IL stack) instead of the class handle from the
signature. These may sometimes differ in __Canon when inlining shared
code. This change switches the class handle stored in CallArg to always
be the type reported back by the EE when asking about the signature.

2 years agoAnnotate System.Runtime tests for NativeAOT (#69803)
Jackson Schuster [Tue, 31 May 2022 04:05:26 +0000 (23:05 -0500)]
Annotate System.Runtime tests for NativeAOT (#69803)

2 years ago[main] Update dependencies from dotnet/hotreload-utils (#69431)
dotnet-maestro[bot] [Tue, 31 May 2022 02:56:09 +0000 (21:56 -0500)]
[main] Update dependencies from dotnet/hotreload-utils (#69431)

* Update dependencies from https://github.com/dotnet/hotreload-utils build 20220516.1

Microsoft.DotNet.HotReload.Utils.Generator.BuildTool
 From Version 1.1.0-alpha.0.22259.2 -> To Version 1.1.0-alpha.0.22266.1

* Update dependencies from https://github.com/dotnet/hotreload-utils build 20220523.2

Microsoft.DotNet.HotReload.Utils.Generator.BuildTool
 From Version 1.1.0-alpha.0.22259.2 -> To Version 1.1.0-alpha.0.22273.2

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: Larry Ewing <lewing@microsoft.com>
Co-authored-by: Aleksey Kliger (λgeek) <alklig@microsoft.com>
2 years ago[NativeAot] Null ref return is wrapped in TargetInvocationException (#69838)
Lakshan Fernando [Tue, 31 May 2022 00:36:20 +0000 (17:36 -0700)]
[NativeAot] Null ref return is wrapped in TargetInvocationException (#69838)

When a null ref return method is invoked. Fixes #69755

2 years agoAdd static default interface methods smoke test (#69973)
Michal Strehovský [Mon, 30 May 2022 23:49:52 +0000 (08:49 +0900)]
Add static default interface methods smoke test (#69973)

We should have Roslyn that is recent enough to compile this now.

2 years ago[mono][interp] Fix invocation of finally clauses with tiering enabled (#69909)
Vlad Brezae [Mon, 30 May 2022 20:02:30 +0000 (23:02 +0300)]
[mono][interp] Fix invocation of finally clauses with tiering enabled (#69909)

When unwinding the stack during EH, we first populate a StackFrameInfo with various data, like native_offset and jinfo. Let's assume this data is for an untiered method. If this frame has multiple finally clauses that need to be invoked, a finally invocation could tier up the InterpFrame that it is executing. The future finally invocations would use the IPs from the previously resolved untiered method. This change makes the interpreter receive only the clause index (in interp_run_finally) so we correctly resolve the native offsets of the handler.

2 years agoJIT: defer some flow graph reordering until after loop recognition (#69878)
Andy Ayers [Mon, 30 May 2022 17:18:40 +0000 (10:18 -0700)]
JIT: defer some flow graph reordering until after loop recognition (#69878)

The JIT currently will aggressively reorder the flow graph before running its
loop recognition phases. When there is PGO data this sometimes perturbs the
block order so that loops are no longer recognized, and we miss out on some
loop optimizations.

This change defers most block reordering until after the JIT has gone through
the optimization phases. There is still a limited form of flow cleanup done
early on.

There is also a compensating change in loop recognition in one place where it was
relying on adjacent blocks being combined.

Fixes #67318.

2 years ago[LoongArch64] Fix the segment fault for `writeableOffset`. (#69975)
Qiao Pengcheng [Mon, 30 May 2022 17:05:42 +0000 (01:05 +0800)]
[LoongArch64] Fix the segment fault for `writeableOffset`. (#69975)

2 years ago[LoongArch64] Fix the segment fault within JIT_UpdateWriteBarrierState. (#69782)
Qiao Pengcheng [Mon, 30 May 2022 16:33:23 +0000 (00:33 +0800)]
[LoongArch64] Fix the segment fault within JIT_UpdateWriteBarrierState. (#69782)

* [LoongArch64] Fix the segment fault within JIT_UpdateWriteBarrierState.

* [LoongArch64] update with the upstream.

2 years agoJIT: Move constant vectors to op2 from op1 (#67502)
Egor Bogatov [Mon, 30 May 2022 16:00:41 +0000 (19:00 +0300)]
JIT: Move constant vectors to op2 from op1 (#67502)

2 years agoLocalized file check-in by OneLocBuild Task: Build definition ID 679: Build ID 179428...
dotnet bot [Mon, 30 May 2022 12:57:05 +0000 (05:57 -0700)]
Localized file check-in by OneLocBuild Task: Build definition ID 679: Build ID 1794285 (#69932)

2 years agoAdd issue cleanup documentation and update automation (#69857)
Eirik Tsarpalis [Mon, 30 May 2022 10:34:44 +0000 (11:34 +0100)]
Add issue cleanup documentation and update automation (#69857)

2 years ago[wasm] Process WebSocket connection errors on NodeJS (#69858)
Marek Fišera [Mon, 30 May 2022 10:25:35 +0000 (12:25 +0200)]
[wasm] Process WebSocket connection errors on NodeJS (#69858)

2 years agoUse the signature's struct handle for making outgoing arg copies (#69971)
SingleAccretion [Mon, 30 May 2022 09:47:47 +0000 (12:47 +0300)]
Use the signature's struct handle for making outgoing arg copies (#69971)

* Do not depend on class handle in "fgMorphArgs"

Use the signature's handle when making an outgoing arg copy.

* Add a test

2 years agoDelete dead rationalizer transform (#69958)
SingleAccretion [Mon, 30 May 2022 09:46:14 +0000 (12:46 +0300)]
Delete dead rationalizer transform (#69958)

Seems to have been a workaround for an issue long gone.

2 years agoFix setting of DacpHeapSegmentData::highAllocMark on DAC side. (#69670)
Peter Sollich [Mon, 30 May 2022 09:21:47 +0000 (11:21 +0200)]
Fix setting of DacpHeapSegmentData::highAllocMark on DAC side. (#69670)

Fix setting of DacpHeapSegmentData::highAllocMark on DAC side. Keep some logic for backward compat in dacprivate.h, the copy here and the one in the Diagnostics repo, so that a new SOS can work correctly with an older DAC.

The PR in the diagnostics repo is this: dotnet/diagnostics#3062.

2 years agoAdd the repro case for github issue #68443 (https://github.com/dotnet/runtime/issues...
Peter Sollich [Mon, 30 May 2022 09:20:24 +0000 (11:20 +0200)]
Add the repro case for github issue #68443 (https://github.com/dotnet/runtime/issues/68443) as a GC test case. (#69496)

Let's figure out later whether this test should be part of the GC stress test and/or be added to a CI config.

2 years agoChange dispenser policy for RuntimeAssembly to ReuseAlways (#69937)
Jan Kotas [Mon, 30 May 2022 03:57:24 +0000 (20:57 -0700)]
Change dispenser policy for RuntimeAssembly to ReuseAlways (#69937)

This matches the policy used by all other runtime flavors.

Fixes #69743

2 years agochanged frequently used redhawk mentions. (#69962)
Prasanta Chettri [Sun, 29 May 2022 17:15:01 +0000 (22:45 +0530)]
changed frequently used redhawk mentions. (#69962)

2 years agoConvert Valuetype.FastEqualsCheck and GetHashCodeOfPtr to managed (#69723)
Huo Yaoyuan [Sun, 29 May 2022 13:12:49 +0000 (21:12 +0800)]
Convert Valuetype.FastEqualsCheck and GetHashCodeOfPtr to managed (#69723)

* Convert GetHashCodeOfPtr to managed

* Convert FastEqualsCheck to managed

* Add FCall to get object size

* Reduce local variable creation

* Change FCall to pass MethodTable*

* Sort ecallist and move to MethodTableNative

2 years agoRename NativeMemory.ZeroMemory (#69948)
Jan Kotas [Sun, 29 May 2022 01:52:27 +0000 (18:52 -0700)]
Rename NativeMemory.ZeroMemory (#69948)

- Rename NativeMemory.ZeroMemory to NativeMemory.Clear. Contributes to #69606
- Delete internal Buffer.ZeroMemory and replace it with NativeMemory.Clear

2 years agoJIT: fix jit stress now that W^X is enabled (#69946)
Andy Ayers [Sun, 29 May 2022 00:39:01 +0000 (17:39 -0700)]
JIT: fix jit stress now that W^X is enabled (#69946)

One bit of code that only executes under stress was writing to the wrong
offset, causing the jit to crash.

2 years agoRemove unused MissingMemberException.FormatSignature (#69890)
Huo Yaoyuan [Sat, 28 May 2022 17:07:24 +0000 (01:07 +0800)]
Remove unused MissingMemberException.FormatSignature (#69890)

* Remove unused native code

* Remove FormatSignature

* Add comment and adjust message formatting

Co-authored-by: Jan Kotas <jkotas@microsoft.com>
2 years agoHandle mis-sized structs in ARM/64 `PUTARG_STK` codegen (#69905)
SingleAccretion [Sat, 28 May 2022 15:48:41 +0000 (18:48 +0300)]
Handle mis-sized structs in ARM/64 `PUTARG_STK` codegen (#69905)

* Handle mis-sized structs for PUTARG_STK on ARM/64

We will now generate a series of small loads as necessary
to handle "remainderSize"s of 3, 5, 6 and 7.

* Add tests

* Re-enable tests for 60705

2 years agoJIT: allow pinvoke calli helper in TreatAsShouldHaveRetBufArg (#69927)
Andy Ayers [Sat, 28 May 2022 15:16:19 +0000 (08:16 -0700)]
JIT: allow pinvoke calli helper in TreatAsShouldHaveRetBufArg (#69927)

If we have multiple cold pinvokes in return positions that return
structs by value and we are merging returns, we will end up querying
these calls post-morph, and may see them using CORINFO_HELP_PINVOKE_CALLI.

Fixes #69612.

2 years agoRelax the address exposure condition in forward substitution (#69818)
SingleAccretion [Sat, 28 May 2022 15:04:49 +0000 (18:04 +0300)]
Relax the address exposure condition in forward substitution (#69818)

* Relax the AX condition in forward substitution

* Work around an issue with multi-regs in fwd sub

We only support calls or locals as sources of multi-reg returns.

2 years agoRefactoring the generic-math CreateChecked/Saturating/Truncating APIs to match API...
Tanner Gooding [Sat, 28 May 2022 06:51:39 +0000 (23:51 -0700)]
Refactoring the generic-math CreateChecked/Saturating/Truncating APIs to match API review (#69756)

* Update MicrosoftNetCompilersToolsetVersion to 4.3.0-2.22270.4

* Moving System.Runtime.InteropServices.NFloat down to System.Runtime

* Removing the generic-math CreateChecked, CreateSaturating, CreateTruncating, and TryCreate implementations

* Removing the generic-math TryCreate tests

* Adding the TryConvertTo* and TryConvertFrom* generic math APIs for Checked, Saturating, and Truncating

* Filling out test coverage for the CreateChecked generic-math API

* Fix some edge cases for the CreateSaturating generic-math APIs

* Filling out test coverage for the CreateSaturating generic-math API

* Fix some edge cases for the CreateTruncating generic-math APIs

* Filling out test coverage for the CreateTruncating generic-math API

* Fixing some edge cases in converting BigInteger/Complex to the primitive types

* Filling out test coverage for converting BigInteger and Complex to the primitive types

* Fixing some 32-bit generic-math tests

* Removing the static virtual declarations since things are falling over

* Skipping some tests on Mono where it has bad behavior

* Revert "Removing the static virtual declarations since things are falling over"

This reverts commit baf69de8576f8528125e6ddee518d3dd310e9e9b.

* Move NFloat back to System.Runtime.InteropServices based on feedback

* Fixing the Int128/UInt128 to Decimal tests

* Ensure `JIT_Dbl2ULng` correctly handles NaN

* Revert "Ensure `JIT_Dbl2ULng` correctly handles NaN"

This reverts commit 329834538e262318f5cf599d9e98a748b9f6a8b9.

* Explicitly ensure floating-point to ulong conversion returns 0 for NaN

2 years ago[wasm] Explicitly include mscorlib.dll, to support scanning assemblies (#69886)
Ankit Jain [Sat, 28 May 2022 06:02:07 +0000 (02:02 -0400)]
[wasm] Explicitly include mscorlib.dll, to support scanning assemblies (#69886)

* [wasm] Explicitly include mscorlib.dll, to support scanning assemblies

.. with mscorlib dependency.

This showed up when scanning `Dia2Lib` for icalls, which is indirectly
used by the microbenchmarks in `dotnet/performance`. It would fail with:

```
System.IO.FileNotFoundException: Could not find assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Either explicitly load this assembly using a method such as LoadFromAssemblyPath() or use a MetadataAssemblyResolver that returns a valid assembly.
   at System.Reflection.TypeLoading.Ecma.EcmaResolver.ResolveAssembly(AssemblyReferenceHandle handle, EcmaModule module)
   at System.Reflection.TypeLoading.Ecma.EcmaResolver.ComputeTypeRefResolution(TypeReferenceHandle handle, EcmaModule module)
   at System.Reflection.TypeLoading.Ecma.EcmaResolver.ResolveTypeRef(TypeReferenceHandle handle, EcmaModule module)
   at System.Reflection.TypeLoading.Ecma.EcmaModule.GetTypeFromReference(MetadataReader reader, TypeReferenceHandle handle, Byte rawTypeKind)
   at System.Reflection.Metadata.Ecma335.SignatureDecoder`2.DecodeTypeHandle(BlobReader& blobReader, Byte rawTypeKind, Boolean allowTypeSpecifications)
   at System.Reflection.Metadata.Ecma335.SignatureDecoder`2.DecodeType(BlobReader& blobReader, Boolean allowTypeSpecifications, Int32 typeCode)
   at System.Reflection.Metadata.Ecma335.SignatureDecoder`2.DecodeType(BlobReader& blobReader, Boolean allowTypeSpecifications, Int32 typeCode)
   at System.Reflection.Metadata.Ecma335.SignatureDecoder`2.DecodeMethodSignature(BlobReader& blobReader)
   at System.Reflection.TypeLoading.Ecma.EcmaMethodDecoder.SpecializeMethodSig(IRoMethodBase roMethodBase)
   at System.Reflection.TypeLoading.RoDefinitionMethod`1.ComputeMethodSig()
   at System.Reflection.TypeLoading.RoMethod.get_ReturnType()
   at SignatureMapper.MethodToSignature(MethodInfo method)
   at IcallTableGenerator.<ProcessType>g__AddSignature|15_1(Type type, MethodInfo method)
   at IcallTableGenerator.ProcessType(Type type)
   at IcallTableGenerator.GenIcallTable(String runtimeIcallTableFile, String[] assemblies, String outputPath)
   at ManagedToNativeGenerator.ExecuteInternal()
   at ManagedToNativeGenerator.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)
```

This is thrown when `SignatureMapper.MethodToSignature` called
`method.ReturnType` for:

```
  .method public hidebysig newslot virtual
  instance void  loadAndValidateDataFromPdb([in] string  marshal( lpwstr) pdbPath,
                                            [in] [mscorlib]System.Guid& pcsig70,
                                            [in] uint32 sig,
                                            [in] uint32 age) runtime managed internalcall
  {
    .override Dia2Lib.IDiaDataSource::loadAndValidateDataFromPdb
  } // end of method DiaSourceClass::loadAndValidateDataFromPdb
```

We use `PathAssemblyResolver` with a closed set of assemblies, which
didn't include mscorlib.dll . So, we include that explicitly from the
runtime pack.

Fixes https://github.com/dotnet/runtime/issues/69861

* Add mscorlib.dll, only if it wasn't already there.

`System.Reflection.MetadataLoadContext.Tests` tests failed:

```
The "ManagedToNativeGenerator" task failed unexpectedly. [/datadisks/disk1/work/9ABB086E/w/BDA50A35/e/publish/ProxyProjectForAOTOnHelix.proj]
System.IO.FileLoadException: The assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' has already loaded been loaded into this MetadataLoadContext. [/datadisks/disk1/work/9ABB086E/w/BDA50A35/e/publish/ProxyProjectForAOTOnHelix.proj]
   at System.Reflection.MetadataLoadContext.LoadFromStreamCore(Stream peStream) [/datadisks/disk1/work/9ABB086E/w/BDA50A35/e/publish/ProxyProjectForAOTOnHelix.proj]
   at System.Reflection.MetadataLoadContext.LoadFromAssemblyPath(String assemblyPath) [/datadisks/disk1/work/9ABB086E/w/BDA50A35/e/publish/ProxyProjectForAOTOnHelix.proj]
   at PInvokeTableGenerator.GenPInvokeTable(String[] pinvokeModules, String[] assemblies, String outputPath) in /_/src/tasks/WasmAppBuilder/PInvokeTableGenerator.cs:line 37 [/datadisks/disk1/work/9ABB086E/w/BDA50A35/e/publish/ProxyProjectForAOTOnHelix.proj]
   at ManagedToNativeGenerator.ExecuteInternal() in /_/src/tasks/WasmAppBuilder/ManagedToNativeGenerator.cs:line 71 [/datadisks/disk1/work/9ABB086E/w/BDA50A35/e/publish/ProxyProjectForAOTOnHelix.proj]
   at ManagedToNativeGenerator.Execute() in /_/src/tasks/WasmAppBuilder/ManagedToNativeGenerator.cs:line 56 [/datadisks/disk1/work/9ABB086E/w/BDA50A35/e/publish/ProxyProjectForAOTOnHelix.proj]
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [/datadisks/disk1/work/9ABB086E/w/BDA50A35/e/publish/ProxyProjectForAOTOnHelix.proj]
   at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)
```

2 years agoImplement LoadLibraryErrorTracker (#69842)
Michal Strehovský [Sat, 28 May 2022 05:31:50 +0000 (14:31 +0900)]
Implement LoadLibraryErrorTracker (#69842)

Finishes the LoadLibraryErrorTracker port from CoreCLR VM to C#.

This allows us to report more details about the reason of `DllImport` resolution failures at runtime.

The logic matches CoreCLR. There might be a slight behavior difference for empty string literal `DllImport`/`NativeLibrary.Load`. Not sure we care enough (I couldn't discern what the CoreCLR behavior is - I think we report an arbitrary old message from the last load attempt since we never even try to `dlopen` the empty string).

Instead of:

```
System.DllNotFoundException: Unable to load native library 'bruh' or one of its dependencies.
```

We can now do:

```
System.DllNotFoundException: Unable to load DLL 'bruh' or one of its dependencies: The process cannot access the file because it is being used by another process.
```

2 years ago[mono][wasm] Pin thrown exceptions during EH. (#69916)
Zoltan Varga [Sat, 28 May 2022 03:50:14 +0000 (23:50 -0400)]
[mono][wasm] Pin thrown exceptions during EH. (#69916)

Fixes https://github.com/dotnet/runtime/issues/63749.