Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Linked Away" exception when using CurrentPrincipal with SDK linking enabled #7321

Closed
chamons opened this issue Oct 28, 2019 · 3 comments · Fixed by #7510
Closed

"Linked Away" exception when using CurrentPrincipal with SDK linking enabled #7321

chamons opened this issue Oct 28, 2019 · 3 comments · Fixed by #7510
Assignees
Labels
bug If an issue is a bug or a pull request a bug fix iOS Issues affecting iOS
Milestone

Comments

@chamons
Copy link
Contributor

chamons commented Oct 28, 2019

Steps to Reproduce

  1. Open attached project.
  2. Run on simulator with and without SDK linking enabled
  3. Note different behaviors.

Expected Behavior

Linked and non-linked to behave the same

Actual Behavior

Different behavior

Environment

https://gist.github.com/chamons/fd0e35cb9262e2ed0f4762f058e4f9ca

Example Project (If Possible)

CurrentPrincipalCrash.zip

Workaround

Add --nolinkaway to additional mtouch arguments

@chamons chamons added iOS Issues affecting iOS bug If an issue is a bug or a pull request a bug fix labels Oct 28, 2019
@chamons chamons added this to the Future milestone Oct 28, 2019
@chamons
Copy link
Contributor Author

chamons commented Oct 28, 2019

This older blog post from 2011 has details on where "Linked Away" comes from.

But in short:

  • There are parts of the base class library that use bits that the runtime on iOS does not support
  • Global settings like this tend to use remoting, which the runtime does not have enabled.
  • There is an optimization that we enable during linking which replaces these code paths (remoting, etc) with "Linked Away"

You can work around this by disabling that optimization with --nolinkaway additional mtouch argument.

However, I believe that this used to work. It may be a regression due to runtime changes (we are now calling more remoting code that we did before when using this API?)

@spouliot
Copy link
Contributor

IPrincipal principal = currentThread.GetExecutionContextReader ().LogicalCallContext.Principal;

Looks like the old MONOTOUCH (or MOBILE) code paths were removed from mono and the current code goes thru domain/remoting code that we do not include in our runtime/BCL by default.

@spouliot
Copy link
Contributor

likely worked before mono/mono@d45fb4e got merged

@spouliot spouliot self-assigned this Nov 28, 2019
spouliot added a commit to spouliot/xamarin-macios that referenced this issue Nov 28, 2019
xamarin#7321

Keep 'CallContextSecurityData' around since it's quite small (and the
normal linker logic will be able to deal with it if unused) and allows
the use of `Thread.CurrentPrincipal`

Also add unit test.

Fix xamarin#7321
spouliot added a commit that referenced this issue Nov 28, 2019
#7321 (#7510)

Keep 'CallContextSecurityData' around since it's quite small (and the
normal linker logic will be able to deal with it if unused) and allows
the use of `Thread.CurrentPrincipal`

Also add unit test.

Fix #7321
@ghost ghost locked as resolved and limited conversation to collaborators May 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug If an issue is a bug or a pull request a bug fix iOS Issues affecting iOS
Projects
None yet
2 participants