platform/upstream/dotnet/runtime.git
4 years agoLLVM: Make Buffer.Memmove intrinsic (mono/mono#16610)
Egor Bogatov [Sat, 31 Aug 2019 23:42:44 +0000 (02:42 +0300)]
LLVM: Make Buffer.Memmove intrinsic (mono/mono#16610)

* Add memmove intrinsic

* Fix typo

* Add -lower-expect

Commit migrated from https://github.com/mono/mono/commit/6327274b54cca5ad11207c79f5a611ca1623c60f

4 years ago[aot] Avoid crashing with --aot=llvm is used in a runtime without llvm support. ...
Zoltan Varga [Sat, 31 Aug 2019 13:03:45 +0000 (09:03 -0400)]
[aot] Avoid crashing with --aot=llvm is used in a runtime without llvm support. (mono/mono#16577)

Commit migrated from https://github.com/mono/mono/commit/fb26a68fd1752783cbc8827ac78d2b3bbf260d62

4 years ago[coop] Allow SETUP_ICALL_FRAME (i.e. a loop) to reference calling frame w/o HANDLE_FU...
Jay Krell [Sat, 31 Aug 2019 12:20:44 +0000 (05:20 -0700)]
[coop] Allow SETUP_ICALL_FRAME (i.e. a loop) to reference calling frame w/o HANDLE_FUNCTION_ENTER or SETUP_ICALL_FUNCTION. (mono/mono#16498)

This is based on my read of https://github.com/mono/mono/pull/16487.

Commit migrated from https://github.com/mono/mono/commit/9b193b9ec4594c68b85a20bb7ae2bfcd6be7796b

4 years ago[interp] Fixes for il_offsets associated with instructions (mono/mono#16587)
Vlad Brezae [Sat, 31 Aug 2019 10:37:06 +0000 (13:37 +0300)]
[interp] Fixes for il_offsets associated with instructions (mono/mono#16587)

* [interp] Remove some some false is_bb_start markings

Having fewer basic blocks makes potential optimizations more effective.

* [interp] Persist variables in TransformData

Thate are not used by inlined code because we don't inline code that has multiple basic blocks or clauses.

* [interp] Enable emitting of MINT_NOP instruction

This instruction will be optimized away when compacting the instruction stream.

* [interp] Clear instructions insead of removing them

Makes everything easier.

* [interp] Fix some instructions size inconsistencies

* [interp] Add more is_bb_start markings

* [interp] Add nop instead of extending bb

We should always have an IR instruction associated with an IL offset, especially when that instruction is a bb_start since we will need to branch to it and resolve the IR instruction from the il_offset.

* [interp] Simplify resolving in offset

We should always have an in_offset associated with the il_offset we are branching to.

* [interp] Add correct il_offset for all instructions

Except for special prolog instructions that will have -1 as the offset. We don't make much use of il_offset for non bb_start instructions, but they might be useful for debugging.

* [interp] Fix il_offset of some conv opcodes

Commit migrated from https://github.com/mono/mono/commit/bf53a3a53bd0aef81e0e2eed24ab835ebb1630fa

4 years agoFollow convention -- "static inline" is only for .h files, "static" is for .c. (mono...
Jay Krell [Sat, 31 Aug 2019 07:40:33 +0000 (00:40 -0700)]
Follow convention -- "static inline" is only for .h files, "static" is for .c. (mono/mono#15502)

inlining is up to the compiler to decide.
It is used in .h files for linkage/dedup, not to affect codegen.

Commit migrated from https://github.com/mono/mono/commit/a768b1533051aa37fc34af438e9af5bab48d515d

4 years ago[coop] InternalGetHashCode (mono/mono#16583)
Jay Krell [Sat, 31 Aug 2019 07:38:12 +0000 (00:38 -0700)]
[coop] InternalGetHashCode (mono/mono#16583)

Commit migrated from https://github.com/mono/mono/commit/cba94f28bed566e7a976842d016a7b2d4ef3f91a

4 years ago[runtime] Make eglib tests run on CI (mono/mono#16187)
Aleksey Kliger (λgeek) [Sat, 31 Aug 2019 06:06:25 +0000 (02:06 -0400)]
[runtime] Make eglib tests run on CI (mono/mono#16187)

[runtime] Make eglib tests run on CI

Update mono/eglib SUBDIRS to build tests after eglib is built.

Add a check-local automake rule.

Add CI steps to run the eglib tests.

Commit migrated from https://github.com/mono/mono/commit/8bc27f6665fdd8464f3fdad15a974e5f38f9b7f2

4 years agoCleanup x86_patch and amd64_patch. (mono/mono#16474)
Jay Krell [Fri, 30 Aug 2019 21:45:55 +0000 (14:45 -0700)]
Cleanup x86_patch and amd64_patch. (mono/mono#16474)

* Cleanup x86_patch and amd64_patch.

amd64_patch has two incorrect looking probably unused cases.
 g_assert(0) and fix them.
 call and jmp indirect (one case)
 move reg RIP relative

x86_patch is large-ish inline macro.
Presumably for sharing with amd64, not inlining.
Restructure as an inline function, called once.
Try to make the code a little clearer also, with same functionality and efficiency
 (modulo the optimized perf of "if i == 4" vs. "if i")
i.e. speak of instruction_size and offset_size, not pos and boolean size.

Add to x86_patch the ability to patch jmp/call indirect,
as amd64_patch has, but which was incorrect.
This would seem useful for a later change (using "thunks"
to patch nearby data instead of patching aligned instructions,
indirect call/jmp vs. direct).

amd64_patch largely delegates to x86_patch.
One case asserts and delegates.
Move the assert to the x86 side, where an optimizing
compiler should know to remove it for x86 anyway.

Change some assert to g_assert.

Remove some unnecessary casts.

Fix an assert (https://github.com/mono/mono/pull/16471).

* Change g_assert back to assert except where making larger changes
and less expansion.

Commit migrated from https://github.com/mono/mono/commit/f735571f27738e3354f6d92650a0517d0482039d

4 years ago[mini] publish global patches after JitInfo has been added (mono/mono#16589)
Bernhard Urban [Fri, 30 Aug 2019 20:46:10 +0000 (22:46 +0200)]
[mini] publish global patches after JitInfo has been added (mono/mono#16589)

[mini] publish global patches after JitInfo has been added

Fixes https://github.com/mono/mono/issues/14080

Consider the following example:

```csharp
static void CommonCallTarget () { }

static void TailA () {
    tailcall CommonCallTarget ();
}

static void TailB () {
    tailcall CommonCallTarget ();
}
```

Since `TailA` and `TailB` are tailcalling into `CommonCallTarget`, the resolution at patch-time is a bit tricky, that is, since it's a jump-like instruction the patching machinery won't know where it was called from. That's why we maintain a global hashtable `jump_target_hash` where each jump-site is signed up to be patched. At patch-time we know the target method (in the example `CommonCallTarget`), but since we don't know where we are coming from, we will just apply all patches for that target.

This works since ages, so why did it crash on arm64 sometimes?
When the patching happens, we check if the displacement between jump-site and target fits into it (24bit). If not, which happens not very often, we have to allocate a _thunk_:
https://github.com/mono/mono/blob/mono/mono@36296ce291f8a7b19de3eccb7a32c7e4ed9df8f2/mono/mini/mini-arm64.c#L928-L942

So instead of jumping to the target directly, we'll branch to the thunk. This is a little trampoline that loads the full address of the target and then finally branches to it. This one will live close-by the jump-site, because during compilation we will reserve specifically for that scenario some space after the generated code. For this, however, we need the JitInfo of the jump-site. And that's where the origin of the race is. Let's say:

* Thread A compiles `TailA`, and then jumps into it. Thus one patch point is in the `jump_target_hash`.
* Now Thread B compiles `TailB`, registers the patch point but has _not_ yet registered its JitInfo.
* Then Thread A continues, does the tailcall into `CommonCallTarget`, enters the patching machinery, which sees two patches. Now assume when applying the patch for `TailB` the displacement is too large, thus it tries to allocate a thunk but can't find the relevant JitInfo for it that it needs to emit the thunk. So it crashes as reported in https://github.com/mono/mono/issues/14080

As far as I can tell this only affects ARM64, ARM and PPC.

<!--
Thank you for your Pull Request!

If you are new to contributing to Mono, please try to do your best at conforming to our coding guidelines http://www.mono-project.com/community/contributing/coding-guidelines/ but don't worry if you get something wrong. One of the project members will help you to get things landed.

Does your pull request fix any of the existing issues? Please use the following format: Fixes #issue-number
-->

Commit migrated from https://github.com/mono/mono/commit/06e63b345f0be60008597784d1cc8b3251bf60fa

4 years agoTurned the compiler server off on Windows because Named Pipes aren't fully working...
Steve Pfister [Fri, 30 Aug 2019 20:27:14 +0000 (16:27 -0400)]
Turned the compiler server off on Windows because Named Pipes aren't fully working (mono/mono#16552)

* Turned the compiler server off on Windows because Named Pipes aren't fully working

* Added win32 to the CS is turned off message

Commit migrated from https://github.com/mono/mono/commit/dbce6ac447dcb9443f50da9fe50caed50adc1d06

4 years agoRevert "[android] add hardware specific workaround for Nexus9 in armv7 mode" (mono...
Bernhard Urban [Fri, 30 Aug 2019 20:26:12 +0000 (22:26 +0200)]
Revert "[android] add hardware specific workaround for Nexus9 in armv7 mode" (mono/mono#14691)

Revert "[android] add hardware specific workaround for Nexus9 in armv7 mode"

This reverts commit mono/mono@ee90fc601e762dc31eeb90fc61b6305246ad5275 (also see https://github.com/mono/mono/pull/4878 ).

The device was released November 2014.  I think it's fair to assume it isn't widely used anymore.

Commit migrated from https://github.com/mono/mono/commit/5eb67ac88a2b26f28091d4f4876720ba3dbd8674

4 years ago[netcore] Fix make patch-local-dotnet if .dotnet has more than one netcore install...
Zoltan Varga [Fri, 30 Aug 2019 18:08:41 +0000 (14:08 -0400)]
[netcore] Fix make patch-local-dotnet if .dotnet has more than one netcore install. (mono/mono#16590)

Commit migrated from https://github.com/mono/mono/commit/4997d832916d092ee5a69bd28d0ee354a49c6e35

4 years ago[coop] mono_runtime_class_init_full (mono/mono#16580)
Jay Krell [Fri, 30 Aug 2019 17:30:58 +0000 (10:30 -0700)]
[coop] mono_runtime_class_init_full (mono/mono#16580)

Commit migrated from https://github.com/mono/mono/commit/86c45ff645e59c997341ac44e95d03d4491c50eb

4 years ago[cominterop] Respect ComDefaultInterfaceAttribute when constructing ccw. (mono/mono...
Nikolay Sivov [Fri, 30 Aug 2019 16:29:54 +0000 (19:29 +0300)]
[cominterop] Respect ComDefaultInterfaceAttribute when constructing ccw. (mono/mono#16584)

Commit migrated from https://github.com/mono/mono/commit/c8707c6e84ed5978fb21be3c2dd4fe678b904c9c

4 years ago[Coop] ves_icall_RuntimeFieldInfo_GetRawConstantValue. (mono/mono#16582)
Jay Krell [Fri, 30 Aug 2019 14:53:40 +0000 (07:53 -0700)]
[Coop] ves_icall_RuntimeFieldInfo_GetRawConstantValue. (mono/mono#16582)

Commit migrated from https://github.com/mono/mono/commit/9db00e74950a5b9572dbcfb3c6403503ae5b236d

4 years ago[configure] remove autodection of llvm-config in $PATH (mono/mono#16569)
Bernhard Urban [Fri, 30 Aug 2019 13:16:03 +0000 (15:16 +0200)]
[configure] remove autodection of llvm-config in $PATH (mono/mono#16569)

[configure] remove autodection of llvm-config in $PATH

Instead `./autogen.sh --with-llvm=<path>` should be used if a build from `external/llvm` is not preferred.

The old behavior was confusing when a `llvm-config` is on `$PATH`, which can be the case when you have LLVM packages installed on a Linux distribution. It picked that up when `./autogen.sh --enable-llvm` was used.

/cc @brianrob

Commit migrated from https://github.com/mono/mono/commit/07045604cf8e436359d04f18eff05ae00668e752

4 years ago[interp] Compress interpreter opcode names in usual way, offsets vs. pointers. (mono...
Jay Krell [Fri, 30 Aug 2019 08:27:19 +0000 (01:27 -0700)]
[interp] Compress interpreter opcode names in usual way, offsets vs. pointers. (mono/mono#16350)

* [interp] Compress the interpreter opcode names in the usual way, by changing
from an array of pointers to an array of 16 bit offsets into one large "string".

* PR: Make mono_interp_opname a function.

Commit migrated from https://github.com/mono/mono/commit/36296ce291f8a7b19de3eccb7a32c7e4ed9df8f2

4 years ago[coop] Convert System_Runtime_Remoting_Messaging_AsyncResult, etc. (mono/mono#16566)
Jay Krell [Fri, 30 Aug 2019 03:51:15 +0000 (20:51 -0700)]
[coop] Convert System_Runtime_Remoting_Messaging_AsyncResult, etc. (mono/mono#16566)

* [coop] Convert System_Runtime_Remoting_Messaging_AsyncResult_Invoke, etc.

* Remove mono_load_remote_field_checked from this PR.

* Pin ac->msg earlier (should not matter).

* Add missing barrier.

* Pin slightly earlier -- still should not matter.

Commit migrated from https://github.com/mono/mono/commit/3db78e829c0909bf9ca459e3a3e1033365386569

4 years ago[Coop] mono_runtime_class_init_full mostly single point of exit.
Jay Krell [Wed, 28 Aug 2019 00:20:02 +0000 (17:20 -0700)]
[Coop] mono_runtime_class_init_full mostly single point of exit.

Commit migrated from https://github.com/mono/mono/commit/cbb9c645eb4d4d0f03da3dab3c99a4bcc9919fbe

4 years agoBump ikvm to pick up mono/mono@caa8e7f54279a47422626005d228447f5d3670d5. (mono/mono...
Zoltan Varga [Fri, 30 Aug 2019 00:46:30 +0000 (20:46 -0400)]
Bump ikvm to pick up mono/mono@caa8e7f54279a47422626005d228447f5d3670d5. (mono/mono#16567)

* Bump ikvm to pick up mono/mono@caa8e7f54279a47422626005d228447f5d3670d5.

* [monodis] Add a missing cattr parent case.

Commit migrated from https://github.com/mono/mono/commit/796a5751315dbf95bc7dedea684840e4cce84861

4 years agoMake Math.Pow, Min and Max for doubles intrinsics (mono/mono#16561)
Egor Bogatov [Thu, 29 Aug 2019 23:01:15 +0000 (02:01 +0300)]
Make Math.Pow, Min and Max for doubles intrinsics (mono/mono#16561)

* Add new Math intrinsics

* call EB.setTargetOptions only for fast-math

* Address feedback

* rename float opcodes

* Rename opcodes

* Update CoreFX.issues.rsp

Commit migrated from https://github.com/mono/mono/commit/c3ccb6e0272a6b000a8adfb81c02c240adffc649

4 years ago[simd] Implement .ctor(T[]) and CopyTo () as intrinsics. (mono/mono#16558)
Zoltan Varga [Thu, 29 Aug 2019 23:00:59 +0000 (19:00 -0400)]
[simd] Implement .ctor(T[]) and CopyTo () as intrinsics. (mono/mono#16558)

Commit migrated from https://github.com/mono/mono/commit/210b3243471a61024d54b16d4092e90134ff098e

4 years agoCleanup trampoline size checks. (mono/mono#15624)
Jay Krell [Thu, 29 Aug 2019 20:16:14 +0000 (13:16 -0700)]
Cleanup trampoline size checks. (mono/mono#15624)

Cleanup trampoline size checks.

- named `int` everywhere
- `assert` everywhere
- assert `<=` everywhere instead of `<`
- `const` almost everywhere
Names not consistent, following existing code (`size`, `buf_len`, `kMaxCode`.)

Only touching x86/amd64, granted.

Could be better -- make them two pass and avoid the presizing.

Commit migrated from https://github.com/mono/mono/commit/5390b796dd9c16eaded61c406a4cea9c66ea8905

4 years ago[netcore] Implement AssemblyLoadContext.LoadUnmanagedDllFromPath (mono/mono#16525)
Ryan Lucia [Thu, 29 Aug 2019 16:35:15 +0000 (12:35 -0400)]
[netcore] Implement AssemblyLoadContext.LoadUnmanagedDllFromPath (mono/mono#16525)

* [netcore] Implement AssemblyLoadContext.LoadUnmanagedDllFromPath

* Fixes

Commit migrated from https://github.com/mono/mono/commit/3b57849541b35a8f6cced2957b9a6fdc0680136f

4 years ago[cominterop] Implement native-to-managed safearray marshalling. (mono/mono#16483)
Nikolay Sivov [Thu, 29 Aug 2019 12:19:09 +0000 (15:19 +0300)]
[cominterop] Implement native-to-managed safearray marshalling. (mono/mono#16483)

* [cominterop] Implement native-to-managed safearray marshalling.

* [tests] Fix index variable type.

In attempt ot fix MSVC build failure (int* vs LONG* on Windows).

* [cominterop] Use proper statement block for newly added switch entry.

* [marshal] Conditionally compile in mono_cominterop_emit_marshal_safearray().

Hopefully should fix remaining build failures.

* [cominterop] Don't free user array argument

Commit migrated from https://github.com/mono/mono/commit/421bd79f06a92372e0259be5349e4236edf0e7bb

4 years ago[Coop] mono_load_remote_field_checked single point of exit. (mono/mono#16526)
Jay Krell [Thu, 29 Aug 2019 09:00:44 +0000 (02:00 -0700)]
[Coop] mono_load_remote_field_checked single point of exit. (mono/mono#16526)

Extracted from earlier version of mono/mono#16504.
Baby steps.

Commit migrated from https://github.com/mono/mono/commit/52c1d4acfc751dd83f1964648cd91288988d7eec

4 years agoLLVM: Add more Math intrinsics, introduce `--cpu` flag (mono/mono#16309)
Egor Bogatov [Thu, 29 Aug 2019 08:32:43 +0000 (11:32 +0300)]
LLVM: Add more Math intrinsics, introduce `--cpu` flag (mono/mono#16309)

* Add Math Intrinsics, introduce --cpu flag

* cpu -> mcpu

Commit migrated from https://github.com/mono/mono/commit/2e9c5df855566402a314864580ec7dd908be2112

4 years ago[coop] Cleanup mono_reflection_get_custom_attrs_blob_checked. (mono/mono#16535)
Jay Krell [Thu, 29 Aug 2019 08:23:20 +0000 (01:23 -0700)]
[coop] Cleanup mono_reflection_get_custom_attrs_blob_checked. (mono/mono#16535)

- single point of exit
 - local variable cheaper than strcmp

Commit migrated from https://github.com/mono/mono/commit/2f2d9541e593ed6976b32bde80a5f47b25ff9148

4 years ago[netcore] Add Monitor.LockContentionCount icall (mono/mono#16538)
Filip Navara [Thu, 29 Aug 2019 00:35:07 +0000 (02:35 +0200)]
[netcore] Add Monitor.LockContentionCount icall (mono/mono#16538)

* Add Monitor.LockContentionCount icall

* Add NOHANDLES around the new icall

Commit migrated from https://github.com/mono/mono/commit/e32fb11dbea1743b495241dc648065fa1938aa54

4 years agoRead only function pointers (MonoThreadInfoRuntimeCallbacks). (mono/mono#16545)
Jay Krell [Wed, 28 Aug 2019 22:10:40 +0000 (15:10 -0700)]
Read only function pointers (MonoThreadInfoRuntimeCallbacks). (mono/mono#16545)

Read only memory is preferred, for efficiency and security.

Even if it requires relocation first.

If the runtime is loaded in more than one process, physical pages can be shared (at least on Windows, where the kernel does the relocation).

If there is memory corruption, writes to here will sigsegv/accessviolate.

The older code also copied the pointers. For lifetime purposes that could be useful, but generally is not. i.e. they live with the code they point to.

Writable function pointers are also particularly targets for attackers.
There's been tons of defenses put around them through the years.
Read only ones are not vulnerable -- unless the attacker escalates and calls mprotect first.

When there is a JIT, arguably there is just tons of attack surface.
But there is also AOT.

Structs of function pointers are usually read only in the wider world.

Commit migrated from https://github.com/mono/mono/commit/7ca965e09c35b1f9a2a7a56f68f0be997f841754

4 years agoMerge pull request mono/mono#16323 from EgorBo/ffast-math
Zoltan Varga [Wed, 28 Aug 2019 20:16:18 +0000 (16:16 -0400)]
Merge pull request mono/mono#16323 from EgorBo/ffast-math

Fast Math mode

Commit migrated from https://github.com/mono/mono/commit/c4695b8b4440e0f80c4768379fa24ba78ebff9d2

4 years ago[interp] Fix remaining MonoError reuse. (mono/mono#16533)
Jay Krell [Wed, 28 Aug 2019 19:33:48 +0000 (12:33 -0700)]
[interp] Fix remaining MonoError reuse. (mono/mono#16533)

* [interp] Fix remaining MonoError reuse.

This finishes off:
 https://github.com/mono/mono/commit/mono/mono@38aebeae38704df53ef8f2991ff63e293a3ac4de

which is *ok*, but leaves alone the other approach:
 https://github.com/mono/mono/commit/mono/mono@4d9e6ae20e536394c9ff65c61238045db294c08e
 https://github.com/mono/mono/commit/mono/mono@b654aa1ca858666539a677e96d00f594fd81c630
 https://github.com/mono/mono/commit/mono/mono@fd4956fbf277ec56a13137e01b48efb98a5556f5

Several other options are possible.

* self and peer PR: No need to cleanup successful error.

Commit migrated from https://github.com/mono/mono/commit/056d5ca545d8534fa4b9c8b9268913775607e25a

4 years agoPortably pass a full pointer and not just an integer to terminate vararg pointer...
Jay Krell [Wed, 28 Aug 2019 17:35:10 +0000 (10:35 -0700)]
Portably pass a full pointer and not just an integer to terminate vararg pointer lists. (mono/mono#15629)

i.e. because of define NULL 0.
Though I think at least Visual C++ special cases this and passes a full pointer to varargs.

Commit migrated from https://github.com/mono/mono/commit/ff73c84482f99036f04c883316246d43d17f44d4

4 years ago[interp] Possible code size savings via goto instead of macros. (mono/mono#16531)
Jay Krell [Wed, 28 Aug 2019 16:59:11 +0000 (09:59 -0700)]
[interp] Possible code size savings via goto instead of macros. (mono/mono#16531)

[interp] Possible code size savings via goto instead of macros.

Possibly the compilers do this already.

Commit migrated from https://github.com/mono/mono/commit/a0ba2cbce52dd312fb34a39d366dde5b4a878fe3

4 years agoMerge remote-tracking branch 'origin/master' into ffast-math
Egor Bogatov [Wed, 28 Aug 2019 16:01:34 +0000 (19:01 +0300)]
Merge remote-tracking branch 'origin/master' into ffast-math

Commit migrated from https://github.com/mono/mono/commit/ffc3081c3b9576c922286c79f51fe3fb3cd49f50

4 years agoMerge pull request mono/mono#16242 from lateralusX/lateralusX/windows-fix-local-value...
imhameed [Wed, 28 Aug 2019 15:23:43 +0000 (08:23 -0700)]
Merge pull request mono/mono#16242 from lateralusX/lateralusX/windows-fix-local-valuetype-copy-llvm

OP_LLVM_OUTARG_VT doesn't always create temporary vt needed by some ABI's.

Commit migrated from https://github.com/mono/mono/commit/bd3cc61301cc12d167b284316e9d99af92f2130b

4 years ago[mini] do not re-AOT whole BCL for fullaotcheck targets (mono/mono#16536)
Bernhard Urban [Wed, 28 Aug 2019 15:19:39 +0000 (17:19 +0200)]
[mini] do not re-AOT whole BCL for fullaotcheck targets (mono/mono#16536)

[mini] do not re-AOT whole BCL for fullaotcheck targets

And enable `llvmfullaotcheck` target on CI.

Fixes https://github.com/mono/mono/issues/15999

On my armv7/linux machine with a `--with-runtime-preset=fullaot_llvm` configured build, before this PR:
```console
$ time make -C mono/mini llvmfullaotcheck -j4
[...]
real    9m42.362s
user    23m2.000s
sys     0m18.480s
```
After:
```console
$ time make -C mono/mini llvmfullaotcheck -j4
[...]
real    3m1.984s
user    4m51.648s
sys     0m8.248s
```

Commit migrated from https://github.com/mono/mono/commit/71f0f0ff827b03252e8967aeb6152a14cc3198ec

4 years ago[netcore] Add missing 'prepare' dependency to run-tests-corefx
Alexander Köplinger [Wed, 28 Aug 2019 14:17:31 +0000 (16:17 +0200)]
[netcore] Add missing 'prepare' dependency to run-tests-corefx

Commit migrated from https://github.com/mono/mono/commit/2152f0a16d68021fa28a997806992ad59fd0c7e7

4 years agoMerge pull request mono/mono#16517 from vargaz/wasm-xunit4
Zoltan Varga [Wed, 28 Aug 2019 13:46:09 +0000 (09:46 -0400)]
Merge pull request mono/mono#16517 from vargaz/wasm-xunit4

[wasm] Enable xunit tests for corlib/System.Core.

Commit migrated from https://github.com/mono/mono/commit/f562c7ef6a23e9f713a53b446e937eedc63728b6

4 years agoFix assert in x86_patch regarding second byte of Jcc instructions being 0x80-0x8F...
Jay Krell [Wed, 28 Aug 2019 13:42:44 +0000 (06:42 -0700)]
Fix assert in x86_patch regarding second byte of Jcc instructions being 0x80-0x8F vs. 0x70-0x8F (6byte conditional branch with 32bit offset). (mono/mono#16471)

Commit migrated from https://github.com/mono/mono/commit/c80a1eca636c82014f8fbb9873e5391cddffa9a9

4 years ago[merp] Initialize hang_watchdog_path earlier; be lax if it's missing (mono/mono#16298)
Aleksey Kliger (λgeek) [Wed, 28 Aug 2019 12:34:30 +0000 (08:34 -0400)]
[merp] Initialize hang_watchdog_path earlier; be lax if it's missing (mono/mono#16298)

* [merp] Initialize hang_watchdog_path earlier; be lax if it's missing

Initialize hang_watchdog_path earlier - not just when
ves_icall_Mono_Runtime_EnableCrashReportingLog is called.  That function is
only expected to be called by apps that explicitly want progress reports from
MERP when it's collecting a crash report.  But we want the mono-hang-watchdog
to execute for all mono crashes (when crash reporting isn't ifdef'd out).

Also if we try to exec mono-hang-watchdog and fail for some reason, print a
nice message and then exit.  We used to call g_assert_not_reached which would
kick off another MERP of the _forked child process_ which would then get
confused because it really can't run in the forked process at all.

Commit migrated from https://github.com/mono/mono/commit/fc21168065af270d1e500fa6be618f8563d0c525

4 years ago[interp] Outline box. (mono/mono#16456)
Jay Krell [Wed, 28 Aug 2019 10:51:23 +0000 (03:51 -0700)]
[interp] Outline box. (mono/mono#16456)

With additional reasonable changes this should conserve stack.
A combined PR that demonstrates actual savings probably should/will be presented.

Commit migrated from https://github.com/mono/mono/commit/2ca04a9743ceab99714377180ba3b2b6d589ba7f

4 years ago[interp] Minor cleanup of `stackval_from_data`. Compiler can do it. (mono/mono#16534)
Jay Krell [Wed, 28 Aug 2019 10:11:56 +0000 (03:11 -0700)]
[interp] Minor cleanup of `stackval_from_data`. Compiler can do it. (mono/mono#16534)

I missed this earlier cleaning stackval_to_data.

Commit migrated from https://github.com/mono/mono/commit/56b83f489b42e076bd7259cf42b4c684e63c7785

4 years ago[interp] Asserts pessimize clang. Removing saves 16 bytes on Linux/amd64/clang. ...
Jay Krell [Wed, 28 Aug 2019 10:10:30 +0000 (03:10 -0700)]
[interp] Asserts pessimize clang. Removing saves 16 bytes on Linux/amd64/clang. (mono/mono#16530)

Paired with https://github.com/mono/mono/pull/16456, saves 16 bytes on Linux/amd64/clang.
No change with gcc.
Contributes to https://github.com/mono/mono/issues/16172.

Commit migrated from https://github.com/mono/mono/commit/c870df0aa7a8111743bab8bbe6b9f3f6fa8ed870

4 years agoRemove dead Boehm code. (mono/mono#15224)
Jay Krell [Wed, 28 Aug 2019 08:56:08 +0000 (01:56 -0700)]
Remove dead Boehm code. (mono/mono#15224)

* Remove dead Boehm code.

Unity looked similarly dead.

The key points making it dead were:

create_allocator:
  g_assert_not_reached() covering everything but local variables

mono_gc_get_managed_allocator:
  always returning NULL, killing a bunch of code
  after it

mono_gc_is_critical_method:
   looking at data that was never filled in

This should have no impact, not even on Boehm.
Boehm should continue working just the same.

It is nice because it is the few/only uses of CEE_MONO_TLS.

Commit migrated from https://github.com/mono/mono/commit/c534511003bdd84ef08dd8a7cf725d4d0f063f5e

4 years ago[mini] Cleanup MONO_MMAP_32BIT. (mono/mono#16469)
Jay Krell [Wed, 28 Aug 2019 08:54:00 +0000 (01:54 -0700)]
[mini] Cleanup MONO_MMAP_32BIT. (mono/mono#16469)

- It _presumably_ means nothing on 32bit ARM and 32bit MIPS (was there mono/mips64?).
 - Leaving only PowerPC32 and PowerPC64 (in this vicinity).
   - It presumably means nothing on PowerPC32.
   - Leaving PowerPC64 as the only user in this vicinity -- is it needed?
- Notice this is varyingly absent on x86, arm64, amd64, s390x.
  Subject of another PR maybe.

Perhaps this was to enable the debugger to be 32bit against a 64bit target
on a biarch system, so it could do a cross-process manipulation of these pages?
That makes some sense on Windows at least.
(32bit debugger cannot debug 64bit target as of Vista, but that is using the Win32
"hard" debugger API. Mono could do otherwise).

There remains amd64 mono-codeman.c define ARCH_MAP_FLAGS MONO_MMAP_32BIT left alone.

Commit migrated from https://github.com/mono/mono/commit/0375acd7c8b1634a44477f2a561a10cd4d01858a

4 years agoMerge pull request mono/mono#16520 from vargaz/fix-llvm-2
Zoltan Varga [Wed, 28 Aug 2019 07:24:01 +0000 (03:24 -0400)]
Merge pull request mono/mono#16520 from vargaz/fix-llvm-2

[llvm] Fix ctlz intrinsics, they have 2 arguments.

Commit migrated from https://github.com/mono/mono/commit/162849f97202e8a24355fb77b01657b891436383

4 years agofix cast and signature for mono_rconv_u4
Bernhard Urban [Tue, 27 Aug 2019 19:20:17 +0000 (21:20 +0200)]
fix cast and signature for mono_rconv_u4

Commit migrated from https://github.com/mono/mono/commit/d6fa5ff9c6c482582149c93613468a0e0432d2af

4 years ago[amd64] use opcode emulation for fconv/rconv
Bernhard Urban [Tue, 27 Aug 2019 16:38:57 +0000 (09:38 -0700)]
[amd64] use opcode emulation for fconv/rconv

Commit migrated from https://github.com/mono/mono/commit/460bfa9beb5159156df2256766d738debeffe706

4 years ago[llvmaotcheck] require sse3 being available for regression tests
Bernhard Urban [Tue, 27 Aug 2019 16:37:46 +0000 (09:37 -0700)]
[llvmaotcheck] require sse3 being available for regression tests

Commit migrated from https://github.com/mono/mono/commit/8e6b967391533fbbe555e8aa83a5fdf501f81c36

4 years ago[arm] use opcode emulation for fconv/rconv
Bernhard Urban [Tue, 27 Aug 2019 12:47:54 +0000 (08:47 -0400)]
[arm] use opcode emulation for fconv/rconv

Commit migrated from https://github.com/mono/mono/commit/5b20322a84bac20433103ac06a59e654cf581485

4 years ago[arm] account only 4 bytes on stack for single precision arguments
Bernhard Urban [Tue, 27 Aug 2019 12:46:06 +0000 (08:46 -0400)]
[arm] account only 4 bytes on stack for single precision arguments

Fixes `test_0_arm64_small_stack_args` in gshared.cs when
* `test_0_arm64_small_stack_args` is compiled with LLVM
* `Foo3.Floats` is compiled with Mini

Commit migrated from https://github.com/mono/mono/commit/ba824cb9213670069b85ab397a7163a50e911ff6

4 years ago[arm64] use opcode emulation for fconv/rconv
Bernhard Urban [Mon, 26 Aug 2019 20:00:06 +0000 (16:00 -0400)]
[arm64] use opcode emulation for fconv/rconv

LLVM eagerly optimizes constants such as NaN in a way that does not align with .NET behaviour. In the future we can change it so that we only do opcode emulation when LLVM is used.

Fixes https://github.com/mono/mono/issues/16411

Commit migrated from https://github.com/mono/mono/commit/475defca4d4d24dc44c660244b645df5f33e20ac

4 years agoCleanup arm64 SeqPointInfo.
Jay Krell [Mon, 26 Aug 2019 06:05:18 +0000 (23:05 -0700)]
Cleanup arm64 SeqPointInfo.

Commit migrated from https://github.com/mono/mono/commit/645c01066c08adef6d302a25d1ed9db6047e3042

4 years agoInline mono_string_length_internal and mono_string_chars_internal (mono/mono#16374)
Jay Krell [Tue, 27 Aug 2019 21:39:18 +0000 (14:39 -0700)]
Inline mono_string_length_internal and mono_string_chars_internal (mono/mono#16374)

* Inline mono_string_length_internal and mono_string_chars_internal for everyone.

* Add MONO_REQ_GC_UNSAFE_MODE.

Commit migrated from https://github.com/mono/mono/commit/f516e79dd981e174ebf04fe81b76cdbec25f6b20

4 years agoUpdate version information in System.Private.CoreLib to mimic CoreCLR and make Benchm...
Filip Navara [Tue, 27 Aug 2019 20:55:37 +0000 (22:55 +0200)]
Update version information in System.Private.CoreLib to mimic CoreCLR and make BenchmarkDotNet happy (mono/mono#16515)

BenchmarkDotNet recently updated the algorithms for .NET version detection (https://github.com/dotnet/BenchmarkDotNet/pull/1230) which made it incompatible with the version presented by Mono.

This updates the value of [ProductName](https://github.com/dotnet/coreclr/blob/mono/mono@1f428dbc5554191dadd27511cd5cd181e4a60efb/Directory.Build.targets#L7) and [Version](https://github.com/dotnet/coreclr/blob/mono/mono@c9007e73286456434ba12744e778e87a89fc1d90/eng/Versions.props#L5) to match what CoreCLR is currently reporting and makes the [BDN detection code](https://github.com/dotnet/BenchmarkDotNet/blob/mono/mono@b6d0e0f1d80ed60aa157149a0dfb704a2da4ca41/src/BenchmarkDotNet/Environments/Runtimes/CoreRuntime.cs#L73-L81) happy.

Commit migrated from https://github.com/mono/mono/commit/f4145ce10815b2f4a1d585dbdf462aa17015aed1

4 years ago[netcore] Change exception thrown for SetTypedReference (mono/mono#16518)
Ryan Lucia [Tue, 27 Aug 2019 20:53:37 +0000 (16:53 -0400)]
[netcore] Change exception thrown for SetTypedReference (mono/mono#16518)

This brings us in line with CoreCLR behavior.

Commit migrated from https://github.com/mono/mono/commit/f9f5fff40c2012dc9631b7128d72c945620ce4fb

4 years ago[llvm] Fix ctlz intrinsics, they have 2 arguments.
Zoltan Varga [Tue, 27 Aug 2019 20:34:27 +0000 (16:34 -0400)]
[llvm] Fix ctlz intrinsics, they have 2 arguments.

Commit migrated from https://github.com/mono/mono/commit/340289d4aed8b8fe59379991d7b1320b419a2d36

4 years ago[llvm] Fix the mixing of LLVM modules in the llvm JIT, use ctx->lmodule instead of...
Zoltan Varga [Tue, 27 Aug 2019 20:31:18 +0000 (16:31 -0400)]
[llvm] Fix the mixing of LLVM modules in the llvm JIT, use ctx->lmodule instead of module->lmodule.

Commit migrated from https://github.com/mono/mono/commit/ab1e9be35e78e6a99f5e97cc6e1df514ddbdb8ab

4 years agoFix the netcore build. (mono/mono#16519)
Zoltan Varga [Tue, 27 Aug 2019 20:30:16 +0000 (16:30 -0400)]
Fix the netcore build. (mono/mono#16519)

Commit migrated from https://github.com/mono/mono/commit/44d33673a5d390e1f691967eb776c608d60b7a64

4 years agoMerge pull request mono/mono#16487 from vargaz/cattr-data-handles
Zoltan Varga [Tue, 27 Aug 2019 19:22:30 +0000 (15:22 -0400)]
Merge pull request mono/mono#16487 from vargaz/cattr-data-handles

[runtime] Convert mono_reflection_create_custom_attr_data_args () to use handles.

Commit migrated from https://github.com/mono/mono/commit/3108d4305174a015484aa0f77226e98ea13cb948

4 years agouse gunichar2
Egor Bogatov [Tue, 27 Aug 2019 17:21:51 +0000 (20:21 +0300)]
use gunichar2

Commit migrated from https://github.com/mono/mono/commit/e9dff75d2fb049f11fdcf595b68de1f3061bdeb7

4 years agoRemove AppContext.cs that was moved to shared
Alexander Köplinger [Mon, 26 Aug 2019 23:50:15 +0000 (01:50 +0200)]
Remove AppContext.cs that was moved to shared

Commit migrated from https://github.com/mono/mono/commit/f914d900f6fc639b25eca68432133fedd4f6297b

4 years ago[interp] Remove unnecessary recomputation (mono/mono#16509)
Vlad Brezae [Tue, 27 Aug 2019 17:27:22 +0000 (20:27 +0300)]
[interp] Remove unnecessary recomputation (mono/mono#16509)

Seems to have been added by mistake in https://github.com/mono/mono/pull/16317, which was meant just to remove the locals variable from InterpFrame.

Commit migrated from https://github.com/mono/mono/commit/ccc4bf853618649602691c6a10af59f80cd18466

4 years ago[interp] Error handling refactor (optimize non-exception path) (helps clang save...
Jay Krell [Tue, 27 Aug 2019 13:31:10 +0000 (06:31 -0700)]
[interp] Error handling refactor (optimize non-exception path) (helps clang save stack) (mono/mono#16371)

While working on stack reduction, I believe I found that
the compiler could not tell how THROW_EX and/or NULL_CHECK terminate.

That is, essentially, the success paths preserve volatile registers.
They do not have to be spilled/filled.
This tweak should make it clearer to the compiler, optimized common paths, and not slow down uncommon paths.

This also cleans it up a little and reduces macro expansion, and then possibly should allow for reinlining what is now used only once.

Also add some const so it can be casted away less.

Believed to save 32 bytes of stack with Linux/amd64/clang, nothing for gcc.
And a nice cleanup.

Commit migrated from https://github.com/mono/mono/commit/00c1ec421a3d47931bd9ad719faec62e60277837

4 years agoMerge pull request mono/mono#16493 from EgorBo/impl-lzcnt
Zoltan Varga [Tue, 27 Aug 2019 10:51:03 +0000 (06:51 -0400)]
Merge pull request mono/mono#16493 from EgorBo/impl-lzcnt

Implement System.Runtime.Intrinsics.X86.Lzcnt

Commit migrated from https://github.com/mono/mono/commit/fa1288794b5a38fa717d0f8db459386c3d4b3ad3

4 years agoFix multiple SGEN_LOG to correctly scale elapsed time in usec. (mono/mono#16485)
Johan Lorensson [Tue, 27 Aug 2019 10:14:12 +0000 (12:14 +0200)]
Fix multiple SGEN_LOG to correctly scale elapsed time in usec. (mono/mono#16485)

Several SGEN_LOG entries logged usec based on result returend from TV_ELAPSED.
On SGEN's implementation of TV_ELAPSED, the result is not scaled to usec
but returned as 100ns ticks. This was not handled correctly by SGEN_LOG,
but other measures, like profile counters and SGEN binary protocol handles
it correctly.

Fix will adjust the SGEN_LOG calls currently presenting usec to correctly
scale the result. Fix also adds one additional logging measuring total
amount of time spend scanning thread data.

Commit migrated from https://github.com/mono/mono/commit/70aba13173840818246b470e425a6d2585e7672d

4 years ago [interp] Replace imethod with frame->imethod. (mono/mono#16459)
Jay Krell [Tue, 27 Aug 2019 09:51:21 +0000 (02:51 -0700)]
 [interp] Replace imethod with frame->imethod. (mono/mono#16459)

This conserves stack on Linux/amd64/gcc.

Commit migrated from https://github.com/mono/mono/commit/bfe1b6182cb4e354f94d00d3206be4b83331db1d

4 years agoCodeManager cleanup: (mono/mono#16468)
Jay Krell [Tue, 27 Aug 2019 08:40:35 +0000 (01:40 -0700)]
CodeManager cleanup: (mono/mono#16468)

- Chunks do not need flags, only codemanagers do.
 - Sort by size to minimize padding for alignment.
 - Booleans only need one bit.
 - Chunk is not spelled chunck.
 - Suggest foo accessors be named foo() and set_foo(), not get_foo() and set_foo().
   i.e. the more common "get" is implied.
- Allow free(0) w/o initialization.

Commit migrated from https://github.com/mono/mono/commit/6cf8b6e73824545709cf6556726e0460bc7e2558

4 years ago[monodis] Combine adjacent identical cases. (mono/mono#16501)
Jay Krell [Tue, 27 Aug 2019 08:36:59 +0000 (01:36 -0700)]
[monodis] Combine adjacent identical cases. (mono/mono#16501)

Commit migrated from https://github.com/mono/mono/commit/9f9e5f7803b98494ca8773876c81e0cc582d679d

4 years agoAdd SETUP_ICALL_FUNCTION.
Zoltan Varga [Tue, 27 Aug 2019 07:57:44 +0000 (03:57 -0400)]
Add SETUP_ICALL_FUNCTION.

Commit migrated from https://github.com/mono/mono/commit/c7d785f32996e9faa693f5e297d2ac47ee795acc

4 years agomono_attach_load_agent: Fix leaks, alloc, copy. (mono/mono#15950)
Jay Krell [Tue, 27 Aug 2019 07:46:35 +0000 (00:46 -0700)]
mono_attach_load_agent: Fix leaks, alloc, copy. (mono/mono#15950)

Extracted and slightly modified from https://github.com/mono/mono/pull/15868.

Commit migrated from https://github.com/mono/mono/commit/7ca15e5a42ad03572e9209abb7e030ad712ee4b5

4 years agoAdd missing const, particularly on functions "like" memcpy. (mono/mono#16477)
Jay Krell [Mon, 26 Aug 2019 23:04:46 +0000 (16:04 -0700)]
Add missing const, particularly on functions "like" memcpy. (mono/mono#16477)

But do not change the signatures of external functions.

Commit migrated from https://github.com/mono/mono/commit/67c97d30b45751b5d87254d07c5343d92008dfb5

4 years agoMerge pull request mono/mono#16451 from vargaz/gc-handle-pin
Zoltan Varga [Mon, 26 Aug 2019 21:31:50 +0000 (17:31 -0400)]
Merge pull request mono/mono#16451 from vargaz/gc-handle-pin

[runtime] Make the local gc handles pin the object they point to by scanning the handle area conservatively.

Commit migrated from https://github.com/mono/mono/commit/4f8c0b9b46eb014ba7db36d824b3002c217a6c5b

4 years ago[threadpool-io] Throw if backend won't be able to register a FD (mono/mono#16396)
Aleksey Kliger (λgeek) [Mon, 26 Aug 2019 21:13:45 +0000 (17:13 -0400)]
[threadpool-io] Throw if backend won't be able to register a FD (mono/mono#16396)

The poll+select i/o selector backend can't handle file descriptor ids greater
than FD_SETSIZE.  This can happen if too many files are open and we want to
wait on it.

Previously, mono would fail in the i/o selector thread by which point it was
too late to do anything.

With this change we will fail eagerly on the thread that calls IOSelector.Add
by throwing a NotSupportedException.

Addresses https://github.com/mono/mono/issues/15931

Commit migrated from https://github.com/mono/mono/commit/78edafd6e2d5ce886e2fd2ddc3cf8bbbffeeb860

4 years agoFix review comments.
Zoltan Varga [Mon, 26 Aug 2019 18:17:09 +0000 (14:17 -0400)]
Fix review comments.

Commit migrated from https://github.com/mono/mono/commit/65a71a2912920768134442e04ea17c4fa7382d22

4 years agoImplement Lzcnt hw intrinsics
Egor Bogatov [Mon, 26 Aug 2019 18:08:53 +0000 (21:08 +0300)]
Implement Lzcnt hw intrinsics

Commit migrated from https://github.com/mono/mono/commit/044d1519bdf40f37ec06128dd383c21157dc3c0e

4 years ago[netcore] Implement missing ThreadPool methods (for metrics) (mono/mono#16076)
Egor Bogatov [Mon, 26 Aug 2019 15:35:38 +0000 (18:35 +0300)]
[netcore] Implement missing ThreadPool methods (for metrics) (mono/mono#16076)

* Implement missing ThreadPool methods

* Address feedback

* ifdef for mono_threadpool_worker_get_completed_threads_count

* remove GetPendingUnmanagedWorkItemCount

Commit migrated from https://github.com/mono/mono/commit/85265d884cf31f8779daba2d639eb795fbc9bd5e

4 years ago[runtime] Convert mono_reflection_create_custom_attr_data_args () to use handles.
Zoltan Varga [Mon, 26 Aug 2019 15:17:15 +0000 (11:17 -0400)]
[runtime] Convert mono_reflection_create_custom_attr_data_args () to use handles.

Commit migrated from https://github.com/mono/mono/commit/a908b72037d0fd13f2a86208f35e833b62a96e55

4 years agoFix special case tramp assert in x86/amd64. (mono/mono#16476)
Johan Lorensson [Mon, 26 Aug 2019 14:46:43 +0000 (16:46 +0200)]
Fix special case tramp assert in x86/amd64. (mono/mono#16476)

https://github.com/mono/mono/pull/16408 temporary fixed a tramp issue on
x86 (also exist on amd64). This commit fixes the underlying issue and re-enable
the use of noreturn outside of netcore.

The problem hit by the use of OP_NOT_REACHED on x86/amd64 is due to a specific
case when the address to patch happens to fall at the start of a different
managed method. Since the use of OP_NOT_REACHED can end a method
with the call instruction on x86/amd64 in combination with how patch location
(using the return address from stack) is resolved, the implementation in
mono_arch_patch_callsite didn't take this case into account, reading incorrect
patch data, triggering assert oh x86. So, based on timing we could end up with
the following code:

025715B3 call 02570D98
025715B8 push ebp

since the patch target is 025715B8, but also the start of a completely different
method, method_start == origin_code. The fix is to detect this case on x86/amd64
(done on each arch since the way origin_code is detected is arch specific)
and then use a method_start of NULL, that is already a supported scenario.

Commit migrated from https://github.com/mono/mono/commit/f9be7a67d33d9bdec342401a8ed84885672e9b67

4 years ago[utils] Don't use MAP_32BIT on Apple platforms, fixes crash with XCode 11 beta6 ...
Alexander Köplinger [Mon, 26 Aug 2019 11:53:40 +0000 (13:53 +0200)]
[utils] Don't use MAP_32BIT on Apple platforms, fixes crash with XCode 11 beta6 (mono/mono#16441)

As of XCode 11 beta6 the MacOSX SDK defines the MAP_32BIT symbol:

```diff
--- /Applications/Xcode11-beta5.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include/sys/mman.h    2019-07-25 17:43:49.000000000 -0400
+++ /Applications/Xcode11-beta6.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include/sys/mman.h    2019-08-06 21:03:07.000000000 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2019 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  *
@@ -145,6 +145,10 @@
 #define MAP_RESILIENT_CODESIGN  0x2000 /* no code-signing failures */
 #define MAP_RESILIENT_MEDIA     0x4000 /* no backing-store failures */

+#if !defined(CONFIG_EMBEDDED)
+#define MAP_32BIT       0x8000          /* Return virtual addresses <4G only: Requires entitlement */
+#endif  /* !defined(CONFIG_EMBEDDED) */
+
 #endif  /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */

 /*
```

This causes the mono_valloc() function to try to use the MAP_32BIT flag for mmap().

However as mentioned in the comment for the symbol in mman.h it seems to require a special entitlement
which isn't available/documented anywhere yet.
This in turn causes the mmap call to fail presumably because we're missing that entitlement.

Instead we now skip setting this flag on Apple platforms to make mmap() behave like it did before.

Commit migrated from https://github.com/mono/mono/commit/2f2771fcfa22ac16a24a6a1ff2554440e5de29ca

4 years agoOptimized LLVM IR (mono/mono#16448)
Egor Bogatov [Mon, 26 Aug 2019 11:36:04 +0000 (14:36 +0300)]
Optimized LLVM IR (mono/mono#16448)

LLVM JIT: dump IR after optimizations

```csharp
[MethodImpl(MethodImplOptions.NoInlining)]
static int Test(int a, int b, int c) => a * b + a * c;
```
`MONO_VERBOSE_METHOD="Test"` now prints both unoptimized and optimized IR:
```llvm
*** Unoptimized LLVM IR for P:Test ***

; Function Attrs: noinline uwtable
define monocc i32 @"P:Test (int,int,int)"(i32 %arg_a, i32 %arg_b, i32 %arg_c) mono/mono#0 {
BB0:
  br label %BB3

BB3:                                              ; preds = %BB0
  br label %BB2

BB2:                                              ; preds = %BB3
  %t22 = mul i32 %arg_a, %arg_b
  %t25 = mul i32 %arg_a, %arg_c
  %t27 = add i32 %t22, %t25
  br label %BB1

BB1:                                              ; preds = %BB2
  ret i32 %t27
}
***

*** Optimized LLVM IR for P:Test ***

; Function Attrs: noinline uwtable
define monocc i32 @"P:Test (int,int,int)"(i32 %arg_a, i32 %arg_b, i32 %arg_c) mono/mono#0 {
BB0:
  %t251 = add i32 %arg_b, %arg_c
  %t27 = mul i32 %t251, %arg_a
  ret i32 %t27
}
***
```

Commit migrated from https://github.com/mono/mono/commit/6aaec2fe9b0c57dcd03967160d8c67bebcd91fae

4 years ago[interp] Cleanup stackval_to_data and stackval_to_data_addr. (mono/mono#16458)
Jay Krell [Mon, 26 Aug 2019 08:26:07 +0000 (01:26 -0700)]
[interp] Cleanup stackval_to_data and stackval_to_data_addr. (mono/mono#16458)

No functional change, except for debugging, look up a frame
for the prior value.

Commit migrated from https://github.com/mono/mono/commit/6671316e35d9753539a0276c2c90c0300403b0ad

4 years ago[android] remove text relocations in AOT/arm32 (mono/mono#16432)
Bernhard Urban [Mon, 26 Aug 2019 07:46:12 +0000 (09:46 +0200)]
[android] remove text relocations in AOT/arm32 (mono/mono#16432)

[android] remove text relocations in AOT/arm32

Remove support for "big assemblies" for AOT on Android running on ARM 32bit. This will remove relocations in `.text` which are not allowed in the upcoming Android Q release anymore.

_If_ a customer should run into this problem, the suggested workarounds are:
* Switch to ARM64, or
* Do not use AOT compilation.

Fixes https://github.com/mono/mono/issues/16369

Commit migrated from https://github.com/mono/mono/commit/b6ca76c48415393f09f09977327c0bcd99f10bf4

4 years agoDetect additional invalid assembly names when parsing (mono/mono#16446)
Ryan Lucia [Mon, 26 Aug 2019 03:13:39 +0000 (23:13 -0400)]
Detect additional invalid assembly names when parsing (mono/mono#16446)

Commit migrated from https://github.com/mono/mono/commit/510f3c7d70d576cffc5f32edf8741ed841e6211d

4 years agoAdd MONO_LLVM_INTERNAL to mono_jit_compile_method. (mono/mono#16463)
Jay Krell [Sun, 25 Aug 2019 21:52:17 +0000 (14:52 -0700)]
Add MONO_LLVM_INTERNAL to mono_jit_compile_method. (mono/mono#16463)

Commit migrated from https://github.com/mono/mono/commit/e95ef822a16406c2c75f973f22c6e47d0e4f4e7f

4 years ago[interp] Outline mono_interp_box_vt. (mono/mono#16454)
Jay Krell [Sun, 25 Aug 2019 17:11:02 +0000 (10:11 -0700)]
[interp] Outline mono_interp_box_vt. (mono/mono#16454)

Contributes to https://github.com/mono/mono/issues/16172.

Seen to reduce frame from 0xB8 to 0xA8 on Linux/amd64/gcc against master.
Possibly similar elsewhere.
(Possibly 8 added to a rounded 8.)

Add const, add braces, they might help compiler and/or programmer.

Commit migrated from https://github.com/mono/mono/commit/2224d6b55d286e8ab1f2b222f4171f9667c27ed6

4 years ago[runtime] Make the local gc handles pin the object they point to by scanning
Zoltan Varga [Sat, 24 Aug 2019 15:32:37 +0000 (11:32 -0400)]
[runtime] Make the local gc handles pin the object they point to by scanning
the handle area conservatively.

Commit migrated from https://github.com/mono/mono/commit/7d43ffda1a29315b20d2ab64d19db9d33e8faa4d

4 years ago[interp] Outline STRMFLD_VT. (mono/mono#16355)
Jay Krell [Sat, 24 Aug 2019 07:56:40 +0000 (00:56 -0700)]
[interp] Outline STRMFLD_VT. (mono/mono#16355)

Without being entirely scientific about it, this case seems
to be one that uses more than typical locals and therefore
be on a sort of critical path to reduce frame size.

I have a change that reduces frame to 0x78 bytes (albeit
not yet working) and to achieve that, in this case I refetched
the locals after function calls.

This achieves similar but perhaps more elegantly.

If we rest at larger frame size then this case might not be
on the critical path.

https://github.com/mono/mono/issues/16172

Commit migrated from https://github.com/mono/mono/commit/9d1eec6bf88656e8302441d0349dcc467a52b605

4 years ago[windows gc] Trim one syscall per thread in garbage collection. (mono/mono#16003)
Jay Krell [Sat, 24 Aug 2019 07:56:00 +0000 (00:56 -0700)]
[windows gc] Trim one syscall per thread in garbage collection. (mono/mono#16003)

* Skip one syscall per thread in garbage collection.
Specifically do not query for guard pages.
There are better ways:
 1. Visual C++ specific, __try / __except, get the guard page exception,
    put back the guard page. This is a little slower (exception + two syscalls),
    but exceedinly rare. __try itself is cheap on x86, free on the rest.
    This was also not allowed on UWP. It will be. And is VirtualProtectFromApp.

 2. Record the TEB and get from it the maximum commited page and just use MAX, trivial.

The comments are also not completely clear as to what is going on here, but they were close.
Augment them.

Commit migrated from https://github.com/mono/mono/commit/99e9d8064272eefdba7c567f44d924ad1ec938ac

4 years agoRemove dlmalloc from Win32. (mono/mono#15773)
Jay Krell [Sat, 24 Aug 2019 07:52:30 +0000 (00:52 -0700)]
Remove dlmalloc from Win32. (mono/mono#15773)

Commit migrated from https://github.com/mono/mono/commit/ab6a09741d1017800ecc2d1688562f68547d7834

4 years agoMerge pull request mono/mono#16414 from vargaz/llvm-gc-poll-wrapper
Zoltan Varga [Fri, 23 Aug 2019 22:06:17 +0000 (18:06 -0400)]
Merge pull request mono/mono#16414 from vargaz/llvm-gc-poll-wrapper

[llvm] Add a mono wrapper method for the gc poll cold cconv wrapper so the EH code can unwind through it.

Commit migrated from https://github.com/mono/mono/commit/ab9c58d76d49c750bf69ee4f6ba89c45c8a1df51

4 years agoReturn an empty string for assemblies loaded from stream (mono/mono#16345)
Ryan Lucia [Fri, 23 Aug 2019 19:58:10 +0000 (15:58 -0400)]
Return an empty string for assemblies loaded from stream (mono/mono#16345)

* Return an empty string for assemblies loaded from memory

* Blind attempt to fix wasm

Commit migrated from https://github.com/mono/mono/commit/83cf007ae3e52a7c83d2a31bbc939aa08df67392

4 years ago[netcore] Use requesting assembly's context for InternalLoad calls
Ryan Lucia [Wed, 21 Aug 2019 22:35:24 +0000 (18:35 -0400)]
[netcore] Use requesting assembly's context for InternalLoad calls

Commit migrated from https://github.com/mono/mono/commit/7615ba3e45654ce5b22125c818876c10b6e4fbf9

4 years ago[netcore] Random loader cleanup
Ryan Lucia [Wed, 21 Aug 2019 20:40:08 +0000 (16:40 -0400)]
[netcore] Random loader cleanup

Commit migrated from https://github.com/mono/mono/commit/0661bf0424f78f35571c229733d61b406f082e5b

4 years agoMerge pull request mono/mono#16431 from kjpou1/wasm-maindir-cleanup
Zoltan Varga [Fri, 23 Aug 2019 12:13:21 +0000 (08:13 -0400)]
Merge pull request mono/mono#16431 from kjpou1/wasm-maindir-cleanup

[wasm] Small cleanup of main wasm directory

Commit migrated from https://github.com/mono/mono/commit/f0cbb79b7f17d30c6674f600f4fccef8a4f1cc87

4 years ago[jit] Make mono_unwind_frame () ignore registers which are greater than NUM_DWARF_REGS.
Zoltan Varga [Fri, 23 Aug 2019 11:49:20 +0000 (07:49 -0400)]
[jit] Make mono_unwind_frame () ignore registers which are greater than NUM_DWARF_REGS.

These registers can be encountered in the unwind info for functions with a cold
cconv, like xmm0 on amd64. Since they are caller saved, they don't have to
be restored during EH.

Commit migrated from https://github.com/mono/mono/commit/97d2d976156f5584d913844f2610683978f2a567

4 years agoMerge pull request mono/mono#16429 from vargaz/llvm-jit-module
Zoltan Varga [Fri, 23 Aug 2019 10:40:09 +0000 (06:40 -0400)]
Merge pull request mono/mono#16429 from vargaz/llvm-jit-module

[llvm] Don't pass a module argument to the code in llvm-jit.cpp, we create a new LLVM module for each method.

Commit migrated from https://github.com/mono/mono/commit/fdd0d7f027f2f45a8aacd304747a42e4ae7d9739

4 years agoFix the bitcode build.
Zoltan Varga [Fri, 23 Aug 2019 10:28:40 +0000 (06:28 -0400)]
Fix the bitcode build.

Commit migrated from https://github.com/mono/mono/commit/81f736e7745d7d94c282eb20605e970db74aeef1

4 years ago[llvm] Add a cold wrapper and mono wrapper for gc poll for JITted code as well.
Zoltan Varga [Fri, 23 Aug 2019 09:34:52 +0000 (05:34 -0400)]
[llvm] Add a cold wrapper and mono wrapper for gc poll for JITted code as well.

Commit migrated from https://github.com/mono/mono/commit/4ed1c3335f2ddf88e1e402ad046bcb2d7cebc7d0