Граф коммитов

667 Коммитов

Автор SHA1 Сообщение Дата
Ivan Povazan bcb8e5cfd3
Exclude assemblies from NativeAOT app bundles (#18532)
Since NativeAOT generates native libraries and executables that do not
rely on assemblies they were compiled from, all managed assemblies can
be excluded from the application bundle.

This reduces the size of the application bundle by `3,17Mb` (or ~19%
compared to the baseline)

| MAUI ios app | Base | This PR | diff (%) |
|--------------|-----------|-----------|----------|
| SOD (Mb)     | 50,13 | 41,93 | -16,3%      |
| .ipa (Mb)    | 16,59  | 13,43  | -19%      |

Fixes: https://github.com/xamarin/xamarin-macios/issues/18472
2023-07-06 12:52:28 -04:00
Rolf Bjarne Kvinge 3c912d7aea [dotnet] Treat the ICU data file as a resource instead of an assembly.
We can fix this better once this fix reaches us:

    https://github.com/dotnet/runtime/pull/87813

because then we can set the ICU data file at build time (to a relative path).
2023-06-22 08:44:47 +02:00
Rolf Bjarne Kvinge d5a53d65b7 [runtime] Add a native IsNativeAOT flag. 2023-06-21 20:49:52 +02:00
Rolf Bjarne Kvinge 9b24c5dba6 [runtime] NativeAOT does not support dynamic registration 2023-06-21 20:49:51 +02:00
Rolf Bjarne Kvinge f964b5a157 [runtime] Create a version of our runtime that can be used with NativeAOT.
This contributes towards https://github.com/xamarin/xamarin-macios/issues/17339.
2023-06-21 20:49:49 +02:00
Rolf Bjarne Kvinge 7a5fca4230
Update runtime/xamarin/runtime.h
Co-authored-by: Ivan Povazan <55002338+ivanpovazan@users.noreply.github.com>
2023-05-15 15:18:03 +02:00
Rolf Bjarne Kvinge fb6ed7b770 [runtime] Add an API to look up the native symbol for an [UnmanagedCallersOnly] method.
Add an API to look up the native symbol for an [UnmanagedCallersOnly] method from native code.
2023-05-11 13:10:30 +02:00
Rolf Bjarne Kvinge 34264cd98f [dotnet] Add an 'IsManagedStaticRegistrar' feature to the linker.
This way we can ask the linker to inline the Runtime.IsManagedStaticRegistrar property, and remove any dead code paths.
2023-05-11 12:21:53 +02:00
Rolf Bjarne Kvinge e56920642b
[runtime] Re-generate product.h when the current commit changes. (#18231)
This way the runtime libraries are always up-to-date after building
after making local commits.
2023-05-08 14:54:47 +02:00
Rolf Bjarne Kvinge 36af029204
Change all null checking expressions to use 'is' and 'is not'. (#18176)
Change all null checking expressions to use 'is null' and 'is not null'
instead of '== null' and '!= null'.

This was mostly done with sed, so code can probably be improved in many
other ways with manual inspection, but that will come over time.

Also add code to the autoformat script to automatically fix these issues in the future.
2023-05-05 17:52:19 +02:00
Rolf Bjarne Kvinge edd9881b12
[runtime] Always look for dynamic libraries relative to the root directory first. Fixes #xamarin/maccore@2668. (#18121)
Fixes https://github.com/xamarin/maccore/issues/2668.
2023-04-25 10:22:40 +02:00
Rolf Bjarne Kvinge efc7551e3f
[runtime] Add support for passing on a connect timeout to sdb. (#18037)
The timeout can be given:

* By setting the __XAMARIN_DEBUG_CONNECT_TIMEOUT__ environment variable for the app when launching it.
* By passing the XamarinDebugConnectTimeout MSBuild property to 'dotnet run' or 'dotnet build /t:Run'.
* By setting the IOSDebugConnectTimeout MSBuild property at build time.

Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1778177.
2023-04-13 16:34:52 +02:00
Rolf Bjarne Kvinge 60fbd4d37e
[runtime] Remove native usage of MonoReferenceQueue and use a ConditionalWeakTable in managed code instead. (#17429)
This makes it possible to simplify and remove a good chunk of related code.

Especially for CoreCLR this should be a minor perf improvement, because we'll do fewer transitions between managed and native code.
2023-02-06 07:57:51 +01:00
Rolf Bjarne Kvinge 98819287cc
[runtime/generator] Add support for BindAs with CMVideoDimensions. (#17308)
This is required for some new iOS 16 APIs.
2023-01-25 15:34:28 +01:00
Rolf Bjarne Kvinge 480a6ed844
[src/runtime] Fix lookup of RID-specific satellite resources. Fixes #16847. (#17117)
If we're creating a universal app, and here are satellite assemblies that are not
identical across all RuntimeIdentifiers, those assemblies will be stored in a RuntimeIdentifier-specific
subdirectory during the build.

Unfortunately we didn't know how to find those assemblies at runtime, causing localizations
in universal apps to not work.

This change will:

* Add support for looking in the directory where RID-specific satellite assemblies
  are stored.
* Add an assembly resolution event handler to our CoreCLR bridge so that we can
  execute our custom lookup code.
* Add an assembly resource lookup test to monotouch-test.
* Add a macOS + Mac Catalyst variation of monotouch-test to xharness that triggers
  the bug (a universal test app).

Fixes https://github.com/xamarin/xamarin-macios/issues/16847.
2023-01-13 21:58:34 +01:00
Rolf Bjarne Kvinge 294314a518
[autoformat] Add the rest of the repository. (#16974) 2022-12-07 09:13:36 +01:00
Rolf Bjarne Kvinge 0a53f3cd60
Add automatic support for not building iOS 32-bit stuff when min iOS version is >= 11.0 (#16746)
There are no changes for 32-bit watchOS, because watchOS support is likely to
go away completely anyways.
2022-11-18 07:59:46 +01:00
Rolf Bjarne Kvinge ae0d5b534e
[perf] [runtime] Optimize startup by using function pointers instead of delegates for our native->managed bridge. (#16702)
Use function pointers to our managed callbacks instead of delegates for the native->managed bridge. This makes execution faster on AOT (because the AOT compiler can just emit the native function address, no need to go through the expensive marshalling machinery).

This involved a few changes to make the managed callbacks only use blittable types in the function signature:

* Use `sbyte` / `int8_t` instead of `bool`.
* Use pointers instead of `out`/`ref` arguments.
* Use `IntPtr` instead of `string` arguments.

The code rarely shows up in timing profiles before the change, and never after. This means that time-wise this doesn't save all that much, because there wasn't much to gain to begin with (but it's still a gain).

Memory-wise, we're now allocation 0,19 MiB less on startup (17,61 MiB vs 17,42 MiB).
2022-11-18 07:59:03 +01:00
Rolf Bjarne Kvinge 2f684ca72b
[runtime] Use the built-in support in MonoVM for autorelease pools on threadpool threads. Fixes #11788. (#16751)
MonoVM in .NET 6+ supports automatic autorelease pools on threadpool threads
just like CoreCLR does, so we can remove our custom mono profiler hooks to
accomplish this.

Fixes https://github.com/xamarin/xamarin-macios/issues/11788.
2022-11-15 17:44:41 +01:00
Rolf Bjarne Kvinge b8362b1079
[runtime] Validate that the static registrar code being registered was built using the same runtime. (#16652)
Co-authored-by: Manuel de la Pena <mandel@microsoft.com>
2022-11-10 10:45:20 +01:00
Rolf Bjarne Kvinge 9bca30dce6 Merge remote-tracking branch 'origin/main' into bump-main-in-xcode14-2022-09-09 2022-09-09 16:54:19 +02:00
Rolf Bjarne Kvinge aa8ded8e51
[runtime] Store assemblies' MVID in the generated static registrar code. (#15795)
This will increase app size a little bit: the space for the MVID + 4 bytes for each
assembly, but we'll be able to validate and show a helpful error message if the generated
static registrar code does not match the assembly loaded at runtime.

It's also a step toward per-assembly static registration (ref: #12067).
2022-09-08 10:34:05 +02:00
Rolf Bjarne Kvinge 433c48a35e Merge remote-tracking branch 'origin/main' into bump-main-in-xcode14-2022-09-07 2022-09-07 10:56:00 +02:00
Rolf Bjarne Kvinge 75112818b6
[runtime] Use a custom native -> managed trampoline for calling NSObject.InvokeConformsToProtocol from the generated static registrar code. (#15830)
This avoids one case where we we embed metadata tokens to a different assembly
in the generated static registrar code.

This is required for supporting per-assembly static registration
(https://github.com/xamarin/xamarin-macios/issues/12067).
2022-09-02 15:54:34 +02:00
Rolf Bjarne Kvinge a09a42a1f3
Revert "[debugger] Work around a debugger issue when using the interpreter.". Fixes #15585. (#15827)
This reverts commit f7bb07efc0.

This workaround is no longer needed, since the dotnet/runtime hash we're using
contains this fix.

Fixes https://github.com/xamarin/xamarin-macios/issues/15585.
2022-09-01 20:49:18 +02:00
Rolf Bjarne Kvinge ff3aeb5073 Merge remote-tracking branch 'origin/main' into bump-main-in-xcode14-2022-08-30 2022-08-30 11:14:47 +02:00
Rolf Bjarne Kvinge 68de101ce6
[UIKit] Wrap the call to UIApplicationMain in a @try/@catch handler. (#15746)
Wrap the call to UIApplicationMain in a @try/@catch handler, and convert any
Objective-C exceptions to a managed exception.

This way the managed Main method (which calls UIApplication.Main) will be able
to catch any Objective-C exceptions.
2022-08-26 13:56:33 +02:00
Rolf Bjarne Kvinge 4289148b28 Merge remote-tracking branch 'origin/main' into bump-main-in-xcode14-2022-08-26 2022-08-26 13:24:27 +02:00
Rolf Bjarne Kvinge 2cbf60dd0a
[runtime] Only build macOS libraries if we're building for macOS. (#15754) 2022-08-26 08:46:58 +02:00
Rolf Bjarne Kvinge 15d27acd92
[runtime] Add some debugging aid to xamarin_release_managed_ref. (#15767)
It's fairly frequent (due to various types of coding errors) to have the
call to '[self release]' in xamarin_release_managed_ref crash. These
crashes are typically very hard to diagnose, because it can be hard to
figure out which object caused the crash. So now we store the native
object in a static variable, so that it can be read using lldb from a core
dump.

Ref: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1481312.
2022-08-26 08:14:41 +02:00
Sebastien Pouliot a3310342fd
[runtime] Allow `IntPtr` for native objects in the dynamic registrar. Fixes #15708 (#15712)
Allow code like this

```csharp
[DllImport(Constants.ObjectiveCLibrary, EntryPoint = "objc_msgSendSuper")
static extern IntPtr IntPtr_objc_msgSendSuper(IntPtr receiver, IntPtr selector);

[DllImport(Constants.ObjectiveCLibrary, EntryPoint = "objc_msgSendSuper")]
static extern void void_objc_msgSendSuper(IntPtr receiver, IntPtr selector, IntPtr arg);

[Export("selectedTextRange")]
public new IntPtr SelectedTextRange
{
    get { return IntPtr_objc_msgSendSuper(SuperHandle, Selector.GetHandle("selectedTextRange")); }
    set => void_objc_msgSendSuper(SuperHandle, Selector.GetHandle("setSelectedTextRange:"), value);
}
```

to work on the dynamic registrar since it already work with the static one.
This allows the simulators (which defaults to dynamic) to share the same code which is useful for implementing a workaround for related issue #15677.
2022-08-23 10:44:52 +02:00
Thays Grazia 7cd34d2501
[debugger] Work around a debugger issue when using the interpreter (#15451)
There's a bug in the Mono runtime where the interpreter does not disable optimizations when the debugger is attached, which leads to the interpreter optimizing code and the debugger ending up rather confused.

The bug is fixed in the Mono runtime (https://github.com/dotnet/runtime/pull/71436), but there's no immediate way for the runtime to release this fix, so here we're implementing a workaround that disables interpreter optimizations if the debugging is enabled. It's somewhat clunky because the Mono external API wasn't designed for this, so we have to abuse the API a bit to accomplish the effect we want.

This is somewhat risky (since we're changing the startup path in a pretty big way), but there's an escape hatch via an environment variable, and also the workaround will not be in effect for release builds.

While the runtime issue exists in legacy mono/mono as well, we'll fix the Mono runtime for legacy, because we don't have to wait to consume legacy mono (https://github.com/xamarin/xamarin-macios/pull/15507). This means that the workaround is for .NET scenarios only.

Co-authored-by: Manuel de la Pena <mandel@microsoft.com>
Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
2022-07-15 13:46:14 +02:00
Rolf Bjarne Kvinge a99f6c928a
[runtime] Remove dead code. (#15479)
This has been dead code for over 9 years!
2022-07-13 20:33:40 +02:00
Rolf Bjarne Kvinge 4acb844e5c
[runtime] Adjust exception handling to always return managed exceptions if so requested. (#15432)
In the following scenario:

* Objective-C exception mode is to throw a managed exception.
* The xamarin_process_nsexception_using_mode was given a pointer to store any
  resulting exceptions.
* The Objective-C exception didn't already have an associated managed exception.

We'd throw the managed exception upon return to managed code instead of
returning the managed exception.

With this change the xamarin_process_nsexception_using_mode will always return
the resulting managed exception in the scenario above (this way the behavior
is identical independent of whether the Objective-C exception already has an
associated managed exception or not).
2022-07-13 10:59:40 +02:00
Rolf Bjarne Kvinge 76fbc898cc
[runtime] The InitializationFlagsDynamicRegistrar flag is never used, so remove it (#15435) 2022-07-13 10:59:13 +02:00
Rolf Bjarne Kvinge 4e1114fde6
[tools] Use MONO_AOT_MODE_INTERP_ONLY instead of MONO_AOT_MODE_INTERP for x86_64. (#15429)
The 'MONO_AOT_MODE_INTERP' mode is based on full AOT, which requires infinite
trampoline code to not potentially run out of trampolines. However, that mode
isn't implemented for x86_64, so in that case use 'MONO_AOT_MODE_INTERP_ONLY',
which will use the JIT as a fallback.

Ref: https://github.com/dotnet/runtime/issues/68808

Fixes: https://github.com/xamarin/xamarin-macios/issues/14887
2022-07-12 09:56:51 +02:00
Rolf Bjarne Kvinge 8adbefdac8
[runtime] Fix 'skip_nested_brace' to not read past the string. Fixes #15253. (#15257)
Fix 'skip_nested_brace' to not double skip characters.

Also add a test.

Fixes https://github.com/xamarin/xamarin-macios/issues/15253.
2022-06-14 14:26:07 +02:00
Rolf Bjarne Kvinge a1d0b6eba9
Make our local .NET the default .NET for the build. (#15086)
Make our local .NET the default .NET (in the root's global.json), and then if
a directory wants to use the system .NET, then that directory would have to
opt-in (using its own global.json).

This way we don't have to copy global.json/NuGet.config files around to run
tests with the correct .NET setup.
2022-06-07 10:11:02 +02:00
Rolf Bjarne Kvinge 6bccb1f1d3
[runtime] Improve error reporting when calling mono_assembly_open. (#15139) 2022-06-03 10:41:43 +02:00
Rolf Bjarne Kvinge 5de4754c31
[runtime] Skip passing ICU_DAT_FILE_PATH to the runtime if we don't have an ICU data file. (#15085) 2022-05-25 08:31:26 +02:00
Rolf Bjarne Kvinge 27d1d0292b
[runtime] Handle fatal managed exceptions a bit better in the runtime. (#15029)
Handle managed exceptions a bit better when we know there won't be any other
managed frames further up the stack (such as in the main method). In this
case, there's no use in trying to convert the managed exception into an
Objective-C exception, because we already know the process will be terminated.

Instead just print the exception to stderr, and abort immediately.

This means we'll actually get some useful information printed to stderr.
2022-05-16 21:31:37 +02:00
Rolf Bjarne Kvinge cf44501f0f
[runtime] Fix build when logging is enabled. (#14922) 2022-05-10 09:26:20 +02:00
Eric Sink b84b80902c
Build fixes (-dotnet) for app extensions (#14685)
Resolves #14285 

1.  Make sure `libextension-dotnet.a` gets built, and with the `-DEXTENSION` flag.
2.  Make sure `libextension-dotnet.a` gets included in the package alongside `libxamarin-dotnet.a`
3. At build time, make sure to link with the correct lib[tv]extension-dotnet.a library depending when we need to.
4. Add some tests.

Co-authored-by: Eric Sink <eric@Erics-MacBook-Pro.local>
Co-authored-by: Manuel de la Pena <mandel@microsoft.com>
Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
2022-04-25 16:56:52 +02:00
Rolf Bjarne Kvinge 4fba6701e1
[runtime] Don't try process managed exceptions in xamarin_initialize. (#14792)
If we try to process any exceptions, we'll throw an Objective-C exception,
which will likely be unhandled because we're pretty much at the top of the
stack, and when we handle this Objective-C exception we'll try to convert it
into a managed exception and throw that, and since there are no managed frames
on the stack we'll end up converting it to an Objective-C exception, which
we'll try to throw, and so on, eventually running into a stack overflow.

This is unnecessary, so just abort directly.
2022-04-22 09:01:49 +02:00
Rolf Bjarne Kvinge 3afb12f692
[CoreCLR] Rework how we track the lifetime of managed NSObjects. (#14785)
* We now create a tracking GCHandle for all NSObjects, not only the toggled ones.
  CoreCLR will notify us when a tracked GCHandle's target enters finalization, and
  we need to be notified for all NSObjects, not just the toggled ones.
* Augment the tracking callback to know about non-toggled objects, and in that
  case report that the tracking GCHandle is a weak GCHandle.
* There's no need to store the tracking GCHandle in a field in the NSObject instance,
  since we store it in our runtime object_map.
* Remove one place where we set the InFinalizerQueue flag, since it's no longer
  required there (this reverts a previous attempt at fixing this problem - 0622ae4af2)
  - we only set the InFinalizerQueue flag in the xamarin_coreclr_reference_tracking_tracked_object_entered_finalization
  callback now.
* Update a few comments accordingly.

Partial fix for https://github.com/xamarin/xamarin-macios/issues/13531.

Fixes https://github.com/xamarin/xamarin-macios/issues/13921 (again).
2022-04-21 08:22:24 +02:00
Rolf Bjarne Kvinge 7d229665c8
[runtime] Don't call 'retain' and 'autorelease' selectors on returned NativeObjects. (#14690)
We were trying to call the 'retain' and 'autorelease' selectors on objects
that weren't NSObjects when returning them from function calls. For some
unfathomable reason that has worked until now, but I started running into this
problem with other (unrelated) changes, so it needs to be fixed.

The fix is to not call the 'retain' and 'autorelease' selectors on
NativeObjects, instead call into managed code to either call the Retain method
on the managed NativeObject (if we're supposed to retain the return value), or
if we have to autorelease the return value, then check first if the input is
an NSObject, and only then call retain+autorelease.
2022-04-20 14:09:09 +02:00
Rolf Bjarne Kvinge 80a791cdc9
[runtime] Fix typo in comment. (#14687) 2022-04-07 18:30:06 +02:00
Alex Soto 35e2e45e98 [Xcode 13.3] Initial commit to Xcode 13.3 release 2022-03-14 22:54:33 -04:00
Rolf Bjarne Kvinge bd97933b60
[runtime] Remove ObjCRuntime.nfloat in favor of System.Runtime.InteropServices.NFloat. (#14197)
* Remove ObjCRuntime.nfloat (in favor of   System.Runtime.InteropServices.NFloat).
* Automatically add a reference to the System.Runtime.InteropServices.Internal
  package, so that developers get the new NFloat API (with operators) we've
  added post .NET 6 (but don't do this for .NET 7).
* Automatically add a global using alias for
  System.Runtime.InteropServices.NFloat -> nfloat. This is not behind the
  usual `ImplicitUsings` condition our other implicit usings are, because
  they're off by default for existing projects, and the main target for the
  global using alias for nfloat is upgraded projects.
* Automatically generate a global using alias (like above) in the generator
  for all code the generator compiles.
* Update xtro entries to reference System.Runtime.InteropServices.NFloat
  instead of ObjCRuntime.nfloat.
* Add a workaround for a hopefully temporary issue with .NET/CoreCLR where the
  wrong runtime pack is selected otherwise (without the new NFloat API, so
  nothing works at runtime).

Ref: https://github.com/xamarin/xamarin-macios/issues/13087
2022-02-24 16:51:12 +01:00
Rolf Bjarne Kvinge 5acea1a41f
[runtime] Ask curl to fail (--fail) if fetching the URL fails for coreclrhost.h. (#14216)
This fixes an issue where the build would continue if the server in question
serves an error page (and eventually fail with weird errors because the error
page wouldn't be valid C code).
2022-02-23 08:10:51 +01:00